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