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 # Dieser Zweig funktioniert derzeit NIE. Ggf. ganz raus oder
62 # alle offenen Zahlungen wieder korrekt anzeigen. jb 12.10.2010
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}"}) {
72 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
73 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
74 @{ $form->{"all_$form->{vc}"} };
78 # auf departments kann man auch nicht mehr buchen. Raus oder wieder
79 # aktivieren? Im Backend dann auch anpassen. jb 12.10.2010
80 if (@{ $form->{all_departments} || [] }) {
81 $form->{selectdepartment} = "<option>\n";
82 $form->{department} = "$form->{department}--$form->{department_id}";
85 $form->{selectdepartment} .=
86 "<option>$_->{description}--$_->{id}\n"
87 } (@{ $form->{all_departments} || [] });
90 CP->paymentaccounts(\%myconfig, \%$form);
92 $form->{selectaccount} = "";
93 $form->{"select$form->{ARAP}"} = "";
95 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
96 @{ $form->{PR}{"$form->{ARAP}_paid"} };
98 $form->{"select$form->{ARAP}"} .=
99 "<option>$_->{accno}--$_->{description}\n"
100 } @{ $form->{PR}{ $form->{ARAP} } };
103 # oldcurrency ist zwar noch hier als fragment enthalten, wird aber bei
104 # der aktualisierung der form auch nicht mitübernommen. das konzept
105 # old_$FOO habe ich auch noch nicht verstanden ...
106 # Ok. Wenn currency übernommen werden, dann in callback-string über-
107 # geben und hier reinparsen, oder besser multibox oder html auslagern?
108 @curr_unsorted = split(/:/, $form->{currencies});
109 chomp $curr_unsorted[0];
110 @curr = sort {} @curr_unsorted;
111 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
114 $form->{selectcurrency} = "";
115 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
121 $lxdebug->leave_sub();
125 $lxdebug->enter_sub();
127 $auth->assert('cash');
129 my ($vc, $vclabel, $allvc, $arap, $department, $exchangerate);
130 my ($jsscript, $button1, $button2, $onload);
132 $vclabel = ucfirst $form->{vc};
133 $vclabel = $locale->text($vclabel);
135 if ($form->{type} eq 'receipt') {
136 $form->{title} = $locale->text('Receipt');
137 $form->{origtitle} = "Receipt";
139 if ($form->{type} eq 'check') {
140 $form->{title} = $locale->text('Payment');
141 $form->{origtitle} = "Payment";
144 # $locale->text('Customer')
145 # $locale->text('Vendor')
147 if ($form->{ $form->{vc} } eq "") {
148 map { $form->{"addr$_"} = "" } (1 .. 4);
151 if ($form->{currency} ne $form->{defaultcurrency}) {
152 $form->{exchangerate} =
153 $form->format_amount(\%myconfig, $form->{exchangerate});
154 if ($form->{forex}) {
157 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
158 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
164 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
165 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
171 foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}, "department") {
172 $form->{"select$item"} =~ s/ selected//;
173 $form->{"select$item"} =~
174 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
178 ($form->{"select$form->{vc}"})
179 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
180 : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
182 if ($form->{all_vc}) {
184 $form->{openinvoices} = "";
187 $form->{openinvoices} = 1;
190 # $locale->text('AR')
191 # $locale->text('AP')
193 $form->{jsscript} = 1;
195 if ($form->{jsscript}) {
197 # with JavaScript Calendar
199 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
200 <input type=button name=datepaid id="trigger1" value=|
201 . $locale->text('button') . qq|></td>
206 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
209 # without JavaScript Calendar
211 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
213 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
216 $arap = lc $form->{ARAP};
217 $onload = qq|focus()|;
218 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
219 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
221 <body onLoad="$onload">
223 <form method=post action=cp.pl>
225 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
226 <input type=hidden name=closedto value=$form->{closedto}>
227 <input type=hidden name=vc value=$form->{vc}>
228 <input type=hidden name=type value=$form->{type}>
229 <input type=hidden name=formname value=$form->{type}>
230 <input type=hidden name=queued value="$form->{queued}">
231 <input type=hidden name=arap value=$arap>
232 <input type=hidden name=ARAP value=$form->{ARAP}>
233 <input type=hidden name=openinvoices value=$form->{openinvoices}>
234 <input type=hidden name=title value="$form->{title}">
235 <input type=hidden name=origtitle value="$form->{origtitle}">
239 <th class=listtop>$form->{title}</th>
249 <th align=right>$vclabel</th>
251 <input type=hidden name="select$form->{vc}" value="| . H($form->{"select$form->{vc}"}) . qq|">
252 <input type=hidden name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
253 <input type=hidden name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
256 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
260 <td>$form->{street}</td>
263 <td>$form->{zipcode}</td>
266 <td>$form->{city}</td>
269 <td>$form->{country}</td>
273 <input type=hidden name=street value="$form->{street}">
274 <input type=hidden name=zipcode value="$form->{zipcode}">
275 <input type=hidden name=city value="$form->{city}">
276 <input type=hidden name=country value="$form->{country}">
279 <th align=right>| . $locale->text('Memo') . qq|</th>
280 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
288 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
289 <td colspan=3><select name=account>$form->{selectaccount}</select>
290 <input type=hidden name=selectaccount value="$form->{selectaccount}">
294 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
298 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
299 <td><select name=currency>$form->{selectcurrency}</select></td>
300 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
301 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
305 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
306 <td colspan=3><input name=source value="$form->{source}" size=10></td>
309 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
310 <td colspan="3">| . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|</td>
322 if ($form->{openinvoices_other_currencies}) {
323 my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
324 : $::locale->text('There are #1 more open invoices from this vendor with other currencies.', $form->{openinvoices_other_currencies});
328 <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
330 <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
335 $lxdebug->leave_sub();
339 $lxdebug->enter_sub();
341 $auth->assert('cash');
343 my (@column_index, %column_data, $colspan, $invoice);
344 my ($totalamount, $totaldue, $totalpaid);
346 @column_index = qw(invnumber transdate amount due checked paid);
348 $colspan = $#column_index + 1;
350 $invoice = $locale->text('Invoices');
353 <input type=hidden name=column_index value="id @column_index">
358 <th class=listheading colspan=$colspan>$invoice</th>
362 $column_data{invnumber} =
363 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
364 $column_data{transdate} =
365 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
366 $column_data{amount} =
367 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
369 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
371 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
372 $column_data{checked} =
373 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
378 map { print "$column_data{$_}\n" } @column_index;
383 for my $i (1 .. $form->{rowcount}) {
389 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
390 } qw(amount due paid);
392 $totalamount += $form->{"amount_$i"};
393 $totaldue += $form->{"due_$i"};
394 $totalpaid += $form->{"paid_$i"};
398 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
399 } qw(amount due paid);
401 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
402 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
403 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
404 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
405 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
406 $column_data{amount} =
407 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
408 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
409 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
410 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
413 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
415 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
416 $column_data{checked} =
417 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
424 map { print "$column_data{$_}\n" } @column_index;
430 map { $column_data{$_} = "<td> </td>" } @column_index;
432 $column_data{amount} =
433 qq|<th class=listtotal align=right>|
434 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
437 qq|<th class=listtotal align=right>|
438 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
441 qq|<th class=listtotal align=right>|
442 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
448 map { print "$column_data{$_}\n" } @column_index;
456 $lxdebug->leave_sub();
460 $lxdebug->enter_sub();
462 $auth->assert('cash');
466 <td><hr size=3 noshade></td>
469 <input type=hidden name=rowcount value=$form->{rowcount}>
472 <input class=submit type=submit name=action value="|
473 . $locale->text('Update') . qq|">
474 <input class=submit type=submit name=action value="|
475 . $locale->text('Post') . qq|">
482 $lxdebug->leave_sub();
486 $lxdebug->enter_sub();
488 $auth->assert('cash');
490 my ($new_name_selected) = @_;
492 my ($buysell, $newvc, $updated, $exchangerate, $amount);
494 if ($form->{vc} eq 'customer') {
500 # if we switched to all_vc
501 # funktioniert derzeit nicht 12.10.2010 jb
502 if ($form->{all_vc} ne $form->{oldall_vc}) {
504 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
506 $form->{"select$form->{vc}"} = "";
508 if ($form->{all_vc}) {
509 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
511 if ($form->{"all_$form->{vc}"}) {
513 $form->{"select$form->{vc}"} .=
514 "<option>$_->{name}--$_->{id}\n"
515 } @{ $form->{"all_$form->{vc}"} };
517 } else { # ab hier wieder ausgeführter code (s.o.):
518 CP->get_openvc(\%myconfig, \%$form);
520 if ($form->{"all_$form->{vc}"}) {
522 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
524 $form->{"select$form->{vc}"} .=
525 "<option>$_->{name}--$_->{id}\n"
526 } @{ $form->{"all_$form->{vc}"} };
529 # if the name is not the same
530 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
531 $form->{ $form->{vc} } = $newvc;
536 # get customer and invoices
537 $updated = &check_name($form->{vc});
539 if ($new_name_selected || $updated) {
540 CP->get_openinvoices(\%myconfig, \%$form);
541 ($newvc) = split /--/, $form->{ $form->{vc} };
542 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
546 if ($form->{currency} ne $form->{oldcurrency}) {
547 $form->{oldcurrency} = $form->{currency};
549 CP->get_openinvoices(\%myconfig, \%$form);
554 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
555 $form->{exchangerate} = $form->{forex} if $form->{forex};
557 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
560 $form->{rowcount} = 0;
562 $form->{queued} = "";
565 foreach my $ref (@{ $form->{PR} }) {
567 $form->{"id_$i"} = $ref->{id};
568 $form->{"invnumber_$i"} = $ref->{invnumber};
569 $form->{"transdate_$i"} = $ref->{transdate};
570 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
571 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
573 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
574 $form->{"checked_$i"} = "";
575 $form->{"paid_$i"} = "";
580 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
584 $form->{rowcount} = $i;
589 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
590 # payment amount in Zahlungsausgang
592 for my $i (1 .. $form->{rowcount}) {
596 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
597 } qw(amount due paid);
599 if ($form->{"checked_$i"}) {
602 if (!$form->{"paid_$i"}) {
603 $form->{"paid_$i"} = $form->{"due_$i"};
606 # Modified by J.Zach, see abovev
607 $amount += $form->{"paid_$i"};
610 $form->{"paid_$i"} = "";
615 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
616 } qw(amount due paid);
620 # Line added by J.Zach, see above
621 $form->{amount}=$amount;
627 $lxdebug->leave_sub();
631 $lxdebug->enter_sub();
633 $auth->assert('cash');
637 if ($form->{currency} ne $form->{defaultcurrency}) {
638 $form->error($locale->text('Exchangerate missing!'))
639 unless $form->{exchangerate};
641 # Beim Aktualisieren wird das Konto übernommen
642 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&muh=kuh&account=$form->{account}";
644 my $msg1 = "$form->{origtitle} posted!";
645 my $msg2 = "Cannot post $form->{origtitle}!";
647 # $locale->text('Payment posted!')
648 # $locale->text('Receipt posted!')
649 # $locale->text('Cannot post Payment!')
650 # $locale->text('Cannot post Receipt!')
651 # Die Nachrichten (Receipt posted!) werden nicht angezeigt.
652 # Entweder wieder aktivieren oder komplett rausnehmen
653 $form->redirect($locale->text($msg1))
654 if (CP->process_payment(\%myconfig, \%$form));
655 $form->error($locale->text($msg2));
657 $lxdebug->leave_sub();
661 $lxdebug->enter_sub();
663 $auth->assert('cash');
665 my ($closedto, $datepaid, $amount);
667 &check_name($form->{vc});
669 if ($form->{currency} ne $form->{oldcurrency}) {
673 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
674 my $selected_check = 1;
675 for my $i (1 .. $form->{rowcount}) {
676 if ($form->{"checked_$i"}) {
677 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"}, 2) <= 0) { # negativen Betrag eingegeben
678 $form->error($locale->text('No zero or negative values, please! Correct row number:' . $i));
680 undef($selected_check);
681 # last; # ich muss doch über alle buchungen laufen, da ich noch
682 # die freitext-eingabe der werte prüfen will
685 $form->error($locale->text('No transaction selected!')) if $selected_check;
687 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
688 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
690 $form->error($locale->text('Cannot process payment for a closed period!'))
691 if ($form->date_closed($form->{"datepaid"}, \%myconfig));
693 $amount = $form->parse_amount(\%myconfig, $form->{amount});
694 $form->{amount} = $amount;
696 for my $i (1 .. $form->{rowcount}) {
697 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
698 $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
700 push(@{ $form->{paid} }, $form->{"paid_$i"});
701 push(@{ $form->{due} }, $form->{"due_$i"});
702 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
703 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
707 if ($form->round_amount($amount, 2) != 0) {
708 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
709 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
710 push(@{ $form->{invnumber} },
711 ($form->{ARAP} eq 'AR')
712 ? $locale->text('Deposit')
713 : $locale->text('Prepayment'));
714 push(@{ $form->{invdate} }, $form->{datepaid});
717 $lxdebug->leave_sub();