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')
82 $main::lxdebug->enter_sub();
84 $main::auth->assert('general_ledger');
86 my $form = $main::form;
87 my %myconfig = %main::myconfig;
89 return $main::lxdebug->leave_sub() if (load_draft_maybe());
92 if(!exists $form->{addition} && ($form->{id} ne "")) {
93 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
94 $form->{addition} = "ADDED";
95 $form->save_history($form->dbconnect(\%myconfig));
99 $form->{title} = "Add";
100 $form->{callback} = "ar.pl?action=add" unless $form->{callback};
102 AR->get_transdate(\%myconfig, $form);
103 $form->{initial_transdate} = $form->{transdate};
105 $form->{transdate} = $form->{initial_transdate};
107 $main::lxdebug->leave_sub();
111 $main::lxdebug->enter_sub();
113 $main::auth->assert('general_ledger');
115 my $form = $main::form;
117 # show history button
118 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
119 #/show hhistory button
120 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
121 $form->{title} = "Edit";
126 $main::lxdebug->leave_sub();
130 $main::lxdebug->enter_sub();
132 $main::auth->assert('general_ledger');
134 my $form = $main::form;
139 $main::lxdebug->leave_sub();
143 $main::lxdebug->enter_sub();
145 $main::auth->assert('general_ledger');
147 my $form = $main::form;
148 my %myconfig = %main::myconfig;
150 my ($duedate, $taxincluded);
152 $form->create_links("AR", \%myconfig, "customer");
153 $duedate = $form->{duedate};
155 $taxincluded = $form->{taxincluded};
156 my $id = $form->{id};
157 IS->get_customer(\%myconfig, \%$form);
158 $form->{taxincluded} = $taxincluded;
161 $form->{duedate} = $duedate if $duedate;
162 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
163 $form->{rowcount} = 1;
166 $form->{notes} = $form->{intnotes} unless $form->{notes};
169 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
171 map { $form->{selectcurrency} .= "<option>$_\n" } $form->get_all_currencies(\%myconfig);
174 if (@{ $form->{all_customer} || [] }) {
175 $form->{customer} = "$form->{customer}--$form->{customer_id}";
176 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
177 (@{ $form->{all_customer} });
181 if (@{ $form->{all_departments} || [] }) {
182 $form->{selectdepartment} = "<option>\n";
183 $form->{department} = "$form->{department}--$form->{department_id}";
186 $form->{selectdepartment} .=
187 "<option>$_->{description}--$_->{id}\n"
188 } (@{ $form->{all_departments} || [] });
191 $form->{employee} = "$form->{employee}--$form->{employee_id}";
194 if (@{ $form->{all_employees} || [] }) {
195 $form->{selectemployee} = "";
196 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
197 (@{ $form->{all_employees} || [] });
200 # build the popup menus
201 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
203 AR->setup_form($form);
206 ($form->datetonum($form->{transdate}, \%myconfig) <=
207 $form->datetonum($form->{closedto}, \%myconfig));
209 $main::lxdebug->leave_sub();
213 $main::lxdebug->enter_sub();
215 $main::auth->assert('general_ledger');
217 my $form = $main::form;
218 my %myconfig = %main::myconfig;
219 my $locale = $main::locale;
220 my $cgi = $main::cgi;
222 my ($title, $readonly, $exchangerate, $rows);
223 my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
224 my ($jsscript, $button1, $button2, $onload);
225 my ($selectAR_amount, $selectAR_paid, $ARselected, $tax);
226 my (@column_index, %column_data);
229 $title = $form->{title};
230 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
232 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
234 # $locale->text('Add Accounts Receivables Transaction')
235 # $locale->text('Edit Accounts Receivables Transaction')
236 $form->{javascript} = qq|<script type="text/javascript">
238 function setTaxkey(accno, row) {
239 var taxkey = accno.options[accno.selectedIndex].value;
240 var reg = /--([0-9]*)/;
241 var found = reg.exec(taxkey);
242 var index = found[1];
243 index = parseInt(index);
244 var tax = 'taxchart_' + row;
245 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
246 var reg2 = new RegExp("^"+ index, "");
247 if (reg2.exec(document.getElementById(tax).options[i].value)) {
248 document.getElementById(tax).options[i].selected = true;
255 # show history button js
256 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
257 #/show history button js
258 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
259 $readonly = ($form->{id}) ? "readonly" : "";
262 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
263 $readonly = ($form->{radier}) ? "" : $readonly;
265 # set option selected
266 foreach my $item (qw(customer currency department employee)) {
267 $form->{"select$item"} =~ s/ selected//;
268 $form->{"select$item"} =~
269 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
272 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
273 $form->{exchangerate} = $form->{forex} if $form->{forex};
276 $form->{exchangerate} =
277 $form->format_amount(\%myconfig, $form->{exchangerate});
279 if ($form->{exchangerate} == 0) {
280 $form->{exchangerate} = "";
283 $form->{creditlimit} =
284 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
285 $form->{creditremaining} =
286 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
289 <input type=hidden name=forex value=$form->{forex}>
291 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
292 if ($form->{forex}) {
294 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
295 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
299 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
300 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
307 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
308 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
312 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
316 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
320 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
321 <td colspan=3><select name=department>$form->{selectdepartment}</select>
322 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
325 | if $form->{selectdepartment};
327 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
329 $customer = ($form->{selectcustomer})
330 ? qq|<select name="customer" onchange="document.getElementById('update_button').click();">$form->{selectcustomer}</select>|
331 : qq|<input name=customer value="$form->{customer}" size=35>|;
334 <input type=hidden name=employee value="$form->{employee}">
337 if ($form->{selectemployee}) {
340 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
341 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
342 <input type=hidden name=selectemployee value="$form->{selectemployee}">
347 my @old_project_ids = ();
348 map({ push(@old_project_ids, $form->{"project_id_$_"})
349 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
351 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
353 "old_id" => \@old_project_ids },
354 "charts" => { "key" => "ALL_CHARTS",
355 "transdate" => $form->{transdate} },
356 "taxcharts" => { "key" => "ALL_TAXCHARTS",
357 "module" => "AR" },);
359 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
360 @{ $form->{ALL_CHARTS} });
362 my %project_labels = ();
363 my @project_values = ("");
364 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
365 push(@project_values, $item->{"id"});
366 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
369 my (%AR_amount_labels, @AR_amount_values);
370 my (%AR_labels, @AR_values);
371 my (%AR_paid_labels, @AR_paid_values);
375 foreach my $item (@{ $form->{ALL_CHARTS} }) {
376 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
377 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
378 my $key = "$item->{accno}--$item->{tax_id}";
379 push(@AR_amount_values, $key);
380 $AR_amount_labels{$key} =
381 "$item->{accno}--$item->{description}";
383 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
384 push(@AR_values, $item->{accno});
385 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
387 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
388 push(@AR_paid_values, $item->{accno});
389 $AR_paid_labels{$item->{accno}} =
390 "$item->{accno}--$item->{description}";
393 $charts{$item->{accno}} = $item;
396 my %taxchart_labels = ();
397 my @taxchart_values = ();
399 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
400 my $key = "$item->{id}--$item->{rate}";
401 $taxchart_init = $key if ($taxchart_init eq $item->{id});
402 push(@taxchart_values, $key);
403 $taxchart_labels{$key} =
404 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
405 $taxcharts{$item->{id}} = $item;
408 $form->{fokus} = "arledger.customer";
410 # use JavaScript Calendar or not
411 $form->{jsscript} = 1;
413 if ($form->{jsscript}) {
415 # with JavaScript Calendar
417 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
418 <td><input type=button name=transdate id="trigger1" value=|
419 . $locale->text('button') . qq|></td>
422 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
423 <td><input type=button name=duedate id="trigger2" value=|
424 . $locale->text('button') . qq|></td></td>
429 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
430 "duedate", "BL", "trigger2");
433 # without JavaScript Calendar
435 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
437 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
440 my $follow_up_vc = $form->{customer};
441 $follow_up_vc =~ s/--.*?//;
442 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
444 $form->{javascript} .=
445 qq|<script type="text/javascript" src="js/common.js"></script>| .
446 qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| .
447 qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
450 $onload = qq|focus()|;
451 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
452 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
454 <body onLoad="$onload">
456 <form method=post name="arledger" action=$form->{script}>
458 <input type=hidden name=id value=$form->{id}>
459 <input type=hidden name=sort value=$form->{sort}>
460 <input type=hidden name=closedto value=$form->{closedto}>
461 <input type=hidden name=locked value=$form->{locked}>
462 <input type=hidden name=title value="$title">
463 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
464 <input type="hidden" name="follow_up_trans_type_1" value="ar_transaction">
465 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
466 <input type="hidden" name="follow_up_rowcount" value="1">
468 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
472 <th class=listtop>$form->{title}</th>
482 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
483 <td colspan=3>$customer <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')"></td>
484 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
485 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
486 <input type=hidden name=customer_id value="$form->{customer_id}">
487 <input type=hidden name=terms value=$form->{terms}>
494 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
495 <td>$form->{creditlimit}</td>
496 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
497 <td class="plus$n">$form->{creditremaining}</td>
498 <input type=hidden name=creditlimit value=$form->{creditlimit}>
499 <input type=hidden name=creditremaining value=$form->{creditremaining}>
505 <th align=right>| . $locale->text('Currency') . qq|</th>
506 <td><select name=currency>$form->{selectcurrency}</select></td>
507 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
508 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
509 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
510 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
521 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
522 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
525 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
526 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
529 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
533 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
544 <input type=hidden name=rowcount value=$form->{rowcount}>
548 <tr class=listheading>
549 <th class=listheading style="width:15%">|
550 . $locale->text('Account') . qq|</th>
551 <th class=listheading style="width:10%">|
552 . $locale->text('Amount') . qq|</th>
553 <th class=listheading style="width:10%">|
554 . $locale->text('Tax') . qq|</th>
555 <th class=listheading style="width:5%">|
556 . $locale->text('Taxkey') . qq|</th>
557 <th class=listheading style="width:10%">|
558 . $locale->text('Project') . qq|</th>
562 $amount = $locale->text('Amount');
563 $project = $locale->text('Project');
565 for my $i (1 .. $form->{rowcount}) {
568 $form->{"amount_$i"} =
569 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
570 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
572 my $selected_accno_full;
573 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
574 my $item = $charts{$accno_row};
575 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
577 my $selected_taxchart = $form->{"taxchart_$i"};
578 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
579 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
581 if ($previous_accno &&
582 ($previous_accno eq $selected_accno) &&
583 ($previous_tax_id ne $selected_tax_id)) {
584 my $item = $taxcharts{$selected_tax_id};
585 $selected_taxchart = "$item->{id}--$item->{rate}";
588 if (!$form->{"taxchart_$i"}) {
589 if ($form->{"AR_amount_$i"} =~ m/.--./) {
590 $selected_taxchart = join '--', map { ($_->{id}, $_->{rate}) } first { $_->{id} == $item->{tax_id} } @{ $form->{ALL_TAXCHARTS} };
592 $selected_taxchart = $taxchart_init;
597 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
598 '-id' => "AR_amount_$i",
599 '-style' => 'width:400px',
600 '-onChange' => "setTaxkey(this, $i)",
601 '-values' => \@AR_amount_values,
602 '-labels' => \%AR_amount_labels,
603 '-default' => $selected_accno_full))
604 . $cgi->hidden('-name' => "previous_AR_amount_$i",
605 '-default' => $selected_accno_full);
608 NTI($cgi->popup_menu('-name' => "taxchart_$i",
609 '-id' => "taxchart_$i",
610 '-style' => 'width:200px',
611 '-values' => \@taxchart_values,
612 '-labels' => \%taxchart_labels,
613 '-default' => $selected_taxchart))
617 NTI($cgi->popup_menu('-name' => "project_id_$i",
618 '-values' => \@project_values,
619 '-labels' => \%project_labels,
620 '-default' => $form->{"project_id_$i"} ));
624 <td>$selectAR_amount</td>
625 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
626 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
628 <td>$projectnumber</td>
635 $form->{invtotal_unformatted} = $form->{invtotal};
636 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
639 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
640 '-style' => 'width:400px',
641 '-values' => \@AR_values, '-labels' => \%AR_labels,
642 '-default' => $form->{ARselected}));
651 <td>${ARselected}</td>
652 <th align=left>$form->{invtotal}</th>
654 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
655 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
657 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
670 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
671 <td align=left>$notes</td>
679 <tr class=listheading>
680 <th colspan=7 class=listheading>|
681 . $locale->text('Incoming Payments') . qq|</th>
685 if ($form->{defaultcurrency} && ($form->{currency} eq $form->{defaultcurrency})) {
686 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
688 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
691 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
692 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
693 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
694 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
695 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
696 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
697 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
702 map { print "$column_data{$_}\n" } @column_index;
710 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
711 for my $i (1 .. $form->{paidaccounts}) {
717 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
718 '-id' => "AR_paid_$i",
719 '-values' => \@AR_paid_values,
720 '-labels' => \%AR_paid_labels,
721 '-default' => $form->{"AR_paid_$i"}));
723 $totalpaid += $form->{"paid_$i"};
726 if ($form->{"paid_$i"}) {
728 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
730 $form->{"exchangerate_$i"} =
731 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
733 if ($form->{"exchangerate_$i"} == 0) {
734 $form->{"exchangerate_$i"} = "";
737 $exchangerate = qq| |;
738 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
739 if ($form->{"forex_$i"}) {
741 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
744 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
749 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
753 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
754 $column_data{AR_paid} =
755 qq|<td align=center>${selectAR_paid}</td>|;
756 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
757 $column_data{datepaid} =
758 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
759 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
760 $column_data{source} =
761 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
763 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
765 $column_data{paid_project_id} =
767 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
768 '-values' => \@project_values,
769 '-labels' => \%project_labels,
770 '-default' => $form->{"paid_project_id_$i"} ))
773 map { print qq|$column_data{$_}\n| } @column_index;
778 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
781 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
787 <td align="center">| . $locale->text('Total') . qq|</td>
788 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
793 <td align="center">| . $locale->text('Missing amount') . qq|</td>
794 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
796 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
798 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
804 <td><hr size=3 noshade></td>
809 $main::lxdebug->leave_sub();
813 $main::lxdebug->enter_sub();
815 $main::auth->assert('general_ledger');
817 my $form = $main::form;
818 my %myconfig = %main::myconfig;
819 my $locale = $main::locale;
820 my $cgi = $main::cgi;
822 my ($transdate, $closedto);
824 my $follow_ups_block;
826 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
828 if (@{ $follow_ups} ) {
829 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
830 $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>|;
838 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
840 <input name=callback type=hidden value="$form->{callback}">
842 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
843 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
849 if (!$form->{id} && $form->{draft_id}) {
850 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
851 '-value' => 1, '-checked' => $form->{remove_draft},
853 qq| <label for="remove_draft">| .
854 $locale->text("Remove draft when posting") .
858 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
859 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
861 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
863 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
864 print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
865 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($totalpaid == 0) || ($totalpaid eq "")));
868 if ($form->{radier}) {
870 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
871 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
873 if ($transdate > $closedto) {
875 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
878 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
879 <input type="button" class="submit" onclick="follow_up_window()" value="|
880 . $locale->text('Follow-Up')
884 if ($transdate > $closedto) {
885 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
886 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
890 if ($form->{menubar}) {
891 require "bin/mozilla/menu.pl";
894 # button for saving history
895 if($form->{id} ne "") {
896 print qq| <input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|> |;
898 # /button for saving history
899 # mark_as_paid button
900 if($form->{id} ne "") {
901 print qq|<input type="submit" class="submit" name="action" value="|
902 . $locale->text('mark as paid') . qq|">|;
904 # /mark_as_paid button
913 $main::lxdebug->leave_sub();
917 $main::lxdebug->enter_sub();
919 $main::auth->assert('general_ledger');
921 my $form = $main::form;
922 my %myconfig = %main::myconfig;
924 &mark_as_paid_common(\%myconfig,"ar");
926 $main::lxdebug->leave_sub();
930 $main::lxdebug->enter_sub();
932 $main::auth->assert('general_ledger');
934 my $form = $main::form;
935 my %myconfig = %main::myconfig;
939 my ($totaltax, $exchangerate);
941 $form->{invtotal} = 0;
943 delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
945 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
946 qw(exchangerate creditlimit creditremaining);
948 my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
952 for my $i (1 .. $form->{rowcount}) {
953 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
954 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
955 if ($form->{"amount_$i"}) {
958 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
960 if ($form->{taxincluded}) {
961 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
963 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
966 $form->{"tax_$i"} = 0;
968 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
970 $totaltax += $form->{"tax_$i"};
971 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
976 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
977 $form->{rowcount} = $count + 1;
978 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
980 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
981 $form->{exchangerate} = $form->{forex} if $form->{forex};
983 $form->{invdate} = $form->{transdate};
985 $form->{invdate} = $form->{transdate};
987 my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1);
989 &check_name("customer");
991 $form->{AR} = $saved_variables{AR};
992 if ($saved_variables{AR_amount_1} =~ m/.--./) {
993 map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
995 delete $form->{taxchart_1};
999 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
1001 for my $i (1 .. $form->{paidaccounts}) {
1002 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1004 $form->{"${_}_$i"} =
1005 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1006 } qw(paid exchangerate);
1008 $totalpaid += $form->{"paid_$i"};
1010 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1011 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1015 $form->{creditremaining} -=
1016 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
1017 $form->{oldinvtotal});
1018 $form->{oldinvtotal} = $form->{invtotal};
1019 $form->{oldtotalpaid} = $totalpaid;
1023 $main::lxdebug->leave_sub();
1027 # ToDO: fix $closedto and $invdate
1030 $main::lxdebug->enter_sub();
1032 $main::auth->assert('general_ledger');
1034 my $form = $main::form;
1035 my %myconfig = %main::myconfig;
1036 my $locale = $main::locale;
1038 $form->{defaultcurrency} = $form->get_default_currency(\%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 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1093 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1094 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
1096 $form->error($locale->text('Zero amount posting!'))
1097 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
1099 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1100 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
1102 delete($form->{AR});
1104 for my $i (1 .. $form->{paidaccounts}) {
1105 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1106 $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} if ($transdate == $datepaid);
1115 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1120 # if oldcustomer ne customer redo form
1121 my ($customer) = split /--/, $form->{customer};
1122 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1127 $form->{AR}{receivables} = $form->{ARselected};
1128 $form->{storno} = 0;
1130 $main::lxdebug->message(0, $form->{amount});
1131 $form->{id} = 0 if $form->{postasnew};
1132 $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
1134 # saving the history
1135 if(!exists $form->{addition} && $form->{id} ne "") {
1136 $form->{snumbers} = "invnumber_$form->{invnumber}";
1137 $form->{addition} = "POSTED";
1138 $form->save_history($form->dbconnect(\%myconfig));
1140 # /saving the history
1141 remove_draft() if $form->{remove_draft};
1143 $form->redirect($locale->text('Transaction posted!')) unless $inline;
1145 $main::lxdebug->leave_sub();
1149 $main::lxdebug->enter_sub();
1151 $main::auth->assert('general_ledger');
1153 my $form = $main::form;
1154 my %myconfig = %main::myconfig;
1156 $form->{postasnew} = 1;
1157 # saving the history
1158 if(!exists $form->{addition} && $form->{id} ne "") {
1159 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1160 $form->{addition} = "POSTED AS NEW";
1161 $form->save_history($form->dbconnect(\%myconfig));
1163 # /saving the history
1166 $main::lxdebug->leave_sub();
1169 sub use_as_template {
1170 $main::lxdebug->enter_sub();
1172 $main::auth->assert('general_ledger');
1174 my $form = $main::form;
1175 my %myconfig = %main::myconfig;
1177 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);
1178 $form->{paidaccounts} = 1;
1179 $form->{rowcount}--;
1180 $form->{invdate} = $form->current_date(\%myconfig);
1183 $main::lxdebug->leave_sub();
1187 $main::lxdebug->enter_sub();
1189 $main::auth->assert('general_ledger');
1191 my $form = $main::form;
1192 my $locale = $main::locale;
1194 $form->{title} = $locale->text('Confirm!');
1198 delete $form->{header};
1203 <form method=post action=$form->{script}>
1206 foreach my $key (keys %$form) {
1207 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1208 $form->{$key} =~ s/\"/"/g;
1209 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1213 <h2 class=confirm>$form->{title}</h2>
1216 . $locale->text('Are you sure you want to delete Transaction')
1217 . qq| $form->{invnumber}</h4>
1219 <input name=action class=submit type=submit value="|
1220 . $locale->text('Yes') . qq|">
1227 $main::lxdebug->leave_sub();
1231 $main::lxdebug->enter_sub();
1233 $main::auth->assert('general_ledger');
1235 my $form = $main::form;
1236 my %myconfig = %main::myconfig;
1237 my $locale = $main::locale;
1239 if (AR->delete_transaction(\%myconfig, \%$form)) {
1240 # saving the history
1241 if(!exists $form->{addition}) {
1242 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1243 $form->{addition} = "DELETED";
1244 $form->save_history($form->dbconnect(\%myconfig));
1246 # /saving the history
1247 $form->redirect($locale->text('Transaction deleted!'));
1249 $form->error($locale->text('Cannot delete transaction!'));
1251 $main::lxdebug->leave_sub();
1255 $main::lxdebug->enter_sub();
1257 $main::auth->assert('general_ledger | invoice_edit');
1259 my $form = $main::form;
1260 my %myconfig = %main::myconfig;
1261 my $locale = $main::locale;
1262 my $cgi = $main::cgi;
1264 my ($customer, $department);
1265 my ($jsscript, $button1, $button2, $onload);
1267 # setup customer selection
1268 $form->all_vc(\%myconfig, "customer", "AR");
1270 $form->{title} = $locale->text('AR Transactions');
1271 $form->{fokus} = "search.customer";
1272 $form->{jsscript} = 1;
1274 $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 },
1275 "departments" => "ALL_DEPARTMENTS",
1276 "customers" => "ALL_VC");
1278 # constants and subs for template
1279 $form->{jsscript} = 1;
1280 $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
1283 print $form->parse_html_template('ar/search', { %myconfig });
1285 $main::lxdebug->leave_sub();
1288 sub create_subtotal_row {
1289 $main::lxdebug->enter_sub();
1291 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1293 my $form = $main::form;
1294 my %myconfig = %main::myconfig;
1296 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1298 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1300 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1302 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1304 $main::lxdebug->leave_sub();
1309 sub ar_transactions {
1310 $main::lxdebug->enter_sub();
1312 $main::auth->assert('general_ledger | invoice_edit');
1314 my $form = $main::form;
1315 my %myconfig = %main::myconfig;
1316 my $locale = $main::locale;
1318 my ($callback, $href, @columns);
1320 $form->{customer} = $form->unescape($form->{customer});
1321 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1323 report_generator_set_default_sort('transdate', 1);
1325 AR->ar_transactions(\%myconfig, \%$form);
1327 $form->{title} = $locale->text('AR Transactions');
1329 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1332 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1333 datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
1334 marge_total marge_percent globalprojectnumber customernumber country ustid taxzone payment_terms charts);
1336 my @hidden_variables = map { "l_${_}" } @columns;
1337 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
1339 $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1342 'transdate' => { 'text' => $locale->text('Date'), },
1343 'id' => { 'text' => $locale->text('ID'), },
1344 'type' => { 'text' => $locale->text('Type'), },
1345 'invnumber' => { 'text' => $locale->text('Invoice'), },
1346 'ordnumber' => { 'text' => $locale->text('Order'), },
1347 'name' => { 'text' => $locale->text('Customer'), },
1348 'netamount' => { 'text' => $locale->text('Amount'), },
1349 'tax' => { 'text' => $locale->text('Tax'), },
1350 'amount' => { 'text' => $locale->text('Total'), },
1351 'paid' => { 'text' => $locale->text('Paid'), },
1352 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1353 'due' => { 'text' => $locale->text('Amount Due'), },
1354 'duedate' => { 'text' => $locale->text('Due Date'), },
1355 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1356 'notes' => { 'text' => $locale->text('Notes'), },
1357 'salesman' => { 'text' => $locale->text('Salesperson'), },
1358 'employee' => { 'text' => $locale->text('Employee'), },
1359 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1360 'shipvia' => { 'text' => $locale->text('Ship via'), },
1361 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1362 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1363 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
1364 'customernumber' => { 'text' => $locale->text('Customer Number'), },
1365 'country' => { 'text' => $locale->text('Country'), },
1366 'ustid' => { 'text' => $locale->text('USt-IdNr.'), },
1367 'taxzone' => { 'text' => $locale->text('Steuersatz'), },
1368 'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
1369 'charts' => { 'text' => $locale->text('Buchungskonto'), },
1372 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
1373 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1374 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1377 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1379 $form->{"l_type"} = "Y";
1380 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1382 $report->set_columns(%column_defs);
1383 $report->set_column_order(@columns);
1385 $report->set_export_options('ar_transactions', @hidden_variables, qw(sort sortdir));
1387 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1390 if ($form->{customer}) {
1391 push @options, $locale->text('Customer') . " : $form->{customer}";
1393 if ($form->{department}) {
1394 my ($department) = split /--/, $form->{department};
1395 push @options, $locale->text('Department') . " : $department";
1397 if ($form->{invnumber}) {
1398 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1400 if ($form->{ordnumber}) {
1401 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1403 if ($form->{notes}) {
1404 push @options, $locale->text('Notes') . " : $form->{notes}";
1406 if ($form->{transaction_description}) {
1407 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1409 if ($form->{transdatefrom}) {
1410 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1412 if ($form->{transdateto}) {
1413 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1415 if ($form->{open}) {
1416 push @options, $locale->text('Open');
1418 if ($form->{closed}) {
1419 push @options, $locale->text('Closed');
1422 $report->set_options('top_info_text' => join("\n", @options),
1423 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1424 'output_format' => 'HTML',
1425 'title' => $form->{title},
1426 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1428 $report->set_options_from_form();
1430 # add sort and escape callback, this one we use for the add sub
1431 $form->{callback} = $href .= "&sort=$form->{sort}";
1433 # escape callback for href
1434 $callback = $form->escape($href);
1436 my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
1438 my %totals = map { $_ => 0 } @subtotal_columns;
1439 my %subtotals = map { $_ => 0 } @subtotal_columns;
1443 foreach my $ar (@{ $form->{AR} }) {
1444 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1445 $ar->{due} = $ar->{amount} - $ar->{paid};
1447 map { $subtotals{$_} += $ar->{$_};
1448 $totals{$_} += $ar->{$_} } @subtotal_columns;
1450 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1451 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1453 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
1455 my $is_storno = $ar->{storno} && $ar->{storno_id};
1456 my $has_storno = $ar->{storno} && !$ar->{storno_id};
1459 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1460 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1461 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1462 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1463 $locale->text("AR Transaction (abbreviation)");
1467 foreach my $column (@columns) {
1469 'data' => $ar->{$column},
1470 'align' => $column_alignment{$column},
1474 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1475 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1477 my $row_set = [ $row ];
1479 if (($form->{l_subtotal} eq 'Y')
1480 && (($idx == (scalar @{ $form->{AR} } - 1))
1481 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1482 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1485 $report->add_data($row_set);
1490 $report->add_separator();
1491 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1493 $report->generate_with_headers();
1495 $main::lxdebug->leave_sub();
1499 $main::lxdebug->enter_sub();
1501 $main::auth->assert('general_ledger');
1503 my $form = $main::form;
1504 my %myconfig = %main::myconfig;
1505 my $locale = $main::locale;
1507 # don't cancel cancelled transactions
1508 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1509 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1510 $form->error($locale->text("Transaction has already been cancelled!"));
1513 AR->storno($form, \%myconfig, $form->{id});
1515 # saving the history
1516 if(!exists $form->{addition} && $form->{id} ne "") {
1517 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1518 $form->{addition} = "STORNO";
1519 $form->save_history($form->dbconnect(\%myconfig));
1521 # /saving the history
1523 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1525 $main::lxdebug->leave_sub();