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