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 #======================================================================
39 require "$form->{path}/arap.pl";
45 # this is for our long dates
46 # $locale->text('January')
47 # $locale->text('February')
48 # $locale->text('March')
49 # $locale->text('April')
50 # $locale->text('May ')
51 # $locale->text('June')
52 # $locale->text('July')
53 # $locale->text('August')
54 # $locale->text('September')
55 # $locale->text('October')
56 # $locale->text('November')
57 # $locale->text('December')
59 # this is for our short month
60 # $locale->text('Jan')
61 # $locale->text('Feb')
62 # $locale->text('Mar')
63 # $locale->text('Apr')
64 # $locale->text('May')
65 # $locale->text('Jun')
66 # $locale->text('Jul')
67 # $locale->text('Aug')
68 # $locale->text('Sep')
69 # $locale->text('Oct')
70 # $locale->text('Nov')
71 # $locale->text('Dec')
75 $lxdebug->enter_sub();
78 $form->{title} = "Add";
80 $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
85 $lxdebug->leave_sub();
90 $lxdebug->enter_sub();
93 $form->{title} = "Edit";
98 $lxdebug->leave_sub();
103 $lxdebug->enter_sub();
109 $lxdebug->leave_sub();
114 $lxdebug->enter_sub();
117 $form->create_links("AP", \%myconfig, "vendor");
118 $taxincluded = $form->{taxincluded};
119 $duedate = $form->{duedate};
121 IR->get_vendor(\%myconfig, \%$form);
123 $form->{duedate} = $duedate if $duedate;
124 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
126 # build the popup menus
127 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
129 map { $tax .= qq|<option value=\"$_->{taxkey}--$_->{rate}\">$_->{taxdescription} |.($_->{rate} * 100).qq| %|} @{ $form->{TAX} };
130 $form->{taxchart} = $tax;
131 $form->{selecttaxchart} = $tax;
134 @curr = split /:/, $form->{currencies};
136 $form->{defaultcurrency} = $curr[0];
138 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
141 if (@{ $form->{all_vendor} }) {
142 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
143 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_vendor} });
147 if (@{ $form->{all_departments} }) {
148 $form->{selectdepartment} = "<option>\n";
149 $form->{department} = "$form->{department}--$form->{department_id}";
151 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
154 $form->{employee} = "$form->{employee}--$form->{employee_id}";
157 $form->{forex} = $form->{exchangerate};
158 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
160 foreach $key (keys %{ $form->{AP_links} }) {
161 foreach $ref (@{ $form->{AP_links}{$key} }) {
162 if ($key eq "AP_paid") {
163 $form->{"select$key"} .= "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
165 $form->{"select$key"} .= "<option value=\"$ref->{accno}--$ref->{taxkey}\">$ref->{accno}--$ref->{description}</option>\n";
169 $form->{$key} = $form->{"select$key"};
170 # if there is a value we have an old entry
172 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
174 if ($key eq "AP_paid") {
176 $form->{"AP_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
177 $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{amount};
178 $form->{"datepaid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
179 $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i-1]->{source};
180 $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i-1]->{memo};
182 $form->{"forex_$j"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
183 $form->{"AP_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
184 $form->{paidaccounts}++;
190 if ($key eq "AP_tax") {
191 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
192 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate * -1, 2);
193 if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
194 $totaltax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
195 $taxrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
197 $totalwithholding += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
198 $withholdingrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
200 $formtax = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2) *-1;
202 $form->{"${akey}_$i"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2);
203 if ($akey eq 'amount') {
204 $form->{"${akey}_$i"} *= -1;
205 $totalamount += $form->{"${akey}_$i"};
206 $form->{taxrate} = $form->{acc_trans}{$key}->[$i-1]->{rate};
208 $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
209 $form->{"project_id_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
211 $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
212 $form->{"select${key}"} =~ /(<option value=\"$form->{acc_trans}{$key}->[$i-1]->{accno}--[^\"]*\">$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}<\/option>\n)/;
214 $form->{"select${key}"} = $1;
215 if ($akey eq 'amount') {
216 $form->{selecttaxchart} =~ /(<option value=\"$form->{acc_trans}{$key}->[$i-1]->{taxkey}--[^<]*)/;
217 $form->{selecttaxchart} = $1;
224 $form->{taxincluded} = $taxincluded if ($form->{id});
225 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
227 if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
228 # add tax to amounts and invtotal
230 $taxamount = ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
231 $tax = $form->round_amount($taxamount, 2);
232 $diff += ($taxamount - $tax);
233 $form->{"amount_$i"} += $tax;
235 $form->{amount_1} += $form->round_amount($diff, 2);
238 # check if calculated is equal to stored
239 if ($form->{taxincluded} && $form->{taxrate} && $witholdingrate) {
240 if ($form->{"taxrate"} > 0) {
241 $taxamount = $form->round_amount(($form->{amount_1} - ($form->{amount_1} / ($form->{taxrate} + 1))), 2);
243 $taxamount = $form->round_amount(($totalamount + $totaltax + $totalwithholding) * $withholdingrate / (1 - $withholdingrate), 2) * $form->{"taxrate"} / $withholdingrate;
246 $taxamount = $totalamount * $form->{"taxrate"};
248 $taxamount = $form->round_amount($taxamount, 2);
249 $form->{tax} = $taxamount;
251 $form->{tax} = $formtax;
253 $form->{invtotal} = $totalamount + $totaltax + $totalwithholding;
254 $form->{rowcount}++ if $form->{id};
257 $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
259 $lxdebug->leave_sub();
264 $lxdebug->enter_sub();
267 $title = $form->{title};
268 $form->{title} = $locale->text("$title Accounts Payables Transaction");
270 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
272 # type=submit $locale->text('Add Accounts Payables Transaction')
273 # type=submit $locale->text('Edit Accounts Payables Transaction')
275 # set option selected
276 foreach $item (qw(vendor currency department)) {
277 $form->{"select$item"} =~ s/ selected//;
278 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
280 $readonly = ($form->{id}) ? "readonly" : "";
282 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
283 $readonly = ($form->{radier}) ? "" : $readonly;
285 map { $form->{$_} =~ s/\"/"/g } qw(AP_amount AP taxchart);
287 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
289 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
290 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
293 <input type=hidden name=forex value=$form->{forex}>
295 if ($form->{currency} ne $form->{defaultcurrency}) {
296 if ($form->{forex}) {
299 <th align=right>|.$locale->text('Exchangerate').qq|</th>
300 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
305 <th align=right>|.$locale->text('Exchangerate').qq|</th>
306 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
315 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
316 <th align=left nowrap>|.$locale->text('Tax Included').qq|</th>
322 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
325 $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
329 <th align="right" nowrap>|.$locale->text('Department').qq|</th>
330 <td colspan=3><select name=department>$form->{selectdepartment}</select>
331 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
334 | if $form->{selectdepartment};
336 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
338 $vendor = ($form->{selectvendor}) ? qq|<select name=vendor>$form->{selectvendor}</select>| : qq|<input name=vendor value="$form->{vendor}" size=35>|;
340 # use JavaScript Calendar or not
341 $form->{jsscript} = $jscalendar;
343 if ($form->{jsscript})
345 # with JavaScript Calendar
347 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}> $readonly</td>
348 <td><input type=button name=transdate id="trigger1" value=|.$locale->text('button').qq|></td>
351 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}> $readonly</td>
352 <td><input type=button name=duedate id="trigger2" value=|.$locale->text('button').qq|></td></td>
355 $jsscript = Form->write_trigger(\%myconfig,"2","transdate","BL","trigger1","duedate","BL","trigger2");
359 # without JavaScript Calendar
360 $button1 = qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}> $readonly</td>|;
361 $button2 = qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}> $readonly</td>|;
369 <form method=post action=$form->{script}>
371 <input type=hidden name=id value=$form->{id}>
372 <input type=hidden name=sort value=$form->{sort}>
373 <input type=hidden name=closedto value=$form->{closedto}>
374 <input type=hidden name=locked value=$form->{locked}>
375 <input type=hidden name=title value="$title">
379 <th class=listtop>$form->{title}</th>
389 <th align=right nowrap>|.$locale->text('Vendor').qq|</th>
390 <td colspan=3>$vendor</td>
391 <input type=hidden name=selectvendor value="$form->{selectvendor}">
392 <input type=hidden name=oldvendor value="$form->{oldvendor}">
393 <input type=hidden name=vendor_id value="$form->{vendor_id}">
394 <input type=hidden name=terms value=$form->{terms}>
401 <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th>
402 <td>$form->{creditlimit}</td>
403 <th align=left nowrap>|.$locale->text('Remaining').qq|</th>
404 <td class="plus$n">$form->{creditremaining}</td>
405 <input type=hidden name=creditlimit value=$form->{creditlimit}>
406 <input type=hidden name=creditremaining value=$form->{creditremaining}>
411 <th align=right nowrap>|.$locale->text('Currency').qq|</th>
412 <td><select name=currency>$form->{selectcurrency}</select></td>
413 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
414 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
415 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
416 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
426 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
427 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
430 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
431 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
434 <th align=right nowrap>|.$locale->text('Invoice Date').qq|</th>
438 <th align=right nowrap>|.$locale->text('Due Date').qq|</th>
447 <input type=hidden name=AP_amount value="$form->{AP_amount}">
448 <input type=hidden name=taxchart value="$form->{taxchart}">
449 <input type=hidden name=rowcount value=$form->{rowcount}>
457 $amount = $locale->text('Amount');
458 $project = $locale->text('Project');
462 # $form->{"selectAP_amount"} =~ s/ selected//;
463 # $form->{"selectAP_amount"} =~ s/option>\Q$form->{"AP_amount_$i"}\E/option selected>$form->{"AP_amount_$i"}/;
466 $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
470 <th align=right nowrap>$amount</th>
471 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"} $readonly></td>
473 <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
474 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
475 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
476 <td width=50%><select name="AP_amountselected">$form->{selectAP_amount}</select></td>
483 $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax');
484 # format and reverse tax
485 $form->{"tax"} = $form->format_amount(\%myconfig, $form->{"tax"}, 2);
489 <th align=right nowrap>${taxlabel}</th>
490 <td><input name="tax" size=10 value=$form->{"tax"} $readonly></td>
491 <td align=right><input name=taxcheck class=checkbox type=checkbox value=1></td>
492 <td align=left nowrap>|.$locale->text('Correct Tax').qq|</td>
493 <td><select name=taxchartselected>$form->{"selecttaxchart"}</select></td>
502 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
506 <th align=right nowrap>|.$locale->text('Total').qq|</th>
507 <td>$form->{invtotal}</td>
509 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
510 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
512 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
515 <td><select name=APselected>$form->{selectAP}</select></td>
516 <input type=hidden name=AP value="$form->{AP}">
520 <th align=right nowrap>|.$locale->text('Notes').qq|</th>
521 <td colspan=5>$notes</td>
529 <tr class=listheading>
530 <th class=listheading colspan=6>|.$locale->text('Payments').qq|</th>
535 if ($form->{currency} eq $form->{defaultcurrency}) {
536 @column_index = qw(datepaid source memo paid AP_paid);
538 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
541 $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
542 $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
543 $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
544 $column_data{AP_paid} = "<th>".$locale->text('Account')."</th>";
545 $column_data{source} = "<th>".$locale->text('Source')."</th>";
546 $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
551 map { print "$column_data{$_}\n" } @column_index;
556 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
557 for $i (1 .. $form->{paidaccounts}) {
562 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
563 $form->{"selectAP_paid_$i"} =~ s/option value=\"$form->{"AP_paid_$i"}\">/option value=\"$form->{"AP_paid_$i"}\" selected>/;
567 $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
568 $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
570 $exchangerate = qq| |;
571 if ($form->{currency} ne $form->{defaultcurrency}) {
572 if ($form->{"forex_$i"}) {
573 $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
575 $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
580 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
583 $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
584 $column_data{"AP_paid_$i"} = qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
585 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
586 $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value=$form->{"datepaid_$i"}></td>|;
587 $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
588 $column_data{"memo_$i"} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
590 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
596 map { $form->{$_} =~ s/\"/"/g } qw(selectAP_paid);
598 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
599 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
605 <td><hr size=3 noshade></td>
610 $lxdebug->leave_sub();
615 $lxdebug->enter_sub();
620 <input name=callback type=hidden value="$form->{callback}">
622 <input type=hidden name=path value=$form->{path}>
623 <input type=hidden name=login value=$form->{login}>
624 <input type=hidden name=password value=$form->{password}>
629 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
630 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
632 if ($form->{id} && $form->{radier}) {
633 # print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
636 if (!$form->{revtrans}) {
637 if (!$form->{locked}) {
639 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
640 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
645 if ($transdate > $closedto) {
647 <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
652 if (($transdate > $closedto) && !$form->{id}) {
653 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
654 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
658 if ($form->{menubar}) {
659 require "$form->{path}/menu.pl";
670 $lxdebug->leave_sub();
675 $lxdebug->enter_sub();
683 $form->{invtotal} = 0;
687 $form->{selectAP_amount} = $form->{AP_amount};
688 $form->{selectAP_amount} =~ s/value=\"$form->{AP_amountselected}\"/value=\"$form->{AP_amountselected}\" selected/;
691 $form->{selectAP} = $form->{AP};
692 $form->{selectAP} =~ s/value=\"$form->{APselected}\"/value=\"$form->{APselected}\" selected/;
694 ($AP_amountaccno, $AP_amounttaxkey) = split(/--/, $form->{AP_amountselected});
695 $form->{selecttaxchart} = $form->{taxchart};
696 $form->{selecttaxchart} =~ s/value=\"$AP_amounttaxkey--([^\"]*)\"/value=\"$AP_amounttaxkey--$1\" selected/;
700 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
702 @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
705 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
706 if ($form->{"amount_$i"}) {
709 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
713 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
715 $form->{invtotal} += $form->{"amount_1"};
717 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'sell')));
719 $form->{invdate} = $form->{transdate};
720 $save_AP = $form->{AP};
722 $form->{AP} = $save_AP;
730 @taxaccounts = split / /, $form->{taxaccounts};
732 $form->{"tax"} = $form->parse_amount(\%myconfig, $form->{"tax"});
734 if ($form->{taxincluded} && $form->{"rate"}) {
735 $taxrate = $form->{"rate"};
736 $withholdingrate = 0;
738 $amount = $form->round_amount(($form->{invtotal} - ($form->{invtotal} / ($taxrate + 1))), 2);
739 $form->{"tax"} = $form->round_amount($amount, 2);
740 $taxdiff += ($amount - $form->{"tax"});
743 if (abs $taxdiff >= 0.005) {
744 $form->{"tax"} += $form->round_amount($taxdiff, 2);
747 $totaltax += $form->{"tax"};
750 $form->{"tax"} = $form->round_amount($form->{invtotal} * $form->{"rate"}, 2);
751 $totaltax += $form->{"tax"};
755 $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
757 for $i (1 .. $form->{paidaccounts}) {
758 if ($form->{"paid_$i"}) {
759 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
761 $totalpaid += $form->{"paid_$i"};
763 $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell')));
767 $form->{creditremaining} -= ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - $form->{oldinvtotal});
768 $form->{oldinvtotal} = $form->{invtotal};
769 $form->{oldtotalpaid} = $totalpaid;
773 $lxdebug->leave_sub();
778 $lxdebug->enter_sub();
781 # check if there is a vendor, invoice and due date
782 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
783 $form->isblank("duedate", $locale->text("Due Date missing!"));
784 $form->isblank("vendor", $locale->text('Vendor missing!'));
787 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
788 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
790 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
792 $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
795 for $i (1 .. $form->{paidaccounts}) {
796 if ($form->{"paid_$i"}) {
797 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
799 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
801 $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
803 if ($form->{currency} ne $form->{defaultcurrency}) {
804 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
805 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
812 # if old vendor ne vendor redo form
813 ($vendor) = split /--/, $form->{vendor};
814 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
818 ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
819 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
820 ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
821 $form->{AP}{amount_1} = $debitaccno;
822 $form->{AP}{payables} = $payablesaccno;
823 $form->{taxkey} = $taxkey;
825 $form->{id} = 0 if $form->{postasnew};
827 $form->redirect($locale->text('Transaction posted!')) if (AP->post_transaction(\%myconfig, \%$form));
828 $form->error($locale->text('Cannot post transaction!'));
830 $lxdebug->leave_sub();
835 $lxdebug->enter_sub();
838 $form->{postasnew} = 1;
841 $lxdebug->leave_sub();
846 $lxdebug->enter_sub();
849 $form->{title} = $locale->text('Confirm!');
853 delete $form->{header};
858 <form method=post action=$form->{script}>
861 foreach $key (keys %$form) {
862 $form->{$key} =~ s/\"/"/g;
863 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
867 <h2 class=confirm>$form->{title}</h2>
869 <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber}</h4>
871 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
878 $lxdebug->leave_sub();
884 $lxdebug->enter_sub();
887 $form->redirect($locale->text('Transaction deleted!')) if (AP->delete_transaction(\%myconfig, \%$form, $spool));
888 $form->error($locale->text('Cannot delete transaction!'));
890 $lxdebug->leave_sub();
895 $lxdebug->enter_sub();
898 # setup vendor selection
899 $form->all_vc(\%myconfig, "vendor", "AP");
901 if (@{ $form->{all_vendor} }) {
902 map { $vendor .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{all_vendor} };
903 $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
905 $vendor = qq|<input name=vendor size=35>|;
909 if (@{ $form->{all_departments} }) {
910 $form->{selectdepartment} = "<option>\n";
912 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
917 <th align=right nowrap>|.$locale->text('Department').qq|</th>
918 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
920 | if $form->{selectdepartment};
922 $form->{title} = $locale->text('AP Transactions');
924 # use JavaScript Calendar or not
925 $form->{jsscript} = $jscalendar;
927 if ($form->{jsscript})
929 # with JavaScript Calendar
931 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
932 <input type=button name=transdatefrom id="trigger1" value=|.$locale->text('button').qq|></td>
935 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
936 <input type=button name=transdateto name=transdateto id="trigger2" value=|.$locale->text('button').qq|></td>
939 $jsscript = Form->write_trigger(\%myconfig,"2","transdatefrom","BR","trigger1","transdateto","BL","trigger2");
943 # without JavaScript Calendar
945 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
947 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
955 <form method=post action=$form->{script}>
959 <th class=listtop>$form->{title}</th>
966 <th align=right>|.$locale->text('Vendor').qq|</th>
967 <td colspan=3>$vendor</td>
971 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
972 <td colspan=3><input name=invnumber size=20></td>
975 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
976 <td colspan=3><input name=ordnumber size=20></td>
979 <th align=right nowrap>|.$locale->text('Notes').qq|</th>
980 <td colspan=3><input name=notes size=40></td>
983 <th align=right nowrap>|.$locale->text('From').qq|</th>
985 <th align=right>|.$locale->text('Bis').qq|</th>
988 <input type=hidden name=sort value=transdate>
996 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
1000 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1001 <td nowrap>|.$locale->text('Open').qq|</td>
1002 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1003 <td nowrap>|.$locale->text('Closed').qq|</td>
1006 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1007 <td nowrap>|.$locale->text('ID').qq|</td>
1008 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1009 <td nowrap>|.$locale->text('Invoice Number').qq|</td>
1010 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1011 <td nowrap>|.$locale->text('Order Number').qq|</td>
1014 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1015 <td nowrap>|.$locale->text('Vendor').qq|</td>
1016 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1017 <td nowrap>|.$locale->text('Invoice Date').qq|</td>
1018 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1019 <td nowrap>|.$locale->text('Amount').qq|</td>
1022 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1023 <td nowrap>|.$locale->text('Tax').qq|</td>
1024 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1025 <td nowrap>|.$locale->text('Total').qq|</td>
1026 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1027 <td nowrap>|.$locale->text('Date Paid').qq|</td>
1030 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1031 <td nowrap>|.$locale->text('Paid').qq|</td>
1032 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1033 <td nowrap>|.$locale->text('Due Date').qq|</td>
1034 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1035 <td nowrap>|.$locale->text('Amount Due').qq|</td>
1038 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1039 <td nowrap>|.$locale->text('Notes').qq|</td>
1040 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1041 <td nowrap>|.$locale->text('Employee').qq|</td>
1044 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1045 <td nowrap>|.$locale->text('Subtotal').qq|</td>
1054 <td><hr size=3 noshade></td>
1061 <input type=hidden name=nextsub value=$form->{nextsub}>
1062 <input type=hidden name=path value=$form->{path}>
1063 <input type=hidden name=login value=$form->{login}>
1064 <input type=hidden name=password value=$form->{password}>
1066 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
1073 $lxdebug->leave_sub();
1077 sub ap_transactions {
1078 $lxdebug->enter_sub();
1081 $form->{vendor} = $form->unescape($form->{vendor});
1082 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
1084 AP->ap_transactions(\%myconfig, \%$form);
1086 $callback = "$form->{script}?action=ap_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1090 if ($form->{vendor}) {
1091 $callback .= "&vendor=".$form->escape($form->{vendor},1);
1092 $href .= "&vendor=".$form->escape($form->{vendor});
1093 $option .= $locale->text('Vendor')." : $form->{vendor}";
1095 if ($form->{department}) {
1096 $callback .= "&department=".$form->escape($form->{department},1);
1097 $href .= "&department=".$form->escape($form->{department});
1098 ($department) = split /--/, $form->{department};
1099 $option .= "\n<br>" if ($option);
1100 $option .= $locale->text('Department')." : $department";
1102 if ($form->{invnumber}) {
1103 $callback .= "&invnumber=".$form->escape($form->{invnumber},1);
1104 $href .= "&invnumber=".$form->escape($form->{invnumber});
1105 $option .= "\n<br>" if ($option);
1106 $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
1108 if ($form->{ordnumber}) {
1109 $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);
1110 $href .= "&ordnumber=".$form->escape($form->{ordnumber});
1111 $option .= "\n<br>" if ($option);
1112 $option .= $locale->text('Order Number')." : $form->{ordnumber}";
1114 if ($form->{notes}) {
1115 $callback .= "¬es=".$form->escape($form->{notes},1);
1116 $href .= "¬es=".$form->escape($form->{notes});
1117 $option .= "\n<br>" if $option;
1118 $option .= $locale->text('Notes')." : $form->{notes}";
1121 if ($form->{transdatefrom}) {
1122 $callback .= "&transdatefrom=$form->{transdatefrom}";
1123 $href .= "&transdatefrom=$form->{transdatefrom}";
1124 $option .= "\n<br>" if ($option);
1125 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
1127 if ($form->{transdateto}) {
1128 $callback .= "&transdateto=$form->{transdateto}";
1129 $href .= "&transdateto=$form->{transdateto}";
1130 $option .= "\n<br>" if ($option);
1131 $option .= $locale->text('Bis')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);
1133 if ($form->{open}) {
1134 $callback .= "&open=$form->{open}";
1135 $href .= "&open=$form->{open}";
1136 $option .= "\n<br>" if ($option);
1137 $option .= $locale->text('Open');
1139 if ($form->{closed}) {
1140 $callback .= "&closed=$form->{closed}";
1141 $href .= "&closed=$form->{closed}";
1142 $option .= "\n<br>" if ($option);
1143 $option .= $locale->text('Closed');
1146 @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee));
1148 foreach $item (@columns) {
1149 if ($form->{"l_$item"} eq "Y") {
1150 push @column_index, $item;
1152 # add column to href and callback
1153 $callback .= "&l_$item=Y";
1154 $href .= "&l_$item=Y";
1158 if ($form->{l_subtotal} eq 'Y') {
1159 $callback .= "&l_subtotal=Y";
1160 $href .= "&l_subtotal=Y";
1164 $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</a></th>|;
1165 $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;
1166 $column_header{duedate} = qq|<th><a class=listheading href=$href&sort=duedate>|.$locale->text('Due Date').qq|</a></th>|;
1167 $column_header{due} = qq|<th class=listheading>|.$locale->text('Amount Due').qq|</th>|;
1168 $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</a></th>|;
1169 $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|;
1170 $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Vendor').qq|</a></th>|;
1171 $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
1172 $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
1173 $column_header{amount} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
1174 $column_header{paid} = qq|<th class=listheading>|.$locale->text('Paid').qq|</th>|;
1175 $column_header{datepaid} = qq|<th><a class=listheading href=$href&sort=datepaid>|.$locale->text('Date Paid').qq|</a></th>|;
1176 $column_header{notes} = qq|<th class=listheading>|.$locale->text('Notes').qq|</th>|;
1177 $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Employee')."</th>";
1180 $form->{title} = $locale->text('AP Transactions');
1189 <th class=listtop>$form->{title}</th>
1191 <tr height="5"></tr>
1198 <tr class=listheading>
1201 map { print "\n$column_header{$_}" } @column_index;
1207 # add sort and escape callback
1208 $form->{callback} = "$callback&sort=$form->{sort}";
1209 $callback = $form->escape($form->{callback});
1211 if (@{ $form->{AP} }) {
1212 $sameitem = $form->{AP}->[0]->{$form->{sort}};
1215 # sums and tax on reports by Antonio Gallardo
1217 foreach $ap (@{ $form->{AP} }) {
1219 if ($form->{l_subtotal} eq 'Y') {
1220 if ($sameitem ne $ap->{$form->{sort}}) {
1222 $sameitem = $ap->{$form->{sort}};
1226 $column_data{netamount} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")."</td>";
1227 $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount}, 2, " ") . "</td>";
1228 $column_data{amount} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>";
1229 $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{paid}, 2, " ")."</td>";
1230 $column_data{due} = "<td align=right>".$form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid}, 2, " ")."</td>";
1232 $totalnetamount += $ap->{netamount};
1233 $totalamount += $ap->{amount};
1234 $totalpaid += $ap->{paid};
1235 $totaldue += ($ap->{amount} - $ap->{paid});
1237 $subtotalnetamount += $ap->{netamount};
1238 $subtotalamount += $ap->{amount};
1239 $subtotalpaid += $ap->{paid};
1240 $subtotaldue += ($ap->{amount} - $ap->{paid});
1242 $column_data{transdate} = "<td>$ap->{transdate} </td>";
1243 $column_data{duedate} = "<td>$ap->{duedate} </td>";
1244 $column_data{datepaid} = "<td>$ap->{datepaid} </td>";
1246 $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
1248 $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>|;
1249 $column_data{id} = "<td>$ap->{id}</td>";
1250 $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>";
1251 $column_data{name} = "<td>$ap->{name}</td>";
1252 $ap->{notes} =~ s/\r\n/<br>/g;
1253 $column_data{notes} = "<td>$ap->{notes} </td>";
1254 $column_data{employee} = "<td>$ap->{employee} </td>";
1259 <tr class=listrow$i >
1262 map { print "\n$column_data{$_}" } @column_index;
1270 if ($form->{l_subtotal} eq 'Y') {
1276 <tr class=listtotal>
1279 map { $column_data{$_} = "<td> </td>" } @column_index;
1281 $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, " ")."</th>";
1282 $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ")."</th>";
1283 $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, " ")."</th>";
1284 $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, " ")."</th>";
1285 $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldue, 2, " ")."</th>";
1287 map { print "$column_data{$_}\n" } @column_index;
1295 <td><hr size=3 noshade></td>
1300 <form method=post action=$form->{script}>
1302 <input name=callback type=hidden value="$form->{callback}">
1304 <input type=hidden name=path value=$form->{path}>
1305 <input type=hidden name=login value=$form->{login}>
1306 <input type=hidden name=password value=$form->{password}>
1308 <input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|">
1310 <input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|">|;
1312 if ($form->{menubar}) {
1313 require "$form->{path}/menu.pl";
1324 $lxdebug->leave_sub();
1329 $lxdebug->enter_sub();
1332 map { $column_data{$_} = "<td> </td>" } @column_index;
1334 $column_data{netamount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")."</th>";
1335 $column_data{tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ")."</th>";
1336 $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, " ")."</th>";
1337 $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ")."</th>";
1338 $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldue, 2, " ")."</th>";
1340 $subtotalnetamount = 0;
1341 $subtotalamount = 0;
1345 print "<tr class=listsubtotal>";
1347 map { print "\n$column_data{$_}" } @column_index;
1353 $lxdebug->leave_sub();