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')
185 $form->{jsscript} = 1;
187 if ($form->{jsscript}) {
189 # with JavaScript Calendar
191 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
192 <input type=button name=datepaid id="trigger1" value=|
193 . $locale->text('button') . qq|></td>
198 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
201 # without JavaScript Calendar
203 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
205 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
208 $arap = lc $form->{ARAP};
209 $onload = qq|focus()|;
210 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
211 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
213 <body onLoad="$onload">
215 <form method=post action=cp.pl>
217 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
218 <input type=hidden name=closedto value=$form->{closedto}>
219 <input type=hidden name=vc value=$form->{vc}>
220 <input type=hidden name=type value=$form->{type}>
221 <input type=hidden name=formname value=$form->{type}>
222 <input type=hidden name=queued value="$form->{queued}">
223 <input type=hidden name=arap value=$arap>
224 <input type=hidden name=ARAP value=$form->{ARAP}>
225 <input type=hidden name=openinvoices value=$form->{openinvoices}>
226 <input type=hidden name=title value="$form->{title}">
227 <input type=hidden name=origtitle value="$form->{origtitle}">
231 <th class=listtop>$form->{title}</th>
242 <input name=all_vc type=checkbox style=checkbox value=Y $allvc>
243 <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
244 <th align=left>| . $locale->text('All') . qq|</th>
247 <th align=right>$vclabel</th>
249 <input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">
250 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
251 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
254 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
258 <td>$form->{street}</td>
261 <td>$form->{zipcode}</td>
264 <td>$form->{city}</td>
267 <td>$form->{country}</td>
271 <input type=hidden name=street value="$form->{street}">
272 <input type=hidden name=zipcode value="$form->{zipcode}">
273 <input type=hidden name=city value="$form->{city}">
274 <input type=hidden name=country value="$form->{country}">
277 <th align=right>| . $locale->text('Memo') . qq|</th>
278 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
286 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
287 <td colspan=3><select name=account>$form->{selectaccount}</select>
288 <input type=hidden name=selectaccount value="$form->{selectaccount}">
292 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
296 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
297 <td><select name=currency>$form->{selectcurrency}</select></td>
298 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
299 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
303 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
304 <td colspan=3><input name=source value="$form->{source}" size=10></td>
307 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
308 <td colspan="3"><input name="amount" size="10" value="|
309 . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|" onBlur=\"check_right_number_format(this)\"></td>
321 $lxdebug->leave_sub();
325 $lxdebug->enter_sub();
327 $auth->assert('cash');
329 my (@column_index, %column_data, $colspan, $invoice);
330 my ($totalamount, $totaldue, $totalpaid);
332 @column_index = qw(invnumber transdate amount due checked paid);
334 $colspan = $#column_index + 1;
336 $invoice = $locale->text('Invoices');
339 <input type=hidden name=column_index value="id @column_index">
344 <th class=listheading colspan=$colspan>$invoice</th>
348 $column_data{invnumber} =
349 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
350 $column_data{transdate} =
351 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
352 $column_data{amount} =
353 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
355 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
357 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
358 $column_data{checked} =
359 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
364 map { print "$column_data{$_}\n" } @column_index;
369 for my $i (1 .. $form->{rowcount}) {
375 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
376 } qw(amount due paid);
378 $totalamount += $form->{"amount_$i"};
379 $totaldue += $form->{"due_$i"};
380 $totalpaid += $form->{"paid_$i"};
384 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
385 } qw(amount due paid);
387 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
388 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
389 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
390 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
391 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
392 $column_data{amount} =
393 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
394 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
395 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
396 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
399 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
401 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
402 $column_data{checked} =
403 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
410 map { print "$column_data{$_}\n" } @column_index;
416 map { $column_data{$_} = "<td> </td>" } @column_index;
418 $column_data{amount} =
419 qq|<th class=listtotal align=right>|
420 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
423 qq|<th class=listtotal align=right>|
424 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
427 qq|<th class=listtotal align=right>|
428 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
434 map { print "$column_data{$_}\n" } @column_index;
442 $lxdebug->leave_sub();
446 $lxdebug->enter_sub();
448 $auth->assert('cash');
450 my ($media, $format, $latex_templates);
452 $form->{DF}{ $form->{format} } = "selected";
453 $form->{OP}{ $form->{media} } = "selected";
456 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
458 if ($myconfig{printer} && $latex_templates) {
460 <option value=printer $form->{OP}{printer}>|
461 . $locale->text('Printer');
463 if ($latex_templates) {
465 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
467 <option value=postscript $form->{DF}{postscript}>|
468 . $locale->text('Postscript') . qq|
469 <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
474 <td><hr size=3 noshade></td>
477 <input type=hidden name=rowcount value=$form->{rowcount}>
480 <input class=submit type=submit name=action value="|
481 . $locale->text('Update') . qq|">
482 <input class=submit type=submit name=action value="|
483 . $locale->text('Post') . qq|">|;
485 if ($latex_templates) {
487 <input class=submit type=submit name=action value="|
488 . $locale->text('Print') . qq|">|;
492 <select name=format>$format</select>
493 <select name=media>$media</select>
501 $lxdebug->leave_sub();
505 $lxdebug->enter_sub();
507 $auth->assert('cash');
509 my ($new_name_selected) = @_;
511 my ($buysell, $newvc, $updated, $exchangerate, $amount);
513 if ($form->{vc} eq 'customer') {
519 # if we switched to all_vc
520 if ($form->{all_vc} ne $form->{oldall_vc}) {
522 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
524 $form->{"select$form->{vc}"} = "";
526 if ($form->{all_vc}) {
527 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
529 if ($form->{"all_$form->{vc}"}) {
531 $form->{"select$form->{vc}"} .=
532 "<option>$_->{name}--$_->{id}\n"
533 } @{ $form->{"all_$form->{vc}"} };
536 CP->get_openvc(\%myconfig, \%$form);
538 if ($form->{"all_$form->{vc}"}) {
540 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
542 $form->{"select$form->{vc}"} .=
543 "<option>$_->{name}--$_->{id}\n"
544 } @{ $form->{"all_$form->{vc}"} };
547 # if the name is not the same
548 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
549 $form->{ $form->{vc} } = $newvc;
554 # get customer and invoices
555 $updated = &check_name($form->{vc});
557 if ($new_name_selected || $updated) {
558 CP->get_openinvoices(\%myconfig, \%$form);
559 ($newvc) = split /--/, $form->{ $form->{vc} };
560 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
564 if ($form->{currency} ne $form->{oldcurrency}) {
565 $form->{oldcurrency} = $form->{currency};
567 CP->get_openinvoices(\%myconfig, \%$form);
572 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
573 $form->{exchangerate} = $form->{forex} if $form->{forex};
575 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
578 $form->{rowcount} = 0;
580 $form->{queued} = "";
583 foreach my $ref (@{ $form->{PR} }) {
585 $form->{"id_$i"} = $ref->{id};
586 $form->{"invnumber_$i"} = $ref->{invnumber};
587 $form->{"transdate_$i"} = $ref->{transdate};
588 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
589 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
591 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
592 $form->{"checked_$i"} = "";
593 $form->{"paid_$i"} = "";
598 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
602 $form->{rowcount} = $i;
607 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
608 # payment amount in Zahlungsausgang
610 for my $i (1 .. $form->{rowcount}) {
614 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
615 } qw(amount due paid);
617 if ($form->{"checked_$i"}) {
620 if (!$form->{"paid_$i"}) {
621 $form->{"paid_$i"} = $form->{"due_$i"};
624 # Modified by J.Zach, see abovev
625 $amount += $form->{"paid_$i"};
628 $form->{"paid_$i"} = "";
633 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
634 } qw(amount due paid);
638 # Line added by J.Zach, see above
639 $form->{amount}=$amount;
645 $lxdebug->leave_sub();
649 $lxdebug->enter_sub();
651 $auth->assert('cash');
655 if ($form->{currency} ne $form->{defaultcurrency}) {
656 $form->error($locale->text('Exchangerate missing!'))
657 unless $form->{exchangerate};
660 my $msg1 = "$form->{origtitle} posted!";
661 my $msg2 = "Cannot post $form->{origtitle}!";
663 # $locale->text('Payment posted!')
664 # $locale->text('Receipt posted!')
665 # $locale->text('Cannot post Payment!')
666 # $locale->text('Cannot post Receipt!')
668 $form->redirect($locale->text($msg1))
669 if (CP->process_payment(\%myconfig, \%$form));
670 $form->error($locale->text($msg2));
672 $lxdebug->leave_sub();
676 $lxdebug->enter_sub();
678 $auth->assert('cash');
680 my ($whole, $check, %queued, $spool, $filename, $userspath);
684 ($whole, $form->{decimal}) = split(/\./, $form->{amount});
686 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
688 #$form->{decimal} .= "00";
689 $form->{decimal} = substr($form->{decimal}, 0, 2);
691 $check = new CP $myconfig{countrycode};
693 $form->{text_amount} = $check->num2text($whole);
695 if ($form->{vc} eq 'customer') {
696 IS->customer_details(\%myconfig, $form);
698 IR->vendor_details(\%myconfig, $form);
701 $form->{callback} = "";
703 $form->{templates} = "$myconfig{templates}";
704 $form->{IN} = "$form->{formname}.tex";
706 if ($form->{format} eq 'postscript') {
707 $form->{postscript} = 1;
709 if ($form->{format} eq 'pdf') {
715 if ($form->{media} eq 'printer') {
716 $form->{OUT} = "| $myconfig{printer}";
718 if ($form->{media} eq 'queue') {
719 %queued = map { s|.*/|| } split / /, $form->{queued};
721 if ($filename = $queued{ $form->{formname} }) {
722 unlink "$spool/$filename";
723 $filename =~ s/\..*$//g;
728 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
729 $form->{queued} = "$form->{formname} $filename";
730 $form->{OUT} = ">$spool/$filename";
732 $form->update_status(\%myconfig);
736 $form->{company} = $myconfig{company};
737 $form->{address} = $myconfig{address};
739 $form->parse_template(\%myconfig, $userspath);
741 if ($form->{media} ne 'screen') {
742 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&all_vc=$form->{all_vc}";
744 $form->redirect if (CP->process_payment(\%myconfig, \%$form));
745 $form->error($locale->text('Cannot post payment!'));
748 $lxdebug->leave_sub();
752 $lxdebug->enter_sub();
754 $auth->assert('cash');
756 my ($closedto, $datepaid, $amount);
758 &check_name($form->{vc});
760 if ($form->{currency} ne $form->{oldcurrency}) {
765 $form->error($locale->text('Zero amount posting!')) if !$form->parse_amount(\%myconfig, $form->{amount});
766 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
768 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
769 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
771 $form->error($locale->text('Cannot process payment for a closed period!'))
772 if ($form->date_closed($form->{"datepaid"}, \%myconfig));
774 $amount = $form->parse_amount(\%myconfig, $form->{amount});
775 $form->{amount} = $amount;
777 for my $i (1 .. $form->{rowcount}) {
778 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
779 $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
781 push(@{ $form->{paid} }, $form->{"paid_$i"});
782 push(@{ $form->{due} }, $form->{"due_$i"});
783 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
784 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
788 if ($form->round_amount($amount, 2) != 0) {
789 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
790 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
791 push(@{ $form->{invnumber} },
792 ($form->{ARAP} eq 'AR')
793 ? $locale->text('Deposit')
794 : $locale->text('Prepayment'));
795 push(@{ $form->{invdate} }, $form->{datepaid});
798 $lxdebug->leave_sub();