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 return $lxdebug->leave_sub() if (load_draft_maybe());
53 if ($form->{type} eq "credit_note") {
54 $form->{title} = $locale->text('Add Credit Note');
56 if ($form->{storno}) {
57 $form->{title} = $locale->text('Add Storno Credit Note');
60 $form->{title} = $locale->text('Add Sales Invoice');
66 "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&password=$form->{password}"
67 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();
86 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
87 #/show hhistory button
89 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
91 $form->error("Access Denied");
94 if ($form->{print_and_post}) {
95 $form->{action} = "print";
96 $form->{resubmit} = 1;
97 $language_id = $form->{language_id};
98 $printer_id = $form->{printer_id};
102 if ($form->{print_and_post}) {
103 $form->{language_id} = $language_id;
104 $form->{printer_id} = $printer_id;
109 $lxdebug->leave_sub();
113 $lxdebug->enter_sub();
115 $form->{vc} = 'customer';
118 $form->{webdav} = $webdav;
119 $form->{lizenzen} = $lizenzen;
121 $form->create_links("AR", \%myconfig, "customer");
123 if ($form->{all_customer}) {
124 unless ($form->{customer_id}) {
125 $form->{customer_id} = $form->{all_customer}->[0]->{id};
126 $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
130 if ($form->{payment_id}) {
131 $payment_id = $form->{payment_id};
133 if ($form->{language_id}) {
134 $language_id = $form->{language_id};
136 if ($form->{taxzone_id}) {
137 $taxzone_id = $form->{taxzone_id};
142 if ($form->{shipto_id}) {
143 $shipto_id = $form->{shipto_id};
146 $cp_id = $form->{cp_id};
147 IS->get_customer(\%myconfig, \%$form);
149 #quote all_customer Bug 133
150 foreach $ref (@{ $form->{all_customer} }) {
151 $ref->{name} = $form->quote($ref->{name});
156 IS->retrieve_invoice(\%myconfig, \%$form);
157 $form->{cp_id} = $cp_id;
160 $form->{payment_id} = $payment_id;
163 $form->{language_id} = $language_id;
166 $form->{taxzone_id} = $taxzone_id;
169 $form->{shipto_id} = $shipto_id;
172 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
175 if ($form->{all_departments}) {
176 $form->{selectdepartment} = "<option>\n";
177 $form->{department} = "$form->{department}--$form->{department_id}";
180 $form->{selectdepartment} .=
181 "<option>$_->{description}--$_->{id}</option>\n"
182 } (@{ $form->{all_departments} });
185 $form->{employee} = "$form->{employee}--$form->{employee_id}";
188 $form->{forex} = $form->{exchangerate};
189 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
191 foreach $key (keys %{ $form->{AR_links} }) {
192 foreach $ref (@{ $form->{AR_links}{$key} }) {
193 $form->{"select$key"} .=
194 "<option>$ref->{accno}--$ref->{description}</option>\n";
197 if ($key eq "AR_paid") {
198 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
199 $form->{"AR_paid_$i"} =
200 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
203 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
204 $form->{"datepaid_$i"} =
205 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
206 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
207 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
208 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
209 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
211 $form->{paidaccounts} = $i;
215 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
220 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
222 $form->{AR} = $form->{AR_1} unless $form->{id};
225 ($form->datetonum($form->{invdate}, \%myconfig) <=
226 $form->datetonum($form->{closedto}, \%myconfig));
228 $lxdebug->leave_sub();
231 sub prepare_invoice {
232 $lxdebug->enter_sub();
234 if ($form->{type} eq "credit_note") {
235 $form->{type} = "credit_note";
236 $form->{formname} = "credit_note";
238 $form->{type} = "invoice";
239 $form->{formname} = "invoice";
244 map { $form->{$_} =~ s/\"/"/g }
245 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
247 # # get pricegroups for parts
248 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
252 foreach $ref (@{ $form->{invoice_details} }) {
255 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
256 $form->{"discount_$i"} =
257 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
258 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
260 $decimalplaces = ($dec > 2) ? $dec : 2;
262 $form->{"sellprice_$i"} =
263 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
266 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
267 $dec_qty = length $dec_qty;
270 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
272 map { $form->{"${_}_$i"} =~ s/\"/"/g }
273 qw(partnumber description unit partnotes);
274 $form->{rowcount} = $i;
278 $lxdebug->leave_sub();
282 $lxdebug->enter_sub();
284 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
285 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
288 if ($form->{type} eq "credit_note") {
289 $form->{title} = $locale->text('Edit Credit Note');
290 $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
292 $form->{title} = $locale->text('Edit Sales Invoice');
293 $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
296 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
297 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
299 $payment = qq|<option value=""></option>|;
300 foreach $item (@{ $form->{payment_terms} }) {
301 if ($form->{payment_id} eq $item->{id}) {
302 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
304 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
308 my $set_duedate_url = "$form->{script}?login=$form->{login}&password=$form->{password}&action=set_duedate";
310 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
311 push(@ { $form->{AJAX} }, $pjx);
313 my @old_project_ids = ($form->{"globalproject_id"});
314 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
316 $form->get_lists("contacts" => "ALL_CONTACTS",
317 "shipto" => "ALL_SHIPTO",
318 "projects" => { "key" => "ALL_PROJECTS",
320 "old_id" => \@old_project_ids },
321 "employees" => "ALL_SALESMEN",
322 "taxzones" => "ALL_TAXZONES",
323 "currencies" => "ALL_CURRENCIES",
324 "customers" => "ALL_CUSTOMERS",
325 "price_factors" => "ALL_PRICE_FACTORS");
328 my @values = (undef);
329 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
330 push(@values, $item->{"cp_id"});
331 $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
334 if (scalar @values > 1) {
337 <th align="right">| . $locale->text('Contact Person') . qq|</th>
338 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
339 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
346 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
347 push(@values, $item->{"id"});
348 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
353 <th align="right">| . $locale->text('Employee') . qq|</th>
354 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
355 '-values' => \@values, '-labels' => \%labels)) . qq|
362 foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
363 push(@values, $item->{name}.qq|--|.$item->{"id"});
364 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
367 $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
370 <th align="right">| . $locale->text('Customer') . qq|</th>
372 (($myconfig{vclimit} <= scalar(@values))
373 ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
374 : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
375 '-onChange' => 'document.getElementById(\'update_button\').click();',
376 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
377 <input type="button" value="?" onclick="show_vc_details('customer')">
382 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
383 push(@values, $item->{"shipto_id"});
384 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
388 if (scalar @values > 1) {
391 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
392 <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
393 '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
399 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
400 push(@values, $item);
401 $labels{$item} = $item;
404 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
406 if (scalar @values) {
409 <th align="right">| . $locale->text('Currency') . qq|</th>
410 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
411 '-values' => \@values, '-labels' => \%labels)) . qq|
418 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
419 push(@values, $item->{"id"});
420 $labels{$item->{"id"}} = $item->{"projectnumber"};
422 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
423 '-labels' => \%labels,
424 '-default' => $form->{"globalproject_id"}));
428 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
429 push(@values, $item->{id});
430 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
434 qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
435 <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
436 '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
442 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
443 push(@values, $item->{"id"});
444 $labels{$item->{"id"}} = $item->{"description"};
447 if (!$form->{"id"}) {
450 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
451 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
452 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
459 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
461 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
462 | . H($labels{$form->{"taxzone_id"}}) . qq|
467 # set option selected
468 foreach $item (qw(AR customer currency department employee)) {
469 $form->{"select$item"} =~ s/ selected//;
470 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
473 $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
475 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
476 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
477 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
480 if ($form->{currency} ne $form->{defaultcurrency}) {
481 if ($form->{forex}) {
482 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
483 <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
485 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
486 <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
489 $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
493 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
494 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
495 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
498 | if $form->{selectdepartment};
500 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
502 if ($form->{business}) {
505 <th align="right">| . $locale->text('Customer type') . qq|</th>
506 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
507 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
513 if ($form->{max_dunning_level}) {
516 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
518 <b>$form->{max_dunning_level}</b>;
519 | . $locale->text('Dunning Amount') . qq|: <b>|
520 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
527 $form->{fokus} = "invoice.customer";
529 # use JavaScript Calendar or not
530 $form->{jsscript} = 1;
532 if ($form->{type} eq "credit_note") {
534 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
535 <input type="button" name="invdate" id="trigger1" value="|
536 . $locale->text('button') . qq|"></td>|;
540 Form->write_trigger(\%myconfig, "1",
545 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
546 <input type="button" name="invdate" id="trigger1" value="|
547 . $locale->text('button') . qq|"></td>
550 <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
551 <input type="button" name="duedate" id="trigger2" value="|
552 . $locale->text('button') . qq|"></td></td>
555 <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
556 <input type="button" name="deliverydate" id="trigger3" value="|
557 . $locale->text('button') . qq|"></td></td>
562 Form->write_trigger(\%myconfig, "3",
563 "invdate", "BL", "trigger1",
564 "duedate", "BL", "trigger2",
565 "deliverydate", "BL", "trigger3");
568 $credittext = $locale->text('Credit Limit exceeded!!!');
569 $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
570 : ($form->{resubmit}) ? qq|document.invoice.submit()|
571 : ($creditwarning) ? qq|alert('$credittext')|
573 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
574 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
576 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
577 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
580 $form->write_trigger(\%myconfig, 2,
581 "orddate", "BL", "trigger_orddate",
582 "quodate", "BL", "trigger_quodate");
583 # show history button js
584 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
585 #/show history button js
589 <body onLoad="$onload">
590 <script type="text/javascript" src="js/common.js"></script>
591 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
592 <script type="text/javascript" src="js/vendor_selection.js"></script>
593 <script type="text/javascript" src="js/calculate_qty.js"></script>
595 <form method="post" name="invoice" action="$form->{script}">
598 $form->hide_form(qw(id action type media format queued printed emailed title vc discount
599 creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
600 max_dunning_level dunning_amount
601 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
602 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts),
603 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
605 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
609 <input type="hidden" name="lizenzen" value="$lizenzen">
611 <div class="listtop" width="100%">$form->{title}</div>
619 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">
620 <input type="hidden" name="customer_id" value="$form->{customer_id}">
621 <input type="hidden" name="oldcustomer" value="$form->{oldcustomer}">
622 <input type="hidden" name="selectcustomer" value="$form->{selectcustomer}">
627 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
628 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
633 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
634 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
635 <input type="hidden" name="selectAR" value="$form->{selectAR}">
641 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
642 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
646 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
648 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
651 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
652 <td colspan="3"><input name="shipvia" size="35" value="$form->{shipvia}"></td>
655 <th align="right">| . $locale->text('Transaction description') . qq|</th>
656 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
663 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
665 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
666 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
670 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
672 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
673 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
680 <td align="right" valign="top">
685 if ($form->{type} eq "credit_note") {
687 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
688 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
691 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
696 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
697 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
700 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
704 <th align="right">| . $locale->text('Due Date') . qq|</th>
708 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
713 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
714 <td><input name="ordnumber" size="11" value="$form->{ordnumber}"></td>
717 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
718 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
719 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
722 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
723 <td><input name="quonumber" size="11" value="$form->{quonumber}"></td>
726 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
727 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
728 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
731 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
732 <td><input name="cusordnumber" size="11" value="$form->{cusordnumber}"></td>
735 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
736 <td>$globalprojectnumber</td>
750 print qq|<input type="hidden" name="webdav" value="$webdav">|;
752 $lxdebug->leave_sub();
756 $lxdebug->enter_sub();
758 $form->{invtotal} = $form->{invsubtotal};
760 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
763 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
766 $rows = ($rows > $introws) ? $rows : $introws;
768 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
770 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
772 $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
775 if ($form->{taxaccounts}) {
777 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
778 . $locale->text('Tax Included') . qq|</b><br><br>|;
781 if (!$form->{taxincluded}) {
783 foreach $item (split / /, $form->{taxaccounts}) {
784 if ($form->{"${item}_base"}) {
785 $form->{"${item}_total"} =
787 $form->{"${item}_base"} * $form->{"${item}_rate"},
789 $form->{invtotal} += $form->{"${item}_total"};
790 $form->{"${item}_total"} =
791 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
795 <th align="right">$form->{"${item}_description"} |
796 . $form->{"${item}_rate"} * 100 .qq|%</th>
797 <td align="right">$form->{"${item}_total"}</td>
803 $form->{invsubtotal} =
804 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
808 <th align="right">| . $locale->text('Subtotal') . qq|</th>
809 <td align="right">$form->{invsubtotal}</td>
815 if ($form->{taxincluded}) {
816 foreach $item (split / /, $form->{taxaccounts}) {
817 if ($form->{"${item}_base"}) {
818 $form->{"${item}_total"} =
820 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
821 (1 + $form->{"${item}_rate"})
824 $form->{"${item}_netto"} =
826 ($form->{"${item}_base"} - $form->{"${item}_total"}),
828 $form->{"${item}_total"} =
829 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
830 $form->{"${item}_netto"} =
831 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
835 <th align="right">Enthaltene $form->{"${item}_description"} |
836 . $form->{"${item}_rate"} * 100 .qq|%</th>
837 <td align="right">$form->{"${item}_total"}</td>
840 <th align="right">Nettobetrag</th>
841 <td align="right">$form->{"${item}_netto"}</td>
849 $form->{oldinvtotal} = $form->{invtotal};
851 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
861 <th align="left">| . $locale->text('Notes') . qq|</th>
862 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
863 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
868 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
876 <th align=left>| . $locale->text('Ertrag') . qq|</th>
877 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
880 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
881 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
883 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
884 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
893 <th align="right">| . $locale->text('Total') . qq|</th>
894 <td align="right">$form->{invtotal}</td>
906 <td><hr size="3" noshade></td>
909 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
912 <td align="left" width="30%"><b>Dateiname</b></td>
913 <td align="left" width="70%"><b>Webdavlink</b></td>
915 foreach $file (@{ $form->{WEBDAV} }) {
918 <td align="left">$file->{name}</td>
919 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
930 if ($form->{type} eq "credit_note") {
935 <tr class="listheading">
936 <th colspan="6" class="listheading">|
937 . $locale->text('Payments') . qq|</th>
945 <tr class="listheading">
946 <th colspan="6" class="listheading">|
947 . $locale->text('Incoming Payments') . qq|</th>
952 if ($form->{currency} eq $form->{defaultcurrency}) {
953 @column_index = qw(datepaid source memo paid AR_paid);
955 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
958 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
959 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
960 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
961 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
962 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
963 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
968 map { print "$column_data{$_}\n" } @column_index;
976 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
977 for $i (1 .. $form->{paidaccounts}) {
982 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
983 $form->{"selectAR_paid_$i"} =~
984 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
987 $totalpaid += $form->{"paid_$i"};
988 if ($form->{"paid_$i"}) {
990 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
992 $form->{"exchangerate_$i"} =
993 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
995 if ($form->{"exchangerate_$i"} == 0) {
996 $form->{"exchangerate_$i"} = "";
998 $exchangerate = qq| |;
999 if ($form->{currency} ne $form->{defaultcurrency}) {
1000 if ($form->{"forex_$i"}) {
1001 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1003 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1007 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1009 $column_data{"paid_$i"} =
1010 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
1011 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1012 $column_data{"AR_paid_$i"} =
1013 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1014 $column_data{"datepaid_$i"} =
1015 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)\">
1016 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1017 $column_data{"source_$i"} =
1018 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1019 $column_data{"memo_$i"} =
1020 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1022 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1025 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1028 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
1034 <td align="center">| . $locale->text('Total') . qq|</td>
1035 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
1040 <td align="center">| . $locale->text('Missing amount') . qq|</td>
1041 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
1045 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1046 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1051 <td><hr size="3" noshade></td>
1065 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1066 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1069 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
1072 <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
1073 . $locale->text('Update') . qq|">
1074 <input class="submit" type="submit" name="action" value="|
1075 . $locale->text('Ship to') . qq|">
1076 <input class="submit" type="submit" name="action" value="|
1077 . $locale->text('Print') . qq|">
1078 <input class="submit" type="submit" name="action" value="|
1079 . $locale->text('E-mail') . qq|"> |;
1080 print qq|<input class="submit" type="submit" name="action" value="|
1081 . $locale->text('Storno') . qq|"> | if ($show_storno);
1082 print qq|<input class="submit" type="submit" name="action" value="|
1083 . $locale->text('Post Payment') . qq|">
1085 print qq|<input class="submit" type="submit" name="action" value="|
1086 . $locale->text('Use As Template') . qq|">
1088 if ($form->{id} && !($form->{type} eq "credit_note")) {
1090 <input class="submit" type="submit" name="action" value="|
1091 . $locale->text('Credit Note') . qq|">
1094 if ($form->{radier}) {
1096 <input class="submit" type="submit" name="action" value="|
1097 . $locale->text('Delete') . qq|">
1102 if ($invdate > $closedto) {
1104 <input class="submit" type="submit" name="action" value="|
1105 . $locale->text('Order') . qq|">
1110 if ($invdate > $closedto) {
1111 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1112 . $locale->text('Update') . qq|">
1113 <input class="submit" type="submit" name="action" value="|
1114 . $locale->text('Ship to') . qq|">
1115 <input class="submit" type="submit" name="action" value="|
1116 . $locale->text('Preview') . qq|">
1117 <input class="submit" type="submit" name="action" value="|
1118 . $locale->text('E-mail') . qq|">
1119 <input class="submit" type="submit" name="action" value="|
1120 . $locale->text('Print and Post') . qq|">
1121 <input class="submit" type="submit" name="action" value="|
1122 . $locale->text('Post') . qq|"> | .
1123 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1124 '-class' => 'submit'));
1128 # button for saving history
1129 if($form->{id} ne "") {
1131 <input type="button" class="submit" onclick="set_history_window(|
1133 . qq|);" name="history" id="history" value="|
1134 . $locale->text('history')
1137 # /button for saving history
1139 # mark_as_paid button
1140 if($form->{id} ne "") {
1141 print qq|<input type="submit" class="submit" name="action" value="|
1142 . $locale->text('mark as paid') . qq|">|;
1144 # /mark_as_paid button
1145 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1148 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1150 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1151 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1152 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1153 map({ print $cgi->hidden("-name" => $_ , "-value" => $form->{$_});} qw(login password));
1162 $lxdebug->leave_sub();
1166 $lxdebug->enter_sub();
1167 &mark_as_paid_common(\%myconfig,"ar");
1168 $lxdebug->leave_sub();
1172 $lxdebug->enter_sub();
1174 my ($recursive_call) = shift;
1176 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
1178 $form->{print_and_post} = 0 if $form->{second_run};
1179 $taxincluded = "checked" if $form->{taxincluded};
1180 $form->{update} = 1;
1182 &check_name(customer);
1184 $form->{taxincluded} ||= $taxincluded;
1186 $form->{exchangerate} = $exchangerate if
1187 $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1189 for $i (1 .. $form->{paidaccounts}) {
1190 next unless $form->{"paid_$i"};
1191 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1192 $form->{"exchangerate_$i"} = $exchangerate if
1193 $form->{"forex_$i"} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1196 $i = $form->{rowcount};
1197 $exchangerate = $form->{exchangerate} || 1;
1199 # if last row empty, check the form otherwise retrieve new item
1200 if ( ($form->{"partnumber_$i"} eq "")
1201 && ($form->{"description_$i"} eq "")
1202 && ($form->{"partsgroup_$i"} eq "")) {
1204 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1209 IS->retrieve_item(\%myconfig, \%$form);
1211 $rows = scalar @{ $form->{item_list} };
1213 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
1216 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1225 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1227 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1228 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1230 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1231 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1233 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1235 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1236 $decimalplaces = max 2, length $1;
1239 $form->{"sellprice_$i"} = $sellprice;
1241 # if there is an exchange rate adjust sellprice
1242 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1243 $form->{"sellprice_$i"} /= $exchangerate;
1246 $form->{"listprice_$i"} /= $exchangerate;
1248 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1249 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1250 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1251 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1253 $form->{creditremaining} -= $amount;
1255 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
1257 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1260 if ($form->{"inventory_accno_$i"} ne "") {
1261 $form->{"lizenzen_$i"} = qq|<option></option>|;
1262 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1263 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1265 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
1269 # get pricegroups for parts
1270 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1272 # build up html code for prices_$i
1273 &set_pricegroup($i);
1280 # ok, so this is a new part
1281 # ask if it is a part or service item
1283 if ( $form->{"partsgroup_$i"}
1284 && ($form->{"partsnumber_$i"} eq "")
1285 && ($form->{"description_$i"} eq "")) {
1286 $form->{rowcount}--;
1287 $form->{"discount_$i"} = "";
1291 $form->{"id_$i"} = 0;
1296 $lxdebug->leave_sub();
1300 $lxdebug->enter_sub();
1302 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1303 for $i (1 .. $form->{paidaccounts}) {
1304 if ($form->{"paid_$i"}) {
1305 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1307 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1309 $form->error($locale->text('Cannot post payment for a closed period!'))
1310 if ($datepaid <= $closedto);
1312 if ($form->{currency} ne $form->{defaultcurrency}) {
1313 $form->{"exchangerate_$i"} = $form->{exchangerate}
1314 if ($invdate == $datepaid);
1315 $form->isblank("exchangerate_$i",
1316 $locale->text('Exchangerate for payment missing!'));
1321 ($form->{AR}) = split /--/, $form->{AR};
1322 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1324 $form->redirect($locale->text('Payment posted!'))
1325 if (IS->post_payment(\%myconfig, \%$form));
1326 $form->error($locale->text('Cannot post payment!'));
1329 $lxdebug->leave_sub();
1333 $lxdebug->enter_sub();
1335 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1336 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1337 $form->isblank("customer", $locale->text('Customer missing!'));
1339 $form->{invnumber} =~ s/^\s*//g;
1340 $form->{invnumber} =~ s/\s*$//g;
1342 # if oldcustomer ne customer redo form
1343 if (&check_name(customer)) {
1347 if ($form->{second_run}) {
1348 $form->{print_and_post} = 0;
1353 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1354 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1356 $form->error($locale->text('Cannot post invoice for a closed period!'))
1357 if ($invdate <= $closedto);
1359 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1360 if ($form->{currency} ne $form->{defaultcurrency});
1362 for $i (1 .. $form->{paidaccounts}) {
1363 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1364 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1366 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1368 $form->error($locale->text('Cannot post payment for a closed period!'))
1369 if ($datepaid <= $closedto);
1371 if ($form->{currency} ne $form->{defaultcurrency}) {
1372 $form->{"exchangerate_$i"} = $form->{exchangerate}
1373 if ($invdate == $datepaid);
1374 $form->isblank("exchangerate_$i",
1375 $locale->text('Exchangerate for payment missing!'));
1380 ($form->{AR}) = split /--/, $form->{AR};
1381 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1382 $form->{storno} ||= 0;
1384 $form->{label} = $locale->text('Invoice');
1386 $form->{id} = 0 if $form->{postasnew};
1388 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1389 if ($form->{postasnew}) {
1390 if ($form->{type} eq "credit_note") {
1391 undef($form->{cnnumber});
1393 undef($form->{invnumber});
1398 $form->error($locale->text('Cannot post invoice!'))
1399 unless IS->post_invoice(\%myconfig, \%$form);
1400 remove_draft() if $form->{remove_draft};
1402 if(!exists $form->{addition}) {
1403 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1404 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1405 $form->{storno} ? "STORNO" :
1407 $form->save_history($form->dbconnect(\%myconfig));
1410 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1413 $lxdebug->leave_sub();
1416 sub print_and_post {
1417 $lxdebug->enter_sub();
1419 $old_form = new Form;
1421 $form->{print_and_post} = 1;
1425 $lxdebug->leave_sub();
1429 sub use_as_template {
1430 $lxdebug->enter_sub();
1432 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);
1433 $form->{paidaccounts} = 1;
1434 $form->{rowcount}--;
1435 $form->{invdate} = $form->current_date(\%myconfig);
1438 $lxdebug->leave_sub();
1442 $lxdebug->enter_sub();
1444 if ($form->{storno}) {
1445 $form->error($locale->text('Cannot storno storno invoice!'));
1448 if (IS->has_storno(\%myconfig, $form, "ar")) {
1449 $form->error($locale->text("Invoice has already been storno'd!"));
1452 map({ my $key = $_; delete($form->{$key})
1453 unless (grep({ $key eq $_ } qw(login password id stylesheet type))); }
1460 # Payments must not be recorded for the new storno invoice.
1461 $form->{paidaccounts} = 0;
1462 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1464 $form->{storno_id} = $form->{id};
1465 $form->{storno} = 1;
1467 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1468 $form->{rowcount}++;
1471 $lxdebug->leave_sub();
1475 $lxdebug->enter_sub();
1477 $form->{preview} = 1;
1478 $old_form = new Form;
1479 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1481 &print_form($old_form);
1482 $lxdebug->leave_sub();
1487 $lxdebug->enter_sub();
1488 if ($form->{second_run}) {
1489 $form->{print_and_post} = 0;
1496 <form method="post" action="$form->{script}">
1499 # delete action variable
1500 map { delete $form->{$_} } qw(action header);
1502 foreach $key (keys %$form) {
1503 $form->{$key} =~ s/\"/"/g;
1504 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1508 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1511 . $locale->text('Are you sure you want to delete Invoice Number')
1512 . qq| $form->{invnumber}
1516 <input name="action" class="submit" type="submit" value="|
1517 . $locale->text('Yes') . qq|">
1521 $lxdebug->leave_sub();
1525 $lxdebug->enter_sub();
1527 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1529 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1532 $form->{rowcount}--;
1533 $form->{shipto} = 1;
1536 $form->{title} = $locale->text('Add Credit Note');
1537 $form->{script} = 'is.pl';
1542 # bo creates the id, reset it
1543 map { delete $form->{$_} }
1544 qw(id invnumber subject message cc bcc printed emailed queued);
1545 $form->{ $form->{vc} } =~ s/--.*//g;
1546 $form->{type} = "credit_note";
1549 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1551 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1552 qw(creditlimit creditremaining);
1554 $currency = $form->{currency};
1557 $form->{currency} = $currency;
1558 $form->{exchangerate} = "";
1559 $form->{forex} = "";
1560 $form->{exchangerate} = $exchangerate
1564 $form->check_exchangerate(
1565 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1568 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1575 $lxdebug->leave_sub();
1579 $lxdebug->enter_sub();
1580 if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
1581 # saving the history
1582 if(!exists $form->{addition}) {
1583 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1584 $form->{addition} = "DELETED";
1585 $form->save_history($form->dbconnect(\%myconfig));
1587 # /saving the history
1588 $form->redirect($locale->text('Invoice deleted!'));
1590 $form->error($locale->text('Cannot delete invoice!'));
1592 $lxdebug->leave_sub();
1596 $lxdebug->enter_sub();
1601 my $saved_form = save_form();
1606 map({ $saved_vars{$_} = $form->{$_}; } qw(id invnumber));
1607 restore_form($saved_form);
1608 map({ $form->{$_} = $saved_vars{$_}; } qw(id invnumber));
1613 $lxdebug->leave_sub();