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;
45 our ($cgi, $form, $lxdebug, $locale, %myconfig);
47 require "bin/mozilla/arap.pl";
48 require "bin/mozilla/common.pl";
49 require "bin/mozilla/drafts.pl";
50 require "bin/mozilla/reportgenerator.pl";
56 # this is for our long dates
57 # $locale->text('January')
58 # $locale->text('February')
59 # $locale->text('March')
60 # $locale->text('April')
61 # $locale->text('May ')
62 # $locale->text('June')
63 # $locale->text('July')
64 # $locale->text('August')
65 # $locale->text('September')
66 # $locale->text('October')
67 # $locale->text('November')
68 # $locale->text('December')
70 # this is for our short month
71 # $locale->text('Jan')
72 # $locale->text('Feb')
73 # $locale->text('Mar')
74 # $locale->text('Apr')
75 # $locale->text('May')
76 # $locale->text('Jun')
77 # $locale->text('Jul')
78 # $locale->text('Aug')
79 # $locale->text('Sep')
80 # $locale->text('Oct')
81 # $locale->text('Nov')
82 # $locale->text('Dec')
85 $lxdebug->enter_sub();
87 $auth->assert('general_ledger');
89 return $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 $lxdebug->leave_sub();
111 $lxdebug->enter_sub();
113 $auth->assert('general_ledger');
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 $lxdebug->leave_sub();
128 $lxdebug->enter_sub();
130 $auth->assert('general_ledger');
135 $lxdebug->leave_sub();
139 $lxdebug->enter_sub();
141 $auth->assert('general_ledger');
143 my ($duedate, $taxincluded, @curr);
145 $form->create_links("AR", \%myconfig, "customer");
146 $duedate = $form->{duedate};
148 $taxincluded = $form->{taxincluded};
149 my $id = $form->{id};
150 IS->get_customer(\%myconfig, \%$form);
151 $form->{taxincluded} = $taxincluded;
154 $form->{duedate} = $duedate if $duedate;
155 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
156 $form->{rowcount} = 1;
159 $form->{notes} = $form->{intnotes} unless $form->{notes};
162 @curr = split(/:/, $form->{currencies});
164 $form->{defaultcurrency} = $curr[0];
166 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
169 if (@{ $form->{all_customer} }) {
170 $form->{customer} = "$form->{customer}--$form->{customer_id}";
171 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
172 (@{ $form->{all_customer} });
176 if (@{ $form->{all_departments} }) {
177 $form->{selectdepartment} = "<option>\n";
178 $form->{department} = "$form->{department}--$form->{department_id}";
181 $form->{selectdepartment} .=
182 "<option>$_->{description}--$_->{id}\n"
183 } (@{ $form->{all_departments} });
186 $form->{employee} = "$form->{employee}--$form->{employee_id}";
189 if (@{ $form->{all_employees} }) {
190 $form->{selectemployee} = "";
191 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
192 (@{ $form->{all_employees} });
195 # build the popup menus
196 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
198 AR->setup_form($form);
201 ($form->datetonum($form->{transdate}, \%myconfig) <=
202 $form->datetonum($form->{closedto}, \%myconfig));
204 $lxdebug->leave_sub();
208 $lxdebug->enter_sub();
210 $auth->assert('general_ledger');
212 my ($title, $readonly, $exchangerate, $rows);
213 my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
214 my ($jsscript, $button1, $button2, $onload);
215 my ($selectAR_amount, $selectAR_paid, $korrektur_checked, $ARselected, $tax);
216 my (@column_index, %column_data);
219 $title = $form->{title};
220 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
222 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
224 # $locale->text('Add Accounts Receivables Transaction')
225 # $locale->text('Edit Accounts Receivables Transaction')
226 $form->{javascript} = qq|<script type="text/javascript">
228 function setTaxkey(accno, row) {
229 var taxkey = accno.options[accno.selectedIndex].value;
230 var reg = /--([0-9]*)/;
231 var found = reg.exec(taxkey);
232 var index = found[1];
233 index = parseInt(index);
234 var tax = 'taxchart_' + row;
235 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
236 var reg2 = new RegExp("^"+ index, "");
237 if (reg2.exec(document.getElementById(tax).options[i].value)) {
238 document.getElementById(tax).options[i].selected = true;
245 # show history button js
246 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
247 #/show history button js
248 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
249 $readonly = ($form->{id}) ? "readonly" : "";
252 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
253 $readonly = ($form->{radier}) ? "" : $readonly;
255 # set option selected
256 foreach my $item (qw(customer currency department employee)) {
257 $form->{"select$item"} =~ s/ selected//;
258 $form->{"select$item"} =~
259 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
262 $form->{exchangerate} = $exchangerate
266 $form->check_exchangerate(
267 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
271 $form->{exchangerate} =
272 $form->format_amount(\%myconfig, $form->{exchangerate});
274 if ($form->{exchangerate} == 0) {
275 $form->{exchangerate} = "";
278 $form->{creditlimit} =
279 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
280 $form->{creditremaining} =
281 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
284 <input type=hidden name=forex value=$form->{forex}>
286 if ($form->{currency} ne $form->{defaultcurrency}) {
287 if ($form->{forex}) {
289 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
290 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
294 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
295 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
302 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
303 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
307 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
311 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
315 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
316 <td colspan=3><select name=department>$form->{selectdepartment}</select>
317 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
320 | if $form->{selectdepartment};
322 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
324 $customer = ($form->{selectcustomer})
325 ? qq|<select name="customer" onchange="document.getElementById('update_button').click();">$form->{selectcustomer}</select>|
326 : qq|<input name=customer value="$form->{customer}" size=35>|;
329 <input type=hidden name=employee value="$form->{employee}">
332 if ($form->{selectemployee}) {
335 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
336 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
337 <input type=hidden name=selectemployee value="$form->{selectemployee}">
342 my @old_project_ids = ();
343 map({ push(@old_project_ids, $form->{"project_id_$_"})
344 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
346 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
348 "old_id" => \@old_project_ids },
349 "charts" => { "key" => "ALL_CHARTS",
350 "transdate" => $form->{transdate} },
351 "taxcharts" => "ALL_TAXCHARTS");
353 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
354 @{ $form->{ALL_CHARTS} });
356 my %project_labels = ();
357 my @project_values = ("");
358 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
359 push(@project_values, $item->{"id"});
360 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
363 my (%AR_amount_labels, @AR_amount_values);
364 my (%AR_labels, @AR_values);
365 my (%AR_paid_labels, @AR_paid_values);
369 foreach my $item (@{ $form->{ALL_CHARTS} }) {
370 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
371 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
372 my $key = "$item->{accno}--$item->{tax_id}";
373 push(@AR_amount_values, $key);
374 $AR_amount_labels{$key} =
375 "$item->{accno}--$item->{description}";
377 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
378 push(@AR_values, $item->{accno});
379 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
381 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
382 push(@AR_paid_values, $item->{accno});
383 $AR_paid_labels{$item->{accno}} =
384 "$item->{accno}--$item->{description}";
387 $charts{$item->{accno}} = $item;
390 my %taxchart_labels = ();
391 my @taxchart_values = ();
393 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
394 my $key = "$item->{id}--$item->{rate}";
395 $taxchart_init = $key if ($taxchart_init eq $item->{id});
396 push(@taxchart_values, $key);
397 $taxchart_labels{$key} =
398 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
399 $taxcharts{$item->{id}} = $item;
402 $form->{fokus} = "arledger.customer";
404 # use JavaScript Calendar or not
405 $form->{jsscript} = 1;
407 if ($form->{jsscript}) {
409 # with JavaScript Calendar
411 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
412 <td><input type=button name=transdate id="trigger1" value=|
413 . $locale->text('button') . qq|></td>
416 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
417 <td><input type=button name=duedate id="trigger2" value=|
418 . $locale->text('button') . qq|></td></td>
423 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
424 "duedate", "BL", "trigger2");
427 # without JavaScript Calendar
429 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
431 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
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>|;
439 $onload = qq|focus()|;
440 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
441 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
443 <body onLoad="$onload">
445 <form method=post name="arledger" action=$form->{script}>
447 <input type=hidden name=id value=$form->{id}>
448 <input type=hidden name=sort value=$form->{sort}>
449 <input type=hidden name=closedto value=$form->{closedto}>
450 <input type=hidden name=locked value=$form->{locked}>
451 <input type=hidden name=title value="$title">
453 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
457 <th class=listtop>$form->{title}</th>
467 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
468 <td colspan=3>$customer <input type="button" value="?" onclick="show_vc_details('customer')"></td>
469 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
470 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
471 <input type=hidden name=customer_id value="$form->{customer_id}">
472 <input type=hidden name=terms value=$form->{terms}>
479 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
480 <td>$form->{creditlimit}</td>
481 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
482 <td class="plus$n">$form->{creditremaining}</td>
483 <input type=hidden name=creditlimit value=$form->{creditlimit}>
484 <input type=hidden name=creditremaining value=$form->{creditremaining}>
490 <th align=right>| . $locale->text('Currency') . qq|</th>
491 <td><select name=currency>$form->{selectcurrency}</select></td>
492 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
493 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
494 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
495 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
506 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
507 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
510 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
511 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
514 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
518 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
529 <input type=hidden name=rowcount value=$form->{rowcount}>
533 <tr class=listheading>
534 <th class=listheading style="width:15%">|
535 . $locale->text('Account') . qq|</th>
536 <th class=listheading style="width:10%">|
537 . $locale->text('Amount') . qq|</th>
538 <th class=listheading style="width:10%">|
539 . $locale->text('Tax') . qq|</th>
540 <th class=listheading style="width:5%">|
541 . $locale->text('Korrektur') . qq|</th>
542 <th class=listheading style="width:10%">|
543 . $locale->text('Taxkey') . qq|</th>
544 <th class=listheading style="width:10%">|
545 . $locale->text('Project') . qq|</th>
549 $amount = $locale->text('Amount');
550 $project = $locale->text('Project');
552 for my $i (1 .. $form->{rowcount}) {
555 $form->{"amount_$i"} =
556 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
557 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
559 my $selected_accno_full;
560 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
561 my $item = $charts{$accno_row};
562 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
564 my $selected_taxchart = $form->{"taxchart_$i"};
565 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
566 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
568 if ($previous_accno &&
569 ($previous_accno eq $selected_accno) &&
570 ($previous_tax_id ne $selected_tax_id)) {
571 my $item = $taxcharts{$selected_tax_id};
572 $selected_taxchart = "$item->{id}--$item->{rate}";
575 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
578 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
579 '-id' => "AR_amount_$i",
580 '-style' => 'width:400px',
581 '-onChange' => "setTaxkey(this, $i)",
582 '-values' => \@AR_amount_values,
583 '-labels' => \%AR_amount_labels,
584 '-default' => $selected_accno_full))
585 . $cgi->hidden('-name' => "previous_AR_amount_$i",
586 '-default' => $selected_accno_full);
589 NTI($cgi->popup_menu('-name' => "taxchart_$i",
590 '-id' => "taxchart_$i",
591 '-style' => 'width:200px',
592 '-values' => \@taxchart_values,
593 '-labels' => \%taxchart_labels,
594 '-default' => $selected_taxchart))
597 $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
600 NTI($cgi->popup_menu('-name' => "project_id_$i",
601 '-values' => \@project_values,
602 '-labels' => \%project_labels,
603 '-default' => $form->{"project_id_$i"} ));
607 <td>$selectAR_amount</td>
608 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
609 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
610 <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
612 <td>$projectnumber</td>
619 $form->{invtotal_unformatted} = $form->{invtotal};
620 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
623 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
624 '-style' => 'width:400px',
625 '-values' => \@AR_values, '-labels' => \%AR_labels,
626 '-default' => $form->{ARselected}));
635 <td>${ARselected}</td>
636 <th align=left>$form->{invtotal}</th>
638 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
639 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
641 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
654 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
655 <td align=left>$notes</td>
663 <tr class=listheading>
664 <th colspan=7 class=listheading>|
665 . $locale->text('Incoming Payments') . qq|</th>
669 if ($form->{currency} eq $form->{defaultcurrency}) {
670 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
672 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
675 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
676 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
677 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
678 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
679 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
680 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
681 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
686 map { print "$column_data{$_}\n" } @column_index;
694 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
695 for my $i (1 .. $form->{paidaccounts}) {
701 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
702 '-id' => "AR_paid_$i",
703 '-values' => \@AR_paid_values,
704 '-labels' => \%AR_paid_labels,
705 '-default' => $form->{"AR_paid_$i"}));
707 $totalpaid += $form->{"paid_$i"};
710 if ($form->{"paid_$i"}) {
712 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
714 $form->{"exchangerate_$i"} =
715 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
717 if ($form->{"exchangerate_$i"} == 0) {
718 $form->{"exchangerate_$i"} = "";
721 $exchangerate = qq| |;
722 if ($form->{currency} ne $form->{defaultcurrency}) {
723 if ($form->{"forex_$i"}) {
725 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
728 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
733 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
737 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
738 $column_data{AR_paid} =
739 qq|<td align=center>${selectAR_paid}</td>|;
740 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
741 $column_data{datepaid} =
742 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
743 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
744 $column_data{source} =
745 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
747 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
749 $column_data{paid_project_id} =
751 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
752 '-values' => \@project_values,
753 '-labels' => \%project_labels,
754 '-default' => $form->{"paid_project_id_$i"} ))
757 map { print qq|$column_data{$_}\n| } @column_index;
762 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
765 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
771 <td align="center">| . $locale->text('Total') . qq|</td>
772 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
777 <td align="center">| . $locale->text('Missing amount') . qq|</td>
778 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
780 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
782 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
788 <td><hr size=3 noshade></td>
793 $lxdebug->leave_sub();
797 $lxdebug->enter_sub();
799 $auth->assert('general_ledger');
801 my ($transdate, $closedto);
805 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
807 <input name=callback type=hidden value="$form->{callback}">
809 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
810 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
816 if (!$form->{id} && $form->{draft_id}) {
817 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
818 '-value' => 1, '-checked' => $form->{remove_draft},
820 qq| <label for="remove_draft">| .
821 $locale->text("Remove draft when posting") .
825 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
826 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
828 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
830 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
831 print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
832 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar'));
835 if ($form->{radier}) {
837 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
838 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
840 if ($transdate > $closedto) {
842 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
845 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|"> |;
848 if ($transdate > $closedto) {
849 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
850 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
854 if ($form->{menubar}) {
855 require "bin/mozilla/menu.pl";
858 # button for saving history
859 if($form->{id} ne "") {
860 print qq| <input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|> |;
862 # /button for saving history
863 # mark_as_paid button
864 if($form->{id} ne "") {
865 print qq|<input type="submit" class="submit" name="action" value="|
866 . $locale->text('mark as paid') . qq|">|;
868 # /mark_as_paid button
877 $lxdebug->leave_sub();
881 $lxdebug->enter_sub();
883 $auth->assert('general_ledger');
885 &mark_as_paid_common(\%myconfig,"ar");
887 $lxdebug->leave_sub();
891 $lxdebug->enter_sub();
893 $auth->assert('general_ledger');
897 my ($totaltax, $exchangerate, $totalpaid);
899 $form->{invtotal} = 0;
901 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
902 qw(exchangerate creditlimit creditremaining);
904 my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
908 for my $i (1 .. $form->{rowcount}) {
909 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
910 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
911 if ($form->{"amount_$i"}) {
914 if (!$form->{"korrektur_$i"}) {
915 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
917 if ($form->{taxincluded}) {
918 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
920 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
923 $form->{"tax_$i"} = 0;
926 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
928 $totaltax += $form->{"tax_$i"};
929 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
934 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
935 $form->{rowcount} = $count + 1;
936 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
938 $form->{exchangerate} = $exchangerate
942 $form->check_exchangerate(
943 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
946 $form->{invdate} = $form->{transdate};
947 my $save_AR = $form->{AR};
948 check_name("customer");
949 $form->{AR} = $save_AR;
952 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
954 for my $i (1 .. $form->{paidaccounts}) {
955 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
958 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
959 } qw(paid exchangerate);
961 $totalpaid += $form->{"paid_$i"};
963 $form->{"exchangerate_$i"} = $exchangerate
965 $form->{"forex_$i"} = (
967 $form->check_exchangerate(
968 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
973 $form->{creditremaining} -=
974 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
975 $form->{oldinvtotal});
976 $form->{oldinvtotal} = $form->{invtotal};
977 $form->{oldtotalpaid} = $totalpaid;
981 $lxdebug->leave_sub();
985 # ToDO: fix $closedto and $invdate
988 $lxdebug->enter_sub();
990 $auth->assert('general_ledger');
992 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
994 for my $i (1 .. $form->{paidaccounts}) {
996 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
997 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
999 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1001 # $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
1003 if ($form->{currency} ne $form->{defaultcurrency}) {
1004 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
1005 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1010 ($form->{AR}) = split /--/, $form->{AR};
1011 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1012 $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
1013 $form->error($locale->text('Cannot post payment!'));
1015 $lxdebug->leave_sub();
1020 $auth->assert('general_ledger');
1027 $lxdebug->enter_sub();
1029 $auth->assert('general_ledger');
1035 # check if there is an invoice number, invoice and due date
1036 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
1037 $form->isblank("duedate", $locale->text('Due Date missing!'));
1038 $form->isblank("customer", $locale->text('Customer missing!'));
1040 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1041 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1042 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
1044 $form->error($locale->text('Zero amount posting!'))
1045 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
1047 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1048 if ($form->{currency} ne $form->{defaultcurrency});
1050 delete($form->{AR});
1052 for my $i (1 .. $form->{paidaccounts}) {
1053 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1054 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1056 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1058 $form->error($locale->text('Cannot post payment for a closed period!'))
1059 if ($datepaid <= $closedto);
1061 if ($form->{currency} ne $form->{defaultcurrency}) {
1062 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
1063 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1068 # if oldcustomer ne customer redo form
1069 my ($customer) = split /--/, $form->{customer};
1070 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1075 $form->{AR}{receivables} = $form->{ARselected};
1076 $form->{storno} = 0;
1078 $lxdebug->message(0, $form->{amount});
1079 $form->{id} = 0 if $form->{postasnew};
1080 $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
1082 # saving the history
1083 if(!exists $form->{addition} && $form->{id} ne "") {
1084 $form->{snumbers} = "invnumber_$form->{invnumber}";
1085 $form->{addition} = "POSTED";
1086 $form->save_history($form->dbconnect(\%myconfig));
1088 # /saving the history
1089 remove_draft() if $form->{remove_draft};
1091 $form->redirect($locale->text('Transaction posted!')) unless $inline;
1093 $lxdebug->leave_sub();
1097 $lxdebug->enter_sub();
1099 $auth->assert('general_ledger');
1101 $form->{postasnew} = 1;
1102 # saving the history
1103 if(!exists $form->{addition} && $form->{id} ne "") {
1104 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1105 $form->{addition} = "POSTED AS NEW";
1106 $form->save_history($form->dbconnect(\%myconfig));
1108 # /saving the history
1111 $lxdebug->leave_sub();
1114 sub use_as_template {
1115 $lxdebug->enter_sub();
1117 $auth->assert('general_ledger');
1119 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);
1120 $form->{paidaccounts} = 1;
1121 $form->{rowcount}--;
1122 $form->{invdate} = $form->current_date(\%myconfig);
1125 $lxdebug->leave_sub();
1129 $lxdebug->enter_sub();
1131 $auth->assert('general_ledger');
1133 $form->{title} = $locale->text('Confirm!');
1137 delete $form->{header};
1142 <form method=post action=$form->{script}>
1145 foreach my $key (keys %$form) {
1146 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1147 $form->{$key} =~ s/\"/"/g;
1148 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1152 <h2 class=confirm>$form->{title}</h2>
1155 . $locale->text('Are you sure you want to delete Transaction')
1156 . qq| $form->{invnumber}</h4>
1158 <input name=action class=submit type=submit value="|
1159 . $locale->text('Yes') . qq|">
1166 $lxdebug->leave_sub();
1170 $lxdebug->enter_sub();
1172 $auth->assert('general_ledger');
1174 if (AR->delete_transaction(\%myconfig, \%$form)) {
1175 # saving the history
1176 if(!exists $form->{addition}) {
1177 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1178 $form->{addition} = "DELETED";
1179 $form->save_history($form->dbconnect(\%myconfig));
1181 # /saving the history
1182 $form->redirect($locale->text('Transaction deleted!'));
1184 $form->error($locale->text('Cannot delete transaction!'));
1186 $lxdebug->leave_sub();
1190 $lxdebug->enter_sub();
1192 $auth->assert('general_ledger | invoice_edit');
1194 my ($customer, $department);
1195 my ($jsscript, $button1, $button2, $onload);
1197 # setup customer selection
1198 $form->all_vc(\%myconfig, "customer", "AR");
1200 if (@{ $form->{all_customer} }) {
1201 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1202 @{ $form->{all_customer} };
1203 $customer = qq|<select name=customer><option>\n$customer</select>|;
1205 $customer = qq|<input name=customer size=35>|;
1209 if (@{ $form->{all_departments} }) {
1210 $form->{selectdepartment} = "<option>\n";
1213 $form->{selectdepartment} .=
1214 "<option>$_->{description}--$_->{id}\n"
1215 } (@{ $form->{all_departments} });
1220 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1221 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1223 | if $form->{selectdepartment};
1225 $form->{title} = $locale->text('AR Transactions');
1227 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1229 # use JavaScript Calendar or not
1230 $form->{jsscript} = 1;
1232 if ($form->{jsscript}) {
1234 # with JavaScript Calendar
1236 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1237 <input type=button name=transdatefrom id="trigger1" value=|
1238 . $locale->text('button') . qq|></td>
1241 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1242 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1243 . $locale->text('button') . qq|></td>
1248 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1249 "transdateto", "BL", "trigger2");
1252 # without JavaScript Calendar
1254 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1256 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1259 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1264 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1265 push(@values, $item->{"id"});
1266 $labels{$item->{"id"}} = $item->{"projectnumber"};
1269 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1270 '-labels' => \%labels));
1272 $form->{fokus} = "search.customer";
1274 $onload = qq|focus()|;
1275 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1276 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1278 <body onLoad="$onload">
1280 <form method=post name="search" action=$form->{script}>
1283 <tr><th class=listtop>$form->{title}</th></tr>
1284 <tr height="5"></tr>
1289 <th align=right>| . $locale->text('Customer') . qq|</th>
1290 <td colspan=3>$customer</td>
1294 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1295 <td colspan=3><input name=invnumber size=20></td>
1298 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1299 <td colspan=3><input name=ordnumber size=20></td>
1302 <th align=right nowrap>| . $locale->text('Transaction description') . qq|</th>
1303 <td colspan=3><input name=transaction_description size=40></td>
1306 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1307 <td colspan=3><input name=notes size=40></td>
1310 <th align="right">| . $locale->text("Project Number") . qq|</th>
1311 <td colspan="3">$projectnumber</td>
1314 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1316 <th align=right>| . $locale->text('Bis') . qq|</th>
1319 <input type=hidden name=sort value=transdate>
1327 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1331 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1332 <td nowrap>| . $locale->text('Open') . qq|</td>
1333 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1334 <td nowrap>| . $locale->text('Closed') . qq|</td>
1337 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1338 <td nowrap>| . $locale->text('ID') . qq|</td>
1339 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1340 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1341 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1342 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1343 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1344 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1347 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1348 <td nowrap>| . $locale->text('Customer') . qq|</td>
1349 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1350 <td nowrap>| . $locale->text('Amount') . qq|</td>
1351 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1352 <td nowrap>| . $locale->text('Tax') . qq|</td>
1353 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1354 <td nowrap>| . $locale->text('Total') . qq|</td>
1357 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1358 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1359 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1360 <td nowrap>| . $locale->text('Paid') . qq|</td>
1361 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1362 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1363 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1364 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1367 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1368 <td nowrap>| . $locale->text('Notes') . qq|</td>
1369 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1370 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1371 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1372 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1373 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1374 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1377 <td align=right><input name="l_marge_total" class=checkbox type=checkbox value=Y></td><td> |
1378 . $locale->text('Ertrag') . qq|</td>
1379 <td align=right><input name="l_marge_percent" class=checkbox type=checkbox value=Y></td><td> |
1380 . $locale->text('Ertrag prozentual') . qq|</td>
1383 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1384 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1385 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1386 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1387 <td align=right><input name="l_transaction_description" class=checkbox type=checkbox value=Y></td>
1388 <td nowrap>| . $locale->text('Transaction description') . qq|</td>
1397 <td><hr size=3 noshade></td>
1401 <input type=hidden name=nextsub value=$form->{nextsub}>
1404 <input class=submit type=submit name=action value="|
1405 . $locale->text('Continue') . qq|">
1416 $lxdebug->leave_sub();
1419 sub create_subtotal_row {
1420 $lxdebug->enter_sub();
1422 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1424 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1426 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1428 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1430 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1432 $lxdebug->leave_sub();
1437 sub ar_transactions {
1438 $lxdebug->enter_sub();
1440 $auth->assert('general_ledger | invoice_edit');
1442 my ($callback, $href, @columns);
1444 $form->{customer} = $form->unescape($form->{customer});
1445 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1447 $form->{sort} ||= 'transdate';
1449 AR->ar_transactions(\%myconfig, \%$form);
1451 $form->{title} = $locale->text('AR Transactions');
1453 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1456 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1457 datepaid due duedate transaction_description notes employee shippingpoint shipvia
1458 marge_total marge_percent globalprojectnumber);
1460 my @hidden_variables = map { "l_${_}" } @columns;
1461 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
1463 $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1466 'transdate' => { 'text' => $locale->text('Date'), },
1467 'id' => { 'text' => $locale->text('ID'), },
1468 'type' => { 'text' => $locale->text('Type'), },
1469 'invnumber' => { 'text' => $locale->text('Invoice'), },
1470 'ordnumber' => { 'text' => $locale->text('Order'), },
1471 'name' => { 'text' => $locale->text('Customer'), },
1472 'netamount' => { 'text' => $locale->text('Amount'), },
1473 'tax' => { 'text' => $locale->text('Tax'), },
1474 'amount' => { 'text' => $locale->text('Total'), },
1475 'paid' => { 'text' => $locale->text('Paid'), },
1476 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1477 'due' => { 'text' => $locale->text('Amount Due'), },
1478 'duedate' => { 'text' => $locale->text('Due Date'), },
1479 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1480 'notes' => { 'text' => $locale->text('Notes'), },
1481 'employee' => { 'text' => $locale->text('Salesperson'), },
1482 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1483 'shipvia' => { 'text' => $locale->text('Ship via'), },
1484 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1485 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1486 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
1489 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid
1490 employee shippingpoint shipvia)) {
1491 $column_defs{$name}->{link} = $href . "&sort=$name";
1494 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1496 $form->{"l_type"} = "Y";
1497 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1499 $report->set_columns(%column_defs);
1500 $report->set_column_order(@columns);
1502 $report->set_export_options('ar_transactions', @hidden_variables);
1504 $report->set_sort_indicator($form->{sort}, 1);
1507 if ($form->{customer}) {
1508 push @options, $locale->text('Customer') . " : $form->{customer}";
1510 if ($form->{department}) {
1511 my ($department) = split /--/, $form->{department};
1512 push @options, $locale->text('Department') . " : $department";
1514 if ($form->{invnumber}) {
1515 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1517 if ($form->{ordnumber}) {
1518 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1520 if ($form->{notes}) {
1521 push @options, $locale->text('Notes') . " : $form->{notes}";
1523 if ($form->{transaction_description}) {
1524 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1526 if ($form->{transdatefrom}) {
1527 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1529 if ($form->{transdateto}) {
1530 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1532 if ($form->{open}) {
1533 push @options, $locale->text('Open');
1535 if ($form->{closed}) {
1536 push @options, $locale->text('Closed');
1539 $report->set_options('top_info_text' => join("\n", @options),
1540 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1541 'output_format' => 'HTML',
1542 'title' => $form->{title},
1543 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1545 $report->set_options_from_form();
1547 # add sort and escape callback, this one we use for the add sub
1548 $form->{callback} = $href .= "&sort=$form->{sort}";
1550 # escape callback for href
1551 $callback = $form->escape($href);
1553 my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
1555 my %totals = map { $_ => 0 } @subtotal_columns;
1556 my %subtotals = map { $_ => 0 } @subtotal_columns;
1560 foreach my $ar (@{ $form->{AR} }) {
1561 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1562 $ar->{due} = $ar->{amount} - $ar->{paid};
1564 map { $subtotals{$_} += $ar->{$_};
1565 $totals{$_} += $ar->{$_} } @subtotal_columns;
1567 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1568 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1570 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
1572 my $is_storno = $ar->{storno} && !$ar->{storno_id};
1573 my $has_storno = $ar->{storno} && $ar->{storno_id};
1576 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1577 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1578 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1579 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1580 $locale->text("AR Transaction (abbreviation)");
1584 foreach my $column (@columns) {
1586 'data' => $ar->{$column},
1587 'align' => $column_alignment{$column},
1591 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1592 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1594 my $row_set = [ $row ];
1596 if (($form->{l_subtotal} eq 'Y')
1597 && (($idx == (scalar @{ $form->{AR} } - 1))
1598 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1599 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1602 $report->add_data($row_set);
1607 $report->add_separator();
1608 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1610 $report->generate_with_headers();
1612 $lxdebug->leave_sub();
1616 $lxdebug->enter_sub();
1618 $auth->assert('general_ledger');
1620 # don't cancel cancelled transactions
1621 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1622 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1623 $form->error($locale->text("Transaction has already been cancelled!"));
1626 AR->storno($form, \%myconfig, $form->{id});
1628 # saving the history
1629 if(!exists $form->{addition} && $form->{id} ne "") {
1630 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1631 $form->{addition} = "STORNO";
1632 $form->save_history($form->dbconnect(\%myconfig));
1634 # /saving the history
1636 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1638 $lxdebug->leave_sub();