1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
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.
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 #======================================================================
32 #======================================================================
39 require "$form->{path}/arap.pl";
46 $lxdebug->enter_sub();
48 $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
49 $form->{arap} = lc $form->{ARAP};
51 # setup customer/vendor selection for open invoices
52 if ($form->{all_vc}) {
53 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
55 CP->get_openvc(\%myconfig, \%$form);
58 $form->{"select$form->{vc}"} = "";
60 if ($form->{"all_$form->{vc}"}) {
61 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
62 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
63 @{ $form->{"all_$form->{vc}"} };
67 if (@{ $form->{all_departments} }) {
68 $form->{selectdepartment} = "<option>\n";
69 $form->{department} = "$form->{department}--$form->{department_id}";
72 $form->{selectdepartment} .=
73 "<option>$_->{description}--$_->{id}\n"
74 } (@{ $form->{all_departments} });
77 CP->paymentaccounts(\%myconfig, \%$form);
79 $form->{selectaccount} = "";
80 $form->{"select$form->{ARAP}"} = "";
82 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
83 @{ $form->{PR}{"$form->{ARAP}_paid"} };
85 $form->{"select$form->{ARAP}"} .=
86 "<option>$_->{accno}--$_->{description}\n"
87 } @{ $form->{PR}{ $form->{ARAP} } };
90 @curr = split /:/, $form->{currencies};
92 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
95 $form->{selectcurrency} = "";
96 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
98 $form->{media} = "screen";
103 $lxdebug->leave_sub();
107 $lxdebug->enter_sub();
109 $vclabel = ucfirst $form->{vc};
110 $vclabel = $locale->text($vclabel);
112 if ($form->{type} eq 'receipt') {
113 $form->{title} = $locale->text('Receipt');
114 $form->{origtitle} = "Receipt";
116 if ($form->{type} eq 'check') {
117 $form->{title} = $locale->text('Payment');
118 $form->{origtitle} = "Payment";
121 # $locale->text('Customer')
122 # $locale->text('Vendor')
124 if ($form->{ $form->{vc} } eq "") {
125 map { $form->{"addr$_"} = "" } (1 .. 4);
128 if ($form->{currency} ne $form->{defaultcurrency}) {
129 $form->{exchangerate} =
130 $form->format_amount(\%myconfig, $form->{exchangerate});
131 if ($form->{forex}) {
134 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
135 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
141 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
142 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
148 foreach $item ($form->{vc}, account, currency, $form->{ARAP}, department) {
149 $form->{"select$item"} =~ s/ selected//;
150 $form->{"select$item"} =~
151 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
155 ($form->{"select$form->{vc}"})
156 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
157 : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
159 if ($form->{all_vc}) {
161 $form->{openinvoices} = "";
164 $form->{openinvoices} = 1;
167 # $locale->text('AR')
168 # $locale->text('AP')
172 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
173 <td><select name=department>$form->{selectdepartment}</select>
174 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
178 | if $form->{selectdepartment};
180 $form->{jsscript} = $jscalendar;
182 if ($form->{jsscript}) {
184 # with JavaScript Calendar
186 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}">
187 <input type=button name=datepaid id="trigger1" value=|
188 . $locale->text('button') . qq|></td>
193 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
196 # without JavaScript Calendar
198 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
203 $arap = lc $form->{ARAP};
208 <form method=post action=$form->{script}>
210 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
211 <input type=hidden name=closedto value=$form->{closedto}>
212 <input type=hidden name=vc value=$form->{vc}>
213 <input type=hidden name=type value=$form->{type}>
214 <input type=hidden name=formname value=$form->{type}>
215 <input type=hidden name=queued value="$form->{queued}">
216 <input type=hidden name=arap value=$arap>
217 <input type=hidden name=ARAP value=$form->{ARAP}>
218 <input type=hidden name=openinvoices value=$form->{openinvoices}>
219 <input type=hidden name=title value="$form->{title}">
220 <input type=hidden name=origtitle value="$form->{origtitle}">
224 <th class=listtop>$form->{title}</th>
235 <input name=all_vc type=checkbox style=checkbox value=Y $allvc>
236 <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
237 <th align=left>| . $locale->text('All') . qq|</th>
240 <th align=right>$vclabel</th>
242 <input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">
243 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
244 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
247 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
251 <td>$form->{street}</td>
254 <td>$form->{zipcode}</td>
257 <td>$form->{city}</td>
260 <td>$form->{country}</td>
264 <input type=hidden name=street value="$form->{street}">
265 <input type=hidden name=zipcode value="$form->{zipcode}">
266 <input type=hidden name=city value="$form->{city}">
267 <input type=hidden name=country value="$form->{country}">
270 <th align=right>| . $locale->text('Memo') . qq|</th>
271 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
279 <th align=right nowrap>| . $locale->text($form->{ARAP}) . qq|</th>
280 <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
282 <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
285 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
286 <td colspan=3><select name=account>$form->{selectaccount}</select>
287 <input type=hidden name=selectaccount value="$form->{selectaccount}">
291 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
295 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
296 <td><select name=currency>$form->{selectcurrency}</select></td>
297 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
298 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
302 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
303 <td colspan=3><input name=source value="$form->{source}" size=10></td>
306 <th align=right nowrap>| . $locale->text('Amount') . qq|</th>
307 <td colspan=3><input name=amount size=10 value=|
308 . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|></td>
320 $lxdebug->leave_sub();
324 $lxdebug->enter_sub();
326 @column_index = qw(invnumber transdate amount due checked paid);
328 $colspan = $#column_index + 1;
330 $invoice = $locale->text('Invoices');
333 <input type=hidden name=column_index value="id @column_index">
338 <th class=listheading colspan=$colspan>$invoice</th>
342 $column_data{invnumber} =
343 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
344 $column_data{transdate} =
345 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
346 $column_data{amount} =
347 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
349 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
351 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
352 $column_data{checked} =
353 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
358 map { print "$column_data{$_}\n" } @column_index;
363 for $i (1 .. $form->{rowcount}) {
367 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
368 } qw(amount due paid);
370 $totalamount += $form->{"amount_$i"};
371 $totaldue += $form->{"due_$i"};
372 $totalpaid += $form->{"paid_$i"};
376 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
377 } qw(amount due paid);
379 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
380 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
381 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
382 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
383 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
384 $column_data{amount} =
385 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
386 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
387 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
388 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
391 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
393 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
394 $column_data{checked} =
395 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
402 map { print "$column_data{$_}\n" } @column_index;
408 map { $column_data{$_} = "<td> </td>" } @column_index;
410 $column_data{amount} =
411 qq|<th class=listtotal align=right>|
412 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
415 qq|<th class=listtotal align=right>|
416 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
419 qq|<th class=listtotal align=right>|
420 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
426 map { print "$column_data{$_}\n" } @column_index;
434 $lxdebug->leave_sub();
438 $lxdebug->enter_sub();
440 $form->{DF}{ $form->{format} } = "selected";
441 $form->{OP}{ $form->{media} } = "selected";
444 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
446 if ($myconfig{printer} && $latex_templates) {
448 <option value=printer $form->{OP}{printer}>|
449 . $locale->text('Printer');
451 if ($latex_templates) {
453 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
455 <option value=postscript $form->{DF}{postscript}>|
456 . $locale->text('Postscript') . qq|
457 <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
462 <td><hr size=3 noshade></td>
465 <input type=hidden name=rowcount value=$form->{rowcount}>
467 <input type=hidden name=path value=$form->{path}>
468 <input type=hidden name=login value=$form->{login}>
469 <input type=hidden name=password value=$form->{password}>
472 <input class=submit type=submit name=action value="|
473 . $locale->text('Update') . qq|">
474 <input class=submit type=submit name=action value="|
475 . $locale->text('Post') . qq|">|;
477 if ($latex_templates) {
479 <input class=submit type=submit name=action value="|
480 . $locale->text('Print') . qq|">|;
484 <select name=format>$format</select>
485 <select name=media>$media</select>
493 $lxdebug->leave_sub();
497 $lxdebug->enter_sub();
499 my ($new_name_selected) = @_;
501 if ($form->{vc} eq 'customer') {
507 # if we switched to all_vc
508 if ($form->{all_vc} ne $form->{oldall_vc}) {
510 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
512 $form->{"select$form->{vc}"} = "";
514 if ($form->{all_vc}) {
515 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
517 if ($form->{"all_$form->{vc}"}) {
519 $form->{"select$form->{vc}"} .=
520 "<option>$_->{name}--$_->{id}\n"
521 } @{ $form->{"all_$form->{vc}"} };
524 CP->get_openvc(\%myconfig, \%$form);
526 if ($form->{"all_$form->{vc}"}) {
528 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
530 $form->{"select$form->{vc}"} .=
531 "<option>$_->{name}--$_->{id}\n"
532 } @{ $form->{"all_$form->{vc}"} };
535 # if the name is not the same
536 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
537 $form->{ $form->{vc} } = $newvc;
542 # get customer and invoices
543 $updated = &check_name($form->{vc});
545 if ($new_name_selected || $updated) {
546 CP->get_openinvoices(\%myconfig, \%$form);
547 ($newvc) = split /--/, $form->{ $form->{vc} };
548 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
552 if ($form->{currency} ne $form->{oldcurrency}) {
553 $form->{oldcurrency} = $form->{currency};
555 CP->get_openinvoices(\%myconfig, \%$form);
560 $form->{exchangerate} = $exchangerate
564 $form->check_exchangerate(
565 \%myconfig, $form->{currency}, $form->{datepaid}, $buysell
568 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
571 $form->{rowcount} = 0;
573 $form->{queued} = "";
576 foreach $ref (@{ $form->{PR} }) {
578 $form->{"id_$i"} = $ref->{id};
579 $form->{"invnumber_$i"} = $ref->{invnumber};
580 $form->{"transdate_$i"} = $ref->{transdate};
581 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
582 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
584 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
585 $form->{"checked_$i"} = "";
586 $form->{"paid_$i"} = "";
591 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
595 $form->{rowcount} = $i;
600 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
601 # payment amount in Zahlungsausgang
603 for $i (1 .. $form->{rowcount}) {
607 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
608 } qw(amount due paid);
610 if ($form->{"checked_$i"}) {
613 if (!$form->{"paid_$i"}) {
614 $form->{"paid_$i"} = $form->{"due_$i"};
617 # Modified by J.Zach, see abovev
618 $amount += $form->{"paid_$i"};
621 $form->{"paid_$i"} = "";
626 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
627 } qw(amount due paid);
631 # Line added by J.Zach, see above
632 $form->{amount}=$amount;
638 $lxdebug->leave_sub();
642 $lxdebug->enter_sub();
646 if ($form->{currency} ne $form->{defaultcurrency}) {
647 $form->error($locale->text('Exchangerate missing!'))
648 unless $form->{exchangerate};
651 $msg1 = "$form->{origtitle} posted!";
652 $msg2 = "Cannot post $form->{origtitle}!";
654 # $locale->text('Payment posted!')
655 # $locale->text('Receipt posted!')
656 # $locale->text('Cannot post Payment!')
657 # $locale->text('Cannot post Receipt!')
659 $form->redirect($locale->text($msg1))
660 if (CP->process_payment(\%myconfig, \%$form));
661 $form->error($locale->text($msg2));
663 $lxdebug->leave_sub();
667 $lxdebug->enter_sub();
671 ($whole, $form->{decimal}) = split /\./, $form->{amount};
673 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
675 $form->{decimal} .= "00";
676 $form->{decimal} = substr($form->{decimal}, 0, 2);
678 $check = new CP $myconfig{countrycode};
680 $form->{text_amount} = $check->num2text($whole);
682 &{"$form->{vc}_details"};
684 $form->{callback} = "";
686 $form->{templates} = "$myconfig{templates}";
687 $form->{IN} = "$form->{formname}.tex";
689 if ($form->{format} eq 'postscript') {
690 $form->{postscript} = 1;
692 if ($form->{format} eq 'pdf') {
696 if ($form->{media} eq 'printer') {
697 $form->{OUT} = "| $myconfig{printer}";
699 if ($form->{media} eq 'queue') {
700 %queued = split / /, $form->{queued};
702 if ($filename = $queued{ $form->{formname} }) {
703 unlink "$spool/$filename";
704 $filename =~ s/\..*$//g;
709 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
710 $form->{queued} = "$form->{formname} $filename";
711 $form->{OUT} = ">$spool/$filename";
713 $form->update_status(\%myconfig);
717 $form->{company} = $myconfig{company};
718 $form->{address} = $myconfig{address};
720 $form->parse_template(\%myconfig, $userspath);
722 if ($form->{media} ne 'screen') {
724 "$form->{script}?action=payment&vc=$form->{vc}&path=$form->{path}&login=$form->{login}&password=$form->{password}&all_vc=$form->{all_vc}";
726 $form->redirect if (CP->process_payment(\%myconfig, \%$form));
727 $form->error($locale->text('Cannot post payment!'));
730 $lxdebug->leave_sub();
733 sub customer_details { IS->customer_details(\%myconfig, \%$form) }
734 sub vendor_details { IR->vendor_details(\%myconfig, \%$form) }
737 $lxdebug->enter_sub();
739 &check_name($form->{vc});
741 if ($form->{currency} ne $form->{oldcurrency}) {
746 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
748 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
749 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
751 $form->error($locale->text('Cannot process payment for a closed period!'))
752 if ($datepaid <= $closedto);
754 $amount = $form->parse_amount(\%myconfig, $form->{amount});
755 $form->{amount} = $amount;
757 for $i (1 .. $form->{rowcount}) {
758 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
759 $amount -= $form->parse_amount($myconfig, $form->{"paid_$i"});
761 push(@{ $form->{paid} }, $form->{"paid_$i"});
762 push(@{ $form->{due} }, $form->{"due_$i"});
763 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
764 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
768 if ($form->round_amount($amount, 2) != 0) {
769 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
770 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
771 push(@{ $form->{invnumber} },
772 ($form->{ARAP} eq 'AR')
773 ? $locale->text('Deposit')
774 : $locale->text('Prepayment'));
775 push(@{ $form->{invdate} }, $form->{datepaid});
778 $lxdebug->leave_sub();