Alle Dateien durch Perltidy laufen lassen. Die verwendeten Optionen sind am Ende...
[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 1;
37
38 # end of main
39
40 sub reconciliation {
41   $lxdebug->enter_sub();
42
43   RC->paymentaccounts(\%myconfig, \%$form);
44
45   $selection = "";
46   map { $selection .= "<option>$_->{accno}--$_->{description}\n" }
47     @{ $form->{PR} };
48
49   $form->{title} = $locale->text('Reconciliation');
50
51   $form->header;
52
53   print qq|
54 <body>
55
56 <form method=post action=$form->{script}>
57
58 <table width=100%>
59   <tr>
60     <th class=listtop>$form->{title}</th>
61   </tr>
62   <tr height="5"></tr>
63   <tr>
64     <td>
65       <table>
66         <tr>
67           <th align=right nowrap>| . $locale->text('Account') . qq|</th>
68           <td colspan=3><select name=accno>$selection</select>
69           </td>
70         </tr>
71         <tr>
72           <th align=right>| . $locale->text('From') . qq|</th>
73           <td><input name=fromdate size=11 title="$myconfig{dateformat}"></td>
74           <th align=right>| . $locale->text('To') . qq|</th>
75           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
76         </tr>
77       </table>
78     </td>
79   </tr>
80   <tr>
81     <td><hr size=3 noshade></td>
82   </tr>
83 </table>
84
85 <br>
86 <input type=hidden name=nextsub value=get_payments>
87
88 <input type=hidden name=path value=$form->{path}>
89 <input type=hidden name=login value=$form->{login}>
90 <input type=hidden name=password value=$form->{password}>
91
92 <input type=submit class=submit name=action value="|
93     . $locale->text('Continue') . qq|">
94
95 </form>
96
97 </body>
98 </html>
99 |;
100
101   $lxdebug->leave_sub();
102 }
103
104 sub continue { &{ $form->{nextsub} } }
105
106 sub get_payments {
107   $lxdebug->enter_sub();
108
109   ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
110
111   RC->payment_transactions(\%myconfig, \%$form);
112
113   &display_form;
114
115   $lxdebug->leave_sub();
116 }
117
118 sub display_form {
119   $lxdebug->enter_sub();
120
121   @column_index = qw(cleared transdate source name credit debit balance);
122
123   $column_header{cleared} = "<th>&nbsp;</th>";
124   $column_header{source}  =
125     "<th class=listheading>" . $locale->text('Source') . "</a></th>";
126   $column_header{name} =
127     "<th class=listheading>" . $locale->text('Description') . "</a></th>";
128   $column_header{transdate} =
129     "<th class=listheading>" . $locale->text('Date') . "</a></th>";
130
131   if ($form->{category} eq 'A') {
132     $column_header{debit} =
133       "<th class=listheading>" . $locale->text('Deposit') . "</a></th>";
134     $column_header{credit} =
135       "<th class=listheading>" . $locale->text('Payment') . "</a></th>";
136   } else {
137     $column_header{debit} =
138       "<th class=listheading>" . $locale->text('Decrease') . "</a></th>";
139     $column_header{credit} =
140       "<th class=listheading>" . $locale->text('Increase') . "</a></th>";
141   }
142
143   $column_header{balance} =
144     "<th class=listheading>" . $locale->text('Balance') . "</a></th>";
145
146   if ($form->{fromdate}) {
147     $option .= "\n<br>" if ($option);
148     $option .=
149         $locale->text('From') . "&nbsp;"
150       . $locale->date(\%myconfig, $form->{fromdate}, 1);
151   }
152   if ($form->{todate}) {
153     $option .= "\n<br>" if ($option);
154     $option .=
155         $locale->text('To') . "&nbsp;"
156       . $locale->date(\%myconfig, $form->{todate}, 1);
157   }
158
159   $form->{title} = "$form->{accno}--$form->{account}";
160
161   $form->header;
162
163   print qq|
164 <body>
165
166 <form method=post action=$form->{script}>
167
168 <table width=100%>
169   <tr>
170     <th class=listtop>$form->{title}</th>
171   </tr>
172   <tr height="5"></tr>
173   <tr>
174     <td>$option</td>
175   </tr>
176   <tr>
177     <td>
178       <table width=100%>
179         <tr class=listheading>
180 |;
181
182   map { print "\n$column_header{$_}" } @column_index;
183
184   print qq|
185         </tr>
186 |;
187
188   $ml = ($form->{category} eq 'A') ? -1 : 1;
189   $form->{beginningbalance} *= $ml;
190   $clearedbalance = $balance = $form->{beginningbalance};
191   $i              = 0;
192   $id             = 0;
193
194   map { $column_data{$_} = "<td>&nbsp;</td>" }
195     qw(cleared transdate source name debit credit);
196   $column_data{balance} =
197     "<td align=right>"
198     . $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
199   $j = 0;
200   print qq|
201         <tr class=listrow$j>
202 |;
203
204   map { print "\n$column_data{$_}" } @column_index;
205
206   print qq|
207         </tr>
208 |;
209
210   foreach $ref (@{ $form->{PR} }) {
211
212     $balance += $ref->{amount} * $ml;
213     $cleared += $ref->{amount} * $ml if $ref->{cleared};
214
215     $column_data{name}   = "<td>$ref->{name}&nbsp;</td>";
216     $column_data{source} = qq|<td>$ref->{source}&nbsp;</a>
217     </td>|;
218     $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
219
220     $column_data{debit}  = "<td>&nbsp;</td>";
221     $column_data{credit} = "<td>&nbsp;</td>";
222
223     if ($ref->{amount} < 0) {
224       $totaldebits += $ref->{amount} * -1;
225       $column_data{debit} =
226           "<td align=right>"
227         . $form->format_amount(\%myconfig, $ref->{amount} * -1, 2, "&nbsp;")
228         . "</td>";
229     } else {
230       $totalcredits += $ref->{amount};
231       $column_data{credit} =
232           "<td align=right>"
233         . $form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")
234         . "</td>";
235     }
236
237     $column_data{balance} =
238       "<td align=right>"
239       . $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
240
241     if ($ref->{fx_transaction}) {
242       $i++ unless $id == $ref->{id};
243       $fx_transaction = 1;
244       $fx += $ref->{amount} * $ml;
245       $column_data{cleared} = qq|<td align=center>&nbsp;
246       <input type=hidden name="fxoid_$i" value=$ref->{oid}>
247       </td>|;
248     } else {
249       $i++ unless ($fx_transaction && $id == $ref->{id});
250       $fx_transaction = 0;
251       $column_data{cleared} = qq|<td>
252       <input name="cleared_$i" type=checkbox class=checkbox value=1 $ref->{cleared}>
253       <input type=hidden name="oid_$i" value=$ref->{oid}>
254       </td>|;
255     }
256     $id = $ref->{id};
257
258     $j++;
259     $j %= 2;
260     print qq|
261         <tr class=listrow$j>
262 |;
263
264     map { print "\n$column_data{$_}" } @column_index;
265
266     print qq|
267         </tr>
268 |;
269
270   }
271
272   # print totals
273   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
274
275   $column_data{debit} =
276     "<th class=listtotal align=right>"
277     . $form->format_amount(\%myconfig, $totaldebits, 2, "&nbsp;") . "</th>";
278   $column_data{credit} =
279     "<th class=listtotal align=right>"
280     . $form->format_amount(\%myconfig, $totalcredits, 2, "&nbsp;") . "</th>";
281
282   print qq|
283         <tr class=listtotal>
284 |;
285
286   map { print "\n$column_data{$_}" } @column_index;
287
288   $form->{statementbalance} =
289     $form->parse_amount(\%myconfig, $form->{statementbalance});
290   $difference =
291     $form->format_amount(\%myconfig,
292                         $form->{statementbalance} - $clearedbalance - $cleared,
293                         2, 0);
294
295   $form->{statementbalance} =
296     $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
297
298   $clearedbalance = $form->format_amount(\%myconfig, $clearedbalance, 2, 0);
299
300   if ($fx) {
301     $fx = $form->format_amount(\%myconfig, $fx, 2, 0);
302     $exchdiff = qq|
303                 <th align=right nowrap>|
304       . $locale->text('Exchangerate Difference')
305       . qq|</th>
306                 <td width=10%></td>
307                 <td align=right>$fx</td>
308 |;
309   }
310
311   print qq|
312         </tr>
313       </table>
314     </td>
315   </tr>
316   <tr>
317     <td>
318       <table width=100%>
319         <tr valign=top>
320           <td>
321             <table>
322               <tr>
323                 <th align=right nowrap>| . $locale->text('Cleared Balance') . qq|</th>
324                 <td width=10%></td>
325                 <td align=right>$clearedbalance</td>
326               </tr>
327               <tr>
328                 $exchdiff
329               </tr>
330             </table>
331           </td>
332           <td align=right>
333             <table>
334               <tr>
335                 <th align=right nowrap>| . $locale->text('Statement Balance') . qq|</th>
336                 <td width=10%></td>
337                 <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
338               </tr>
339               <tr>
340                 <th align=right nowrap>| . $locale->text('Difference') . qq|</th>
341                 <td width=10%></td>
342                 <td align=right><input name=null size=11 value=$difference></td>
343                 <input type=hidden name=difference value=$difference>
344               </tr>
345             </table>
346           </td>
347         </tr>
348       </table>
349     </td>
350   </tr>
351   <tr>
352     <td><hr size=3 noshade></td>
353   </tr>
354 </table>
355
356 <input type=hidden name=rowcount value=$i>
357 <input type=hidden name=accno value=$form->{accno}>
358 <input type=hidden name=account value="$form->{account}">
359
360 <input type=hidden name=fromdate value=$form->{fromdate}>
361 <input type=hidden name=todate value=$form->{todate}>
362
363 <input type=hidden name=path value=$form->{path}>
364 <input type=hidden name=login value=$form->{login}>
365 <input type=hidden name=password value=$form->{password}>
366
367 <br>
368 <input type=submit class=submit name=action value="|
369     . $locale->text('Update') . qq|">
370 <input type=submit class=submit name=action value="|
371     . $locale->text('Select all') . qq|">
372 <input type=submit class=submit name=action value="|
373     . $locale->text('Done') . qq|">|;
374
375   if ($form->{menubar}) {
376     require "$form->{path}/menu.pl";
377     &menubar;
378   }
379
380   print qq|
381 </form>
382
383 </body>
384 </html>
385 |;
386
387   $lxdebug->leave_sub();
388 }
389
390 sub update {
391   $lxdebug->enter_sub();
392
393   RC->payment_transactions(\%myconfig, \%$form);
394
395   foreach $ref (@{ $form->{PR} }) {
396     if (!$ref->{fx_transaction}) {
397       $i++;
398       $ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : "";
399     }
400   }
401
402   &display_form;
403
404   $lxdebug->leave_sub();
405 }
406
407 sub select_all {
408   $lxdebug->enter_sub();
409
410   RC->payment_transactions(\%myconfig, \%$form);
411
412   map { $_->{cleared} = "checked" unless $_->{fx_transaction} }
413     @{ $form->{PR} };
414
415   &display_form;
416
417   $lxdebug->leave_sub();
418 }
419
420 sub done {
421   $lxdebug->enter_sub();
422
423   $form->{callback} =
424     "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&password=$form->{password}";
425
426   $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
427
428   RC->reconcile(\%myconfig, \%$form);
429   $form->redirect;
430
431   $lxdebug->leave_sub();
432 }
433