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"} |
557 . $form->{"${item}_rate"} * 100 .qq|%</th>
558 <td align=right>$form->{"${item}_total"}</td>
564 $form->{invsubtotal} =
565 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
569 <th align=right>| . $locale->text('Subtotal') . qq|</th>
570 <td align=right>$form->{invsubtotal}</td>
576 if ($form->{taxincluded}) {
577 foreach $item (split / /, $form->{taxaccounts}) {
578 if ($form->{"${item}_base"}) {
579 $form->{"${item}_total"} =
581 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
582 (1 + $form->{"${item}_rate"})
585 $form->{"${item}_base"} =
586 $form->round_amount($form->{"${item}_base"}, 2);
587 $form->{"${item}_netto"} =
589 ($form->{"${item}_base"} - $form->{"${item}_total"}),
591 $form->{"${item}_netto"} =
592 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
593 $form->{"${item}_total"} =
594 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
598 <th align=right>Enthaltene $form->{"${item}_description"} |
599 . $form->{"${item}_rate"} * 100 .qq|%</th>
600 <td align=right>$form->{"${item}_total"}</td>
603 <th align=right>Nettobetrag</th>
604 <td align=right>$form->{"${item}_netto"}</td>
612 $form->{oldinvtotal} = $form->{invtotal};
614 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
618 <td colspan=$colspan>
619 <table cellspacing="0">
624 <th align=left>| . $locale->text('Notes') . qq|</th>
625 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
633 <td colspan=2 align=right width=100%>
640 <th align=right>| . $locale->text('Total') . qq|</th>
641 <td align=right>$form->{invtotal}</td>
653 <td><hr size=3 noshade></td>
656 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
659 <td align=left width=30%><b>Dateiname</b></td>
660 <td align=left width=70%><b>Webdavlink</b></td>
662 foreach $file (keys %{ $form->{WEBDAV} }) {
665 <td align=left>$file</td>
666 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
678 <input type=hidden name=jscalendar value=$form->{jscalendar}>
682 <td colspan=$colspan>
685 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
689 if ($form->{currency} eq $form->{defaultcurrency}) {
690 @column_index = qw(datepaid source memo paid AP_paid);
692 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
695 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
696 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
697 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
698 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
699 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
700 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
705 map { print "$column_data{$_}\n" } @column_index;
711 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
712 for $i (1 .. $form->{paidaccounts}) {
718 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
719 $form->{"selectAP_paid_$i"} =~
720 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
723 if ($form->{"paid_$i"}) {
725 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
727 $form->{"exchangerate_$i"} =
728 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
730 $exchangerate = qq| |;
731 if ($form->{currency} ne $form->{defaultcurrency}) {
732 if ($form->{"forex_$i"}) {
734 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
737 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
741 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
744 $column_data{"paid_$i"} =
745 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
746 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
747 $column_data{"AP_paid_$i"} =
748 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
749 $column_data{"datepaid_$i"} =
750 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
751 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
752 $column_data{"source_$i"} =
753 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
754 $column_data{"memo_$i"} =
755 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
757 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
762 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
766 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
767 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
768 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
773 <td><hr size=3 noshade></td>
779 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
780 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
783 print qq|<input class=submit type=submit name=action value="|
784 . $locale->text('Post Payment') . qq|">
786 print qq|<input class=submit type=submit name=action value="|
787 . $locale->text('Storno') . qq|">
788 | unless ($form->{storno});
789 if ($form->{radier}) {
791 <input class=submit type=submit name=action value="|
792 . $locale->text('Delete') . qq|">
795 print qq|<input class=submit type=submit name=action value="|
796 . $locale->text('Use As Template') . qq|">
801 print qq|<input class=submit type=submit name=action id=update_button value="|
802 . $locale->text('Update') . qq|">|;
804 if (!$form->{id} && ($invdate > $closedto)) {
805 print qq| <input class=submit type=submit name=action value="|
806 . $locale->text('Post') . qq|">|;
809 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
812 <input type=hidden name=rowcount value=$form->{rowcount}>
814 <input name=callback type=hidden value="$form->{callback}">
816 <input type=hidden name=path value=$form->{path}>
817 <input type=hidden name=login value=$form->{login}>
818 <input type=hidden name=password value=$form->{password}>
820 # button for saving history
821 if($form->{id} ne "") {
823 <input type=button class=submit onclick=set_history_window(|
825 . qq|); name=history id=history value=|
826 . $locale->text('history')
829 # /button for saving history
837 $lxdebug->leave_sub();
841 $lxdebug->enter_sub();
843 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
844 qw(exchangerate creditlimit creditremaining);
848 $form->{exchangerate} = $exchangerate
852 $form->check_exchangerate(
853 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
856 for $i (1 .. $form->{paidaccounts}) {
857 if ($form->{"paid_$i"}) {
860 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
861 } qw(paid exchangerate);
863 $form->{"exchangerate_$i"} = $exchangerate
865 $form->{"forex_$i"} = (
867 $form->check_exchangerate(
868 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
873 $i = $form->{rowcount};
874 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
876 if ( ($form->{"partnumber_$i"} eq "")
877 && ($form->{"description_$i"} eq "")
878 && ($form->{"partsgroup_$i"} eq "")) {
879 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
884 IR->retrieve_item(\%myconfig, \%$form);
886 my $rows = scalar @{ $form->{item_list} };
889 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
898 # override sellprice if there is one entered
899 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
901 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
902 qw(partnumber description unit);
904 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
905 keys %{ $form->{item_list}[0] };
907 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
909 ($dec) = ($s =~ /\.(\d+)/);
911 $decimalplaces = ($dec > 2) ? $dec : 2;
914 $form->{"sellprice_$i"} = $sellprice;
917 # if there is an exchange rate adjust sellprice
918 $form->{"sellprice_$i"} /= $exchangerate;
922 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
923 (1 - $form->{"discount_$i"} / 100);
924 $form->{creditremaining} -= $amount;
925 $form->{"sellprice_$i"} =
926 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
929 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
936 # ok, so this is a new part
937 # ask if it is a part or service item
939 if ( $form->{"partsgroup_$i"}
940 && ($form->{"partsnumber_$i"} eq "")
941 && ($form->{"description_$i"} eq "")) {
943 $form->{"discount_$i"} = "";
947 $form->{"id_$i"} = 0;
948 $form->{"unit_$i"} = $locale->text('ea');
955 $lxdebug->leave_sub();
959 $lxdebug->enter_sub();
961 if ($form->{storno}) {
962 $form->error($locale->text('Cannot storno storno invoice!'));
965 $form->{storno_id} = $form->{id};
968 $form->{invnumber} = "Storno zu " . $form->{invnumber};
971 $lxdebug->leave_sub();
975 sub use_as_template {
976 $lxdebug->enter_sub();
978 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);
979 $form->{paidaccounts} = 1;
981 $form->{invdate} = $form->current_date(\%myconfig);
984 $lxdebug->leave_sub();
988 $lxdebug->enter_sub();
989 for $i (1 .. $form->{paidaccounts}) {
990 if ($form->{"paid_$i"}) {
991 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
993 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
995 $form->error($locale->text('Cannot post payment for a closed period!'))
996 if ($datepaid <= $closedto);
998 if ($form->{currency} ne $form->{defaultcurrency}) {
999 $form->{"exchangerate_$i"} = $form->{exchangerate}
1000 if ($invdate == $datepaid);
1001 $form->isblank("exchangerate_$i",
1002 $locale->text('Exchangerate for payment missing!'));
1007 ($form->{AP}) = split /--/, $form->{AP};
1008 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1009 if (IR->post_payment(\%myconfig, \%$form)){
1011 if(!exists $form->{addition} && $form->{id} ne "") {
1012 # saving the history
1013 $form->{addition} = "PAYMENT POSTED";
1014 $form->save_history($form->dbconnect(\%myconfig));
1015 # /saving the history
1016 $form->redirect($locale->text(' Payment posted!'));
1019 $form->error($locale->text('Cannot post payment!'));
1022 $lxdebug->leave_sub();
1026 $lxdebug->enter_sub();
1028 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1029 $form->isblank("vendor", $locale->text('Vendor missing!'));
1031 # if the vendor changed get new values
1032 if (&check_name(vendor)) {
1039 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1040 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1042 $form->error($locale->text('Cannot post invoice for a closed period!'))
1043 if ($invdate <= $closedto);
1045 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1046 if ($form->{currency} ne $form->{defaultcurrency});
1048 for $i (1 .. $form->{paidaccounts}) {
1049 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1050 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1052 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1054 $form->error($locale->text('Cannot post payment for a closed period!'))
1055 if ($datepaid <= $closedto);
1057 if ($form->{currency} ne $form->{defaultcurrency}) {
1058 $form->{"exchangerate_$i"} = $form->{exchangerate}
1059 if ($invdate == $datepaid);
1060 $form->isblank("exchangerate_$i",
1061 $locale->text('Exchangerate for payment missing!'));
1066 ($form->{AP}) = split /--/, $form->{AP};
1067 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1069 $form->{id} = 0 if $form->{postasnew};
1073 if (IR->post_invoice(\%myconfig, \%$form)){
1074 # saving the history
1075 if(!exists $form->{addition} && $form->{id} ne "") {
1076 $form->{addition} = "POSTED";
1077 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1078 $form->save_history($form->dbconnect(\%myconfig));
1080 # /saving the history
1081 $form->redirect( $locale->text('Invoice')
1082 . " $form->{invnumber} "
1083 . $locale->text('posted!'));
1085 $form->error($locale->text('Cannot post invoice!'));
1087 $lxdebug->leave_sub();
1091 $lxdebug->enter_sub();
1097 <form method=post action=$form->{script}>
1100 # delete action variable
1101 map { delete $form->{$_} } qw(action header);
1103 foreach $key (keys %$form) {
1104 $form->{$key} =~ s/\"/"/g;
1105 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1109 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1112 . $locale->text('Are you sure you want to delete Invoice Number')
1113 . qq| $form->{invnumber}</h4>
1115 <input name=action class=submit type=submit value="|
1116 . $locale->text('Yes') . qq|">
1120 $lxdebug->leave_sub();
1124 $lxdebug->enter_sub();
1125 if (IR->delete_invoice(\%myconfig, \%$form)) {
1126 # saving the history
1127 if(!exists $form->{addition}) {
1128 $form->{addition} = "DELETED";
1129 $form->save_history($form->dbconnect(\%myconfig));
1131 # /saving the history
1132 $form->redirect($locale->text('Invoice deleted!'));
1134 $form->error($locale->text('Cannot delete invoice!'));
1136 $lxdebug->leave_sub();