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&DONT_LOAD_DRAFT=1" 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} = $form->{exchangerate} ? $form->format_amount(\%myconfig, $form->{exchangerate}) : '';
275 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
276 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
279 <input type=hidden name=forex value=$form->{forex}>
281 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
282 if ($form->{forex}) {
284 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
285 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
289 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
290 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
297 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
298 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
302 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
306 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
310 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
311 <td colspan=3><select name=department>$form->{selectdepartment}</select>
312 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
315 | if $form->{selectdepartment};
317 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
319 $customer = ($form->{selectcustomer})
320 ? qq|<select name="customer" onchange="document.getElementById('update_button').click();">$form->{selectcustomer}</select>|
321 : qq|<input name=customer value="$form->{customer}" size=35>|;
324 <input type=hidden name=employee value="$form->{employee}">
327 if ($form->{selectemployee}) {
330 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
331 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
332 <input type=hidden name=selectemployee value="$form->{selectemployee}">
337 my @old_project_ids = ();
338 map({ push(@old_project_ids, $form->{"project_id_$_"})
339 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
341 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
343 "old_id" => \@old_project_ids },
344 "charts" => { "key" => "ALL_CHARTS",
345 "transdate" => $form->{transdate} },
346 "taxcharts" => { "key" => "ALL_TAXCHARTS",
347 "module" => "AR" },);
349 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
350 @{ $form->{ALL_CHARTS} });
352 my %project_labels = ();
353 my @project_values = ("");
354 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
355 push(@project_values, $item->{"id"});
356 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
359 my (%AR_amount_labels, @AR_amount_values);
360 my (%AR_labels, @AR_values);
361 my (%AR_paid_labels, @AR_paid_values);
365 foreach my $item (@{ $form->{ALL_CHARTS} }) {
366 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
367 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
368 my $key = "$item->{accno}--$item->{tax_id}";
369 push(@AR_amount_values, $key);
370 $AR_amount_labels{$key} =
371 "$item->{accno}--$item->{description}";
373 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
374 push(@AR_values, $item->{accno});
375 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
377 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
378 push(@AR_paid_values, $item->{accno});
379 $AR_paid_labels{$item->{accno}} =
380 "$item->{accno}--$item->{description}";
383 $charts{$item->{accno}} = $item;
386 my %taxchart_labels = ();
387 my @taxchart_values = ();
389 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
390 my $key = "$item->{id}--$item->{rate}";
391 $taxchart_init = $key if ($taxchart_init eq $item->{id});
392 push(@taxchart_values, $key);
393 $taxchart_labels{$key} =
394 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
395 $taxcharts{$item->{id}} = $item;
398 $form->{fokus} = "arledger.customer";
400 # use JavaScript Calendar or not
401 $form->{jsscript} = 1;
403 if ($form->{jsscript}) {
405 # with JavaScript Calendar
407 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
408 <td><input type=button name=transdate id="trigger1" value=|
409 . $locale->text('button') . qq|></td>
412 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
413 <td><input type=button name=duedate id="trigger2" value=|
414 . $locale->text('button') . qq|></td></td>
419 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
420 "duedate", "BL", "trigger2");
423 # without JavaScript Calendar
425 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
427 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
430 my $follow_up_vc = $form->{customer};
431 $follow_up_vc =~ s/--.*?//;
432 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
434 $form->{javascript} .=
435 qq|<script type="text/javascript" src="js/common.js"></script>| .
436 qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| .
437 qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
439 my $globalprojectnumber =
440 NTI($cgi->popup_menu('-name' => "globalproject_id",
441 '-values' => \@project_values,
442 '-labels' => \%project_labels,
443 '-default' => $form->{"globalproject_id"} ));
446 $onload = qq|focus()|;
447 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
448 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
450 <body onLoad="$onload">
452 <form method=post name="arledger" action=$form->{script}>
454 <input type=hidden name=id value=$form->{id}>
455 <input type=hidden name=sort value=$form->{sort}>
456 <input type=hidden name=closedto value=$form->{closedto}>
457 <input type=hidden name=locked value=$form->{locked}>
458 <input type=hidden name=title value="$title">
459 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
460 <input type="hidden" name="follow_up_trans_type_1" value="ar_transaction">
461 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
462 <input type="hidden" name="follow_up_rowcount" value="1">
464 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
468 <th class=listtop>$form->{title}</th>
478 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
479 <td colspan=3>$customer <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')"></td>
480 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
481 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
482 <input type=hidden name=customer_id value="$form->{customer_id}">
483 <input type=hidden name=terms value=$form->{terms}>
490 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
491 <td>$form->{creditlimit}</td>
492 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
493 <td class="plus$n">$form->{creditremaining}</td>
494 <input type=hidden name=creditlimit value=$form->{creditlimit}>
495 <input type=hidden name=creditremaining value=$form->{creditremaining}>
501 <th align=right>| . $locale->text('Currency') . qq|</th>
502 <td><select name=currency>$form->{selectcurrency}</select></td>
503 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
504 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
505 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
506 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
517 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
518 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
521 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
522 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
525 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
529 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
533 <th align=right nowrap>| . $locale->text('Project Number') . qq|</th>
534 <td>$globalprojectnumber</td>
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;
708 $form->{totalpaid} = 0;
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 $form->{totalpaid} += $form->{"paid_$i"};
726 if ($form->{"paid_$i"}) {
728 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
730 if ($form->{"exchangerate_$i"} == 0) {
731 $form->{"exchangerate_$i"} = "";
733 $form->{"exchangerate_$i"} =
734 $form->format_amount(\%myconfig, $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} - $form->{totalpaid};
787 <td align="center">| . $locale->text('Total') . qq|</td>
788 <td align="center">| . H($form->format_amount(\%myconfig, $form->{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') && (($form->{totalpaid} == 0) || ($form->{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 oldcustomer);
989 &check_name("customer");
991 # check_name ruft get_customer auf, oldcustomer wird überschrieben, daher wird dies vorher gemerkt
992 # get_customer holt Bemerkungen als intnotes, für Debitorenbuchungen gibt es aber nur das Feld notes
993 $form->{notes} = $form->{intnotes} if $saved_variables{oldcustomer} ne $form->{customer};
995 $form->{AR} = $saved_variables{AR};
996 if ($saved_variables{AR_amount_1} =~ m/.--./) {
997 map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
999 delete $form->{taxchart_1};
1003 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
1005 for my $i (1 .. $form->{paidaccounts}) {
1006 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1008 $form->{"${_}_$i"} =
1009 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1010 } qw(paid exchangerate);
1012 $form->{totalpaid} += $form->{"paid_$i"};
1014 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1015 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1019 $form->{creditremaining} -=
1020 ($form->{invtotal} - $form->{totalpaid} + $form->{oldtotalpaid} -
1021 $form->{oldinvtotal});
1022 $form->{oldinvtotal} = $form->{invtotal};
1023 $form->{oldtotalpaid} = $form->{totalpaid};
1027 $main::lxdebug->leave_sub();
1031 # ToDO: fix $closedto and $invdate
1034 $main::lxdebug->enter_sub();
1036 $main::auth->assert('general_ledger');
1038 my $form = $main::form;
1039 my %myconfig = %main::myconfig;
1040 my $locale = $main::locale;
1042 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1044 my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
1046 for my $i (1 .. $form->{paidaccounts}) {
1048 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1049 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1051 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1053 $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1055 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
1056 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
1057 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1062 ($form->{AR}) = split /--/, $form->{AR};
1063 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1064 $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
1065 $form->error($locale->text('Cannot post payment!'));
1067 $main::lxdebug->leave_sub();
1072 $main::auth->assert('general_ledger');
1074 my $form = $main::form;
1081 $main::lxdebug->enter_sub();
1083 $main::auth->assert('general_ledger');
1085 my $form = $main::form;
1086 my %myconfig = %main::myconfig;
1087 my $locale = $main::locale;
1093 # check if there is an invoice number, invoice and due date
1094 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
1095 $form->isblank("duedate", $locale->text('Due Date missing!'));
1096 $form->isblank("customer", $locale->text('Customer missing!'));
1098 if ($myconfig{mandatory_departments} && !$form->{department}) {
1099 $form->{saved_message} = $::locale->text('You have to specify a department.');
1104 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1105 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1106 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
1108 $form->error($locale->text('Zero amount posting!'))
1109 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
1111 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1112 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
1114 delete($form->{AR});
1116 for my $i (1 .. $form->{paidaccounts}) {
1117 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1118 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1120 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1122 $form->error($locale->text('Cannot post payment for a closed period!'))
1123 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1125 if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
1126 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
1127 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1132 # if oldcustomer ne customer redo form
1133 my ($customer) = split /--/, $form->{customer};
1134 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1139 $form->{AR}{receivables} = $form->{ARselected};
1140 $form->{storno} = 0;
1142 $form->{id} = 0 if $form->{postasnew};
1143 $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
1145 # saving the history
1146 if(!exists $form->{addition} && $form->{id} ne "") {
1147 $form->{snumbers} = "invnumber_$form->{invnumber}";
1148 $form->{addition} = "POSTED";
1149 $form->save_history;
1151 # /saving the history
1152 remove_draft() if $form->{remove_draft};
1154 $form->redirect($locale->text('Transaction posted!')) unless $inline;
1156 $main::lxdebug->leave_sub();
1160 $main::lxdebug->enter_sub();
1162 $main::auth->assert('general_ledger');
1164 my $form = $main::form;
1165 my %myconfig = %main::myconfig;
1167 $form->{postasnew} = 1;
1168 # saving the history
1169 if(!exists $form->{addition} && $form->{id} ne "") {
1170 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1171 $form->{addition} = "POSTED AS NEW";
1172 $form->save_history;
1174 # /saving the history
1177 $main::lxdebug->leave_sub();
1180 sub use_as_template {
1181 $main::lxdebug->enter_sub();
1183 $main::auth->assert('general_ledger');
1185 my $form = $main::form;
1186 my %myconfig = %main::myconfig;
1188 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);
1189 $form->{paidaccounts} = 1;
1190 $form->{rowcount}--;
1191 $form->{invdate} = $form->current_date(\%myconfig);
1194 $main::lxdebug->leave_sub();
1198 $main::lxdebug->enter_sub();
1200 $main::auth->assert('general_ledger');
1202 my $form = $main::form;
1203 my $locale = $main::locale;
1205 $form->{title} = $locale->text('Confirm!');
1209 delete $form->{header};
1214 <form method=post action=$form->{script}>
1217 foreach my $key (keys %$form) {
1218 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1219 $form->{$key} =~ s/\"/"/g;
1220 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1224 <h2 class=confirm>$form->{title}</h2>
1227 . $locale->text('Are you sure you want to delete Transaction')
1228 . qq| $form->{invnumber}</h4>
1230 <input name=action class=submit type=submit value="|
1231 . $locale->text('Yes') . qq|">
1238 $main::lxdebug->leave_sub();
1242 $main::lxdebug->enter_sub();
1244 $main::auth->assert('general_ledger');
1246 my $form = $main::form;
1247 my %myconfig = %main::myconfig;
1248 my $locale = $main::locale;
1250 if (AR->delete_transaction(\%myconfig, \%$form)) {
1251 # saving the history
1252 if(!exists $form->{addition}) {
1253 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1254 $form->{addition} = "DELETED";
1255 $form->save_history;
1257 # /saving the history
1258 $form->redirect($locale->text('Transaction deleted!'));
1260 $form->error($locale->text('Cannot delete transaction!'));
1262 $main::lxdebug->leave_sub();
1266 $main::lxdebug->enter_sub();
1268 $main::auth->assert('general_ledger | invoice_edit');
1270 my $form = $main::form;
1271 my %myconfig = %main::myconfig;
1272 my $locale = $main::locale;
1273 my $cgi = $main::cgi;
1275 my ($customer, $department);
1276 my ($jsscript, $button1, $button2, $onload);
1278 # setup customer selection
1279 $form->all_vc(\%myconfig, "customer", "AR");
1281 $form->{title} = $locale->text('AR Transactions');
1282 $form->{jsscript} = 1;
1284 # Auch in Rechnungsübersicht nach Kundentyp filtern - jan
1285 $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 },
1286 "departments" => "ALL_DEPARTMENTS",
1287 "customers" => "ALL_VC",
1288 "employees" => "ALL_EMPLOYEES",
1289 "salesmen" => "ALL_SALESMEN",
1290 "business_types" => "ALL_BUSINESS_TYPES");
1291 $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
1293 # constants and subs for template
1294 $form->{jsscript} = 1;
1295 $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
1296 $form->{employee_labels} = sub { $_[0]->{"name"} || $_[0]->{"login"} };
1297 $form->{salesman_labels} = $form->{employee_labels};
1300 print $form->parse_html_template('ar/search', { %myconfig });
1302 $main::lxdebug->leave_sub();
1305 sub create_subtotal_row {
1306 $main::lxdebug->enter_sub();
1308 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1310 my $form = $main::form;
1311 my %myconfig = %main::myconfig;
1313 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1315 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1317 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1319 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1321 $main::lxdebug->leave_sub();
1326 sub ar_transactions {
1327 $main::lxdebug->enter_sub();
1329 $main::auth->assert('general_ledger | invoice_edit');
1331 my $form = $main::form;
1332 my %myconfig = %main::myconfig;
1333 my $locale = $main::locale;
1335 my ($callback, $href, @columns);
1337 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1339 report_generator_set_default_sort('transdate', 1);
1341 AR->ar_transactions(\%myconfig, \%$form);
1343 $form->{title} = $locale->text('AR Transactions');
1345 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1348 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1349 datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
1350 marge_total marge_percent globalprojectnumber customernumber country ustid taxzone payment_terms charts customertype);
1352 my @hidden_variables = map { "l_${_}" } @columns;
1353 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto employee_id salesman_id business_id);
1355 $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1358 'transdate' => { 'text' => $locale->text('Date'), },
1359 'id' => { 'text' => $locale->text('ID'), },
1360 'type' => { 'text' => $locale->text('Type'), },
1361 'invnumber' => { 'text' => $locale->text('Invoice'), },
1362 'ordnumber' => { 'text' => $locale->text('Order'), },
1363 'name' => { 'text' => $locale->text('Customer'), },
1364 'netamount' => { 'text' => $locale->text('Amount'), },
1365 'tax' => { 'text' => $locale->text('Tax'), },
1366 'amount' => { 'text' => $locale->text('Total'), },
1367 'paid' => { 'text' => $locale->text('Paid'), },
1368 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1369 'due' => { 'text' => $locale->text('Amount Due'), },
1370 'duedate' => { 'text' => $locale->text('Due Date'), },
1371 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1372 'notes' => { 'text' => $locale->text('Notes'), },
1373 'salesman' => { 'text' => $locale->text('Salesperson'), },
1374 'employee' => { 'text' => $locale->text('Employee'), },
1375 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1376 'shipvia' => { 'text' => $locale->text('Ship via'), },
1377 'globalprojectnumber' => { 'text' => $locale->text('Document Project Number'), },
1378 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1379 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
1380 'customernumber' => { 'text' => $locale->text('Customer Number'), },
1381 'country' => { 'text' => $locale->text('Country'), },
1382 'ustid' => { 'text' => $locale->text('USt-IdNr.'), },
1383 'taxzone' => { 'text' => $locale->text('Steuersatz'), },
1384 'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
1385 'charts' => { 'text' => $locale->text('Buchungskonto'), },
1386 'customertype' => { 'text' => $locale->text('Customer type'), },
1389 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
1390 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1391 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1394 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1396 $form->{"l_type"} = "Y";
1397 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1399 $report->set_columns(%column_defs);
1400 $report->set_column_order(@columns);
1402 $report->set_export_options('ar_transactions', @hidden_variables, qw(sort sortdir));
1404 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1407 if ($form->{customer}) {
1408 push @options, $locale->text('Customer') . " : $form->{customer}";
1410 if ($form->{department}) {
1411 my ($department) = split /--/, $form->{department};
1412 push @options, $locale->text('Department') . " : $department";
1414 if ($form->{department_id}) {
1415 push @options, $locale->text('Department Id') . " : $form->{department_id}";
1417 if ($form->{invnumber}) {
1418 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1420 if ($form->{ordnumber}) {
1421 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1423 if ($form->{notes}) {
1424 push @options, $locale->text('Notes') . " : $form->{notes}";
1426 if ($form->{transaction_description}) {
1427 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1429 if ($form->{transdatefrom}) {
1430 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1432 if ($form->{transdateto}) {
1433 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1435 if ($form->{open}) {
1436 push @options, $locale->text('Open');
1438 if ($form->{employee_id}) {
1439 my $employee = SL::DB::Employee->new(id => $form->{employee_id})->load;
1440 push @options, $locale->text('Employee') . ' : ' . $employee->name;
1442 if ($form->{salesman_id}) {
1443 my $salesman = SL::DB::Employee->new(id => $form->{salesman_id})->load;
1444 push @options, $locale->text('Salesman') . ' : ' . $salesman->name;
1446 if ($form->{closed}) {
1447 push @options, $locale->text('Closed');
1450 $report->set_options('top_info_text' => join("\n", @options),
1451 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1452 'output_format' => 'HTML',
1453 'title' => $form->{title},
1454 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1456 $report->set_options_from_form();
1457 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
1459 # add sort and escape callback, this one we use for the add sub
1460 $form->{callback} = $href .= "&sort=$form->{sort}";
1462 # escape callback for href
1463 $callback = $form->escape($href);
1465 my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
1467 my %totals = map { $_ => 0 } @subtotal_columns;
1468 my %subtotals = map { $_ => 0 } @subtotal_columns;
1472 foreach my $ar (@{ $form->{AR} }) {
1473 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1474 $ar->{due} = $ar->{amount} - $ar->{paid};
1476 map { $subtotals{$_} += $ar->{$_};
1477 $totals{$_} += $ar->{$_} } @subtotal_columns;
1479 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1480 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1482 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
1484 my $is_storno = $ar->{storno} && $ar->{storno_id};
1485 my $has_storno = $ar->{storno} && !$ar->{storno_id};
1488 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1489 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1490 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1491 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1492 $locale->text("AR Transaction (abbreviation)");
1496 foreach my $column (@columns) {
1498 'data' => $ar->{$column},
1499 'align' => $column_alignment{$column},
1503 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1504 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1506 my $row_set = [ $row ];
1508 if (($form->{l_subtotal} eq 'Y')
1509 && (($idx == (scalar @{ $form->{AR} } - 1))
1510 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1511 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1514 $report->add_data($row_set);
1519 $report->add_separator();
1520 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1522 $report->generate_with_headers();
1524 $main::lxdebug->leave_sub();
1528 $main::lxdebug->enter_sub();
1530 $main::auth->assert('general_ledger');
1532 my $form = $main::form;
1533 my %myconfig = %main::myconfig;
1534 my $locale = $main::locale;
1536 # don't cancel cancelled transactions
1537 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1538 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1539 $form->error($locale->text("Transaction has already been cancelled!"));
1542 AR->storno($form, \%myconfig, $form->{id});
1544 # saving the history
1545 if(!exists $form->{addition} && $form->{id} ne "") {
1546 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1547 $form->{addition} = "STORNO";
1548 $form->save_history;
1550 # /saving the history
1552 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1554 $main::lxdebug->leave_sub();