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 invoicing module
32 #======================================================================
37 use List::Util qw(max);
39 require "bin/mozilla/io.pl";
40 require "bin/mozilla/invoice_io.pl";
41 require "bin/mozilla/arap.pl";
42 require "bin/mozilla/drafts.pl";
49 $lxdebug->enter_sub();
51 $auth->assert('invoice_edit');
53 return $lxdebug->leave_sub() if (load_draft_maybe());
55 if ($form->{type} eq "credit_note") {
56 $form->{title} = $locale->text('Add Credit Note');
58 if ($form->{storno}) {
59 $form->{title} = $locale->text('Add Storno Credit Note');
62 $form->{title} = $locale->text('Add Sales Invoice');
67 $form->{callback} = "$form->{script}?action=add&type=$form->{type}" unless $form->{callback};
69 $form{jsscript} = "date";
71 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
73 $form->error("Access Denied");
79 $lxdebug->leave_sub();
83 $lxdebug->enter_sub();
85 $auth->assert('invoice_edit');
88 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
89 #/show hhistory button
91 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
93 $form->error("Access Denied");
96 if ($form->{print_and_post}) {
97 $form->{action} = "print";
98 $form->{resubmit} = 1;
99 $language_id = $form->{language_id};
100 $printer_id = $form->{printer_id};
104 if ($form->{print_and_post}) {
105 $form->{language_id} = $language_id;
106 $form->{printer_id} = $printer_id;
111 $lxdebug->leave_sub();
115 $lxdebug->enter_sub();
117 $auth->assert('invoice_edit');
119 $form->{vc} = 'customer';
122 $form->{webdav} = $webdav;
123 $form->{lizenzen} = $lizenzen;
125 $form->create_links("AR", \%myconfig, "customer");
127 if ($form->{all_customer}) {
128 unless ($form->{customer_id}) {
129 $form->{customer_id} = $form->{all_customer}->[0]->{id};
130 $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
134 if ($form->{payment_id}) {
135 $payment_id = $form->{payment_id};
137 if ($form->{language_id}) {
138 $language_id = $form->{language_id};
140 if ($form->{taxzone_id}) {
141 $taxzone_id = $form->{taxzone_id};
146 if ($form->{shipto_id}) {
147 $shipto_id = $form->{shipto_id};
150 $cp_id = $form->{cp_id};
151 IS->get_customer(\%myconfig, \%$form);
153 #quote all_customer Bug 133
154 foreach $ref (@{ $form->{all_customer} }) {
155 $ref->{name} = $form->quote($ref->{name});
160 IS->retrieve_invoice(\%myconfig, \%$form);
161 $form->{cp_id} = $cp_id;
164 $form->{payment_id} = $payment_id;
167 $form->{language_id} = $language_id;
170 $form->{taxzone_id} = $taxzone_id;
173 $form->{shipto_id} = $shipto_id;
176 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
179 if ($form->{all_departments}) {
180 $form->{selectdepartment} = "<option>\n";
181 $form->{department} = "$form->{department}--$form->{department_id}";
184 $form->{selectdepartment} .=
185 "<option>$_->{description}--$_->{id}</option>\n"
186 } (@{ $form->{all_departments} });
189 $form->{employee} = "$form->{employee}--$form->{employee_id}";
192 $form->{forex} = $form->{exchangerate};
193 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
195 foreach $key (keys %{ $form->{AR_links} }) {
196 foreach $ref (@{ $form->{AR_links}{$key} }) {
197 $form->{"select$key"} .=
198 "<option>$ref->{accno}--$ref->{description}</option>\n";
201 if ($key eq "AR_paid") {
202 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
203 $form->{"AR_paid_$i"} =
204 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
207 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
208 $form->{"datepaid_$i"} =
209 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
210 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
211 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
212 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
213 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
215 $form->{paidaccounts} = $i;
219 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
224 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
226 $form->{AR} = $form->{AR_1} unless $form->{id};
229 ($form->datetonum($form->{invdate}, \%myconfig) <=
230 $form->datetonum($form->{closedto}, \%myconfig));
232 $lxdebug->leave_sub();
235 sub prepare_invoice {
236 $lxdebug->enter_sub();
238 $auth->assert('invoice_edit');
240 if ($form->{type} eq "credit_note") {
241 $form->{type} = "credit_note";
242 $form->{formname} = "credit_note";
244 $form->{type} = "invoice";
245 $form->{formname} = "invoice";
250 map { $form->{$_} =~ s/\"/"/g }
251 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
253 # # get pricegroups for parts
254 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
258 foreach $ref (@{ $form->{invoice_details} }) {
261 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
262 $form->{"discount_$i"} =
263 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
264 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
266 $decimalplaces = ($dec > 2) ? $dec : 2;
268 $form->{"sellprice_$i"} =
269 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
272 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
273 $dec_qty = length $dec_qty;
276 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
278 map { $form->{"${_}_$i"} =~ s/\"/"/g }
279 qw(partnumber description unit partnotes);
280 $form->{rowcount} = $i;
284 $lxdebug->leave_sub();
288 $lxdebug->enter_sub();
290 $auth->assert('invoice_edit');
292 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
293 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
296 if ($form->{type} eq "credit_note") {
297 $form->{title} = $locale->text('Edit Credit Note');
298 $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
300 $form->{title} = $locale->text('Edit Sales Invoice');
301 $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
304 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
305 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
307 $payment = qq|<option value=""></option>|;
308 foreach $item (@{ $form->{payment_terms} }) {
309 if ($form->{payment_id} eq $item->{id}) {
310 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
312 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
316 my $set_duedate_url = "$form->{script}?action=set_duedate";
318 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
319 push(@ { $form->{AJAX} }, $pjx);
321 my @old_project_ids = ($form->{"globalproject_id"});
322 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
324 $form->get_lists("contacts" => "ALL_CONTACTS",
325 "shipto" => "ALL_SHIPTO",
326 "projects" => { "key" => "ALL_PROJECTS",
328 "old_id" => \@old_project_ids },
329 "employees" => "ALL_SALESMEN",
330 "taxzones" => "ALL_TAXZONES",
331 "currencies" => "ALL_CURRENCIES",
332 "customers" => "ALL_CUSTOMERS",
333 "price_factors" => "ALL_PRICE_FACTORS");
336 my @values = (undef);
337 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
338 push(@values, $item->{"cp_id"});
339 $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
342 if (scalar @values > 1) {
345 <th align="right">| . $locale->text('Contact Person') . qq|</th>
346 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
347 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
354 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
355 push(@values, $item->{"id"});
356 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
361 <th align="right">| . $locale->text('Employee') . qq|</th>
362 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
363 '-values' => \@values, '-labels' => \%labels)) . qq|
370 foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
371 push(@values, $item->{name}.qq|--|.$item->{"id"});
372 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
375 $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
378 <th align="right">| . $locale->text('Customer') . qq|</th>
380 (($myconfig{vclimit} <= scalar(@values))
381 ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
382 : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
383 '-onChange' => 'document.getElementById(\'update_button\').click();',
384 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
385 <input type="button" value="?" onclick="show_vc_details('customer')">
390 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
391 push(@values, $item->{"shipto_id"});
392 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
396 if (scalar @values > 1) {
399 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
400 <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
401 '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
407 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
408 push(@values, $item);
409 $labels{$item} = $item;
412 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
414 if (scalar @values) {
417 <th align="right">| . $locale->text('Currency') . qq|</th>
418 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
419 '-values' => \@values, '-labels' => \%labels)) . qq|
426 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
427 push(@values, $item->{"id"});
428 $labels{$item->{"id"}} = $item->{"projectnumber"};
430 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
431 '-labels' => \%labels,
432 '-default' => $form->{"globalproject_id"}));
436 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
437 push(@values, $item->{id});
438 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
442 qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
443 <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
444 '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
450 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
451 push(@values, $item->{"id"});
452 $labels{$item->{"id"}} = $item->{"description"};
455 if (!$form->{"id"}) {
458 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
459 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
460 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
467 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
469 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
470 | . H($labels{$form->{"taxzone_id"}}) . qq|
475 # set option selected
476 foreach $item (qw(AR customer currency department employee)) {
477 $form->{"select$item"} =~ s/ selected//;
478 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
481 $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
483 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
484 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
485 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
488 if ($form->{currency} ne $form->{defaultcurrency}) {
489 if ($form->{forex}) {
490 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
491 <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
493 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
494 <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
497 $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
501 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
502 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
503 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
506 | if $form->{selectdepartment};
508 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
510 if ($form->{business}) {
513 <th align="right">| . $locale->text('Customer type') . qq|</th>
514 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
515 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
521 if ($form->{max_dunning_level}) {
524 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
526 <b>$form->{max_dunning_level}</b>;
527 | . $locale->text('Dunning Amount') . qq|: <b>|
528 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
535 $form->{fokus} = "invoice.customer";
537 # use JavaScript Calendar or not
538 $form->{jsscript} = 1;
540 if ($form->{type} eq "credit_note") {
542 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
543 <input type="button" name="invdate" id="trigger1" value="|
544 . $locale->text('button') . qq|"></td>|;
548 Form->write_trigger(\%myconfig, "1",
553 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
554 <input type="button" name="invdate" id="trigger1" value="|
555 . $locale->text('button') . qq|"></td>
558 <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
559 <input type="button" name="duedate" id="trigger2" value="|
560 . $locale->text('button') . qq|"></td>
563 <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
564 <input type="button" name="deliverydate" id="trigger3" value="|
565 . $locale->text('button') . qq|"></td>
570 Form->write_trigger(\%myconfig, "3",
571 "invdate", "BL", "trigger1",
572 "duedate", "BL", "trigger2",
573 "deliverydate", "BL", "trigger3");
576 $credittext = $locale->text('Credit Limit exceeded!!!');
577 $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
578 : ($form->{resubmit}) ? qq|document.invoice.submit()|
579 : ($creditwarning) ? qq|alert('$credittext')|
581 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
582 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
584 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
585 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
588 $form->write_trigger(\%myconfig, 2,
589 "orddate", "BL", "trigger_orddate",
590 "quodate", "BL", "trigger_quodate");
591 # show history button js
592 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
593 #/show history button js
597 <body onLoad="$onload">
598 <script type="text/javascript" src="js/common.js"></script>
599 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
600 <script type="text/javascript" src="js/vendor_selection.js"></script>
601 <script type="text/javascript" src="js/calculate_qty.js"></script>
603 <form method="post" name="invoice" action="$form->{script}">
606 $form->hide_form(qw(id action type media format queued printed emailed title vc discount
607 creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
608 max_dunning_level dunning_amount
609 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
610 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts),
611 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
613 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
617 <input type="hidden" name="lizenzen" value="$lizenzen">
619 <div class="listtop" width="100%">$form->{title}</div>
627 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">
628 <input type="hidden" name="customer_id" value="$form->{customer_id}">
629 <input type="hidden" name="oldcustomer" value="$form->{oldcustomer}">
630 <input type="hidden" name="selectcustomer" value="$form->{selectcustomer}">
635 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
636 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
641 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
642 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
643 <input type="hidden" name="selectAR" value="$form->{selectAR}">
649 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
650 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
654 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
656 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
659 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
660 <td colspan="3"><input name="shipvia" size="35" value="$form->{shipvia}"></td>
663 <th align="right">| . $locale->text('Transaction description') . qq|</th>
664 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
671 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
673 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
674 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
678 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
680 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
681 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
688 <td align="right" valign="top">
693 if ($form->{type} eq "credit_note") {
695 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
696 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
699 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
704 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
705 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
708 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
712 <th align="right">| . $locale->text('Due Date') . qq|</th>
716 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
721 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
722 <td><input name="ordnumber" size="11" value="$form->{ordnumber}"></td>
725 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
726 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
727 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
730 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
731 <td><input name="quonumber" size="11" value="$form->{quonumber}"></td>
734 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
735 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
736 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
739 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
740 <td><input name="cusordnumber" size="11" value="$form->{cusordnumber}"></td>
743 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
744 <td>$globalprojectnumber</td>
758 print qq|<input type="hidden" name="webdav" value="$webdav">|;
760 $lxdebug->leave_sub();
764 $lxdebug->enter_sub();
766 $auth->assert('invoice_edit');
768 $form->{invtotal} = $form->{invsubtotal};
770 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
773 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
776 $rows = ($rows > $introws) ? $rows : $introws;
778 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
780 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
782 $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
785 if ($form->{taxaccounts}) {
787 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
788 . $locale->text('Tax Included') . qq|</b><br><br>|;
791 if (!$form->{taxincluded}) {
793 foreach $item (split / /, $form->{taxaccounts}) {
794 if ($form->{"${item}_base"}) {
795 $form->{"${item}_total"} =
797 $form->{"${item}_base"} * $form->{"${item}_rate"},
799 $form->{invtotal} += $form->{"${item}_total"};
800 $form->{"${item}_total"} =
801 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
805 <th align="right">$form->{"${item}_description"} |
806 . $form->{"${item}_rate"} * 100 .qq|%</th>
807 <td align="right">$form->{"${item}_total"}</td>
813 $form->{invsubtotal} =
814 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
818 <th align="right">| . $locale->text('Subtotal') . qq|</th>
819 <td align="right">$form->{invsubtotal}</td>
825 if ($form->{taxincluded}) {
826 foreach $item (split / /, $form->{taxaccounts}) {
827 if ($form->{"${item}_base"}) {
828 $form->{"${item}_total"} =
830 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
831 (1 + $form->{"${item}_rate"})
834 $form->{"${item}_netto"} =
836 ($form->{"${item}_base"} - $form->{"${item}_total"}),
838 $form->{"${item}_total"} =
839 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
840 $form->{"${item}_netto"} =
841 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
845 <th align="right">Enthaltene $form->{"${item}_description"} |
846 . $form->{"${item}_rate"} * 100 .qq|%</th>
847 <td align="right">$form->{"${item}_total"}</td>
850 <th align="right">Nettobetrag</th>
851 <td align="right">$form->{"${item}_netto"}</td>
859 $form->{oldinvtotal} = $form->{invtotal};
861 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
871 <th align="left">| . $locale->text('Notes') . qq|</th>
872 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
873 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
878 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
886 <th align=left>| . $locale->text('Ertrag') . qq|</th>
887 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
890 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
891 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
893 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
894 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
903 <th align="right">| . $locale->text('Total') . qq|</th>
904 <td align="right">$form->{invtotal}</td>
916 <td><hr size="3" noshade></td>
919 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
922 <td align="left" width="30%"><b>Dateiname</b></td>
923 <td align="left" width="70%"><b>Webdavlink</b></td>
925 foreach $file (@{ $form->{WEBDAV} }) {
928 <td align="left">$file->{name}</td>
929 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
940 if ($form->{type} eq "credit_note") {
945 <tr class="listheading">
946 <th colspan="6" class="listheading">|
947 . $locale->text('Payments') . qq|</th>
955 <tr class="listheading">
956 <th colspan="6" class="listheading">|
957 . $locale->text('Incoming Payments') . qq|</th>
962 if ($form->{currency} eq $form->{defaultcurrency}) {
963 @column_index = qw(datepaid source memo paid AR_paid);
965 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
968 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
969 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
970 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
971 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
972 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
973 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
978 map { print "$column_data{$_}\n" } @column_index;
986 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
987 for $i (1 .. $form->{paidaccounts}) {
992 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
993 $form->{"selectAR_paid_$i"} =~
994 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
997 $totalpaid += $form->{"paid_$i"};
998 if ($form->{"paid_$i"}) {
1000 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1002 $form->{"exchangerate_$i"} =
1003 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1005 if ($form->{"exchangerate_$i"} == 0) {
1006 $form->{"exchangerate_$i"} = "";
1008 $exchangerate = qq| |;
1009 if ($form->{currency} ne $form->{defaultcurrency}) {
1010 if ($form->{"forex_$i"}) {
1011 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1013 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1017 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1019 $column_data{"paid_$i"} =
1020 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
1021 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1022 $column_data{"AR_paid_$i"} =
1023 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1024 $column_data{"datepaid_$i"} =
1025 qq|<td align="center"><input id="datepaid_$i" name="datepaid_$i" size="11" title="$myconfig{dateformat}" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
1026 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1027 $column_data{"source_$i"} =
1028 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1029 $column_data{"memo_$i"} =
1030 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1032 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1035 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1038 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
1044 <td align="center">| . $locale->text('Total') . qq|</td>
1045 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
1050 <td align="center">| . $locale->text('Missing amount') . qq|</td>
1051 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
1055 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1056 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1061 <td><hr size="3" noshade></td>
1075 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1076 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1079 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
1082 <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
1083 . $locale->text('Update') . qq|">
1084 <input class="submit" type="submit" name="action" value="|
1085 . $locale->text('Ship to') . qq|">
1086 <input class="submit" type="submit" name="action" value="|
1087 . $locale->text('Print') . qq|">
1088 <input class="submit" type="submit" name="action" value="|
1089 . $locale->text('E-mail') . qq|"> |;
1090 print qq|<input class="submit" type="submit" name="action" value="|
1091 . $locale->text('Storno') . qq|"> | if ($show_storno);
1092 print qq|<input class="submit" type="submit" name="action" value="|
1093 . $locale->text('Post Payment') . qq|">
1095 print qq|<input class="submit" type="submit" name="action" value="|
1096 . $locale->text('Use As Template') . qq|">
1098 if ($form->{id} && !($form->{type} eq "credit_note")) {
1100 <input class="submit" type="submit" name="action" value="|
1101 . $locale->text('Credit Note') . qq|">
1104 if ($form->{radier}) {
1106 <input class="submit" type="submit" name="action" value="|
1107 . $locale->text('Delete') . qq|">
1112 if ($invdate > $closedto) {
1114 <input class="submit" type="submit" name="action" value="|
1115 . $locale->text('Order') . qq|">
1120 if ($invdate > $closedto) {
1121 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1122 . $locale->text('Update') . qq|">
1123 <input class="submit" type="submit" name="action" value="|
1124 . $locale->text('Ship to') . qq|">
1125 <input class="submit" type="submit" name="action" value="|
1126 . $locale->text('Preview') . qq|">
1127 <input class="submit" type="submit" name="action" value="|
1128 . $locale->text('E-mail') . qq|">
1129 <input class="submit" type="submit" name="action" value="|
1130 . $locale->text('Print and Post') . qq|">
1131 <input class="submit" type="submit" name="action" value="|
1132 . $locale->text('Post') . qq|"> | .
1133 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1134 '-class' => 'submit'));
1138 # button for saving history
1139 if($form->{id} ne "") {
1141 <input type="button" class="submit" onclick="set_history_window(|
1143 . qq|);" name="history" id="history" value="|
1144 . $locale->text('history')
1147 # /button for saving history
1149 # mark_as_paid button
1150 if($form->{id} ne "") {
1151 print qq|<input type="submit" class="submit" name="action" value="|
1152 . $locale->text('mark as paid') . qq|">|;
1154 # /mark_as_paid button
1155 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1158 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1160 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1161 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1162 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
1171 $lxdebug->leave_sub();
1175 $lxdebug->enter_sub();
1177 $auth->assert('invoice_edit');
1179 &mark_as_paid_common(\%myconfig,"ar");
1181 $lxdebug->leave_sub();
1185 $lxdebug->enter_sub();
1187 $auth->assert('invoice_edit');
1189 my ($recursive_call) = shift;
1191 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
1193 $form->{print_and_post} = 0 if $form->{second_run};
1194 $taxincluded = "checked" if $form->{taxincluded};
1195 $form->{update} = 1;
1197 &check_name(customer);
1199 $form->{taxincluded} ||= $taxincluded;
1201 $form->{exchangerate} = $exchangerate if
1202 $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1204 for $i (1 .. $form->{paidaccounts}) {
1205 next unless $form->{"paid_$i"};
1206 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1207 $form->{"exchangerate_$i"} = $exchangerate if
1208 $form->{"forex_$i"} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1211 $i = $form->{rowcount};
1212 $exchangerate = $form->{exchangerate} || 1;
1214 # if last row empty, check the form otherwise retrieve new item
1215 if ( ($form->{"partnumber_$i"} eq "")
1216 && ($form->{"description_$i"} eq "")
1217 && ($form->{"partsgroup_$i"} eq "")) {
1219 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1224 IS->retrieve_item(\%myconfig, \%$form);
1226 $rows = scalar @{ $form->{item_list} };
1228 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
1231 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1240 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1242 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1243 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1245 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1246 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1248 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1250 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1251 $decimalplaces = max 2, length $1;
1254 $form->{"sellprice_$i"} = $sellprice;
1256 # if there is an exchange rate adjust sellprice
1257 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1258 $form->{"sellprice_$i"} /= $exchangerate;
1261 $form->{"listprice_$i"} /= $exchangerate;
1263 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1264 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1265 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1266 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1268 $form->{creditremaining} -= $amount;
1270 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
1272 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1275 if ($form->{"inventory_accno_$i"} ne "") {
1276 $form->{"lizenzen_$i"} = qq|<option></option>|;
1277 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1278 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1280 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
1284 # get pricegroups for parts
1285 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1287 # build up html code for prices_$i
1288 &set_pricegroup($i);
1295 # ok, so this is a new part
1296 # ask if it is a part or service item
1298 if ( $form->{"partsgroup_$i"}
1299 && ($form->{"partsnumber_$i"} eq "")
1300 && ($form->{"description_$i"} eq "")) {
1301 $form->{rowcount}--;
1302 $form->{"discount_$i"} = "";
1306 $form->{"id_$i"} = 0;
1311 $lxdebug->leave_sub();
1315 $lxdebug->enter_sub();
1317 $auth->assert('invoice_edit');
1319 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1320 for $i (1 .. $form->{paidaccounts}) {
1321 if ($form->{"paid_$i"}) {
1322 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1324 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1326 $form->error($locale->text('Cannot post payment for a closed period!'))
1327 if ($datepaid <= $closedto);
1329 if ($form->{currency} ne $form->{defaultcurrency}) {
1330 $form->{"exchangerate_$i"} = $form->{exchangerate}
1331 if ($invdate == $datepaid);
1332 $form->isblank("exchangerate_$i",
1333 $locale->text('Exchangerate for payment missing!'));
1338 ($form->{AR}) = split /--/, $form->{AR};
1339 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1341 $form->redirect($locale->text('Payment posted!'))
1342 if (IS->post_payment(\%myconfig, \%$form));
1343 $form->error($locale->text('Cannot post payment!'));
1346 $lxdebug->leave_sub();
1350 $lxdebug->enter_sub();
1352 $auth->assert('invoice_edit');
1354 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1355 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1356 $form->isblank("customer", $locale->text('Customer missing!'));
1358 $form->{invnumber} =~ s/^\s*//g;
1359 $form->{invnumber} =~ s/\s*$//g;
1361 # if oldcustomer ne customer redo form
1362 if (&check_name(customer)) {
1366 if ($form->{second_run}) {
1367 $form->{print_and_post} = 0;
1372 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1373 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1375 $form->error($locale->text('Cannot post invoice for a closed period!'))
1376 if ($invdate <= $closedto);
1378 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1379 if ($form->{currency} ne $form->{defaultcurrency});
1381 for $i (1 .. $form->{paidaccounts}) {
1382 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1383 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1385 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1387 $form->error($locale->text('Cannot post payment for a closed period!'))
1388 if ($datepaid <= $closedto);
1390 if ($form->{currency} ne $form->{defaultcurrency}) {
1391 $form->{"exchangerate_$i"} = $form->{exchangerate}
1392 if ($invdate == $datepaid);
1393 $form->isblank("exchangerate_$i",
1394 $locale->text('Exchangerate for payment missing!'));
1399 ($form->{AR}) = split /--/, $form->{AR};
1400 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1401 $form->{storno} ||= 0;
1403 $form->{label} = $locale->text('Invoice');
1405 $form->{id} = 0 if $form->{postasnew};
1407 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1408 if ($form->{postasnew}) {
1409 if ($form->{type} eq "credit_note") {
1410 undef($form->{cnnumber});
1412 undef($form->{invnumber});
1417 $form->error($locale->text('Cannot post invoice!'))
1418 unless IS->post_invoice(\%myconfig, \%$form);
1419 remove_draft() if $form->{remove_draft};
1421 if(!exists $form->{addition}) {
1422 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1423 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1424 $form->{storno} ? "STORNO" :
1426 $form->save_history($form->dbconnect(\%myconfig));
1429 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1432 $lxdebug->leave_sub();
1435 sub print_and_post {
1436 $lxdebug->enter_sub();
1438 $auth->assert('invoice_edit');
1440 $old_form = new Form;
1442 $form->{print_and_post} = 1;
1446 $lxdebug->leave_sub();
1450 sub use_as_template {
1451 $lxdebug->enter_sub();
1453 $auth->assert('invoice_edit');
1455 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);
1456 $form->{paidaccounts} = 1;
1457 $form->{rowcount}--;
1458 $form->{invdate} = $form->current_date(\%myconfig);
1461 $lxdebug->leave_sub();
1465 $lxdebug->enter_sub();
1467 $auth->assert('invoice_edit');
1469 if ($form->{storno}) {
1470 $form->error($locale->text('Cannot storno storno invoice!'));
1473 if (IS->has_storno(\%myconfig, $form, "ar")) {
1474 $form->error($locale->text("Invoice has already been storno'd!"));
1477 map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
1483 # Payments must not be recorded for the new storno invoice.
1484 $form->{paidaccounts} = 0;
1485 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1487 $form->{storno_id} = $form->{id};
1488 $form->{storno} = 1;
1490 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1491 $form->{rowcount}++;
1494 $lxdebug->leave_sub();
1498 $lxdebug->enter_sub();
1500 $auth->assert('invoice_edit');
1502 $form->{preview} = 1;
1503 $old_form = new Form;
1504 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1506 &print_form($old_form);
1507 $lxdebug->leave_sub();
1512 $lxdebug->enter_sub();
1514 $auth->assert('invoice_edit');
1516 if ($form->{second_run}) {
1517 $form->{print_and_post} = 0;
1524 <form method="post" action="$form->{script}">
1527 # delete action variable
1528 map { delete $form->{$_} } qw(action header);
1530 foreach $key (keys %$form) {
1531 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1532 $form->{$key} =~ s/\"/"/g;
1533 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1537 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1540 . $locale->text('Are you sure you want to delete Invoice Number')
1541 . qq| $form->{invnumber}
1545 <input name="action" class="submit" type="submit" value="|
1546 . $locale->text('Yes') . qq|">
1550 $lxdebug->leave_sub();
1554 $lxdebug->enter_sub();
1556 $auth->assert('invoice_edit');
1558 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1560 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1563 $form->{rowcount}--;
1564 $form->{shipto} = 1;
1567 $form->{title} = $locale->text('Add Credit Note');
1568 $form->{script} = 'is.pl';
1573 # bo creates the id, reset it
1574 map { delete $form->{$_} }
1575 qw(id invnumber subject message cc bcc printed emailed queued);
1576 $form->{ $form->{vc} } =~ s/--.*//g;
1577 $form->{type} = "credit_note";
1580 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1582 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1583 qw(creditlimit creditremaining);
1585 $currency = $form->{currency};
1588 $form->{currency} = $currency;
1589 $form->{exchangerate} = "";
1590 $form->{forex} = "";
1591 $form->{exchangerate} = $exchangerate
1595 $form->check_exchangerate(
1596 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1599 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1606 $lxdebug->leave_sub();
1610 $lxdebug->enter_sub();
1612 $auth->assert('invoice_edit');
1614 if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
1615 # saving the history
1616 if(!exists $form->{addition}) {
1617 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1618 $form->{addition} = "DELETED";
1619 $form->save_history($form->dbconnect(\%myconfig));
1621 # /saving the history
1622 $form->redirect($locale->text('Invoice deleted!'));
1624 $form->error($locale->text('Cannot delete invoice!'));
1626 $lxdebug->leave_sub();
1630 $lxdebug->enter_sub();
1632 $auth->assert('invoice_edit');
1637 my $saved_form = save_form();
1641 restore_form($saved_form, 0, qw(id invnumber));
1646 $lxdebug->leave_sub();