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