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};
82 AP->get_transdate(\%myconfig, $form);
85 $lxdebug->leave_sub();
89 $lxdebug->enter_sub();
91 $form->{title} = "Edit";
96 $lxdebug->leave_sub();
100 $lxdebug->enter_sub();
105 $lxdebug->leave_sub();
109 $lxdebug->enter_sub();
111 $form->create_links("AP", \%myconfig, "vendor");
112 $taxincluded = $form->{taxincluded};
113 $duedate = $form->{duedate};
115 IR->get_vendor(\%myconfig, \%$form);
116 $form->{taxincluded} = $taxincluded;
117 $form->{duedate} = $duedate if $duedate;
118 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
119 $form->{rowcount} = 1;
121 # build the popup menus
122 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
126 qq|<option value=\"$_->{id}--$_->{rate}\">$_->{taxdescription} |
127 . ($_->{rate} * 100) . qq| %|
129 $form->{taxchart} = $tax;
130 $form->{selecttaxchart} = $tax;
133 @curr = split(/:/, $form->{currencies});
135 $form->{defaultcurrency} = $curr[0];
137 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
140 if (@{ $form->{all_vendor} }) {
141 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
142 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
143 (@{ $form->{all_vendor} });
147 if (@{ $form->{all_departments} }) {
148 $form->{selectdepartment} = "<option>\n";
149 $form->{department} = "$form->{department}--$form->{department_id}";
152 $form->{selectdepartment} .=
153 "<option>$_->{description}--$_->{id}\n"
154 } (@{ $form->{all_departments} });
157 $form->{employee} = "$form->{employee}--$form->{employee_id}";
160 $form->{forex} = $form->{exchangerate};
161 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
163 foreach $key (keys %{ $form->{AP_links} }) {
164 foreach $ref (@{ $form->{AP_links}{$key} }) {
165 if ($key eq "AP_paid") {
166 $form->{"select$key"} .=
167 "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
169 $form->{"select$key"} .=
170 "<option value=\"$ref->{accno}--$ref->{tax_id}\">$ref->{accno}--$ref->{description}</option>\n";
174 $form->{$key} = $form->{"select$key"};
176 # if there is a value we have an old entry
180 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
182 if ($key eq "AP_paid") {
184 $form->{"AP_paid_$j"} =
185 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
186 $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
187 $form->{"datepaid_$j"} =
188 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
189 $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
190 $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
192 $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
193 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
194 $form->{"AP_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
195 $form->{paidaccounts}++;
201 if (($key eq "AP_tax") || ($key eq "AR_tax")) {
202 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
203 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
204 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
206 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
209 if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
211 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
213 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
216 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
218 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
220 $index = $form->{acc_trans}{$key}->[$i - 1]->{index};
221 $form->{"tax_$index"} =
222 $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
223 $totaltax += $form->{"tax_$index"};
227 $form->{"${akey}_$k"} =
229 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
231 if ($akey eq 'amount') {
233 $form->{"${akey}_$i"} *= -1;
234 $totalamount += $form->{"${akey}_$i"};
235 $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
236 $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} =
237 "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
238 $form->{"project_id_$k"} =
239 "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
241 $form->{"${key}_$k"} =
242 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
243 my $q_description = quotemeta($form->{acc_trans}{$key}->[$i-1]->{description});
244 $form->{"select${key}"} =~
245 /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{accno}--[^\"]*)\">$form->{acc_trans}{$key}->[$i-1]->{accno}--${q_description}<\/option>\n/;
246 $form->{"${key}_$k"} = $1;
247 if ($akey eq 'amount') {
248 $form->{"taxchart_$k"} = $form->{taxchart};
249 $form->{"taxchart_$k"} =~
250 /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{id}--[^\"]*)/;
251 $form->{"taxchart_$k"} = $1;
258 $form->{taxincluded} = $taxincluded if ($form->{id});
259 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
261 if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
263 # add tax to amounts and invtotal
264 for $i (1 .. $form->{rowcount}) {
266 ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
267 $tax = $form->round_amount($taxamount, 2);
268 $diff += ($taxamount - $tax);
269 $form->{"amount_$i"} += $form->{"tax_$i"};
271 $form->{amount_1} += $form->round_amount($diff, 2);
274 $taxamount = $form->round_amount($taxamount, 2);
276 $form->{invtotal} = $totalamount + $totaltax;
279 ($form->datetonum($form->{transdate}, \%myconfig) <=
280 $form->datetonum($form->{closedto}, \%myconfig));
282 $lxdebug->leave_sub();
286 $lxdebug->enter_sub();
288 $title = $form->{title};
289 $form->{title} = $locale->text("$title Accounts Payables Transaction");
291 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
293 # type=submit $locale->text('Add Accounts Payables Transaction')
294 # type=submit $locale->text('Edit Accounts Payables Transaction')
296 $form->{javascript} = qq|<script type="text/javascript">
298 function setTaxkey(accno, row) {
299 var taxkey = accno.options[accno.selectedIndex].value;
300 var reg = /--([0-9]*)/;
301 var found = reg.exec(taxkey);
302 var index = found[1];
303 index = parseInt(index);
304 var tax = 'taxchart_' + row;
305 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
306 var reg2 = new RegExp("^"+ index, "");
307 if (reg2.exec(document.getElementById(tax).options[i].value)) {
308 document.getElementById(tax).options[i].selected = true;
316 # set option selected
317 foreach $item (qw(vendor currency department)) {
318 $form->{"select$item"} =~ s/ selected//;
319 $form->{"select$item"} =~
320 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
322 $readonly = ($form->{id}) ? "readonly" : "";
325 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
326 $readonly = ($form->{radier}) ? "" : $readonly;
327 $selectAP_amount_unquoted = $form->{selectAP_amount};
328 $taxchart = $form->{taxchart};
329 map { $form->{$_} =~ s/\"/"/g }
330 qw(AP_amount selectAP_amount AP taxchart);
333 $form->{exchangerate} =
334 $form->format_amount(\%myconfig, $form->{exchangerate});
336 $form->{creditlimit} =
337 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
338 $form->{creditremaining} =
339 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
342 <input type=hidden name=forex value=$form->{forex}>
344 if ($form->{currency} ne $form->{defaultcurrency}) {
345 if ($form->{forex}) {
348 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
349 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
354 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
355 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
364 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
365 <th align=left nowrap>|
366 . $locale->text('Tax Included') . qq|</th>
370 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
374 qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
378 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
379 <td colspan=3><select name=department>$form->{selectdepartment}</select>
380 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
383 | if $form->{selectdepartment};
385 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
388 ($form->{selectvendor})
389 ? qq|<select name=vendor>$form->{selectvendor}</select>|
390 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
392 # use JavaScript Calendar or not
393 $form->{jsscript} = $jscalendar;
395 if ($form->{jsscript}) {
397 # with JavaScript Calendar
399 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}> $readonly</td>
400 <td><input type=button name=transdate id="trigger1" value=|
401 . $locale->text('button') . qq|></td>
404 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}> $readonly</td>
405 <td><input type=button name=duedate id="trigger2" value=|
406 . $locale->text('button') . qq|></td></td>
411 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
412 "duedate", "BL", "trigger2");
415 # without JavaScript Calendar
417 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}> $readonly</td>|;
419 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}> $readonly</td>|;
427 <form method=post action=$form->{script}>
429 <input type=hidden name=id value=$form->{id}>
430 <input type=hidden name=sort value=$form->{sort}>
431 <input type=hidden name=closedto value=$form->{closedto}>
432 <input type=hidden name=locked value=$form->{locked}>
433 <input type=hidden name=title value="$title">
437 <th class=listtop>$form->{title}</th>
447 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
448 <td colspan=3>$vendor</td>
449 <input type=hidden name=selectvendor value="$form->{selectvendor}">
450 <input type=hidden name=oldvendor value="$form->{oldvendor}">
451 <input type=hidden name=vendor_id value="$form->{vendor_id}">
452 <input type=hidden name=terms value=$form->{terms}>
459 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
460 <td>$form->{creditlimit}</td>
461 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
462 <td class="plus$n">$form->{creditremaining}</td>
463 <input type=hidden name=creditlimit value=$form->{creditlimit}>
464 <input type=hidden name=creditremaining value=$form->{creditremaining}>
469 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
470 <td><select name=currency>$form->{selectcurrency}</select></td>
471 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
472 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
473 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
474 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
484 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
485 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
488 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
489 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
492 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
496 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
509 <input type=hidden name=selectAP_amount value="$form->{selectAP_amount}">
510 <input type=hidden name=AP_amount value="$form->{AP_amount}">
511 <input type=hidden name=taxchart value="$form->{taxchart}">
512 <input type=hidden name=rowcount value=$form->{rowcount}>
516 <tr class=listheading>
517 <th class=listheading style="width:15%">|
518 . $locale->text('Account') . qq|</th>
519 <th class=listheading style="width:10%">|
520 . $locale->text('Amount') . qq|</th>
521 <th class=listheading style="width:10%">|
522 . $locale->text('Tax') . qq|</th>
523 <th class=listheading style="width:5%">|
524 . $locale->text('Korrektur') . qq|</th>
525 <th class=listheading style="width:10%">|
526 . $locale->text('Taxkey') . qq|</th>
527 <th class=listheading style="width:10%">|
528 . $locale->text('Project') . qq|</th>
532 $amount = $locale->text('Amount');
533 $project = $locale->text('Project');
535 for $i (1 .. $form->{rowcount}) {
538 $form->{"amount_$i"} =
539 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
540 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
541 $selectAP_amount = $selectAP_amount_unquoted;
542 $re_amount = quotemeta($form->{"AP_amount_$i"});
544 s/option value=\"${re_amount}\"/option value=\"$form->{"AP_amount_$i"}\" selected/;
546 $tax_selected = $form->{"taxchart_$i"};
547 $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
549 qq|<td><select id="taxchart_$i" name="taxchart_$i" style="width:200px">$tax</select></td>|;
551 my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
555 <td width=50%><select name="AP_amount_$i" onChange="setTaxkey(this, $i)" style="width:100%">$selectAP_amount</select></td>
556 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
557 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
558 <td><input type="checkbox" name="korrektur_$i" value="1" "$korrektur"></td>
560 <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
561 <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
562 <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
570 ($form->{taxincluded})
571 ? $locale->text('Tax Included')
572 : $locale->text('Tax');
574 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
583 <td><select name=APselected>$form->{selectAP}</select></td>
584 <input type=hidden name=AP value="$form->{AP}">
585 <th align=left>$form->{invtotal}</th>
587 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
588 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
590 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
603 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
604 <td align=left>$notes</td>
612 <tr class=listheading>
613 <th class=listheading colspan=6>| . $locale->text('Payments') . qq|</th>
617 if ($form->{currency} eq $form->{defaultcurrency}) {
618 @column_index = qw(datepaid source memo paid AP_paid);
620 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
623 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
624 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
625 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
626 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
627 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
628 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
633 map { print "$column_data{$_}\n" } @column_index;
639 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
640 for $i (1 .. $form->{paidaccounts}) {
645 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
646 $form->{"selectAP_paid_$i"} =~
647 s/option value=\"$form->{"AP_paid_$i"}\">/option value=\"$form->{"AP_paid_$i"}\" selected>/;
650 if ($form->{"paid_$i"}) {
652 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
654 $form->{"exchangerate_$i"} =
655 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
657 $exchangerate = qq| |;
658 if ($form->{currency} ne $form->{defaultcurrency}) {
659 if ($form->{"forex_$i"}) {
661 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
664 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
669 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
672 $column_data{"paid_$i"} =
673 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
674 $column_data{"AP_paid_$i"} =
675 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
676 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
677 $column_data{"datepaid_$i"} =
678 qq|<td align=center><input name="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value=$form->{"datepaid_$i"}>
679 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
680 $column_data{"source_$i"} =
681 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
682 $column_data{"memo_$i"} =
683 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
685 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
690 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
692 map { $form->{$_} =~ s/\"/"/g } qw(selectAP_paid);
693 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
695 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
696 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
702 <td><hr size=3 noshade></td>
707 $lxdebug->leave_sub();
711 $lxdebug->enter_sub();
715 <input name=callback type=hidden value="$form->{callback}">
717 <input type=hidden name=path value=$form->{path}>
718 <input type=hidden name=login value=$form->{login}>
719 <input type=hidden name=password value=$form->{password}>
724 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
725 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
729 # print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
731 if ($form->{radier}) {
733 <input class=submit type=submit name=action value="|
734 . $locale->text('Post') . qq|">
735 <input class=submit type=submit name=action value="|
736 . $locale->text('Delete') . qq|">
741 <input class=submit type=submit name=action value="|
742 . $locale->text('Use As Template') . qq|">
746 if (($transdate > $closedto) && !$form->{id}) {
747 print qq|<input class=submit type=submit name=action value="|
748 . $locale->text('Update') . qq|">
749 <input class=submit type=submit name=action value="|
750 . $locale->text('Post') . qq|">|;
761 $lxdebug->leave_sub();
765 $lxdebug->enter_sub();
773 $form->{invtotal} = 0;
775 # $form->{selectAP_amount} = $form->{AP_amount};
776 # $form->{selectAP_amount} =~
777 # s/value=\"$form->{AP_amountselected}\"/value=\"$form->{AP_amountselected}\" selected/;
779 $form->{selectAP} = $form->{AP};
781 s/value=\"$form->{APselected}\"/value=\"$form->{APselected}\" selected/;
783 ($AP_amountaccno, $AP_amounttaxkey) =
784 split(/--/, $form->{AP_amountselected});
785 $form->{selecttaxchart} = $form->{taxchart};
786 $form->{selecttaxchart} =~
787 s/value=\"$AP_amounttaxkey--([^\"]*)\"/value=\"$AP_amounttaxkey--$1\" selected/;
791 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
792 qw(exchangerate creditlimit creditremaining);
794 @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
796 for $i (1 .. $form->{rowcount}) {
797 $form->{"amount_$i"} =
798 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
799 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
800 if ($form->{"amount_$i"}) {
803 if (!$form->{"korrektur_$i"}) {
804 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
806 if ($form->{taxincluded}) {
807 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
809 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
812 $form->{"tax_$i"} = 0;
815 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
817 $totaltax += $form->{"tax_$i"};
818 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
822 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
824 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
826 $form->{exchangerate} = $exchangerate
830 $form->check_exchangerate(
831 \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
834 $form->{invdate} = $form->{transdate};
835 $save_AP = $form->{AP};
837 $form->{AP} = $save_AP;
840 $form->{rowcount} = $count + 1;
843 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
845 for $i (1 .. $form->{paidaccounts}) {
846 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
849 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
850 } qw(paid exchangerate);
852 $totalpaid += $form->{"paid_$i"};
854 $form->{"exchangerate_$i"} = $exchangerate
856 $form->{"forex_$i"} = (
858 $form->check_exchangerate(
859 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
864 $form->{creditremaining} -=
865 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
866 $form->{oldinvtotal});
867 $form->{oldinvtotal} = $form->{invtotal};
868 $form->{oldtotalpaid} = $totalpaid;
872 $lxdebug->leave_sub();
876 $lxdebug->enter_sub();
878 # check if there is a vendor, invoice and due date
879 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
880 $form->isblank("duedate", $locale->text("Due Date missing!"));
881 $form->isblank("vendor", $locale->text('Vendor missing!'));
883 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
884 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
886 $form->error($locale->text('Cannot post transaction for a closed period!'))
887 if ($transdate <= $closedto);
889 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
890 if ($form->{currency} ne $form->{defaultcurrency});
893 for $i (1 .. $form->{paidaccounts}) {
894 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
895 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
897 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
899 $form->error($locale->text('Cannot post payment for a closed period!'))
900 if ($datepaid <= $closedto);
902 if ($form->{currency} ne $form->{defaultcurrency}) {
903 $form->{"exchangerate_$i"} = $form->{exchangerate}
904 if ($transdate == $datepaid);
905 $form->isblank("exchangerate_$i",
906 $locale->text('Exchangerate for payment missing!'));
912 # if old vendor ne vendor redo form
913 ($vendor) = split /--/, $form->{vendor};
914 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
918 ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
919 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
920 ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
921 $form->{AP}{amount_1} = $debitaccno;
922 $form->{AP}{payables} = $payablesaccno;
923 $form->{taxkey} = $taxkey;
925 $form->{id} = 0 if $form->{postasnew};
927 $form->redirect($locale->text('Transaction posted!'))
928 if (AP->post_transaction(\%myconfig, \%$form));
929 $form->error($locale->text('Cannot post transaction!'));
931 $lxdebug->leave_sub();
935 $lxdebug->enter_sub();
937 $form->{postasnew} = 1;
940 $lxdebug->leave_sub();
943 sub use_as_template {
944 $lxdebug->enter_sub();
946 map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
947 $form->{paidaccounts} = 1;
949 $form->{invdate} = $form->current_date(\%myconfig);
952 $lxdebug->leave_sub();
956 $lxdebug->enter_sub();
958 $form->{title} = $locale->text('Confirm!');
962 delete $form->{header};
967 <form method=post action=$form->{script}>
970 foreach $key (keys %$form) {
971 $form->{$key} =~ s/\"/"/g;
972 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
976 <h2 class=confirm>$form->{title}</h2>
979 . $locale->text('Are you sure you want to delete Transaction')
980 . qq| $form->{invnumber}</h4>
982 <input name=action class=submit type=submit value="|
983 . $locale->text('Yes') . qq|">
990 $lxdebug->leave_sub();
994 $lxdebug->enter_sub();
996 $form->redirect($locale->text('Transaction deleted!'))
997 if (AP->delete_transaction(\%myconfig, \%$form, $spool));
998 $form->error($locale->text('Cannot delete transaction!'));
1000 $lxdebug->leave_sub();
1004 $lxdebug->enter_sub();
1006 # setup vendor selection
1007 $form->all_vc(\%myconfig, "vendor", "AP");
1009 if (@{ $form->{all_vendor} }) {
1010 map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
1011 @{ $form->{all_vendor} };
1012 $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
1014 $vendor = qq|<input name=vendor size=35>|;
1018 if (@{ $form->{all_departments} }) {
1019 $form->{selectdepartment} = "<option>\n";
1022 $form->{selectdepartment} .=
1023 "<option>$_->{description}--$_->{id}\n"
1024 } (@{ $form->{all_departments} });
1029 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1030 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1032 | if $form->{selectdepartment};
1034 $form->{title} = $locale->text('AP Transactions');
1036 # use JavaScript Calendar or not
1037 $form->{jsscript} = $jscalendar;
1039 if ($form->{jsscript}) {
1041 # with JavaScript Calendar
1043 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1044 <input type=button name=transdatefrom id="trigger1" value=|
1045 . $locale->text('button') . qq|></td>
1048 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1049 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1050 . $locale->text('button') . qq|></td>
1055 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1056 "transdateto", "BL", "trigger2");
1059 # without JavaScript Calendar
1061 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1063 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1071 <form method=post action=$form->{script}>
1075 <th class=listtop>$form->{title}</th>
1077 <tr height="5"></tr>
1082 <th align=right>| . $locale->text('Vendor') . qq|</th>
1083 <td colspan=3>$vendor</td>
1087 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1088 <td colspan=3><input name=invnumber size=20></td>
1091 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1092 <td colspan=3><input name=ordnumber size=20></td>
1095 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1096 <td colspan=3><input name=notes size=40></td>
1099 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1101 <th align=right>| . $locale->text('Bis') . qq|</th>
1104 <input type=hidden name=sort value=transdate>
1112 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1116 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1117 <td nowrap>| . $locale->text('Open') . qq|</td>
1118 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1119 <td nowrap>| . $locale->text('Closed') . qq|</td>
1122 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1123 <td nowrap>| . $locale->text('ID') . qq|</td>
1124 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1125 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1126 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1127 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1130 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1131 <td nowrap>| . $locale->text('Vendor') . qq|</td>
1132 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1133 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1134 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1135 <td nowrap>| . $locale->text('Amount') . qq|</td>
1138 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1139 <td nowrap>| . $locale->text('Tax') . qq|</td>
1140 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1141 <td nowrap>| . $locale->text('Total') . qq|</td>
1142 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1143 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1146 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1147 <td nowrap>| . $locale->text('Paid') . qq|</td>
1148 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1149 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1150 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1151 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1154 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1155 <td nowrap>| . $locale->text('Notes') . qq|</td>
1156 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1157 <td nowrap>| . $locale->text('Employee') . qq|</td>
1160 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1161 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1170 <td><hr size=3 noshade></td>
1177 <input type=hidden name=nextsub value=$form->{nextsub}>
1178 <input type=hidden name=path value=$form->{path}>
1179 <input type=hidden name=login value=$form->{login}>
1180 <input type=hidden name=password value=$form->{password}>
1182 <input class=submit type=submit name=action value="|
1183 . $locale->text('Continue') . qq|">
1190 $lxdebug->leave_sub();
1193 sub ap_transactions {
1194 $lxdebug->enter_sub();
1196 $form->{vendor} = $form->unescape($form->{vendor});
1197 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
1199 AP->ap_transactions(\%myconfig, \%$form);
1202 "$form->{script}?action=ap_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1205 if ($form->{vendor}) {
1206 $callback .= "&vendor=" . $form->escape($form->{vendor}, 1);
1207 $href .= "&vendor=" . $form->escape($form->{vendor});
1208 $option .= $locale->text('Vendor') . " : $form->{vendor}";
1210 if ($form->{department}) {
1211 $callback .= "&department=" . $form->escape($form->{department}, 1);
1212 $href .= "&department=" . $form->escape($form->{department});
1213 ($department) = split /--/, $form->{department};
1214 $option .= "\n<br>" if ($option);
1215 $option .= $locale->text('Department') . " : $department";
1217 if ($form->{invnumber}) {
1218 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1219 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1220 $option .= "\n<br>" if ($option);
1221 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1223 if ($form->{ordnumber}) {
1224 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1225 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1226 $option .= "\n<br>" if ($option);
1227 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1229 if ($form->{notes}) {
1230 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1231 $href .= "¬es=" . $form->escape($form->{notes});
1232 $option .= "\n<br>" if $option;
1233 $option .= $locale->text('Notes') . " : $form->{notes}";
1236 if ($form->{transdatefrom}) {
1237 $callback .= "&transdatefrom=$form->{transdatefrom}";
1238 $href .= "&transdatefrom=$form->{transdatefrom}";
1239 $option .= "\n<br>" if ($option);
1241 $locale->text('From') . " "
1242 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1244 if ($form->{transdateto}) {
1245 $callback .= "&transdateto=$form->{transdateto}";
1246 $href .= "&transdateto=$form->{transdateto}";
1247 $option .= "\n<br>" if ($option);
1249 $locale->text('Bis') . " "
1250 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1252 if ($form->{open}) {
1253 $callback .= "&open=$form->{open}";
1254 $href .= "&open=$form->{open}";
1255 $option .= "\n<br>" if ($option);
1256 $option .= $locale->text('Open');
1258 if ($form->{closed}) {
1259 $callback .= "&closed=$form->{closed}";
1260 $href .= "&closed=$form->{closed}";
1261 $option .= "\n<br>" if ($option);
1262 $option .= $locale->text('Closed');
1265 @columns = $form->sort_columns(
1266 qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee)
1269 foreach $item (@columns) {
1270 if ($form->{"l_$item"} eq "Y") {
1271 push @column_index, $item;
1273 # add column to href and callback
1274 $callback .= "&l_$item=Y";
1275 $href .= "&l_$item=Y";
1279 if ($form->{l_subtotal} eq 'Y') {
1280 $callback .= "&l_subtotal=Y";
1281 $href .= "&l_subtotal=Y";
1284 $column_header{id} =
1285 qq|<th><a class=listheading href=$href&sort=id>|
1286 . $locale->text('ID')
1288 $column_header{transdate} =
1289 qq|<th><a class=listheading href=$href&sort=transdate>|
1290 . $locale->text('Date')
1292 $column_header{duedate} =
1293 qq|<th><a class=listheading href=$href&sort=duedate>|
1294 . $locale->text('Due Date')
1296 $column_header{due} =
1297 qq|<th class=listheading>| . $locale->text('Amount Due') . qq|</th>|;
1298 $column_header{invnumber} =
1299 qq|<th><a class=listheading href=$href&sort=invnumber>|
1300 . $locale->text('Invoice')
1302 $column_header{ordnumber} =
1303 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1304 . $locale->text('Order')
1306 $column_header{name} =
1307 qq|<th><a class=listheading href=$href&sort=name>|
1308 . $locale->text('Vendor')
1310 $column_header{netamount} =
1311 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1312 $column_header{tax} =
1313 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1314 $column_header{amount} =
1315 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1316 $column_header{paid} =
1317 qq|<th class=listheading>| . $locale->text('Paid') . qq|</th>|;
1318 $column_header{datepaid} =
1319 qq|<th><a class=listheading href=$href&sort=datepaid>|
1320 . $locale->text('Date Paid')
1322 $column_header{notes} =
1323 qq|<th class=listheading>| . $locale->text('Notes') . qq|</th>|;
1324 $column_header{employee} =
1325 "<th><a class=listheading href=$href&sort=employee>"
1326 . $locale->text('Employee') . "</th>";
1328 $form->{title} = $locale->text('AP Transactions');
1337 <th class=listtop>$form->{title}</th>
1339 <tr height="5"></tr>
1346 <tr class=listheading>
1349 map { print "\n$column_header{$_}" } @column_index;
1355 # add sort and escape callback
1356 $form->{callback} = "$callback&sort=$form->{sort}";
1357 $callback = $form->escape($form->{callback});
1359 if (@{ $form->{AP} }) {
1360 $sameitem = $form->{AP}->[0]->{ $form->{sort} };
1363 # sums and tax on reports by Antonio Gallardo
1365 foreach $ap (@{ $form->{AP} }) {
1367 if ($form->{l_subtotal} eq 'Y') {
1368 if ($sameitem ne $ap->{ $form->{sort} }) {
1370 $sameitem = $ap->{ $form->{sort} };
1374 $column_data{netamount} =
1376 . $form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")
1378 $column_data{tax} = "<td align=right>"
1379 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount},
1382 $column_data{amount} =
1384 . $form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>";
1385 $column_data{paid} =
1387 . $form->format_amount(\%myconfig, $ap->{paid}, 2, " ") . "</td>";
1388 $column_data{due} = "<td align=right>"
1389 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid},
1393 $totalnetamount += $ap->{netamount};
1394 $totalamount += $ap->{amount};
1395 $totalpaid += $ap->{paid};
1396 $totaldue += ($ap->{amount} - $ap->{paid});
1398 $subtotalnetamount += $ap->{netamount};
1399 $subtotalamount += $ap->{amount};
1400 $subtotalpaid += $ap->{paid};
1401 $subtotaldue += ($ap->{amount} - $ap->{paid});
1403 $column_data{transdate} = "<td>$ap->{transdate} </td>";
1404 $column_data{duedate} = "<td>$ap->{duedate} </td>";
1405 $column_data{datepaid} = "<td>$ap->{datepaid} </td>";
1407 $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
1409 $column_data{invnumber} =
1410 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>|;
1411 $column_data{id} = "<td>$ap->{id}</td>";
1412 $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>";
1413 $column_data{name} = "<td>$ap->{name}</td>";
1414 $ap->{notes} =~ s/\r\n/<br>/g;
1415 $column_data{notes} = "<td>$ap->{notes} </td>";
1416 $column_data{employee} = "<td>$ap->{employee} </td>";
1421 <tr class=listrow$i >
1424 map { print "\n$column_data{$_}" } @column_index;
1432 if ($form->{l_subtotal} eq 'Y') {
1438 <tr class=listtotal>
1441 map { $column_data{$_} = "<td> </td>" } @column_index;
1443 $column_data{netamount} =
1444 "<th class=listtotal align=right>"
1445 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1446 $column_data{tax} = "<th class=listtotal align=right>"
1447 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1450 $column_data{amount} =
1451 "<th class=listtotal align=right>"
1452 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1453 $column_data{paid} =
1454 "<th class=listtotal align=right>"
1455 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1457 "<th class=listtotal align=right>"
1458 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1460 map { print "$column_data{$_}\n" } @column_index;
1468 <td><hr size=3 noshade></td>
1473 <form method=post action=$form->{script}>
1475 <input name=callback type=hidden value="$form->{callback}">
1477 <input type=hidden name=path value=$form->{path}>
1478 <input type=hidden name=login value=$form->{login}>
1479 <input type=hidden name=password value=$form->{password}>
1481 <input class=submit type=submit name=action value="|
1482 . $locale->text('AP Transaction') . qq|">
1484 <input class=submit type=submit name=action value="|
1485 . $locale->text('Vendor Invoice') . qq|">
1493 $lxdebug->leave_sub();
1497 $lxdebug->enter_sub();
1499 map { $column_data{$_} = "<td> </td>" } @column_index;
1501 $column_data{netamount} =
1502 "<th class=listsubtotal align=right>"
1503 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1505 $column_data{tax} = "<th class=listsubtotal align=right>"
1506 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1509 $column_data{amount} =
1510 "<th class=listsubtotal align=right>"
1511 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1512 $column_data{paid} =
1513 "<th class=listsubtotal align=right>"
1514 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1516 "<th class=listsubtotal align=right>"
1517 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1519 $subtotalnetamount = 0;
1520 $subtotalamount = 0;
1524 print "<tr class=listsubtotal>";
1526 map { print "\n$column_data{$_}" } @column_index;
1532 $lxdebug->leave_sub();