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);
35 use List::Util qw(sum);
42 use SL::ReportGenerator;
44 require "bin/mozilla/arap.pl";
45 require "bin/mozilla/common.pl";
46 require "bin/mozilla/drafts.pl";
47 require "bin/mozilla/reportgenerator.pl";
55 # this is for our long dates
56 # $locale->text('January')
57 # $locale->text('February')
58 # $locale->text('March')
59 # $locale->text('April')
60 # $locale->text('May ')
61 # $locale->text('June')
62 # $locale->text('July')
63 # $locale->text('August')
64 # $locale->text('September')
65 # $locale->text('October')
66 # $locale->text('November')
67 # $locale->text('December')
69 # this is for our short month
70 # $locale->text('Jan')
71 # $locale->text('Feb')
72 # $locale->text('Mar')
73 # $locale->text('Apr')
74 # $locale->text('May')
75 # $locale->text('Jun')
76 # $locale->text('Jul')
77 # $locale->text('Aug')
78 # $locale->text('Sep')
79 # $locale->text('Oct')
80 # $locale->text('Nov')
81 # $locale->text('Dec')
84 $main::lxdebug->enter_sub();
86 my $form = $main::form;
87 my %myconfig = %main::myconfig;
89 $main::auth->assert('general_ledger');
91 return $main::lxdebug->leave_sub() if (load_draft_maybe());
93 $form->{title} = "Add";
95 $form->{callback} = "ap.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback};
97 AP->get_transdate(\%myconfig, $form);
98 $form->{initial_transdate} = $form->{transdate};
100 $form->{transdate} = $form->{initial_transdate};
103 $main::lxdebug->leave_sub();
107 $main::lxdebug->enter_sub();
109 my $form = $main::form;
111 $main::auth->assert('general_ledger');
113 $form->{title} = "Edit";
118 $main::lxdebug->leave_sub();
122 $main::lxdebug->enter_sub();
124 my $form = $main::form;
126 $main::auth->assert('general_ledger');
131 $main::lxdebug->leave_sub();
135 $main::lxdebug->enter_sub();
137 my $form = $main::form;
138 my %myconfig = %main::myconfig;
140 $main::auth->assert('general_ledger');
142 $form->create_links("AP", \%myconfig, "vendor");
143 my $taxincluded = $form->{taxincluded};
144 my $duedate = $form->{duedate};
146 IR->get_vendor(\%myconfig, \%$form);
147 $form->{taxincluded} = $taxincluded;
148 $form->{duedate} = $duedate if $duedate;
149 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
150 $form->{rowcount} = 1;
152 # build the popup menus
153 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
156 $form->{notes} = $form->{intnotes} unless $form->{notes};
159 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
161 map { $form->{selectcurrency} .= "<option>$_\n" } $form->get_all_currencies(\%myconfig);
164 if (@{ $form->{all_vendor} || [] }) {
165 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
166 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
167 (@{ $form->{all_vendor} });
171 if (@{ $form->{all_departments} || [] }) {
172 $form->{selectdepartment} = "<option>\n";
173 $form->{department} = "$form->{department}--$form->{department_id}";
176 $form->{selectdepartment} .=
177 "<option>$_->{description}--$_->{id}\n"
178 } (@{ $form->{all_departments} || [] });
181 $form->{employee} = "$form->{employee}--$form->{employee_id}";
183 AP->setup_form($form);
186 ($form->datetonum($form->{transdate}, \%myconfig) <=
187 $form->datetonum($form->{closedto}, \%myconfig));
189 $main::lxdebug->leave_sub();
193 $main::lxdebug->enter_sub();
195 my $form = $main::form;
196 my %myconfig = %main::myconfig;
197 my $locale = $main::locale;
198 my $cgi = $main::cgi;
200 $main::auth->assert('general_ledger');
202 my $title = $form->{title};
203 $form->{title} = $locale->text("$title Accounts Payables Transaction");
205 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
207 # type=submit $locale->text('Add Accounts Payables Transaction')
208 # type=submit $locale->text('Edit Accounts Payables Transaction')
210 $form->{javascript} = qq|<script type="text/javascript">
212 function setTaxkey(accno, row) {
213 var taxkey = accno.options[accno.selectedIndex].value;
214 var reg = /--([0-9]*)/;
215 var found = reg.exec(taxkey);
216 var index = found[1];
217 index = parseInt(index);
218 var tax = 'taxchart_' + row;
219 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
220 var reg2 = new RegExp("^"+ index, "");
221 if (reg2.exec(document.getElementById(tax).options[i].value)) {
222 document.getElementById(tax).options[i].selected = true;
229 # show history button
230 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
231 #/show hhistory button
233 # set option selected
234 foreach my $item (qw(vendor currency department)) {
235 $form->{"select$item"} =~ s/ selected//;
236 $form->{"select$item"} =~
237 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
239 my $readonly = ($form->{id}) ? "readonly" : "";
241 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
242 $readonly = ($form->{radier}) ? "" : $readonly;
244 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell');
245 $form->{exchangerate} = $form->{forex} if $form->{forex};
248 $form->{exchangerate} = $form->{exchangerate} ? $form->format_amount(\%myconfig, $form->{exchangerate}) : '';
249 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
250 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
252 my $exchangerate = qq|
253 <input type=hidden name=forex value=$form->{forex}>
255 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
256 if ($form->{forex}) {
259 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
260 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
265 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
266 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
271 my $taxincluded = "";
275 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
276 <th align=left nowrap>|
277 . $locale->text('Tax Included') . qq|</th>
282 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
286 qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
290 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
291 <td colspan=3><select name=department>$form->{selectdepartment}</select>
292 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
295 | if $form->{selectdepartment};
297 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
300 ($form->{selectvendor})
301 ? qq|<select name="vendor" onchange="document.getElementById('update_button').click();">$form->{selectvendor} </select>|
302 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
304 my @old_project_ids = ();
305 map({ push(@old_project_ids, $form->{"project_id_$_"})
306 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
308 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
310 "old_id" => \@old_project_ids },
311 "charts" => { "key" => "ALL_CHARTS",
312 "transdate" => $form->{transdate} },
313 "taxcharts" => { "key" => "ALL_TAXCHARTS",
314 "module" => "AP" },);
316 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
317 @{ $form->{ALL_CHARTS} });
319 my %project_labels = ();
320 my @project_values = ("");
321 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
322 push(@project_values, $item->{"id"});
323 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
326 my (%AP_amount_labels, @AP_amount_values);
327 my (%AP_labels, @AP_values);
328 my (%AP_paid_labels, @AP_paid_values);
332 foreach my $item (@{ $form->{ALL_CHARTS} }) {
333 if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) {
334 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
335 my $key = "$item->{accno}--$item->{tax_id}";
336 push(@AP_amount_values, $key);
337 $AP_amount_labels{$key} =
338 "$item->{accno}--$item->{description}";
340 } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) {
341 push(@AP_values, $item->{accno});
342 $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
344 } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) {
345 push(@AP_paid_values, $item->{accno});
346 $AP_paid_labels{$item->{accno}} =
347 "$item->{accno}--$item->{description}";
350 $charts{$item->{accno}} = $item;
353 my %taxchart_labels = ();
354 my @taxchart_values = ();
356 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
357 my $key = "$item->{id}--$item->{rate}";
358 $taxchart_init = $key if ($taxchart_init eq $item->{id});
359 push(@taxchart_values, $key);
360 $taxchart_labels{$key} =
361 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
362 $taxcharts{$item->{id}} = $item;
365 # use JavaScript Calendar or not
366 $form->{jsscript} = 1;
368 my ($button1, $button2);
369 if ($form->{jsscript}) {
371 # with JavaScript Calendar
373 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\" $readonly></td>
374 <td><input type=button name=transdate id="trigger1" value=|
375 . $locale->text('button') . qq|></td>
378 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\" $readonly></td>
379 <td><input type=button name=duedate id="trigger2" value=|
380 . $locale->text('button') . qq|></td></td>
385 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
386 "duedate", "BL", "trigger2");
389 # without JavaScript Calendar
391 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\" $readonly></td>|;
393 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\" $readonly></td>|;
396 my $follow_up_vc = $form->{vendor};
397 $follow_up_vc =~ s/--.*?//;
398 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
400 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
401 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
402 $form->{javascript} .= qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
404 my $globalprojectnumber =
405 NTI($cgi->popup_menu('-name' => "globalproject_id",
406 '-values' => \@project_values,
407 '-labels' => \%project_labels,
408 '-default' => $form->{"globalproject_id"} ));
411 my $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
412 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
414 <body onLoad="$onload">
416 <form method=post action=$form->{script}>
418 <input type=hidden name=id value=$form->{id}>
419 <input type=hidden name=sort value=$form->{sort}>
420 <input type=hidden name=closedto value=$form->{closedto}>
421 <input type=hidden name=locked value=$form->{locked}>
422 <input type=hidden name=title value="$title">
424 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
425 <input type="hidden" name="follow_up_trans_type_1" value="ap_transaction">
426 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
427 <input type="hidden" name="follow_up_rowcount" value="1">
429 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
433 <th class=listtop>$form->{title}</th>
443 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
444 <td colspan=3>$vendor <input type="button" value="D" onclick="show_vc_details('vendor')"></td>
445 <input type=hidden name=selectvendor value="| . H($form->{selectvendor}) . qq|">
446 <input type=hidden name=oldvendor value="| . H($form->{oldvendor}) . qq|">
447 <input type=hidden name=vendor_id value="| . H($form->{vendor_id}) . qq|">
448 <input type=hidden name=terms value="| . H($form->{terms}) . qq|">
455 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
456 <td>$form->{creditlimit}</td>
457 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
458 <td class="plus$n">$form->{creditremaining}</td>
459 <input type=hidden name=creditlimit value=$form->{creditlimit}>
460 <input type=hidden name=creditremaining value=$form->{creditremaining}>
465 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
466 <td><select name=currency>$form->{selectcurrency}</select></td>
467 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
468 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
469 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
470 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
480 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
481 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
484 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
485 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
488 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
492 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
496 <th align=right nowrap>| . $locale->text('Project Number') . qq|</th>
497 <td>$globalprojectnumber</td>
509 <input type=hidden name=rowcount value=$form->{rowcount}>
513 <tr class=listheading>
514 <th class=listheading style="width:15%">| . $locale->text('Account') . qq|</th>
515 <th class=listheading style="width:10%">| . $locale->text('Amount') . qq|</th>
516 <th class=listheading style="width:10%">| . $locale->text('Tax') . qq|</th>
517 <th class=listheading style="width:10%">| . $locale->text('Taxkey') . qq|</th>
518 <th class=listheading style="width:10%">| . $locale->text('Project') . qq|</th>
522 my $amount = $locale->text('Amount');
523 my $project = $locale->text('Project');
525 for my $i (1 .. $form->{rowcount}) {
528 $form->{"amount_$i"} =
529 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
530 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
532 my $selected_accno_full;
533 my ($accno_row) = split(/--/, $form->{"AP_amount_$i"});
534 my $item = $charts{$accno_row};
535 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
537 my $selected_taxchart = $form->{"taxchart_$i"};
538 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
539 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AP_amount_$i"});
541 if ($previous_accno &&
542 ($previous_accno eq $selected_accno) &&
543 ($previous_tax_id ne $selected_tax_id)) {
544 my $item = $taxcharts{$selected_tax_id};
545 $selected_taxchart = "$item->{id}--$item->{rate}";
548 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
550 my $selectAP_amount =
551 NTI($cgi->popup_menu('-name' => "AP_amount_$i",
552 '-id' => "AP_amount_$i",
553 '-style' => 'width:400px',
554 '-onChange' => "setTaxkey(this, $i)",
555 '-values' => \@AP_amount_values,
556 '-labels' => \%AP_amount_labels,
557 '-default' => $selected_accno_full))
558 . $cgi->hidden('-name' => "previous_AP_amount_$i",
559 '-default' => $selected_accno_full);
562 NTI($cgi->popup_menu('-name' => "taxchart_$i",
563 '-id' => "taxchart_$i",
564 '-style' => 'width:200px',
565 '-values' => \@taxchart_values,
566 '-labels' => \%taxchart_labels,
567 '-default' => $selected_taxchart))
571 NTI($cgi->popup_menu('-name' => "project_id_$i",
572 '-values' => \@project_values,
573 '-labels' => \%project_labels,
574 '-default' => $form->{"project_id_$i"} ));
578 <td>$selectAP_amount</td>
579 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
580 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
582 <td>$projectnumber</td>
590 ($form->{taxincluded})
591 ? $locale->text('Tax Included')
592 : $locale->text('Tax');
594 $form->{invtotal_unformatted} = $form->{invtotal};
595 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
598 NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
599 '-style' => 'width:400px',
600 '-values' => \@AP_values, '-labels' => \%AP_labels,
601 '-default' => $form->{APselected}));
609 <td>${APselected}</td>
610 <th align=left>$form->{invtotal}</th>
612 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
613 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
615 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
628 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
629 <td align=left>$notes</td>
637 <tr class=listheading>
638 <th class=listheading colspan=7>| . $locale->text('Payments') . qq|</th>
643 if ($form->{defaultcurrency} && ($form->{currency} eq $form->{defaultcurrency})) {
644 @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
646 @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
650 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
651 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
652 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
653 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
654 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
655 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
656 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
661 map { print "$column_data{$_}\n" } @column_index;
667 $form->{totalpaid} = 0;
669 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
670 for my $i (1 .. $form->{paidaccounts}) {
676 NTI($cgi->popup_menu('-name' => "AP_paid_$i",
677 '-id' => "AP_paid_$i",
678 '-values' => \@AP_paid_values,
679 '-labels' => \%AP_paid_labels,
680 '-default' => $form->{"AP_paid_$i"}));
682 $form->{totalpaid} += $form->{"paid_$i"};
685 if ($form->{"paid_$i"}) {
687 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
689 if ($form->{"exchangerate_$i"} == 0) {
690 $form->{"exchangerate_$i"} = "";
692 $form->{"exchangerate_$i"} =
693 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
696 print qq|<input type=hidden name="gldate_$i" value=$form->{"gldate_$i"}>\n|;
697 my $changeable = (($form->{"gldate_$i"} eq '') || $form->current_date(\%myconfig) eq $form->{"gldate_$i"});
698 $form->{"payment_readonly_$i"} = ($changeable)? 0 : 1;
699 print qq|<input type=hidden name="payment_readonly_$i" value=$form->{"payment_readonly_$i"}>\n|;
701 $exchangerate = qq| |;
702 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
703 if ($form->{"forex_$i"}) {
705 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
709 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
711 $exchangerate = qq|$form->{"exchangerate_$i"}|.
712 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
718 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
723 $datepaid = 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)\">
724 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="| . $locale->text('Details (one letter abbreviation)') . qq|"></td>|;
726 $datepaid = qq|<td align=center>$form->{"datepaid_$i"}</td>|.
727 qq|<input type=hidden name="datepaid_$i" value=$form->{"datepaid_$i"}>|;
732 $paid = qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
734 $paid = qq|<td align=center>$form->{"paid_$i"}</td>|.
735 qq|<input type=hidden name="paid_$i" value=$form->{"paid_$i"}>|;
740 $source = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
742 $source = qq|<td align=center>$form->{"source_$i"}</td>|.
743 qq|<input type=hidden name="source_$i" value=$form->{"source_$i"}>|;
748 $memo = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
750 $memo = qq|<td align=center>$form->{"memo_$i"}</td>|.
751 qq|<input type=hidden name="memo_$i" value=$form->{"memo_$i"}>|;
756 $AP_paid = qq|<td align=center>${selectAP_paid}</td>|;
758 $AP_paid = qq|<td align=center>$form->{"AP_paid_$i"}</td>|.
759 qq|<input type=hidden name="AP_paid_$i" value=$form->{"AP_paid_$i"}>|;
766 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
767 '-values' => \@project_values,
768 '-labels' => \%project_labels,
769 '-default' => $form->{"paid_project_id_$i"} ))
772 my $projectnumber = $project_labels{$form->{"paid_project_id_$i"}};
773 $paid_project_id = qq|<td>$projectnumber</td>|.
774 qq|<input type=hidden name="paid_project_id_$i" value=$form->{"paid_project_id_$i"}>|;
777 $column_data{"paid_$i"} = $paid;
778 $column_data{"AP_paid_$i"} = $AP_paid;
779 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
780 $column_data{"datepaid_$i"} = $datepaid;
781 $column_data{"source_$i"} = $source;
782 $column_data{"memo_$i"} = $memo;
783 $column_data{"paid_project_id_$i"} = $paid_project_id;
785 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
791 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
795 my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid};
801 <td align="center">| . $locale->text('Total') . qq|</td>
802 <td align="center">| . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq|</td>
807 <td align="center">| . $locale->text('Missing amount') . qq|</td>
808 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
810 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
812 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
818 <td><hr size=3 noshade></td>
823 $main::lxdebug->leave_sub();
827 $main::lxdebug->enter_sub();
829 my $form = $main::form;
830 my %myconfig = %main::myconfig;
831 my $locale = $main::locale;
832 my $cgi = $main::cgi;
834 $main::auth->assert('general_ledger');
836 my $follow_ups_block;
838 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
840 if (@{ $follow_ups} ) {
841 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
842 $follow_ups_block = qq|<p>| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</p>|;
850 <input name=callback type=hidden value="$form->{callback}">
851 <input name="gldate" type="hidden" value="| . Q($form->{gldate}) . qq|">
853 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
854 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
860 if (!$form->{id} && $form->{draft_id}) {
861 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
862 '-value' => 1, '-checked' => $form->{remove_draft},
864 qq| <label for="remove_draft">| .
865 $locale->text("Remove draft when posting") .
869 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
870 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
872 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">|;
875 if ($form->{radier}) {
876 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
877 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">
880 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
881 print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
882 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}) && (($form->{totalpaid} == 0) || ($form->{totalpaid} eq "")));
884 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
885 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|">
886 <input type="button" class="submit" onclick="follow_up_window()" value="| . $locale->text('Follow-Up') . qq|">
888 } elsif (($transdate > $closedto) && !$form->{id}) {
890 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
891 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
893 # button for saving history
894 if($form->{id} ne "") {
895 print qq| <input type="button" class="submit" onclick="set_history_window($form->{id});" name="history" id="history" value="| . $locale->text('history') . qq|"> |;
897 # /button for saving history
898 # mark_as_paid button
899 if($form->{id} ne "") {
900 print qq| <input type="submit" class="submit" name="action" value="| . $locale->text('mark as paid') . qq|"> |;
902 # /mark_as_paid button
910 $main::lxdebug->leave_sub();
914 $main::lxdebug->enter_sub();
916 my $form = $main::form;
917 my %myconfig = %main::myconfig;
919 $main::auth->assert('general_ledger');
921 &mark_as_paid_common(\%myconfig,"ap");
923 $main::lxdebug->leave_sub();
927 $main::lxdebug->enter_sub();
929 my $form = $main::form;
930 my %myconfig = %main::myconfig;
932 $main::auth->assert('general_ledger');
936 $form->{invtotal} = 0;
938 delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
940 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
941 qw(exchangerate creditlimit creditremaining);
943 my @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id taxchart);
945 my (@a, $j, $totaltax);
946 for my $i (1 .. $form->{rowcount}) {
947 $form->{"amount_$i"} =
948 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
949 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
950 if ($form->{"amount_$i"}) {
953 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
955 if ($form->{taxincluded}) {
956 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
958 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
961 $form->{"tax_$i"} = 0;
963 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
965 $totaltax += $form->{"tax_$i"};
966 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
970 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
972 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
974 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell');
975 $form->{exchangerate} = $form->{forex} if $form->{forex};
977 $form->{invdate} = $form->{transdate};
978 my %saved_variables = map +( $_ => $form->{$_} ), qw(AP AP_amount_1 taxchart_1);
980 my $vendor_changed = &check_name("vendor");
982 $form->{AP} = $saved_variables{AP};
983 if ($saved_variables{AP_amount_1} =~ m/.--./) {
984 map { $form->{$_} = $saved_variables{$_} } qw(AP_amount_1 taxchart_1);
986 delete $form->{taxchart_1};
989 $form->{rowcount} = $count + 1;
992 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
995 for my $i (1 .. $form->{paidaccounts}) {
996 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
999 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1000 } qw(paid exchangerate);
1002 $totalpaid += $form->{"paid_$i"};
1004 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
1005 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1009 $form->{creditremaining} -=
1010 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
1011 $form->{oldinvtotal});
1012 $form->{oldinvtotal} = $form->{invtotal};
1013 $form->{oldtotalpaid} = $totalpaid;
1016 $form->{notes} = $form->{intnotes} if $vendor_changed;
1020 $main::lxdebug->leave_sub();
1025 $main::lxdebug->enter_sub();
1027 my $form = $main::form;
1028 my %myconfig = %main::myconfig;
1029 my $locale = $main::locale;
1031 $main::auth->assert('general_ledger');
1033 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1035 my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
1037 for my $i (1 .. $form->{paidaccounts}) {
1038 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1039 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1041 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1043 $form->error($locale->text('Cannot post payment for a closed period!'))
1044 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1046 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
1047 $form->{"exchangerate_$i"} = $form->{exchangerate}
1048 if ($invdate == $datepaid);
1049 $form->isblank("exchangerate_$i",
1050 $locale->text('Exchangerate for payment missing!'));
1055 ($form->{AP}) = split /--/, $form->{AP};
1056 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1057 $form->redirect($locale->text('Payment posted!'))
1058 if (AP->post_payment(\%myconfig, \%$form));
1059 $form->error($locale->text('Cannot post payment!'));
1062 $main::lxdebug->leave_sub();
1067 $main::lxdebug->enter_sub();
1069 my $form = $main::form;
1070 my %myconfig = %main::myconfig;
1071 my $locale = $main::locale;
1073 $main::auth->assert('general_ledger');
1075 # check if there is a vendor, invoice and due date
1076 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
1077 $form->isblank("duedate", $locale->text("Due Date missing!"));
1078 $form->isblank("vendor", $locale->text('Vendor missing!'));
1080 if ($myconfig{mandatory_departments} && !$form->{department}) {
1081 $form->{saved_message} = $::locale->text('You have to specify a department.');
1086 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1087 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1088 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
1090 my $zero_amount_posting = 1;
1091 for my $i (1 .. $form->{rowcount}) {
1092 if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
1093 $zero_amount_posting = 0;
1098 $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
1100 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1101 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
1102 delete($form->{AP});
1104 for my $i (1 .. $form->{paidaccounts}) {
1105 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1106 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1108 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1110 $form->error($locale->text('Cannot post payment for a closed period!'))
1111 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1113 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
1114 $form->{"exchangerate_$i"} = $form->{exchangerate}
1115 if ($transdate == $datepaid);
1116 $form->isblank("exchangerate_$i",
1117 $locale->text('Exchangerate for payment missing!'));
1123 # if old vendor ne vendor redo form
1124 my ($vendor) = split /--/, $form->{vendor};
1125 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
1129 my ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
1130 my ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
1131 my ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
1132 # $form->{AP_amount_1} = $debitaccno;
1133 $form->{AP_payables} = $payablesaccno;
1134 $form->{taxkey} = $taxkey;
1135 $form->{storno} = 0;
1137 $form->{id} = 0 if $form->{postasnew};
1139 if (AP->post_transaction(\%myconfig, \%$form)) {
1140 # saving the history
1141 if(!exists $form->{addition} && $form->{id} ne "") {
1142 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1143 $form->{addition} = "POSTED";
1144 $form->save_history;
1146 # /saving the history
1147 remove_draft() if $form->{remove_draft};
1148 # Dieser Text wird niemals ausgegeben: Probleme beim redirect?
1149 $form->redirect($locale->text('Transaction posted!'));
1151 $form->error($locale->text('Cannot post transaction!'));
1154 $main::lxdebug->leave_sub();
1158 $main::lxdebug->enter_sub();
1160 my $form = $main::form;
1161 my %myconfig = %main::myconfig;
1163 $main::auth->assert('general_ledger');
1165 $form->{postasnew} = 1;
1166 # saving the history
1167 if(!exists $form->{addition} && $form->{id} ne "") {
1168 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1169 $form->{addition} = "POSTED AS NEW";
1170 $form->save_history;
1172 # /saving the history
1175 $main::lxdebug->leave_sub();
1178 sub use_as_template {
1179 $main::lxdebug->enter_sub();
1181 my $form = $main::form;
1182 my %myconfig = %main::myconfig;
1184 $main::auth->assert('general_ledger');
1186 map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
1187 $form->{paidaccounts} = 1;
1188 $form->{rowcount}--;
1189 $form->{invdate} = $form->current_date(\%myconfig);
1192 $main::lxdebug->leave_sub();
1196 $main::lxdebug->enter_sub();
1198 my $form = $main::form;
1199 my $locale = $main::locale;
1201 $main::auth->assert('general_ledger');
1203 $form->{title} = $locale->text('Confirm!');
1207 delete $form->{header};
1212 <form method=post action=$form->{script}>
1215 foreach my $key (keys %$form) {
1216 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1217 $form->{$key} =~ s/\"/"/g;
1218 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1222 <h2 class=confirm>$form->{title}</h2>
1225 . $locale->text('Are you sure you want to delete Transaction')
1226 . qq| $form->{invnumber}</h4>
1228 <input name=action class=submit type=submit value="|
1229 . $locale->text('Yes') . qq|">
1236 $main::lxdebug->leave_sub();
1240 $main::lxdebug->enter_sub();
1242 my $form = $main::form;
1243 my %myconfig = %main::myconfig;
1244 my $locale = $main::locale;
1246 $main::auth->assert('general_ledger');
1248 if (AP->delete_transaction(\%myconfig, \%$form)) {
1249 # saving the history
1250 if(!exists $form->{addition}) {
1251 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1252 $form->{addition} = "DELETED";
1253 $form->save_history;
1255 # /saving the history
1256 $form->redirect($locale->text('Transaction deleted!'));
1258 $form->error($locale->text('Cannot delete transaction!'));
1260 $main::lxdebug->leave_sub();
1264 $main::lxdebug->enter_sub();
1266 $main::auth->assert('general_ledger | vendor_invoice_edit');
1268 my $form = $main::form;
1269 my %myconfig = %main::myconfig;
1270 my $locale = $main::locale;
1272 # setup customer selection
1273 $form->all_vc(\%myconfig, "vendor", "AP");
1275 $form->{title} = $locale->text('AP Transactions');
1276 $form->{fokus} = "search.vendor";
1277 $form->{jsscript} = 1;
1279 $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 },
1280 "departments" => "ALL_DEPARTMENTS",
1281 "vendors" => "ALL_VC");
1283 # constants and subs for template
1284 $form->{jsscript} = 1;
1285 $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
1288 print $form->parse_html_template('ap/search', { %myconfig });
1290 $main::lxdebug->leave_sub();
1293 sub create_subtotal_row {
1294 $main::lxdebug->enter_sub();
1296 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1298 my $form = $main::form;
1299 my %myconfig = %main::myconfig;
1301 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1303 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1305 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1307 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1309 $main::lxdebug->leave_sub();
1314 sub ap_transactions {
1315 $main::lxdebug->enter_sub();
1317 my $form = $main::form;
1318 my %myconfig = %main::myconfig;
1319 my $locale = $main::locale;
1321 $main::auth->assert('general_ledger | vendor_invoice_edit');
1323 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
1325 report_generator_set_default_sort('transdate', 1);
1327 AP->ap_transactions(\%myconfig, \%$form);
1329 $form->{title} = $locale->text('AP Transactions');
1331 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1334 qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
1335 due duedate transaction_description notes employee globalprojectnumber
1336 vendornumber country ustid taxzone payment_terms charts);
1338 my @hidden_variables = map { "l_${_}" } @columns;
1339 push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto department);
1341 my $href = build_std_url('action=ap_transactions', grep { $form->{$_} } @hidden_variables);
1344 'transdate' => { 'text' => $locale->text('Date'), },
1345 'id' => { 'text' => $locale->text('ID'), },
1346 'type' => { 'text' => $locale->text('Type'), },
1347 'invnumber' => { 'text' => $locale->text('Invoice'), },
1348 'ordnumber' => { 'text' => $locale->text('Order'), },
1349 'name' => { 'text' => $locale->text('Vendor'), },
1350 'netamount' => { 'text' => $locale->text('Amount'), },
1351 'tax' => { 'text' => $locale->text('Tax'), },
1352 'amount' => { 'text' => $locale->text('Total'), },
1353 'paid' => { 'text' => $locale->text('Paid'), },
1354 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1355 'due' => { 'text' => $locale->text('Amount Due'), },
1356 'duedate' => { 'text' => $locale->text('Due Date'), },
1357 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1358 'notes' => { 'text' => $locale->text('Notes'), },
1359 'employee' => { 'text' => $locale->text('Employee'), },
1360 'globalprojectnumber' => { 'text' => $locale->text('Document Project Number'), },
1361 'vendornumber' => { 'text' => $locale->text('Vendor Number'), },
1362 'country' => { 'text' => $locale->text('Country'), },
1363 'ustid' => { 'text' => $locale->text('USt-IdNr.'), },
1364 'taxzone' => { 'text' => $locale->text('Steuersatz'), },
1365 'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
1366 'charts' => { 'text' => $locale->text('Buchungskonto'), },
1369 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
1370 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1371 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1374 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1376 $form->{"l_type"} = "Y";
1377 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1379 $report->set_columns(%column_defs);
1380 $report->set_column_order(@columns);
1382 $report->set_export_options('ap_transactions', @hidden_variables, qw(sort sortdir));
1384 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1387 push @options, $locale->text('Vendor') . " : $form->{vendor}" if ($form->{vendor});
1388 push @options, $locale->text('Department') . " : " . (split /--/, $form->{department})[0] if ($form->{department});
1389 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}" if ($form->{invnumber});
1390 push @options, $locale->text('Order Number') . " : $form->{ordnumber}" if ($form->{ordnumber});
1391 push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
1392 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}" if ($form->{transaction_description});
1393 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1) if ($form->{transdatefrom});
1394 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1) if ($form->{transdateto});
1395 push @options, $locale->text('Open') if ($form->{open});
1396 push @options, $locale->text('Closed') if ($form->{closed});
1398 $report->set_options('top_info_text' => join("\n", @options),
1399 'raw_bottom_info_text' => $form->parse_html_template('ap/ap_transactions_bottom'),
1400 'output_format' => 'HTML',
1401 'title' => $form->{title},
1402 'attachment_basename' => $locale->text('vendor_invoice_list') . strftime('_%Y%m%d', localtime time),
1404 $report->set_options_from_form();
1405 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1407 # add sort and escape callback, this one we use for the add sub
1408 $form->{callback} = $href .= "&sort=$form->{sort}";
1410 # escape callback for href
1411 my $callback = $form->escape($href);
1413 my @subtotal_columns = qw(netamount amount paid due);
1415 my %totals = map { $_ => 0 } @subtotal_columns;
1416 my %subtotals = map { $_ => 0 } @subtotal_columns;
1420 foreach my $ap (@{ $form->{AP} }) {
1421 $ap->{tax} = $ap->{amount} - $ap->{netamount};
1422 $ap->{due} = $ap->{amount} - $ap->{paid};
1424 map { $subtotals{$_} += $ap->{$_};
1425 $totals{$_} += $ap->{$_} } @subtotal_columns;
1427 map { $ap->{$_} = $form->format_amount(\%myconfig, $ap->{$_}, 2) } qw(netamount tax amount paid due);
1429 my $is_storno = $ap->{storno} && $ap->{storno_id};
1430 my $has_storno = $ap->{storno} && !$ap->{storno_id};
1432 if ($ap->{invoice}) {
1434 $has_storno ? $locale->text("Invoice with Storno (abbreviation)")
1435 : $is_storno ? $locale->text("Storno (one letter abbreviation)")
1436 : $locale->text("Invoice (one letter abbreviation)");
1439 $has_storno ? $locale->text("AP Transaction with Storno (abbreviation)")
1440 : $is_storno ? $locale->text("AP Transaction Storno (one letter abbreviation)")
1441 : $locale->text("AP Transaction (abbreviation)");
1446 foreach my $column (@columns) {
1448 'data' => $ap->{$column},
1449 'align' => $column_alignment{$column},
1453 $row->{invnumber}->{link} = build_std_url("script=" . ($ap->{invoice} ? 'ir.pl' : 'ap.pl'), 'action=edit')
1454 . "&id=" . E($ap->{id}) . "&callback=${callback}";
1456 my $row_set = [ $row ];
1458 if (($form->{l_subtotal} eq 'Y')
1459 && (($idx == (scalar @{ $form->{AP} } - 1))
1460 || ($ap->{ $form->{sort} } ne $form->{AP}->[$idx + 1]->{ $form->{sort} }))) {
1461 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1464 $report->add_data($row_set);
1469 $report->add_separator();
1470 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1472 $report->generate_with_headers();
1474 $main::lxdebug->leave_sub();
1478 $main::lxdebug->enter_sub();
1480 my $form = $main::form;
1481 my %myconfig = %main::myconfig;
1482 my $locale = $main::locale;
1484 $main::auth->assert('general_ledger');
1486 if (IS->has_storno(\%myconfig, $form, 'ap')) {
1487 $form->{title} = $locale->text("Cancel Accounts Payables Transaction");
1488 $form->error($locale->text("Transaction has already been cancelled!"));
1491 AP->storno($form, \%myconfig, $form->{id});
1493 # saving the history
1494 if(!exists $form->{addition} && $form->{id} ne "") {
1495 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1496 $form->{addition} = "STORNO";
1497 $form->save_history;
1499 # /saving the history
1501 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1503 $main::lxdebug->leave_sub();