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;
110 $lxdebug->leave_sub();
114 $lxdebug->enter_sub();
116 $auth->assert('cash');
118 my ($vc, $vclabel, $allvc, $arap, $department, $exchangerate);
119 my ($jsscript, $button1, $button2, $onload);
121 $vclabel = ucfirst $form->{vc};
122 $vclabel = $locale->text($vclabel);
124 if ($form->{type} eq 'receipt') {
125 $form->{title} = $locale->text('Receipt');
126 $form->{origtitle} = "Receipt";
128 if ($form->{type} eq 'check') {
129 $form->{title} = $locale->text('Payment');
130 $form->{origtitle} = "Payment";
133 # $locale->text('Customer')
134 # $locale->text('Vendor')
136 if ($form->{ $form->{vc} } eq "") {
137 map { $form->{"addr$_"} = "" } (1 .. 4);
140 if ($form->{currency} ne $form->{defaultcurrency}) {
141 $form->{exchangerate} =
142 $form->format_amount(\%myconfig, $form->{exchangerate});
143 if ($form->{forex}) {
146 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
147 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
153 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
154 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
160 foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}, "department") {
161 $form->{"select$item"} =~ s/ selected//;
162 $form->{"select$item"} =~
163 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
167 ($form->{"select$form->{vc}"})
168 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
169 : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
171 if ($form->{all_vc}) {
173 $form->{openinvoices} = "";
176 $form->{openinvoices} = 1;
179 # $locale->text('AR')
180 # $locale->text('AP')
182 $form->{jsscript} = 1;
184 if ($form->{jsscript}) {
186 # with JavaScript Calendar
188 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
189 <input type=button name=datepaid id="trigger1" value=|
190 . $locale->text('button') . qq|></td>
195 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
198 # without JavaScript Calendar
200 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
202 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
205 $arap = lc $form->{ARAP};
206 $onload = qq|focus()|;
207 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
208 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
210 <body onLoad="$onload">
212 <form method=post action=cp.pl>
214 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
215 <input type=hidden name=closedto value=$form->{closedto}>
216 <input type=hidden name=vc value=$form->{vc}>
217 <input type=hidden name=type value=$form->{type}>
218 <input type=hidden name=formname value=$form->{type}>
219 <input type=hidden name=queued value="$form->{queued}">
220 <input type=hidden name=arap value=$arap>
221 <input type=hidden name=ARAP value=$form->{ARAP}>
222 <input type=hidden name=openinvoices value=$form->{openinvoices}>
223 <input type=hidden name=title value="$form->{title}">
224 <input type=hidden name=origtitle value="$form->{origtitle}">
228 <th class=listtop>$form->{title}</th>
238 <th align=right>$vclabel</th>
240 <input type=hidden name="select$form->{vc}" value="| . H($form->{"select$form->{vc}"}) . qq|">
241 <input type=hidden name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
242 <input type=hidden name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
245 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
249 <td>$form->{street}</td>
252 <td>$form->{zipcode}</td>
255 <td>$form->{city}</td>
258 <td>$form->{country}</td>
262 <input type=hidden name=street value="$form->{street}">
263 <input type=hidden name=zipcode value="$form->{zipcode}">
264 <input type=hidden name=city value="$form->{city}">
265 <input type=hidden name=country value="$form->{country}">
268 <th align=right>| . $locale->text('Memo') . qq|</th>
269 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
277 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
278 <td colspan=3><select name=account>$form->{selectaccount}</select>
279 <input type=hidden name=selectaccount value="$form->{selectaccount}">
283 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
287 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
288 <td><select name=currency>$form->{selectcurrency}</select></td>
289 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
290 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
294 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
295 <td colspan=3><input name=source value="$form->{source}" size=10></td>
298 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
299 <td colspan="3">| . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|</td>
311 if ($form->{openinvoices_other_currencies}) {
312 my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
313 : $::locale->text('There are #1 more open invoices from this vendor with other currencies.', $form->{openinvoices_other_currencies});
317 <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
319 <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
324 $lxdebug->leave_sub();
328 $lxdebug->enter_sub();
330 $auth->assert('cash');
332 my (@column_index, %column_data, $colspan, $invoice);
333 my ($totalamount, $totaldue, $totalpaid);
335 @column_index = qw(invnumber transdate amount due checked paid);
337 $colspan = $#column_index + 1;
339 $invoice = $locale->text('Invoices');
342 <input type=hidden name=column_index value="id @column_index">
347 <th class=listheading colspan=$colspan>$invoice</th>
351 $column_data{invnumber} =
352 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
353 $column_data{transdate} =
354 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
355 $column_data{amount} =
356 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
358 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
360 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
361 $column_data{checked} =
362 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
367 map { print "$column_data{$_}\n" } @column_index;
372 for my $i (1 .. $form->{rowcount}) {
378 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
379 } qw(amount due paid);
381 $totalamount += $form->{"amount_$i"};
382 $totaldue += $form->{"due_$i"};
383 $totalpaid += $form->{"paid_$i"};
387 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
388 } qw(amount due paid);
390 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
391 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
392 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
393 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
394 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
395 $column_data{amount} =
396 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
397 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
398 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
399 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
402 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
404 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
405 $column_data{checked} =
406 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
413 map { print "$column_data{$_}\n" } @column_index;
419 map { $column_data{$_} = "<td> </td>" } @column_index;
421 $column_data{amount} =
422 qq|<th class=listtotal align=right>|
423 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
426 qq|<th class=listtotal align=right>|
427 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
430 qq|<th class=listtotal align=right>|
431 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
437 map { print "$column_data{$_}\n" } @column_index;
445 $lxdebug->leave_sub();
449 $lxdebug->enter_sub();
451 $auth->assert('cash');
455 <td><hr size=3 noshade></td>
458 <input type=hidden name=rowcount value=$form->{rowcount}>
461 <input class=submit type=submit name=action value="|
462 . $locale->text('Update') . qq|">
463 <input class=submit type=submit name=action value="|
464 . $locale->text('Post') . qq|">
471 $lxdebug->leave_sub();
475 $lxdebug->enter_sub();
477 $auth->assert('cash');
479 my ($new_name_selected) = @_;
481 my ($buysell, $newvc, $updated, $exchangerate, $amount);
483 if ($form->{vc} eq 'customer') {
489 # if we switched to all_vc
490 if ($form->{all_vc} ne $form->{oldall_vc}) {
492 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
494 $form->{"select$form->{vc}"} = "";
496 if ($form->{all_vc}) {
497 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
499 if ($form->{"all_$form->{vc}"}) {
501 $form->{"select$form->{vc}"} .=
502 "<option>$_->{name}--$_->{id}\n"
503 } @{ $form->{"all_$form->{vc}"} };
506 CP->get_openvc(\%myconfig, \%$form);
508 if ($form->{"all_$form->{vc}"}) {
510 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
512 $form->{"select$form->{vc}"} .=
513 "<option>$_->{name}--$_->{id}\n"
514 } @{ $form->{"all_$form->{vc}"} };
517 # if the name is not the same
518 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
519 $form->{ $form->{vc} } = $newvc;
524 # get customer and invoices
525 $updated = &check_name($form->{vc});
527 if ($new_name_selected || $updated) {
528 CP->get_openinvoices(\%myconfig, \%$form);
529 ($newvc) = split /--/, $form->{ $form->{vc} };
530 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
534 if ($form->{currency} ne $form->{oldcurrency}) {
535 $form->{oldcurrency} = $form->{currency};
537 CP->get_openinvoices(\%myconfig, \%$form);
542 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
543 $form->{exchangerate} = $form->{forex} if $form->{forex};
545 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
548 $form->{rowcount} = 0;
550 $form->{queued} = "";
553 foreach my $ref (@{ $form->{PR} }) {
555 $form->{"id_$i"} = $ref->{id};
556 $form->{"invnumber_$i"} = $ref->{invnumber};
557 $form->{"transdate_$i"} = $ref->{transdate};
558 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
559 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
561 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
562 $form->{"checked_$i"} = "";
563 $form->{"paid_$i"} = "";
568 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
572 $form->{rowcount} = $i;
577 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
578 # payment amount in Zahlungsausgang
580 for my $i (1 .. $form->{rowcount}) {
584 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
585 } qw(amount due paid);
587 if ($form->{"checked_$i"}) {
590 if (!$form->{"paid_$i"}) {
591 $form->{"paid_$i"} = $form->{"due_$i"};
594 # Modified by J.Zach, see abovev
595 $amount += $form->{"paid_$i"};
598 $form->{"paid_$i"} = "";
603 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
604 } qw(amount due paid);
608 # Line added by J.Zach, see above
609 $form->{amount}=$amount;
615 $lxdebug->leave_sub();
619 $lxdebug->enter_sub();
621 $auth->assert('cash');
625 if ($form->{currency} ne $form->{defaultcurrency}) {
626 $form->error($locale->text('Exchangerate missing!'))
627 unless $form->{exchangerate};
630 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&muh=kuh&account=$form->{account}";
632 my $msg1 = "$form->{origtitle} posted!";
633 my $msg2 = "Cannot post $form->{origtitle}!";
635 # $locale->text('Payment posted!')
636 # $locale->text('Receipt posted!')
637 # $locale->text('Cannot post Payment!')
638 # $locale->text('Cannot post Receipt!')
640 $form->redirect($locale->text($msg1))
641 if (CP->process_payment(\%myconfig, \%$form));
642 $form->error($locale->text($msg2));
644 $lxdebug->leave_sub();
648 $lxdebug->enter_sub();
650 $auth->assert('cash');
652 my ($closedto, $datepaid, $amount);
654 &check_name($form->{vc});
656 if ($form->{currency} ne $form->{oldcurrency}) {
660 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
661 my $selected_check = 1;
662 for my $i (1 .. $form->{rowcount}) {
663 if ($form->{"checked_$i"}) {
664 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"}, 2) <= 0) { # negativen Betrag eingegeben
665 $form->error($locale->text('No zero or negative values, please! Correct row number:' . $i));
667 undef($selected_check);
668 # last; # ich muss doch über alle buchungen laufen, da ich noch
669 # die freitext-eingabe der werte prüfen will
672 $form->error($locale->text('No transaction selected!')) if $selected_check;
674 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
675 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
677 $form->error($locale->text('Cannot process payment for a closed period!'))
678 if ($form->date_closed($form->{"datepaid"}, \%myconfig));
680 $amount = $form->parse_amount(\%myconfig, $form->{amount});
681 $form->{amount} = $amount;
683 for my $i (1 .. $form->{rowcount}) {
684 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
685 $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
687 push(@{ $form->{paid} }, $form->{"paid_$i"});
688 push(@{ $form->{due} }, $form->{"due_$i"});
689 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
690 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
694 if ($form->round_amount($amount, 2) != 0) {
695 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
696 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
697 push(@{ $form->{invnumber} },
698 ($form->{ARAP} eq 'AR')
699 ? $locale->text('Deposit')
700 : $locale->text('Prepayment'));
701 push(@{ $form->{invdate} }, $form->{datepaid});
704 $lxdebug->leave_sub();