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";
53 # this is for our long dates
54 # $locale->text('January')
55 # $locale->text('February')
56 # $locale->text('March')
57 # $locale->text('April')
58 # $locale->text('May ')
59 # $locale->text('June')
60 # $locale->text('July')
61 # $locale->text('August')
62 # $locale->text('September')
63 # $locale->text('October')
64 # $locale->text('November')
65 # $locale->text('December')
67 # this is for our short month
68 # $locale->text('Jan')
69 # $locale->text('Feb')
70 # $locale->text('Mar')
71 # $locale->text('Apr')
72 # $locale->text('May')
73 # $locale->text('Jun')
74 # $locale->text('Jul')
75 # $locale->text('Aug')
76 # $locale->text('Sep')
77 # $locale->text('Oct')
78 # $locale->text('Nov')
79 # $locale->text('Dec')
82 $lxdebug->enter_sub();
84 $auth->assert('general_ledger');
86 return $lxdebug->leave_sub() if (load_draft_maybe());
88 $form->{title} = "Add";
90 $form->{callback} = "ap.pl?action=add" unless $form->{callback};
92 AP->get_transdate(\%myconfig, $form);
93 $form->{initial_transdate} = $form->{transdate};
95 $form->{transdate} = $form->{initial_transdate};
98 $lxdebug->leave_sub();
102 $lxdebug->enter_sub();
104 $auth->assert('general_ledger');
106 $form->{title} = "Edit";
111 $lxdebug->leave_sub();
115 $lxdebug->enter_sub();
117 $auth->assert('general_ledger');
122 $lxdebug->leave_sub();
126 $lxdebug->enter_sub();
128 $auth->assert('general_ledger');
130 $form->create_links("AP", \%myconfig, "vendor");
131 $taxincluded = $form->{taxincluded};
132 $duedate = $form->{duedate};
134 IR->get_vendor(\%myconfig, \%$form);
135 $form->{taxincluded} = $taxincluded;
136 $form->{duedate} = $duedate if $duedate;
137 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
138 $form->{rowcount} = 1;
140 # build the popup menus
141 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
144 $form->{notes} = $form->{intnotes} unless $form->{notes};
147 @curr = split(/:/, $form->{currencies});
149 $form->{defaultcurrency} = $curr[0];
151 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
154 if (@{ $form->{all_vendor} }) {
155 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
156 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
157 (@{ $form->{all_vendor} });
161 if (@{ $form->{all_departments} }) {
162 $form->{selectdepartment} = "<option>\n";
163 $form->{department} = "$form->{department}--$form->{department_id}";
166 $form->{selectdepartment} .=
167 "<option>$_->{description}--$_->{id}\n"
168 } (@{ $form->{all_departments} });
171 $form->{employee} = "$form->{employee}--$form->{employee_id}";
173 AP->setup_form($form);
176 ($form->datetonum($form->{transdate}, \%myconfig) <=
177 $form->datetonum($form->{closedto}, \%myconfig));
179 $lxdebug->leave_sub();
183 $lxdebug->enter_sub();
185 $auth->assert('general_ledger');
187 $title = $form->{title};
188 $form->{title} = $locale->text("$title Accounts Payables Transaction");
190 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
192 # type=submit $locale->text('Add Accounts Payables Transaction')
193 # type=submit $locale->text('Edit Accounts Payables Transaction')
195 $form->{javascript} = qq|<script type="text/javascript">
197 function setTaxkey(accno, row) {
198 var taxkey = accno.options[accno.selectedIndex].value;
199 var reg = /--([0-9]*)/;
200 var found = reg.exec(taxkey);
201 var index = found[1];
202 index = parseInt(index);
203 var tax = 'taxchart_' + row;
204 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
205 var reg2 = new RegExp("^"+ index, "");
206 if (reg2.exec(document.getElementById(tax).options[i].value)) {
207 document.getElementById(tax).options[i].selected = true;
214 # show history button
215 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
216 #/show hhistory button
218 # set option selected
219 foreach $item (qw(vendor currency department)) {
220 $form->{"select$item"} =~ s/ selected//;
221 $form->{"select$item"} =~
222 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
224 $readonly = ($form->{id}) ? "readonly" : "";
226 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
227 $readonly = ($form->{radier}) ? "" : $readonly;
229 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell');
230 $form->{exchangerate} = $form->{forex} if $form->{forex};
234 $form->{exchangerate} =
235 $form->format_amount(\%myconfig, $form->{exchangerate});
236 if ($form->{exchangerate} == 0) {
237 $form->{exchangerate} = "";
239 $form->{creditlimit} =
240 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
241 $form->{creditremaining} =
242 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
245 <input type=hidden name=forex value=$form->{forex}>
247 if ($form->{currency} ne $form->{defaultcurrency}) {
248 if ($form->{forex}) {
251 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
252 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
257 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
258 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
267 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
268 <th align=left nowrap>|
269 . $locale->text('Tax Included') . qq|</th>
273 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
277 qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
281 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
282 <td colspan=3><select name=department>$form->{selectdepartment}</select>
283 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
286 | if $form->{selectdepartment};
288 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
291 ($form->{selectvendor})
292 ? qq|<select name="vendor"
293 onchange="document.getElementById('update_button').click();">$form->{
294 selectvendor } </select>|
295 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
297 my @old_project_ids = ();
298 map({ push(@old_project_ids, $form->{"project_id_$_"})
299 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
301 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
303 "old_id" => \@old_project_ids },
304 "charts" => { "key" => "ALL_CHARTS",
305 "transdate" => $form->{transdate} },
306 "taxcharts" => { "key" => "ALL_TAXCHARTS",
307 "module" => "AP" },);
309 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
310 @{ $form->{ALL_CHARTS} });
312 my %project_labels = ();
313 my @project_values = ("");
314 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
315 push(@project_values, $item->{"id"});
316 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
319 my (%AP_amount_labels, @AP_amount_values);
320 my (%AP_labels, @AP_values);
321 my (%AP_paid_labels, @AP_paid_values);
325 foreach my $item (@{ $form->{ALL_CHARTS} }) {
326 if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) {
327 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
328 my $key = "$item->{accno}--$item->{tax_id}";
329 push(@AP_amount_values, $key);
330 $AP_amount_labels{$key} =
331 "$item->{accno}--$item->{description}";
333 } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) {
334 push(@AP_values, $item->{accno});
335 $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
337 } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) {
338 push(@AP_paid_values, $item->{accno});
339 $AP_paid_labels{$item->{accno}} =
340 "$item->{accno}--$item->{description}";
343 $charts{$item->{accno}} = $item;
346 my %taxchart_labels = ();
347 my @taxchart_values = ();
349 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
350 my $key = "$item->{id}--$item->{rate}";
351 $taxchart_init = $key if ($taxchart_init eq $item->{id});
352 push(@taxchart_values, $key);
353 $taxchart_labels{$key} =
354 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
355 $taxcharts{$item->{id}} = $item;
358 # use JavaScript Calendar or not
359 $form->{jsscript} = 1;
361 if ($form->{jsscript}) {
363 # with JavaScript Calendar
365 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\" $readonly></td>
366 <td><input type=button name=transdate id="trigger1" value=|
367 . $locale->text('button') . qq|></td>
370 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\" $readonly></td>
371 <td><input type=button name=duedate id="trigger2" value=|
372 . $locale->text('button') . qq|></td></td>
377 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
378 "duedate", "BL", "trigger2");
381 # without JavaScript Calendar
383 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\" $readonly></td>|;
385 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\" $readonly></td>|;
388 my $follow_up_vc = $form->{vendor};
389 $follow_up_vc =~ s/--.*?//;
390 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
392 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
393 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
394 $form->{javascript} .= qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
397 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
398 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
400 <body onLoad="$onload">
402 <form method=post action=$form->{script}>
404 <input type=hidden name=id value=$form->{id}>
405 <input type=hidden name=sort value=$form->{sort}>
406 <input type=hidden name=closedto value=$form->{closedto}>
407 <input type=hidden name=locked value=$form->{locked}>
408 <input type=hidden name=title value="$title">
410 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
411 <input type="hidden" name="follow_up_trans_type_1" value="ap_transaction">
412 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
413 <input type="hidden" name="follow_up_rowcount" value="1">
415 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
419 <th class=listtop>$form->{title}</th>
429 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
430 <td colspan=3>$vendor <input type="button" value="?" onclick="show_vc_details('vendor')"></td>
431 <input type=hidden name=selectvendor value="$form->{selectvendor}">
432 <input type=hidden name=oldvendor value="$form->{oldvendor}">
433 <input type=hidden name=vendor_id value="$form->{vendor_id}">
434 <input type=hidden name=terms value=$form->{terms}>
441 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
442 <td>$form->{creditlimit}</td>
443 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
444 <td class="plus$n">$form->{creditremaining}</td>
445 <input type=hidden name=creditlimit value=$form->{creditlimit}>
446 <input type=hidden name=creditremaining value=$form->{creditremaining}>
451 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
452 <td><select name=currency>$form->{selectcurrency}</select></td>
453 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
454 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
455 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
456 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
466 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
467 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
470 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
471 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
474 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
478 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
491 <input type=hidden name=rowcount value=$form->{rowcount}>
495 <tr class=listheading>
496 <th class=listheading style="width:15%">|
497 . $locale->text('Account') . qq|</th>
498 <th class=listheading style="width:10%">|
499 . $locale->text('Amount') . qq|</th>
500 <th class=listheading style="width:10%">|
501 . $locale->text('Tax') . qq|</th>
502 <th class=listheading style="width:10%">|
503 . $locale->text('Taxkey') . qq|</th>
504 <th class=listheading style="width:10%">|
505 . $locale->text('Project') . qq|</th>
509 $amount = $locale->text('Amount');
510 $project = $locale->text('Project');
512 for $i (1 .. $form->{rowcount}) {
515 $form->{"amount_$i"} =
516 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
517 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
519 my $selected_accno_full;
520 my ($accno_row) = split(/--/, $form->{"AP_amount_$i"});
521 my $item = $charts{$accno_row};
522 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
524 my $selected_taxchart = $form->{"taxchart_$i"};
525 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
526 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AP_amount_$i"});
528 if ($previous_accno &&
529 ($previous_accno eq $selected_accno) &&
530 ($previous_tax_id ne $selected_tax_id)) {
531 my $item = $taxcharts{$selected_tax_id};
532 $selected_taxchart = "$item->{id}--$item->{rate}";
535 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
538 NTI($cgi->popup_menu('-name' => "AP_amount_$i",
539 '-id' => "AP_amount_$i",
540 '-style' => 'width:400px',
541 '-onChange' => "setTaxkey(this, $i)",
542 '-values' => \@AP_amount_values,
543 '-labels' => \%AP_amount_labels,
544 '-default' => $selected_accno_full))
545 . $cgi->hidden('-name' => "previous_AP_amount_$i",
546 '-default' => $selected_accno_full);
549 NTI($cgi->popup_menu('-name' => "taxchart_$i",
550 '-id' => "taxchart_$i",
551 '-style' => 'width:200px',
552 '-values' => \@taxchart_values,
553 '-labels' => \%taxchart_labels,
554 '-default' => $selected_taxchart))
558 NTI($cgi->popup_menu('-name' => "project_id_$i",
559 '-values' => \@project_values,
560 '-labels' => \%project_labels,
561 '-default' => $form->{"project_id_$i"} ));
565 <td>$selectAP_amount</td>
566 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
567 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
569 <td>$projectnumber</td>
577 ($form->{taxincluded})
578 ? $locale->text('Tax Included')
579 : $locale->text('Tax');
581 $form->{invtotal_unformatted} = $form->{invtotal};
582 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
585 NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
586 '-style' => 'width:400px',
587 '-values' => \@AP_values, '-labels' => \%AP_labels,
588 '-default' => $form->{APselected}));
596 <td>${APselected}</td>
597 <th align=left>$form->{invtotal}</th>
599 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
600 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
602 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
615 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
616 <td align=left>$notes</td>
624 <tr class=listheading>
625 <th class=listheading colspan=7>| . $locale->text('Payments') . qq|</th>
629 if ($form->{currency} eq $form->{defaultcurrency}) {
630 @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
632 @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
635 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
636 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
637 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
638 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
639 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
640 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
641 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
646 map { print "$column_data{$_}\n" } @column_index;
654 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
655 for $i (1 .. $form->{paidaccounts}) {
661 NTI($cgi->popup_menu('-name' => "AP_paid_$i",
662 '-id' => "AP_paid_$i",
663 '-values' => \@AP_paid_values,
664 '-labels' => \%AP_paid_labels,
665 '-default' => $form->{"AP_paid_$i"}));
667 $totalpaid += $form->{"paid_$i"};
670 if ($form->{"paid_$i"}) {
672 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
674 $form->{"exchangerate_$i"} =
675 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
676 if ($form->{"exchangerate_$i"} == 0) {
677 $form->{"exchangerate_$i"} = "";
680 $exchangerate = qq| |;
681 if ($form->{currency} ne $form->{defaultcurrency}) {
682 if ($form->{"forex_$i"}) {
684 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
687 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
692 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
695 $column_data{"paid_$i"} =
696 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
697 $column_data{"AP_paid_$i"} =
698 qq|<td align=center>${selectAP_paid}</td>|;
699 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
700 $column_data{"datepaid_$i"} =
701 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)\">
702 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
703 $column_data{"source_$i"} =
704 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
705 $column_data{"memo_$i"} =
706 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
707 $column_data{"paid_project_id_$i"} =
709 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
710 '-values' => \@project_values,
711 '-labels' => \%project_labels,
712 '-default' => $form->{"paid_project_id_$i"} ))
715 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
720 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
723 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
729 <td align="center">| . $locale->text('Total') . qq|</td>
730 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
735 <td align="center">| . $locale->text('Missing amount') . qq|</td>
736 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
738 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
740 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
746 <td><hr size=3 noshade></td>
751 $lxdebug->leave_sub();
755 $lxdebug->enter_sub();
757 $auth->assert('general_ledger');
759 my $follow_ups_block;
761 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
763 if (@{ $follow_ups} ) {
764 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
765 $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>|;
773 <input name=callback type=hidden value="$form->{callback}">
774 <input name="gldate" type="hidden" value="| . Q($form->{gldate}) . qq|">
776 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
777 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
783 if (!$form->{id} && $form->{draft_id}) {
784 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
785 '-value' => 1, '-checked' => $form->{remove_draft},
787 qq| <label for="remove_draft">| .
788 $locale->text("Remove draft when posting") .
792 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
793 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
795 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">|;
798 if ($form->{radier}) {
799 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
800 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">
804 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
805 print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
806 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}));
808 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
809 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|">
810 <input type="button" class="submit" onclick="follow_up_window()" value="| . $locale->text('Follow-Up') . qq|">
812 } elsif (($transdate > $closedto) && !$form->{id}) {
814 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
815 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
817 # button for saving history
818 if($form->{id} ne "") {
819 print qq| <input type="button" class="submit" onclick="set_history_window($form->{id});" name="history" id="history" value="| . $locale->text('history') . qq|"> |;
821 # /button for saving history
822 # mark_as_paid button
823 if($form->{id} ne "") {
824 print qq| <input type="submit" class="submit" name="action" value="| . $locale->text('mark as paid') . qq|"> |;
826 # /mark_as_paid button
834 $lxdebug->leave_sub();
838 $lxdebug->enter_sub();
840 $auth->assert('general_ledger');
842 &mark_as_paid_common(\%myconfig,"ap");
844 $lxdebug->leave_sub();
848 $lxdebug->enter_sub();
850 $auth->assert('general_ledger');
854 $form->{invtotal} = 0;
856 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
857 qw(exchangerate creditlimit creditremaining);
859 @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
861 for $i (1 .. $form->{rowcount}) {
862 $form->{"amount_$i"} =
863 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
864 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
865 if ($form->{"amount_$i"}) {
868 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
870 if ($form->{taxincluded}) {
871 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
873 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
876 $form->{"tax_$i"} = 0;
878 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
880 $totaltax += $form->{"tax_$i"};
881 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
885 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
887 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
889 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell');
890 $form->{exchangerate} = $form->{forex} if $form->{forex};
892 $form->{invdate} = $form->{transdate};
893 $save_AP = $form->{AP};
894 &check_name("vendor");
895 $form->{AP} = $save_AP;
897 $form->{rowcount} = $count + 1;
900 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
902 for $i (1 .. $form->{paidaccounts}) {
903 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
906 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
907 } qw(paid exchangerate);
909 $totalpaid += $form->{"paid_$i"};
911 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
912 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
916 $form->{creditremaining} -=
917 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
918 $form->{oldinvtotal});
919 $form->{oldinvtotal} = $form->{invtotal};
920 $form->{oldtotalpaid} = $totalpaid;
923 $form->{notes} = $form->{intnotes};
927 $lxdebug->leave_sub();
932 $lxdebug->enter_sub();
934 $auth->assert('general_ledger');
936 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
938 for $i (1 .. $form->{paidaccounts}) {
939 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
940 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
942 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
944 $form->error($locale->text('Cannot post payment for a closed period!'))
945 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
947 if ($form->{currency} ne $form->{defaultcurrency}) {
948 $form->{"exchangerate_$i"} = $form->{exchangerate}
949 if ($invdate == $datepaid);
950 $form->isblank("exchangerate_$i",
951 $locale->text('Exchangerate for payment missing!'));
956 ($form->{AP}) = split /--/, $form->{AP};
957 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
958 $form->redirect($locale->text('Payment posted!'))
959 if (AP->post_payment(\%myconfig, \%$form));
960 $form->error($locale->text('Cannot post payment!'));
963 $lxdebug->leave_sub();
968 $lxdebug->enter_sub();
970 $auth->assert('general_ledger');
972 # check if there is a vendor, invoice and due date
973 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
974 $form->isblank("duedate", $locale->text("Due Date missing!"));
975 $form->isblank("vendor", $locale->text('Vendor missing!'));
977 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
978 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
979 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
981 my $zero_amount_posting = 1;
982 for $i (1 .. $form->{rowcount}) {
983 if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
984 $zero_amount_posting = 0;
989 $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
991 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
992 if ($form->{currency} ne $form->{defaultcurrency});
995 for $i (1 .. $form->{paidaccounts}) {
996 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
997 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
999 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1001 $form->error($locale->text('Cannot post payment for a closed period!'))
1002 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1004 if ($form->{currency} ne $form->{defaultcurrency}) {
1005 $form->{"exchangerate_$i"} = $form->{exchangerate}
1006 if ($transdate == $datepaid);
1007 $form->isblank("exchangerate_$i",
1008 $locale->text('Exchangerate for payment missing!'));
1014 # if old vendor ne vendor redo form
1015 ($vendor) = split /--/, $form->{vendor};
1016 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
1020 ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
1021 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
1022 ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
1023 $form->{AP}{amount_1} = $debitaccno;
1024 $form->{AP}{payables} = $payablesaccno;
1025 $form->{taxkey} = $taxkey;
1026 $form->{storno} = 0;
1028 $form->{id} = 0 if $form->{postasnew};
1030 if (AP->post_transaction(\%myconfig, \%$form)) {
1031 # saving the history
1032 if(!exists $form->{addition} && $form->{id} ne "") {
1033 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1034 $form->{addition} = "POSTED";
1035 $form->save_history($form->dbconnect(\%myconfig));
1037 # /saving the history
1038 remove_draft() if $form->{remove_draft};
1039 $form->redirect($locale->text('Transaction posted!'));
1041 $form->error($locale->text('Cannot post transaction!'));
1043 $lxdebug->leave_sub();
1047 $lxdebug->enter_sub();
1049 $auth->assert('general_ledger');
1051 $form->{postasnew} = 1;
1052 # saving the history
1053 if(!exists $form->{addition} && $form->{id} ne "") {
1054 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1055 $form->{addition} = "POSTED AS NEW";
1056 $form->save_history($form->dbconnect(\%myconfig));
1058 # /saving the history
1061 $lxdebug->leave_sub();
1064 sub use_as_template {
1065 $lxdebug->enter_sub();
1067 $auth->assert('general_ledger');
1069 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);
1070 $form->{paidaccounts} = 1;
1071 $form->{rowcount}--;
1072 $form->{invdate} = $form->current_date(\%myconfig);
1075 $lxdebug->leave_sub();
1079 $lxdebug->enter_sub();
1081 $auth->assert('general_ledger');
1083 $form->{title} = $locale->text('Confirm!');
1087 delete $form->{header};
1092 <form method=post action=$form->{script}>
1095 foreach $key (keys %$form) {
1096 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1097 $form->{$key} =~ s/\"/"/g;
1098 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1102 <h2 class=confirm>$form->{title}</h2>
1105 . $locale->text('Are you sure you want to delete Transaction')
1106 . qq| $form->{invnumber}</h4>
1108 <input name=action class=submit type=submit value="|
1109 . $locale->text('Yes') . qq|">
1116 $lxdebug->leave_sub();
1120 $lxdebug->enter_sub();
1122 $auth->assert('general_ledger');
1124 if (AP->delete_transaction(\%myconfig, \%$form, $spool)) {
1125 # saving the history
1126 if(!exists $form->{addition}) {
1127 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1128 $form->{addition} = "DELETED";
1129 $form->save_history($form->dbconnect(\%myconfig));
1131 # /saving the history
1132 $form->redirect($locale->text('Transaction deleted!'));
1134 $form->error($locale->text('Cannot delete transaction!'));
1136 $lxdebug->leave_sub();
1140 $lxdebug->enter_sub();
1142 $auth->assert('general_ledger | vendor_invoice_edit');
1144 # setup vendor selection
1145 $form->all_vc(\%myconfig, "vendor", "AP");
1147 if (@{ $form->{all_vendor} }) {
1148 map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
1149 @{ $form->{all_vendor} };
1150 $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
1152 $vendor = qq|<input name=vendor size=35>|;
1156 if (@{ $form->{all_departments} }) {
1157 $form->{selectdepartment} = "<option>\n";
1160 $form->{selectdepartment} .=
1161 "<option>$_->{description}--$_->{id}\n"
1162 } (@{ $form->{all_departments} });
1167 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1168 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1170 | if $form->{selectdepartment};
1172 $form->{title} = $locale->text('AP Transactions');
1174 # use JavaScript Calendar or not
1175 $form->{jsscript} = 1;
1177 if ($form->{jsscript}) {
1179 # with JavaScript Calendar
1181 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1182 <input type=button name=transdatefrom id="trigger1" value=|
1183 . $locale->text('button') . qq|></td>
1186 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1187 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1188 . $locale->text('button') . qq|></td>
1193 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1194 "transdateto", "BL", "trigger2");
1197 # without JavaScript Calendar
1199 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1201 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1204 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1209 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1210 push(@values, $item->{"id"});
1211 $labels{$item->{"id"}} = $item->{"projectnumber"};
1214 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1215 '-labels' => \%labels));
1216 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1218 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1219 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1221 <body onLoad="$onload">
1223 <form method=post action=$form->{script}>
1227 <th class=listtop>$form->{title}</th>
1229 <tr height="5"></tr>
1234 <th align=right>| . $locale->text('Vendor') . qq|</th>
1235 <td colspan=3>$vendor</td>
1239 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1240 <td colspan=3><input name=invnumber size=20></td>
1243 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1244 <td colspan=3><input name=ordnumber size=20></td>
1247 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1248 <td colspan=3><input name=notes size=40></td>
1251 <th align="right">| . $locale->text("Project Number") . qq|</th>
1252 <td colspan="3">$projectnumber</td>
1255 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1257 <th align=right>| . $locale->text('Bis') . qq|</th>
1260 <input type=hidden name=sort value=transdate>
1268 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1272 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1273 <td nowrap>| . $locale->text('Open') . qq|</td>
1274 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1275 <td nowrap>| . $locale->text('Closed') . qq|</td>
1278 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1279 <td nowrap>| . $locale->text('ID') . qq|</td>
1280 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1281 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1282 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1283 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1286 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1287 <td nowrap>| . $locale->text('Vendor') . qq|</td>
1288 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1289 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1290 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1291 <td nowrap>| . $locale->text('Amount') . qq|</td>
1294 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1295 <td nowrap>| . $locale->text('Tax') . qq|</td>
1296 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1297 <td nowrap>| . $locale->text('Total') . qq|</td>
1298 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1299 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1302 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1303 <td nowrap>| . $locale->text('Paid') . qq|</td>
1304 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1305 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1306 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1307 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1310 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1311 <td nowrap>| . $locale->text('Notes') . qq|</td>
1312 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1313 <td nowrap>| . $locale->text('Employee') . qq|</td>
1316 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1317 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1318 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1319 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1328 <td><hr size=3 noshade></td>
1335 <input type=hidden name=nextsub value=$form->{nextsub}>
1337 <input class=submit type=submit name=action value="|
1338 . $locale->text('Continue') . qq|">
1345 $lxdebug->leave_sub();
1348 sub create_subtotal_row {
1349 $lxdebug->enter_sub();
1351 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1353 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1355 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1357 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1359 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1361 $lxdebug->leave_sub();
1366 sub ap_transactions {
1367 $lxdebug->enter_sub();
1369 $auth->assert('general_ledger | vendor_invoice_edit');
1371 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
1373 report_generator_set_default_sort('transdate', 1);
1375 AP->ap_transactions(\%myconfig, \%$form);
1377 $form->{title} = $locale->text('AP Transactions');
1379 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1382 qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
1383 due duedate transaction_description notes employee globalprojectnumber);
1385 my @hidden_variables = map { "l_${_}" } @columns;
1386 push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
1388 my $href = build_std_url('action=ap_transactions', grep { $form->{$_} } @hidden_variables);
1391 'transdate' => { 'text' => $locale->text('Date'), },
1392 'id' => { 'text' => $locale->text('ID'), },
1393 'type' => { 'text' => $locale->text('Type'), },
1394 'invnumber' => { 'text' => $locale->text('Invoice'), },
1395 'ordnumber' => { 'text' => $locale->text('Order'), },
1396 'name' => { 'text' => $locale->text('Vendor'), },
1397 'netamount' => { 'text' => $locale->text('Amount'), },
1398 'tax' => { 'text' => $locale->text('Tax'), },
1399 'amount' => { 'text' => $locale->text('Total'), },
1400 'paid' => { 'text' => $locale->text('Paid'), },
1401 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1402 'due' => { 'text' => $locale->text('Amount Due'), },
1403 'duedate' => { 'text' => $locale->text('Due Date'), },
1404 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1405 'notes' => { 'text' => $locale->text('Notes'), },
1406 'employee' => { 'text' => $locale->text('Salesperson'), },
1407 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1410 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
1411 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1412 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1415 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1417 $form->{"l_type"} = "Y";
1418 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1420 $report->set_columns(%column_defs);
1421 $report->set_column_order(@columns);
1423 $report->set_export_options('ap_transactions', @hidden_variables);
1425 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1428 if ($form->{vendor}) {
1429 push @options, $locale->text('Vendor') . " : $form->{vendor}";
1431 if ($form->{department}) {
1432 ($department) = split /--/, $form->{department};
1433 push @options, $locale->text('Department') . " : $department";
1435 if ($form->{invnumber}) {
1436 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1438 if ($form->{ordnumber}) {
1439 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1441 if ($form->{notes}) {
1442 push @options, $locale->text('Notes') . " : $form->{notes}";
1444 if ($form->{transaction_description}) {
1445 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1447 if ($form->{transdatefrom}) {
1448 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1450 if ($form->{transdateto}) {
1451 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1453 if ($form->{open}) {
1454 push @options, $locale->text('Open');
1456 if ($form->{closed}) {
1457 push @options, $locale->text('Closed');
1460 $report->set_options('top_info_text' => join("\n", @options),
1461 'raw_bottom_info_text' => $form->parse_html_template('ap/ap_transactions_bottom'),
1462 'output_format' => 'HTML',
1463 'title' => $form->{title},
1464 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1466 $report->set_options_from_form();
1468 # add sort and escape callback, this one we use for the add sub
1469 $form->{callback} = $href .= "&sort=$form->{sort}";
1471 # escape callback for href
1472 $callback = $form->escape($href);
1474 my @subtotal_columns = qw(netamount amount paid due);
1476 my %totals = map { $_ => 0 } @subtotal_columns;
1477 my %subtotals = map { $_ => 0 } @subtotal_columns;
1481 foreach $ap (@{ $form->{AP} }) {
1482 $ap->{tax} = $ap->{amount} - $ap->{netamount};
1483 $ap->{due} = $ap->{amount} - $ap->{paid};
1485 map { $subtotals{$_} += $ap->{$_};
1486 $totals{$_} += $ap->{$_} } @subtotal_columns;
1488 map { $ap->{$_} = $form->format_amount(\%myconfig, $ap->{$_}, 2) } qw(netamount tax amount paid due);
1490 my $is_storno = $ap->{storno} && $ap->{storno_id};
1491 my $has_storno = $ap->{storno} && !$ap->{storno_id};
1493 if ($ap->{invoice}) {
1495 $has_storno ? $locale->text("Invoice with Storno (abbreviation)")
1496 : $is_storno ? $locale->text("Storno (one letter abbreviation)")
1497 : $locale->text("Invoice (one letter abbreviation)");
1500 $has_storno ? $locale->text("AP Transaction with Storno (abbreviation)")
1501 : $is_storno ? $locale->text("AP Transaction Storno (one letter abbreviation)")
1502 : $locale->text("AP Transaction (abbreviation)");
1507 foreach my $column (@columns) {
1509 'data' => $ap->{$column},
1510 'align' => $column_alignment{$column},
1514 $row->{invnumber}->{link} = build_std_url("script=" . ($ap->{invoice} ? 'ir.pl' : 'ap.pl'), 'action=edit')
1515 . "&id=" . E($ap->{id}) . "&callback=${callback}";
1517 my $row_set = [ $row ];
1519 if (($form->{l_subtotal} eq 'Y')
1520 && (($idx == (scalar @{ $form->{AP} } - 1))
1521 || ($ap->{ $form->{sort} } ne $form->{AP}->[$idx + 1]->{ $form->{sort} }))) {
1522 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1525 $report->add_data($row_set);
1530 $report->add_separator();
1531 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1533 $report->generate_with_headers();
1535 $lxdebug->leave_sub();
1539 $lxdebug->enter_sub();
1541 $auth->assert('general_ledger');
1543 if (IS->has_storno(\%myconfig, $form, 'ap')) {
1544 $form->{title} = $locale->text("Cancel Accounts Payables Transaction");
1545 $form->error($locale->text("Transaction has already been cancelled!"));
1548 AP->storno($form, \%myconfig, $form->{id});
1550 # saving the history
1551 if(!exists $form->{addition} && $form->{id} ne "") {
1552 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1553 $form->{addition} = "STORNO";
1554 $form->save_history($form->dbconnect(\%myconfig));
1556 # /saving the history
1558 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1560 $lxdebug->leave_sub();