X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Frc.pl;h=f0ef98e732687c5a062f376cd0b60600869abf3a;hb=65b2387a54494a8cbc1d011602ae3f8d7208ea4d;hp=b36f6e381de7aa950cb99b761fd4a3d910c8e60f;hpb=b390c3884452b45898a4e8ff4624ac36e20fe943;p=kivitendo-erp.git diff --git a/bin/mozilla/rc.pl b/bin/mozilla/rc.pl index b36f6e381..f0ef98e73 100644 --- a/bin/mozilla/rc.pl +++ b/bin/mozilla/rc.pl @@ -24,7 +24,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Account reconciliation module @@ -32,6 +33,7 @@ #====================================================================== use SL::RC; +use SL::Locale::String qw(t8); require "bin/mozilla/common.pl"; @@ -47,6 +49,8 @@ sub reconciliation { RC->paymentaccounts(\%::myconfig, $::form); + setup_rc_reconciliation_action_bar(); + $::form->header; print $::form->parse_html_template('rc/step1', { selection_sub => sub { ("$_[0]{accno}--$_[0]{description}")x2 }, @@ -55,357 +59,138 @@ sub reconciliation { $::lxdebug->leave_sub; } -sub continue { call_sub($main::form->{"nextsub"}); } - sub get_payments { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - - $main::auth->assert('cash'); + $::lxdebug->enter_sub; + $::auth->assert('cash'); - ($form->{accno}, $form->{account}) = split /--/, $form->{accno}; + ($::form->{accno}, $::form->{account}) = split /--/, $::form->{accno}; - RC->payment_transactions(\%myconfig, \%$form); + RC->payment_transactions(\%::myconfig, $::form); - &display_form; + display_form(); - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } 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') . ""; + $::lxdebug->enter_sub; + $::auth->assert('cash'); - 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); + 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 }; } - $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| - -|; + my $statementbalance = $::form->parse_amount(\%::myconfig, $::form->{statementbalance}); + my $difference = $statementbalance - $clearedbalance - $cleared; - } + setup_rc_display_form_action_bar(); - # 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| - - - -|; - } + $::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, + }); - 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}> - -
- - - - -
- - - -|; - - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub update { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; + $::lxdebug->enter_sub; + $::auth->assert('cash'); - $main::auth->assert('cash'); + # reset difference as it doesn't always arrive here empty + $::form->{difference} = 0; - RC->payment_transactions(\%myconfig, \%$form); + RC->payment_transactions(\%::myconfig, $::form); my $i; - foreach my $ref (@{ $form->{PR} }) { - if (!$ref->{fx_transaction}) { - $i++; - $ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : ""; - } + for my $ref (@{ $::form->{PR} }) { + next if $ref->{fx_transaction}; + $i++; + $ref->{cleared} = $::form->{"cleared_$i"}; } - &display_form; + display_form(); - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } -sub select_all { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - - $main::auth->assert('cash'); +sub reconcile { + $::lxdebug->enter_sub; + $::auth->assert('cash'); - RC->payment_transactions(\%myconfig, \%$form); + $::form->{callback} = "$::form->{script}?action=reconciliation"; - map { $_->{cleared} = "checked" unless $_->{fx_transaction} } - @{ $form->{PR} }; + $::form->error($::locale->text('Out of balance!')) if $::form->{difference} *= 1; - &display_form; + RC->reconcile(\%::myconfig, $::form); + $::form->redirect; - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } -sub done { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $main::auth->assert('cash'); - - $form->{callback} = "$form->{script}?action=reconciliation"; - - $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1); - - RC->reconcile(\%myconfig, \%$form); - $form->redirect; - - $main::lxdebug->leave_sub(); +sub setup_rc_reconciliation_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Show'), + submit => [ '#form', { action => "get_payments" } ], + accesskey => 'enter', + ], + ); + } } +sub setup_rc_display_form_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Update'), + submit => [ '#form', { action => "update" } ], + accesskey => 'enter', + ], + action => [ + t8('Reconcile'), + submit => [ '#form', { action => "reconcile" } ], + ], + ); + } +}