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., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  28 #======================================================================
 
  30 # Account reconciliation module
 
  32 #======================================================================
 
  36 require "bin/mozilla/common.pl";
 
  45   $::lxdebug->enter_sub;
 
  46   $::auth->assert('cash');
 
  48   RC->paymentaccounts(\%::myconfig, $::form);
 
  51   print $::form->parse_html_template('rc/step1', {
 
  52     selection_sub => sub { ("$_[0]{accno}--$_[0]{description}")x2 },
 
  55   $::lxdebug->leave_sub;
 
  58 sub continue { call_sub($::form->{"nextsub"}); }
 
  61   $::lxdebug->enter_sub;
 
  62   $::auth->assert('cash');
 
  64   ($::form->{accno}, $::form->{account}) = split /--/, $::form->{accno};
 
  66   RC->payment_transactions(\%::myconfig, $::form);
 
  70   $::lxdebug->leave_sub;
 
  74   $::lxdebug->enter_sub;
 
  75   $::auth->assert('cash');
 
  78   push @options, $::locale->text('From') . " " . $::locale->date(\%::myconfig, $::form->{fromdate}, 0) if $::form->{fromdate};
 
  79   push @options, $::locale->text('Until') . " " . $::locale->date(\%::myconfig, $::form->{todate}, 0) if $::form->{todate};
 
  81   my $ml = ($::form->{category} eq 'A') ? -1 : 1;
 
  82   my $beginningbalance = $::form->{beginningbalance} * $ml;
 
  84   my $balance          = $beginningbalance;
 
  87   my ($last_fx, @rows, $cleared, $totaldebits, $totalcredits, $fx);
 
  89   for my $ref (@{ $::form->{PR} }) {
 
  90     $balance      += $ref->{amount} * $ml;
 
  91     $cleared      += $ref->{amount} * $ml if $ref->{cleared};
 
  92     $totaldebits  += $ref->{amount} * -1  if $ref->{amount} < 0;
 
  93     $totalcredits += $ref->{amount}       if $ref->{amount} >= 0;
 
  94     $fx           += $ref->{amount} * $ml if $ref->{fx_transaction};
 
  95     $i++                                  if (!$ref->{fx_transaction} && !$last_fx) || $last_id != $ref->{id};
 
  96     $last_fx       = $ref->{fx_transaction};
 
  97     $last_id       = $ref->{id};
 
  99     push @rows, { %$ref, balance => $balance, i => $i };
 
 102   my $statementbalance = $::form->parse_amount(\%::myconfig, $::form->{statementbalance});
 
 103   my $difference       = $statementbalance - $clearedbalance - $cleared;
 
 106   print $::form->parse_html_template('rc/step2', {
 
 107     is_asset         => $::form->{category} eq 'A',
 
 111       credit => $totalcredits,
 
 112       debit  => $totaldebits,
 
 115       beginning => $beginningbalance,
 
 116       cleared   => $clearedbalance,
 
 117       statement => $statementbalance,
 
 119     difference       => $difference,
 
 124   $::lxdebug->leave_sub;
 
 128   $::lxdebug->enter_sub;
 
 129   $::auth->assert('cash');
 
 131   RC->payment_transactions(\%::myconfig, $::form);
 
 134   for my $ref (@{ $::form->{PR} }) {
 
 135     next if $ref->{fx_transaction};
 
 137     $ref->{cleared} = $::form->{"cleared_$i"};
 
 142   $::lxdebug->leave_sub;
 
 146   $::lxdebug->enter_sub;
 
 147   $::auth->assert('cash');
 
 149   $::form->{callback} = "$::form->{script}?action=reconciliation";
 
 151   $::form->error($::locale->text('Out of balance!')) if $::form->{difference} *= 1;
 
 153   RC->reconcile(\%::myconfig, $::form);
 
 156   $::lxdebug->leave_sub;