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 "bin/mozilla/io.pl";
39 require "bin/mozilla/arap.pl";
40 require "bin/mozilla/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;
82 $form->{jsscript} = 1;
84 $form->create_links("AP", \%myconfig, "vendor");
86 #quote all_vendor Bug 133
87 foreach $ref (@{ $form->{all_vendor} }) {
88 $ref->{name} = $form->quote($ref->{name});
91 if ($form->{all_vendor}) {
92 unless ($form->{vendor_id}) {
93 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
96 if ($form->{payment_id}) {
97 $payment_id = $form->{payment_id};
99 if ($form->{language_id}) {
100 $language_id = $form->{language_id};
102 if ($form->{taxzone_id}) {
103 $taxzone_id = $form->{taxzone_id};
106 $cp_id = $form->{cp_id};
107 IR->get_vendor(\%myconfig, \%$form);
108 IR->retrieve_invoice(\%myconfig, \%$form);
109 $form->{cp_id} = $cp_id;
112 $form->{payment_id} = $payment_id;
115 $form->{language_id} = $language_id;
118 $form->{taxzone_id} = $taxzone_id;
121 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
123 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
126 if ($form->{all_departments}) {
127 $form->{selectdepartment} = "<option>\n";
128 $form->{department} = "$form->{department}--$form->{department_id}";
131 $form->{selectdepartment} .=
132 "<option>$_->{description}--$_->{id}\n"
133 } (@{ $form->{all_departments} });
137 $form->{forex} = $form->{exchangerate};
138 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
140 foreach $key (keys %{ $form->{AP_links} }) {
142 foreach $ref (@{ $form->{AP_links}{$key} }) {
143 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
146 if ($key eq "AP_paid") {
147 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
148 $form->{"AP_paid_$i"} =
149 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
152 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
153 $form->{"datepaid_$i"} =
154 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
155 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
156 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
157 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
158 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
160 $form->{paidaccounts} = $i;
164 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
169 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
171 $form->{AP} = $form->{AP_1} unless $form->{id};
174 ($form->datetonum($form->{invdate}, \%myconfig) <=
175 $form->datetonum($form->{closedto}, \%myconfig));
177 $lxdebug->leave_sub();
180 sub prepare_invoice {
181 $lxdebug->enter_sub();
185 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
188 foreach $ref (@{ $form->{invoice_details} }) {
190 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
192 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
194 $decimalplaces = ($dec > 2) ? $dec : 2;
196 $form->{"sellprice_$i"} =
197 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
200 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
201 $dec_qty = length $dec_qty;
204 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
206 $form->{rowcount} = $i;
210 $lxdebug->leave_sub();
214 $lxdebug->enter_sub();
216 # set option selected
217 foreach $item (qw(AP vendor currency department)) {
218 $form->{"select$item"} =~ s/ selected//;
219 $form->{"select$item"} =~
220 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
224 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
226 $form->{exchangerate} =
227 $form->format_amount(\%myconfig, $form->{exchangerate});
229 $form->{creditlimit} =
230 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
231 $form->{creditremaining} =
232 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
235 if ($form->{currency} ne $form->{defaultcurrency}) {
236 if ($form->{forex}) {
238 <th align=right nowrap>|
239 . $locale->text('Exchangerate') . qq|</th>
240 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
244 <th align=right nowrap>|
245 . $locale->text('Exchangerate') . qq|</th>
246 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
251 <input type=hidden name=forex value=$form->{forex}>
254 my @old_project_ids = ($form->{"globalproject_id"});
255 map({ push(@old_project_ids, $form->{"project_id_$_"})
256 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
258 $form->get_lists("contacts" => "ALL_CONTACTS",
259 "projects" => { "key" => "ALL_PROJECTS",
261 "old_id" => \@old_project_ids },
262 "taxzones" => "ALL_TAXZONES",
263 "employees" => "ALL_SALESMEN",
264 "currencies" => "ALL_CURRENCIES",
265 "vendors" => "ALL_VENDORS");
268 my @values = (undef);
269 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
270 push(@values, $item->{"cp_id"});
271 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
272 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
276 if (scalar @values > 1) {
279 <th align="right">| . $locale->text('Contact Person') . qq|</th>
281 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
282 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
290 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
291 push(@values, $item->{"id"});
292 $labels{$item->{"id"}} = $item->{"projectnumber"};
294 my $globalprojectnumber =
295 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
296 '-labels' => \%labels,
297 '-default' => $form->{"globalproject_id"}));
302 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
303 push(@values, $item);
304 $labels{$item} = $item;
307 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
309 if (scalar @values) {
312 <th align="right">| . $locale->text('Currency') . qq|</th>
314 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
315 '-values' => \@values, '-labels' => \%labels)) . qq|
323 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
324 push(@values, $item->{"id"});
325 $labels{$item->{"id"}} = $item->{"name"};
329 <th align="right">| . $locale->text('Employee') . qq|</th>
331 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
332 '-values' => \@values, '-labels' => \%labels)) . qq|
339 foreach my $item (@{ $form->{"ALL_VENDORS"} }) {
340 push(@values, $item->{name}.qq|--|.$item->{"id"});
341 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
344 $form->{selectvendor} = ($myconfig{vclimit} > scalar(@values));
347 <th align="right">| . $locale->text('Vendor') . qq|</th>
349 (($myconfig{vclimit} <= scalar(@values))
350 ? qq|<input type="text" value="| . H($form->{vendor}) . qq|" name="vendor">|
351 : (NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{oldvendor},
352 '-onChange' => 'document.getElementById(\'update_button\').click();',
353 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
354 <input type="button" value="?" onclick="show_vc_details('vendor')">
359 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
360 push(@values, $item->{"id"});
361 $labels{$item->{"id"}} = $item->{"description"};
364 if (!$form->{"id"}) {
367 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
369 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
370 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
377 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
379 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
380 | . H($labels{$form->{"taxzone_id"}}) . qq|
387 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
388 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
389 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
392 | if $form->{selectdepartment};
394 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
396 # use JavaScript Calendar or not
397 $form->{jsscript} = 1;
401 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
402 <input type=button name=invdate id="trigger1" value=|
403 . $locale->text('button') . qq|></td>
406 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
407 <input type=button name=duedate id="trigger2" value=|
408 . $locale->text('button') . qq|></td></td>
413 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
414 "duedate", "BL", "trigger2");
416 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
417 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
418 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
421 $form->write_trigger(\%myconfig, 2,
422 "orddate", "BL", "trigger_orddate",
423 "quodate", "BL", "trigger_quodate");
426 $onload = qq|focus()|;
427 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
428 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
430 <body onLoad="$onload">
432 <form method=post action=$form->{script}>
435 $form->hide_form(qw(id title vc type level creditlimit creditremaining
436 closedto locked shippted storno storno_id
437 max_dunning_level dunning_amount));
439 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
443 <div class="listtop" width="100%">$form->{title}</div>
450 <input type="hidden" name="vendor_id" value="$form->{vendor_id}">
451 <input type="hidden" name="oldvendor" value="$form->{oldvendor}">
452 <input type="hidden" name="selectvendor" value= "$form->{selectvendor}">
455 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
456 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
459 <th align="right">| . $locale->text('Record in') . qq|</th>
460 <td colspan="3"><select name="AP" style="width: 250px">$form->{selectAP}</select></td>
461 <input type="hidden" name="selectAP" value="$form->{selectAP}">
475 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
476 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
479 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
483 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
487 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
488 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
489 <input type=hidden name=quonumber value="$form->{quonumber}">
492 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
493 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
494 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
497 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
498 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
499 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
502 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
503 <td>$globalprojectnumber</td>
514 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
515 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
516 <input type=hidden name=webdav value=$webdav>
518 <input type=hidden name=taxpart value="$form->{taxpart}">
519 <input type=hidden name=taxservice value="$form->{taxservice}">
521 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
524 foreach $item (split / /, $form->{taxaccounts}) {
526 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
527 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
531 $lxdebug->leave_sub();
535 $lxdebug->enter_sub();
537 $form->{invtotal} = $form->{invsubtotal};
539 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
542 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
545 $rows = ($rows > $introws) ? $rows : $introws;
547 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
549 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
551 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
554 if ($form->{taxaccounts}) {
556 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
557 . $locale->text('Tax Included') . qq|</b>
561 if (!$form->{taxincluded}) {
563 foreach $item (split / /, $form->{taxaccounts}) {
564 if ($form->{"${item}_base"}) {
565 $form->{invtotal} += $form->{"${item}_total"} =
567 $form->{"${item}_base"} * $form->{"${item}_rate"},
569 $form->{"${item}_total"} =
570 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
574 <th align=right>$form->{"${item}_description"} |
575 . $form->{"${item}_rate"} * 100 .qq|%</th>
576 <td align=right>$form->{"${item}_total"}</td>
582 $form->{invsubtotal} =
583 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
587 <th align=right>| . $locale->text('Subtotal') . qq|</th>
588 <td align=right>$form->{invsubtotal}</td>
594 if ($form->{taxincluded}) {
595 foreach $item (split / /, $form->{taxaccounts}) {
596 if ($form->{"${item}_base"}) {
597 $form->{"${item}_total"} =
599 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
600 (1 + $form->{"${item}_rate"})
603 $form->{"${item}_base"} =
604 $form->round_amount($form->{"${item}_base"}, 2);
605 $form->{"${item}_netto"} =
607 ($form->{"${item}_base"} - $form->{"${item}_total"}),
609 $form->{"${item}_netto"} =
610 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
611 $form->{"${item}_total"} =
612 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
616 <th align=right>Enthaltene $form->{"${item}_description"} |
617 . $form->{"${item}_rate"} * 100 .qq|%</th>
618 <td align=right>$form->{"${item}_total"}</td>
621 <th align=right>Nettobetrag</th>
622 <td align=right>$form->{"${item}_netto"}</td>
630 $form->{oldinvtotal} = $form->{invtotal};
632 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
636 <td colspan=$colspan>
637 <table cellspacing="0">
642 <th align=left>| . $locale->text('Notes') . qq|</th>
643 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
651 <td colspan=2 align=right width=100%>
658 <th align=right>| . $locale->text('Total') . qq|</th>
659 <td align=right>$form->{invtotal}</td>
671 <td><hr size=3 noshade></td>
674 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
677 <td align=left width=30%><b>Dateiname</b></td>
678 <td align=left width=70%><b>Webdavlink</b></td>
680 foreach $file (keys %{ $form->{WEBDAV} }) {
683 <td align=left>$file</td>
684 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
697 <td colspan=$colspan>
700 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
704 if ($form->{currency} eq $form->{defaultcurrency}) {
705 @column_index = qw(datepaid source memo paid AP_paid);
707 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
710 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
711 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
712 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
713 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
714 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
715 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
720 map { print "$column_data{$_}\n" } @column_index;
728 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
729 for $i (1 .. $form->{paidaccounts}) {
735 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
736 $form->{"selectAP_paid_$i"} =~
737 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
739 $totalpaid += $form->{"paid_$i"};
742 if ($form->{"paid_$i"}) {
744 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
746 $form->{"exchangerate_$i"} =
747 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
749 $exchangerate = qq| |;
750 if ($form->{currency} ne $form->{defaultcurrency}) {
751 if ($form->{"forex_$i"}) {
753 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
756 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
760 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
763 $column_data{"paid_$i"} =
764 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
765 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
766 $column_data{"AP_paid_$i"} =
767 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
768 $column_data{"datepaid_$i"} =
769 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
770 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
771 $column_data{"source_$i"} =
772 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
773 $column_data{"memo_$i"} =
774 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
776 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
781 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
784 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
790 <td align="center">| . $locale->text('Total') . qq|</td>
791 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
796 <td align="center">| . $locale->text('Missing amount') . qq|</td>
797 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
800 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
801 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
802 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
807 <td><hr size=3 noshade></td>
813 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
814 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
816 print qq|<input class=submit type=submit name=action id=update_button value="|
817 . $locale->text('Update') . qq|">
821 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
823 print qq|<input class=submit type=submit name=action value="|
824 . $locale->text('Post Payment') . qq|">
826 print qq|<input class=submit type=submit name=action value="|
827 . $locale->text('Storno') . qq|">
829 if ($form->{radier}) {
831 <input class=submit type=submit name=action value="|
832 . $locale->text('Delete') . qq|">
835 print qq|<input class=submit type=submit name=action value="|
836 . $locale->text('Use As Template') . qq|">
841 if (!$form->{id} && ($invdate > $closedto)) {
842 print qq| <input class=submit type=submit name=action value="|
843 . $locale->text('Post') . qq|"> | .
844 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
845 '-class' => 'submit'));
848 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
849 $form->hide_form(qw(rowcount callback draft_id draft_description login password));
851 # button for saving history
852 if($form->{id} ne "") {
854 <input type="button" class="submit" onclick="set_history_window(|
856 . qq|);" name="history" id="history" value="|
857 . $locale->text('history')
860 # /button for saving history
868 $lxdebug->leave_sub();
872 $lxdebug->enter_sub();
874 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
875 qw(exchangerate creditlimit creditremaining);
879 $form->{exchangerate} = $exchangerate
883 $form->check_exchangerate(
884 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
887 for $i (1 .. $form->{paidaccounts}) {
888 if ($form->{"paid_$i"}) {
891 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
892 } qw(paid exchangerate);
894 $form->{"exchangerate_$i"} = $exchangerate
896 $form->{"forex_$i"} = (
898 $form->check_exchangerate(
899 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
904 $i = $form->{rowcount};
905 $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
907 if ( ($form->{"partnumber_$i"} eq "")
908 && ($form->{"description_$i"} eq "")
909 && ($form->{"partsgroup_$i"} eq "")) {
910 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
915 IR->retrieve_item(\%myconfig, \%$form);
917 my $rows = scalar @{ $form->{item_list} };
920 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
929 # override sellprice if there is one entered
930 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
932 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
933 qw(partnumber description unit);
935 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
936 keys %{ $form->{item_list}[0] };
938 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
940 ($dec) = ($s =~ /\.(\d+)/);
942 $decimalplaces = ($dec > 2) ? $dec : 2;
945 $form->{"sellprice_$i"} = $sellprice;
948 # if there is an exchange rate adjust sellprice
949 $form->{"sellprice_$i"} /= $exchangerate;
953 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
954 (1 - $form->{"discount_$i"} / 100);
955 $form->{creditremaining} -= $amount;
956 $form->{"sellprice_$i"} =
957 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
960 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
967 # ok, so this is a new part
968 # ask if it is a part or service item
970 if ( $form->{"partsgroup_$i"}
971 && ($form->{"partsnumber_$i"} eq "")
972 && ($form->{"description_$i"} eq "")) {
974 $form->{"discount_$i"} = "";
978 $form->{"id_$i"} = 0;
979 $form->{"unit_$i"} = $locale->text('ea');
986 $lxdebug->leave_sub();
990 $lxdebug->enter_sub();
992 if ($form->{storno}) {
993 $form->error($locale->text('Cannot storno storno invoice!'));
996 if (IS->has_storno(\%myconfig, $form, "ap")) {
997 $form->error($locale->text("Invoice has already been storno'd!"));
1000 my $employee_id = $form->{employee_id};
1005 # Payments must not be recorded for the new storno invoice.
1006 $form->{paidaccounts} = 0;
1007 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1009 # saving the history
1010 if(!exists $form->{addition} && $form->{id} ne "") {
1011 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1012 $form->{addition} = "CANCELED";
1013 $form->save_history($form->dbconnect(\%myconfig));
1015 # /saving the history
1017 $form->{storno_id} = $form->{id};
1018 $form->{storno} = 1;
1020 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1021 $form->{rowcount}++;
1022 $form->{employee_id} = $employee_id;
1024 $lxdebug->leave_sub();
1028 sub use_as_template {
1029 $lxdebug->enter_sub();
1031 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);
1032 $form->{paidaccounts} = 1;
1033 $form->{rowcount}--;
1034 $form->{invdate} = $form->current_date(\%myconfig);
1037 $lxdebug->leave_sub();
1041 $lxdebug->enter_sub();
1042 for $i (1 .. $form->{paidaccounts}) {
1043 if ($form->{"paid_$i"}) {
1044 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1046 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1048 $form->error($locale->text('Cannot post payment for a closed period!'))
1049 if ($datepaid <= $closedto);
1051 if ($form->{currency} ne $form->{defaultcurrency}) {
1052 $form->{"exchangerate_$i"} = $form->{exchangerate}
1053 if ($invdate == $datepaid);
1054 $form->isblank("exchangerate_$i",
1055 $locale->text('Exchangerate for payment missing!'));
1060 ($form->{AP}) = split /--/, $form->{AP};
1061 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1062 if (IR->post_payment(\%myconfig, \%$form)){
1063 if (!exists $form->{addition} && $form->{id} ne "") {
1064 # saving the history
1065 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1066 $form->{addition} = "PAYMENT POSTED";
1067 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
1068 $form->save_history($form->dbconnect(\%myconfig));
1069 # /saving the history
1072 $form->redirect($locale->text('Payment posted!'));
1075 $form->error($locale->text('Cannot post payment!'));
1077 $lxdebug->leave_sub();
1081 $lxdebug->enter_sub();
1083 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1084 $form->isblank("vendor", $locale->text('Vendor missing!'));
1086 $form->{invnumber} =~ s/^\s*//g;
1087 $form->{invnumber} =~ s/\s*$//g;
1089 # if the vendor changed get new values
1090 if (&check_name(vendor)) {
1097 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1098 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1100 $form->error($locale->text('Cannot post invoice for a closed period!'))
1101 if ($invdate <= $closedto);
1103 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1104 if ($form->{currency} ne $form->{defaultcurrency});
1106 for $i (1 .. $form->{paidaccounts}) {
1107 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1108 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1110 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1112 $form->error($locale->text('Cannot post payment for a closed period!'))
1113 if ($datepaid <= $closedto);
1115 if ($form->{currency} ne $form->{defaultcurrency}) {
1116 $form->{"exchangerate_$i"} = $form->{exchangerate}
1117 if ($invdate == $datepaid);
1118 $form->isblank("exchangerate_$i",
1119 $locale->text('Exchangerate for payment missing!'));
1124 ($form->{AP}) = split /--/, $form->{AP};
1125 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1127 $form->{id} = 0 if $form->{postasnew};
1131 if (IR->post_invoice(\%myconfig, \%$form)){
1132 # saving the history
1133 if(!exists $form->{addition} && $form->{id} ne "") {
1134 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1135 $form->{addition} = "POSTED";
1136 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1137 $form->save_history($form->dbconnect(\%myconfig));
1139 # /saving the history
1140 remove_draft() if $form->{remove_draft};
1141 $form->redirect( $locale->text('Invoice')
1142 . " $form->{invnumber} "
1143 . $locale->text('posted!'));
1145 $form->error($locale->text('Cannot post invoice!'));
1147 $lxdebug->leave_sub();
1151 $lxdebug->enter_sub();
1157 <form method=post action=$form->{script}>
1160 # delete action variable
1161 map { delete $form->{$_} } qw(action header);
1163 foreach $key (keys %$form) {
1164 $form->{$key} =~ s/\"/"/g;
1165 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1169 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1172 . $locale->text('Are you sure you want to delete Invoice Number')
1173 . qq| $form->{invnumber}</h4>
1175 <input name=action class=submit type=submit value="|
1176 . $locale->text('Yes') . qq|">
1180 $lxdebug->leave_sub();
1184 $lxdebug->enter_sub();
1185 if (IR->delete_invoice(\%myconfig, \%$form)) {
1186 # saving the history
1187 if(!exists $form->{addition}) {
1188 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1189 $form->{addition} = "DELETED";
1190 $form->save_history($form->dbconnect(\%myconfig));
1192 # /saving the history
1193 $form->redirect($locale->text('Invoice deleted!'));
1195 $form->error($locale->text('Cannot delete invoice!'));
1197 $lxdebug->leave_sub();