1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  16 # This program is free software; you can redistribute it and/or modify
 
  17 # it under the terms of the GNU General Public License as published by
 
  18 # the Free Software Foundation; either version 2 of the License, or
 
  19 # (at your option) any later version.
 
  21 # This program is distributed in the hope that it will be useful,
 
  22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  24 # GNU General Public License for more details.
 
  25 # You should have received a copy of the GNU General Public License
 
  26 # along with this program; if not, write to the Free Software
 
  27 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
  29 #======================================================================
 
  31 # Account reconciliation module
 
  33 #======================================================================
 
  36 use SL::Locale::String qw(t8);
 
  38 require "bin/mozilla/common.pl";
 
  47   $::lxdebug->enter_sub;
 
  48   $::auth->assert('cash');
 
  50   RC->paymentaccounts(\%::myconfig, $::form);
 
  52   setup_rc_reconciliation_action_bar();
 
  55   print $::form->parse_html_template('rc/step1', {
 
  56     selection_sub => sub { ("$_[0]{accno}--$_[0]{description}")x2 },
 
  59   $::lxdebug->leave_sub;
 
  63   $::lxdebug->enter_sub;
 
  64   $::auth->assert('cash');
 
  66   ($::form->{accno}, $::form->{account}) = split /--/, $::form->{accno};
 
  68   RC->payment_transactions(\%::myconfig, $::form);
 
  72   $::lxdebug->leave_sub;
 
  76   $::lxdebug->enter_sub;
 
  77   $::auth->assert('cash');
 
  80   push @options, $::locale->text('From') . " " . $::locale->date(\%::myconfig, $::form->{fromdate}, 0) if $::form->{fromdate};
 
  81   push @options, $::locale->text('Until') . " " . $::locale->date(\%::myconfig, $::form->{todate}, 0) if $::form->{todate};
 
  83   my $ml = ($::form->{category} eq 'A') ? -1 : 1;
 
  84   my $beginningbalance = $::form->{beginningbalance} * $ml;
 
  86   my $balance          = $beginningbalance;
 
  89   my ($last_fx, @rows, $cleared, $totaldebits, $totalcredits, $fx);
 
  91   for my $ref (@{ $::form->{PR} }) {
 
  92     $balance      += $ref->{amount} * $ml;
 
  93     $cleared      += $ref->{amount} * $ml if $ref->{cleared};
 
  94     $totaldebits  += $ref->{amount} * -1  if $ref->{amount} < 0;
 
  95     $totalcredits += $ref->{amount}       if $ref->{amount} >= 0;
 
  96     $fx           += $ref->{amount} * $ml if $ref->{fx_transaction};
 
  97     $i++                                  if (!$ref->{fx_transaction} && !$last_fx) || $last_id != $ref->{id};
 
  98     $last_fx       = $ref->{fx_transaction};
 
  99     $last_id       = $ref->{id};
 
 101     push @rows, { %$ref, balance => $balance, i => $i };
 
 104   my $statementbalance = $::form->parse_amount(\%::myconfig, $::form->{statementbalance});
 
 105   my $difference       = $statementbalance - $clearedbalance - $cleared;
 
 107   setup_rc_display_form_action_bar();
 
 110   print $::form->parse_html_template('rc/step2', {
 
 111     is_asset         => $::form->{category} eq 'A',
 
 115       credit => $totalcredits,
 
 116       debit  => $totaldebits,
 
 119       beginning => $beginningbalance,
 
 120       cleared   => $clearedbalance,
 
 121       statement => $statementbalance,
 
 123     difference       => $difference,
 
 128   $::lxdebug->leave_sub;
 
 132   $::lxdebug->enter_sub;
 
 133   $::auth->assert('cash');
 
 135   # reset difference as it doesn't always arrive here empty
 
 136   $::form->{difference} = 0;
 
 138   RC->payment_transactions(\%::myconfig, $::form);
 
 141   for my $ref (@{ $::form->{PR} }) {
 
 142     next if $ref->{fx_transaction};
 
 144     $ref->{cleared} = $::form->{"cleared_$i"};
 
 149   $::lxdebug->leave_sub;
 
 153   $::lxdebug->enter_sub;
 
 154   $::auth->assert('cash');
 
 156   $::form->{callback} = "$::form->{script}?action=reconciliation";
 
 158   $::form->error($::locale->text('Out of balance!')) if $::form->{difference} *= 1;
 
 160   RC->reconcile(\%::myconfig, $::form);
 
 163   $::lxdebug->leave_sub;
 
 166 sub setup_rc_reconciliation_action_bar {
 
 169   for my $bar ($::request->layout->get('actionbar')) {
 
 173         submit    => [ '#form', { action => "get_payments" } ],
 
 174         accesskey => 'enter',
 
 180 sub setup_rc_display_form_action_bar {
 
 183   for my $bar ($::request->layout->get('actionbar')) {
 
 187         submit    => [ '#form', { action => "update" } ],
 
 188         accesskey => 'enter',
 
 192         submit => [ '#form', { action => "reconcile" } ],