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