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 #======================================================================
38 require "$form->{path}/arap.pl";
44 # this is for our long dates
45 # $locale->text('January')
46 # $locale->text('February')
47 # $locale->text('March')
48 # $locale->text('April')
49 # $locale->text('May ')
50 # $locale->text('June')
51 # $locale->text('July')
52 # $locale->text('August')
53 # $locale->text('September')
54 # $locale->text('October')
55 # $locale->text('November')
56 # $locale->text('December')
58 # this is for our short month
59 # $locale->text('Jan')
60 # $locale->text('Feb')
61 # $locale->text('Mar')
62 # $locale->text('Apr')
63 # $locale->text('May')
64 # $locale->text('Jun')
65 # $locale->text('Jul')
66 # $locale->text('Aug')
67 # $locale->text('Sep')
68 # $locale->text('Oct')
69 # $locale->text('Nov')
70 # $locale->text('Dec')
73 $lxdebug->enter_sub();
75 $form->{title} = "Add";
77 "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}"
78 unless $form->{callback};
83 $lxdebug->leave_sub();
87 $lxdebug->enter_sub();
89 $form->{title} = "Edit";
94 $lxdebug->leave_sub();
98 $lxdebug->enter_sub();
103 $lxdebug->leave_sub();
107 $lxdebug->enter_sub();
109 $form->create_links("AR", \%myconfig, "customer");
110 $duedate = $form->{duedate};
112 $taxincluded = $form->{taxincluded};
114 IS->get_customer(\%myconfig, \%$form);
116 $form->{duedate} = $duedate if $duedate;
117 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
120 @curr = split /:/, $form->{currencies};
122 $form->{defaultcurrency} = $curr[0];
124 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
127 if (@{ $form->{all_customer} }) {
128 $form->{customer} = "$form->{customer}--$form->{customer_id}";
129 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
130 (@{ $form->{all_customer} });
134 if (@{ $form->{all_departments} }) {
135 $form->{selectdepartment} = "<option>\n";
136 $form->{department} = "$form->{department}--$form->{department_id}";
139 $form->{selectdepartment} .=
140 "<option>$_->{description}--$_->{id}\n"
141 } (@{ $form->{all_departments} });
144 $form->{employee} = "$form->{employee}--$form->{employee_id}";
147 if (@{ $form->{all_employees} }) {
148 $form->{selectemployee} = "";
149 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
150 (@{ $form->{all_employees} });
153 # build the popup menus
154 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
158 qq|<option value=\"$_->{taxkey}--$_->{rate}\">$_->{taxdescription} |
159 . ($_->{rate} * 100) . qq| %|
161 $form->{taxchart} = $tax;
162 $form->{selecttaxchart} = $tax;
165 $form->{forex} = $form->{exchangerate};
166 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
167 foreach $key (keys %{ $form->{AR_links} }) {
169 foreach $ref (@{ $form->{AR_links}{$key} }) {
170 if ($key eq "AR_paid") {
171 $form->{"select$key"} .=
172 "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
174 $form->{"select$key"} .=
175 "<option value=\"$ref->{accno}--$ref->{taxkey}\">$ref->{accno}--$ref->{description}</option>\n";
179 $form->{$key} = $form->{"select$key"};
181 # if there is a value we have an old entry
183 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
184 if ($key eq "AR_paid") {
186 $form->{"AR_paid_$j"} =
187 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
190 $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
191 $form->{"datepaid_$j"} =
192 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
193 $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
194 $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
196 $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
197 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
198 $form->{"AR_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
199 $form->{paidaccounts}++;
205 if ($key eq "AR_tax") {
206 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
207 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
208 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
210 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
213 if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
215 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
217 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
220 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
222 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
226 $form->{"${akey}_$i"} =
228 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
230 if ($akey eq 'amount') {
232 $totalamount += $form->{"${akey}_$i"};
234 $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} =
235 "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
236 $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
237 $form->{"project_id_$i"} =
238 "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
240 $form->{"${key}_$i"} =
241 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
242 $form->{"${key}_$i"} =
243 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
244 $form->{"select${key}"} =~
245 /(<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)/;
247 $form->{"select${key}"} = $1;
248 if ($akey eq 'amount') {
249 $form->{selecttaxchart} =~
250 /(<option value=\"$form->{acc_trans}{$key}->[$i-1]->{taxkey}--[^<]*)/;
251 $form->{selecttaxchart} = $1;
258 $form->{taxincluded} = $taxincluded if ($form->{id});
259 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
261 if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
263 # add tax to amounts and invtotal
266 ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
267 $tax = $form->round_amount($taxamount, 2);
268 $diff += ($taxamount - $tax);
269 $form->{"amount_$i"} += $tax;
271 $form->{amount_1} += $form->round_amount($diff, 2);
274 # check if calculated is equal to stored
275 if ($form->{taxincluded} && $form->{taxrate} && $withholdingrate) {
276 if ($form->{"taxrate"} > 0) {
279 ($form->{amount_1} - ($form->{amount_1} / ($form->{taxrate} + 1))),
284 ($totalamount + $totaltax + $totalwithholding) * $withholdingrate /
285 (1 - $withholdingrate),
287 ) * $form->{"taxrate"} / $withholdingrate;
290 $taxamount = $totalamount * $form->{"taxrate"};
292 $taxamount = $form->round_amount($taxamount, 2);
293 $form->{tax} = $taxamount;
295 $form->{invtotal} = $totalamount + $totaltax + $totalwithholding;
298 ($form->datetonum($form->{transdate}, \%myconfig) <=
299 $form->datetonum($form->{closedto}, \%myconfig));
301 $lxdebug->leave_sub();
305 $lxdebug->enter_sub();
307 $title = $form->{title};
308 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
310 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
312 # $locale->text('Add Accounts Receivables Transaction')
313 # $locale->text('Edit Accounts Receivables Transaction')
315 $readonly = ($form->{id}) ? "readonly" : "";
318 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
319 $readonly = ($form->{radier}) ? "" : $readonly;
321 # set option selected
322 foreach $item (qw(customer currency department employee)) {
323 $form->{"select$item"} =~ s/ selected//;
324 $form->{"select$item"} =~
325 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
328 map { $form->{$_} =~ s/\"/"/g } qw(AR_amount AR taxchart);
331 $form->{exchangerate} =
332 $form->format_amount(\%myconfig, $form->{exchangerate});
334 $form->{creditlimit} =
335 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
336 $form->{creditremaining} =
337 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
340 <input type=hidden name=forex value=$form->{forex}>
342 if ($form->{currency} ne $form->{defaultcurrency}) {
343 if ($form->{forex}) {
345 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
346 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
350 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
351 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
360 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
361 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
365 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
369 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
373 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
374 <td colspan=3><select name=department>$form->{selectdepartment}</select>
375 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
378 | if $form->{selectdepartment};
380 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
383 ($form->{selectcustomer})
384 ? qq|<select name=customer>$form->{selectcustomer}</select>|
385 : qq|<input name=customer value="$form->{customer}" size=35>|;
388 <input type=hidden name=employee value="$form->{employee}">
391 if ($form->{selectemployee}) {
394 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
395 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
396 <input type=hidden name=selectemployee value="$form->{selectemployee}">
401 $form->{fokus} = "arledger.customer";
403 # use JavaScript Calendar or not
404 $form->{jsscript} = $jscalendar;
406 if ($form->{jsscript}) {
408 # with JavaScript Calendar
410 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
411 <td><input type=button name=transdate id="trigger1" value=|
412 . $locale->text('button')
416 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
417 <td><input type=button name=duedate id="trigger2" value=|
418 . $locale->text('button')
424 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
425 "duedate", "BL", "trigger2");
428 # without JavaScript Calendar
430 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>|;
432 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
438 <body onLoad="fokus()">
440 <form method=post name="arledger" action=$form->{script}>
442 <input type=hidden name=id value=$form->{id}>
443 <input type=hidden name=sort value=$form->{sort}>
444 <input type=hidden name=closedto value=$form->{closedto}>
445 <input type=hidden name=locked value=$form->{locked}>
446 <input type=hidden name=title value="$title">
450 <th class=listtop>$form->{title}</th>
460 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
461 <td colspan=3>$customer</td>
462 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
463 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
464 <input type=hidden name=customer_id value="$form->{customer_id}">
465 <input type=hidden name=terms value=$form->{terms}>
472 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
473 <td>$form->{creditlimit}</td>
474 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
475 <td class="plus$n">$form->{creditremaining}</td>
476 <input type=hidden name=creditlimit value=$form->{creditlimit}>
477 <input type=hidden name=creditremaining value=$form->{creditremaining}>
483 <th align=right>| . $locale->text('Currency') . qq|</th>
484 <td><select name=currency>$form->{selectcurrency}</select></td>
485 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
486 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
487 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
488 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
499 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
500 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
503 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
504 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
507 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
511 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
526 <input type=hidden name=AR_amount value="$form->{AR_amount}">
527 <input type=hidden name=taxchart value="$form->{taxchart}">
528 <input type=hidden name=rowcount value=$form->{rowcount}>
531 $form->{"tax"} = $form->format_amount(\%myconfig, $form->{"tax"}, 2);
533 $amount = $locale->text('Amount');
534 $project = $locale->text('Project');
539 $form->{"amount_$i"} =
540 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
544 <th align=right>$amount</th>
545 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
547 <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
548 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
549 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
550 <td width=50%><select name="AR_amountselected">$form->{"selectAR_amount"}</select></td>
558 ($form->{taxincluded})
559 ? $locale->text('Tax Included')
560 : $locale->text('Tax');
564 <th align=right nowrap>$taxlabel</th>
565 <td><input name="tax" size=10 value=$form->{"tax"}></td>
566 <td align=right></td>
568 <td><select name="taxchartselected">$form->{"selecttaxchart"}</select></td>
572 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
577 <th align=right>| . $locale->text('Total') . qq|</th>
578 <th align=left>$form->{invtotal}</th>
580 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
581 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
583 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
586 <td><select name=ARselected>$form->{selectAR}</select></td>
587 <input type=hidden name=AR value="$form->{AR}">
591 <th align=right>| . $locale->text('Notes') . qq|</th>
592 <td colspan=4>$notes</td>
600 <tr class=listheading>
601 <th colspan=6 class=listheading>|
602 . $locale->text('Incoming Payments')
607 if ($form->{currency} eq $form->{defaultcurrency}) {
608 @column_index = qw(datepaid source memo paid AR_paid);
610 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
613 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
614 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
615 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
616 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
617 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
618 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
623 map { print "$column_data{$_}\n" } @column_index;
628 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
629 for $i (1 .. $form->{paidaccounts}) {
634 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
635 $form->{"selectAR_paid_$i"} =~
636 s/option value=\"$form->{"AR_paid_$i"}\">/option value=\"$form->{"AR_paid_$i"}\" selected>/;
640 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
641 $form->{"exchangerate_$i"} =
642 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
644 $exchangerate = qq| |;
645 if ($form->{currency} ne $form->{defaultcurrency}) {
646 if ($form->{"forex_$i"}) {
648 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
651 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
656 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
660 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
661 $column_data{AR_paid} =
662 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
663 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
664 $column_data{datepaid} =
665 qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|;
666 $column_data{source} =
667 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
669 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
671 map { print qq|$column_data{$_}\n| } @column_index;
677 map { $form->{$_} =~ s/\"/"/g } qw(selectAR_paid);
679 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
680 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
686 <td><hr size=3 noshade></td>
691 $lxdebug->leave_sub();
695 $lxdebug->enter_sub();
699 <input name=callback type=hidden value="$form->{callback}">
701 <input type=hidden name=path value=$form->{path}>
702 <input type=hidden name=login value=$form->{login}>
703 <input type=hidden name=password value=$form->{password}>
708 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
709 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
711 if ($form->{id} && $form->{radier}) {
713 print qq|<input class=submit type=submit name=action value="|
714 . $locale->text('Update') . qq|">
717 if (!$form->{revtrans}) {
718 if (!$form->{locked}) {
720 <input class=submit type=submit name=action value="|
721 . $locale->text('Post') . qq|">
722 <input class=submit type=submit name=action value="|
723 . $locale->text('Delete') . qq|">
728 if ($transdate > $closedto) {
730 <input class=submit type=submit name=action value="|
731 . $locale->text('Post as new') . qq|">
736 if ($transdate > $closedto) {
737 print qq|<input class=submit type=submit name=action value="|
738 . $locale->text('Update') . qq|">
739 <input class=submit type=submit name=action value="|
740 . $locale->text('Post') . qq|">|;
744 if ($form->{menubar}) {
745 require "$form->{path}/menu.pl";
756 $lxdebug->leave_sub();
760 $lxdebug->enter_sub();
768 $form->{invtotal} = 0;
770 $form->{selectAR_amount} = $form->{AR_amount};
771 $form->{selectAR_amount} =~
772 s/value=\"$form->{AR_amountselected}\"/value=\"$form->{AR_amountselected}\" selected/;
774 $form->{selectAR} = $form->{AR};
777 s/value=\"$form->{ARselected}\"/value=\"$form->{ARselected}\" selected/;
779 ($AR_amountaccno, $AR_amounttaxkey) =
780 split(/--/, $form->{AR_amountselected});
781 $form->{selecttaxchart} = $form->{taxchart};
782 $form->{selecttaxchart} =~
783 s/value=\"$AR_amounttaxkey--([^\"]*)\"/value=\"$AR_amounttaxkey--$1\" selected/;
787 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
788 qw(exchangerate creditlimit creditremaining);
790 @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
794 $form->{"amount_$i"} =
795 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
796 if ($form->{"amount_$i"}) {
800 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
805 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
807 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. 1);
809 $form->{exchangerate} = $exchangerate
813 $form->check_exchangerate(
814 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
817 $form->{invdate} = $form->{transdate};
818 $save_AR = $form->{AR};
819 &check_name(customer);
820 $form->{AR} = $save_AR;
828 @taxaccounts = split / /, $form->{taxaccounts};
830 $form->{"tax"} = $form->parse_amount(\%myconfig, $form->{"tax"});
832 if ($form->{taxincluded} && $form->{"rate"}) {
833 $taxrate = $form->{"rate"};
834 $withholdingrate = 0;
838 ($form->{invtotal} - ($form->{invtotal} / ($taxrate + 1))),
840 $form->{"tax"} = $form->round_amount($amount, 2);
841 $taxdiff += ($amount - $form->{"tax"});
843 if (abs $taxdiff >= 0.005) {
844 $form->{"tax"} += $form->round_amount($taxdiff, 2);
847 $totaltax += $form->{"tax"};
851 $form->round_amount($form->{invtotal} * $form->{"rate"}, 2);
852 $totaltax += $form->{"tax"};
857 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
859 for $i (1 .. $form->{paidaccounts}) {
860 if ($form->{"paid_$i"}) {
863 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
864 } qw(paid exchangerate);
866 $totalpaid += $form->{"paid_$i"};
868 $form->{"exchangerate_$i"} = $exchangerate
870 $form->{"forex_$i"} = (
872 $form->check_exchangerate(
873 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
878 $form->{creditremaining} -=
879 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
880 $form->{oldinvtotal});
881 $form->{oldinvtotal} = $form->{invtotal};
882 $form->{oldtotalpaid} = $totalpaid;
886 $lxdebug->leave_sub();
890 $lxdebug->enter_sub();
892 # check if there is an invoice number, invoice and due date
893 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
894 $form->isblank("duedate", $locale->text('Due Date missing!'));
895 $form->isblank("customer", $locale->text('Customer missing!'));
897 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
898 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
900 $form->error($locale->text('Cannot post transaction for a closed period!'))
901 if ($transdate <= $closedto);
903 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
904 if ($form->{currency} ne $form->{defaultcurrency});
908 for $i (1 .. $form->{paidaccounts}) {
909 if ($form->{"paid_$i"}) {
910 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
912 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
914 $form->error($locale->text('Cannot post payment for a closed period!'))
915 if ($datepaid <= $closedto);
917 if ($form->{currency} ne $form->{defaultcurrency}) {
918 $form->{"exchangerate_$i"} = $form->{exchangerate}
919 if ($transdate == $datepaid);
920 $form->isblank("exchangerate_$i",
921 $locale->text('Exchangerate for payment missing!'));
926 # if oldcustomer ne customer redo form
927 ($customer) = split /--/, $form->{customer};
928 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
933 ($creditaccno, $credittaxkey) = split /--/, $form->{AR_amountselected};
934 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
935 ($receivablesaccno, $payablestaxkey) = split /--/, $form->{ARselected};
936 $form->{AR}{amount_1} = $creditaccno;
937 $form->{AR}{receivables} = $receivablesaccno;
938 $form->{taxkey} = $taxkey;
940 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber")
941 unless $form->{invnumber};
943 $form->{id} = 0 if $form->{postasnew};
945 $form->redirect($locale->text('Transaction posted!'))
946 if (AR->post_transaction(\%myconfig, \%$form));
947 $form->error($locale->text('Cannot post transaction!'));
949 $lxdebug->leave_sub();
953 $lxdebug->enter_sub();
955 $form->{postasnew} = 1;
958 $lxdebug->leave_sub();
962 $lxdebug->enter_sub();
964 $form->{title} = $locale->text('Confirm!');
968 delete $form->{header};
973 <form method=post action=$form->{script}>
976 foreach $key (keys %$form) {
977 $form->{$key} =~ s/\"/"/g;
978 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
982 <h2 class=confirm>$form->{title}</h2>
985 . $locale->text('Are you sure you want to delete Transaction')
986 . qq| $form->{invnumber}</h4>
988 <input name=action class=submit type=submit value="|
989 . $locale->text('Yes') . qq|">
996 $lxdebug->leave_sub();
1000 $lxdebug->enter_sub();
1002 $form->redirect($locale->text('Transaction deleted!'))
1003 if (AR->delete_transaction(\%myconfig, \%$form, $spool));
1004 $form->error($locale->text('Cannot delete transaction!'));
1006 $lxdebug->leave_sub();
1010 $lxdebug->enter_sub();
1012 # setup customer selection
1013 $form->all_vc(\%myconfig, "customer", "AR");
1015 if (@{ $form->{all_customer} }) {
1016 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1017 @{ $form->{all_customer} };
1018 $customer = qq|<select name=customer><option>\n$customer</select>|;
1020 $customer = qq|<input name=customer size=35>|;
1024 if (@{ $form->{all_departments} }) {
1025 $form->{selectdepartment} = "<option>\n";
1028 $form->{selectdepartment} .=
1029 "<option>$_->{description}--$_->{id}\n"
1030 } (@{ $form->{all_departments} });
1035 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1036 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1038 | if $form->{selectdepartment};
1040 $form->{title} = $locale->text('AR Transactions');
1042 # use JavaScript Calendar or not
1043 $form->{jsscript} = $jscalendar;
1045 if ($form->{jsscript}) {
1047 # with JavaScript Calendar
1049 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1050 <input type=button name=transdatefrom id="trigger1" value=|
1051 . $locale->text('button')
1055 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1056 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1057 . $locale->text('button')
1063 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1064 "transdateto", "BL", "trigger2");
1067 # without JavaScript Calendar
1069 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1071 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1074 $form->{fokus} = "search.customer";
1078 <body onLoad="fokus()">
1080 <form method=post name="search" action=$form->{script}>
1083 <tr><th class=listtop>$form->{title}</th></tr>
1084 <tr height="5"></tr>
1089 <th align=right>| . $locale->text('Customer') . qq|</th>
1090 <td colspan=3>$customer</td>
1094 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1095 <td colspan=3><input name=invnumber size=20></td>
1098 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1099 <td colspan=3><input name=ordnumber size=20></td>
1102 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1103 <td colspan=3><input name=notes size=40></td>
1106 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1108 <th align=right>| . $locale->text('Bis') . qq|</th>
1111 <input type=hidden name=sort value=transdate>
1119 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1123 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1124 <td nowrap>| . $locale->text('Open') . qq|</td>
1125 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1126 <td nowrap>| . $locale->text('Closed') . qq|</td>
1129 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1130 <td nowrap>| . $locale->text('ID') . qq|</td>
1131 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1132 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1133 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1134 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1135 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1136 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1139 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1140 <td nowrap>| . $locale->text('Customer') . qq|</td>
1141 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1142 <td nowrap>| . $locale->text('Amount') . qq|</td>
1143 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1144 <td nowrap>| . $locale->text('Tax') . qq|</td>
1145 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1146 <td nowrap>| . $locale->text('Total') . qq|</td>
1149 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1150 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1151 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1152 <td nowrap>| . $locale->text('Paid') . qq|</td>
1153 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1154 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1155 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1156 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1159 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1160 <td nowrap>| . $locale->text('Notes') . qq|</td>
1161 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1162 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1163 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1164 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1165 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1166 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1169 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1170 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1179 <td><hr size=3 noshade></td>
1183 <input type=hidden name=nextsub value=$form->{nextsub}>
1185 <input type=hidden name=path value=$form->{path}>
1186 <input type=hidden name=login value=$form->{login}>
1187 <input type=hidden name=password value=$form->{password}>
1190 <input class=submit type=submit name=action value="|
1191 . $locale->text('Continue') . qq|">
1202 $lxdebug->leave_sub();
1205 sub ar_transactions {
1206 $lxdebug->enter_sub();
1208 $form->{customer} = $form->unescape($form->{customer});
1209 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1211 AR->ar_transactions(\%myconfig, \%$form);
1214 "$form->{script}?action=ar_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1217 if ($form->{customer}) {
1218 $callback .= "&customer=" . $form->escape($form->{customer}, 1);
1219 $href .= "&customer=" . $form->escape($form->{customer});
1220 $option = $locale->text('Customer') . " : $form->{customer}";
1222 if ($form->{department}) {
1223 $callback .= "&department=" . $form->escape($form->{department}, 1);
1224 $href .= "&department=" . $form->escape($form->{department});
1225 ($department) = split /--/, $form->{department};
1226 $option .= "\n<br>" if ($option);
1227 $option .= $locale->text('Department') . " : $department";
1229 if ($form->{invnumber}) {
1230 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1231 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1232 $option .= "\n<br>" if ($option);
1233 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1235 if ($form->{ordnumber}) {
1236 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1237 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1238 $option .= "\n<br>" if ($option);
1239 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1241 if ($form->{notes}) {
1242 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1243 $href .= "¬es=" . $form->escape($form->{notes});
1244 $option .= "\n<br>" if $option;
1245 $option .= $locale->text('Notes') . " : $form->{notes}";
1248 if ($form->{transdatefrom}) {
1249 $callback .= "&transdatefrom=$form->{transdatefrom}";
1250 $href .= "&transdatefrom=$form->{transdatefrom}";
1251 $option .= "\n<br>" if ($option);
1253 $locale->text('From') . " "
1254 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1256 if ($form->{transdateto}) {
1257 $callback .= "&transdateto=$form->{transdateto}";
1258 $href .= "&transdateto=$form->{transdateto}";
1259 $option .= "\n<br>" if ($option);
1261 $locale->text('Bis') . " "
1262 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1264 if ($form->{open}) {
1265 $callback .= "&open=$form->{open}";
1266 $href .= "&open=$form->{open}";
1267 $option .= "\n<br>" if ($option);
1268 $option .= $locale->text('Open');
1270 if ($form->{closed}) {
1271 $callback .= "&closed=$form->{closed}";
1272 $href .= "&closed=$form->{closed}";
1273 $option .= "\n<br>" if ($option);
1274 $option .= $locale->text('Closed');
1278 $form->sort_columns(
1279 qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint shipvia)
1282 foreach $item (@columns) {
1283 if ($form->{"l_$item"} eq "Y") {
1284 push @column_index, $item;
1286 # add column to href and callback
1287 $callback .= "&l_$item=Y";
1288 $href .= "&l_$item=Y";
1292 if ($form->{l_subtotal} eq 'Y') {
1293 $callback .= "&l_subtotal=Y";
1294 $href .= "&l_subtotal=Y";
1297 $column_header{id} =
1298 "<th><a class=listheading href=$href&sort=id>"
1299 . $locale->text('ID')
1301 $column_header{transdate} =
1302 "<th><a class=listheading href=$href&sort=transdate>"
1303 . $locale->text('Date')
1305 $column_header{duedate} =
1306 "<th><a class=listheading href=$href&sort=duedate>"
1307 . $locale->text('Due Date')
1309 $column_header{invnumber} =
1310 "<th><a class=listheading href=$href&sort=invnumber>"
1311 . $locale->text('Invoice')
1313 $column_header{ordnumber} =
1314 "<th><a class=listheading href=$href&sort=ordnumber>"
1315 . $locale->text('Order')
1317 $column_header{name} =
1318 "<th><a class=listheading href=$href&sort=name>"
1319 . $locale->text('Customer')
1321 $column_header{netamount} =
1322 "<th class=listheading>" . $locale->text('Amount') . "</th>";
1323 $column_header{tax} =
1324 "<th class=listheading>" . $locale->text('Tax') . "</th>";
1325 $column_header{amount} =
1326 "<th class=listheading>" . $locale->text('Total') . "</th>";
1327 $column_header{paid} =
1328 "<th class=listheading>" . $locale->text('Paid') . "</th>";
1329 $column_header{datepaid} =
1330 "<th><a class=listheading href=$href&sort=datepaid>"
1331 . $locale->text('Date Paid')
1333 $column_header{due} =
1334 "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
1335 $column_header{notes} =
1336 "<th class=listheading>" . $locale->text('Notes') . "</th>";
1337 $column_header{employee} =
1338 "<th><a class=listheading href=$href&sort=employee>"
1339 . $locale->text('Salesperson') . "</th>";
1341 $column_header{shippingpoint} =
1342 "<th><a class=listheading href=$href&sort=shippingpoint>"
1343 . $locale->text('Shipping Point')
1345 $column_header{shipvia} =
1346 "<th><a class=listheading href=$href&sort=shipvia>"
1347 . $locale->text('Ship via')
1350 $form->{title} = $locale->text('AR Transactions');
1359 <th class=listtop>$form->{title}</th>
1361 <tr height="5"></tr>
1368 <tr class=listheading>
1371 map { print "\n$column_header{$_}" } @column_index;
1377 # add sort and escape callback, this one we use for the add sub
1378 $form->{callback} = $callback .= "&sort=$form->{sort}";
1380 # escape callback for href
1381 $callback = $form->escape($callback);
1383 if (@{ $form->{AR} }) {
1384 $sameitem = $form->{AR}->[0]->{ $form->{sort} };
1387 # sums and tax on reports by Antonio Gallardo
1389 foreach $ar (@{ $form->{AR} }) {
1391 if ($form->{l_subtotal} eq 'Y') {
1392 if ($sameitem ne $ar->{ $form->{sort} }) {
1397 $column_data{netamount} =
1399 . $form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")
1401 $column_data{tax} = "<td align=right>"
1402 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount},
1405 $column_data{amount} =
1407 . $form->format_amount(\%myconfig, $ar->{amount}, 2, " ") . "</td>";
1408 $column_data{paid} =
1410 . $form->format_amount(\%myconfig, $ar->{paid}, 2, " ") . "</td>";
1411 $column_data{due} = "<td align=right>"
1412 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid},
1416 $subtotalnetamount += $ar->{netamount};
1417 $subtotalamount += $ar->{amount};
1418 $subtotalpaid += $ar->{paid};
1419 $subtotaldue += $ar->{amount} - $ar->{paid};
1421 $totalnetamount += $ar->{netamount};
1422 $totalamount += $ar->{amount};
1423 $totalpaid += $ar->{paid};
1424 $totaldue += ($ar->{amount} - $ar->{paid});
1426 $column_data{transdate} = "<td>$ar->{transdate} </td>";
1427 $column_data{id} = "<td>$ar->{id}</td>";
1428 $column_data{datepaid} = "<td>$ar->{datepaid} </td>";
1429 $column_data{duedate} = "<td>$ar->{duedate} </td>";
1431 $module = ($ar->{invoice}) ? "is.pl" : $form->{script};
1433 $column_data{invnumber} =
1434 "<td><a href=$module?action=edit&id=$ar->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}</a></td>";
1435 $column_data{ordnumber} = "<td>$ar->{ordnumber} </td>";
1436 $column_data{name} = "<td>$ar->{name}</td>";
1437 $ar->{notes} =~ s/\r\n/<br>/g;
1438 $column_data{notes} = "<td>$ar->{notes} </td>";
1439 $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>";
1440 $column_data{shipvia} = "<td>$ar->{shipvia} </td>";
1441 $column_data{employee} = "<td>$ar->{employee} </td>";
1446 <tr class=listrow$i>
1449 map { print "\n$column_data{$_}" } @column_index;
1457 if ($form->{l_subtotal} eq 'Y') {
1463 <tr class=listtotal>
1466 map { $column_data{$_} = "<td> </td>" } @column_index;
1468 $column_data{netamount} =
1469 "<th class=listtotal align=right>"
1470 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1471 $column_data{tax} = "<th class=listtotal align=right>"
1472 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1475 $column_data{amount} =
1476 "<th class=listtotal align=right>"
1477 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1478 $column_data{paid} =
1479 "<th class=listtotal align=right>"
1480 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1482 "<th class=listtotal align=right>"
1483 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1485 map { print "\n$column_data{$_}" } @column_index;
1493 <td><hr size=3 noshade></td>
1498 <form method=post action=$form->{script}>
1500 <input name=callback type=hidden value="$form->{callback}">
1502 <input type=hidden name=path value=$form->{path}>
1503 <input type=hidden name=login value=$form->{login}>
1504 <input type=hidden name=password value=$form->{password}>
1506 <input class=submit type=submit name=action value="|
1507 . $locale->text('AR Transaction') . qq|">
1508 <input class=submit type=submit name=action value="|
1509 . $locale->text('Sales Invoice') . qq|">|;
1511 if ($form->{menubar}) {
1512 require "$form->{path}/menu.pl";
1523 $lxdebug->leave_sub();
1527 $lxdebug->enter_sub();
1529 map { $column_data{$_} = "<td> </td>" } @column_index;
1531 $column_data{tax} = "<th class=listsubtotal align=right>"
1532 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1535 $column_data{amount} =
1536 "<th class=listsubtotal align=right>"
1537 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1538 $column_data{paid} =
1539 "<th class=listsubtotal align=right>"
1540 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1542 "<th class=listsubtotal align=right>"
1543 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1545 $subtotalnetamount = 0;
1546 $subtotalamount = 0;
1550 $sameitem = $ar->{ $form->{sort} };
1552 print "<tr class=listsubtotal>";
1554 map { print "\n$column_data{$_}" } @column_index;
1560 $lxdebug->leave_sub();