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);
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, $korrektur_checked, $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" => "ALL_TAXCHARTS");
350 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
351 @{ $form->{ALL_CHARTS} });
353 my %project_labels = ();
354 my @project_values = ("");
355 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
356 push(@project_values, $item->{"id"});
357 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
360 my (%AR_amount_labels, @AR_amount_values);
361 my (%AR_labels, @AR_values);
362 my (%AR_paid_labels, @AR_paid_values);
366 foreach my $item (@{ $form->{ALL_CHARTS} }) {
367 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
368 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
369 my $key = "$item->{accno}--$item->{tax_id}";
370 push(@AR_amount_values, $key);
371 $AR_amount_labels{$key} =
372 "$item->{accno}--$item->{description}";
374 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
375 push(@AR_values, $item->{accno});
376 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
378 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
379 push(@AR_paid_values, $item->{accno});
380 $AR_paid_labels{$item->{accno}} =
381 "$item->{accno}--$item->{description}";
384 $charts{$item->{accno}} = $item;
387 my %taxchart_labels = ();
388 my @taxchart_values = ();
390 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
391 my $key = "$item->{id}--$item->{rate}";
392 $taxchart_init = $key if ($taxchart_init eq $item->{id});
393 push(@taxchart_values, $key);
394 $taxchart_labels{$key} =
395 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
396 $taxcharts{$item->{id}} = $item;
399 $form->{fokus} = "arledger.customer";
401 # use JavaScript Calendar or not
402 $form->{jsscript} = 1;
404 if ($form->{jsscript}) {
406 # with JavaScript Calendar
408 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
409 <td><input type=button name=transdate id="trigger1" value=|
410 . $locale->text('button') . qq|></td>
413 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
414 <td><input type=button name=duedate id="trigger2" value=|
415 . $locale->text('button') . qq|></td></td>
420 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
421 "duedate", "BL", "trigger2");
424 # without JavaScript Calendar
426 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
428 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
431 my $follow_up_vc = $form->{customer};
432 $follow_up_vc =~ s/--.*?//;
433 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
435 $form->{javascript} .=
436 qq|<script type="text/javascript" src="js/common.js"></script>| .
437 qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| .
438 qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
441 $onload = qq|focus()|;
442 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
443 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
445 <body onLoad="$onload">
447 <form method=post name="arledger" action=$form->{script}>
449 <input type=hidden name=id value=$form->{id}>
450 <input type=hidden name=sort value=$form->{sort}>
451 <input type=hidden name=closedto value=$form->{closedto}>
452 <input type=hidden name=locked value=$form->{locked}>
453 <input type=hidden name=title value="$title">
454 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
455 <input type="hidden" name="follow_up_trans_type_1" value="ar_transaction">
456 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
457 <input type="hidden" name="follow_up_rowcount" value="1">
459 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
463 <th class=listtop>$form->{title}</th>
473 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
474 <td colspan=3>$customer <input type="button" value="?" onclick="show_vc_details('customer')"></td>
475 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
476 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
477 <input type=hidden name=customer_id value="$form->{customer_id}">
478 <input type=hidden name=terms value=$form->{terms}>
485 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
486 <td>$form->{creditlimit}</td>
487 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
488 <td class="plus$n">$form->{creditremaining}</td>
489 <input type=hidden name=creditlimit value=$form->{creditlimit}>
490 <input type=hidden name=creditremaining value=$form->{creditremaining}>
496 <th align=right>| . $locale->text('Currency') . qq|</th>
497 <td><select name=currency>$form->{selectcurrency}</select></td>
498 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
499 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
500 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
501 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
512 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
513 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
516 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
517 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
520 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
524 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
535 <input type=hidden name=rowcount value=$form->{rowcount}>
539 <tr class=listheading>
540 <th class=listheading style="width:15%">|
541 . $locale->text('Account') . qq|</th>
542 <th class=listheading style="width:10%">|
543 . $locale->text('Amount') . qq|</th>
544 <th class=listheading style="width:10%">|
545 . $locale->text('Tax') . qq|</th>
546 <th class=listheading style="width:5%">|
547 . $locale->text('Korrektur') . qq|</th>
548 <th class=listheading style="width:10%">|
549 . $locale->text('Taxkey') . qq|</th>
550 <th class=listheading style="width:10%">|
551 . $locale->text('Project') . qq|</th>
555 $amount = $locale->text('Amount');
556 $project = $locale->text('Project');
558 for my $i (1 .. $form->{rowcount}) {
561 $form->{"amount_$i"} =
562 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
563 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
565 my $selected_accno_full;
566 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
567 my $item = $charts{$accno_row};
568 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
570 my $selected_taxchart = $form->{"taxchart_$i"};
571 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
572 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
574 if ($previous_accno &&
575 ($previous_accno eq $selected_accno) &&
576 ($previous_tax_id ne $selected_tax_id)) {
577 my $item = $taxcharts{$selected_tax_id};
578 $selected_taxchart = "$item->{id}--$item->{rate}";
581 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
584 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
585 '-id' => "AR_amount_$i",
586 '-style' => 'width:400px',
587 '-onChange' => "setTaxkey(this, $i)",
588 '-values' => \@AR_amount_values,
589 '-labels' => \%AR_amount_labels,
590 '-default' => $selected_accno_full))
591 . $cgi->hidden('-name' => "previous_AR_amount_$i",
592 '-default' => $selected_accno_full);
595 NTI($cgi->popup_menu('-name' => "taxchart_$i",
596 '-id' => "taxchart_$i",
597 '-style' => 'width:200px',
598 '-values' => \@taxchart_values,
599 '-labels' => \%taxchart_labels,
600 '-default' => $selected_taxchart))
603 $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
606 NTI($cgi->popup_menu('-name' => "project_id_$i",
607 '-values' => \@project_values,
608 '-labels' => \%project_labels,
609 '-default' => $form->{"project_id_$i"} ));
613 <td>$selectAR_amount</td>
614 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
615 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
616 <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
618 <td>$projectnumber</td>
625 $form->{invtotal_unformatted} = $form->{invtotal};
626 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
629 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
630 '-style' => 'width:400px',
631 '-values' => \@AR_values, '-labels' => \%AR_labels,
632 '-default' => $form->{ARselected}));
641 <td>${ARselected}</td>
642 <th align=left>$form->{invtotal}</th>
644 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
645 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
647 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
660 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
661 <td align=left>$notes</td>
669 <tr class=listheading>
670 <th colspan=7 class=listheading>|
671 . $locale->text('Incoming Payments') . qq|</th>
675 if ($form->{currency} eq $form->{defaultcurrency}) {
676 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
678 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
681 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
682 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
683 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
684 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
685 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
686 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
687 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
692 map { print "$column_data{$_}\n" } @column_index;
700 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
701 for my $i (1 .. $form->{paidaccounts}) {
707 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
708 '-id' => "AR_paid_$i",
709 '-values' => \@AR_paid_values,
710 '-labels' => \%AR_paid_labels,
711 '-default' => $form->{"AR_paid_$i"}));
713 $totalpaid += $form->{"paid_$i"};
716 if ($form->{"paid_$i"}) {
718 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
720 $form->{"exchangerate_$i"} =
721 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
723 if ($form->{"exchangerate_$i"} == 0) {
724 $form->{"exchangerate_$i"} = "";
727 $exchangerate = qq| |;
728 if ($form->{currency} ne $form->{defaultcurrency}) {
729 if ($form->{"forex_$i"}) {
731 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
734 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
739 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
743 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
744 $column_data{AR_paid} =
745 qq|<td align=center>${selectAR_paid}</td>|;
746 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
747 $column_data{datepaid} =
748 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
749 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
750 $column_data{source} =
751 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
753 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
755 $column_data{paid_project_id} =
757 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
758 '-values' => \@project_values,
759 '-labels' => \%project_labels,
760 '-default' => $form->{"paid_project_id_$i"} ))
763 map { print qq|$column_data{$_}\n| } @column_index;
768 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
771 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
777 <td align="center">| . $locale->text('Total') . qq|</td>
778 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
783 <td align="center">| . $locale->text('Missing amount') . qq|</td>
784 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
786 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
788 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
794 <td><hr size=3 noshade></td>
799 $lxdebug->leave_sub();
803 $lxdebug->enter_sub();
805 $auth->assert('general_ledger');
807 my ($transdate, $closedto);
809 my $follow_ups_block;
811 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
813 if (@{ $follow_ups} ) {
814 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
815 $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>|;
823 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
825 <input name=callback type=hidden value="$form->{callback}">
827 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
828 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
834 if (!$form->{id} && $form->{draft_id}) {
835 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
836 '-value' => 1, '-checked' => $form->{remove_draft},
838 qq| <label for="remove_draft">| .
839 $locale->text("Remove draft when posting") .
843 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
844 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
846 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
848 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
849 print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
850 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar'));
853 if ($form->{radier}) {
855 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
856 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
858 if ($transdate > $closedto) {
860 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
863 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
864 <input type="button" class="submit" onclick="follow_up_window()" value="|
865 . $locale->text('Follow-Up')
869 if ($transdate > $closedto) {
870 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
871 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
875 if ($form->{menubar}) {
876 require "bin/mozilla/menu.pl";
879 # button for saving history
880 if($form->{id} ne "") {
881 print qq| <input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|> |;
883 # /button for saving history
884 # mark_as_paid button
885 if($form->{id} ne "") {
886 print qq|<input type="submit" class="submit" name="action" value="|
887 . $locale->text('mark as paid') . qq|">|;
889 # /mark_as_paid button
898 $lxdebug->leave_sub();
902 $lxdebug->enter_sub();
904 $auth->assert('general_ledger');
906 &mark_as_paid_common(\%myconfig,"ar");
908 $lxdebug->leave_sub();
912 $lxdebug->enter_sub();
914 $auth->assert('general_ledger');
918 my ($totaltax, $exchangerate, $totalpaid);
920 $form->{invtotal} = 0;
922 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
923 qw(exchangerate creditlimit creditremaining);
925 my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
929 for my $i (1 .. $form->{rowcount}) {
930 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
931 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
932 if ($form->{"amount_$i"}) {
935 if (!$form->{"korrektur_$i"}) {
936 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
938 if ($form->{taxincluded}) {
939 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
941 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
944 $form->{"tax_$i"} = 0;
947 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
949 $totaltax += $form->{"tax_$i"};
950 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
955 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
956 $form->{rowcount} = $count + 1;
957 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
959 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
960 $form->{exchangerate} = $form->{forex} if $form->{forex};
962 $form->{invdate} = $form->{transdate};
963 my $save_AR = $form->{AR};
964 check_name("customer");
965 $form->{AR} = $save_AR;
968 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
970 for my $i (1 .. $form->{paidaccounts}) {
971 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
974 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
975 } qw(paid exchangerate);
977 $totalpaid += $form->{"paid_$i"};
979 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
980 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
984 $form->{creditremaining} -=
985 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
986 $form->{oldinvtotal});
987 $form->{oldinvtotal} = $form->{invtotal};
988 $form->{oldtotalpaid} = $totalpaid;
992 $lxdebug->leave_sub();
996 # ToDO: fix $closedto and $invdate
999 $lxdebug->enter_sub();
1001 $auth->assert('general_ledger');
1003 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1005 for my $i (1 .. $form->{paidaccounts}) {
1007 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1008 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1010 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1012 $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1014 if ($form->{currency} ne $form->{defaultcurrency}) {
1015 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
1016 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1021 ($form->{AR}) = split /--/, $form->{AR};
1022 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1023 $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
1024 $form->error($locale->text('Cannot post payment!'));
1026 $lxdebug->leave_sub();
1031 $auth->assert('general_ledger');
1038 $lxdebug->enter_sub();
1040 $auth->assert('general_ledger');
1046 # check if there is an invoice number, invoice and due date
1047 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
1048 $form->isblank("duedate", $locale->text('Due Date missing!'));
1049 $form->isblank("customer", $locale->text('Customer missing!'));
1051 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1052 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1053 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
1055 $form->error($locale->text('Zero amount posting!'))
1056 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
1058 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1059 if ($form->{currency} ne $form->{defaultcurrency});
1061 delete($form->{AR});
1063 for my $i (1 .. $form->{paidaccounts}) {
1064 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1065 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1067 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1069 $form->error($locale->text('Cannot post payment for a closed period!'))
1070 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1072 if ($form->{currency} ne $form->{defaultcurrency}) {
1073 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
1074 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1079 # if oldcustomer ne customer redo form
1080 my ($customer) = split /--/, $form->{customer};
1081 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1086 $form->{AR}{receivables} = $form->{ARselected};
1087 $form->{storno} = 0;
1089 $lxdebug->message(0, $form->{amount});
1090 $form->{id} = 0 if $form->{postasnew};
1091 $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
1093 # saving the history
1094 if(!exists $form->{addition} && $form->{id} ne "") {
1095 $form->{snumbers} = "invnumber_$form->{invnumber}";
1096 $form->{addition} = "POSTED";
1097 $form->save_history($form->dbconnect(\%myconfig));
1099 # /saving the history
1100 remove_draft() if $form->{remove_draft};
1102 $form->redirect($locale->text('Transaction posted!')) unless $inline;
1104 $lxdebug->leave_sub();
1108 $lxdebug->enter_sub();
1110 $auth->assert('general_ledger');
1112 $form->{postasnew} = 1;
1113 # saving the history
1114 if(!exists $form->{addition} && $form->{id} ne "") {
1115 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1116 $form->{addition} = "POSTED AS NEW";
1117 $form->save_history($form->dbconnect(\%myconfig));
1119 # /saving the history
1122 $lxdebug->leave_sub();
1125 sub use_as_template {
1126 $lxdebug->enter_sub();
1128 $auth->assert('general_ledger');
1130 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);
1131 $form->{paidaccounts} = 1;
1132 $form->{rowcount}--;
1133 $form->{invdate} = $form->current_date(\%myconfig);
1136 $lxdebug->leave_sub();
1140 $lxdebug->enter_sub();
1142 $auth->assert('general_ledger');
1144 $form->{title} = $locale->text('Confirm!');
1148 delete $form->{header};
1153 <form method=post action=$form->{script}>
1156 foreach my $key (keys %$form) {
1157 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1158 $form->{$key} =~ s/\"/"/g;
1159 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1163 <h2 class=confirm>$form->{title}</h2>
1166 . $locale->text('Are you sure you want to delete Transaction')
1167 . qq| $form->{invnumber}</h4>
1169 <input name=action class=submit type=submit value="|
1170 . $locale->text('Yes') . qq|">
1177 $lxdebug->leave_sub();
1181 $lxdebug->enter_sub();
1183 $auth->assert('general_ledger');
1185 if (AR->delete_transaction(\%myconfig, \%$form)) {
1186 # saving the history
1187 if(!exists $form->{addition}) {
1188 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1189 $form->{addition} = "DELETED";
1190 $form->save_history($form->dbconnect(\%myconfig));
1192 # /saving the history
1193 $form->redirect($locale->text('Transaction deleted!'));
1195 $form->error($locale->text('Cannot delete transaction!'));
1197 $lxdebug->leave_sub();
1201 $lxdebug->enter_sub();
1203 $auth->assert('general_ledger | invoice_edit');
1205 my ($customer, $department);
1206 my ($jsscript, $button1, $button2, $onload);
1208 # setup customer selection
1209 $form->all_vc(\%myconfig, "customer", "AR");
1211 if (@{ $form->{all_customer} }) {
1212 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1213 @{ $form->{all_customer} };
1214 $customer = qq|<select name=customer><option>\n$customer</select>|;
1216 $customer = qq|<input name=customer size=35>|;
1220 if (@{ $form->{all_departments} }) {
1221 $form->{selectdepartment} = "<option>\n";
1224 $form->{selectdepartment} .=
1225 "<option>$_->{description}--$_->{id}\n"
1226 } (@{ $form->{all_departments} });
1231 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1232 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1234 | if $form->{selectdepartment};
1236 $form->{title} = $locale->text('AR Transactions');
1238 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1240 # use JavaScript Calendar or not
1241 $form->{jsscript} = 1;
1243 if ($form->{jsscript}) {
1245 # with JavaScript Calendar
1247 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1248 <input type=button name=transdatefrom id="trigger1" value=|
1249 . $locale->text('button') . qq|></td>
1252 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1253 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1254 . $locale->text('button') . qq|></td>
1259 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1260 "transdateto", "BL", "trigger2");
1263 # without JavaScript Calendar
1265 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1267 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1270 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1275 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1276 push(@values, $item->{"id"});
1277 $labels{$item->{"id"}} = $item->{"projectnumber"};
1280 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1281 '-labels' => \%labels));
1283 $form->{fokus} = "search.customer";
1285 $onload = qq|focus()|;
1286 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1287 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1289 <body onLoad="$onload">
1291 <form method=post name="search" action=$form->{script}>
1294 <tr><th class=listtop>$form->{title}</th></tr>
1295 <tr height="5"></tr>
1300 <th align=right>| . $locale->text('Customer') . qq|</th>
1301 <td colspan=3>$customer</td>
1305 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1306 <td colspan=3><input name=invnumber size=20></td>
1309 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1310 <td colspan=3><input name=ordnumber size=20></td>
1313 <th align=right nowrap>| . $locale->text('Transaction description') . qq|</th>
1314 <td colspan=3><input name=transaction_description size=40></td>
1317 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1318 <td colspan=3><input name=notes size=40></td>
1321 <th align="right">| . $locale->text("Project Number") . qq|</th>
1322 <td colspan="3">$projectnumber</td>
1325 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1327 <th align=right>| . $locale->text('Bis') . qq|</th>
1330 <input type=hidden name=sort value=transdate>
1338 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1342 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1343 <td nowrap>| . $locale->text('Open') . qq|</td>
1344 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1345 <td nowrap>| . $locale->text('Closed') . qq|</td>
1348 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1349 <td nowrap>| . $locale->text('ID') . qq|</td>
1350 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1351 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1352 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1353 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1354 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1355 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1358 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1359 <td nowrap>| . $locale->text('Customer') . qq|</td>
1360 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1361 <td nowrap>| . $locale->text('Amount') . qq|</td>
1362 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1363 <td nowrap>| . $locale->text('Tax') . qq|</td>
1364 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1365 <td nowrap>| . $locale->text('Total') . qq|</td>
1368 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1369 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1370 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1371 <td nowrap>| . $locale->text('Paid') . qq|</td>
1372 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1373 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1374 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1375 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1378 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1379 <td nowrap>| . $locale->text('Notes') . qq|</td>
1380 <td align=right><input name="l_salesman" class=checkbox type=checkbox value=Y></td>
1381 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1382 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1383 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1384 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1385 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1388 <td align=right><input name="l_marge_total" class=checkbox type=checkbox value=Y></td>
1389 <td nowrap> | . $locale->text('Ertrag') . qq|</td>
1390 <td align=right><input name="l_marge_percent" class=checkbox type=checkbox value=Y></td>
1391 <td nowrap> | . $locale->text('Ertrag prozentual') . qq|</td>
1392 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1393 <td nowrap>| . $locale->text('Employee') . qq|</td>
1396 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1397 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1398 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1399 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1400 <td align=right><input name="l_transaction_description" class=checkbox type=checkbox value=Y></td>
1401 <td nowrap>| . $locale->text('Transaction description') . qq|</td>
1410 <td><hr size=3 noshade></td>
1414 <input type=hidden name=nextsub value=$form->{nextsub}>
1417 <input class=submit type=submit name=action value="|
1418 . $locale->text('Continue') . qq|">
1429 $lxdebug->leave_sub();
1432 sub create_subtotal_row {
1433 $lxdebug->enter_sub();
1435 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1437 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1439 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1441 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1443 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1445 $lxdebug->leave_sub();
1450 sub ar_transactions {
1451 $lxdebug->enter_sub();
1453 $auth->assert('general_ledger | invoice_edit');
1455 my ($callback, $href, @columns);
1457 $form->{customer} = $form->unescape($form->{customer});
1458 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1460 report_generator_set_default_sort('transdate', 1);
1462 AR->ar_transactions(\%myconfig, \%$form);
1464 $form->{title} = $locale->text('AR Transactions');
1466 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1469 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1470 datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
1471 marge_total marge_percent globalprojectnumber);
1473 my @hidden_variables = map { "l_${_}" } @columns;
1474 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
1476 $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1479 'transdate' => { 'text' => $locale->text('Date'), },
1480 'id' => { 'text' => $locale->text('ID'), },
1481 'type' => { 'text' => $locale->text('Type'), },
1482 'invnumber' => { 'text' => $locale->text('Invoice'), },
1483 'ordnumber' => { 'text' => $locale->text('Order'), },
1484 'name' => { 'text' => $locale->text('Customer'), },
1485 'netamount' => { 'text' => $locale->text('Amount'), },
1486 'tax' => { 'text' => $locale->text('Tax'), },
1487 'amount' => { 'text' => $locale->text('Total'), },
1488 'paid' => { 'text' => $locale->text('Paid'), },
1489 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1490 'due' => { 'text' => $locale->text('Amount Due'), },
1491 'duedate' => { 'text' => $locale->text('Due Date'), },
1492 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1493 'notes' => { 'text' => $locale->text('Notes'), },
1494 'salesman' => { 'text' => $locale->text('Salesperson'), },
1495 'employee' => { 'text' => $locale->text('Employee'), },
1496 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1497 'shipvia' => { 'text' => $locale->text('Ship via'), },
1498 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1499 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1500 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
1503 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia)) {
1504 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1505 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1508 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1510 $form->{"l_type"} = "Y";
1511 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1513 $report->set_columns(%column_defs);
1514 $report->set_column_order(@columns);
1516 $report->set_export_options('ar_transactions', @hidden_variables);
1518 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1521 if ($form->{customer}) {
1522 push @options, $locale->text('Customer') . " : $form->{customer}";
1524 if ($form->{department}) {
1525 my ($department) = split /--/, $form->{department};
1526 push @options, $locale->text('Department') . " : $department";
1528 if ($form->{invnumber}) {
1529 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1531 if ($form->{ordnumber}) {
1532 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1534 if ($form->{notes}) {
1535 push @options, $locale->text('Notes') . " : $form->{notes}";
1537 if ($form->{transaction_description}) {
1538 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1540 if ($form->{transdatefrom}) {
1541 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1543 if ($form->{transdateto}) {
1544 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1546 if ($form->{open}) {
1547 push @options, $locale->text('Open');
1549 if ($form->{closed}) {
1550 push @options, $locale->text('Closed');
1553 $report->set_options('top_info_text' => join("\n", @options),
1554 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1555 'output_format' => 'HTML',
1556 'title' => $form->{title},
1557 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1559 $report->set_options_from_form();
1561 # add sort and escape callback, this one we use for the add sub
1562 $form->{callback} = $href .= "&sort=$form->{sort}";
1564 # escape callback for href
1565 $callback = $form->escape($href);
1567 my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
1569 my %totals = map { $_ => 0 } @subtotal_columns;
1570 my %subtotals = map { $_ => 0 } @subtotal_columns;
1574 foreach my $ar (@{ $form->{AR} }) {
1575 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1576 $ar->{due} = $ar->{amount} - $ar->{paid};
1578 map { $subtotals{$_} += $ar->{$_};
1579 $totals{$_} += $ar->{$_} } @subtotal_columns;
1581 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1582 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1584 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
1586 my $is_storno = $ar->{storno} && !$ar->{storno_id};
1587 my $has_storno = $ar->{storno} && $ar->{storno_id};
1590 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1591 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1592 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1593 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1594 $locale->text("AR Transaction (abbreviation)");
1598 foreach my $column (@columns) {
1600 'data' => $ar->{$column},
1601 'align' => $column_alignment{$column},
1605 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1606 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1608 my $row_set = [ $row ];
1610 if (($form->{l_subtotal} eq 'Y')
1611 && (($idx == (scalar @{ $form->{AR} } - 1))
1612 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1613 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1616 $report->add_data($row_set);
1621 $report->add_separator();
1622 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1624 $report->generate_with_headers();
1626 $lxdebug->leave_sub();
1630 $lxdebug->enter_sub();
1632 $auth->assert('general_ledger');
1634 # don't cancel cancelled transactions
1635 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1636 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1637 $form->error($locale->text("Transaction has already been cancelled!"));
1640 AR->storno($form, \%myconfig, $form->{id});
1642 # saving the history
1643 if(!exists $form->{addition} && $form->{id} ne "") {
1644 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1645 $form->{addition} = "STORNO";
1646 $form->save_history($form->dbconnect(\%myconfig));
1648 # /saving the history
1650 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1652 $lxdebug->leave_sub();