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