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";
40 require "bin/mozilla/drafts.pl";
47 $lxdebug->enter_sub();
49 return $lxdebug->leave_sub() if (load_draft_maybe());
51 $form->{title} = $locale->text('Add Vendor Invoice');
57 $lxdebug->leave_sub();
61 $lxdebug->enter_sub();
64 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
65 #/show hhistory button
67 $form->{title} = $locale->text('Edit Vendor Invoice');
73 $lxdebug->leave_sub();
77 $lxdebug->enter_sub();
80 $form->{webdav} = $webdav;
83 $form->{jscalendar} = $jscalendar;
85 $form->create_links("AP", \%myconfig, "vendor");
87 #quote all_vendor Bug 133
88 foreach $ref (@{ $form->{all_vendor} }) {
89 $ref->{name} = $form->quote($ref->{name});
92 if ($form->{all_vendor}) {
93 unless ($form->{vendor_id}) {
94 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
97 if ($form->{payment_id}) {
98 $payment_id = $form->{payment_id};
100 if ($form->{language_id}) {
101 $language_id = $form->{language_id};
103 if ($form->{taxzone_id}) {
104 $taxzone_id = $form->{taxzone_id};
107 $cp_id = $form->{cp_id};
108 IR->get_vendor(\%myconfig, \%$form);
109 IR->retrieve_invoice(\%myconfig, \%$form);
110 $form->{cp_id} = $cp_id;
113 $form->{payment_id} = $payment_id;
116 $form->{language_id} = $language_id;
119 $form->{taxzone_id} = $taxzone_id;
123 @curr = split(/:/, $form->{currencies});
125 $form->{defaultcurrency} = $curr[0];
127 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
129 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
132 if (@{ $form->{all_vendor} }) {
133 $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
134 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
135 (@{ $form->{all_vendor} });
139 if ($form->{all_departments}) {
140 $form->{selectdepartment} = "<option>\n";
141 $form->{department} = "$form->{department}--$form->{department_id}";
144 $form->{selectdepartment} .=
145 "<option>$_->{description}--$_->{id}\n"
146 } (@{ $form->{all_departments} });
150 $form->{forex} = $form->{exchangerate};
151 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
153 foreach $key (keys %{ $form->{AP_links} }) {
155 foreach $ref (@{ $form->{AP_links}{$key} }) {
156 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
159 if ($key eq "AP_paid") {
160 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
161 $form->{"AP_paid_$i"} =
162 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
165 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
166 $form->{"datepaid_$i"} =
167 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
168 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
169 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
170 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
171 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
173 $form->{paidaccounts} = $i;
177 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
182 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
184 $form->{AP} = $form->{AP_1} unless $form->{id};
187 ($form->datetonum($form->{invdate}, \%myconfig) <=
188 $form->datetonum($form->{closedto}, \%myconfig));
190 $lxdebug->leave_sub();
193 sub prepare_invoice {
194 $lxdebug->enter_sub();
198 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
201 foreach $ref (@{ $form->{invoice_details} }) {
203 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
205 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
207 $decimalplaces = ($dec > 2) ? $dec : 2;
209 $form->{"sellprice_$i"} =
210 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
213 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
214 $dec_qty = length $dec_qty;
217 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
219 $form->{rowcount} = $i;
223 $lxdebug->leave_sub();
227 $lxdebug->enter_sub();
229 # set option selected
230 foreach $item (qw(AP vendor currency department)) {
231 $form->{"select$item"} =~ s/ selected//;
232 $form->{"select$item"} =~
233 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
237 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
239 #quote selectvendor Bug 133
240 $form->{"selectvendor"} = $form->quote($form->{"selectvendor"});
242 $form->{exchangerate} =
243 $form->format_amount(\%myconfig, $form->{exchangerate});
245 $form->{creditlimit} =
246 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
247 $form->{creditremaining} =
248 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
251 if ($form->{currency} ne $form->{defaultcurrency}) {
252 if ($form->{forex}) {
254 <th align=right nowrap>|
255 . $locale->text('Exchangerate') . qq|</th>
256 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
260 <th align=right nowrap>|
261 . $locale->text('Exchangerate') . qq|</th>
262 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
267 <input type=hidden name=forex value=$form->{forex}>
270 my @old_project_ids = ($form->{"globalproject_id"});
271 map({ push(@old_project_ids, $form->{"project_id_$_"})
272 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
274 $form->get_lists("contacts" => "ALL_CONTACTS",
275 "projects" => { "key" => "ALL_PROJECTS",
277 "old_id" => \@old_project_ids });
279 my (%labels, @values);
280 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
281 push(@values, $item->{"cp_id"});
282 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
283 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
286 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
287 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
291 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
292 push(@values, $item->{"id"});
293 $labels{$item->{"id"}} = $item->{"projectnumber"};
295 my $globalprojectnumber =
296 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
297 '-labels' => \%labels,
298 '-default' => $form->{"globalproject_id"}));
300 if (@{ $form->{TAXZONE} }) {
301 $form->{selecttaxzone} = "";
302 foreach $item (@{ $form->{TAXZONE} }) {
303 if ($item->{id} == $form->{taxzone_id}) {
304 $form->{selecttaxzone} .=
305 "<option value=$item->{id} selected>" . H($item->{description}) .
308 $form->{selecttaxzone} .=
309 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
314 $form->{selecttaxzone} =~ s/ selected//g;
315 if ($form->{taxzone_id} ne "") {
316 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
322 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
323 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
324 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
330 ($form->{selectvendor})
331 ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
332 : qq|<input name=vendor value="$form->{vendor}" size=35>|;
336 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
337 <td colspan=3><select name=department>$form->{selectdepartment}</select>
338 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
341 | if $form->{selectdepartment};
343 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
345 # use JavaScript Calendar or not
346 $form->{jsscript} = $form->{jscalendar};
348 if ($form->{jsscript}) {
350 # with JavaScript Calendar
352 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
353 <td><input type=button name=invdate id="trigger1" value=|
354 . $locale->text('button') . qq|></td>
357 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
358 <td width="4"><input type=button name=duedate id="trigger2" value=|
359 . $locale->text('button') . qq|></td></td>
364 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
365 "duedate", "BL", "trigger2");
368 # without JavaScript Calendar
370 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
372 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
375 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
378 $form->write_trigger(\%myconfig, 2,
379 "orddate", "BL", "trigger_orddate",
380 "quodate", "BL", "trigger_quodate");
387 <form method=post action=$form->{script}>
389 <input type=hidden name=id value=$form->{id}>
390 <input type=hidden name=title value="$form->{title}">
391 <input type=hidden name=vc value="vendor">
392 <input type=hidden name=type value=$form->{type}>
393 <input type=hidden name=level value=$form->{level}>
395 <input type=hidden name=creditlimit value=$form->{creditlimit}>
396 <input type=hidden name=creditremaining value=$form->{creditremaining}>
398 <input type=hidden name=closedto value=$form->{closedto}>
399 <input type=hidden name=locked value=$form->{locked}>
401 <input type=hidden name=shipped value=$form->{shipped}>
402 <input type=hidden name=storno value=$form->{storno}>
403 <input type=hidden name=storno_id value=$form->{storno_id}>
405 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
409 <th class=listtop>$form->{title}</th>
419 <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
420 <td colspan=3>$vendor</td>
422 <th align=richt nowrap>|
423 . $locale->text('Contact Person') . qq|</th>
424 <td colspan=3>$contact</td>
426 <input type=hidden name=vendor_id value=$form->{vendor_id}>
427 <input type=hidden name=oldvendor value="$form->{oldvendor}">
435 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
436 <td>$form->{creditlimit}</td>
438 <th nowrap>| . $locale->text('Remaining') . qq|</th>
439 <td class="plus$n">$form->{creditremaining}</td>
444 <th align=right>| . $locale->text('Record in') . qq|</th>
445 <td colspan=3><select name=AP>$form->{selectAP}</select></td>
446 <input type=hidden name=selectAP value="$form->{selectAP}">
451 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
452 <td><select name=currency>$form->{selectcurrency}</select></td>
460 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
461 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
464 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
468 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
472 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
473 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
474 <input type=hidden name=quonumber value="$form->{quonumber}">
477 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
478 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
479 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
482 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
483 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
484 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
487 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
488 <td>$globalprojectnumber</td>
499 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
500 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
501 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
502 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
503 <input type=hidden name=webdav value=$webdav>
505 <input type=hidden name=taxpart value="$form->{taxpart}">
506 <input type=hidden name=taxservice value="$form->{taxservice}">
508 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
511 foreach $item (split / /, $form->{taxaccounts}) {
513 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
514 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
518 $lxdebug->leave_sub();
522 $lxdebug->enter_sub();
524 $form->{invtotal} = $form->{invsubtotal};
526 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
529 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
532 $rows = ($rows > $introws) ? $rows : $introws;
534 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
536 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
538 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
541 if ($form->{taxaccounts}) {
543 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
544 . $locale->text('Tax Included') . qq|</b>
548 if (!$form->{taxincluded}) {
550 foreach $item (split / /, $form->{taxaccounts}) {
551 if ($form->{"${item}_base"}) {
552 $form->{invtotal} += $form->{"${item}_total"} =
554 $form->{"${item}_base"} * $form->{"${item}_rate"},
556 $form->{"${item}_total"} =
557 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
561 <th align=right>$form->{"${item}_description"} |
562 . $form->{"${item}_rate"} * 100 .qq|%</th>
563 <td align=right>$form->{"${item}_total"}</td>
569 $form->{invsubtotal} =
570 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
574 <th align=right>| . $locale->text('Subtotal') . qq|</th>
575 <td align=right>$form->{invsubtotal}</td>
581 if ($form->{taxincluded}) {
582 foreach $item (split / /, $form->{taxaccounts}) {
583 if ($form->{"${item}_base"}) {
584 $form->{"${item}_total"} =
586 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
587 (1 + $form->{"${item}_rate"})
590 $form->{"${item}_base"} =
591 $form->round_amount($form->{"${item}_base"}, 2);
592 $form->{"${item}_netto"} =
594 ($form->{"${item}_base"} - $form->{"${item}_total"}),
596 $form->{"${item}_netto"} =
597 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
598 $form->{"${item}_total"} =
599 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
603 <th align=right>Enthaltene $form->{"${item}_description"} |
604 . $form->{"${item}_rate"} * 100 .qq|%</th>
605 <td align=right>$form->{"${item}_total"}</td>
608 <th align=right>Nettobetrag</th>
609 <td align=right>$form->{"${item}_netto"}</td>
617 $form->{oldinvtotal} = $form->{invtotal};
619 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
623 <td colspan=$colspan>
624 <table cellspacing="0">
629 <th align=left>| . $locale->text('Notes') . qq|</th>
630 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
638 <td colspan=2 align=right width=100%>
645 <th align=right>| . $locale->text('Total') . qq|</th>
646 <td align=right>$form->{invtotal}</td>
658 <td><hr size=3 noshade></td>
661 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
664 <td align=left width=30%><b>Dateiname</b></td>
665 <td align=left width=70%><b>Webdavlink</b></td>
667 foreach $file (keys %{ $form->{WEBDAV} }) {
670 <td align=left>$file</td>
671 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
683 <input type=hidden name=jscalendar value=$form->{jscalendar}>
687 <td colspan=$colspan>
690 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
694 if ($form->{currency} eq $form->{defaultcurrency}) {
695 @column_index = qw(datepaid source memo paid AP_paid);
697 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
700 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
701 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
702 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
703 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
704 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
705 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
710 map { print "$column_data{$_}\n" } @column_index;
716 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
717 for $i (1 .. $form->{paidaccounts}) {
723 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
724 $form->{"selectAP_paid_$i"} =~
725 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
728 if ($form->{"paid_$i"}) {
730 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
732 $form->{"exchangerate_$i"} =
733 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
735 $exchangerate = qq| |;
736 if ($form->{currency} ne $form->{defaultcurrency}) {
737 if ($form->{"forex_$i"}) {
739 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
742 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
746 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
749 $column_data{"paid_$i"} =
750 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
751 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
752 $column_data{"AP_paid_$i"} =
753 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
754 $column_data{"datepaid_$i"} =
755 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
756 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
757 $column_data{"source_$i"} =
758 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
759 $column_data{"memo_$i"} =
760 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
762 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
767 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
771 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
772 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
773 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
778 <td><hr size=3 noshade></td>
784 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
785 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
788 print qq|<input class=submit type=submit name=action value="|
789 . $locale->text('Post Payment') . qq|">
791 print qq|<input class=submit type=submit name=action value="|
792 . $locale->text('Storno') . qq|">
793 | unless ($form->{storno});
794 if ($form->{radier}) {
796 <input class=submit type=submit name=action value="|
797 . $locale->text('Delete') . qq|">
800 print qq|<input class=submit type=submit name=action value="|
801 . $locale->text('Use As Template') . qq|">
806 print qq|<input class=submit type=submit name=action id=update_button value="|
807 . $locale->text('Update') . qq|">|;
809 if (!$form->{id} && ($invdate > $closedto)) {
810 print qq| <input class=submit type=submit name=action value="|
811 . $locale->text('Post') . qq|"> | .
812 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
813 '-class' => 'submit'));
816 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
819 <input type=hidden name=rowcount value=$form->{rowcount}>
821 <input name=callback type=hidden value="$form->{callback}">
823 <input type=hidden name=path value=$form->{path}>
824 <input type=hidden name=login value=$form->{login}>
825 <input type=hidden name=password value=$form->{password}>
827 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
828 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
830 # button for saving history
831 if($form->{id} ne "") {
833 <input type="button" class="submit" onclick="set_history_window(|
835 . qq|);" name="history" id="history" value="|
836 . $locale->text('history')
839 # /button for saving history
847 $lxdebug->leave_sub();
851 $lxdebug->enter_sub();
853 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
854 qw(exchangerate creditlimit creditremaining);
858 $form->{exchangerate} = $exchangerate
862 $form->check_exchangerate(
863 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
866 for $i (1 .. $form->{paidaccounts}) {
867 if ($form->{"paid_$i"}) {
870 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
871 } qw(paid exchangerate);
873 $form->{"exchangerate_$i"} = $exchangerate
875 $form->{"forex_$i"} = (
877 $form->check_exchangerate(
878 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
883 $i = $form->{rowcount};
884 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
886 if ( ($form->{"partnumber_$i"} eq "")
887 && ($form->{"description_$i"} eq "")
888 && ($form->{"partsgroup_$i"} eq "")) {
889 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
894 IR->retrieve_item(\%myconfig, \%$form);
896 my $rows = scalar @{ $form->{item_list} };
899 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
908 # override sellprice if there is one entered
909 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
911 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
912 qw(partnumber description unit);
914 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
915 keys %{ $form->{item_list}[0] };
917 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
919 ($dec) = ($s =~ /\.(\d+)/);
921 $decimalplaces = ($dec > 2) ? $dec : 2;
924 $form->{"sellprice_$i"} = $sellprice;
927 # if there is an exchange rate adjust sellprice
928 $form->{"sellprice_$i"} /= $exchangerate;
932 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
933 (1 - $form->{"discount_$i"} / 100);
934 $form->{creditremaining} -= $amount;
935 $form->{"sellprice_$i"} =
936 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
939 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
946 # ok, so this is a new part
947 # ask if it is a part or service item
949 if ( $form->{"partsgroup_$i"}
950 && ($form->{"partsnumber_$i"} eq "")
951 && ($form->{"description_$i"} eq "")) {
953 $form->{"discount_$i"} = "";
957 $form->{"id_$i"} = 0;
958 $form->{"unit_$i"} = $locale->text('ea');
965 $lxdebug->leave_sub();
969 $lxdebug->enter_sub();
971 if ($form->{storno}) {
972 $form->error($locale->text('Cannot storno storno invoice!'));
975 $form->{storno_id} = $form->{id};
978 $form->{invnumber} = "Storno zu " . $form->{invnumber};
981 $lxdebug->leave_sub();
985 sub use_as_template {
986 $lxdebug->enter_sub();
988 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);
989 $form->{paidaccounts} = 1;
991 $form->{invdate} = $form->current_date(\%myconfig);
994 $lxdebug->leave_sub();
998 $lxdebug->enter_sub();
999 for $i (1 .. $form->{paidaccounts}) {
1000 if ($form->{"paid_$i"}) {
1001 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1003 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1005 $form->error($locale->text('Cannot post payment for a closed period!'))
1006 if ($datepaid <= $closedto);
1008 if ($form->{currency} ne $form->{defaultcurrency}) {
1009 $form->{"exchangerate_$i"} = $form->{exchangerate}
1010 if ($invdate == $datepaid);
1011 $form->isblank("exchangerate_$i",
1012 $locale->text('Exchangerate for payment missing!'));
1017 ($form->{AP}) = split /--/, $form->{AP};
1018 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1019 if (IR->post_payment(\%myconfig, \%$form)){
1021 if(!exists $form->{addition} && $form->{id} ne "") {
1022 # saving the history
1023 $form->{addition} = "PAYMENT POSTED";
1024 $form->save_history($form->dbconnect(\%myconfig));
1025 # /saving the history
1026 $form->redirect($locale->text(' Payment posted!'));
1029 $form->error($locale->text('Cannot post payment!'));
1032 $lxdebug->leave_sub();
1036 $lxdebug->enter_sub();
1038 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1039 $form->isblank("vendor", $locale->text('Vendor missing!'));
1041 # if the vendor changed get new values
1042 if (&check_name(vendor)) {
1049 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1050 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1052 $form->error($locale->text('Cannot post invoice for a closed period!'))
1053 if ($invdate <= $closedto);
1055 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1056 if ($form->{currency} ne $form->{defaultcurrency});
1058 for $i (1 .. $form->{paidaccounts}) {
1059 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1060 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1062 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1064 $form->error($locale->text('Cannot post payment for a closed period!'))
1065 if ($datepaid <= $closedto);
1067 if ($form->{currency} ne $form->{defaultcurrency}) {
1068 $form->{"exchangerate_$i"} = $form->{exchangerate}
1069 if ($invdate == $datepaid);
1070 $form->isblank("exchangerate_$i",
1071 $locale->text('Exchangerate for payment missing!'));
1076 ($form->{AP}) = split /--/, $form->{AP};
1077 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1079 $form->{id} = 0 if $form->{postasnew};
1083 if (IR->post_invoice(\%myconfig, \%$form)){
1084 # saving the history
1085 if(!exists $form->{addition} && $form->{id} ne "") {
1086 $form->{addition} = "POSTED";
1087 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1088 $form->save_history($form->dbconnect(\%myconfig));
1090 # /saving the history
1091 remove_draft() if $form->{remove_draft};
1092 $form->redirect( $locale->text('Invoice')
1093 . " $form->{invnumber} "
1094 . $locale->text('posted!'));
1096 $form->error($locale->text('Cannot post invoice!'));
1098 $lxdebug->leave_sub();
1102 $lxdebug->enter_sub();
1108 <form method=post action=$form->{script}>
1111 # delete action variable
1112 map { delete $form->{$_} } qw(action header);
1114 foreach $key (keys %$form) {
1115 $form->{$key} =~ s/\"/"/g;
1116 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1120 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1123 . $locale->text('Are you sure you want to delete Invoice Number')
1124 . qq| $form->{invnumber}</h4>
1126 <input name=action class=submit type=submit value="|
1127 . $locale->text('Yes') . qq|">
1131 $lxdebug->leave_sub();
1135 $lxdebug->enter_sub();
1136 if (IR->delete_invoice(\%myconfig, \%$form)) {
1137 # saving the history
1138 if(!exists $form->{addition}) {
1139 $form->{addition} = "DELETED";
1140 $form->save_history($form->dbconnect(\%myconfig));
1142 # /saving the history
1143 $form->redirect($locale->text('Invoice deleted!'));
1145 $form->error($locale->text('Cannot delete invoice!'));
1147 $lxdebug->leave_sub();