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>|;
572 $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
576 <td width=50%><select name="AR_amount_$i" onChange="setTaxkey(this, $i)" style="width:100%">$selectAR_amount</select></td>
577 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
578 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
579 <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
581 <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
582 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
583 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
590 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
599 <td><select name=ARselected>$form->{selectAR}</select></td>
600 <input type=hidden name=AR value="$form->{AR}">
601 <th align=left>$form->{invtotal}</th>
603 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
604 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
606 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
619 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
620 <td align=left>$notes</td>
628 <tr class=listheading>
629 <th colspan=6 class=listheading>|
630 . $locale->text('Incoming Payments') . qq|</th>
634 if ($form->{currency} eq $form->{defaultcurrency}) {
635 @column_index = qw(datepaid source memo paid AR_paid);
637 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
640 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
641 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
642 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
643 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
644 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
645 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
650 map { print "$column_data{$_}\n" } @column_index;
655 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
656 for $i (1 .. $form->{paidaccounts}) {
661 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
662 $form->{"selectAR_paid_$i"} =~
663 s/option value=\"$form->{"AR_paid_$i"}\">/option value=\"$form->{"AR_paid_$i"}\" selected>/;
667 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
668 $form->{"exchangerate_$i"} =
669 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
671 $exchangerate = qq| |;
672 if ($form->{currency} ne $form->{defaultcurrency}) {
673 if ($form->{"forex_$i"}) {
675 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
678 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
683 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
687 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
688 $column_data{AR_paid} =
689 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
690 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
691 $column_data{datepaid} =
692 qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|;
693 $column_data{source} =
694 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
696 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
698 map { print qq|$column_data{$_}\n| } @column_index;
704 map { $form->{$_} =~ s/\"/"/g } qw(selectAR_paid);
706 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
707 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
713 <td><hr size=3 noshade></td>
718 $lxdebug->leave_sub();
722 $lxdebug->enter_sub();
726 <input name=callback type=hidden value="$form->{callback}">
728 <input type=hidden name=path value=$form->{path}>
729 <input type=hidden name=login value=$form->{login}>
730 <input type=hidden name=password value=$form->{password}>
735 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
736 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
738 if ($form->{id} && $form->{radier}) {
740 print qq|<input class=submit type=submit name=action value="|
741 . $locale->text('Update') . qq|">
744 if (!$form->{revtrans}) {
745 if (!$form->{locked}) {
747 <input class=submit type=submit name=action value="|
748 . $locale->text('Post') . qq|">
749 <input class=submit type=submit name=action value="|
750 . $locale->text('Delete') . qq|">
755 if ($transdate > $closedto) {
757 <input class=submit type=submit name=action value="|
758 . $locale->text('Post as new') . qq|">
763 if ($transdate > $closedto) {
764 print qq|<input class=submit type=submit name=action value="|
765 . $locale->text('Update') . qq|">
766 <input class=submit type=submit name=action value="|
767 . $locale->text('Post') . qq|">|;
771 if ($form->{menubar}) {
772 require "$form->{path}/menu.pl";
783 $lxdebug->leave_sub();
787 $lxdebug->enter_sub();
795 $form->{invtotal} = 0;
797 # $form->{selectAR_amount} = $form->{AR_amount};
798 # $form->{selectAR_amount} =~
799 # s/value=\"$form->{AR_amountselected}\"/value=\"$form->{AR_amountselected}\" selected/;
801 $form->{selectAR} = $form->{AR};
804 s/value=\"$form->{ARselected}\"/value=\"$form->{ARselected}\" selected/;
806 ($AR_amountaccno, $AR_amounttaxkey) =
807 split(/--/, $form->{AR_amountselected});
808 $form->{selecttaxchart} = $form->{taxchart};
809 $form->{selecttaxchart} =~
810 s/value=\"$AR_amounttaxkey--([^\"]*)\"/value=\"$AR_amounttaxkey--$1\" selected/;
814 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
815 qw(exchangerate creditlimit creditremaining);
817 @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
821 for $i (1 .. $form->{rowcount}) {
822 $form->{"amount_$i"} =
823 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
824 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
825 if ($form->{"amount_$i"}) {
828 if (!$form->{"korrektur_$i"}) {
829 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
831 if ($form->{taxincluded}) {
832 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
834 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
837 $form->{"tax_$i"} = 0;
840 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
842 $totaltax += $form->{"tax_$i"};
843 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
848 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
849 $form->{rowcount} = $count + 1;
850 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
852 $form->{exchangerate} = $exchangerate
856 $form->check_exchangerate(
857 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
860 $form->{invdate} = $form->{transdate};
861 $save_AR = $form->{AR};
862 &check_name(customer);
863 $form->{AR} = $save_AR;
868 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
870 for $i (1 .. $form->{paidaccounts}) {
871 if ($form->{"paid_$i"}) {
874 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
875 } qw(paid exchangerate);
877 $totalpaid += $form->{"paid_$i"};
879 $form->{"exchangerate_$i"} = $exchangerate
881 $form->{"forex_$i"} = (
883 $form->check_exchangerate(
884 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
889 $form->{creditremaining} -=
890 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
891 $form->{oldinvtotal});
892 $form->{oldinvtotal} = $form->{invtotal};
893 $form->{oldtotalpaid} = $totalpaid;
897 $lxdebug->leave_sub();
901 $lxdebug->enter_sub();
903 # check if there is an invoice number, invoice and due date
904 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
905 $form->isblank("duedate", $locale->text('Due Date missing!'));
906 $form->isblank("customer", $locale->text('Customer missing!'));
908 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
909 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
911 $form->error($locale->text('Cannot post transaction for a closed period!'))
912 if ($transdate <= $closedto);
914 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
915 if ($form->{currency} ne $form->{defaultcurrency});
919 for $i (1 .. $form->{paidaccounts}) {
920 if ($form->{"paid_$i"}) {
921 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
923 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
925 $form->error($locale->text('Cannot post payment for a closed period!'))
926 if ($datepaid <= $closedto);
928 if ($form->{currency} ne $form->{defaultcurrency}) {
929 $form->{"exchangerate_$i"} = $form->{exchangerate}
930 if ($transdate == $datepaid);
931 $form->isblank("exchangerate_$i",
932 $locale->text('Exchangerate for payment missing!'));
937 # if oldcustomer ne customer redo form
938 ($customer) = split /--/, $form->{customer};
939 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
944 ($creditaccno, $credittaxkey) = split /--/, $form->{AR_amountselected};
945 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
946 ($receivablesaccno, $payablestaxkey) = split /--/, $form->{ARselected};
947 $form->{AR}{amount_1} = $creditaccno;
948 $form->{AR}{receivables} = $receivablesaccno;
949 $form->{taxkey} = $taxkey;
951 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber")
952 unless $form->{invnumber};
954 $form->{id} = 0 if $form->{postasnew};
956 $form->redirect($locale->text('Transaction posted!'))
957 if (AR->post_transaction(\%myconfig, \%$form));
958 $form->error($locale->text('Cannot post transaction!'));
960 $lxdebug->leave_sub();
964 $lxdebug->enter_sub();
966 $form->{postasnew} = 1;
969 $lxdebug->leave_sub();
973 $lxdebug->enter_sub();
975 $form->{title} = $locale->text('Confirm!');
979 delete $form->{header};
984 <form method=post action=$form->{script}>
987 foreach $key (keys %$form) {
988 $form->{$key} =~ s/\"/"/g;
989 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
993 <h2 class=confirm>$form->{title}</h2>
996 . $locale->text('Are you sure you want to delete Transaction')
997 . qq| $form->{invnumber}</h4>
999 <input name=action class=submit type=submit value="|
1000 . $locale->text('Yes') . qq|">
1007 $lxdebug->leave_sub();
1011 $lxdebug->enter_sub();
1013 $form->redirect($locale->text('Transaction deleted!'))
1014 if (AR->delete_transaction(\%myconfig, \%$form, $spool));
1015 $form->error($locale->text('Cannot delete transaction!'));
1017 $lxdebug->leave_sub();
1021 $lxdebug->enter_sub();
1023 # setup customer selection
1024 $form->all_vc(\%myconfig, "customer", "AR");
1026 if (@{ $form->{all_customer} }) {
1027 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1028 @{ $form->{all_customer} };
1029 $customer = qq|<select name=customer><option>\n$customer</select>|;
1031 $customer = qq|<input name=customer size=35>|;
1035 if (@{ $form->{all_departments} }) {
1036 $form->{selectdepartment} = "<option>\n";
1039 $form->{selectdepartment} .=
1040 "<option>$_->{description}--$_->{id}\n"
1041 } (@{ $form->{all_departments} });
1046 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1047 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1049 | if $form->{selectdepartment};
1051 $form->{title} = $locale->text('AR Transactions');
1053 # use JavaScript Calendar or not
1054 $form->{jsscript} = $jscalendar;
1056 if ($form->{jsscript}) {
1058 # with JavaScript Calendar
1060 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1061 <input type=button name=transdatefrom id="trigger1" value=|
1062 . $locale->text('button') . qq|></td>
1065 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1066 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1067 . $locale->text('button') . qq|></td>
1072 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1073 "transdateto", "BL", "trigger2");
1076 # without JavaScript Calendar
1078 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1080 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1083 $form->{fokus} = "search.customer";
1087 <body onLoad="fokus()">
1089 <form method=post name="search" action=$form->{script}>
1092 <tr><th class=listtop>$form->{title}</th></tr>
1093 <tr height="5"></tr>
1098 <th align=right>| . $locale->text('Customer') . qq|</th>
1099 <td colspan=3>$customer</td>
1103 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1104 <td colspan=3><input name=invnumber size=20></td>
1107 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1108 <td colspan=3><input name=ordnumber size=20></td>
1111 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1112 <td colspan=3><input name=notes size=40></td>
1115 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1117 <th align=right>| . $locale->text('Bis') . qq|</th>
1120 <input type=hidden name=sort value=transdate>
1128 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1132 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1133 <td nowrap>| . $locale->text('Open') . qq|</td>
1134 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1135 <td nowrap>| . $locale->text('Closed') . qq|</td>
1138 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1139 <td nowrap>| . $locale->text('ID') . qq|</td>
1140 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1141 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1142 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1143 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1144 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1145 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1148 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1149 <td nowrap>| . $locale->text('Customer') . qq|</td>
1150 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1151 <td nowrap>| . $locale->text('Amount') . qq|</td>
1152 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1153 <td nowrap>| . $locale->text('Tax') . qq|</td>
1154 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1155 <td nowrap>| . $locale->text('Total') . qq|</td>
1158 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1159 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1160 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1161 <td nowrap>| . $locale->text('Paid') . qq|</td>
1162 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1163 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1164 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1165 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1168 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1169 <td nowrap>| . $locale->text('Notes') . qq|</td>
1170 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1171 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1172 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1173 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1174 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1175 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1178 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1179 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1188 <td><hr size=3 noshade></td>
1192 <input type=hidden name=nextsub value=$form->{nextsub}>
1194 <input type=hidden name=path value=$form->{path}>
1195 <input type=hidden name=login value=$form->{login}>
1196 <input type=hidden name=password value=$form->{password}>
1199 <input class=submit type=submit name=action value="|
1200 . $locale->text('Continue') . qq|">
1211 $lxdebug->leave_sub();
1214 sub ar_transactions {
1215 $lxdebug->enter_sub();
1217 $form->{customer} = $form->unescape($form->{customer});
1218 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1220 AR->ar_transactions(\%myconfig, \%$form);
1223 "$form->{script}?action=ar_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1226 if ($form->{customer}) {
1227 $callback .= "&customer=" . $form->escape($form->{customer}, 1);
1228 $href .= "&customer=" . $form->escape($form->{customer});
1229 $option = $locale->text('Customer') . " : $form->{customer}";
1231 if ($form->{department}) {
1232 $callback .= "&department=" . $form->escape($form->{department}, 1);
1233 $href .= "&department=" . $form->escape($form->{department});
1234 ($department) = split /--/, $form->{department};
1235 $option .= "\n<br>" if ($option);
1236 $option .= $locale->text('Department') . " : $department";
1238 if ($form->{invnumber}) {
1239 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1240 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1241 $option .= "\n<br>" if ($option);
1242 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1244 if ($form->{ordnumber}) {
1245 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1246 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1247 $option .= "\n<br>" if ($option);
1248 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1250 if ($form->{notes}) {
1251 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1252 $href .= "¬es=" . $form->escape($form->{notes});
1253 $option .= "\n<br>" if $option;
1254 $option .= $locale->text('Notes') . " : $form->{notes}";
1257 if ($form->{transdatefrom}) {
1258 $callback .= "&transdatefrom=$form->{transdatefrom}";
1259 $href .= "&transdatefrom=$form->{transdatefrom}";
1260 $option .= "\n<br>" if ($option);
1262 $locale->text('From') . " "
1263 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1265 if ($form->{transdateto}) {
1266 $callback .= "&transdateto=$form->{transdateto}";
1267 $href .= "&transdateto=$form->{transdateto}";
1268 $option .= "\n<br>" if ($option);
1270 $locale->text('Bis') . " "
1271 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1273 if ($form->{open}) {
1274 $callback .= "&open=$form->{open}";
1275 $href .= "&open=$form->{open}";
1276 $option .= "\n<br>" if ($option);
1277 $option .= $locale->text('Open');
1279 if ($form->{closed}) {
1280 $callback .= "&closed=$form->{closed}";
1281 $href .= "&closed=$form->{closed}";
1282 $option .= "\n<br>" if ($option);
1283 $option .= $locale->text('Closed');
1286 @columns = $form->sort_columns(
1287 qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint shipvia)
1290 foreach $item (@columns) {
1291 if ($form->{"l_$item"} eq "Y") {
1292 push @column_index, $item;
1294 # add column to href and callback
1295 $callback .= "&l_$item=Y";
1296 $href .= "&l_$item=Y";
1300 if ($form->{l_subtotal} eq 'Y') {
1301 $callback .= "&l_subtotal=Y";
1302 $href .= "&l_subtotal=Y";
1305 $column_header{id} =
1306 "<th><a class=listheading href=$href&sort=id>"
1307 . $locale->text('ID')
1309 $column_header{transdate} =
1310 "<th><a class=listheading href=$href&sort=transdate>"
1311 . $locale->text('Date')
1313 $column_header{duedate} =
1314 "<th><a class=listheading href=$href&sort=duedate>"
1315 . $locale->text('Due Date')
1317 $column_header{invnumber} =
1318 "<th><a class=listheading href=$href&sort=invnumber>"
1319 . $locale->text('Invoice')
1321 $column_header{ordnumber} =
1322 "<th><a class=listheading href=$href&sort=ordnumber>"
1323 . $locale->text('Order')
1325 $column_header{name} =
1326 "<th><a class=listheading href=$href&sort=name>"
1327 . $locale->text('Customer')
1329 $column_header{netamount} =
1330 "<th class=listheading>" . $locale->text('Amount') . "</th>";
1331 $column_header{tax} =
1332 "<th class=listheading>" . $locale->text('Tax') . "</th>";
1333 $column_header{amount} =
1334 "<th class=listheading>" . $locale->text('Total') . "</th>";
1335 $column_header{paid} =
1336 "<th class=listheading>" . $locale->text('Paid') . "</th>";
1337 $column_header{datepaid} =
1338 "<th><a class=listheading href=$href&sort=datepaid>"
1339 . $locale->text('Date Paid')
1341 $column_header{due} =
1342 "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
1343 $column_header{notes} =
1344 "<th class=listheading>" . $locale->text('Notes') . "</th>";
1345 $column_header{employee} =
1346 "<th><a class=listheading href=$href&sort=employee>"
1347 . $locale->text('Salesperson') . "</th>";
1349 $column_header{shippingpoint} =
1350 "<th><a class=listheading href=$href&sort=shippingpoint>"
1351 . $locale->text('Shipping Point')
1353 $column_header{shipvia} =
1354 "<th><a class=listheading href=$href&sort=shipvia>"
1355 . $locale->text('Ship via')
1358 $form->{title} = $locale->text('AR Transactions');
1367 <th class=listtop>$form->{title}</th>
1369 <tr height="5"></tr>
1376 <tr class=listheading>
1379 map { print "\n$column_header{$_}" } @column_index;
1385 # add sort and escape callback, this one we use for the add sub
1386 $form->{callback} = $callback .= "&sort=$form->{sort}";
1388 # escape callback for href
1389 $callback = $form->escape($callback);
1391 if (@{ $form->{AR} }) {
1392 $sameitem = $form->{AR}->[0]->{ $form->{sort} };
1395 # sums and tax on reports by Antonio Gallardo
1397 foreach $ar (@{ $form->{AR} }) {
1399 if ($form->{l_subtotal} eq 'Y') {
1400 if ($sameitem ne $ar->{ $form->{sort} }) {
1405 $column_data{netamount} =
1407 . $form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")
1409 $column_data{tax} = "<td align=right>"
1410 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount},
1413 $column_data{amount} =
1415 . $form->format_amount(\%myconfig, $ar->{amount}, 2, " ") . "</td>";
1416 $column_data{paid} =
1418 . $form->format_amount(\%myconfig, $ar->{paid}, 2, " ") . "</td>";
1419 $column_data{due} = "<td align=right>"
1420 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid},
1424 $subtotalnetamount += $ar->{netamount};
1425 $subtotalamount += $ar->{amount};
1426 $subtotalpaid += $ar->{paid};
1427 $subtotaldue += $ar->{amount} - $ar->{paid};
1429 $totalnetamount += $ar->{netamount};
1430 $totalamount += $ar->{amount};
1431 $totalpaid += $ar->{paid};
1432 $totaldue += ($ar->{amount} - $ar->{paid});
1434 $column_data{transdate} = "<td>$ar->{transdate} </td>";
1435 $column_data{id} = "<td>$ar->{id}</td>";
1436 $column_data{datepaid} = "<td>$ar->{datepaid} </td>";
1437 $column_data{duedate} = "<td>$ar->{duedate} </td>";
1439 $module = ($ar->{invoice}) ? "is.pl" : $form->{script};
1441 $column_data{invnumber} =
1442 "<td><a href=$module?action=edit&id=$ar->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}</a></td>";
1443 $column_data{ordnumber} = "<td>$ar->{ordnumber} </td>";
1444 $column_data{name} = "<td>$ar->{name}</td>";
1445 $ar->{notes} =~ s/\r\n/<br>/g;
1446 $column_data{notes} = "<td>$ar->{notes} </td>";
1447 $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>";
1448 $column_data{shipvia} = "<td>$ar->{shipvia} </td>";
1449 $column_data{employee} = "<td>$ar->{employee} </td>";
1454 <tr class=listrow$i>
1457 map { print "\n$column_data{$_}" } @column_index;
1465 if ($form->{l_subtotal} eq 'Y') {
1471 <tr class=listtotal>
1474 map { $column_data{$_} = "<td> </td>" } @column_index;
1476 $column_data{netamount} =
1477 "<th class=listtotal align=right>"
1478 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1479 $column_data{tax} = "<th class=listtotal align=right>"
1480 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1483 $column_data{amount} =
1484 "<th class=listtotal align=right>"
1485 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1486 $column_data{paid} =
1487 "<th class=listtotal align=right>"
1488 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1490 "<th class=listtotal align=right>"
1491 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1493 map { print "\n$column_data{$_}" } @column_index;
1501 <td><hr size=3 noshade></td>
1506 <form method=post action=$form->{script}>
1508 <input name=callback type=hidden value="$form->{callback}">
1510 <input type=hidden name=path value=$form->{path}>
1511 <input type=hidden name=login value=$form->{login}>
1512 <input type=hidden name=password value=$form->{password}>
1514 <input class=submit type=submit name=action value="|
1515 . $locale->text('AR Transaction') . qq|">
1516 <input class=submit type=submit name=action value="|
1517 . $locale->text('Sales Invoice') . qq|">|;
1519 if ($form->{menubar}) {
1520 require "$form->{path}/menu.pl";
1531 $lxdebug->leave_sub();
1535 $lxdebug->enter_sub();
1537 map { $column_data{$_} = "<td> </td>" } @column_index;
1539 $column_data{tax} = "<th class=listsubtotal align=right>"
1540 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1543 $column_data{amount} =
1544 "<th class=listsubtotal align=right>"
1545 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1546 $column_data{paid} =
1547 "<th class=listsubtotal align=right>"
1548 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1550 "<th class=listsubtotal align=right>"
1551 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1553 $subtotalnetamount = 0;
1554 $subtotalamount = 0;
1558 $sameitem = $ar->{ $form->{sort} };
1560 print "<tr class=listsubtotal>";
1562 map { print "\n$column_data{$_}" } @column_index;
1568 $lxdebug->leave_sub();