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}";
161 AP->setup_form($form);
164 ($form->datetonum($form->{transdate}, \%myconfig) <=
165 $form->datetonum($form->{closedto}, \%myconfig));
167 $lxdebug->leave_sub();
171 $lxdebug->enter_sub();
173 $title = $form->{title};
174 $form->{title} = $locale->text("$title Accounts Payables Transaction");
176 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
178 # type=submit $locale->text('Add Accounts Payables Transaction')
179 # type=submit $locale->text('Edit Accounts Payables Transaction')
181 $form->{javascript} = qq|<script type="text/javascript">
183 function setTaxkey(accno, row) {
184 var taxkey = accno.options[accno.selectedIndex].value;
185 var reg = /--([0-9]*)/;
186 var found = reg.exec(taxkey);
187 var index = found[1];
188 index = parseInt(index);
189 var tax = 'taxchart_' + row;
190 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
191 var reg2 = new RegExp("^"+ index, "");
192 if (reg2.exec(document.getElementById(tax).options[i].value)) {
193 document.getElementById(tax).options[i].selected = true;
200 # show history button
201 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
202 #/show hhistory button
204 # set option selected
205 foreach $item (qw(vendor currency department)) {
206 $form->{"select$item"} =~ s/ selected//;
207 $form->{"select$item"} =~
208 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
210 $readonly = ($form->{id}) ? "readonly" : "";
213 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
214 $readonly = ($form->{radier}) ? "" : $readonly;
216 $form->{exchangerate} = $exchangerate
220 $form->check_exchangerate(
221 \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
226 $form->{exchangerate} =
227 $form->format_amount(\%myconfig, $form->{exchangerate});
228 if ($form->{exchangerate} == 0) {
229 $form->{exchangerate} = "";
231 $form->{creditlimit} =
232 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
233 $form->{creditremaining} =
234 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
237 <input type=hidden name=forex value=$form->{forex}>
239 if ($form->{currency} ne $form->{defaultcurrency}) {
240 if ($form->{forex}) {
243 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
244 <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
249 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
250 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
259 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
260 <th align=left nowrap>|
261 . $locale->text('Tax Included') . qq|</th>
265 if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
269 qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
273 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
274 <td colspan=3><select name=department>$form->{selectdepartment}</select>
275 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
278 | if $form->{selectdepartment};
280 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
283 ($form->{selectvendor})
284 ? qq|<select name="vendor"
285 onchange="document.getElementById('update_button').click();">$form->{
286 selectvendor } </select>|
287 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
289 my @old_project_ids = ();
290 map({ push(@old_project_ids, $form->{"project_id_$_"})
291 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
293 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
295 "old_id" => \@old_project_ids },
296 "charts" => { "key" => "ALL_CHARTS",
297 "transdate" => $form->{transdate} },
298 "taxcharts" => "ALL_TAXCHARTS");
300 map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
301 @{ $form->{ALL_CHARTS} });
303 my %project_labels = ();
304 my @project_values = ("");
305 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
306 push(@project_values, $item->{"id"});
307 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
310 my (%AP_amount_labels, @AP_amount_values);
311 my (%AP_labels, @AP_values);
312 my (%AP_paid_labels, @AP_paid_values);
316 foreach my $item (@{ $form->{ALL_CHARTS} }) {
317 if (grep({ $_ eq "AP_amount" } @{ $item->{link_split} })) {
318 $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
319 my $key = "$item->{accno}--$item->{tax_id}";
320 push(@AP_amount_values, $key);
321 $AP_amount_labels{$key} =
322 "$item->{accno}--$item->{description}";
324 } elsif (grep({ $_ eq "AP" } @{ $item->{link_split} })) {
325 push(@AP_values, $item->{accno});
326 $AP_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
328 } elsif (grep({ $_ eq "AP_paid" } @{ $item->{link_split} })) {
329 push(@AP_paid_values, $item->{accno});
330 $AP_paid_labels{$item->{accno}} =
331 "$item->{accno}--$item->{description}";
334 $charts{$item->{accno}} = $item;
337 my %taxchart_labels = ();
338 my @taxchart_values = ();
340 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
341 my $key = "$item->{id}--$item->{rate}";
342 $taxchart_init = $key if ($taxchart_init eq $item->{id});
343 push(@taxchart_values, $key);
344 $taxchart_labels{$key} =
345 "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
346 $taxcharts{$item->{id}} = $item;
349 # use JavaScript Calendar or not
350 $form->{jsscript} = 1;
352 if ($form->{jsscript}) {
354 # with JavaScript Calendar
356 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
357 <td><input type=button name=transdate id="trigger1" value=|
358 . $locale->text('button') . qq|></td>
361 <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>
362 <td><input type=button name=duedate id="trigger2" value=|
363 . $locale->text('button') . qq|></td></td>
368 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
369 "duedate", "BL", "trigger2");
372 # without JavaScript Calendar
374 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
376 qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"> $readonly</td>|;
378 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
379 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
382 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
383 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
385 <body onLoad="$onload">
387 <form method=post action=$form->{script}>
389 <input type=hidden name=id value=$form->{id}>
390 <input type=hidden name=sort value=$form->{sort}>
391 <input type=hidden name=closedto value=$form->{closedto}>
392 <input type=hidden name=locked value=$form->{locked}>
393 <input type=hidden name=title value="$title">
395 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
399 <th class=listtop>$form->{title}</th>
409 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
410 <td colspan=3>$vendor <input type="button" value="?" onclick="show_vc_details('vendor')"></td>
411 <input type=hidden name=selectvendor value="$form->{selectvendor}">
412 <input type=hidden name=oldvendor value="$form->{oldvendor}">
413 <input type=hidden name=vendor_id value="$form->{vendor_id}">
414 <input type=hidden name=terms value=$form->{terms}>
421 <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
422 <td>$form->{creditlimit}</td>
423 <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
424 <td class="plus$n">$form->{creditremaining}</td>
425 <input type=hidden name=creditlimit value=$form->{creditlimit}>
426 <input type=hidden name=creditremaining value=$form->{creditremaining}>
431 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
432 <td><select name=currency>$form->{selectcurrency}</select></td>
433 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
434 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
435 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
436 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
446 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
447 <td><input name=invnumber size=11 value="$form->{invnumber}" $readonly></td>
450 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
451 <td><input name=ordnumber size=11 value="$form->{ordnumber}" $readonly></td>
454 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
458 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
471 <input type=hidden name=rowcount value=$form->{rowcount}>
475 <tr class=listheading>
476 <th class=listheading style="width:15%">|
477 . $locale->text('Account') . qq|</th>
478 <th class=listheading style="width:10%">|
479 . $locale->text('Amount') . qq|</th>
480 <th class=listheading style="width:10%">|
481 . $locale->text('Tax') . qq|</th>
482 <th class=listheading style="width:5%">|
483 . $locale->text('Korrektur') . qq|</th>
484 <th class=listheading style="width:10%">|
485 . $locale->text('Taxkey') . qq|</th>
486 <th class=listheading style="width:10%">|
487 . $locale->text('Project') . qq|</th>
491 $amount = $locale->text('Amount');
492 $project = $locale->text('Project');
494 for $i (1 .. $form->{rowcount}) {
497 $form->{"amount_$i"} =
498 $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
499 $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
501 my $selected_accno_full;
502 my ($accno_row) = split(/--/, $form->{"AP_amount_$i"});
503 my $item = $charts{$accno_row};
504 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
506 my $selected_taxchart = $form->{"taxchart_$i"};
507 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
508 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AP_amount_$i"});
510 if ($previous_accno &&
511 ($previous_accno eq $selected_accno) &&
512 ($previous_tax_id ne $selected_tax_id)) {
513 my $item = $taxcharts{$selected_tax_id};
514 $selected_taxchart = "$item->{id}--$item->{rate}";
517 $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
520 NTI($cgi->popup_menu('-name' => "AP_amount_$i",
521 '-id' => "AP_amount_$i",
522 '-style' => 'width:400px',
523 '-onChange' => "setTaxkey(this, $i)",
524 '-values' => \@AP_amount_values,
525 '-labels' => \%AP_amount_labels,
526 '-default' => $selected_accno_full))
527 . $cgi->hidden('-name' => "previous_AP_amount_$i",
528 '-default' => $selected_accno_full);
531 NTI($cgi->popup_menu('-name' => "taxchart_$i",
532 '-id' => "taxchart_$i",
533 '-style' => 'width:200px',
534 '-values' => \@taxchart_values,
535 '-labels' => \%taxchart_labels,
536 '-default' => $selected_taxchart))
539 my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
542 NTI($cgi->popup_menu('-name' => "project_id_$i",
543 '-values' => \@project_values,
544 '-labels' => \%project_labels,
545 '-default' => $form->{"project_id_$i"} ));
549 <td>$selectAP_amount</td>
550 <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
551 <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
552 <td><input type="checkbox" name="korrektur_$i" value="1" "$korrektur"></td>
554 <td>$projectnumber</td>
562 ($form->{taxincluded})
563 ? $locale->text('Tax Included')
564 : $locale->text('Tax');
566 $form->{invtotal_unformatted} = $form->{invtotal};
567 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
570 NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
571 '-style' => 'width:400px',
572 '-values' => \@AP_values, '-labels' => \%AP_labels,
573 '-default' => $form->{APselected}));
581 <td>${APselected}</td>
582 <th align=left>$form->{invtotal}</th>
584 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
585 <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
587 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
600 <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
601 <td align=left>$notes</td>
609 <tr class=listheading>
610 <th class=listheading colspan=7>| . $locale->text('Payments') . qq|</th>
614 if ($form->{currency} eq $form->{defaultcurrency}) {
615 @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
617 @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
620 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
621 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
622 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
623 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
624 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
625 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
626 $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>";
631 map { print "$column_data{$_}\n" } @column_index;
639 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
640 for $i (1 .. $form->{paidaccounts}) {
646 NTI($cgi->popup_menu('-name' => "AP_paid_$i",
647 '-id' => "AP_paid_$i",
648 '-values' => \@AP_paid_values,
649 '-labels' => \%AP_paid_labels,
650 '-default' => $form->{"AP_paid_$i"}));
652 $totalpaid += $form->{"paid_$i"};
655 if ($form->{"paid_$i"}) {
657 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
659 $form->{"exchangerate_$i"} =
660 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
661 if ($form->{"exchangerate_$i"} == 0) {
662 $form->{"exchangerate_$i"} = "";
665 $exchangerate = qq| |;
666 if ($form->{currency} ne $form->{defaultcurrency}) {
667 if ($form->{"forex_$i"}) {
669 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
672 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
677 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
680 $column_data{"paid_$i"} =
681 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
682 $column_data{"AP_paid_$i"} =
683 qq|<td align=center>${selectAP_paid}</td>|;
684 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
685 $column_data{"datepaid_$i"} =
686 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)\">
687 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
688 $column_data{"source_$i"} =
689 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
690 $column_data{"memo_$i"} =
691 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
692 $column_data{"paid_project_id_$i"} =
694 . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
695 '-values' => \@project_values,
696 '-labels' => \%project_labels,
697 '-default' => $form->{"paid_project_id_$i"} ))
700 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
705 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
708 my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
714 <td align="center">| . $locale->text('Total') . qq|</td>
715 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
720 <td align="center">| . $locale->text('Missing amount') . qq|</td>
721 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
723 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
725 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
731 <td><hr size=3 noshade></td>
736 $lxdebug->leave_sub();
740 $lxdebug->enter_sub();
744 <input name=callback type=hidden value="$form->{callback}">
745 <input name="gldate" type="hidden" value="| . Q($form->{gldate}) . qq|">
747 <input type=hidden name=login value=$form->{login}>
748 <input type=hidden name=password value=$form->{password}>
750 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
751 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
757 if (!$form->{id} && $form->{draft_id}) {
758 print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
759 '-value' => 1, '-checked' => $form->{remove_draft},
761 qq| <label for="remove_draft">| .
762 $locale->text("Remove draft when posting") .
766 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
767 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
769 print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">|;
772 if ($form->{radier}) {
773 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
774 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">
778 # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
779 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
780 if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap') && !$form->{paid_1});
782 print qq| <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
783 <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|">
785 } elsif (($transdate > $closedto) && !$form->{id}) {
787 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
788 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
790 # button for saving history
791 if($form->{id} ne "") {
792 print qq| <input type="button" class="submit" onclick="set_history_window($form->{id});" name="history" id="history" value="| . $locale->text('history') . qq|">|;
794 # /button for saving history
795 # mark_as_paid button
796 if($form->{id} ne "") {
797 print qq|<input type="submit" class="submit" name="action" value="|
798 . $locale->text('mark as paid') . qq|">|;
800 # /mark_as_paid button
808 $lxdebug->leave_sub();
812 $lxdebug->enter_sub();
813 &mark_as_paid_common(\%myconfig,"ap");
814 $lxdebug->leave_sub();
818 $lxdebug->enter_sub();
822 $form->{invtotal} = 0;
824 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
825 qw(exchangerate creditlimit creditremaining);
827 @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
829 for $i (1 .. $form->{rowcount}) {
830 $form->{"amount_$i"} =
831 $form->parse_amount(\%myconfig, $form->{"amount_$i"});
832 $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
833 if ($form->{"amount_$i"}) {
836 if (!$form->{"korrektur_$i"}) {
837 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
839 if ($form->{taxincluded}) {
840 $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
842 $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
845 $form->{"tax_$i"} = 0;
848 $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
850 $totaltax += $form->{"tax_$i"};
851 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
855 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
857 map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
859 $form->{exchangerate} = $exchangerate
863 $form->check_exchangerate(
864 \%myconfig, $form->{currency}, $form->{transdate}, 'sell'
867 $form->{invdate} = $form->{transdate};
868 $save_AP = $form->{AP};
870 $form->{AP} = $save_AP;
872 $form->{rowcount} = $count + 1;
875 ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
877 for $i (1 .. $form->{paidaccounts}) {
878 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
881 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
882 } qw(paid exchangerate);
884 $totalpaid += $form->{"paid_$i"};
886 $form->{"exchangerate_$i"} = $exchangerate
888 $form->{"forex_$i"} = (
890 $form->check_exchangerate(
891 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
896 $form->{creditremaining} -=
897 ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
898 $form->{oldinvtotal});
899 $form->{oldinvtotal} = $form->{invtotal};
900 $form->{oldtotalpaid} = $totalpaid;
904 $lxdebug->leave_sub();
909 $lxdebug->enter_sub();
910 for $i (1 .. $form->{paidaccounts}) {
911 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
912 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
914 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
916 $form->error($locale->text('Cannot post payment for a closed period!'))
917 if ($datepaid <= $closedto);
919 if ($form->{currency} ne $form->{defaultcurrency}) {
920 $form->{"exchangerate_$i"} = $form->{exchangerate}
921 if ($invdate == $datepaid);
922 $form->isblank("exchangerate_$i",
923 $locale->text('Exchangerate for payment missing!'));
928 ($form->{AP}) = split /--/, $form->{AP};
929 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
930 $form->redirect($locale->text('Payment posted!'))
931 if (AP->post_payment(\%myconfig, \%$form));
932 $form->error($locale->text('Cannot post payment!'));
935 $lxdebug->leave_sub();
940 $lxdebug->enter_sub();
942 # check if there is a vendor, invoice and due date
943 $form->isblank("transdate", $locale->text("Invoice Date missing!"));
944 $form->isblank("duedate", $locale->text("Due Date missing!"));
945 $form->isblank("vendor", $locale->text('Vendor missing!'));
947 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
948 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
949 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
951 my $zero_amount_posting = 1;
952 for $i (1 .. $form->{rowcount}) {
953 if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
954 $zero_amount_posting = 0;
959 $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
961 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
962 if ($form->{currency} ne $form->{defaultcurrency});
965 for $i (1 .. $form->{paidaccounts}) {
966 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
967 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
969 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
971 $form->error($locale->text('Cannot post payment for a closed period!'))
972 if ($datepaid <= $closedto);
974 if ($form->{currency} ne $form->{defaultcurrency}) {
975 $form->{"exchangerate_$i"} = $form->{exchangerate}
976 if ($transdate == $datepaid);
977 $form->isblank("exchangerate_$i",
978 $locale->text('Exchangerate for payment missing!'));
984 # if old vendor ne vendor redo form
985 ($vendor) = split /--/, $form->{vendor};
986 if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
990 ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
991 ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
992 ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
993 $form->{AP}{amount_1} = $debitaccno;
994 $form->{AP}{payables} = $payablesaccno;
995 $form->{taxkey} = $taxkey;
998 $form->{id} = 0 if $form->{postasnew};
1000 if (AP->post_transaction(\%myconfig, \%$form)) {
1001 # saving the history
1002 if(!exists $form->{addition} && $form->{id} ne "") {
1003 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1004 $form->{addition} = "POSTED";
1005 $form->save_history($form->dbconnect(\%myconfig));
1007 # /saving the history
1008 remove_draft() if $form->{remove_draft};
1009 $form->redirect($locale->text('Transaction posted!'));
1011 $form->error($locale->text('Cannot post transaction!'));
1013 $lxdebug->leave_sub();
1017 $lxdebug->enter_sub();
1019 $form->{postasnew} = 1;
1020 # saving the history
1021 if(!exists $form->{addition} && $form->{id} ne "") {
1022 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1023 $form->{addition} = "POSTED AS NEW";
1024 $form->save_history($form->dbconnect(\%myconfig));
1026 # /saving the history
1029 $lxdebug->leave_sub();
1032 sub use_as_template {
1033 $lxdebug->enter_sub();
1035 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);
1036 $form->{paidaccounts} = 1;
1037 $form->{rowcount}--;
1038 $form->{invdate} = $form->current_date(\%myconfig);
1041 $lxdebug->leave_sub();
1045 $lxdebug->enter_sub();
1047 $form->{title} = $locale->text('Confirm!');
1051 delete $form->{header};
1056 <form method=post action=$form->{script}>
1059 foreach $key (keys %$form) {
1060 $form->{$key} =~ s/\"/"/g;
1061 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1065 <h2 class=confirm>$form->{title}</h2>
1068 . $locale->text('Are you sure you want to delete Transaction')
1069 . qq| $form->{invnumber}</h4>
1071 <input name=action class=submit type=submit value="|
1072 . $locale->text('Yes') . qq|">
1079 $lxdebug->leave_sub();
1083 $lxdebug->enter_sub();
1084 if (AP->delete_transaction(\%myconfig, \%$form, $spool)) {
1085 # saving the history
1086 if(!exists $form->{addition}) {
1087 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1088 $form->{addition} = "DELETED";
1089 $form->save_history($form->dbconnect(\%myconfig));
1091 # /saving the history
1092 $form->redirect($locale->text('Transaction deleted!'));
1094 $form->error($locale->text('Cannot delete transaction!'));
1096 $lxdebug->leave_sub();
1100 $lxdebug->enter_sub();
1102 # setup vendor selection
1103 $form->all_vc(\%myconfig, "vendor", "AP");
1105 if (@{ $form->{all_vendor} }) {
1106 map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
1107 @{ $form->{all_vendor} };
1108 $vendor = qq|<select name=vendor><option>\n$vendor\n</select>|;
1110 $vendor = qq|<input name=vendor size=35>|;
1114 if (@{ $form->{all_departments} }) {
1115 $form->{selectdepartment} = "<option>\n";
1118 $form->{selectdepartment} .=
1119 "<option>$_->{description}--$_->{id}\n"
1120 } (@{ $form->{all_departments} });
1125 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1126 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1128 | if $form->{selectdepartment};
1130 $form->{title} = $locale->text('AP Transactions');
1132 # use JavaScript Calendar or not
1133 $form->{jsscript} = 1;
1135 if ($form->{jsscript}) {
1137 # with JavaScript Calendar
1139 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1140 <input type=button name=transdatefrom id="trigger1" value=|
1141 . $locale->text('button') . qq|></td>
1144 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1145 <input type=button name=transdateto name=transdateto id="trigger2" value=|
1146 . $locale->text('button') . qq|></td>
1151 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
1152 "transdateto", "BL", "trigger2");
1155 # without JavaScript Calendar
1157 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1159 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1162 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1167 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1168 push(@values, $item->{"id"});
1169 $labels{$item->{"id"}} = $item->{"projectnumber"};
1172 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1173 '-labels' => \%labels));
1174 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
1176 $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
1177 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
1179 <body onLoad="$onload">
1181 <form method=post action=$form->{script}>
1185 <th class=listtop>$form->{title}</th>
1187 <tr height="5"></tr>
1192 <th align=right>| . $locale->text('Vendor') . qq|</th>
1193 <td colspan=3>$vendor</td>
1197 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
1198 <td colspan=3><input name=invnumber size=20></td>
1201 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
1202 <td colspan=3><input name=ordnumber size=20></td>
1205 <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
1206 <td colspan=3><input name=notes size=40></td>
1209 <th align="right">| . $locale->text("Project Number") . qq|</th>
1210 <td colspan="3">$projectnumber</td>
1213 <th align=right nowrap>| . $locale->text('From') . qq|</th>
1215 <th align=right>| . $locale->text('Bis') . qq|</th>
1218 <input type=hidden name=sort value=transdate>
1226 <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
1230 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
1231 <td nowrap>| . $locale->text('Open') . qq|</td>
1232 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
1233 <td nowrap>| . $locale->text('Closed') . qq|</td>
1236 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
1237 <td nowrap>| . $locale->text('ID') . qq|</td>
1238 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
1239 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
1240 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
1241 <td nowrap>| . $locale->text('Order Number') . qq|</td>
1244 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
1245 <td nowrap>| . $locale->text('Vendor') . qq|</td>
1246 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
1247 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
1248 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
1249 <td nowrap>| . $locale->text('Amount') . qq|</td>
1252 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
1253 <td nowrap>| . $locale->text('Tax') . qq|</td>
1254 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
1255 <td nowrap>| . $locale->text('Total') . qq|</td>
1256 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
1257 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
1260 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
1261 <td nowrap>| . $locale->text('Paid') . qq|</td>
1262 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
1263 <td nowrap>| . $locale->text('Due Date') . qq|</td>
1264 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
1265 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
1268 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
1269 <td nowrap>| . $locale->text('Notes') . qq|</td>
1270 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
1271 <td nowrap>| . $locale->text('Employee') . qq|</td>
1274 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
1275 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
1276 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
1277 <td nowrap>| . $locale->text('Project Number') . qq|</td>
1286 <td><hr size=3 noshade></td>
1293 <input type=hidden name=nextsub value=$form->{nextsub}>
1294 <input type=hidden name=login value=$form->{login}>
1295 <input type=hidden name=password value=$form->{password}>
1297 <input class=submit type=submit name=action value="|
1298 . $locale->text('Continue') . qq|">
1305 $lxdebug->leave_sub();
1308 sub ap_transactions {
1309 $lxdebug->enter_sub();
1311 $form->{vendor} = $form->unescape($form->{vendor});
1312 ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
1314 AP->ap_transactions(\%myconfig, \%$form);
1317 "$form->{script}?action=ap_transactions&login=$form->{login}&password=$form->{password}";
1320 if ($form->{vendor}) {
1321 $callback .= "&vendor=" . $form->escape($form->{vendor}, 1);
1322 $href .= "&vendor=" . $form->escape($form->{vendor});
1323 $option .= $locale->text('Vendor') . " : $form->{vendor}";
1325 if ($form->{department}) {
1326 $callback .= "&department=" . $form->escape($form->{department}, 1);
1327 $href .= "&department=" . $form->escape($form->{department});
1328 ($department) = split /--/, $form->{department};
1329 $option .= "\n<br>" if ($option);
1330 $option .= $locale->text('Department') . " : $department";
1332 if ($form->{invnumber}) {
1333 $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
1334 $href .= "&invnumber=" . $form->escape($form->{invnumber});
1335 $option .= "\n<br>" if ($option);
1336 $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
1338 if ($form->{ordnumber}) {
1339 $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
1340 $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
1341 $option .= "\n<br>" if ($option);
1342 $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
1344 if ($form->{notes}) {
1345 $callback .= "¬es=" . $form->escape($form->{notes}, 1);
1346 $href .= "¬es=" . $form->escape($form->{notes});
1347 $option .= "\n<br>" if $option;
1348 $option .= $locale->text('Notes') . " : $form->{notes}";
1351 if ($form->{transdatefrom}) {
1352 $callback .= "&transdatefrom=$form->{transdatefrom}";
1353 $href .= "&transdatefrom=$form->{transdatefrom}";
1354 $option .= "\n<br>" if ($option);
1356 $locale->text('From') . " "
1357 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1359 if ($form->{transdateto}) {
1360 $callback .= "&transdateto=$form->{transdateto}";
1361 $href .= "&transdateto=$form->{transdateto}";
1362 $option .= "\n<br>" if ($option);
1364 $locale->text('Bis') . " "
1365 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1367 if ($form->{open}) {
1368 $callback .= "&open=$form->{open}";
1369 $href .= "&open=$form->{open}";
1370 $option .= "\n<br>" if ($option);
1371 $option .= $locale->text('Open');
1373 if ($form->{closed}) {
1374 $callback .= "&closed=$form->{closed}";
1375 $href .= "&closed=$form->{closed}";
1376 $option .= "\n<br>" if ($option);
1377 $option .= $locale->text('Closed');
1379 if ($form->{globalproject_id}) {
1380 $callback .= "&globalproject_id=" . E($form->{globalproject_id});
1381 $href .= "&globalproject_id=" . E($form->{globalproject_id});
1385 qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
1386 due duedate notes employee globalprojectnumber);
1388 $form->{"l_type"} = "Y";
1390 foreach $item (@columns) {
1391 if ($form->{"l_$item"} eq "Y") {
1392 push @column_index, $item;
1394 # add column to href and callback
1395 $callback .= "&l_$item=Y";
1396 $href .= "&l_$item=Y";
1400 if ($form->{l_subtotal} eq 'Y') {
1401 $callback .= "&l_subtotal=Y";
1402 $href .= "&l_subtotal=Y";
1405 $column_header{id} =
1406 qq|<th><a class=listheading href=$href&sort=id>|
1407 . $locale->text('ID')
1409 $column_header{transdate} =
1410 qq|<th><a class=listheading href=$href&sort=transdate>|
1411 . $locale->text('Date')
1413 $column_header{type} =
1414 "<th class=\"listheading\">" . $locale->text('Type') . "</th>";
1415 $column_header{duedate} =
1416 qq|<th><a class=listheading href=$href&sort=duedate>|
1417 . $locale->text('Due Date')
1419 $column_header{due} =
1420 qq|<th class=listheading>| . $locale->text('Amount Due') . qq|</th>|;
1421 $column_header{invnumber} =
1422 qq|<th><a class=listheading href=$href&sort=invnumber>|
1423 . $locale->text('Invoice')
1425 $column_header{ordnumber} =
1426 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1427 . $locale->text('Order')
1429 $column_header{name} =
1430 qq|<th><a class=listheading href=$href&sort=name>|
1431 . $locale->text('Vendor')
1433 $column_header{netamount} =
1434 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1435 $column_header{tax} =
1436 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1437 $column_header{amount} =
1438 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1439 $column_header{paid} =
1440 qq|<th class=listheading>| . $locale->text('Paid') . qq|</th>|;
1441 $column_header{datepaid} =
1442 qq|<th><a class=listheading href=$href&sort=datepaid>|
1443 . $locale->text('Date Paid')
1445 $column_header{notes} =
1446 qq|<th class=listheading>| . $locale->text('Notes') . qq|</th>|;
1447 $column_header{employee} =
1448 "<th><a class=listheading href=$href&sort=employee>"
1449 . $locale->text('Employee') . "</th>";
1450 $column_header{globalprojectnumber} =
1451 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1453 $form->{title} = $locale->text('AP Transactions');
1462 <th class=listtop>$form->{title}</th>
1464 <tr height="5"></tr>
1471 <tr class=listheading>
1474 map { print "\n$column_header{$_}" } @column_index;
1480 # add sort and escape callback
1481 $form->{callback} = "$callback&sort=$form->{sort}";
1482 $callback = $form->escape($form->{callback});
1484 if (@{ $form->{AP} }) {
1485 $sameitem = $form->{AP}->[0]->{ $form->{sort} };
1488 # sums and tax on reports by Antonio Gallardo
1490 foreach $ap (@{ $form->{AP} }) {
1492 if ($form->{l_subtotal} eq 'Y') {
1493 if ($sameitem ne $ap->{ $form->{sort} }) {
1495 $sameitem = $ap->{ $form->{sort} };
1499 $column_data{netamount} =
1501 . $form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")
1503 $column_data{tax} = "<td align=right>"
1504 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount},
1507 $column_data{amount} =
1509 . $form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . "</td>";
1510 $column_data{paid} =
1512 . $form->format_amount(\%myconfig, $ap->{paid}, 2, " ") . "</td>";
1513 $column_data{due} = "<td align=right>"
1514 . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid},
1518 $totalnetamount += $ap->{netamount};
1519 $totalamount += $ap->{amount};
1520 $totalpaid += $ap->{paid};
1521 $totaldue += ($ap->{amount} - $ap->{paid});
1523 $subtotalnetamount += $ap->{netamount};
1524 $subtotalamount += $ap->{amount};
1525 $subtotalpaid += $ap->{paid};
1526 $subtotaldue += ($ap->{amount} - $ap->{paid});
1528 $column_data{transdate} = "<td>$ap->{transdate} </td>";
1529 $column_data{type} = "<td>" .
1530 ($ap->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
1531 $locale->text("AP Transaction (abbreviation)"))
1533 $column_data{duedate} = "<td>$ap->{duedate} </td>";
1534 $column_data{datepaid} = "<td>$ap->{datepaid} </td>";
1536 $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
1538 $column_data{invnumber} =
1539 qq|<td><a href="$module?action=edit&id=$ap->{id}&login=$form->{login}&password=$form->{password}&callback=$callback">$ap->{invnumber}</a></td>|;
1540 $column_data{id} = "<td>$ap->{id}</td>";
1541 $column_data{ordnumber} = "<td>$ap->{ordnumber} </td>";
1542 $column_data{name} = "<td>$ap->{name}</td>";
1543 $ap->{notes} =~ s/\r\n/<br>/g;
1544 $column_data{notes} = "<td>$ap->{notes} </td>";
1545 $column_data{employee} = "<td>$ap->{employee} </td>";
1546 $column_data{globalprojectnumber} =
1547 "<td>" . H($ap->{globalprojectnumber}) . "</td>";
1552 <tr class=listrow$i >
1555 map { print "\n$column_data{$_}" } @column_index;
1563 if ($form->{l_subtotal} eq 'Y') {
1569 <tr class=listtotal>
1572 map { $column_data{$_} = "<td> </td>" } @column_index;
1574 $column_data{netamount} =
1575 "<th class=listtotal align=right>"
1576 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1577 $column_data{tax} = "<th class=listtotal align=right>"
1578 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1581 $column_data{amount} =
1582 "<th class=listtotal align=right>"
1583 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1584 $column_data{paid} =
1585 "<th class=listtotal align=right>"
1586 . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
1588 "<th class=listtotal align=right>"
1589 . $form->format_amount(\%myconfig, $totaldue, 2, " ") . "</th>";
1591 map { print "$column_data{$_}\n" } @column_index;
1599 <td><hr size=3 noshade></td>
1604 <form method=post action=$form->{script}>
1606 <input name=callback type=hidden value="$form->{callback}">
1608 <input type=hidden name=login value=$form->{login}>
1609 <input type=hidden name=password value=$form->{password}>
1611 <input class=submit type=submit name=action value="|
1612 . $locale->text('AP Transaction') . qq|">
1614 <input class=submit type=submit name=action value="|
1615 . $locale->text('Vendor Invoice') . qq|">
1623 $lxdebug->leave_sub();
1627 $lxdebug->enter_sub();
1629 map { $column_data{$_} = "<td> </td>" } @column_index;
1631 $column_data{netamount} =
1632 "<th class=listsubtotal align=right>"
1633 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1635 $column_data{tax} = "<th class=listsubtotal align=right>"
1636 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1639 $column_data{amount} =
1640 "<th class=listsubtotal align=right>"
1641 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1642 $column_data{paid} =
1643 "<th class=listsubtotal align=right>"
1644 . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
1646 "<th class=listsubtotal align=right>"
1647 . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . "</th>";
1649 $subtotalnetamount = 0;
1650 $subtotalamount = 0;
1654 print "<tr class=listsubtotal>";
1656 map { print "\n$column_data{$_}" } @column_index;
1662 $lxdebug->leave_sub();
1666 $lxdebug->enter_sub();
1668 if (IS->has_storno(\%myconfig, $form, 'ap')) {
1669 $form->{title} = $locale->text("Cancel Accounts Payables Transaction");
1670 $form->error($locale->text("Transaction has already been cancelled!"));
1673 # negate amount/taxes
1674 for my $i (1 .. $form->{rowcount}) {
1675 $form->{"amount_$i"} *= -1;
1676 $form->{"tax_$i"} *= -1;
1680 for my $i (1 .. $form->{rowcount}) {
1681 for (qw(amount tax)) {
1682 $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"};
1686 $form->{storno} = 1;
1687 $form->{storno_id} = $form->{id};
1690 $form->{invnumber} = "Storno-" . $form->{invnumber};
1694 # saving the history
1695 if(!exists $form->{addition} && $form->{id} ne "") {
1696 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1697 $form->{addition} = "STORNO";
1698 $form->save_history($form->dbconnect(\%myconfig));
1700 # /saving the history
1702 $lxdebug->leave_sub();