Kosmetik.
[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=login value=$form->{login}>
100 <input type=hidden name=password value=$form->{password}>
101
102 <input type=submit class=submit name=action value="|
103     . $locale->text('Continue') . qq|">
104
105 </form>
106
107 </body>
108 </html>
109 |;
110
111   $lxdebug->leave_sub();
112 }
113
114 sub continue { call_sub($form->{"nextsub"}); }
115
116 sub get_payments {
117   $lxdebug->enter_sub();
118
119   ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
120
121   RC->payment_transactions(\%myconfig, \%$form);
122
123   &display_form;
124
125   $lxdebug->leave_sub();
126 }
127
128 sub display_form {
129   $lxdebug->enter_sub();
130
131   @column_index = qw(cleared transdate source name credit debit balance);
132
133   $column_header{cleared} = "<th>&nbsp;</th>";
134   $column_header{source}  =
135     "<th class=listheading>" . $locale->text('Source') . "</a></th>";
136   $column_header{name} =
137     "<th class=listheading>" . $locale->text('Description') . "</a></th>";
138   $column_header{transdate} =
139     "<th class=listheading>" . $locale->text('Date') . "</a></th>";
140
141   if ($form->{category} eq 'A') {
142     $column_header{debit} =
143       "<th class=listheading>" . $locale->text('Deposit') . "</a></th>";
144     $column_header{credit} =
145       "<th class=listheading>" . $locale->text('Payment') . "</a></th>";
146   } else {
147     $column_header{debit} =
148       "<th class=listheading>" . $locale->text('Decrease') . "</a></th>";
149     $column_header{credit} =
150       "<th class=listheading>" . $locale->text('Increase') . "</a></th>";
151   }
152
153   $column_header{balance} =
154     "<th class=listheading>" . $locale->text('Balance') . "</a></th>";
155
156   if ($form->{fromdate}) {
157     $option .= "\n<br>" if ($option);
158     $option .=
159         $locale->text('From') . "&nbsp;"
160       . $locale->date(\%myconfig, $form->{fromdate}, 0);
161   }
162   if ($form->{todate}) {
163     $option .= "\n<br>" if ($option);
164     $option .=
165         $locale->text('Until') . "&nbsp;"
166       . $locale->date(\%myconfig, $form->{todate}, 0);
167   }
168
169   $form->{title} = "$form->{accno}--$form->{account}";
170
171   $form->header;
172
173   print qq|
174 <body>
175
176 <form method=post action=$form->{script}>
177
178 <table width=100%>
179   <tr>
180     <th class=listtop>$form->{title}</th>
181   </tr>
182   <tr height="5"></tr>
183   <tr>
184     <td>$option</td>
185   </tr>
186   <tr>
187     <td>
188       <table width=100%>
189         <tr class=listheading>
190 |;
191
192   map { print "\n$column_header{$_}" } @column_index;
193
194   print qq|
195         </tr>
196 |;
197
198   $ml = ($form->{category} eq 'A') ? -1 : 1;
199   $form->{beginningbalance} *= $ml;
200   $clearedbalance = $balance = $form->{beginningbalance};
201   $i              = 0;
202   $id             = 0;
203
204   map { $column_data{$_} = "<td>&nbsp;</td>" }
205     qw(cleared transdate source name debit credit);
206   $column_data{balance} =
207     "<td align=right>"
208     . $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
209   $j = 0;
210   print qq|
211         <tr class=listrow$j>
212 |;
213
214   map { print "\n$column_data{$_}" } @column_index;
215
216   print qq|
217         </tr>
218 |;
219
220   foreach $ref (@{ $form->{PR} }) {
221
222     $balance += $ref->{amount} * $ml;
223     $cleared += $ref->{amount} * $ml if $ref->{cleared};
224
225     $column_data{name}   = "<td>$ref->{name}&nbsp;</td>";
226     $column_data{source} = qq|<td>$ref->{source}&nbsp;</a>
227     </td>|;
228     $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
229
230     $column_data{debit}  = "<td>&nbsp;</td>";
231     $column_data{credit} = "<td>&nbsp;</td>";
232
233     if ($ref->{amount} < 0) {
234       $totaldebits += $ref->{amount} * -1;
235       $column_data{debit} =
236           "<td align=right>"
237         . $form->format_amount(\%myconfig, $ref->{amount} * -1, 2, "&nbsp;")
238         . "</td>";
239     } else {
240       $totalcredits += $ref->{amount};
241       $column_data{credit} =
242           "<td align=right>"
243         . $form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")
244         . "</td>";
245     }
246
247     $column_data{balance} =
248       "<td align=right>"
249       . $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
250
251     if ($ref->{fx_transaction}) {
252       $i++ unless $id == $ref->{id};
253       $fx_transaction = 1;
254       $fx += $ref->{amount} * $ml;
255       $column_data{cleared} = qq|<td align=center>&nbsp;
256       <input type=hidden name="fxoid_$i" value=$ref->{oid}>
257       </td>|;
258     } else {
259       $i++ unless ($fx_transaction && $id == $ref->{id});
260       $fx_transaction = 0;
261       $column_data{cleared} = qq|<td>
262       <input name="cleared_$i" type=checkbox class=checkbox value=1 $ref->{cleared}>
263       <input type=hidden name="oid_$i" value=$ref->{oid}>
264       </td>|;
265     }
266     $id = $ref->{id};
267
268     $j++;
269     $j %= 2;
270     print qq|
271         <tr class=listrow$j>
272 |;
273
274     map { print "\n$column_data{$_}" } @column_index;
275
276     print qq|
277         </tr>
278 |;
279
280   }
281
282   # print totals
283   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
284
285   $column_data{debit} =
286     "<th class=listtotal align=right>"
287     . $form->format_amount(\%myconfig, $totaldebits, 2, "&nbsp;") . "</th>";
288   $column_data{credit} =
289     "<th class=listtotal align=right>"
290     . $form->format_amount(\%myconfig, $totalcredits, 2, "&nbsp;") . "</th>";
291
292   print qq|
293         <tr class=listtotal>
294 |;
295
296   map { print "\n$column_data{$_}" } @column_index;
297
298   $form->{statementbalance} =
299     $form->parse_amount(\%myconfig, $form->{statementbalance});
300   $difference =
301     $form->format_amount(\%myconfig,
302                         $form->{statementbalance} - $clearedbalance - $cleared,
303                         2, 0);
304
305   $form->{statementbalance} =
306     $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
307
308   $clearedbalance = $form->format_amount(\%myconfig, $clearedbalance, 2, 0);
309
310   if ($fx) {
311     $fx       = $form->format_amount(\%myconfig, $fx, 2, 0);
312     $exchdiff = qq|
313                 <th align=right nowrap>|
314       . $locale->text('Exchangerate Difference') . qq|</th>
315                 <td width=10%></td>
316                 <td align=right>$fx</td>
317 |;
318   }
319
320   print qq|
321         </tr>
322       </table>
323     </td>
324   </tr>
325   <tr>
326     <td>
327       <table width=100%>
328         <tr valign=top>
329           <td>
330             <table>
331               <tr>
332                 <th align=right nowrap>| . $locale->text('Cleared Balance') . qq|</th>
333                 <td width=10%></td>
334                 <td align=right>$clearedbalance</td>
335               </tr>
336               <tr>
337                 $exchdiff
338               </tr>
339             </table>
340           </td>
341           <td align=right>
342             <table>
343               <tr>
344                 <th align=right nowrap>| . $locale->text('Statement Balance') . qq|</th>
345                 <td width=10%></td>
346                 <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
347               </tr>
348               <tr>
349                 <th align=right nowrap>| . $locale->text('Difference') . qq|</th>
350                 <td width=10%></td>
351                 <td align=right><input name=null size=11 value=$difference></td>
352                 <input type=hidden name=difference value=$difference>
353               </tr>
354             </table>
355           </td>
356         </tr>
357       </table>
358     </td>
359   </tr>
360   <tr>
361     <td><hr size=3 noshade></td>
362   </tr>
363 </table>
364
365 <input type=hidden name=rowcount value=$i>
366 <input type=hidden name=accno value=$form->{accno}>
367 <input type=hidden name=account value="$form->{account}">
368
369 <input type=hidden name=fromdate value=$form->{fromdate}>
370 <input type=hidden name=todate value=$form->{todate}>
371
372 <input type=hidden name=login value=$form->{login}>
373 <input type=hidden name=password value=$form->{password}>
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   RC->payment_transactions(\%myconfig, \%$form);
396
397   foreach $ref (@{ $form->{PR} }) {
398     if (!$ref->{fx_transaction}) {
399       $i++;
400       $ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : "";
401     }
402   }
403
404   &display_form;
405
406   $lxdebug->leave_sub();
407 }
408
409 sub select_all {
410   $lxdebug->enter_sub();
411
412   RC->payment_transactions(\%myconfig, \%$form);
413
414   map { $_->{cleared} = "checked" unless $_->{fx_transaction} }
415     @{ $form->{PR} };
416
417   &display_form;
418
419   $lxdebug->leave_sub();
420 }
421
422 sub done {
423   $lxdebug->enter_sub();
424
425   $form->{callback} =
426     "$form->{script}?action=reconciliation&login=$form->{login}&password=$form->{password}";
427
428   $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
429
430   RC->reconcile(\%myconfig, \%$form);
431   $form->redirect;
432
433   $lxdebug->leave_sub();
434 }
435