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 });
280 my (%labels, @values);
281 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
282 push(@values, $item->{"cp_id"});
283 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
284 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
287 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
288 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
292 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
293 push(@values, $item->{"id"});
294 $labels{$item->{"id"}} = $item->{"projectnumber"};
296 my $globalprojectnumber =
297 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
298 '-labels' => \%labels,
299 '-default' => $form->{"globalproject_id"}));
301 if (@{ $form->{TAXZONE} }) {
302 $form->{selecttaxzone} = "";
303 foreach $item (@{ $form->{TAXZONE} }) {
304 if ($item->{id} == $form->{taxzone_id}) {
305 $form->{selecttaxzone} .=
306 "<option value=$item->{id} selected>" . H($item->{description}) .
309 $form->{selecttaxzone} .=
310 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
315 $form->{selecttaxzone} =~ s/ selected//g;
316 if ($form->{taxzone_id} ne "") {
317 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
323 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
324 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
325 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
331 ($form->{selectvendor})
332 ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
333 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
337 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
338 <td colspan=3><select name=department>$form->{selectdepartment}</select>
339 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
342 | if $form->{selectdepartment};
344 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
346 # use JavaScript Calendar or not
347 $form->{jsscript} = $form->{jscalendar};
349 if ($form->{jsscript}) {
351 # with JavaScript Calendar
353 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
354 <td><input type=button name=invdate id="trigger1" value=|
355 . $locale->text('button') . qq|></td>
358 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
359 <td width="4"><input type=button name=duedate id="trigger2" value=|
360 . $locale->text('button') . qq|></td></td>
365 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
366 "duedate", "BL", "trigger2");
369 # without JavaScript Calendar
371 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
373 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
376 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
379 $form->write_trigger(\%myconfig, 2,
380 "orddate", "BL", "trigger_orddate",
381 "quodate", "BL", "trigger_quodate");
388 <form method=post action=$form->{script}>
390 <input type=hidden name=id value=$form->{id}>
391 <input type=hidden name=title value="$form->{title}">
392 <input type=hidden name=vc value="vendor">
393 <input type=hidden name=type value=$form->{type}>
394 <input type=hidden name=level value=$form->{level}>
396 <input type=hidden name=creditlimit value=$form->{creditlimit}>
397 <input type=hidden name=creditremaining value=$form->{creditremaining}>
399 <input type=hidden name=closedto value=$form->{closedto}>
400 <input type=hidden name=locked value=$form->{locked}>
402 <input type=hidden name=shipped value=$form->{shipped}>
403 <input type=hidden name=storno value=$form->{storno}>
404 <input type=hidden name=storno_id value=$form->{storno_id}>
406 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
410 <th class=listtop>$form->{title}</th>
420 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
421 <td colspan=3>$vendor</td>
423 <th align=richt nowrap>|
424 . $locale->text('Contact Person') . qq|</th>
425 <td colspan=3>$contact</td>
427 <input type=hidden name=vendor_id value=$form->{vendor_id}>
428 <input type=hidden name=oldvendor value="$form->{oldvendor}">
436 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
437 <td>$form->{creditlimit}</td>
439 <th nowrap>| . $locale->text('Remaining') . qq|</th>
440 <td class="plus$n">$form->{creditremaining}</td>
445 <th align=right>| . $locale->text('Record in') . qq|</th>
446 <td colspan=3><select name=AP>$form->{selectAP}</select></td>
447 <input type=hidden name=selectAP value="$form->{selectAP}">
452 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
453 <td><select name=currency>$form->{selectcurrency}</select></td>
461 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
462 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
465 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
469 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
473 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
474 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
475 <input type=hidden name=quonumber value="$form->{quonumber}">
478 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
479 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
480 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
483 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
484 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
485 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
488 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
489 <td>$globalprojectnumber</td>
500 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
501 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
502 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
503 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
504 <input type=hidden name=webdav value=$webdav>
506 <input type=hidden name=taxpart value="$form->{taxpart}">
507 <input type=hidden name=taxservice value="$form->{taxservice}">
509 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
512 foreach $item (split / /, $form->{taxaccounts}) {
514 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
515 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
519 $lxdebug->leave_sub();
523 $lxdebug->enter_sub();
525 $form->{invtotal} = $form->{invsubtotal};
527 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
530 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
533 $rows = ($rows > $introws) ? $rows : $introws;
535 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
537 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
539 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
542 if ($form->{taxaccounts}) {
544 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
545 . $locale->text('Tax Included') . qq|</b>
549 if (!$form->{taxincluded}) {
551 foreach $item (split / /, $form->{taxaccounts}) {
552 if ($form->{"${item}_base"}) {
553 $form->{invtotal} += $form->{"${item}_total"} =
555 $form->{"${item}_base"} * $form->{"${item}_rate"},
557 $form->{"${item}_total"} =
558 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
562 <th align=right>$form->{"${item}_description"} |
563 . $form->{"${item}_rate"} * 100 .qq|%</th>
564 <td align=right>$form->{"${item}_total"}</td>
570 $form->{invsubtotal} =
571 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
575 <th align=right>| . $locale->text('Subtotal') . qq|</th>
576 <td align=right>$form->{invsubtotal}</td>
582 if ($form->{taxincluded}) {
583 foreach $item (split / /, $form->{taxaccounts}) {
584 if ($form->{"${item}_base"}) {
585 $form->{"${item}_total"} =
587 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
588 (1 + $form->{"${item}_rate"})
591 $form->{"${item}_base"} =
592 $form->round_amount($form->{"${item}_base"}, 2);
593 $form->{"${item}_netto"} =
595 ($form->{"${item}_base"} - $form->{"${item}_total"}),
597 $form->{"${item}_netto"} =
598 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
599 $form->{"${item}_total"} =
600 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
604 <th align=right>Enthaltene $form->{"${item}_description"} |
605 . $form->{"${item}_rate"} * 100 .qq|%</th>
606 <td align=right>$form->{"${item}_total"}</td>
609 <th align=right>Nettobetrag</th>
610 <td align=right>$form->{"${item}_netto"}</td>
618 $form->{oldinvtotal} = $form->{invtotal};
620 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
624 <td colspan=$colspan>
625 <table cellspacing="0">
630 <th align=left>| . $locale->text('Notes') . qq|</th>
631 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
639 <td colspan=2 align=right width=100%>
646 <th align=right>| . $locale->text('Total') . qq|</th>
647 <td align=right>$form->{invtotal}</td>
659 <td><hr size=3 noshade></td>
662 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
665 <td align=left width=30%><b>Dateiname</b></td>
666 <td align=left width=70%><b>Webdavlink</b></td>
668 foreach $file (keys %{ $form->{WEBDAV} }) {
671 <td align=left>$file</td>
672 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
684 <input type=hidden name=jscalendar value=$form->{jscalendar}>
688 <td colspan=$colspan>
691 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
695 if ($form->{currency} eq $form->{defaultcurrency}) {
696 @column_index = qw(datepaid source memo paid AP_paid);
698 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
701 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
702 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
703 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
704 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
705 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
706 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
711 map { print "$column_data{$_}\n" } @column_index;
717 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
718 for $i (1 .. $form->{paidaccounts}) {
724 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
725 $form->{"selectAP_paid_$i"} =~
726 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
729 if ($form->{"paid_$i"}) {
731 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
733 $form->{"exchangerate_$i"} =
734 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
736 $exchangerate = qq| |;
737 if ($form->{currency} ne $form->{defaultcurrency}) {
738 if ($form->{"forex_$i"}) {
740 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
743 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
747 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
750 $column_data{"paid_$i"} =
751 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
752 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
753 $column_data{"AP_paid_$i"} =
754 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
755 $column_data{"datepaid_$i"} =
756 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
757 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
758 $column_data{"source_$i"} =
759 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
760 $column_data{"memo_$i"} =
761 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
763 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
768 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
772 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
773 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
774 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
779 <td><hr size=3 noshade></td>
785 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
786 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
789 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
791 print qq|<input class=submit type=submit name=action value="|
792 . $locale->text('Post Payment') . qq|">
794 print qq|<input class=submit type=submit name=action value="|
795 . $locale->text('Storno') . qq|">
797 if ($form->{radier}) {
799 <input class=submit type=submit name=action value="|
800 . $locale->text('Delete') . qq|">
803 print qq|<input class=submit type=submit name=action value="|
804 . $locale->text('Use As Template') . qq|">
809 print qq|<input class=submit type=submit name=action id=update_button value="|
810 . $locale->text('Update') . qq|">|;
812 if (!$form->{id} && ($invdate > $closedto)) {
813 print qq| <input class=submit type=submit name=action value="|
814 . $locale->text('Post') . qq|"> | .
815 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
816 '-class' => 'submit'));
819 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
822 <input type=hidden name=rowcount value=$form->{rowcount}>
824 <input name=callback type=hidden value="$form->{callback}">
826 <input type=hidden name=path value=$form->{path}>
827 <input type=hidden name=login value=$form->{login}>
828 <input type=hidden name=password value=$form->{password}>
830 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
831 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
833 # button for saving history
834 if($form->{id} ne "") {
836 <input type="button" class="submit" onclick="set_history_window(|
838 . qq|);" name="history" id="history" value="|
839 . $locale->text('history')
842 # /button for saving history
850 $lxdebug->leave_sub();
854 $lxdebug->enter_sub();
856 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
857 qw(exchangerate creditlimit creditremaining);
861 $form->{exchangerate} = $exchangerate
865 $form->check_exchangerate(
866 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
869 for $i (1 .. $form->{paidaccounts}) {
870 if ($form->{"paid_$i"}) {
873 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
874 } qw(paid exchangerate);
876 $form->{"exchangerate_$i"} = $exchangerate
878 $form->{"forex_$i"} = (
880 $form->check_exchangerate(
881 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
886 $i = $form->{rowcount};
887 $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
889 if ( ($form->{"partnumber_$i"} eq "")
890 && ($form->{"description_$i"} eq "")
891 && ($form->{"partsgroup_$i"} eq "")) {
892 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
897 IR->retrieve_item(\%myconfig, \%$form);
899 my $rows = scalar @{ $form->{item_list} };
902 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
911 # override sellprice if there is one entered
912 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
914 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
915 qw(partnumber description unit);
917 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
918 keys %{ $form->{item_list}[0] };
920 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
922 ($dec) = ($s =~ /\.(\d+)/);
924 $decimalplaces = ($dec > 2) ? $dec : 2;
927 $form->{"sellprice_$i"} = $sellprice;
930 # if there is an exchange rate adjust sellprice
931 $form->{"sellprice_$i"} /= $exchangerate;
935 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
936 (1 - $form->{"discount_$i"} / 100);
937 $form->{creditremaining} -= $amount;
938 $form->{"sellprice_$i"} =
939 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
942 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
949 # ok, so this is a new part
950 # ask if it is a part or service item
952 if ( $form->{"partsgroup_$i"}
953 && ($form->{"partsnumber_$i"} eq "")
954 && ($form->{"description_$i"} eq "")) {
956 $form->{"discount_$i"} = "";
960 $form->{"id_$i"} = 0;
961 $form->{"unit_$i"} = $locale->text('ea');
968 $lxdebug->leave_sub();
972 $lxdebug->enter_sub();
974 if ($form->{storno}) {
975 $form->error($locale->text('Cannot storno storno invoice!'));
978 if (IS->has_storno(\%myconfig, $form, "ap")) {
979 $form->error($locale->text("Invoice has already been storno'd!"));
986 $form->{storno_id} = $form->{id};
989 $form->{invnumber} = "Storno zu " . $form->{invnumber};
992 $lxdebug->leave_sub();
996 sub use_as_template {
997 $lxdebug->enter_sub();
999 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);
1000 $form->{paidaccounts} = 1;
1001 $form->{rowcount}--;
1002 $form->{invdate} = $form->current_date(\%myconfig);
1005 $lxdebug->leave_sub();
1009 $lxdebug->enter_sub();
1010 for $i (1 .. $form->{paidaccounts}) {
1011 if ($form->{"paid_$i"}) {
1012 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1014 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1016 $form->error($locale->text('Cannot post payment for a closed period!'))
1017 if ($datepaid <= $closedto);
1019 if ($form->{currency} ne $form->{defaultcurrency}) {
1020 $form->{"exchangerate_$i"} = $form->{exchangerate}
1021 if ($invdate == $datepaid);
1022 $form->isblank("exchangerate_$i",
1023 $locale->text('Exchangerate for payment missing!'));
1028 ($form->{AP}) = split /--/, $form->{AP};
1029 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1030 if (IR->post_payment(\%myconfig, \%$form)){
1032 if(!exists $form->{addition} && $form->{id} ne "") {
1033 # saving the history
1034 $form->{addition} = "PAYMENT POSTED";
1035 $form->save_history($form->dbconnect(\%myconfig));
1036 # /saving the history
1037 $form->redirect($locale->text(' Payment posted!'));
1040 $form->error($locale->text('Cannot post payment!'));
1043 $lxdebug->leave_sub();
1047 $lxdebug->enter_sub();
1049 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1050 $form->isblank("vendor", $locale->text('Vendor missing!'));
1052 # if the vendor changed get new values
1053 if (&check_name(vendor)) {
1060 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1061 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1063 $form->error($locale->text('Cannot post invoice for a closed period!'))
1064 if ($invdate <= $closedto);
1066 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1067 if ($form->{currency} ne $form->{defaultcurrency});
1069 for $i (1 .. $form->{paidaccounts}) {
1070 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1071 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1073 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1075 $form->error($locale->text('Cannot post payment for a closed period!'))
1076 if ($datepaid <= $closedto);
1078 if ($form->{currency} ne $form->{defaultcurrency}) {
1079 $form->{"exchangerate_$i"} = $form->{exchangerate}
1080 if ($invdate == $datepaid);
1081 $form->isblank("exchangerate_$i",
1082 $locale->text('Exchangerate for payment missing!'));
1087 ($form->{AP}) = split /--/, $form->{AP};
1088 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1090 $form->{id} = 0 if $form->{postasnew};
1094 if (IR->post_invoice(\%myconfig, \%$form)){
1095 # saving the history
1096 if(!exists $form->{addition} && $form->{id} ne "") {
1097 $form->{addition} = "POSTED";
1098 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1099 $form->save_history($form->dbconnect(\%myconfig));
1101 # /saving the history
1102 remove_draft() if $form->{remove_draft};
1103 $form->redirect( $locale->text('Invoice')
1104 . " $form->{invnumber} "
1105 . $locale->text('posted!'));
1107 $form->error($locale->text('Cannot post invoice!'));
1109 $lxdebug->leave_sub();
1113 $lxdebug->enter_sub();
1119 <form method=post action=$form->{script}>
1122 # delete action variable
1123 map { delete $form->{$_} } qw(action header);
1125 foreach $key (keys %$form) {
1126 $form->{$key} =~ s/\"/"/g;
1127 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1131 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1134 . $locale->text('Are you sure you want to delete Invoice Number')
1135 . qq| $form->{invnumber}</h4>
1137 <input name=action class=submit type=submit value="|
1138 . $locale->text('Yes') . qq|">
1142 $lxdebug->leave_sub();
1146 $lxdebug->enter_sub();
1147 if (IR->delete_invoice(\%myconfig, \%$form)) {
1148 # saving the history
1149 if(!exists $form->{addition}) {
1150 $form->{addition} = "DELETED";
1151 $form->save_history($form->dbconnect(\%myconfig));
1153 # /saving the history
1154 $form->redirect($locale->text('Invoice deleted!'));
1156 $form->error($locale->text('Cannot delete invoice!'));
1158 $lxdebug->leave_sub();