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 # Dieser Zweig funktioniert derzeit NIE. Ggf. ganz raus oder
64 # alle offenen Zahlungen wieder korrekt anzeigen. jb 12.10.2010
65 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
67 CP->get_openvc(\%myconfig, \%$form);
70 $form->{"select$form->{vc}"} = "";
72 if ($form->{"all_$form->{vc}"}) {
74 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
75 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
76 @{ $form->{"all_$form->{vc}"} };
79 CP->paymentaccounts(\%myconfig, \%$form);
81 # Standard Konto für Umlaufvermögen
82 my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
84 $form->{selectaccount} = "";
85 $form->{"select$form->{ARAP}"} = "";
87 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n";
88 $form->{account} = "$_->{accno}--$_->{description}" if ($_->{accno} eq $accno_arap) } @{ $form->{PR}{"$form->{ARAP}_paid"} };
90 # Braucht man das hier überhaupt? Erstmal auskommentieren .. jan 18.12.2010
92 # $form->{"select$form->{ARAP}"} .=
93 # "<option>$_->{accno}--$_->{description}\n"
94 # } @{ $form->{PR}{ $form->{ARAP} } };
95 # ENDE LOESCHMICH in 2012
98 # oldcurrency ist zwar noch hier als fragment enthalten, wird aber bei
99 # der aktualisierung der form auch nicht mitübernommen. das konzept
100 # old_$FOO habe ich auch noch nicht verstanden ...
101 # Ok. Wenn currency übernommen werden, dann in callback-string über-
102 # geben und hier reinparsen, oder besser multibox oder html auslagern?
103 # Antwort: form->currency wird mit oldcurrency oder curr[0] überschrieben
104 # Wofür macht das Sinn?
105 @curr = split(/:/, $form->{currencies});
107 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
110 $form->{selectcurrency} = "";
111 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
117 $lxdebug->leave_sub();
121 $lxdebug->enter_sub();
123 $auth->assert('cash');
125 my ($vc, $vclabel, $allvc, $arap, $exchangerate);
126 my ($jsscript, $button1, $button2, $onload);
128 $vclabel = ucfirst $form->{vc};
129 $vclabel = $locale->text($vclabel);
131 if ($form->{type} eq 'receipt') {
132 $form->{title} = $locale->text('Receipt');
133 $form->{origtitle} = "Receipt";
135 if ($form->{type} eq 'check') {
136 $form->{title} = $locale->text('Payment');
137 $form->{origtitle} = "Payment";
140 # $locale->text('Customer')
141 # $locale->text('Vendor')
143 if ($form->{ $form->{vc} } eq "") {
144 map { $form->{"addr$_"} = "" } (1 .. 4);
147 if ($form->{currency} ne $form->{defaultcurrency}) {
148 $form->{exchangerate} =
149 $form->format_amount(\%myconfig, $form->{exchangerate});
150 if ($form->{forex}) {
153 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
154 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
160 <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
161 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
166 foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}) {
167 $form->{"select$item"} =~ s/ selected//;
168 $form->{"select$item"} =~
169 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
173 ($form->{"select$form->{vc}"})
174 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
175 : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
177 if ($form->{all_vc}) {
179 $form->{openinvoices} = "";
182 $form->{openinvoices} = 1;
185 # $locale->text('AR')
186 # $locale->text('AP')
188 $form->{jsscript} = 1;
190 if ($form->{jsscript}) {
192 # with JavaScript Calendar
194 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
195 <input type=button name=datepaid id="trigger1" value=|
196 . $locale->text('button') . qq|></td>
201 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
204 # without JavaScript Calendar
206 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
208 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
211 $arap = lc $form->{ARAP};
212 $onload = qq|focus()|;
213 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
214 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
216 <body onLoad="$onload">
218 <form method=post action=cp.pl>
220 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
221 <input type=hidden name=closedto value=$form->{closedto}>
222 <input type=hidden name=vc value=$form->{vc}>
223 <input type=hidden name=type value=$form->{type}>
224 <input type=hidden name=formname value=$form->{type}>
225 <input type=hidden name=queued value="$form->{queued}">
226 <input type=hidden name=arap value=$arap>
227 <input type=hidden name=ARAP value=$form->{ARAP}>
228 <input type=hidden name=openinvoices value=$form->{openinvoices}>
229 <input type=hidden name=title value="$form->{title}">
230 <input type=hidden name=origtitle value="$form->{origtitle}">
234 <th class=listtop>$form->{title}</th>
244 <th align=right>$vclabel</th>
246 <input type=hidden name="select$form->{vc}" value="| . H($form->{"select$form->{vc}"}) . qq|">
247 <input type=hidden name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
248 <input type=hidden name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
251 <th align=right>| . $locale->text('Invoice Number') . qq|</th>
252 <td><input name="invnumber" size="35"</td>
255 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
259 <td>$form->{street}</td>
262 <td>$form->{zipcode}</td>
265 <td>$form->{city}</td>
268 <td>$form->{country}</td>
272 <input type=hidden name=street value="$form->{street}">
273 <input type=hidden name=zipcode value="$form->{zipcode}">
274 <input type=hidden name=city value="$form->{city}">
275 <input type=hidden name=country value="$form->{country}">
278 <th align=right>| . $locale->text('Memo') . qq|</th>
279 <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">| . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|</td>
320 if ($form->{openinvoices_other_currencies}) {
321 my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
322 : $::locale->text('There are #1 more open invoices from this vendor with other currencies.', $form->{openinvoices_other_currencies});
326 <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
328 <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
333 $lxdebug->leave_sub();
337 $lxdebug->enter_sub();
339 $auth->assert('cash');
341 my (@column_index, %column_data, $colspan, $invoice);
342 my ($totalamount, $totaldue, $totalpaid);
344 @column_index = qw(invnumber transdate amount due checked paid);
346 $colspan = $#column_index + 1;
348 $invoice = $locale->text('Invoices');
351 <input type=hidden name=column_index value="id @column_index">
356 <th class=listheading colspan=$colspan>$invoice</th>
360 $column_data{invnumber} =
361 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
362 $column_data{transdate} =
363 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
364 $column_data{amount} =
365 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
367 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
369 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
370 $column_data{checked} =
371 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
376 map { print "$column_data{$_}\n" } @column_index;
381 for my $i (1 .. $form->{rowcount}) {
387 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
388 } qw(amount due paid);
390 $totalamount += $form->{"amount_$i"};
391 $totaldue += $form->{"due_$i"};
392 $totalpaid += $form->{"paid_$i"};
396 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
397 } qw(amount due paid);
399 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
400 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
401 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
402 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
403 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
404 $column_data{amount} =
405 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
406 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
407 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
408 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
411 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
413 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
414 $column_data{checked} =
415 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
422 map { print "$column_data{$_}\n" } @column_index;
428 map { $column_data{$_} = "<td> </td>" } @column_index;
430 $column_data{amount} =
431 qq|<th class=listtotal align=right>|
432 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
435 qq|<th class=listtotal align=right>|
436 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
439 qq|<th class=listtotal align=right>|
440 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
446 map { print "$column_data{$_}\n" } @column_index;
454 $lxdebug->leave_sub();
458 $lxdebug->enter_sub();
460 $auth->assert('cash');
464 <td><hr size=3 noshade></td>
467 <input type=hidden name=rowcount value=$form->{rowcount}>
470 <input class=submit type=submit name=action value="|
471 . $locale->text('Update') . qq|">
472 <input class=submit type=submit name=action value="|
473 . $locale->text('Post') . qq|">
480 $lxdebug->leave_sub();
484 $lxdebug->enter_sub();
486 $auth->assert('cash');
488 my ($new_name_selected) = @_;
490 my ($buysell, $newvc, $updated, $exchangerate, $amount);
492 if ($form->{vc} eq 'customer') {
498 # if we switched to all_vc
499 # funktioniert derzeit nicht 12.10.2010 jb
500 if ($form->{all_vc} ne $form->{oldall_vc}) {
502 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
504 $form->{"select$form->{vc}"} = "";
506 if ($form->{all_vc}) {
507 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
509 if ($form->{"all_$form->{vc}"}) {
511 $form->{"select$form->{vc}"} .=
512 "<option>$_->{name}--$_->{id}\n"
513 } @{ $form->{"all_$form->{vc}"} };
515 } else { # ab hier wieder ausgeführter code (s.o.):
516 CP->get_openvc(\%myconfig, \%$form);
518 if ($form->{"all_$form->{vc}"}) {
520 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
522 $form->{"select$form->{vc}"} .=
523 "<option>$_->{name}--$_->{id}\n"
524 } @{ $form->{"all_$form->{vc}"} };
527 # if the name is not the same
528 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
529 $form->{ $form->{vc} } = $newvc;
533 # Falls Suche über Rechnungsnummer und kein Kundenname vorhanden
534 if ($form->{invnumber} && !($form->{$form->{vc}})){
535 $form->{open} ='Y'; # nur die offenen rechnungen
536 if ($form->{ARAP} eq 'AR'){
537 AR->ar_transactions(\%myconfig, \%$form);
538 # den ersten treffen nehmen und mit dem namen überschreiben
539 $form->{$form->{vc}} = $form->{AR}[0]{name};
541 # s.o. nur für zahlungsausgang
542 AP->ap_transactions(\%myconfig, \%$form);
543 $form->{$form->{vc}} = $form->{AP}[0]{name};
546 # get customer and invoices
547 $updated = &check_name($form->{vc});
549 if ($new_name_selected || $updated) {
550 CP->get_openinvoices(\%myconfig, \%$form);
551 ($newvc) = split /--/, $form->{ $form->{vc} };
552 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
556 if ($form->{currency} ne $form->{oldcurrency}) {
557 $form->{oldcurrency} = $form->{currency};
559 CP->get_openinvoices(\%myconfig, \%$form);
564 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
565 $form->{exchangerate} = $form->{forex} if $form->{forex};
567 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
570 $form->{rowcount} = 0;
572 $form->{queued} = "";
575 foreach my $ref (@{ $form->{PR} }) {
577 $form->{"id_$i"} = $ref->{id};
578 $form->{"invnumber_$i"} = $ref->{invnumber};
579 $form->{"transdate_$i"} = $ref->{transdate};
580 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
581 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
583 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
584 $form->{"checked_$i"} = "";
585 $form->{"paid_$i"} = "";
590 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
594 $form->{rowcount} = $i;
599 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
600 # payment amount in Zahlungsausgang
602 for my $i (1 .. $form->{rowcount}) {
606 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
607 } qw(amount due paid);
609 if ($form->{"checked_$i"}) {
612 if (!$form->{"paid_$i"}) {
613 $form->{"paid_$i"} = $form->{"due_$i"};
616 # Modified by J.Zach, see abovev
617 $amount += $form->{"paid_$i"};
620 $form->{"paid_$i"} = "";
625 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
626 } qw(amount due paid);
630 # Line added by J.Zach, see above
631 $form->{amount}=$amount;
637 $lxdebug->leave_sub();
641 $lxdebug->enter_sub();
643 $auth->assert('cash');
647 if ($form->{currency} ne $form->{defaultcurrency}) {
648 $form->error($locale->text('Exchangerate missing!'))
649 unless $form->{exchangerate};
652 # Beim Aktualisieren wird das Konto übernommen
653 # und jetzt auch Beleg und Datum
654 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&type=$form->{type}&account=$form->{account}&$form->{currency}" .
655 "&datepaid=$form->{datepaid}&source=$form->{source}";
657 my $msg1 = "$form->{origtitle} posted!";
658 my $msg2 = "Cannot post $form->{origtitle}!";
660 # $locale->text('Payment posted!')
661 # $locale->text('Receipt posted!')
662 # $locale->text('Cannot post Payment!')
663 # $locale->text('Cannot post Receipt!')
664 # Die Nachrichten (Receipt posted!) werden nicht angezeigt.
665 # Entweder wieder aktivieren oder komplett rausnehmen
666 $form->redirect($locale->text($msg1))
667 if (CP->process_payment(\%myconfig, \%$form));
668 $form->error($locale->text($msg2));
670 $lxdebug->leave_sub();
674 $lxdebug->enter_sub();
676 $auth->assert('cash');
678 my ($closedto, $datepaid, $amount);
680 &check_name($form->{vc});
682 if ($form->{currency} ne $form->{oldcurrency}) {
686 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
687 my $selected_check = 1;
688 for my $i (1 .. $form->{rowcount}) {
689 if ($form->{"checked_$i"}) {
690 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"}, 2) <= 0) { # negativen Betrag eingegeben
691 $form->error($locale->text('Amount has to be greater then zero! Wrong row number: ') . $i);
693 undef($selected_check);
694 # last; # ich muss doch über alle buchungen laufen, da ich noch
695 # die freitext-eingabe der werte prüfen will
698 $form->error($locale->text('No transaction selected!')) if $selected_check;
700 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
701 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
703 $form->error($locale->text('Cannot process payment for a closed period!'))
704 if ($form->date_closed($form->{"datepaid"}, \%myconfig));
706 $amount = $form->parse_amount(\%myconfig, $form->{amount});
707 $form->{amount} = $amount;
709 for my $i (1 .. $form->{rowcount}) {
710 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
711 $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
713 push(@{ $form->{paid} }, $form->{"paid_$i"});
714 push(@{ $form->{due} }, $form->{"due_$i"});
715 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
716 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
720 if ($form->round_amount($amount, 2) != 0) {
721 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
722 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
723 push(@{ $form->{invnumber} },
724 ($form->{ARAP} eq 'AR')
725 ? $locale->text('Deposit')
726 : $locale->text('Prepayment'));
727 push(@{ $form->{invdate} }, $form->{datepaid});
730 $lxdebug->leave_sub();