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_vendor} }) {
127 $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
128 map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" }
129 (@{ $form->{all_vendor} });
133 if ($form->{all_departments}) {
134 $form->{selectdepartment} = "<option>\n";
135 $form->{department} = "$form->{department}--$form->{department_id}";
138 $form->{selectdepartment} .=
139 "<option>$_->{description}--$_->{id}\n"
140 } (@{ $form->{all_departments} });
144 $form->{forex} = $form->{exchangerate};
145 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
147 foreach $key (keys %{ $form->{AP_links} }) {
149 foreach $ref (@{ $form->{AP_links}{$key} }) {
150 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
153 if ($key eq "AP_paid") {
154 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
155 $form->{"AP_paid_$i"} =
156 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
159 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
160 $form->{"datepaid_$i"} =
161 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
162 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
163 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
164 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
165 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
167 $form->{paidaccounts} = $i;
171 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
176 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
178 $form->{AP} = $form->{AP_1} unless $form->{id};
181 ($form->datetonum($form->{invdate}, \%myconfig) <=
182 $form->datetonum($form->{closedto}, \%myconfig));
184 $lxdebug->leave_sub();
187 sub prepare_invoice {
188 $lxdebug->enter_sub();
192 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
195 foreach $ref (@{ $form->{invoice_details} }) {
197 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
199 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
201 $decimalplaces = ($dec > 2) ? $dec : 2;
203 $form->{"sellprice_$i"} =
204 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
207 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
208 $dec_qty = length $dec_qty;
211 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
213 $form->{rowcount} = $i;
217 $lxdebug->leave_sub();
221 $lxdebug->enter_sub();
223 # set option selected
224 foreach $item (qw(AP vendor currency department)) {
225 $form->{"select$item"} =~ s/ selected//;
226 $form->{"select$item"} =~
227 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
231 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
233 #quote selectvendor Bug 133
234 $form->{"selectvendor"} = $form->quote($form->{"selectvendor"});
236 #substitute \n and \r to \s (bug 543)
237 $form->{"selectvendor"} =~ s/[\n\r]/ /g;
239 $form->{exchangerate} =
240 $form->format_amount(\%myconfig, $form->{exchangerate});
242 $form->{creditlimit} =
243 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
244 $form->{creditremaining} =
245 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
248 if ($form->{currency} ne $form->{defaultcurrency}) {
249 if ($form->{forex}) {
251 <th align=right nowrap>|
252 . $locale->text('Exchangerate') . qq|</th>
253 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
257 <th align=right nowrap>|
258 . $locale->text('Exchangerate') . qq|</th>
259 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
264 <input type=hidden name=forex value=$form->{forex}>
267 my @old_project_ids = ($form->{"globalproject_id"});
268 map({ push(@old_project_ids, $form->{"project_id_$_"})
269 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
271 $form->get_lists("contacts" => "ALL_CONTACTS",
272 "projects" => { "key" => "ALL_PROJECTS",
274 "old_id" => \@old_project_ids },
275 "taxzones" => "ALL_TAXZONES",
276 "employees" => "ALL_SALESMEN",
277 "currencies" => "ALL_CURRENCIES",
278 "vendors" => "ALL_VENDORS");
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})" : "");
289 if (scalar @values > 1) {
292 <th align="right">| . $locale->text('Contact Person') . qq|</th>
294 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
295 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
303 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
304 push(@values, $item->{"id"});
305 $labels{$item->{"id"}} = $item->{"projectnumber"};
307 my $globalprojectnumber =
308 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
309 '-labels' => \%labels,
310 '-default' => $form->{"globalproject_id"}));
315 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
316 push(@values, $item);
317 $labels{$item} = $item;
320 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
322 if (scalar @values) {
325 <th align="right">| . $locale->text('Currency') . qq|</th>
327 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
328 '-values' => \@values, '-labels' => \%labels)) . qq|
336 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
337 push(@values, $item->{"id"});
338 $labels{$item->{"id"}} = $item->{"name"};
342 <th align="right">| . $locale->text('Employee') . qq|</th>
344 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
345 '-values' => \@values, '-labels' => \%labels)) . qq|
352 foreach my $item (@{ $form->{"ALL_VENDORS"} }) {
353 push(@values, $item->{name}.qq|--|.$item->{"id"});
354 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
357 <th align="right">| . $locale->text('Vendor') . qq|</th>
359 NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{"vendor"},
360 '-onChange' => 'document.getElementById(\'update_button\').click();',
361 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
362 <input type="button" value="?" onclick="show_vc_details('vendor')">
367 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
368 push(@values, $item->{"id"});
369 $labels{$item->{"id"}} = $item->{"description"};
372 if (!$form->{"id"}) {
375 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
377 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
378 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
385 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
387 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
388 | . H($labels{$form->{"taxzone_id"}}) . qq|
395 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
396 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
397 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
400 | if $form->{selectdepartment};
402 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
404 # use JavaScript Calendar or not
405 $form->{jsscript} = 1;
409 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
410 <input type=button name=invdate id="trigger1" value=|
411 . $locale->text('button') . qq|></td>
414 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
415 <input type=button name=duedate id="trigger2" value=|
416 . $locale->text('button') . qq|></td></td>
421 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
422 "duedate", "BL", "trigger2");
424 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
425 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
426 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
429 $form->write_trigger(\%myconfig, 2,
430 "orddate", "BL", "trigger_orddate",
431 "quodate", "BL", "trigger_quodate");
434 $onload = qq|focus()|;
435 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
436 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
438 <body onLoad="$onload">
440 <form method=post action=$form->{script}>
443 $form->hide_form(qw(id title vc type level creditlimit creditremaining
444 closedto locked shippted storno storno_id
445 max_dunning_level dunning_amount));
447 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
451 <div class="listtop" width="100%">$form->{title}</div>
458 <input type="hidden" name="vendor_id" value="$form->{vendor_id}">
459 <input type="hidden" name="oldvendor" value="$form->{oldvendor}">
460 <input type="hidden" name="selectvendor" value= "1">
463 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
464 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
467 <th align="right">| . $locale->text('Record in') . qq|</th>
468 <td colspan="3"><select name="AP" style="width: 250px">$form->{selectAP}</select></td>
469 <input type="hidden" name="selectAP" value="$form->{selectAP}">
483 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
484 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
487 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
491 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
495 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
496 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
497 <input type=hidden name=quonumber value="$form->{quonumber}">
500 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
501 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
502 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
505 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
506 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
507 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
510 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
511 <td>$globalprojectnumber</td>
522 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
523 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
524 <input type=hidden name=webdav value=$webdav>
526 <input type=hidden name=taxpart value="$form->{taxpart}">
527 <input type=hidden name=taxservice value="$form->{taxservice}">
529 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
532 foreach $item (split / /, $form->{taxaccounts}) {
534 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
535 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
539 $lxdebug->leave_sub();
543 $lxdebug->enter_sub();
545 $form->{invtotal} = $form->{invsubtotal};
547 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
550 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
553 $rows = ($rows > $introws) ? $rows : $introws;
555 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
557 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
559 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
562 if ($form->{taxaccounts}) {
564 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
565 . $locale->text('Tax Included') . qq|</b>
569 if (!$form->{taxincluded}) {
571 foreach $item (split / /, $form->{taxaccounts}) {
572 if ($form->{"${item}_base"}) {
573 $form->{invtotal} += $form->{"${item}_total"} =
575 $form->{"${item}_base"} * $form->{"${item}_rate"},
577 $form->{"${item}_total"} =
578 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
582 <th align=right>$form->{"${item}_description"} |
583 . $form->{"${item}_rate"} * 100 .qq|%</th>
584 <td align=right>$form->{"${item}_total"}</td>
590 $form->{invsubtotal} =
591 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
595 <th align=right>| . $locale->text('Subtotal') . qq|</th>
596 <td align=right>$form->{invsubtotal}</td>
602 if ($form->{taxincluded}) {
603 foreach $item (split / /, $form->{taxaccounts}) {
604 if ($form->{"${item}_base"}) {
605 $form->{"${item}_total"} =
607 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
608 (1 + $form->{"${item}_rate"})
611 $form->{"${item}_base"} =
612 $form->round_amount($form->{"${item}_base"}, 2);
613 $form->{"${item}_netto"} =
615 ($form->{"${item}_base"} - $form->{"${item}_total"}),
617 $form->{"${item}_netto"} =
618 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
619 $form->{"${item}_total"} =
620 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
624 <th align=right>Enthaltene $form->{"${item}_description"} |
625 . $form->{"${item}_rate"} * 100 .qq|%</th>
626 <td align=right>$form->{"${item}_total"}</td>
629 <th align=right>Nettobetrag</th>
630 <td align=right>$form->{"${item}_netto"}</td>
638 $form->{oldinvtotal} = $form->{invtotal};
640 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
644 <td colspan=$colspan>
645 <table cellspacing="0">
650 <th align=left>| . $locale->text('Notes') . qq|</th>
651 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
659 <td colspan=2 align=right width=100%>
666 <th align=right>| . $locale->text('Total') . qq|</th>
667 <td align=right>$form->{invtotal}</td>
679 <td><hr size=3 noshade></td>
682 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
685 <td align=left width=30%><b>Dateiname</b></td>
686 <td align=left width=70%><b>Webdavlink</b></td>
688 foreach $file (keys %{ $form->{WEBDAV} }) {
691 <td align=left>$file</td>
692 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
705 <td colspan=$colspan>
708 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
712 if ($form->{currency} eq $form->{defaultcurrency}) {
713 @column_index = qw(datepaid source memo paid AP_paid);
715 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
718 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
719 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
720 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
721 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
722 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
723 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
728 map { print "$column_data{$_}\n" } @column_index;
734 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
735 for $i (1 .. $form->{paidaccounts}) {
741 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
742 $form->{"selectAP_paid_$i"} =~
743 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
746 if ($form->{"paid_$i"}) {
748 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
750 $form->{"exchangerate_$i"} =
751 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
753 $exchangerate = qq| |;
754 if ($form->{currency} ne $form->{defaultcurrency}) {
755 if ($form->{"forex_$i"}) {
757 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
760 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
764 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
767 $column_data{"paid_$i"} =
768 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
769 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
770 $column_data{"AP_paid_$i"} =
771 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
772 $column_data{"datepaid_$i"} =
773 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)\">
774 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
775 $column_data{"source_$i"} =
776 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
777 $column_data{"memo_$i"} =
778 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
780 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
785 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
789 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
790 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
791 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
796 <td><hr size=3 noshade></td>
802 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
803 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
805 print qq|<input class=submit type=submit name=action id=update_button value="|
806 . $locale->text('Update') . qq|">
810 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
812 print qq|<input class=submit type=submit name=action value="|
813 . $locale->text('Post Payment') . qq|">
815 print qq|<input class=submit type=submit name=action value="|
816 . $locale->text('Storno') . qq|">
818 if ($form->{radier}) {
820 <input class=submit type=submit name=action value="|
821 . $locale->text('Delete') . qq|">
824 print qq|<input class=submit type=submit name=action value="|
825 . $locale->text('Use As Template') . qq|">
830 if (!$form->{id} && ($invdate > $closedto)) {
831 print qq| <input class=submit type=submit name=action value="|
832 . $locale->text('Post') . qq|"> | .
833 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
834 '-class' => 'submit'));
837 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
838 $form->hide_form(qw(rowcount callback draft_id draft_description login password));
840 # button for saving history
841 if($form->{id} ne "") {
843 <input type="button" class="submit" onclick="set_history_window(|
845 . qq|);" name="history" id="history" value="|
846 . $locale->text('history')
849 # /button for saving history
857 $lxdebug->leave_sub();
861 $lxdebug->enter_sub();
863 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
864 qw(exchangerate creditlimit creditremaining);
868 $form->{exchangerate} = $exchangerate
872 $form->check_exchangerate(
873 \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
876 for $i (1 .. $form->{paidaccounts}) {
877 if ($form->{"paid_$i"}) {
880 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
881 } qw(paid exchangerate);
883 $form->{"exchangerate_$i"} = $exchangerate
885 $form->{"forex_$i"} = (
887 $form->check_exchangerate(
888 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
893 $i = $form->{rowcount};
894 $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
896 if ( ($form->{"partnumber_$i"} eq "")
897 && ($form->{"description_$i"} eq "")
898 && ($form->{"partsgroup_$i"} eq "")) {
899 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
904 IR->retrieve_item(\%myconfig, \%$form);
906 my $rows = scalar @{ $form->{item_list} };
909 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
918 # override sellprice if there is one entered
919 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
921 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
922 qw(partnumber description unit);
924 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
925 keys %{ $form->{item_list}[0] };
927 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
929 ($dec) = ($s =~ /\.(\d+)/);
931 $decimalplaces = ($dec > 2) ? $dec : 2;
934 $form->{"sellprice_$i"} = $sellprice;
937 # if there is an exchange rate adjust sellprice
938 $form->{"sellprice_$i"} /= $exchangerate;
942 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
943 (1 - $form->{"discount_$i"} / 100);
944 $form->{creditremaining} -= $amount;
945 $form->{"sellprice_$i"} =
946 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
949 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
956 # ok, so this is a new part
957 # ask if it is a part or service item
959 if ( $form->{"partsgroup_$i"}
960 && ($form->{"partsnumber_$i"} eq "")
961 && ($form->{"description_$i"} eq "")) {
963 $form->{"discount_$i"} = "";
967 $form->{"id_$i"} = 0;
968 $form->{"unit_$i"} = $locale->text('ea');
975 $lxdebug->leave_sub();
979 $lxdebug->enter_sub();
981 if ($form->{storno}) {
982 $form->error($locale->text('Cannot storno storno invoice!'));
985 if (IS->has_storno(\%myconfig, $form, "ap")) {
986 $form->error($locale->text("Invoice has already been storno'd!"));
989 my $employee_id = $form->{employee_id};
994 # Payments must not be recorded for the new storno invoice.
995 $form->{paidaccounts} = 0;
996 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
999 if(!exists $form->{addition} && $form->{id} ne "") {
1000 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1001 $form->{addition} = "CANCELED";
1002 $form->save_history($form->dbconnect(\%myconfig));
1004 # /saving the history
1006 $form->{storno_id} = $form->{id};
1007 $form->{storno} = 1;
1009 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1010 $form->{rowcount}++;
1011 $form->{employee_id} = $employee_id;
1013 $lxdebug->leave_sub();
1017 sub use_as_template {
1018 $lxdebug->enter_sub();
1020 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);
1021 $form->{paidaccounts} = 1;
1022 $form->{rowcount}--;
1023 $form->{invdate} = $form->current_date(\%myconfig);
1026 $lxdebug->leave_sub();
1030 $lxdebug->enter_sub();
1031 for $i (1 .. $form->{paidaccounts}) {
1032 if ($form->{"paid_$i"}) {
1033 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1035 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1037 $form->error($locale->text('Cannot post payment for a closed period!'))
1038 if ($datepaid <= $closedto);
1040 if ($form->{currency} ne $form->{defaultcurrency}) {
1041 $form->{"exchangerate_$i"} = $form->{exchangerate}
1042 if ($invdate == $datepaid);
1043 $form->isblank("exchangerate_$i",
1044 $locale->text('Exchangerate for payment missing!'));
1049 ($form->{AP}) = split /--/, $form->{AP};
1050 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1051 if (IR->post_payment(\%myconfig, \%$form)){
1053 if(!exists $form->{addition} && $form->{id} ne "") {
1054 # saving the history
1055 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1056 $form->{addition} = "PAYMENT POSTED";
1057 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
1058 $form->save_history($form->dbconnect(\%myconfig));
1059 # /saving the history
1060 $form->redirect($locale->text(' Payment posted!'));
1063 $form->error($locale->text('Cannot post payment!'));
1066 $lxdebug->leave_sub();
1070 $lxdebug->enter_sub();
1072 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1073 $form->isblank("vendor", $locale->text('Vendor missing!'));
1075 $form->{invnumber} =~ s/^\s*//g;
1076 $form->{invnumber} =~ s/\s*$//g;
1078 # if the vendor changed get new values
1079 if (&check_name(vendor)) {
1086 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1087 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1089 $form->error($locale->text('Cannot post invoice for a closed period!'))
1090 if ($invdate <= $closedto);
1092 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1093 if ($form->{currency} ne $form->{defaultcurrency});
1095 for $i (1 .. $form->{paidaccounts}) {
1096 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1097 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1099 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1101 $form->error($locale->text('Cannot post payment for a closed period!'))
1102 if ($datepaid <= $closedto);
1104 if ($form->{currency} ne $form->{defaultcurrency}) {
1105 $form->{"exchangerate_$i"} = $form->{exchangerate}
1106 if ($invdate == $datepaid);
1107 $form->isblank("exchangerate_$i",
1108 $locale->text('Exchangerate for payment missing!'));
1113 ($form->{AP}) = split /--/, $form->{AP};
1114 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1116 $form->{id} = 0 if $form->{postasnew};
1120 if (IR->post_invoice(\%myconfig, \%$form)){
1121 # saving the history
1122 if(!exists $form->{addition} && $form->{id} ne "") {
1123 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1124 $form->{addition} = "POSTED";
1125 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1126 $form->save_history($form->dbconnect(\%myconfig));
1128 # /saving the history
1129 remove_draft() if $form->{remove_draft};
1130 $form->redirect( $locale->text('Invoice')
1131 . " $form->{invnumber} "
1132 . $locale->text('posted!'));
1134 $form->error($locale->text('Cannot post invoice!'));
1136 $lxdebug->leave_sub();
1140 $lxdebug->enter_sub();
1146 <form method=post action=$form->{script}>
1149 # delete action variable
1150 map { delete $form->{$_} } qw(action header);
1152 foreach $key (keys %$form) {
1153 $form->{$key} =~ s/\"/"/g;
1154 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1158 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1161 . $locale->text('Are you sure you want to delete Invoice Number')
1162 . qq| $form->{invnumber}</h4>
1164 <input name=action class=submit type=submit value="|
1165 . $locale->text('Yes') . qq|">
1169 $lxdebug->leave_sub();
1173 $lxdebug->enter_sub();
1174 if (IR->delete_invoice(\%myconfig, \%$form)) {
1175 # saving the history
1176 if(!exists $form->{addition}) {
1177 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1178 $form->{addition} = "DELETED";
1179 $form->save_history($form->dbconnect(\%myconfig));
1181 # /saving the history
1182 $form->redirect($locale->text('Invoice deleted!'));
1184 $form->error($locale->text('Cannot delete invoice!'));
1186 $lxdebug->leave_sub();