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($main::form->{"nextsub"}); }
61 $main::lxdebug->enter_sub();
63 my $form = $main::form;
64 my %myconfig = %main::myconfig;
66 $main::auth->assert('cash');
68 ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
70 RC->payment_transactions(\%myconfig, \%$form);
74 $main::lxdebug->leave_sub();
78 $::lxdebug->enter_sub;
79 $::auth->assert('cash');
82 push @options, $::locale->text('From') . " " . $::locale->date(\%::myconfig, $::form->{fromdate}, 0) if $::form->{fromdate};
83 push @options, $::locale->text('Until') . " " . $::locale->date(\%::myconfig, $::form->{todate}, 0) if $::form->{todate};
85 my $ml = ($::form->{category} eq 'A') ? -1 : 1;
86 my $beginningbalance = $::form->{beginningbalance} * $ml;
88 my $balance = $beginningbalance;
91 my ($last_fx, @rows, $cleared, $totaldebits, $totalcredits, $fx);
93 for my $ref (@{ $::form->{PR} }) {
94 $balance += $ref->{amount} * $ml;
95 $cleared += $ref->{amount} * $ml if $ref->{cleared};
96 $totaldebits += $ref->{amount} * -1 if $ref->{amount} < 0;
97 $totalcredits += $ref->{amount} if $ref->{amount} >= 0;
98 $fx += $ref->{amount} * $ml if $ref->{fx_transaction};
99 $i++ if (!$ref->{fx_transaction} && !$last_fx) || $last_id != $ref->{id};
100 $last_fx = $ref->{fx_transaction};
101 $last_id = $ref->{id};
103 push @rows, { %$ref, balance => $balance, i => $i };
106 my $statementbalance = $::form->parse_amount(\%::myconfig, $::form->{statementbalance});
107 my $difference = $statementbalance - $clearedbalance - $cleared;
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 $main::lxdebug->enter_sub();
134 my $form = $main::form;
135 my %myconfig = %main::myconfig;
137 $main::auth->assert('cash');
139 RC->payment_transactions(\%myconfig, \%$form);
142 foreach my $ref (@{ $form->{PR} }) {
143 if (!$ref->{fx_transaction}) {
145 $ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : "";
151 $main::lxdebug->leave_sub();
155 $main::lxdebug->enter_sub();
157 my $form = $main::form;
158 my %myconfig = %main::myconfig;
160 $main::auth->assert('cash');
162 RC->payment_transactions(\%myconfig, \%$form);
164 map { $_->{cleared} = "checked" unless $_->{fx_transaction} }
169 $main::lxdebug->leave_sub();
173 $main::lxdebug->enter_sub();
175 my $form = $main::form;
176 my %myconfig = %main::myconfig;
177 my $locale = $main::locale;
179 $main::auth->assert('cash');
181 $form->{callback} = "$form->{script}?action=reconciliation";
183 $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
185 RC->reconcile(\%myconfig, \%$form);
188 $main::lxdebug->leave_sub();