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";
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')
74 $lxdebug->enter_sub();
77 $form->{title} = "Add";
78 $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
83 $lxdebug->leave_sub();
88 $lxdebug->enter_sub();
91 $form->{title} = "Edit";
96 $lxdebug->leave_sub();
101 $lxdebug->enter_sub();
107 $lxdebug->leave_sub();
112 $lxdebug->enter_sub();
115 $form->create_links("AR", \%myconfig, "customer");
116 $duedate = $form->{duedate};
118 $taxincluded = $form->{taxincluded};
120 IS->get_customer(\%myconfig, \%$form);
122 $form->{duedate} = $duedate if $duedate;
123 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
126 @curr = split /:/, $form->{currencies};
128 $form->{defaultcurrency} = $curr[0];
130 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
133 if (@{ $form->{all_customer} }) {
134 $form->{customer} = "$form->{customer}--$form->{customer_id}";
135 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} });
139 if (@{ $form->{all_departments} }) {
140 $form->{selectdepartment} = "<option>\n";
141 $form->{department} = "$form->{department}--$form->{department_id}";
143 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
146 $form->{employee} = "$form->{employee}--$form->{employee_id}";
148 if (@{ $form->{all_employees} }) {
149 $form->{selectemployee} = "";
150 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_employees} });
152 # build the popup menus
153 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
155 map { $tax .= qq|<option value=\"$_->{taxkey}--$_->{rate}\">$_->{taxdescription} |.($_->{rate} * 100).qq| %|} @{ $form->{TAX} };
156 $form->{taxchart} = $tax;
157 $form->{selecttaxchart} = $tax;
160 $form->{forex} = $form->{exchangerate};
161 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
162 foreach $key (keys %{ $form->{AR_links} }) {
164 foreach $ref (@{ $form->{AR_links}{$key} }) {
165 if ($key eq "AR_paid") {
166 $form->{"select$key"} .= "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
168 $form->{"select$key"} .= "<option value=\"$ref->{accno}--$ref->{taxkey}\">$ref->{accno}--$ref->{description}</option>\n";
172 $form->{$key} = $form->{"select$key"};
173 # if there is a value we have an old entry
175 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
176 if ($key eq "AR_paid") {
178 $form->{"AR_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
180 $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1;
181 $form->{"datepaid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
182 $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i-1]->{source};
183 $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i-1]->{memo};
185 $form->{"forex_$j"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
186 $form->{"AR_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
187 $form->{paidaccounts}++;
193 if ($key eq "AR_tax") {
194 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
195 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2);
197 if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
198 $totaltax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
199 $taxrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
201 $totalwithholding += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
202 $withholdingrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
206 $form->{"${akey}_$i"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2);
207 if ($akey eq 'amount') {
209 $totalamount += $form->{"${akey}_$i"};
211 $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
212 $form->{taxrate} = $form->{acc_trans}{$key}->[$i-1]->{rate};
213 $form->{"project_id_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
215 $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
216 $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
217 $form->{"select${key}"} =~ /(<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)/;
219 $form->{"select${key}"} = $1;
220 if ($akey eq 'amount') {
221 $form->{selecttaxchart} =~ /(<option value=\"$form->{acc_trans}{$key}->[$i-1]->{taxkey}--[^<]*)/;
222 $form->{selecttaxchart} = $1;
229 $form->{taxincluded} = $taxincluded if ($form->{id});
230 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
232 if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
233 # add tax to amounts and invtotal
235 $taxamount = ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
236 $tax = $form->round_amount($taxamount, 2);
237 $diff += ($taxamount - $tax);
238 $form->{"amount_$i"} += $tax;
240 $form->{amount_1} += $form->round_amount($diff, 2);
243 # check if calculated is equal to stored
244 if ($form->{taxincluded} && $form->{taxrate} && $withholdingrate) {
245 if ($form->{"taxrate"} > 0) {
246 $taxamount = $form->round_amount(($form->{amount_1} - ($form->{amount_1} / ($form->{taxrate} + 1))), 2);
248 $taxamount = $form->round_amount(($totalamount + $totaltax + $totalwithholding) * $withholdingrate / (1 - $withholdingrate), 2) * $form->{"taxrate"} / $withholdingrate;
251 $taxamount = $totalamount * $form->{"taxrate"};
253 $taxamount = $form->round_amount($taxamount, 2);
254 $form->{tax} = $taxamount;
256 $form->{invtotal} = $totalamount + $totaltax + $totalwithholding;
259 $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
262 $lxdebug->leave_sub();
267 $lxdebug->enter_sub();
270 $title = $form->{title};
271 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
273 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
276 # $locale->text('Add Accounts Receivables Transaction')
277 # $locale->text('Edit Accounts Receivables Transaction')
280 $readonly = ($form->{id}) ? "readonly" : "";
282 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
283 $readonly = ($form->{radier}) ? "" : $readonly;
285 # set option selected
286 foreach $item (qw(customer currency department employee)) {
287 $form->{"select$item"} =~ s/ selected//;
288 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
291 map { $form->{$_} =~ s/\"/"/g } qw(AR_amount AR taxchart);
294 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
296 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
297 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
300 <input type=hidden name=forex value=$form->{forex}>
302 if ($form->{currency} ne $form->{defaultcurrency}) {
303 if ($form->{forex}) {
305 <th align=right>|.$locale->text('Exchangerate').qq|</th>
306 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
310 <th align=right>|.$locale->text('Exchangerate').qq|</th>
311 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
320 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
321 <th align=left nowrap>|.$locale->text('Tax Included').qq|</th>
327 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
330 $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
334 <th align="right" nowrap>|.$locale->text('Department').qq|</th>
335 <td colspan=3><select name=department>$form->{selectdepartment}</select>
336 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
339 | if $form->{selectdepartment};
342 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
344 $customer = ($form->{selectcustomer}) ? qq|<select name=customer>$form->{selectcustomer}</select>| : qq|<input name=customer value="$form->{customer}" size=35>|;
347 <input type=hidden name=employee value="$form->{employee}">
350 if ($form->{selectemployee}) {
353 <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
354 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
355 <input type=hidden name=selectemployee value="$form->{selectemployee}">
360 $form->{fokus} = "arledger.customer";
362 # use JavaScript Calendar or not
363 $form->{jsscript} = $jscalendar;
365 if ($form->{jsscript})
367 # with JavaScript Calendar
369 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
370 <td><input type=button name=transdate id="trigger1" value=|.$locale->text('button').qq|></td>
373 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
374 <td><input type=button name=duedate id="trigger2" value=|.$locale->text('button').qq|></td></td>
377 $jsscript = Form->write_trigger(\%myconfig,"2","transdate","BL","trigger1","duedate","BL","trigger2");
381 # without JavaScript Calendar
382 $button1 = qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>|;
383 $button2 = qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
389 <body onLoad="fokus()">
391 <form method=post name="arledger" action=$form->{script}>
393 <input type=hidden name=id value=$form->{id}>
394 <input type=hidden name=sort value=$form->{sort}>
395 <input type=hidden name=closedto value=$form->{closedto}>
396 <input type=hidden name=locked value=$form->{locked}>
397 <input type=hidden name=title value="$title">
401 <th class=listtop>$form->{title}</th>
411 <th align="right" nowrap>|.$locale->text('Customer').qq|</th>
412 <td colspan=3>$customer</td>
413 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
414 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
415 <input type=hidden name=customer_id value="$form->{customer_id}">
416 <input type=hidden name=terms value=$form->{terms}>
423 <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th>
424 <td>$form->{creditlimit}</td>
425 <th align=left nowrap>|.$locale->text('Remaining').qq|</th>
426 <td class="plus$n">$form->{creditremaining}</td>
427 <input type=hidden name=creditlimit value=$form->{creditlimit}>
428 <input type=hidden name=creditremaining value=$form->{creditremaining}>
434 <th align=right>|.$locale->text('Currency').qq|</th>
435 <td><select name=currency>$form->{selectcurrency}</select></td>
436 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
437 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
438 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
439 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
450 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
451 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
454 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
455 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
458 <th align=right nowrap>|.$locale->text('Invoice Date').qq|</th>
462 <th align=right nowrap>|.$locale->text('Due Date').qq|</th>
477 <input type=hidden name=AR_amount value="$form->{AR_amount}">
478 <input type=hidden name=taxchart value="$form->{taxchart}">
479 <input type=hidden name=rowcount value=$form->{rowcount}>
482 $form->{"tax"} = $form->format_amount(\%myconfig, $form->{"tax"}, 2);
484 $amount = $locale->text('Amount');
485 $project = $locale->text('Project');
491 $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
495 <th align=right>$amount</th>
496 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
498 <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
499 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
500 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
501 <td width=50%><select name="AR_amountselected">$form->{"selectAR_amount"}</select></td>
508 $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax');
512 <th align=right nowrap>$taxlabel</th>
513 <td><input name="tax" size=10 value=$form->{"tax"}></td>
514 <td align=right></td>
516 <td><select name="taxchartselected">$form->{"selecttaxchart"}</select></td>
522 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
527 <th align=right>|.$locale->text('Total').qq|</th>
528 <th align=left>$form->{invtotal}</th>
530 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
531 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
533 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
536 <td><select name=ARselected>$form->{selectAR}</select></td>
537 <input type=hidden name=AR value="$form->{AR}">
541 <th align=right>|.$locale->text('Notes').qq|</th>
542 <td colspan=4>$notes</td>
550 <tr class=listheading>
551 <th colspan=6 class=listheading>|.$locale->text('Incoming Payments').qq|</th>
555 if ($form->{currency} eq $form->{defaultcurrency}) {
556 @column_index = qw(datepaid source memo paid AR_paid);
558 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
561 $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
562 $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
563 $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
564 $column_data{AR_paid} = "<th>".$locale->text('Account')."</th>";
565 $column_data{source} = "<th>".$locale->text('Source')."</th>";
566 $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
571 map { print "$column_data{$_}\n" } @column_index;
577 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
578 for $i (1 .. $form->{paidaccounts}) {
583 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
584 $form->{"selectAR_paid_$i"} =~ s/option value=\"$form->{"AR_paid_$i"}\">/option value=\"$form->{"AR_paid_$i"}\" selected>/;
587 $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
588 $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
590 $exchangerate = qq| |;
591 if ($form->{currency} ne $form->{defaultcurrency}) {
592 if ($form->{"forex_$i"}) {
593 $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
595 $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
600 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
603 $column_data{paid} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
604 $column_data{AR_paid} = qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
605 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
606 $column_data{datepaid} = qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|;
607 $column_data{source} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
608 $column_data{memo} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
610 map { print qq|$column_data{$_}\n| } @column_index;
616 map { $form->{$_} =~ s/\"/"/g } qw(selectAR_paid);
618 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
619 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
625 <td><hr size=3 noshade></td>
630 $lxdebug->leave_sub();
635 $lxdebug->enter_sub();
640 <input name=callback type=hidden value="$form->{callback}">
642 <input type=hidden name=path value=$form->{path}>
643 <input type=hidden name=login value=$form->{login}>
644 <input type=hidden name=password value=$form->{password}>
649 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
650 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
652 if ($form->{id} && $form->{radier}) {
654 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
657 if (!$form->{revtrans}) {
658 if (!$form->{locked}) {
660 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
661 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
666 if ($transdate > $closedto) {
668 <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
673 if ($transdate > $closedto) {
674 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
675 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
679 if ($form->{menubar}) {
680 require "$form->{path}/menu.pl";
691 $lxdebug->leave_sub();
696 $lxdebug->enter_sub();
706 $form->{invtotal} = 0;
708 $form->{selectAR_amount} = $form->{AR_amount};
709 $form->{selectAR_amount} =~ s/value=\"$form->{AR_amountselected}\"/value=\"$form->{AR_amountselected}\" selected/;
711 $form->{selectAR} = $form->{AR};
713 $form->{selectAR} =~ s/value=\"$form->{ARselected}\"/value=\"$form->{ARselected}\" selected/;
715 ($AR_amountaccno, $AR_amounttaxkey) = split(/--/, $form->{AR_amountselected});
716 $form->{selecttaxchart} = $form->{taxchart};
717 $form->{selecttaxchart} =~ s/value=\"$AR_amounttaxkey--([^\"]*)\"/value=\"$AR_amounttaxkey--$1\" selected/;
721 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
723 @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
727 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
728 if ($form->{"amount_$i"}) {
732 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
737 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
739 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. 1);
741 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'buy')));
744 $form->{invdate} = $form->{transdate};
745 $save_AR = $form->{AR};
746 &check_name(customer);
747 $form->{AR} = $save_AR;
755 @taxaccounts = split / /, $form->{taxaccounts};
757 $form->{"tax"} = $form->parse_amount(\%myconfig, $form->{"tax"});
759 if ($form->{taxincluded} && $form->{"rate"}) {
760 $taxrate = $form->{"rate"};
761 $withholdingrate = 0;
763 $amount = $form->round_amount(($form->{invtotal} - ($form->{invtotal} / ($taxrate + 1))), 2);
764 $form->{"tax"} = $form->round_amount($amount, 2);
765 $taxdiff += ($amount - $form->{"tax"});
768 if (abs $taxdiff >= 0.005) {
769 $form->{"tax"} += $form->round_amount($taxdiff, 2);
772 $totaltax += $form->{"tax"};
775 $form->{"tax"} = $form->round_amount($form->{invtotal} * $form->{"rate"}, 2);
776 $totaltax += $form->{"tax"};
780 $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
782 for $i (1 .. $form->{paidaccounts}) {
783 if ($form->{"paid_$i"}) {
784 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
786 $totalpaid += $form->{"paid_$i"};
788 $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy')));
792 $form->{creditremaining} -= ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - $form->{oldinvtotal});
793 $form->{oldinvtotal} = $form->{invtotal};
794 $form->{oldtotalpaid} = $totalpaid;
798 $lxdebug->leave_sub();
803 $lxdebug->enter_sub();
806 # check if there is an invoice number, invoice and due date
807 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
808 $form->isblank("duedate", $locale->text('Due Date missing!'));
809 $form->isblank("customer", $locale->text('Customer missing!'));
811 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
812 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
814 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
816 $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
818 delete ($form->{AR});
820 for $i (1 .. $form->{paidaccounts}) {
821 if ($form->{"paid_$i"}) {
822 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
824 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
826 $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
828 if ($form->{currency} ne $form->{defaultcurrency}) {
829 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
830 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
835 # if oldcustomer ne customer redo form
836 ($customer) = split /--/, $form->{customer};
837 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
843 ($creditaccno, $credittaxkey) = split /--/, $form->{AR_amountselected};
844 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
845 ($receivablesaccno, $payablestaxkey) = split /--/, $form->{ARselected};
846 $form->{AR}{amount_1} = $creditaccno;
847 $form->{AR}{receivables} = $receivablesaccno;
848 $form->{taxkey} = $taxkey;
850 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber") unless $form->{invnumber};
852 $form->{id} = 0 if $form->{postasnew};
854 $form->redirect($locale->text('Transaction posted!')) if (AR->post_transaction(\%myconfig, \%$form));
855 $form->error($locale->text('Cannot post transaction!'));
857 $lxdebug->leave_sub();
862 $lxdebug->enter_sub();
865 $form->{postasnew} = 1;
868 $lxdebug->leave_sub();
873 $lxdebug->enter_sub();
876 $form->{title} = $locale->text('Confirm!');
880 delete $form->{header};
885 <form method=post action=$form->{script}>
888 foreach $key (keys %$form) {
889 $form->{$key} =~ s/\"/"/g;
890 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
894 <h2 class=confirm>$form->{title}</h2>
896 <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber}</h4>
898 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
905 $lxdebug->leave_sub();
911 $lxdebug->enter_sub();
914 $form->redirect($locale->text('Transaction deleted!')) if (AR->delete_transaction(\%myconfig, \%$form, $spool));
915 $form->error($locale->text('Cannot delete transaction!'));
917 $lxdebug->leave_sub();
922 $lxdebug->enter_sub();
925 # setup customer selection
926 $form->all_vc(\%myconfig, "customer", "AR");
928 if (@{ $form->{all_customer} }) {
929 map { $customer .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{all_customer} };
930 $customer = qq|<select name=customer><option>\n$customer</select>|;
932 $customer = qq|<input name=customer size=35>|;
936 if (@{ $form->{all_departments} }) {
937 $form->{selectdepartment} = "<option>\n";
939 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
944 <th align=right nowrap>|.$locale->text('Department').qq|</th>
945 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
947 | if $form->{selectdepartment};
949 $form->{title} = $locale->text('AR Transactions');
951 # use JavaScript Calendar or not
952 $form->{jsscript} = $jscalendar;
954 if ($form->{jsscript})
956 # with JavaScript Calendar
958 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
959 <input type=button name=transdatefrom id="trigger1" value=|.$locale->text('button').qq|></td>
962 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
963 <input type=button name=transdateto name=transdateto id="trigger2" value=|.$locale->text('button').qq|></td>
966 $jsscript = Form->write_trigger(\%myconfig,"2","transdatefrom","BR","trigger1","transdateto","BL","trigger2");
970 # without JavaScript Calendar
972 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
974 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
977 $form->{fokus} = "search.customer";
981 <body onLoad="fokus()">
983 <form method=post name="search" action=$form->{script}>
986 <tr><th class=listtop>$form->{title}</th></tr>
992 <th align=right>|.$locale->text('Customer').qq|</th>
993 <td colspan=3>$customer</td>
997 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
998 <td colspan=3><input name=invnumber size=20></td>
1001 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
1002 <td colspan=3><input name=ordnumber size=20></td>
1005 <th align=right nowrap>|.$locale->text('Notes').qq|</th>
1006 <td colspan=3><input name=notes size=40></td>
1009 <th align=right nowrap>|.$locale->text('From').qq|</th>
1011 <th align=right>|.$locale->text('Bis').qq|</th>
1014 <input type=hidden name=sort value=transdate>
1022 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
1026 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1027 <td nowrap>|.$locale->text('Open').qq|</td>
1028 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1029 <td nowrap>|.$locale->text('Closed').qq|</td>
1032 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1033 <td nowrap>|.$locale->text('ID').qq|</td>
1034 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1035 <td nowrap>|.$locale->text('Invoice Number').qq|</td>
1036 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1037 <td nowrap>|.$locale->text('Order Number').qq|</td>
1038 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1039 <td nowrap>|.$locale->text('Invoice Date').qq|</td>
1042 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1043 <td nowrap>|.$locale->text('Customer').qq|</td>
1044 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1045 <td nowrap>|.$locale->text('Amount').qq|</td>
1046 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1047 <td nowrap>|.$locale->text('Tax').qq|</td>
1048 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1049 <td nowrap>|.$locale->text('Total').qq|</td>
1052 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1053 <td nowrap>|.$locale->text('Date Paid').qq|</td>
1054 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1055 <td nowrap>|.$locale->text('Paid').qq|</td>
1056 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1057 <td nowrap>|.$locale->text('Due Date').qq|</td>
1058 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1059 <td nowrap>|.$locale->text('Amount Due').qq|</td>
1062 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1063 <td nowrap>|.$locale->text('Notes').qq|</td>
1064 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1065 <td nowrap>|.$locale->text('Salesperson').qq|</td>
1066 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1067 <td nowrap>|.$locale->text('Shipping Point').qq|</td>
1068 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1069 <td nowrap>|.$locale->text('Ship via').qq|</td>
1072 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1073 <td nowrap>|.$locale->text('Subtotal').qq|</td>
1082 <td><hr size=3 noshade></td>
1086 <input type=hidden name=nextsub value=$form->{nextsub}>
1088 <input type=hidden name=path value=$form->{path}>
1089 <input type=hidden name=login value=$form->{login}>
1090 <input type=hidden name=password value=$form->{password}>
1093 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
1104 $lxdebug->leave_sub();
1108 sub ar_transactions {
1109 $lxdebug->enter_sub();
1112 $form->{customer} = $form->unescape($form->{customer});
1113 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1116 AR->ar_transactions(\%myconfig, \%$form);
1118 $callback = "$form->{script}?action=ar_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1121 if ($form->{customer}) {
1122 $callback .= "&customer=".$form->escape($form->{customer},1);
1123 $href .= "&customer=".$form->escape($form->{customer});
1124 $option = $locale->text('Customer')." : $form->{customer}";
1126 if ($form->{department}) {
1127 $callback .= "&department=".$form->escape($form->{department},1);
1128 $href .= "&department=".$form->escape($form->{department});
1129 ($department) = split /--/, $form->{department};
1130 $option .= "\n<br>" if ($option);
1131 $option .= $locale->text('Department')." : $department";
1133 if ($form->{invnumber}) {
1134 $callback .= "&invnumber=".$form->escape($form->{invnumber},1);
1135 $href .= "&invnumber=".$form->escape($form->{invnumber});
1136 $option .= "\n<br>" if ($option);
1137 $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
1139 if ($form->{ordnumber}) {
1140 $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);
1141 $href .= "&ordnumber=".$form->escape($form->{ordnumber});
1142 $option .= "\n<br>" if ($option);
1143 $option .= $locale->text('Order Number')." : $form->{ordnumber}";
1145 if ($form->{notes}) {
1146 $callback .= "¬es=".$form->escape($form->{notes},1);
1147 $href .= "¬es=".$form->escape($form->{notes});
1148 $option .= "\n<br>" if $option;
1149 $option .= $locale->text('Notes')." : $form->{notes}";
1152 if ($form->{transdatefrom}) {
1153 $callback .= "&transdatefrom=$form->{transdatefrom}";
1154 $href .= "&transdatefrom=$form->{transdatefrom}";
1155 $option .= "\n<br>" if ($option);
1156 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
1158 if ($form->{transdateto}) {
1159 $callback .= "&transdateto=$form->{transdateto}";
1160 $href .= "&transdateto=$form->{transdateto}";
1161 $option .= "\n<br>" if ($option);
1162 $option .= $locale->text('Bis')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);
1164 if ($form->{open}) {
1165 $callback .= "&open=$form->{open}";
1166 $href .= "&open=$form->{open}";
1167 $option .= "\n<br>" if ($option);
1168 $option .= $locale->text('Open');
1170 if ($form->{closed}) {
1171 $callback .= "&closed=$form->{closed}";
1172 $href .= "&closed=$form->{closed}";
1173 $option .= "\n<br>" if ($option);
1174 $option .= $locale->text('Closed');
1177 @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint shipvia));
1179 foreach $item (@columns) {
1180 if ($form->{"l_$item"} eq "Y") {
1181 push @column_index, $item;
1183 # add column to href and callback
1184 $callback .= "&l_$item=Y";
1185 $href .= "&l_$item=Y";
1189 if ($form->{l_subtotal} eq 'Y') {
1190 $callback .= "&l_subtotal=Y";
1191 $href .= "&l_subtotal=Y";
1195 $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
1196 $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
1197 $column_header{duedate} = "<th><a class=listheading href=$href&sort=duedate>".$locale->text('Due Date')."</a></th>";
1198 $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";
1199 $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>";
1200 $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Customer')."</a></th>";
1201 $column_header{netamount} = "<th class=listheading>" . $locale->text('Amount') . "</th>";
1202 $column_header{tax} = "<th class=listheading>" . $locale->text('Tax') . "</th>";
1203 $column_header{amount} = "<th class=listheading>" . $locale->text('Total') . "</th>";
1204 $column_header{paid} = "<th class=listheading>" . $locale->text('Paid') . "</th>";
1205 $column_header{datepaid} = "<th><a class=listheading href=$href&sort=datepaid>" . $locale->text('Date Paid') . "</a></th>";
1206 $column_header{due} = "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
1207 $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
1208 $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</th>";
1210 $column_header{shippingpoint} = "<th><a class=listheading href=$href&sort=shippingpoint>" . $locale->text('Shipping Point') . "</a></th>";
1211 $column_header{shipvia} = "<th><a class=listheading href=$href&sort=shipvia>" . $locale->text('Ship via') . "</a></th>";
1213 $form->{title} = $locale->text('AR Transactions');
1222 <th class=listtop>$form->{title}</th>
1224 <tr height="5"></tr>
1231 <tr class=listheading>
1234 map { print "\n$column_header{$_}" } @column_index;
1241 # add sort and escape callback, this one we use for the add sub
1242 $form->{callback} = $callback .= "&sort=$form->{sort}";
1244 # escape callback for href
1245 $callback = $form->escape($callback);
1247 if (@{ $form->{AR} }) {
1248 $sameitem = $form->{AR}->[0]->{$form->{sort}};
1251 # sums and tax on reports by Antonio Gallardo
1253 foreach $ar (@{ $form->{AR} }) {
1255 if ($form->{l_subtotal} eq 'Y') {
1256 if ($sameitem ne $ar->{$form->{sort}}) {
1261 $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")."</td>";
1262 $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount}, 2, " ")."</td>";
1263 $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{amount}, 2, " ")."</td>";
1264 $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{paid}, 2, " ")."</td>";
1265 $column_data{due} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid}, 2, " ")."</td>";
1267 $subtotalnetamount += $ar->{netamount};
1268 $subtotalamount += $ar->{amount};
1269 $subtotalpaid += $ar->{paid};
1270 $subtotaldue += $ar->{amount} - $ar->{paid};
1272 $totalnetamount += $ar->{netamount};
1273 $totalamount += $ar->{amount};
1274 $totalpaid += $ar->{paid};
1275 $totaldue += ($ar->{amount} - $ar->{paid});
1277 $column_data{transdate} = "<td>$ar->{transdate} </td>";
1278 $column_data{id} = "<td>$ar->{id}</td>";
1279 $column_data{datepaid} = "<td>$ar->{datepaid} </td>";
1280 $column_data{duedate} = "<td>$ar->{duedate} </td>";
1282 $module = ($ar->{invoice}) ? "is.pl" : $form->{script};
1284 $column_data{invnumber} = "<td><a href=$module?action=edit&id=$ar->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}</a></td>";
1285 $column_data{ordnumber} = "<td>$ar->{ordnumber} </td>";
1286 $column_data{name} = "<td>$ar->{name}</td>";
1287 $ar->{notes} =~ s/\r\n/<br>/g;
1288 $column_data{notes} = "<td>$ar->{notes} </td>";
1289 $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>";
1290 $column_data{shipvia} = "<td>$ar->{shipvia} </td>";
1291 $column_data{employee} = "<td>$ar->{employee} </td>";
1295 <tr class=listrow$i>
1298 map { print "\n$column_data{$_}" } @column_index;
1307 if ($form->{l_subtotal} eq 'Y') {
1313 <tr class=listtotal>
1316 map { $column_data{$_} = "<td> </td>" } @column_index;
1318 $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, " ")."</th>";
1319 $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ")."</th>";
1320 $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, " ")."</th>";
1321 $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, " ")."</th>";
1322 $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldue, 2, " ")."</th>";
1324 map { print "\n$column_data{$_}" } @column_index;
1332 <td><hr size=3 noshade></td>
1337 <form method=post action=$form->{script}>
1339 <input name=callback type=hidden value="$form->{callback}">
1341 <input type=hidden name=path value=$form->{path}>
1342 <input type=hidden name=login value=$form->{login}>
1343 <input type=hidden name=password value=$form->{password}>
1345 <input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|">
1346 <input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|">|;
1348 if ($form->{menubar}) {
1349 require "$form->{path}/menu.pl";
1360 $lxdebug->leave_sub();
1365 $lxdebug->enter_sub();
1368 map { $column_data{$_} = "<td> </td>" } @column_index;
1370 $column_data{tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ")."</th>";
1371 $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, " ")."</th>";
1372 $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>";
1373 $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldue, 2, " ")."</th>";
1375 $subtotalnetamount = 0;
1376 $subtotalamount = 0;
1380 $sameitem = $ar->{$form->{sort}};
1382 print "<tr class=listsubtotal>";
1384 map { print "\n$column_data{$_}" } @column_index;
1390 $lxdebug->leave_sub();