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