1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # Accounts Receivables
32 #======================================================================
34 use POSIX qw(strftime);
35 use List::Util qw(sum first);
41 use SL::ReportGenerator;
43 require "bin/mozilla/arap.pl";
44 require "bin/mozilla/common.pl";
45 require "bin/mozilla/drafts.pl";
46 require "bin/mozilla/reportgenerator.pl";
55 # this is for our long dates
56 # $locale->text('January')
57 # $locale->text('February')
58 # $locale->text('March')
59 # $locale->text('April')
60 # $locale->text('May ')
61 # $locale->text('June')
62 # $locale->text('July')
63 # $locale->text('August')
64 # $locale->text('September')
65 # $locale->text('October')
66 # $locale->text('November')
67 # $locale->text('December')
69 # this is for our short month
70 # $locale->text('Jan')
71 # $locale->text('Feb')
72 # $locale->text('Mar')
73 # $locale->text('Apr')
74 # $locale->text('May')
75 # $locale->text('Jun')
76 # $locale->text('Jul')
77 # $locale->text('Aug')
78 # $locale->text('Sep')
79 # $locale->text('Oct')
80 # $locale->text('Nov')
81 # $locale->text('Dec')
86 $main::lxdebug->enter_sub();
88 $main::auth->assert('general_ledger');
90 my $form = $main::form;
91 my %myconfig = %main::myconfig;
93 return $main::lxdebug->leave_sub() if (load_draft_maybe());
96 if(!exists $form->{addition} && ($form->{id} ne "")) {
97 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
98 $form->{addition} = "ADDED";
99 $form->save_history($form->dbconnect(\%myconfig));
101 # /saving the history
103 $form->{title} = "Add";
104 $form->{callback} = "ar.pl?action=add" unless $form->{callback};
106 AR->get_transdate(\%myconfig, $form);
107 $form->{initial_transdate} = $form->{transdate};
109 $form->{transdate} = $form->{initial_transdate};
111 $main::lxdebug->leave_sub();
115 $main::lxdebug->enter_sub();
117 $main::auth->assert('general_ledger');
119 my $form = $main::form;
121 # show history button
122 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
123 #/show hhistory button
124 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
125 $form->{title} = "Edit";
130 $main::lxdebug->leave_sub();
134 $main::lxdebug->enter_sub();
136 $main::auth->assert('general_ledger');
138 my $form = $main::form;
143 $main::lxdebug->leave_sub();
147 $main::lxdebug->enter_sub();
149 $main::auth->assert('general_ledger');
151 my $form = $main::form;
152 my %myconfig = %main::myconfig;
154 my ($duedate, $taxincluded, @curr);
156 $form->create_links("AR", \%myconfig, "customer");
157 $duedate = $form->{duedate};
159 $taxincluded = $form->{taxincluded};
160 my $id = $form->{id};
161 IS->get_customer(\%myconfig, \%$form);
162 $form->{taxincluded} = $taxincluded;
165 $form->{duedate} = $duedate if $duedate;
166 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
167 $form->{rowcount} = 1;
170 $form->{notes} = $form->{intnotes} unless $form->{notes};
173 @curr = split(/:/, $form->{currencies});
175 $form->{defaultcurrency} = $curr[0];
177 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
180 if (@{ $form->{all_customer} }) {
181 $form->{customer} = "$form->{customer}--$form->{customer_id}";
182 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
183 (@{ $form->{all_customer} });
187 if (@{ $form->{all_departments} }) {
188 $form->{selectdepartment} = "<option>\n";
189 $form->{department} = "$form->{department}--$form->{department_id}";
192 $form->{selectdepartment} .=
193 "<option>$_->{description}--$_->{id}\n"
194 } (@{ $form->{all_departments} });
197 $form->{employee} = "$form->{employee}--$form->{employee_id}";
200 if (@{ $form->{all_employees} }) {
201 $form->{selectemployee} = "";
202 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
203 (@{ $form->{all_employees} });
206 # build the popup menus
207 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
209 AR->setup_form($form);
212 ($form->datetonum($form->{transdate}, \%myconfig) <=
213 $form->datetonum($form->{closedto}, \%myconfig));
215 $main::lxdebug->leave_sub();
219 $main::lxdebug->enter_sub();
221 $main::auth->assert('general_ledger');
223 my $form = $main::form;
224 my %myconfig = %main::myconfig;
225 my $locale = $main::locale;
226 my $cgi = $main::cgi;
228 my ($title, $readonly, $exchangerate, $rows);
229 my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
230 my ($jsscript, $button1, $button2, $onload);
231 my ($selectAR_amount, $selectAR_paid, $ARselected, $tax);
232 my (@column_index, %column_data);
235 $title = $form->{title};
236 $form->{title} = $locale->text("$title Accounts Receivables Transaction");
238 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
240 # $locale->text('Add Accounts Receivables Transaction')
241 # $locale->text('Edit Accounts Receivables Transaction')
242 $form->{javascript} = qq|<script type="text/javascript">
244 function setTaxkey(accno, row) {
245 var taxkey = accno.options[accno.selectedIndex].value;
246 var reg = /--([0-9]*)/;
247 var found = reg.exec(taxkey);
248 var index = found[1];
249 index = parseInt(index);
250 var tax = 'taxchart_' + row;
251 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
252 var reg2 = new RegExp("^"+ index, "");
253 if (reg2.exec(document.getElementById(tax).options[i].value)) {
254 document.getElementById(tax).options[i].selected = true;
261 # show history button js
262 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
263 #/show history button js
264 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
265 $readonly = ($form->{id}) ? "readonly" : "";
268 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
269 $readonly = ($form->{radier}) ? "" : $readonly;
271 # set option selected
272 foreach my $item (qw(customer currency department employee)) {
273 $form->{"select$item"} =~ s/ selected//;
274 $form->{"select$item"} =~
275 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
278 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
279 $form->{exchangerate} = $form->{forex} if $form->{forex};
282 $form->{exchangerate} =
283 $form->format_amount(\%myconfig, $form->{exchangerate});
285 if ($form->{exchangerate} == 0) {
286 $form->{exchangerate} = "";
289 $form->{creditlimit} =
290 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
291 $form->{creditremaining} =
292 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
295 <input type=hidden name=forex value=$form->{forex}>
297 if ($form->{currency} ne $form->{defaultcurrency}) {
298 if ($form->{forex}) {
300 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
301 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
305 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
306 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
313 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
314 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
318 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
322 qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
326 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
327 <td colspan=3><select name=department>$form->{selectdepartment}</select>
328 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
331 | if $form->{selectdepartment};
333 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
335 $customer = ($form->{selectcustomer})
336 ? qq|<select name="customer" onchange="document.getElementById('update_button').click();">$form->{selectcustomer}</select>|
337 : qq|<input name=customer value="$form->{customer}" size=35>|;
340 <input type=hidden name=employee value="$form->{employee}">
343 if ($form->{selectemployee}) {
346 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
347 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
348 <input type=hidden name=selectemployee value="$form->{selectemployee}">
353 my @old_project_ids = ();
354 map({ push(@old_project_ids, $form->{"project_id_$_"})
355 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
357 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
359 "old_id" => \@old_project_ids },
360 "charts" => { "key" => "ALL_CHARTS",
361 "transdate" => $form->{transdate} },
362 "taxcharts" => { "key" => "ALL_TAXCHARTS",
363 "module" => "AR" },);
365 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
366 @{ $form->{ALL_CHARTS} });
368 my %project_labels = ();
369 my @project_values = ("");
370 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
371 push(@project_values, $item->{"id"});
372 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
375 my (%AR_amount_labels, @AR_amount_values);
376 my (%AR_labels, @AR_values);
377 my (%AR_paid_labels, @AR_paid_values);
381 foreach my $item (@{ $form->{ALL_CHARTS} }) {
382 if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
383 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
384 my $key = "$item->{accno}--$item->{tax_id}";
385 push(@AR_amount_values, $key);
386 $AR_amount_labels{$key} =
387 "$item->{accno}--$item->{description}";
389 } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
390 push(@AR_values, $item->{accno});
391 $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
393 } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
394 push(@AR_paid_values, $item->{accno});
395 $AR_paid_labels{$item->{accno}} =
396 "$item->{accno}--$item->{description}";
399 $charts{$item->{accno}} = $item;
402 my %taxchart_labels = ();
403 my @taxchart_values = ();
405 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
406 my $key = "$item->{id}--$item->{rate}";
407 $taxchart_init = $key if ($taxchart_init eq $item->{id});
408 push(@taxchart_values, $key);
409 $taxchart_labels{$key} =
410 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
411 $taxcharts{$item->{id}} = $item;
414 $form->{fokus} = "arledger.customer";
416 # use JavaScript Calendar or not
417 $form->{jsscript} = 1;
419 if ($form->{jsscript}) {
421 # with JavaScript Calendar
423 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
424 <td><input type=button name=transdate id="trigger1" value=|
425 . $locale->text('button') . qq|></td>
428 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
429 <td><input type=button name=duedate id="trigger2" value=|
430 . $locale->text('button') . qq|></td></td>
435 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
436 "duedate", "BL", "trigger2");
439 # without JavaScript Calendar
441 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
443 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
446 my $follow_up_vc = $form->{customer};
447 $follow_up_vc =~ s/--.*?//;
448 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
450 $form->{javascript} .=
451 qq|<script type="text/javascript" src="js/common.js"></script>| .
452 qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| .
453 qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
456 $onload = qq|focus()|;
457 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
458 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
460 <body onLoad="$onload">
462 <form method=post name="arledger" action=$form->{script}>
464 <input type=hidden name=id value=$form->{id}>
465 <input type=hidden name=sort value=$form->{sort}>
466 <input type=hidden name=closedto value=$form->{closedto}>
467 <input type=hidden name=locked value=$form->{locked}>
468 <input type=hidden name=title value="$title">
469 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
470 <input type="hidden" name="follow_up_trans_type_1" value="ar_transaction">
471 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
472 <input type="hidden" name="follow_up_rowcount" value="1">
474 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
478 <th class=listtop>$form->{title}</th>
488 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
489 <td colspan=3>$customer <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')"></td>
490 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
491 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
492 <input type=hidden name=customer_id value="$form->{customer_id}">
493 <input type=hidden name=terms value=$form->{terms}>
500 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
501 <td>$form->{creditlimit}</td>
502 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
503 <td class="plus$n">$form->{creditremaining}</td>
504 <input type=hidden name=creditlimit value=$form->{creditlimit}>
505 <input type=hidden name=creditremaining value=$form->{creditremaining}>
511 <th align=right>| . $locale->text('Currency') . qq|</th>
512 <td><select name=currency>$form->{selectcurrency}</select></td>
513 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
514 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
515 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
516 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
527 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
528 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
531 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
532 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
535 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
539 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
550 <input type=hidden name=rowcount value=$form->{rowcount}>
554 <tr class=listheading>
555 <th class=listheading style="width:15%">|
556 . $locale->text('Account') . qq|</th>
557 <th class=listheading style="width:10%">|
558 . $locale->text('Amount') . qq|</th>
559 <th class=listheading style="width:10%">|
560 . $locale->text('Tax') . qq|</th>
561 <th class=listheading style="width:5%">|
562 . $locale->text('Taxkey') . qq|</th>
563 <th class=listheading style="width:10%">|
564 . $locale->text('Project') . qq|</th>
568 $amount = $locale->text('Amount');
569 $project = $locale->text('Project');
571 for my $i (1 .. $form->{rowcount}) {
574 $form->{"amount_$i"} =
575 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
576 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
578 my $selected_accno_full;
579 my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
580 my $item = $charts{$accno_row};
581 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
583 my $selected_taxchart = $form->{"taxchart_$i"};
584 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
585 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
587 if ($previous_accno &&
588 ($previous_accno eq $selected_accno) &&
589 ($previous_tax_id ne $selected_tax_id)) {
590 my $item = $taxcharts{$selected_tax_id};
591 $selected_taxchart = "$item->{id}--$item->{rate}";
594 if (!$form->{"taxchart_$i"}) {
595 if ($form->{"AR_amount_$i"} =~ m/.--./) {
596 $selected_taxchart = join '--', map { ($_->{id}, $_->{rate}) } first { $_->{id} == $item->{tax_id} } @{ $form->{ALL_TAXCHARTS} };
598 $selected_taxchart = $taxchart_init;
603 NTI($cgi->popup_menu('-name' => "AR_amount_$i",
604 '-id' => "AR_amount_$i",
605 '-style' => 'width:400px',
606 '-onChange' => "setTaxkey(this, $i)",
607 '-values' => \@AR_amount_values,
608 '-labels' => \%AR_amount_labels,
609 '-default' => $selected_accno_full))
610 . $cgi->hidden('-name' => "previous_AR_amount_$i",
611 '-default' => $selected_accno_full);
614 NTI($cgi->popup_menu('-name' => "taxchart_$i",
615 '-id' => "taxchart_$i",
616 '-style' => 'width:200px',
617 '-values' => \@taxchart_values,
618 '-labels' => \%taxchart_labels,
619 '-default' => $selected_taxchart))
623 NTI($cgi->popup_menu('-name' => "project_id_$i",
624 '-values' => \@project_values,
625 '-labels' => \%project_labels,
626 '-default' => $form->{"project_id_$i"} ));
630 <td>$selectAR_amount</td>
631 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
632 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
634 <td>$projectnumber</td>
641 $form->{invtotal_unformatted} = $form->{invtotal};
642 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
645 NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
646 '-style' => 'width:400px',
647 '-values' => \@AR_values, '-labels' => \%AR_labels,
648 '-default' => $form->{ARselected}));
657 <td>${ARselected}</td>
658 <th align=left>$form->{invtotal}</th>
660 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
661 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
663 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
676 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
677 <td align=left>$notes</td>
685 <tr class=listheading>
686 <th colspan=7 class=listheading>|
687 . $locale->text('Incoming Payments') . qq|</th>
691 if ($form->{currency} eq $form->{defaultcurrency}) {
692 @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
694 @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
697 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
698 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
699 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
700 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
701 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
702 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
703 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
708 map { print "$column_data{$_}\n" } @column_index;
716 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
717 for my $i (1 .. $form->{paidaccounts}) {
723 NTI($cgi->popup_menu('-name' => "AR_paid_$i",
724 '-id' => "AR_paid_$i",
725 '-values' => \@AR_paid_values,
726 '-labels' => \%AR_paid_labels,
727 '-default' => $form->{"AR_paid_$i"}));
729 $totalpaid += $form->{"paid_$i"};
732 if ($form->{"paid_$i"}) {
734 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
736 $form->{"exchangerate_$i"} =
737 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
739 if ($form->{"exchangerate_$i"} == 0) {
740 $form->{"exchangerate_$i"} = "";
743 $exchangerate = qq| |;
744 if ($form->{currency} ne $form->{defaultcurrency}) {
745 if ($form->{"forex_$i"}) {
747 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
750 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
755 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
759 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
760 $column_data{AR_paid} =
761 qq|<td align=center>${selectAR_paid}</td>|;
762 $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
763 $column_data{datepaid} =
764 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
765 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
766 $column_data{source} =
767 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
769 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
771 $column_data{paid_project_id} =
773 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
774 '-values' => \@project_values,
775 '-labels' => \%project_labels,
776 '-default' => $form->{"paid_project_id_$i"} ))
779 map { print qq|$column_data{$_}\n| } @column_index;
784 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
787 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
793 <td align="center">| . $locale->text('Total') . qq|</td>
794 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
799 <td align="center">| . $locale->text('Missing amount') . qq|</td>
800 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
802 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
804 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
810 <td><hr size=3 noshade></td>
815 $main::lxdebug->leave_sub();
819 $main::lxdebug->enter_sub();
821 $main::auth->assert('general_ledger');
823 my $form = $main::form;
824 my %myconfig = %main::myconfig;
825 my $locale = $main::locale;
826 my $cgi = $main::cgi;
828 my ($transdate, $closedto);
830 my $follow_ups_block;
832 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
834 if (@{ $follow_ups} ) {
835 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
836 $follow_ups_block = qq|<p>| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</p>|;
844 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
846 <input name=callback type=hidden value="$form->{callback}">
848 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
849 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
855 if (!$form->{id} && $form->{draft_id}) {
856 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
857 '-value' => 1, '-checked' => $form->{remove_draft},
859 qq| <label for="remove_draft">| .
860 $locale->text("Remove draft when posting") .
864 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
865 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
867 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
869 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
870 print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
871 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($totalpaid == 0) || ($totalpaid eq "")));
874 if ($form->{radier}) {
876 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
877 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
879 if ($transdate > $closedto) {
881 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
884 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
885 <input type="button" class="submit" onclick="follow_up_window()" value="|
886 . $locale->text('Follow-Up')
890 if ($transdate > $closedto) {
891 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
892 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
896 if ($form->{menubar}) {
897 require "bin/mozilla/menu.pl";
900 # button for saving history
901 if($form->{id} ne "") {
902 print qq| <input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|> |;
904 # /button for saving history
905 # mark_as_paid button
906 if($form->{id} ne "") {
907 print qq|<input type="submit" class="submit" name="action" value="|
908 . $locale->text('mark as paid') . qq|">|;
910 # /mark_as_paid button
919 $main::lxdebug->leave_sub();
923 $main::lxdebug->enter_sub();
925 $main::auth->assert('general_ledger');
927 my $form = $main::form;
928 my %myconfig = %main::myconfig;
930 &mark_as_paid_common(\%myconfig,"ar");
932 $main::lxdebug->leave_sub();
936 $main::lxdebug->enter_sub();
938 $main::auth->assert('general_ledger');
940 my $form = $main::form;
941 my %myconfig = %main::myconfig;
945 my ($totaltax, $exchangerate);
947 $form->{invtotal} = 0;
949 delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
951 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
952 qw(exchangerate creditlimit creditremaining);
954 my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
958 for my $i (1 .. $form->{rowcount}) {
959 $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
960 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
961 if ($form->{"amount_$i"}) {
964 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
966 if ($form->{taxincluded}) {
967 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
969 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
972 $form->{"tax_$i"} = 0;
974 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
976 $totaltax += $form->{"tax_$i"};
977 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
982 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
983 $form->{rowcount} = $count + 1;
984 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
986 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
987 $form->{exchangerate} = $form->{forex} if $form->{forex};
989 $form->{invdate} = $form->{transdate};
991 $form->{invdate} = $form->{transdate};
993 my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1);
995 &check_name("customer");
997 $form->{AR} = $saved_variables{AR};
998 if ($saved_variables{AR_amount_1} =~ m/.--./) {
999 map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
1001 delete $form->{taxchart_1};
1005 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
1007 for my $i (1 .. $form->{paidaccounts}) {
1008 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1010 $form->{"${_}_$i"} =
1011 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1012 } qw(paid exchangerate);
1014 $totalpaid += $form->{"paid_$i"};
1016 $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1017 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1021 $form->{creditremaining} -=
1022 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
1023 $form->{oldinvtotal});
1024 $form->{oldinvtotal} = $form->{invtotal};
1025 $form->{oldtotalpaid} = $totalpaid;
1029 $main::lxdebug->leave_sub();
1033 # ToDO: fix $closedto and $invdate
1036 $main::lxdebug->enter_sub();
1038 $main::auth->assert('general_ledger');
1040 my $form = $main::form;
1041 my %myconfig = %main::myconfig;
1042 my $locale = $main::locale;
1044 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1046 for my $i (1 .. $form->{paidaccounts}) {
1048 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1049 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1051 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1053 $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1055 if ($form->{currency} ne $form->{defaultcurrency}) {
1056 # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
1057 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1062 ($form->{AR}) = split /--/, $form->{AR};
1063 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1064 $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
1065 $form->error($locale->text('Cannot post payment!'));
1067 $main::lxdebug->leave_sub();
1072 $main::auth->assert('general_ledger');
1074 my $form = $main::form;
1081 $main::lxdebug->enter_sub();
1083 $main::auth->assert('general_ledger');
1085 my $form = $main::form;
1086 my %myconfig = %main::myconfig;
1087 my $locale = $main::locale;
1093 # check if there is an invoice number, invoice and due date
1094 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
1095 $form->isblank("duedate", $locale->text('Due Date missing!'));
1096 $form->isblank("customer", $locale->text('Customer missing!'));
1098 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1099 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1100 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
1102 $form->error($locale->text('Zero amount posting!'))
1103 unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
1105 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1106 if ($form->{currency} ne $form->{defaultcurrency});
1108 delete($form->{AR});
1110 for my $i (1 .. $form->{paidaccounts}) {
1111 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1112 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1114 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1116 $form->error($locale->text('Cannot post payment for a closed period!'))
1117 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1119 if ($form->{currency} ne $form->{defaultcurrency}) {
1120 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
1121 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
1126 # if oldcustomer ne customer redo form
1127 my ($customer) = split /--/, $form->{customer};
1128 if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
1133 $form->{AR}{receivables} = $form->{ARselected};
1134 $form->{storno} = 0;
1136 $main::lxdebug->message(0, $form->{amount});
1137 $form->{id} = 0 if $form->{postasnew};
1138 $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
1140 # saving the history
1141 if(!exists $form->{addition} && $form->{id} ne "") {
1142 $form->{snumbers} = "invnumber_$form->{invnumber}";
1143 $form->{addition} = "POSTED";
1144 $form->save_history($form->dbconnect(\%myconfig));
1146 # /saving the history
1147 remove_draft() if $form->{remove_draft};
1149 $form->redirect($locale->text('Transaction posted!')) unless $inline;
1151 $main::lxdebug->leave_sub();
1155 $main::lxdebug->enter_sub();
1157 $main::auth->assert('general_ledger');
1159 my $form = $main::form;
1160 my %myconfig = %main::myconfig;
1162 $form->{postasnew} = 1;
1163 # saving the history
1164 if(!exists $form->{addition} && $form->{id} ne "") {
1165 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1166 $form->{addition} = "POSTED AS NEW";
1167 $form->save_history($form->dbconnect(\%myconfig));
1169 # /saving the history
1172 $main::lxdebug->leave_sub();
1175 sub use_as_template {
1176 $main::lxdebug->enter_sub();
1178 $main::auth->assert('general_ledger');
1180 my $form = $main::form;
1181 my %myconfig = %main::myconfig;
1183 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);
1184 $form->{paidaccounts} = 1;
1185 $form->{rowcount}--;
1186 $form->{invdate} = $form->current_date(\%myconfig);
1189 $main::lxdebug->leave_sub();
1193 $main::lxdebug->enter_sub();
1195 $main::auth->assert('general_ledger');
1197 my $form = $main::form;
1198 my $locale = $main::locale;
1200 $form->{title} = $locale->text('Confirm!');
1204 delete $form->{header};
1209 <form method=post action=$form->{script}>
1212 foreach my $key (keys %$form) {
1213 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1214 $form->{$key} =~ s/\"/"/g;
1215 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1219 <h2 class=confirm>$form->{title}</h2>
1222 . $locale->text('Are you sure you want to delete Transaction')
1223 . qq| $form->{invnumber}</h4>
1225 <input name=action class=submit type=submit value="|
1226 . $locale->text('Yes') . qq|">
1233 $main::lxdebug->leave_sub();
1237 $main::lxdebug->enter_sub();
1239 $main::auth->assert('general_ledger');
1241 my $form = $main::form;
1242 my %myconfig = %main::myconfig;
1243 my $locale = $main::locale;
1245 if (AR->delete_transaction(\%myconfig, \%$form)) {
1246 # saving the history
1247 if(!exists $form->{addition}) {
1248 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1249 $form->{addition} = "DELETED";
1250 $form->save_history($form->dbconnect(\%myconfig));
1252 # /saving the history
1253 $form->redirect($locale->text('Transaction deleted!'));
1255 $form->error($locale->text('Cannot delete transaction!'));
1257 $main::lxdebug->leave_sub();
1261 $main::lxdebug->enter_sub();
1263 $main::auth->assert('general_ledger | invoice_edit');
1265 my $form = $main::form;
1266 my %myconfig = %main::myconfig;
1267 my $locale = $main::locale;
1268 my $cgi = $main::cgi;
1270 my ($customer, $department);
1271 my ($jsscript, $button1, $button2, $onload);
1273 # setup customer selection
1274 $form->all_vc(\%myconfig, "customer", "AR");
1276 if (@{ $form->{all_customer} }) {
1277 map { $customer .= "<option>$_->{name}--$_->{id}\n" }
1278 @{ $form->{all_customer} };
1279 $customer = qq|<select name=customer><option>\n$customer</select>|;
1281 $customer = qq|<input name=customer size=35>|;
1285 if (@{ $form->{all_departments} }) {
1286 $form->{selectdepartment} = "<option>\n";
1289 $form->{selectdepartment} .=
1290 "<option>$_->{description}--$_->{id}\n"
1291 } (@{ $form->{all_departments} });
1296 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1297 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1299 | if $form->{selectdepartment};
1301 $form->{title} = $locale->text('AR Transactions');
1303 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1305 # use JavaScript Calendar or not
1306 $form->{jsscript} = 1;
1308 if ($form->{jsscript}) {
1310 # with JavaScript Calendar
1312 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1313 <input type=button name=transdatefrom id="trigger1" value=|
1314 . $locale->text('button') . qq|></td>
1317 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1318 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1319 . $locale->text('button') . qq|></td>
1324 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1325 "transdateto", "BL", "trigger2");
1328 # without JavaScript Calendar
1330 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1332 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1335 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1340 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1341 push(@values, $item->{"id"});
1342 $labels{$item->{"id"}} = $item->{"projectnumber"};
1345 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1346 '-labels' => \%labels));
1348 $form->{fokus} = "search.customer";
1350 $onload = qq|focus()|;
1351 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1352 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1354 <body onLoad="$onload">
1356 <form method=post name="search" action=$form->{script}>
1359 <tr><th class=listtop>$form->{title}</th></tr>
1360 <tr height="5"></tr>
1365 <th align=right>| . $locale->text('Customer') . qq|</th>
1366 <td colspan=3>$customer</td>
1370 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1371 <td colspan=3><input name=invnumber size=20></td>
1374 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1375 <td colspan=3><input name=ordnumber size=20></td>
1378 <th align=right nowrap>| . $locale->text('Transaction description') . qq|</th>
1379 <td colspan=3><input name=transaction_description size=40></td>
1382 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1383 <td colspan=3><input name=notes size=40></td>
1386 <th align="right">| . $locale->text("Project Number") . qq|</th>
1387 <td colspan="3">$projectnumber</td>
1390 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1392 <th align=right>| . $locale->text('Bis') . qq|</th>
1395 <input type=hidden name=sort value=transdate>
1403 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1407 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1408 <td nowrap>| . $locale->text('Open') . qq|</td>
1409 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1410 <td nowrap>| . $locale->text('Closed') . qq|</td>
1413 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1414 <td nowrap>| . $locale->text('ID') . qq|</td>
1415 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1416 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1417 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1418 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1419 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1420 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1423 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1424 <td nowrap>| . $locale->text('Customer') . qq|</td>
1425 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1426 <td nowrap>| . $locale->text('Amount') . qq|</td>
1427 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1428 <td nowrap>| . $locale->text('Tax') . qq|</td>
1429 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1430 <td nowrap>| . $locale->text('Total') . qq|</td>
1433 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1434 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1435 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1436 <td nowrap>| . $locale->text('Paid') . qq|</td>
1437 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1438 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1439 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1440 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1443 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1444 <td nowrap>| . $locale->text('Notes') . qq|</td>
1445 <td align=right><input name="l_salesman" class=checkbox type=checkbox value=Y></td>
1446 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
1447 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
1448 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
1449 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
1450 <td nowrap>| . $locale->text('Ship via') . qq|</td>
1453 <td align=right><input name="l_marge_total" class=checkbox type=checkbox value=Y></td>
1454 <td nowrap> | . $locale->text('Ertrag') . qq|</td>
1455 <td align=right><input name="l_marge_percent" class=checkbox type=checkbox value=Y></td>
1456 <td nowrap> | . $locale->text('Ertrag prozentual') . qq|</td>
1457 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1458 <td nowrap>| . $locale->text('Employee') . qq|</td>
1461 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1462 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1463 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1464 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1465 <td align=right><input name="l_transaction_description" class=checkbox type=checkbox value=Y></td>
1466 <td nowrap>| . $locale->text('Transaction description') . qq|</td>
1469 <td colspan=4 align=left><b>| . $locale->text('Customer') . qq| </td>
1472 <td align=right><input name="l_customernumber" class=checkbox type=checkbox value=Y></td>
1473 <td nowrap>| . $locale->text('Customer Number') . qq|</td>
1474 <td align=right><input name="l_country" class=checkbox type=checkbox value=Y></td>
1475 <td nowrap>| . $locale->text('Country') . qq|</td>
1476 <td align=right><input name="l_ustid" class=checkbox type=checkbox value=Y></td>
1477 <td nowrap>| . $locale->text('USt-IdNr.') . qq|</td>
1478 <td align=right><input name="l_taxzone" class=checkbox type=checkbox value=Y></td>
1479 <td nowrap>| . $locale->text('Steuersatz') . qq|</td>
1482 <td align=right><input name="l_payment_terms" class=checkbox type=checkbox value=Y></td>
1483 <td nowrap>| . $locale->text('Payment Terms') . qq|</td>
1484 <td align=right><input name="l_charts" class=checkbox type=checkbox value=Y></td>
1485 <td nowrap>| . $locale->text('Buchungskonto') . qq|</td>
1495 <td><hr size=3 noshade></td>
1499 <input type=hidden name=nextsub value=$form->{nextsub}>
1502 <input class=submit type=submit name=action value="|
1503 . $locale->text('Continue') . qq|">
1514 $main::lxdebug->leave_sub();
1517 sub create_subtotal_row {
1518 $main::lxdebug->enter_sub();
1520 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1522 my $form = $main::form;
1523 my %myconfig = %main::myconfig;
1525 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1527 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1529 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1531 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1533 $main::lxdebug->leave_sub();
1538 sub ar_transactions {
1539 $main::lxdebug->enter_sub();
1541 $main::auth->assert('general_ledger | invoice_edit');
1543 my $form = $main::form;
1544 my %myconfig = %main::myconfig;
1545 my $locale = $main::locale;
1547 my ($callback, $href, @columns);
1549 $form->{customer} = $form->unescape($form->{customer});
1550 ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
1552 report_generator_set_default_sort('transdate', 1);
1554 AR->ar_transactions(\%myconfig, \%$form);
1556 $form->{title} = $locale->text('AR Transactions');
1558 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1561 qw(transdate id type invnumber ordnumber name netamount tax amount paid
1562 datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
1563 marge_total marge_percent globalprojectnumber customernumber country ustid taxzone payment_terms charts);
1565 my @hidden_variables = map { "l_${_}" } @columns;
1566 push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
1568 $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
1571 'transdate' => { 'text' => $locale->text('Date'), },
1572 'id' => { 'text' => $locale->text('ID'), },
1573 'type' => { 'text' => $locale->text('Type'), },
1574 'invnumber' => { 'text' => $locale->text('Invoice'), },
1575 'ordnumber' => { 'text' => $locale->text('Order'), },
1576 'name' => { 'text' => $locale->text('Customer'), },
1577 'netamount' => { 'text' => $locale->text('Amount'), },
1578 'tax' => { 'text' => $locale->text('Tax'), },
1579 'amount' => { 'text' => $locale->text('Total'), },
1580 'paid' => { 'text' => $locale->text('Paid'), },
1581 'datepaid' => { 'text' => $locale->text('Date Paid'), },
1582 'due' => { 'text' => $locale->text('Amount Due'), },
1583 'duedate' => { 'text' => $locale->text('Due Date'), },
1584 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1585 'notes' => { 'text' => $locale->text('Notes'), },
1586 'salesman' => { 'text' => $locale->text('Salesperson'), },
1587 'employee' => { 'text' => $locale->text('Employee'), },
1588 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
1589 'shipvia' => { 'text' => $locale->text('Ship via'), },
1590 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1591 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1592 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
1593 'customernumber' => { 'text' => $locale->text('Customer Number'), },
1594 'country' => { 'text' => $locale->text('Country'), },
1595 'ustid' => { 'text' => $locale->text('USt-IdNr.'), },
1596 'taxzone' => { 'text' => $locale->text('Steuersatz'), },
1597 'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
1598 'charts' => { 'text' => $locale->text('Buchungskonto'), },
1601 foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
1602 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
1603 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
1606 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
1608 $form->{"l_type"} = "Y";
1609 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1611 $report->set_columns(%column_defs);
1612 $report->set_column_order(@columns);
1614 $report->set_export_options('ar_transactions', @hidden_variables, qw(sort sortdir));
1616 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
1619 if ($form->{customer}) {
1620 push @options, $locale->text('Customer') . " : $form->{customer}";
1622 if ($form->{department}) {
1623 my ($department) = split /--/, $form->{department};
1624 push @options, $locale->text('Department') . " : $department";
1626 if ($form->{invnumber}) {
1627 push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
1629 if ($form->{ordnumber}) {
1630 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1632 if ($form->{notes}) {
1633 push @options, $locale->text('Notes') . " : $form->{notes}";
1635 if ($form->{transaction_description}) {
1636 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1638 if ($form->{transdatefrom}) {
1639 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1641 if ($form->{transdateto}) {
1642 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1644 if ($form->{open}) {
1645 push @options, $locale->text('Open');
1647 if ($form->{closed}) {
1648 push @options, $locale->text('Closed');
1651 $report->set_options('top_info_text' => join("\n", @options),
1652 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
1653 'output_format' => 'HTML',
1654 'title' => $form->{title},
1655 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
1657 $report->set_options_from_form();
1659 # add sort and escape callback, this one we use for the add sub
1660 $form->{callback} = $href .= "&sort=$form->{sort}";
1662 # escape callback for href
1663 $callback = $form->escape($href);
1665 my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
1667 my %totals = map { $_ => 0 } @subtotal_columns;
1668 my %subtotals = map { $_ => 0 } @subtotal_columns;
1672 foreach my $ar (@{ $form->{AR} }) {
1673 $ar->{tax} = $ar->{amount} - $ar->{netamount};
1674 $ar->{due} = $ar->{amount} - $ar->{paid};
1676 map { $subtotals{$_} += $ar->{$_};
1677 $totals{$_} += $ar->{$_} } @subtotal_columns;
1679 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1680 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1682 map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
1684 my $is_storno = $ar->{storno} && $ar->{storno_id};
1685 my $has_storno = $ar->{storno} && !$ar->{storno_id};
1688 $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
1689 $is_storno ? $locale->text("Storno (one letter abbreviation)") :
1690 $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
1691 $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1692 $locale->text("AR Transaction (abbreviation)");
1696 foreach my $column (@columns) {
1698 'data' => $ar->{$column},
1699 'align' => $column_alignment{$column},
1703 $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
1704 . "&id=" . E($ar->{id}) . "&callback=${callback}";
1706 my $row_set = [ $row ];
1708 if (($form->{l_subtotal} eq 'Y')
1709 && (($idx == (scalar @{ $form->{AR} } - 1))
1710 || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
1711 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1714 $report->add_data($row_set);
1719 $report->add_separator();
1720 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1722 $report->generate_with_headers();
1724 $main::lxdebug->leave_sub();
1728 $main::lxdebug->enter_sub();
1730 $main::auth->assert('general_ledger');
1732 my $form = $main::form;
1733 my %myconfig = %main::myconfig;
1734 my $locale = $main::locale;
1736 # don't cancel cancelled transactions
1737 if (IS->has_storno(\%myconfig, $form, 'ar')) {
1738 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1739 $form->error($locale->text("Transaction has already been cancelled!"));
1742 AR->storno($form, \%myconfig, $form->{id});
1744 # saving the history
1745 if(!exists $form->{addition} && $form->{id} ne "") {
1746 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1747 $form->{addition} = "STORNO";
1748 $form->save_history($form->dbconnect(\%myconfig));
1750 # /saving the history
1752 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1754 $main::lxdebug->leave_sub();