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 #======================================================================
39 require "bin/mozilla/arap.pl";
40 require "bin/mozilla/common.pl";
41 require "bin/mozilla/drafts.pl";
47 # this is for our long dates
48 # $locale->text('January')
49 # $locale->text('February')
50 # $locale->text('March')
51 # $locale->text('April')
52 # $locale->text('May ')
53 # $locale->text('June')
54 # $locale->text('July')
55 # $locale->text('August')
56 # $locale->text('September')
57 # $locale->text('October')
58 # $locale->text('November')
59 # $locale->text('December')
61 # this is for our short month
62 # $locale->text('Jan')
63 # $locale->text('Feb')
64 # $locale->text('Mar')
65 # $locale->text('Apr')
66 # $locale->text('May')
67 # $locale->text('Jun')
68 # $locale->text('Jul')
69 # $locale->text('Aug')
70 # $locale->text('Sep')
71 # $locale->text('Oct')
72 # $locale->text('Nov')
73 # $locale->text('Dec')
76 $lxdebug->enter_sub();
78 return $lxdebug->leave_sub() if (load_draft_maybe());
81 if(!exists $form->{addition} && ($form->{id} ne "")) {
82 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
83 $form->{addition} = "ADDED";
84 $form->save_history($form->dbconnect(\%myconfig));
88 $form->{title} = "Add";
90 "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
91 unless $form->{callback};
93 AR->get_transdate(\%myconfig, $form);
94 $form->{initial_transdate} = $form->{transdate};
96 $form->{transdate} = $form->{initial_transdate};
98 $lxdebug->leave_sub();
102 $lxdebug->enter_sub();
103 # show history button
104 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
105 #/show hhistory button
106 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
107 $form->{title} = "Edit";
112 $lxdebug->leave_sub();
116 $lxdebug->enter_sub();
121 $lxdebug->leave_sub();
125 $lxdebug->enter_sub();
127 $form->create_links("AR", \%myconfig, "customer");
128 $duedate = $form->{duedate};
130 $taxincluded = $form->{taxincluded};
131 my $id = $form->{id};
132 IS->get_customer(\%myconfig, \%$form);
133 $form->{taxincluded} = $taxincluded;
136 $form->{duedate} = $duedate if $duedate;
137 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
138 $form->{rowcount} = 1;
141 $form->{notes} = $form->{intnotes} unless $form->{notes};
144 @curr = split(/:/, $form->{currencies});
146 $form->{defaultcurrency} = $curr[0];
148 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
151 if (@{ $form->{all_customer} }) {
152 $form->{customer} = "$form->{customer}--$form->{customer_id}";
153 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
154 (@{ $form->{all_customer} });
158 if (@{ $form->{all_departments} }) {
159 $form->{selectdepartment} = "<option>\n";
160 $form->{department} = "$form->{department}--$form->{department_id}";
163 $form->{selectdepartment} .=
164 "<option>$_->{description}--$_->{id}\n"
165 } (@{ $form->{all_departments} });
168 $form->{employee} = "$form->{employee}--$form->{employee_id}";
171 if (@{ $form->{all_employees} }) {
172 $form->{selectemployee} = "";
173 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
174 (@{ $form->{all_employees} });
177 # build the popup menus
178 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
181 $form->{forex} = $form->{exchangerate};
182 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
183 foreach $key (keys %{ $form->{AR_links} }) {
184 # if there is a value we have an old entry
188 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
189 if ($key eq "AR_paid") {
191 $form->{"AR_paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{accno};
194 $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
195 $form->{"datepaid_$j"} =
196 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
197 $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
198 $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
200 $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
201 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
202 $form->{"paid_project_id_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{project_id};
203 $form->{paidaccounts}++;
210 if ($key eq "AR_tax" || $key eq "AP_tax") {
211 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
212 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
213 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
215 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
218 if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
220 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
222 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
225 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
227 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
229 $index = $form->{acc_trans}{$key}->[$i - 1]->{index};
230 $form->{"tax_$index"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
231 $totaltax += $form->{"tax_$index"};
235 $form->{"${akey}_$k"} =
237 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
239 if ($akey eq 'amount') {
241 $totalamount += $form->{"${akey}_$i"};
243 $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} =
244 "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
245 $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
246 $form->{"project_id_$k"} =
247 "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
249 $form->{"${key}_$i"} =
250 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
253 $form->{ARselected} = $form->{acc_trans}{$key}->[$i-1]->{accno};
255 } elsif ($akey eq "amount") {
256 $form->{"${key}_$k"} = $form->{acc_trans}{$key}->[$i-1]->{accno} .
257 "--" . $form->{acc_trans}{$key}->[$i-1]->{id};
258 $form->{"taxchart_$k"} = $form->{acc_trans}{$key}->[$i-1]->{id} .
259 "--" . $form->{acc_trans}{$key}->[$i-1]->{rate};
266 $form->{taxincluded} = $taxincluded if ($form->{id});
267 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
269 if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
271 # add tax to amounts and invtotal
272 for $i (1 .. $form->{rowcount}) {
274 ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
275 $tax = $form->round_amount($taxamount, 2);
276 $diff += ($taxamount - $tax);
277 $form->{"amount_$i"} += $form->{"tax_$i"};
279 $form->{amount_1} += $form->round_amount($diff, 2);
282 $taxamount = $form->round_amount($taxamount, 2);
283 $form->{tax} = $taxamount;
285 $form->{invtotal} = $totalamount + $totaltax;
288 ($form->datetonum($form->{transdate}, \%myconfig) <=
289 $form->datetonum($form->{closedto}, \%myconfig));
291 $lxdebug->leave_sub();
295 $lxdebug->enter_sub();
297 $title = $form->{title};
298 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
300 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
302 # $locale->text('Add Accounts Receivables Transaction')
303 # $locale->text('Edit Accounts Receivables Transaction')
304 $form->{javascript} = qq|<script type="text/javascript">
306 function setTaxkey(accno, row) {
307 var taxkey = accno.options[accno.selectedIndex].value;
308 var reg = /--([0-9]*)/;
309 var found = reg.exec(taxkey);
310 var index = found[1];
311 index = parseInt(index);
312 var tax = 'taxchart_' + row;
313 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
314 var reg2 = new RegExp("^"+ index, "");
315 if (reg2.exec(document.getElementById(tax).options[i].value)) {
316 document.getElementById(tax).options[i].selected = true;
323 # show history button js
324 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
325 #/show history button js
326 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
327 $readonly = ($form->{id}) ? "readonly" : "";
330 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
331 $readonly = ($form->{radier}) ? "" : $readonly;
333 # set option selected
334 foreach $item (qw(customer currency department employee)) {
335 $form->{"select$item"} =~ s/ selected//;
336 $form->{"select$item"} =~
337 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
341 $form->{exchangerate} =
342 $form->format_amount(\%myconfig, $form->{exchangerate});
344 $form->{creditlimit} =
345 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
346 $form->{creditremaining} =
347 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
350 <input type=hidden name=forex value=$form->{forex}>
352 if ($form->{currency} ne $form->{defaultcurrency}) {
353 if ($form->{forex}) {
355 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
356 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
360 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
361 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
368 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
369 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
373 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
377 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
381 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
382 <td colspan=3><select name=department>$form->{selectdepartment}</select>
383 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
386 | if $form->{selectdepartment};
388 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
391 ($form->{selectcustomer})
392 ? qq|<select name="customer"
393 onchange="document.getElementById('update_button').click();">$form->{
394 selectcustomer}</select>|
395 : qq|<input name=customer value="$form->{customer}" size=35>|;
398 <input type=hidden name=employee value="$form->{employee}">
401 if ($form->{selectemployee}) {
404 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
405 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
406 <input type=hidden name=selectemployee value="$form->{selectemployee}">
411 my @old_project_ids = ();
412 map({ push(@old_project_ids, $form->{"project_id_$_"})
413 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
415 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
417 "old_id" => \@old_project_ids },
418 "charts" => { "key" => "ALL_CHARTS",
419 "transdate" => $form->{transdate} },
420 "taxcharts" => "ALL_TAXCHARTS");
422 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
423 @{ $form->{ALL_CHARTS} });
425 my %project_labels = ();
426 my @project_values = ("");
427 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
428 push(@project_values, $item->{"id"});
429 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
432 my (%AR_amount_labels, @AR_amount_values);
433 my (%AR_labels, @AR_values);
434 my (%AR_paid_labels, @AR_paid_values);
438 foreach my $item (@{ $form->{ALL_CHARTS} }) {
439 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
440 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
441 my $key = "$item->{accno}--$item->{tax_id}";
442 push(@AR_amount_values, $key);
443 $AR_amount_labels{$key} =
444 "$item->{accno}--$item->{description}";
446 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
447 push(@AR_values, $item->{accno});
448 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
450 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
451 push(@AR_paid_values, $item->{accno});
452 $AR_paid_labels{$item->{accno}} =
453 "$item->{accno}--$item->{description}";
456 $charts{$item->{accno}} = $item;
459 my %taxchart_labels = ();
460 my @taxchart_values = ();
462 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
463 my $key = "$item->{id}--$item->{rate}";
464 $taxchart_init = $key if ($taxchart_init eq $item->{id});
465 push(@taxchart_values, $key);
466 $taxchart_labels{$key} =
467 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
468 $taxcharts{$item->{id}} = $item;
471 $form->{fokus} = "arledger.customer";
473 # use JavaScript Calendar or not
474 $form->{jsscript} = $jscalendar;
476 if ($form->{jsscript}) {
478 # with JavaScript Calendar
480 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
481 <td><input type=button name=transdate id="trigger1" value=|
482 . $locale->text('button') . qq|></td>
485 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
486 <td><input type=button name=duedate id="trigger2" value=|
487 . $locale->text('button') . qq|></td></td>
492 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
493 "duedate", "BL", "trigger2");
496 # without JavaScript Calendar
498 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
500 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
504 $onload = qq|focus()|;
505 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
506 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
508 <body onLoad="$onload">
510 <form method=post name="arledger" action=$form->{script}>
512 <input type=hidden name=id value=$form->{id}>
513 <input type=hidden name=sort value=$form->{sort}>
514 <input type=hidden name=closedto value=$form->{closedto}>
515 <input type=hidden name=locked value=$form->{locked}>
516 <input type=hidden name=title value="$title">
518 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
522 <th class=listtop>$form->{title}</th>
532 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
533 <td colspan=3>$customer</td>
534 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
535 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
536 <input type=hidden name=customer_id value="$form->{customer_id}">
537 <input type=hidden name=terms value=$form->{terms}>
544 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
545 <td>$form->{creditlimit}</td>
546 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
547 <td class="plus$n">$form->{creditremaining}</td>
548 <input type=hidden name=creditlimit value=$form->{creditlimit}>
549 <input type=hidden name=creditremaining value=$form->{creditremaining}>
555 <th align=right>| . $locale->text('Currency') . qq|</th>
556 <td><select name=currency>$form->{selectcurrency}</select></td>
557 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
558 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
559 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
560 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
571 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
572 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
575 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
576 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
579 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
583 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
594 <input type=hidden name=rowcount value=$form->{rowcount}>
598 <tr class=listheading>
599 <th class=listheading style="width:15%">|
600 . $locale->text('Account') . qq|</th>
601 <th class=listheading style="width:10%">|
602 . $locale->text('Amount') . qq|</th>
603 <th class=listheading style="width:10%">|
604 . $locale->text('Tax') . qq|</th>
605 <th class=listheading style="width:5%">|
606 . $locale->text('Korrektur') . qq|</th>
607 <th class=listheading style="width:10%">|
608 . $locale->text('Taxkey') . qq|</th>
609 <th class=listheading style="width:10%">|
610 . $locale->text('Project') . qq|</th>
614 $amount = $locale->text('Amount');
615 $project = $locale->text('Project');
617 for $i (1 .. $form->{rowcount}) {
620 $form->{"amount_$i"} =
621 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
622 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
624 my $selected_accno_full;
625 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
626 my $item = $charts{$accno_row};
627 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
629 my $selected_taxchart = $form->{"taxchart_$i"};
630 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
631 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
633 if ($previous_accno &&
634 ($previous_accno eq $selected_accno) &&
635 ($previous_tax_id ne $selected_tax_id)) {
636 my $item = $taxcharts{$selected_tax_id};
637 $selected_taxchart = "$item->{id}--$item->{rate}";
640 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
643 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
644 '-id' => "AR_amount_$i",
645 '-style' => 'width:400px',
646 '-onChange' => "setTaxkey(this, $i)",
647 '-values' => \@AR_amount_values,
648 '-labels' => \%AR_amount_labels,
649 '-default' => $selected_accno_full))
650 . $cgi->hidden('-name' => "previous_AR_amount_$i",
651 '-default' => $selected_accno_full);
654 NTI($cgi->popup_menu('-name' => "taxchart_$i",
655 '-id' => "taxchart_$i",
656 '-style' => 'width:200px',
657 '-values' => \@taxchart_values,
658 '-labels' => \%taxchart_labels,
659 '-default' => $selected_taxchart))
662 $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
665 NTI($cgi->popup_menu('-name' => "project_id_$i",
666 '-values' => \@project_values,
667 '-labels' => \%project_labels,
668 '-default' => $form->{"project_id_$i"} ));
672 <td>$selectAR_amount</td>
673 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
674 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
675 <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
677 <td>$projectnumber</td>
684 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
687 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
688 '-style' => 'width:400px',
689 '-values' => \@AR_values, '-labels' => \%AR_labels,
690 '-default' => $form->{ARselected}));
699 <td>${ARselected}</td>
700 <th align=left>$form->{invtotal}</th>
702 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
703 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
705 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
718 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
719 <td align=left>$notes</td>
727 <tr class=listheading>
728 <th colspan=7 class=listheading>|
729 . $locale->text('Incoming Payments') . qq|</th>
733 if ($form->{currency} eq $form->{defaultcurrency}) {
734 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
736 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
739 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
740 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
741 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
742 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
743 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
744 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
745 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
750 map { print "$column_data{$_}\n" } @column_index;
756 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
757 for $i (1 .. $form->{paidaccounts}) {
763 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
764 '-id' => "AR_paid_$i",
765 '-values' => \@AR_paid_values,
766 '-labels' => \%AR_paid_labels,
767 '-default' => $form->{"AR_paid_$i"}));
770 if ($form->{"paid_$i"}) {
772 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
774 $form->{"exchangerate_$i"} =
775 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
777 $exchangerate = qq| |;
778 if ($form->{currency} ne $form->{defaultcurrency}) {
779 if ($form->{"forex_$i"}) {
781 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
784 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
789 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
793 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
794 $column_data{AR_paid} =
795 qq|<td align=center>${selectAR_paid}</td>|;
796 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
797 $column_data{datepaid} =
798 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
799 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
800 $column_data{source} =
801 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
803 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
805 $column_data{paid_project_id} =
807 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
808 '-values' => \@project_values,
809 '-labels' => \%project_labels,
810 '-default' => $form->{"paid_project_id_$i"} ))
813 map { print qq|$column_data{$_}\n| } @column_index;
818 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
821 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
823 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
829 <td><hr size=3 noshade></td>
834 $lxdebug->leave_sub();
838 $lxdebug->enter_sub();
842 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
844 <input name=callback type=hidden value="$form->{callback}">
846 <input type=hidden name=login value=$form->{login}>
847 <input type=hidden name=password value=$form->{password}>
849 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
850 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
856 if (!$form->{id} && $form->{draft_id}) {
857 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
858 '-value' => 1, '-checked' => $form->{remove_draft},
860 qq| <label for="remove_draft">| .
861 $locale->text("Remove draft when posting") .
865 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
866 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
868 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
869 . $locale->text('Update') . qq|">
872 if ($form->{radier}) {
874 <input class=submit type=submit name=action value="|
875 . $locale->text('Post') . qq|">
876 <input class=submit type=submit name=action value="|
877 . $locale->text('Delete') . qq|">
880 if ($transdate > $closedto) {
882 <input class=submit type=submit name=action value="|
883 . $locale->text('Use As Template') . qq|">
887 <input class=submit type=submit name=action value="|
888 . $locale->text('Post Payment') . qq|">
892 if ($transdate > $closedto) {
893 print qq|<input class=submit type=submit name=action value="|
894 . $locale->text('Post') . qq|"> | .
895 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
896 '-class' => 'submit'));
900 if ($form->{menubar}) {
901 require "bin/mozilla/menu.pl";
904 # button for saving history
905 if($form->{id} ne "") {
907 <input type=button class=submit onclick=set_history_window(|
909 . qq|); name=history id=history value=|
910 . $locale->text('history')
913 # /button for saving history
921 $lxdebug->leave_sub();
925 $lxdebug->enter_sub();
929 $form->{invtotal} = 0;
931 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
932 qw(exchangerate creditlimit creditremaining);
934 @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
938 for $i (1 .. $form->{rowcount}) {
939 $form->{"amount_$i"} =
940 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
941 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
942 if ($form->{"amount_$i"}) {
945 if (!$form->{"korrektur_$i"}) {
946 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
948 if ($form->{taxincluded}) {
949 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
951 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
954 $form->{"tax_$i"} = 0;
957 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
959 $totaltax += $form->{"tax_$i"};
960 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
965 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
966 $form->{rowcount} = $count + 1;
967 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
969 $form->{exchangerate} = $exchangerate
973 $form->check_exchangerate(
974 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
977 $form->{invdate} = $form->{transdate};
978 $save_AR = $form->{AR};
979 &check_name(customer);
980 $form->{AR} = $save_AR;
983 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
985 for $i (1 .. $form->{paidaccounts}) {
986 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
989 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
990 } qw(paid exchangerate);
992 $totalpaid += $form->{"paid_$i"};
994 $form->{"exchangerate_$i"} = $exchangerate
996 $form->{"forex_$i"} = (
998 $form->check_exchangerate(
999 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
1004 $form->{creditremaining} -=
1005 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
1006 $form->{oldinvtotal});
1007 $form->{oldinvtotal} = $form->{invtotal};
1008 $form->{oldtotalpaid} = $totalpaid;
1012 $lxdebug->leave_sub();
1016 $lxdebug->enter_sub();
1017 for $i (1 .. $form->{paidaccounts}) {
1018 if ($form->{"paid_$i"}) {
1019 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1021 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1023 $form->error($locale->text('Cannot post payment for a closed period!'))
1024 if ($datepaid <= $closedto);
1026 if ($form->{currency} ne $form->{defaultcurrency}) {
1027 $form->{"exchangerate_$i"} = $form->{exchangerate}
1028 if ($invdate == $datepaid);
1029 $form->isblank("exchangerate_$i",
1030 $locale->text('Exchangerate for payment missing!'));
1035 ($form->{AR}) = split /--/, $form->{AR};
1036 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1037 $form->redirect($locale->text(' Payment posted!'))
1038 if (AR->post_payment(\%myconfig, \%$form));
1039 $form->error($locale->text('Cannot post payment!'));
1042 $lxdebug->leave_sub();
1046 $lxdebug->enter_sub();
1048 # check if there is an invoice number, invoice and due date
1049 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
1050 $form->isblank("duedate", $locale->text('Due Date missing!'));
1051 $form->isblank("customer", $locale->text('Customer missing!'));
1053 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1054 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1056 $form->error($locale->text('Cannot post transaction for a closed period!'))
1057 if ($transdate <= $closedto);
1059 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1060 if ($form->{currency} ne $form->{defaultcurrency});
1062 delete($form->{AR});
1064 for $i (1 .. $form->{paidaccounts}) {
1065 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1066 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1068 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1070 $form->error($locale->text('Cannot post payment for a closed period!'))
1071 if ($datepaid <= $closedto);
1073 if ($form->{currency} ne $form->{defaultcurrency}) {
1074 $form->{"exchangerate_$i"} = $form->{exchangerate}
1075 if ($transdate == $datepaid);
1076 $form->isblank("exchangerate_$i",
1077 $locale->text('Exchangerate for payment missing!'));
1082 # if oldcustomer ne customer redo form
1083 ($customer) = split /--/, $form->{customer};
1084 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1089 $form->{AR}{receivables} = $form->{ARselected};
1091 $form->{id} = 0 if $form->{postasnew};
1092 if (AR->post_transaction(\%myconfig, \%$form)) {
1093 # saving the history
1094 if(!exists $form->{addition} && $form->{id} ne "") {
1095 $form->{snumbers} = qq|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};
1101 $form->redirect($locale->text('Transaction posted!'));
1103 $form->error($locale->text('Cannot post transaction!'));
1105 $lxdebug->leave_sub();
1109 $lxdebug->enter_sub();
1111 $form->{postasnew} = 1;
1112 # saving the history
1113 if(!exists $form->{addition} && $form->{id} ne "") {
1114 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1115 $form->{addition} = "POSTED AS NEW";
1116 $form->save_history($form->dbconnect(\%myconfig));
1118 # /saving the history
1121 $lxdebug->leave_sub();
1124 sub use_as_template {
1125 $lxdebug->enter_sub();
1127 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);
1128 $form->{paidaccounts} = 1;
1129 $form->{rowcount}--;
1130 $form->{invdate} = $form->current_date(\%myconfig);
1133 $lxdebug->leave_sub();
1137 $lxdebug->enter_sub();
1139 $form->{title} = $locale->text('Confirm!');
1143 delete $form->{header};
1148 <form method=post action=$form->{script}>
1151 foreach $key (keys %$form) {
1152 $form->{$key} =~ s/\"/"/g;
1153 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1157 <h2 class=confirm>$form->{title}</h2>
1160 . $locale->text('Are you sure you want to delete Transaction')
1161 . qq| $form->{invnumber}</h4>
1163 <input name=action class=submit type=submit value="|
1164 . $locale->text('Yes') . qq|">
1171 $lxdebug->leave_sub();
1175 $lxdebug->enter_sub();
1176 if (AR->delete_transaction(\%myconfig, \%$form, $spool)) {
1177 # saving the history
1178 if(!exists $form->{addition}) {
1179 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1180 $form->{addition} = "DELETED";
1181 $form->save_history($form->dbconnect(\%myconfig));
1183 # /saving the history
1184 $form->redirect($locale->text('Transaction deleted!'));
1186 $form->error($locale->text('Cannot delete transaction!'));
1188 $lxdebug->leave_sub();
1192 $lxdebug->enter_sub();
1194 # setup customer selection
1195 $form->all_vc(\%myconfig, "customer", "AR");
1197 if (@{ $form->{all_customer} }) {
1198 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1199 @{ $form->{all_customer} };
1200 $customer = qq|<select name=customer><option>\n$customer</select>|;
1202 $customer = qq|<input name=customer size=35>|;
1206 if (@{ $form->{all_departments} }) {
1207 $form->{selectdepartment} = "<option>\n";
1210 $form->{selectdepartment} .=
1211 "<option>$_->{description}--$_->{id}\n"
1212 } (@{ $form->{all_departments} });
1217 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1218 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1220 | if $form->{selectdepartment};
1222 $form->{title} = $locale->text('AR Transactions');
1224 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1226 # use JavaScript Calendar or not
1227 $form->{jsscript} = $jscalendar;
1229 if ($form->{jsscript}) {
1231 # with JavaScript Calendar
1233 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1234 <input type=button name=transdatefrom id="trigger1" value=|
1235 . $locale->text('button') . qq|></td>
1238 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1239 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1240 . $locale->text('button') . qq|></td>
1245 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1246 "transdateto", "BL", "trigger2");
1249 # without JavaScript Calendar
1251 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1253 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1256 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1261 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1262 push(@values, $item->{"id"});
1263 $labels{$item->{"id"}} = $item->{"projectnumber"};
1266 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1267 '-labels' => \%labels));
1269 $form->{fokus} = "search.customer";
1271 $onload = qq|focus()|;
1272 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1273 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1275 <body onLoad="$onload">
1277 <form method=post name="search" action=$form->{script}>
1280 <tr><th class=listtop>$form->{title}</th></tr>
1281 <tr height="5"></tr>
1286 <th align=right>| . $locale->text('Customer') . qq|</th>
1287 <td colspan=3>$customer</td>
1291 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1292 <td colspan=3><input name=invnumber size=20></td>
1295 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1296 <td colspan=3><input name=ordnumber size=20></td>
1299 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1300 <td colspan=3><input name=notes size=40></td>
1303 <th align="right">| . $locale->text("Project Number") . qq|</th>
1304 <td colspan="3">$projectnumber</td>
1307 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1309 <th align=right>| . $locale->text('Bis') . qq|</th>
1312 <input type=hidden name=sort value=transdate>
1320 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1324 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1325 <td nowrap>| . $locale->text('Open') . qq|</td>
1326 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1327 <td nowrap>| . $locale->text('Closed') . qq|</td>
1330 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1331 <td nowrap>| . $locale->text('ID') . qq|</td>
1332 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1333 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1334 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1335 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1336 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1337 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1340 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1341 <td nowrap>| . $locale->text('Customer') . qq|</td>
1342 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1343 <td nowrap>| . $locale->text('Amount') . qq|</td>
1344 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1345 <td nowrap>| . $locale->text('Tax') . qq|</td>
1346 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1347 <td nowrap>| . $locale->text('Total') . qq|</td>
1350 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1351 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1352 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1353 <td nowrap>| . $locale->text('Paid') . qq|</td>
1354 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1355 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1356 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1357 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1360 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1361 <td nowrap>| . $locale->text('Notes') . qq|</td>
1362 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1363 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1364 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1365 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1366 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1367 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1370 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1371 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1372 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1373 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1382 <td><hr size=3 noshade></td>
1386 <input type=hidden name=nextsub value=$form->{nextsub}>
1388 <input type=hidden name=login value=$form->{login}>
1389 <input type=hidden name=password value=$form->{password}>
1392 <input class=submit type=submit name=action value="|
1393 . $locale->text('Continue') . qq|">
1404 $lxdebug->leave_sub();
1407 sub ar_transactions {
1408 $lxdebug->enter_sub();
1410 $form->{customer} = $form->unescape($form->{customer});
1411 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1413 AR->ar_transactions(\%myconfig, \%$form);
1416 "$form->{script}?action=ar_transactions&login=$form->{login}&password=$form->{password}";
1419 if ($form->{customer}) {
1420 $callback .= "&customer=" . $form->escape($form->{customer}, 1);
1421 $href .= "&customer=" . $form->escape($form->{customer});
1422 $option = $locale->text('Customer') . " : $form->{customer}";
1424 if ($form->{department}) {
1425 $callback .= "&department=" . $form->escape($form->{department}, 1);
1426 $href .= "&department=" . $form->escape($form->{department});
1427 ($department) = split /--/, $form->{department};
1428 $option .= "\n<br>" if ($option);
1429 $option .= $locale->text('Department') . " : $department";
1431 if ($form->{invnumber}) {
1432 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1433 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1434 $option .= "\n<br>" if ($option);
1435 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1437 if ($form->{ordnumber}) {
1438 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1439 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1440 $option .= "\n<br>" if ($option);
1441 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1443 if ($form->{notes}) {
1444 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1445 $href .= "¬es=" . $form->escape($form->{notes});
1446 $option .= "\n<br>" if $option;
1447 $option .= $locale->text('Notes') . " : $form->{notes}";
1450 if ($form->{transdatefrom}) {
1451 $callback .= "&transdatefrom=$form->{transdatefrom}";
1452 $href .= "&transdatefrom=$form->{transdatefrom}";
1453 $option .= "\n<br>" if ($option);
1455 $locale->text('From') . " "
1456 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1458 if ($form->{transdateto}) {
1459 $callback .= "&transdateto=$form->{transdateto}";
1460 $href .= "&transdateto=$form->{transdateto}";
1461 $option .= "\n<br>" if ($option);
1463 $locale->text('Bis') . " "
1464 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1466 if ($form->{open}) {
1467 $callback .= "&open=$form->{open}";
1468 $href .= "&open=$form->{open}";
1469 $option .= "\n<br>" if ($option);
1470 $option .= $locale->text('Open');
1472 if ($form->{closed}) {
1473 $callback .= "&closed=$form->{closed}";
1474 $href .= "&closed=$form->{closed}";
1475 $option .= "\n<br>" if ($option);
1476 $option .= $locale->text('Closed');
1478 if ($form->{globalproject_id}) {
1479 $callback .= "&globalproject_id=" . E($form->{globalproject_id});
1480 $href .= "&globalproject_id=" . E($form->{globalproject_id});
1484 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1485 datepaid due duedate notes employee shippingpoint shipvia
1486 globalprojectnumber);
1488 $form->{"l_type"} = "Y";
1490 foreach $item (@columns) {
1491 if ($form->{"l_$item"} eq "Y") {
1492 push @column_index, $item;
1494 # add column to href and callback
1495 $callback .= "&l_$item=Y";
1496 $href .= "&l_$item=Y";
1500 if ($form->{l_subtotal} eq 'Y') {
1501 $callback .= "&l_subtotal=Y";
1502 $href .= "&l_subtotal=Y";
1505 $column_header{id} =
1506 "<th><a class=listheading href=$href&sort=id>"
1507 . $locale->text('ID')
1509 $column_header{transdate} =
1510 "<th><a class=listheading href=$href&sort=transdate>"
1511 . $locale->text('Date')
1513 $column_header{duedate} =
1514 "<th><a class=listheading href=$href&sort=duedate>"
1515 . $locale->text('Due Date')
1517 $column_header{type} =
1518 "<th class=\"listheading\">" . $locale->text('Type') . "</th>";
1519 $column_header{invnumber} =
1520 "<th><a class=listheading href=$href&sort=invnumber>"
1521 . $locale->text('Invoice')
1523 $column_header{ordnumber} =
1524 "<th><a class=listheading href=$href&sort=ordnumber>"
1525 . $locale->text('Order')
1527 $column_header{name} =
1528 "<th><a class=listheading href=$href&sort=name>"
1529 . $locale->text('Customer')
1531 $column_header{netamount} =
1532 "<th class=listheading>" . $locale->text('Amount') . "</th>";
1533 $column_header{tax} =
1534 "<th class=listheading>" . $locale->text('Tax') . "</th>";
1535 $column_header{amount} =
1536 "<th class=listheading>" . $locale->text('Total') . "</th>";
1537 $column_header{paid} =
1538 "<th class=listheading>" . $locale->text('Paid') . "</th>";
1539 $column_header{datepaid} =
1540 "<th><a class=listheading href=$href&sort=datepaid>"
1541 . $locale->text('Date Paid')
1543 $column_header{due} =
1544 "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
1545 $column_header{notes} =
1546 "<th class=listheading>" . $locale->text('Notes') . "</th>";
1547 $column_header{employee} =
1548 "<th><a class=listheading href=$href&sort=employee>"
1549 . $locale->text('Salesperson') . "</th>";
1551 $column_header{shippingpoint} =
1552 "<th><a class=listheading href=$href&sort=shippingpoint>"
1553 . $locale->text('Shipping Point')
1555 $column_header{shipvia} =
1556 "<th><a class=listheading href=$href&sort=shipvia>"
1557 . $locale->text('Ship via')
1559 $column_header{globalprojectnumber} =
1560 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1562 $form->{title} = $locale->text('AR Transactions');
1571 <th class=listtop>$form->{title}</th>
1573 <tr height="5"></tr>
1580 <tr class=listheading>
1583 map { print "\n$column_header{$_}" } @column_index;
1589 # add sort and escape callback, this one we use for the add sub
1590 $form->{callback} = $callback .= "&sort=$form->{sort}";
1592 # escape callback for href
1593 $callback = $form->escape($callback);
1595 if (@{ $form->{AR} }) {
1596 $sameitem = $form->{AR}->[0]->{ $form->{sort} };
1599 # sums and tax on reports by Antonio Gallardo
1601 foreach $ar (@{ $form->{AR} }) {
1603 if ($form->{l_subtotal} eq 'Y') {
1604 if ($sameitem ne $ar->{ $form->{sort} }) {
1609 $column_data{netamount} =
1611 . $form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")
1613 $column_data{tax} = "<td align=right>"
1614 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount},
1617 $column_data{amount} =
1619 . $form->format_amount(\%myconfig, $ar->{amount}, 2, " ") . "</td>";
1620 $column_data{paid} =
1622 . $form->format_amount(\%myconfig, $ar->{paid}, 2, " ") . "</td>";
1623 $column_data{due} = "<td align=right>"
1624 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid},
1628 $subtotalnetamount += $ar->{netamount};
1629 $subtotalamount += $ar->{amount};
1630 $subtotalpaid += $ar->{paid};
1631 $subtotaldue += $ar->{amount} - $ar->{paid};
1633 $totalnetamount += $ar->{netamount};
1634 $totalamount += $ar->{amount};
1635 $totalpaid += $ar->{paid};
1636 $totaldue += ($ar->{amount} - $ar->{paid});
1638 $column_data{transdate} = "<td>$ar->{transdate} </td>";
1639 $column_data{id} = "<td>$ar->{id}</td>";
1640 $column_data{datepaid} = "<td>$ar->{datepaid} </td>";
1641 $column_data{duedate} = "<td>$ar->{duedate} </td>";
1643 $module = ($ar->{invoice}) ? "is.pl" : $form->{script};
1645 $column_data{invnumber} =
1646 "<td><a href=$module?action=edit&id=$ar->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}</a></td>";
1647 $column_data{type} = "<td>" .
1648 ($ar->{storno} ? $locale->text("Storno (one letter abbreviation)") :
1649 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1650 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1651 $locale->text("AR Transaction (abbreviation)"))
1653 $column_data{ordnumber} = "<td>$ar->{ordnumber} </td>";
1654 $column_data{name} = "<td>$ar->{name}</td>";
1655 $ar->{notes} =~ s/\r\n/<br>/g;
1656 $column_data{notes} = "<td>$ar->{notes} </td>";
1657 $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>";
1658 $column_data{shipvia} = "<td>$ar->{shipvia} </td>";
1659 $column_data{employee} = "<td>$ar->{employee} </td>";
1660 $column_data{globalprojectnumber} =
1661 "<td>" . H($ar->{globalprojectnumber}) . "</td>";
1666 <tr class=listrow$i>
1669 map { print "\n$column_data{$_}" } @column_index;
1677 if ($form->{l_subtotal} eq 'Y') {
1683 <tr class=listtotal>
1686 map { $column_data{$_} = "<td> </td>" } @column_index;
1688 $column_data{netamount} =
1689 "<th class=listtotal align=right>"
1690 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1691 $column_data{tax} = "<th class=listtotal align=right>"
1692 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1695 $column_data{amount} =
1696 "<th class=listtotal align=right>"
1697 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1698 $column_data{paid} =
1699 "<th class=listtotal align=right>"
1700 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1702 "<th class=listtotal align=right>"
1703 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1705 map { print "\n$column_data{$_}" } @column_index;
1713 <td><hr size=3 noshade></td>
1718 <form method=post action=$form->{script}>
1720 <input name=callback type=hidden value="$form->{callback}">
1722 <input type=hidden name=login value=$form->{login}>
1723 <input type=hidden name=password value=$form->{password}>
1725 <input class=submit type=submit name=action value="|
1726 . $locale->text('AR Transaction') . qq|">
1727 <input class=submit type=submit name=action value="|
1728 . $locale->text('Sales Invoice') . qq|">
1736 $lxdebug->leave_sub();
1740 $lxdebug->enter_sub();
1742 map { $column_data{$_} = "<td> </td>" } @column_index;
1744 $column_data{tax} = "<th class=listsubtotal align=right>"
1745 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1748 $column_data{amount} =
1749 "<th class=listsubtotal align=right>"
1750 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1751 $column_data{paid} =
1752 "<th class=listsubtotal align=right>"
1753 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1755 "<th class=listsubtotal align=right>"
1756 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1758 $subtotalnetamount = 0;
1759 $subtotalamount = 0;
1763 $sameitem = $ar->{ $form->{sort} };
1765 print "<tr class=listsubtotal>";
1767 map { print "\n$column_data{$_}" } @column_index;
1773 $lxdebug->leave_sub();