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();
61 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
62 #/show hhistory button
64 $form->{title} = $locale->text('Edit Vendor Invoice');
70 $lxdebug->leave_sub();
74 $lxdebug->enter_sub();
77 $form->{webdav} = $webdav;
80 $form->{jscalendar} = $jscalendar;
82 $form->create_links("AP", \%myconfig, "vendor");
84 #quote all_vendor Bug 133
85 foreach $ref (@{ $form->{all_vendor} }) {
86 $ref->{name} = $form->quote($ref->{name});
89 if ($form->{all_vendor}) {
90 unless ($form->{vendor_id}) {
91 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
94 if ($form->{payment_id}) {
95 $payment_id = $form->{payment_id};
97 if ($form->{language_id}) {
98 $language_id = $form->{language_id};
100 if ($form->{taxzone_id}) {
101 $taxzone_id = $form->{taxzone_id};
104 $cp_id = $form->{cp_id};
105 IR->get_vendor(\%myconfig, \%$form);
106 IR->retrieve_invoice(\%myconfig, \%$form);
107 $form->{cp_id} = $cp_id;
110 $form->{payment_id} = $payment_id;
113 $form->{language_id} = $language_id;
116 $form->{taxzone_id} = $taxzone_id;
120 @curr = split(/:/, $form->{currencies});
122 $form->{defaultcurrency} = $curr[0];
124 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
126 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
129 if (@{ $form->{all_vendor} }) {
130 $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
131 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
132 (@{ $form->{all_vendor} });
136 if ($form->{all_departments}) {
137 $form->{selectdepartment} = "<option>\n";
138 $form->{department} = "$form->{department}--$form->{department_id}";
141 $form->{selectdepartment} .=
142 "<option>$_->{description}--$_->{id}\n"
143 } (@{ $form->{all_departments} });
147 $form->{forex} = $form->{exchangerate};
148 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
150 foreach $key (keys %{ $form->{AP_links} }) {
152 foreach $ref (@{ $form->{AP_links}{$key} }) {
153 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
156 if ($key eq "AP_paid") {
157 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
158 $form->{"AP_paid_$i"} =
159 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
162 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
163 $form->{"datepaid_$i"} =
164 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
165 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
166 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
167 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
168 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
170 $form->{paidaccounts} = $i;
174 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
179 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
181 $form->{AP} = $form->{AP_1} unless $form->{id};
184 ($form->datetonum($form->{invdate}, \%myconfig) <=
185 $form->datetonum($form->{closedto}, \%myconfig));
187 $lxdebug->leave_sub();
190 sub prepare_invoice {
191 $lxdebug->enter_sub();
195 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
198 foreach $ref (@{ $form->{invoice_details} }) {
200 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
202 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
204 $decimalplaces = ($dec > 2) ? $dec : 2;
206 $form->{"sellprice_$i"} =
207 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
210 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
211 $dec_qty = length $dec_qty;
214 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
216 $form->{rowcount} = $i;
220 $lxdebug->leave_sub();
224 $lxdebug->enter_sub();
226 # set option selected
227 foreach $item (qw(AP vendor currency department)) {
228 $form->{"select$item"} =~ s/ selected//;
229 $form->{"select$item"} =~
230 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
234 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
236 #quote selectvendor Bug 133
237 $form->{"selectvendor"} = $form->quote($form->{"selectvendor"});
239 $form->{exchangerate} =
240 $form->format_amount(\%myconfig, $form->{exchangerate});
242 $form->{creditlimit} =
243 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
244 $form->{creditremaining} =
245 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
248 if ($form->{currency} ne $form->{defaultcurrency}) {
249 if ($form->{forex}) {
251 <th align=right nowrap>|
252 . $locale->text('Exchangerate') . qq|</th>
253 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
257 <th align=right nowrap>|
258 . $locale->text('Exchangerate') . qq|</th>
259 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
264 <input type=hidden name=forex value=$form->{forex}>
267 my @old_project_ids = ($form->{"globalproject_id"});
268 map({ push(@old_project_ids, $form->{"project_id_$_"})
269 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
271 $form->get_lists("contacts" => "ALL_CONTACTS",
272 "projects" => { "key" => "ALL_PROJECTS",
274 "old_id" => \@old_project_ids });
276 my (%labels, @values);
277 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
278 push(@values, $item->{"cp_id"});
279 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
280 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
283 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
284 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
288 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
289 push(@values, $item->{"id"});
290 $labels{$item->{"id"}} = $item->{"projectnumber"};
292 my $globalprojectnumber =
293 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
294 '-labels' => \%labels,
295 '-default' => $form->{"globalproject_id"}));
297 if (@{ $form->{TAXZONE} }) {
298 $form->{selecttaxzone} = "";
299 foreach $item (@{ $form->{TAXZONE} }) {
300 if ($item->{id} == $form->{taxzone_id}) {
301 $form->{selecttaxzone} .=
302 "<option value=$item->{id} selected>" . H($item->{description}) .
305 $form->{selecttaxzone} .=
306 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
311 $form->{selecttaxzone} =~ s/ selected//g;
312 if ($form->{taxzone_id} ne "") {
313 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
319 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
320 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
321 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
327 ($form->{selectvendor})
328 ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
329 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
333 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
334 <td colspan=3><select name=department>$form->{selectdepartment}</select>
335 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
338 | if $form->{selectdepartment};
340 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
342 # use JavaScript Calendar or not
343 $form->{jsscript} = $form->{jscalendar};
345 if ($form->{jsscript}) {
347 # with JavaScript Calendar
349 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
350 <td><input type=button name=invdate id="trigger1" value=|
351 . $locale->text('button') . qq|></td>
354 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
355 <td width="4"><input type=button name=duedate id="trigger2" value=|
356 . $locale->text('button') . qq|></td></td>
361 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
362 "duedate", "BL", "trigger2");
365 # without JavaScript Calendar
367 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
369 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
372 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
375 $form->write_trigger(\%myconfig, 2,
376 "orddate", "BL", "trigger_orddate",
377 "quodate", "BL", "trigger_quodate");
384 <form method=post action=$form->{script}>
386 <input type=hidden name=id value=$form->{id}>
387 <input type=hidden name=title value="$form->{title}">
388 <input type=hidden name=vc value="vendor">
389 <input type=hidden name=type value=$form->{type}>
390 <input type=hidden name=level value=$form->{level}>
392 <input type=hidden name=creditlimit value=$form->{creditlimit}>
393 <input type=hidden name=creditremaining value=$form->{creditremaining}>
395 <input type=hidden name=closedto value=$form->{closedto}>
396 <input type=hidden name=locked value=$form->{locked}>
398 <input type=hidden name=shipped value=$form->{shipped}>
399 <input type=hidden name=storno value=$form->{storno}>
400 <input type=hidden name=storno_id value=$form->{storno_id}>
404 <th class=listtop>$form->{title}</th>
414 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
415 <td colspan=3>$vendor</td>
417 <th align=richt nowrap>|
418 . $locale->text('Contact Person') . qq|</th>
419 <td colspan=3>$contact</td>
421 <input type=hidden name=vendor_id value=$form->{vendor_id}>
422 <input type=hidden name=oldvendor value="$form->{oldvendor}">
430 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
431 <td>$form->{creditlimit}</td>
433 <th nowrap>| . $locale->text('Remaining') . qq|</th>
434 <td class="plus$n">$form->{creditremaining}</td>
439 <th align=right>| . $locale->text('Record in') . qq|</th>
440 <td colspan=3><select name=AP>$form->{selectAP}</select></td>
441 <input type=hidden name=selectAP value="$form->{selectAP}">
446 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
447 <td><select name=currency>$form->{selectcurrency}</select></td>
455 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
456 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
459 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
463 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
467 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
468 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
469 <input type=hidden name=quonumber value="$form->{quonumber}">
472 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
473 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
474 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
477 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
478 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
479 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
482 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
483 <td>$globalprojectnumber</td>
494 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
495 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
496 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
497 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
498 <input type=hidden name=webdav value=$webdav>
500 <input type=hidden name=taxpart value="$form->{taxpart}">
501 <input type=hidden name=taxservice value="$form->{taxservice}">
503 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
506 foreach $item (split / /, $form->{taxaccounts}) {
508 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
509 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
513 $lxdebug->leave_sub();
517 $lxdebug->enter_sub();
519 $form->{invtotal} = $form->{invsubtotal};
521 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
524 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
527 $rows = ($rows > $introws) ? $rows : $introws;
529 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
531 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
533 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
536 if ($form->{taxaccounts}) {
538 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
539 . $locale->text('Tax Included') . qq|</b>
543 if (!$form->{taxincluded}) {
545 foreach $item (split / /, $form->{taxaccounts}) {
546 if ($form->{"${item}_base"}) {
547 $form->{invtotal} += $form->{"${item}_total"} =
549 $form->{"${item}_base"} * $form->{"${item}_rate"},
551 $form->{"${item}_total"} =
552 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
556 <th align=right>$form->{"${item}_description"}</th>
557 <td align=right>$form->{"${item}_total"}</td>
563 $form->{invsubtotal} =
564 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
568 <th align=right>| . $locale->text('Subtotal') . qq|</th>
569 <td align=right>$form->{invsubtotal}</td>
575 if ($form->{taxincluded}) {
576 foreach $item (split / /, $form->{taxaccounts}) {
577 if ($form->{"${item}_base"}) {
578 $form->{"${item}_total"} =
580 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
581 (1 + $form->{"${item}_rate"})
584 $form->{"${item}_base"} =
585 $form->round_amount($form->{"${item}_base"}, 2);
586 $form->{"${item}_netto"} =
588 ($form->{"${item}_base"} - $form->{"${item}_total"}),
590 $form->{"${item}_netto"} =
591 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
592 $form->{"${item}_total"} =
593 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
597 <th align=right>Enthaltene $form->{"${item}_description"}</th>
598 <td align=right>$form->{"${item}_total"}</td>
601 <th align=right>Nettobetrag</th>
602 <td align=right>$form->{"${item}_netto"}</td>
610 $form->{oldinvtotal} = $form->{invtotal};
612 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
616 <td colspan=$colspan>
617 <table cellspacing="0">
622 <th align=left>| . $locale->text('Notes') . qq|</th>
623 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
631 <td colspan=2 align=right width=100%>
638 <th align=right>| . $locale->text('Total') . qq|</th>
639 <td align=right>$form->{invtotal}</td>
651 <td><hr size=3 noshade></td>
654 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
657 <td align=left width=30%><b>Dateiname</b></td>
658 <td align=left width=70%><b>Webdavlink</b></td>
660 foreach $file (keys %{ $form->{WEBDAV} }) {
663 <td align=left>$file</td>
664 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
676 <input type=hidden name=jscalendar value=$form->{jscalendar}>
680 <td colspan=$colspan>
683 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
687 if ($form->{currency} eq $form->{defaultcurrency}) {
688 @column_index = qw(datepaid source memo paid AP_paid);
690 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
693 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
694 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
695 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
696 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
697 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
698 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
703 map { print "$column_data{$_}\n" } @column_index;
709 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
710 for $i (1 .. $form->{paidaccounts}) {
716 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
717 $form->{"selectAP_paid_$i"} =~
718 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
721 if ($form->{"paid_$i"}) {
723 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
725 $form->{"exchangerate_$i"} =
726 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
728 $exchangerate = qq| |;
729 if ($form->{currency} ne $form->{defaultcurrency}) {
730 if ($form->{"forex_$i"}) {
732 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
735 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
739 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
742 $column_data{"paid_$i"} =
743 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
744 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
745 $column_data{"AP_paid_$i"} =
746 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
747 $column_data{"datepaid_$i"} =
748 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
749 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
750 $column_data{"source_$i"} =
751 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
752 $column_data{"memo_$i"} =
753 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
755 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
760 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
764 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
765 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
766 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
771 <td><hr size=3 noshade></td>
777 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
778 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
781 print qq|<input class=submit type=submit name=action value="|
782 . $locale->text('Post Payment') . qq|">
784 print qq|<input class=submit type=submit name=action value="|
785 . $locale->text('Storno') . qq|">
786 | unless ($form->{storno});
787 if ($form->{radier}) {
789 <input class=submit type=submit name=action value="|
790 . $locale->text('Delete') . qq|">
793 print qq|<input class=submit type=submit name=action value="|
794 . $locale->text('Use As Template') . qq|">
799 print qq|<input class=submit type=submit name=action id=update_button value="|
800 . $locale->text('Update') . qq|">|;
802 if (!$form->{id} && ($invdate > $closedto)) {
803 print qq| <input class=submit type=submit name=action value="|
804 . $locale->text('Post') . qq|">|;
807 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
810 <input type=hidden name=rowcount value=$form->{rowcount}>
812 <input name=callback type=hidden value="$form->{callback}">
814 <input type=hidden name=path value=$form->{path}>
815 <input type=hidden name=login value=$form->{login}>
816 <input type=hidden name=password value=$form->{password}>
818 # button for saving history
819 if($form->{id} ne "") {
821 <input type=button class=submit onclick=set_history_window(|
823 . qq|); name=history id=history value=|
824 . $locale->text('history')
827 # /button for saving history
835 $lxdebug->leave_sub();
839 $lxdebug->enter_sub();
841 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
842 qw(exchangerate creditlimit creditremaining);
846 $form->{exchangerate} = $exchangerate
850 $form->check_exchangerate(
851 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
854 for $i (1 .. $form->{paidaccounts}) {
855 if ($form->{"paid_$i"}) {
858 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
859 } qw(paid exchangerate);
861 $form->{"exchangerate_$i"} = $exchangerate
863 $form->{"forex_$i"} = (
865 $form->check_exchangerate(
866 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
871 $i = $form->{rowcount};
872 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
874 if ( ($form->{"partnumber_$i"} eq "")
875 && ($form->{"description_$i"} eq "")
876 && ($form->{"partsgroup_$i"} eq "")) {
877 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
882 IR->retrieve_item(\%myconfig, \%$form);
884 my $rows = scalar @{ $form->{item_list} };
887 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
896 # override sellprice if there is one entered
897 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
899 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
900 qw(partnumber description unit);
902 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
903 keys %{ $form->{item_list}[0] };
905 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
907 ($dec) = ($s =~ /\.(\d+)/);
909 $decimalplaces = ($dec > 2) ? $dec : 2;
912 $form->{"sellprice_$i"} = $sellprice;
915 # if there is an exchange rate adjust sellprice
916 $form->{"sellprice_$i"} /= $exchangerate;
920 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
921 (1 - $form->{"discount_$i"} / 100);
922 $form->{creditremaining} -= $amount;
923 $form->{"sellprice_$i"} =
924 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
927 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
934 # ok, so this is a new part
935 # ask if it is a part or service item
937 if ( $form->{"partsgroup_$i"}
938 && ($form->{"partsnumber_$i"} eq "")
939 && ($form->{"description_$i"} eq "")) {
941 $form->{"discount_$i"} = "";
945 $form->{"id_$i"} = 0;
946 $form->{"unit_$i"} = $locale->text('ea');
953 $lxdebug->leave_sub();
957 $lxdebug->enter_sub();
959 if ($form->{storno}) {
960 $form->error($locale->text('Cannot storno storno invoice!'));
963 $form->{storno_id} = $form->{id};
966 $form->{invnumber} = "Storno zu " . $form->{invnumber};
969 $lxdebug->leave_sub();
973 sub use_as_template {
974 $lxdebug->enter_sub();
976 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);
977 $form->{paidaccounts} = 1;
979 $form->{invdate} = $form->current_date(\%myconfig);
982 $lxdebug->leave_sub();
986 $lxdebug->enter_sub();
987 for $i (1 .. $form->{paidaccounts}) {
988 if ($form->{"paid_$i"}) {
989 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
991 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
993 $form->error($locale->text('Cannot post payment for a closed period!'))
994 if ($datepaid <= $closedto);
996 if ($form->{currency} ne $form->{defaultcurrency}) {
997 $form->{"exchangerate_$i"} = $form->{exchangerate}
998 if ($invdate == $datepaid);
999 $form->isblank("exchangerate_$i",
1000 $locale->text('Exchangerate for payment missing!'));
1005 ($form->{AP}) = split /--/, $form->{AP};
1006 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1007 if (IR->post_payment(\%myconfig, \%$form)){
1009 if(!exists $form->{addition} && $form->{id} ne "") {
1010 # saving the history
1011 $form->{addition} = "PAYMENT POSTED";
1012 $form->save_history($form->dbconnect(\%myconfig));
1013 # /saving the history
1014 $form->redirect($locale->text(' Payment posted!'));
1017 $form->error($locale->text('Cannot post payment!'));
1020 $lxdebug->leave_sub();
1024 $lxdebug->enter_sub();
1026 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1027 $form->isblank("vendor", $locale->text('Vendor missing!'));
1029 # if the vendor changed get new values
1030 if (&check_name(vendor)) {
1037 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1038 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1040 $form->error($locale->text('Cannot post invoice for a closed period!'))
1041 if ($invdate <= $closedto);
1043 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1044 if ($form->{currency} ne $form->{defaultcurrency});
1046 for $i (1 .. $form->{paidaccounts}) {
1047 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1048 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1050 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1052 $form->error($locale->text('Cannot post payment for a closed period!'))
1053 if ($datepaid <= $closedto);
1055 if ($form->{currency} ne $form->{defaultcurrency}) {
1056 $form->{"exchangerate_$i"} = $form->{exchangerate}
1057 if ($invdate == $datepaid);
1058 $form->isblank("exchangerate_$i",
1059 $locale->text('Exchangerate for payment missing!'));
1064 ($form->{AP}) = split /--/, $form->{AP};
1065 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1067 $form->{id} = 0 if $form->{postasnew};
1071 if (IR->post_invoice(\%myconfig, \%$form)){
1072 # saving the history
1073 if(!exists $form->{addition} && $form->{id} ne "") {
1074 $form->{addition} = "POSTED";
1075 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1076 $form->save_history($form->dbconnect(\%myconfig));
1078 # /saving the history
1079 $form->redirect( $locale->text('Invoice')
1080 . " $form->{invnumber} "
1081 . $locale->text('posted!'));
1083 $form->error($locale->text('Cannot post invoice!'));
1085 $lxdebug->leave_sub();
1089 $lxdebug->enter_sub();
1095 <form method=post action=$form->{script}>
1098 # delete action variable
1099 map { delete $form->{$_} } qw(action header);
1101 foreach $key (keys %$form) {
1102 $form->{$key} =~ s/\"/"/g;
1103 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1107 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1110 . $locale->text('Are you sure you want to delete Invoice Number')
1111 . qq| $form->{invnumber}</h4>
1113 <input name=action class=submit type=submit value="|
1114 . $locale->text('Yes') . qq|">
1118 $lxdebug->leave_sub();
1122 $lxdebug->enter_sub();
1123 if (IR->delete_invoice(\%myconfig, \%$form)) {
1124 # saving the history
1125 if(!exists $form->{addition}) {
1126 $form->{addition} = "DELETED";
1127 $form->save_history($form->dbconnect(\%myconfig));
1129 # /saving the history
1130 $form->redirect($locale->text('Invoice deleted!'));
1132 $form->error($locale->text('Cannot delete invoice!'));
1134 $lxdebug->leave_sub();