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";
39 require "$form->{path}/common.pl";
46 $lxdebug->enter_sub();
48 $form->{title} = $locale->text('Add Vendor Invoice');
54 $lxdebug->leave_sub();
58 $lxdebug->enter_sub();
60 $form->{title} = $locale->text('Edit Vendor Invoice');
66 $lxdebug->leave_sub();
70 $lxdebug->enter_sub();
73 $form->{webdav} = $webdav;
76 $form->{jscalendar} = $jscalendar;
78 $form->create_links("AP", \%myconfig, "vendor");
80 #quote all_vendor Bug 133
81 foreach $ref (@{ $form->{all_vendor} }) {
82 $ref->{name} = $form->quote($ref->{name});
85 if ($form->{all_vendor}) {
86 unless ($form->{vendor_id}) {
87 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
90 if ($form->{payment_id}) {
91 $payment_id = $form->{payment_id};
93 if ($form->{language_id}) {
94 $language_id = $form->{language_id};
96 if ($form->{taxzone_id}) {
97 $taxzone_id = $form->{taxzone_id};
100 $cp_id = $form->{cp_id};
101 IR->get_vendor(\%myconfig, \%$form);
102 IR->retrieve_invoice(\%myconfig, \%$form);
103 $form->{cp_id} = $cp_id;
106 $form->{payment_id} = $payment_id;
109 $form->{language_id} = $language_id;
112 $form->{taxzone_id} = $taxzone_id;
116 @curr = split(/:/, $form->{currencies});
118 $form->{defaultcurrency} = $curr[0];
120 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
122 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
125 if (@{ $form->{all_vendor} }) {
126 $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
127 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
128 (@{ $form->{all_vendor} });
132 if ($form->{all_departments}) {
133 $form->{selectdepartment} = "<option>\n";
134 $form->{department} = "$form->{department}--$form->{department_id}";
137 $form->{selectdepartment} .=
138 "<option>$_->{description}--$_->{id}\n"
139 } (@{ $form->{all_departments} });
143 $form->{forex} = $form->{exchangerate};
144 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
146 foreach $key (keys %{ $form->{AP_links} }) {
148 foreach $ref (@{ $form->{AP_links}{$key} }) {
149 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
152 if ($key eq "AP_paid") {
153 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
154 $form->{"AP_paid_$i"} =
155 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
158 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
159 $form->{"datepaid_$i"} =
160 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
161 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
162 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
163 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
164 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
166 $form->{paidaccounts} = $i;
170 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
175 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
177 $form->{AP} = $form->{AP_1} unless $form->{id};
180 ($form->datetonum($form->{invdate}, \%myconfig) <=
181 $form->datetonum($form->{closedto}, \%myconfig));
183 $lxdebug->leave_sub();
186 sub prepare_invoice {
187 $lxdebug->enter_sub();
191 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
194 foreach $ref (@{ $form->{invoice_details} }) {
196 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
198 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
200 $decimalplaces = ($dec > 2) ? $dec : 2;
202 $form->{"sellprice_$i"} =
203 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
206 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
207 $dec_qty = length $dec_qty;
210 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
212 $form->{rowcount} = $i;
216 $lxdebug->leave_sub();
220 $lxdebug->enter_sub();
222 # set option selected
223 foreach $item (qw(AP vendor currency department)) {
224 $form->{"select$item"} =~ s/ selected//;
225 $form->{"select$item"} =~
226 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
230 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
232 #quote selectvendor Bug 133
233 $form->{"selectvendor"} = $form->quote($form->{"selectvendor"});
235 $form->{exchangerate} =
236 $form->format_amount(\%myconfig, $form->{exchangerate});
238 $form->{creditlimit} =
239 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
240 $form->{creditremaining} =
241 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
244 if ($form->{currency} ne $form->{defaultcurrency}) {
245 if ($form->{forex}) {
247 <th align=right nowrap>|
248 . $locale->text('Exchangerate') . qq|</th>
249 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
253 <th align=right nowrap>|
254 . $locale->text('Exchangerate') . qq|</th>
255 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
260 <input type=hidden name=forex value=$form->{forex}>
263 my @old_project_ids = ($form->{"globalproject_id"});
264 map({ push(@old_project_ids, $form->{"project_id_$_"})
265 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
267 $form->get_lists("contacts" => "ALL_CONTACTS",
268 "projects" => { "key" => "ALL_PROJECTS",
270 "old_id" => \@old_project_ids });
272 my (%labels, @values);
273 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
274 push(@values, $item->{"cp_id"});
275 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
276 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
279 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
280 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
284 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
285 push(@values, $item->{"id"});
286 $labels{$item->{"id"}} = $item->{"projectnumber"};
288 my $globalprojectnumber =
289 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
290 '-labels' => \%labels,
291 '-default' => $form->{"globalproject_id"}));
293 if (@{ $form->{TAXZONE} }) {
294 $form->{selecttaxzone} = "";
295 foreach $item (@{ $form->{TAXZONE} }) {
296 if ($item->{id} == $form->{taxzone_id}) {
297 $form->{selecttaxzone} .=
298 "<option value=$item->{id} selected>" . H($item->{description}) .
301 $form->{selecttaxzone} .=
302 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
307 $form->{selecttaxzone} =~ s/ selected//g;
308 if ($form->{taxzone_id} ne "") {
309 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
315 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
316 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
317 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
323 ($form->{selectvendor})
324 ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
325 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
329 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
330 <td colspan=3><select name=department>$form->{selectdepartment}</select>
331 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
334 | if $form->{selectdepartment};
336 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
338 # use JavaScript Calendar or not
339 $form->{jsscript} = $form->{jscalendar};
341 if ($form->{jsscript}) {
343 # with JavaScript Calendar
345 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
346 <td><input type=button name=invdate id="trigger1" value=|
347 . $locale->text('button') . qq|></td>
350 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
351 <td width="4"><input type=button name=duedate id="trigger2" value=|
352 . $locale->text('button') . qq|></td></td>
357 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
358 "duedate", "BL", "trigger2");
361 # without JavaScript Calendar
363 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
365 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
368 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
371 $form->write_trigger(\%myconfig, 2,
372 "orddate", "BL", "trigger_orddate",
373 "quodate", "BL", "trigger_quodate");
380 <form method=post action=$form->{script}>
382 <input type=hidden name=id value=$form->{id}>
383 <input type=hidden name=title value="$form->{title}">
384 <input type=hidden name=vc value="vendor">
385 <input type=hidden name=type value=$form->{type}>
386 <input type=hidden name=level value=$form->{level}>
388 <input type=hidden name=creditlimit value=$form->{creditlimit}>
389 <input type=hidden name=creditremaining value=$form->{creditremaining}>
391 <input type=hidden name=closedto value=$form->{closedto}>
392 <input type=hidden name=locked value=$form->{locked}>
394 <input type=hidden name=shipped value=$form->{shipped}>
395 <input type=hidden name=storno value=$form->{storno}>
396 <input type=hidden name=storno_id value=$form->{storno_id}>
400 <th class=listtop>$form->{title}</th>
410 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
411 <td colspan=3>$vendor</td>
413 <th align=richt nowrap>|
414 . $locale->text('Contact Person') . qq|</th>
415 <td colspan=3>$contact</td>
417 <input type=hidden name=vendor_id value=$form->{vendor_id}>
418 <input type=hidden name=oldvendor value="$form->{oldvendor}">
426 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
427 <td>$form->{creditlimit}</td>
429 <th nowrap>| . $locale->text('Remaining') . qq|</th>
430 <td class="plus$n">$form->{creditremaining}</td>
435 <th align=right>| . $locale->text('Record in') . qq|</th>
436 <td colspan=3><select name=AP>$form->{selectAP}</select></td>
437 <input type=hidden name=selectAP value="$form->{selectAP}">
442 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
443 <td><select name=currency>$form->{selectcurrency}</select></td>
451 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
452 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
455 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
459 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
463 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
464 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
465 <input type=hidden name=quonumber value="$form->{quonumber}">
468 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
469 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
470 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
473 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
474 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
475 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
478 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
479 <td>$globalprojectnumber</td>
490 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
491 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
492 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
493 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
494 <input type=hidden name=webdav value=$webdav>
496 <input type=hidden name=taxpart value="$form->{taxpart}">
497 <input type=hidden name=taxservice value="$form->{taxservice}">
499 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
502 foreach $item (split / /, $form->{taxaccounts}) {
504 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
505 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
509 $lxdebug->leave_sub();
513 $lxdebug->enter_sub();
515 $form->{invtotal} = $form->{invsubtotal};
517 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
520 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
523 $rows = ($rows > $introws) ? $rows : $introws;
525 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
527 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
529 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
532 if ($form->{taxaccounts}) {
534 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
535 . $locale->text('Tax Included') . qq|</b>
539 if (!$form->{taxincluded}) {
541 foreach $item (split / /, $form->{taxaccounts}) {
542 if ($form->{"${item}_base"}) {
543 $form->{invtotal} += $form->{"${item}_total"} =
545 $form->{"${item}_base"} * $form->{"${item}_rate"},
547 $form->{"${item}_total"} =
548 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
552 <th align=right>$form->{"${item}_description"}</th>
553 <td align=right>$form->{"${item}_total"}</td>
559 $form->{invsubtotal} =
560 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
564 <th align=right>| . $locale->text('Subtotal') . qq|</th>
565 <td align=right>$form->{invsubtotal}</td>
571 if ($form->{taxincluded}) {
572 foreach $item (split / /, $form->{taxaccounts}) {
573 if ($form->{"${item}_base"}) {
574 $form->{"${item}_total"} =
576 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
577 (1 + $form->{"${item}_rate"})
580 $form->{"${item}_base"} =
581 $form->round_amount($form->{"${item}_base"}, 2);
582 $form->{"${item}_netto"} =
584 ($form->{"${item}_base"} - $form->{"${item}_total"}),
586 $form->{"${item}_netto"} =
587 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
588 $form->{"${item}_total"} =
589 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
593 <th align=right>Enthaltene $form->{"${item}_description"}</th>
594 <td align=right>$form->{"${item}_total"}</td>
597 <th align=right>Nettobetrag</th>
598 <td align=right>$form->{"${item}_netto"}</td>
606 $form->{oldinvtotal} = $form->{invtotal};
608 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
612 <td colspan=$colspan>
613 <table cellspacing="0">
618 <th align=left>| . $locale->text('Notes') . qq|</th>
619 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
627 <td colspan=2 align=right width=100%>
634 <th align=right>| . $locale->text('Total') . qq|</th>
635 <td align=right>$form->{invtotal}</td>
647 <td><hr size=3 noshade></td>
650 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
653 <td align=left width=30%><b>Dateiname</b></td>
654 <td align=left width=70%><b>Webdavlink</b></td>
656 foreach $file (keys %{ $form->{WEBDAV} }) {
659 <td align=left>$file</td>
660 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
672 <input type=hidden name=jscalendar value=$form->{jscalendar}>
676 <td colspan=$colspan>
679 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
683 if ($form->{currency} eq $form->{defaultcurrency}) {
684 @column_index = qw(datepaid source memo paid AP_paid);
686 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
689 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
690 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
691 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
692 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
693 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
694 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
699 map { print "$column_data{$_}\n" } @column_index;
705 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
706 for $i (1 .. $form->{paidaccounts}) {
712 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
713 $form->{"selectAP_paid_$i"} =~
714 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
717 if ($form->{"paid_$i"}) {
719 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
721 $form->{"exchangerate_$i"} =
722 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
724 $exchangerate = qq| |;
725 if ($form->{currency} ne $form->{defaultcurrency}) {
726 if ($form->{"forex_$i"}) {
728 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
731 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
735 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
738 $column_data{"paid_$i"} =
739 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
740 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
741 $column_data{"AP_paid_$i"} =
742 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
743 $column_data{"datepaid_$i"} =
744 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
745 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
746 $column_data{"source_$i"} =
747 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
748 $column_data{"memo_$i"} =
749 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
751 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
756 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
760 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
761 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
762 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
767 <td><hr size=3 noshade></td>
773 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
774 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
777 print qq|<input class=submit type=submit name=action value="|
778 . $locale->text('Post Payment') . qq|">
780 print qq|<input class=submit type=submit name=action value="|
781 . $locale->text('Storno') . qq|">
782 | unless ($form->{storno});
783 if ($form->{radier}) {
785 <input class=submit type=submit name=action value="|
786 . $locale->text('Delete') . qq|">
789 print qq|<input class=submit type=submit name=action value="|
790 . $locale->text('Use As Template') . qq|">
795 print qq|<input class=submit type=submit name=action id=update_button value="|
796 . $locale->text('Update') . qq|">|;
798 if (!$form->{id} && ($invdate > $closedto)) {
799 print qq| <input class=submit type=submit name=action value="|
800 . $locale->text('Post') . qq|">|;
803 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
806 <input type=hidden name=rowcount value=$form->{rowcount}>
808 <input name=callback type=hidden value="$form->{callback}">
810 <input type=hidden name=path value=$form->{path}>
811 <input type=hidden name=login value=$form->{login}>
812 <input type=hidden name=password value=$form->{password}>
820 $lxdebug->leave_sub();
824 $lxdebug->enter_sub();
826 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
827 qw(exchangerate creditlimit creditremaining);
831 $form->{exchangerate} = $exchangerate
835 $form->check_exchangerate(
836 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
839 for $i (1 .. $form->{paidaccounts}) {
840 if ($form->{"paid_$i"}) {
843 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
844 } qw(paid exchangerate);
846 $form->{"exchangerate_$i"} = $exchangerate
848 $form->{"forex_$i"} = (
850 $form->check_exchangerate(
851 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
856 $i = $form->{rowcount};
857 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
859 if ( ($form->{"partnumber_$i"} eq "")
860 && ($form->{"description_$i"} eq "")
861 && ($form->{"partsgroup_$i"} eq "")) {
862 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
867 IR->retrieve_item(\%myconfig, \%$form);
869 my $rows = scalar @{ $form->{item_list} };
872 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
881 # override sellprice if there is one entered
882 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
884 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
885 qw(partnumber description unit);
887 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
888 keys %{ $form->{item_list}[0] };
890 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
892 ($dec) = ($s =~ /\.(\d+)/);
894 $decimalplaces = ($dec > 2) ? $dec : 2;
897 $form->{"sellprice_$i"} = $sellprice;
900 # if there is an exchange rate adjust sellprice
901 $form->{"sellprice_$i"} /= $exchangerate;
905 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
906 (1 - $form->{"discount_$i"} / 100);
907 $form->{creditremaining} -= $amount;
908 $form->{"sellprice_$i"} =
909 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
912 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
919 # ok, so this is a new part
920 # ask if it is a part or service item
922 if ( $form->{"partsgroup_$i"}
923 && ($form->{"partsnumber_$i"} eq "")
924 && ($form->{"description_$i"} eq "")) {
926 $form->{"discount_$i"} = "";
930 $form->{"id_$i"} = 0;
931 $form->{"unit_$i"} = $locale->text('ea');
938 $lxdebug->leave_sub();
942 $lxdebug->enter_sub();
944 if ($form->{storno}) {
945 $form->error($locale->text('Cannot storno storno invoice!'));
948 $form->{storno_id} = $form->{id};
951 $form->{invnumber} = "Storno zu " . $form->{invnumber};
954 $lxdebug->leave_sub();
958 sub use_as_template {
959 $lxdebug->enter_sub();
961 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);
962 $form->{paidaccounts} = 1;
964 $form->{invdate} = $form->current_date(\%myconfig);
967 $lxdebug->leave_sub();
971 $lxdebug->enter_sub();
972 for $i (1 .. $form->{paidaccounts}) {
973 if ($form->{"paid_$i"}) {
974 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
976 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
978 $form->error($locale->text('Cannot post payment for a closed period!'))
979 if ($datepaid <= $closedto);
981 if ($form->{currency} ne $form->{defaultcurrency}) {
982 $form->{"exchangerate_$i"} = $form->{exchangerate}
983 if ($invdate == $datepaid);
984 $form->isblank("exchangerate_$i",
985 $locale->text('Exchangerate for payment missing!'));
990 ($form->{AP}) = split /--/, $form->{AP};
991 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
992 $form->redirect($locale->text(' Payment posted!'))
993 if (IR->post_payment(\%myconfig, \%$form));
994 $form->error($locale->text('Cannot post payment!'));
997 $lxdebug->leave_sub();
1001 $lxdebug->enter_sub();
1003 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1004 $form->isblank("vendor", $locale->text('Vendor missing!'));
1006 # if the vendor changed get new values
1007 if (&check_name(vendor)) {
1014 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1015 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1017 $form->error($locale->text('Cannot post invoice for a closed period!'))
1018 if ($invdate <= $closedto);
1020 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1021 if ($form->{currency} ne $form->{defaultcurrency});
1023 for $i (1 .. $form->{paidaccounts}) {
1024 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1025 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1027 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1029 $form->error($locale->text('Cannot post payment for a closed period!'))
1030 if ($datepaid <= $closedto);
1032 if ($form->{currency} ne $form->{defaultcurrency}) {
1033 $form->{"exchangerate_$i"} = $form->{exchangerate}
1034 if ($invdate == $datepaid);
1035 $form->isblank("exchangerate_$i",
1036 $locale->text('Exchangerate for payment missing!'));
1041 ($form->{AP}) = split /--/, $form->{AP};
1042 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1044 $form->{id} = 0 if $form->{postasnew};
1048 $form->redirect( $locale->text('Invoice')
1049 . " $form->{invnumber} "
1050 . $locale->text('posted!'))
1051 if (IR->post_invoice(\%myconfig, \%$form));
1052 $form->error($locale->text('Cannot post invoice!'));
1054 $lxdebug->leave_sub();
1058 $lxdebug->enter_sub();
1065 <form method=post action=$form->{script}>
1068 # delete action variable
1069 map { delete $form->{$_} } qw(action header);
1071 foreach $key (keys %$form) {
1072 $form->{$key} =~ s/\"/"/g;
1073 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1077 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1080 . $locale->text('Are you sure you want to delete Invoice Number')
1081 . qq| $form->{invnumber}</h4>
1083 <input name=action class=submit type=submit value="|
1084 . $locale->text('Yes') . qq|">
1088 $lxdebug->leave_sub();
1092 $lxdebug->enter_sub();
1094 $form->redirect($locale->text('Invoice deleted!'))
1095 if (IR->delete_invoice(\%myconfig, \%$form));
1096 $form->error($locale->text('Cannot delete invoice!'));
1098 $lxdebug->leave_sub();