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 #======================================================================
32 #======================================================================
38 require "$form->{path}/arap.pl";
44 # this is for our long dates
45 # $locale->text('January')
46 # $locale->text('February')
47 # $locale->text('March')
48 # $locale->text('April')
49 # $locale->text('May ')
50 # $locale->text('June')
51 # $locale->text('July')
52 # $locale->text('August')
53 # $locale->text('September')
54 # $locale->text('October')
55 # $locale->text('November')
56 # $locale->text('December')
58 # this is for our short month
59 # $locale->text('Jan')
60 # $locale->text('Feb')
61 # $locale->text('Mar')
62 # $locale->text('Apr')
63 # $locale->text('May')
64 # $locale->text('Jun')
65 # $locale->text('Jul')
66 # $locale->text('Aug')
67 # $locale->text('Sep')
68 # $locale->text('Oct')
69 # $locale->text('Nov')
70 # $locale->text('Dec')
73 $lxdebug->enter_sub();
75 $form->{title} = "Add";
78 "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}"
79 unless $form->{callback};
84 $lxdebug->leave_sub();
88 $lxdebug->enter_sub();
90 $form->{title} = "Edit";
95 $lxdebug->leave_sub();
99 $lxdebug->enter_sub();
104 $lxdebug->leave_sub();
108 $lxdebug->enter_sub();
110 $form->create_links("AP", \%myconfig, "vendor");
111 $taxincluded = $form->{taxincluded};
112 $duedate = $form->{duedate};
114 IR->get_vendor(\%myconfig, \%$form);
116 $form->{duedate} = $duedate if $duedate;
117 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
119 # build the popup menus
120 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
124 qq|<option value=\"$_->{taxkey}--$_->{rate}\">$_->{taxdescription} |
125 . ($_->{rate} * 100) . qq| %|
127 $form->{taxchart} = $tax;
128 $form->{selecttaxchart} = $tax;
131 @curr = split /:/, $form->{currencies};
133 $form->{defaultcurrency} = $curr[0];
135 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
138 if (@{ $form->{all_vendor} }) {
139 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
140 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
141 (@{ $form->{all_vendor} });
145 if (@{ $form->{all_departments} }) {
146 $form->{selectdepartment} = "<option>\n";
147 $form->{department} = "$form->{department}--$form->{department_id}";
150 $form->{selectdepartment} .=
151 "<option>$_->{description}--$_->{id}\n"
152 } (@{ $form->{all_departments} });
155 $form->{employee} = "$form->{employee}--$form->{employee_id}";
158 $form->{forex} = $form->{exchangerate};
159 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
161 foreach $key (keys %{ $form->{AP_links} }) {
162 foreach $ref (@{ $form->{AP_links}{$key} }) {
163 if ($key eq "AP_paid") {
164 $form->{"select$key"} .=
165 "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
167 $form->{"select$key"} .=
168 "<option value=\"$ref->{accno}--$ref->{taxkey}\">$ref->{accno}--$ref->{description}</option>\n";
172 $form->{$key} = $form->{"select$key"};
174 # if there is a value we have an old entry
176 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
178 if ($key eq "AP_paid") {
180 $form->{"AP_paid_$j"} =
181 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
182 $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
183 $form->{"datepaid_$j"} =
184 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
185 $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
186 $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
188 $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
189 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
190 $form->{"AP_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
191 $form->{paidaccounts}++;
197 if ($key eq "AP_tax") {
198 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
199 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
200 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
202 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate * -1,
204 if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
206 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
208 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
211 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
213 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
217 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
220 $form->{"${akey}_$i"} =
222 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
224 if ($akey eq 'amount') {
225 $form->{"${akey}_$i"} *= -1;
226 $totalamount += $form->{"${akey}_$i"};
227 $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
229 $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} =
230 "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
231 $form->{"project_id_$i"} =
232 "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
234 $form->{"${key}_$i"} =
235 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
236 $form->{"select${key}"} =~
237 /(<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)/;
239 $form->{"select${key}"} = $1;
240 if ($akey eq 'amount') {
241 $form->{selecttaxchart} =~
242 /(<option value=\"$form->{acc_trans}{$key}->[$i-1]->{taxkey}--[^<]*)/;
243 $form->{selecttaxchart} = $1;
250 $form->{taxincluded} = $taxincluded if ($form->{id});
251 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
253 if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
255 # add tax to amounts and invtotal
258 ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
259 $tax = $form->round_amount($taxamount, 2);
260 $diff += ($taxamount - $tax);
261 $form->{"amount_$i"} += $tax;
263 $form->{amount_1} += $form->round_amount($diff, 2);
266 # check if calculated is equal to stored
267 if ($form->{taxincluded} && $form->{taxrate} && $witholdingrate) {
268 if ($form->{"taxrate"} > 0) {
271 ($form->{amount_1} - ($form->{amount_1} / ($form->{taxrate} + 1))),
276 ($totalamount + $totaltax + $totalwithholding) * $withholdingrate /
277 (1 - $withholdingrate),
279 ) * $form->{"taxrate"} / $withholdingrate;
282 $taxamount = $totalamount * $form->{"taxrate"};
284 $taxamount = $form->round_amount($taxamount, 2);
285 $form->{tax} = $taxamount;
287 $form->{tax} = $formtax;
289 $form->{invtotal} = $totalamount + $totaltax + $totalwithholding;
290 $form->{rowcount}++ if $form->{id};
293 ($form->datetonum($form->{transdate}, \%myconfig) <=
294 $form->datetonum($form->{closedto}, \%myconfig));
296 $lxdebug->leave_sub();
300 $lxdebug->enter_sub();
302 $title = $form->{title};
303 $form->{title} = $locale->text("$title Accounts Payables Transaction");
305 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
307 # type=submit $locale->text('Add Accounts Payables Transaction')
308 # type=submit $locale->text('Edit Accounts Payables Transaction')
310 # set option selected
311 foreach $item (qw(vendor currency department)) {
312 $form->{"select$item"} =~ s/ selected//;
313 $form->{"select$item"} =~
314 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
316 $readonly = ($form->{id}) ? "readonly" : "";
319 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
320 $readonly = ($form->{radier}) ? "" : $readonly;
322 map { $form->{$_} =~ s/\"/"/g } qw(AP_amount AP taxchart);
325 $form->{exchangerate} =
326 $form->format_amount(\%myconfig, $form->{exchangerate});
328 $form->{creditlimit} =
329 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
330 $form->{creditremaining} =
331 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
334 <input type=hidden name=forex value=$form->{forex}>
336 if ($form->{currency} ne $form->{defaultcurrency}) {
337 if ($form->{forex}) {
340 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
341 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
346 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
347 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
356 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
357 <th align=left nowrap>|
358 . $locale->text('Tax Included')
363 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
367 qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
371 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
372 <td colspan=3><select name=department>$form->{selectdepartment}</select>
373 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
376 | if $form->{selectdepartment};
378 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
381 ($form->{selectvendor})
382 ? qq|<select name=vendor>$form->{selectvendor}</select>|
383 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
385 # use JavaScript Calendar or not
386 $form->{jsscript} = $jscalendar;
388 if ($form->{jsscript}) {
390 # with JavaScript Calendar
392 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}> $readonly</td>
393 <td><input type=button name=transdate id="trigger1" value=|
394 . $locale->text('button')
398 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}> $readonly</td>
399 <td><input type=button name=duedate id="trigger2" value=|
400 . $locale->text('button')
406 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
407 "duedate", "BL", "trigger2");
410 # without JavaScript Calendar
412 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}> $readonly</td>|;
414 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}> $readonly</td>|;
422 <form method=post action=$form->{script}>
424 <input type=hidden name=id value=$form->{id}>
425 <input type=hidden name=sort value=$form->{sort}>
426 <input type=hidden name=closedto value=$form->{closedto}>
427 <input type=hidden name=locked value=$form->{locked}>
428 <input type=hidden name=title value="$title">
432 <th class=listtop>$form->{title}</th>
442 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
443 <td colspan=3>$vendor</td>
444 <input type=hidden name=selectvendor value="$form->{selectvendor}">
445 <input type=hidden name=oldvendor value="$form->{oldvendor}">
446 <input type=hidden name=vendor_id value="$form->{vendor_id}">
447 <input type=hidden name=terms value=$form->{terms}>
454 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
455 <td>$form->{creditlimit}</td>
456 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
457 <td class="plus$n">$form->{creditremaining}</td>
458 <input type=hidden name=creditlimit value=$form->{creditlimit}>
459 <input type=hidden name=creditremaining value=$form->{creditremaining}>
464 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
465 <td><select name=currency>$form->{selectcurrency}</select></td>
466 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
467 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
468 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
469 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
479 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
480 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
483 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
484 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
487 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
491 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
500 <input type=hidden name=AP_amount value="$form->{AP_amount}">
501 <input type=hidden name=taxchart value="$form->{taxchart}">
502 <input type=hidden name=rowcount value=$form->{rowcount}>
510 $amount = $locale->text('Amount');
511 $project = $locale->text('Project');
515 # $form->{"selectAP_amount"} =~ s/ selected//;
516 # $form->{"selectAP_amount"} =~ s/option>\Q$form->{"AP_amount_$i"}\E/option selected>$form->{"AP_amount_$i"}/;
519 $form->{"amount_$i"} =
520 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
524 <th align=right nowrap>$amount</th>
525 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"} $readonly></td>
527 <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
528 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
529 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
530 <td width=50%><select name="AP_amountselected">$form->{selectAP_amount}</select></td>
538 ($form->{taxincluded})
539 ? $locale->text('Tax Included')
540 : $locale->text('Tax');
542 # format and reverse tax
543 $form->{"tax"} = $form->format_amount(\%myconfig, $form->{"tax"}, 2);
547 <th align=right nowrap>${taxlabel}</th>
548 <td><input name="tax" size=10 value=$form->{"tax"} $readonly></td>
549 <td align=right><input name=taxcheck class=checkbox type=checkbox value=1></td>
550 <td align=left nowrap>| . $locale->text('Correct Tax') . qq|</td>
551 <td><select name=taxchartselected>$form->{"selecttaxchart"}</select></td>
555 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
559 <th align=right nowrap>| . $locale->text('Total') . qq|</th>
560 <td>$form->{invtotal}</td>
562 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
563 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
565 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
568 <td><select name=APselected>$form->{selectAP}</select></td>
569 <input type=hidden name=AP value="$form->{AP}">
573 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
574 <td colspan=5>$notes</td>
582 <tr class=listheading>
583 <th class=listheading colspan=6>| . $locale->text('Payments') . qq|</th>
587 if ($form->{currency} eq $form->{defaultcurrency}) {
588 @column_index = qw(datepaid source memo paid AP_paid);
590 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
593 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
594 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
595 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
596 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
597 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
598 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
603 map { print "$column_data{$_}\n" } @column_index;
608 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
609 for $i (1 .. $form->{paidaccounts}) {
614 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
615 $form->{"selectAP_paid_$i"} =~
616 s/option value=\"$form->{"AP_paid_$i"}\">/option value=\"$form->{"AP_paid_$i"}\" selected>/;
620 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
621 $form->{"exchangerate_$i"} =
622 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
624 $exchangerate = qq| |;
625 if ($form->{currency} ne $form->{defaultcurrency}) {
626 if ($form->{"forex_$i"}) {
628 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
631 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
636 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
639 $column_data{"paid_$i"} =
640 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
641 $column_data{"AP_paid_$i"} =
642 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
643 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
644 $column_data{"datepaid_$i"} =
645 qq|<td align=center><input name="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value=$form->{"datepaid_$i"}></td>|;
646 $column_data{"source_$i"} =
647 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
648 $column_data{"memo_$i"} =
649 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
651 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
657 map { $form->{$_} =~ s/\"/"/g } qw(selectAP_paid);
659 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
660 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
666 <td><hr size=3 noshade></td>
671 $lxdebug->leave_sub();
675 $lxdebug->enter_sub();
679 <input name=callback type=hidden value="$form->{callback}">
681 <input type=hidden name=path value=$form->{path}>
682 <input type=hidden name=login value=$form->{login}>
683 <input type=hidden name=password value=$form->{password}>
688 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
689 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
691 if ($form->{id} && $form->{radier}) {
693 # print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
696 if (!$form->{revtrans}) {
697 if (!$form->{locked}) {
699 <input class=submit type=submit name=action value="|
700 . $locale->text('Post') . qq|">
701 <input class=submit type=submit name=action value="|
702 . $locale->text('Delete') . qq|">
707 if ($transdate > $closedto) {
709 <input class=submit type=submit name=action value="|
710 . $locale->text('Post as new') . qq|">
715 if (($transdate > $closedto) && !$form->{id}) {
716 print qq|<input class=submit type=submit name=action value="|
717 . $locale->text('Update') . qq|">
718 <input class=submit type=submit name=action value="|
719 . $locale->text('Post') . qq|">|;
723 if ($form->{menubar}) {
724 require "$form->{path}/menu.pl";
735 $lxdebug->leave_sub();
739 $lxdebug->enter_sub();
747 $form->{invtotal} = 0;
749 $form->{selectAP_amount} = $form->{AP_amount};
750 $form->{selectAP_amount} =~
751 s/value=\"$form->{AP_amountselected}\"/value=\"$form->{AP_amountselected}\" selected/;
753 $form->{selectAP} = $form->{AP};
755 s/value=\"$form->{APselected}\"/value=\"$form->{APselected}\" selected/;
757 ($AP_amountaccno, $AP_amounttaxkey) =
758 split(/--/, $form->{AP_amountselected});
759 $form->{selecttaxchart} = $form->{taxchart};
760 $form->{selecttaxchart} =~
761 s/value=\"$AP_amounttaxkey--([^\"]*)\"/value=\"$AP_amounttaxkey--$1\" selected/;
765 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
766 qw(exchangerate creditlimit creditremaining);
768 @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
771 $form->{"amount_$i"} =
772 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
773 if ($form->{"amount_$i"}) {
776 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
780 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
782 $form->{invtotal} += $form->{"amount_1"};
784 $form->{exchangerate} = $exchangerate
788 $form->check_exchangerate(
789 \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
792 $form->{invdate} = $form->{transdate};
793 $save_AP = $form->{AP};
795 $form->{AP} = $save_AP;
803 @taxaccounts = split / /, $form->{taxaccounts};
805 $form->{"tax"} = $form->parse_amount(\%myconfig, $form->{"tax"});
807 if ($form->{taxincluded} && $form->{"rate"}) {
808 $taxrate = $form->{"rate"};
809 $withholdingrate = 0;
813 ($form->{invtotal} - ($form->{invtotal} / ($taxrate + 1))),
815 $form->{"tax"} = $form->round_amount($amount, 2);
816 $taxdiff += ($amount - $form->{"tax"});
818 if (abs $taxdiff >= 0.005) {
819 $form->{"tax"} += $form->round_amount($taxdiff, 2);
822 $totaltax += $form->{"tax"};
826 $form->round_amount($form->{invtotal} * $form->{"rate"}, 2);
827 $totaltax += $form->{"tax"};
832 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
834 for $i (1 .. $form->{paidaccounts}) {
835 if ($form->{"paid_$i"}) {
838 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
839 } qw(paid exchangerate);
841 $totalpaid += $form->{"paid_$i"};
843 $form->{"exchangerate_$i"} = $exchangerate
845 $form->{"forex_$i"} = (
847 $form->check_exchangerate(
848 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
853 $form->{creditremaining} -=
854 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
855 $form->{oldinvtotal});
856 $form->{oldinvtotal} = $form->{invtotal};
857 $form->{oldtotalpaid} = $totalpaid;
861 $lxdebug->leave_sub();
865 $lxdebug->enter_sub();
867 # check if there is a vendor, invoice and due date
868 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
869 $form->isblank("duedate", $locale->text("Due Date missing!"));
870 $form->isblank("vendor", $locale->text('Vendor missing!'));
872 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
873 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
875 $form->error($locale->text('Cannot post transaction for a closed period!'))
876 if ($transdate <= $closedto);
878 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
879 if ($form->{currency} ne $form->{defaultcurrency});
882 for $i (1 .. $form->{paidaccounts}) {
883 if ($form->{"paid_$i"}) {
884 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
886 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
888 $form->error($locale->text('Cannot post payment for a closed period!'))
889 if ($datepaid <= $closedto);
891 if ($form->{currency} ne $form->{defaultcurrency}) {
892 $form->{"exchangerate_$i"} = $form->{exchangerate}
893 if ($transdate == $datepaid);
894 $form->isblank("exchangerate_$i",
895 $locale->text('Exchangerate for payment missing!'));
901 # if old vendor ne vendor redo form
902 ($vendor) = split /--/, $form->{vendor};
903 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
907 ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
908 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
909 ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
910 $form->{AP}{amount_1} = $debitaccno;
911 $form->{AP}{payables} = $payablesaccno;
912 $form->{taxkey} = $taxkey;
914 $form->{id} = 0 if $form->{postasnew};
916 $form->redirect($locale->text('Transaction posted!'))
917 if (AP->post_transaction(\%myconfig, \%$form));
918 $form->error($locale->text('Cannot post transaction!'));
920 $lxdebug->leave_sub();
924 $lxdebug->enter_sub();
926 $form->{postasnew} = 1;
929 $lxdebug->leave_sub();
933 $lxdebug->enter_sub();
935 $form->{title} = $locale->text('Confirm!');
939 delete $form->{header};
944 <form method=post action=$form->{script}>
947 foreach $key (keys %$form) {
948 $form->{$key} =~ s/\"/"/g;
949 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
953 <h2 class=confirm>$form->{title}</h2>
956 . $locale->text('Are you sure you want to delete Transaction')
957 . qq| $form->{invnumber}</h4>
959 <input name=action class=submit type=submit value="|
960 . $locale->text('Yes') . qq|">
967 $lxdebug->leave_sub();
971 $lxdebug->enter_sub();
973 $form->redirect($locale->text('Transaction deleted!'))
974 if (AP->delete_transaction(\%myconfig, \%$form, $spool));
975 $form->error($locale->text('Cannot delete transaction!'));
977 $lxdebug->leave_sub();
981 $lxdebug->enter_sub();
983 # setup vendor selection
984 $form->all_vc(\%myconfig, "vendor", "AP");
986 if (@{ $form->{all_vendor} }) {
987 map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
988 @{ $form->{all_vendor} };
989 $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
991 $vendor = qq|<input name=vendor size=35>|;
995 if (@{ $form->{all_departments} }) {
996 $form->{selectdepartment} = "<option>\n";
999 $form->{selectdepartment} .=
1000 "<option>$_->{description}--$_->{id}\n"
1001 } (@{ $form->{all_departments} });
1006 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1007 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1009 | if $form->{selectdepartment};
1011 $form->{title} = $locale->text('AP Transactions');
1013 # use JavaScript Calendar or not
1014 $form->{jsscript} = $jscalendar;
1016 if ($form->{jsscript}) {
1018 # with JavaScript Calendar
1020 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1021 <input type=button name=transdatefrom id="trigger1" value=|
1022 . $locale->text('button')
1026 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1027 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1028 . $locale->text('button')
1034 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1035 "transdateto", "BL", "trigger2");
1038 # without JavaScript Calendar
1040 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1042 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1050 <form method=post action=$form->{script}>
1054 <th class=listtop>$form->{title}</th>
1056 <tr height="5"></tr>
1061 <th align=right>| . $locale->text('Vendor') . qq|</th>
1062 <td colspan=3>$vendor</td>
1066 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1067 <td colspan=3><input name=invnumber size=20></td>
1070 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1071 <td colspan=3><input name=ordnumber size=20></td>
1074 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1075 <td colspan=3><input name=notes size=40></td>
1078 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1080 <th align=right>| . $locale->text('Bis') . qq|</th>
1083 <input type=hidden name=sort value=transdate>
1091 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1095 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1096 <td nowrap>| . $locale->text('Open') . qq|</td>
1097 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1098 <td nowrap>| . $locale->text('Closed') . qq|</td>
1101 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1102 <td nowrap>| . $locale->text('ID') . qq|</td>
1103 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1104 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1105 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1106 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1109 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1110 <td nowrap>| . $locale->text('Vendor') . qq|</td>
1111 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1112 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1113 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1114 <td nowrap>| . $locale->text('Amount') . qq|</td>
1117 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1118 <td nowrap>| . $locale->text('Tax') . qq|</td>
1119 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1120 <td nowrap>| . $locale->text('Total') . qq|</td>
1121 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1122 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1125 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1126 <td nowrap>| . $locale->text('Paid') . qq|</td>
1127 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1128 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1129 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1130 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1133 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1134 <td nowrap>| . $locale->text('Notes') . qq|</td>
1135 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1136 <td nowrap>| . $locale->text('Employee') . qq|</td>
1139 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1140 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1149 <td><hr size=3 noshade></td>
1156 <input type=hidden name=nextsub value=$form->{nextsub}>
1157 <input type=hidden name=path value=$form->{path}>
1158 <input type=hidden name=login value=$form->{login}>
1159 <input type=hidden name=password value=$form->{password}>
1161 <input class=submit type=submit name=action value="|
1162 . $locale->text('Continue') . qq|">
1169 $lxdebug->leave_sub();
1172 sub ap_transactions {
1173 $lxdebug->enter_sub();
1175 $form->{vendor} = $form->unescape($form->{vendor});
1176 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
1178 AP->ap_transactions(\%myconfig, \%$form);
1181 "$form->{script}?action=ap_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1184 if ($form->{vendor}) {
1185 $callback .= "&vendor=" . $form->escape($form->{vendor}, 1);
1186 $href .= "&vendor=" . $form->escape($form->{vendor});
1187 $option .= $locale->text('Vendor') . " : $form->{vendor}";
1189 if ($form->{department}) {
1190 $callback .= "&department=" . $form->escape($form->{department}, 1);
1191 $href .= "&department=" . $form->escape($form->{department});
1192 ($department) = split /--/, $form->{department};
1193 $option .= "\n<br>" if ($option);
1194 $option .= $locale->text('Department') . " : $department";
1196 if ($form->{invnumber}) {
1197 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1198 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1199 $option .= "\n<br>" if ($option);
1200 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1202 if ($form->{ordnumber}) {
1203 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1204 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1205 $option .= "\n<br>" if ($option);
1206 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1208 if ($form->{notes}) {
1209 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1210 $href .= "¬es=" . $form->escape($form->{notes});
1211 $option .= "\n<br>" if $option;
1212 $option .= $locale->text('Notes') . " : $form->{notes}";
1215 if ($form->{transdatefrom}) {
1216 $callback .= "&transdatefrom=$form->{transdatefrom}";
1217 $href .= "&transdatefrom=$form->{transdatefrom}";
1218 $option .= "\n<br>" if ($option);
1220 $locale->text('From') . " "
1221 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1223 if ($form->{transdateto}) {
1224 $callback .= "&transdateto=$form->{transdateto}";
1225 $href .= "&transdateto=$form->{transdateto}";
1226 $option .= "\n<br>" if ($option);
1228 $locale->text('Bis') . " "
1229 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1231 if ($form->{open}) {
1232 $callback .= "&open=$form->{open}";
1233 $href .= "&open=$form->{open}";
1234 $option .= "\n<br>" if ($option);
1235 $option .= $locale->text('Open');
1237 if ($form->{closed}) {
1238 $callback .= "&closed=$form->{closed}";
1239 $href .= "&closed=$form->{closed}";
1240 $option .= "\n<br>" if ($option);
1241 $option .= $locale->text('Closed');
1245 $form->sort_columns(
1246 qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee)
1249 foreach $item (@columns) {
1250 if ($form->{"l_$item"} eq "Y") {
1251 push @column_index, $item;
1253 # add column to href and callback
1254 $callback .= "&l_$item=Y";
1255 $href .= "&l_$item=Y";
1259 if ($form->{l_subtotal} eq 'Y') {
1260 $callback .= "&l_subtotal=Y";
1261 $href .= "&l_subtotal=Y";
1264 $column_header{id} =
1265 qq|<th><a class=listheading href=$href&sort=id>|
1266 . $locale->text('ID')
1268 $column_header{transdate} =
1269 qq|<th><a class=listheading href=$href&sort=transdate>|
1270 . $locale->text('Date')
1272 $column_header{duedate} =
1273 qq|<th><a class=listheading href=$href&sort=duedate>|
1274 . $locale->text('Due Date')
1276 $column_header{due} =
1277 qq|<th class=listheading>| . $locale->text('Amount Due') . qq|</th>|;
1278 $column_header{invnumber} =
1279 qq|<th><a class=listheading href=$href&sort=invnumber>|
1280 . $locale->text('Invoice')
1282 $column_header{ordnumber} =
1283 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1284 . $locale->text('Order')
1286 $column_header{name} =
1287 qq|<th><a class=listheading href=$href&sort=name>|
1288 . $locale->text('Vendor')
1290 $column_header{netamount} =
1291 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1292 $column_header{tax} =
1293 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1294 $column_header{amount} =
1295 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1296 $column_header{paid} =
1297 qq|<th class=listheading>| . $locale->text('Paid') . qq|</th>|;
1298 $column_header{datepaid} =
1299 qq|<th><a class=listheading href=$href&sort=datepaid>|
1300 . $locale->text('Date Paid')
1302 $column_header{notes} =
1303 qq|<th class=listheading>| . $locale->text('Notes') . qq|</th>|;
1304 $column_header{employee} =
1305 "<th><a class=listheading href=$href&sort=employee>"
1306 . $locale->text('Employee') . "</th>";
1308 $form->{title} = $locale->text('AP Transactions');
1317 <th class=listtop>$form->{title}</th>
1319 <tr height="5"></tr>
1326 <tr class=listheading>
1329 map { print "\n$column_header{$_}" } @column_index;
1335 # add sort and escape callback
1336 $form->{callback} = "$callback&sort=$form->{sort}";
1337 $callback = $form->escape($form->{callback});
1339 if (@{ $form->{AP} }) {
1340 $sameitem = $form->{AP}->[0]->{ $form->{sort} };
1343 # sums and tax on reports by Antonio Gallardo
1345 foreach $ap (@{ $form->{AP} }) {
1347 if ($form->{l_subtotal} eq 'Y') {
1348 if ($sameitem ne $ap->{ $form->{sort} }) {
1350 $sameitem = $ap->{ $form->{sort} };
1354 $column_data{netamount} =
1356 . $form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")
1358 $column_data{tax} = "<td align=right>"
1359 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount},
1362 $column_data{amount} =
1364 . $form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>";
1365 $column_data{paid} =
1367 . $form->format_amount(\%myconfig, $ap->{paid}, 2, " ") . "</td>";
1368 $column_data{due} = "<td align=right>"
1369 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid},
1373 $totalnetamount += $ap->{netamount};
1374 $totalamount += $ap->{amount};
1375 $totalpaid += $ap->{paid};
1376 $totaldue += ($ap->{amount} - $ap->{paid});
1378 $subtotalnetamount += $ap->{netamount};
1379 $subtotalamount += $ap->{amount};
1380 $subtotalpaid += $ap->{paid};
1381 $subtotaldue += ($ap->{amount} - $ap->{paid});
1383 $column_data{transdate} = "<td>$ap->{transdate} </td>";
1384 $column_data{duedate} = "<td>$ap->{duedate} </td>";
1385 $column_data{datepaid} = "<td>$ap->{datepaid} </td>";
1387 $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
1389 $column_data{invnumber} =
1390 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>|;
1391 $column_data{id} = "<td>$ap->{id}</td>";
1392 $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>";
1393 $column_data{name} = "<td>$ap->{name}</td>";
1394 $ap->{notes} =~ s/\r\n/<br>/g;
1395 $column_data{notes} = "<td>$ap->{notes} </td>";
1396 $column_data{employee} = "<td>$ap->{employee} </td>";
1401 <tr class=listrow$i >
1404 map { print "\n$column_data{$_}" } @column_index;
1412 if ($form->{l_subtotal} eq 'Y') {
1418 <tr class=listtotal>
1421 map { $column_data{$_} = "<td> </td>" } @column_index;
1423 $column_data{netamount} =
1424 "<th class=listtotal align=right>"
1425 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1426 $column_data{tax} = "<th class=listtotal align=right>"
1427 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1430 $column_data{amount} =
1431 "<th class=listtotal align=right>"
1432 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1433 $column_data{paid} =
1434 "<th class=listtotal align=right>"
1435 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1437 "<th class=listtotal align=right>"
1438 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1440 map { print "$column_data{$_}\n" } @column_index;
1448 <td><hr size=3 noshade></td>
1453 <form method=post action=$form->{script}>
1455 <input name=callback type=hidden value="$form->{callback}">
1457 <input type=hidden name=path value=$form->{path}>
1458 <input type=hidden name=login value=$form->{login}>
1459 <input type=hidden name=password value=$form->{password}>
1461 <input class=submit type=submit name=action value="|
1462 . $locale->text('AP Transaction') . qq|">
1464 <input class=submit type=submit name=action value="|
1465 . $locale->text('Vendor Invoice') . qq|">|;
1467 if ($form->{menubar}) {
1468 require "$form->{path}/menu.pl";
1479 $lxdebug->leave_sub();
1483 $lxdebug->enter_sub();
1485 map { $column_data{$_} = "<td> </td>" } @column_index;
1487 $column_data{netamount} =
1488 "<th class=listsubtotal align=right>"
1489 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1491 $column_data{tax} = "<th class=listsubtotal align=right>"
1492 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1495 $column_data{amount} =
1496 "<th class=listsubtotal align=right>"
1497 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1498 $column_data{paid} =
1499 "<th class=listsubtotal align=right>"
1500 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1502 "<th class=listsubtotal align=right>"
1503 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1505 $subtotalnetamount = 0;
1506 $subtotalamount = 0;
1510 print "<tr class=listsubtotal>";
1512 map { print "\n$column_data{$_}" } @column_index;
1518 $lxdebug->leave_sub();