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 #======================================================================
34 use POSIX qw(strftime);
40 use SL::ReportGenerator;
42 require "bin/mozilla/arap.pl";
43 require "bin/mozilla/common.pl";
44 require "bin/mozilla/drafts.pl";
45 require "bin/mozilla/report_generator.pl";
51 # this is for our long dates
52 # $locale->text('January')
53 # $locale->text('February')
54 # $locale->text('March')
55 # $locale->text('April')
56 # $locale->text('May ')
57 # $locale->text('June')
58 # $locale->text('July')
59 # $locale->text('August')
60 # $locale->text('September')
61 # $locale->text('October')
62 # $locale->text('November')
63 # $locale->text('December')
65 # this is for our short month
66 # $locale->text('Jan')
67 # $locale->text('Feb')
68 # $locale->text('Mar')
69 # $locale->text('Apr')
70 # $locale->text('May')
71 # $locale->text('Jun')
72 # $locale->text('Jul')
73 # $locale->text('Aug')
74 # $locale->text('Sep')
75 # $locale->text('Oct')
76 # $locale->text('Nov')
77 # $locale->text('Dec')
80 $lxdebug->enter_sub();
82 return $lxdebug->leave_sub() if (load_draft_maybe());
84 $form->{title} = "Add";
87 "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
88 unless $form->{callback};
90 AP->get_transdate(\%myconfig, $form);
91 $form->{initial_transdate} = $form->{transdate};
93 $form->{transdate} = $form->{initial_transdate};
96 $lxdebug->leave_sub();
100 $lxdebug->enter_sub();
102 $form->{title} = "Edit";
107 $lxdebug->leave_sub();
111 $lxdebug->enter_sub();
116 $lxdebug->leave_sub();
120 $lxdebug->enter_sub();
122 $form->create_links("AP", \%myconfig, "vendor");
123 $taxincluded = $form->{taxincluded};
124 $duedate = $form->{duedate};
126 IR->get_vendor(\%myconfig, \%$form);
127 $form->{taxincluded} = $taxincluded;
128 $form->{duedate} = $duedate if $duedate;
129 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
130 $form->{rowcount} = 1;
132 # build the popup menus
133 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
136 $form->{notes} = $form->{intnotes} unless $form->{notes};
139 @curr = split(/:/, $form->{currencies});
141 $form->{defaultcurrency} = $curr[0];
143 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
146 if (@{ $form->{all_vendor} }) {
147 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
148 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
149 (@{ $form->{all_vendor} });
153 if (@{ $form->{all_departments} }) {
154 $form->{selectdepartment} = "<option>\n";
155 $form->{department} = "$form->{department}--$form->{department_id}";
158 $form->{selectdepartment} .=
159 "<option>$_->{description}--$_->{id}\n"
160 } (@{ $form->{all_departments} });
163 $form->{employee} = "$form->{employee}--$form->{employee_id}";
165 AP->setup_form($form);
168 ($form->datetonum($form->{transdate}, \%myconfig) <=
169 $form->datetonum($form->{closedto}, \%myconfig));
171 $lxdebug->leave_sub();
175 $lxdebug->enter_sub();
177 $title = $form->{title};
178 $form->{title} = $locale->text("$title Accounts Payables Transaction");
180 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
182 # type=submit $locale->text('Add Accounts Payables Transaction')
183 # type=submit $locale->text('Edit Accounts Payables Transaction')
185 $form->{javascript} = qq|<script type="text/javascript">
187 function setTaxkey(accno, row) {
188 var taxkey = accno.options[accno.selectedIndex].value;
189 var reg = /--([0-9]*)/;
190 var found = reg.exec(taxkey);
191 var index = found[1];
192 index = parseInt(index);
193 var tax = 'taxchart_' + row;
194 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
195 var reg2 = new RegExp("^"+ index, "");
196 if (reg2.exec(document.getElementById(tax).options[i].value)) {
197 document.getElementById(tax).options[i].selected = true;
204 # show history button
205 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
206 #/show hhistory button
208 # set option selected
209 foreach $item (qw(vendor currency department)) {
210 $form->{"select$item"} =~ s/ selected//;
211 $form->{"select$item"} =~
212 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
214 $readonly = ($form->{id}) ? "readonly" : "";
217 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
218 $readonly = ($form->{radier}) ? "" : $readonly;
220 $form->{exchangerate} = $exchangerate
224 $form->check_exchangerate(
225 \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
230 $form->{exchangerate} =
231 $form->format_amount(\%myconfig, $form->{exchangerate});
232 if ($form->{exchangerate} == 0) {
233 $form->{exchangerate} = "";
235 $form->{creditlimit} =
236 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
237 $form->{creditremaining} =
238 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
241 <input type=hidden name=forex value=$form->{forex}>
243 if ($form->{currency} ne $form->{defaultcurrency}) {
244 if ($form->{forex}) {
247 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
248 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
253 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
254 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
263 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
264 <th align=left nowrap>|
265 . $locale->text('Tax Included') . qq|</th>
269 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
273 qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
277 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
278 <td colspan=3><select name=department>$form->{selectdepartment}</select>
279 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
282 | if $form->{selectdepartment};
284 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
287 ($form->{selectvendor})
288 ? qq|<select name="vendor"
289 onchange="document.getElementById('update_button').click();">$form->{
290 selectvendor } </select>|
291 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
293 my @old_project_ids = ();
294 map({ push(@old_project_ids, $form->{"project_id_$_"})
295 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
297 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
299 "old_id" => \@old_project_ids },
300 "charts" => { "key" => "ALL_CHARTS",
301 "transdate" => $form->{transdate} },
302 "taxcharts" => "ALL_TAXCHARTS");
304 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
305 @{ $form->{ALL_CHARTS} });
307 my %project_labels = ();
308 my @project_values = ("");
309 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
310 push(@project_values, $item->{"id"});
311 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
314 my (%AP_amount_labels, @AP_amount_values);
315 my (%AP_labels, @AP_values);
316 my (%AP_paid_labels, @AP_paid_values);
320 foreach my $item (@{ $form->{ALL_CHARTS} }) {
321 if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) {
322 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
323 my $key = "$item->{accno}--$item->{tax_id}";
324 push(@AP_amount_values, $key);
325 $AP_amount_labels{$key} =
326 "$item->{accno}--$item->{description}";
328 } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) {
329 push(@AP_values, $item->{accno});
330 $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
332 } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) {
333 push(@AP_paid_values, $item->{accno});
334 $AP_paid_labels{$item->{accno}} =
335 "$item->{accno}--$item->{description}";
338 $charts{$item->{accno}} = $item;
341 my %taxchart_labels = ();
342 my @taxchart_values = ();
344 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
345 my $key = "$item->{id}--$item->{rate}";
346 $taxchart_init = $key if ($taxchart_init eq $item->{id});
347 push(@taxchart_values, $key);
348 $taxchart_labels{$key} =
349 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
350 $taxcharts{$item->{id}} = $item;
353 # use JavaScript Calendar or not
354 $form->{jsscript} = 1;
356 if ($form->{jsscript}) {
358 # with JavaScript Calendar
360 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
361 <td><input type=button name=transdate id="trigger1" value=|
362 . $locale->text('button') . qq|></td>
365 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
366 <td><input type=button name=duedate id="trigger2" value=|
367 . $locale->text('button') . qq|></td></td>
372 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
373 "duedate", "BL", "trigger2");
376 # without JavaScript Calendar
378 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
380 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
382 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
383 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
386 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
387 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
389 <body onLoad="$onload">
391 <form method=post action=$form->{script}>
393 <input type=hidden name=id value=$form->{id}>
394 <input type=hidden name=sort value=$form->{sort}>
395 <input type=hidden name=closedto value=$form->{closedto}>
396 <input type=hidden name=locked value=$form->{locked}>
397 <input type=hidden name=title value="$title">
399 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
403 <th class=listtop>$form->{title}</th>
413 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
414 <td colspan=3>$vendor <input type="button" value="?" onclick="show_vc_details('vendor')"></td>
415 <input type=hidden name=selectvendor value="$form->{selectvendor}">
416 <input type=hidden name=oldvendor value="$form->{oldvendor}">
417 <input type=hidden name=vendor_id value="$form->{vendor_id}">
418 <input type=hidden name=terms value=$form->{terms}>
425 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
426 <td>$form->{creditlimit}</td>
427 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
428 <td class="plus$n">$form->{creditremaining}</td>
429 <input type=hidden name=creditlimit value=$form->{creditlimit}>
430 <input type=hidden name=creditremaining value=$form->{creditremaining}>
435 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
436 <td><select name=currency>$form->{selectcurrency}</select></td>
437 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
438 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
439 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
440 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
450 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
451 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
454 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
455 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
458 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
462 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
475 <input type=hidden name=rowcount value=$form->{rowcount}>
479 <tr class=listheading>
480 <th class=listheading style="width:15%">|
481 . $locale->text('Account') . qq|</th>
482 <th class=listheading style="width:10%">|
483 . $locale->text('Amount') . qq|</th>
484 <th class=listheading style="width:10%">|
485 . $locale->text('Tax') . qq|</th>
486 <th class=listheading style="width:5%">|
487 . $locale->text('Korrektur') . qq|</th>
488 <th class=listheading style="width:10%">|
489 . $locale->text('Taxkey') . qq|</th>
490 <th class=listheading style="width:10%">|
491 . $locale->text('Project') . qq|</th>
495 $amount = $locale->text('Amount');
496 $project = $locale->text('Project');
498 for $i (1 .. $form->{rowcount}) {
501 $form->{"amount_$i"} =
502 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
503 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
505 my $selected_accno_full;
506 my ($accno_row) = split(/--/, $form->{"AP_amount_$i"});
507 my $item = $charts{$accno_row};
508 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
510 my $selected_taxchart = $form->{"taxchart_$i"};
511 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
512 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AP_amount_$i"});
514 if ($previous_accno &&
515 ($previous_accno eq $selected_accno) &&
516 ($previous_tax_id ne $selected_tax_id)) {
517 my $item = $taxcharts{$selected_tax_id};
518 $selected_taxchart = "$item->{id}--$item->{rate}";
521 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
524 NTI($cgi->popup_menu('-name' => "AP_amount_$i",
525 '-id' => "AP_amount_$i",
526 '-style' => 'width:400px',
527 '-onChange' => "setTaxkey(this, $i)",
528 '-values' => \@AP_amount_values,
529 '-labels' => \%AP_amount_labels,
530 '-default' => $selected_accno_full))
531 . $cgi->hidden('-name' => "previous_AP_amount_$i",
532 '-default' => $selected_accno_full);
535 NTI($cgi->popup_menu('-name' => "taxchart_$i",
536 '-id' => "taxchart_$i",
537 '-style' => 'width:200px',
538 '-values' => \@taxchart_values,
539 '-labels' => \%taxchart_labels,
540 '-default' => $selected_taxchart))
543 my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
546 NTI($cgi->popup_menu('-name' => "project_id_$i",
547 '-values' => \@project_values,
548 '-labels' => \%project_labels,
549 '-default' => $form->{"project_id_$i"} ));
553 <td>$selectAP_amount</td>
554 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
555 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
556 <td><input type="checkbox" name="korrektur_$i" value="1" "$korrektur"></td>
558 <td>$projectnumber</td>
566 ($form->{taxincluded})
567 ? $locale->text('Tax Included')
568 : $locale->text('Tax');
570 $form->{invtotal_unformatted} = $form->{invtotal};
571 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
574 NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
575 '-style' => 'width:400px',
576 '-values' => \@AP_values, '-labels' => \%AP_labels,
577 '-default' => $form->{APselected}));
585 <td>${APselected}</td>
586 <th align=left>$form->{invtotal}</th>
588 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
589 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
591 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
604 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
605 <td align=left>$notes</td>
613 <tr class=listheading>
614 <th class=listheading colspan=7>| . $locale->text('Payments') . qq|</th>
618 if ($form->{currency} eq $form->{defaultcurrency}) {
619 @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
621 @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
624 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
625 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
626 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
627 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
628 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
629 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
630 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
635 map { print "$column_data{$_}\n" } @column_index;
643 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
644 for $i (1 .. $form->{paidaccounts}) {
650 NTI($cgi->popup_menu('-name' => "AP_paid_$i",
651 '-id' => "AP_paid_$i",
652 '-values' => \@AP_paid_values,
653 '-labels' => \%AP_paid_labels,
654 '-default' => $form->{"AP_paid_$i"}));
656 $totalpaid += $form->{"paid_$i"};
659 if ($form->{"paid_$i"}) {
661 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
663 $form->{"exchangerate_$i"} =
664 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
665 if ($form->{"exchangerate_$i"} == 0) {
666 $form->{"exchangerate_$i"} = "";
669 $exchangerate = qq| |;
670 if ($form->{currency} ne $form->{defaultcurrency}) {
671 if ($form->{"forex_$i"}) {
673 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
676 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
681 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
684 $column_data{"paid_$i"} =
685 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
686 $column_data{"AP_paid_$i"} =
687 qq|<td align=center>${selectAP_paid}</td>|;
688 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
689 $column_data{"datepaid_$i"} =
690 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)\">
691 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
692 $column_data{"source_$i"} =
693 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
694 $column_data{"memo_$i"} =
695 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
696 $column_data{"paid_project_id_$i"} =
698 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
699 '-values' => \@project_values,
700 '-labels' => \%project_labels,
701 '-default' => $form->{"paid_project_id_$i"} ))
704 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
709 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
712 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
718 <td align="center">| . $locale->text('Total') . qq|</td>
719 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
724 <td align="center">| . $locale->text('Missing amount') . qq|</td>
725 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
727 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
729 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
735 <td><hr size=3 noshade></td>
740 $lxdebug->leave_sub();
744 $lxdebug->enter_sub();
748 <input name=callback type=hidden value="$form->{callback}">
749 <input name="gldate" type="hidden" value="| . Q($form->{gldate}) . qq|">
751 <input type=hidden name=login value=$form->{login}>
752 <input type=hidden name=password value=$form->{password}>
754 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
755 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
761 if (!$form->{id} && $form->{draft_id}) {
762 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
763 '-value' => 1, '-checked' => $form->{remove_draft},
765 qq| <label for="remove_draft">| .
766 $locale->text("Remove draft when posting") .
770 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
771 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
773 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">|;
776 if ($form->{radier}) {
777 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
778 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">
782 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
783 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
784 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap') && !$form->{paid_1});
786 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
787 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|">
789 } elsif (($transdate > $closedto) && !$form->{id}) {
791 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
792 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
794 # button for saving history
795 if($form->{id} ne "") {
796 print qq| <input type="button" class="submit" onclick="set_history_window($form->{id});" name="history" id="history" value="| . $locale->text('history') . qq|">|;
798 # /button for saving history
799 # mark_as_paid button
800 if($form->{id} ne "") {
801 print qq|<input type="submit" class="submit" name="action" value="|
802 . $locale->text('mark as paid') . qq|">|;
804 # /mark_as_paid button
812 $lxdebug->leave_sub();
816 $lxdebug->enter_sub();
817 &mark_as_paid_common(\%myconfig,"ap");
818 $lxdebug->leave_sub();
822 $lxdebug->enter_sub();
826 $form->{invtotal} = 0;
828 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
829 qw(exchangerate creditlimit creditremaining);
831 @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
833 for $i (1 .. $form->{rowcount}) {
834 $form->{"amount_$i"} =
835 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
836 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
837 if ($form->{"amount_$i"}) {
840 if (!$form->{"korrektur_$i"}) {
841 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
843 if ($form->{taxincluded}) {
844 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
846 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
849 $form->{"tax_$i"} = 0;
852 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
854 $totaltax += $form->{"tax_$i"};
855 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
859 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
861 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
863 $form->{exchangerate} = $exchangerate
867 $form->check_exchangerate(
868 \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
871 $form->{invdate} = $form->{transdate};
872 $save_AP = $form->{AP};
874 $form->{AP} = $save_AP;
876 $form->{rowcount} = $count + 1;
879 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
881 for $i (1 .. $form->{paidaccounts}) {
882 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
885 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
886 } qw(paid exchangerate);
888 $totalpaid += $form->{"paid_$i"};
890 $form->{"exchangerate_$i"} = $exchangerate
892 $form->{"forex_$i"} = (
894 $form->check_exchangerate(
895 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
900 $form->{creditremaining} -=
901 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
902 $form->{oldinvtotal});
903 $form->{oldinvtotal} = $form->{invtotal};
904 $form->{oldtotalpaid} = $totalpaid;
908 $lxdebug->leave_sub();
913 $lxdebug->enter_sub();
915 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
917 for $i (1 .. $form->{paidaccounts}) {
918 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
919 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
921 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
923 $form->error($locale->text('Cannot post payment for a closed period!'))
924 if ($datepaid <= $closedto);
926 if ($form->{currency} ne $form->{defaultcurrency}) {
927 $form->{"exchangerate_$i"} = $form->{exchangerate}
928 if ($invdate == $datepaid);
929 $form->isblank("exchangerate_$i",
930 $locale->text('Exchangerate for payment missing!'));
935 ($form->{AP}) = split /--/, $form->{AP};
936 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
937 $form->redirect($locale->text('Payment posted!'))
938 if (AP->post_payment(\%myconfig, \%$form));
939 $form->error($locale->text('Cannot post payment!'));
942 $lxdebug->leave_sub();
947 $lxdebug->enter_sub();
949 # check if there is a vendor, invoice and due date
950 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
951 $form->isblank("duedate", $locale->text("Due Date missing!"));
952 $form->isblank("vendor", $locale->text('Vendor missing!'));
954 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
955 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
956 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
958 my $zero_amount_posting = 1;
959 for $i (1 .. $form->{rowcount}) {
960 if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
961 $zero_amount_posting = 0;
966 $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
968 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
969 if ($form->{currency} ne $form->{defaultcurrency});
972 for $i (1 .. $form->{paidaccounts}) {
973 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
974 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
976 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
978 $form->error($locale->text('Cannot post payment for a closed period!'))
979 if ($datepaid <= $closedto);
981 if ($form->{currency} ne $form->{defaultcurrency}) {
982 $form->{"exchangerate_$i"} = $form->{exchangerate}
983 if ($transdate == $datepaid);
984 $form->isblank("exchangerate_$i",
985 $locale->text('Exchangerate for payment missing!'));
991 # if old vendor ne vendor redo form
992 ($vendor) = split /--/, $form->{vendor};
993 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
997 ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
998 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
999 ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
1000 $form->{AP}{amount_1} = $debitaccno;
1001 $form->{AP}{payables} = $payablesaccno;
1002 $form->{taxkey} = $taxkey;
1003 $form->{storno} = 0;
1005 $form->{id} = 0 if $form->{postasnew};
1007 if (AP->post_transaction(\%myconfig, \%$form)) {
1008 # saving the history
1009 if(!exists $form->{addition} && $form->{id} ne "") {
1010 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1011 $form->{addition} = "POSTED";
1012 $form->save_history($form->dbconnect(\%myconfig));
1014 # /saving the history
1015 remove_draft() if $form->{remove_draft};
1016 $form->redirect($locale->text('Transaction posted!'));
1018 $form->error($locale->text('Cannot post transaction!'));
1020 $lxdebug->leave_sub();
1024 $lxdebug->enter_sub();
1026 $form->{postasnew} = 1;
1027 # saving the history
1028 if(!exists $form->{addition} && $form->{id} ne "") {
1029 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1030 $form->{addition} = "POSTED AS NEW";
1031 $form->save_history($form->dbconnect(\%myconfig));
1033 # /saving the history
1036 $lxdebug->leave_sub();
1039 sub use_as_template {
1040 $lxdebug->enter_sub();
1042 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);
1043 $form->{paidaccounts} = 1;
1044 $form->{rowcount}--;
1045 $form->{invdate} = $form->current_date(\%myconfig);
1048 $lxdebug->leave_sub();
1052 $lxdebug->enter_sub();
1054 $form->{title} = $locale->text('Confirm!');
1058 delete $form->{header};
1063 <form method=post action=$form->{script}>
1066 foreach $key (keys %$form) {
1067 $form->{$key} =~ s/\"/"/g;
1068 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1072 <h2 class=confirm>$form->{title}</h2>
1075 . $locale->text('Are you sure you want to delete Transaction')
1076 . qq| $form->{invnumber}</h4>
1078 <input name=action class=submit type=submit value="|
1079 . $locale->text('Yes') . qq|">
1086 $lxdebug->leave_sub();
1090 $lxdebug->enter_sub();
1091 if (AP->delete_transaction(\%myconfig, \%$form, $spool)) {
1092 # saving the history
1093 if(!exists $form->{addition}) {
1094 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1095 $form->{addition} = "DELETED";
1096 $form->save_history($form->dbconnect(\%myconfig));
1098 # /saving the history
1099 $form->redirect($locale->text('Transaction deleted!'));
1101 $form->error($locale->text('Cannot delete transaction!'));
1103 $lxdebug->leave_sub();
1107 $lxdebug->enter_sub();
1109 # setup vendor selection
1110 $form->all_vc(\%myconfig, "vendor", "AP");
1112 if (@{ $form->{all_vendor} }) {
1113 map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
1114 @{ $form->{all_vendor} };
1115 $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
1117 $vendor = qq|<input name=vendor size=35>|;
1121 if (@{ $form->{all_departments} }) {
1122 $form->{selectdepartment} = "<option>\n";
1125 $form->{selectdepartment} .=
1126 "<option>$_->{description}--$_->{id}\n"
1127 } (@{ $form->{all_departments} });
1132 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1133 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1135 | if $form->{selectdepartment};
1137 $form->{title} = $locale->text('AP Transactions');
1139 # use JavaScript Calendar or not
1140 $form->{jsscript} = 1;
1142 if ($form->{jsscript}) {
1144 # with JavaScript Calendar
1146 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1147 <input type=button name=transdatefrom id="trigger1" value=|
1148 . $locale->text('button') . qq|></td>
1151 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1152 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1153 . $locale->text('button') . qq|></td>
1158 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1159 "transdateto", "BL", "trigger2");
1162 # without JavaScript Calendar
1164 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1166 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1169 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1174 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1175 push(@values, $item->{"id"});
1176 $labels{$item->{"id"}} = $item->{"projectnumber"};
1179 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1180 '-labels' => \%labels));
1181 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1183 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1184 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1186 <body onLoad="$onload">
1188 <form method=post action=$form->{script}>
1192 <th class=listtop>$form->{title}</th>
1194 <tr height="5"></tr>
1199 <th align=right>| . $locale->text('Vendor') . qq|</th>
1200 <td colspan=3>$vendor</td>
1204 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1205 <td colspan=3><input name=invnumber size=20></td>
1208 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1209 <td colspan=3><input name=ordnumber size=20></td>
1212 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1213 <td colspan=3><input name=notes size=40></td>
1216 <th align="right">| . $locale->text("Project Number") . qq|</th>
1217 <td colspan="3">$projectnumber</td>
1220 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1222 <th align=right>| . $locale->text('Bis') . qq|</th>
1225 <input type=hidden name=sort value=transdate>
1233 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1237 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1238 <td nowrap>| . $locale->text('Open') . qq|</td>
1239 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1240 <td nowrap>| . $locale->text('Closed') . qq|</td>
1243 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1244 <td nowrap>| . $locale->text('ID') . qq|</td>
1245 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1246 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1247 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1248 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1251 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1252 <td nowrap>| . $locale->text('Vendor') . qq|</td>
1253 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1254 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1255 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1256 <td nowrap>| . $locale->text('Amount') . qq|</td>
1259 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1260 <td nowrap>| . $locale->text('Tax') . qq|</td>
1261 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1262 <td nowrap>| . $locale->text('Total') . qq|</td>
1263 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1264 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1267 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1268 <td nowrap>| . $locale->text('Paid') . qq|</td>
1269 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1270 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1271 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1272 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1275 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1276 <td nowrap>| . $locale->text('Notes') . qq|</td>
1277 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1278 <td nowrap>| . $locale->text('Employee') . qq|</td>
1281 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1282 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1283 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1284 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1293 <td><hr size=3 noshade></td>
1300 <input type=hidden name=nextsub value=$form->{nextsub}>
1301 <input type=hidden name=login value=$form->{login}>
1302 <input type=hidden name=password value=$form->{password}>
1304 <input class=submit type=submit name=action value="|
1305 . $locale->text('Continue') . qq|">
1312 $lxdebug->leave_sub();
1315 sub create_subtotal_row {
1316 $lxdebug->enter_sub();
1318 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1320 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1322 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1324 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1326 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1328 $lxdebug->leave_sub();
1333 sub ap_transactions {
1334 $lxdebug->enter_sub();
1336 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
1338 $form->{sort} ||= 'transdate';
1340 AP->ap_transactions(\%myconfig, \%$form);
1342 $form->{title} = $locale->text('AP Transactions');
1344 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1347 qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
1348 due duedate transaction_description notes employee globalprojectnumber);
1350 my @hidden_variables = map { "l_${_}" } @columns;
1351 push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
1353 my $href = build_std_url('action=ap_transactions', grep { $form->{$_} } @hidden_variables);
1356 'transdate' => { 'text' => $locale->text('Date'), },
1357 'id' => { 'text' => $locale->text('ID'), },
1358 'type' => { 'text' => $locale->text('Type'), },
1359 'invnumber' => { 'text' => $locale->text('Invoice'), },
1360 'ordnumber' => { 'text' => $locale->text('Order'), },
1361 'name' => { 'text' => $locale->text('Vendor'), },
1362 'netamount' => { 'text' => $locale->text('Amount'), },
1363 'tax' => { 'text' => $locale->text('Tax'), },
1364 'amount' => { 'text' => $locale->text('Total'), },
1365 'paid' => { 'text' => $locale->text('Paid'), },
1366 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1367 'due' => { 'text' => $locale->text('Amount Due'), },
1368 'duedate' => { 'text' => $locale->text('Due Date'), },
1369 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1370 'notes' => { 'text' => $locale->text('Notes'), },
1371 'employee' => { 'text' => $locale->text('Salesperson'), },
1372 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1375 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid
1376 employee shippingpoint shipvia)) {
1377 $column_defs{$name}->{link} = $href . "&sort=$name";
1380 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1382 $form->{"l_type"} = "Y";
1383 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1385 $report->set_columns(%column_defs);
1386 $report->set_column_order(@columns);
1388 $report->set_export_options('ap_transactions', @hidden_variables);
1391 if ($form->{vendor}) {
1392 push @options, $locale->text('Vendor') . " : $form->{vendor}";
1394 if ($form->{department}) {
1395 ($department) = split /--/, $form->{department};
1396 push @options, $locale->text('Department') . " : $department";
1398 if ($form->{invnumber}) {
1399 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1401 if ($form->{ordnumber}) {
1402 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1404 if ($form->{notes}) {
1405 push @options, $locale->text('Notes') . " : $form->{notes}";
1407 if ($form->{transaction_description}) {
1408 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1410 if ($form->{transdatefrom}) {
1411 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1413 if ($form->{transdateto}) {
1414 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1416 if ($form->{open}) {
1417 push @options, $locale->text('Open');
1419 if ($form->{closed}) {
1420 push @options, $locale->text('Closed');
1423 $report->set_options('top_info_text' => join("\n", @options),
1424 'raw_bottom_info_text' => $form->parse_html_template('ap/ap_transactions_bottom'),
1425 'output_format' => 'HTML',
1426 'title' => $form->{title},
1427 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1429 $report->set_options_from_form();
1431 # add sort and escape callback, this one we use for the add sub
1432 $form->{callback} = $href .= "&sort=$form->{sort}";
1434 # escape callback for href
1435 $callback = $form->escape($href);
1437 my @subtotal_columns = qw(netamount amount paid due);
1439 my %totals = map { $_ => 0 } @subtotal_columns;
1440 my %subtotals = map { $_ => 0 } @subtotal_columns;
1444 foreach $ap (@{ $form->{AP} }) {
1445 $ap->{tax} = $ap->{amount} - $ap->{netamount};
1446 $ap->{due} = $ap->{amount} - $ap->{paid};
1448 map { $subtotals{$_} += $ap->{$_};
1449 $totals{$_} += $ap->{$_} } @subtotal_columns;
1451 map { $ap->{$_} = $form->format_amount(\%myconfig, $ap->{$_}, 2) } qw(netamount tax amount paid due);
1454 $ap->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1455 $locale->text("AP Transaction (abbreviation)");
1459 foreach my $column (@columns) {
1461 'data' => $ap->{$column},
1462 'align' => $column_alignment{$column},
1466 $row->{invnumber}->{link} = build_std_url("script=" . ($ap->{invoice} ? 'ir.pl' : 'ap.pl'), 'action=edit')
1467 . "&id=" . E($ap->{id}) . "&callback=${callback}";
1469 my $row_set = [ $row ];
1471 if (($form->{l_subtotal} eq 'Y')
1472 && (($idx == (scalar @{ $form->{AP} } - 1))
1473 || ($ap->{ $form->{sort} } ne $form->{AP}->[$idx + 1]->{ $form->{sort} }))) {
1474 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1477 $report->add_data($row_set);
1482 $report->add_separator();
1483 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1485 $report->generate_with_headers();
1487 $lxdebug->leave_sub();
1491 $lxdebug->enter_sub();
1493 if (IS->has_storno(\%myconfig, $form, 'ap')) {
1494 $form->{title} = $locale->text("Cancel Accounts Payables Transaction");
1495 $form->error($locale->text("Transaction has already been cancelled!"));
1498 # negate amount/taxes
1499 for my $i (1 .. $form->{rowcount}) {
1500 $form->{"amount_$i"} *= -1;
1501 $form->{"tax_$i"} *= -1;
1505 for my $i (1 .. $form->{rowcount}) {
1506 for (qw(amount tax)) {
1507 $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"};
1511 $form->{storno} = 1;
1512 $form->{storno_id} = $form->{id};
1515 $form->{invnumber} = "Storno-" . $form->{invnumber};
1519 # saving the history
1520 if(!exists $form->{addition} && $form->{id} ne "") {
1521 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1522 $form->{addition} = "STORNO";
1523 $form->save_history($form->dbconnect(\%myconfig));
1525 # /saving the history
1527 $lxdebug->leave_sub();