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 $form->{exchangerate} =
244 $form->format_amount(\%myconfig, $form->{exchangerate});
246 $form->{creditlimit} =
247 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
248 $form->{creditremaining} =
249 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
252 if ($form->{currency} ne $form->{defaultcurrency}) {
253 if ($form->{forex}) {
255 <th align=right nowrap>|
256 . $locale->text('Exchangerate') . qq|</th>
257 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
261 <th align=right nowrap>|
262 . $locale->text('Exchangerate') . qq|</th>
263 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
268 <input type=hidden name=forex value=$form->{forex}>
271 my @old_project_ids = ($form->{"globalproject_id"});
272 map({ push(@old_project_ids, $form->{"project_id_$_"})
273 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
275 $form->get_lists("contacts" => "ALL_CONTACTS",
276 "projects" => { "key" => "ALL_PROJECTS",
278 "old_id" => \@old_project_ids });
281 my @values = (undef);
282 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
283 push(@values, $item->{"cp_id"});
284 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
285 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
288 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
289 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
293 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
294 push(@values, $item->{"id"});
295 $labels{$item->{"id"}} = $item->{"projectnumber"};
297 my $globalprojectnumber =
298 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
299 '-labels' => \%labels,
300 '-default' => $form->{"globalproject_id"}));
302 if (@{ $form->{TAXZONE} }) {
303 $form->{selecttaxzone} = "";
304 foreach $item (@{ $form->{TAXZONE} }) {
305 if ($item->{id} == $form->{taxzone_id}) {
306 $form->{selecttaxzone} .=
307 "<option value=$item->{id} selected>" . H($item->{description}) .
310 $form->{selecttaxzone} .=
311 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
316 $form->{selecttaxzone} =~ s/ selected//g;
317 if ($form->{taxzone_id} ne "") {
318 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
324 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
325 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
326 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
332 ($form->{selectvendor})
333 ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
334 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
338 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
339 <td colspan=3><select name=department>$form->{selectdepartment}</select>
340 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
343 | if $form->{selectdepartment};
345 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
347 # use JavaScript Calendar or not
348 $form->{jsscript} = $form->{jscalendar};
350 if ($form->{jsscript}) {
352 # with JavaScript Calendar
354 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
355 <td><input type=button name=invdate id="trigger1" value=|
356 . $locale->text('button') . qq|></td>
359 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
360 <td width="4"><input type=button name=duedate id="trigger2" value=|
361 . $locale->text('button') . qq|></td></td>
366 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
367 "duedate", "BL", "trigger2");
370 # without JavaScript Calendar
372 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
374 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
377 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
380 $form->write_trigger(\%myconfig, 2,
381 "orddate", "BL", "trigger_orddate",
382 "quodate", "BL", "trigger_quodate");
389 <form method=post action=$form->{script}>
391 <input type=hidden name=id value=$form->{id}>
392 <input type=hidden name=title value="$form->{title}">
393 <input type=hidden name=vc value="vendor">
394 <input type=hidden name=type value=$form->{type}>
395 <input type=hidden name=level value=$form->{level}>
397 <input type=hidden name=creditlimit value=$form->{creditlimit}>
398 <input type=hidden name=creditremaining value=$form->{creditremaining}>
400 <input type=hidden name=closedto value=$form->{closedto}>
401 <input type=hidden name=locked value=$form->{locked}>
403 <input type=hidden name=shipped value=$form->{shipped}>
404 <input type=hidden name=storno value=$form->{storno}>
405 <input type=hidden name=storno_id value=$form->{storno_id}>
407 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
411 <th class=listtop>$form->{title}</th>
421 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
422 <td colspan=3>$vendor</td>
424 <th align=richt nowrap>|
425 . $locale->text('Contact Person') . qq|</th>
426 <td colspan=3>$contact</td>
428 <input type=hidden name=vendor_id value=$form->{vendor_id}>
429 <input type=hidden name=oldvendor value="$form->{oldvendor}">
437 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
438 <td>$form->{creditlimit}</td>
440 <th nowrap>| . $locale->text('Remaining') . qq|</th>
441 <td class="plus$n">$form->{creditremaining}</td>
446 <th align=right>| . $locale->text('Record in') . qq|</th>
447 <td colspan=3><select name=AP>$form->{selectAP}</select></td>
448 <input type=hidden name=selectAP value="$form->{selectAP}">
453 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
454 <td><select name=currency>$form->{selectcurrency}</select></td>
462 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
463 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
466 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
470 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
474 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
475 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
476 <input type=hidden name=quonumber value="$form->{quonumber}">
479 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
480 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
481 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
484 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
485 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
486 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
489 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
490 <td>$globalprojectnumber</td>
501 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
502 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
503 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
504 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
505 <input type=hidden name=webdav value=$webdav>
507 <input type=hidden name=taxpart value="$form->{taxpart}">
508 <input type=hidden name=taxservice value="$form->{taxservice}">
510 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
513 foreach $item (split / /, $form->{taxaccounts}) {
515 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
516 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
520 $lxdebug->leave_sub();
524 $lxdebug->enter_sub();
526 $form->{invtotal} = $form->{invsubtotal};
528 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
531 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
534 $rows = ($rows > $introws) ? $rows : $introws;
536 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
538 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
540 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
543 if ($form->{taxaccounts}) {
545 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
546 . $locale->text('Tax Included') . qq|</b>
550 if (!$form->{taxincluded}) {
552 foreach $item (split / /, $form->{taxaccounts}) {
553 if ($form->{"${item}_base"}) {
554 $form->{invtotal} += $form->{"${item}_total"} =
556 $form->{"${item}_base"} * $form->{"${item}_rate"},
558 $form->{"${item}_total"} =
559 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
563 <th align=right>$form->{"${item}_description"} |
564 . $form->{"${item}_rate"} * 100 .qq|%</th>
565 <td align=right>$form->{"${item}_total"}</td>
571 $form->{invsubtotal} =
572 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
576 <th align=right>| . $locale->text('Subtotal') . qq|</th>
577 <td align=right>$form->{invsubtotal}</td>
583 if ($form->{taxincluded}) {
584 foreach $item (split / /, $form->{taxaccounts}) {
585 if ($form->{"${item}_base"}) {
586 $form->{"${item}_total"} =
588 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
589 (1 + $form->{"${item}_rate"})
592 $form->{"${item}_base"} =
593 $form->round_amount($form->{"${item}_base"}, 2);
594 $form->{"${item}_netto"} =
596 ($form->{"${item}_base"} - $form->{"${item}_total"}),
598 $form->{"${item}_netto"} =
599 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
600 $form->{"${item}_total"} =
601 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
605 <th align=right>Enthaltene $form->{"${item}_description"} |
606 . $form->{"${item}_rate"} * 100 .qq|%</th>
607 <td align=right>$form->{"${item}_total"}</td>
610 <th align=right>Nettobetrag</th>
611 <td align=right>$form->{"${item}_netto"}</td>
619 $form->{oldinvtotal} = $form->{invtotal};
621 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
625 <td colspan=$colspan>
626 <table cellspacing="0">
631 <th align=left>| . $locale->text('Notes') . qq|</th>
632 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
640 <td colspan=2 align=right width=100%>
647 <th align=right>| . $locale->text('Total') . qq|</th>
648 <td align=right>$form->{invtotal}</td>
660 <td><hr size=3 noshade></td>
663 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
666 <td align=left width=30%><b>Dateiname</b></td>
667 <td align=left width=70%><b>Webdavlink</b></td>
669 foreach $file (keys %{ $form->{WEBDAV} }) {
672 <td align=left>$file</td>
673 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
685 <input type=hidden name=jscalendar value=$form->{jscalendar}>
689 <td colspan=$colspan>
692 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
696 if ($form->{currency} eq $form->{defaultcurrency}) {
697 @column_index = qw(datepaid source memo paid AP_paid);
699 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
702 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
703 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
704 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
705 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
706 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
707 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
712 map { print "$column_data{$_}\n" } @column_index;
718 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
719 for $i (1 .. $form->{paidaccounts}) {
725 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
726 $form->{"selectAP_paid_$i"} =~
727 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
730 if ($form->{"paid_$i"}) {
732 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
734 $form->{"exchangerate_$i"} =
735 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
737 $exchangerate = qq| |;
738 if ($form->{currency} ne $form->{defaultcurrency}) {
739 if ($form->{"forex_$i"}) {
741 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
744 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
748 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
751 $column_data{"paid_$i"} =
752 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
753 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
754 $column_data{"AP_paid_$i"} =
755 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
756 $column_data{"datepaid_$i"} =
757 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
758 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
759 $column_data{"source_$i"} =
760 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
761 $column_data{"memo_$i"} =
762 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
764 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
769 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
773 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
774 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
775 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
780 <td><hr size=3 noshade></td>
786 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
787 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
790 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
792 print qq|<input class=submit type=submit name=action value="|
793 . $locale->text('Post Payment') . qq|">
795 print qq|<input class=submit type=submit name=action value="|
796 . $locale->text('Storno') . qq|">
798 if ($form->{radier}) {
800 <input class=submit type=submit name=action value="|
801 . $locale->text('Delete') . qq|">
804 print qq|<input class=submit type=submit name=action value="|
805 . $locale->text('Use As Template') . qq|">
810 print qq|<input class=submit type=submit name=action id=update_button value="|
811 . $locale->text('Update') . qq|">|;
813 if (!$form->{id} && ($invdate > $closedto)) {
814 print qq| <input class=submit type=submit name=action value="|
815 . $locale->text('Post') . qq|"> | .
816 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
817 '-class' => 'submit'));
820 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
823 <input type=hidden name=rowcount value=$form->{rowcount}>
825 <input name=callback type=hidden value="$form->{callback}">
827 <input type=hidden name=path value=$form->{path}>
828 <input type=hidden name=login value=$form->{login}>
829 <input type=hidden name=password value=$form->{password}>
831 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
832 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
834 # button for saving history
835 if($form->{id} ne "") {
837 <input type="button" class="submit" onclick="set_history_window(|
839 . qq|);" name="history" id="history" value="|
840 . $locale->text('history')
843 # /button for saving history
851 $lxdebug->leave_sub();
855 $lxdebug->enter_sub();
857 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
858 qw(exchangerate creditlimit creditremaining);
862 $form->{exchangerate} = $exchangerate
866 $form->check_exchangerate(
867 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
870 for $i (1 .. $form->{paidaccounts}) {
871 if ($form->{"paid_$i"}) {
874 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
875 } qw(paid exchangerate);
877 $form->{"exchangerate_$i"} = $exchangerate
879 $form->{"forex_$i"} = (
881 $form->check_exchangerate(
882 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
887 $i = $form->{rowcount};
888 $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
890 if ( ($form->{"partnumber_$i"} eq "")
891 && ($form->{"description_$i"} eq "")
892 && ($form->{"partsgroup_$i"} eq "")) {
893 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
898 IR->retrieve_item(\%myconfig, \%$form);
900 my $rows = scalar @{ $form->{item_list} };
903 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
912 # override sellprice if there is one entered
913 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
915 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
916 qw(partnumber description unit);
918 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
919 keys %{ $form->{item_list}[0] };
921 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
923 ($dec) = ($s =~ /\.(\d+)/);
925 $decimalplaces = ($dec > 2) ? $dec : 2;
928 $form->{"sellprice_$i"} = $sellprice;
931 # if there is an exchange rate adjust sellprice
932 $form->{"sellprice_$i"} /= $exchangerate;
936 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
937 (1 - $form->{"discount_$i"} / 100);
938 $form->{creditremaining} -= $amount;
939 $form->{"sellprice_$i"} =
940 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
943 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
950 # ok, so this is a new part
951 # ask if it is a part or service item
953 if ( $form->{"partsgroup_$i"}
954 && ($form->{"partsnumber_$i"} eq "")
955 && ($form->{"description_$i"} eq "")) {
957 $form->{"discount_$i"} = "";
961 $form->{"id_$i"} = 0;
962 $form->{"unit_$i"} = $locale->text('ea');
969 $lxdebug->leave_sub();
973 $lxdebug->enter_sub();
975 if ($form->{storno}) {
976 $form->error($locale->text('Cannot storno storno invoice!'));
979 if (IS->has_storno(\%myconfig, $form, "ap")) {
980 $form->error($locale->text("Invoice has already been storno'd!"));
987 $form->{storno_id} = $form->{id};
990 $form->{invnumber} = "Storno zu " . $form->{invnumber};
993 $lxdebug->leave_sub();
997 sub use_as_template {
998 $lxdebug->enter_sub();
1000 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);
1001 $form->{paidaccounts} = 1;
1002 $form->{rowcount}--;
1003 $form->{invdate} = $form->current_date(\%myconfig);
1006 $lxdebug->leave_sub();
1010 $lxdebug->enter_sub();
1011 for $i (1 .. $form->{paidaccounts}) {
1012 if ($form->{"paid_$i"}) {
1013 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1015 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1017 $form->error($locale->text('Cannot post payment for a closed period!'))
1018 if ($datepaid <= $closedto);
1020 if ($form->{currency} ne $form->{defaultcurrency}) {
1021 $form->{"exchangerate_$i"} = $form->{exchangerate}
1022 if ($invdate == $datepaid);
1023 $form->isblank("exchangerate_$i",
1024 $locale->text('Exchangerate for payment missing!'));
1029 ($form->{AP}) = split /--/, $form->{AP};
1030 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1031 if (IR->post_payment(\%myconfig, \%$form)){
1033 if(!exists $form->{addition} && $form->{id} ne "") {
1034 # saving the history
1035 $form->{addition} = "PAYMENT POSTED";
1036 $form->save_history($form->dbconnect(\%myconfig));
1037 # /saving the history
1038 $form->redirect($locale->text(' Payment posted!'));
1041 $form->error($locale->text('Cannot post payment!'));
1044 $lxdebug->leave_sub();
1048 $lxdebug->enter_sub();
1050 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1051 $form->isblank("vendor", $locale->text('Vendor missing!'));
1053 # if the vendor changed get new values
1054 if (&check_name(vendor)) {
1061 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1062 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1064 $form->error($locale->text('Cannot post invoice for a closed period!'))
1065 if ($invdate <= $closedto);
1067 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1068 if ($form->{currency} ne $form->{defaultcurrency});
1070 for $i (1 .. $form->{paidaccounts}) {
1071 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1072 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1074 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1076 $form->error($locale->text('Cannot post payment for a closed period!'))
1077 if ($datepaid <= $closedto);
1079 if ($form->{currency} ne $form->{defaultcurrency}) {
1080 $form->{"exchangerate_$i"} = $form->{exchangerate}
1081 if ($invdate == $datepaid);
1082 $form->isblank("exchangerate_$i",
1083 $locale->text('Exchangerate for payment missing!'));
1088 ($form->{AP}) = split /--/, $form->{AP};
1089 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1091 $form->{id} = 0 if $form->{postasnew};
1095 if (IR->post_invoice(\%myconfig, \%$form)){
1096 # saving the history
1097 if(!exists $form->{addition} && $form->{id} ne "") {
1098 $form->{addition} = "POSTED";
1099 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1100 $form->save_history($form->dbconnect(\%myconfig));
1102 # /saving the history
1103 remove_draft() if $form->{remove_draft};
1104 $form->redirect( $locale->text('Invoice')
1105 . " $form->{invnumber} "
1106 . $locale->text('posted!'));
1108 $form->error($locale->text('Cannot post invoice!'));
1110 $lxdebug->leave_sub();
1114 $lxdebug->enter_sub();
1120 <form method=post action=$form->{script}>
1123 # delete action variable
1124 map { delete $form->{$_} } qw(action header);
1126 foreach $key (keys %$form) {
1127 $form->{$key} =~ s/\"/"/g;
1128 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1132 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1135 . $locale->text('Are you sure you want to delete Invoice Number')
1136 . qq| $form->{invnumber}</h4>
1138 <input name=action class=submit type=submit value="|
1139 . $locale->text('Yes') . qq|">
1143 $lxdebug->leave_sub();
1147 $lxdebug->enter_sub();
1148 if (IR->delete_invoice(\%myconfig, \%$form)) {
1149 # saving the history
1150 if(!exists $form->{addition}) {
1151 $form->{addition} = "DELETED";
1152 $form->save_history($form->dbconnect(\%myconfig));
1154 # /saving the history
1155 $form->redirect($locale->text('Invoice deleted!'));
1157 $form->error($locale->text('Cannot delete invoice!'));
1159 $lxdebug->leave_sub();