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 #======================================================================
30 # Accounts Receivables
32 #======================================================================
34 use POSIX qw(strftime);
35 use List::Util qw(sum first);
41 use SL::ReportGenerator;
43 require "bin/mozilla/arap.pl";
44 require "bin/mozilla/common.pl";
45 require "bin/mozilla/drafts.pl";
46 require "bin/mozilla/reportgenerator.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 $main::lxdebug->enter_sub();
82 $main::auth->assert('general_ledger');
84 my $form = $main::form;
85 my %myconfig = %main::myconfig;
87 return $main::lxdebug->leave_sub() if (load_draft_maybe());
90 if(!exists $form->{addition} && ($form->{id} ne "")) {
91 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
92 $form->{addition} = "ADDED";
97 $form->{title} = "Add";
98 $form->{callback} = "ar.pl?action=add" unless $form->{callback};
100 AR->get_transdate(\%myconfig, $form);
101 $form->{initial_transdate} = $form->{transdate};
103 $form->{transdate} = $form->{initial_transdate};
105 $main::lxdebug->leave_sub();
109 $main::lxdebug->enter_sub();
111 $main::auth->assert('general_ledger');
113 my $form = $main::form;
115 # show history button
116 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
117 #/show hhistory button
118 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
119 $form->{title} = "Edit";
124 $main::lxdebug->leave_sub();
128 $main::lxdebug->enter_sub();
130 $main::auth->assert('general_ledger');
132 my $form = $main::form;
137 $main::lxdebug->leave_sub();
141 $main::lxdebug->enter_sub();
143 $main::auth->assert('general_ledger');
145 my $form = $main::form;
146 my %myconfig = %main::myconfig;
148 my ($duedate, $taxincluded);
150 $form->create_links("AR", \%myconfig, "customer");
151 $duedate = $form->{duedate};
153 $taxincluded = $form->{taxincluded};
154 my $id = $form->{id};
155 IS->get_customer(\%myconfig, \%$form);
156 $form->{taxincluded} = $taxincluded;
159 $form->{duedate} = $duedate if $duedate;
160 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
161 $form->{rowcount} = 1;
164 $form->{notes} = $form->{intnotes} unless $form->{notes};
167 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
169 map { $form->{selectcurrency} .= "<option>$_\n" } $form->get_all_currencies(\%myconfig);
172 if (@{ $form->{all_customer} || [] }) {
173 $form->{customer} = "$form->{customer}--$form->{customer_id}";
174 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
175 (@{ $form->{all_customer} });
179 if (@{ $form->{all_departments} || [] }) {
180 $form->{selectdepartment} = "<option>\n";
181 $form->{department} = "$form->{department}--$form->{department_id}";
184 $form->{selectdepartment} .=
185 "<option>$_->{description}--$_->{id}\n"
186 } (@{ $form->{all_departments} || [] });
189 $form->{employee} = "$form->{employee}--$form->{employee_id}";
192 if (@{ $form->{all_employees} || [] }) {
193 $form->{selectemployee} = "";
194 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
195 (@{ $form->{all_employees} || [] });
198 # build the popup menus
199 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
201 AR->setup_form($form);
204 ($form->datetonum($form->{transdate}, \%myconfig) <=
205 $form->datetonum($form->{closedto}, \%myconfig));
207 $main::lxdebug->leave_sub();
211 $main::lxdebug->enter_sub();
213 $main::auth->assert('general_ledger');
215 my $form = $main::form;
216 my %myconfig = %main::myconfig;
217 my $locale = $main::locale;
218 my $cgi = $main::cgi;
220 my ($title, $readonly, $exchangerate, $rows);
221 my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
222 my ($jsscript, $button1, $button2, $onload);
223 my ($selectAR_amount, $selectAR_paid, $ARselected, $tax);
224 my (@column_index, %column_data);
227 $title = $form->{title};
228 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
230 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
232 # $locale->text('Add Accounts Receivables Transaction')
233 # $locale->text('Edit Accounts Receivables Transaction')
234 $form->{javascript} = qq|<script type="text/javascript">
236 function setTaxkey(accno, row) {
237 var taxkey = accno.options[accno.selectedIndex].value;
238 var reg = /--([0-9]*)/;
239 var found = reg.exec(taxkey);
240 var index = found[1];
241 index = parseInt(index);
242 var tax = 'taxchart_' + row;
243 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
244 var reg2 = new RegExp("^"+ index, "");
245 if (reg2.exec(document.getElementById(tax).options[i].value)) {
246 document.getElementById(tax).options[i].selected = true;
253 # show history button js
254 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
255 #/show history button js
256 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
257 $readonly = ($form->{id}) ? "readonly" : "";
260 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
261 $readonly = ($form->{radier}) ? "" : $readonly;
263 # set option selected
264 foreach my $item (qw(customer currency department employee)) {
265 $form->{"select$item"} =~ s/ selected//;
266 $form->{"select$item"} =~
267 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
270 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
271 $form->{exchangerate} = $form->{forex} if $form->{forex};
274 $form->{exchangerate} =
275 $form->format_amount(\%myconfig, $form->{exchangerate});
277 if ($form->{exchangerate} == 0) {
278 $form->{exchangerate} = "";
281 $form->{creditlimit} =
282 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
283 $form->{creditremaining} =
284 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
287 <input type=hidden name=forex value=$form->{forex}>
289 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
290 if ($form->{forex}) {
292 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
293 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
297 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
298 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
305 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
306 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
310 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
314 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
318 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
319 <td colspan=3><select name=department>$form->{selectdepartment}</select>
320 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
323 | if $form->{selectdepartment};
325 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
327 $customer = ($form->{selectcustomer})
328 ? qq|<select name="customer" onchange="document.getElementById('update_button').click();">$form->{selectcustomer}</select>|
329 : qq|<input name=customer value="$form->{customer}" size=35>|;
332 <input type=hidden name=employee value="$form->{employee}">
335 if ($form->{selectemployee}) {
338 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
339 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
340 <input type=hidden name=selectemployee value="$form->{selectemployee}">
345 my @old_project_ids = ();
346 map({ push(@old_project_ids, $form->{"project_id_$_"})
347 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
349 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
351 "old_id" => \@old_project_ids },
352 "charts" => { "key" => "ALL_CHARTS",
353 "transdate" => $form->{transdate} },
354 "taxcharts" => { "key" => "ALL_TAXCHARTS",
355 "module" => "AR" },);
357 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
358 @{ $form->{ALL_CHARTS} });
360 my %project_labels = ();
361 my @project_values = ("");
362 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
363 push(@project_values, $item->{"id"});
364 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
367 my (%AR_amount_labels, @AR_amount_values);
368 my (%AR_labels, @AR_values);
369 my (%AR_paid_labels, @AR_paid_values);
373 foreach my $item (@{ $form->{ALL_CHARTS} }) {
374 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
375 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
376 my $key = "$item->{accno}--$item->{tax_id}";
377 push(@AR_amount_values, $key);
378 $AR_amount_labels{$key} =
379 "$item->{accno}--$item->{description}";
381 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
382 push(@AR_values, $item->{accno});
383 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
385 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
386 push(@AR_paid_values, $item->{accno});
387 $AR_paid_labels{$item->{accno}} =
388 "$item->{accno}--$item->{description}";
391 $charts{$item->{accno}} = $item;
394 my %taxchart_labels = ();
395 my @taxchart_values = ();
397 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
398 my $key = "$item->{id}--$item->{rate}";
399 $taxchart_init = $key if ($taxchart_init eq $item->{id});
400 push(@taxchart_values, $key);
401 $taxchart_labels{$key} =
402 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
403 $taxcharts{$item->{id}} = $item;
406 $form->{fokus} = "arledger.customer";
408 # use JavaScript Calendar or not
409 $form->{jsscript} = 1;
411 if ($form->{jsscript}) {
413 # with JavaScript Calendar
415 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
416 <td><input type=button name=transdate id="trigger1" value=|
417 . $locale->text('button') . qq|></td>
420 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
421 <td><input type=button name=duedate id="trigger2" value=|
422 . $locale->text('button') . qq|></td></td>
427 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
428 "duedate", "BL", "trigger2");
431 # without JavaScript Calendar
433 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
435 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
438 my $follow_up_vc = $form->{customer};
439 $follow_up_vc =~ s/--.*?//;
440 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
442 $form->{javascript} .=
443 qq|<script type="text/javascript" src="js/common.js"></script>| .
444 qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| .
445 qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
448 $onload = qq|focus()|;
449 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
450 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
452 <body onLoad="$onload">
454 <form method=post name="arledger" action=$form->{script}>
456 <input type=hidden name=id value=$form->{id}>
457 <input type=hidden name=sort value=$form->{sort}>
458 <input type=hidden name=closedto value=$form->{closedto}>
459 <input type=hidden name=locked value=$form->{locked}>
460 <input type=hidden name=title value="$title">
461 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
462 <input type="hidden" name="follow_up_trans_type_1" value="ar_transaction">
463 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
464 <input type="hidden" name="follow_up_rowcount" value="1">
466 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
470 <th class=listtop>$form->{title}</th>
480 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
481 <td colspan=3>$customer <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')"></td>
482 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
483 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
484 <input type=hidden name=customer_id value="$form->{customer_id}">
485 <input type=hidden name=terms value=$form->{terms}>
492 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
493 <td>$form->{creditlimit}</td>
494 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
495 <td class="plus$n">$form->{creditremaining}</td>
496 <input type=hidden name=creditlimit value=$form->{creditlimit}>
497 <input type=hidden name=creditremaining value=$form->{creditremaining}>
503 <th align=right>| . $locale->text('Currency') . qq|</th>
504 <td><select name=currency>$form->{selectcurrency}</select></td>
505 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
506 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
507 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
508 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
519 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
520 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
523 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
524 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
527 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
531 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
542 <input type=hidden name=rowcount value=$form->{rowcount}>
546 <tr class=listheading>
547 <th class=listheading style="width:15%">|
548 . $locale->text('Account') . qq|</th>
549 <th class=listheading style="width:10%">|
550 . $locale->text('Amount') . qq|</th>
551 <th class=listheading style="width:10%">|
552 . $locale->text('Tax') . qq|</th>
553 <th class=listheading style="width:5%">|
554 . $locale->text('Taxkey') . qq|</th>
555 <th class=listheading style="width:10%">|
556 . $locale->text('Project') . qq|</th>
560 $amount = $locale->text('Amount');
561 $project = $locale->text('Project');
563 for my $i (1 .. $form->{rowcount}) {
566 $form->{"amount_$i"} =
567 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
568 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
570 my $selected_accno_full;
571 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
572 my $item = $charts{$accno_row};
573 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
575 my $selected_taxchart = $form->{"taxchart_$i"};
576 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
577 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
579 if ($previous_accno &&
580 ($previous_accno eq $selected_accno) &&
581 ($previous_tax_id ne $selected_tax_id)) {
582 my $item = $taxcharts{$selected_tax_id};
583 $selected_taxchart = "$item->{id}--$item->{rate}";
586 if (!$form->{"taxchart_$i"}) {
587 if ($form->{"AR_amount_$i"} =~ m/.--./) {
588 $selected_taxchart = join '--', map { ($_->{id}, $_->{rate}) } first { $_->{id} == $item->{tax_id} } @{ $form->{ALL_TAXCHARTS} };
590 $selected_taxchart = $taxchart_init;
595 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
596 '-id' => "AR_amount_$i",
597 '-style' => 'width:400px',
598 '-onChange' => "setTaxkey(this, $i)",
599 '-values' => \@AR_amount_values,
600 '-labels' => \%AR_amount_labels,
601 '-default' => $selected_accno_full))
602 . $cgi->hidden('-name' => "previous_AR_amount_$i",
603 '-default' => $selected_accno_full);
606 NTI($cgi->popup_menu('-name' => "taxchart_$i",
607 '-id' => "taxchart_$i",
608 '-style' => 'width:200px',
609 '-values' => \@taxchart_values,
610 '-labels' => \%taxchart_labels,
611 '-default' => $selected_taxchart))
615 NTI($cgi->popup_menu('-name' => "project_id_$i",
616 '-values' => \@project_values,
617 '-labels' => \%project_labels,
618 '-default' => $form->{"project_id_$i"} ));
622 <td>$selectAR_amount</td>
623 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
624 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
626 <td>$projectnumber</td>
633 $form->{invtotal_unformatted} = $form->{invtotal};
634 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
637 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
638 '-style' => 'width:400px',
639 '-values' => \@AR_values, '-labels' => \%AR_labels,
640 '-default' => $form->{ARselected}));
649 <td>${ARselected}</td>
650 <th align=left>$form->{invtotal}</th>
652 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
653 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
655 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
668 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
669 <td align=left>$notes</td>
677 <tr class=listheading>
678 <th colspan=7 class=listheading>|
679 . $locale->text('Incoming Payments') . qq|</th>
683 if ($form->{defaultcurrency} && ($form->{currency} eq $form->{defaultcurrency})) {
684 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
686 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
689 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
690 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
691 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
692 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
693 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
694 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
695 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
700 map { print "$column_data{$_}\n" } @column_index;
706 $form->{totalpaid} = 0;
708 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
709 for my $i (1 .. $form->{paidaccounts}) {
715 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
716 '-id' => "AR_paid_$i",
717 '-values' => \@AR_paid_values,
718 '-labels' => \%AR_paid_labels,
719 '-default' => $form->{"AR_paid_$i"}));
721 $form->{totalpaid} += $form->{"paid_$i"};
724 if ($form->{"paid_$i"}) {
726 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
728 $form->{"exchangerate_$i"} =
729 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
731 if ($form->{"exchangerate_$i"} == 0) {
732 $form->{"exchangerate_$i"} = "";
735 $exchangerate = qq| |;
736 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
737 if ($form->{"forex_$i"}) {
739 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
742 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
747 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
751 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
752 $column_data{AR_paid} =
753 qq|<td align=center>${selectAR_paid}</td>|;
754 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
755 $column_data{datepaid} =
756 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
757 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
758 $column_data{source} =
759 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
761 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
763 $column_data{paid_project_id} =
765 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
766 '-values' => \@project_values,
767 '-labels' => \%project_labels,
768 '-default' => $form->{"paid_project_id_$i"} ))
771 map { print qq|$column_data{$_}\n| } @column_index;
776 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
779 my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid};
785 <td align="center">| . $locale->text('Total') . qq|</td>
786 <td align="center">| . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq|</td>
791 <td align="center">| . $locale->text('Missing amount') . qq|</td>
792 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
794 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
796 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
802 <td><hr size=3 noshade></td>
807 $main::lxdebug->leave_sub();
811 $main::lxdebug->enter_sub();
813 $main::auth->assert('general_ledger');
815 my $form = $main::form;
816 my %myconfig = %main::myconfig;
817 my $locale = $main::locale;
818 my $cgi = $main::cgi;
820 my ($transdate, $closedto);
822 my $follow_ups_block;
824 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
826 if (@{ $follow_ups} ) {
827 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
828 $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>|;
836 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
838 <input name=callback type=hidden value="$form->{callback}">
840 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
841 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
847 if (!$form->{id} && $form->{draft_id}) {
848 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
849 '-value' => 1, '-checked' => $form->{remove_draft},
851 qq| <label for="remove_draft">| .
852 $locale->text("Remove draft when posting") .
856 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
857 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
859 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
861 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
862 print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
863 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($form->{totalpaid} == 0) || ($form->{totalpaid} eq "")));
866 if ($form->{radier}) {
868 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
869 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
871 if ($transdate > $closedto) {
873 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
876 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
877 <input type="button" class="submit" onclick="follow_up_window()" value="|
878 . $locale->text('Follow-Up')
882 if ($transdate > $closedto) {
883 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
884 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
888 if ($form->{menubar}) {
889 require "bin/mozilla/menu.pl";
892 # button for saving history
893 if($form->{id} ne "") {
894 print qq| <input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|> |;
896 # /button for saving history
897 # mark_as_paid button
898 if($form->{id} ne "") {
899 print qq|<input type="submit" class="submit" name="action" value="|
900 . $locale->text('mark as paid') . qq|">|;
902 # /mark_as_paid button
911 $main::lxdebug->leave_sub();
915 $main::lxdebug->enter_sub();
917 $main::auth->assert('general_ledger');
919 my $form = $main::form;
920 my %myconfig = %main::myconfig;
922 &mark_as_paid_common(\%myconfig,"ar");
924 $main::lxdebug->leave_sub();
928 $main::lxdebug->enter_sub();
930 $main::auth->assert('general_ledger');
932 my $form = $main::form;
933 my %myconfig = %main::myconfig;
937 my ($totaltax, $exchangerate);
939 $form->{invtotal} = 0;
941 delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
943 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
944 qw(exchangerate creditlimit creditremaining);
946 my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
950 for my $i (1 .. $form->{rowcount}) {
951 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
952 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
953 if ($form->{"amount_$i"}) {
956 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
958 if ($form->{taxincluded}) {
959 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
961 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
964 $form->{"tax_$i"} = 0;
966 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
968 $totaltax += $form->{"tax_$i"};
969 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
974 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
975 $form->{rowcount} = $count + 1;
976 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
978 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
979 $form->{exchangerate} = $form->{forex} if $form->{forex};
981 $form->{invdate} = $form->{transdate};
983 $form->{invdate} = $form->{transdate};
985 my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1);
987 &check_name("customer");
989 $form->{AR} = $saved_variables{AR};
990 if ($saved_variables{AR_amount_1} =~ m/.--./) {
991 map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
993 delete $form->{taxchart_1};
997 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
999 for my $i (1 .. $form->{paidaccounts}) {
1000 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1002 $form->{"${_}_$i"} =
1003 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1004 } qw(paid exchangerate);
1006 $form->{totalpaid} += $form->{"paid_$i"};
1008 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1009 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1013 $form->{creditremaining} -=
1014 ($form->{invtotal} - $form->{totalpaid} + $form->{oldtotalpaid} -
1015 $form->{oldinvtotal});
1016 $form->{oldinvtotal} = $form->{invtotal};
1017 $form->{oldtotalpaid} = $form->{totalpaid};
1021 $main::lxdebug->leave_sub();
1025 # ToDO: fix $closedto and $invdate
1028 $main::lxdebug->enter_sub();
1030 $main::auth->assert('general_ledger');
1032 my $form = $main::form;
1033 my %myconfig = %main::myconfig;
1034 my $locale = $main::locale;
1036 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1038 my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
1040 for my $i (1 .. $form->{paidaccounts}) {
1042 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1043 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1045 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1047 $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1049 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
1050 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
1051 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1056 ($form->{AR}) = split /--/, $form->{AR};
1057 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1058 $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
1059 $form->error($locale->text('Cannot post payment!'));
1061 $main::lxdebug->leave_sub();
1066 $main::auth->assert('general_ledger');
1068 my $form = $main::form;
1075 $main::lxdebug->enter_sub();
1077 $main::auth->assert('general_ledger');
1079 my $form = $main::form;
1080 my %myconfig = %main::myconfig;
1081 my $locale = $main::locale;
1087 # check if there is an invoice number, invoice and due date
1088 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
1089 $form->isblank("duedate", $locale->text('Due Date missing!'));
1090 $form->isblank("customer", $locale->text('Customer missing!'));
1092 if ($myconfig{mandatory_departments} && !$form->{department}) {
1093 $form->{saved_message} = $::locale->text('You have to specify a department.');
1098 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1099 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1100 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
1102 $form->error($locale->text('Zero amount posting!'))
1103 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
1105 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1106 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
1108 delete($form->{AR});
1110 for my $i (1 .. $form->{paidaccounts}) {
1111 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1112 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1114 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1116 $form->error($locale->text('Cannot post payment for a closed period!'))
1117 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1119 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
1120 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
1121 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1126 # if oldcustomer ne customer redo form
1127 my ($customer) = split /--/, $form->{customer};
1128 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1133 $form->{AR}{receivables} = $form->{ARselected};
1134 $form->{storno} = 0;
1136 $form->{id} = 0 if $form->{postasnew};
1137 $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
1139 # saving the history
1140 if(!exists $form->{addition} && $form->{id} ne "") {
1141 $form->{snumbers} = "invnumber_$form->{invnumber}";
1142 $form->{addition} = "POSTED";
1143 $form->save_history;
1145 # /saving the history
1146 remove_draft() if $form->{remove_draft};
1148 $form->redirect($locale->text('Transaction posted!')) unless $inline;
1150 $main::lxdebug->leave_sub();
1154 $main::lxdebug->enter_sub();
1156 $main::auth->assert('general_ledger');
1158 my $form = $main::form;
1159 my %myconfig = %main::myconfig;
1161 $form->{postasnew} = 1;
1162 # saving the history
1163 if(!exists $form->{addition} && $form->{id} ne "") {
1164 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1165 $form->{addition} = "POSTED AS NEW";
1166 $form->save_history;
1168 # /saving the history
1171 $main::lxdebug->leave_sub();
1174 sub use_as_template {
1175 $main::lxdebug->enter_sub();
1177 $main::auth->assert('general_ledger');
1179 my $form = $main::form;
1180 my %myconfig = %main::myconfig;
1182 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);
1183 $form->{paidaccounts} = 1;
1184 $form->{rowcount}--;
1185 $form->{invdate} = $form->current_date(\%myconfig);
1188 $main::lxdebug->leave_sub();
1192 $main::lxdebug->enter_sub();
1194 $main::auth->assert('general_ledger');
1196 my $form = $main::form;
1197 my $locale = $main::locale;
1199 $form->{title} = $locale->text('Confirm!');
1203 delete $form->{header};
1208 <form method=post action=$form->{script}>
1211 foreach my $key (keys %$form) {
1212 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1213 $form->{$key} =~ s/\"/"/g;
1214 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1218 <h2 class=confirm>$form->{title}</h2>
1221 . $locale->text('Are you sure you want to delete Transaction')
1222 . qq| $form->{invnumber}</h4>
1224 <input name=action class=submit type=submit value="|
1225 . $locale->text('Yes') . qq|">
1232 $main::lxdebug->leave_sub();
1236 $main::lxdebug->enter_sub();
1238 $main::auth->assert('general_ledger');
1240 my $form = $main::form;
1241 my %myconfig = %main::myconfig;
1242 my $locale = $main::locale;
1244 if (AR->delete_transaction(\%myconfig, \%$form)) {
1245 # saving the history
1246 if(!exists $form->{addition}) {
1247 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1248 $form->{addition} = "DELETED";
1249 $form->save_history;
1251 # /saving the history
1252 $form->redirect($locale->text('Transaction deleted!'));
1254 $form->error($locale->text('Cannot delete transaction!'));
1256 $main::lxdebug->leave_sub();
1260 $main::lxdebug->enter_sub();
1262 $main::auth->assert('general_ledger | invoice_edit');
1264 my $form = $main::form;
1265 my %myconfig = %main::myconfig;
1266 my $locale = $main::locale;
1267 my $cgi = $main::cgi;
1269 my ($customer, $department);
1270 my ($jsscript, $button1, $button2, $onload);
1272 # setup customer selection
1273 $form->all_vc(\%myconfig, "customer", "AR");
1275 $form->{title} = $locale->text('AR Transactions');
1276 $form->{jsscript} = 1;
1278 # Auch in Rechnungsübersicht nach Kundentyp filtern - jan
1279 $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 },
1280 "departments" => "ALL_DEPARTMENTS",
1281 "customers" => "ALL_VC",
1282 "business_types" => "ALL_BUSINESS_TYPES");
1283 $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
1285 # constants and subs for template
1286 $form->{jsscript} = 1;
1287 $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
1290 print $form->parse_html_template('ar/search', { %myconfig });
1292 $main::lxdebug->leave_sub();
1295 sub create_subtotal_row {
1296 $main::lxdebug->enter_sub();
1298 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1300 my $form = $main::form;
1301 my %myconfig = %main::myconfig;
1303 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1305 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1307 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1309 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1311 $main::lxdebug->leave_sub();
1316 sub ar_transactions {
1317 $main::lxdebug->enter_sub();
1319 $main::auth->assert('general_ledger | invoice_edit');
1321 my $form = $main::form;
1322 my %myconfig = %main::myconfig;
1323 my $locale = $main::locale;
1325 my ($callback, $href, @columns);
1327 $form->{customer} = $form->unescape($form->{customer});
1328 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1330 report_generator_set_default_sort('transdate', 1);
1332 AR->ar_transactions(\%myconfig, \%$form);
1334 $form->{title} = $locale->text('AR Transactions');
1336 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1339 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1340 datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
1341 marge_total marge_percent globalprojectnumber customernumber country ustid taxzone payment_terms charts);
1343 my @hidden_variables = map { "l_${_}" } @columns;
1344 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
1346 $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1349 'transdate' => { 'text' => $locale->text('Date'), },
1350 'id' => { 'text' => $locale->text('ID'), },
1351 'type' => { 'text' => $locale->text('Type'), },
1352 'invnumber' => { 'text' => $locale->text('Invoice'), },
1353 'ordnumber' => { 'text' => $locale->text('Order'), },
1354 'name' => { 'text' => $locale->text('Customer'), },
1355 'netamount' => { 'text' => $locale->text('Amount'), },
1356 'tax' => { 'text' => $locale->text('Tax'), },
1357 'amount' => { 'text' => $locale->text('Total'), },
1358 'paid' => { 'text' => $locale->text('Paid'), },
1359 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1360 'due' => { 'text' => $locale->text('Amount Due'), },
1361 'duedate' => { 'text' => $locale->text('Due Date'), },
1362 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1363 'notes' => { 'text' => $locale->text('Notes'), },
1364 'salesman' => { 'text' => $locale->text('Salesperson'), },
1365 'employee' => { 'text' => $locale->text('Employee'), },
1366 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1367 'shipvia' => { 'text' => $locale->text('Ship via'), },
1368 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1369 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1370 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
1371 'customernumber' => { 'text' => $locale->text('Customer Number'), },
1372 'country' => { 'text' => $locale->text('Country'), },
1373 'ustid' => { 'text' => $locale->text('USt-IdNr.'), },
1374 'taxzone' => { 'text' => $locale->text('Steuersatz'), },
1375 'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
1376 'charts' => { 'text' => $locale->text('Buchungskonto'), },
1379 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
1380 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1381 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1384 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1386 $form->{"l_type"} = "Y";
1387 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1389 $report->set_columns(%column_defs);
1390 $report->set_column_order(@columns);
1392 $report->set_export_options('ar_transactions', @hidden_variables, qw(sort sortdir));
1394 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1397 if ($form->{customer}) {
1398 push @options, $locale->text('Customer') . " : $form->{customer}";
1400 if ($form->{department}) {
1401 my ($department) = split /--/, $form->{department};
1402 push @options, $locale->text('Department') . " : $department";
1404 if ($form->{department_id}) {
1405 push @options, $locale->text('Department Id') . " : $form->{department_id}";
1407 if ($form->{invnumber}) {
1408 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1410 if ($form->{ordnumber}) {
1411 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1413 if ($form->{notes}) {
1414 push @options, $locale->text('Notes') . " : $form->{notes}";
1416 if ($form->{transaction_description}) {
1417 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1419 if ($form->{transdatefrom}) {
1420 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1422 if ($form->{transdateto}) {
1423 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1425 if ($form->{open}) {
1426 push @options, $locale->text('Open');
1428 if ($form->{closed}) {
1429 push @options, $locale->text('Closed');
1432 $report->set_options('top_info_text' => join("\n", @options),
1433 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1434 'output_format' => 'HTML',
1435 'title' => $form->{title},
1436 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1438 $report->set_options_from_form();
1440 # add sort and escape callback, this one we use for the add sub
1441 $form->{callback} = $href .= "&sort=$form->{sort}";
1443 # escape callback for href
1444 $callback = $form->escape($href);
1446 my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
1448 my %totals = map { $_ => 0 } @subtotal_columns;
1449 my %subtotals = map { $_ => 0 } @subtotal_columns;
1453 foreach my $ar (@{ $form->{AR} }) {
1454 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1455 $ar->{due} = $ar->{amount} - $ar->{paid};
1457 map { $subtotals{$_} += $ar->{$_};
1458 $totals{$_} += $ar->{$_} } @subtotal_columns;
1460 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1461 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1463 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
1465 my $is_storno = $ar->{storno} && $ar->{storno_id};
1466 my $has_storno = $ar->{storno} && !$ar->{storno_id};
1469 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1470 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1471 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1472 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1473 $locale->text("AR Transaction (abbreviation)");
1477 foreach my $column (@columns) {
1479 'data' => $ar->{$column},
1480 'align' => $column_alignment{$column},
1484 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1485 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1487 my $row_set = [ $row ];
1489 if (($form->{l_subtotal} eq 'Y')
1490 && (($idx == (scalar @{ $form->{AR} } - 1))
1491 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1492 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1495 $report->add_data($row_set);
1500 $report->add_separator();
1501 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1503 $report->generate_with_headers();
1505 $main::lxdebug->leave_sub();
1509 $main::lxdebug->enter_sub();
1511 $main::auth->assert('general_ledger');
1513 my $form = $main::form;
1514 my %myconfig = %main::myconfig;
1515 my $locale = $main::locale;
1517 # don't cancel cancelled transactions
1518 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1519 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1520 $form->error($locale->text("Transaction has already been cancelled!"));
1523 AR->storno($form, \%myconfig, $form->{id});
1525 # saving the history
1526 if(!exists $form->{addition} && $form->{id} ne "") {
1527 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1528 $form->{addition} = "STORNO";
1529 $form->save_history;
1531 # /saving the history
1533 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1535 $main::lxdebug->leave_sub();