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 #======================================================================
38 require "$form->{path}/io.pl";
39 require "$form->{path}/arap.pl";
40 require "$form->{path}/common.pl";
41 require "bin/mozilla/drafts.pl";
48 $lxdebug->enter_sub();
50 return $lxdebug->leave_sub() if (load_draft_maybe());
52 $form->{title} = $locale->text('Add Vendor Invoice');
58 $lxdebug->leave_sub();
62 $lxdebug->enter_sub();
65 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
66 #/show hhistory button
68 $form->{title} = $locale->text('Edit Vendor Invoice');
74 $lxdebug->leave_sub();
78 $lxdebug->enter_sub();
81 $form->{webdav} = $webdav;
84 $form->{jscalendar} = $jscalendar;
86 $form->create_links("AP", \%myconfig, "vendor");
88 #quote all_vendor Bug 133
89 foreach $ref (@{ $form->{all_vendor} }) {
90 $ref->{name} = $form->quote($ref->{name});
93 if ($form->{all_vendor}) {
94 unless ($form->{vendor_id}) {
95 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
98 if ($form->{payment_id}) {
99 $payment_id = $form->{payment_id};
101 if ($form->{language_id}) {
102 $language_id = $form->{language_id};
104 if ($form->{taxzone_id}) {
105 $taxzone_id = $form->{taxzone_id};
108 $cp_id = $form->{cp_id};
109 IR->get_vendor(\%myconfig, \%$form);
110 IR->retrieve_invoice(\%myconfig, \%$form);
111 $form->{cp_id} = $cp_id;
114 $form->{payment_id} = $payment_id;
117 $form->{language_id} = $language_id;
120 $form->{taxzone_id} = $taxzone_id;
124 @curr = split(/:/, $form->{currencies});
126 $form->{defaultcurrency} = $curr[0];
128 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
130 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
133 if (@{ $form->{all_vendor} }) {
134 $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
135 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
136 (@{ $form->{all_vendor} });
140 if ($form->{all_departments}) {
141 $form->{selectdepartment} = "<option>\n";
142 $form->{department} = "$form->{department}--$form->{department_id}";
145 $form->{selectdepartment} .=
146 "<option>$_->{description}--$_->{id}\n"
147 } (@{ $form->{all_departments} });
151 $form->{forex} = $form->{exchangerate};
152 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
154 foreach $key (keys %{ $form->{AP_links} }) {
156 foreach $ref (@{ $form->{AP_links}{$key} }) {
157 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
160 if ($key eq "AP_paid") {
161 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
162 $form->{"AP_paid_$i"} =
163 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
166 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
167 $form->{"datepaid_$i"} =
168 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
169 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
170 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
171 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
172 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
174 $form->{paidaccounts} = $i;
178 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
183 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
185 $form->{AP} = $form->{AP_1} unless $form->{id};
188 ($form->datetonum($form->{invdate}, \%myconfig) <=
189 $form->datetonum($form->{closedto}, \%myconfig));
191 $lxdebug->leave_sub();
194 sub prepare_invoice {
195 $lxdebug->enter_sub();
199 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
202 foreach $ref (@{ $form->{invoice_details} }) {
204 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
206 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
208 $decimalplaces = ($dec > 2) ? $dec : 2;
210 $form->{"sellprice_$i"} =
211 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
214 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
215 $dec_qty = length $dec_qty;
218 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
220 $form->{rowcount} = $i;
224 $lxdebug->leave_sub();
228 $lxdebug->enter_sub();
230 # set option selected
231 foreach $item (qw(AP vendor currency department)) {
232 $form->{"select$item"} =~ s/ selected//;
233 $form->{"select$item"} =~
234 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
238 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
240 #quote selectvendor Bug 133
241 $form->{"selectvendor"} = $form->quote($form->{"selectvendor"});
243 #substitute \n and \r to \s (bug 543)
244 $form->{"selectvendor"} =~ s/[\n\r]/ /g;
246 $form->{exchangerate} =
247 $form->format_amount(\%myconfig, $form->{exchangerate});
249 $form->{creditlimit} =
250 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
251 $form->{creditremaining} =
252 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
255 if ($form->{currency} ne $form->{defaultcurrency}) {
256 if ($form->{forex}) {
258 <th align=right nowrap>|
259 . $locale->text('Exchangerate') . qq|</th>
260 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
264 <th align=right nowrap>|
265 . $locale->text('Exchangerate') . qq|</th>
266 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
271 <input type=hidden name=forex value=$form->{forex}>
274 my @old_project_ids = ($form->{"globalproject_id"});
275 map({ push(@old_project_ids, $form->{"project_id_$_"})
276 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
278 $form->get_lists("contacts" => "ALL_CONTACTS",
279 "projects" => { "key" => "ALL_PROJECTS",
281 "old_id" => \@old_project_ids });
284 my @values = (undef);
285 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
286 push(@values, $item->{"cp_id"});
287 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
288 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
291 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
292 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
296 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
297 push(@values, $item->{"id"});
298 $labels{$item->{"id"}} = $item->{"projectnumber"};
300 my $globalprojectnumber =
301 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
302 '-labels' => \%labels,
303 '-default' => $form->{"globalproject_id"}));
305 if (@{ $form->{TAXZONE} }) {
306 $form->{selecttaxzone} = "";
307 foreach $item (@{ $form->{TAXZONE} }) {
308 if ($item->{id} == $form->{taxzone_id}) {
309 $form->{selecttaxzone} .=
310 "<option value=$item->{id} selected>" . H($item->{description}) .
313 $form->{selecttaxzone} .=
314 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
319 $form->{selecttaxzone} =~ s/ selected//g;
320 if ($form->{taxzone_id} ne "") {
321 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
327 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
328 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
329 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
335 ($form->{selectvendor})
336 ? qq|<select name="vendor"
337 onchange="document.getElementById('update_button').click();">| .
338 qq|$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="| .
339 Q($form->{selectvendor}) . qq|">|
340 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
344 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
345 <td colspan=3><select name=department>$form->{selectdepartment}</select>
346 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
349 | if $form->{selectdepartment};
351 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
353 # use JavaScript Calendar or not
354 $form->{jsscript} = $form->{jscalendar};
356 if ($form->{jsscript}) {
358 # with JavaScript Calendar
360 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
361 <td><input type=button name=invdate id="trigger1" value=|
362 . $locale->text('button') . qq|></td>
365 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
366 <td width="4"><input type=button name=duedate id="trigger2" value=|
367 . $locale->text('button') . qq|></td></td>
372 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
373 "duedate", "BL", "trigger2");
376 # without JavaScript Calendar
378 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
380 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
383 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
386 $form->write_trigger(\%myconfig, 2,
387 "orddate", "BL", "trigger_orddate",
388 "quodate", "BL", "trigger_quodate");
395 <form method=post action=$form->{script}>
397 <input type=hidden name=id value=$form->{id}>
398 <input type=hidden name=title value="$form->{title}">
399 <input type=hidden name=vc value="vendor">
400 <input type=hidden name=type value=$form->{type}>
401 <input type=hidden name=level value=$form->{level}>
403 <input type=hidden name=creditlimit value=$form->{creditlimit}>
404 <input type=hidden name=creditremaining value=$form->{creditremaining}>
406 <input type=hidden name=closedto value=$form->{closedto}>
407 <input type=hidden name=locked value=$form->{locked}>
409 <input type=hidden name=shipped value=$form->{shipped}>
410 <input type=hidden name=storno value=$form->{storno}>
411 <input type=hidden name=storno_id value=$form->{storno_id}>
413 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
417 <th class=listtop>$form->{title}</th>
427 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
428 <td colspan=3>$vendor</td>
430 <th align=richt nowrap>|
431 . $locale->text('Contact Person') . qq|</th>
432 <td colspan=3>$contact</td>
434 <input type=hidden name=vendor_id value=$form->{vendor_id}>
435 <input type=hidden name=oldvendor value="$form->{oldvendor}">
443 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
444 <td>$form->{creditlimit}</td>
446 <th nowrap>| . $locale->text('Remaining') . qq|</th>
447 <td class="plus$n">$form->{creditremaining}</td>
452 <th align=right>| . $locale->text('Record in') . qq|</th>
453 <td colspan=3><select name=AP>$form->{selectAP}</select></td>
454 <input type=hidden name=selectAP value="$form->{selectAP}">
459 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
460 <td><select name=currency>$form->{selectcurrency}</select></td>
468 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
469 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
472 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
476 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
480 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
481 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
482 <input type=hidden name=quonumber value="$form->{quonumber}">
485 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
486 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
487 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
490 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
491 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
492 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
495 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
496 <td>$globalprojectnumber</td>
507 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
508 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
509 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
510 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
511 <input type=hidden name=webdav value=$webdav>
513 <input type=hidden name=taxpart value="$form->{taxpart}">
514 <input type=hidden name=taxservice value="$form->{taxservice}">
516 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
519 foreach $item (split / /, $form->{taxaccounts}) {
521 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
522 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
526 $lxdebug->leave_sub();
530 $lxdebug->enter_sub();
532 $form->{invtotal} = $form->{invsubtotal};
534 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
537 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
540 $rows = ($rows > $introws) ? $rows : $introws;
542 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
544 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
546 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
549 if ($form->{taxaccounts}) {
551 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
552 . $locale->text('Tax Included') . qq|</b>
556 if (!$form->{taxincluded}) {
558 foreach $item (split / /, $form->{taxaccounts}) {
559 if ($form->{"${item}_base"}) {
560 $form->{invtotal} += $form->{"${item}_total"} =
562 $form->{"${item}_base"} * $form->{"${item}_rate"},
564 $form->{"${item}_total"} =
565 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
569 <th align=right>$form->{"${item}_description"} |
570 . $form->{"${item}_rate"} * 100 .qq|%</th>
571 <td align=right>$form->{"${item}_total"}</td>
577 $form->{invsubtotal} =
578 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
582 <th align=right>| . $locale->text('Subtotal') . qq|</th>
583 <td align=right>$form->{invsubtotal}</td>
589 if ($form->{taxincluded}) {
590 foreach $item (split / /, $form->{taxaccounts}) {
591 if ($form->{"${item}_base"}) {
592 $form->{"${item}_total"} =
594 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
595 (1 + $form->{"${item}_rate"})
598 $form->{"${item}_base"} =
599 $form->round_amount($form->{"${item}_base"}, 2);
600 $form->{"${item}_netto"} =
602 ($form->{"${item}_base"} - $form->{"${item}_total"}),
604 $form->{"${item}_netto"} =
605 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
606 $form->{"${item}_total"} =
607 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
611 <th align=right>Enthaltene $form->{"${item}_description"} |
612 . $form->{"${item}_rate"} * 100 .qq|%</th>
613 <td align=right>$form->{"${item}_total"}</td>
616 <th align=right>Nettobetrag</th>
617 <td align=right>$form->{"${item}_netto"}</td>
625 $form->{oldinvtotal} = $form->{invtotal};
627 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
631 <td colspan=$colspan>
632 <table cellspacing="0">
637 <th align=left>| . $locale->text('Notes') . qq|</th>
638 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
646 <td colspan=2 align=right width=100%>
653 <th align=right>| . $locale->text('Total') . qq|</th>
654 <td align=right>$form->{invtotal}</td>
666 <td><hr size=3 noshade></td>
669 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
672 <td align=left width=30%><b>Dateiname</b></td>
673 <td align=left width=70%><b>Webdavlink</b></td>
675 foreach $file (keys %{ $form->{WEBDAV} }) {
678 <td align=left>$file</td>
679 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
691 <input type=hidden name=jscalendar value=$form->{jscalendar}>
695 <td colspan=$colspan>
698 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
702 if ($form->{currency} eq $form->{defaultcurrency}) {
703 @column_index = qw(datepaid source memo paid AP_paid);
705 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
708 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
709 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
710 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
711 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
712 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
713 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
718 map { print "$column_data{$_}\n" } @column_index;
724 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
725 for $i (1 .. $form->{paidaccounts}) {
731 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
732 $form->{"selectAP_paid_$i"} =~
733 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
736 if ($form->{"paid_$i"}) {
738 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
740 $form->{"exchangerate_$i"} =
741 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
743 $exchangerate = qq| |;
744 if ($form->{currency} ne $form->{defaultcurrency}) {
745 if ($form->{"forex_$i"}) {
747 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
750 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
754 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
757 $column_data{"paid_$i"} =
758 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
759 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
760 $column_data{"AP_paid_$i"} =
761 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
762 $column_data{"datepaid_$i"} =
763 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
764 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
765 $column_data{"source_$i"} =
766 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
767 $column_data{"memo_$i"} =
768 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
770 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
775 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
779 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
780 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
781 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
786 <td><hr size=3 noshade></td>
792 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
793 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
796 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
798 print qq|<input class=submit type=submit name=action value="|
799 . $locale->text('Post Payment') . qq|">
801 print qq|<input class=submit type=submit name=action value="|
802 . $locale->text('Storno') . qq|">
804 if ($form->{radier}) {
806 <input class=submit type=submit name=action value="|
807 . $locale->text('Delete') . qq|">
810 print qq|<input class=submit type=submit name=action value="|
811 . $locale->text('Use As Template') . qq|">
816 print qq|<input class=submit type=submit name=action id=update_button value="|
817 . $locale->text('Update') . qq|">|;
819 if (!$form->{id} && ($invdate > $closedto)) {
820 print qq| <input class=submit type=submit name=action value="|
821 . $locale->text('Post') . qq|"> | .
822 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
823 '-class' => 'submit'));
826 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
829 <input type=hidden name=rowcount value=$form->{rowcount}>
831 <input name=callback type=hidden value="$form->{callback}">
833 <input type=hidden name=path value=$form->{path}>
834 <input type=hidden name=login value=$form->{login}>
835 <input type=hidden name=password value=$form->{password}>
837 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
838 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
840 # button for saving history
841 if($form->{id} ne "") {
843 <input type="button" class="submit" onclick="set_history_window(|
845 . qq|);" name="history" id="history" value="|
846 . $locale->text('history')
849 # /button for saving history
857 $lxdebug->leave_sub();
861 $lxdebug->enter_sub();
863 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
864 qw(exchangerate creditlimit creditremaining);
868 $form->{exchangerate} = $exchangerate
872 $form->check_exchangerate(
873 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
876 for $i (1 .. $form->{paidaccounts}) {
877 if ($form->{"paid_$i"}) {
880 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
881 } qw(paid exchangerate);
883 $form->{"exchangerate_$i"} = $exchangerate
885 $form->{"forex_$i"} = (
887 $form->check_exchangerate(
888 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
893 $i = $form->{rowcount};
894 $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
896 if ( ($form->{"partnumber_$i"} eq "")
897 && ($form->{"description_$i"} eq "")
898 && ($form->{"partsgroup_$i"} eq "")) {
899 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
904 IR->retrieve_item(\%myconfig, \%$form);
906 my $rows = scalar @{ $form->{item_list} };
909 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
918 # override sellprice if there is one entered
919 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
921 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
922 qw(partnumber description unit);
924 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
925 keys %{ $form->{item_list}[0] };
927 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
929 ($dec) = ($s =~ /\.(\d+)/);
931 $decimalplaces = ($dec > 2) ? $dec : 2;
934 $form->{"sellprice_$i"} = $sellprice;
937 # if there is an exchange rate adjust sellprice
938 $form->{"sellprice_$i"} /= $exchangerate;
942 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
943 (1 - $form->{"discount_$i"} / 100);
944 $form->{creditremaining} -= $amount;
945 $form->{"sellprice_$i"} =
946 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
949 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
956 # ok, so this is a new part
957 # ask if it is a part or service item
959 if ( $form->{"partsgroup_$i"}
960 && ($form->{"partsnumber_$i"} eq "")
961 && ($form->{"description_$i"} eq "")) {
963 $form->{"discount_$i"} = "";
967 $form->{"id_$i"} = 0;
968 $form->{"unit_$i"} = $locale->text('ea');
975 $lxdebug->leave_sub();
979 $lxdebug->enter_sub();
981 if ($form->{storno}) {
982 $form->error($locale->text('Cannot storno storno invoice!'));
985 if (IS->has_storno(\%myconfig, $form, "ap")) {
986 $form->error($locale->text("Invoice has already been storno'd!"));
993 $form->{storno_id} = $form->{id};
996 $form->{invnumber} = "Storno zu " . $form->{invnumber};
999 $lxdebug->leave_sub();
1003 sub use_as_template {
1004 $lxdebug->enter_sub();
1006 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);
1007 $form->{paidaccounts} = 1;
1008 $form->{rowcount}--;
1009 $form->{invdate} = $form->current_date(\%myconfig);
1012 $lxdebug->leave_sub();
1016 $lxdebug->enter_sub();
1017 for $i (1 .. $form->{paidaccounts}) {
1018 if ($form->{"paid_$i"}) {
1019 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1021 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1023 $form->error($locale->text('Cannot post payment for a closed period!'))
1024 if ($datepaid <= $closedto);
1026 if ($form->{currency} ne $form->{defaultcurrency}) {
1027 $form->{"exchangerate_$i"} = $form->{exchangerate}
1028 if ($invdate == $datepaid);
1029 $form->isblank("exchangerate_$i",
1030 $locale->text('Exchangerate for payment missing!'));
1035 ($form->{AP}) = split /--/, $form->{AP};
1036 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1037 if (IR->post_payment(\%myconfig, \%$form)){
1039 if(!exists $form->{addition} && $form->{id} ne "") {
1040 # saving the history
1041 $form->{addition} = "PAYMENT POSTED";
1042 $form->save_history($form->dbconnect(\%myconfig));
1043 # /saving the history
1044 $form->redirect($locale->text(' Payment posted!'));
1047 $form->error($locale->text('Cannot post payment!'));
1050 $lxdebug->leave_sub();
1054 $lxdebug->enter_sub();
1056 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1057 $form->isblank("vendor", $locale->text('Vendor missing!'));
1059 # if the vendor changed get new values
1060 if (&check_name(vendor)) {
1067 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1068 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1070 $form->error($locale->text('Cannot post invoice for a closed period!'))
1071 if ($invdate <= $closedto);
1073 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1074 if ($form->{currency} ne $form->{defaultcurrency});
1076 for $i (1 .. $form->{paidaccounts}) {
1077 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1078 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1080 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1082 $form->error($locale->text('Cannot post payment for a closed period!'))
1083 if ($datepaid <= $closedto);
1085 if ($form->{currency} ne $form->{defaultcurrency}) {
1086 $form->{"exchangerate_$i"} = $form->{exchangerate}
1087 if ($invdate == $datepaid);
1088 $form->isblank("exchangerate_$i",
1089 $locale->text('Exchangerate for payment missing!'));
1094 ($form->{AP}) = split /--/, $form->{AP};
1095 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1097 $form->{id} = 0 if $form->{postasnew};
1101 if (IR->post_invoice(\%myconfig, \%$form)){
1102 # saving the history
1103 if(!exists $form->{addition} && $form->{id} ne "") {
1104 $form->{addition} = "POSTED";
1105 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1106 $form->save_history($form->dbconnect(\%myconfig));
1108 # /saving the history
1109 remove_draft() if $form->{remove_draft};
1110 $form->redirect( $locale->text('Invoice')
1111 . " $form->{invnumber} "
1112 . $locale->text('posted!'));
1114 $form->error($locale->text('Cannot post invoice!'));
1116 $lxdebug->leave_sub();
1120 $lxdebug->enter_sub();
1126 <form method=post action=$form->{script}>
1129 # delete action variable
1130 map { delete $form->{$_} } qw(action header);
1132 foreach $key (keys %$form) {
1133 $form->{$key} =~ s/\"/"/g;
1134 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1138 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1141 . $locale->text('Are you sure you want to delete Invoice Number')
1142 . qq| $form->{invnumber}</h4>
1144 <input name=action class=submit type=submit value="|
1145 . $locale->text('Yes') . qq|">
1149 $lxdebug->leave_sub();
1153 $lxdebug->enter_sub();
1154 if (IR->delete_invoice(\%myconfig, \%$form)) {
1155 # saving the history
1156 if(!exists $form->{addition}) {
1157 $form->{addition} = "DELETED";
1158 $form->save_history($form->dbconnect(\%myconfig));
1160 # /saving the history
1161 $form->redirect($locale->text('Invoice deleted!'));
1163 $form->error($locale->text('Cannot delete invoice!'));
1165 $lxdebug->leave_sub();