]> wagnertech.de Git - kivitendo-erp.git/blob - bin/mozilla/rc.pl
rc.pl display_form in template ausgelagert.
[kivitendo-erp.git] / bin / mozilla / rc.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
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.
20 #
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 #======================================================================
29 #
30 # Account reconciliation module
31 #
32 #======================================================================
33
34 use SL::RC;
35
36 require "bin/mozilla/common.pl";
37
38 use strict;
39
40 1;
41
42 # end of main
43
44 sub reconciliation {
45   $::lxdebug->enter_sub;
46   $::auth->assert('cash');
47
48   RC->paymentaccounts(\%::myconfig, $::form);
49
50   $::form->header;
51   print $::form->parse_html_template('rc/step1', {
52     selection_sub => sub { ("$_[0]{accno}--$_[0]{description}")x2 },
53   });
54
55   $::lxdebug->leave_sub;
56 }
57
58 sub continue { call_sub($main::form->{"nextsub"}); }
59
60 sub get_payments {
61   $main::lxdebug->enter_sub();
62
63   my $form     = $main::form;
64   my %myconfig = %main::myconfig;
65
66   $main::auth->assert('cash');
67
68   ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
69
70   RC->payment_transactions(\%myconfig, \%$form);
71
72   &display_form;
73
74   $main::lxdebug->leave_sub();
75 }
76
77 sub display_form {
78   $::lxdebug->enter_sub;
79   $::auth->assert('cash');
80
81   my @options;
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};
84
85   my $ml = ($::form->{category} eq 'A') ? -1 : 1;
86   my $beginningbalance = $::form->{beginningbalance} * $ml;
87   my $clearedbalance   =
88   my $balance          = $beginningbalance;
89   my $i                = 0;
90   my $last_id          = 0;
91   my ($last_fx, @rows, $cleared, $totaldebits, $totalcredits, $fx);
92
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};
102
103     push @rows, { %$ref, balance => $balance, i => $i };
104   }
105
106   my $statementbalance = $::form->parse_amount(\%::myconfig, $::form->{statementbalance});
107   my $difference       = $statementbalance - $clearedbalance - $cleared;
108
109   $::form->header;
110   print $::form->parse_html_template('rc/step2', {
111     is_asset         => $::form->{category} eq 'A',
112     option           => \@options,
113     DATA             => \@rows,
114     total            => {
115       credit => $totalcredits,
116       debit  => $totaldebits,
117     },
118     balance          => {
119       beginning => $beginningbalance,
120       cleared   => $clearedbalance,
121       statement => $statementbalance,
122     },
123     difference       => $difference,
124     rowcount         => $i,
125     fx               => $fx,
126   });
127
128   $::lxdebug->leave_sub;
129 }
130
131 sub update {
132   $main::lxdebug->enter_sub();
133
134   my $form     = $main::form;
135   my %myconfig = %main::myconfig;
136
137   $main::auth->assert('cash');
138
139   RC->payment_transactions(\%myconfig, \%$form);
140
141   my $i;
142   foreach my $ref (@{ $form->{PR} }) {
143     if (!$ref->{fx_transaction}) {
144       $i++;
145       $ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : "";
146     }
147   }
148
149   &display_form;
150
151   $main::lxdebug->leave_sub();
152 }
153
154 sub select_all {
155   $main::lxdebug->enter_sub();
156
157   my $form     = $main::form;
158   my %myconfig = %main::myconfig;
159
160   $main::auth->assert('cash');
161
162   RC->payment_transactions(\%myconfig, \%$form);
163
164   map { $_->{cleared} = "checked" unless $_->{fx_transaction} }
165     @{ $form->{PR} };
166
167   &display_form;
168
169   $main::lxdebug->leave_sub();
170 }
171
172 sub done {
173   $main::lxdebug->enter_sub();
174
175   my $form     = $main::form;
176   my %myconfig = %main::myconfig;
177   my $locale   = $main::locale;
178
179   $main::auth->assert('cash');
180
181   $form->{callback} = "$form->{script}?action=reconciliation";
182
183   $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
184
185   RC->reconcile(\%myconfig, \%$form);
186   $form->redirect;
187
188   $main::lxdebug->leave_sub();
189 }
190