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 use strict ("vars", "subs");
42 require "bin/mozilla/arap.pl";
43 require "bin/mozilla/common.pl";
45 our ($form, %myconfig, $lxdebug, $locale, $auth);
52 $lxdebug->enter_sub();
54 $auth->assert('cash');
58 $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
59 $form->{arap} = lc $form->{ARAP};
61 # setup customer/vendor selection for open invoices
62 if ($form->{all_vc}) {
63 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
65 CP->get_openvc(\%myconfig, \%$form);
68 $form->{"select$form->{vc}"} = "";
70 if ($form->{"all_$form->{vc}"}) {
71 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
72 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
73 @{ $form->{"all_$form->{vc}"} };
77 if (@{ $form->{all_departments} }) {
78 $form->{selectdepartment} = "<option>\n";
79 $form->{department} = "$form->{department}--$form->{department_id}";
82 $form->{selectdepartment} .=
83 "<option>$_->{description}--$_->{id}\n"
84 } (@{ $form->{all_departments} });
87 CP->paymentaccounts(\%myconfig, \%$form);
89 $form->{selectaccount} = "";
90 $form->{"select$form->{ARAP}"} = "";
92 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
93 @{ $form->{PR}{"$form->{ARAP}_paid"} };
95 $form->{"select$form->{ARAP}"} .=
96 "<option>$_->{accno}--$_->{description}\n"
97 } @{ $form->{PR}{ $form->{ARAP} } };
100 @curr = split(/:/, $form->{currencies});
102 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
105 $form->{selectcurrency} = "";
106 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
108 $form->{media} = "screen";
113 $lxdebug->leave_sub();
117 $lxdebug->enter_sub();
119 $auth->assert('cash');
121 my ($vc, $vclabel, $allvc, $arap, $department, $exchangerate);
122 my ($jsscript, $button1, $button2, $onload);
124 $vclabel = ucfirst $form->{vc};
125 $vclabel = $locale->text($vclabel);
127 if ($form->{type} eq 'receipt') {
128 $form->{title} = $locale->text('Receipt');
129 $form->{origtitle} = "Receipt";
131 if ($form->{type} eq 'check') {
132 $form->{title} = $locale->text('Payment');
133 $form->{origtitle} = "Payment";
136 # $locale->text('Customer')
137 # $locale->text('Vendor')
139 if ($form->{ $form->{vc} } eq "") {
140 map { $form->{"addr$_"} = "" } (1 .. 4);
143 if ($form->{currency} ne $form->{defaultcurrency}) {
144 $form->{exchangerate} =
145 $form->format_amount(\%myconfig, $form->{exchangerate});
146 if ($form->{forex}) {
149 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
150 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
156 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
157 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
163 foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}, "department") {
164 $form->{"select$item"} =~ s/ selected//;
165 $form->{"select$item"} =~
166 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
170 ($form->{"select$form->{vc}"})
171 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
172 : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
174 if ($form->{all_vc}) {
176 $form->{openinvoices} = "";
179 $form->{openinvoices} = 1;
182 # $locale->text('AR')
183 # $locale->text('AP')
187 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
188 <td><select name=department>$form->{selectdepartment}</select>
189 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
193 | if $form->{selectdepartment};
195 $form->{jsscript} = 1;
197 if ($form->{jsscript}) {
199 # with JavaScript Calendar
201 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
202 <input type=button name=datepaid id="trigger1" value=|
203 . $locale->text('button') . qq|></td>
208 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
211 # without JavaScript Calendar
213 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
215 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
218 $arap = lc $form->{ARAP};
219 $onload = qq|focus()|;
220 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
221 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
223 <body onLoad="$onload">
225 <form method=post action=cp.pl>
227 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
228 <input type=hidden name=closedto value=$form->{closedto}>
229 <input type=hidden name=vc value=$form->{vc}>
230 <input type=hidden name=type value=$form->{type}>
231 <input type=hidden name=formname value=$form->{type}>
232 <input type=hidden name=queued value="$form->{queued}">
233 <input type=hidden name=arap value=$arap>
234 <input type=hidden name=ARAP value=$form->{ARAP}>
235 <input type=hidden name=openinvoices value=$form->{openinvoices}>
236 <input type=hidden name=title value="$form->{title}">
237 <input type=hidden name=origtitle value="$form->{origtitle}">
241 <th class=listtop>$form->{title}</th>
252 <input name=all_vc type=checkbox style=checkbox value=Y $allvc>
253 <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
254 <th align=left>| . $locale->text('All') . qq|</th>
257 <th align=right>$vclabel</th>
259 <input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">
260 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
261 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
264 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
268 <td>$form->{street}</td>
271 <td>$form->{zipcode}</td>
274 <td>$form->{city}</td>
277 <td>$form->{country}</td>
281 <input type=hidden name=street value="$form->{street}">
282 <input type=hidden name=zipcode value="$form->{zipcode}">
283 <input type=hidden name=city value="$form->{city}">
284 <input type=hidden name=country value="$form->{country}">
287 <th align=right>| . $locale->text('Memo') . qq|</th>
288 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
296 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
297 <td colspan=3><select name=account>$form->{selectaccount}</select>
298 <input type=hidden name=selectaccount value="$form->{selectaccount}">
302 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
306 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
307 <td><select name=currency>$form->{selectcurrency}</select></td>
308 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
309 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
313 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
314 <td colspan=3><input name=source value="$form->{source}" size=10></td>
317 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
318 <td colspan="3"><input name="amount" size="10" value="|
319 . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|" onBlur=\"check_right_number_format(this)\"></td>
331 $lxdebug->leave_sub();
335 $lxdebug->enter_sub();
337 $auth->assert('cash');
339 my (@column_index, %column_data, $colspan, $invoice);
340 my ($totalamount, $totaldue, $totalpaid);
342 @column_index = qw(invnumber transdate amount due checked paid);
344 $colspan = $#column_index + 1;
346 $invoice = $locale->text('Invoices');
349 <input type=hidden name=column_index value="id @column_index">
354 <th class=listheading colspan=$colspan>$invoice</th>
358 $column_data{invnumber} =
359 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
360 $column_data{transdate} =
361 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
362 $column_data{amount} =
363 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
365 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
367 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
368 $column_data{checked} =
369 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
374 map { print "$column_data{$_}\n" } @column_index;
379 for my $i (1 .. $form->{rowcount}) {
385 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
386 } qw(amount due paid);
388 $totalamount += $form->{"amount_$i"};
389 $totaldue += $form->{"due_$i"};
390 $totalpaid += $form->{"paid_$i"};
394 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
395 } qw(amount due paid);
397 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
398 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
399 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
400 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
401 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
402 $column_data{amount} =
403 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
404 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
405 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
406 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
409 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
411 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
412 $column_data{checked} =
413 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
420 map { print "$column_data{$_}\n" } @column_index;
426 map { $column_data{$_} = "<td> </td>" } @column_index;
428 $column_data{amount} =
429 qq|<th class=listtotal align=right>|
430 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
433 qq|<th class=listtotal align=right>|
434 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
437 qq|<th class=listtotal align=right>|
438 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
444 map { print "$column_data{$_}\n" } @column_index;
452 $lxdebug->leave_sub();
456 $lxdebug->enter_sub();
458 $auth->assert('cash');
460 my ($media, $format, $latex_templates);
462 $form->{DF}{ $form->{format} } = "selected";
463 $form->{OP}{ $form->{media} } = "selected";
466 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
468 if ($myconfig{printer} && $latex_templates) {
470 <option value=printer $form->{OP}{printer}>|
471 . $locale->text('Printer');
473 if ($latex_templates) {
475 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
477 <option value=postscript $form->{DF}{postscript}>|
478 . $locale->text('Postscript') . qq|
479 <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
484 <td><hr size=3 noshade></td>
487 <input type=hidden name=rowcount value=$form->{rowcount}>
490 <input class=submit type=submit name=action value="|
491 . $locale->text('Update') . qq|">
492 <input class=submit type=submit name=action value="|
493 . $locale->text('Post') . qq|">|;
495 if ($latex_templates) {
497 <input class=submit type=submit name=action value="|
498 . $locale->text('Print') . qq|">|;
502 <select name=format>$format</select>
503 <select name=media>$media</select>
511 $lxdebug->leave_sub();
515 $lxdebug->enter_sub();
517 $auth->assert('cash');
519 my ($new_name_selected) = @_;
521 my ($buysell, $newvc, $updated, $exchangerate, $amount);
523 if ($form->{vc} eq 'customer') {
529 # if we switched to all_vc
530 if ($form->{all_vc} ne $form->{oldall_vc}) {
532 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
534 $form->{"select$form->{vc}"} = "";
536 if ($form->{all_vc}) {
537 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
539 if ($form->{"all_$form->{vc}"}) {
541 $form->{"select$form->{vc}"} .=
542 "<option>$_->{name}--$_->{id}\n"
543 } @{ $form->{"all_$form->{vc}"} };
546 CP->get_openvc(\%myconfig, \%$form);
548 if ($form->{"all_$form->{vc}"}) {
550 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
552 $form->{"select$form->{vc}"} .=
553 "<option>$_->{name}--$_->{id}\n"
554 } @{ $form->{"all_$form->{vc}"} };
557 # if the name is not the same
558 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
559 $form->{ $form->{vc} } = $newvc;
564 # get customer and invoices
565 $updated = &check_name($form->{vc});
567 if ($new_name_selected || $updated) {
568 CP->get_openinvoices(\%myconfig, \%$form);
569 ($newvc) = split /--/, $form->{ $form->{vc} };
570 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
574 if ($form->{currency} ne $form->{oldcurrency}) {
575 $form->{oldcurrency} = $form->{currency};
577 CP->get_openinvoices(\%myconfig, \%$form);
582 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
583 $form->{exchangerate} = $form->{forex} if $form->{forex};
585 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
588 $form->{rowcount} = 0;
590 $form->{queued} = "";
593 foreach my $ref (@{ $form->{PR} }) {
595 $form->{"id_$i"} = $ref->{id};
596 $form->{"invnumber_$i"} = $ref->{invnumber};
597 $form->{"transdate_$i"} = $ref->{transdate};
598 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
599 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
601 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
602 $form->{"checked_$i"} = "";
603 $form->{"paid_$i"} = "";
608 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
612 $form->{rowcount} = $i;
617 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
618 # payment amount in Zahlungsausgang
620 for my $i (1 .. $form->{rowcount}) {
624 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
625 } qw(amount due paid);
627 if ($form->{"checked_$i"}) {
630 if (!$form->{"paid_$i"}) {
631 $form->{"paid_$i"} = $form->{"due_$i"};
634 # Modified by J.Zach, see abovev
635 $amount += $form->{"paid_$i"};
638 $form->{"paid_$i"} = "";
643 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
644 } qw(amount due paid);
648 # Line added by J.Zach, see above
649 $form->{amount}=$amount;
655 $lxdebug->leave_sub();
659 $lxdebug->enter_sub();
661 $auth->assert('cash');
665 if ($form->{currency} ne $form->{defaultcurrency}) {
666 $form->error($locale->text('Exchangerate missing!'))
667 unless $form->{exchangerate};
670 my $msg1 = "$form->{origtitle} posted!";
671 my $msg2 = "Cannot post $form->{origtitle}!";
673 # $locale->text('Payment posted!')
674 # $locale->text('Receipt posted!')
675 # $locale->text('Cannot post Payment!')
676 # $locale->text('Cannot post Receipt!')
678 $form->redirect($locale->text($msg1))
679 if (CP->process_payment(\%myconfig, \%$form));
680 $form->error($locale->text($msg2));
682 $lxdebug->leave_sub();
686 $lxdebug->enter_sub();
688 $auth->assert('cash');
690 my ($whole, $check, %queued, $spool, $filename, $userspath);
694 ($whole, $form->{decimal}) = split(/\./, $form->{amount});
696 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
698 #$form->{decimal} .= "00";
699 $form->{decimal} = substr($form->{decimal}, 0, 2);
701 $check = new CP $myconfig{countrycode};
703 $form->{text_amount} = $check->num2text($whole);
705 if ($form->{vc} eq 'customer') {
706 IS->customer_details(\%myconfig, $form);
708 IR->vendor_details(\%myconfig, $form);
711 $form->{callback} = "";
713 $form->{templates} = "$myconfig{templates}";
714 $form->{IN} = "$form->{formname}.tex";
716 if ($form->{format} eq 'postscript') {
717 $form->{postscript} = 1;
719 if ($form->{format} eq 'pdf') {
725 if ($form->{media} eq 'printer') {
726 $form->{OUT} = "| $myconfig{printer}";
728 if ($form->{media} eq 'queue') {
729 %queued = map { s|.*/|| } split / /, $form->{queued};
731 if ($filename = $queued{ $form->{formname} }) {
732 unlink "$spool/$filename";
733 $filename =~ s/\..*$//g;
738 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
739 $form->{queued} = "$form->{formname} $filename";
740 $form->{OUT} = ">$spool/$filename";
742 $form->update_status(\%myconfig);
746 $form->{company} = $myconfig{company};
747 $form->{address} = $myconfig{address};
749 $form->parse_template(\%myconfig, $userspath);
751 if ($form->{media} ne 'screen') {
752 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&all_vc=$form->{all_vc}";
754 $form->redirect if (CP->process_payment(\%myconfig, \%$form));
755 $form->error($locale->text('Cannot post payment!'));
758 $lxdebug->leave_sub();
762 $lxdebug->enter_sub();
764 $auth->assert('cash');
766 my ($closedto, $datepaid, $amount);
768 &check_name($form->{vc});
770 if ($form->{currency} ne $form->{oldcurrency}) {
775 $form->error($locale->text('Zero amount posting!')) if !$form->parse_amount(\%myconfig, $form->{amount});
776 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
778 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
779 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
781 $form->error($locale->text('Cannot process payment for a closed period!'))
782 if ($form->date_closed($form->{"datepaid"}, \%myconfig));
784 $amount = $form->parse_amount(\%myconfig, $form->{amount});
785 $form->{amount} = $amount;
787 for my $i (1 .. $form->{rowcount}) {
788 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
789 $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
791 push(@{ $form->{paid} }, $form->{"paid_$i"});
792 push(@{ $form->{due} }, $form->{"due_$i"});
793 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
794 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
798 if ($form->round_amount($amount, 2) != 0) {
799 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
800 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
801 push(@{ $form->{invnumber} },
802 ($form->{ARAP} eq 'AR')
803 ? $locale->text('Deposit')
804 : $locale->text('Prepayment'));
805 push(@{ $form->{invdate} }, $form->{datepaid});
808 $lxdebug->leave_sub();