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 #======================================================================
30 # Accounts Receivables
32 #======================================================================
39 require "$form->{path}/arap.pl";
45 # this is for our long dates
46 # $locale->text('January')
47 # $locale->text('February')
48 # $locale->text('March')
49 # $locale->text('April')
50 # $locale->text('May ')
51 # $locale->text('June')
52 # $locale->text('July')
53 # $locale->text('August')
54 # $locale->text('September')
55 # $locale->text('October')
56 # $locale->text('November')
57 # $locale->text('December')
59 # this is for our short month
60 # $locale->text('Jan')
61 # $locale->text('Feb')
62 # $locale->text('Mar')
63 # $locale->text('Apr')
64 # $locale->text('May')
65 # $locale->text('Jun')
66 # $locale->text('Jul')
67 # $locale->text('Aug')
68 # $locale->text('Sep')
69 # $locale->text('Oct')
70 # $locale->text('Nov')
71 # $locale->text('Dec')
74 $lxdebug->enter_sub();
76 $form->{title} = "Add";
78 "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}"
79 unless $form->{callback};
84 $lxdebug->leave_sub();
88 $lxdebug->enter_sub();
90 $form->{title} = "Edit";
95 $lxdebug->leave_sub();
99 $lxdebug->enter_sub();
104 $lxdebug->leave_sub();
108 $lxdebug->enter_sub();
110 $form->create_links("AR", \%myconfig, "customer");
111 $duedate = $form->{duedate};
113 $taxincluded = $form->{taxincluded};
115 IS->get_customer(\%myconfig, \%$form);
117 $form->{duedate} = $duedate if $duedate;
118 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
119 $form->{rowcount} = 1;
122 @curr = split /:/, $form->{currencies};
124 $form->{defaultcurrency} = $curr[0];
126 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
129 if (@{ $form->{all_customer} }) {
130 $form->{customer} = "$form->{customer}--$form->{customer_id}";
131 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
132 (@{ $form->{all_customer} });
136 if (@{ $form->{all_departments} }) {
137 $form->{selectdepartment} = "<option>\n";
138 $form->{department} = "$form->{department}--$form->{department_id}";
141 $form->{selectdepartment} .=
142 "<option>$_->{description}--$_->{id}\n"
143 } (@{ $form->{all_departments} });
146 $form->{employee} = "$form->{employee}--$form->{employee_id}";
149 if (@{ $form->{all_employees} }) {
150 $form->{selectemployee} = "";
151 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
152 (@{ $form->{all_employees} });
155 # build the popup menus
156 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
160 qq|<option value=\"$_->{taxkey}--$_->{rate}\">$_->{taxdescription} |
161 . ($_->{rate} * 100) . qq| %|
163 $form->{taxchart} = $tax;
164 $form->{selecttaxchart} = $tax;
167 $form->{forex} = $form->{exchangerate};
168 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
169 foreach $key (keys %{ $form->{AR_links} }) {
171 foreach $ref (@{ $form->{AR_links}{$key} }) {
172 if ($key eq "AR_paid") {
173 $form->{"select$key"} .=
174 "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
176 $form->{"select$key"} .=
177 "<option value=\"$ref->{accno}--$ref->{taxkey}\">$ref->{accno}--$ref->{description}</option>\n";
181 $form->{$key} = $form->{"select$key"};
183 # if there is a value we have an old entry
187 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
188 if ($key eq "AR_paid") {
190 $form->{"AR_paid_$j"} =
191 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
194 $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
195 $form->{"datepaid_$j"} =
196 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
197 $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
198 $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
200 $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
201 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
202 $form->{"AR_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
203 $form->{paidaccounts}++;
209 if ($key eq "AR_tax" || $key eq "AP_tax") {
210 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
211 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
212 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
214 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
217 if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
219 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
221 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
224 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
226 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
228 $index = $form->{acc_trans}{$key}->[$i - 1]->{index};
229 $form->{"tax_$index"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
230 $totaltax += $form->{"tax_$index"};
234 $form->{"${akey}_$k"} =
236 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
238 if ($akey eq 'amount') {
240 $totalamount += $form->{"${akey}_$i"};
242 $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} =
243 "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
244 $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
245 $form->{"project_id_$k"} =
246 "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
248 $form->{"${key}_$k"} =
249 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
250 $form->{"${key}_$i"} =
251 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
252 $form->{"select${key}"} =~
253 /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{accno}--[^\"]*)\">$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}<\/option>\n/;
255 $form->{"${key}_$k"} = $1;
256 if ($akey eq 'amount') {
257 $form->{"taxchart_$k"} = $form->{taxchart};
258 $form->{"taxchart_$k"} =~
259 /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{taxkey}--[^\"]*)/;
260 $form->{"taxchart_$k"} = $1;
267 $form->{taxincluded} = $taxincluded if ($form->{id});
268 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
270 if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
272 # add tax to amounts and invtotal
273 for $i (1 .. $form->{rowcount}) {
275 ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
276 $tax = $form->round_amount($taxamount, 2);
277 $diff += ($taxamount - $tax);
278 $form->{"amount_$i"} += $form->{"tax_$i"};
280 $form->{amount_1} += $form->round_amount($diff, 2);
283 $taxamount = $form->round_amount($taxamount, 2);
284 $form->{tax} = $taxamount;
286 $form->{invtotal} = $totalamount + $totaltax;
289 ($form->datetonum($form->{transdate}, \%myconfig) <=
290 $form->datetonum($form->{closedto}, \%myconfig));
292 $lxdebug->leave_sub();
296 $lxdebug->enter_sub();
298 $title = $form->{title};
299 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
301 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
303 # $locale->text('Add Accounts Receivables Transaction')
304 # $locale->text('Edit Accounts Receivables Transaction')
305 $form->{javascript} = qq|<script type="text/javascript">
307 function setTaxkey(accno, row) {
308 var taxkey = accno.options[accno.selectedIndex].value;
309 var reg = /--([0-9])*/;
310 var found = reg.exec(taxkey);
311 var index = found[1];
312 index = parseInt(index);
313 var tax = 'taxchart_' + row;
314 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
315 var reg2 = new RegExp("^"+ index, "");
316 if (reg2.exec(document.getElementById(tax).options[i].value)) {
317 document.getElementById(tax).options[i].selected = true;
325 $readonly = ($form->{id}) ? "readonly" : "";
328 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
329 $readonly = ($form->{radier}) ? "" : $readonly;
331 # set option selected
332 foreach $item (qw(customer currency department employee)) {
333 $form->{"select$item"} =~ s/ selected//;
334 $form->{"select$item"} =~
335 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
337 $selectAR_amount_unquoted = $form->{selectAR_amount};
338 $taxchart = $form->{taxchart};
339 map { $form->{$_} =~ s/\"/"/g }
340 qw(AR_amount selectAR_amount AR taxchart);
343 $form->{exchangerate} =
344 $form->format_amount(\%myconfig, $form->{exchangerate});
346 $form->{creditlimit} =
347 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
348 $form->{creditremaining} =
349 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
352 <input type=hidden name=forex value=$form->{forex}>
354 if ($form->{currency} ne $form->{defaultcurrency}) {
355 if ($form->{forex}) {
357 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
358 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
362 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
363 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
372 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
373 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
377 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
381 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
385 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
386 <td colspan=3><select name=department>$form->{selectdepartment}</select>
387 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
390 | if $form->{selectdepartment};
392 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
395 ($form->{selectcustomer})
396 ? qq|<select name=customer>$form->{selectcustomer}</select>|
397 : qq|<input name=customer value="$form->{customer}" size=35>|;
400 <input type=hidden name=employee value="$form->{employee}">
403 if ($form->{selectemployee}) {
406 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
407 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
408 <input type=hidden name=selectemployee value="$form->{selectemployee}">
413 $form->{fokus} = "arledger.customer";
415 # use JavaScript Calendar or not
416 $form->{jsscript} = $jscalendar;
418 if ($form->{jsscript}) {
420 # with JavaScript Calendar
422 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
423 <td><input type=button name=transdate id="trigger1" value=|
424 . $locale->text('button') . qq|></td>
427 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
428 <td><input type=button name=duedate id="trigger2" value=|
429 . $locale->text('button') . qq|></td></td>
434 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
435 "duedate", "BL", "trigger2");
438 # without JavaScript Calendar
440 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>|;
442 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
448 <body onLoad="fokus()">
450 <form method=post name="arledger" action=$form->{script}>
452 <input type=hidden name=id value=$form->{id}>
453 <input type=hidden name=sort value=$form->{sort}>
454 <input type=hidden name=closedto value=$form->{closedto}>
455 <input type=hidden name=locked value=$form->{locked}>
456 <input type=hidden name=title value="$title">
460 <th class=listtop>$form->{title}</th>
470 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
471 <td colspan=3>$customer</td>
472 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
473 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
474 <input type=hidden name=customer_id value="$form->{customer_id}">
475 <input type=hidden name=terms value=$form->{terms}>
482 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
483 <td>$form->{creditlimit}</td>
484 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
485 <td class="plus$n">$form->{creditremaining}</td>
486 <input type=hidden name=creditlimit value=$form->{creditlimit}>
487 <input type=hidden name=creditremaining value=$form->{creditremaining}>
493 <th align=right>| . $locale->text('Currency') . qq|</th>
494 <td><select name=currency>$form->{selectcurrency}</select></td>
495 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
496 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
497 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
498 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
509 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
510 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
513 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
514 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
517 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
521 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
532 <input type=hidden name=selectAR_amount value="$form->{selectAR_amount}">
533 <input type=hidden name=AR_amount value="$form->{AR_amount}">
534 <input type=hidden name=taxchart value="$form->{taxchart}">
535 <input type=hidden name=rowcount value=$form->{rowcount}>
539 <tr class=listheading>
540 <th class=listheading style="width:15%">|
541 . $locale->text('Account') . qq|</th>
542 <th class=listheading style="width:10%">|
543 . $locale->text('Amount') . qq|</th>
544 <th class=listheading style="width:10%">|
545 . $locale->text('Tax') . qq|</th>
546 <th class=listheading style="width:5%">|
547 . $locale->text('Korrektur') . qq|</th>
548 <th class=listheading style="width:10%">|
549 . $locale->text('Taxkey') . qq|</th>
550 <th class=listheading style="width:10%">|
551 . $locale->text('Project') . qq|</th>
555 $amount = $locale->text('Amount');
556 $project = $locale->text('Project');
558 for $i (1 .. $form->{rowcount}) {
561 $form->{"amount_$i"} =
562 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
563 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
564 $selectAR_amount = $selectAR_amount_unquoted;
566 s/option value=\"$form->{"AR_amount_$i"}\"/option value=\"$form->{"AR_amount_$i"}\" selected/;
568 $tax_selected = $form->{"taxchart_$i"};
569 $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
571 qq|<td><select id="taxchart_$i" name="taxchart_$i" style="width:200px">$tax</select></td>|;
575 <td width=50%><select name="AR_amount_$i" onChange="setTaxkey(this, $i)" style="width:100%">$selectAR_amount</select></td>
576 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
577 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
578 <td><input type="checkbox" name="korrektur_$i" value="1"></td>
580 <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
581 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
582 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
589 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
598 <td><select name=ARselected>$form->{selectAR}</select></td>
599 <input type=hidden name=AR value="$form->{AR}">
600 <th align=left>$form->{invtotal}</th>
602 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
603 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
605 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
618 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
619 <td align=left>$notes</td>
627 <tr class=listheading>
628 <th colspan=6 class=listheading>|
629 . $locale->text('Incoming Payments') . qq|</th>
633 if ($form->{currency} eq $form->{defaultcurrency}) {
634 @column_index = qw(datepaid source memo paid AR_paid);
636 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
639 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
640 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
641 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
642 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
643 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
644 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
649 map { print "$column_data{$_}\n" } @column_index;
654 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
655 for $i (1 .. $form->{paidaccounts}) {
660 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
661 $form->{"selectAR_paid_$i"} =~
662 s/option value=\"$form->{"AR_paid_$i"}\">/option value=\"$form->{"AR_paid_$i"}\" selected>/;
666 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
667 $form->{"exchangerate_$i"} =
668 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
670 $exchangerate = qq| |;
671 if ($form->{currency} ne $form->{defaultcurrency}) {
672 if ($form->{"forex_$i"}) {
674 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
677 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
682 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
686 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
687 $column_data{AR_paid} =
688 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
689 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
690 $column_data{datepaid} =
691 qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|;
692 $column_data{source} =
693 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
695 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
697 map { print qq|$column_data{$_}\n| } @column_index;
703 map { $form->{$_} =~ s/\"/"/g } qw(selectAR_paid);
705 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
706 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
712 <td><hr size=3 noshade></td>
717 $lxdebug->leave_sub();
721 $lxdebug->enter_sub();
725 <input name=callback type=hidden value="$form->{callback}">
727 <input type=hidden name=path value=$form->{path}>
728 <input type=hidden name=login value=$form->{login}>
729 <input type=hidden name=password value=$form->{password}>
734 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
735 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
737 if ($form->{id} && $form->{radier}) {
739 print qq|<input class=submit type=submit name=action value="|
740 . $locale->text('Update') . qq|">
743 if (!$form->{revtrans}) {
744 if (!$form->{locked}) {
746 <input class=submit type=submit name=action value="|
747 . $locale->text('Post') . qq|">
748 <input class=submit type=submit name=action value="|
749 . $locale->text('Delete') . qq|">
754 if ($transdate > $closedto) {
756 <input class=submit type=submit name=action value="|
757 . $locale->text('Post as new') . qq|">
762 if ($transdate > $closedto) {
763 print qq|<input class=submit type=submit name=action value="|
764 . $locale->text('Update') . qq|">
765 <input class=submit type=submit name=action value="|
766 . $locale->text('Post') . qq|">|;
770 if ($form->{menubar}) {
771 require "$form->{path}/menu.pl";
782 $lxdebug->leave_sub();
786 $lxdebug->enter_sub();
794 $form->{invtotal} = 0;
796 # $form->{selectAR_amount} = $form->{AR_amount};
797 # $form->{selectAR_amount} =~
798 # s/value=\"$form->{AR_amountselected}\"/value=\"$form->{AR_amountselected}\" selected/;
800 $form->{selectAR} = $form->{AR};
803 s/value=\"$form->{ARselected}\"/value=\"$form->{ARselected}\" selected/;
805 ($AR_amountaccno, $AR_amounttaxkey) =
806 split(/--/, $form->{AR_amountselected});
807 $form->{selecttaxchart} = $form->{taxchart};
808 $form->{selecttaxchart} =~
809 s/value=\"$AR_amounttaxkey--([^\"]*)\"/value=\"$AR_amounttaxkey--$1\" selected/;
813 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
814 qw(exchangerate creditlimit creditremaining);
816 @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
820 for $i (1 .. $form->{rowcount}) {
821 $form->{"amount_$i"} =
822 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
823 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
824 if ($form->{"amount_$i"}) {
827 if (!$form->{"korrektur_$i"}) {
828 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
830 if ($form->{taxincluded}) {
831 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
833 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
836 $form->{"tax_$i"} = 0;
839 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
841 $totaltax += $form->{"tax_$i"};
842 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
847 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
848 $form->{rowcount} = $count + 1;
849 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
851 $form->{exchangerate} = $exchangerate
855 $form->check_exchangerate(
856 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
859 $form->{invdate} = $form->{transdate};
860 $save_AR = $form->{AR};
861 &check_name(customer);
862 $form->{AR} = $save_AR;
867 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
869 for $i (1 .. $form->{paidaccounts}) {
870 if ($form->{"paid_$i"}) {
873 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
874 } qw(paid exchangerate);
876 $totalpaid += $form->{"paid_$i"};
878 $form->{"exchangerate_$i"} = $exchangerate
880 $form->{"forex_$i"} = (
882 $form->check_exchangerate(
883 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
888 $form->{creditremaining} -=
889 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
890 $form->{oldinvtotal});
891 $form->{oldinvtotal} = $form->{invtotal};
892 $form->{oldtotalpaid} = $totalpaid;
896 $lxdebug->leave_sub();
900 $lxdebug->enter_sub();
902 # check if there is an invoice number, invoice and due date
903 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
904 $form->isblank("duedate", $locale->text('Due Date missing!'));
905 $form->isblank("customer", $locale->text('Customer missing!'));
907 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
908 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
910 $form->error($locale->text('Cannot post transaction for a closed period!'))
911 if ($transdate <= $closedto);
913 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
914 if ($form->{currency} ne $form->{defaultcurrency});
918 for $i (1 .. $form->{paidaccounts}) {
919 if ($form->{"paid_$i"}) {
920 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
922 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
924 $form->error($locale->text('Cannot post payment for a closed period!'))
925 if ($datepaid <= $closedto);
927 if ($form->{currency} ne $form->{defaultcurrency}) {
928 $form->{"exchangerate_$i"} = $form->{exchangerate}
929 if ($transdate == $datepaid);
930 $form->isblank("exchangerate_$i",
931 $locale->text('Exchangerate for payment missing!'));
936 # if oldcustomer ne customer redo form
937 ($customer) = split /--/, $form->{customer};
938 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
943 ($creditaccno, $credittaxkey) = split /--/, $form->{AR_amountselected};
944 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
945 ($receivablesaccno, $payablestaxkey) = split /--/, $form->{ARselected};
946 $form->{AR}{amount_1} = $creditaccno;
947 $form->{AR}{receivables} = $receivablesaccno;
948 $form->{taxkey} = $taxkey;
950 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber")
951 unless $form->{invnumber};
953 $form->{id} = 0 if $form->{postasnew};
955 $form->redirect($locale->text('Transaction posted!'))
956 if (AR->post_transaction(\%myconfig, \%$form));
957 $form->error($locale->text('Cannot post transaction!'));
959 $lxdebug->leave_sub();
963 $lxdebug->enter_sub();
965 $form->{postasnew} = 1;
968 $lxdebug->leave_sub();
972 $lxdebug->enter_sub();
974 $form->{title} = $locale->text('Confirm!');
978 delete $form->{header};
983 <form method=post action=$form->{script}>
986 foreach $key (keys %$form) {
987 $form->{$key} =~ s/\"/"/g;
988 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
992 <h2 class=confirm>$form->{title}</h2>
995 . $locale->text('Are you sure you want to delete Transaction')
996 . qq| $form->{invnumber}</h4>
998 <input name=action class=submit type=submit value="|
999 . $locale->text('Yes') . qq|">
1006 $lxdebug->leave_sub();
1010 $lxdebug->enter_sub();
1012 $form->redirect($locale->text('Transaction deleted!'))
1013 if (AR->delete_transaction(\%myconfig, \%$form, $spool));
1014 $form->error($locale->text('Cannot delete transaction!'));
1016 $lxdebug->leave_sub();
1020 $lxdebug->enter_sub();
1022 # setup customer selection
1023 $form->all_vc(\%myconfig, "customer", "AR");
1025 if (@{ $form->{all_customer} }) {
1026 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1027 @{ $form->{all_customer} };
1028 $customer = qq|<select name=customer><option>\n$customer</select>|;
1030 $customer = qq|<input name=customer size=35>|;
1034 if (@{ $form->{all_departments} }) {
1035 $form->{selectdepartment} = "<option>\n";
1038 $form->{selectdepartment} .=
1039 "<option>$_->{description}--$_->{id}\n"
1040 } (@{ $form->{all_departments} });
1045 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1046 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1048 | if $form->{selectdepartment};
1050 $form->{title} = $locale->text('AR Transactions');
1052 # use JavaScript Calendar or not
1053 $form->{jsscript} = $jscalendar;
1055 if ($form->{jsscript}) {
1057 # with JavaScript Calendar
1059 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1060 <input type=button name=transdatefrom id="trigger1" value=|
1061 . $locale->text('button') . qq|></td>
1064 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1065 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1066 . $locale->text('button') . qq|></td>
1071 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1072 "transdateto", "BL", "trigger2");
1075 # without JavaScript Calendar
1077 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1079 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1082 $form->{fokus} = "search.customer";
1086 <body onLoad="fokus()">
1088 <form method=post name="search" action=$form->{script}>
1091 <tr><th class=listtop>$form->{title}</th></tr>
1092 <tr height="5"></tr>
1097 <th align=right>| . $locale->text('Customer') . qq|</th>
1098 <td colspan=3>$customer</td>
1102 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1103 <td colspan=3><input name=invnumber size=20></td>
1106 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1107 <td colspan=3><input name=ordnumber size=20></td>
1110 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1111 <td colspan=3><input name=notes size=40></td>
1114 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1116 <th align=right>| . $locale->text('Bis') . qq|</th>
1119 <input type=hidden name=sort value=transdate>
1127 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1131 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1132 <td nowrap>| . $locale->text('Open') . qq|</td>
1133 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1134 <td nowrap>| . $locale->text('Closed') . qq|</td>
1137 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1138 <td nowrap>| . $locale->text('ID') . qq|</td>
1139 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1140 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1141 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1142 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1143 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1144 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1147 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1148 <td nowrap>| . $locale->text('Customer') . qq|</td>
1149 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1150 <td nowrap>| . $locale->text('Amount') . qq|</td>
1151 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1152 <td nowrap>| . $locale->text('Tax') . qq|</td>
1153 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1154 <td nowrap>| . $locale->text('Total') . qq|</td>
1157 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1158 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1159 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1160 <td nowrap>| . $locale->text('Paid') . qq|</td>
1161 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1162 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1163 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1164 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1167 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1168 <td nowrap>| . $locale->text('Notes') . qq|</td>
1169 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1170 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1171 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1172 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1173 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1174 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1177 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1178 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1187 <td><hr size=3 noshade></td>
1191 <input type=hidden name=nextsub value=$form->{nextsub}>
1193 <input type=hidden name=path value=$form->{path}>
1194 <input type=hidden name=login value=$form->{login}>
1195 <input type=hidden name=password value=$form->{password}>
1198 <input class=submit type=submit name=action value="|
1199 . $locale->text('Continue') . qq|">
1210 $lxdebug->leave_sub();
1213 sub ar_transactions {
1214 $lxdebug->enter_sub();
1216 $form->{customer} = $form->unescape($form->{customer});
1217 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1219 AR->ar_transactions(\%myconfig, \%$form);
1222 "$form->{script}?action=ar_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1225 if ($form->{customer}) {
1226 $callback .= "&customer=" . $form->escape($form->{customer}, 1);
1227 $href .= "&customer=" . $form->escape($form->{customer});
1228 $option = $locale->text('Customer') . " : $form->{customer}";
1230 if ($form->{department}) {
1231 $callback .= "&department=" . $form->escape($form->{department}, 1);
1232 $href .= "&department=" . $form->escape($form->{department});
1233 ($department) = split /--/, $form->{department};
1234 $option .= "\n<br>" if ($option);
1235 $option .= $locale->text('Department') . " : $department";
1237 if ($form->{invnumber}) {
1238 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1239 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1240 $option .= "\n<br>" if ($option);
1241 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1243 if ($form->{ordnumber}) {
1244 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1245 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1246 $option .= "\n<br>" if ($option);
1247 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1249 if ($form->{notes}) {
1250 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1251 $href .= "¬es=" . $form->escape($form->{notes});
1252 $option .= "\n<br>" if $option;
1253 $option .= $locale->text('Notes') . " : $form->{notes}";
1256 if ($form->{transdatefrom}) {
1257 $callback .= "&transdatefrom=$form->{transdatefrom}";
1258 $href .= "&transdatefrom=$form->{transdatefrom}";
1259 $option .= "\n<br>" if ($option);
1261 $locale->text('From') . " "
1262 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1264 if ($form->{transdateto}) {
1265 $callback .= "&transdateto=$form->{transdateto}";
1266 $href .= "&transdateto=$form->{transdateto}";
1267 $option .= "\n<br>" if ($option);
1269 $locale->text('Bis') . " "
1270 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1272 if ($form->{open}) {
1273 $callback .= "&open=$form->{open}";
1274 $href .= "&open=$form->{open}";
1275 $option .= "\n<br>" if ($option);
1276 $option .= $locale->text('Open');
1278 if ($form->{closed}) {
1279 $callback .= "&closed=$form->{closed}";
1280 $href .= "&closed=$form->{closed}";
1281 $option .= "\n<br>" if ($option);
1282 $option .= $locale->text('Closed');
1285 @columns = $form->sort_columns(
1286 qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint shipvia)
1289 foreach $item (@columns) {
1290 if ($form->{"l_$item"} eq "Y") {
1291 push @column_index, $item;
1293 # add column to href and callback
1294 $callback .= "&l_$item=Y";
1295 $href .= "&l_$item=Y";
1299 if ($form->{l_subtotal} eq 'Y') {
1300 $callback .= "&l_subtotal=Y";
1301 $href .= "&l_subtotal=Y";
1304 $column_header{id} =
1305 "<th><a class=listheading href=$href&sort=id>"
1306 . $locale->text('ID')
1308 $column_header{transdate} =
1309 "<th><a class=listheading href=$href&sort=transdate>"
1310 . $locale->text('Date')
1312 $column_header{duedate} =
1313 "<th><a class=listheading href=$href&sort=duedate>"
1314 . $locale->text('Due Date')
1316 $column_header{invnumber} =
1317 "<th><a class=listheading href=$href&sort=invnumber>"
1318 . $locale->text('Invoice')
1320 $column_header{ordnumber} =
1321 "<th><a class=listheading href=$href&sort=ordnumber>"
1322 . $locale->text('Order')
1324 $column_header{name} =
1325 "<th><a class=listheading href=$href&sort=name>"
1326 . $locale->text('Customer')
1328 $column_header{netamount} =
1329 "<th class=listheading>" . $locale->text('Amount') . "</th>";
1330 $column_header{tax} =
1331 "<th class=listheading>" . $locale->text('Tax') . "</th>";
1332 $column_header{amount} =
1333 "<th class=listheading>" . $locale->text('Total') . "</th>";
1334 $column_header{paid} =
1335 "<th class=listheading>" . $locale->text('Paid') . "</th>";
1336 $column_header{datepaid} =
1337 "<th><a class=listheading href=$href&sort=datepaid>"
1338 . $locale->text('Date Paid')
1340 $column_header{due} =
1341 "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
1342 $column_header{notes} =
1343 "<th class=listheading>" . $locale->text('Notes') . "</th>";
1344 $column_header{employee} =
1345 "<th><a class=listheading href=$href&sort=employee>"
1346 . $locale->text('Salesperson') . "</th>";
1348 $column_header{shippingpoint} =
1349 "<th><a class=listheading href=$href&sort=shippingpoint>"
1350 . $locale->text('Shipping Point')
1352 $column_header{shipvia} =
1353 "<th><a class=listheading href=$href&sort=shipvia>"
1354 . $locale->text('Ship via')
1357 $form->{title} = $locale->text('AR Transactions');
1366 <th class=listtop>$form->{title}</th>
1368 <tr height="5"></tr>
1375 <tr class=listheading>
1378 map { print "\n$column_header{$_}" } @column_index;
1384 # add sort and escape callback, this one we use for the add sub
1385 $form->{callback} = $callback .= "&sort=$form->{sort}";
1387 # escape callback for href
1388 $callback = $form->escape($callback);
1390 if (@{ $form->{AR} }) {
1391 $sameitem = $form->{AR}->[0]->{ $form->{sort} };
1394 # sums and tax on reports by Antonio Gallardo
1396 foreach $ar (@{ $form->{AR} }) {
1398 if ($form->{l_subtotal} eq 'Y') {
1399 if ($sameitem ne $ar->{ $form->{sort} }) {
1404 $column_data{netamount} =
1406 . $form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")
1408 $column_data{tax} = "<td align=right>"
1409 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount},
1412 $column_data{amount} =
1414 . $form->format_amount(\%myconfig, $ar->{amount}, 2, " ") . "</td>";
1415 $column_data{paid} =
1417 . $form->format_amount(\%myconfig, $ar->{paid}, 2, " ") . "</td>";
1418 $column_data{due} = "<td align=right>"
1419 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid},
1423 $subtotalnetamount += $ar->{netamount};
1424 $subtotalamount += $ar->{amount};
1425 $subtotalpaid += $ar->{paid};
1426 $subtotaldue += $ar->{amount} - $ar->{paid};
1428 $totalnetamount += $ar->{netamount};
1429 $totalamount += $ar->{amount};
1430 $totalpaid += $ar->{paid};
1431 $totaldue += ($ar->{amount} - $ar->{paid});
1433 $column_data{transdate} = "<td>$ar->{transdate} </td>";
1434 $column_data{id} = "<td>$ar->{id}</td>";
1435 $column_data{datepaid} = "<td>$ar->{datepaid} </td>";
1436 $column_data{duedate} = "<td>$ar->{duedate} </td>";
1438 $module = ($ar->{invoice}) ? "is.pl" : $form->{script};
1440 $column_data{invnumber} =
1441 "<td><a href=$module?action=edit&id=$ar->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}</a></td>";
1442 $column_data{ordnumber} = "<td>$ar->{ordnumber} </td>";
1443 $column_data{name} = "<td>$ar->{name}</td>";
1444 $ar->{notes} =~ s/\r\n/<br>/g;
1445 $column_data{notes} = "<td>$ar->{notes} </td>";
1446 $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>";
1447 $column_data{shipvia} = "<td>$ar->{shipvia} </td>";
1448 $column_data{employee} = "<td>$ar->{employee} </td>";
1453 <tr class=listrow$i>
1456 map { print "\n$column_data{$_}" } @column_index;
1464 if ($form->{l_subtotal} eq 'Y') {
1470 <tr class=listtotal>
1473 map { $column_data{$_} = "<td> </td>" } @column_index;
1475 $column_data{netamount} =
1476 "<th class=listtotal align=right>"
1477 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1478 $column_data{tax} = "<th class=listtotal align=right>"
1479 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1482 $column_data{amount} =
1483 "<th class=listtotal align=right>"
1484 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1485 $column_data{paid} =
1486 "<th class=listtotal align=right>"
1487 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1489 "<th class=listtotal align=right>"
1490 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1492 map { print "\n$column_data{$_}" } @column_index;
1500 <td><hr size=3 noshade></td>
1505 <form method=post action=$form->{script}>
1507 <input name=callback type=hidden value="$form->{callback}">
1509 <input type=hidden name=path value=$form->{path}>
1510 <input type=hidden name=login value=$form->{login}>
1511 <input type=hidden name=password value=$form->{password}>
1513 <input class=submit type=submit name=action value="|
1514 . $locale->text('AR Transaction') . qq|">
1515 <input class=submit type=submit name=action value="|
1516 . $locale->text('Sales Invoice') . qq|">|;
1518 if ($form->{menubar}) {
1519 require "$form->{path}/menu.pl";
1530 $lxdebug->leave_sub();
1534 $lxdebug->enter_sub();
1536 map { $column_data{$_} = "<td> </td>" } @column_index;
1538 $column_data{tax} = "<th class=listsubtotal align=right>"
1539 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1542 $column_data{amount} =
1543 "<th class=listsubtotal align=right>"
1544 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1545 $column_data{paid} =
1546 "<th class=listsubtotal align=right>"
1547 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1549 "<th class=listsubtotal align=right>"
1550 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1552 $subtotalnetamount = 0;
1553 $subtotalamount = 0;
1557 $sameitem = $ar->{ $form->{sort} };
1559 print "<tr class=listsubtotal>";
1561 map { print "\n$column_data{$_}" } @column_index;
1567 $lxdebug->leave_sub();