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();
51 $auth->assert('cash');
55 $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
56 $form->{arap} = lc $form->{ARAP};
58 # setup customer/vendor selection for open invoices
59 if ($form->{all_vc}) {
60 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
62 CP->get_openvc(\%myconfig, \%$form);
65 $form->{"select$form->{vc}"} = "";
67 if ($form->{"all_$form->{vc}"}) {
68 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
69 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
70 @{ $form->{"all_$form->{vc}"} };
74 if (@{ $form->{all_departments} || [] }) {
75 $form->{selectdepartment} = "<option>\n";
76 $form->{department} = "$form->{department}--$form->{department_id}";
79 $form->{selectdepartment} .=
80 "<option>$_->{description}--$_->{id}\n"
81 } (@{ $form->{all_departments} || [] });
84 CP->paymentaccounts(\%myconfig, \%$form);
85 $form->{selectaccount} = "";
86 $form->{"select$form->{ARAP}"} = "";
88 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
89 @{ $form->{PR}{"$form->{ARAP}_paid"} };
91 $form->{"select$form->{ARAP}"} .=
92 "<option>$_->{accno}--$_->{description}\n"
93 } @{ $form->{PR}{ $form->{ARAP} } };
96 @curr = split(/:/, $form->{currencies});
98 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
101 $form->{selectcurrency} = "";
102 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
104 $form->{media} = "screen";
109 $lxdebug->leave_sub();
113 $lxdebug->enter_sub();
115 $auth->assert('cash');
117 my ($vc, $vclabel, $allvc, $arap, $department, $exchangerate);
118 my ($jsscript, $button1, $button2, $onload);
120 $vclabel = ucfirst $form->{vc};
121 $vclabel = $locale->text($vclabel);
123 if ($form->{type} eq 'receipt') {
124 $form->{title} = $locale->text('Receipt');
125 $form->{origtitle} = "Receipt";
127 if ($form->{type} eq 'check') {
128 $form->{title} = $locale->text('Payment');
129 $form->{origtitle} = "Payment";
132 # $locale->text('Customer')
133 # $locale->text('Vendor')
135 if ($form->{ $form->{vc} } eq "") {
136 map { $form->{"addr$_"} = "" } (1 .. 4);
139 if ($form->{currency} ne $form->{defaultcurrency}) {
140 $form->{exchangerate} =
141 $form->format_amount(\%myconfig, $form->{exchangerate});
142 if ($form->{forex}) {
145 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
146 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
152 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
153 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
159 foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}, "department") {
160 $form->{"select$item"} =~ s/ selected//;
161 $form->{"select$item"} =~
162 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
166 ($form->{"select$form->{vc}"})
167 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
168 : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
170 if ($form->{all_vc}) {
172 $form->{openinvoices} = "";
175 $form->{openinvoices} = 1;
178 # $locale->text('AR')
179 # $locale->text('AP')
181 $form->{jsscript} = 1;
183 if ($form->{jsscript}) {
185 # with JavaScript Calendar
187 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
188 <input type=button name=datepaid id="trigger1" value=|
189 . $locale->text('button') . qq|></td>
194 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
197 # without JavaScript Calendar
199 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
201 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
204 $arap = lc $form->{ARAP};
205 $onload = qq|focus()|;
206 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
207 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
209 <body onLoad="$onload">
211 <form method=post action=cp.pl>
213 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
214 <input type=hidden name=closedto value=$form->{closedto}>
215 <input type=hidden name=vc value=$form->{vc}>
216 <input type=hidden name=type value=$form->{type}>
217 <input type=hidden name=formname value=$form->{type}>
218 <input type=hidden name=queued value="$form->{queued}">
219 <input type=hidden name=arap value=$arap>
220 <input type=hidden name=ARAP value=$form->{ARAP}>
221 <input type=hidden name=openinvoices value=$form->{openinvoices}>
222 <input type=hidden name=title value="$form->{title}">
223 <input type=hidden name=origtitle value="$form->{origtitle}">
227 <th class=listtop>$form->{title}</th>
237 <th align=right>$vclabel</th>
239 <input type=hidden name="select$form->{vc}" value="| . H($form->{"select$form->{vc}"}) . qq|">
240 <input type=hidden name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
241 <input type=hidden name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
244 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
248 <td>$form->{street}</td>
251 <td>$form->{zipcode}</td>
254 <td>$form->{city}</td>
257 <td>$form->{country}</td>
261 <input type=hidden name=street value="$form->{street}">
262 <input type=hidden name=zipcode value="$form->{zipcode}">
263 <input type=hidden name=city value="$form->{city}">
264 <input type=hidden name=country value="$form->{country}">
267 <th align=right>| . $locale->text('Memo') . qq|</th>
268 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
276 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
277 <td colspan=3><select name=account>$form->{selectaccount}</select>
278 <input type=hidden name=selectaccount value="$form->{selectaccount}">
282 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
286 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
287 <td><select name=currency>$form->{selectcurrency}</select></td>
288 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
292 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
293 <td colspan=3><input name=source value="$form->{source}" size=10></td>
296 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
297 <td colspan="3">| . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|</td>
309 if ($form->{openinvoices_other_currencies}) {
310 my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
311 : $::locale->text('There are #1 more open invoices from this vendor with other currencies.', $form->{openinvoices_other_currencies});
315 <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
317 <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
322 $lxdebug->leave_sub();
326 $lxdebug->enter_sub();
328 $auth->assert('cash');
330 my (@column_index, %column_data, $colspan, $invoice);
331 my ($totalamount, $totaldue, $totalpaid);
333 @column_index = qw(invnumber transdate amount due checked paid);
335 $colspan = $#column_index + 1;
337 $invoice = $locale->text('Invoices');
340 <input type=hidden name=column_index value="id @column_index">
345 <th class=listheading colspan=$colspan>$invoice</th>
349 $column_data{invnumber} =
350 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
351 $column_data{transdate} =
352 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
353 $column_data{amount} =
354 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
356 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
358 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
359 $column_data{checked} =
360 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
365 map { print "$column_data{$_}\n" } @column_index;
370 for my $i (1 .. $form->{rowcount}) {
376 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
377 } qw(amount due paid);
379 $totalamount += $form->{"amount_$i"};
380 $totaldue += $form->{"due_$i"};
381 $totalpaid += $form->{"paid_$i"};
385 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
386 } qw(amount due paid);
388 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
389 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
390 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
391 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
392 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
393 $column_data{amount} =
394 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
395 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
396 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
397 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
400 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
402 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
403 $column_data{checked} =
404 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
411 map { print "$column_data{$_}\n" } @column_index;
417 map { $column_data{$_} = "<td> </td>" } @column_index;
419 $column_data{amount} =
420 qq|<th class=listtotal align=right>|
421 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
424 qq|<th class=listtotal align=right>|
425 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
428 qq|<th class=listtotal align=right>|
429 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
435 map { print "$column_data{$_}\n" } @column_index;
443 $lxdebug->leave_sub();
447 $lxdebug->enter_sub();
449 $auth->assert('cash');
451 my ($media, $format, $latex_templates);
453 $form->{DF}{ $form->{format} } = "selected";
454 $form->{OP}{ $form->{media} } = "selected";
457 <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
459 if ($myconfig{printer} && $latex_templates) {
461 <option value=printer $form->{OP}{printer}>|
462 . $locale->text('Printer');
464 if ($latex_templates) {
466 <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
468 <option value=postscript $form->{DF}{postscript}>|
469 . $locale->text('Postscript') . qq|
470 <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
475 <td><hr size=3 noshade></td>
478 <input type=hidden name=rowcount value=$form->{rowcount}>
481 <input class=submit type=submit name=action value="|
482 . $locale->text('Update') . qq|">
483 <input class=submit type=submit name=action value="|
484 . $locale->text('Post') . qq|">|;
486 if ($latex_templates) {
488 <input class=submit type=submit name=action value="|
489 . $locale->text('Print') . qq|">|;
493 <select name=format>$format</select>
494 <select name=media>$media</select>
502 $lxdebug->leave_sub();
506 $lxdebug->enter_sub();
508 $auth->assert('cash');
510 my ($new_name_selected) = @_;
512 my ($buysell, $newvc, $updated, $exchangerate, $amount);
514 if ($form->{vc} eq 'customer') {
520 # if we switched to all_vc
521 if ($form->{all_vc} ne $form->{oldall_vc}) {
523 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
525 $form->{"select$form->{vc}"} = "";
527 if ($form->{all_vc}) {
528 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
530 if ($form->{"all_$form->{vc}"}) {
532 $form->{"select$form->{vc}"} .=
533 "<option>$_->{name}--$_->{id}\n"
534 } @{ $form->{"all_$form->{vc}"} };
537 CP->get_openvc(\%myconfig, \%$form);
539 if ($form->{"all_$form->{vc}"}) {
541 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
543 $form->{"select$form->{vc}"} .=
544 "<option>$_->{name}--$_->{id}\n"
545 } @{ $form->{"all_$form->{vc}"} };
548 # if the name is not the same
549 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
550 $form->{ $form->{vc} } = $newvc;
555 # get customer and invoices
556 $updated = &check_name($form->{vc});
558 if ($new_name_selected || $updated) {
559 CP->get_openinvoices(\%myconfig, \%$form);
560 ($newvc) = split /--/, $form->{ $form->{vc} };
561 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
565 if ($form->{currency} ne $form->{oldcurrency}) {
566 $form->{oldcurrency} = $form->{currency};
568 CP->get_openinvoices(\%myconfig, \%$form);
573 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
574 $form->{exchangerate} = $form->{forex} if $form->{forex};
576 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
579 $form->{rowcount} = 0;
581 $form->{queued} = "";
584 foreach my $ref (@{ $form->{PR} }) {
586 $form->{"id_$i"} = $ref->{id};
587 $form->{"invnumber_$i"} = $ref->{invnumber};
588 $form->{"transdate_$i"} = $ref->{transdate};
589 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
590 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
592 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
593 $form->{"checked_$i"} = "";
594 $form->{"paid_$i"} = "";
599 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
603 $form->{rowcount} = $i;
608 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
609 # payment amount in Zahlungsausgang
611 for my $i (1 .. $form->{rowcount}) {
615 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
616 } qw(amount due paid);
618 if ($form->{"checked_$i"}) {
621 if (!$form->{"paid_$i"}) {
622 $form->{"paid_$i"} = $form->{"due_$i"};
625 # Modified by J.Zach, see abovev
626 $amount += $form->{"paid_$i"};
629 $form->{"paid_$i"} = "";
634 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
635 } qw(amount due paid);
639 # Line added by J.Zach, see above
640 $form->{amount}=$amount;
646 $lxdebug->leave_sub();
650 $lxdebug->enter_sub();
652 $auth->assert('cash');
656 if ($form->{currency} ne $form->{defaultcurrency}) {
657 $form->error($locale->text('Exchangerate missing!'))
658 unless $form->{exchangerate};
661 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&muh=kuh&account=$form->{account}";
663 my $msg1 = "$form->{origtitle} posted!";
664 my $msg2 = "Cannot post $form->{origtitle}!";
666 # $locale->text('Payment posted!')
667 # $locale->text('Receipt posted!')
668 # $locale->text('Cannot post Payment!')
669 # $locale->text('Cannot post Receipt!')
671 $form->redirect($locale->text($msg1))
672 if (CP->process_payment(\%myconfig, \%$form));
673 $form->error($locale->text($msg2));
675 $lxdebug->leave_sub();
679 $lxdebug->enter_sub();
680 exit; # Niemand braucht mich mehr! LöschMich endlich! jb 8.10.2010
681 $auth->assert('cash');
683 my ($whole, $check, %queued, $spool, $filename, $userspath);
687 ($whole, $form->{decimal}) = split(/\./, $form->{amount});
689 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
691 #$form->{decimal} .= "00";
692 $form->{decimal} = substr($form->{decimal}, 0, 2);
694 $check = new CP $myconfig{countrycode};
696 $form->{text_amount} = $check->num2text($whole);
698 if ($form->{vc} eq 'customer') {
699 IS->customer_details(\%myconfig, $form);
701 IR->vendor_details(\%myconfig, $form);
704 $form->{callback} = "";
706 $form->{templates} = "$myconfig{templates}";
707 $form->{IN} = "$form->{formname}.tex";
709 if ($form->{format} eq 'postscript') {
710 $form->{postscript} = 1;
712 if ($form->{format} eq 'pdf') {
718 if ($form->{media} eq 'printer') {
719 $form->{OUT} = "| $myconfig{printer}";
721 if ($form->{media} eq 'queue') {
722 %queued = map { s|.*/|| } split / /, $form->{queued};
724 if ($filename = $queued{ $form->{formname} }) {
725 unlink "$spool/$filename";
726 $filename =~ s/\..*$//g;
731 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
732 $form->{queued} = "$form->{formname} $filename";
733 $form->{OUT} = ">$spool/$filename";
735 $form->update_status(\%myconfig);
739 $form->{company} = $myconfig{company};
740 $form->{address} = $myconfig{address};
742 $form->parse_template(\%myconfig, $userspath);
744 if ($form->{media} ne 'screen') {
745 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&all_vc=$form->{all_vc}";
747 $form->redirect if (CP->process_payment(\%myconfig, \%$form));
748 $form->error($locale->text('Cannot post payment!'));
751 $lxdebug->leave_sub();
755 $lxdebug->enter_sub();
757 $auth->assert('cash');
759 my ($closedto, $datepaid, $amount);
761 &check_name($form->{vc});
763 if ($form->{currency} ne $form->{oldcurrency}) {
767 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
768 my $selected_check = 1;
769 for my $i (1 .. $form->{rowcount}) {
770 if ($form->{"checked_$i"}) {
771 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"}, 2) <= 0) { # negativen Betrag eingegeben
772 $form->error($locale->text('Amount has to be greater then zero! Wrong row number: ') . $i);
774 undef($selected_check);
775 # last; # ich muss doch über alle buchungen laufen, da ich noch
776 # die freitext-eingabe der werte prüfen will
779 $form->error($locale->text('No transaction selected!')) if $selected_check;
781 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
782 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
784 $form->error($locale->text('Cannot process payment for a closed period!'))
785 if ($form->date_closed($form->{"datepaid"}, \%myconfig));
787 $amount = $form->parse_amount(\%myconfig, $form->{amount});
788 $form->{amount} = $amount;
790 for my $i (1 .. $form->{rowcount}) {
791 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
792 $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
794 push(@{ $form->{paid} }, $form->{"paid_$i"});
795 push(@{ $form->{due} }, $form->{"due_$i"});
796 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
797 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
801 if ($form->round_amount($amount, 2) != 0) {
802 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
803 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
804 push(@{ $form->{invnumber} },
805 ($form->{ARAP} eq 'AR')
806 ? $locale->text('Deposit')
807 : $locale->text('Prepayment'));
808 push(@{ $form->{invdate} }, $form->{datepaid});
811 $lxdebug->leave_sub();