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 #======================================================================
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());
80 $form->{title} = "Add";
83 "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
84 unless $form->{callback};
86 AP->get_transdate(\%myconfig, $form);
87 $form->{initial_transdate} = $form->{transdate};
89 $form->{transdate} = $form->{initial_transdate};
92 $lxdebug->leave_sub();
96 $lxdebug->enter_sub();
98 $form->{title} = "Edit";
103 $lxdebug->leave_sub();
107 $lxdebug->enter_sub();
112 $lxdebug->leave_sub();
116 $lxdebug->enter_sub();
118 $form->create_links("AP", \%myconfig, "vendor");
119 $taxincluded = $form->{taxincluded};
120 $duedate = $form->{duedate};
122 IR->get_vendor(\%myconfig, \%$form);
123 $form->{taxincluded} = $taxincluded;
124 $form->{duedate} = $duedate if $duedate;
125 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
126 $form->{rowcount} = 1;
128 # build the popup menus
129 $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
132 $form->{notes} = $form->{intnotes} unless $form->{notes};
135 @curr = split(/:/, $form->{currencies});
137 $form->{defaultcurrency} = $curr[0];
139 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
142 if (@{ $form->{all_vendor} }) {
143 $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
144 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
145 (@{ $form->{all_vendor} });
149 if (@{ $form->{all_departments} }) {
150 $form->{selectdepartment} = "<option>\n";
151 $form->{department} = "$form->{department}--$form->{department_id}";
154 $form->{selectdepartment} .=
155 "<option>$_->{description}--$_->{id}\n"
156 } (@{ $form->{all_departments} });
159 $form->{employee} = "$form->{employee}--$form->{employee_id}";
162 $form->{forex} = $form->{exchangerate};
163 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
165 foreach $key (keys %{ $form->{AP_links} }) {
166 foreach $ref (@{ $form->{AP_links}{$key} }) {
167 if ($key eq "AP_paid") {
168 $form->{"select$key"} .=
169 "<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
171 $form->{"select$key"} .=
172 "<option value=\"$ref->{accno}--$ref->{tax_id}\">$ref->{accno}--$ref->{description}</option>\n";
176 $form->{$key} = $form->{"select$key"};
178 # if there is a value we have an old entry
182 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
184 if ($key eq "AP_paid") {
186 $form->{"AP_paid_$j"} =
187 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
188 $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
189 $form->{"datepaid_$j"} =
190 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
191 $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
192 $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
194 $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
195 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
196 $form->{"AP_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}";
197 $form->{"paid_project_id_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{project_id};
198 $form->{paidaccounts}++;
204 if (($key eq "AP_tax") || ($key eq "AR_tax")) {
205 $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
206 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
207 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
209 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
212 if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
214 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
217 $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
219 $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
221 $index = $form->{acc_trans}{$key}->[$i - 1]->{index};
222 $form->{"tax_$index"} =
223 $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
224 $totaltax += $form->{"tax_$index"};
228 $form->{"${akey}_$k"} =
230 $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
232 if ($akey eq 'amount') {
234 $form->{"${akey}_$i"} *= -1;
235 $totalamount += $form->{"${akey}_$i"};
236 $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
237 $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} =
238 "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
239 $form->{"project_id_$k"} =
240 "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
242 $form->{"${key}_$k"} =
243 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
244 my $q_description = quotemeta($form->{acc_trans}{$key}->[$i-1]->{description});
245 $form->{"select${key}"} =~
246 /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{accno}--[^\"]*)\">$form->{acc_trans}{$key}->[$i-1]->{accno}--${q_description}<\/option>\n/;
247 $form->{"${key}_$k"} = $1;
250 $form->{APselected} = $form->{acc_trans}{$key}->[$i-1]->{accno};
252 } elsif ($akey eq 'amount') {
253 $form->{"${key}_$k"} = $form->{acc_trans}{$key}->[$i-1]->{accno} .
254 "--" . $form->{acc_trans}{$key}->[$i-1]->{id};
255 $form->{"taxchart_$k"} = $form->{acc_trans}{$key}->[$i-1]->{id} .
256 "--" . $form->{acc_trans}{$key}->[$i-1]->{rate};
263 $form->{taxincluded} = $taxincluded if ($form->{id});
264 $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
266 if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
268 # add tax to amounts and invtotal
269 for $i (1 .. $form->{rowcount}) {
271 ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
272 $tax = $form->round_amount($taxamount, 2);
273 $diff += ($taxamount - $tax);
274 $form->{"amount_$i"} += $form->{"tax_$i"};
276 $form->{amount_1} += $form->round_amount($diff, 2);
279 $taxamount = $form->round_amount($taxamount, 2);
281 $form->{invtotal} = $totalamount + $totaltax;
284 ($form->datetonum($form->{transdate}, \%myconfig) <=
285 $form->datetonum($form->{closedto}, \%myconfig));
287 $lxdebug->leave_sub();
291 $lxdebug->enter_sub();
293 $title = $form->{title};
294 $form->{title} = $locale->text("$title Accounts Payables Transaction");
296 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
298 # type=submit $locale->text('Add Accounts Payables Transaction')
299 # type=submit $locale->text('Edit Accounts Payables Transaction')
301 $form->{javascript} = qq|<script type="text/javascript">
303 function setTaxkey(accno, row) {
304 var taxkey = accno.options[accno.selectedIndex].value;
305 var reg = /--([0-9]*)/;
306 var found = reg.exec(taxkey);
307 var index = found[1];
308 index = parseInt(index);
309 var tax = 'taxchart_' + row;
310 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
311 var reg2 = new RegExp("^"+ index, "");
312 if (reg2.exec(document.getElementById(tax).options[i].value)) {
313 document.getElementById(tax).options[i].selected = true;
320 # show history button
321 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
322 #/show hhistory button
324 # set option selected
325 foreach $item (qw(vendor currency department)) {
326 $form->{"select$item"} =~ s/ selected//;
327 $form->{"select$item"} =~
328 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
330 $readonly = ($form->{id}) ? "readonly" : "";
333 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
334 $readonly = ($form->{radier}) ? "" : $readonly;
337 $form->{exchangerate} =
338 $form->format_amount(\%myconfig, $form->{exchangerate});
340 $form->{creditlimit} =
341 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
342 $form->{creditremaining} =
343 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
346 <input type=hidden name=forex value=$form->{forex}>
348 if ($form->{currency} ne $form->{defaultcurrency}) {
349 if ($form->{forex}) {
352 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
353 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
358 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
359 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
368 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
369 <th align=left nowrap>|
370 . $locale->text('Tax Included') . qq|</th>
374 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
378 qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
382 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
383 <td colspan=3><select name=department>$form->{selectdepartment}</select>
384 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
387 | if $form->{selectdepartment};
389 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
392 ($form->{selectvendor})
393 ? qq|<select name="vendor"
394 onchange="document.getElementById('update_button').click();">$form->{
395 selectvendor } </select>|
396 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
398 my @old_project_ids = ();
399 map({ push(@old_project_ids, $form->{"project_id_$_"})
400 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
402 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
404 "old_id" => \@old_project_ids },
405 "charts" => { "key" => "ALL_CHARTS",
406 "transdate" => $form->{transdate} },
407 "taxcharts" => "ALL_TAXCHARTS");
409 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
410 @{ $form->{ALL_CHARTS} });
412 my %project_labels = ();
413 my @project_values = ("");
414 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
415 push(@project_values, $item->{"id"});
416 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
419 my (%AP_amount_labels, @AP_amount_values);
420 my (%AP_labels, @AP_values);
421 my (%AP_paid_labels, @AP_paid_values);
425 foreach my $item (@{ $form->{ALL_CHARTS} }) {
426 if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) {
427 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
428 my $key = "$item->{accno}--$item->{tax_id}";
429 push(@AP_amount_values, $key);
430 $AP_amount_labels{$key} =
431 "$item->{accno}--$item->{description}";
433 } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) {
434 push(@AP_values, $item->{accno});
435 $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
437 } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) {
438 push(@AP_paid_values, $item->{accno});
439 $AP_paid_labels{$item->{accno}} =
440 "$item->{accno}--$item->{description}";
443 $charts{$item->{accno}} = $item;
446 my %taxchart_labels = ();
447 my @taxchart_values = ();
449 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
450 my $key = "$item->{id}--$item->{rate}";
451 $taxchart_init = $key if ($taxchart_init eq $item->{id});
452 push(@taxchart_values, $key);
453 $taxchart_labels{$key} =
454 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
455 $taxcharts{$item->{id}} = $item;
458 # use JavaScript Calendar or not
459 $form->{jsscript} = 1;
461 if ($form->{jsscript}) {
463 # with JavaScript Calendar
465 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
466 <td><input type=button name=transdate id="trigger1" value=|
467 . $locale->text('button') . qq|></td>
470 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
471 <td><input type=button name=duedate id="trigger2" value=|
472 . $locale->text('button') . qq|></td></td>
477 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
478 "duedate", "BL", "trigger2");
481 # without JavaScript Calendar
483 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
485 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
487 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
488 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
491 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
492 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
494 <body onLoad="$onload">
496 <form method=post action=$form->{script}>
498 <input type=hidden name=id value=$form->{id}>
499 <input type=hidden name=sort value=$form->{sort}>
500 <input type=hidden name=closedto value=$form->{closedto}>
501 <input type=hidden name=locked value=$form->{locked}>
502 <input type=hidden name=title value="$title">
504 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
508 <th class=listtop>$form->{title}</th>
518 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
519 <td colspan=3>$vendor <input type="button" value="?" onclick="show_vc_details('vendor')"></td>
520 <input type=hidden name=selectvendor value="$form->{selectvendor}">
521 <input type=hidden name=oldvendor value="$form->{oldvendor}">
522 <input type=hidden name=vendor_id value="$form->{vendor_id}">
523 <input type=hidden name=terms value=$form->{terms}>
530 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
531 <td>$form->{creditlimit}</td>
532 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
533 <td class="plus$n">$form->{creditremaining}</td>
534 <input type=hidden name=creditlimit value=$form->{creditlimit}>
535 <input type=hidden name=creditremaining value=$form->{creditremaining}>
540 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
541 <td><select name=currency>$form->{selectcurrency}</select></td>
542 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
543 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
544 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
545 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
555 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
556 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
559 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
560 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
563 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
567 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
580 <input type=hidden name=rowcount value=$form->{rowcount}>
584 <tr class=listheading>
585 <th class=listheading style="width:15%">|
586 . $locale->text('Account') . qq|</th>
587 <th class=listheading style="width:10%">|
588 . $locale->text('Amount') . qq|</th>
589 <th class=listheading style="width:10%">|
590 . $locale->text('Tax') . qq|</th>
591 <th class=listheading style="width:5%">|
592 . $locale->text('Korrektur') . qq|</th>
593 <th class=listheading style="width:10%">|
594 . $locale->text('Taxkey') . qq|</th>
595 <th class=listheading style="width:10%">|
596 . $locale->text('Project') . qq|</th>
600 $amount = $locale->text('Amount');
601 $project = $locale->text('Project');
603 for $i (1 .. $form->{rowcount}) {
606 $form->{"amount_$i"} =
607 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
608 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
610 my $selected_accno_full;
611 my ($accno_row) = split(/--/, $form->{"AP_amount_$i"});
612 my $item = $charts{$accno_row};
613 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
615 my $selected_taxchart = $form->{"taxchart_$i"};
616 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
617 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AP_amount_$i"});
619 if ($previous_accno &&
620 ($previous_accno eq $selected_accno) &&
621 ($previous_tax_id ne $selected_tax_id)) {
622 my $item = $taxcharts{$selected_tax_id};
623 $selected_taxchart = "$item->{id}--$item->{rate}";
626 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
629 NTI($cgi->popup_menu('-name' => "AP_amount_$i",
630 '-id' => "AP_amount_$i",
631 '-style' => 'width:400px',
632 '-onChange' => "setTaxkey(this, $i)",
633 '-values' => \@AP_amount_values,
634 '-labels' => \%AP_amount_labels,
635 '-default' => $selected_accno_full))
636 . $cgi->hidden('-name' => "previous_AP_amount_$i",
637 '-default' => $selected_accno_full);
640 NTI($cgi->popup_menu('-name' => "taxchart_$i",
641 '-id' => "taxchart_$i",
642 '-style' => 'width:200px',
643 '-values' => \@taxchart_values,
644 '-labels' => \%taxchart_labels,
645 '-default' => $selected_taxchart))
648 my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
651 NTI($cgi->popup_menu('-name' => "project_id_$i",
652 '-values' => \@project_values,
653 '-labels' => \%project_labels,
654 '-default' => $form->{"project_id_$i"} ));
658 <td>$selectAP_amount</td>
659 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
660 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
661 <td><input type="checkbox" name="korrektur_$i" value="1" "$korrektur"></td>
663 <td>$projectnumber</td>
671 ($form->{taxincluded})
672 ? $locale->text('Tax Included')
673 : $locale->text('Tax');
675 $form->{invtotal_unformatted} = $form->{invtotal};
676 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
679 NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
680 '-style' => 'width:400px',
681 '-values' => \@AP_values, '-labels' => \%AP_labels,
682 '-default' => $form->{APselected}));
690 <td>${APselected}</td>
691 <th align=left>$form->{invtotal}</th>
693 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
694 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
696 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
709 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
710 <td align=left>$notes</td>
718 <tr class=listheading>
719 <th class=listheading colspan=7>| . $locale->text('Payments') . qq|</th>
723 if ($form->{currency} eq $form->{defaultcurrency}) {
724 @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
726 @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
729 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
730 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
731 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
732 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
733 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
734 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
735 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
740 map { print "$column_data{$_}\n" } @column_index;
748 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
749 for $i (1 .. $form->{paidaccounts}) {
755 NTI($cgi->popup_menu('-name' => "AP_paid_$i",
756 '-id' => "AP_paid_$i",
757 '-values' => \@AP_paid_values,
758 '-labels' => \%AP_paid_labels,
759 '-default' => $form->{"AP_paid_$i"}));
761 $totalpaid += $form->{"paid_$i"};
764 if ($form->{"paid_$i"}) {
766 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
768 $form->{"exchangerate_$i"} =
769 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
771 $exchangerate = qq| |;
772 if ($form->{currency} ne $form->{defaultcurrency}) {
773 if ($form->{"forex_$i"}) {
775 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
778 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
783 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
786 $column_data{"paid_$i"} =
787 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
788 $column_data{"AP_paid_$i"} =
789 qq|<td align=center>${selectAP_paid}</td>|;
790 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
791 $column_data{"datepaid_$i"} =
792 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
793 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
794 $column_data{"source_$i"} =
795 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
796 $column_data{"memo_$i"} =
797 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
798 $column_data{"paid_project_id_$i"} =
800 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
801 '-values' => \@project_values,
802 '-labels' => \%project_labels,
803 '-default' => $form->{"paid_project_id_$i"} ))
806 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
811 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
814 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
820 <td align="center">| . $locale->text('Total') . qq|</td>
821 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
826 <td align="center">| . $locale->text('Missing amount') . qq|</td>
827 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
829 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
831 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
837 <td><hr size=3 noshade></td>
842 $lxdebug->leave_sub();
846 $lxdebug->enter_sub();
850 <input name=callback type=hidden value="$form->{callback}">
851 <input name="gldate" type="hidden" value="| . Q($form->{gldate}) . qq|">
853 <input type=hidden name=login value=$form->{login}>
854 <input type=hidden name=password value=$form->{password}>
856 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
857 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
863 if (!$form->{id} && $form->{draft_id}) {
864 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
865 '-value' => 1, '-checked' => $form->{remove_draft},
867 qq| <label for="remove_draft">| .
868 $locale->text("Remove draft when posting") .
872 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
873 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
875 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
876 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|
877 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap') && !$form->{paid_1});
879 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">|;
882 if ($form->{radier}) {
883 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
884 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">
888 print qq| <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|">
889 <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
891 } elsif (($transdate > $closedto) && !$form->{id}) {
893 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
894 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
896 # button for saving history
897 if($form->{id} ne "") {
898 print qq| <input type="button" class="submit" onclick="set_history_window($form->{id});" name="history" id="history" value="| . $locale->text('history') . qq|">|;
900 # /button for saving history
908 $lxdebug->leave_sub();
912 $lxdebug->enter_sub();
916 $form->{invtotal} = 0;
918 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
919 qw(exchangerate creditlimit creditremaining);
921 @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
923 for $i (1 .. $form->{rowcount}) {
924 $form->{"amount_$i"} =
925 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
926 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
927 if ($form->{"amount_$i"}) {
930 if (!$form->{"korrektur_$i"}) {
931 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
933 if ($form->{taxincluded}) {
934 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
936 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
939 $form->{"tax_$i"} = 0;
942 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
944 $totaltax += $form->{"tax_$i"};
945 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
949 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
951 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
953 $form->{exchangerate} = $exchangerate
957 $form->check_exchangerate(
958 \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
961 $form->{invdate} = $form->{transdate};
962 $save_AP = $form->{AP};
964 $form->{AP} = $save_AP;
966 $form->{rowcount} = $count + 1;
969 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
971 for $i (1 .. $form->{paidaccounts}) {
972 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
975 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
976 } qw(paid exchangerate);
978 $totalpaid += $form->{"paid_$i"};
980 $form->{"exchangerate_$i"} = $exchangerate
982 $form->{"forex_$i"} = (
984 $form->check_exchangerate(
985 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
990 $form->{creditremaining} -=
991 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
992 $form->{oldinvtotal});
993 $form->{oldinvtotal} = $form->{invtotal};
994 $form->{oldtotalpaid} = $totalpaid;
998 $lxdebug->leave_sub();
1003 $lxdebug->enter_sub();
1004 for $i (1 .. $form->{paidaccounts}) {
1005 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1006 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1008 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1010 $form->error($locale->text('Cannot post payment for a closed period!'))
1011 if ($datepaid <= $closedto);
1013 if ($form->{currency} ne $form->{defaultcurrency}) {
1014 $form->{"exchangerate_$i"} = $form->{exchangerate}
1015 if ($invdate == $datepaid);
1016 $form->isblank("exchangerate_$i",
1017 $locale->text('Exchangerate for payment missing!'));
1022 ($form->{AP}) = split /--/, $form->{AP};
1023 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1024 $form->redirect($locale->text('Payment posted!'))
1025 if (AP->post_payment(\%myconfig, \%$form));
1026 $form->error($locale->text('Cannot post payment!'));
1029 $lxdebug->leave_sub();
1034 $lxdebug->enter_sub();
1036 # check if there is a vendor, invoice and due date
1037 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
1038 $form->isblank("duedate", $locale->text("Due Date missing!"));
1039 $form->isblank("vendor", $locale->text('Vendor missing!'));
1041 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1042 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1043 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
1045 my $zero_amount_posting = 1;
1046 for $i (1 .. $form->{rowcount}) {
1047 if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
1048 $zero_amount_posting = 0;
1053 $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
1055 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1056 if ($form->{currency} ne $form->{defaultcurrency});
1057 delete($form->{AP});
1059 for $i (1 .. $form->{paidaccounts}) {
1060 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1061 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1063 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1065 $form->error($locale->text('Cannot post payment for a closed period!'))
1066 if ($datepaid <= $closedto);
1068 if ($form->{currency} ne $form->{defaultcurrency}) {
1069 $form->{"exchangerate_$i"} = $form->{exchangerate}
1070 if ($transdate == $datepaid);
1071 $form->isblank("exchangerate_$i",
1072 $locale->text('Exchangerate for payment missing!'));
1078 # if old vendor ne vendor redo form
1079 ($vendor) = split /--/, $form->{vendor};
1080 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
1084 ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
1085 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
1086 ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
1087 $form->{AP}{amount_1} = $debitaccno;
1088 $form->{AP}{payables} = $payablesaccno;
1089 $form->{taxkey} = $taxkey;
1091 $form->{id} = 0 if $form->{postasnew};
1093 if (AP->post_transaction(\%myconfig, \%$form)) {
1094 # saving the history
1095 if(!exists $form->{addition} && $form->{id} ne "") {
1096 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1097 $form->{addition} = "POSTED";
1098 $form->save_history($form->dbconnect(\%myconfig));
1100 # /saving the history
1101 remove_draft() if $form->{remove_draft};
1102 $form->redirect($locale->text('Transaction posted!'));
1104 $form->error($locale->text('Cannot post transaction!'));
1106 $lxdebug->leave_sub();
1110 $lxdebug->enter_sub();
1112 $form->{postasnew} = 1;
1113 # saving the history
1114 if(!exists $form->{addition} && $form->{id} ne "") {
1115 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1116 $form->{addition} = "POSTED AS NEW";
1117 $form->save_history($form->dbconnect(\%myconfig));
1119 # /saving the history
1122 $lxdebug->leave_sub();
1125 sub use_as_template {
1126 $lxdebug->enter_sub();
1128 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);
1129 $form->{paidaccounts} = 1;
1130 $form->{rowcount}--;
1131 $form->{invdate} = $form->current_date(\%myconfig);
1134 $lxdebug->leave_sub();
1138 $lxdebug->enter_sub();
1140 $form->{title} = $locale->text('Confirm!');
1144 delete $form->{header};
1149 <form method=post action=$form->{script}>
1152 foreach $key (keys %$form) {
1153 $form->{$key} =~ s/\"/"/g;
1154 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1158 <h2 class=confirm>$form->{title}</h2>
1161 . $locale->text('Are you sure you want to delete Transaction')
1162 . qq| $form->{invnumber}</h4>
1164 <input name=action class=submit type=submit value="|
1165 . $locale->text('Yes') . qq|">
1172 $lxdebug->leave_sub();
1176 $lxdebug->enter_sub();
1177 if (AP->delete_transaction(\%myconfig, \%$form, $spool)) {
1178 # saving the history
1179 if(!exists $form->{addition}) {
1180 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1181 $form->{addition} = "DELETED";
1182 $form->save_history($form->dbconnect(\%myconfig));
1184 # /saving the history
1185 $form->redirect($locale->text('Transaction deleted!'));
1187 $form->error($locale->text('Cannot delete transaction!'));
1189 $lxdebug->leave_sub();
1193 $lxdebug->enter_sub();
1195 # setup vendor selection
1196 $form->all_vc(\%myconfig, "vendor", "AP");
1198 if (@{ $form->{all_vendor} }) {
1199 map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
1200 @{ $form->{all_vendor} };
1201 $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
1203 $vendor = qq|<input name=vendor size=35>|;
1207 if (@{ $form->{all_departments} }) {
1208 $form->{selectdepartment} = "<option>\n";
1211 $form->{selectdepartment} .=
1212 "<option>$_->{description}--$_->{id}\n"
1213 } (@{ $form->{all_departments} });
1218 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1219 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1221 | if $form->{selectdepartment};
1223 $form->{title} = $locale->text('AP Transactions');
1225 # use JavaScript Calendar or not
1226 $form->{jsscript} = 1;
1228 if ($form->{jsscript}) {
1230 # with JavaScript Calendar
1232 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1233 <input type=button name=transdatefrom id="trigger1" value=|
1234 . $locale->text('button') . qq|></td>
1237 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1238 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1239 . $locale->text('button') . qq|></td>
1244 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1245 "transdateto", "BL", "trigger2");
1248 # without JavaScript Calendar
1250 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1252 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1255 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1260 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1261 push(@values, $item->{"id"});
1262 $labels{$item->{"id"}} = $item->{"projectnumber"};
1265 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1266 '-labels' => \%labels));
1267 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1269 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1270 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1272 <body onLoad="$onload">
1274 <form method=post action=$form->{script}>
1278 <th class=listtop>$form->{title}</th>
1280 <tr height="5"></tr>
1285 <th align=right>| . $locale->text('Vendor') . qq|</th>
1286 <td colspan=3>$vendor</td>
1290 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1291 <td colspan=3><input name=invnumber size=20></td>
1294 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1295 <td colspan=3><input name=ordnumber size=20></td>
1298 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1299 <td colspan=3><input name=notes size=40></td>
1302 <th align="right">| . $locale->text("Project Number") . qq|</th>
1303 <td colspan="3">$projectnumber</td>
1306 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1308 <th align=right>| . $locale->text('Bis') . qq|</th>
1311 <input type=hidden name=sort value=transdate>
1319 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1323 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1324 <td nowrap>| . $locale->text('Open') . qq|</td>
1325 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1326 <td nowrap>| . $locale->text('Closed') . qq|</td>
1329 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1330 <td nowrap>| . $locale->text('ID') . qq|</td>
1331 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1332 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1333 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1334 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1337 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1338 <td nowrap>| . $locale->text('Vendor') . qq|</td>
1339 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1340 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1341 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1342 <td nowrap>| . $locale->text('Amount') . qq|</td>
1345 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1346 <td nowrap>| . $locale->text('Tax') . qq|</td>
1347 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1348 <td nowrap>| . $locale->text('Total') . qq|</td>
1349 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1350 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1353 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1354 <td nowrap>| . $locale->text('Paid') . qq|</td>
1355 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1356 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1357 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1358 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1361 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1362 <td nowrap>| . $locale->text('Notes') . qq|</td>
1363 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1364 <td nowrap>| . $locale->text('Employee') . qq|</td>
1367 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1368 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1369 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1370 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1379 <td><hr size=3 noshade></td>
1386 <input type=hidden name=nextsub value=$form->{nextsub}>
1387 <input type=hidden name=login value=$form->{login}>
1388 <input type=hidden name=password value=$form->{password}>
1390 <input class=submit type=submit name=action value="|
1391 . $locale->text('Continue') . qq|">
1398 $lxdebug->leave_sub();
1401 sub ap_transactions {
1402 $lxdebug->enter_sub();
1404 $form->{vendor} = $form->unescape($form->{vendor});
1405 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
1407 AP->ap_transactions(\%myconfig, \%$form);
1410 "$form->{script}?action=ap_transactions&login=$form->{login}&password=$form->{password}";
1413 if ($form->{vendor}) {
1414 $callback .= "&vendor=" . $form->escape($form->{vendor}, 1);
1415 $href .= "&vendor=" . $form->escape($form->{vendor});
1416 $option .= $locale->text('Vendor') . " : $form->{vendor}";
1418 if ($form->{department}) {
1419 $callback .= "&department=" . $form->escape($form->{department}, 1);
1420 $href .= "&department=" . $form->escape($form->{department});
1421 ($department) = split /--/, $form->{department};
1422 $option .= "\n<br>" if ($option);
1423 $option .= $locale->text('Department') . " : $department";
1425 if ($form->{invnumber}) {
1426 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1427 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1428 $option .= "\n<br>" if ($option);
1429 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1431 if ($form->{ordnumber}) {
1432 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1433 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1434 $option .= "\n<br>" if ($option);
1435 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1437 if ($form->{notes}) {
1438 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1439 $href .= "¬es=" . $form->escape($form->{notes});
1440 $option .= "\n<br>" if $option;
1441 $option .= $locale->text('Notes') . " : $form->{notes}";
1444 if ($form->{transdatefrom}) {
1445 $callback .= "&transdatefrom=$form->{transdatefrom}";
1446 $href .= "&transdatefrom=$form->{transdatefrom}";
1447 $option .= "\n<br>" if ($option);
1449 $locale->text('From') . " "
1450 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1452 if ($form->{transdateto}) {
1453 $callback .= "&transdateto=$form->{transdateto}";
1454 $href .= "&transdateto=$form->{transdateto}";
1455 $option .= "\n<br>" if ($option);
1457 $locale->text('Bis') . " "
1458 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1460 if ($form->{open}) {
1461 $callback .= "&open=$form->{open}";
1462 $href .= "&open=$form->{open}";
1463 $option .= "\n<br>" if ($option);
1464 $option .= $locale->text('Open');
1466 if ($form->{closed}) {
1467 $callback .= "&closed=$form->{closed}";
1468 $href .= "&closed=$form->{closed}";
1469 $option .= "\n<br>" if ($option);
1470 $option .= $locale->text('Closed');
1472 if ($form->{globalproject_id}) {
1473 $callback .= "&globalproject_id=" . E($form->{globalproject_id});
1474 $href .= "&globalproject_id=" . E($form->{globalproject_id});
1478 qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
1479 due duedate notes employee globalprojectnumber);
1481 $form->{"l_type"} = "Y";
1483 foreach $item (@columns) {
1484 if ($form->{"l_$item"} eq "Y") {
1485 push @column_index, $item;
1487 # add column to href and callback
1488 $callback .= "&l_$item=Y";
1489 $href .= "&l_$item=Y";
1493 if ($form->{l_subtotal} eq 'Y') {
1494 $callback .= "&l_subtotal=Y";
1495 $href .= "&l_subtotal=Y";
1498 $column_header{id} =
1499 qq|<th><a class=listheading href=$href&sort=id>|
1500 . $locale->text('ID')
1502 $column_header{transdate} =
1503 qq|<th><a class=listheading href=$href&sort=transdate>|
1504 . $locale->text('Date')
1506 $column_header{type} =
1507 "<th class=\"listheading\">" . $locale->text('Type') . "</th>";
1508 $column_header{duedate} =
1509 qq|<th><a class=listheading href=$href&sort=duedate>|
1510 . $locale->text('Due Date')
1512 $column_header{due} =
1513 qq|<th class=listheading>| . $locale->text('Amount Due') . qq|</th>|;
1514 $column_header{invnumber} =
1515 qq|<th><a class=listheading href=$href&sort=invnumber>|
1516 . $locale->text('Invoice')
1518 $column_header{ordnumber} =
1519 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1520 . $locale->text('Order')
1522 $column_header{name} =
1523 qq|<th><a class=listheading href=$href&sort=name>|
1524 . $locale->text('Vendor')
1526 $column_header{netamount} =
1527 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1528 $column_header{tax} =
1529 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1530 $column_header{amount} =
1531 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1532 $column_header{paid} =
1533 qq|<th class=listheading>| . $locale->text('Paid') . qq|</th>|;
1534 $column_header{datepaid} =
1535 qq|<th><a class=listheading href=$href&sort=datepaid>|
1536 . $locale->text('Date Paid')
1538 $column_header{notes} =
1539 qq|<th class=listheading>| . $locale->text('Notes') . qq|</th>|;
1540 $column_header{employee} =
1541 "<th><a class=listheading href=$href&sort=employee>"
1542 . $locale->text('Employee') . "</th>";
1543 $column_header{globalprojectnumber} =
1544 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1546 $form->{title} = $locale->text('AP Transactions');
1555 <th class=listtop>$form->{title}</th>
1557 <tr height="5"></tr>
1564 <tr class=listheading>
1567 map { print "\n$column_header{$_}" } @column_index;
1573 # add sort and escape callback
1574 $form->{callback} = "$callback&sort=$form->{sort}";
1575 $callback = $form->escape($form->{callback});
1577 if (@{ $form->{AP} }) {
1578 $sameitem = $form->{AP}->[0]->{ $form->{sort} };
1581 # sums and tax on reports by Antonio Gallardo
1583 foreach $ap (@{ $form->{AP} }) {
1585 if ($form->{l_subtotal} eq 'Y') {
1586 if ($sameitem ne $ap->{ $form->{sort} }) {
1588 $sameitem = $ap->{ $form->{sort} };
1592 $column_data{netamount} =
1594 . $form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")
1596 $column_data{tax} = "<td align=right>"
1597 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount},
1600 $column_data{amount} =
1602 . $form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>";
1603 $column_data{paid} =
1605 . $form->format_amount(\%myconfig, $ap->{paid}, 2, " ") . "</td>";
1606 $column_data{due} = "<td align=right>"
1607 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid},
1611 $totalnetamount += $ap->{netamount};
1612 $totalamount += $ap->{amount};
1613 $totalpaid += $ap->{paid};
1614 $totaldue += ($ap->{amount} - $ap->{paid});
1616 $subtotalnetamount += $ap->{netamount};
1617 $subtotalamount += $ap->{amount};
1618 $subtotalpaid += $ap->{paid};
1619 $subtotaldue += ($ap->{amount} - $ap->{paid});
1621 $column_data{transdate} = "<td>$ap->{transdate} </td>";
1622 $column_data{type} = "<td>" .
1623 ($ap->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1624 $locale->text("AP Transaction (abbreviation)"))
1626 $column_data{duedate} = "<td>$ap->{duedate} </td>";
1627 $column_data{datepaid} = "<td>$ap->{datepaid} </td>";
1629 $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
1631 $column_data{invnumber} =
1632 qq|<td><a href="$module?action=edit&id=$ap->{id}&login=$form->{login}&password=$form->{password}&callback=$callback">$ap->{invnumber}</a></td>|;
1633 $column_data{id} = "<td>$ap->{id}</td>";
1634 $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>";
1635 $column_data{name} = "<td>$ap->{name}</td>";
1636 $ap->{notes} =~ s/\r\n/<br>/g;
1637 $column_data{notes} = "<td>$ap->{notes} </td>";
1638 $column_data{employee} = "<td>$ap->{employee} </td>";
1639 $column_data{globalprojectnumber} =
1640 "<td>" . H($ap->{globalprojectnumber}) . "</td>";
1645 <tr class=listrow$i >
1648 map { print "\n$column_data{$_}" } @column_index;
1656 if ($form->{l_subtotal} eq 'Y') {
1662 <tr class=listtotal>
1665 map { $column_data{$_} = "<td> </td>" } @column_index;
1667 $column_data{netamount} =
1668 "<th class=listtotal align=right>"
1669 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1670 $column_data{tax} = "<th class=listtotal align=right>"
1671 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1674 $column_data{amount} =
1675 "<th class=listtotal align=right>"
1676 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1677 $column_data{paid} =
1678 "<th class=listtotal align=right>"
1679 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1681 "<th class=listtotal align=right>"
1682 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1684 map { print "$column_data{$_}\n" } @column_index;
1692 <td><hr size=3 noshade></td>
1697 <form method=post action=$form->{script}>
1699 <input name=callback type=hidden value="$form->{callback}">
1701 <input type=hidden name=login value=$form->{login}>
1702 <input type=hidden name=password value=$form->{password}>
1704 <input class=submit type=submit name=action value="|
1705 . $locale->text('AP Transaction') . qq|">
1707 <input class=submit type=submit name=action value="|
1708 . $locale->text('Vendor Invoice') . qq|">
1716 $lxdebug->leave_sub();
1720 $lxdebug->enter_sub();
1722 map { $column_data{$_} = "<td> </td>" } @column_index;
1724 $column_data{netamount} =
1725 "<th class=listsubtotal align=right>"
1726 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1728 $column_data{tax} = "<th class=listsubtotal align=right>"
1729 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1732 $column_data{amount} =
1733 "<th class=listsubtotal align=right>"
1734 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1735 $column_data{paid} =
1736 "<th class=listsubtotal align=right>"
1737 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1739 "<th class=listsubtotal align=right>"
1740 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1742 $subtotalnetamount = 0;
1743 $subtotalamount = 0;
1747 print "<tr class=listsubtotal>";
1749 map { print "\n$column_data{$_}" } @column_index;
1755 $lxdebug->leave_sub();
1759 $lxdebug->enter_sub();
1761 if (IS->has_storno(\%myconfig, $form, 'ap')) {
1762 $form->{title} = $locale->text("Cancel Accounts Payables Transaction");
1763 $form->error($locale->text("Transaction has already been cancelled!"));
1766 # negate amount/taxes
1767 for my $i (1 .. $form->{rowcount}) {
1768 $form->{"amount_$i"} *= -1;
1769 $form->{"tax_$i"} *= -1;
1773 for my $i (1 .. $form->{rowcount}) {
1774 for (qw(amount tax)) {
1775 $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"};
1779 $form->{storno} = 1;
1780 $form->{storno_id} = $form->{id};
1783 $form->{invnumber} = "Storno-" . $form->{invnumber};
1787 # saving the history
1788 if(!exists $form->{addition} && $form->{id} ne "") {
1789 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1790 $form->{addition} = "STORNO";
1791 $form->save_history($form->dbconnect(\%myconfig));
1793 # /saving the history
1795 $lxdebug->leave_sub();