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 $form->{selectaccount} = "";
82 $form->{"select$form->{ARAP}"} = "";
84 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
85 @{ $form->{PR}{"$form->{ARAP}_paid"} };
87 $form->{"select$form->{ARAP}"} .=
88 "<option>$_->{accno}--$_->{description}\n"
89 } @{ $form->{PR}{ $form->{ARAP} } };
92 # oldcurrency ist zwar noch hier als fragment enthalten, wird aber bei
93 # der aktualisierung der form auch nicht mitübernommen. das konzept
94 # old_$FOO habe ich auch noch nicht verstanden ...
95 # Ok. Wenn currency übernommen werden, dann in callback-string über-
96 # geben und hier reinparsen, oder besser multibox oder html auslagern?
97 # Antwort: form->currency wird mit oldcurrency oder curr[0] überschrieben
98 # Wofür macht das Sinn?
99 @curr = split(/:/, $form->{currencies});
101 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
104 $form->{selectcurrency} = "";
105 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
111 $lxdebug->leave_sub();
115 $lxdebug->enter_sub();
117 $auth->assert('cash');
119 my ($vc, $vclabel, $allvc, $arap, $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>
160 foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}) {
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>| . $locale->text('Invoice Number') . qq|</th>
246 <td><input name="invnumber" size="35"</td>
249 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
253 <td>$form->{street}</td>
256 <td>$form->{zipcode}</td>
259 <td>$form->{city}</td>
262 <td>$form->{country}</td>
266 <input type=hidden name=street value="$form->{street}">
267 <input type=hidden name=zipcode value="$form->{zipcode}">
268 <input type=hidden name=city value="$form->{city}">
269 <input type=hidden name=country value="$form->{country}">
272 <th align=right>| . $locale->text('Memo') . qq|</th>
273 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
280 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
281 <td colspan=3><select name=account>$form->{selectaccount}</select>
282 <input type=hidden name=selectaccount value="$form->{selectaccount}">
286 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
290 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
291 <td><select name=currency>$form->{selectcurrency}</select></td>
292 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
293 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
297 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
298 <td colspan=3><input name=source value="$form->{source}" size=10></td>
301 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
302 <td colspan="3">| . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|</td>
314 if ($form->{openinvoices_other_currencies}) {
315 my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
316 : $::locale->text('There are #1 more open invoices from this vendor with other currencies.', $form->{openinvoices_other_currencies});
320 <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
322 <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
327 $lxdebug->leave_sub();
331 $lxdebug->enter_sub();
333 $auth->assert('cash');
335 my (@column_index, %column_data, $colspan, $invoice);
336 my ($totalamount, $totaldue, $totalpaid);
338 @column_index = qw(invnumber transdate amount due checked paid);
340 $colspan = $#column_index + 1;
342 $invoice = $locale->text('Invoices');
345 <input type=hidden name=column_index value="id @column_index">
350 <th class=listheading colspan=$colspan>$invoice</th>
354 $column_data{invnumber} =
355 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
356 $column_data{transdate} =
357 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
358 $column_data{amount} =
359 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
361 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
363 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
364 $column_data{checked} =
365 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
370 map { print "$column_data{$_}\n" } @column_index;
375 for my $i (1 .. $form->{rowcount}) {
381 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
382 } qw(amount due paid);
384 $totalamount += $form->{"amount_$i"};
385 $totaldue += $form->{"due_$i"};
386 $totalpaid += $form->{"paid_$i"};
390 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
391 } qw(amount due paid);
393 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
394 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
395 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
396 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
397 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
398 $column_data{amount} =
399 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
400 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
401 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
402 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
405 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
407 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
408 $column_data{checked} =
409 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
416 map { print "$column_data{$_}\n" } @column_index;
422 map { $column_data{$_} = "<td> </td>" } @column_index;
424 $column_data{amount} =
425 qq|<th class=listtotal align=right>|
426 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
429 qq|<th class=listtotal align=right>|
430 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
433 qq|<th class=listtotal align=right>|
434 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
440 map { print "$column_data{$_}\n" } @column_index;
448 $lxdebug->leave_sub();
452 $lxdebug->enter_sub();
454 $auth->assert('cash');
458 <td><hr size=3 noshade></td>
461 <input type=hidden name=rowcount value=$form->{rowcount}>
464 <input class=submit type=submit name=action value="|
465 . $locale->text('Update') . qq|">
466 <input class=submit type=submit name=action value="|
467 . $locale->text('Post') . qq|">
474 $lxdebug->leave_sub();
478 $lxdebug->enter_sub();
480 $auth->assert('cash');
482 my ($new_name_selected) = @_;
484 my ($buysell, $newvc, $updated, $exchangerate, $amount);
486 if ($form->{vc} eq 'customer') {
492 # if we switched to all_vc
493 # funktioniert derzeit nicht 12.10.2010 jb
494 if ($form->{all_vc} ne $form->{oldall_vc}) {
496 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
498 $form->{"select$form->{vc}"} = "";
500 if ($form->{all_vc}) {
501 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
503 if ($form->{"all_$form->{vc}"}) {
505 $form->{"select$form->{vc}"} .=
506 "<option>$_->{name}--$_->{id}\n"
507 } @{ $form->{"all_$form->{vc}"} };
509 } else { # ab hier wieder ausgeführter code (s.o.):
510 CP->get_openvc(\%myconfig, \%$form);
512 if ($form->{"all_$form->{vc}"}) {
514 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
516 $form->{"select$form->{vc}"} .=
517 "<option>$_->{name}--$_->{id}\n"
518 } @{ $form->{"all_$form->{vc}"} };
521 # if the name is not the same
522 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
523 $form->{ $form->{vc} } = $newvc;
527 # Falls Suche über Rechnungsnummer und kein Kundenname vorhanden
528 if ($form->{invnumber} && !($form->{$form->{vc}})){
529 $form->{open} ='Y'; # nur die offenen rechnungen
530 if ($form->{ARAP} eq 'AR'){
531 AR->ar_transactions(\%myconfig, \%$form);
532 # den ersten treffen nehmen und mit dem namen überschreiben
533 $form->{$form->{vc}} = $form->{AR}[0]{name};
535 # s.o. nur für zahlungsausgang
536 AP->ap_transactions(\%myconfig, \%$form);
537 $form->{$form->{vc}} = $form->{AP}[0]{name};
540 # get customer and invoices
541 $updated = &check_name($form->{vc});
543 if ($new_name_selected || $updated) {
544 CP->get_openinvoices(\%myconfig, \%$form);
545 ($newvc) = split /--/, $form->{ $form->{vc} };
546 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
550 if ($form->{currency} ne $form->{oldcurrency}) {
551 $form->{oldcurrency} = $form->{currency};
553 CP->get_openinvoices(\%myconfig, \%$form);
558 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
559 $form->{exchangerate} = $form->{forex} if $form->{forex};
561 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
564 $form->{rowcount} = 0;
566 $form->{queued} = "";
569 foreach my $ref (@{ $form->{PR} }) {
571 $form->{"id_$i"} = $ref->{id};
572 $form->{"invnumber_$i"} = $ref->{invnumber};
573 $form->{"transdate_$i"} = $ref->{transdate};
574 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
575 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
577 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
578 $form->{"checked_$i"} = "";
579 $form->{"paid_$i"} = "";
584 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
588 $form->{rowcount} = $i;
593 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
594 # payment amount in Zahlungsausgang
596 for my $i (1 .. $form->{rowcount}) {
600 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
601 } qw(amount due paid);
603 if ($form->{"checked_$i"}) {
606 if (!$form->{"paid_$i"}) {
607 $form->{"paid_$i"} = $form->{"due_$i"};
610 # Modified by J.Zach, see abovev
611 $amount += $form->{"paid_$i"};
614 $form->{"paid_$i"} = "";
619 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
620 } qw(amount due paid);
624 # Line added by J.Zach, see above
625 $form->{amount}=$amount;
631 $lxdebug->leave_sub();
635 $lxdebug->enter_sub();
637 $auth->assert('cash');
641 if ($form->{currency} ne $form->{defaultcurrency}) {
642 $form->error($locale->text('Exchangerate missing!'))
643 unless $form->{exchangerate};
646 # Beim Aktualisieren wird das Konto übernommen
647 # und jetzt auch Beleg und Datum
648 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&type=$form->{type}&account=$form->{account}&$form->{currency}" .
649 "&datepaid=$form->{datepaid}&source=$form->{source}";
651 my $msg1 = "$form->{origtitle} posted!";
652 my $msg2 = "Cannot post $form->{origtitle}!";
654 # $locale->text('Payment posted!')
655 # $locale->text('Receipt posted!')
656 # $locale->text('Cannot post Payment!')
657 # $locale->text('Cannot post Receipt!')
658 # Die Nachrichten (Receipt posted!) werden nicht angezeigt.
659 # Entweder wieder aktivieren oder komplett rausnehmen
660 $form->redirect($locale->text($msg1))
661 if (CP->process_payment(\%myconfig, \%$form));
662 $form->error($locale->text($msg2));
664 $lxdebug->leave_sub();
668 $lxdebug->enter_sub();
670 $auth->assert('cash');
672 my ($closedto, $datepaid, $amount);
674 &check_name($form->{vc});
676 if ($form->{currency} ne $form->{oldcurrency}) {
680 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
681 my $selected_check = 1;
682 for my $i (1 .. $form->{rowcount}) {
683 if ($form->{"checked_$i"}) {
684 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"}, 2) <= 0) { # negativen Betrag eingegeben
685 $form->error($locale->text('Amount has to be greater then zero! Wrong row number: ') . $i);
687 undef($selected_check);
688 # last; # ich muss doch über alle buchungen laufen, da ich noch
689 # die freitext-eingabe der werte prüfen will
692 $form->error($locale->text('No transaction selected!')) if $selected_check;
694 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
695 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
697 $form->error($locale->text('Cannot process payment for a closed period!'))
698 if ($form->date_closed($form->{"datepaid"}, \%myconfig));
700 $amount = $form->parse_amount(\%myconfig, $form->{amount});
701 $form->{amount} = $amount;
703 for my $i (1 .. $form->{rowcount}) {
704 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
705 $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
707 push(@{ $form->{paid} }, $form->{"paid_$i"});
708 push(@{ $form->{due} }, $form->{"due_$i"});
709 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
710 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
714 if ($form->round_amount($amount, 2) != 0) {
715 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
716 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
717 push(@{ $form->{invnumber} },
718 ($form->{ARAP} eq 'AR')
719 ? $locale->text('Deposit')
720 : $locale->text('Prepayment'));
721 push(@{ $form->{invdate} }, $form->{datepaid});
724 $lxdebug->leave_sub();