Currencies nochmal besser kommentiert und fehlerhaften Array wieder rausgenommen...
[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     # Dieser Zweig funktioniert derzeit NIE. Ggf. ganz raus oder
62     # alle offenen Zahlungen wieder korrekt anzeigen. jb 12.10.2010
63     $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
64   } else {
65     CP->get_openvc(\%myconfig, \%$form);
66   }
67
68   $form->{"select$form->{vc}"} = "";
69
70   if ($form->{"all_$form->{vc}"}) {
71     # s.o. jb 12.10.2010
72     $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
73     map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
74       @{ $form->{"all_$form->{vc}"} };
75   }
76
77   CP->paymentaccounts(\%myconfig, \%$form);
78
79   $form->{selectaccount} = "";
80   $form->{"select$form->{ARAP}"} = "";
81
82   map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
83     @{ $form->{PR}{"$form->{ARAP}_paid"} };
84   map {
85     $form->{"select$form->{ARAP}"} .=
86       "<option>$_->{accno}--$_->{description}\n"
87   } @{ $form->{PR}{ $form->{ARAP} } };
88
89   # currencies
90   # oldcurrency ist zwar noch hier als fragment enthalten, wird aber bei
91   # der aktualisierung der form auch nicht mitübernommen. das konzept
92   # old_$FOO habe ich auch noch nicht verstanden ...
93   # Ok. Wenn currency übernommen werden, dann in callback-string über-
94   # geben und hier reinparsen, oder besser multibox oder html auslagern?
95   # Antwort: form->currency wird mit oldcurrency oder curr[0] überschrieben
96   # Wofür macht das Sinn?
97   @curr = split(/:/, $form->{currencies});
98   chomp $curr[0];
99   $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
100     $curr[0];
101
102   $form->{selectcurrency} = "";
103   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
104
105
106   &form_header;
107   &form_footer;
108
109   $lxdebug->leave_sub();
110 }
111
112 sub form_header {
113   $lxdebug->enter_sub();
114
115   $auth->assert('cash');
116
117   my ($vc, $vclabel, $allvc, $arap, $exchangerate);
118   my ($jsscript, $button1, $button2, $onload);
119
120   $vclabel = ucfirst $form->{vc};
121   $vclabel = $locale->text($vclabel);
122
123   if ($form->{type} eq 'receipt') {
124     $form->{title}     = $locale->text('Receipt');
125     $form->{origtitle} = "Receipt";
126   }
127   if ($form->{type} eq 'check') {
128     $form->{title}     = $locale->text('Payment');
129     $form->{origtitle} = "Payment";
130   }
131
132   # $locale->text('Customer')
133   # $locale->text('Vendor')
134
135   if ($form->{ $form->{vc} } eq "") {
136     map { $form->{"addr$_"} = "" } (1 .. 4);
137   }
138
139   if ($form->{currency} ne $form->{defaultcurrency}) {
140     $form->{exchangerate} =
141       $form->format_amount(\%myconfig, $form->{exchangerate});
142     if ($form->{forex}) {
143       $exchangerate = qq|
144               <tr>
145                 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
146                 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
147               </tr>
148 |;
149     } else {
150       $exchangerate = qq|
151                <tr>
152                 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
153                 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
154               </tr>
155 |;
156     }
157   }
158   foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}) {
159     $form->{"select$item"} =~ s/ selected//;
160     $form->{"select$item"} =~
161       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
162   }
163
164   $vc =
165     ($form->{"select$form->{vc}"})
166     ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
167     : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
168
169   if ($form->{all_vc}) {
170     $allvc = "checked";
171     $form->{openinvoices} = "";
172   } else {
173     $allvc = "";
174     $form->{openinvoices} = 1;
175   }
176
177   # $locale->text('AR')
178   # $locale->text('AP')
179
180   $form->{jsscript} = 1;
181   $jsscript = "";
182   if ($form->{jsscript}) {
183
184     # with JavaScript Calendar
185     $button1 = qq|
186        <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
187        <input type=button name=datepaid id="trigger1" value=|
188       . $locale->text('button') . qq|></td>
189        |;
190
191     #write Trigger
192     $jsscript =
193       Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
194   } else {
195
196     # without JavaScript Calendar
197     $button1 = qq|
198                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
199   }
200   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
201   $form->header;
202
203   $arap = lc $form->{ARAP};
204   $onload = qq|focus()|;
205   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
206   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
207   print qq|
208 <body onLoad="$onload">
209
210 <form method=post action=cp.pl>
211
212 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
213 <input type=hidden name=closedto value=$form->{closedto}>
214 <input type=hidden name=vc value=$form->{vc}>
215 <input type=hidden name=type value=$form->{type}>
216 <input type=hidden name=formname value=$form->{type}>
217 <input type=hidden name=queued value="$form->{queued}">
218 <input type=hidden name=arap value=$arap>
219 <input type=hidden name=ARAP value=$form->{ARAP}>
220 <input type=hidden name=openinvoices value=$form->{openinvoices}>
221 <input type=hidden name=title value="$form->{title}">
222 <input type=hidden name=origtitle value="$form->{origtitle}">
223
224 <table width=100%>
225   <tr>
226     <th class=listtop>$form->{title}</th>
227   </tr>
228   <tr height="5"></tr>
229   <tr>
230     <td>
231       <table width=100%>
232         <tr valign=top>
233           <td>
234             <table>
235               <tr>
236                 <th align=right>$vclabel</th>
237                 <td>$vc</td>
238                 <input type=hidden name="select$form->{vc}" value="| . H($form->{"select$form->{vc}"}) . qq|">
239                 <input type=hidden name="$form->{vc}_id" value="|    . H($form->{"$form->{vc}_id"}) . qq|">
240                 <input type=hidden name="old$form->{vc}" value="|    . H($form->{"old$form->{vc}"}) . qq|">
241               </tr>
242               <tr valign=top>
243                 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
244                 <td colspan=2>
245                   <table>
246                     <tr>
247                       <td>$form->{street}</td>
248                     </tr>
249                     <tr>
250                       <td>$form->{zipcode}</td>
251                     </tr>
252                     <tr>
253                       <td>$form->{city}</td>
254                     </tr>
255                     <tr>
256                       <td>$form->{country}</td>
257                     </tr>
258                   </table>
259                 </td>
260                 <input type=hidden name=street value="$form->{street}">
261                 <input type=hidden name=zipcode value="$form->{zipcode}">
262                 <input type=hidden name=city value="$form->{city}">
263                 <input type=hidden name=country value="$form->{country}">
264               </tr>
265               <tr>
266                 <th align=right>| . $locale->text('Memo') . qq|</th>
267                 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
268               </tr>
269             </table>
270           </td>
271           <td align=right>
272             <table>
273               <tr>
274                 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
275                 <td colspan=3><select name=account>$form->{selectaccount}</select>
276                 <input type=hidden name=selectaccount value="$form->{selectaccount}">
277                 </td>
278               </tr>
279               <tr>
280                 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
281                 $button1
282               </tr>
283               <tr>
284                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
285                 <td><select name=currency>$form->{selectcurrency}</select></td>
286                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
287                 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
288               </tr>
289               $exchangerate
290               <tr>
291                 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
292                 <td colspan=3><input name=source value="$form->{source}" size=10></td>
293               </tr>
294               <tr>
295                 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
296                 <td colspan="3">| .  $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|</td>
297               </tr>
298             </table>
299           </td>
300         </tr>
301       </table>
302     </td>
303   </tr>
304
305 $jsscript
306 |;
307
308   if ($form->{openinvoices_other_currencies}) {
309     my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
310                 :                             $::locale->text('There are #1 more open invoices from this vendor with other currencies.',  $form->{openinvoices_other_currencies});
311
312     print qq|
313
314   <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
315   <tr>
316    <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
317   </tr>
318 |;
319   }
320
321   $lxdebug->leave_sub();
322 }
323
324 sub list_invoices {
325   $lxdebug->enter_sub();
326
327   $auth->assert('cash');
328
329   my (@column_index, %column_data, $colspan, $invoice);
330   my ($totalamount, $totaldue, $totalpaid);
331
332   @column_index = qw(invnumber transdate amount due checked paid);
333
334   $colspan = $#column_index + 1;
335
336   $invoice = $locale->text('Invoices');
337
338   print qq|
339   <input type=hidden name=column_index value="id @column_index">
340   <tr>
341     <td>
342       <table width=100%>
343         <tr>
344           <th class=listheading colspan=$colspan>$invoice</th>
345         </tr>
346 |;
347
348   $column_data{invnumber} =
349     qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
350   $column_data{transdate} =
351     qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
352   $column_data{amount} =
353     qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
354   $column_data{due} =
355     qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
356   $column_data{paid} =
357     qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
358   $column_data{checked} =
359     qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
360
361   print qq|
362         <tr>
363 |;
364   map { print "$column_data{$_}\n" } @column_index;
365   print qq|
366         </tr>
367 |;
368
369   for my $i (1 .. $form->{rowcount}) {
370
371     my $j = 0;
372
373     map {
374       $form->{"${_}_$i"} =
375         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
376     } qw(amount due paid);
377
378     $totalamount += $form->{"amount_$i"};
379     $totaldue    += $form->{"due_$i"};
380     $totalpaid   += $form->{"paid_$i"};
381
382     map {
383       $form->{"${_}_$i"} =
384         $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
385     } qw(amount due paid);
386
387     $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
388       <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
389       <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
390     $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
391       <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
392     $column_data{amount} =
393       qq|<td align=right width=15%>$form->{"amount_$i"}</td>
394       <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
395     $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
396       <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
397
398     $column_data{paid} =
399       qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
400
401     $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
402     $column_data{checked} =
403       qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
404
405     $j++;
406     $j %= 2;
407     print qq|
408         <tr class=listrow$j>
409 |;
410     map { print "$column_data{$_}\n" } @column_index;
411     print qq|
412         </tr>
413 |;
414   }
415
416   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
417
418   $column_data{amount} =
419       qq|<th class=listtotal align=right>|
420     . $form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;")
421     . qq|</th>|;
422   $column_data{due} =
423       qq|<th class=listtotal align=right>|
424     . $form->format_amount(\%myconfig, $totaldue, 2, "&nbsp;")
425     . qq|</th>|;
426   $column_data{paid} =
427       qq|<th class=listtotal align=right>|
428     . $form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")
429     . qq|</th>|;
430
431   print qq|
432         <tr class=listtotal>
433 |;
434   map { print "$column_data{$_}\n" } @column_index;
435   print qq|
436         </tr>
437       </table>
438     </td>
439   </tr>
440 |;
441
442   $lxdebug->leave_sub();
443 }
444
445 sub form_footer {
446   $lxdebug->enter_sub();
447
448   $auth->assert('cash');
449
450   print qq|
451   <tr>
452     <td><hr size=3 noshade></td>
453   </tr>
454 </table>
455 <input type=hidden name=rowcount value=$form->{rowcount}>
456
457 <br>
458 <input class=submit type=submit name=action value="|
459     . $locale->text('Update') . qq|">
460 <input class=submit type=submit name=action value="|
461     . $locale->text('Post') . qq|">
462  </form>
463
464 </body>
465 </html>
466 |;
467
468   $lxdebug->leave_sub();
469 }
470
471 sub update {
472   $lxdebug->enter_sub();
473
474   $auth->assert('cash');
475
476   my ($new_name_selected) = @_;
477
478   my ($buysell, $newvc, $updated, $exchangerate, $amount);
479
480   if ($form->{vc} eq 'customer') {
481     $buysell = "buy";
482   } else {
483     $buysell = "sell";
484   }
485
486   # if we switched to all_vc
487   # funktioniert derzeit nicht 12.10.2010 jb
488   if ($form->{all_vc} ne $form->{oldall_vc}) {
489
490     $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
491
492     $form->{"select$form->{vc}"} = "";
493
494     if ($form->{all_vc}) {
495       $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
496
497       if ($form->{"all_$form->{vc}"}) {
498         map {
499           $form->{"select$form->{vc}"} .=
500             "<option>$_->{name}--$_->{id}\n"
501         } @{ $form->{"all_$form->{vc}"} };
502       }
503     } else {  # ab hier wieder ausgeführter code (s.o.):
504       CP->get_openvc(\%myconfig, \%$form);
505
506       if ($form->{"all_$form->{vc}"}) {
507         $newvc =
508           qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
509         map {
510           $form->{"select$form->{vc}"} .=
511             "<option>$_->{name}--$_->{id}\n"
512         } @{ $form->{"all_$form->{vc}"} };
513       }
514
515       # if the name is not the same
516       if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
517         $form->{ $form->{vc} } = $newvc;
518       }
519     }
520   }
521
522   # get customer and invoices
523   $updated = &check_name($form->{vc});
524
525   if ($new_name_selected || $updated) {
526     CP->get_openinvoices(\%myconfig, \%$form);
527     ($newvc) = split /--/, $form->{ $form->{vc} };
528     $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
529     $updated = 1;
530   }
531
532   if ($form->{currency} ne $form->{oldcurrency}) {
533     $form->{oldcurrency} = $form->{currency};
534     if (!$updated) {
535       CP->get_openinvoices(\%myconfig, \%$form);
536       $updated = 1;
537     }
538   }
539
540   $form->{forex}        = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
541   $form->{exchangerate} = $form->{forex} if $form->{forex};
542
543   $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
544
545   if ($updated) {
546     $form->{rowcount} = 0;
547
548     $form->{queued} = "";
549
550     my $i = 0;
551     foreach my $ref (@{ $form->{PR} }) {
552       $i++;
553       $form->{"id_$i"}        = $ref->{id};
554       $form->{"invnumber_$i"} = $ref->{invnumber};
555       $form->{"transdate_$i"} = $ref->{transdate};
556       $ref->{exchangerate} = 1 unless $ref->{exchangerate};
557       $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
558       $form->{"due_$i"}    =
559         ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
560       $form->{"checked_$i"} = "";
561       $form->{"paid_$i"}    = "";
562
563       # need to format
564       map {
565         $form->{"${_}_$i"} =
566           $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
567       } qw(amount due);
568
569     }
570     $form->{rowcount} = $i;
571   }
572
573   # recalculate
574
575   # Modified from $amount = $form->{amount} by J.Zach to update amount to total
576   # payment amount in Zahlungsausgang
577   $amount = 0;
578   for my $i (1 .. $form->{rowcount}) {
579
580     map {
581       $form->{"${_}_$i"} =
582         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
583     } qw(amount due paid);
584
585     if ($form->{"checked_$i"}) {
586
587       # calculate paid_$i
588       if (!$form->{"paid_$i"}) {
589         $form->{"paid_$i"} = $form->{"due_$i"};
590       }
591
592       # Modified by J.Zach, see abovev
593       $amount += $form->{"paid_$i"};
594
595     } else {
596       $form->{"paid_$i"} = "";
597     }
598
599     map {
600       $form->{"${_}_$i"} =
601         $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
602     } qw(amount due paid);
603
604   }
605
606   # Line added by J.Zach, see above
607   $form->{amount}=$amount;
608
609   &form_header;
610   &list_invoices;
611   &form_footer;
612
613   $lxdebug->leave_sub();
614 }
615
616 sub post {
617   $lxdebug->enter_sub();
618
619   $auth->assert('cash');
620
621   &check_form;
622
623   if ($form->{currency} ne $form->{defaultcurrency}) {
624     $form->error($locale->text('Exchangerate missing!'))
625       unless $form->{exchangerate};
626   }
627
628   # Beim Aktualisieren wird das Konto übernommen
629   $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&type=$form->{type}&account=$form->{account}&$form->{currency}";
630
631   my $msg1 = "$form->{origtitle} posted!";
632   my $msg2 = "Cannot post $form->{origtitle}!";
633
634   # $locale->text('Payment posted!')
635   # $locale->text('Receipt posted!')
636   # $locale->text('Cannot post Payment!')
637   # $locale->text('Cannot post Receipt!')
638   # Die Nachrichten (Receipt posted!) werden nicht angezeigt.
639   # Entweder wieder aktivieren oder komplett rausnehmen
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('Amount has to be greater then zero! Wrong 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 }