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";
180 AR->setup_form($form);
183 ($form->datetonum($form->{transdate}, \%myconfig) <=
184 $form->datetonum($form->{closedto}, \%myconfig));
186 $lxdebug->leave_sub();
190 $lxdebug->enter_sub();
192 $title = $form->{title};
193 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
195 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
197 # $locale->text('Add Accounts Receivables Transaction')
198 # $locale->text('Edit Accounts Receivables Transaction')
199 $form->{javascript} = qq|<script type="text/javascript">
201 function setTaxkey(accno, row) {
202 var taxkey = accno.options[accno.selectedIndex].value;
203 var reg = /--([0-9]*)/;
204 var found = reg.exec(taxkey);
205 var index = found[1];
206 index = parseInt(index);
207 var tax = 'taxchart_' + row;
208 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
209 var reg2 = new RegExp("^"+ index, "");
210 if (reg2.exec(document.getElementById(tax).options[i].value)) {
211 document.getElementById(tax).options[i].selected = true;
218 # show history button js
219 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
220 #/show history button js
221 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
222 $readonly = ($form->{id}) ? "readonly" : "";
225 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
226 $readonly = ($form->{radier}) ? "" : $readonly;
228 # set option selected
229 foreach $item (qw(customer currency department employee)) {
230 $form->{"select$item"} =~ s/ selected//;
231 $form->{"select$item"} =~
232 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
235 $form->{exchangerate} = $exchangerate
239 $form->check_exchangerate(
240 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
244 $form->{exchangerate} =
245 $form->format_amount(\%myconfig, $form->{exchangerate});
247 if ($form->{exchangerate} == 0) {
248 $form->{exchangerate} = "";
251 $form->{creditlimit} =
252 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
253 $form->{creditremaining} =
254 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
257 <input type=hidden name=forex value=$form->{forex}>
259 if ($form->{currency} ne $form->{defaultcurrency}) {
260 if ($form->{forex}) {
262 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
263 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
267 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
268 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
275 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
276 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
280 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
284 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
288 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
289 <td colspan=3><select name=department>$form->{selectdepartment}</select>
290 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
293 | if $form->{selectdepartment};
295 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
298 ($form->{selectcustomer})
299 ? qq|<select name="customer"
300 onchange="document.getElementById('update_button').click();">$form->{
301 selectcustomer}</select>|
302 : qq|<input name=customer value="$form->{customer}" size=35>|;
305 <input type=hidden name=employee value="$form->{employee}">
308 if ($form->{selectemployee}) {
311 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
312 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
313 <input type=hidden name=selectemployee value="$form->{selectemployee}">
318 my @old_project_ids = ();
319 map({ push(@old_project_ids, $form->{"project_id_$_"})
320 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
322 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
324 "old_id" => \@old_project_ids },
325 "charts" => { "key" => "ALL_CHARTS",
326 "transdate" => $form->{transdate} },
327 "taxcharts" => "ALL_TAXCHARTS");
329 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
330 @{ $form->{ALL_CHARTS} });
332 my %project_labels = ();
333 my @project_values = ("");
334 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
335 push(@project_values, $item->{"id"});
336 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
339 my (%AR_amount_labels, @AR_amount_values);
340 my (%AR_labels, @AR_values);
341 my (%AR_paid_labels, @AR_paid_values);
345 foreach my $item (@{ $form->{ALL_CHARTS} }) {
346 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
347 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
348 my $key = "$item->{accno}--$item->{tax_id}";
349 push(@AR_amount_values, $key);
350 $AR_amount_labels{$key} =
351 "$item->{accno}--$item->{description}";
353 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
354 push(@AR_values, $item->{accno});
355 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
357 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
358 push(@AR_paid_values, $item->{accno});
359 $AR_paid_labels{$item->{accno}} =
360 "$item->{accno}--$item->{description}";
363 $charts{$item->{accno}} = $item;
366 my %taxchart_labels = ();
367 my @taxchart_values = ();
369 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
370 my $key = "$item->{id}--$item->{rate}";
371 $taxchart_init = $key if ($taxchart_init eq $item->{id});
372 push(@taxchart_values, $key);
373 $taxchart_labels{$key} =
374 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
375 $taxcharts{$item->{id}} = $item;
378 $form->{fokus} = "arledger.customer";
380 # use JavaScript Calendar or not
381 $form->{jsscript} = 1;
383 if ($form->{jsscript}) {
385 # with JavaScript Calendar
387 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
388 <td><input type=button name=transdate id="trigger1" value=|
389 . $locale->text('button') . qq|></td>
392 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
393 <td><input type=button name=duedate id="trigger2" value=|
394 . $locale->text('button') . qq|></td></td>
399 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
400 "duedate", "BL", "trigger2");
403 # without JavaScript Calendar
405 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
407 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
410 $form->{javascript} .=
411 qq|<script type="text/javascript" src="js/common.js"></script>| .
412 qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
415 $onload = qq|focus()|;
416 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
417 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
419 <body onLoad="$onload">
421 <form method=post name="arledger" action=$form->{script}>
423 <input type=hidden name=id value=$form->{id}>
424 <input type=hidden name=sort value=$form->{sort}>
425 <input type=hidden name=closedto value=$form->{closedto}>
426 <input type=hidden name=locked value=$form->{locked}>
427 <input type=hidden name=title value="$title">
429 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
433 <th class=listtop>$form->{title}</th>
443 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
444 <td colspan=3>$customer <input type="button" value="?" onclick="show_vc_details('customer')"></td>
445 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
446 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
447 <input type=hidden name=customer_id value="$form->{customer_id}">
448 <input type=hidden name=terms value=$form->{terms}>
455 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
456 <td>$form->{creditlimit}</td>
457 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
458 <td class="plus$n">$form->{creditremaining}</td>
459 <input type=hidden name=creditlimit value=$form->{creditlimit}>
460 <input type=hidden name=creditremaining value=$form->{creditremaining}>
466 <th align=right>| . $locale->text('Currency') . qq|</th>
467 <td><select name=currency>$form->{selectcurrency}</select></td>
468 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
469 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
470 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
471 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
482 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
483 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
486 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
487 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
490 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
494 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
505 <input type=hidden name=rowcount value=$form->{rowcount}>
509 <tr class=listheading>
510 <th class=listheading style="width:15%">|
511 . $locale->text('Account') . qq|</th>
512 <th class=listheading style="width:10%">|
513 . $locale->text('Amount') . qq|</th>
514 <th class=listheading style="width:10%">|
515 . $locale->text('Tax') . qq|</th>
516 <th class=listheading style="width:5%">|
517 . $locale->text('Korrektur') . qq|</th>
518 <th class=listheading style="width:10%">|
519 . $locale->text('Taxkey') . qq|</th>
520 <th class=listheading style="width:10%">|
521 . $locale->text('Project') . qq|</th>
525 $amount = $locale->text('Amount');
526 $project = $locale->text('Project');
528 for $i (1 .. $form->{rowcount}) {
531 $form->{"amount_$i"} =
532 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
533 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
535 my $selected_accno_full;
536 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
537 my $item = $charts{$accno_row};
538 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
540 my $selected_taxchart = $form->{"taxchart_$i"};
541 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
542 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
544 if ($previous_accno &&
545 ($previous_accno eq $selected_accno) &&
546 ($previous_tax_id ne $selected_tax_id)) {
547 my $item = $taxcharts{$selected_tax_id};
548 $selected_taxchart = "$item->{id}--$item->{rate}";
551 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
554 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
555 '-id' => "AR_amount_$i",
556 '-style' => 'width:400px',
557 '-onChange' => "setTaxkey(this, $i)",
558 '-values' => \@AR_amount_values,
559 '-labels' => \%AR_amount_labels,
560 '-default' => $selected_accno_full))
561 . $cgi->hidden('-name' => "previous_AR_amount_$i",
562 '-default' => $selected_accno_full);
565 NTI($cgi->popup_menu('-name' => "taxchart_$i",
566 '-id' => "taxchart_$i",
567 '-style' => 'width:200px',
568 '-values' => \@taxchart_values,
569 '-labels' => \%taxchart_labels,
570 '-default' => $selected_taxchart))
573 $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
576 NTI($cgi->popup_menu('-name' => "project_id_$i",
577 '-values' => \@project_values,
578 '-labels' => \%project_labels,
579 '-default' => $form->{"project_id_$i"} ));
583 <td>$selectAR_amount</td>
584 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
585 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
586 <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
588 <td>$projectnumber</td>
595 $form->{invtotal_unformatted} = $form->{invtotal};
596 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
599 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
600 '-style' => 'width:400px',
601 '-values' => \@AR_values, '-labels' => \%AR_labels,
602 '-default' => $form->{ARselected}));
611 <td>${ARselected}</td>
612 <th align=left>$form->{invtotal}</th>
614 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
615 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
617 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
630 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
631 <td align=left>$notes</td>
639 <tr class=listheading>
640 <th colspan=7 class=listheading>|
641 . $locale->text('Incoming Payments') . qq|</th>
645 if ($form->{currency} eq $form->{defaultcurrency}) {
646 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
648 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
651 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
652 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
653 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
654 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
655 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
656 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
657 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
662 map { print "$column_data{$_}\n" } @column_index;
670 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
671 for $i (1 .. $form->{paidaccounts}) {
677 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
678 '-id' => "AR_paid_$i",
679 '-values' => \@AR_paid_values,
680 '-labels' => \%AR_paid_labels,
681 '-default' => $form->{"AR_paid_$i"}));
683 $totalpaid += $form->{"paid_$i"};
686 if ($form->{"paid_$i"}) {
688 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
690 $form->{"exchangerate_$i"} =
691 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
693 if ($form->{"exchangerate_$i"} == 0) {
694 $form->{"exchangerate_$i"} = "";
697 $exchangerate = qq| |;
698 if ($form->{currency} ne $form->{defaultcurrency}) {
699 if ($form->{"forex_$i"}) {
701 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
704 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
709 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
713 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
714 $column_data{AR_paid} =
715 qq|<td align=center>${selectAR_paid}</td>|;
716 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
717 $column_data{datepaid} =
718 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
719 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
720 $column_data{source} =
721 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
723 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
725 $column_data{paid_project_id} =
727 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
728 '-values' => \@project_values,
729 '-labels' => \%project_labels,
730 '-default' => $form->{"paid_project_id_$i"} ))
733 map { print qq|$column_data{$_}\n| } @column_index;
738 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
741 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
747 <td align="center">| . $locale->text('Total') . qq|</td>
748 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
753 <td align="center">| . $locale->text('Missing amount') . qq|</td>
754 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
756 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
758 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
764 <td><hr size=3 noshade></td>
769 $lxdebug->leave_sub();
773 $lxdebug->enter_sub();
777 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
779 <input name=callback type=hidden value="$form->{callback}">
781 <input type=hidden name=login value=$form->{login}>
782 <input type=hidden name=password value=$form->{password}>
784 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
785 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
791 if (!$form->{id} && $form->{draft_id}) {
792 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
793 '-value' => 1, '-checked' => $form->{remove_draft},
795 qq| <label for="remove_draft">| .
796 $locale->text("Remove draft when posting") .
800 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
801 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
803 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
805 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
806 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|
807 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && !$form->{paid_1});
810 if ($form->{radier}) {
812 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
813 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
815 if ($transdate > $closedto) {
817 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
820 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|"> |;
823 if ($transdate > $closedto) {
824 print qq|<input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
825 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
829 if ($form->{menubar}) {
830 require "bin/mozilla/menu.pl";
833 # button for saving history
834 if($form->{id} ne "") {
835 print qq|<input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|>|;
837 # /button for saving history
838 # mark_as_paid button
839 if($form->{id} ne "") {
840 print qq|<input type="submit" class="submit" name="action" value="|
841 . $locale->text('mark as paid') . qq|">|;
843 # /mark_as_paid button
852 $lxdebug->leave_sub();
856 $lxdebug->enter_sub();
857 &mark_as_paid_common(\%myconfig,"ar");
858 $lxdebug->leave_sub();
862 $lxdebug->enter_sub();
866 $form->{invtotal} = 0;
868 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
869 qw(exchangerate creditlimit creditremaining);
871 @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
875 for $i (1 .. $form->{rowcount}) {
876 $form->{"amount_$i"} =
877 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
878 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
879 if ($form->{"amount_$i"}) {
882 if (!$form->{"korrektur_$i"}) {
883 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
885 if ($form->{taxincluded}) {
886 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
888 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
891 $form->{"tax_$i"} = 0;
894 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
896 $totaltax += $form->{"tax_$i"};
897 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
902 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
903 $form->{rowcount} = $count + 1;
904 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
906 $form->{exchangerate} = $exchangerate
910 $form->check_exchangerate(
911 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
914 $form->{invdate} = $form->{transdate};
915 $save_AR = $form->{AR};
916 &check_name(customer);
917 $form->{AR} = $save_AR;
920 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
922 for $i (1 .. $form->{paidaccounts}) {
923 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
926 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
927 } qw(paid exchangerate);
929 $totalpaid += $form->{"paid_$i"};
931 $form->{"exchangerate_$i"} = $exchangerate
933 $form->{"forex_$i"} = (
935 $form->check_exchangerate(
936 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
941 $form->{creditremaining} -=
942 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
943 $form->{oldinvtotal});
944 $form->{oldinvtotal} = $form->{invtotal};
945 $form->{oldtotalpaid} = $totalpaid;
949 $lxdebug->leave_sub();
953 $lxdebug->enter_sub();
955 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
957 for $i (1 .. $form->{paidaccounts}) {
958 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
959 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
961 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
963 $form->error($locale->text('Cannot post payment for a closed period!'))
964 if ($datepaid <= $closedto);
966 if ($form->{currency} ne $form->{defaultcurrency}) {
967 $form->{"exchangerate_$i"} = $form->{exchangerate}
968 if ($invdate == $datepaid);
969 $form->isblank("exchangerate_$i",
970 $locale->text('Exchangerate for payment missing!'));
975 ($form->{AR}) = split /--/, $form->{AR};
976 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
977 $form->redirect($locale->text('Payment posted!'))
978 if (AR->post_payment(\%myconfig, \%$form));
979 $form->error($locale->text('Cannot post payment!'));
982 $lxdebug->leave_sub();
986 $lxdebug->enter_sub();
988 # check if there is an invoice number, invoice and due date
989 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
990 $form->isblank("duedate", $locale->text('Due Date missing!'));
991 $form->isblank("customer", $locale->text('Customer missing!'));
993 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
994 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
995 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
997 $form->error($locale->text('Zero amount posting!'))
998 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
1000 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1001 if ($form->{currency} ne $form->{defaultcurrency});
1003 delete($form->{AR});
1005 for $i (1 .. $form->{paidaccounts}) {
1006 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1007 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1009 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1011 $form->error($locale->text('Cannot post payment for a closed period!'))
1012 if ($datepaid <= $closedto);
1014 if ($form->{currency} ne $form->{defaultcurrency}) {
1015 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
1016 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1021 # if oldcustomer ne customer redo form
1022 ($customer) = split /--/, $form->{customer};
1023 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1028 $form->{AR}{receivables} = $form->{ARselected};
1029 $form->{storno} = 0;
1031 $form->{id} = 0 if $form->{postasnew};
1034 if (AR->post_transaction(\%myconfig, \%$form)) {
1035 # saving the history
1036 if(!exists $form->{addition} && $form->{id} ne "") {
1037 $form->{snumbers} = "invnumber_$form->{invnumber}";
1038 $form->{addition} = "POSTED";
1039 $form->save_history($form->dbconnect(\%myconfig));
1041 # /saving the history
1042 remove_draft() if $form->{remove_draft};
1043 $form->redirect($locale->text('Transaction posted!'));
1045 $form->error($locale->text('Cannot post transaction!'));
1047 $lxdebug->leave_sub();
1051 $lxdebug->enter_sub();
1053 $form->{postasnew} = 1;
1054 # saving the history
1055 if(!exists $form->{addition} && $form->{id} ne "") {
1056 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1057 $form->{addition} = "POSTED AS NEW";
1058 $form->save_history($form->dbconnect(\%myconfig));
1060 # /saving the history
1063 $lxdebug->leave_sub();
1066 sub use_as_template {
1067 $lxdebug->enter_sub();
1069 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);
1070 $form->{paidaccounts} = 1;
1071 $form->{rowcount}--;
1072 $form->{invdate} = $form->current_date(\%myconfig);
1075 $lxdebug->leave_sub();
1079 $lxdebug->enter_sub();
1081 $form->{title} = $locale->text('Confirm!');
1085 delete $form->{header};
1090 <form method=post action=$form->{script}>
1093 foreach $key (keys %$form) {
1094 $form->{$key} =~ s/\"/"/g;
1095 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1099 <h2 class=confirm>$form->{title}</h2>
1102 . $locale->text('Are you sure you want to delete Transaction')
1103 . qq| $form->{invnumber}</h4>
1105 <input name=action class=submit type=submit value="|
1106 . $locale->text('Yes') . qq|">
1113 $lxdebug->leave_sub();
1117 $lxdebug->enter_sub();
1118 if (AR->delete_transaction(\%myconfig, \%$form, $spool)) {
1119 # saving the history
1120 if(!exists $form->{addition}) {
1121 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1122 $form->{addition} = "DELETED";
1123 $form->save_history($form->dbconnect(\%myconfig));
1125 # /saving the history
1126 $form->redirect($locale->text('Transaction deleted!'));
1128 $form->error($locale->text('Cannot delete transaction!'));
1130 $lxdebug->leave_sub();
1134 $lxdebug->enter_sub();
1136 # setup customer selection
1137 $form->all_vc(\%myconfig, "customer", "AR");
1139 if (@{ $form->{all_customer} }) {
1140 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1141 @{ $form->{all_customer} };
1142 $customer = qq|<select name=customer><option>\n$customer</select>|;
1144 $customer = qq|<input name=customer size=35>|;
1148 if (@{ $form->{all_departments} }) {
1149 $form->{selectdepartment} = "<option>\n";
1152 $form->{selectdepartment} .=
1153 "<option>$_->{description}--$_->{id}\n"
1154 } (@{ $form->{all_departments} });
1159 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1160 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1162 | if $form->{selectdepartment};
1164 $form->{title} = $locale->text('AR Transactions');
1166 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1168 # use JavaScript Calendar or not
1169 $form->{jsscript} = 1;
1171 if ($form->{jsscript}) {
1173 # with JavaScript Calendar
1175 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1176 <input type=button name=transdatefrom id="trigger1" value=|
1177 . $locale->text('button') . qq|></td>
1180 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1181 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1182 . $locale->text('button') . qq|></td>
1187 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1188 "transdateto", "BL", "trigger2");
1191 # without JavaScript Calendar
1193 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1195 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1198 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1203 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1204 push(@values, $item->{"id"});
1205 $labels{$item->{"id"}} = $item->{"projectnumber"};
1208 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1209 '-labels' => \%labels));
1211 $form->{fokus} = "search.customer";
1213 $onload = qq|focus()|;
1214 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1215 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1217 <body onLoad="$onload">
1219 <form method=post name="search" action=$form->{script}>
1222 <tr><th class=listtop>$form->{title}</th></tr>
1223 <tr height="5"></tr>
1228 <th align=right>| . $locale->text('Customer') . qq|</th>
1229 <td colspan=3>$customer</td>
1233 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1234 <td colspan=3><input name=invnumber size=20></td>
1237 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1238 <td colspan=3><input name=ordnumber size=20></td>
1241 <th align=right nowrap>| . $locale->text('Transaction description') . qq|</th>
1242 <td colspan=3><input name=transaction_description size=40></td>
1245 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1246 <td colspan=3><input name=notes size=40></td>
1249 <th align="right">| . $locale->text("Project Number") . qq|</th>
1250 <td colspan="3">$projectnumber</td>
1253 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1255 <th align=right>| . $locale->text('Bis') . qq|</th>
1258 <input type=hidden name=sort value=transdate>
1266 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1270 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1271 <td nowrap>| . $locale->text('Open') . qq|</td>
1272 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1273 <td nowrap>| . $locale->text('Closed') . qq|</td>
1276 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1277 <td nowrap>| . $locale->text('ID') . qq|</td>
1278 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1279 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1280 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1281 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1282 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1283 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1286 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1287 <td nowrap>| . $locale->text('Customer') . qq|</td>
1288 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1289 <td nowrap>| . $locale->text('Amount') . qq|</td>
1290 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1291 <td nowrap>| . $locale->text('Tax') . qq|</td>
1292 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1293 <td nowrap>| . $locale->text('Total') . qq|</td>
1296 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1297 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1298 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1299 <td nowrap>| . $locale->text('Paid') . qq|</td>
1300 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1301 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1302 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1303 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1306 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1307 <td nowrap>| . $locale->text('Notes') . qq|</td>
1308 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1309 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1310 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1311 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1312 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1313 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1316 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1317 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1318 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1319 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1320 <td align=right><input name="l_transaction_description" class=checkbox type=checkbox value=Y></td>
1321 <td nowrap>| . $locale->text('Transaction description') . qq|</td>
1330 <td><hr size=3 noshade></td>
1334 <input type=hidden name=nextsub value=$form->{nextsub}>
1336 <input type=hidden name=login value=$form->{login}>
1337 <input type=hidden name=password value=$form->{password}>
1340 <input class=submit type=submit name=action value="|
1341 . $locale->text('Continue') . qq|">
1352 $lxdebug->leave_sub();
1355 sub ar_transactions {
1356 $lxdebug->enter_sub();
1358 $form->{customer} = $form->unescape($form->{customer});
1359 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1361 AR->ar_transactions(\%myconfig, \%$form);
1364 "$form->{script}?action=ar_transactions&login=$form->{login}&password=$form->{password}";
1367 if ($form->{customer}) {
1368 $callback .= "&customer=" . $form->escape($form->{customer}, 1);
1369 $href .= "&customer=" . $form->escape($form->{customer});
1370 $option = $locale->text('Customer') . " : $form->{customer}";
1372 if ($form->{department}) {
1373 $callback .= "&department=" . $form->escape($form->{department}, 1);
1374 $href .= "&department=" . $form->escape($form->{department});
1375 ($department) = split /--/, $form->{department};
1376 $option .= "\n<br>" if ($option);
1377 $option .= $locale->text('Department') . " : $department";
1379 if ($form->{invnumber}) {
1380 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1381 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1382 $option .= "\n<br>" if ($option);
1383 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1385 if ($form->{ordnumber}) {
1386 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1387 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1388 $option .= "\n<br>" if ($option);
1389 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1391 if ($form->{notes}) {
1392 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1393 $href .= "¬es=" . $form->escape($form->{notes});
1394 $option .= "\n<br>" if $option;
1395 $option .= $locale->text('Notes') . " : $form->{notes}";
1397 if ($form->{transaction_description}) {
1398 $callback .= "&transaction_description=" . $form->escape($form->{transaction_description}, 1);
1399 $href .= "&transaction_description=" . $form->escape($form->{transaction_description});
1400 $option .= "\n<br>" if $option;
1401 $option .= $locale->text('Transaction description') . " : $form->{transaction_description}";
1404 if ($form->{transdatefrom}) {
1405 $callback .= "&transdatefrom=$form->{transdatefrom}";
1406 $href .= "&transdatefrom=$form->{transdatefrom}";
1407 $option .= "\n<br>" if ($option);
1409 $locale->text('From') . " "
1410 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1412 if ($form->{transdateto}) {
1413 $callback .= "&transdateto=$form->{transdateto}";
1414 $href .= "&transdateto=$form->{transdateto}";
1415 $option .= "\n<br>" if ($option);
1417 $locale->text('Bis') . " "
1418 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1420 if ($form->{open}) {
1421 $callback .= "&open=$form->{open}";
1422 $href .= "&open=$form->{open}";
1423 $option .= "\n<br>" if ($option);
1424 $option .= $locale->text('Open');
1426 if ($form->{closed}) {
1427 $callback .= "&closed=$form->{closed}";
1428 $href .= "&closed=$form->{closed}";
1429 $option .= "\n<br>" if ($option);
1430 $option .= $locale->text('Closed');
1432 if ($form->{globalproject_id}) {
1433 $callback .= "&globalproject_id=" . E($form->{globalproject_id});
1434 $href .= "&globalproject_id=" . E($form->{globalproject_id});
1438 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1439 datepaid due duedate transaction_description notes employee shippingpoint shipvia
1440 globalprojectnumber);
1442 $form->{"l_type"} = "Y";
1444 foreach $item (@columns) {
1445 if ($form->{"l_$item"} eq "Y") {
1446 push @column_index, $item;
1448 # add column to href and callback
1449 $callback .= "&l_$item=Y";
1450 $href .= "&l_$item=Y";
1454 if ($form->{l_subtotal} eq 'Y') {
1455 $callback .= "&l_subtotal=Y";
1456 $href .= "&l_subtotal=Y";
1459 $column_header{id} =
1460 "<th><a class=listheading href=$href&sort=id>"
1461 . $locale->text('ID')
1463 $column_header{transdate} =
1464 "<th><a class=listheading href=$href&sort=transdate>"
1465 . $locale->text('Date')
1467 $column_header{duedate} =
1468 "<th><a class=listheading href=$href&sort=duedate>"
1469 . $locale->text('Due Date')
1471 $column_header{type} =
1472 "<th class=\"listheading\">" . $locale->text('Type') . "</th>";
1473 $column_header{invnumber} =
1474 "<th><a class=listheading href=$href&sort=invnumber>"
1475 . $locale->text('Invoice')
1477 $column_header{ordnumber} =
1478 "<th><a class=listheading href=$href&sort=ordnumber>"
1479 . $locale->text('Order')
1481 $column_header{name} =
1482 "<th><a class=listheading href=$href&sort=name>"
1483 . $locale->text('Customer')
1485 $column_header{netamount} =
1486 "<th class=listheading>" . $locale->text('Amount') . "</th>";
1487 $column_header{tax} =
1488 "<th class=listheading>" . $locale->text('Tax') . "</th>";
1489 $column_header{amount} =
1490 "<th class=listheading>" . $locale->text('Total') . "</th>";
1491 $column_header{paid} =
1492 "<th class=listheading>" . $locale->text('Paid') . "</th>";
1493 $column_header{datepaid} =
1494 "<th><a class=listheading href=$href&sort=datepaid>"
1495 . $locale->text('Date Paid')
1497 $column_header{due} =
1498 "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
1499 $column_header{notes} =
1500 "<th class=listheading>" . $locale->text('Notes') . "</th>";
1501 $column_header{employee} =
1502 "<th><a class=listheading href=$href&sort=employee>"
1503 . $locale->text('Salesperson') . "</th>";
1505 $column_header{shippingpoint} =
1506 "<th><a class=listheading href=$href&sort=shippingpoint>"
1507 . $locale->text('Shipping Point')
1509 $column_header{shipvia} =
1510 "<th><a class=listheading href=$href&sort=shipvia>"
1511 . $locale->text('Ship via')
1513 $column_header{globalprojectnumber} =
1514 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1515 $column_header{transaction_description} =
1516 "<th class=listheading>" . $locale->text('Transaction description') . "</th>";
1518 $form->{title} = $locale->text('AR Transactions');
1527 <th class=listtop>$form->{title}</th>
1529 <tr height="5"></tr>
1536 <tr class=listheading>
1539 map { print "\n$column_header{$_}" } @column_index;
1545 # add sort and escape callback, this one we use for the add sub
1546 $form->{callback} = $callback .= "&sort=$form->{sort}";
1548 # escape callback for href
1549 $callback = $form->escape($callback);
1551 if (@{ $form->{AR} }) {
1552 $sameitem = $form->{AR}->[0]->{ $form->{sort} };
1555 # sums and tax on reports by Antonio Gallardo
1557 foreach $ar (@{ $form->{AR} }) {
1559 if ($form->{l_subtotal} eq 'Y') {
1560 if ($sameitem ne $ar->{ $form->{sort} }) {
1565 $column_data{netamount} =
1567 . $form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")
1569 $column_data{tax} = "<td align=right>"
1570 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount},
1573 $column_data{amount} =
1575 . $form->format_amount(\%myconfig, $ar->{amount}, 2, " ") . "</td>";
1576 $column_data{paid} =
1578 . $form->format_amount(\%myconfig, $ar->{paid}, 2, " ") . "</td>";
1579 $column_data{due} = "<td align=right>"
1580 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid},
1584 $subtotalnetamount += $ar->{netamount};
1585 $subtotalamount += $ar->{amount};
1586 $subtotalpaid += $ar->{paid};
1587 $subtotaldue += $ar->{amount} - $ar->{paid};
1589 $totalnetamount += $ar->{netamount};
1590 $totalamount += $ar->{amount};
1591 $totalpaid += $ar->{paid};
1592 $totaldue += ($ar->{amount} - $ar->{paid});
1594 $column_data{transdate} = "<td>$ar->{transdate} </td>";
1595 $column_data{id} = "<td>$ar->{id}</td>";
1596 $column_data{datepaid} = "<td>$ar->{datepaid} </td>";
1597 $column_data{duedate} = "<td>$ar->{duedate} </td>";
1599 $module = ($ar->{invoice}) ? "is.pl" : $form->{script};
1601 $column_data{invnumber} =
1602 "<td><a href=$module?action=edit&id=$ar->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}</a></td>";
1604 my $is_storno = $ar->{storno} && IS->is_storno(\%myconfig, $form, 'ar');
1605 my $has_storno = $ar->{storno} && !$is_storno;
1607 $column_data{type} = "<td>" .
1608 ($has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1609 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1610 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1611 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1612 $locale->text("AR Transaction (abbreviation)"))
1614 $column_data{ordnumber} = "<td>$ar->{ordnumber} </td>";
1615 $column_data{name} = "<td>$ar->{name}</td>";
1616 $ar->{notes} =~ s/\r\n/<br>/g;
1617 $column_data{notes} = "<td>$ar->{notes} </td>";
1618 $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>";
1619 $column_data{shipvia} = "<td>$ar->{shipvia} </td>";
1620 $column_data{employee} = "<td>$ar->{employee} </td>";
1621 $column_data{globalprojectnumber} =
1622 "<td>" . H($ar->{globalprojectnumber}) . "</td>";
1623 $column_data{transaction_description} =
1624 "<td>" . H($ar->{transaction_description}) . "</td>";
1629 <tr class=listrow$i>
1632 map { print "\n$column_data{$_}" } @column_index;
1640 if ($form->{l_subtotal} eq 'Y') {
1646 <tr class=listtotal>
1649 map { $column_data{$_} = "<td> </td>" } @column_index;
1651 $column_data{netamount} =
1652 "<th class=listtotal align=right>"
1653 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1654 $column_data{tax} = "<th class=listtotal align=right>"
1655 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1658 $column_data{amount} =
1659 "<th class=listtotal align=right>"
1660 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1661 $column_data{paid} =
1662 "<th class=listtotal align=right>"
1663 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1665 "<th class=listtotal align=right>"
1666 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1668 map { print "\n$column_data{$_}" } @column_index;
1676 <td><hr size=3 noshade></td>
1681 <form method=post action=$form->{script}>
1683 <input name=callback type=hidden value="$form->{callback}">
1685 <input type=hidden name=login value=$form->{login}>
1686 <input type=hidden name=password value=$form->{password}>
1688 <input class=submit type=submit name=action value="|
1689 . $locale->text('AR Transaction') . qq|">
1690 <input class=submit type=submit name=action value="|
1691 . $locale->text('Sales Invoice') . qq|">
1699 $lxdebug->leave_sub();
1703 $lxdebug->enter_sub();
1705 map { $column_data{$_} = "<td> </td>" } @column_index;
1707 $column_data{tax} = "<th class=listsubtotal align=right>"
1708 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1711 $column_data{amount} =
1712 "<th class=listsubtotal align=right>"
1713 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1714 $column_data{paid} =
1715 "<th class=listsubtotal align=right>"
1716 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1718 "<th class=listsubtotal align=right>"
1719 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1721 $subtotalnetamount = 0;
1722 $subtotalamount = 0;
1726 $sameitem = $ar->{ $form->{sort} };
1728 print "<tr class=listsubtotal>";
1730 map { print "\n$column_data{$_}" } @column_index;
1736 $lxdebug->leave_sub();
1741 $lxdebug->enter_sub();
1743 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1744 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1745 $form->error($locale->text("Transaction has already been cancelled!"));
1748 # negate amount/taxes
1749 for my $i (1 .. $form->{rowcount}) {
1750 $form->{"amount_$i"} *= -1;
1751 $form->{"tax_$i"} *= -1;
1755 for my $i (1 .. $form->{rowcount}) {
1756 for (qw(amount tax)) {
1757 $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"};
1761 $form->{storno} = 1;
1762 $form->{storno_id} = $form->{id};
1765 $form->{invnumber} = "Storno-" . $form->{invnumber};
1769 # saving the history
1770 if(!exists $form->{addition} && $form->{id} ne "") {
1771 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1772 $form->{addition} = "STORNO";
1773 $form->save_history($form->dbconnect(\%myconfig));
1775 # /saving the history
1777 $lxdebug->leave_sub();