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;
47 our ($cgi, $form, $lxdebug, $locale, %myconfig);
49 require "bin/mozilla/arap.pl";
50 require "bin/mozilla/common.pl";
51 require "bin/mozilla/drafts.pl";
52 require "bin/mozilla/reportgenerator.pl";
58 # this is for our long dates
59 # $locale->text('January')
60 # $locale->text('February')
61 # $locale->text('March')
62 # $locale->text('April')
63 # $locale->text('May ')
64 # $locale->text('June')
65 # $locale->text('July')
66 # $locale->text('August')
67 # $locale->text('September')
68 # $locale->text('October')
69 # $locale->text('November')
70 # $locale->text('December')
72 # this is for our short month
73 # $locale->text('Jan')
74 # $locale->text('Feb')
75 # $locale->text('Mar')
76 # $locale->text('Apr')
77 # $locale->text('May')
78 # $locale->text('Jun')
79 # $locale->text('Jul')
80 # $locale->text('Aug')
81 # $locale->text('Sep')
82 # $locale->text('Oct')
83 # $locale->text('Nov')
84 # $locale->text('Dec')
87 $lxdebug->enter_sub();
89 $auth->assert('general_ledger');
91 return $lxdebug->leave_sub() if (load_draft_maybe());
94 if(!exists $form->{addition} && ($form->{id} ne "")) {
95 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
96 $form->{addition} = "ADDED";
97 $form->save_history($form->dbconnect(\%myconfig));
101 $form->{title} = "Add";
102 $form->{callback} = "ar.pl?action=add" unless $form->{callback};
104 AR->get_transdate(\%myconfig, $form);
105 $form->{initial_transdate} = $form->{transdate};
107 $form->{transdate} = $form->{initial_transdate};
109 $lxdebug->leave_sub();
113 $lxdebug->enter_sub();
115 $auth->assert('general_ledger');
117 # show history button
118 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
119 #/show hhistory button
120 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
121 $form->{title} = "Edit";
126 $lxdebug->leave_sub();
130 $lxdebug->enter_sub();
132 $auth->assert('general_ledger');
137 $lxdebug->leave_sub();
141 $lxdebug->enter_sub();
143 $auth->assert('general_ledger');
145 my ($duedate, $taxincluded, @curr);
147 $form->create_links("AR", \%myconfig, "customer");
148 $duedate = $form->{duedate};
150 $taxincluded = $form->{taxincluded};
151 my $id = $form->{id};
152 IS->get_customer(\%myconfig, \%$form);
153 $form->{taxincluded} = $taxincluded;
156 $form->{duedate} = $duedate if $duedate;
157 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
158 $form->{rowcount} = 1;
161 $form->{notes} = $form->{intnotes} unless $form->{notes};
164 @curr = split(/:/, $form->{currencies});
166 $form->{defaultcurrency} = $curr[0];
168 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
171 if (@{ $form->{all_customer} }) {
172 $form->{customer} = "$form->{customer}--$form->{customer_id}";
173 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
174 (@{ $form->{all_customer} });
178 if (@{ $form->{all_departments} }) {
179 $form->{selectdepartment} = "<option>\n";
180 $form->{department} = "$form->{department}--$form->{department_id}";
183 $form->{selectdepartment} .=
184 "<option>$_->{description}--$_->{id}\n"
185 } (@{ $form->{all_departments} });
188 $form->{employee} = "$form->{employee}--$form->{employee_id}";
191 if (@{ $form->{all_employees} }) {
192 $form->{selectemployee} = "";
193 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
194 (@{ $form->{all_employees} });
197 # build the popup menus
198 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
200 AR->setup_form($form);
203 ($form->datetonum($form->{transdate}, \%myconfig) <=
204 $form->datetonum($form->{closedto}, \%myconfig));
206 $lxdebug->leave_sub();
210 $lxdebug->enter_sub();
212 $auth->assert('general_ledger');
214 my ($title, $readonly, $exchangerate, $rows);
215 my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
216 my ($jsscript, $button1, $button2, $onload);
217 my ($selectAR_amount, $selectAR_paid, $ARselected, $tax);
218 my (@column_index, %column_data);
221 $title = $form->{title};
222 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
224 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
226 # $locale->text('Add Accounts Receivables Transaction')
227 # $locale->text('Edit Accounts Receivables Transaction')
228 $form->{javascript} = qq|<script type="text/javascript">
230 function setTaxkey(accno, row) {
231 var taxkey = accno.options[accno.selectedIndex].value;
232 var reg = /--([0-9]*)/;
233 var found = reg.exec(taxkey);
234 var index = found[1];
235 index = parseInt(index);
236 var tax = 'taxchart_' + row;
237 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
238 var reg2 = new RegExp("^"+ index, "");
239 if (reg2.exec(document.getElementById(tax).options[i].value)) {
240 document.getElementById(tax).options[i].selected = true;
247 # show history button js
248 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
249 #/show history button js
250 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
251 $readonly = ($form->{id}) ? "readonly" : "";
254 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
255 $readonly = ($form->{radier}) ? "" : $readonly;
257 # set option selected
258 foreach my $item (qw(customer currency department employee)) {
259 $form->{"select$item"} =~ s/ selected//;
260 $form->{"select$item"} =~
261 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
264 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
265 $form->{exchangerate} = $form->{forex} if $form->{forex};
268 $form->{exchangerate} =
269 $form->format_amount(\%myconfig, $form->{exchangerate});
271 if ($form->{exchangerate} == 0) {
272 $form->{exchangerate} = "";
275 $form->{creditlimit} =
276 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
277 $form->{creditremaining} =
278 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
281 <input type=hidden name=forex value=$form->{forex}>
283 if ($form->{currency} ne $form->{defaultcurrency}) {
284 if ($form->{forex}) {
286 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
287 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
291 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
292 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
299 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
300 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
304 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
308 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
312 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
313 <td colspan=3><select name=department>$form->{selectdepartment}</select>
314 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
317 | if $form->{selectdepartment};
319 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
321 $customer = ($form->{selectcustomer})
322 ? qq|<select name="customer" onchange="document.getElementById('update_button').click();">$form->{selectcustomer}</select>|
323 : qq|<input name=customer value="$form->{customer}" size=35>|;
326 <input type=hidden name=employee value="$form->{employee}">
329 if ($form->{selectemployee}) {
332 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
333 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
334 <input type=hidden name=selectemployee value="$form->{selectemployee}">
339 my @old_project_ids = ();
340 map({ push(@old_project_ids, $form->{"project_id_$_"})
341 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
343 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
345 "old_id" => \@old_project_ids },
346 "charts" => { "key" => "ALL_CHARTS",
347 "transdate" => $form->{transdate} },
348 "taxcharts" => { "key" => "ALL_TAXCHARTS",
349 "module" => "AR" },);
351 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
352 @{ $form->{ALL_CHARTS} });
354 my %project_labels = ();
355 my @project_values = ("");
356 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
357 push(@project_values, $item->{"id"});
358 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
361 my (%AR_amount_labels, @AR_amount_values);
362 my (%AR_labels, @AR_values);
363 my (%AR_paid_labels, @AR_paid_values);
367 foreach my $item (@{ $form->{ALL_CHARTS} }) {
368 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
369 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
370 my $key = "$item->{accno}--$item->{tax_id}";
371 push(@AR_amount_values, $key);
372 $AR_amount_labels{$key} =
373 "$item->{accno}--$item->{description}";
375 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
376 push(@AR_values, $item->{accno});
377 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
379 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
380 push(@AR_paid_values, $item->{accno});
381 $AR_paid_labels{$item->{accno}} =
382 "$item->{accno}--$item->{description}";
385 $charts{$item->{accno}} = $item;
388 my %taxchart_labels = ();
389 my @taxchart_values = ();
391 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
392 my $key = "$item->{id}--$item->{rate}";
393 $taxchart_init = $key if ($taxchart_init eq $item->{id});
394 push(@taxchart_values, $key);
395 $taxchart_labels{$key} =
396 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
397 $taxcharts{$item->{id}} = $item;
400 $form->{fokus} = "arledger.customer";
402 # use JavaScript Calendar or not
403 $form->{jsscript} = 1;
405 if ($form->{jsscript}) {
407 # with JavaScript Calendar
409 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
410 <td><input type=button name=transdate id="trigger1" value=|
411 . $locale->text('button') . qq|></td>
414 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
415 <td><input type=button name=duedate id="trigger2" value=|
416 . $locale->text('button') . qq|></td></td>
421 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
422 "duedate", "BL", "trigger2");
425 # without JavaScript Calendar
427 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
429 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
432 my $follow_up_vc = $form->{customer};
433 $follow_up_vc =~ s/--.*?//;
434 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
436 $form->{javascript} .=
437 qq|<script type="text/javascript" src="js/common.js"></script>| .
438 qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| .
439 qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
442 $onload = qq|focus()|;
443 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
444 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
446 <body onLoad="$onload">
448 <form method=post name="arledger" action=$form->{script}>
450 <input type=hidden name=id value=$form->{id}>
451 <input type=hidden name=sort value=$form->{sort}>
452 <input type=hidden name=closedto value=$form->{closedto}>
453 <input type=hidden name=locked value=$form->{locked}>
454 <input type=hidden name=title value="$title">
455 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
456 <input type="hidden" name="follow_up_trans_type_1" value="ar_transaction">
457 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
458 <input type="hidden" name="follow_up_rowcount" value="1">
460 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
464 <th class=listtop>$form->{title}</th>
474 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
475 <td colspan=3>$customer <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')"></td>
476 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
477 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
478 <input type=hidden name=customer_id value="$form->{customer_id}">
479 <input type=hidden name=terms value=$form->{terms}>
486 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
487 <td>$form->{creditlimit}</td>
488 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
489 <td class="plus$n">$form->{creditremaining}</td>
490 <input type=hidden name=creditlimit value=$form->{creditlimit}>
491 <input type=hidden name=creditremaining value=$form->{creditremaining}>
497 <th align=right>| . $locale->text('Currency') . qq|</th>
498 <td><select name=currency>$form->{selectcurrency}</select></td>
499 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
500 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
501 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
502 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
513 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
514 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
517 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
518 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
521 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
525 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
536 <input type=hidden name=rowcount value=$form->{rowcount}>
540 <tr class=listheading>
541 <th class=listheading style="width:15%">|
542 . $locale->text('Account') . qq|</th>
543 <th class=listheading style="width:10%">|
544 . $locale->text('Amount') . qq|</th>
545 <th class=listheading style="width:10%">|
546 . $locale->text('Tax') . qq|</th>
547 <th class=listheading style="width:5%">|
548 . $locale->text('Taxkey') . qq|</th>
549 <th class=listheading style="width:10%">|
550 . $locale->text('Project') . qq|</th>
554 $amount = $locale->text('Amount');
555 $project = $locale->text('Project');
557 for my $i (1 .. $form->{rowcount}) {
560 $form->{"amount_$i"} =
561 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
562 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
564 my $selected_accno_full;
565 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
566 my $item = $charts{$accno_row};
567 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
569 my $selected_taxchart = $form->{"taxchart_$i"};
570 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
571 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
573 if ($previous_accno &&
574 ($previous_accno eq $selected_accno) &&
575 ($previous_tax_id ne $selected_tax_id)) {
576 my $item = $taxcharts{$selected_tax_id};
577 $selected_taxchart = "$item->{id}--$item->{rate}";
580 if (!$form->{"taxchart_$i"}) {
581 if ($form->{"AR_amount_$i"} =~ m/.--./) {
582 $selected_taxchart = join '--', map { ($_->{id}, $_->{rate}) } first { $_->{id} == $item->{tax_id} } @{ $form->{ALL_TAXCHARTS} };
584 $selected_taxchart = $taxchart_init;
589 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
590 '-id' => "AR_amount_$i",
591 '-style' => 'width:400px',
592 '-onChange' => "setTaxkey(this, $i)",
593 '-values' => \@AR_amount_values,
594 '-labels' => \%AR_amount_labels,
595 '-default' => $selected_accno_full))
596 . $cgi->hidden('-name' => "previous_AR_amount_$i",
597 '-default' => $selected_accno_full);
600 NTI($cgi->popup_menu('-name' => "taxchart_$i",
601 '-id' => "taxchart_$i",
602 '-style' => 'width:200px',
603 '-values' => \@taxchart_values,
604 '-labels' => \%taxchart_labels,
605 '-default' => $selected_taxchart))
609 NTI($cgi->popup_menu('-name' => "project_id_$i",
610 '-values' => \@project_values,
611 '-labels' => \%project_labels,
612 '-default' => $form->{"project_id_$i"} ));
616 <td>$selectAR_amount</td>
617 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
618 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
620 <td>$projectnumber</td>
627 $form->{invtotal_unformatted} = $form->{invtotal};
628 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
631 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
632 '-style' => 'width:400px',
633 '-values' => \@AR_values, '-labels' => \%AR_labels,
634 '-default' => $form->{ARselected}));
643 <td>${ARselected}</td>
644 <th align=left>$form->{invtotal}</th>
646 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
647 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
649 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
662 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
663 <td align=left>$notes</td>
671 <tr class=listheading>
672 <th colspan=7 class=listheading>|
673 . $locale->text('Incoming Payments') . qq|</th>
677 if ($form->{currency} eq $form->{defaultcurrency}) {
678 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
680 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
683 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
684 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
685 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
686 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
687 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
688 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
689 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
694 map { print "$column_data{$_}\n" } @column_index;
702 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
703 for my $i (1 .. $form->{paidaccounts}) {
709 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
710 '-id' => "AR_paid_$i",
711 '-values' => \@AR_paid_values,
712 '-labels' => \%AR_paid_labels,
713 '-default' => $form->{"AR_paid_$i"}));
715 $totalpaid += $form->{"paid_$i"};
718 if ($form->{"paid_$i"}) {
720 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
722 $form->{"exchangerate_$i"} =
723 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
725 if ($form->{"exchangerate_$i"} == 0) {
726 $form->{"exchangerate_$i"} = "";
729 $exchangerate = qq| |;
730 if ($form->{currency} ne $form->{defaultcurrency}) {
731 if ($form->{"forex_$i"}) {
733 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
736 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
741 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
745 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
746 $column_data{AR_paid} =
747 qq|<td align=center>${selectAR_paid}</td>|;
748 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
749 $column_data{datepaid} =
750 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
751 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
752 $column_data{source} =
753 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
755 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
757 $column_data{paid_project_id} =
759 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
760 '-values' => \@project_values,
761 '-labels' => \%project_labels,
762 '-default' => $form->{"paid_project_id_$i"} ))
765 map { print qq|$column_data{$_}\n| } @column_index;
770 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
773 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
779 <td align="center">| . $locale->text('Total') . qq|</td>
780 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
785 <td align="center">| . $locale->text('Missing amount') . qq|</td>
786 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
788 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
790 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
796 <td><hr size=3 noshade></td>
801 $lxdebug->leave_sub();
805 $lxdebug->enter_sub();
807 $auth->assert('general_ledger');
809 my ($transdate, $closedto);
811 my $follow_ups_block;
813 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
815 if (@{ $follow_ups} ) {
816 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
817 $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>|;
825 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
827 <input name=callback type=hidden value="$form->{callback}">
829 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
830 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
836 if (!$form->{id} && $form->{draft_id}) {
837 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
838 '-value' => 1, '-checked' => $form->{remove_draft},
840 qq| <label for="remove_draft">| .
841 $locale->text("Remove draft when posting") .
845 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
846 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
848 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
850 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
851 print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
852 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($total_paid == 0) || ($total_paid eq "")));
855 if ($form->{radier}) {
857 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
858 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
860 if ($transdate > $closedto) {
862 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
865 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
866 <input type="button" class="submit" onclick="follow_up_window()" value="|
867 . $locale->text('Follow-Up')
871 if ($transdate > $closedto) {
872 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
873 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
877 if ($form->{menubar}) {
878 require "bin/mozilla/menu.pl";
881 # button for saving history
882 if($form->{id} ne "") {
883 print qq| <input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|> |;
885 # /button for saving history
886 # mark_as_paid button
887 if($form->{id} ne "") {
888 print qq|<input type="submit" class="submit" name="action" value="|
889 . $locale->text('mark as paid') . qq|">|;
891 # /mark_as_paid button
900 $lxdebug->leave_sub();
904 $lxdebug->enter_sub();
906 $auth->assert('general_ledger');
908 &mark_as_paid_common(\%myconfig,"ar");
910 $lxdebug->leave_sub();
914 $lxdebug->enter_sub();
916 $auth->assert('general_ledger');
920 my ($totaltax, $exchangerate, $totalpaid);
922 $form->{invtotal} = 0;
924 delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
926 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
927 qw(exchangerate creditlimit creditremaining);
929 my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
933 for my $i (1 .. $form->{rowcount}) {
934 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
935 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
936 if ($form->{"amount_$i"}) {
939 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
941 if ($form->{taxincluded}) {
942 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
944 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
947 $form->{"tax_$i"} = 0;
949 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
951 $totaltax += $form->{"tax_$i"};
952 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
957 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
958 $form->{rowcount} = $count + 1;
959 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
961 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
962 $form->{exchangerate} = $form->{forex} if $form->{forex};
964 $form->{invdate} = $form->{transdate};
966 $form->{invdate} = $form->{transdate};
968 my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1);
970 &check_name("customer");
972 $form->{AR} = $saved_variables{AR};
973 if ($saved_variables{AR_amount_1} =~ m/.--./) {
974 map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
976 delete $form->{taxchart_1};
980 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
982 for my $i (1 .. $form->{paidaccounts}) {
983 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
986 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
987 } qw(paid exchangerate);
989 $totalpaid += $form->{"paid_$i"};
991 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
992 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
996 $form->{creditremaining} -=
997 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
998 $form->{oldinvtotal});
999 $form->{oldinvtotal} = $form->{invtotal};
1000 $form->{oldtotalpaid} = $totalpaid;
1004 $lxdebug->leave_sub();
1008 # ToDO: fix $closedto and $invdate
1011 $lxdebug->enter_sub();
1013 $auth->assert('general_ledger');
1015 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1017 for my $i (1 .. $form->{paidaccounts}) {
1019 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1020 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1022 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1024 $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1026 if ($form->{currency} ne $form->{defaultcurrency}) {
1027 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
1028 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1033 ($form->{AR}) = split /--/, $form->{AR};
1034 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1035 $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
1036 $form->error($locale->text('Cannot post payment!'));
1038 $lxdebug->leave_sub();
1043 $auth->assert('general_ledger');
1050 $lxdebug->enter_sub();
1052 $auth->assert('general_ledger');
1058 # check if there is an invoice number, invoice and due date
1059 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
1060 $form->isblank("duedate", $locale->text('Due Date missing!'));
1061 $form->isblank("customer", $locale->text('Customer missing!'));
1063 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1064 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1065 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
1067 $form->error($locale->text('Zero amount posting!'))
1068 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
1070 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1071 if ($form->{currency} ne $form->{defaultcurrency});
1073 delete($form->{AR});
1075 for my $i (1 .. $form->{paidaccounts}) {
1076 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1077 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1079 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1081 $form->error($locale->text('Cannot post payment for a closed period!'))
1082 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1084 if ($form->{currency} ne $form->{defaultcurrency}) {
1085 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
1086 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1091 # if oldcustomer ne customer redo form
1092 my ($customer) = split /--/, $form->{customer};
1093 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1098 $form->{AR}{receivables} = $form->{ARselected};
1099 $form->{storno} = 0;
1101 $lxdebug->message(0, $form->{amount});
1102 $form->{id} = 0 if $form->{postasnew};
1103 $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
1105 # saving the history
1106 if(!exists $form->{addition} && $form->{id} ne "") {
1107 $form->{snumbers} = "invnumber_$form->{invnumber}";
1108 $form->{addition} = "POSTED";
1109 $form->save_history($form->dbconnect(\%myconfig));
1111 # /saving the history
1112 remove_draft() if $form->{remove_draft};
1114 $form->redirect($locale->text('Transaction posted!')) unless $inline;
1116 $lxdebug->leave_sub();
1120 $lxdebug->enter_sub();
1122 $auth->assert('general_ledger');
1124 $form->{postasnew} = 1;
1125 # saving the history
1126 if(!exists $form->{addition} && $form->{id} ne "") {
1127 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1128 $form->{addition} = "POSTED AS NEW";
1129 $form->save_history($form->dbconnect(\%myconfig));
1131 # /saving the history
1134 $lxdebug->leave_sub();
1137 sub use_as_template {
1138 $lxdebug->enter_sub();
1140 $auth->assert('general_ledger');
1142 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);
1143 $form->{paidaccounts} = 1;
1144 $form->{rowcount}--;
1145 $form->{invdate} = $form->current_date(\%myconfig);
1148 $lxdebug->leave_sub();
1152 $lxdebug->enter_sub();
1154 $auth->assert('general_ledger');
1156 $form->{title} = $locale->text('Confirm!');
1160 delete $form->{header};
1165 <form method=post action=$form->{script}>
1168 foreach my $key (keys %$form) {
1169 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1170 $form->{$key} =~ s/\"/"/g;
1171 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1175 <h2 class=confirm>$form->{title}</h2>
1178 . $locale->text('Are you sure you want to delete Transaction')
1179 . qq| $form->{invnumber}</h4>
1181 <input name=action class=submit type=submit value="|
1182 . $locale->text('Yes') . qq|">
1189 $lxdebug->leave_sub();
1193 $lxdebug->enter_sub();
1195 $auth->assert('general_ledger');
1197 if (AR->delete_transaction(\%myconfig, \%$form)) {
1198 # saving the history
1199 if(!exists $form->{addition}) {
1200 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1201 $form->{addition} = "DELETED";
1202 $form->save_history($form->dbconnect(\%myconfig));
1204 # /saving the history
1205 $form->redirect($locale->text('Transaction deleted!'));
1207 $form->error($locale->text('Cannot delete transaction!'));
1209 $lxdebug->leave_sub();
1213 $lxdebug->enter_sub();
1215 $auth->assert('general_ledger | invoice_edit');
1217 my ($customer, $department);
1218 my ($jsscript, $button1, $button2, $onload);
1220 # setup customer selection
1221 $form->all_vc(\%myconfig, "customer", "AR");
1223 if (@{ $form->{all_customer} }) {
1224 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1225 @{ $form->{all_customer} };
1226 $customer = qq|<select name=customer><option>\n$customer</select>|;
1228 $customer = qq|<input name=customer size=35>|;
1232 if (@{ $form->{all_departments} }) {
1233 $form->{selectdepartment} = "<option>\n";
1236 $form->{selectdepartment} .=
1237 "<option>$_->{description}--$_->{id}\n"
1238 } (@{ $form->{all_departments} });
1243 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1244 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1246 | if $form->{selectdepartment};
1248 $form->{title} = $locale->text('AR Transactions');
1250 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1252 # use JavaScript Calendar or not
1253 $form->{jsscript} = 1;
1255 if ($form->{jsscript}) {
1257 # with JavaScript Calendar
1259 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1260 <input type=button name=transdatefrom id="trigger1" value=|
1261 . $locale->text('button') . qq|></td>
1264 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1265 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1266 . $locale->text('button') . qq|></td>
1271 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1272 "transdateto", "BL", "trigger2");
1275 # without JavaScript Calendar
1277 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1279 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1282 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1287 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1288 push(@values, $item->{"id"});
1289 $labels{$item->{"id"}} = $item->{"projectnumber"};
1292 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1293 '-labels' => \%labels));
1295 $form->{fokus} = "search.customer";
1297 $onload = qq|focus()|;
1298 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1299 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1301 <body onLoad="$onload">
1303 <form method=post name="search" action=$form->{script}>
1306 <tr><th class=listtop>$form->{title}</th></tr>
1307 <tr height="5"></tr>
1312 <th align=right>| . $locale->text('Customer') . qq|</th>
1313 <td colspan=3>$customer</td>
1317 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1318 <td colspan=3><input name=invnumber size=20></td>
1321 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1322 <td colspan=3><input name=ordnumber size=20></td>
1325 <th align=right nowrap>| . $locale->text('Transaction description') . qq|</th>
1326 <td colspan=3><input name=transaction_description size=40></td>
1329 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1330 <td colspan=3><input name=notes size=40></td>
1333 <th align="right">| . $locale->text("Project Number") . qq|</th>
1334 <td colspan="3">$projectnumber</td>
1337 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1339 <th align=right>| . $locale->text('Bis') . qq|</th>
1342 <input type=hidden name=sort value=transdate>
1350 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1354 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1355 <td nowrap>| . $locale->text('Open') . qq|</td>
1356 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1357 <td nowrap>| . $locale->text('Closed') . qq|</td>
1360 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1361 <td nowrap>| . $locale->text('ID') . qq|</td>
1362 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1363 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1364 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1365 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1366 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1367 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1370 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1371 <td nowrap>| . $locale->text('Customer') . qq|</td>
1372 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1373 <td nowrap>| . $locale->text('Amount') . qq|</td>
1374 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1375 <td nowrap>| . $locale->text('Tax') . qq|</td>
1376 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1377 <td nowrap>| . $locale->text('Total') . qq|</td>
1380 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1381 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1382 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1383 <td nowrap>| . $locale->text('Paid') . qq|</td>
1384 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1385 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1386 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1387 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1390 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1391 <td nowrap>| . $locale->text('Notes') . qq|</td>
1392 <td align=right><input name="l_salesman" class=checkbox type=checkbox value=Y></td>
1393 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1394 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1395 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1396 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1397 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1400 <td align=right><input name="l_marge_total" class=checkbox type=checkbox value=Y></td>
1401 <td nowrap> | . $locale->text('Ertrag') . qq|</td>
1402 <td align=right><input name="l_marge_percent" class=checkbox type=checkbox value=Y></td>
1403 <td nowrap> | . $locale->text('Ertrag prozentual') . qq|</td>
1404 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1405 <td nowrap>| . $locale->text('Employee') . qq|</td>
1408 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1409 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1410 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1411 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1412 <td align=right><input name="l_transaction_description" class=checkbox type=checkbox value=Y></td>
1413 <td nowrap>| . $locale->text('Transaction description') . qq|</td>
1422 <td><hr size=3 noshade></td>
1426 <input type=hidden name=nextsub value=$form->{nextsub}>
1429 <input class=submit type=submit name=action value="|
1430 . $locale->text('Continue') . qq|">
1441 $lxdebug->leave_sub();
1444 sub create_subtotal_row {
1445 $lxdebug->enter_sub();
1447 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1449 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1451 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1453 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1455 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1457 $lxdebug->leave_sub();
1462 sub ar_transactions {
1463 $lxdebug->enter_sub();
1465 $auth->assert('general_ledger | invoice_edit');
1467 my ($callback, $href, @columns);
1469 $form->{customer} = $form->unescape($form->{customer});
1470 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1472 report_generator_set_default_sort('transdate', 1);
1474 AR->ar_transactions(\%myconfig, \%$form);
1476 $form->{title} = $locale->text('AR Transactions');
1478 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1481 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1482 datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
1483 marge_total marge_percent globalprojectnumber);
1485 my @hidden_variables = map { "l_${_}" } @columns;
1486 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
1488 $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1491 'transdate' => { 'text' => $locale->text('Date'), },
1492 'id' => { 'text' => $locale->text('ID'), },
1493 'type' => { 'text' => $locale->text('Type'), },
1494 'invnumber' => { 'text' => $locale->text('Invoice'), },
1495 'ordnumber' => { 'text' => $locale->text('Order'), },
1496 'name' => { 'text' => $locale->text('Customer'), },
1497 'netamount' => { 'text' => $locale->text('Amount'), },
1498 'tax' => { 'text' => $locale->text('Tax'), },
1499 'amount' => { 'text' => $locale->text('Total'), },
1500 'paid' => { 'text' => $locale->text('Paid'), },
1501 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1502 'due' => { 'text' => $locale->text('Amount Due'), },
1503 'duedate' => { 'text' => $locale->text('Due Date'), },
1504 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1505 'notes' => { 'text' => $locale->text('Notes'), },
1506 'salesman' => { 'text' => $locale->text('Salesperson'), },
1507 'employee' => { 'text' => $locale->text('Employee'), },
1508 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1509 'shipvia' => { 'text' => $locale->text('Ship via'), },
1510 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1511 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1512 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
1515 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
1516 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1517 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1520 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1522 $form->{"l_type"} = "Y";
1523 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1525 $report->set_columns(%column_defs);
1526 $report->set_column_order(@columns);
1528 $report->set_export_options('ar_transactions', @hidden_variables, qw(sort sortdir));
1530 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1533 if ($form->{customer}) {
1534 push @options, $locale->text('Customer') . " : $form->{customer}";
1536 if ($form->{department}) {
1537 my ($department) = split /--/, $form->{department};
1538 push @options, $locale->text('Department') . " : $department";
1540 if ($form->{invnumber}) {
1541 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1543 if ($form->{ordnumber}) {
1544 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1546 if ($form->{notes}) {
1547 push @options, $locale->text('Notes') . " : $form->{notes}";
1549 if ($form->{transaction_description}) {
1550 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1552 if ($form->{transdatefrom}) {
1553 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1555 if ($form->{transdateto}) {
1556 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1558 if ($form->{open}) {
1559 push @options, $locale->text('Open');
1561 if ($form->{closed}) {
1562 push @options, $locale->text('Closed');
1565 $report->set_options('top_info_text' => join("\n", @options),
1566 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1567 'output_format' => 'HTML',
1568 'title' => $form->{title},
1569 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1571 $report->set_options_from_form();
1573 # add sort and escape callback, this one we use for the add sub
1574 $form->{callback} = $href .= "&sort=$form->{sort}";
1576 # escape callback for href
1577 $callback = $form->escape($href);
1579 my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
1581 my %totals = map { $_ => 0 } @subtotal_columns;
1582 my %subtotals = map { $_ => 0 } @subtotal_columns;
1586 foreach my $ar (@{ $form->{AR} }) {
1587 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1588 $ar->{due} = $ar->{amount} - $ar->{paid};
1590 map { $subtotals{$_} += $ar->{$_};
1591 $totals{$_} += $ar->{$_} } @subtotal_columns;
1593 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1594 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1596 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
1598 my $is_storno = $ar->{storno} && $ar->{storno_id};
1599 my $has_storno = $ar->{storno} && !$ar->{storno_id};
1602 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1603 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1604 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1605 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1606 $locale->text("AR Transaction (abbreviation)");
1610 foreach my $column (@columns) {
1612 'data' => $ar->{$column},
1613 'align' => $column_alignment{$column},
1617 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1618 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1620 my $row_set = [ $row ];
1622 if (($form->{l_subtotal} eq 'Y')
1623 && (($idx == (scalar @{ $form->{AR} } - 1))
1624 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1625 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1628 $report->add_data($row_set);
1633 $report->add_separator();
1634 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1636 $report->generate_with_headers();
1638 $lxdebug->leave_sub();
1642 $lxdebug->enter_sub();
1644 $auth->assert('general_ledger');
1646 # don't cancel cancelled transactions
1647 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1648 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1649 $form->error($locale->text("Transaction has already been cancelled!"));
1652 AR->storno($form, \%myconfig, $form->{id});
1654 # saving the history
1655 if(!exists $form->{addition} && $form->{id} ne "") {
1656 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1657 $form->{addition} = "STORNO";
1658 $form->save_history($form->dbconnect(\%myconfig));
1660 # /saving the history
1662 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1664 $lxdebug->leave_sub();