Alle Dateien durch Perltidy laufen lassen. Die verwendeten Optionen sind am Ende...
[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')
189       . qq|></td>
190        |;
191
192     #write Trigger
193     $jsscript =
194       Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1", "",
195                           "", "");
196   } else {
197
198     # without JavaScript Calendar
199     $button1 = qq|
200                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
201   }
202
203   $form->header;
204
205   $arap = lc $form->{ARAP};
206
207   print qq|
208 <body>
209
210 <form method=post action=$form->{script}>
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                 <td align=right>
237                 <input name=all_vc type=checkbox style=checkbox value=Y $allvc>
238                 <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
239                 <th align=left>| . $locale->text('All') . qq|</th>
240               </tr>
241               <tr>
242                 <th align=right>$vclabel</th>
243                 <td>$vc</td>
244                 <input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">
245                 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
246                 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
247               </tr>
248               <tr valign=top>
249                 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
250                 <td colspan=2>
251                   <table>
252                     <tr>
253                       <td>$form->{street}</td>
254                     </tr>
255                     <tr>
256                       <td>$form->{zipcode}</td>
257                     </tr>
258                     <tr>
259                       <td>$form->{city}</td>
260                     </tr>
261                     <tr>
262                       <td>$form->{country}</td>
263                     </tr>
264                   </table>
265                 </td>
266                 <input type=hidden name=street value="$form->{street}">
267                 <input type=hidden name=zipcode value="$form->{zipcode}">
268                 <input type=hidden name=city value="$form->{city}">
269                 <input type=hidden name=country value="$form->{country}">
270               </tr>
271               <tr>
272                 <th align=right>| . $locale->text('Memo') . qq|</th>
273                 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
274               </tr>
275             </table>
276           </td>
277           <td align=right>
278             <table>
279               $department
280               <tr>
281                 <th align=right nowrap>| . $locale->text($form->{ARAP}) . qq|</th>
282                 <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
283                 </td>
284                 <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
285               </tr>
286               <tr>
287                 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
288                 <td colspan=3><select name=account>$form->{selectaccount}</select>
289                 <input type=hidden name=selectaccount value="$form->{selectaccount}">
290                 </td>
291               </tr>
292               <tr>
293                 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
294                 $button1
295               </tr>
296               <tr>
297                 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
298                 <td><select name=currency>$form->{selectcurrency}</select></td>
299                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
300                 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
301               </tr>
302               $exchangerate
303               <tr>
304                 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
305                 <td colspan=3><input name=source value="$form->{source}" size=10></td>
306               </tr>
307               <tr>
308                 <th align=right nowrap>| . $locale->text('Amount') . qq|</th>
309                 <td colspan=3><input name=amount size=10 value=|
310     . $form->format_amount(\%myconfig, $form->{amount}, 2)
311     . qq|></td>
312               </tr>
313             </table>
314           </td>
315         </tr>
316       </table>
317     </td>
318   </tr>
319   
320 $jsscript
321 |;
322
323   $lxdebug->leave_sub();
324 }
325
326 sub list_invoices {
327   $lxdebug->enter_sub();
328
329   @column_index = qw(invnumber transdate amount due checked paid);
330
331   $colspan = $#column_index + 1;
332
333   $invoice = $locale->text('Invoices');
334
335   print qq|
336   <input type=hidden name=column_index value="id @column_index">
337   <tr>
338     <td>
339       <table width=100%>
340         <tr>
341           <th class=listheading colspan=$colspan>$invoice</th>
342         </tr>
343 |;
344
345   $column_data{invnumber} =
346     qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
347   $column_data{transdate} =
348     qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
349   $column_data{amount} =
350     qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
351   $column_data{due} =
352     qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
353   $column_data{paid} =
354     qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
355   $column_data{checked} =
356     qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
357
358   print qq|
359         <tr>
360 |;
361   map { print "$column_data{$_}\n" } @column_index;
362   print qq|
363         </tr>
364 |;
365
366   for $i (1 .. $form->{rowcount}) {
367
368     map {
369       $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
370     } qw(amount due paid);
371
372     $totalamount += $form->{"amount_$i"};
373     $totaldue    += $form->{"due_$i"};
374     $totalpaid   += $form->{"paid_$i"};
375
376     map {
377       $form->{"${_}_$i"} =
378         $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
379     } qw(amount due paid);
380
381     $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
382       <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
383       <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
384     $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
385       <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
386     $column_data{amount} =
387       qq|<td align=right width=15%>$form->{"amount_$i"}</td>
388       <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
389     $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
390       <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
391
392     $column_data{paid} =
393       qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
394
395     $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
396     $column_data{checked} =
397       qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
398
399     $j++;
400     $j %= 2;
401     print qq|
402         <tr class=listrow$j>
403 |;
404     map { print "$column_data{$_}\n" } @column_index;
405     print qq|
406         </tr>
407 |;
408   }
409
410   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
411
412   $column_data{amount} =
413       qq|<th class=listtotal align=right>|
414     . $form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;")
415     . qq|</th>|;
416   $column_data{due} =
417       qq|<th class=listtotal align=right>|
418     . $form->format_amount(\%myconfig, $totaldue, 2, "&nbsp;")
419     . qq|</th>|;
420   $column_data{paid} =
421       qq|<th class=listtotal align=right>|
422     . $form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")
423     . qq|</th>|;
424
425   print qq|
426         <tr class=listtotal>
427 |;
428   map { print "$column_data{$_}\n" } @column_index;
429   print qq|
430         </tr>
431       </table>
432     </td>
433   </tr>
434 |;
435
436   $lxdebug->leave_sub();
437 }
438
439 sub form_footer {
440   $lxdebug->enter_sub();
441
442   $form->{DF}{ $form->{format} } = "selected";
443   $form->{OP}{ $form->{media} }  = "selected";
444
445   $media = qq|
446           <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
447
448   if ($myconfig{printer} && $latex) {
449     $media .= qq|
450           <option value=printer $form->{OP}{printer}>|
451       . $locale->text('Printer');
452   }
453   if ($latex) {
454     $media .= qq|
455           <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
456     $format .= qq|
457             <option value=postscript $form->{DF}{postscript}>|
458       . $locale->text('Postscript') . qq|
459             <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
460   }
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 <input type=hidden name=path value=$form->{path}>
470 <input type=hidden name=login value=$form->{login}>
471 <input type=hidden name=password value=$form->{password}>
472
473 <br>
474 <input class=submit type=submit name=action value="|
475     . $locale->text('Update') . qq|">
476 <input class=submit type=submit name=action value="|
477     . $locale->text('Post') . qq|">|;
478
479   if ($latex) {
480     print qq|
481 <input class=submit type=submit name=action value="|
482       . $locale->text('Print') . qq|">|;
483   }
484
485   print qq|
486 <select name=format>$format</select>
487 <select name=media>$media</select>
488 |;
489
490   if ($form->{menubar}) {
491     require "$form->{path}/menu.pl";
492     &menubar;
493   }
494
495   print qq|
496   </form>
497
498 </body>
499 </html>
500 |;
501
502   $lxdebug->leave_sub();
503 }
504
505 sub update {
506   $lxdebug->enter_sub();
507
508   my ($new_name_selected) = @_;
509
510   if ($form->{vc} eq 'customer') {
511     $buysell = "buy";
512   } else {
513     $buysell = "sell";
514   }
515
516   # if we switched to all_vc
517   if ($form->{all_vc} ne $form->{oldall_vc}) {
518
519     $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
520
521     $form->{"select$form->{vc}"} = "";
522
523     if ($form->{all_vc}) {
524       $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
525
526       if ($form->{"all_$form->{vc}"}) {
527         map {
528           $form->{"select$form->{vc}"} .=
529             "<option>$_->{name}--$_->{id}\n"
530         } @{ $form->{"all_$form->{vc}"} };
531       }
532     } else {
533       CP->get_openvc(\%myconfig, \%$form);
534
535       if ($form->{"all_$form->{vc}"}) {
536         $newvc =
537           qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
538         map {
539           $form->{"select$form->{vc}"} .=
540             "<option>$_->{name}--$_->{id}\n"
541         } @{ $form->{"all_$form->{vc}"} };
542       }
543
544       # if the name is not the same
545       if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
546         $form->{ $form->{vc} } = $newvc;
547       }
548     }
549   }
550
551   # get customer and invoices
552   $updated = &check_name($form->{vc});
553
554   if ($new_name_selected || $updated) {
555     CP->get_openinvoices(\%myconfig, \%$form);
556     ($newvc) = split /--/, $form->{ $form->{vc} };
557     $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
558     $updated = 1;
559   }
560
561   if ($form->{currency} ne $form->{oldcurrency}) {
562     $form->{oldcurrency} = $form->{currency};
563     if (!$updated) {
564       CP->get_openinvoices(\%myconfig, \%$form);
565       $updated = 1;
566     }
567   }
568
569   $form->{exchangerate} = $exchangerate
570     if (
571         $form->{forex} = (
572                    $exchangerate =
573                      $form->check_exchangerate(
574                      \%myconfig, $form->{currency}, $form->{datepaid}, $buysell
575                      )));
576
577   $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
578
579   if ($updated) {
580     $form->{rowcount} = 0;
581
582     $form->{queued} = "";
583
584     $i = 0;
585     foreach $ref (@{ $form->{PR} }) {
586       $i++;
587       $form->{"id_$i"}        = $ref->{id};
588       $form->{"invnumber_$i"} = $ref->{invnumber};
589       $form->{"transdate_$i"} = $ref->{transdate};
590       $ref->{exchangerate} = 1 unless $ref->{exchangerate};
591       $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
592       $form->{"due_$i"}    =
593         ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
594       $form->{"checked_$i"} = "";
595       $form->{"paid_$i"}    = "";
596
597       # need to format
598       map {
599         $form->{"${_}_$i"} =
600           $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
601       } qw(amount due);
602
603     }
604     $form->{rowcount} = $i;
605   }
606
607   # recalculate
608   $amount = $form->{amount};
609   for $i (1 .. $form->{rowcount}) {
610
611     map {
612       $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
613     } qw(amount due paid);
614
615     if ($form->{"checked_$i"}) {
616
617       # calculate paid_$i
618       if (!$form->{"paid_$i"}) {
619         $form->{"paid_$i"} = $form->{"due_$i"};
620       }
621
622       $amount -= $form->{"paid_$i"};
623     } else {
624       $form->{"paid_$i"} = "";
625     }
626
627     map {
628       $form->{"${_}_$i"} =
629         $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
630     } qw(amount due paid);
631
632   }
633
634   &form_header;
635   &list_invoices;
636   &form_footer;
637
638   $lxdebug->leave_sub();
639 }
640
641 sub post {
642   $lxdebug->enter_sub();
643
644   &check_form;
645
646   if ($form->{currency} ne $form->{defaultcurrency}) {
647     $form->error($locale->text('Exchangerate missing!'))
648       unless $form->{exchangerate};
649   }
650
651   $msg1 = "$form->{origtitle} posted!";
652   $msg2 = "Cannot post $form->{origtitle}!";
653
654   # $locale->text('Payment posted!')
655   # $locale->text('Receipt posted!')
656   # $locale->text('Cannot post Payment!')
657   # $locale->text('Cannot post Receipt!')
658
659   $form->redirect($locale->text($msg1))
660     if (CP->process_payment(\%myconfig, \%$form));
661   $form->error($locale->text($msg2));
662
663   $lxdebug->leave_sub();
664 }
665
666 sub print {
667   $lxdebug->enter_sub();
668
669   &check_form;
670
671   ($whole, $form->{decimal}) = split /\./, $form->{amount};
672
673   $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
674
675   $form->{decimal} .= "00";
676   $form->{decimal} = substr($form->{decimal}, 0, 2);
677
678   $check = new CP $myconfig{countrycode};
679   $check->init;
680   $form->{text_amount} = $check->num2text($whole);
681
682   &{"$form->{vc}_details"};
683
684   $form->{callback} = "";
685
686   $form->{templates} = "$myconfig{templates}";
687   $form->{IN}        = "$form->{formname}.tex";
688
689   if ($form->{format} eq 'postscript') {
690     $form->{postscript} = 1;
691   }
692   if ($form->{format} eq 'pdf') {
693     $form->{pdf} = 1;
694   }
695
696   if ($form->{media} eq 'printer') {
697     $form->{OUT} = "| $myconfig{printer}";
698   }
699   if ($form->{media} eq 'queue') {
700     %queued = split / /, $form->{queued};
701
702     if ($filename = $queued{ $form->{formname} }) {
703       unlink "$spool/$filename";
704       $filename =~ s/\..*$//g;
705     } else {
706       $filename = time;
707       $filename .= $$;
708     }
709     $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
710     $form->{queued} = "$form->{formname} $filename";
711     $form->{OUT}    = ">$spool/$filename";
712
713     $form->update_status(\%myconfig);
714
715   }
716
717   $form->{company} = $myconfig{company};
718   $form->{address} = $myconfig{address};
719
720   @a =
721     qw(name invnumber company address text_amount street zipcode city country memo);
722   $form->format_string(@a);
723
724   $form->parse_template(\%myconfig, $userspath);
725
726   if ($form->{media} ne 'screen') {
727     $form->{callback} =
728       "$form->{script}?action=payment&vc=$form->{vc}&path=$form->{path}&login=$form->{login}&password=$form->{password}&all_vc=$form->{all_vc}";
729
730     $form->redirect if (CP->process_payment(\%myconfig, \%$form));
731     $form->error($locale->text('Cannot post payment!'));
732   }
733
734   $lxdebug->leave_sub();
735 }
736
737 sub customer_details { IS->customer_details(\%myconfig, \%$form) }
738 sub vendor_details { IR->vendor_details(\%myconfig, \%$form) }
739
740 sub check_form {
741   $lxdebug->enter_sub();
742
743   &check_name($form->{vc});
744
745   if ($form->{currency} ne $form->{oldcurrency}) {
746     &update;
747     exit;
748   }
749
750   $form->error($locale->text('Date missing!')) unless $form->{datepaid};
751
752   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
753   $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
754
755   $form->error($locale->text('Cannot process payment for a closed period!'))
756     if ($datepaid <= $closedto);
757
758   $amount = $form->parse_amount(\%myconfig, $form->{amount});
759   $form->{amount} = $amount;
760
761   for $i (1 .. $form->{rowcount}) {
762     if ($form->{"paid_$i"}) {
763       $amount -= $form->parse_amount($myconfig, $form->{"paid_$i"});
764
765       push(@{ $form->{paid} },      $form->{"paid_$i"});
766       push(@{ $form->{due} },       $form->{"due_$i"});
767       push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
768       push(@{ $form->{invdate} },   $form->{"transdate_$i"});
769     }
770   }
771
772   if ($form->round_amount($amount, 2) != 0) {
773     push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
774     push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
775     push(@{ $form->{invnumber} },
776          ($form->{ARAP} eq 'AR')
777          ? $locale->text('Deposit')
778          : $locale->text('Prepayment'));
779     push(@{ $form->{invdate} }, $form->{datepaid});
780   }
781
782   $lxdebug->leave_sub();
783 }
784