Die Überbleibsel für die Druckfunktion aus dem HTML-Kode entfernt und ferner die...
[kivitendo-erp.git] / bin / mozilla / cp.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 # Payment module
31 #
32 #======================================================================
33
34 use SL::CP;
35 use SL::IS;
36 use SL::IR;
37 use strict ("vars", "subs");
38 #use warnings;
39
40 require "bin/mozilla/arap.pl";
41 require "bin/mozilla/common.pl";
42
43 our ($form, %myconfig, $lxdebug, $locale, $auth);
44
45 1;
46
47 # end of main
48
49 sub payment {
50   $lxdebug->enter_sub();
51
52   $auth->assert('cash');
53
54   my (@curr);
55
56   $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
57   $form->{arap} = lc $form->{ARAP};
58
59   # setup customer/vendor selection for open invoices
60   if ($form->{all_vc}) {
61     $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
62   } else {
63     CP->get_openvc(\%myconfig, \%$form);
64   }
65
66   $form->{"select$form->{vc}"} = "";
67
68   if ($form->{"all_$form->{vc}"}) {
69     $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
70     map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
71       @{ $form->{"all_$form->{vc}"} };
72   }
73
74   # departments
75   if (@{ $form->{all_departments} || [] }) {
76     $form->{selectdepartment} = "<option>\n";
77     $form->{department}       = "$form->{department}--$form->{department_id}";
78
79     map {
80       $form->{selectdepartment} .=
81         "<option>$_->{description}--$_->{id}\n"
82     } (@{ $form->{all_departments} || [] });
83   }
84
85   CP->paymentaccounts(\%myconfig, \%$form);
86
87   $form->{selectaccount} = "";
88   $form->{"select$form->{ARAP}"} = "";
89
90   map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
91     @{ $form->{PR}{"$form->{ARAP}_paid"} };
92   map {
93     $form->{"select$form->{ARAP}"} .=
94       "<option>$_->{accno}--$_->{description}\n"
95   } @{ $form->{PR}{ $form->{ARAP} } };
96
97   # currencies
98   @curr = split(/:/, $form->{currencies});
99   chomp $curr[0];
100   $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
101     $curr[0];
102
103   $form->{selectcurrency} = "";
104   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
105
106
107   &form_header;
108   &form_footer;
109
110   $lxdebug->leave_sub();
111 }
112
113 sub form_header {
114   $lxdebug->enter_sub();
115
116   $auth->assert('cash');
117
118   my ($vc, $vclabel, $allvc, $arap, $department, $exchangerate);
119   my ($jsscript, $button1, $button2, $onload);
120
121   $vclabel = ucfirst $form->{vc};
122   $vclabel = $locale->text($vclabel);
123
124   if ($form->{type} eq 'receipt') {
125     $form->{title}     = $locale->text('Receipt');
126     $form->{origtitle} = "Receipt";
127   }
128   if ($form->{type} eq 'check') {
129     $form->{title}     = $locale->text('Payment');
130     $form->{origtitle} = "Payment";
131   }
132
133   # $locale->text('Customer')
134   # $locale->text('Vendor')
135
136   if ($form->{ $form->{vc} } eq "") {
137     map { $form->{"addr$_"} = "" } (1 .. 4);
138   }
139
140   if ($form->{currency} ne $form->{defaultcurrency}) {
141     $form->{exchangerate} =
142       $form->format_amount(\%myconfig, $form->{exchangerate});
143     if ($form->{forex}) {
144       $exchangerate = qq|
145               <tr>
146                 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
147                 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
148               </tr>
149 |;
150     } else {
151       $exchangerate = qq|
152                <tr>
153                 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
154                 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
155               </tr>
156 |;
157     }
158   }
159
160   foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}, "department") {
161     $form->{"select$item"} =~ s/ selected//;
162     $form->{"select$item"} =~
163       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
164   }
165
166   $vc =
167     ($form->{"select$form->{vc}"})
168     ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
169     : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
170
171   if ($form->{all_vc}) {
172     $allvc = "checked";
173     $form->{openinvoices} = "";
174   } else {
175     $allvc = "";
176     $form->{openinvoices} = 1;
177   }
178
179   # $locale->text('AR')
180   # $locale->text('AP')
181
182   $form->{jsscript} = 1;
183   $jsscript = "";
184   if ($form->{jsscript}) {
185
186     # with JavaScript Calendar
187     $button1 = qq|
188        <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
189        <input type=button name=datepaid id="trigger1" value=|
190       . $locale->text('button') . qq|></td>
191        |;
192
193     #write Trigger
194     $jsscript =
195       Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
196   } else {
197
198     # without JavaScript Calendar
199     $button1 = qq|
200                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
201   }
202   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
203   $form->header;
204
205   $arap = lc $form->{ARAP};
206   $onload = qq|focus()|;
207   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
208   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
209   print qq|
210 <body onLoad="$onload">
211
212 <form method=post action=cp.pl>
213
214 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
215 <input type=hidden name=closedto value=$form->{closedto}>
216 <input type=hidden name=vc value=$form->{vc}>
217 <input type=hidden name=type value=$form->{type}>
218 <input type=hidden name=formname value=$form->{type}>
219 <input type=hidden name=queued value="$form->{queued}">
220 <input type=hidden name=arap value=$arap>
221 <input type=hidden name=ARAP value=$form->{ARAP}>
222 <input type=hidden name=openinvoices value=$form->{openinvoices}>
223 <input type=hidden name=title value="$form->{title}">
224 <input type=hidden name=origtitle value="$form->{origtitle}">
225
226 <table width=100%>
227   <tr>
228     <th class=listtop>$form->{title}</th>
229   </tr>
230   <tr height="5"></tr>
231   <tr>
232     <td>
233       <table width=100%>
234         <tr valign=top>
235           <td>
236             <table>
237               <tr>
238                 <th align=right>$vclabel</th>
239                 <td>$vc</td>
240                 <input type=hidden name="select$form->{vc}" value="| . H($form->{"select$form->{vc}"}) . qq|">
241                 <input type=hidden name="$form->{vc}_id" value="|    . H($form->{"$form->{vc}_id"}) . qq|">
242                 <input type=hidden name="old$form->{vc}" value="|    . H($form->{"old$form->{vc}"}) . qq|">
243               </tr>
244               <tr valign=top>
245                 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
246                 <td colspan=2>
247                   <table>
248                     <tr>
249                       <td>$form->{street}</td>
250                     </tr>
251                     <tr>
252                       <td>$form->{zipcode}</td>
253                     </tr>
254                     <tr>
255                       <td>$form->{city}</td>
256                     </tr>
257                     <tr>
258                       <td>$form->{country}</td>
259                     </tr>
260                   </table>
261                 </td>
262                 <input type=hidden name=street value="$form->{street}">
263                 <input type=hidden name=zipcode value="$form->{zipcode}">
264                 <input type=hidden name=city value="$form->{city}">
265                 <input type=hidden name=country value="$form->{country}">
266               </tr>
267               <tr>
268                 <th align=right>| . $locale->text('Memo') . qq|</th>
269                 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
270               </tr>
271             </table>
272           </td>
273           <td align=right>
274             <table>
275               $department
276               <tr>
277                 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
278                 <td colspan=3><select name=account>$form->{selectaccount}</select>
279                 <input type=hidden name=selectaccount value="$form->{selectaccount}">
280                 </td>
281               </tr>
282               <tr>
283                 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
284                 $button1
285               </tr>
286               <tr>
287                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
288                 <td><select name=currency>$form->{selectcurrency}</select></td>
289                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
290                 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
291               </tr>
292               $exchangerate
293               <tr>
294                 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
295                 <td colspan=3><input name=source value="$form->{source}" size=10></td>
296               </tr>
297               <tr>
298                 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
299                 <td colspan="3">| .  $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|</td>
300               </tr>
301             </table>
302           </td>
303         </tr>
304       </table>
305     </td>
306   </tr>
307
308 $jsscript
309 |;
310
311   if ($form->{openinvoices_other_currencies}) {
312     my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
313                 :                             $::locale->text('There are #1 more open invoices from this vendor with other currencies.',  $form->{openinvoices_other_currencies});
314
315     print qq|
316
317   <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
318   <tr>
319    <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
320   </tr>
321 |;
322   }
323
324   $lxdebug->leave_sub();
325 }
326
327 sub list_invoices {
328   $lxdebug->enter_sub();
329
330   $auth->assert('cash');
331
332   my (@column_index, %column_data, $colspan, $invoice);
333   my ($totalamount, $totaldue, $totalpaid);
334
335   @column_index = qw(invnumber transdate amount due checked paid);
336
337   $colspan = $#column_index + 1;
338
339   $invoice = $locale->text('Invoices');
340
341   print qq|
342   <input type=hidden name=column_index value="id @column_index">
343   <tr>
344     <td>
345       <table width=100%>
346         <tr>
347           <th class=listheading colspan=$colspan>$invoice</th>
348         </tr>
349 |;
350
351   $column_data{invnumber} =
352     qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
353   $column_data{transdate} =
354     qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
355   $column_data{amount} =
356     qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
357   $column_data{due} =
358     qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
359   $column_data{paid} =
360     qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
361   $column_data{checked} =
362     qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
363
364   print qq|
365         <tr>
366 |;
367   map { print "$column_data{$_}\n" } @column_index;
368   print qq|
369         </tr>
370 |;
371
372   for my $i (1 .. $form->{rowcount}) {
373
374     my $j = 0;
375
376     map {
377       $form->{"${_}_$i"} =
378         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
379     } qw(amount due paid);
380
381     $totalamount += $form->{"amount_$i"};
382     $totaldue    += $form->{"due_$i"};
383     $totalpaid   += $form->{"paid_$i"};
384
385     map {
386       $form->{"${_}_$i"} =
387         $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
388     } qw(amount due paid);
389
390     $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
391       <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
392       <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
393     $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
394       <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
395     $column_data{amount} =
396       qq|<td align=right width=15%>$form->{"amount_$i"}</td>
397       <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
398     $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
399       <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
400
401     $column_data{paid} =
402       qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
403
404     $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
405     $column_data{checked} =
406       qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
407
408     $j++;
409     $j %= 2;
410     print qq|
411         <tr class=listrow$j>
412 |;
413     map { print "$column_data{$_}\n" } @column_index;
414     print qq|
415         </tr>
416 |;
417   }
418
419   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
420
421   $column_data{amount} =
422       qq|<th class=listtotal align=right>|
423     . $form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;")
424     . qq|</th>|;
425   $column_data{due} =
426       qq|<th class=listtotal align=right>|
427     . $form->format_amount(\%myconfig, $totaldue, 2, "&nbsp;")
428     . qq|</th>|;
429   $column_data{paid} =
430       qq|<th class=listtotal align=right>|
431     . $form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")
432     . qq|</th>|;
433
434   print qq|
435         <tr class=listtotal>
436 |;
437   map { print "$column_data{$_}\n" } @column_index;
438   print qq|
439         </tr>
440       </table>
441     </td>
442   </tr>
443 |;
444
445   $lxdebug->leave_sub();
446 }
447
448 sub form_footer {
449   $lxdebug->enter_sub();
450
451   $auth->assert('cash');
452
453   print qq|
454   <tr>
455     <td><hr size=3 noshade></td>
456   </tr>
457 </table>
458 <input type=hidden name=rowcount value=$form->{rowcount}>
459
460 <br>
461 <input class=submit type=submit name=action value="|
462     . $locale->text('Update') . qq|">
463 <input class=submit type=submit name=action value="|
464     . $locale->text('Post') . qq|">
465  </form>
466
467 </body>
468 </html>
469 |;
470
471   $lxdebug->leave_sub();
472 }
473
474 sub update {
475   $lxdebug->enter_sub();
476
477   $auth->assert('cash');
478
479   my ($new_name_selected) = @_;
480
481   my ($buysell, $newvc, $updated, $exchangerate, $amount);
482
483   if ($form->{vc} eq 'customer') {
484     $buysell = "buy";
485   } else {
486     $buysell = "sell";
487   }
488
489   # if we switched to all_vc
490   if ($form->{all_vc} ne $form->{oldall_vc}) {
491
492     $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
493
494     $form->{"select$form->{vc}"} = "";
495
496     if ($form->{all_vc}) {
497       $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
498
499       if ($form->{"all_$form->{vc}"}) {
500         map {
501           $form->{"select$form->{vc}"} .=
502             "<option>$_->{name}--$_->{id}\n"
503         } @{ $form->{"all_$form->{vc}"} };
504       }
505     } else {
506       CP->get_openvc(\%myconfig, \%$form);
507
508       if ($form->{"all_$form->{vc}"}) {
509         $newvc =
510           qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
511         map {
512           $form->{"select$form->{vc}"} .=
513             "<option>$_->{name}--$_->{id}\n"
514         } @{ $form->{"all_$form->{vc}"} };
515       }
516
517       # if the name is not the same
518       if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
519         $form->{ $form->{vc} } = $newvc;
520       }
521     }
522   }
523
524   # get customer and invoices
525   $updated = &check_name($form->{vc});
526
527   if ($new_name_selected || $updated) {
528     CP->get_openinvoices(\%myconfig, \%$form);
529     ($newvc) = split /--/, $form->{ $form->{vc} };
530     $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
531     $updated = 1;
532   }
533
534   if ($form->{currency} ne $form->{oldcurrency}) {
535     $form->{oldcurrency} = $form->{currency};
536     if (!$updated) {
537       CP->get_openinvoices(\%myconfig, \%$form);
538       $updated = 1;
539     }
540   }
541
542   $form->{forex}        = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
543   $form->{exchangerate} = $form->{forex} if $form->{forex};
544
545   $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
546
547   if ($updated) {
548     $form->{rowcount} = 0;
549
550     $form->{queued} = "";
551
552     my $i = 0;
553     foreach my $ref (@{ $form->{PR} }) {
554       $i++;
555       $form->{"id_$i"}        = $ref->{id};
556       $form->{"invnumber_$i"} = $ref->{invnumber};
557       $form->{"transdate_$i"} = $ref->{transdate};
558       $ref->{exchangerate} = 1 unless $ref->{exchangerate};
559       $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
560       $form->{"due_$i"}    =
561         ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
562       $form->{"checked_$i"} = "";
563       $form->{"paid_$i"}    = "";
564
565       # need to format
566       map {
567         $form->{"${_}_$i"} =
568           $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
569       } qw(amount due);
570
571     }
572     $form->{rowcount} = $i;
573   }
574
575   # recalculate
576
577   # Modified from $amount = $form->{amount} by J.Zach to update amount to total
578   # payment amount in Zahlungsausgang
579   $amount = 0;
580   for my $i (1 .. $form->{rowcount}) {
581
582     map {
583       $form->{"${_}_$i"} =
584         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
585     } qw(amount due paid);
586
587     if ($form->{"checked_$i"}) {
588
589       # calculate paid_$i
590       if (!$form->{"paid_$i"}) {
591         $form->{"paid_$i"} = $form->{"due_$i"};
592       }
593
594       # Modified by J.Zach, see abovev
595       $amount += $form->{"paid_$i"};
596
597     } else {
598       $form->{"paid_$i"} = "";
599     }
600
601     map {
602       $form->{"${_}_$i"} =
603         $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
604     } qw(amount due paid);
605
606   }
607
608   # Line added by J.Zach, see above
609   $form->{amount}=$amount;
610
611   &form_header;
612   &list_invoices;
613   &form_footer;
614
615   $lxdebug->leave_sub();
616 }
617
618 sub post {
619   $lxdebug->enter_sub();
620
621   $auth->assert('cash');
622
623   &check_form;
624
625   if ($form->{currency} ne $form->{defaultcurrency}) {
626     $form->error($locale->text('Exchangerate missing!'))
627       unless $form->{exchangerate};
628   }
629
630   $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&muh=kuh&account=$form->{account}";
631
632   my $msg1 = "$form->{origtitle} posted!";
633   my $msg2 = "Cannot post $form->{origtitle}!";
634
635   # $locale->text('Payment posted!')
636   # $locale->text('Receipt posted!')
637   # $locale->text('Cannot post Payment!')
638   # $locale->text('Cannot post Receipt!')
639
640   $form->redirect($locale->text($msg1))
641     if (CP->process_payment(\%myconfig, \%$form));
642   $form->error($locale->text($msg2));
643
644   $lxdebug->leave_sub();
645 }
646
647 sub check_form {
648   $lxdebug->enter_sub();
649
650   $auth->assert('cash');
651
652   my ($closedto, $datepaid, $amount);
653
654   &check_name($form->{vc});
655
656   if ($form->{currency} ne $form->{oldcurrency}) {
657     &update;
658     ::end_of_request();
659   }
660   $form->error($locale->text('Date missing!')) unless $form->{datepaid};
661   my $selected_check = 1; 
662   for my $i (1 .. $form->{rowcount}) {
663     if ($form->{"checked_$i"}) {
664       if ($form->parse_amount(\%myconfig, $form->{"paid_$i"}, 2) <= 0) { # negativen Betrag eingegeben
665           $form->error($locale->text('No zero or negative values, please! Correct row number:' . $i));
666       }
667         undef($selected_check);
668         # last; # ich muss doch über alle buchungen laufen, da ich noch
669         # die freitext-eingabe der werte prüfen will 
670     }
671   }
672   $form->error($locale->text('No transaction selected!')) if $selected_check;
673
674   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
675   $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
676
677   $form->error($locale->text('Cannot process payment for a closed period!'))
678     if ($form->date_closed($form->{"datepaid"}, \%myconfig));
679
680   $amount = $form->parse_amount(\%myconfig, $form->{amount});
681   $form->{amount} = $amount;
682
683   for my $i (1 .. $form->{rowcount}) {
684     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
685       $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
686
687       push(@{ $form->{paid} },      $form->{"paid_$i"});
688       push(@{ $form->{due} },       $form->{"due_$i"});
689       push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
690       push(@{ $form->{invdate} },   $form->{"transdate_$i"});
691     }
692   }
693
694   if ($form->round_amount($amount, 2) != 0) {
695     push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
696     push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
697     push(@{ $form->{invnumber} },
698          ($form->{ARAP} eq 'AR')
699          ? $locale->text('Deposit')
700          : $locale->text('Prepayment'));
701     push(@{ $form->{invdate} }, $form->{datepaid});
702   }
703
704   $lxdebug->leave_sub();
705 }