Uebernahme der kompletten Version, so wie sie Philip als "Demo-Version" gezeigt hat...
[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') . qq|</th>
305                 <td width=10%></td>
306                 <td align=right>$fx</td>
307 |;
308   }
309
310   print qq|
311         </tr>
312       </table>
313     </td>
314   </tr>
315   <tr>
316     <td>
317       <table width=100%>
318         <tr valign=top>
319           <td>
320             <table>
321               <tr>
322                 <th align=right nowrap>| . $locale->text('Cleared Balance') . qq|</th>
323                 <td width=10%></td>
324                 <td align=right>$clearedbalance</td>
325               </tr>
326               <tr>
327                 $exchdiff
328               </tr>
329             </table>
330           </td>
331           <td align=right>
332             <table>
333               <tr>
334                 <th align=right nowrap>| . $locale->text('Statement Balance') . qq|</th>
335                 <td width=10%></td>
336                 <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
337               </tr>
338               <tr>
339                 <th align=right nowrap>| . $locale->text('Difference') . qq|</th>
340                 <td width=10%></td>
341                 <td align=right><input name=null size=11 value=$difference></td>
342                 <input type=hidden name=difference value=$difference>
343               </tr>
344             </table>
345           </td>
346         </tr>
347       </table>
348     </td>
349   </tr>
350   <tr>
351     <td><hr size=3 noshade></td>
352   </tr>
353 </table>
354
355 <input type=hidden name=rowcount value=$i>
356 <input type=hidden name=accno value=$form->{accno}>
357 <input type=hidden name=account value="$form->{account}">
358
359 <input type=hidden name=fromdate value=$form->{fromdate}>
360 <input type=hidden name=todate value=$form->{todate}>
361
362 <input type=hidden name=path value=$form->{path}>
363 <input type=hidden name=login value=$form->{login}>
364 <input type=hidden name=password value=$form->{password}>
365
366 <br>
367 <input type=submit class=submit name=action value="|
368     . $locale->text('Update') . qq|">
369 <input type=submit class=submit name=action value="|
370     . $locale->text('Select all') . qq|">
371 <input type=submit class=submit name=action value="|
372     . $locale->text('Done') . qq|">|;
373
374   if ($form->{menubar}) {
375     require "$form->{path}/menu.pl";
376     &menubar;
377   }
378
379   print qq|
380 </form>
381
382 </body>
383 </html>
384 |;
385
386   $lxdebug->leave_sub();
387 }
388
389 sub update {
390   $lxdebug->enter_sub();
391
392   RC->payment_transactions(\%myconfig, \%$form);
393
394   foreach $ref (@{ $form->{PR} }) {
395     if (!$ref->{fx_transaction}) {
396       $i++;
397       $ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : "";
398     }
399   }
400
401   &display_form;
402
403   $lxdebug->leave_sub();
404 }
405
406 sub select_all {
407   $lxdebug->enter_sub();
408
409   RC->payment_transactions(\%myconfig, \%$form);
410
411   map { $_->{cleared} = "checked" unless $_->{fx_transaction} }
412     @{ $form->{PR} };
413
414   &display_form;
415
416   $lxdebug->leave_sub();
417 }
418
419 sub done {
420   $lxdebug->enter_sub();
421
422   $form->{callback} =
423     "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&password=$form->{password}";
424
425   $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
426
427   RC->reconcile(\%myconfig, \%$form);
428   $form->redirect;
429
430   $lxdebug->leave_sub();
431 }
432