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