Kosmetik: Perltidy-Lauf nach den Einstellungen in doc/programmierrichtlinien.txt...
[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::OP;
36 use SL::IS;
37 use SL::IR;
38
39 require "$form->{path}/arap.pl";
40
41 1;
42
43 # end of main
44
45 sub payment {
46   $lxdebug->enter_sub();
47
48   $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
49   $form->{arap} = lc $form->{ARAP};
50
51   # setup customer/vendor selection for open invoices
52   if ($form->{all_vc}) {
53     $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
54   } else {
55     CP->get_openvc(\%myconfig, \%$form);
56   }
57
58   $form->{"select$form->{vc}"} = "";
59
60   if ($form->{"all_$form->{vc}"}) {
61     $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
62     map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
63       @{ $form->{"all_$form->{vc}"} };
64   }
65
66   # departments
67   if (@{ $form->{all_departments} }) {
68     $form->{selectdepartment} = "<option>\n";
69     $form->{department}       = "$form->{department}--$form->{department_id}";
70
71     map {
72       $form->{selectdepartment} .=
73         "<option>$_->{description}--$_->{id}\n"
74     } (@{ $form->{all_departments} });
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   @curr = split /:/, $form->{currencies};
91   chomp $curr[0];
92   $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
93     $curr[0];
94
95   $form->{selectcurrency} = "";
96   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
97
98   $form->{media} = "screen";
99
100   &form_header;
101   &form_footer;
102
103   $lxdebug->leave_sub();
104 }
105
106 sub form_header {
107   $lxdebug->enter_sub();
108
109   $vclabel = ucfirst $form->{vc};
110   $vclabel = $locale->text($vclabel);
111
112   if ($form->{type} eq 'receipt') {
113     $form->{title}     = $locale->text('Receipt');
114     $form->{origtitle} = "Receipt";
115   }
116   if ($form->{type} eq 'check') {
117     $form->{title}     = $locale->text('Payment');
118     $form->{origtitle} = "Payment";
119   }
120
121   # $locale->text('Customer')
122   # $locale->text('Vendor')
123
124   if ($form->{ $form->{vc} } eq "") {
125     map { $form->{"addr$_"} = "" } (1 .. 4);
126   }
127
128   if ($form->{currency} ne $form->{defaultcurrency}) {
129     $form->{exchangerate} =
130       $form->format_amount(\%myconfig, $form->{exchangerate});
131     if ($form->{forex}) {
132       $exchangerate = qq|
133               <tr>
134                 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
135                 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
136               </tr>
137 |;
138     } else {
139       $exchangerate = qq|
140               <tr>
141                 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
142                 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
143               </tr>
144 |;
145     }
146   }
147
148   foreach $item ($form->{vc}, account, currency, $form->{ARAP}, department) {
149     $form->{"select$item"} =~ s/ selected//;
150     $form->{"select$item"} =~
151       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
152   }
153
154   $vc =
155     ($form->{"select$form->{vc}"})
156     ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
157     : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
158
159   if ($form->{all_vc}) {
160     $allvc = "checked";
161     $form->{openinvoices} = "";
162   } else {
163     $allvc = "";
164     $form->{openinvoices} = 1;
165   }
166
167   # $locale->text('AR')
168   # $locale->text('AP')
169
170   $department = qq|
171               <tr>
172                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
173                 <td><select name=department>$form->{selectdepartment}</select>
174                 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
175
176               </td>
177             </tr>
178 | if $form->{selectdepartment};
179
180   $form->{jsscript} = $jscalendar;
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}">
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}"></td>|;
199   }
200
201   $form->header;
202
203   $arap = lc $form->{ARAP};
204
205   print qq|
206 <body>
207
208 <form method=post action=$form->{script}>
209
210 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
211 <input type=hidden name=closedto value=$form->{closedto}>
212 <input type=hidden name=vc value=$form->{vc}>
213 <input type=hidden name=type value=$form->{type}>
214 <input type=hidden name=formname value=$form->{type}>
215 <input type=hidden name=queued value="$form->{queued}">
216 <input type=hidden name=arap value=$arap>
217 <input type=hidden name=ARAP value=$form->{ARAP}>
218 <input type=hidden name=openinvoices value=$form->{openinvoices}>
219 <input type=hidden name=title value="$form->{title}">
220 <input type=hidden name=origtitle value="$form->{origtitle}">
221
222 <table width=100%>
223   <tr>
224     <th class=listtop>$form->{title}</th>
225   </tr>
226   <tr height="5"></tr>
227   <tr>
228     <td>
229       <table width=100%>
230         <tr valign=top>
231           <td>
232             <table>
233               <tr>
234                 <td align=right>
235                 <input name=all_vc type=checkbox style=checkbox value=Y $allvc>
236                 <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
237                 <th align=left>| . $locale->text('All') . qq|</th>
238               </tr>
239               <tr>
240                 <th align=right>$vclabel</th>
241                 <td>$vc</td>
242                 <input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">
243                 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
244                 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
245               </tr>
246               <tr valign=top>
247                 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
248                 <td colspan=2>
249                   <table>
250                     <tr>
251                       <td>$form->{street}</td>
252                     </tr>
253                     <tr>
254                       <td>$form->{zipcode}</td>
255                     </tr>
256                     <tr>
257                       <td>$form->{city}</td>
258                     </tr>
259                     <tr>
260                       <td>$form->{country}</td>
261                     </tr>
262                   </table>
263                 </td>
264                 <input type=hidden name=street value="$form->{street}">
265                 <input type=hidden name=zipcode value="$form->{zipcode}">
266                 <input type=hidden name=city value="$form->{city}">
267                 <input type=hidden name=country value="$form->{country}">
268               </tr>
269               <tr>
270                 <th align=right>| . $locale->text('Memo') . qq|</th>
271                 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
272               </tr>
273             </table>
274           </td>
275           <td align=right>
276             <table>
277               $department
278               <tr>
279                 <th align=right nowrap>| . $locale->text($form->{ARAP}) . qq|</th>
280                 <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
281                 </td>
282                 <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
283               </tr>
284               <tr>
285                 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
286                 <td colspan=3><select name=account>$form->{selectaccount}</select>
287                 <input type=hidden name=selectaccount value="$form->{selectaccount}">
288                 </td>
289               </tr>
290               <tr>
291                 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
292                 $button1
293               </tr>
294               <tr>
295                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
296                 <td><select name=currency>$form->{selectcurrency}</select></td>
297                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
298                 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
299               </tr>
300               $exchangerate
301               <tr>
302                 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
303                 <td colspan=3><input name=source value="$form->{source}" size=10></td>
304               </tr>
305               <tr>
306                 <th align=right nowrap>| . $locale->text('Amount') . qq|</th>
307                 <td colspan=3><input name=amount size=10 value=|
308     . $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   $lxdebug->leave_sub();
321 }
322
323 sub list_invoices {
324   $lxdebug->enter_sub();
325
326   @column_index = qw(invnumber transdate amount due checked paid);
327
328   $colspan = $#column_index + 1;
329
330   $invoice = $locale->text('Invoices');
331
332   print qq|
333   <input type=hidden name=column_index value="id @column_index">
334   <tr>
335     <td>
336       <table width=100%>
337         <tr>
338           <th class=listheading colspan=$colspan>$invoice</th>
339         </tr>
340 |;
341
342   $column_data{invnumber} =
343     qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
344   $column_data{transdate} =
345     qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
346   $column_data{amount} =
347     qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
348   $column_data{due} =
349     qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
350   $column_data{paid} =
351     qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
352   $column_data{checked} =
353     qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
354
355   print qq|
356         <tr>
357 |;
358   map { print "$column_data{$_}\n" } @column_index;
359   print qq|
360         </tr>
361 |;
362
363   for $i (1 .. $form->{rowcount}) {
364
365     map {
366       $form->{"${_}_$i"} =
367         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
368     } qw(amount due paid);
369
370     $totalamount += $form->{"amount_$i"};
371     $totaldue    += $form->{"due_$i"};
372     $totalpaid   += $form->{"paid_$i"};
373
374     map {
375       $form->{"${_}_$i"} =
376         $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
377     } qw(amount due paid);
378
379     $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
380       <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
381       <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
382     $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
383       <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
384     $column_data{amount} =
385       qq|<td align=right width=15%>$form->{"amount_$i"}</td>
386       <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
387     $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
388       <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
389
390     $column_data{paid} =
391       qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
392
393     $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
394     $column_data{checked} =
395       qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
396
397     $j++;
398     $j %= 2;
399     print qq|
400         <tr class=listrow$j>
401 |;
402     map { print "$column_data{$_}\n" } @column_index;
403     print qq|
404         </tr>
405 |;
406   }
407
408   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
409
410   $column_data{amount} =
411       qq|<th class=listtotal align=right>|
412     . $form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;")
413     . qq|</th>|;
414   $column_data{due} =
415       qq|<th class=listtotal align=right>|
416     . $form->format_amount(\%myconfig, $totaldue, 2, "&nbsp;")
417     . qq|</th>|;
418   $column_data{paid} =
419       qq|<th class=listtotal align=right>|
420     . $form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")
421     . qq|</th>|;
422
423   print qq|
424         <tr class=listtotal>
425 |;
426   map { print "$column_data{$_}\n" } @column_index;
427   print qq|
428         </tr>
429       </table>
430     </td>
431   </tr>
432 |;
433
434   $lxdebug->leave_sub();
435 }
436
437 sub form_footer {
438   $lxdebug->enter_sub();
439
440   $form->{DF}{ $form->{format} } = "selected";
441   $form->{OP}{ $form->{media} }  = "selected";
442
443   $media = qq|
444           <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
445
446   if ($myconfig{printer} && $latex) {
447     $media .= qq|
448           <option value=printer $form->{OP}{printer}>|
449       . $locale->text('Printer');
450   }
451   if ($latex) {
452     $media .= qq|
453           <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
454     $format .= qq|
455             <option value=postscript $form->{DF}{postscript}>|
456       . $locale->text('Postscript') . qq|
457             <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
458   }
459
460   print qq|
461   <tr>
462     <td><hr size=3 noshade></td>
463   </tr>
464 </table>
465 <input type=hidden name=rowcount value=$form->{rowcount}>
466
467 <input type=hidden name=path value=$form->{path}>
468 <input type=hidden name=login value=$form->{login}>
469 <input type=hidden name=password value=$form->{password}>
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
477   if ($latex) {
478     print qq|
479 <input class=submit type=submit name=action value="|
480       . $locale->text('Print') . qq|">|;
481   }
482
483   print qq|
484 <select name=format>$format</select>
485 <select name=media>$media</select>
486 |;
487
488   if ($form->{menubar}) {
489     require "$form->{path}/menu.pl";
490     &menubar;
491   }
492
493   print qq|
494   </form>
495
496 </body>
497 </html>
498 |;
499
500   $lxdebug->leave_sub();
501 }
502
503 sub update {
504   $lxdebug->enter_sub();
505
506   my ($new_name_selected) = @_;
507
508   if ($form->{vc} eq 'customer') {
509     $buysell = "buy";
510   } else {
511     $buysell = "sell";
512   }
513
514   # if we switched to all_vc
515   if ($form->{all_vc} ne $form->{oldall_vc}) {
516
517     $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
518
519     $form->{"select$form->{vc}"} = "";
520
521     if ($form->{all_vc}) {
522       $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
523
524       if ($form->{"all_$form->{vc}"}) {
525         map {
526           $form->{"select$form->{vc}"} .=
527             "<option>$_->{name}--$_->{id}\n"
528         } @{ $form->{"all_$form->{vc}"} };
529       }
530     } else {
531       CP->get_openvc(\%myconfig, \%$form);
532
533       if ($form->{"all_$form->{vc}"}) {
534         $newvc =
535           qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
536         map {
537           $form->{"select$form->{vc}"} .=
538             "<option>$_->{name}--$_->{id}\n"
539         } @{ $form->{"all_$form->{vc}"} };
540       }
541
542       # if the name is not the same
543       if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
544         $form->{ $form->{vc} } = $newvc;
545       }
546     }
547   }
548
549   # get customer and invoices
550   $updated = &check_name($form->{vc});
551
552   if ($new_name_selected || $updated) {
553     CP->get_openinvoices(\%myconfig, \%$form);
554     ($newvc) = split /--/, $form->{ $form->{vc} };
555     $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
556     $updated = 1;
557   }
558
559   if ($form->{currency} ne $form->{oldcurrency}) {
560     $form->{oldcurrency} = $form->{currency};
561     if (!$updated) {
562       CP->get_openinvoices(\%myconfig, \%$form);
563       $updated = 1;
564     }
565   }
566
567   $form->{exchangerate} = $exchangerate
568     if (
569         $form->{forex} = (
570                    $exchangerate =
571                      $form->check_exchangerate(
572                      \%myconfig, $form->{currency}, $form->{datepaid}, $buysell
573                      )));
574
575   $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
576
577   if ($updated) {
578     $form->{rowcount} = 0;
579
580     $form->{queued} = "";
581
582     $i = 0;
583     foreach $ref (@{ $form->{PR} }) {
584       $i++;
585       $form->{"id_$i"}        = $ref->{id};
586       $form->{"invnumber_$i"} = $ref->{invnumber};
587       $form->{"transdate_$i"} = $ref->{transdate};
588       $ref->{exchangerate} = 1 unless $ref->{exchangerate};
589       $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
590       $form->{"due_$i"}    =
591         ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
592       $form->{"checked_$i"} = "";
593       $form->{"paid_$i"}    = "";
594
595       # need to format
596       map {
597         $form->{"${_}_$i"} =
598           $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
599       } qw(amount due);
600
601     }
602     $form->{rowcount} = $i;
603   }
604
605   # recalculate
606   $amount = $form->{amount};
607   for $i (1 .. $form->{rowcount}) {
608
609     map {
610       $form->{"${_}_$i"} =
611         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
612     } qw(amount due paid);
613
614     if ($form->{"checked_$i"}) {
615
616       # calculate paid_$i
617       if (!$form->{"paid_$i"}) {
618         $form->{"paid_$i"} = $form->{"due_$i"};
619       }
620
621       $amount -= $form->{"paid_$i"};
622     } else {
623       $form->{"paid_$i"} = "";
624     }
625
626     map {
627       $form->{"${_}_$i"} =
628         $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
629     } qw(amount due paid);
630
631   }
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   &check_form;
644
645   if ($form->{currency} ne $form->{defaultcurrency}) {
646     $form->error($locale->text('Exchangerate missing!'))
647       unless $form->{exchangerate};
648   }
649
650   $msg1 = "$form->{origtitle} posted!";
651   $msg2 = "Cannot post $form->{origtitle}!";
652
653   # $locale->text('Payment posted!')
654   # $locale->text('Receipt posted!')
655   # $locale->text('Cannot post Payment!')
656   # $locale->text('Cannot post Receipt!')
657
658   $form->redirect($locale->text($msg1))
659     if (CP->process_payment(\%myconfig, \%$form));
660   $form->error($locale->text($msg2));
661
662   $lxdebug->leave_sub();
663 }
664
665 sub print {
666   $lxdebug->enter_sub();
667
668   &check_form;
669
670   ($whole, $form->{decimal}) = split /\./, $form->{amount};
671
672   $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
673
674   $form->{decimal} .= "00";
675   $form->{decimal} = substr($form->{decimal}, 0, 2);
676
677   $check = new CP $myconfig{countrycode};
678   $check->init;
679   $form->{text_amount} = $check->num2text($whole);
680
681   &{"$form->{vc}_details"};
682
683   $form->{callback} = "";
684
685   $form->{templates} = "$myconfig{templates}";
686   $form->{IN}        = "$form->{formname}.tex";
687
688   if ($form->{format} eq 'postscript') {
689     $form->{postscript} = 1;
690   }
691   if ($form->{format} eq 'pdf') {
692     $form->{pdf} = 1;
693   }
694
695   if ($form->{media} eq 'printer') {
696     $form->{OUT} = "| $myconfig{printer}";
697   }
698   if ($form->{media} eq 'queue') {
699     %queued = split / /, $form->{queued};
700
701     if ($filename = $queued{ $form->{formname} }) {
702       unlink "$spool/$filename";
703       $filename =~ s/\..*$//g;
704     } else {
705       $filename = time;
706       $filename .= $$;
707     }
708     $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
709     $form->{queued} = "$form->{formname} $filename";
710     $form->{OUT}    = ">$spool/$filename";
711
712     $form->update_status(\%myconfig);
713
714   }
715
716   $form->{company} = $myconfig{company};
717   $form->{address} = $myconfig{address};
718
719   @a =
720     qw(name invnumber company address text_amount street zipcode city country memo);
721   $form->format_string(@a);
722
723   $form->parse_template(\%myconfig, $userspath);
724
725   if ($form->{media} ne 'screen') {
726     $form->{callback} =
727       "$form->{script}?action=payment&vc=$form->{vc}&path=$form->{path}&login=$form->{login}&password=$form->{password}&all_vc=$form->{all_vc}";
728
729     $form->redirect if (CP->process_payment(\%myconfig, \%$form));
730     $form->error($locale->text('Cannot post payment!'));
731   }
732
733   $lxdebug->leave_sub();
734 }
735
736 sub customer_details { IS->customer_details(\%myconfig, \%$form) }
737 sub vendor_details { IR->vendor_details(\%myconfig, \%$form) }
738
739 sub check_form {
740   $lxdebug->enter_sub();
741
742   &check_name($form->{vc});
743
744   if ($form->{currency} ne $form->{oldcurrency}) {
745     &update;
746     exit;
747   }
748
749   $form->error($locale->text('Date missing!')) unless $form->{datepaid};
750
751   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
752   $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
753
754   $form->error($locale->text('Cannot process payment for a closed period!'))
755     if ($datepaid <= $closedto);
756
757   $amount = $form->parse_amount(\%myconfig, $form->{amount});
758   $form->{amount} = $amount;
759
760   for $i (1 .. $form->{rowcount}) {
761     if ($form->{"paid_$i"}) {
762       $amount -= $form->parse_amount($myconfig, $form->{"paid_$i"});
763
764       push(@{ $form->{paid} },      $form->{"paid_$i"});
765       push(@{ $form->{due} },       $form->{"due_$i"});
766       push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
767       push(@{ $form->{invdate} },   $form->{"transdate_$i"});
768     }
769   }
770
771   if ($form->round_amount($amount, 2) != 0) {
772     push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
773     push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
774     push(@{ $form->{invnumber} },
775          ($form->{ARAP} eq 'AR')
776          ? $locale->text('Deposit')
777          : $locale->text('Prepayment'));
778     push(@{ $form->{invdate} }, $form->{datepaid});
779   }
780
781   $lxdebug->leave_sub();
782 }