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 #======================================================================
 
  37 require "bin/mozilla/common.pl";
 
  46   $::lxdebug->enter_sub;
 
  47   $::auth->assert('cash');
 
  49   RC->paymentaccounts(\%::myconfig, $::form);
 
  52   print $::form->parse_html_template('rc/step1', {
 
  53     selection_sub => sub { ("$_[0]{accno}--$_[0]{description}")x2 },
 
  56   $::lxdebug->leave_sub;
 
  59 sub continue { call_sub($::form->{"nextsub"}); }
 
  62   $::lxdebug->enter_sub;
 
  63   $::auth->assert('cash');
 
  65   ($::form->{accno}, $::form->{account}) = split /--/, $::form->{accno};
 
  67   RC->payment_transactions(\%::myconfig, $::form);
 
  71   $::lxdebug->leave_sub;
 
  75   $::lxdebug->enter_sub;
 
  76   $::auth->assert('cash');
 
  79   push @options, $::locale->text('From') . " " . $::locale->date(\%::myconfig, $::form->{fromdate}, 0) if $::form->{fromdate};
 
  80   push @options, $::locale->text('Until') . " " . $::locale->date(\%::myconfig, $::form->{todate}, 0) if $::form->{todate};
 
  82   my $ml = ($::form->{category} eq 'A') ? -1 : 1;
 
  83   my $beginningbalance = $::form->{beginningbalance} * $ml;
 
  85   my $balance          = $beginningbalance;
 
  88   my ($last_fx, @rows, $cleared, $totaldebits, $totalcredits, $fx);
 
  90   for my $ref (@{ $::form->{PR} }) {
 
  91     $balance      += $ref->{amount} * $ml;
 
  92     $cleared      += $ref->{amount} * $ml if $ref->{cleared};
 
  93     $totaldebits  += $ref->{amount} * -1  if $ref->{amount} < 0;
 
  94     $totalcredits += $ref->{amount}       if $ref->{amount} >= 0;
 
  95     $fx           += $ref->{amount} * $ml if $ref->{fx_transaction};
 
  96     $i++                                  if (!$ref->{fx_transaction} && !$last_fx) || $last_id != $ref->{id};
 
  97     $last_fx       = $ref->{fx_transaction};
 
  98     $last_id       = $ref->{id};
 
 100     push @rows, { %$ref, balance => $balance, i => $i };
 
 103   my $statementbalance = $::form->parse_amount(\%::myconfig, $::form->{statementbalance});
 
 104   my $difference       = $statementbalance - $clearedbalance - $cleared;
 
 107   print $::form->parse_html_template('rc/step2', {
 
 108     is_asset         => $::form->{category} eq 'A',
 
 112       credit => $totalcredits,
 
 113       debit  => $totaldebits,
 
 116       beginning => $beginningbalance,
 
 117       cleared   => $clearedbalance,
 
 118       statement => $statementbalance,
 
 120     difference       => $difference,
 
 125   $::lxdebug->leave_sub;
 
 129   $::lxdebug->enter_sub;
 
 130   $::auth->assert('cash');
 
 132   # reset difference as it doesn't always arrive here empty
 
 133   $::form->{difference} = 0;
 
 135   RC->payment_transactions(\%::myconfig, $::form);
 
 138   for my $ref (@{ $::form->{PR} }) {
 
 139     next if $ref->{fx_transaction};
 
 141     $ref->{cleared} = $::form->{"cleared_$i"};
 
 146   $::lxdebug->leave_sub;
 
 150   $::lxdebug->enter_sub;
 
 151   $::auth->assert('cash');
 
 153   $::form->{callback} = "$::form->{script}?action=reconciliation";
 
 155   $::form->error($::locale->text('Out of balance!')) if $::form->{difference} *= 1;
 
 157   RC->reconcile(\%::myconfig, $::form);
 
 160   $::lxdebug->leave_sub;