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