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}/;
236 $form->{exchangerate} =
237 $form->format_amount(\%myconfig, $form->{exchangerate});
239 $form->{creditlimit} =
240 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
241 $form->{creditremaining} =
242 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
245 <input type=hidden name=forex value=$form->{forex}>
247 if ($form->{currency} ne $form->{defaultcurrency}) {
248 if ($form->{forex}) {
250 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
251 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
255 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
256 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
263 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
264 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
268 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
272 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
276 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
277 <td colspan=3><select name=department>$form->{selectdepartment}</select>
278 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
281 | if $form->{selectdepartment};
283 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
286 ($form->{selectcustomer})
287 ? qq|<select name="customer"
288 onchange="document.getElementById('update_button').click();">$form->{
289 selectcustomer}</select>|
290 : qq|<input name=customer value="$form->{customer}" size=35>|;
293 <input type=hidden name=employee value="$form->{employee}">
296 if ($form->{selectemployee}) {
299 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
300 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
301 <input type=hidden name=selectemployee value="$form->{selectemployee}">
306 my @old_project_ids = ();
307 map({ push(@old_project_ids, $form->{"project_id_$_"})
308 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
310 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
312 "old_id" => \@old_project_ids },
313 "charts" => { "key" => "ALL_CHARTS",
314 "transdate" => $form->{transdate} },
315 "taxcharts" => "ALL_TAXCHARTS");
317 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
318 @{ $form->{ALL_CHARTS} });
320 my %project_labels = ();
321 my @project_values = ("");
322 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
323 push(@project_values, $item->{"id"});
324 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
327 my (%AR_amount_labels, @AR_amount_values);
328 my (%AR_labels, @AR_values);
329 my (%AR_paid_labels, @AR_paid_values);
333 foreach my $item (@{ $form->{ALL_CHARTS} }) {
334 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
335 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
336 my $key = "$item->{accno}--$item->{tax_id}";
337 push(@AR_amount_values, $key);
338 $AR_amount_labels{$key} =
339 "$item->{accno}--$item->{description}";
341 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
342 push(@AR_values, $item->{accno});
343 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
345 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
346 push(@AR_paid_values, $item->{accno});
347 $AR_paid_labels{$item->{accno}} =
348 "$item->{accno}--$item->{description}";
351 $charts{$item->{accno}} = $item;
354 my %taxchart_labels = ();
355 my @taxchart_values = ();
357 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
358 my $key = "$item->{id}--$item->{rate}";
359 $taxchart_init = $key if ($taxchart_init eq $item->{id});
360 push(@taxchart_values, $key);
361 $taxchart_labels{$key} =
362 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
363 $taxcharts{$item->{id}} = $item;
366 $form->{fokus} = "arledger.customer";
368 # use JavaScript Calendar or not
369 $form->{jsscript} = 1;
371 if ($form->{jsscript}) {
373 # with JavaScript Calendar
375 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
376 <td><input type=button name=transdate id="trigger1" value=|
377 . $locale->text('button') . qq|></td>
380 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
381 <td><input type=button name=duedate id="trigger2" value=|
382 . $locale->text('button') . qq|></td></td>
387 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
388 "duedate", "BL", "trigger2");
391 # without JavaScript Calendar
393 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
395 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
398 $form->{javascript} .=
399 qq|<script type="text/javascript" src="js/common.js"></script>| .
400 qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
403 $onload = qq|focus()|;
404 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
405 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
407 <body onLoad="$onload">
409 <form method=post name="arledger" action=$form->{script}>
411 <input type=hidden name=id value=$form->{id}>
412 <input type=hidden name=sort value=$form->{sort}>
413 <input type=hidden name=closedto value=$form->{closedto}>
414 <input type=hidden name=locked value=$form->{locked}>
415 <input type=hidden name=title value="$title">
417 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
421 <th class=listtop>$form->{title}</th>
431 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
432 <td colspan=3>$customer <input type="button" value="?" onclick="show_vc_details('customer')"></td>
433 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
434 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
435 <input type=hidden name=customer_id value="$form->{customer_id}">
436 <input type=hidden name=terms value=$form->{terms}>
443 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
444 <td>$form->{creditlimit}</td>
445 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
446 <td class="plus$n">$form->{creditremaining}</td>
447 <input type=hidden name=creditlimit value=$form->{creditlimit}>
448 <input type=hidden name=creditremaining value=$form->{creditremaining}>
454 <th align=right>| . $locale->text('Currency') . qq|</th>
455 <td><select name=currency>$form->{selectcurrency}</select></td>
456 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
457 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
458 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
459 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
470 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
471 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
474 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
475 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
478 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
482 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
493 <input type=hidden name=rowcount value=$form->{rowcount}>
497 <tr class=listheading>
498 <th class=listheading style="width:15%">|
499 . $locale->text('Account') . qq|</th>
500 <th class=listheading style="width:10%">|
501 . $locale->text('Amount') . qq|</th>
502 <th class=listheading style="width:10%">|
503 . $locale->text('Tax') . qq|</th>
504 <th class=listheading style="width:5%">|
505 . $locale->text('Korrektur') . qq|</th>
506 <th class=listheading style="width:10%">|
507 . $locale->text('Taxkey') . qq|</th>
508 <th class=listheading style="width:10%">|
509 . $locale->text('Project') . qq|</th>
513 $amount = $locale->text('Amount');
514 $project = $locale->text('Project');
516 for $i (1 .. $form->{rowcount}) {
519 $form->{"amount_$i"} =
520 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
521 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
523 my $selected_accno_full;
524 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
525 my $item = $charts{$accno_row};
526 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
528 my $selected_taxchart = $form->{"taxchart_$i"};
529 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
530 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
532 if ($previous_accno &&
533 ($previous_accno eq $selected_accno) &&
534 ($previous_tax_id ne $selected_tax_id)) {
535 my $item = $taxcharts{$selected_tax_id};
536 $selected_taxchart = "$item->{id}--$item->{rate}";
539 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
542 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
543 '-id' => "AR_amount_$i",
544 '-style' => 'width:400px',
545 '-onChange' => "setTaxkey(this, $i)",
546 '-values' => \@AR_amount_values,
547 '-labels' => \%AR_amount_labels,
548 '-default' => $selected_accno_full))
549 . $cgi->hidden('-name' => "previous_AR_amount_$i",
550 '-default' => $selected_accno_full);
553 NTI($cgi->popup_menu('-name' => "taxchart_$i",
554 '-id' => "taxchart_$i",
555 '-style' => 'width:200px',
556 '-values' => \@taxchart_values,
557 '-labels' => \%taxchart_labels,
558 '-default' => $selected_taxchart))
561 $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
564 NTI($cgi->popup_menu('-name' => "project_id_$i",
565 '-values' => \@project_values,
566 '-labels' => \%project_labels,
567 '-default' => $form->{"project_id_$i"} ));
571 <td>$selectAR_amount</td>
572 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
573 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
574 <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
576 <td>$projectnumber</td>
583 $form->{invtotal_unformatted} = $form->{invtotal};
584 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
587 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
588 '-style' => 'width:400px',
589 '-values' => \@AR_values, '-labels' => \%AR_labels,
590 '-default' => $form->{ARselected}));
599 <td>${ARselected}</td>
600 <th align=left>$form->{invtotal}</th>
602 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
603 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
605 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
618 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
619 <td align=left>$notes</td>
627 <tr class=listheading>
628 <th colspan=7 class=listheading>|
629 . $locale->text('Incoming Payments') . qq|</th>
633 if ($form->{currency} eq $form->{defaultcurrency}) {
634 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
636 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
639 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
640 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
641 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
642 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
643 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
644 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
645 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
650 map { print "$column_data{$_}\n" } @column_index;
658 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
659 for $i (1 .. $form->{paidaccounts}) {
665 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
666 '-id' => "AR_paid_$i",
667 '-values' => \@AR_paid_values,
668 '-labels' => \%AR_paid_labels,
669 '-default' => $form->{"AR_paid_$i"}));
671 $totalpaid += $form->{"paid_$i"};
674 if ($form->{"paid_$i"}) {
676 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
678 $form->{"exchangerate_$i"} =
679 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
681 $exchangerate = qq| |;
682 if ($form->{currency} ne $form->{defaultcurrency}) {
683 if ($form->{"forex_$i"}) {
685 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
688 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
693 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
697 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
698 $column_data{AR_paid} =
699 qq|<td align=center>${selectAR_paid}</td>|;
700 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
701 $column_data{datepaid} =
702 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
703 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
704 $column_data{source} =
705 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
707 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
709 $column_data{paid_project_id} =
711 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
712 '-values' => \@project_values,
713 '-labels' => \%project_labels,
714 '-default' => $form->{"paid_project_id_$i"} ))
717 map { print qq|$column_data{$_}\n| } @column_index;
722 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
725 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
731 <td align="center">| . $locale->text('Total') . qq|</td>
732 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
737 <td align="center">| . $locale->text('Missing amount') . qq|</td>
738 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
740 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
742 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
748 <td><hr size=3 noshade></td>
753 $lxdebug->leave_sub();
757 $lxdebug->enter_sub();
761 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
763 <input name=callback type=hidden value="$form->{callback}">
765 <input type=hidden name=login value=$form->{login}>
766 <input type=hidden name=password value=$form->{password}>
768 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
769 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
775 if (!$form->{id} && $form->{draft_id}) {
776 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
777 '-value' => 1, '-checked' => $form->{remove_draft},
779 qq| <label for="remove_draft">| .
780 $locale->text("Remove draft when posting") .
784 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
785 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
787 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
789 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
790 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|
791 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && !$form->{paid_1});
794 if ($form->{radier}) {
796 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
797 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
799 if ($transdate > $closedto) {
801 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
804 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|"> |;
807 if ($transdate > $closedto) {
808 print qq|<input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
809 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
813 if ($form->{menubar}) {
814 require "bin/mozilla/menu.pl";
817 # button for saving history
818 if($form->{id} ne "") {
819 print qq|<input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|>|;
821 # /button for saving history
822 # mark_as_paid button
823 if($form->{id} ne "") {
824 print qq|<input type="submit" class="submit" name="action" value="|
825 . $locale->text('mark as paid') . qq|">|;
827 # /mark_as_paid button
836 $lxdebug->leave_sub();
840 $lxdebug->enter_sub();
841 $form->mark_as_paid(\%myconfig,"ar");
842 $lxdebug->leave_sub();
846 $lxdebug->enter_sub();
850 $form->{invtotal} = 0;
852 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
853 qw(exchangerate creditlimit creditremaining);
855 @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
859 for $i (1 .. $form->{rowcount}) {
860 $form->{"amount_$i"} =
861 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
862 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
863 if ($form->{"amount_$i"}) {
866 if (!$form->{"korrektur_$i"}) {
867 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
869 if ($form->{taxincluded}) {
870 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
872 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
875 $form->{"tax_$i"} = 0;
878 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
880 $totaltax += $form->{"tax_$i"};
881 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
886 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
887 $form->{rowcount} = $count + 1;
888 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
890 $form->{exchangerate} = $exchangerate
894 $form->check_exchangerate(
895 \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
898 $form->{invdate} = $form->{transdate};
899 $save_AR = $form->{AR};
900 &check_name(customer);
901 $form->{AR} = $save_AR;
904 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
906 for $i (1 .. $form->{paidaccounts}) {
907 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
910 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
911 } qw(paid exchangerate);
913 $totalpaid += $form->{"paid_$i"};
915 $form->{"exchangerate_$i"} = $exchangerate
917 $form->{"forex_$i"} = (
919 $form->check_exchangerate(
920 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
925 $form->{creditremaining} -=
926 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
927 $form->{oldinvtotal});
928 $form->{oldinvtotal} = $form->{invtotal};
929 $form->{oldtotalpaid} = $totalpaid;
933 $lxdebug->leave_sub();
937 $lxdebug->enter_sub();
938 for $i (1 .. $form->{paidaccounts}) {
939 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
940 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
942 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
944 $form->error($locale->text('Cannot post payment for a closed period!'))
945 if ($datepaid <= $closedto);
947 if ($form->{currency} ne $form->{defaultcurrency}) {
948 $form->{"exchangerate_$i"} = $form->{exchangerate}
949 if ($invdate == $datepaid);
950 $form->isblank("exchangerate_$i",
951 $locale->text('Exchangerate for payment missing!'));
956 ($form->{AR}) = split /--/, $form->{AR};
957 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
958 $form->redirect($locale->text('Payment posted!'))
959 if (AR->post_payment(\%myconfig, \%$form));
960 $form->error($locale->text('Cannot post payment!'));
963 $lxdebug->leave_sub();
967 $lxdebug->enter_sub();
969 # check if there is an invoice number, invoice and due date
970 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
971 $form->isblank("duedate", $locale->text('Due Date missing!'));
972 $form->isblank("customer", $locale->text('Customer missing!'));
974 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
975 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
976 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
978 $form->error($locale->text('Zero amount posting!'))
979 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
981 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
982 if ($form->{currency} ne $form->{defaultcurrency});
986 for $i (1 .. $form->{paidaccounts}) {
987 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
988 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
990 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
992 $form->error($locale->text('Cannot post payment for a closed period!'))
993 if ($datepaid <= $closedto);
995 if ($form->{currency} ne $form->{defaultcurrency}) {
996 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
997 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1002 # if oldcustomer ne customer redo form
1003 ($customer) = split /--/, $form->{customer};
1004 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1009 $form->{AR}{receivables} = $form->{ARselected};
1011 $form->{id} = 0 if $form->{postasnew};
1012 if (AR->post_transaction(\%myconfig, \%$form)) {
1013 # saving the history
1014 if(!exists $form->{addition} && $form->{id} ne "") {
1015 $form->{snumbers} = "invnumber_$form->{invnumber}";
1016 $form->{addition} = "POSTED";
1017 $form->save_history($form->dbconnect(\%myconfig));
1019 # /saving the history
1020 remove_draft() if $form->{remove_draft};
1021 $form->redirect($locale->text('Transaction posted!'));
1023 $form->error($locale->text('Cannot post transaction!'));
1025 $lxdebug->leave_sub();
1029 $lxdebug->enter_sub();
1031 $form->{postasnew} = 1;
1032 # saving the history
1033 if(!exists $form->{addition} && $form->{id} ne "") {
1034 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1035 $form->{addition} = "POSTED AS NEW";
1036 $form->save_history($form->dbconnect(\%myconfig));
1038 # /saving the history
1041 $lxdebug->leave_sub();
1044 sub use_as_template {
1045 $lxdebug->enter_sub();
1047 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);
1048 $form->{paidaccounts} = 1;
1049 $form->{rowcount}--;
1050 $form->{invdate} = $form->current_date(\%myconfig);
1053 $lxdebug->leave_sub();
1057 $lxdebug->enter_sub();
1059 $form->{title} = $locale->text('Confirm!');
1063 delete $form->{header};
1068 <form method=post action=$form->{script}>
1071 foreach $key (keys %$form) {
1072 $form->{$key} =~ s/\"/"/g;
1073 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1077 <h2 class=confirm>$form->{title}</h2>
1080 . $locale->text('Are you sure you want to delete Transaction')
1081 . qq| $form->{invnumber}</h4>
1083 <input name=action class=submit type=submit value="|
1084 . $locale->text('Yes') . qq|">
1091 $lxdebug->leave_sub();
1095 $lxdebug->enter_sub();
1096 if (AR->delete_transaction(\%myconfig, \%$form, $spool)) {
1097 # saving the history
1098 if(!exists $form->{addition}) {
1099 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1100 $form->{addition} = "DELETED";
1101 $form->save_history($form->dbconnect(\%myconfig));
1103 # /saving the history
1104 $form->redirect($locale->text('Transaction deleted!'));
1106 $form->error($locale->text('Cannot delete transaction!'));
1108 $lxdebug->leave_sub();
1112 $lxdebug->enter_sub();
1114 # setup customer selection
1115 $form->all_vc(\%myconfig, "customer", "AR");
1117 if (@{ $form->{all_customer} }) {
1118 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1119 @{ $form->{all_customer} };
1120 $customer = qq|<select name=customer><option>\n$customer</select>|;
1122 $customer = qq|<input name=customer size=35>|;
1126 if (@{ $form->{all_departments} }) {
1127 $form->{selectdepartment} = "<option>\n";
1130 $form->{selectdepartment} .=
1131 "<option>$_->{description}--$_->{id}\n"
1132 } (@{ $form->{all_departments} });
1137 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1138 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1140 | if $form->{selectdepartment};
1142 $form->{title} = $locale->text('AR Transactions');
1144 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1146 # use JavaScript Calendar or not
1147 $form->{jsscript} = 1;
1149 if ($form->{jsscript}) {
1151 # with JavaScript Calendar
1153 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1154 <input type=button name=transdatefrom id="trigger1" value=|
1155 . $locale->text('button') . qq|></td>
1158 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1159 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1160 . $locale->text('button') . qq|></td>
1165 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1166 "transdateto", "BL", "trigger2");
1169 # without JavaScript Calendar
1171 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1173 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1176 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1181 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1182 push(@values, $item->{"id"});
1183 $labels{$item->{"id"}} = $item->{"projectnumber"};
1186 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1187 '-labels' => \%labels));
1189 $form->{fokus} = "search.customer";
1191 $onload = qq|focus()|;
1192 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1193 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1195 <body onLoad="$onload">
1197 <form method=post name="search" action=$form->{script}>
1200 <tr><th class=listtop>$form->{title}</th></tr>
1201 <tr height="5"></tr>
1206 <th align=right>| . $locale->text('Customer') . qq|</th>
1207 <td colspan=3>$customer</td>
1211 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1212 <td colspan=3><input name=invnumber size=20></td>
1215 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1216 <td colspan=3><input name=ordnumber size=20></td>
1219 <th align=right nowrap>| . $locale->text('Transaction description') . qq|</th>
1220 <td colspan=3><input name=transaction_description size=40></td>
1223 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1224 <td colspan=3><input name=notes size=40></td>
1227 <th align="right">| . $locale->text("Project Number") . qq|</th>
1228 <td colspan="3">$projectnumber</td>
1231 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1233 <th align=right>| . $locale->text('Bis') . qq|</th>
1236 <input type=hidden name=sort value=transdate>
1244 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1248 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1249 <td nowrap>| . $locale->text('Open') . qq|</td>
1250 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1251 <td nowrap>| . $locale->text('Closed') . qq|</td>
1254 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1255 <td nowrap>| . $locale->text('ID') . qq|</td>
1256 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1257 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1258 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1259 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1260 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1261 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1264 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1265 <td nowrap>| . $locale->text('Customer') . qq|</td>
1266 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1267 <td nowrap>| . $locale->text('Amount') . qq|</td>
1268 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1269 <td nowrap>| . $locale->text('Tax') . qq|</td>
1270 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1271 <td nowrap>| . $locale->text('Total') . qq|</td>
1274 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1275 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1276 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1277 <td nowrap>| . $locale->text('Paid') . qq|</td>
1278 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1279 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1280 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1281 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1284 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1285 <td nowrap>| . $locale->text('Notes') . qq|</td>
1286 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1287 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1288 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1289 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1290 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1291 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1294 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1295 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1296 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1297 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1298 <td align=right><input name="l_transaction_description" class=checkbox type=checkbox value=Y></td>
1299 <td nowrap>| . $locale->text('Transaction description') . qq|</td>
1308 <td><hr size=3 noshade></td>
1312 <input type=hidden name=nextsub value=$form->{nextsub}>
1314 <input type=hidden name=login value=$form->{login}>
1315 <input type=hidden name=password value=$form->{password}>
1318 <input class=submit type=submit name=action value="|
1319 . $locale->text('Continue') . qq|">
1330 $lxdebug->leave_sub();
1333 sub ar_transactions {
1334 $lxdebug->enter_sub();
1336 $form->{customer} = $form->unescape($form->{customer});
1337 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1339 AR->ar_transactions(\%myconfig, \%$form);
1342 "$form->{script}?action=ar_transactions&login=$form->{login}&password=$form->{password}";
1345 if ($form->{customer}) {
1346 $callback .= "&customer=" . $form->escape($form->{customer}, 1);
1347 $href .= "&customer=" . $form->escape($form->{customer});
1348 $option = $locale->text('Customer') . " : $form->{customer}";
1350 if ($form->{department}) {
1351 $callback .= "&department=" . $form->escape($form->{department}, 1);
1352 $href .= "&department=" . $form->escape($form->{department});
1353 ($department) = split /--/, $form->{department};
1354 $option .= "\n<br>" if ($option);
1355 $option .= $locale->text('Department') . " : $department";
1357 if ($form->{invnumber}) {
1358 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1359 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1360 $option .= "\n<br>" if ($option);
1361 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1363 if ($form->{ordnumber}) {
1364 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1365 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1366 $option .= "\n<br>" if ($option);
1367 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1369 if ($form->{notes}) {
1370 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1371 $href .= "¬es=" . $form->escape($form->{notes});
1372 $option .= "\n<br>" if $option;
1373 $option .= $locale->text('Notes') . " : $form->{notes}";
1375 if ($form->{transaction_description}) {
1376 $callback .= "&transaction_description=" . $form->escape($form->{transaction_description}, 1);
1377 $href .= "&transaction_description=" . $form->escape($form->{transaction_description});
1378 $option .= "\n<br>" if $option;
1379 $option .= $locale->text('Transaction description') . " : $form->{transaction_description}";
1382 if ($form->{transdatefrom}) {
1383 $callback .= "&transdatefrom=$form->{transdatefrom}";
1384 $href .= "&transdatefrom=$form->{transdatefrom}";
1385 $option .= "\n<br>" if ($option);
1387 $locale->text('From') . " "
1388 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1390 if ($form->{transdateto}) {
1391 $callback .= "&transdateto=$form->{transdateto}";
1392 $href .= "&transdateto=$form->{transdateto}";
1393 $option .= "\n<br>" if ($option);
1395 $locale->text('Bis') . " "
1396 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1398 if ($form->{open}) {
1399 $callback .= "&open=$form->{open}";
1400 $href .= "&open=$form->{open}";
1401 $option .= "\n<br>" if ($option);
1402 $option .= $locale->text('Open');
1404 if ($form->{closed}) {
1405 $callback .= "&closed=$form->{closed}";
1406 $href .= "&closed=$form->{closed}";
1407 $option .= "\n<br>" if ($option);
1408 $option .= $locale->text('Closed');
1410 if ($form->{globalproject_id}) {
1411 $callback .= "&globalproject_id=" . E($form->{globalproject_id});
1412 $href .= "&globalproject_id=" . E($form->{globalproject_id});
1416 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1417 datepaid due duedate transaction_description notes employee shippingpoint shipvia
1418 globalprojectnumber);
1420 $form->{"l_type"} = "Y";
1422 foreach $item (@columns) {
1423 if ($form->{"l_$item"} eq "Y") {
1424 push @column_index, $item;
1426 # add column to href and callback
1427 $callback .= "&l_$item=Y";
1428 $href .= "&l_$item=Y";
1432 if ($form->{l_subtotal} eq 'Y') {
1433 $callback .= "&l_subtotal=Y";
1434 $href .= "&l_subtotal=Y";
1437 $column_header{id} =
1438 "<th><a class=listheading href=$href&sort=id>"
1439 . $locale->text('ID')
1441 $column_header{transdate} =
1442 "<th><a class=listheading href=$href&sort=transdate>"
1443 . $locale->text('Date')
1445 $column_header{duedate} =
1446 "<th><a class=listheading href=$href&sort=duedate>"
1447 . $locale->text('Due Date')
1449 $column_header{type} =
1450 "<th class=\"listheading\">" . $locale->text('Type') . "</th>";
1451 $column_header{invnumber} =
1452 "<th><a class=listheading href=$href&sort=invnumber>"
1453 . $locale->text('Invoice')
1455 $column_header{ordnumber} =
1456 "<th><a class=listheading href=$href&sort=ordnumber>"
1457 . $locale->text('Order')
1459 $column_header{name} =
1460 "<th><a class=listheading href=$href&sort=name>"
1461 . $locale->text('Customer')
1463 $column_header{netamount} =
1464 "<th class=listheading>" . $locale->text('Amount') . "</th>";
1465 $column_header{tax} =
1466 "<th class=listheading>" . $locale->text('Tax') . "</th>";
1467 $column_header{amount} =
1468 "<th class=listheading>" . $locale->text('Total') . "</th>";
1469 $column_header{paid} =
1470 "<th class=listheading>" . $locale->text('Paid') . "</th>";
1471 $column_header{datepaid} =
1472 "<th><a class=listheading href=$href&sort=datepaid>"
1473 . $locale->text('Date Paid')
1475 $column_header{due} =
1476 "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
1477 $column_header{notes} =
1478 "<th class=listheading>" . $locale->text('Notes') . "</th>";
1479 $column_header{employee} =
1480 "<th><a class=listheading href=$href&sort=employee>"
1481 . $locale->text('Salesperson') . "</th>";
1483 $column_header{shippingpoint} =
1484 "<th><a class=listheading href=$href&sort=shippingpoint>"
1485 . $locale->text('Shipping Point')
1487 $column_header{shipvia} =
1488 "<th><a class=listheading href=$href&sort=shipvia>"
1489 . $locale->text('Ship via')
1491 $column_header{globalprojectnumber} =
1492 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1493 $column_header{transaction_description} =
1494 "<th class=listheading>" . $locale->text('Transaction description') . "</th>";
1496 $form->{title} = $locale->text('AR Transactions');
1505 <th class=listtop>$form->{title}</th>
1507 <tr height="5"></tr>
1514 <tr class=listheading>
1517 map { print "\n$column_header{$_}" } @column_index;
1523 # add sort and escape callback, this one we use for the add sub
1524 $form->{callback} = $callback .= "&sort=$form->{sort}";
1526 # escape callback for href
1527 $callback = $form->escape($callback);
1529 if (@{ $form->{AR} }) {
1530 $sameitem = $form->{AR}->[0]->{ $form->{sort} };
1533 # sums and tax on reports by Antonio Gallardo
1535 foreach $ar (@{ $form->{AR} }) {
1537 if ($form->{l_subtotal} eq 'Y') {
1538 if ($sameitem ne $ar->{ $form->{sort} }) {
1543 $column_data{netamount} =
1545 . $form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")
1547 $column_data{tax} = "<td align=right>"
1548 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount},
1551 $column_data{amount} =
1553 . $form->format_amount(\%myconfig, $ar->{amount}, 2, " ") . "</td>";
1554 $column_data{paid} =
1556 . $form->format_amount(\%myconfig, $ar->{paid}, 2, " ") . "</td>";
1557 $column_data{due} = "<td align=right>"
1558 . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid},
1562 $subtotalnetamount += $ar->{netamount};
1563 $subtotalamount += $ar->{amount};
1564 $subtotalpaid += $ar->{paid};
1565 $subtotaldue += $ar->{amount} - $ar->{paid};
1567 $totalnetamount += $ar->{netamount};
1568 $totalamount += $ar->{amount};
1569 $totalpaid += $ar->{paid};
1570 $totaldue += ($ar->{amount} - $ar->{paid});
1572 $column_data{transdate} = "<td>$ar->{transdate} </td>";
1573 $column_data{id} = "<td>$ar->{id}</td>";
1574 $column_data{datepaid} = "<td>$ar->{datepaid} </td>";
1575 $column_data{duedate} = "<td>$ar->{duedate} </td>";
1577 $module = ($ar->{invoice}) ? "is.pl" : $form->{script};
1579 $column_data{invnumber} =
1580 "<td><a href=$module?action=edit&id=$ar->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}</a></td>";
1582 my $is_storno = $ar->{storno} && IS->is_storno(\%myconfig, $form, 'ar');
1583 my $has_storno = $ar->{storno} && !$is_storno;
1585 $column_data{type} = "<td>" .
1586 ($has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1587 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1588 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1589 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1590 $locale->text("AR Transaction (abbreviation)"))
1592 $column_data{ordnumber} = "<td>$ar->{ordnumber} </td>";
1593 $column_data{name} = "<td>$ar->{name}</td>";
1594 $ar->{notes} =~ s/\r\n/<br>/g;
1595 $column_data{notes} = "<td>$ar->{notes} </td>";
1596 $column_data{shippingpoint} = "<td>$ar->{shippingpoint} </td>";
1597 $column_data{shipvia} = "<td>$ar->{shipvia} </td>";
1598 $column_data{employee} = "<td>$ar->{employee} </td>";
1599 $column_data{globalprojectnumber} =
1600 "<td>" . H($ar->{globalprojectnumber}) . "</td>";
1601 $column_data{transaction_description} =
1602 "<td>" . H($ar->{transaction_description}) . "</td>";
1607 <tr class=listrow$i>
1610 map { print "\n$column_data{$_}" } @column_index;
1618 if ($form->{l_subtotal} eq 'Y') {
1624 <tr class=listtotal>
1627 map { $column_data{$_} = "<td> </td>" } @column_index;
1629 $column_data{netamount} =
1630 "<th class=listtotal align=right>"
1631 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1632 $column_data{tax} = "<th class=listtotal align=right>"
1633 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1636 $column_data{amount} =
1637 "<th class=listtotal align=right>"
1638 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1639 $column_data{paid} =
1640 "<th class=listtotal align=right>"
1641 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1643 "<th class=listtotal align=right>"
1644 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1646 map { print "\n$column_data{$_}" } @column_index;
1654 <td><hr size=3 noshade></td>
1659 <form method=post action=$form->{script}>
1661 <input name=callback type=hidden value="$form->{callback}">
1663 <input type=hidden name=login value=$form->{login}>
1664 <input type=hidden name=password value=$form->{password}>
1666 <input class=submit type=submit name=action value="|
1667 . $locale->text('AR Transaction') . qq|">
1668 <input class=submit type=submit name=action value="|
1669 . $locale->text('Sales Invoice') . qq|">
1677 $lxdebug->leave_sub();
1681 $lxdebug->enter_sub();
1683 map { $column_data{$_} = "<td> </td>" } @column_index;
1685 $column_data{tax} = "<th class=listsubtotal align=right>"
1686 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1689 $column_data{amount} =
1690 "<th class=listsubtotal align=right>"
1691 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1692 $column_data{paid} =
1693 "<th class=listsubtotal align=right>"
1694 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1696 "<th class=listsubtotal align=right>"
1697 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1699 $subtotalnetamount = 0;
1700 $subtotalamount = 0;
1704 $sameitem = $ar->{ $form->{sort} };
1706 print "<tr class=listsubtotal>";
1708 map { print "\n$column_data{$_}" } @column_index;
1714 $lxdebug->leave_sub();
1719 $lxdebug->enter_sub();
1721 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1722 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1723 $form->error($locale->text("Transaction has already been cancelled!"));
1726 # negate amount/taxes
1727 for my $i (1 .. $form->{rowcount}) {
1728 $form->{"amount_$i"} *= -1;
1729 $form->{"tax_$i"} *= -1;
1733 for my $i (1 .. $form->{rowcount}) {
1734 for (qw(amount tax)) {
1735 $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"};
1739 $form->{storno} = 1;
1740 $form->{storno_id} = $form->{id};
1743 $form->{invnumber} = "Storno-" . $form->{invnumber};
1747 # saving the history
1748 if(!exists $form->{addition} && $form->{id} ne "") {
1749 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1750 $form->{addition} = "STORNO";
1751 $form->save_history($form->dbconnect(\%myconfig));
1753 # /saving the history
1755 $lxdebug->leave_sub();