- |.$locale->text('Include in Report').qq| |
+ | . $locale->text('Include in Report') . qq| |
- |.$locale->text('All').qq|
- |.$locale->text('Asset').qq|
- |.$locale->text('Liability').qq|
- |.$locale->text('Revenue').qq|
- |.$locale->text('Expense').qq|
+ |
+ . $locale->text('All') . qq|
+ |
+ . $locale->text('Asset') . qq|
+ |
+ . $locale->text('Liability') . qq|
+ |
+ . $locale->text('Revenue') . qq|
+ |
+ . $locale->text('Expense') . qq|
|
@@ -307,12 +382,12 @@ $jsscript
-{path}>
{login}>
{password}>
-
+
@@ -321,594 +396,672 @@ $jsscript
$lxdebug->leave_sub();
}
+sub create_subtotal_row {
+ $lxdebug->enter_sub();
+
+ my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
+
+ my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
+
+ map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
+
+ map { $totals->{$_} = 0 } @{ $subtotal_columns };
+
+ $lxdebug->leave_sub();
+
+ return $row;
+}
sub generate_report {
$lxdebug->enter_sub();
- $form->{sort} = "transdate" unless $form->{sort};
+ $form->{sort} ||= "transdate";
GL->all_transactions(\%myconfig, \%$form);
-
- $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}";
- $href = $callback;
-
- %acctype = ( 'A' => $locale->text('Asset'),
- 'C' => $locale->text('Contra'),
- 'L' => $locale->text('Liability'),
- 'Q' => $locale->text('Equity'),
- 'I' => $locale->text('Revenue'),
- 'E' => $locale->text('Expense'),
- );
-
- $form->{title} = $locale->text('General Ledger');
-
- $ml = ($form->{ml} =~ /(A|E)/) ? -1 : 1;
+ my %acctype = ('A' => $locale->text('Asset'),
+ 'C' => $locale->text('Contra'),
+ 'L' => $locale->text('Liability'),
+ 'Q' => $locale->text('Equity'),
+ 'I' => $locale->text('Revenue'),
+ 'E' => $locale->text('Expense'),);
- unless ($form->{category} eq 'X') {
- $form->{title} .= " : ".$locale->text($acctype{$form->{category}});
+ $form->{title} = $locale->text('Journal');
+ if ($form->{category} ne 'X') {
+ $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
}
+
+ $form->{landscape} = 1;
+
+ my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
+
+ my @columns = qw(
+ transdate id reference description
+ notes source debit debit_accno
+ credit credit_accno debit_tax debit_tax_accno
+ credit_tax credit_tax_accno projectnumbers balance
+ );
+
+ my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
+ push @hidden_variables, map { "l_${_}" } @columns;
+
+ my (@options, $date_option);
if ($form->{accno}) {
- $href .= "&accno=".$form->escape($form->{accno});
- $callback .= "&accno=".$form->escape($form->{accno},1);
- $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";
- }
- if ($form->{gifi_accno}) {
- $href .= "&gifi_accno=".$form->escape($form->{gifi_accno});
- $callback .= "&gifi_accno=".$form->escape($form->{gifi_accno},1);
- $option .= "\n " if $option;
- $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";
+ push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}";
}
if ($form->{source}) {
- $href .= "&source=".$form->escape($form->{source});
- $callback .= "&source=".$form->escape($form->{source},1);
- $option .= "\n " if $option;
- $option .= $locale->text('Source')." : $form->{source}";
+ push @options, $locale->text('Source') . " : $form->{source}";
}
if ($form->{reference}) {
- $href .= "&reference=".$form->escape($form->{reference});
- $callback .= "&reference=".$form->escape($form->{reference},1);
- $option .= "\n " if $option;
- $option .= $locale->text('Reference')." : $form->{reference}";
+ push @options, $locale->text('Reference') . " : $form->{reference}";
}
if ($form->{department}) {
- $href .= "&department=".$form->escape($form->{department});
- $callback .= "&department=".$form->escape($form->{department},1);
- ($department) = split /--/, $form->{department};
- $option .= "\n " if $option;
- $option .= $locale->text('Department')." : $department";
+ my ($department) = split /--/, $form->{department};
+ push @options, $locale->text('Department') . " : $department";
}
-
if ($form->{description}) {
- $href .= "&description=".$form->escape($form->{description});
- $callback .= "&description=".$form->escape($form->{description},1);
- $option .= "\n " if $option;
- $option .= $locale->text('Description')." : $form->{description}";
+ push @options, $locale->text('Description') . " : $form->{description}";
}
if ($form->{notes}) {
- $href .= "¬es=".$form->escape($form->{notes});
- $callback .= "¬es=".$form->escape($form->{notes},1);
- $option .= "\n " if $option;
- $option .= $locale->text('Notes')." : $form->{notes}";
+ push @options, $locale->text('Notes') . " : $form->{notes}";
}
-
if ($form->{datefrom}) {
- $href .= "&datefrom=$form->{datefrom}";
- $callback .= "&datefrom=$form->{datefrom}";
- $option .= "\n " if $option;
- $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);
+ $date_option = $locale->text('From') . " " . $locale->date(\%myconfig, $form->{datefrom}, 1);
}
if ($form->{dateto}) {
- $href .= "&dateto=$form->{dateto}";
- $callback .= "&dateto=$form->{dateto}";
if ($form->{datefrom}) {
- $option .= " ";
- } else {
- $option .= "\n " if $option;
+ $date_option .= " ";
}
- $option .= $locale->text('Bis')." ".$locale->date(\%myconfig, $form->{dateto}, 1);
+ $date_option .= $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{dateto}, 1);
}
+ push @options, $date_option if $date_option;
+
+ my $callback = build_std_url('action=generate_report', @hidden_variables);
+
+ $form->{l_credit_accno} = 'Y';
+ $form->{l_debit_accno} = 'Y';
+ $form->{l_credit_tax} = 'Y';
+ $form->{l_debit_tax} = 'Y';
+ $form->{l_credit_tax_accno} = 'Y';
+ $form->{l_debit_tax_accno} = 'Y';
+ $form->{l_balance} = $form->{accno} ? 'Y' : '';
+
+ my %column_defs = (
+ 'id' => { 'text' => $locale->text('ID'), },
+ 'transdate' => { 'text' => $locale->text('Date'), },
+ 'reference' => { 'text' => $locale->text('Reference'), },
+ 'source' => { 'text' => $locale->text('Source'), },
+ 'description' => { 'text' => $locale->text('Description'), },
+ 'notes' => { 'text' => $locale->text('Notes'), },
+ 'debit' => { 'text' => $locale->text('Debit'), },
+ 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
+ 'credit' => { 'text' => $locale->text('Credit'), },
+ 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
+ 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
+ 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
+ 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
+ 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
+ 'balance' => { 'text' => $locale->text('Balance'), },
+ '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);
+ 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);
+
+ 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_sort_indicator($form->{sort}, 1);
+
+ $report->set_options('top_info_text' => join("\n", @options),
+ 'output_format' => 'HTML',
+ 'title' => $form->{title},
+ 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
+ );
+ $report->set_options_from_form();
+ # add sort to callback
+ $form->{callback} = "$callback&sort=" . E($form->{sort});
- @columns = $form->sort_columns(qw(transdate id reference description notes source debit debit_accno credit credit_accno debit_tax debit_tax_accno credit_tax credit_tax_accno accno gifi_accno));
+ $form->{balance} *= $ml;
- if ($form->{accno} || $form->{gifi_accno}) {
- @columns = grep !/(accno|gifi_accno)/, @columns;
- push @columns, "balance";
- $form->{l_balance} = "Y";
-
- }
-
- $form->{l_credit_accno} = "Y";
- $form->{l_debit_accno} = "Y";
- $form->{l_credit_tax} = "Y";
- $form->{l_debit_tax} = "Y";
- $form->{l_credit_tax_accno} = "Y";
- $form->{l_debit_tax_accno} = "Y";
- $form->{l_accno} = "N";
- foreach $item (@columns) {
- if ($form->{"l_$item"} eq "Y") {
- push @column_index, $item;
-
- # add column to href and callback
- $callback .= "&l_$item=Y";
- $href .= "&l_$item=Y";
- }
- }
+ if ($form->{accno} && $form->{balance}) {
+ my $row = {
+ 'balance' => {
+ 'data' => $form->format_amount(\%myconfig, $form->{balance}, 2),
+ 'align' => 'right',
+ },
+ };
- if ($form->{l_subtotal} eq 'Y') {
- $callback .= "&l_subtotal=Y";
- $href .= "&l_subtotal=Y";
+ $report->add_data($row);
}
- $callback .= "&category=$form->{category}";
- $href .= "&category=$form->{category}";
-
- $column_header{id} = "".$locale->text('ID')." | ";
- $column_header{transdate} = "".$locale->text('Date')." | ";
- $column_header{reference} = "".$locale->text('Reference')." | ";
- $column_header{source} = "".$locale->text('Source')." | ";
- $column_header{description} = "".$locale->text('Description')." | ";
- $column_header{notes} = "".$locale->text('Notes')." | ";
- $column_header{debit} = "".$locale->text('Debit')." | ";
- $column_header{debit_accno} = "".$locale->text('Debit Account')." | ";
- $column_header{credit} = "".$locale->text('Credit')." | ";
- $column_header{credit_accno} = "".$locale->text('Credit Account')." | ";
- $column_header{debit_tax} = "".$locale->text('Debit Tax')." | ";
- $column_header{debit_tax_accno} = "".$locale->text('Debit Tax Account')." | ";
- $column_header{credit_tax} = "".$locale->text('Credit Tax')." | ";
- $column_header{credit_tax_accno} = "".$locale->text('Credit Tax Account')." | ";
- $column_header{gifi_accno} = "".$locale->text('GIFI')." | ";
- $column_header{balance} = "".$locale->text('Balance')." | ";
-
- $form->{landscape} = 1;
-
- $form->header;
-
- print qq|
-
-
-
-
- $form->{title} |
-
-
-
- $option |
-
-
-
-
-
-
-|;
-
-map { print "$column_header{$_}\n" } @column_index;
-
-print "
-
-
-
-
-";
-
- # add sort to callback
- $form->{callback} = "$callback&sort=$form->{sort}";
- $callback = $form->escape($form->{callback});
-
- # initial item for subtotals
- if (@{ $form->{GL} }) {
- $sameitem = $form->{GL}->[0]->{$form->{sort}};
- }
-
- if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
+ my @totals_columns = qw(debit credit debit_tax credit_tax);
+ my %subtotals = map { $_ => 0 } @totals_columns;
+ my %totals = map { $_ => 0 } @totals_columns;
+ my $idx = 0;
- map { $column_data{$_} = " | " } @column_index;
- $column_data{balance} = "".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)." | ";
-
- $i++; $i %= 2;
- print qq|
-
-|;
- map { print "$column_data{$_}\n" } @column_index;
-
- print qq|
-
-|;
- }
-
foreach $ref (@{ $form->{GL} }) {
-
- # if item ne sort print subtotal
- if ($form->{l_subtotal} eq 'Y') {
- if ($sameitem ne $ref->{$form->{sort}}) {
- &gl_subtotal;
- }
- }
- foreach $key (sort keys (%{$ref->{amount}})) {
- $form->{balance} += $ref->{amount}{$key};
- }
-
- $debit = "";
- foreach $key (sort keys (%{$ref->{debit}})) {
- $subtotaldebit += $ref->{debit}{$key};
- $totaldebit += $ref->{debit}{$key};
- if ($key == 0) {
- $debit = $form->format_amount(\%myconfig, $ref->{debit}{$key} , 2, 0);
- } else {
- $debit .= " ".$form->format_amount(\%myconfig, $ref->{debit}{$key} , 2, 0);
- }
- }
-
- $credit = "";
- foreach $key (sort keys (%{$ref->{credit}})) {
- $subtotalcredit += $ref->{credit}{$key};
- $totalcredit += $ref->{credit}{$key};
- if ($key == 0) {
- $credit = $form->format_amount(\%myconfig, $ref->{credit}{$key} , 2, 0);
- } else {
- $credit .= " ".$form->format_amount(\%myconfig, $ref->{credit}{$key} , 2, 0);
- }
- }
-
- $debittax = "";
- foreach $key (sort keys (%{$ref->{debit_tax}})) {
- $subtotaldebittax += $ref->{debit_tax}{$key};
- $totaldebittax += $ref->{debit_tax}{$key};
- if ($key == 0) {
- $debittax = $form->format_amount(\%myconfig, $ref->{debit_tax}{$key} , 2, 0);
- } else {
- $debittax .= " ".$form->format_amount(\%myconfig, $ref->{debit_tax}{$key} , 2, 0);
+ $form->{balance} *= $ml;
+
+ my %rows;
+
+ foreach my $key (qw(debit credit debit_tax credit_tax)) {
+ $rows{$key} = [];
+ foreach my $idx (sort keys(%{ $ref->{$key} })) {
+ my $value = $ref->{$key}->{$idx};
+ $subtotals{$key} += $value;
+ $totals{$key} += $value;
+ $form->{balance} = abs($form->{balance}) - abs($value);
+ push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
}
}
-
- $credittax = "";
- foreach $key (sort keys (%{$ref->{credit_tax}})) {
- $subtotalcredittax += $ref->{credit_tax}{$key};
- $totalcredittax += $ref->{credit_tax}{$key};
- if ($key == 0) {
- $credittax = $form->format_amount(\%myconfig, $ref->{credit_tax}{$key} , 2, 0);
- } else {
- $credittax .= " ".$form->format_amount(\%myconfig, $ref->{credit_tax}{$key} , 2, 0);
- }
- }
-
- $debitaccno = "";
- $debittaxkey = "";
- $taxaccno = "";
- foreach $key (sort keys (%{$ref->{debit_accno}})) {
- if ($key == 0) {
- $debitaccno = "{accno}&callback=$callback>$ref->{debit_accno}{$key}";
- } else {
- $debitaccno .= " {accno}&callback=$callback>$ref->{debit_accno}{$key}";
- }
- if ($ref->{debit_taxkey}{$key} eq $debittaxkey) {
- $ref->{debit_tax_accno}{$key} = $taxaccno;
- }
- $taxaccno = $ref->{debit_tax_accno}{$key};
- $debittaxkey = $ref->{debit_taxkey}{$key};
- }
-
- $creditaccno = "";
- $credittaxkey = "";
- $taxaccno = "";
- foreach $key (sort keys (%{$ref->{credit_accno}})) {
- if ($key == 0) {
- $creditaccno = "{accno}&callback=$callback>$ref->{credit_accno}{$key}";
- } else {
- $creditaccno .= " {accno}&callback=$callback>$ref->{credit_accno}{$key}";
- }
- if ($ref->{credit_taxkey}{$key} eq $credittaxkey) {
- $ref->{credit_tax_accno}{$key} = $taxaccno;
- }
- $taxaccno = $ref->{credit_tax_accno}{$key};
- $credittaxkey = $ref->{credit_taxkey}{$key};
- }
-
- $debittaxaccno = "";
- foreach $key (sort keys (%{$ref->{debit_tax_accno}})) {
- if ($key == 0) {
- $debittaxaccno = "{accno}&callback=$callback>$ref->{debit_tax_accno}{$key}";
- } else {
- $debittaxaccno .= " {accno}&callback=$callback>$ref->{debit_tax_accno}{$key}";
- }
+
+ foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate)) {
+ my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
+ $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
}
-
- $credittaxaccno = "";
- foreach $key (sort keys (%{$ref->{credit_tax_accno}})) {
- if ($key == 0) {
- $credittaxaccno = "{accno}&callback=$callback>$ref->{credit_tax_accno}{$key}";
- } else {
- $credittaxaccno .= " {accno}&callback=$callback>$ref->{credit_tax_accno}{$key}";
- }
- }
-# $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
-# $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
-
- $column_data{id} = " $ref->{id} | ";
- $column_data{transdate} = " $ref->{transdate} | ";
- $column_data{reference} = "{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{reference} | ";
- $column_data{description} = "$ref->{description} | ";
- $column_data{source} = "$ref->{source} | ";
- $column_data{notes} = "$ref->{notes} | ";
- $column_data{debit} = "$debit | ";
- $column_data{debit_accno} = "$debitaccno | ";
- $column_data{credit} = "$credit | ";
- $column_data{credit_accno} = "$creditaccno | ";
- $column_data{debit_tax} = ($ref->{debit_tax_accno} ne "") ? "$debittax | " : " | ";
- $column_data{debit_tax_accno} = "$debittaxaccno | ";
- $column_data{gifi_accno} = "{gifi_accno}&callback=$callback>$ref->{gifi_accno} | ";
- $column_data{credit_tax} = ($ref->{credit_tax_accno} ne "") ? "$credittax | " : " | ";
- $column_data{credit_tax_accno} = "$credittaxaccno | ";
- $column_data{gifi_accno} = "{gifi_accno}&callback=$callback>$ref->{gifi_accno} | ";
- $column_data{balance} = "".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)." | ";
-
- $i++; $i %= 2;
- print "
- ";
- map { print "$column_data{$_}\n" } @column_index;
- print " ";
-
- }
+ my $row = { };
+ map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
- &gl_subtotal if ($form->{l_subtotal} eq 'Y');
+ $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance}, 2);
+ $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
+ map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description source notes);
- map { $column_data{$_} = " | " } @column_index;
-
- $column_data{debit} = "".$form->format_amount(\%myconfig, $totaldebit, 2, " ")." | ";
- $column_data{credit} = "".$form->format_amount(\%myconfig, $totalcredit, 2, " ")." | ";
- $column_data{debit_tax} = "".$form->format_amount(\%myconfig, $totaldebittax, 2, " ")." | ";
- $column_data{credit_tax} = "".$form->format_amount(\%myconfig, $totalcredittax, 2, " ")." | ";
- $column_data{balance} = "".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)." | ";
-
- print qq|
-
-|;
+ map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno);
- map { print "$column_data{$_}\n" } @column_index;
+ foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
+ $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
+ }
- print qq|
-
-
-
- |
-
-
-
|
-
-
+ map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
-
+ $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
-
+ $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
-
-
-|;
+ $report->generate_with_headers();
$lxdebug->leave_sub();
}
-
-sub gl_subtotal {
+sub update {
$lxdebug->enter_sub();
-
- $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
- $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
-
- map { $column_data{$_} = " | " } qw(transdate id reference source description accno);
- $column_data{debit} = "$subtotaldebit";
- $column_data{credit} = " | $subtotalcredit";
-
- print " | ";
- map { print "$column_data{$_}\n" } @column_index;
- print " ";
+ $form->{oldtransdate} = $form->{transdate};
- $subtotaldebit = 0;
- $subtotalcredit = 0;
+ my @a = ();
+ my $count = 0;
+ my $debittax = 0;
+ my $credittax = 0;
+ my $debitcount = 0;
+ my $creditcount = 0;
+ $debitlock = 0;
+ $creditlock = 0;
- $sameitem = $ref->{$form->{sort}};
+ my @flds =
+ qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
- $lxdebug->leave_sub();
+ for my $i (1 .. $form->{rowcount}) {
- return $sameitem;
-}
+ unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
+ for (qw(debit credit tax)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
+ }
+ push @a, {};
+ $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
+ if ($debitcredit) {
+ $debitcount++;
+ } else {
+ $creditcount++;
+ }
-sub update {
- $lxdebug->enter_sub();
+ if (($debitcount >= 2) && ($creditcount == 2)) {
+ $form->{"credit_$i"} = 0;
+ $form->{"tax_$i"} = 0;
+ $creditcount--;
+ $creditlock = 1;
+ }
+ if (($creditcount >= 2) && ($debitcount == 2)) {
+ $form->{"debit_$i"} = 0;
+ $form->{"tax_$i"} = 0;
+ $debitcount--;
+ $debitlock = 1;
+ }
+ if (($creditcount == 1) && ($debitcount == 2)) {
+ $creditlock = 1;
+ }
+ if (($creditcount == 2) && ($debitcount == 1)) {
+ $debitlock = 1;
+ }
+ if ($debitcredit && $credittax) {
+ $form->{"taxchart_$i"} = "0--0.00";
+ }
+ if (!$debitcredit && $debittax) {
+ $form->{"taxchart_$i"} = "0--0.00";
+ }
+ $amount =
+ ($form->{"debit_$i"} == 0)
+ ? $form->{"credit_$i"}
+ : $form->{"debit_$i"};
+ $j = $#a;
+ if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
+ $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;
+ }
+ } else {
+ $form->{"tax_$i"} = 0;
+ }
+ }
- @a = ();
- $count = 0;
- @flds = (qw(accno debit credit projectnumber project_id oldprojectnumber));
- $credit_save = $form->{credit};
- $debit_save = $form->{debit};
-
- if ($form->{chart} eq "") {
- $form->{creditchart} = "";
- $form->{debitchart} = "";
- } else {
- $form->{creditchart} = $form->{chart};
- $form->{creditchart} =~ s/value=\"$form->{creditchartselected}\"/value=\"$form->{creditchartselected}\" selected/;
-
- $form->{debitchart} = $form->{chart};
- $form->{debitchart} =~ s/value=\"$form->{debitchartselected}\"/value=\"$form->{debitchartselected}\" selected/;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
}
- ($debitaccno, $debittaxkey) = split(/--/, $form->{debitchartselected});
- ($creditaccno, $credittaxkey) = split(/--/, $form->{creditchartselected});
- if ($debittaxkey >0) {
- $form->{taxchart} = $form->unescape($form->{taxchart});
- $form->{taxchart} =~ s/selected//ig;
- $form->{taxchart} =~ s/\"$debittaxkey--([^\"]*)\"/\"$debittaxkey--$1\" selected/;
-
- $rate = $1;
-
- if ($form->{taxincluded}) {
- $form->{debit} = $form->parse_amount(\%myconfig, $form->{amount}) / ($rate + 1);
- $form->{credit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{tax} = $form->parse_amount(\%myconfig, $form->{amount}) / ($rate + 1) * $rate;
- } else {
- $form->{debit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{credit} = $form->parse_amount(\%myconfig, $form->{amount}) * ($rate + 1);
- $form->{tax} = $form->parse_amount(\%myconfig, $form->{amount}) * $rate;
- }
- } else {
- $form->{taxchart} = $form->unescape($form->{taxchart});
- $form->{taxchart} =~ s/selected//ig;
- $form->{taxchart} =~ s/\"$credittaxkey--([^\"]*)\"/\"$credittaxkey--$1\" selected/;
- $rate = $1;
-
- if ($form->{taxincluded}) {
- $form->{debit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{credit} = $form->parse_amount(\%myconfig, $form->{amount}) / ($rate + 1);
- $form->{tax} = $form->parse_amount(\%myconfig, $form->{amount}) / ($rate + 1) * $rate;
- } else {
- $form->{debit} = $form->parse_amount(\%myconfig, $form->{amount}) * ($rate + 1);
- $form->{credit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{tax} = $form->parse_amount(\%myconfig, $form->{amount}) * $rate;
- }
- }
- if ($form->{credit_splited}) {
- $form->{debit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{credit} = $credit_save;
- $form->{tax} = 0;
- } elsif ($form->{debit_splited}) {
- $form->{credit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{debit} = $debit_save;
- $form->{tax} = 0;
+
+ for $i (1 .. $count) {
+ $j = $i - 1;
+ for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
+ }
+
+ for $i ($count + 1 .. $form->{rowcount}) {
+ for (@flds) { delete $form->{"${_}_$i"} }
}
- &check_project;
+
+ $form->{rowcount} = $count + 1;
&display_form;
-
$lxdebug->leave_sub();
-}
+}
sub display_form {
+ my ($init) = @_;
$lxdebug->enter_sub();
+ &form_header($init);
- &form_header;
-# for $i (1 .. $form->{rowcount}) {
-# $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
-# $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
-#
-# &form_row($i);
-# }
-
+ # for $i (1 .. $form->{rowcount}) {
+ # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
+ # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
+ #
+ # &form_row($i);
+ # }
+ &display_rows($init);
&form_footer;
-
$lxdebug->leave_sub();
+
}
+sub display_rows {
+ my ($init) = @_;
+ $lxdebug->enter_sub();
+
+ $form->{debit_1} = 0 if !$form->{"debit_1"};
+ $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"} }) {
+ push(@project_values, $item->{"id"});
+ $project_labels{$item->{"id"}} = $item->{"projectnumber"};
+ }
+ my %chart_labels = ();
+ my @chart_values = ();
+ 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);
+ push(@chart_values, $key);
+ $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
+ $charts{$item->{accno}} = $item;
+ }
+ my %taxchart_labels = ();
+ 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});
+ push(@taxchart_values, $key);
+ $taxchart_labels{$key} = H($item->{taxdescription}) . " " .
+ H($item->{rate} * 100) . ' %';
+ $taxcharts{$item->{id}} = $item;
+ }
-sub form_header {
- $lxdebug->enter_sub();
+ for $i (1 .. $form->{rowcount}) {
- $title = $form->{title};
- $form->{title} = $locale->text("$title General Ledger Transaction");
- $readonly = ($form->{id}) ? "readonly" : "";
-
- $form->{urldebit} = "$form->{script}?action=split_debit&path=$form->{path}&login=$form->{login}&password=$form->{password}";
- $form->{urlcredit} = "$form->{script}?action=split_credit&path=$form->{path}&login=$form->{login}&password=$form->{password}";
-# $locale->text('Add General Ledger Transaction')
-# $locale->text('Edit General Ledger Transaction')
- map { $form->{$_} =~ s/\"/"/g } qw(reference description chart);
+ $source = qq|
+ | |;
+ $memo = qq|
+ | |;
- $form->{selectdepartment} =~ s/ selected//;
- $form->{taxchart} =~ s/ selected//;
- $form->{selectdepartment} =~ s/option>\Q$form->{department}\E/option selected>$form->{department}/;
+ my $selected_accno_full;
+ my ($accno_row) = split(/--/, $form->{"accno_$i"});
+ my $item = $charts{$accno_row};
+ $selected_accno_full = "$item->{accno}--$item->{tax_id}";
- if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
- $description = qq||;
- } else {
- $description = qq||;
- }
-
- $taxincluded = ($form->{taxincluded}) ? "checked" : "";
-
- if (!$form->{id}) {
- $taxincluded = "checked";
- }
-
- $amount = qq||;
-
-
- $department = qq|
-
- |.$locale->text('Department').qq| |
- |
-
-
-| if $form->{selectdepartment};
+ my $selected_taxchart = $form->{"taxchart_$i"};
+ my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
+ my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
- $form->{fokus} = "gl.reference";
- $form->{remote} = 1;
-
- # use JavaScript Calendar or not
- $form->{jsscript} = $jscalendar;
- $jsscript = "";
- if ($form->{jsscript})
- {
- # with JavaScript Calendar
- $button1 = qq|
- {transdate} tabindex="2" $readonly> |
- text('button').qq|> |
- |;
- #write Trigger
- $jsscript = Form->write_trigger(\%myconfig,"1","transdate","BL","trigger1","","","");
- }
- else
- {
- # without JavaScript Calendar
- $button1 = qq|{transdate} tabindex="2" $readonly> | |;
+ if ($previous_accno &&
+ ($previous_accno eq $selected_accno) &&
+ ($previous_tax_id ne $selected_tax_id)) {
+ my $item = $taxcharts{$selected_tax_id};
+ $selected_taxchart = "$item->{id}--$item->{rate}";
}
-
- $form->header;
-
+ $selected_accno = '' if ($init);
+ $selected_taxchart = $taxchart_init unless ($selected_taxchart ne "");
+
+ $accno = qq|| .
+ NTI($cgi->popup_menu('-name' => "accno_$i",
+ '-id' => "accno_$i",
+ '-onChange' => "setTaxkey(this, $i)",
+ '-style' => 'width:200px',
+ '-values' => \@chart_values,
+ '-labels' => \%chart_labels,
+ '-default' => $selected_accno_full))
+ . $cgi->hidden('-name' => "previous_accno_$i",
+ '-default' => $selected_accno_full)
+ . qq| | |;
+ $tax = qq|| .
+ NTI($cgi->popup_menu('-name' => "taxchart_$i",
+ '-id' => "taxchart_$i",
+ '-style' => 'width:200px',
+ '-values' => \@taxchart_values,
+ '-labels' => \%taxchart_labels,
+ '-default' => $selected_taxchart))
+ . qq| | |;
+
+ if ($init) {
+ $korrektur =
+ qq| | |;
+ if ($form->{transfer}) {
+ $fx_transaction = qq|
+ |
+ |;
+ }
+
+ } else {
+ if ($form->{"debit_$i"} != 0) {
+ $form->{totaldebit} += $form->{"debit_$i"};
+ if (!$form->{taxincluded}) {
+ $form->{totaldebit} += $form->{"tax_$i"};
+ }
+ } else {
+ $form->{totalcredit} += $form->{"credit_$i"};
+ if (!$form->{taxincluded}) {
+ $form->{totalcredit} += $form->{"tax_$i"};
+ }
+ }
+
+ for (qw(debit credit tax)) {
+ $form->{"${_}_$i"} =
+ ($form->{"${_}_$i"})
+ ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
+ : "";
+ }
+
+ if ($i < $form->{rowcount}) {
+ if ($form->{transfer}) {
+ $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
+ $x = ($checked) ? "x" : "";
+ $fx_transaction = qq|
+ $x |
+ |;
+ }
+ $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
+ $korrektur =
+ qq| | |;
+ $form->hide_form("accno_$i");
+
+ } else {
+ $korrektur =
+ qq| | |;
+ if ($form->{transfer}) {
+ $fx_transaction = qq|
+ |
+ |;
+ }
+ }
+ }
+ my $debitreadonly = "";
+ my $creditreadonly = "";
+ if ($i == $form->{rowcount}) {
+ if ($debitlock) {
+ $debitreadonly = "readonly";
+ } elsif ($creditlock) {
+ $creditreadonly = "readonly";
+ }
+ }
+
+ my $projectnumber =
+ NTI($cgi->popup_menu('-name' => "project_id_$i",
+ '-values' => \@project_values,
+ '-labels' => \%project_labels,
+ '-default' => $form->{"project_id_$i"} ));
+
+ my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
+
+ print qq|
+ $accno
+ $fx_transaction
+ |
+ |
+ |
+ $korrektur
+ $tax|;
+
+ if ($form->{show_details}) {
+ print qq|
+ $source
+ $memo
+ $projectnumber |
+|;
+ }
+ print qq|
+
+|;
+ }
+
+ $form->hide_form(qw(rowcount selectaccno));
+
+ $lxdebug->leave_sub();
+
+}
+
+sub form_header {
+ my ($init) = @_;
+ $lxdebug->enter_sub();
+ $title = $form->{title};
+ $form->{title} = $locale->text("$title General Ledger Transaction");
+ $readonly = ($form->{id}) ? "readonly" : "";
+
+ $show_details_checked = "checked" if $form->{show_details};
+
+ # $locale->text('Add General Ledger Transaction')
+ # $locale->text('Edit General Ledger Transaction')
+
+ map { $form->{$_} =~ s/\"/"/g }
+ qw(reference description chart taxchart);
+
+ $form->{javascript} = qq||;
+ $form->{javascript} .= qq||;
+
+ $form->{selectdepartment} =~ s/ selected//;
+ $form->{selectdepartment} =~
+ s/option>\Q$form->{department}\E/option selected>$form->{department}/;
+
+ if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
+ $description =
+ qq||;
+ } else {
+ $description =
+ qq||;
+ }
+
+ $taxincluded = ($form->{taxincluded}) ? "checked" : "";
+
+ if ($init) {
+ $taxincluded = "checked";
+ }
+
+ $department = qq|
+
+ | . $locale->text('Department') . qq| |
+ |
+
+
+| if $form->{selectdepartment};
+ if ($init) {
+ $form->{fokus} = "gl.reference";
+ } else {
+ $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
+ }
+
+ # use JavaScript Calendar or not
+ $form->{jsscript} = 1;
+ $jsscript = "";
+ if ($form->{jsscript}) {
+
+ # with JavaScript Calendar
+ $button1 = qq|
+
+ text('button') . qq|> |
+ |;
+
+ #write Trigger
+ $jsscript =
+ Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
+ } else {
+
+ # without JavaScript Calendar
+ $button1 =
+ qq| | |;
+ }
+
+ $form->{previous_id} ||= "--";
+ $form->{previous_gldate} ||= "--";
+
+ $form->header;
+
print qq|
|