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