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 #======================================================================
26 #======================================================================
33 require "$form->{path}/arap.pl";
39 # this is for our long dates
40 # $locale->text('January')
41 # $locale->text('February')
42 # $locale->text('March')
43 # $locale->text('April')
44 # $locale->text('May ')
45 # $locale->text('June')
46 # $locale->text('July')
47 # $locale->text('August')
48 # $locale->text('September')
49 # $locale->text('October')
50 # $locale->text('November')
51 # $locale->text('December')
53 # this is for our short month
54 # $locale->text('Jan')
55 # $locale->text('Feb')
56 # $locale->text('Mar')
57 # $locale->text('Apr')
58 # $locale->text('May')
59 # $locale->text('Jun')
60 # $locale->text('Jul')
61 # $locale->text('Aug')
62 # $locale->text('Sep')
63 # $locale->text('Oct')
64 # $locale->text('Nov')
65 # $locale->text('Dec')
70 $form->{title} = "Add";
72 $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
82 $form->{title} = "Edit";
100 $form->create_links("AP", \%myconfig, "vendor");
102 $taxincluded = $form->{taxincluded};
103 $duedate = $form->{duedate};
105 IR->get_vendor(\%myconfig, \%$form);
107 $form->{duedate} = $duedate;
108 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
110 # build the popup menus
113 @curr = split /:/, $form->{currencies};
115 $form->{defaultcurrency} = $curr[0];
117 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
120 if (@{ $form->{all_vendor} }) {
121 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
122 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_vendor} });
127 $form->{forex} = $form->{exchangerate};
128 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
130 foreach $key (keys %{ $form->{AP_links} }) {
132 foreach $ref (@{ $form->{AP_links}{$key} }) {
133 if ($key eq "AP_tax") {
134 $form->{"selectAP_tax_$ref->{accno}"} = "<option>$ref->{accno}--$ref->{description}\n";
137 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
140 # if there is a value we have an old entry
141 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
143 if ($key eq "AP_paid") {
144 $form->{"AP_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
145 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount};
146 $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
147 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source};
149 $form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
151 $form->{paidaccounts}++;
157 if ($key eq "AP_tax") {
158 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
159 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate * -1, 2);
160 $totaltax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
162 $form->{"${akey}_$i"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2);
163 if ($akey eq 'amount') {
164 $form->{"${akey}_$i"} *= -1;
165 $totalamount += $form->{"${akey}_$i"};
168 $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
169 $form->{"project_id_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
171 $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
177 $form->{taxincluded} = $taxincluded if ($form->{id});
178 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
180 if ($form->{taxincluded} && $totalamount) {
181 # add tax to amounts and invtotal
182 for $i (1 .. $form->{rowcount}) {
183 $taxamount = $totaltax * $form->{"amount_$i"} / $totalamount;
184 $tax = $form->round_amount($taxamount, 2);
185 $diff += ($taxamount - $tax);
186 $form->{"amount_$i"} += $tax;
188 $form->{amount_1} += $form->round_amount($diff, 2);
191 $form->{invtotal} = $totalamount + $totaltax;
192 $form->{rowcount}++ if $form->{id};
194 $form->{AP} = $form->{AP_1};
196 $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
203 $title = $form->{title};
204 $form->{title} = $locale->text("$title Accounts Payables Transaction");
206 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
208 # type=submit $locale->text('Add Accounts Payables Transaction')
209 # type=submit $locale->text('Edit Accounts Payables Transaction')
211 # set option selected
212 foreach $item (qw(AP vendor currency)) {
213 $form->{"select$item"} =~ s/ selected//;
214 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
219 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
222 <input type=hidden name=forex value=$form->{forex}>
224 if ($form->{currency} ne $form->{defaultcurrency}) {
225 if ($form->{forex}) {
227 <th align=right>|.$locale->text('Exchangerate').qq|</th>
228 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
232 <th align=right>|.$locale->text('Exchangerate').qq|</th>
233 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
239 if ($form->{taxaccounts}) {
242 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
243 <th align=left nowrap>|.$locale->text('Tax Included').qq|</th>
249 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
252 $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
257 $vendor = ($form->{selectvendor}) ? qq|<select name=vendor>$form->{selectvendor}</select>| : qq|<input name=vendor value="$form->{vendor}" size=35>|;
262 <form method=post action=$form->{script}>
264 <input type=hidden name=id value=$form->{id}>
265 <input type=hidden name=sort value=$form->{sort}>
266 <input type=hidden name=closedto value=$form->{closedto}>
267 <input type=hidden name=locked value=$form->{locked}>
268 <input type=hidden name=title value="$title">
272 <th class=listtop>$form->{title}</th>
282 <th align=right nowrap>|.$locale->text('Vendor').qq|</th>
283 <td colspan=3>$vendor</td>
284 <input type=hidden name=selectvendor value="$form->{selectvendor}">
285 <input type=hidden name=oldvendor value="$form->{oldvendor}">
286 <input type=hidden name=vendor_id value="$form->{vendor_id}">
287 <input type=hidden name=terms value=$form->{terms}>
292 <th align=right nowrap>|.$locale->text('Currency').qq|</th>
293 <td><select name=currency>$form->{selectcurrency}</select></td>
294 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
295 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
296 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
297 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
305 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
306 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
309 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
310 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
313 <th align=right nowrap>|.$locale->text('Invoice Date').qq|</th>
314 <td><input name=transdate size=11 title="$myconfig{'dateformat'}" value=$form->{transdate}></td>
317 <th align=right nowrap>|.$locale->text('Due Date').qq|</th>
318 <td><input name=duedate size=11 title="$myconfig{'dateformat'}" value=$form->{duedate}></td>
326 <input type=hidden name=selectAP_amount value="$form->{selectAP_amount}">
327 <input type=hidden name=rowcount value=$form->{rowcount}>
333 $amount = $locale->text('Amount');
334 $project = $locale->text('Project');
336 for $i (1 .. $form->{rowcount}) {
338 $form->{"selectAP_amount"} =~ s/ selected//;
339 $form->{"selectAP_amount"} =~ s/option>\Q$form->{"AP_amount_$i"}\E/option selected>$form->{"AP_amount_$i"}/;
342 $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
346 <th align=right nowrap>$amount</th>
347 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
349 <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
350 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
351 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
352 <td width=50%><select name="AP_amount_$i">$form->{selectAP_amount}</select></td>
359 $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax');
361 foreach $item (split / /, $form->{taxaccounts}) {
363 # format and reverse tax
364 $form->{"tax_$item"} = $form->format_amount(\%myconfig, $form->{"tax_$item"}, 2);
368 <th align=right nowrap>${taxlabel}</th>
369 <td><input name="tax_$item" size=10 value=$form->{"tax_$item"}></td>
371 <td><select name=AP_tax_$item>$form->{"selectAP_tax_$item"}</select></td>
373 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
374 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
375 <input type=hidden name="selectAP_tax_$item" value="$form->{"selectAP_tax_$item"}">
379 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
383 <th align=right nowrap>|.$locale->text('Total').qq|</th>
384 <td>$form->{invtotal}</td>
386 <td><select name=AP>$form->{selectAP}</select></td>
387 <input type=hidden name=selectAP value="$form->{selectAP}">
388 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
391 <th align=right nowrap>|.$locale->text('Notes').qq|</th>
392 <td colspan=5>$notes</td>
400 <tr class=listheading>
401 <th class=listheading colspan=5>|.$locale->text('Payments').qq|</th>
406 if ($form->{currency} eq $form->{defaultcurrency}) {
407 @column_index = qw(datepaid source paid AP_paid);
409 @column_index = qw(datepaid source paid exchangerate AP_paid);
412 $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
413 $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
414 $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
415 $column_data{AP_paid} = "<th>".$locale->text('Account')."</th>";
416 $column_data{source} = "<th>".$locale->text('Source')."</th>";
421 map { print "$column_data{$_}\n" } @column_index;
426 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
427 for $i (1 .. $form->{paidaccounts}) {
432 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
433 $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
436 $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
437 $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
439 $exchangerate = qq| |;
440 if ($form->{currency} ne $form->{defaultcurrency}) {
441 if ($form->{"forex_$i"}) {
442 $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
444 $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
449 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
452 $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
453 $column_data{"AP_paid_$i"} = qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
454 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
455 $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value=$form->{"datepaid_$i"}></td>|;
456 $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
458 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
466 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
467 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
473 <td><hr size=3 noshade></td>
485 <input name=callback type=hidden value="$form->{callback}">
487 <input type=hidden name=path value=$form->{path}>
488 <input type=hidden name=login value=$form->{login}>
489 <input type=hidden name=password value=$form->{password}>
494 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
495 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
498 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
501 if (!$form->{revtrans}) {
502 if (!$form->{locked}) {
504 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
505 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
510 if ($transdate > $closedto) {
512 <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
517 if ($transdate > $closedto) {
518 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
519 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
540 $form->{invtotal} = 0;
542 $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
544 @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
546 for $i (1 .. $form->{rowcount}) {
547 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
548 if ($form->{"amount_$i"}) {
551 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
555 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
556 $form->{rowcount} = $count + 1;
558 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
560 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'sell')));
562 $form->{invdate} = $form->{transdate};
570 if ($form->{taxincluded}) {
573 map { $taxrate += $form->{"${_}_rate"} } split / /, $form->{taxaccounts};
575 foreach $item (split / /, $form->{taxaccounts}) {
576 $amount = ($form->{invtotal} * (1 - 1 / (1 + $taxrate)) * $form->{"${item}_rate"} / $taxrate) if $taxrate;
577 $form->{"tax_$item"} = $form->round_amount($amount, 2);
578 $taxdiff += ($amount - $form->{"tax_$item"});
579 if (abs $taxdiff >= 0.005) {
580 $form->{"tax_$item"} += $form->round_amount($taxdiff, 2);
583 $form->{"selectAP_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|;
584 $totaltax += $form->{"tax_$item"};
587 foreach $item (split / /, $form->{taxaccounts}) {
588 $form->{"tax_$item"} = $form->round_amount($form->{invtotal} * $form->{"${item}_rate"}, 2);
589 $form->{"selectAP_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|;
590 $totaltax += $form->{"tax_$item"};
594 $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
596 for $i (1 .. $form->{paidaccounts}) {
597 if ($form->{"paid_$i"}) {
598 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
600 $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell')));
611 # check if there is an invoice number, invoice and due date
612 $form->isblank("invnumber", $locale->text("Invoice Number missing!"));
613 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
614 $form->isblank("duedate", $locale->text("Due Date missing!"));
615 $form->isblank("vendor", $locale->text('Vendor missing!'));
618 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
619 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
621 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
623 $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
625 for $i (1 .. $form->{paidaccounts}) {
626 if ($form->{"paid_$i"}) {
627 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
629 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
631 $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
633 if ($form->{currency} ne $form->{defaultcurrency}) {
634 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
635 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
642 # if old vendor ne vendor redo form
643 ($vendor) = split /--/, $form->{vendor};
644 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
649 $form->{id} = 0 if $form->{postasnew};
651 $form->redirect($locale->text('Transaction posted!')) if (AP->post_transaction(\%myconfig, \%$form));
652 $form->error($locale->text('Cannot post transaction!'));
659 $form->{postasnew} = 1;
667 $form->{title} = $locale->text('Confirm!');
674 <form method=post action=$form->{script}>
677 foreach $key (keys %$form) {
678 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
682 <h2 class=confirm>$form->{title}</h2>
684 <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber}</h4>
686 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
699 $form->redirect($locale->text('Transaction deleted!')) if (AP->delete_transaction(\%myconfig, \%$form));
700 $form->error($locale->text('Cannot delete transaction!'));
707 # setup vendor selection
708 $form->all_vc(\%myconfig, "vendor");
710 if (@{ $form->{all_vendor} }) {
711 map { $vendor .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{all_vendor} };
712 $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
714 $vendor = qq|<input name=vendor size=35>|;
717 $form->{title} = $locale->text('AP Transactions');
724 <form method=post action=$form->{script}>
728 <th class=listtop>$form->{title}</th>
735 <th align=right>|.$locale->text('Vendor').qq|</th>
736 <td colspan=3>$vendor</td>
739 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
740 <td colspan=3><input name=invnumber size=20></td>
743 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
744 <td colspan=3><input name=ordnumber size=20></td>
747 <th align=right nowrap>|.$locale->text('Notes').qq|</th>
748 <td colspan=3><input name=notes size=40></td>
751 <th align=right nowrap>|.$locale->text('From').qq|</th>
752 <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
753 <th align=right>|.$locale->text('to').qq|</th>
754 <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
756 <input type=hidden name=sort value=transdate>
764 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
768 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
769 <td nowrap>|.$locale->text('Open').qq|</td>
770 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
771 <td nowrap>|.$locale->text('Closed').qq|</td>
774 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
775 <td nowrap>|.$locale->text('ID').qq|</td>
776 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
777 <td nowrap>|.$locale->text('Invoice Number').qq|</td>
778 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
779 <td nowrap>|.$locale->text('Order Number').qq|</td>
782 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
783 <td nowrap>|.$locale->text('Vendor').qq|</td>
784 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
785 <td nowrap>|.$locale->text('Invoice Date').qq|</td>
786 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
787 <td nowrap>|.$locale->text('Amount').qq|</td>
790 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
791 <td nowrap>|.$locale->text('Tax').qq|</td>
792 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
793 <td nowrap>|.$locale->text('Total').qq|</td>
794 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
795 <td nowrap>|.$locale->text('Date Paid').qq|</td>
798 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
799 <td nowrap>|.$locale->text('Paid').qq|</td>
800 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
801 <td nowrap>|.$locale->text('Due Date').qq|</td>
802 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
803 <td nowrap>|.$locale->text('Amount Due').qq|</td>
806 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
807 <td nowrap>|.$locale->text('Notes').qq|</td>
808 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
809 <td nowrap>|.$locale->text('Employee').qq|</td>
812 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
813 <td nowrap>|.$locale->text('Subtotal').qq|</td>
822 <td><hr size=3 noshade></td>
827 <input type=hidden name=nextsub value=$form->{nextsub}>
828 <input type=hidden name=path value=$form->{path}>
829 <input type=hidden name=login value=$form->{login}>
830 <input type=hidden name=password value=$form->{password}>
832 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
842 sub ap_transactions {
844 $form->{vendor} = $form->unescape($form->{vendor});
845 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
847 AP->ap_transactions(\%myconfig, \%$form);
849 $callback = "$form->{script}?action=ap_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
853 if ($form->{vendor}) {
854 $callback .= "&vendor=".$form->escape($form->{vendor});
855 $href .= "&vendor=".$form->escape($form->{vendor});
856 $option .= $locale->text('Vendor')." : $form->{vendor}";
858 if ($form->{invnumber}) {
859 $callback .= "&invnumber=$form->{invnumber}";
860 $href .= "&invnumber=".$form->escape($form->{invnumber});
861 $option .= "\n<br>" if ($option);
862 $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
864 if ($form->{ordnumber}) {
865 $callback .= "&ordnumber=$form->{ordnumber}";
866 $href .= "&ordnumber=".$form->escape($form->{ordnumber});
867 $option .= "\n<br>" if ($option);
868 $option .= $locale->text('Order Number')." : $form->{ordnumber}";
870 if ($form->{notes}) {
871 $callback .= "¬es=$form->{notes}";
872 $href .= "¬es=".$form->escape($form->{notes});
873 $option .= "\n<br>" if $option;
874 $option .= $locale->text('Notes')." : $form->{notes}";
877 if ($form->{transdatefrom}) {
878 $callback .= "&transdatefrom=$form->{transdatefrom}";
879 $href .= "&transdatefrom=$form->{transdatefrom}";
880 $option .= "\n<br>" if ($option);
881 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
883 if ($form->{transdateto}) {
884 $callback .= "&transdateto=$form->{transdateto}";
885 $href .= "&transdateto=$form->{transdateto}";
886 $option .= "\n<br>" if ($option);
887 $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);
890 $callback .= "&open=$form->{open}";
891 $href .= "&open=$form->{open}";
892 $option .= "\n<br>" if ($option);
893 $option .= $locale->text('Open');
895 if ($form->{closed}) {
896 $callback .= "&closed=$form->{closed}";
897 $href .= "&closed=$form->{closed}";
898 $option .= "\n<br>" if ($option);
899 $option .= $locale->text('Closed');
902 @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee));
904 foreach $item (@columns) {
905 if ($form->{"l_$item"} eq "Y") {
906 push @column_index, $item;
908 # add column to href and callback
909 $callback .= "&l_$item=Y";
910 $href .= "&l_$item=Y";
914 if ($form->{l_subtotal} eq 'Y') {
915 $callback .= "&l_subtotal=Y";
916 $href .= "&l_subtotal=Y";
920 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</a></th>|;
921 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;
922 $column_header{duedate} = qq|<th><a class=listheading href=$href&sort=duedate>|.$locale->text('Due Date').qq|</a></th>|;
923 $column_header{due} = qq|<th class=listheading>|.$locale->text('Amount Due').qq|</th>|;
924 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</a></th>|;
925 $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|;
926 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Vendor').qq|</a></th>|;
927 $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
928 $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
929 $column_header{amount} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
930 $column_header{paid} = qq|<th class=listheading>|.$locale->text('Paid').qq|</th>|;
931 $column_header{datepaid} = qq|<th><a class=listheading href=$href&sort=datepaid>|.$locale->text('Date Paid').qq|</a></th>|;
932 $column_header{notes} = qq|<th><a class=listheading>|.$locale->text('Notes').qq|</th>|;
933 $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Employee')."</th>";
936 $form->{title} = $locale->text('AP Transactions');
945 <th class=listtop>$form->{title}</th>
954 <tr class=listheading>
957 map { print "\n$column_header{$_}" } @column_index;
963 # add sort and escape callback
964 $form->{callback} = "$callback&sort=$form->{sort}";
965 $callback = $form->escape($form->{callback});
967 if (@{ $form->{AP} }) {
968 $sameitem = $form->{AP}->[0]->{$form->{sort}};
971 # sums and tax on reports by Antonio Gallardo
973 foreach $ap (@{ $form->{AP} }) {
975 if ($form->{l_subtotal} eq 'Y') {
976 if ($sameitem ne $ap->{$form->{sort}}) {
978 $sameitem = $ap->{$form->{sort}};
982 $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")."</td>";
983 $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount}, 2, " ") . "</td>";
984 $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>";
985 $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{paid}, 2, " ")."</td>";
986 $column_data{due} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid}, 2, " ")."</td>";
988 $totalnetamount += $ap->{netamount};
989 $totalamount += $ap->{amount};
990 $totalpaid += $ap->{paid};
991 $totaldue += ($ap->{amount} - $ap->{paid});
993 $subtotalnetamount += $ap->{netamount};
994 $subtotalamount += $ap->{amount};
995 $subtotalpaid += $ap->{paid};
996 $subtotaldue += ($ap->{amount} - $ap->{paid});
998 $column_data{transdate} = "<td>$ap->{transdate} </td>";
999 $column_data{duedate} = "<td>$ap->{duedate} </td>";
1000 $column_data{datepaid} = "<td>$ap->{datepaid} </td>";
1002 $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
1004 $column_data{invnumber} = qq|<td><a href="$module?action=edit&path=$form->{path}&id=$ap->{id}&login=$form->{login}&password=$form->{password}&callback=$callback">$ap->{invnumber}</a></td>|;
1005 $column_data{id} = "<td>$ap->{id}</td>";
1006 $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>";
1007 $column_data{name} = "<td>$ap->{name}</td>";
1008 $ap->{notes} =~ s/\r\n/<br>/g;
1009 $column_data{notes} = "<td>$ap->{notes} </td>";
1010 $column_data{employee} = "<td>$ap->{employee} </td>";
1015 <tr class=listrow$i >
1018 map { print "\n$column_data{$_}" } @column_index;
1026 if ($form->{l_subtotal} eq 'Y') {
1032 <tr class=listtotal>
1035 map { $column_data{$_} = "<td> </td>" } @column_index;
1037 $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, " ")."</th>";
1038 $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ")."</th>";
1039 $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, " ")."</th>";
1040 $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, " ")."</th>";
1041 $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldue, 2, " ")."</th>";
1043 map { print "$column_data{$_}\n" } @column_index;
1051 <td><hr size=3 noshade></td>
1056 <form method=post action=$form->{script}>
1058 <input name=callback type=hidden value="$form->{callback}">
1060 <input type=hidden name=path value=$form->{path}>
1061 <input type=hidden name=login value=$form->{login}>
1062 <input type=hidden name=password value=$form->{password}>
1064 <input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|">
1066 <input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|">
1079 map { $column_data{$_} = "<td> </td>" } @column_index;
1081 $column_data{netamount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")."</th>";
1082 $column_data{tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ")."</th>";
1083 $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, " ")."</th>";
1084 $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>";
1085 $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldue, 2, " ")."</th>";
1087 $subtotalnetamount = 0;
1088 $subtotalamount = 0;
1092 print "<tr class=listsubtotal>";
1094 map { print "\n$column_data{$_}" } @column_index;