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 "bin/mozilla/arap.pl";
40 require "bin/mozilla/common.pl";
41 require "bin/mozilla/drafts.pl";
47 # this is for our long dates
48 # $locale->text('January')
49 # $locale->text('February')
50 # $locale->text('March')
51 # $locale->text('April')
52 # $locale->text('May ')
53 # $locale->text('June')
54 # $locale->text('July')
55 # $locale->text('August')
56 # $locale->text('September')
57 # $locale->text('October')
58 # $locale->text('November')
59 # $locale->text('December')
61 # this is for our short month
62 # $locale->text('Jan')
63 # $locale->text('Feb')
64 # $locale->text('Mar')
65 # $locale->text('Apr')
66 # $locale->text('May')
67 # $locale->text('Jun')
68 # $locale->text('Jul')
69 # $locale->text('Aug')
70 # $locale->text('Sep')
71 # $locale->text('Oct')
72 # $locale->text('Nov')
73 # $locale->text('Dec')
76 $lxdebug->enter_sub();
78 return $lxdebug->leave_sub() if (load_draft_maybe());
80 $form->{title} = "Add";
83 "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
84 unless $form->{callback};
86 AP->get_transdate(\%myconfig, $form);
87 $form->{initial_transdate} = $form->{transdate};
89 $form->{transdate} = $form->{initial_transdate};
92 $lxdebug->leave_sub();
96 $lxdebug->enter_sub();
98 $form->{title} = "Edit";
103 $lxdebug->leave_sub();
107 $lxdebug->enter_sub();
112 $lxdebug->leave_sub();
116 $lxdebug->enter_sub();
118 $form->create_links("AP", \%myconfig, "vendor");
119 $taxincluded = $form->{taxincluded};
120 $duedate = $form->{duedate};
122 IR->get_vendor(\%myconfig, \%$form);
123 $form->{taxincluded} = $taxincluded;
124 $form->{duedate} = $duedate if $duedate;
125 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
126 $form->{rowcount} = 1;
128 # build the popup menus
129 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
132 $form->{notes} = $form->{intnotes} unless $form->{notes};
135 @curr = split(/:/, $form->{currencies});
137 $form->{defaultcurrency} = $curr[0];
139 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
142 if (@{ $form->{all_vendor} }) {
143 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
144 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
145 (@{ $form->{all_vendor} });
149 if (@{ $form->{all_departments} }) {
150 $form->{selectdepartment} = "<option>\n";
151 $form->{department} = "$form->{department}--$form->{department_id}";
154 $form->{selectdepartment} .=
155 "<option>$_->{description}--$_->{id}\n"
156 } (@{ $form->{all_departments} });
159 $form->{employee} = "$form->{employee}--$form->{employee_id}";
162 $form->{forex} = $form->{exchangerate};
163 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
165 foreach $key (keys %{ $form->{AP_links} }) {
166 foreach $ref (@{ $form->{AP_links}{$key} }) {
167 if ($key eq "AP_paid") {
168 $form->{"select$key"} .=
169 "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
171 $form->{"select$key"} .=
172 "<option value=\"$ref->{accno}--$ref->{tax_id}\">$ref->{accno}--$ref->{description}</option>\n";
176 $form->{$key} = $form->{"select$key"};
178 # if there is a value we have an old entry
182 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
184 if ($key eq "AP_paid") {
186 $form->{"AP_paid_$j"} =
187 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
188 $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
189 $form->{"datepaid_$j"} =
190 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
191 $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
192 $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
194 $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
195 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
196 $form->{"AP_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
197 $form->{"paid_project_id_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{project_id};
198 $form->{paidaccounts}++;
204 if (($key eq "AP_tax") || ($key eq "AR_tax")) {
205 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
206 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
207 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
209 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
212 if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
214 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
217 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
219 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
221 $index = $form->{acc_trans}{$key}->[$i - 1]->{index};
222 $form->{"tax_$index"} =
223 $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
224 $totaltax += $form->{"tax_$index"};
228 $form->{"${akey}_$k"} =
230 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
232 if ($akey eq 'amount') {
234 $form->{"${akey}_$i"} *= -1;
235 $totalamount += $form->{"${akey}_$i"};
236 $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
237 $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} =
238 "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
239 $form->{"project_id_$k"} =
240 "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
242 $form->{"${key}_$k"} =
243 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
244 my $q_description = quotemeta($form->{acc_trans}{$key}->[$i-1]->{description});
245 $form->{"select${key}"} =~
246 /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{accno}--[^\"]*)\">$form->{acc_trans}{$key}->[$i-1]->{accno}--${q_description}<\/option>\n/;
247 $form->{"${key}_$k"} = $1;
250 $form->{APselected} = $form->{acc_trans}{$key}->[$i-1]->{accno};
252 } elsif ($akey eq 'amount') {
253 $form->{"${key}_$k"} = $form->{acc_trans}{$key}->[$i-1]->{accno} .
254 "--" . $form->{acc_trans}{$key}->[$i-1]->{id};
255 $form->{"taxchart_$k"} = $form->{acc_trans}{$key}->[$i-1]->{id} .
256 "--" . $form->{acc_trans}{$key}->[$i-1]->{rate};
263 $form->{taxincluded} = $taxincluded if ($form->{id});
264 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
266 if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
268 # add tax to amounts and invtotal
269 for $i (1 .. $form->{rowcount}) {
271 ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
272 $tax = $form->round_amount($taxamount, 2);
273 $diff += ($taxamount - $tax);
274 $form->{"amount_$i"} += $form->{"tax_$i"};
276 $form->{amount_1} += $form->round_amount($diff, 2);
279 $taxamount = $form->round_amount($taxamount, 2);
281 $form->{invtotal} = $totalamount + $totaltax;
284 ($form->datetonum($form->{transdate}, \%myconfig) <=
285 $form->datetonum($form->{closedto}, \%myconfig));
287 $lxdebug->leave_sub();
291 $lxdebug->enter_sub();
293 $title = $form->{title};
294 $form->{title} = $locale->text("$title Accounts Payables Transaction");
296 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
298 # type=submit $locale->text('Add Accounts Payables Transaction')
299 # type=submit $locale->text('Edit Accounts Payables Transaction')
301 $form->{javascript} = qq|<script type="text/javascript">
303 function setTaxkey(accno, row) {
304 var taxkey = accno.options[accno.selectedIndex].value;
305 var reg = /--([0-9]*)/;
306 var found = reg.exec(taxkey);
307 var index = found[1];
308 index = parseInt(index);
309 var tax = 'taxchart_' + row;
310 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
311 var reg2 = new RegExp("^"+ index, "");
312 if (reg2.exec(document.getElementById(tax).options[i].value)) {
313 document.getElementById(tax).options[i].selected = true;
320 # show history button
321 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
322 #/show hhistory button
324 # set option selected
325 foreach $item (qw(vendor currency department)) {
326 $form->{"select$item"} =~ s/ selected//;
327 $form->{"select$item"} =~
328 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
330 $readonly = ($form->{id}) ? "readonly" : "";
333 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
334 $readonly = ($form->{radier}) ? "" : $readonly;
337 $form->{exchangerate} =
338 $form->format_amount(\%myconfig, $form->{exchangerate});
340 $form->{creditlimit} =
341 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
342 $form->{creditremaining} =
343 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
346 <input type=hidden name=forex value=$form->{forex}>
348 if ($form->{currency} ne $form->{defaultcurrency}) {
349 if ($form->{forex}) {
352 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
353 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
358 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
359 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
368 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
369 <th align=left nowrap>|
370 . $locale->text('Tax Included') . qq|</th>
374 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
378 qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
382 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
383 <td colspan=3><select name=department>$form->{selectdepartment}</select>
384 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
387 | if $form->{selectdepartment};
389 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
392 ($form->{selectvendor})
393 ? qq|<select name="vendor"
394 onchange="document.getElementById('update_button').click();">$form->{
395 selectvendor } </select>|
396 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
398 my @old_project_ids = ();
399 map({ push(@old_project_ids, $form->{"project_id_$_"})
400 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
402 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
404 "old_id" => \@old_project_ids },
405 "charts" => { "key" => "ALL_CHARTS",
406 "transdate" => $form->{transdate} },
407 "taxcharts" => "ALL_TAXCHARTS");
409 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
410 @{ $form->{ALL_CHARTS} });
412 my %project_labels = ();
413 my @project_values = ("");
414 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
415 push(@project_values, $item->{"id"});
416 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
419 my (%AP_amount_labels, @AP_amount_values);
420 my (%AP_labels, @AP_values);
421 my (%AP_paid_labels, @AP_paid_values);
425 foreach my $item (@{ $form->{ALL_CHARTS} }) {
426 if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) {
427 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
428 my $key = "$item->{accno}--$item->{tax_id}";
429 push(@AP_amount_values, $key);
430 $AP_amount_labels{$key} =
431 "$item->{accno}--$item->{description}";
433 } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) {
434 push(@AP_values, $item->{accno});
435 $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
437 } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) {
438 push(@AP_paid_values, $item->{accno});
439 $AP_paid_labels{$item->{accno}} =
440 "$item->{accno}--$item->{description}";
443 $charts{$item->{accno}} = $item;
446 my %taxchart_labels = ();
447 my @taxchart_values = ();
449 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
450 my $key = "$item->{id}--$item->{rate}";
451 $taxchart_init = $key if ($taxchart_init eq $item->{id});
452 push(@taxchart_values, $key);
453 $taxchart_labels{$key} =
454 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
455 $taxcharts{$item->{id}} = $item;
458 # use JavaScript Calendar or not
459 $form->{jsscript} = 1;
461 if ($form->{jsscript}) {
463 # with JavaScript Calendar
465 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
466 <td><input type=button name=transdate id="trigger1" value=|
467 . $locale->text('button') . qq|></td>
470 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
471 <td><input type=button name=duedate id="trigger2" value=|
472 . $locale->text('button') . qq|></td></td>
477 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
478 "duedate", "BL", "trigger2");
481 # without JavaScript Calendar
483 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
485 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
487 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
488 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
491 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
492 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
494 <body onLoad="$onload">
496 <form method=post action=$form->{script}>
498 <input type=hidden name=id value=$form->{id}>
499 <input type=hidden name=sort value=$form->{sort}>
500 <input type=hidden name=closedto value=$form->{closedto}>
501 <input type=hidden name=locked value=$form->{locked}>
502 <input type=hidden name=title value="$title">
504 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
508 <th class=listtop>$form->{title}</th>
518 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
519 <td colspan=3>$vendor <input type="button" value="?" onclick="show_vc_details('vendor')"></td>
520 <input type=hidden name=selectvendor value="$form->{selectvendor}">
521 <input type=hidden name=oldvendor value="$form->{oldvendor}">
522 <input type=hidden name=vendor_id value="$form->{vendor_id}">
523 <input type=hidden name=terms value=$form->{terms}>
530 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
531 <td>$form->{creditlimit}</td>
532 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
533 <td class="plus$n">$form->{creditremaining}</td>
534 <input type=hidden name=creditlimit value=$form->{creditlimit}>
535 <input type=hidden name=creditremaining value=$form->{creditremaining}>
540 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
541 <td><select name=currency>$form->{selectcurrency}</select></td>
542 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
543 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
544 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
545 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
555 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
556 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
559 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
560 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
563 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
567 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
580 <input type=hidden name=rowcount value=$form->{rowcount}>
584 <tr class=listheading>
585 <th class=listheading style="width:15%">|
586 . $locale->text('Account') . qq|</th>
587 <th class=listheading style="width:10%">|
588 . $locale->text('Amount') . qq|</th>
589 <th class=listheading style="width:10%">|
590 . $locale->text('Tax') . qq|</th>
591 <th class=listheading style="width:5%">|
592 . $locale->text('Korrektur') . qq|</th>
593 <th class=listheading style="width:10%">|
594 . $locale->text('Taxkey') . qq|</th>
595 <th class=listheading style="width:10%">|
596 . $locale->text('Project') . qq|</th>
600 $amount = $locale->text('Amount');
601 $project = $locale->text('Project');
603 for $i (1 .. $form->{rowcount}) {
606 $form->{"amount_$i"} =
607 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
608 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
610 my $selected_accno_full;
611 my ($accno_row) = split(/--/, $form->{"AP_amount_$i"});
612 my $item = $charts{$accno_row};
613 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
615 my $selected_taxchart = $form->{"taxchart_$i"};
616 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
617 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AP_amount_$i"});
619 if ($previous_accno &&
620 ($previous_accno eq $selected_accno) &&
621 ($previous_tax_id ne $selected_tax_id)) {
622 my $item = $taxcharts{$selected_tax_id};
623 $selected_taxchart = "$item->{id}--$item->{rate}";
626 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
629 NTI($cgi->popup_menu('-name' => "AP_amount_$i",
630 '-id' => "AP_amount_$i",
631 '-style' => 'width:400px',
632 '-onChange' => "setTaxkey(this, $i)",
633 '-values' => \@AP_amount_values,
634 '-labels' => \%AP_amount_labels,
635 '-default' => $selected_accno_full))
636 . $cgi->hidden('-name' => "previous_AP_amount_$i",
637 '-default' => $selected_accno_full);
640 NTI($cgi->popup_menu('-name' => "taxchart_$i",
641 '-id' => "taxchart_$i",
642 '-style' => 'width:200px',
643 '-values' => \@taxchart_values,
644 '-labels' => \%taxchart_labels,
645 '-default' => $selected_taxchart))
648 my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
651 NTI($cgi->popup_menu('-name' => "project_id_$i",
652 '-values' => \@project_values,
653 '-labels' => \%project_labels,
654 '-default' => $form->{"project_id_$i"} ));
658 <td>$selectAP_amount</td>
659 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
660 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
661 <td><input type="checkbox" name="korrektur_$i" value="1" "$korrektur"></td>
663 <td>$projectnumber</td>
671 ($form->{taxincluded})
672 ? $locale->text('Tax Included')
673 : $locale->text('Tax');
675 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
678 NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
679 '-style' => 'width:400px',
680 '-values' => \@AP_values, '-labels' => \%AP_labels,
681 '-default' => $form->{APselected}));
689 <td>${APselected}</td>
690 <th align=left>$form->{invtotal}</th>
692 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
693 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
695 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
708 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
709 <td align=left>$notes</td>
717 <tr class=listheading>
718 <th class=listheading colspan=7>| . $locale->text('Payments') . qq|</th>
722 if ($form->{currency} eq $form->{defaultcurrency}) {
723 @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
725 @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
728 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
729 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
730 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
731 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
732 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
733 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
734 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
739 map { print "$column_data{$_}\n" } @column_index;
745 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
746 for $i (1 .. $form->{paidaccounts}) {
752 NTI($cgi->popup_menu('-name' => "AP_paid_$i",
753 '-id' => "AP_paid_$i",
754 '-values' => \@AP_paid_values,
755 '-labels' => \%AP_paid_labels,
756 '-default' => $form->{"AP_paid_$i"}));
759 if ($form->{"paid_$i"}) {
761 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
763 $form->{"exchangerate_$i"} =
764 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
766 $exchangerate = qq| |;
767 if ($form->{currency} ne $form->{defaultcurrency}) {
768 if ($form->{"forex_$i"}) {
770 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
773 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
778 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
781 $column_data{"paid_$i"} =
782 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
783 $column_data{"AP_paid_$i"} =
784 qq|<td align=center>${selectAP_paid}</td>|;
785 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
786 $column_data{"datepaid_$i"} =
787 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
788 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
789 $column_data{"source_$i"} =
790 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
791 $column_data{"memo_$i"} =
792 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
793 $column_data{"paid_project_id_$i"} =
795 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
796 '-values' => \@project_values,
797 '-labels' => \%project_labels,
798 '-default' => $form->{"paid_project_id_$i"} ))
801 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
806 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
808 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
810 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
816 <td><hr size=3 noshade></td>
821 $lxdebug->leave_sub();
825 $lxdebug->enter_sub();
829 <input name=callback type=hidden value="$form->{callback}">
830 <input name="gldate" type="hidden" value="| . Q($form->{gldate}) . qq|">
832 <input type=hidden name=login value=$form->{login}>
833 <input type=hidden name=password value=$form->{password}>
835 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
836 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
842 if (!$form->{id} && $form->{draft_id}) {
843 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
844 '-value' => 1, '-checked' => $form->{remove_draft},
846 qq| <label for="remove_draft">| .
847 $locale->text("Remove draft when posting") .
851 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
852 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
854 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
855 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|
856 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap') && !$form->{paid_1});
858 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">|;
861 if ($form->{radier}) {
862 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
863 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">
867 print qq| <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|">
868 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
870 } elsif (($transdate > $closedto) && !$form->{id}) {
872 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
873 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
875 # button for saving history
876 if($form->{id} ne "") {
877 print qq| <input type="button" class="submit" onclick="set_history_window($form->{id});" name="history" id="history" value="| . $locale->text('history') . qq|">|;
879 # /button for saving history
887 $lxdebug->leave_sub();
891 $lxdebug->enter_sub();
895 $form->{invtotal} = 0;
897 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
898 qw(exchangerate creditlimit creditremaining);
900 @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
902 for $i (1 .. $form->{rowcount}) {
903 $form->{"amount_$i"} =
904 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
905 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
906 if ($form->{"amount_$i"}) {
909 if (!$form->{"korrektur_$i"}) {
910 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
912 if ($form->{taxincluded}) {
913 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
915 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
918 $form->{"tax_$i"} = 0;
921 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
923 $totaltax += $form->{"tax_$i"};
924 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
928 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
930 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
932 $form->{exchangerate} = $exchangerate
936 $form->check_exchangerate(
937 \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
940 $form->{invdate} = $form->{transdate};
941 $save_AP = $form->{AP};
943 $form->{AP} = $save_AP;
945 $form->{rowcount} = $count + 1;
948 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
950 for $i (1 .. $form->{paidaccounts}) {
951 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
954 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
955 } qw(paid exchangerate);
957 $totalpaid += $form->{"paid_$i"};
959 $form->{"exchangerate_$i"} = $exchangerate
961 $form->{"forex_$i"} = (
963 $form->check_exchangerate(
964 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
969 $form->{creditremaining} -=
970 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
971 $form->{oldinvtotal});
972 $form->{oldinvtotal} = $form->{invtotal};
973 $form->{oldtotalpaid} = $totalpaid;
977 $lxdebug->leave_sub();
982 $lxdebug->enter_sub();
983 for $i (1 .. $form->{paidaccounts}) {
984 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
985 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
987 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
989 $form->error($locale->text('Cannot post payment for a closed period!'))
990 if ($datepaid <= $closedto);
992 if ($form->{currency} ne $form->{defaultcurrency}) {
993 $form->{"exchangerate_$i"} = $form->{exchangerate}
994 if ($invdate == $datepaid);
995 $form->isblank("exchangerate_$i",
996 $locale->text('Exchangerate for payment missing!'));
1001 ($form->{AP}) = split /--/, $form->{AP};
1002 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1003 $form->redirect($locale->text(' Payment posted!'))
1004 if (AP->post_payment(\%myconfig, \%$form));
1005 $form->error($locale->text('Cannot post payment!'));
1008 $lxdebug->leave_sub();
1013 $lxdebug->enter_sub();
1015 # check if there is a vendor, invoice and due date
1016 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
1017 $form->isblank("duedate", $locale->text("Due Date missing!"));
1018 $form->isblank("vendor", $locale->text('Vendor missing!'));
1020 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1021 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1022 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
1024 my $zero_amount_posting = 1;
1025 for $i (1 .. $form->{rowcount}) {
1026 if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
1027 $zero_amount_posting = 0;
1032 $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
1034 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1035 if ($form->{currency} ne $form->{defaultcurrency});
1036 delete($form->{AP});
1038 for $i (1 .. $form->{paidaccounts}) {
1039 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1040 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1042 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1044 $form->error($locale->text('Cannot post payment for a closed period!'))
1045 if ($datepaid <= $closedto);
1047 if ($form->{currency} ne $form->{defaultcurrency}) {
1048 $form->{"exchangerate_$i"} = $form->{exchangerate}
1049 if ($transdate == $datepaid);
1050 $form->isblank("exchangerate_$i",
1051 $locale->text('Exchangerate for payment missing!'));
1057 # if old vendor ne vendor redo form
1058 ($vendor) = split /--/, $form->{vendor};
1059 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
1063 ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
1064 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
1065 ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
1066 $form->{AP}{amount_1} = $debitaccno;
1067 $form->{AP}{payables} = $payablesaccno;
1068 $form->{taxkey} = $taxkey;
1070 $form->{id} = 0 if $form->{postasnew};
1072 if (AP->post_transaction(\%myconfig, \%$form)) {
1073 # saving the history
1074 if(!exists $form->{addition} && $form->{id} ne "") {
1075 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1076 $form->{addition} = "POSTED";
1077 $form->save_history($form->dbconnect(\%myconfig));
1079 # /saving the history
1080 remove_draft() if $form->{remove_draft};
1081 $form->redirect($locale->text('Transaction posted!'));
1083 $form->error($locale->text('Cannot post transaction!'));
1085 $lxdebug->leave_sub();
1089 $lxdebug->enter_sub();
1091 $form->{postasnew} = 1;
1092 # saving the history
1093 if(!exists $form->{addition} && $form->{id} ne "") {
1094 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1095 $form->{addition} = "POSTED AS NEW";
1096 $form->save_history($form->dbconnect(\%myconfig));
1098 # /saving the history
1101 $lxdebug->leave_sub();
1104 sub use_as_template {
1105 $lxdebug->enter_sub();
1107 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);
1108 $form->{paidaccounts} = 1;
1109 $form->{rowcount}--;
1110 $form->{invdate} = $form->current_date(\%myconfig);
1113 $lxdebug->leave_sub();
1117 $lxdebug->enter_sub();
1119 $form->{title} = $locale->text('Confirm!');
1123 delete $form->{header};
1128 <form method=post action=$form->{script}>
1131 foreach $key (keys %$form) {
1132 $form->{$key} =~ s/\"/"/g;
1133 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1137 <h2 class=confirm>$form->{title}</h2>
1140 . $locale->text('Are you sure you want to delete Transaction')
1141 . qq| $form->{invnumber}</h4>
1143 <input name=action class=submit type=submit value="|
1144 . $locale->text('Yes') . qq|">
1151 $lxdebug->leave_sub();
1155 $lxdebug->enter_sub();
1156 if (AP->delete_transaction(\%myconfig, \%$form, $spool)) {
1157 # saving the history
1158 if(!exists $form->{addition}) {
1159 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1160 $form->{addition} = "DELETED";
1161 $form->save_history($form->dbconnect(\%myconfig));
1163 # /saving the history
1164 $form->redirect($locale->text('Transaction deleted!'));
1166 $form->error($locale->text('Cannot delete transaction!'));
1168 $lxdebug->leave_sub();
1172 $lxdebug->enter_sub();
1174 # setup vendor selection
1175 $form->all_vc(\%myconfig, "vendor", "AP");
1177 if (@{ $form->{all_vendor} }) {
1178 map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
1179 @{ $form->{all_vendor} };
1180 $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
1182 $vendor = qq|<input name=vendor size=35>|;
1186 if (@{ $form->{all_departments} }) {
1187 $form->{selectdepartment} = "<option>\n";
1190 $form->{selectdepartment} .=
1191 "<option>$_->{description}--$_->{id}\n"
1192 } (@{ $form->{all_departments} });
1197 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1198 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1200 | if $form->{selectdepartment};
1202 $form->{title} = $locale->text('AP Transactions');
1204 # use JavaScript Calendar or not
1205 $form->{jsscript} = 1;
1207 if ($form->{jsscript}) {
1209 # with JavaScript Calendar
1211 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1212 <input type=button name=transdatefrom id="trigger1" value=|
1213 . $locale->text('button') . qq|></td>
1216 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1217 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1218 . $locale->text('button') . qq|></td>
1223 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1224 "transdateto", "BL", "trigger2");
1227 # without JavaScript Calendar
1229 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1231 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1234 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1239 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1240 push(@values, $item->{"id"});
1241 $labels{$item->{"id"}} = $item->{"projectnumber"};
1244 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1245 '-labels' => \%labels));
1246 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1248 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1249 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1251 <body onLoad="$onload">
1253 <form method=post action=$form->{script}>
1257 <th class=listtop>$form->{title}</th>
1259 <tr height="5"></tr>
1264 <th align=right>| . $locale->text('Vendor') . qq|</th>
1265 <td colspan=3>$vendor</td>
1269 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1270 <td colspan=3><input name=invnumber size=20></td>
1273 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1274 <td colspan=3><input name=ordnumber size=20></td>
1277 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1278 <td colspan=3><input name=notes size=40></td>
1281 <th align="right">| . $locale->text("Project Number") . qq|</th>
1282 <td colspan="3">$projectnumber</td>
1285 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1287 <th align=right>| . $locale->text('Bis') . qq|</th>
1290 <input type=hidden name=sort value=transdate>
1298 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1302 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1303 <td nowrap>| . $locale->text('Open') . qq|</td>
1304 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1305 <td nowrap>| . $locale->text('Closed') . qq|</td>
1308 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1309 <td nowrap>| . $locale->text('ID') . qq|</td>
1310 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1311 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1312 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1313 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1316 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1317 <td nowrap>| . $locale->text('Vendor') . qq|</td>
1318 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1319 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1320 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1321 <td nowrap>| . $locale->text('Amount') . qq|</td>
1324 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1325 <td nowrap>| . $locale->text('Tax') . qq|</td>
1326 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1327 <td nowrap>| . $locale->text('Total') . qq|</td>
1328 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1329 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1332 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1333 <td nowrap>| . $locale->text('Paid') . qq|</td>
1334 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1335 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1336 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1337 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1340 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1341 <td nowrap>| . $locale->text('Notes') . qq|</td>
1342 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1343 <td nowrap>| . $locale->text('Employee') . qq|</td>
1346 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1347 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1348 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1349 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1358 <td><hr size=3 noshade></td>
1365 <input type=hidden name=nextsub value=$form->{nextsub}>
1366 <input type=hidden name=login value=$form->{login}>
1367 <input type=hidden name=password value=$form->{password}>
1369 <input class=submit type=submit name=action value="|
1370 . $locale->text('Continue') . qq|">
1377 $lxdebug->leave_sub();
1380 sub ap_transactions {
1381 $lxdebug->enter_sub();
1383 $form->{vendor} = $form->unescape($form->{vendor});
1384 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
1386 AP->ap_transactions(\%myconfig, \%$form);
1389 "$form->{script}?action=ap_transactions&login=$form->{login}&password=$form->{password}";
1392 if ($form->{vendor}) {
1393 $callback .= "&vendor=" . $form->escape($form->{vendor}, 1);
1394 $href .= "&vendor=" . $form->escape($form->{vendor});
1395 $option .= $locale->text('Vendor') . " : $form->{vendor}";
1397 if ($form->{department}) {
1398 $callback .= "&department=" . $form->escape($form->{department}, 1);
1399 $href .= "&department=" . $form->escape($form->{department});
1400 ($department) = split /--/, $form->{department};
1401 $option .= "\n<br>" if ($option);
1402 $option .= $locale->text('Department') . " : $department";
1404 if ($form->{invnumber}) {
1405 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1406 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1407 $option .= "\n<br>" if ($option);
1408 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1410 if ($form->{ordnumber}) {
1411 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1412 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1413 $option .= "\n<br>" if ($option);
1414 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1416 if ($form->{notes}) {
1417 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1418 $href .= "¬es=" . $form->escape($form->{notes});
1419 $option .= "\n<br>" if $option;
1420 $option .= $locale->text('Notes') . " : $form->{notes}";
1423 if ($form->{transdatefrom}) {
1424 $callback .= "&transdatefrom=$form->{transdatefrom}";
1425 $href .= "&transdatefrom=$form->{transdatefrom}";
1426 $option .= "\n<br>" if ($option);
1428 $locale->text('From') . " "
1429 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1431 if ($form->{transdateto}) {
1432 $callback .= "&transdateto=$form->{transdateto}";
1433 $href .= "&transdateto=$form->{transdateto}";
1434 $option .= "\n<br>" if ($option);
1436 $locale->text('Bis') . " "
1437 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1439 if ($form->{open}) {
1440 $callback .= "&open=$form->{open}";
1441 $href .= "&open=$form->{open}";
1442 $option .= "\n<br>" if ($option);
1443 $option .= $locale->text('Open');
1445 if ($form->{closed}) {
1446 $callback .= "&closed=$form->{closed}";
1447 $href .= "&closed=$form->{closed}";
1448 $option .= "\n<br>" if ($option);
1449 $option .= $locale->text('Closed');
1451 if ($form->{globalproject_id}) {
1452 $callback .= "&globalproject_id=" . E($form->{globalproject_id});
1453 $href .= "&globalproject_id=" . E($form->{globalproject_id});
1457 qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
1458 due duedate notes employee globalprojectnumber);
1460 $form->{"l_type"} = "Y";
1462 foreach $item (@columns) {
1463 if ($form->{"l_$item"} eq "Y") {
1464 push @column_index, $item;
1466 # add column to href and callback
1467 $callback .= "&l_$item=Y";
1468 $href .= "&l_$item=Y";
1472 if ($form->{l_subtotal} eq 'Y') {
1473 $callback .= "&l_subtotal=Y";
1474 $href .= "&l_subtotal=Y";
1477 $column_header{id} =
1478 qq|<th><a class=listheading href=$href&sort=id>|
1479 . $locale->text('ID')
1481 $column_header{transdate} =
1482 qq|<th><a class=listheading href=$href&sort=transdate>|
1483 . $locale->text('Date')
1485 $column_header{type} =
1486 "<th class=\"listheading\">" . $locale->text('Type') . "</th>";
1487 $column_header{duedate} =
1488 qq|<th><a class=listheading href=$href&sort=duedate>|
1489 . $locale->text('Due Date')
1491 $column_header{due} =
1492 qq|<th class=listheading>| . $locale->text('Amount Due') . qq|</th>|;
1493 $column_header{invnumber} =
1494 qq|<th><a class=listheading href=$href&sort=invnumber>|
1495 . $locale->text('Invoice')
1497 $column_header{ordnumber} =
1498 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1499 . $locale->text('Order')
1501 $column_header{name} =
1502 qq|<th><a class=listheading href=$href&sort=name>|
1503 . $locale->text('Vendor')
1505 $column_header{netamount} =
1506 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1507 $column_header{tax} =
1508 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1509 $column_header{amount} =
1510 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1511 $column_header{paid} =
1512 qq|<th class=listheading>| . $locale->text('Paid') . qq|</th>|;
1513 $column_header{datepaid} =
1514 qq|<th><a class=listheading href=$href&sort=datepaid>|
1515 . $locale->text('Date Paid')
1517 $column_header{notes} =
1518 qq|<th class=listheading>| . $locale->text('Notes') . qq|</th>|;
1519 $column_header{employee} =
1520 "<th><a class=listheading href=$href&sort=employee>"
1521 . $locale->text('Employee') . "</th>";
1522 $column_header{globalprojectnumber} =
1523 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1525 $form->{title} = $locale->text('AP Transactions');
1534 <th class=listtop>$form->{title}</th>
1536 <tr height="5"></tr>
1543 <tr class=listheading>
1546 map { print "\n$column_header{$_}" } @column_index;
1552 # add sort and escape callback
1553 $form->{callback} = "$callback&sort=$form->{sort}";
1554 $callback = $form->escape($form->{callback});
1556 if (@{ $form->{AP} }) {
1557 $sameitem = $form->{AP}->[0]->{ $form->{sort} };
1560 # sums and tax on reports by Antonio Gallardo
1562 foreach $ap (@{ $form->{AP} }) {
1564 if ($form->{l_subtotal} eq 'Y') {
1565 if ($sameitem ne $ap->{ $form->{sort} }) {
1567 $sameitem = $ap->{ $form->{sort} };
1571 $column_data{netamount} =
1573 . $form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")
1575 $column_data{tax} = "<td align=right>"
1576 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount},
1579 $column_data{amount} =
1581 . $form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>";
1582 $column_data{paid} =
1584 . $form->format_amount(\%myconfig, $ap->{paid}, 2, " ") . "</td>";
1585 $column_data{due} = "<td align=right>"
1586 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid},
1590 $totalnetamount += $ap->{netamount};
1591 $totalamount += $ap->{amount};
1592 $totalpaid += $ap->{paid};
1593 $totaldue += ($ap->{amount} - $ap->{paid});
1595 $subtotalnetamount += $ap->{netamount};
1596 $subtotalamount += $ap->{amount};
1597 $subtotalpaid += $ap->{paid};
1598 $subtotaldue += ($ap->{amount} - $ap->{paid});
1600 $column_data{transdate} = "<td>$ap->{transdate} </td>";
1601 $column_data{type} = "<td>" .
1602 ($ap->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1603 $locale->text("AP Transaction (abbreviation)"))
1605 $column_data{duedate} = "<td>$ap->{duedate} </td>";
1606 $column_data{datepaid} = "<td>$ap->{datepaid} </td>";
1608 $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
1610 $column_data{invnumber} =
1611 qq|<td><a href="$module?action=edit&id=$ap->{id}&login=$form->{login}&password=$form->{password}&callback=$callback">$ap->{invnumber}</a></td>|;
1612 $column_data{id} = "<td>$ap->{id}</td>";
1613 $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>";
1614 $column_data{name} = "<td>$ap->{name}</td>";
1615 $ap->{notes} =~ s/\r\n/<br>/g;
1616 $column_data{notes} = "<td>$ap->{notes} </td>";
1617 $column_data{employee} = "<td>$ap->{employee} </td>";
1618 $column_data{globalprojectnumber} =
1619 "<td>" . H($ap->{globalprojectnumber}) . "</td>";
1624 <tr class=listrow$i >
1627 map { print "\n$column_data{$_}" } @column_index;
1635 if ($form->{l_subtotal} eq 'Y') {
1641 <tr class=listtotal>
1644 map { $column_data{$_} = "<td> </td>" } @column_index;
1646 $column_data{netamount} =
1647 "<th class=listtotal align=right>"
1648 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1649 $column_data{tax} = "<th class=listtotal align=right>"
1650 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1653 $column_data{amount} =
1654 "<th class=listtotal align=right>"
1655 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1656 $column_data{paid} =
1657 "<th class=listtotal align=right>"
1658 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1660 "<th class=listtotal align=right>"
1661 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1663 map { print "$column_data{$_}\n" } @column_index;
1671 <td><hr size=3 noshade></td>
1676 <form method=post action=$form->{script}>
1678 <input name=callback type=hidden value="$form->{callback}">
1680 <input type=hidden name=login value=$form->{login}>
1681 <input type=hidden name=password value=$form->{password}>
1683 <input class=submit type=submit name=action value="|
1684 . $locale->text('AP Transaction') . qq|">
1686 <input class=submit type=submit name=action value="|
1687 . $locale->text('Vendor Invoice') . qq|">
1695 $lxdebug->leave_sub();
1699 $lxdebug->enter_sub();
1701 map { $column_data{$_} = "<td> </td>" } @column_index;
1703 $column_data{netamount} =
1704 "<th class=listsubtotal align=right>"
1705 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1707 $column_data{tax} = "<th class=listsubtotal align=right>"
1708 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1711 $column_data{amount} =
1712 "<th class=listsubtotal align=right>"
1713 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1714 $column_data{paid} =
1715 "<th class=listsubtotal align=right>"
1716 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1718 "<th class=listsubtotal align=right>"
1719 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1721 $subtotalnetamount = 0;
1722 $subtotalamount = 0;
1726 print "<tr class=listsubtotal>";
1728 map { print "\n$column_data{$_}" } @column_index;
1734 $lxdebug->leave_sub();
1738 $lxdebug->enter_sub();
1740 if (IS->has_storno(\%myconfig, $form, 'ap')) {
1741 $form->{title} = $locale->text("Cancel Accounts Payables Transaction");
1742 $form->error($locale->text("Transaction has already been cancelled!"));
1745 # negate amount/taxes
1746 for my $i (1 .. $form->{rowcount}) {
1747 $form->{"amount_$i"} *= -1;
1748 $form->{"tax_$i"} *= -1;
1752 for my $i (1 .. $form->{rowcount}) {
1753 for (qw(amount tax)) {
1754 $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"};
1758 $form->{storno} = 1;
1759 $form->{storno_id} = $form->{id};
1762 $form->{invnumber} = "Storno-" . $form->{invnumber};
1766 # saving the history
1767 if(!exists $form->{addition} && $form->{id} ne "") {
1768 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1769 $form->{addition} = "STORNO";
1770 $form->save_history($form->dbconnect(\%myconfig));
1772 # /saving the history
1774 $lxdebug->leave_sub();