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 #======================================================================
38 use strict ("vars", "subs");
41 require "bin/mozilla/arap.pl";
42 require "bin/mozilla/common.pl";
44 our ($form, %myconfig, $lxdebug, $locale, $auth);
51 $lxdebug->enter_sub();
53 $auth->assert('cash');
57 $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
58 $form->{arap} = lc $form->{ARAP};
60 # setup customer/vendor selection for open invoices
61 if ($form->{all_vc}) {
62 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
64 CP->get_openvc(\%myconfig, \%$form);
67 $form->{"select$form->{vc}"} = "";
69 if ($form->{"all_$form->{vc}"}) {
70 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
71 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
72 @{ $form->{"all_$form->{vc}"} };
76 if (@{ $form->{all_departments} || [] }) {
77 $form->{selectdepartment} = "<option>\n";
78 $form->{department} = "$form->{department}--$form->{department_id}";
81 $form->{selectdepartment} .=
82 "<option>$_->{description}--$_->{id}\n"
83 } (@{ $form->{all_departments} || [] });
86 CP->paymentaccounts(\%myconfig, \%$form);
88 $form->{selectaccount} = "";
89 $form->{"select$form->{ARAP}"} = "";
91 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
92 @{ $form->{PR}{"$form->{ARAP}_paid"} };
94 $form->{"select$form->{ARAP}"} .=
95 "<option>$_->{accno}--$_->{description}\n"
96 } @{ $form->{PR}{ $form->{ARAP} } };
99 @curr = split(/:/, $form->{currencies});
101 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
104 $form->{selectcurrency} = "";
105 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
107 $form->{media} = "screen";
112 $lxdebug->leave_sub();
116 $lxdebug->enter_sub();
118 $auth->assert('cash');
120 my ($vc, $vclabel, $allvc, $arap, $department, $exchangerate);
121 my ($jsscript, $button1, $button2, $onload);
123 $vclabel = ucfirst $form->{vc};
124 $vclabel = $locale->text($vclabel);
126 if ($form->{type} eq 'receipt') {
127 $form->{title} = $locale->text('Receipt');
128 $form->{origtitle} = "Receipt";
130 if ($form->{type} eq 'check') {
131 $form->{title} = $locale->text('Payment');
132 $form->{origtitle} = "Payment";
135 # $locale->text('Customer')
136 # $locale->text('Vendor')
138 if ($form->{ $form->{vc} } eq "") {
139 map { $form->{"addr$_"} = "" } (1 .. 4);
142 if ($form->{currency} ne $form->{defaultcurrency}) {
143 $form->{exchangerate} =
144 $form->format_amount(\%myconfig, $form->{exchangerate});
145 if ($form->{forex}) {
148 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
149 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
155 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
156 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
162 foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}, "department") {
163 $form->{"select$item"} =~ s/ selected//;
164 $form->{"select$item"} =~
165 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
169 ($form->{"select$form->{vc}"})
170 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
171 : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
173 if ($form->{all_vc}) {
175 $form->{openinvoices} = "";
178 $form->{openinvoices} = 1;
181 # $locale->text('AR')
182 # $locale->text('AP')
184 $form->{jsscript} = 1;
186 if ($form->{jsscript}) {
188 # with JavaScript Calendar
190 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
191 <input type=button name=datepaid id="trigger1" value=|
192 . $locale->text('button') . qq|></td>
197 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
200 # without JavaScript Calendar
202 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
204 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
207 $arap = lc $form->{ARAP};
208 $onload = qq|focus()|;
209 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
210 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
212 <body onLoad="$onload">
214 <form method=post action=cp.pl>
216 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
217 <input type=hidden name=closedto value=$form->{closedto}>
218 <input type=hidden name=vc value=$form->{vc}>
219 <input type=hidden name=type value=$form->{type}>
220 <input type=hidden name=formname value=$form->{type}>
221 <input type=hidden name=queued value="$form->{queued}">
222 <input type=hidden name=arap value=$arap>
223 <input type=hidden name=ARAP value=$form->{ARAP}>
224 <input type=hidden name=openinvoices value=$form->{openinvoices}>
225 <input type=hidden name=title value="$form->{title}">
226 <input type=hidden name=origtitle value="$form->{origtitle}">
230 <th class=listtop>$form->{title}</th>
241 <input name=all_vc type=checkbox style=checkbox value=Y $allvc>
242 <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
243 <th align=left>| . $locale->text('All') . qq|</th>
246 <th align=right>$vclabel</th>
248 <input type=hidden name="select$form->{vc}" value="| . H($form->{"select$form->{vc}"}) . qq|">
249 <input type=hidden name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
250 <input type=hidden name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
253 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
257 <td>$form->{street}</td>
260 <td>$form->{zipcode}</td>
263 <td>$form->{city}</td>
266 <td>$form->{country}</td>
270 <input type=hidden name=street value="$form->{street}">
271 <input type=hidden name=zipcode value="$form->{zipcode}">
272 <input type=hidden name=city value="$form->{city}">
273 <input type=hidden name=country value="$form->{country}">
276 <th align=right>| . $locale->text('Memo') . qq|</th>
277 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
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|" onBlur=\"check_right_number_format(this)\"></td>
320 if ($form->{openinvoices_other_currencies}) {
321 my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
322 : $::locale->text('There are #1 more open invoices from this vendor with other currencies.', $form->{openinvoices_other_currencies});
326 <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
328 <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
333 $lxdebug->leave_sub();
337 $lxdebug->enter_sub();
339 $auth->assert('cash');
341 my (@column_index, %column_data, $colspan, $invoice);
342 my ($totalamount, $totaldue, $totalpaid);
344 @column_index = qw(invnumber transdate amount due checked paid);
346 $colspan = $#column_index + 1;
348 $invoice = $locale->text('Invoices');
351 <input type=hidden name=column_index value="id @column_index">
356 <th class=listheading colspan=$colspan>$invoice</th>
360 $column_data{invnumber} =
361 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
362 $column_data{transdate} =
363 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
364 $column_data{amount} =
365 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
367 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
369 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
370 $column_data{checked} =
371 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
376 map { print "$column_data{$_}\n" } @column_index;
381 for my $i (1 .. $form->{rowcount}) {
387 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
388 } qw(amount due paid);
390 $totalamount += $form->{"amount_$i"};
391 $totaldue += $form->{"due_$i"};
392 $totalpaid += $form->{"paid_$i"};
396 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
397 } qw(amount due paid);
399 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
400 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
401 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
402 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
403 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
404 $column_data{amount} =
405 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
406 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
407 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
408 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
411 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
413 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
414 $column_data{checked} =
415 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
422 map { print "$column_data{$_}\n" } @column_index;
428 map { $column_data{$_} = "<td> </td>" } @column_index;
430 $column_data{amount} =
431 qq|<th class=listtotal align=right>|
432 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
435 qq|<th class=listtotal align=right>|
436 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
439 qq|<th class=listtotal align=right>|
440 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
446 map { print "$column_data{$_}\n" } @column_index;
454 $lxdebug->leave_sub();
458 $lxdebug->enter_sub();
460 $auth->assert('cash');
462 my ($media, $format, $latex_templates);
464 $form->{DF}{ $form->{format} } = "selected";
465 $form->{OP}{ $form->{media} } = "selected";
468 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
470 if ($myconfig{printer} && $latex_templates) {
472 <option value=printer $form->{OP}{printer}>|
473 . $locale->text('Printer');
475 if ($latex_templates) {
477 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
479 <option value=postscript $form->{DF}{postscript}>|
480 . $locale->text('Postscript') . qq|
481 <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
486 <td><hr size=3 noshade></td>
489 <input type=hidden name=rowcount value=$form->{rowcount}>
492 <input class=submit type=submit name=action value="|
493 . $locale->text('Update') . qq|">
494 <input class=submit type=submit name=action value="|
495 . $locale->text('Post') . qq|">|;
497 if ($latex_templates) {
499 <input class=submit type=submit name=action value="|
500 . $locale->text('Print') . qq|">|;
504 <select name=format>$format</select>
505 <select name=media>$media</select>
513 $lxdebug->leave_sub();
517 $lxdebug->enter_sub();
519 $auth->assert('cash');
521 my ($new_name_selected) = @_;
523 my ($buysell, $newvc, $updated, $exchangerate, $amount);
525 if ($form->{vc} eq 'customer') {
531 # if we switched to all_vc
532 if ($form->{all_vc} ne $form->{oldall_vc}) {
534 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
536 $form->{"select$form->{vc}"} = "";
538 if ($form->{all_vc}) {
539 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
541 if ($form->{"all_$form->{vc}"}) {
543 $form->{"select$form->{vc}"} .=
544 "<option>$_->{name}--$_->{id}\n"
545 } @{ $form->{"all_$form->{vc}"} };
548 CP->get_openvc(\%myconfig, \%$form);
550 if ($form->{"all_$form->{vc}"}) {
552 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
554 $form->{"select$form->{vc}"} .=
555 "<option>$_->{name}--$_->{id}\n"
556 } @{ $form->{"all_$form->{vc}"} };
559 # if the name is not the same
560 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
561 $form->{ $form->{vc} } = $newvc;
566 # get customer and invoices
567 $updated = &check_name($form->{vc});
569 if ($new_name_selected || $updated) {
570 CP->get_openinvoices(\%myconfig, \%$form);
571 ($newvc) = split /--/, $form->{ $form->{vc} };
572 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
576 if ($form->{currency} ne $form->{oldcurrency}) {
577 $form->{oldcurrency} = $form->{currency};
579 CP->get_openinvoices(\%myconfig, \%$form);
584 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
585 $form->{exchangerate} = $form->{forex} if $form->{forex};
587 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
590 $form->{rowcount} = 0;
592 $form->{queued} = "";
595 foreach my $ref (@{ $form->{PR} }) {
597 $form->{"id_$i"} = $ref->{id};
598 $form->{"invnumber_$i"} = $ref->{invnumber};
599 $form->{"transdate_$i"} = $ref->{transdate};
600 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
601 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
603 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
604 $form->{"checked_$i"} = "";
605 $form->{"paid_$i"} = "";
610 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
614 $form->{rowcount} = $i;
619 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
620 # payment amount in Zahlungsausgang
622 for my $i (1 .. $form->{rowcount}) {
626 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
627 } qw(amount due paid);
629 if ($form->{"checked_$i"}) {
632 if (!$form->{"paid_$i"}) {
633 $form->{"paid_$i"} = $form->{"due_$i"};
636 # Modified by J.Zach, see abovev
637 $amount += $form->{"paid_$i"};
640 $form->{"paid_$i"} = "";
645 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
646 } qw(amount due paid);
650 # Line added by J.Zach, see above
651 $form->{amount}=$amount;
657 $lxdebug->leave_sub();
661 $lxdebug->enter_sub();
663 $auth->assert('cash');
667 if ($form->{currency} ne $form->{defaultcurrency}) {
668 $form->error($locale->text('Exchangerate missing!'))
669 unless $form->{exchangerate};
672 my $msg1 = "$form->{origtitle} posted!";
673 my $msg2 = "Cannot post $form->{origtitle}!";
675 # $locale->text('Payment posted!')
676 # $locale->text('Receipt posted!')
677 # $locale->text('Cannot post Payment!')
678 # $locale->text('Cannot post Receipt!')
680 $form->redirect($locale->text($msg1))
681 if (CP->process_payment(\%myconfig, \%$form));
682 $form->error($locale->text($msg2));
684 $lxdebug->leave_sub();
688 $lxdebug->enter_sub();
690 $auth->assert('cash');
692 my ($whole, $check, %queued, $spool, $filename, $userspath);
696 ($whole, $form->{decimal}) = split(/\./, $form->{amount});
698 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
700 #$form->{decimal} .= "00";
701 $form->{decimal} = substr($form->{decimal}, 0, 2);
703 $check = new CP $myconfig{countrycode};
705 $form->{text_amount} = $check->num2text($whole);
707 if ($form->{vc} eq 'customer') {
708 IS->customer_details(\%myconfig, $form);
710 IR->vendor_details(\%myconfig, $form);
713 $form->{callback} = "";
715 $form->{templates} = "$myconfig{templates}";
716 $form->{IN} = "$form->{formname}.tex";
718 if ($form->{format} eq 'postscript') {
719 $form->{postscript} = 1;
721 if ($form->{format} eq 'pdf') {
727 if ($form->{media} eq 'printer') {
728 $form->{OUT} = "| $myconfig{printer}";
730 if ($form->{media} eq 'queue') {
731 %queued = map { s|.*/|| } split / /, $form->{queued};
733 if ($filename = $queued{ $form->{formname} }) {
734 unlink "$spool/$filename";
735 $filename =~ s/\..*$//g;
740 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
741 $form->{queued} = "$form->{formname} $filename";
742 $form->{OUT} = ">$spool/$filename";
744 $form->update_status(\%myconfig);
748 $form->{company} = $myconfig{company};
749 $form->{address} = $myconfig{address};
751 $form->parse_template(\%myconfig, $userspath);
753 if ($form->{media} ne 'screen') {
754 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&all_vc=$form->{all_vc}";
756 $form->redirect if (CP->process_payment(\%myconfig, \%$form));
757 $form->error($locale->text('Cannot post payment!'));
760 $lxdebug->leave_sub();
764 $lxdebug->enter_sub();
766 $auth->assert('cash');
768 my ($closedto, $datepaid, $amount);
770 &check_name($form->{vc});
772 if ($form->{currency} ne $form->{oldcurrency}) {
777 $form->error($locale->text('Zero amount posting!')) if !$form->parse_amount(\%myconfig, $form->{amount});
778 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
780 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
781 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
783 $form->error($locale->text('Cannot process payment for a closed period!'))
784 if ($form->date_closed($form->{"datepaid"}, \%myconfig));
786 $amount = $form->parse_amount(\%myconfig, $form->{amount});
787 $form->{amount} = $amount;
789 for my $i (1 .. $form->{rowcount}) {
790 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
791 $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
793 push(@{ $form->{paid} }, $form->{"paid_$i"});
794 push(@{ $form->{due} }, $form->{"due_$i"});
795 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
796 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
800 if ($form->round_amount($amount, 2) != 0) {
801 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
802 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
803 push(@{ $form->{invnumber} },
804 ($form->{ARAP} eq 'AR')
805 ? $locale->text('Deposit')
806 : $locale->text('Prepayment'));
807 push(@{ $form->{invdate} }, $form->{datepaid});
810 $lxdebug->leave_sub();