]> wagnertech.de Git - mfinanz.git/blob - bin/mozilla/rc.pl
restart apache2 in postinst
[mfinanz.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., 51 Franklin Street, Fifth Floor, Boston,
28 # MA 02110-1335, USA.
29 #======================================================================
30 #
31 # Account reconciliation module
32 #
33 #======================================================================
34
35 use SL::RC;
36 use SL::Locale::String qw(t8);
37
38 require "bin/mozilla/common.pl";
39
40 use strict;
41
42 1;
43
44 # end of main
45
46 sub reconciliation {
47   $::lxdebug->enter_sub;
48   $::auth->assert('cash');
49
50   RC->paymentaccounts(\%::myconfig, $::form);
51
52   setup_rc_reconciliation_action_bar();
53
54   $::form->{title} = t8('Reconciliation');
55   $::form->header;
56   print $::form->parse_html_template('rc/step1', {
57     selection_sub => sub { ("$_[0]{accno}--$_[0]{description}")x2 },
58   });
59
60   $::lxdebug->leave_sub;
61 }
62
63 sub get_payments {
64   $::lxdebug->enter_sub;
65   $::auth->assert('cash');
66
67   ($::form->{accno}, $::form->{account}) = split /--/, $::form->{accno};
68
69   RC->payment_transactions(\%::myconfig, $::form);
70
71   display_form();
72
73   $::lxdebug->leave_sub;
74 }
75
76 sub display_form {
77   $::lxdebug->enter_sub;
78   $::auth->assert('cash');
79
80   my @options;
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};
83
84   my $ml = ($::form->{category} eq 'A') ? -1 : 1;
85   my $beginningbalance = $::form->{beginningbalance} * $ml;
86   my $clearedbalance   =
87   my $balance          = $beginningbalance;
88   my $i                = 0;
89   my $last_id          = 0;
90   my ($last_fx, @rows, $cleared, $totaldebits, $totalcredits, $fx);
91
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};
101
102     push @rows, { %$ref, balance => $balance, i => $i };
103   }
104
105   my $statementbalance = $::form->parse_amount(\%::myconfig, $::form->{statementbalance});
106   my $difference       = $statementbalance - $clearedbalance - $cleared;
107
108   setup_rc_display_form_action_bar();
109
110   $::form->header;
111   print $::form->parse_html_template('rc/step2', {
112     is_asset         => $::form->{category} eq 'A',
113     option           => \@options,
114     DATA             => \@rows,
115     total            => {
116       credit => $totalcredits,
117       debit  => $totaldebits,
118     },
119     balance          => {
120       beginning => $beginningbalance,
121       cleared   => $clearedbalance,
122       statement => $statementbalance,
123     },
124     difference       => $difference,
125     rowcount         => $i,
126     fx               => $fx,
127   });
128
129   $::lxdebug->leave_sub;
130 }
131
132 sub update {
133   $::lxdebug->enter_sub;
134   $::auth->assert('cash');
135
136   # reset difference as it doesn't always arrive here empty
137   $::form->{difference} = 0;
138
139   RC->payment_transactions(\%::myconfig, $::form);
140
141   my $i;
142   for my $ref (@{ $::form->{PR} }) {
143     next if $ref->{fx_transaction};
144     $i++;
145     $ref->{cleared} = $::form->{"cleared_$i"};
146   }
147
148   display_form();
149
150   $::lxdebug->leave_sub;
151 }
152
153 sub reconcile {
154   $::lxdebug->enter_sub;
155   $::auth->assert('cash');
156
157   $::form->{callback} = "$::form->{script}?action=reconciliation";
158
159   $::form->error($::locale->text('Out of balance!')) if $::form->{difference} *= 1;
160
161   RC->reconcile(\%::myconfig, $::form);
162   $::form->redirect;
163
164   $::lxdebug->leave_sub;
165 }
166
167 sub setup_rc_reconciliation_action_bar {
168   my %params = @_;
169
170   for my $bar ($::request->layout->get('actionbar')) {
171     $bar->add(
172       action => [
173         t8('Show'),
174         submit    => [ '#form', { action => "get_payments" } ],
175         accesskey => 'enter',
176       ],
177     );
178   }
179 }
180
181 sub setup_rc_display_form_action_bar {
182   my %params = @_;
183
184   for my $bar ($::request->layout->get('actionbar')) {
185     $bar->add(
186       action => [
187         t8('Update'),
188         submit    => [ '#form', { action => "update" } ],
189         accesskey => 'enter',
190       ],
191       action => [
192         t8('Reconcile'),
193         submit => [ '#form', { action => "reconcile" } ],
194       ],
195     );
196   }
197 }