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();
54 $::form->{title} = t8('Reconciliation');
56 print $::form->parse_html_template('rc/step1', {
57 selection_sub => sub { ("$_[0]{accno}--$_[0]{description}")x2 },
60 $::lxdebug->leave_sub;
64 $::lxdebug->enter_sub;
65 $::auth->assert('cash');
67 ($::form->{accno}, $::form->{account}) = split /--/, $::form->{accno};
69 RC->payment_transactions(\%::myconfig, $::form);
73 $::lxdebug->leave_sub;
77 $::lxdebug->enter_sub;
78 $::auth->assert('cash');
81 push @options, $::locale->text('From') . " " . $::locale->date(\%::myconfig, $::form->{fromdate}, 0) if $::form->{fromdate};
82 push @options, $::locale->text('Until') . " " . $::locale->date(\%::myconfig, $::form->{todate}, 0) if $::form->{todate};
84 my $ml = ($::form->{category} eq 'A') ? -1 : 1;
85 my $beginningbalance = $::form->{beginningbalance} * $ml;
87 my $balance = $beginningbalance;
90 my ($last_fx, @rows, $cleared, $totaldebits, $totalcredits, $fx);
92 for my $ref (@{ $::form->{PR} }) {
93 $balance += $ref->{amount} * $ml;
94 $cleared += $ref->{amount} * $ml if $ref->{cleared};
95 $totaldebits += $ref->{amount} * -1 if $ref->{amount} < 0;
96 $totalcredits += $ref->{amount} if $ref->{amount} >= 0;
97 $fx += $ref->{amount} * $ml if $ref->{fx_transaction};
98 $i++ if (!$ref->{fx_transaction} && !$last_fx) || $last_id != $ref->{id};
99 $last_fx = $ref->{fx_transaction};
100 $last_id = $ref->{id};
102 push @rows, { %$ref, balance => $balance, i => $i };
105 my $statementbalance = $::form->parse_amount(\%::myconfig, $::form->{statementbalance});
106 my $difference = $statementbalance - $clearedbalance - $cleared;
108 setup_rc_display_form_action_bar();
111 print $::form->parse_html_template('rc/step2', {
112 is_asset => $::form->{category} eq 'A',
116 credit => $totalcredits,
117 debit => $totaldebits,
120 beginning => $beginningbalance,
121 cleared => $clearedbalance,
122 statement => $statementbalance,
124 difference => $difference,
129 $::lxdebug->leave_sub;
133 $::lxdebug->enter_sub;
134 $::auth->assert('cash');
136 # reset difference as it doesn't always arrive here empty
137 $::form->{difference} = 0;
139 RC->payment_transactions(\%::myconfig, $::form);
142 for my $ref (@{ $::form->{PR} }) {
143 next if $ref->{fx_transaction};
145 $ref->{cleared} = $::form->{"cleared_$i"};
150 $::lxdebug->leave_sub;
154 $::lxdebug->enter_sub;
155 $::auth->assert('cash');
157 $::form->{callback} = "$::form->{script}?action=reconciliation";
159 $::form->error($::locale->text('Out of balance!')) if $::form->{difference} *= 1;
161 RC->reconcile(\%::myconfig, $::form);
164 $::lxdebug->leave_sub;
167 sub setup_rc_reconciliation_action_bar {
170 for my $bar ($::request->layout->get('actionbar')) {
174 submit => [ '#form', { action => "get_payments" } ],
175 accesskey => 'enter',
181 sub setup_rc_display_form_action_bar {
184 for my $bar ($::request->layout->get('actionbar')) {
188 submit => [ '#form', { action => "update" } ],
189 accesskey => 'enter',
193 submit => [ '#form', { action => "reconcile" } ],