1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
24 # Accounts Receivables
26 #======================================================================
33 require "$form->{path}/arap.pl";
38 # this is for our long dates
39 # $locale->text('January')
40 # $locale->text('February')
41 # $locale->text('March')
42 # $locale->text('April')
43 # $locale->text('May ')
44 # $locale->text('June')
45 # $locale->text('July')
46 # $locale->text('August')
47 # $locale->text('September')
48 # $locale->text('October')
49 # $locale->text('November')
50 # $locale->text('December')
52 # this is for our short month
53 # $locale->text('Jan')
54 # $locale->text('Feb')
55 # $locale->text('Mar')
56 # $locale->text('Apr')
57 # $locale->text('May')
58 # $locale->text('Jun')
59 # $locale->text('Jul')
60 # $locale->text('Aug')
61 # $locale->text('Sep')
62 # $locale->text('Oct')
63 # $locale->text('Nov')
64 # $locale->text('Dec')
69 $form->{title} = "Add";
70 $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
80 $form->{title} = "Edit";
98 $form->create_links("AR", \%myconfig, "customer");
99 $duedate = $form->{duedate};
101 $taxincluded = $form->{taxincluded};
103 IS->get_customer(\%myconfig, \%$form);
105 $form->{duedate} = $duedate;
106 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
109 @curr = split /:/, $form->{currencies};
111 $form->{defaultcurrency} = $curr[0];
113 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
116 if (@{ $form->{all_customer} }) {
117 $form->{customer} = "$form->{customer}--$form->{customer_id}";
118 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} });
122 $form->{forex} = $form->{exchangerate};
123 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
125 foreach $key (keys %{ $form->{AR_links} }) {
127 foreach $ref (@{ $form->{AR_links}{$key} }) {
128 if ($key eq 'AR_tax') {
129 $form->{"selectAR_tax_$ref->{accno}"} = "<option>$ref->{accno}--$ref->{description}\n";
132 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
135 # if there is a value we have an old entry
136 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
137 if ($key eq "AR_paid") {
138 $form->{"AR_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
140 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1;
141 $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
142 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source};
144 $form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
146 $form->{paidaccounts}++;
152 if ($key eq "AR_tax") {
154 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
155 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2);
156 $totaltax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
158 $form->{"${akey}_$i"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2);
159 if ($akey eq 'amount') {
161 $totalamount += $form->{"${akey}_$i"};
163 $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
164 $form->{"project_id_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
166 $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
172 $form->{taxincluded} = $taxincluded if ($form->{id});
173 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
175 if ($form->{taxincluded} && $totalamount) {
176 # add tax to amounts and invtotal
177 for $i (1 .. $form->{rowcount}) {
178 $taxamount = $totaltax * $form->{"amount_$i"} / $totalamount;
179 $tax = $form->round_amount($taxamount, 2);
180 $diff += ($taxamount - $tax);
181 $form->{"amount_$i"} += $tax;
183 $form->{amount_1} += $form->round_amount($diff, 2);
186 $form->{invtotal} = $totalamount + $totaltax;
187 $form->{rowcount}++ if $form->{id};
189 $form->{AR} = $form->{AR_1};
191 $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
198 $title = $form->{title};
199 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
201 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
203 # $locale->text('Add Accounts Receivables Transaction')
204 # $locale->text('Edit Accounts Receivables Transaction')
206 # set option selected
207 foreach $item (qw(AR customer currency)) {
208 $form->{"select$item"} =~ s/ selected//;
209 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
213 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
215 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
216 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
219 <input type=hidden name=forex value=$form->{forex}>
221 if ($form->{currency} ne $form->{defaultcurrency}) {
222 if ($form->{forex}) {
224 <th align=right>|.$locale->text('Exchangerate').qq|</th>
225 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
229 <th align=right>|.$locale->text('Exchangerate').qq|</th>
230 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
236 if ($form->{taxaccounts}) {
239 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
240 <th align=left nowrap>|.$locale->text('Tax Included').qq|</th>
246 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
249 $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
254 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
256 $customer = ($form->{selectcustomer}) ? qq|<select name=customer>$form->{selectcustomer}</select>| : qq|<input name=customer value="$form->{customer}" size=35>|;
261 <form method=post action=$form->{script}>
263 <input type=hidden name=id value=$form->{id}>
264 <input type=hidden name=sort value=$form->{sort}>
265 <input type=hidden name=closedto value=$form->{closedto}>
266 <input type=hidden name=locked value=$form->{locked}>
267 <input type=hidden name=title value="$title">
271 <th class=listtop>$form->{title}</th>
281 <th align="right" nowrap>|.$locale->text('Customer').qq|</th>
282 <td colspan=3>$customer</td>
283 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
284 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
285 <input type=hidden name=customer_id value="$form->{customer_id}">
286 <input type=hidden name=terms value=$form->{terms}>
293 <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th>
294 <td>$form->{creditlimit}</td>
295 <th align=left nowrap>|.$locale->text('Remaining').qq|</th>
296 <td class="plus$n">$form->{creditremaining}</td>
297 <input type=hidden name=creditlimit value=$form->{creditlimit}>
298 <input type=hidden name=creditremaining value=$form->{creditremaining}>
305 <th align=right>|.$locale->text('Currency').qq|</th>
306 <td><select name=currency>$form->{selectcurrency}</select></td>
307 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
308 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
309 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
310 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
318 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
319 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
322 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
323 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
326 <th align=right nowrap>|.$locale->text('Invoice Date').qq|</th>
327 <td><input name=transdate size=11 title="($myconfig{'dateformat'})" value=$form->{transdate}></td>
330 <th align=right nowrap>|.$locale->text('Due Date').qq|</th>
331 <td><input name=duedate size=11 title="$myconfig{'dateformat'}" value=$form->{duedate}></td>
343 <input type=hidden name=selectAR_amount value="$form->{selectAR_amount}">
344 <input type=hidden name=rowcount value=$form->{rowcount}>
347 $amount = $locale->text('Amount');
348 $project = $locale->text('Project');
350 for $i (1 .. $form->{rowcount}) {
352 $form->{"selectAR_amount"} =~ s/ selected//;
353 $form->{"selectAR_amount"} =~ s/option>\Q$form->{"AR_amount_$i"}\E/option selected>$form->{"AR_amount_$i"}/;
356 $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
360 <th align=right>$amount</th>
361 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
363 <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
364 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
365 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
366 <td width=50%><select name="AR_amount_$i">$form->{"selectAR_amount"}</select></td>
373 $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax');
375 foreach $item (split / /, $form->{taxaccounts}) {
377 $form->{"tax_$item"} = $form->format_amount(\%myconfig, $form->{"tax_$item"}, 2);
380 <th align=right nowrap>$taxlabel</th>
381 <td><input name="tax_$item" size=10 value=$form->{"tax_$item"}></td>
383 <td><select name="AR_tax_$item">$form->{"selectAR_tax_$item"}</select></td>
385 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
386 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
387 <input type=hidden name="selectAR_tax_$item" value="$form->{"selectAR_tax_$item"}">
392 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
397 <th align=right>|.$locale->text('Total').qq|</th>
398 <th align=left>$form->{invtotal}</th>
400 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
401 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
403 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
406 <td><select name=AR>$form->{selectAR}</select></td>
407 <input type=hidden name=selectAR value="$form->{selectAR}">
411 <th align=right>|.$locale->text('Notes').qq|</th>
412 <td colspan=4>$notes</td>
421 <th class=listheading colspan=5>|.$locale->text('Payments').qq|</th>
426 if ($form->{currency} eq $form->{defaultcurrency}) {
427 @column_index = qw(datepaid source paid AR_paid);
429 @column_index = qw(datepaid source paid exchangerate AR_paid);
432 $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
433 $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
434 $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
435 $column_data{AR_paid} = "<th>".$locale->text('Account')."</th>";
436 $column_data{source} = "<th>".$locale->text('Source')."</th>";
441 map { print "$column_data{$_}\n" } @column_index;
446 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
447 for $i (1 .. $form->{paidaccounts}) {
452 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
453 $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
456 $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
457 $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
459 $exchangerate = qq| |;
460 if ($form->{currency} ne $form->{defaultcurrency}) {
461 if ($form->{"forex_$i"}) {
462 $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
464 $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
469 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
472 $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
473 $column_data{"AR_paid_$i"} = qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
474 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
475 $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|;
476 $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
478 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
486 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
487 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
493 <td><hr size=3 noshade></td>
505 <input name=callback type=hidden value="$form->{callback}">
507 <input type=hidden name=path value=$form->{path}>
508 <input type=hidden name=login value=$form->{login}>
509 <input type=hidden name=password value=$form->{password}>
514 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
515 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
519 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
522 if (!$form->{revtrans}) {
523 if (!$form->{locked}) {
525 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
526 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
531 if ($transdate > $closedto) {
533 <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
538 if ($transdate > $closedto) {
539 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
540 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
561 $form->{invtotal} = 0;
563 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
565 @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
568 for $i (1 .. $form->{rowcount}) {
569 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
570 if ($form->{"amount_$i"}) {
574 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
579 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
580 $form->{rowcount} = $count + 1;
582 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
584 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'buy')));
587 $form->{invdate} = $form->{transdate};
588 &check_name(customer);
595 if ($form->{taxincluded}) {
598 map { $taxrate += $form->{"${_}_rate"} } split / /, $form->{taxaccounts};
600 foreach $item (split / /, $form->{taxaccounts}) {
601 $amount = ($form->{invtotal} * (1 - 1 / (1 + $taxrate)) * $form->{"${item}_rate"} / $taxrate) if $taxrate;
602 $form->{"tax_$item"} = $form->round_amount($amount, 2);
603 $taxdiff += ($amount - $form->{"tax_$item"});
604 if (abs $taxdiff >= 0.005) {
605 $form->{"tax_$item"} += $form->round_amount($taxdiff, 2);
608 $form->{"selectAR_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|;
609 $totaltax += $form->{"tax_$item"};
612 foreach $item (split / /, $form->{taxaccounts}) {
613 $form->{"tax_$item"} = $form->round_amount($form->{invtotal} * $form->{"${item}_rate"}, 2);
614 $form->{"selectAR_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|;
615 $totaltax += $form->{"tax_$item"};
619 $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
621 for $i (1 .. $form->{paidaccounts}) {
622 if ($form->{"paid_$i"}) {
623 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
625 $totalpaid += $form->{"paid_$i"};
627 $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy')));
631 $form->{creditremaining} -= ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - $form->{oldinvtotal});
632 $form->{oldinvtotal} = $form->{invtotal};
633 $form->{oldtotalpaid} = $totalpaid;
642 # check if there is an invoice number, invoice and due date
643 $form->isblank("invnumber", $locale->text('Invoice Number missing!'));
644 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
645 $form->isblank("duedate", $locale->text('Due Date missing!'));
646 $form->isblank("customer", $locale->text('Customer missing!'));
648 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
649 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
651 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
653 $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
655 for $i (1 .. $form->{paidaccounts}) {
656 if ($form->{"paid_$i"}) {
657 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
659 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
661 $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
663 if ($form->{currency} ne $form->{defaultcurrency}) {
664 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
665 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
670 # if oldcustomer ne customer redo form
671 ($customer) = split /--/, $form->{customer};
672 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
677 $form->{id} = 0 if $form->{postasnew};
679 $form->redirect($locale->text('Transaction posted!')) if (AR->post_transaction(\%myconfig, \%$form));
680 $form->error($locale->text('Cannot post transaction!'));
687 $form->{postasnew} = 1;
695 $form->{title} = $locale->text('Confirm!');
702 <form method=post action=$form->{script}>
705 foreach $key (keys %$form) {
706 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
710 <h2 class=confirm>$form->{title}</h2>
712 <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber}</h4>
714 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
727 $form->redirect($locale->text('Transaction deleted!')) if (AR->delete_transaction(\%myconfig, \%$form));
728 $form->error($locale->text('Cannot delete transaction!'));
735 # setup customer selection
736 $form->all_vc(\%myconfig, "customer");
738 if (@{ $form->{all_customer} }) {
739 map { $customer .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{all_customer} };
740 $customer = qq|<select name=customer><option>\n$customer</select>|;
742 $customer = qq|<input name=customer size=35>|;
745 $form->{title} = $locale->text('AR Transactions');
752 <form method=post action=$form->{script}>
755 <tr><th class=listtop>$form->{title}</th></tr>
761 <th align=right>|.$locale->text('Customer').qq|</th>
762 <td colspan=3>$customer</td>
765 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
766 <td colspan=3><input name=invnumber size=20></td>
769 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
770 <td colspan=3><input name=ordnumber size=20></td>
773 <th align=right nowrap>|.$locale->text('Notes').qq|</th>
774 <td colspan=3><input name=notes size=40></td>
777 <th align=right nowrap>|.$locale->text('From').qq|</th>
778 <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
779 <th align=right>|.$locale->text('to').qq|</th>
780 <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
782 <input type=hidden name=sort value=transdate>
790 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
794 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
795 <td nowrap>|.$locale->text('Open').qq|</td>
796 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
797 <td nowrap>|.$locale->text('Closed').qq|</td>
800 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
801 <td nowrap>|.$locale->text('ID').qq|</td>
802 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
803 <td nowrap>|.$locale->text('Invoice Number').qq|</td>
804 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
805 <td nowrap>|.$locale->text('Order Number').qq|</td>
806 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
807 <td nowrap>|.$locale->text('Invoice Date').qq|</td>
810 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
811 <td nowrap>|.$locale->text('Customer').qq|</td>
812 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
813 <td nowrap>|.$locale->text('Amount').qq|</td>
814 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
815 <td nowrap>|.$locale->text('Tax').qq|</td>
816 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
817 <td nowrap>|.$locale->text('Total').qq|</td>
820 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
821 <td nowrap>|.$locale->text('Date Paid').qq|</td>
822 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
823 <td nowrap>|.$locale->text('Paid').qq|</td>
824 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
825 <td nowrap>|.$locale->text('Due Date').qq|</td>
826 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
827 <td nowrap>|.$locale->text('Amount Due').qq|</td>
830 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
831 <td nowrap>|.$locale->text('Notes').qq|</td>
832 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
833 <td nowrap>|.$locale->text('Salesperson').qq|</td>
834 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
835 <td nowrap>|.$locale->text('Ship via').qq|</td>
838 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
839 <td nowrap>|.$locale->text('Subtotal').qq|</td>
848 <td><hr size=3 noshade></td>
852 <input type=hidden name=nextsub value=$form->{nextsub}>
854 <input type=hidden name=path value=$form->{path}>
855 <input type=hidden name=login value=$form->{login}>
856 <input type=hidden name=password value=$form->{password}>
859 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
870 sub ar_transactions {
872 $form->{customer} = $form->unescape($form->{customer});
873 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
875 AR->ar_transactions(\%myconfig, \%$form);
877 $callback = "$form->{script}?action=ar_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
880 if ($form->{customer}) {
881 $callback .= "&customer=".$form->escape($form->{customer});
882 $href .= "&customer=".$form->escape($form->{customer});
883 $option = $locale->text('Customer')." : $form->{customer}";
885 if ($form->{invnumber}) {
886 $callback .= "&invnumber=$form->{invnumber}";
887 $href .= "&invnumber=".$form->escape($form->{invnumber});
888 $option .= "\n<br>" if ($option);
889 $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
891 if ($form->{ordnumber}) {
892 $callback .= "&ordnumber=$form->{ordnumber}";
893 $href .= "&ordnumber=".$form->escape($form->{ordnumber});
894 $option .= "\n<br>" if ($option);
895 $option .= $locale->text('Order Number')." : $form->{ordnumber}";
897 if ($form->{notes}) {
898 $callback .= "¬es=$form->{notes}";
899 $href .= "¬es=".$form->escape($form->{notes});
900 $option .= "\n<br>" if $option;
901 $option .= $locale->text('Notes')." : $form->{notes}";
904 if ($form->{transdatefrom}) {
905 $callback .= "&transdatefrom=$form->{transdatefrom}";
906 $href .= "&transdatefrom=$form->{transdatefrom}";
907 $option .= "\n<br>" if ($option);
908 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
910 if ($form->{transdateto}) {
911 $callback .= "&transdateto=$form->{transdateto}";
912 $href .= "&transdateto=$form->{transdateto}";
913 $option .= "\n<br>" if ($option);
914 $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);
917 $callback .= "&open=$form->{open}";
918 $href .= "&open=$form->{open}";
919 $option .= "\n<br>" if ($option);
920 $option .= $locale->text('Open');
922 if ($form->{closed}) {
923 $callback .= "&closed=$form->{closed}";
924 $href .= "&closed=$form->{closed}";
925 $option .= "\n<br>" if ($option);
926 $option .= $locale->text('Closed');
929 @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint));
931 foreach $item (@columns) {
932 if ($form->{"l_$item"} eq "Y") {
933 push @column_index, $item;
935 # add column to href and callback
936 $callback .= "&l_$item=Y";
937 $href .= "&l_$item=Y";
941 if ($form->{l_subtotal} eq 'Y') {
942 $callback .= "&l_subtotal=Y";
943 $href .= "&l_subtotal=Y";
947 $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
948 $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
949 $column_header{duedate} = "<th><a class=listheading href=$href&sort=duedate>".$locale->text('Due Date')."</a></th>";
950 $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";
951 $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>";
952 $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Customer')."</a></th>";
953 $column_header{netamount} = "<th class=listheading>" . $locale->text('Amount') . "</th>";
954 $column_header{tax} = "<th class=listheading>" . $locale->text('Tax') . "</th>";
955 $column_header{amount} = "<th class=listheading>" . $locale->text('Total') . "</th>";
956 $column_header{paid} = "<th class=listheading>" . $locale->text('Paid') . "</th>";
957 $column_header{datepaid} = "<th><a class=listheading href=$href&sort=datepaid>" . $locale->text('Date Paid') . "</a></th>";
958 $column_header{due} = "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
959 $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
960 $column_header{employee} = "<th class=listheading><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</th>";
962 $column_header{shippingpoint} = "<th class=listheading><a class=listheading href=$href&sort=shippingpoint>" . $locale->text('Ship via') . "</a></th>";
965 $form->{title} = $locale->text('AR Transactions');
974 <th class=listtop>$form->{title}</th>
983 <tr class=listheading>
986 map { print "\n$column_header{$_}" } @column_index;
993 # add sort and escape callback, this one we use for the add sub
994 $form->{callback} = $callback .= "&sort=$form->{sort}";
996 # escape callback for href
997 $callback = $form->escape($callback);
999 if (@{ $form->{AR} }) {
1000 $sameitem = $form->{AR}->[0]->{$form->{sort}};
1003 # sums and tax on reports by Antonio Gallardo
1005 foreach $ar (@{ $form->{AR} }) {
1007 if ($form->{l_subtotal} eq 'Y') {
1008 if ($sameitem ne $ar->{$form->{sort}}) {
1013 $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")."</td>";
1014 $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount}, 2, " ")."</td>";
1015 $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{amount}, 2, " ")."</td>";
1016 $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{paid}, 2, " ")."</td>";
1017 $column_data{due} = "<td align=right>".$form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid}, 2, " ")."</td>";
1019 $subtotalnetamount += $ar->{netamount};
1020 $subtotalamount += $ar->{amount};
1021 $subtotalpaid += $ar->{paid};
1022 $subtotaldue += $ar->{amount} - $ar->{paid};
1024 $totalnetamount += $ar->{netamount};
1025 $totalamount += $ar->{amount};
1026 $totalpaid += $ar->{paid};
1027 $totaldue += ($ar->{amount} - $ar->{paid});
1029 $column_data{transdate} = "<td>$ar->{transdate} </td>";
1030 $column_data{id} = "<td>$ar->{id}</td>";
1031 $column_data{datepaid} = "<td>$ar->{datepaid} </td>";
1032 $column_data{duedate} = "<td>$ar->{duedate} </td>";
1034 $module = ($ar->{invoice}) ? "is.pl" : $form->{script};
1036 $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>";
1037 $column_data{ordnumber} = "<td>$ar->{ordnumber} </td>";
1038 $column_data{name} = "<td>$ar->{name}</td>";
1039 $ar->{notes} =~ s/\r\n/<br>/g;
1040 $column_data{notes} = "<td>$ar->{notes} </td>";
1041 $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>";
1042 $column_data{employee} = "<td>$ar->{employee} </td>";
1046 <tr class=listrow$i>
1049 map { print "\n$column_data{$_}" } @column_index;
1058 if ($form->{l_subtotal} eq 'Y') {
1064 <tr class=listtotal>
1067 map { $column_data{$_} = "<td> </td>" } @column_index;
1069 $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, " ")."</th>";
1070 $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ")."</th>";
1071 $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, " ")."</th>";
1072 $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, " ")."</th>";
1073 $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldue, 2, " ")."</th>";
1075 map { print "\n$column_data{$_}" } @column_index;
1083 <td><hr size=3 noshade></td>
1088 <form method=post action=$form->{script}>
1090 <input name=callback type=hidden value="$form->{callback}">
1092 <input type=hidden name=path value=$form->{path}>
1093 <input type=hidden name=login value=$form->{login}>
1094 <input type=hidden name=password value=$form->{password}>
1096 <input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|">
1097 <input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|">
1110 map { $column_data{$_} = "<td> </td>" } @column_index;
1112 $column_data{tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ")."</th>";
1113 $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, " ")."</th>";
1114 $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>";
1115 $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldue, 2, " ")."</th>";
1117 $subtotalnetamount = 0;
1118 $subtotalamount = 0;
1122 $sameitem = $ar->{$form->{sort}};
1124 print "<tr class=listsubtotal>";
1126 map { print "\n$column_data{$_}" } @column_index;