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