use SL::ReportGenerator;
require "bin/mozilla/common.pl";
+require "bin/mozilla/drafts.pl";
require "bin/mozilla/reportgenerator.pl";
1;
$auth->assert('general_ledger');
+ return $lxdebug->leave_sub() if (load_draft_maybe());
+
$form->{title} = "Add";
$form->{callback} = "gl.pl?action=add" unless $form->{callback};
$button1 = qq|
<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
<input type=button name=datefrom id="trigger1" value=|
- . $locale->text('button') . qq|></td>
+ . $locale->text('button') . qq|></td>
|;
$button2 = qq|
<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
$auth->assert('general_ledger');
- $form->{sort} ||= "transdate";
+ report_generator_set_default_sort('transdate', 1);
GL->all_transactions(\%myconfig, \%$form);
}
- my $callback = build_std_url('action=generate_report', @hidden_variables);
+ my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
$form->{l_credit_accno} = 'Y';
$form->{l_debit_accno} = 'Y';
'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
);
- map { $column_defs{$_}->{link} = $callback . "&sort=${_}" } qw(id transdate reference source description);
- map { $column_defs{$_}->{link} = $callback . "&sort=accno" } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno debit_tax credit_tax);
+ foreach my $name (qw(id transdate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
+ my $sortname = $name =~ m/accno/ ? 'accno' : $name;
+ my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
+ $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
+ }
+
map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
my %column_alignment;
- map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax);
- map { $column_alignment{$_} = 'center' } qw(transdate reference description source notes debit_accno credit_accno debit_tax_accno credit_tax_accno);
+ map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance);
+ map { $column_alignment{$_} = 'center' } qw(reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
+ map { $column_alignment{$_} = 'left' } qw(description source notes);
+ map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
my $report = SL::ReportGenerator->new(\%myconfig, $form);
$report->set_columns(%column_defs);
$report->set_column_order(@columns);
- $report->set_export_options('generate_report', @hidden_variables);
+ $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
- $report->set_sort_indicator($form->{sort}, 1);
+ $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
$report->set_options('top_info_text' => join("\n", @options),
'output_format' => 'HTML',
$report->set_options_from_form();
# add sort to callback
- $form->{callback} = "$callback&sort=" . E($form->{sort});
-
- $form->{balance} *= $ml;
+ $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
- if ($form->{accno} && $form->{balance}) {
- my $row = {
- 'balance' => {
- 'data' => $form->format_amount(\%myconfig, $form->{balance}, 2),
- 'align' => 'right',
- },
- };
-
- $report->add_data($row);
- }
my @totals_columns = qw(debit credit debit_tax credit_tax);
my %subtotals = map { $_ => 0 } @totals_columns;
my $idx = 0;
foreach $ref (@{ $form->{GL} }) {
- $form->{balance} *= $ml;
my %rows;
my $value = $ref->{$key}->{$idx};
$subtotals{$key} += $value;
$totals{$key} += $value;
- $form->{balance} = abs($form->{balance}) - abs($value);
+ if ($key =~ /debit.*/) {
+ $ml = -1;
+ } else {
+ $ml = 1;
+ }
+ $form->{balance} = $form->{balance} + $value * $ml;
push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
}
}
- foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate)) {
+ foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
$rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
}
my $row = { };
map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
- $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance}, 2);
+ my $sh = "";
+ if ($form->{balance} < 0) {
+ $sh = " S";
+ $ml = -1;
+ } elsif ($form->{balance} > 0) {
+ $sh = " H";
+ $ml = 1;
+ }
+ my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
+ $data .= $sh;
+
+ $row->{balance}->{data} = $data;
$row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
- map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description source notes);
+ map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes);
- map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno);
+ map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
$row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
- $row->{balance} = {
- 'data' => $form->format_amount(\%myconfig, $form->{balance} * $ml, 2),
- 'align' => 'right',
- 'class' => 'listtotal',
- };
+
+ my $sh = "";
+ if ($form->{balance} < 0) {
+ $sh = " S";
+ $ml = -1;
+ } elsif ($form->{balance} > 0) {
+ $sh = " H";
+ $ml = 1;
+ }
+ my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
+ $data .= $sh;
+
+ $row->{balance}->{data} = $data;
+
$report->add_data($row);
my $raw_bottom_info_text;
$form->{"taxchart_$i"} = "0--0.00";
$form->{"tax_$i"} = 0;
}
- if (!$form->{"korrektur_$i"}) {
- ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
- if ($taxkey > 1) {
- if ($debitcredit) {
- $debittax = 1;
- } else {
- $credittax = 1;
- }
- if ($form->{taxincluded}) {
- $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
- } else {
- $form->{"tax_$i"} = $amount * $rate;
- }
+ ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
+ if ($taxkey > 1) {
+ if ($debitcredit) {
+ $debittax = 1;
} else {
- $form->{"tax_$i"} = 0;
+ $credittax = 1;
+ }
+ if ($form->{taxincluded}) {
+ $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
+ } else {
+ $form->{"tax_$i"} = $amount * $rate;
}
+ } else {
+ $form->{"tax_$i"} = 0;
}
for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
$form->{totaldebit} = 0;
$form->{totalcredit} = 0;
- my @old_project_ids = ();
- map({ push(@old_project_ids, $form->{"project_id_$_"})
- if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
-
- $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
- "all" => 0,
- "old_id" => \@old_project_ids },
- "charts" => { "key" => "ALL_CHARTS",
- "transdate" => $form->{transdate} },
- "taxcharts" => "ALL_TAXCHARTS");
-
my %project_labels = ();
my @project_values = ("");
foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
my %charts = ();
my $taxchart_init;
foreach my $item (@{ $form->{ALL_CHARTS} }) {
- my $key = Q($item->{accno}) . "--" . Q($item->{tax_id});
- $taxchart_init = $item->{taxkey_id} unless (@chart_values);
+ my $key = $item->{accno} . "--" . $item->{tax_id};
+ $taxchart_init = $item->{tax_id} unless (@chart_values);
push(@chart_values, $key);
- $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
+ $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
$charts{$item->{accno}} = $item;
}
my @taxchart_values = ();
my %taxcharts = ();
foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
- my $key = Q($item->{id}) . "--" . Q($item->{rate});
- $taxchart_init = $key if ($taxchart_init eq $item->{taxkey});
+ my $key = $item->{id} . "--" . $item->{rate};
+ $taxchart_init = $key if ($taxchart_init == $item->{id});
push(@taxchart_values, $key);
- $taxchart_labels{$key} = H($item->{taxdescription}) . " " .
- H($item->{rate} * 100) . ' %';
+ $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
$taxcharts{$item->{id}} = $item;
}
for $i (1 .. $form->{rowcount}) {
-
- $source = qq|
- <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
- $memo = qq|
- <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
+ if ($form->{show_details}) {
+ $source = qq|
+ <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
+ $memo = qq|
+ <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
+ } else {
+ $source_hidden = qq|
+ <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
+ $memo_hidden = qq|
+ <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
+ }
my $selected_accno_full;
my ($accno_row) = split(/--/, $form->{"accno_$i"});
$selected_taxchart = "$item->{id}--$item->{rate}";
}
- $selected_accno = '' if ($init);
- $selected_taxchart = $taxchart_init unless ($selected_taxchart ne "");
+ $selected_accno = '' if ($init);
+ $selected_taxchart ||= $taxchart_init;
$accno = qq|<td>| .
NTI($cgi->popup_menu('-name' => "accno_$i",
'-id' => "accno_$i",
- '-onChange' => "setTaxkey(this, $i)",
+ '-onChange' => "setTaxkey($i)",
'-style' => 'width:200px',
'-values' => \@chart_values,
'-labels' => \%chart_labels,
. qq|</td>|;
if ($init) {
- $korrektur =
- qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
if ($form->{transfer}) {
$fx_transaction = qq|
<td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
<td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
|;
}
- $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
- $korrektur =
- qq|<td><input type="checkbox" name="korrektur_$i" value="1" $checked></td>|;
$form->hide_form("accno_$i");
} else {
- $korrektur =
- qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
if ($form->{transfer}) {
$fx_transaction = qq|
<td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
print qq|<tr valign=top>
$accno
+ <td id="chart_balance_$i" align="right"> </td>
$fx_transaction
<td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
<td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
- <td><input name="tax_$i" size=6 value="$form->{"tax_$i"}"></td>
- $korrektur
+ <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
$tax|;
if ($form->{show_details}) {
|;
}
print qq|
+ $source_hidden
+ $memo_hidden
</tr>
|;
}
$auth->assert('general_ledger');
+ my @old_project_ids = ();
+ map({ push(@old_project_ids, $form->{"project_id_$_"})
+ if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
+
+ $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
+ "all" => 0,
+ "old_id" => \@old_project_ids },
+ "charts" => { "key" => "ALL_CHARTS",
+ "transdate" => $form->{transdate} },
+ "taxcharts" => "ALL_TAXCHARTS");
+
+ GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
+
$title = $form->{title};
$form->{title} = $locale->text("$title General Ledger Transaction");
$readonly = ($form->{id}) ? "readonly" : "";
$form->{javascript} = qq|<script type="text/javascript">
<!--
- function setTaxkey(accno, row) {
+ function setTaxkey(row) {
+ var accno = document.getElementById('accno_' + row);
var taxkey = accno.options[accno.selectedIndex].value;
var reg = /--([0-9]*)/;
var found = reg.exec(taxkey);
var txt = document.getElementsByName('debit_1')[0].value;
document.getElementsByName('credit_2')[0].value = txt;
};
-
//-->
- </script>|;
- $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
+ </script>
+ <script type="text/javascript" src="js/show_form_details.js"></script>
+ <script type="text/javascript" src="js/jquery.js"></script>
+|;
$form->{selectdepartment} =~ s/ selected//;
$form->{selectdepartment} =~
$button1 = qq|
<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
<input type=button name=transdate id="trigger1" value=|
- . $locale->text('button') . qq|></td>
+ . $locale->text('button') . qq|></td>
|;
#write Trigger
$form->{previous_id} ||= "--";
$form->{previous_gldate} ||= "--";
+ $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js');
+
$form->header;
print qq|
-<body onLoad="fokus()">
+<body onLoad="focus()">
-<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/follow_up.js"></script>
<form method=post name="gl" action=gl.pl>
</td>
</tr>|;
}
- print qq|
+ print qq|
$department|;
if ($form->{id}) {
print qq|
<tr class=listheading>
<th class=listheading style="width:15%">|
. $locale->text('Account') . qq|</th>
+ <th class=listheading style="width:10%">| . $locale->text('Chart balance') . qq|</th>
<th class=listheading style="width:10%">|
. $locale->text('Debit') . qq|</th>
<th class=listheading style="width:10%">|
<th class=listheading style="width:10%">|
. $locale->text('Tax') . qq|</th>
<th class=listheading style="width:5%">|
- . $locale->text('Korrektur') . qq|</th>
- <th class=listheading style="width:10%">|
. $locale->text('Taxkey') . qq|</th>|;
if ($form->{show_details}) {
print qq|
<tr class=listtotal>
- <td></td>
- <th align=right class=listtotal> $form->{totaldebit}</th>
- <th align=right class=listtotal> $form->{totalcredit}</th>
+ <th colspan="3" align=right class=listtotal> $form->{totaldebit}</th>
+ <th align=right class=listtotal> $form->{totalcredit}</th>
<td colspan=6></td>
</tr>
</table>
<input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
}
- print qq|
+ print qq|
<input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
<input type="button" class="submit" onclick="follow_up_window()" value="|
. $locale->text('Follow-Up')
. qq|"> |;
} else {
- print qq|
+ if ($form->{draft_id}) {
+ my $remove_draft_checked = 'checked' if ($form->{remove_draft});
+ print qq|<p>\n|
+ . qq| <input name="remove_draft" id="remove_draft" type="checkbox" class="checkbox" ${remove_draft_checked}>|
+ . qq| <label for="remove_draft">| . $locale->text('Remove Draft') . qq|</label>\n|
+ . qq|</p>\n|;
+ }
+
+ print qq|
<input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
- <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">|;
+ <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> |
+ . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'))
+ . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
+ . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
}
print "
$form->{addition} = "DELETED";
$form->save_history($form->dbconnect(\%myconfig));
}
- # /saving the history
+ # /saving the history
$form->redirect($locale->text('Transaction deleted!'))
}
$form->error($locale->text('Cannot delete transaction!'));
$form->{"taxchart_$i"} = "0--0.00";
$form->{"tax_$i"} = 0;
}
- if (!$form->{"korrektur_$i"}) {
- ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
- if ($taxkey > 1) {
+ ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
+ if ($taxkey > 1) {
+ if ($debitcredit) {
+ $debittax = 1;
+ } else {
+ $credittax = 1;
+ }
+ if ($form->{taxincluded}) {
+ $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
if ($debitcredit) {
- $debittax = 1;
- } else {
- $credittax = 1;
- }
- if ($form->{taxincluded}) {
- $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
- if ($debitcredit) {
- $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
- } else {
- $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
- }
+ $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
} else {
- $form->{"tax_$i"} = $amount * $rate;
+ $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
}
} else {
- $form->{"tax_$i"} = 0;
- }
- } elsif ($form->{taxincluded}) {
- if ($debitcredit) {
- $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
- } else {
- $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
+ $form->{"tax_$i"} = $amount * $rate;
}
+ } else {
+ $form->{"tax_$i"} = 0;
}
for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
$credit += $cr + $tax if $cr;
$taxtotal += $tax if $form->{taxincluded}
}
-
+
$form->{taxincluded} = 0 if !$taxtotal;
# this is just for the wise guys
if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
$form->error($locale->text('Out of balance transaction!'));
}
-
+
if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
$form->error($locale->text('Empty transaction!'));
}
-
+
if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
$errno *= -1;
$err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
if(!exists $form->{addition} && $form->{id} ne "") {
$form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
$form->{addition} = "SAVED";
- $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
+ $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
$form->save_history($form->dbconnect(\%myconfig));
}
- # /saving the history
+ # /saving the history
$lxdebug->leave_sub();
}
post_transaction();
+ remove_draft() if $form->{remove_draft};
+
$form->{callback} = build_std_url("action=add", "show_details");
$form->redirect($form->{callback});
$form->{addition} = "STORNO";
$form->save_history($form->dbconnect(\%myconfig));
}
- # /saving the history
+ # /saving the history
- $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
+ $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
$lxdebug->leave_sub();
}