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);
39 use SL::ReportGenerator;
41 require "bin/mozilla/arap.pl";
42 require "bin/mozilla/common.pl";
43 require "bin/mozilla/drafts.pl";
44 require "bin/mozilla/report_generator.pl";
50 # this is for our long dates
51 # $locale->text('January')
52 # $locale->text('February')
53 # $locale->text('March')
54 # $locale->text('April')
55 # $locale->text('May ')
56 # $locale->text('June')
57 # $locale->text('July')
58 # $locale->text('August')
59 # $locale->text('September')
60 # $locale->text('October')
61 # $locale->text('November')
62 # $locale->text('December')
64 # this is for our short month
65 # $locale->text('Jan')
66 # $locale->text('Feb')
67 # $locale->text('Mar')
68 # $locale->text('Apr')
69 # $locale->text('May')
70 # $locale->text('Jun')
71 # $locale->text('Jul')
72 # $locale->text('Aug')
73 # $locale->text('Sep')
74 # $locale->text('Oct')
75 # $locale->text('Nov')
76 # $locale->text('Dec')
79 $lxdebug->enter_sub();
81 return $lxdebug->leave_sub() if (load_draft_maybe());
84 if(!exists $form->{addition} && ($form->{id} ne "")) {
85 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
86 $form->{addition} = "ADDED";
87 $form->save_history($form->dbconnect(\%myconfig));
91 $form->{title} = "Add";
93 "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
94 unless $form->{callback};
96 AR->get_transdate(\%myconfig, $form);
97 $form->{initial_transdate} = $form->{transdate};
99 $form->{transdate} = $form->{initial_transdate};
101 $lxdebug->leave_sub();
105 $lxdebug->enter_sub();
106 # show history button
107 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
108 #/show hhistory button
109 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
110 $form->{title} = "Edit";
115 $lxdebug->leave_sub();
119 $lxdebug->enter_sub();
124 $lxdebug->leave_sub();
128 $lxdebug->enter_sub();
130 $form->create_links("AR", \%myconfig, "customer");
131 $duedate = $form->{duedate};
133 $taxincluded = $form->{taxincluded};
134 my $id = $form->{id};
135 IS->get_customer(\%myconfig, \%$form);
136 $form->{taxincluded} = $taxincluded;
139 $form->{duedate} = $duedate if $duedate;
140 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
141 $form->{rowcount} = 1;
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_customer} }) {
155 $form->{customer} = "$form->{customer}--$form->{customer_id}";
156 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
157 (@{ $form->{all_customer} });
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}";
174 if (@{ $form->{all_employees} }) {
175 $form->{selectemployee} = "";
176 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
177 (@{ $form->{all_employees} });
180 # build the popup menus
181 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
183 AR->setup_form($form);
186 ($form->datetonum($form->{transdate}, \%myconfig) <=
187 $form->datetonum($form->{closedto}, \%myconfig));
189 $lxdebug->leave_sub();
193 $lxdebug->enter_sub();
195 $title = $form->{title};
196 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
198 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
200 # $locale->text('Add Accounts Receivables Transaction')
201 # $locale->text('Edit Accounts Receivables Transaction')
202 $form->{javascript} = qq|<script type="text/javascript">
204 function setTaxkey(accno, row) {
205 var taxkey = accno.options[accno.selectedIndex].value;
206 var reg = /--([0-9]*)/;
207 var found = reg.exec(taxkey);
208 var index = found[1];
209 index = parseInt(index);
210 var tax = 'taxchart_' + row;
211 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
212 var reg2 = new RegExp("^"+ index, "");
213 if (reg2.exec(document.getElementById(tax).options[i].value)) {
214 document.getElementById(tax).options[i].selected = true;
221 # show history button js
222 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
223 #/show history button js
224 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
225 $readonly = ($form->{id}) ? "readonly" : "";
228 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
229 $readonly = ($form->{radier}) ? "" : $readonly;
231 # set option selected
232 foreach $item (qw(customer currency department employee)) {
233 $form->{"select$item"} =~ s/ selected//;
234 $form->{"select$item"} =~
235 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
238 $form->{exchangerate} = $exchangerate
242 $form->check_exchangerate(
243 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
247 $form->{exchangerate} =
248 $form->format_amount(\%myconfig, $form->{exchangerate});
250 if ($form->{exchangerate} == 0) {
251 $form->{exchangerate} = "";
254 $form->{creditlimit} =
255 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
256 $form->{creditremaining} =
257 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
260 <input type=hidden name=forex value=$form->{forex}>
262 if ($form->{currency} ne $form->{defaultcurrency}) {
263 if ($form->{forex}) {
265 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
266 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
270 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
271 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
278 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
279 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
283 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
287 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
291 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
292 <td colspan=3><select name=department>$form->{selectdepartment}</select>
293 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
296 | if $form->{selectdepartment};
298 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
301 ($form->{selectcustomer})
302 ? qq|<select name="customer"
303 onchange="document.getElementById('update_button').click();">$form->{
304 selectcustomer}</select>|
305 : qq|<input name=customer value="$form->{customer}" size=35>|;
308 <input type=hidden name=employee value="$form->{employee}">
311 if ($form->{selectemployee}) {
314 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
315 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
316 <input type=hidden name=selectemployee value="$form->{selectemployee}">
321 my @old_project_ids = ();
322 map({ push(@old_project_ids, $form->{"project_id_$_"})
323 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
325 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
327 "old_id" => \@old_project_ids },
328 "charts" => { "key" => "ALL_CHARTS",
329 "transdate" => $form->{transdate} },
330 "taxcharts" => "ALL_TAXCHARTS");
332 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
333 @{ $form->{ALL_CHARTS} });
335 my %project_labels = ();
336 my @project_values = ("");
337 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
338 push(@project_values, $item->{"id"});
339 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
342 my (%AR_amount_labels, @AR_amount_values);
343 my (%AR_labels, @AR_values);
344 my (%AR_paid_labels, @AR_paid_values);
348 foreach my $item (@{ $form->{ALL_CHARTS} }) {
349 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
350 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
351 my $key = "$item->{accno}--$item->{tax_id}";
352 push(@AR_amount_values, $key);
353 $AR_amount_labels{$key} =
354 "$item->{accno}--$item->{description}";
356 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
357 push(@AR_values, $item->{accno});
358 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
360 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
361 push(@AR_paid_values, $item->{accno});
362 $AR_paid_labels{$item->{accno}} =
363 "$item->{accno}--$item->{description}";
366 $charts{$item->{accno}} = $item;
369 my %taxchart_labels = ();
370 my @taxchart_values = ();
372 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
373 my $key = "$item->{id}--$item->{rate}";
374 $taxchart_init = $key if ($taxchart_init eq $item->{id});
375 push(@taxchart_values, $key);
376 $taxchart_labels{$key} =
377 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
378 $taxcharts{$item->{id}} = $item;
381 $form->{fokus} = "arledger.customer";
383 # use JavaScript Calendar or not
384 $form->{jsscript} = 1;
386 if ($form->{jsscript}) {
388 # with JavaScript Calendar
390 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
391 <td><input type=button name=transdate id="trigger1" value=|
392 . $locale->text('button') . qq|></td>
395 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
396 <td><input type=button name=duedate id="trigger2" value=|
397 . $locale->text('button') . qq|></td></td>
402 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
403 "duedate", "BL", "trigger2");
406 # without JavaScript Calendar
408 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
410 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
413 $form->{javascript} .=
414 qq|<script type="text/javascript" src="js/common.js"></script>| .
415 qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
418 $onload = qq|focus()|;
419 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
420 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
422 <body onLoad="$onload">
424 <form method=post name="arledger" action=$form->{script}>
426 <input type=hidden name=id value=$form->{id}>
427 <input type=hidden name=sort value=$form->{sort}>
428 <input type=hidden name=closedto value=$form->{closedto}>
429 <input type=hidden name=locked value=$form->{locked}>
430 <input type=hidden name=title value="$title">
432 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
436 <th class=listtop>$form->{title}</th>
446 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
447 <td colspan=3>$customer <input type="button" value="?" onclick="show_vc_details('customer')"></td>
448 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
449 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
450 <input type=hidden name=customer_id value="$form->{customer_id}">
451 <input type=hidden name=terms value=$form->{terms}>
458 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
459 <td>$form->{creditlimit}</td>
460 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
461 <td class="plus$n">$form->{creditremaining}</td>
462 <input type=hidden name=creditlimit value=$form->{creditlimit}>
463 <input type=hidden name=creditremaining value=$form->{creditremaining}>
469 <th align=right>| . $locale->text('Currency') . qq|</th>
470 <td><select name=currency>$form->{selectcurrency}</select></td>
471 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
472 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
473 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
474 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
485 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
486 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
489 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
490 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
493 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
497 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
508 <input type=hidden name=rowcount value=$form->{rowcount}>
512 <tr class=listheading>
513 <th class=listheading style="width:15%">|
514 . $locale->text('Account') . qq|</th>
515 <th class=listheading style="width:10%">|
516 . $locale->text('Amount') . qq|</th>
517 <th class=listheading style="width:10%">|
518 . $locale->text('Tax') . qq|</th>
519 <th class=listheading style="width:5%">|
520 . $locale->text('Korrektur') . qq|</th>
521 <th class=listheading style="width:10%">|
522 . $locale->text('Taxkey') . qq|</th>
523 <th class=listheading style="width:10%">|
524 . $locale->text('Project') . qq|</th>
528 $amount = $locale->text('Amount');
529 $project = $locale->text('Project');
531 for $i (1 .. $form->{rowcount}) {
534 $form->{"amount_$i"} =
535 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
536 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
538 my $selected_accno_full;
539 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
540 my $item = $charts{$accno_row};
541 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
543 my $selected_taxchart = $form->{"taxchart_$i"};
544 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
545 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
547 if ($previous_accno &&
548 ($previous_accno eq $selected_accno) &&
549 ($previous_tax_id ne $selected_tax_id)) {
550 my $item = $taxcharts{$selected_tax_id};
551 $selected_taxchart = "$item->{id}--$item->{rate}";
554 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
557 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
558 '-id' => "AR_amount_$i",
559 '-style' => 'width:400px',
560 '-onChange' => "setTaxkey(this, $i)",
561 '-values' => \@AR_amount_values,
562 '-labels' => \%AR_amount_labels,
563 '-default' => $selected_accno_full))
564 . $cgi->hidden('-name' => "previous_AR_amount_$i",
565 '-default' => $selected_accno_full);
568 NTI($cgi->popup_menu('-name' => "taxchart_$i",
569 '-id' => "taxchart_$i",
570 '-style' => 'width:200px',
571 '-values' => \@taxchart_values,
572 '-labels' => \%taxchart_labels,
573 '-default' => $selected_taxchart))
576 $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
579 NTI($cgi->popup_menu('-name' => "project_id_$i",
580 '-values' => \@project_values,
581 '-labels' => \%project_labels,
582 '-default' => $form->{"project_id_$i"} ));
586 <td>$selectAR_amount</td>
587 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
588 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
589 <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
591 <td>$projectnumber</td>
598 $form->{invtotal_unformatted} = $form->{invtotal};
599 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
602 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
603 '-style' => 'width:400px',
604 '-values' => \@AR_values, '-labels' => \%AR_labels,
605 '-default' => $form->{ARselected}));
614 <td>${ARselected}</td>
615 <th align=left>$form->{invtotal}</th>
617 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
618 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
620 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
633 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
634 <td align=left>$notes</td>
642 <tr class=listheading>
643 <th colspan=7 class=listheading>|
644 . $locale->text('Incoming Payments') . qq|</th>
648 if ($form->{currency} eq $form->{defaultcurrency}) {
649 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
651 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
654 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
655 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
656 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
657 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
658 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
659 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
660 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
665 map { print "$column_data{$_}\n" } @column_index;
673 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
674 for $i (1 .. $form->{paidaccounts}) {
680 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
681 '-id' => "AR_paid_$i",
682 '-values' => \@AR_paid_values,
683 '-labels' => \%AR_paid_labels,
684 '-default' => $form->{"AR_paid_$i"}));
686 $totalpaid += $form->{"paid_$i"};
689 if ($form->{"paid_$i"}) {
691 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
693 $form->{"exchangerate_$i"} =
694 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
696 if ($form->{"exchangerate_$i"} == 0) {
697 $form->{"exchangerate_$i"} = "";
700 $exchangerate = qq| |;
701 if ($form->{currency} ne $form->{defaultcurrency}) {
702 if ($form->{"forex_$i"}) {
704 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
707 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
712 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
716 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
717 $column_data{AR_paid} =
718 qq|<td align=center>${selectAR_paid}</td>|;
719 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
720 $column_data{datepaid} =
721 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
722 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
723 $column_data{source} =
724 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
726 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
728 $column_data{paid_project_id} =
730 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
731 '-values' => \@project_values,
732 '-labels' => \%project_labels,
733 '-default' => $form->{"paid_project_id_$i"} ))
736 map { print qq|$column_data{$_}\n| } @column_index;
741 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
744 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
750 <td align="center">| . $locale->text('Total') . qq|</td>
751 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
756 <td align="center">| . $locale->text('Missing amount') . qq|</td>
757 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
759 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
761 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
767 <td><hr size=3 noshade></td>
772 $lxdebug->leave_sub();
776 $lxdebug->enter_sub();
780 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
782 <input name=callback type=hidden value="$form->{callback}">
784 <input type=hidden name=login value=$form->{login}>
785 <input type=hidden name=password value=$form->{password}>
787 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
788 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
794 if (!$form->{id} && $form->{draft_id}) {
795 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
796 '-value' => 1, '-checked' => $form->{remove_draft},
798 qq| <label for="remove_draft">| .
799 $locale->text("Remove draft when posting") .
803 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
804 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
806 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
808 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
809 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|
810 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && !$form->{paid_1});
813 if ($form->{radier}) {
815 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
816 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
818 if ($transdate > $closedto) {
820 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
823 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|"> |;
826 if ($transdate > $closedto) {
827 print qq|<input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
828 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
832 if ($form->{menubar}) {
833 require "bin/mozilla/menu.pl";
836 # button for saving history
837 if($form->{id} ne "") {
838 print qq|<input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|>|;
840 # /button for saving history
841 # mark_as_paid button
842 if($form->{id} ne "") {
843 print qq|<input type="submit" class="submit" name="action" value="|
844 . $locale->text('mark as paid') . qq|">|;
846 # /mark_as_paid button
855 $lxdebug->leave_sub();
859 $lxdebug->enter_sub();
860 &mark_as_paid_common(\%myconfig,"ar");
861 $lxdebug->leave_sub();
865 $lxdebug->enter_sub();
869 $form->{invtotal} = 0;
871 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
872 qw(exchangerate creditlimit creditremaining);
874 @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
878 for $i (1 .. $form->{rowcount}) {
879 $form->{"amount_$i"} =
880 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
881 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
882 if ($form->{"amount_$i"}) {
885 if (!$form->{"korrektur_$i"}) {
886 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
888 if ($form->{taxincluded}) {
889 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
891 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
894 $form->{"tax_$i"} = 0;
897 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
899 $totaltax += $form->{"tax_$i"};
900 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
905 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
906 $form->{rowcount} = $count + 1;
907 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
909 $form->{exchangerate} = $exchangerate
913 $form->check_exchangerate(
914 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
917 $form->{invdate} = $form->{transdate};
918 $save_AR = $form->{AR};
919 &check_name(customer);
920 $form->{AR} = $save_AR;
923 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
925 for $i (1 .. $form->{paidaccounts}) {
926 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
929 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
930 } qw(paid exchangerate);
932 $totalpaid += $form->{"paid_$i"};
934 $form->{"exchangerate_$i"} = $exchangerate
936 $form->{"forex_$i"} = (
938 $form->check_exchangerate(
939 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
944 $form->{creditremaining} -=
945 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
946 $form->{oldinvtotal});
947 $form->{oldinvtotal} = $form->{invtotal};
948 $form->{oldtotalpaid} = $totalpaid;
952 $lxdebug->leave_sub();
956 $lxdebug->enter_sub();
958 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
960 for $i (1 .. $form->{paidaccounts}) {
961 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
962 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
964 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
966 $form->error($locale->text('Cannot post payment for a closed period!'))
967 if ($datepaid <= $closedto);
969 if ($form->{currency} ne $form->{defaultcurrency}) {
970 $form->{"exchangerate_$i"} = $form->{exchangerate}
971 if ($invdate == $datepaid);
972 $form->isblank("exchangerate_$i",
973 $locale->text('Exchangerate for payment missing!'));
978 ($form->{AR}) = split /--/, $form->{AR};
979 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
980 $form->redirect($locale->text('Payment posted!'))
981 if (AR->post_payment(\%myconfig, \%$form));
982 $form->error($locale->text('Cannot post payment!'));
985 $lxdebug->leave_sub();
989 $lxdebug->enter_sub();
991 # check if there is an invoice number, invoice and due date
992 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
993 $form->isblank("duedate", $locale->text('Due Date missing!'));
994 $form->isblank("customer", $locale->text('Customer missing!'));
996 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
997 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
998 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
1000 $form->error($locale->text('Zero amount posting!'))
1001 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
1003 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1004 if ($form->{currency} ne $form->{defaultcurrency});
1006 delete($form->{AR});
1008 for $i (1 .. $form->{paidaccounts}) {
1009 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1010 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1012 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1014 $form->error($locale->text('Cannot post payment for a closed period!'))
1015 if ($datepaid <= $closedto);
1017 if ($form->{currency} ne $form->{defaultcurrency}) {
1018 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
1019 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1024 # if oldcustomer ne customer redo form
1025 ($customer) = split /--/, $form->{customer};
1026 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1031 $form->{AR}{receivables} = $form->{ARselected};
1032 $form->{storno} = 0;
1034 $form->{id} = 0 if $form->{postasnew};
1037 if (AR->post_transaction(\%myconfig, \%$form)) {
1038 # saving the history
1039 if(!exists $form->{addition} && $form->{id} ne "") {
1040 $form->{snumbers} = "invnumber_$form->{invnumber}";
1041 $form->{addition} = "POSTED";
1042 $form->save_history($form->dbconnect(\%myconfig));
1044 # /saving the history
1045 remove_draft() if $form->{remove_draft};
1046 $form->redirect($locale->text('Transaction posted!'));
1048 $form->error($locale->text('Cannot post transaction!'));
1050 $lxdebug->leave_sub();
1054 $lxdebug->enter_sub();
1056 $form->{postasnew} = 1;
1057 # saving the history
1058 if(!exists $form->{addition} && $form->{id} ne "") {
1059 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1060 $form->{addition} = "POSTED AS NEW";
1061 $form->save_history($form->dbconnect(\%myconfig));
1063 # /saving the history
1066 $lxdebug->leave_sub();
1069 sub use_as_template {
1070 $lxdebug->enter_sub();
1072 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);
1073 $form->{paidaccounts} = 1;
1074 $form->{rowcount}--;
1075 $form->{invdate} = $form->current_date(\%myconfig);
1078 $lxdebug->leave_sub();
1082 $lxdebug->enter_sub();
1084 $form->{title} = $locale->text('Confirm!');
1088 delete $form->{header};
1093 <form method=post action=$form->{script}>
1096 foreach $key (keys %$form) {
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();
1121 if (AR->delete_transaction(\%myconfig, \%$form, $spool)) {
1122 # saving the history
1123 if(!exists $form->{addition}) {
1124 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1125 $form->{addition} = "DELETED";
1126 $form->save_history($form->dbconnect(\%myconfig));
1128 # /saving the history
1129 $form->redirect($locale->text('Transaction deleted!'));
1131 $form->error($locale->text('Cannot delete transaction!'));
1133 $lxdebug->leave_sub();
1137 $lxdebug->enter_sub();
1139 # setup customer selection
1140 $form->all_vc(\%myconfig, "customer", "AR");
1142 if (@{ $form->{all_customer} }) {
1143 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1144 @{ $form->{all_customer} };
1145 $customer = qq|<select name=customer><option>\n$customer</select>|;
1147 $customer = qq|<input name=customer size=35>|;
1151 if (@{ $form->{all_departments} }) {
1152 $form->{selectdepartment} = "<option>\n";
1155 $form->{selectdepartment} .=
1156 "<option>$_->{description}--$_->{id}\n"
1157 } (@{ $form->{all_departments} });
1162 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1163 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1165 | if $form->{selectdepartment};
1167 $form->{title} = $locale->text('AR Transactions');
1169 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1171 # use JavaScript Calendar or not
1172 $form->{jsscript} = 1;
1174 if ($form->{jsscript}) {
1176 # with JavaScript Calendar
1178 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1179 <input type=button name=transdatefrom id="trigger1" value=|
1180 . $locale->text('button') . qq|></td>
1183 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1184 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1185 . $locale->text('button') . qq|></td>
1190 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1191 "transdateto", "BL", "trigger2");
1194 # without JavaScript Calendar
1196 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1198 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1201 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1206 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1207 push(@values, $item->{"id"});
1208 $labels{$item->{"id"}} = $item->{"projectnumber"};
1211 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1212 '-labels' => \%labels));
1214 $form->{fokus} = "search.customer";
1216 $onload = qq|focus()|;
1217 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1218 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1220 <body onLoad="$onload">
1222 <form method=post name="search" action=$form->{script}>
1225 <tr><th class=listtop>$form->{title}</th></tr>
1226 <tr height="5"></tr>
1231 <th align=right>| . $locale->text('Customer') . qq|</th>
1232 <td colspan=3>$customer</td>
1236 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1237 <td colspan=3><input name=invnumber size=20></td>
1240 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1241 <td colspan=3><input name=ordnumber size=20></td>
1244 <th align=right nowrap>| . $locale->text('Transaction description') . qq|</th>
1245 <td colspan=3><input name=transaction_description size=40></td>
1248 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1249 <td colspan=3><input name=notes size=40></td>
1252 <th align="right">| . $locale->text("Project Number") . qq|</th>
1253 <td colspan="3">$projectnumber</td>
1256 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1258 <th align=right>| . $locale->text('Bis') . qq|</th>
1261 <input type=hidden name=sort value=transdate>
1269 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1273 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1274 <td nowrap>| . $locale->text('Open') . qq|</td>
1275 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1276 <td nowrap>| . $locale->text('Closed') . qq|</td>
1279 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1280 <td nowrap>| . $locale->text('ID') . qq|</td>
1281 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1282 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1283 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1284 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1285 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1286 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1289 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1290 <td nowrap>| . $locale->text('Customer') . qq|</td>
1291 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1292 <td nowrap>| . $locale->text('Amount') . qq|</td>
1293 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1294 <td nowrap>| . $locale->text('Tax') . qq|</td>
1295 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1296 <td nowrap>| . $locale->text('Total') . qq|</td>
1299 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1300 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1301 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1302 <td nowrap>| . $locale->text('Paid') . qq|</td>
1303 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1304 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1305 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1306 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1309 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1310 <td nowrap>| . $locale->text('Notes') . qq|</td>
1311 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1312 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1313 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1314 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1315 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1316 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1319 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1320 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1321 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1322 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1323 <td align=right><input name="l_transaction_description" class=checkbox type=checkbox value=Y></td>
1324 <td nowrap>| . $locale->text('Transaction description') . qq|</td>
1333 <td><hr size=3 noshade></td>
1337 <input type=hidden name=nextsub value=$form->{nextsub}>
1339 <input type=hidden name=login value=$form->{login}>
1340 <input type=hidden name=password value=$form->{password}>
1343 <input class=submit type=submit name=action value="|
1344 . $locale->text('Continue') . qq|">
1355 $lxdebug->leave_sub();
1358 sub create_subtotal_row {
1359 $lxdebug->enter_sub();
1361 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1363 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1365 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1367 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1369 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1371 $lxdebug->leave_sub();
1376 sub ar_transactions {
1377 $lxdebug->enter_sub();
1379 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1381 $form->{sort} ||= 'transdate';
1383 AR->ar_transactions(\%myconfig, \%$form);
1385 $form->{title} = $locale->text('AR Transactions');
1387 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1390 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1391 datepaid due duedate transaction_description notes employee shippingpoint shipvia
1392 globalprojectnumber);
1394 my @hidden_variables = map { "l_${_}" } @columns;
1395 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
1397 my $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1400 'transdate' => { 'text' => $locale->text('Date'), },
1401 'id' => { 'text' => $locale->text('ID'), },
1402 'type' => { 'text' => $locale->text('Type'), },
1403 'invnumber' => { 'text' => $locale->text('Invoice'), },
1404 'ordnumber' => { 'text' => $locale->text('Order'), },
1405 'name' => { 'text' => $locale->text('Customer'), },
1406 'netamount' => { 'text' => $locale->text('Amount'), },
1407 'tax' => { 'text' => $locale->text('Tax'), },
1408 'amount' => { 'text' => $locale->text('Total'), },
1409 'paid' => { 'text' => $locale->text('Paid'), },
1410 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1411 'due' => { 'text' => $locale->text('Amount Due'), },
1412 'duedate' => { 'text' => $locale->text('Due Date'), },
1413 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1414 'notes' => { 'text' => $locale->text('Notes'), },
1415 'employee' => { 'text' => $locale->text('Salesperson'), },
1416 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1417 'shipvia' => { 'text' => $locale->text('Ship via'), },
1418 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1421 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid
1422 employee shippingpoint shipvia)) {
1423 $column_defs{$name}->{link} = $href . "&sort=$name";
1426 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1428 $form->{"l_type"} = "Y";
1429 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1431 $report->set_columns(%column_defs);
1432 $report->set_column_order(@columns);
1434 $report->set_export_options('ar_transactions', @hidden_variables);
1436 $report->set_sort_indicator($form->{sort}, 1);
1439 if ($form->{customer}) {
1440 push @options, $locale->text('Customer') . " : $form->{customer}";
1442 if ($form->{department}) {
1443 ($department) = split /--/, $form->{department};
1444 push @options, $locale->text('Department') . " : $department";
1446 if ($form->{invnumber}) {
1447 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1449 if ($form->{ordnumber}) {
1450 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1452 if ($form->{notes}) {
1453 push @options, $locale->text('Notes') . " : $form->{notes}";
1455 if ($form->{transaction_description}) {
1456 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1458 if ($form->{transdatefrom}) {
1459 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1461 if ($form->{transdateto}) {
1462 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1464 if ($form->{open}) {
1465 push @options, $locale->text('Open');
1467 if ($form->{closed}) {
1468 push @options, $locale->text('Closed');
1471 $report->set_options('top_info_text' => join("\n", @options),
1472 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1473 'output_format' => 'HTML',
1474 'title' => $form->{title},
1475 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1477 $report->set_options_from_form();
1479 # add sort and escape callback, this one we use for the add sub
1480 $form->{callback} = $href .= "&sort=$form->{sort}";
1482 # escape callback for href
1483 $callback = $form->escape($href);
1485 my @subtotal_columns = qw(netamount amount paid due);
1487 my %totals = map { $_ => 0 } @subtotal_columns;
1488 my %subtotals = map { $_ => 0 } @subtotal_columns;
1492 foreach $ar (@{ $form->{AR} }) {
1493 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1494 $ar->{due} = $ar->{amount} - $ar->{paid};
1496 map { $subtotals{$_} += $ar->{$_};
1497 $totals{$_} += $ar->{$_} } @subtotal_columns;
1499 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due);
1501 my $is_storno = $ar->{storno} && IS->is_storno(\%myconfig, $form, 'ar');
1502 my $has_storno = $ar->{storno} && !$is_storno;
1505 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1506 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1507 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1508 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1509 $locale->text("AR Transaction (abbreviation)");
1513 foreach my $column (@columns) {
1515 'data' => $ar->{$column},
1516 'align' => $column_alignment{$column},
1520 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1521 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1523 my $row_set = [ $row ];
1525 if (($form->{l_subtotal} eq 'Y')
1526 && (($idx == (scalar @{ $form->{AR} } - 1))
1527 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1528 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1531 $report->add_data($row_set);
1536 $report->add_separator();
1537 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1539 $report->generate_with_headers();
1541 $lxdebug->leave_sub();
1545 $lxdebug->enter_sub();
1547 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1548 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1549 $form->error($locale->text("Transaction has already been cancelled!"));
1552 # negate amount/taxes
1553 for my $i (1 .. $form->{rowcount}) {
1554 $form->{"amount_$i"} *= -1;
1555 $form->{"tax_$i"} *= -1;
1559 for my $i (1 .. $form->{rowcount}) {
1560 for (qw(amount tax)) {
1561 $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"};
1565 $form->{storno} = 1;
1566 $form->{storno_id} = $form->{id};
1569 $form->{invnumber} = "Storno-" . $form->{invnumber};
1573 # saving the history
1574 if(!exists $form->{addition} && $form->{id} ne "") {
1575 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1576 $form->{addition} = "STORNO";
1577 $form->save_history($form->dbconnect(\%myconfig));
1579 # /saving the history
1581 $lxdebug->leave_sub();