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 #======================================================================
37 use strict ("vars", "subs");
40 require "bin/mozilla/arap.pl";
41 require "bin/mozilla/common.pl";
43 our ($form, %myconfig, $lxdebug, $locale, $auth);
50 $lxdebug->enter_sub();
52 $auth->assert('cash');
56 $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
57 $form->{arap} = lc $form->{ARAP};
59 # setup customer/vendor selection for open invoices
60 if ($form->{all_vc}) {
61 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
63 CP->get_openvc(\%myconfig, \%$form);
66 $form->{"select$form->{vc}"} = "";
68 if ($form->{"all_$form->{vc}"}) {
69 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
70 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
71 @{ $form->{"all_$form->{vc}"} };
75 if (@{ $form->{all_departments} || [] }) {
76 $form->{selectdepartment} = "<option>\n";
77 $form->{department} = "$form->{department}--$form->{department_id}";
80 $form->{selectdepartment} .=
81 "<option>$_->{description}--$_->{id}\n"
82 } (@{ $form->{all_departments} || [] });
85 CP->paymentaccounts(\%myconfig, \%$form);
87 $form->{selectaccount} = "";
88 $form->{"select$form->{ARAP}"} = "";
90 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
91 @{ $form->{PR}{"$form->{ARAP}_paid"} };
93 $form->{"select$form->{ARAP}"} .=
94 "<option>$_->{accno}--$_->{description}\n"
95 } @{ $form->{PR}{ $form->{ARAP} } };
98 @curr = split(/:/, $form->{currencies});
100 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
103 $form->{selectcurrency} = "";
104 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
106 $form->{media} = "screen";
111 $lxdebug->leave_sub();
115 $lxdebug->enter_sub();
117 $auth->assert('cash');
119 my ($vc, $vclabel, $allvc, $arap, $department, $exchangerate);
120 my ($jsscript, $button1, $button2, $onload);
122 $vclabel = ucfirst $form->{vc};
123 $vclabel = $locale->text($vclabel);
125 if ($form->{type} eq 'receipt') {
126 $form->{title} = $locale->text('Receipt');
127 $form->{origtitle} = "Receipt";
129 if ($form->{type} eq 'check') {
130 $form->{title} = $locale->text('Payment');
131 $form->{origtitle} = "Payment";
134 # $locale->text('Customer')
135 # $locale->text('Vendor')
137 if ($form->{ $form->{vc} } eq "") {
138 map { $form->{"addr$_"} = "" } (1 .. 4);
141 if ($form->{currency} ne $form->{defaultcurrency}) {
142 $form->{exchangerate} =
143 $form->format_amount(\%myconfig, $form->{exchangerate});
144 if ($form->{forex}) {
147 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
148 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
154 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
155 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
161 foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}, "department") {
162 $form->{"select$item"} =~ s/ selected//;
163 $form->{"select$item"} =~
164 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
168 ($form->{"select$form->{vc}"})
169 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
170 : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
172 if ($form->{all_vc}) {
174 $form->{openinvoices} = "";
177 $form->{openinvoices} = 1;
180 # $locale->text('AR')
181 # $locale->text('AP')
183 $form->{jsscript} = 1;
185 if ($form->{jsscript}) {
187 # with JavaScript Calendar
189 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
190 <input type=button name=datepaid id="trigger1" value=|
191 . $locale->text('button') . qq|></td>
196 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
199 # without JavaScript Calendar
201 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
203 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
206 $arap = lc $form->{ARAP};
207 $onload = qq|focus()|;
208 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
209 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
211 <body onLoad="$onload">
213 <form method=post action=cp.pl>
215 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
216 <input type=hidden name=closedto value=$form->{closedto}>
217 <input type=hidden name=vc value=$form->{vc}>
218 <input type=hidden name=type value=$form->{type}>
219 <input type=hidden name=formname value=$form->{type}>
220 <input type=hidden name=queued value="$form->{queued}">
221 <input type=hidden name=arap value=$arap>
222 <input type=hidden name=ARAP value=$form->{ARAP}>
223 <input type=hidden name=openinvoices value=$form->{openinvoices}>
224 <input type=hidden name=title value="$form->{title}">
225 <input type=hidden name=origtitle value="$form->{origtitle}">
229 <th class=listtop>$form->{title}</th>
240 <input name=all_vc type=checkbox style=checkbox value=Y $allvc>
241 <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
242 <th align=left>| . $locale->text('All') . qq|</th>
245 <th align=right>$vclabel</th>
247 <input type=hidden name="select$form->{vc}" value="| . H($form->{"select$form->{vc}"}) . qq|">
248 <input type=hidden name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
249 <input type=hidden name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
252 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
256 <td>$form->{street}</td>
259 <td>$form->{zipcode}</td>
262 <td>$form->{city}</td>
265 <td>$form->{country}</td>
269 <input type=hidden name=street value="$form->{street}">
270 <input type=hidden name=zipcode value="$form->{zipcode}">
271 <input type=hidden name=city value="$form->{city}">
272 <input type=hidden name=country value="$form->{country}">
275 <th align=right>| . $locale->text('Memo') . qq|</th>
276 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
284 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
285 <td colspan=3><select name=account>$form->{selectaccount}</select>
286 <input type=hidden name=selectaccount value="$form->{selectaccount}">
290 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
294 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
295 <td><select name=currency>$form->{selectcurrency}</select></td>
296 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
297 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
301 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
302 <td colspan=3><input name=source value="$form->{source}" size=10></td>
305 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
306 <td colspan="3"><input name="amount" size="10" value="|
307 . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|" onBlur=\"check_right_number_format(this)\"></td>
319 if ($form->{openinvoices_other_currencies}) {
320 my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
321 : $::locale->text('There are #1 more open invoices from this vendor with other currencies.', $form->{openinvoices_other_currencies});
325 <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
327 <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
332 $lxdebug->leave_sub();
336 $lxdebug->enter_sub();
338 $auth->assert('cash');
340 my (@column_index, %column_data, $colspan, $invoice);
341 my ($totalamount, $totaldue, $totalpaid);
343 @column_index = qw(invnumber transdate amount due checked paid);
345 $colspan = $#column_index + 1;
347 $invoice = $locale->text('Invoices');
350 <input type=hidden name=column_index value="id @column_index">
355 <th class=listheading colspan=$colspan>$invoice</th>
359 $column_data{invnumber} =
360 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
361 $column_data{transdate} =
362 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
363 $column_data{amount} =
364 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
366 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
368 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
369 $column_data{checked} =
370 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
375 map { print "$column_data{$_}\n" } @column_index;
380 for my $i (1 .. $form->{rowcount}) {
386 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
387 } qw(amount due paid);
389 $totalamount += $form->{"amount_$i"};
390 $totaldue += $form->{"due_$i"};
391 $totalpaid += $form->{"paid_$i"};
395 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
396 } qw(amount due paid);
398 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
399 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
400 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
401 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
402 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
403 $column_data{amount} =
404 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
405 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
406 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
407 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
410 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
412 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
413 $column_data{checked} =
414 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
421 map { print "$column_data{$_}\n" } @column_index;
427 map { $column_data{$_} = "<td> </td>" } @column_index;
429 $column_data{amount} =
430 qq|<th class=listtotal align=right>|
431 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
434 qq|<th class=listtotal align=right>|
435 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
438 qq|<th class=listtotal align=right>|
439 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
445 map { print "$column_data{$_}\n" } @column_index;
453 $lxdebug->leave_sub();
457 $lxdebug->enter_sub();
459 $auth->assert('cash');
461 my ($media, $format, $latex_templates);
463 $form->{DF}{ $form->{format} } = "selected";
464 $form->{OP}{ $form->{media} } = "selected";
467 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
469 if ($myconfig{printer} && $latex_templates) {
471 <option value=printer $form->{OP}{printer}>|
472 . $locale->text('Printer');
474 if ($latex_templates) {
476 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
478 <option value=postscript $form->{DF}{postscript}>|
479 . $locale->text('Postscript') . qq|
480 <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
485 <td><hr size=3 noshade></td>
488 <input type=hidden name=rowcount value=$form->{rowcount}>
491 <input class=submit type=submit name=action value="|
492 . $locale->text('Update') . qq|">
493 <input class=submit type=submit name=action value="|
494 . $locale->text('Post') . qq|">|;
496 if ($latex_templates) {
498 <input class=submit type=submit name=action value="|
499 . $locale->text('Print') . qq|">|;
503 <select name=format>$format</select>
504 <select name=media>$media</select>
512 $lxdebug->leave_sub();
516 $lxdebug->enter_sub();
518 $auth->assert('cash');
520 my ($new_name_selected) = @_;
522 my ($buysell, $newvc, $updated, $exchangerate, $amount);
524 if ($form->{vc} eq 'customer') {
530 # if we switched to all_vc
531 if ($form->{all_vc} ne $form->{oldall_vc}) {
533 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
535 $form->{"select$form->{vc}"} = "";
537 if ($form->{all_vc}) {
538 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
540 if ($form->{"all_$form->{vc}"}) {
542 $form->{"select$form->{vc}"} .=
543 "<option>$_->{name}--$_->{id}\n"
544 } @{ $form->{"all_$form->{vc}"} };
547 CP->get_openvc(\%myconfig, \%$form);
549 if ($form->{"all_$form->{vc}"}) {
551 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
553 $form->{"select$form->{vc}"} .=
554 "<option>$_->{name}--$_->{id}\n"
555 } @{ $form->{"all_$form->{vc}"} };
558 # if the name is not the same
559 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
560 $form->{ $form->{vc} } = $newvc;
565 # get customer and invoices
566 $updated = &check_name($form->{vc});
568 if ($new_name_selected || $updated) {
569 CP->get_openinvoices(\%myconfig, \%$form);
570 ($newvc) = split /--/, $form->{ $form->{vc} };
571 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
575 if ($form->{currency} ne $form->{oldcurrency}) {
576 $form->{oldcurrency} = $form->{currency};
578 CP->get_openinvoices(\%myconfig, \%$form);
583 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
584 $form->{exchangerate} = $form->{forex} if $form->{forex};
586 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
589 $form->{rowcount} = 0;
591 $form->{queued} = "";
594 foreach my $ref (@{ $form->{PR} }) {
596 $form->{"id_$i"} = $ref->{id};
597 $form->{"invnumber_$i"} = $ref->{invnumber};
598 $form->{"transdate_$i"} = $ref->{transdate};
599 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
600 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
602 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
603 $form->{"checked_$i"} = "";
604 $form->{"paid_$i"} = "";
609 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
613 $form->{rowcount} = $i;
618 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
619 # payment amount in Zahlungsausgang
621 for my $i (1 .. $form->{rowcount}) {
625 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
626 } qw(amount due paid);
628 if ($form->{"checked_$i"}) {
631 if (!$form->{"paid_$i"}) {
632 $form->{"paid_$i"} = $form->{"due_$i"};
635 # Modified by J.Zach, see abovev
636 $amount += $form->{"paid_$i"};
639 $form->{"paid_$i"} = "";
644 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
645 } qw(amount due paid);
649 # Line added by J.Zach, see above
650 $form->{amount}=$amount;
656 $lxdebug->leave_sub();
660 $lxdebug->enter_sub();
662 $auth->assert('cash');
666 if ($form->{currency} ne $form->{defaultcurrency}) {
667 $form->error($locale->text('Exchangerate missing!'))
668 unless $form->{exchangerate};
671 my $msg1 = "$form->{origtitle} posted!";
672 my $msg2 = "Cannot post $form->{origtitle}!";
674 # $locale->text('Payment posted!')
675 # $locale->text('Receipt posted!')
676 # $locale->text('Cannot post Payment!')
677 # $locale->text('Cannot post Receipt!')
679 $form->redirect($locale->text($msg1))
680 if (CP->process_payment(\%myconfig, \%$form));
681 $form->error($locale->text($msg2));
683 $lxdebug->leave_sub();
687 $lxdebug->enter_sub();
689 $auth->assert('cash');
691 my ($whole, $check, %queued, $spool, $filename, $userspath);
695 ($whole, $form->{decimal}) = split(/\./, $form->{amount});
697 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
699 #$form->{decimal} .= "00";
700 $form->{decimal} = substr($form->{decimal}, 0, 2);
702 $check = new CP $myconfig{countrycode};
704 $form->{text_amount} = $check->num2text($whole);
706 if ($form->{vc} eq 'customer') {
707 IS->customer_details(\%myconfig, $form);
709 IR->vendor_details(\%myconfig, $form);
712 $form->{callback} = "";
714 $form->{templates} = "$myconfig{templates}";
715 $form->{IN} = "$form->{formname}.tex";
717 if ($form->{format} eq 'postscript') {
718 $form->{postscript} = 1;
720 if ($form->{format} eq 'pdf') {
726 if ($form->{media} eq 'printer') {
727 $form->{OUT} = "| $myconfig{printer}";
729 if ($form->{media} eq 'queue') {
730 %queued = map { s|.*/|| } split / /, $form->{queued};
732 if ($filename = $queued{ $form->{formname} }) {
733 unlink "$spool/$filename";
734 $filename =~ s/\..*$//g;
739 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
740 $form->{queued} = "$form->{formname} $filename";
741 $form->{OUT} = ">$spool/$filename";
743 $form->update_status(\%myconfig);
747 $form->{company} = $myconfig{company};
748 $form->{address} = $myconfig{address};
750 $form->parse_template(\%myconfig, $userspath);
752 if ($form->{media} ne 'screen') {
753 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&all_vc=$form->{all_vc}";
755 $form->redirect if (CP->process_payment(\%myconfig, \%$form));
756 $form->error($locale->text('Cannot post payment!'));
759 $lxdebug->leave_sub();
763 $lxdebug->enter_sub();
765 $auth->assert('cash');
767 my ($closedto, $datepaid, $amount);
769 &check_name($form->{vc});
771 if ($form->{currency} ne $form->{oldcurrency}) {
775 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
776 my $selected_check = 1;
777 for my $i (1 .. $form->{rowcount}) {
778 if ($form->{"checked_$i"}) {
779 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"}, 2) <= 0) { # negativen Betrag eingegeben
780 $form->error($locale->text('No zero or negative values, please! Correct row number:' . $i));
782 undef($selected_check);
783 # last; # ich muss doch über alle buchungen laufen, da ich noch
784 # die freitext-eingabe der werte prüfen will
787 $form->error($locale->text('No transaction selected!')) if $selected_check;
789 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
790 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
792 $form->error($locale->text('Cannot process payment for a closed period!'))
793 if ($form->date_closed($form->{"datepaid"}, \%myconfig));
795 $amount = $form->parse_amount(\%myconfig, $form->{amount});
796 $form->{amount} = $amount;
798 for my $i (1 .. $form->{rowcount}) {
799 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
800 $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
802 push(@{ $form->{paid} }, $form->{"paid_$i"});
803 push(@{ $form->{due} }, $form->{"due_$i"});
804 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
805 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
809 if ($form->round_amount($amount, 2) != 0) {
810 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
811 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
812 push(@{ $form->{invnumber} },
813 ($form->{ARAP} eq 'AR')
814 ? $locale->text('Deposit')
815 : $locale->text('Prepayment'));
816 push(@{ $form->{invdate} }, $form->{datepaid});
819 $lxdebug->leave_sub();