From da6943d46ec5b1aee6e69f928ac6f1417166e5ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 20 Sep 2011 11:38:06 +0200 Subject: [PATCH] rc.pl display_form in template ausgelagert. Warnung: Muss nochmal gut durchgetestet werden. --- bin/mozilla/rc.pl | 313 +++++-------------------------- templates/webpages/rc/step2.html | 120 ++++++++++++ 2 files changed, 166 insertions(+), 267 deletions(-) create mode 100644 templates/webpages/rc/step2.html diff --git a/bin/mozilla/rc.pl b/bin/mozilla/rc.pl index b36f6e381..e07829528 100644 --- a/bin/mozilla/rc.pl +++ b/bin/mozilla/rc.pl @@ -75,278 +75,57 @@ sub get_payments { } sub display_form { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $main::auth->assert('cash'); - - my @column_index = qw(cleared transdate source name credit debit balance); - my %column_header; - $column_header{cleared} = " "; - $column_header{source} = - "" . $locale->text('Source') . ""; - $column_header{name} = - "" . $locale->text('Description') . ""; - $column_header{transdate} = - "" . $locale->text('Date') . ""; - - if ($form->{category} eq 'A') { - $column_header{debit} = - "" . $locale->text('Deposit') . ""; - $column_header{credit} = - "" . $locale->text('Payment') . ""; - } else { - $column_header{debit} = - "" . $locale->text('Decrease') . ""; - $column_header{credit} = - "" . $locale->text('Increase') . ""; - } - - $column_header{balance} = - "" . $locale->text('Balance') . ""; - - my $option; - if ($form->{fromdate}) { - $option .= "\n
" if ($option); - $option .= - $locale->text('From') . " " - . $locale->date(\%myconfig, $form->{fromdate}, 0); - } - if ($form->{todate}) { - $option .= "\n
" if ($option); - $option .= - $locale->text('Until') . " " - . $locale->date(\%myconfig, $form->{todate}, 0); - } - - $form->{title} = "$form->{accno}--$form->{account}"; - - $form->header; - - print qq| - - -
{script}> - - - - - - - - - - - - - - - - - - -
$form->{title}
$option
- - -|; - - map { print "\n$column_header{$_}" } @column_index; - - print qq| - -|; - - my $ml = ($form->{category} eq 'A') ? -1 : 1; - $form->{beginningbalance} *= $ml; - my $balance = $form->{beginningbalance}; - my $clearedbalance = $balance; - my $i = 0; - my $id = 0; - - my %column_data; - map { $column_data{$_} = "" } - qw(cleared transdate source name debit credit); - $column_data{balance} = - ""; - my $j = 0; - print qq| - -|; - - map { print "\n$column_data{$_}" } @column_index; - - print qq| - -|; - - my $cleared; - my $totaldebits; - my $totalcredits; - my $fx_transaction; - my $fx; - foreach my $ref (@{ $form->{PR} }) { - - $balance += $ref->{amount} * $ml; - $cleared += $ref->{amount} * $ml if $ref->{cleared}; - - $column_data{name} = ""; - $column_data{source} = qq||; - $column_data{transdate} = ""; - - $column_data{debit} = ""; - $column_data{credit} = ""; - - if ($ref->{amount} < 0) { - $totaldebits += $ref->{amount} * -1; - $column_data{debit} = - ""; - } else { - $totalcredits += $ref->{amount}; - $column_data{credit} = - ""; - } - - $column_data{balance} = - ""; - - if ($ref->{fx_transaction}) { - $i++ unless $id == $ref->{id}; - $fx_transaction = 1; - $fx += $ref->{amount} * $ml; - $column_data{cleared} = qq||; - } else { - $i++ unless ($fx_transaction && $id == $ref->{id}); - $fx_transaction = 0; - $column_data{cleared} = qq||; - } - $id = $ref->{id}; - - $j++; - $j %= 2; - print qq| - -|; - - map { print "\n$column_data{$_}" } @column_index; - - print qq| - -|; + $::lxdebug->enter_sub; + $::auth->assert('cash'); + my @options; + push @options, $::locale->text('From') . " " . $::locale->date(\%::myconfig, $::form->{fromdate}, 0) if $::form->{fromdate}; + push @options, $::locale->text('Until') . " " . $::locale->date(\%::myconfig, $::form->{todate}, 0) if $::form->{todate}; + + my $ml = ($::form->{category} eq 'A') ? -1 : 1; + my $beginningbalance = $::form->{beginningbalance} * $ml; + my $clearedbalance = + my $balance = $beginningbalance; + my $i = 0; + my $last_id = 0; + my ($last_fx, @rows, $cleared, $totaldebits, $totalcredits, $fx); + + for my $ref (@{ $::form->{PR} }) { + $balance += $ref->{amount} * $ml; + $cleared += $ref->{amount} * $ml if $ref->{cleared}; + $totaldebits += $ref->{amount} * -1 if $ref->{amount} < 0; + $totalcredits += $ref->{amount} if $ref->{amount} >= 0; + $fx += $ref->{amount} * $ml if $ref->{fx_transaction}; + $i++ if (!$ref->{fx_transaction} && !$last_fx) || $last_id != $ref->{id}; + $last_fx = $ref->{fx_transaction}; + $last_id = $ref->{id}; + + push @rows, { %$ref, balance => $balance, i => $i }; } - # print totals - map { $column_data{$_} = "" } @column_index; - - $column_data{debit} = - ""; - $column_data{credit} = - ""; - - print qq| - -|; - - map { print "\n$column_data{$_}" } @column_index; - - $form->{statementbalance} = - $form->parse_amount(\%myconfig, $form->{statementbalance}); - my $difference = - $form->format_amount(\%myconfig, - $form->{statementbalance} - $clearedbalance - $cleared, - 2, 0); - - $form->{statementbalance} = - $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0); - - $clearedbalance = $form->format_amount(\%myconfig, $clearedbalance, 2, 0); - - my $exchdiff; - if ($fx) { - $fx = $form->format_amount(\%myconfig, $fx, 2, 0); - $exchdiff = qq| - - - -|; - } + my $statementbalance = $::form->parse_amount(\%::myconfig, $::form->{statementbalance}); + my $difference = $statementbalance - $clearedbalance - $cleared; - print qq| - -
 " - . $form->format_amount(\%myconfig, $balance, 2, 0) . "
$ref->{name} $ref->{source}  - $ref->{transdate}   " - . $form->format_amount(\%myconfig, $ref->{amount} * -1, 2, " ") - . "" - . $form->format_amount(\%myconfig, $ref->{amount}, 2, " ") - . "" - . $form->format_amount(\%myconfig, $balance, 2, 0) . "  - {oid}> - - {cleared}> - {oid}> -
 " - . $form->format_amount(\%myconfig, $totaldebits, 2, " ") . "" - . $form->format_amount(\%myconfig, $totalcredits, 2, " ") . "
| . $locale->text('Exchangerate Difference') . qq|$fx
-
- - - - - -
- - - - - - - - $exchdiff - -
| . $locale->text('Cleared Balance') . qq|$clearedbalance
-
- - - - - - - - - - - - -
| . $locale->text('Statement Balance') . qq|{statementbalance}>
| . $locale->text('Difference') . qq|
-
-

- - -{accno}> - - -{fromdate}> -{todate}> - -
- - - - -
- - - -|; + $::form->header; + print $::form->parse_html_template('rc/step2', { + is_asset => $::form->{category} eq 'A', + option => \@options, + DATA => \@rows, + total => { + credit => $totalcredits, + debit => $totaldebits, + }, + balance => { + beginning => $beginningbalance, + cleared => $clearedbalance, + statement => $statementbalance, + }, + difference => $difference, + rowcount => $i, + fx => $fx, + }); - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub update { diff --git a/templates/webpages/rc/step2.html b/templates/webpages/rc/step2.html new file mode 100644 index 000000000..75ec83cae --- /dev/null +++ b/templates/webpages/rc/step2.html @@ -0,0 +1,120 @@ +[%- USE HTML %] +[%- USE L %] +[%- USE T8 %] +[%- USE LxERP %] + + +

[% accno | html %]--[% account | html %]

+ +

[% FOREACH row IN option %][% row %][% ', ' UNLESS loop.last %][% END %]

+ +
+ + + + + + + +[%- IF is_asset %] + + +[%- ELSE %] + + +[%- END %] + + + + + + + + + + + +[% FOREACH row = DATA %] + + + + + + + + + +[% END %] + + + + + + + + + +
 [% 'Date' | $T8 %][% 'Source' | $T8 %][% 'Description' | $T8 %][% 'Deposit' | $T8 %][% 'Payment' | $T8 %][% 'Decrease' | $T8 %][% 'Increase' | $T8 %][% 'Balance' | $T8 %]
[% LxERP.format_amount(balance.beginning, 2, 0) %]
+[%- IF row.fx_transaction %] + [% L.hidden_tag('fxoid_' _ row.i, row.oid) %] +[%- ELSE %] + [% L.checkbox_tag('cleared_' _ row.i, checked=row.cleared) %] + [% L.hidden_tag('oid_' _ row.i, row.oid) %] +[%- END %] + [% row.transdate %][% row.source %][% row.name %][% LxERP.format_amount(row.amount, 2) IF row.amount > 0 %][% LxERP.format_amount(row.amount * -1, 2) IF row.amount < 0 %][% LxERP.format_amount(row.balance, 2, 0) %]
[% LxERP.format_amount(total.credit, 2, 0) %][% LxERP.format_amount(total.debit, 2, 0) %]
+ + + + + + +
+ + + + + + + +[%- IF fx %] + + + +[%- END %] + +
[% 'Cleared Balance' | $T8 %][% LxERP.format_amount(balance.cleared, 2, 0) %]
[% 'Exchangerate Difference' | $T8 %][% LxERP.format_amount(fx, 2, 0) %]
+
+ + + + + + + + + + + + +
[% 'Statement Balance' | $T8 %]
[% 'Difference' | $T8 %]
+
+ +
+
+ + + + + + + + +
+ + + + +
+ + + -- 2.20.1