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}"} };
77 CP->paymentaccounts(\%myconfig, \%$form);
79 $form->{selectaccount} = "";
80 $form->{"select$form->{ARAP}"} = "";
82 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
83 @{ $form->{PR}{"$form->{ARAP}_paid"} };
85 $form->{"select$form->{ARAP}"} .=
86 "<option>$_->{accno}--$_->{description}\n"
87 } @{ $form->{PR}{ $form->{ARAP} } };
90 # oldcurrency ist zwar noch hier als fragment enthalten, wird aber bei
91 # der aktualisierung der form auch nicht mitübernommen. das konzept
92 # old_$FOO habe ich auch noch nicht verstanden ...
93 # Ok. Wenn currency übernommen werden, dann in callback-string über-
94 # geben und hier reinparsen, oder besser multibox oder html auslagern?
95 # Antwort: form->currency wird mit oldcurrency oder curr[0] überschrieben
96 # Wofür macht das Sinn?
97 @curr = split(/:/, $form->{currencies});
99 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
102 $form->{selectcurrency} = "";
103 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
109 $lxdebug->leave_sub();
113 $lxdebug->enter_sub();
115 $auth->assert('cash');
117 my ($vc, $vclabel, $allvc, $arap, $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>
158 foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}) {
159 $form->{"select$item"} =~ s/ selected//;
160 $form->{"select$item"} =~
161 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
165 ($form->{"select$form->{vc}"})
166 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
167 : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
169 if ($form->{all_vc}) {
171 $form->{openinvoices} = "";
174 $form->{openinvoices} = 1;
177 # $locale->text('AR')
178 # $locale->text('AP')
180 $form->{jsscript} = 1;
182 if ($form->{jsscript}) {
184 # with JavaScript Calendar
186 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}" onBlur=\"check_right_date_format(this)\">
187 <input type=button name=datepaid id="trigger1" value=|
188 . $locale->text('button') . qq|></td>
193 Form->write_trigger(\%myconfig, "1", "datepaid", "BL", "trigger1");
196 # without JavaScript Calendar
198 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
200 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
203 $arap = lc $form->{ARAP};
204 $onload = qq|focus()|;
205 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
206 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
208 <body onLoad="$onload">
210 <form method=post action=cp.pl>
212 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
213 <input type=hidden name=closedto value=$form->{closedto}>
214 <input type=hidden name=vc value=$form->{vc}>
215 <input type=hidden name=type value=$form->{type}>
216 <input type=hidden name=formname value=$form->{type}>
217 <input type=hidden name=queued value="$form->{queued}">
218 <input type=hidden name=arap value=$arap>
219 <input type=hidden name=ARAP value=$form->{ARAP}>
220 <input type=hidden name=openinvoices value=$form->{openinvoices}>
221 <input type=hidden name=title value="$form->{title}">
222 <input type=hidden name=origtitle value="$form->{origtitle}">
226 <th class=listtop>$form->{title}</th>
236 <th align=right>$vclabel</th>
238 <input type=hidden name="select$form->{vc}" value="| . H($form->{"select$form->{vc}"}) . qq|">
239 <input type=hidden name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
240 <input type=hidden name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
243 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
247 <td>$form->{street}</td>
250 <td>$form->{zipcode}</td>
253 <td>$form->{city}</td>
256 <td>$form->{country}</td>
260 <input type=hidden name=street value="$form->{street}">
261 <input type=hidden name=zipcode value="$form->{zipcode}">
262 <input type=hidden name=city value="$form->{city}">
263 <input type=hidden name=country value="$form->{country}">
266 <th align=right>| . $locale->text('Memo') . qq|</th>
267 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
274 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
275 <td colspan=3><select name=account>$form->{selectaccount}</select>
276 <input type=hidden name=selectaccount value="$form->{selectaccount}">
280 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
284 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
285 <td><select name=currency>$form->{selectcurrency}</select></td>
286 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
287 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
291 <th align=right nowrap>| . $locale->text('Source') . qq|</th>
292 <td colspan=3><input name=source value="$form->{source}" size=10></td>
295 <th align="right" nowrap>| . $locale->text('Amount') . qq|</th>
296 <td colspan="3">| . $form->format_amount(\%myconfig, $form->{amount}, 2) . qq|</td>
308 if ($form->{openinvoices_other_currencies}) {
309 my $warning = $form->{vc} eq 'customer' ? $::locale->text('There are #1 more open invoices for this customer with other currencies.', $form->{openinvoices_other_currencies})
310 : $::locale->text('There are #1 more open invoices from this vendor with other currencies.', $form->{openinvoices_other_currencies});
314 <input type="hidden" name="openinvoices_other_currencies" value="| . H($form->{openinvoices_other_currencies}) . qq|">
316 <td><b>| . $::locale->text('Note') . qq|: $warning</b></td>
321 $lxdebug->leave_sub();
325 $lxdebug->enter_sub();
327 $auth->assert('cash');
329 my (@column_index, %column_data, $colspan, $invoice);
330 my ($totalamount, $totaldue, $totalpaid);
332 @column_index = qw(invnumber transdate amount due checked paid);
334 $colspan = $#column_index + 1;
336 $invoice = $locale->text('Invoices');
339 <input type=hidden name=column_index value="id @column_index">
344 <th class=listheading colspan=$colspan>$invoice</th>
348 $column_data{invnumber} =
349 qq|<th nowrap class=listheading>| . $locale->text('Invoice') . "</th>";
350 $column_data{transdate} =
351 qq|<th nowrap class=listheading>| . $locale->text('Date') . "</th>";
352 $column_data{amount} =
353 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
355 qq|<th nowrap class=listheading>| . $locale->text('Due') . "</th>";
357 qq|<th nowrap class=listheading>| . $locale->text('Amount') . "</th>";
358 $column_data{checked} =
359 qq|<th nowrap class=listheading>| . $locale->text('Select') . "</th>";
364 map { print "$column_data{$_}\n" } @column_index;
369 for my $i (1 .. $form->{rowcount}) {
375 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
376 } qw(amount due paid);
378 $totalamount += $form->{"amount_$i"};
379 $totaldue += $form->{"due_$i"};
380 $totalpaid += $form->{"paid_$i"};
384 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
385 } qw(amount due paid);
387 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
388 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
389 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
390 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
391 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
392 $column_data{amount} =
393 qq|<td align=right width=15%>$form->{"amount_$i"}</td>
394 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
395 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
396 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
399 qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
401 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
402 $column_data{checked} =
403 qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
410 map { print "$column_data{$_}\n" } @column_index;
416 map { $column_data{$_} = "<td> </td>" } @column_index;
418 $column_data{amount} =
419 qq|<th class=listtotal align=right>|
420 . $form->format_amount(\%myconfig, $totalamount, 2, " ")
423 qq|<th class=listtotal align=right>|
424 . $form->format_amount(\%myconfig, $totaldue, 2, " ")
427 qq|<th class=listtotal align=right>|
428 . $form->format_amount(\%myconfig, $totalpaid, 2, " ")
434 map { print "$column_data{$_}\n" } @column_index;
442 $lxdebug->leave_sub();
446 $lxdebug->enter_sub();
448 $auth->assert('cash');
452 <td><hr size=3 noshade></td>
455 <input type=hidden name=rowcount value=$form->{rowcount}>
458 <input class=submit type=submit name=action value="|
459 . $locale->text('Update') . qq|">
460 <input class=submit type=submit name=action value="|
461 . $locale->text('Post') . qq|">
468 $lxdebug->leave_sub();
472 $lxdebug->enter_sub();
474 $auth->assert('cash');
476 my ($new_name_selected) = @_;
478 my ($buysell, $newvc, $updated, $exchangerate, $amount);
480 if ($form->{vc} eq 'customer') {
486 # if we switched to all_vc
487 # funktioniert derzeit nicht 12.10.2010 jb
488 if ($form->{all_vc} ne $form->{oldall_vc}) {
490 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
492 $form->{"select$form->{vc}"} = "";
494 if ($form->{all_vc}) {
495 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
497 if ($form->{"all_$form->{vc}"}) {
499 $form->{"select$form->{vc}"} .=
500 "<option>$_->{name}--$_->{id}\n"
501 } @{ $form->{"all_$form->{vc}"} };
503 } else { # ab hier wieder ausgeführter code (s.o.):
504 CP->get_openvc(\%myconfig, \%$form);
506 if ($form->{"all_$form->{vc}"}) {
508 qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
510 $form->{"select$form->{vc}"} .=
511 "<option>$_->{name}--$_->{id}\n"
512 } @{ $form->{"all_$form->{vc}"} };
515 # if the name is not the same
516 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
517 $form->{ $form->{vc} } = $newvc;
522 # get customer and invoices
523 $updated = &check_name($form->{vc});
525 if ($new_name_selected || $updated) {
526 CP->get_openinvoices(\%myconfig, \%$form);
527 ($newvc) = split /--/, $form->{ $form->{vc} };
528 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
532 if ($form->{currency} ne $form->{oldcurrency}) {
533 $form->{oldcurrency} = $form->{currency};
535 CP->get_openinvoices(\%myconfig, \%$form);
540 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{datepaid}, $buysell);
541 $form->{exchangerate} = $form->{forex} if $form->{forex};
543 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
546 $form->{rowcount} = 0;
548 $form->{queued} = "";
551 foreach my $ref (@{ $form->{PR} }) {
553 $form->{"id_$i"} = $ref->{id};
554 $form->{"invnumber_$i"} = $ref->{invnumber};
555 $form->{"transdate_$i"} = $ref->{transdate};
556 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
557 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
559 ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
560 $form->{"checked_$i"} = "";
561 $form->{"paid_$i"} = "";
566 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
570 $form->{rowcount} = $i;
575 # Modified from $amount = $form->{amount} by J.Zach to update amount to total
576 # payment amount in Zahlungsausgang
578 for my $i (1 .. $form->{rowcount}) {
582 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
583 } qw(amount due paid);
585 if ($form->{"checked_$i"}) {
588 if (!$form->{"paid_$i"}) {
589 $form->{"paid_$i"} = $form->{"due_$i"};
592 # Modified by J.Zach, see abovev
593 $amount += $form->{"paid_$i"};
596 $form->{"paid_$i"} = "";
601 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
602 } qw(amount due paid);
606 # Line added by J.Zach, see above
607 $form->{amount}=$amount;
613 $lxdebug->leave_sub();
617 $lxdebug->enter_sub();
619 $auth->assert('cash');
623 if ($form->{currency} ne $form->{defaultcurrency}) {
624 $form->error($locale->text('Exchangerate missing!'))
625 unless $form->{exchangerate};
628 # Beim Aktualisieren wird das Konto übernommen
629 $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&type=$form->{type}&account=$form->{account}&$form->{currency}";
631 my $msg1 = "$form->{origtitle} posted!";
632 my $msg2 = "Cannot post $form->{origtitle}!";
634 # $locale->text('Payment posted!')
635 # $locale->text('Receipt posted!')
636 # $locale->text('Cannot post Payment!')
637 # $locale->text('Cannot post Receipt!')
638 # Die Nachrichten (Receipt posted!) werden nicht angezeigt.
639 # Entweder wieder aktivieren oder komplett rausnehmen
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('Amount has to be greater then zero! Wrong 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();