1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger, Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # Inventory received module
32 #======================================================================
37 require "$form->{path}/io.pl";
38 require "$form->{path}/arap.pl";
45 $lxdebug->enter_sub();
47 $form->{title} = $locale->text('Add Vendor Invoice');
53 $lxdebug->leave_sub();
57 $lxdebug->enter_sub();
59 $form->{title} = $locale->text('Edit Vendor Invoice');
65 $lxdebug->leave_sub();
69 $lxdebug->enter_sub();
72 $form->{webdav} = $webdav;
75 $form->{jscalendar} = $jscalendar;
77 $form->create_links("AP", \%myconfig, "vendor");
79 #quote all_vendor Bug 133
80 foreach $ref (@{ $form->{all_vendor} }) {
81 $ref->{name} = $form->quote($ref->{name});
84 if ($form->{all_vendor}) {
85 unless ($form->{vendor_id}) {
86 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
89 if ($form->{payment_id}) {
90 $payment_id = $form->{payment_id};
92 if ($form->{language_id}) {
93 $language_id = $form->{language_id};
95 if ($form->{taxzone_id}) {
96 $taxzone_id = $form->{taxzone_id};
99 $cp_id = $form->{cp_id};
100 IR->get_vendor(\%myconfig, \%$form);
101 IR->retrieve_invoice(\%myconfig, \%$form);
102 $form->{cp_id} = $cp_id;
105 $form->{payment_id} = $payment_id;
108 $form->{language_id} = $language_id;
111 $form->{taxzone_id} = $taxzone_id;
115 @curr = split(/:/, $form->{currencies});
117 $form->{defaultcurrency} = $curr[0];
119 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
121 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
124 if (@{ $form->{all_vendor} }) {
125 $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
126 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
127 (@{ $form->{all_vendor} });
131 if ($form->{all_departments}) {
132 $form->{selectdepartment} = "<option>\n";
133 $form->{department} = "$form->{department}--$form->{department_id}";
136 $form->{selectdepartment} .=
137 "<option>$_->{description}--$_->{id}\n"
138 } (@{ $form->{all_departments} });
142 $form->{forex} = $form->{exchangerate};
143 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
145 foreach $key (keys %{ $form->{AP_links} }) {
147 foreach $ref (@{ $form->{AP_links}{$key} }) {
148 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
151 if ($key eq "AP_paid") {
152 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
153 $form->{"AP_paid_$i"} =
154 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
157 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
158 $form->{"datepaid_$i"} =
159 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
160 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
161 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
162 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
163 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
165 $form->{paidaccounts} = $i;
169 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
174 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
176 $form->{AP} = $form->{AP_1} unless $form->{id};
179 ($form->datetonum($form->{invdate}, \%myconfig) <=
180 $form->datetonum($form->{closedto}, \%myconfig));
182 $lxdebug->leave_sub();
185 sub prepare_invoice {
186 $lxdebug->enter_sub();
190 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
193 foreach $ref (@{ $form->{invoice_details} }) {
195 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
197 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
199 $decimalplaces = ($dec > 2) ? $dec : 2;
201 $form->{"sellprice_$i"} =
202 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
205 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
206 $dec_qty = length $dec_qty;
209 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
211 $form->{rowcount} = $i;
215 $lxdebug->leave_sub();
219 $lxdebug->enter_sub();
221 # set option selected
222 foreach $item (qw(AP vendor currency department)) {
223 $form->{"select$item"} =~ s/ selected//;
224 $form->{"select$item"} =~
225 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
229 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
231 #quote selectvendor Bug 133
232 $form->{"selectvendor"} = $form->quote($form->{"selectvendor"});
234 $form->{exchangerate} =
235 $form->format_amount(\%myconfig, $form->{exchangerate});
237 $form->{creditlimit} =
238 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
239 $form->{creditremaining} =
240 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
243 if ($form->{currency} ne $form->{defaultcurrency}) {
244 if ($form->{forex}) {
246 <th align=right nowrap>|
247 . $locale->text('Exchangerate') . qq|</th>
248 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
252 <th align=right nowrap>|
253 . $locale->text('Exchangerate') . qq|</th>
254 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
259 <input type=hidden name=forex value=$form->{forex}>
262 $form->get_lists("contacts" => "ALL_CONTACTS");
264 my (%labels, @values);
265 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
266 push(@values, $item->{"cp_id"});
267 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
268 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
271 $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
272 '-labels' => \%labels, '-default' => $form->{"cp_id"});
274 if (@{ $form->{TAXZONE} }) {
275 $form->{selecttaxzone} = "";
276 foreach $item (@{ $form->{TAXZONE} }) {
277 if ($item->{id} == $form->{taxzone_id}) {
278 $form->{selecttaxzone} .=
279 "<option value=$item->{id} selected>" . H($item->{description}) .
282 $form->{selecttaxzone} .=
283 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
288 $form->{selecttaxzone} =~ s/ selected//g;
289 if ($form->{taxzone_id} ne "") {
290 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
296 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
297 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
298 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
304 ($form->{selectvendor})
305 ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
306 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
310 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
311 <td colspan=3><select name=department>$form->{selectdepartment}</select>
312 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
315 | if $form->{selectdepartment};
317 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
319 # use JavaScript Calendar or not
320 $form->{jsscript} = $form->{jscalendar};
322 if ($form->{jsscript}) {
324 # with JavaScript Calendar
326 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
327 <td><input type=button name=invdate id="trigger1" value=|
328 . $locale->text('button') . qq|></td>
331 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
332 <td width="4"><input type=button name=duedate id="trigger2" value=|
333 . $locale->text('button') . qq|></td></td>
338 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
339 "duedate", "BL", "trigger2");
342 # without JavaScript Calendar
344 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
346 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
349 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
352 $form->write_trigger(\%myconfig, 2,
353 "orddate", "BL", "trigger_orddate",
354 "quodate", "BL", "trigger_quodate");
361 <form method=post action=$form->{script}>
363 <input type=hidden name=id value=$form->{id}>
364 <input type=hidden name=title value="$form->{title}">
365 <input type=hidden name=vc value="vendor">
366 <input type=hidden name=type value=$form->{type}>
367 <input type=hidden name=level value=$form->{level}>
369 <input type=hidden name=creditlimit value=$form->{creditlimit}>
370 <input type=hidden name=creditremaining value=$form->{creditremaining}>
372 <input type=hidden name=closedto value=$form->{closedto}>
373 <input type=hidden name=locked value=$form->{locked}>
375 <input type=hidden name=shipped value=$form->{shipped}>
376 <input type=hidden name=storno value=$form->{storno}>
377 <input type=hidden name=storno_id value=$form->{storno_id}>
381 <th class=listtop>$form->{title}</th>
391 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
392 <td colspan=3>$vendor</td>
394 <th align=richt nowrap>|
395 . $locale->text('Contact Person') . qq|</th>
396 <td colspan=3>$contact</td>
398 <input type=hidden name=vendor_id value=$form->{vendor_id}>
399 <input type=hidden name=oldvendor value="$form->{oldvendor}">
407 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
408 <td>$form->{creditlimit}</td>
410 <th nowrap>| . $locale->text('Remaining') . qq|</th>
411 <td class="plus$n">$form->{creditremaining}</td>
416 <th align=right>| . $locale->text('Record in') . qq|</th>
417 <td colspan=3><select name=AP>$form->{selectAP}</select></td>
418 <input type=hidden name=selectAP value="$form->{selectAP}">
423 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
424 <td><select name=currency>$form->{selectcurrency}</select></td>
432 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
433 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
436 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
440 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
444 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
445 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
446 <input type=hidden name=quonumber value="$form->{quonumber}">
449 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
450 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
451 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
454 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
455 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
456 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
467 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
468 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
469 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
470 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
471 <input type=hidden name=webdav value=$webdav>
473 <input type=hidden name=taxpart value="$form->{taxpart}">
474 <input type=hidden name=taxservice value="$form->{taxservice}">
476 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
479 foreach $item (split / /, $form->{taxaccounts}) {
481 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
482 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
486 $lxdebug->leave_sub();
490 $lxdebug->enter_sub();
492 $form->{invtotal} = $form->{invsubtotal};
494 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
497 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
500 $rows = ($rows > $introws) ? $rows : $introws;
502 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
504 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
506 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
509 if ($form->{taxaccounts}) {
511 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
512 . $locale->text('Tax Included') . qq|</b>
516 if (!$form->{taxincluded}) {
518 foreach $item (split / /, $form->{taxaccounts}) {
519 if ($form->{"${item}_base"}) {
520 $form->{invtotal} += $form->{"${item}_total"} =
522 $form->{"${item}_base"} * $form->{"${item}_rate"},
524 $form->{"${item}_total"} =
525 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
529 <th align=right>$form->{"${item}_description"}</th>
530 <td align=right>$form->{"${item}_total"}</td>
536 $form->{invsubtotal} =
537 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
541 <th align=right>| . $locale->text('Subtotal') . qq|</th>
542 <td align=right>$form->{invsubtotal}</td>
548 if ($form->{taxincluded}) {
549 foreach $item (split / /, $form->{taxaccounts}) {
550 if ($form->{"${item}_base"}) {
551 $form->{"${item}_total"} =
553 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
554 (1 + $form->{"${item}_rate"})
557 $form->{"${item}_base"} =
558 $form->round_amount($form->{"${item}_base"}, 2);
559 $form->{"${item}_netto"} =
561 ($form->{"${item}_base"} - $form->{"${item}_total"}),
563 $form->{"${item}_netto"} =
564 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
565 $form->{"${item}_total"} =
566 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
570 <th align=right>Enthaltene $form->{"${item}_description"}</th>
571 <td align=right>$form->{"${item}_total"}</td>
574 <th align=right>Nettobetrag</th>
575 <td align=right>$form->{"${item}_netto"}</td>
583 $form->{oldinvtotal} = $form->{invtotal};
585 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
589 <td colspan=$colspan>
590 <table cellspacing="0">
595 <th align=left>| . $locale->text('Notes') . qq|</th>
596 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
604 <td colspan=2 align=right width=100%>
611 <th align=right>| . $locale->text('Total') . qq|</th>
612 <td align=right>$form->{invtotal}</td>
624 <td><hr size=3 noshade></td>
627 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
630 <td align=left width=30%><b>Dateiname</b></td>
631 <td align=left width=70%><b>Webdavlink</b></td>
633 foreach $file (keys %{ $form->{WEBDAV} }) {
636 <td align=left>$file</td>
637 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
649 <input type=hidden name=jscalendar value=$form->{jscalendar}>
653 <td colspan=$colspan>
656 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
660 if ($form->{currency} eq $form->{defaultcurrency}) {
661 @column_index = qw(datepaid source memo paid AP_paid);
663 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
666 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
667 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
668 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
669 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
670 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
671 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
676 map { print "$column_data{$_}\n" } @column_index;
682 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
683 for $i (1 .. $form->{paidaccounts}) {
689 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
690 $form->{"selectAP_paid_$i"} =~
691 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
694 if ($form->{"paid_$i"}) {
696 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
698 $form->{"exchangerate_$i"} =
699 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
701 $exchangerate = qq| |;
702 if ($form->{currency} ne $form->{defaultcurrency}) {
703 if ($form->{"forex_$i"}) {
705 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
708 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
712 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
715 $column_data{"paid_$i"} =
716 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
717 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
718 $column_data{"AP_paid_$i"} =
719 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
720 $column_data{"datepaid_$i"} =
721 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
722 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
723 $column_data{"source_$i"} =
724 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
725 $column_data{"memo_$i"} =
726 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
728 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
733 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
737 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
738 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
739 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
744 <td><hr size=3 noshade></td>
750 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
751 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
754 print qq|<input class=submit type=submit name=action value="|
755 . $locale->text('Post Payment') . qq|">
757 print qq|<input class=submit type=submit name=action value="|
758 . $locale->text('Storno') . qq|">
759 | unless ($form->{storno});
760 if ($form->{radier}) {
762 <input class=submit type=submit name=action value="|
763 . $locale->text('Delete') . qq|">
766 print qq|<input class=submit type=submit name=action value="|
767 . $locale->text('Use As Template') . qq|">
772 print qq|<input class=submit type=submit name=action id=update_button value="|
773 . $locale->text('Update') . qq|">|;
775 if (!$form->{id} && ($invdate > $closedto)) {
776 print qq| <input class=submit type=submit name=action value="|
777 . $locale->text('Post') . qq|">|;
780 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
783 <input type=hidden name=rowcount value=$form->{rowcount}>
785 <input name=callback type=hidden value="$form->{callback}">
787 <input type=hidden name=path value=$form->{path}>
788 <input type=hidden name=login value=$form->{login}>
789 <input type=hidden name=password value=$form->{password}>
797 $lxdebug->leave_sub();
801 $lxdebug->enter_sub();
803 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
804 qw(exchangerate creditlimit creditremaining);
810 $form->{exchangerate} = $exchangerate
814 $form->check_exchangerate(
815 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
818 for $i (1 .. $form->{paidaccounts}) {
819 if ($form->{"paid_$i"}) {
822 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
823 } qw(paid exchangerate);
825 $form->{"exchangerate_$i"} = $exchangerate
827 $form->{"forex_$i"} = (
829 $form->check_exchangerate(
830 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
835 $i = $form->{rowcount};
836 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
838 if ( ($form->{"partnumber_$i"} eq "")
839 && ($form->{"description_$i"} eq "")
840 && ($form->{"partsgroup_$i"} eq "")) {
841 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
846 IR->retrieve_item(\%myconfig, \%$form);
848 my $rows = scalar @{ $form->{item_list} };
851 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
860 # override sellprice if there is one entered
861 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
863 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
864 qw(partnumber description unit);
866 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
867 keys %{ $form->{item_list}[0] };
869 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
871 ($dec) = ($s =~ /\.(\d+)/);
873 $decimalplaces = ($dec > 2) ? $dec : 2;
876 $form->{"sellprice_$i"} = $sellprice;
879 # if there is an exchange rate adjust sellprice
880 $form->{"sellprice_$i"} /= $exchangerate;
884 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
885 (1 - $form->{"discount_$i"} / 100);
886 $form->{creditremaining} -= $amount;
887 $form->{"sellprice_$i"} =
888 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
891 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
898 # ok, so this is a new part
899 # ask if it is a part or service item
901 if ( $form->{"partsgroup_$i"}
902 && ($form->{"partsnumber_$i"} eq "")
903 && ($form->{"description_$i"} eq "")) {
905 $form->{"discount_$i"} = "";
909 $form->{"id_$i"} = 0;
910 $form->{"unit_$i"} = $locale->text('ea');
917 $lxdebug->leave_sub();
921 $lxdebug->enter_sub();
923 if ($form->{storno}) {
924 $form->error($locale->text('Cannot storno storno invoice!'));
927 $form->{storno_id} = $form->{id};
930 $form->{invnumber} = "Storno zu " . $form->{invnumber};
933 $lxdebug->leave_sub();
937 sub use_as_template {
938 $lxdebug->enter_sub();
940 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);
941 $form->{paidaccounts} = 1;
943 $form->{invdate} = $form->current_date(\%myconfig);
946 $lxdebug->leave_sub();
950 $lxdebug->enter_sub();
951 for $i (1 .. $form->{paidaccounts}) {
952 if ($form->{"paid_$i"}) {
953 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
955 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
957 $form->error($locale->text('Cannot post payment for a closed period!'))
958 if ($datepaid <= $closedto);
960 if ($form->{currency} ne $form->{defaultcurrency}) {
961 $form->{"exchangerate_$i"} = $form->{exchangerate}
962 if ($invdate == $datepaid);
963 $form->isblank("exchangerate_$i",
964 $locale->text('Exchangerate for payment missing!'));
969 ($form->{AP}) = split /--/, $form->{AP};
970 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
971 $form->redirect($locale->text(' Payment posted!'))
972 if (IR->post_payment(\%myconfig, \%$form));
973 $form->error($locale->text('Cannot post payment!'));
976 $lxdebug->leave_sub();
980 $lxdebug->enter_sub();
982 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
983 $form->isblank("vendor", $locale->text('Vendor missing!'));
985 # if the vendor changed get new values
986 if (&check_name(vendor)) {
993 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
994 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
996 $form->error($locale->text('Cannot post invoice for a closed period!'))
997 if ($invdate <= $closedto);
999 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1000 if ($form->{currency} ne $form->{defaultcurrency});
1002 for $i (1 .. $form->{paidaccounts}) {
1003 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1004 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1006 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1008 $form->error($locale->text('Cannot post payment for a closed period!'))
1009 if ($datepaid <= $closedto);
1011 if ($form->{currency} ne $form->{defaultcurrency}) {
1012 $form->{"exchangerate_$i"} = $form->{exchangerate}
1013 if ($invdate == $datepaid);
1014 $form->isblank("exchangerate_$i",
1015 $locale->text('Exchangerate for payment missing!'));
1020 ($form->{AP}) = split /--/, $form->{AP};
1021 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1023 $form->{id} = 0 if $form->{postasnew};
1027 $form->redirect( $locale->text('Invoice')
1028 . " $form->{invnumber} "
1029 . $locale->text('posted!'))
1030 if (IR->post_invoice(\%myconfig, \%$form));
1031 $form->error($locale->text('Cannot post invoice!'));
1033 $lxdebug->leave_sub();
1037 $lxdebug->enter_sub();
1044 <form method=post action=$form->{script}>
1047 # delete action variable
1048 map { delete $form->{$_} } qw(action header);
1050 foreach $key (keys %$form) {
1051 $form->{$key} =~ s/\"/"/g;
1052 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1056 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1059 . $locale->text('Are you sure you want to delete Invoice Number')
1060 . qq| $form->{invnumber}</h4>
1062 <input name=action class=submit type=submit value="|
1063 . $locale->text('Yes') . qq|">
1067 $lxdebug->leave_sub();
1071 $lxdebug->enter_sub();
1073 $form->redirect($locale->text('Invoice deleted!'))
1074 if (IR->delete_invoice(\%myconfig, \%$form));
1075 $form->error($locale->text('Cannot delete invoice!'));
1077 $lxdebug->leave_sub();