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/arap.pl";
41 require "bin/mozilla/drafts.pl";
48 $lxdebug->enter_sub();
50 return $lxdebug->leave_sub() if (load_draft_maybe());
52 if ($form->{type} eq "credit_note") {
53 $form->{title} = $locale->text('Add Credit Note');
55 if ($form->{storno}) {
56 $form->{title} = $locale->text('Add Storno Credit Note');
59 $form->{title} = $locale->text('Add Sales Invoice');
65 "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&password=$form->{password}"
66 unless $form->{callback};
68 $form{jsscript} = "date";
70 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
72 $form->error("Access Denied");
78 $lxdebug->leave_sub();
82 $lxdebug->enter_sub();
85 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
86 #/show hhistory button
88 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
90 $form->error("Access Denied");
93 if ($form->{print_and_post}) {
94 $form->{action} = "print";
95 $form->{resubmit} = 1;
96 $language_id = $form->{language_id};
97 $printer_id = $form->{printer_id};
101 if ($form->{print_and_post}) {
102 $form->{language_id} = $language_id;
103 $form->{printer_id} = $printer_id;
108 $lxdebug->leave_sub();
112 $lxdebug->enter_sub();
114 $form->{vc} = 'customer';
117 $form->{webdav} = $webdav;
118 $form->{lizenzen} = $lizenzen;
120 $form->create_links("AR", \%myconfig, "customer");
122 if ($form->{all_customer}) {
123 unless ($form->{customer_id}) {
124 $form->{customer_id} = $form->{all_customer}->[0]->{id};
125 $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
129 if ($form->{payment_id}) {
130 $payment_id = $form->{payment_id};
132 if ($form->{language_id}) {
133 $language_id = $form->{language_id};
135 if ($form->{taxzone_id}) {
136 $taxzone_id = $form->{taxzone_id};
141 if ($form->{shipto_id}) {
142 $shipto_id = $form->{shipto_id};
145 $cp_id = $form->{cp_id};
146 IS->get_customer(\%myconfig, \%$form);
148 #quote all_customer Bug 133
149 foreach $ref (@{ $form->{all_customer} }) {
150 $ref->{name} = $form->quote($ref->{name});
155 IS->retrieve_invoice(\%myconfig, \%$form);
156 $form->{cp_id} = $cp_id;
159 $form->{payment_id} = $payment_id;
162 $form->{language_id} = $language_id;
165 $form->{taxzone_id} = $taxzone_id;
168 $form->{shipto_id} = $shipto_id;
171 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
174 if ($form->{all_departments}) {
175 $form->{selectdepartment} = "<option>\n";
176 $form->{department} = "$form->{department}--$form->{department_id}";
179 $form->{selectdepartment} .=
180 "<option>$_->{description}--$_->{id}</option>\n"
181 } (@{ $form->{all_departments} });
184 $form->{employee} = "$form->{employee}--$form->{employee_id}";
187 $form->{forex} = $form->{exchangerate};
188 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
190 foreach $key (keys %{ $form->{AR_links} }) {
191 foreach $ref (@{ $form->{AR_links}{$key} }) {
192 $form->{"select$key"} .=
193 "<option>$ref->{accno}--$ref->{description}</option>\n";
196 if ($key eq "AR_paid") {
197 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
198 $form->{"AR_paid_$i"} =
199 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
202 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
203 $form->{"datepaid_$i"} =
204 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
205 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
206 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
207 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
208 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
210 $form->{paidaccounts} = $i;
214 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
219 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
221 $form->{AR} = $form->{AR_1} unless $form->{id};
224 ($form->datetonum($form->{invdate}, \%myconfig) <=
225 $form->datetonum($form->{closedto}, \%myconfig));
227 $lxdebug->leave_sub();
230 sub prepare_invoice {
231 $lxdebug->enter_sub();
233 if ($form->{type} eq "credit_note") {
234 $form->{type} = "credit_note";
235 $form->{formname} = "credit_note";
237 $form->{type} = "invoice";
238 $form->{formname} = "invoice";
243 map { $form->{$_} =~ s/\"/"/g }
244 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
246 # # get pricegroups for parts
247 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
251 foreach $ref (@{ $form->{invoice_details} }) {
254 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
255 $form->{"discount_$i"} =
256 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
257 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
259 $decimalplaces = ($dec > 2) ? $dec : 2;
261 $form->{"sellprice_$i"} =
262 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
265 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
266 $dec_qty = length $dec_qty;
269 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
271 map { $form->{"${_}_$i"} =~ s/\"/"/g }
272 qw(partnumber description unit partnotes);
273 $form->{rowcount} = $i;
277 $lxdebug->leave_sub();
281 $lxdebug->enter_sub();
283 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
284 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
287 if ($form->{type} eq "credit_note") {
288 $form->{title} = $locale->text('Edit Credit Note');
289 $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
291 $form->{title} = $locale->text('Edit Sales Invoice');
292 $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
295 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
296 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
298 $payment = qq|<option value=""></option>|;
299 foreach $item (@{ $form->{payment_terms} }) {
300 if ($form->{payment_id} eq $item->{id}) {
301 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
303 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
307 my $set_duedate_url = "$form->{script}?login=$form->{login}&password=$form->{password}&action=set_duedate";
309 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
310 push(@ { $form->{AJAX} }, $pjx);
312 my @old_project_ids = ($form->{"globalproject_id"});
313 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
315 $form->get_lists("contacts" => "ALL_CONTACTS",
316 "shipto" => "ALL_SHIPTO",
317 "projects" => { "key" => "ALL_PROJECTS",
319 "old_id" => \@old_project_ids },
320 "employees" => "ALL_SALESMEN",
321 "taxzones" => "ALL_TAXZONES",
322 "currencies" => "ALL_CURRENCIES",
323 "customers" => "ALL_CUSTOMERS",
324 "price_factors" => "ALL_PRICE_FACTORS");
327 my @values = (undef);
328 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
329 push(@values, $item->{"cp_id"});
330 $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
333 if (scalar @values > 1) {
336 <th align="right">| . $locale->text('Contact Person') . qq|</th>
337 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
338 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
345 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
346 push(@values, $item->{"id"});
347 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
352 <th align="right">| . $locale->text('Employee') . qq|</th>
353 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
354 '-values' => \@values, '-labels' => \%labels)) . qq|
361 foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
362 push(@values, $item->{name}.qq|--|.$item->{"id"});
363 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
366 $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
369 <th align="right">| . $locale->text('Customer') . qq|</th>
371 (($myconfig{vclimit} <= scalar(@values))
372 ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
373 : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
374 '-onChange' => 'document.getElementById(\'update_button\').click();',
375 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
376 <input type="button" value="?" onclick="show_vc_details('customer')">
381 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
382 push(@values, $item->{"shipto_id"});
383 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
387 if (scalar @values > 1) {
390 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
391 <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
392 '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
398 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
399 push(@values, $item);
400 $labels{$item} = $item;
403 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
405 if (scalar @values) {
408 <th align="right">| . $locale->text('Currency') . qq|</th>
409 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
410 '-values' => \@values, '-labels' => \%labels)) . qq|
417 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
418 push(@values, $item->{"id"});
419 $labels{$item->{"id"}} = $item->{"projectnumber"};
421 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
422 '-labels' => \%labels,
423 '-default' => $form->{"globalproject_id"}));
427 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
428 push(@values, $item->{id});
429 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
433 qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
434 <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
435 '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
441 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
442 push(@values, $item->{"id"});
443 $labels{$item->{"id"}} = $item->{"description"};
446 if (!$form->{"id"}) {
449 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
450 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
451 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
458 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
460 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
461 | . H($labels{$form->{"taxzone_id"}}) . qq|
466 # set option selected
467 foreach $item (qw(AR customer currency department employee)) {
468 $form->{"select$item"} =~ s/ selected//;
469 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
472 $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
474 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
475 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
476 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
479 if ($form->{currency} ne $form->{defaultcurrency}) {
480 if ($form->{forex}) {
481 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
482 <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
484 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
485 <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
488 $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
492 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
493 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
494 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
497 | if $form->{selectdepartment};
499 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
501 if ($form->{business}) {
504 <th align="right">| . $locale->text('Customer type') . qq|</th>
505 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
506 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
512 if ($form->{max_dunning_level}) {
515 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
517 <b>$form->{max_dunning_level}</b>;
518 | . $locale->text('Dunning Amount') . qq|: <b>|
519 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
526 $form->{fokus} = "invoice.customer";
528 # use JavaScript Calendar or not
529 $form->{jsscript} = 1;
531 if ($form->{type} eq "credit_note") {
533 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
534 <input type="button" name="invdate" id="trigger1" value="|
535 . $locale->text('button') . qq|"></td>|;
539 Form->write_trigger(\%myconfig, "1",
544 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
545 <input type="button" name="invdate" id="trigger1" value="|
546 . $locale->text('button') . qq|"></td>
549 <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
550 <input type="button" name="duedate" id="trigger2" value="|
551 . $locale->text('button') . qq|"></td></td>
554 <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
555 <input type="button" name="deliverydate" id="trigger3" value="|
556 . $locale->text('button') . qq|"></td></td>
561 Form->write_trigger(\%myconfig, "3",
562 "invdate", "BL", "trigger1",
563 "duedate", "BL", "trigger2",
564 "deliverydate", "BL", "trigger3");
567 $credittext = $locale->text('Credit Limit exceeded!!!');
568 $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
569 : ($form->{resubmit}) ? qq|document.invoice.submit()|
570 : ($creditwarning) ? qq|alert('$credittext')|
572 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
573 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
575 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
576 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
579 $form->write_trigger(\%myconfig, 2,
580 "orddate", "BL", "trigger_orddate",
581 "quodate", "BL", "trigger_quodate");
582 # show history button js
583 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
584 #/show history button js
588 <body onLoad="$onload">
589 <script type="text/javascript" src="js/common.js"></script>
590 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
591 <script type="text/javascript" src="js/vendor_selection.js"></script>
592 <script type="text/javascript" src="js/calculate_qty.js"></script>
594 <form method="post" name="invoice" action="$form->{script}">
597 $form->hide_form(qw(id action type media format queued printed emailed title vc discount
598 creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
599 max_dunning_level dunning_amount
600 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
601 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts),
602 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
604 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
608 <input type="hidden" name="lizenzen" value="$lizenzen">
610 <div class="listtop" width="100%">$form->{title}</div>
618 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">
619 <input type="hidden" name="customer_id" value="$form->{customer_id}">
620 <input type="hidden" name="oldcustomer" value="$form->{oldcustomer}">
621 <input type="hidden" name="selectcustomer" value="$form->{selectcustomer}">
626 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
627 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
632 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
633 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
634 <input type="hidden" name="selectAR" value="$form->{selectAR}">
640 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
641 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
645 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
647 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
650 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
651 <td colspan="3"><input name="shipvia" size="35" value="$form->{shipvia}"></td>
654 <th align="right">| . $locale->text('Transaction description') . qq|</th>
655 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
662 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
664 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
665 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
669 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
671 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
672 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
679 <td align="right" valign="top">
684 if ($form->{type} eq "credit_note") {
686 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
687 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
690 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
695 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
696 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
699 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
703 <th align="right">| . $locale->text('Due Date') . qq|</th>
707 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
712 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
713 <td><input name="ordnumber" size="11" value="$form->{ordnumber}"></td>
716 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
717 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
718 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
721 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
722 <td><input name="quonumber" size="11" value="$form->{quonumber}"></td>
725 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
726 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
727 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
730 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
731 <td><input name="cusordnumber" size="11" value="$form->{cusordnumber}"></td>
734 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
735 <td>$globalprojectnumber</td>
749 print qq|<input type="hidden" name="webdav" value="$webdav">|;
751 $lxdebug->leave_sub();
755 $lxdebug->enter_sub();
757 $form->{invtotal} = $form->{invsubtotal};
759 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
762 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
765 $rows = ($rows > $introws) ? $rows : $introws;
767 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
769 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
771 $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
774 if ($form->{taxaccounts}) {
776 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
777 . $locale->text('Tax Included') . qq|</b><br><br>|;
780 if (!$form->{taxincluded}) {
782 foreach $item (split / /, $form->{taxaccounts}) {
783 if ($form->{"${item}_base"}) {
784 $form->{"${item}_total"} =
786 $form->{"${item}_base"} * $form->{"${item}_rate"},
788 $form->{invtotal} += $form->{"${item}_total"};
789 $form->{"${item}_total"} =
790 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
794 <th align="right">$form->{"${item}_description"} |
795 . $form->{"${item}_rate"} * 100 .qq|%</th>
796 <td align="right">$form->{"${item}_total"}</td>
802 $form->{invsubtotal} =
803 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
807 <th align="right">| . $locale->text('Subtotal') . qq|</th>
808 <td align="right">$form->{invsubtotal}</td>
814 if ($form->{taxincluded}) {
815 foreach $item (split / /, $form->{taxaccounts}) {
816 if ($form->{"${item}_base"}) {
817 $form->{"${item}_total"} =
819 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
820 (1 + $form->{"${item}_rate"})
823 $form->{"${item}_netto"} =
825 ($form->{"${item}_base"} - $form->{"${item}_total"}),
827 $form->{"${item}_total"} =
828 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
829 $form->{"${item}_netto"} =
830 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
834 <th align="right">Enthaltene $form->{"${item}_description"} |
835 . $form->{"${item}_rate"} * 100 .qq|%</th>
836 <td align="right">$form->{"${item}_total"}</td>
839 <th align="right">Nettobetrag</th>
840 <td align="right">$form->{"${item}_netto"}</td>
848 $form->{oldinvtotal} = $form->{invtotal};
850 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
860 <th align="left">| . $locale->text('Notes') . qq|</th>
861 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
862 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
867 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
875 <th align=left>| . $locale->text('Ertrag') . qq|</th>
876 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
879 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
880 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
882 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
883 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
892 <th align="right">| . $locale->text('Total') . qq|</th>
893 <td align="right">$form->{invtotal}</td>
905 <td><hr size="3" noshade></td>
908 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
911 <td align="left" width="30%"><b>Dateiname</b></td>
912 <td align="left" width="70%"><b>Webdavlink</b></td>
914 foreach $file (@{ $form->{WEBDAV} }) {
917 <td align="left">$file->{name}</td>
918 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
929 if ($form->{type} eq "credit_note") {
934 <tr class="listheading">
935 <th colspan="6" class="listheading">|
936 . $locale->text('Payments') . qq|</th>
944 <tr class="listheading">
945 <th colspan="6" class="listheading">|
946 . $locale->text('Incoming Payments') . qq|</th>
951 if ($form->{currency} eq $form->{defaultcurrency}) {
952 @column_index = qw(datepaid source memo paid AR_paid);
954 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
957 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
958 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
959 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
960 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
961 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
962 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
967 map { print "$column_data{$_}\n" } @column_index;
975 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
976 for $i (1 .. $form->{paidaccounts}) {
981 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
982 $form->{"selectAR_paid_$i"} =~
983 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
986 $totalpaid += $form->{"paid_$i"};
987 if ($form->{"paid_$i"}) {
989 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
991 $form->{"exchangerate_$i"} =
992 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
994 if ($form->{"exchangerate_$i"} == 0) {
995 $form->{"exchangerate_$i"} = "";
997 $exchangerate = qq| |;
998 if ($form->{currency} ne $form->{defaultcurrency}) {
999 if ($form->{"forex_$i"}) {
1000 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1002 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1006 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1008 $column_data{"paid_$i"} =
1009 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
1010 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1011 $column_data{"AR_paid_$i"} =
1012 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1013 $column_data{"datepaid_$i"} =
1014 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)\">
1015 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1016 $column_data{"source_$i"} =
1017 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1018 $column_data{"memo_$i"} =
1019 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1021 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1024 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1027 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
1033 <td align="center">| . $locale->text('Total') . qq|</td>
1034 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
1039 <td align="center">| . $locale->text('Missing amount') . qq|</td>
1040 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
1044 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1045 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1050 <td><hr size="3" noshade></td>
1064 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1065 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1068 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
1071 <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
1072 . $locale->text('Update') . qq|">
1073 <input class="submit" type="submit" name="action" value="|
1074 . $locale->text('Ship to') . qq|">
1075 <input class="submit" type="submit" name="action" value="|
1076 . $locale->text('Print') . qq|">
1077 <input class="submit" type="submit" name="action" value="|
1078 . $locale->text('E-mail') . qq|"> |;
1079 print qq|<input class="submit" type="submit" name="action" value="|
1080 . $locale->text('Storno') . qq|"> | if ($show_storno);
1081 print qq|<input class="submit" type="submit" name="action" value="|
1082 . $locale->text('Post Payment') . qq|">
1084 print qq|<input class="submit" type="submit" name="action" value="|
1085 . $locale->text('Use As Template') . qq|">
1087 if ($form->{id} && !($form->{type} eq "credit_note")) {
1089 <input class="submit" type="submit" name="action" value="|
1090 . $locale->text('Credit Note') . qq|">
1093 if ($form->{radier}) {
1095 <input class="submit" type="submit" name="action" value="|
1096 . $locale->text('Delete') . qq|">
1101 if ($invdate > $closedto) {
1103 <input class="submit" type="submit" name="action" value="|
1104 . $locale->text('Order') . qq|">
1109 if ($invdate > $closedto) {
1110 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1111 . $locale->text('Update') . qq|">
1112 <input class="submit" type="submit" name="action" value="|
1113 . $locale->text('Ship to') . qq|">
1114 <input class="submit" type="submit" name="action" value="|
1115 . $locale->text('Preview') . qq|">
1116 <input class="submit" type="submit" name="action" value="|
1117 . $locale->text('E-mail') . qq|">
1118 <input class="submit" type="submit" name="action" value="|
1119 . $locale->text('Print and Post') . qq|">
1120 <input class="submit" type="submit" name="action" value="|
1121 . $locale->text('Post') . qq|"> | .
1122 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1123 '-class' => 'submit'));
1127 # button for saving history
1128 if($form->{id} ne "") {
1130 <input type="button" class="submit" onclick="set_history_window(|
1132 . qq|);" name="history" id="history" value="|
1133 . $locale->text('history')
1136 # /button for saving history
1138 # mark_as_paid button
1139 if($form->{id} ne "") {
1140 print qq|<input type="submit" class="submit" name="action" value="|
1141 . $locale->text('mark as paid') . qq|">|;
1143 # /mark_as_paid button
1144 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1147 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1149 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1150 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1151 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1152 map({ print $cgi->hidden("-name" => $_ , "-value" => $form->{$_});} qw(login password));
1161 $lxdebug->leave_sub();
1165 $lxdebug->enter_sub();
1166 &mark_as_paid_common(\%myconfig,"ar");
1167 $lxdebug->leave_sub();
1171 $lxdebug->enter_sub();
1173 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1175 $form->{print_and_post} = 0 if $form->{second_run};
1176 $taxincluded = "checked" if $form->{taxincluded};
1177 $form->{update} = 1;
1179 &check_name(customer);
1181 $form->{taxincluded} ||= $taxincluded;
1183 $form->{exchangerate} = $exchangerate if
1184 $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1186 for $i (1 .. $form->{paidaccounts}) {
1187 next unless $form->{"paid_$i"};
1188 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1189 $form->{"exchangerate_$i"} = $exchangerate if
1190 $form->{"forex_$i"} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1193 $i = $form->{rowcount};
1194 $exchangerate = $form->{exchangerate} || 1;
1196 # if last row empty, check the form otherwise retrieve new item
1197 if ( ($form->{"partnumber_$i"} eq "")
1198 && ($form->{"description_$i"} eq "")
1199 && ($form->{"partsgroup_$i"} eq "")) {
1201 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1206 IS->retrieve_item(\%myconfig, \%$form);
1208 $rows = scalar @{ $form->{item_list} };
1210 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
1213 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1222 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1224 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1225 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1227 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1228 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1230 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1232 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1233 $decimalplaces = max 2, length $1;
1236 $form->{"sellprice_$i"} = $sellprice;
1238 # if there is an exchange rate adjust sellprice
1239 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1240 $form->{"sellprice_$i"} /= $exchangerate;
1243 $form->{"listprice_$i"} /= $exchangerate;
1245 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1246 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1247 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1248 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1250 $form->{creditremaining} -= $amount;
1252 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
1254 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1257 if ($form->{"inventory_accno_$i"} ne "") {
1258 $form->{"lizenzen_$i"} = qq|<option></option>|;
1259 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1260 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1262 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
1266 # get pricegroups for parts
1267 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1269 # build up html code for prices_$i
1270 &set_pricegroup($i);
1277 # ok, so this is a new part
1278 # ask if it is a part or service item
1280 if ( $form->{"partsgroup_$i"}
1281 && ($form->{"partsnumber_$i"} eq "")
1282 && ($form->{"description_$i"} eq "")) {
1283 $form->{rowcount}--;
1284 $form->{"discount_$i"} = "";
1288 $form->{"id_$i"} = 0;
1293 $lxdebug->leave_sub();
1297 $lxdebug->enter_sub();
1299 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1300 for $i (1 .. $form->{paidaccounts}) {
1301 if ($form->{"paid_$i"}) {
1302 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1304 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1306 $form->error($locale->text('Cannot post payment for a closed period!'))
1307 if ($datepaid <= $closedto);
1309 if ($form->{currency} ne $form->{defaultcurrency}) {
1310 $form->{"exchangerate_$i"} = $form->{exchangerate}
1311 if ($invdate == $datepaid);
1312 $form->isblank("exchangerate_$i",
1313 $locale->text('Exchangerate for payment missing!'));
1318 ($form->{AR}) = split /--/, $form->{AR};
1319 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1321 $form->redirect($locale->text('Payment posted!'))
1322 if (IS->post_payment(\%myconfig, \%$form));
1323 $form->error($locale->text('Cannot post payment!'));
1326 $lxdebug->leave_sub();
1330 $lxdebug->enter_sub();
1332 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1333 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1334 $form->isblank("customer", $locale->text('Customer missing!'));
1336 $form->{invnumber} =~ s/^\s*//g;
1337 $form->{invnumber} =~ s/\s*$//g;
1339 # if oldcustomer ne customer redo form
1340 if (&check_name(customer)) {
1344 if ($form->{second_run}) {
1345 $form->{print_and_post} = 0;
1350 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1351 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1353 $form->error($locale->text('Cannot post invoice for a closed period!'))
1354 if ($invdate <= $closedto);
1356 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1357 if ($form->{currency} ne $form->{defaultcurrency});
1359 for $i (1 .. $form->{paidaccounts}) {
1360 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1361 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1363 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1365 $form->error($locale->text('Cannot post payment for a closed period!'))
1366 if ($datepaid <= $closedto);
1368 if ($form->{currency} ne $form->{defaultcurrency}) {
1369 $form->{"exchangerate_$i"} = $form->{exchangerate}
1370 if ($invdate == $datepaid);
1371 $form->isblank("exchangerate_$i",
1372 $locale->text('Exchangerate for payment missing!'));
1377 ($form->{AR}) = split /--/, $form->{AR};
1378 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1379 $form->{storno} ||= 0;
1381 $form->{label} = $locale->text('Invoice');
1383 $form->{id} = 0 if $form->{postasnew};
1385 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1386 if ($form->{postasnew}) {
1387 if ($form->{type} eq "credit_note") {
1388 undef($form->{cnnumber});
1390 undef($form->{invnumber});
1395 $form->error($locale->text('Cannot post invoice!'))
1396 unless IS->post_invoice(\%myconfig, \%$form);
1397 remove_draft() if $form->{remove_draft};
1399 if(!exists $form->{addition}) {
1400 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1401 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1402 $form->{storno} ? "STORNO" :
1404 $form->save_history($form->dbconnect(\%myconfig));
1407 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1410 $lxdebug->leave_sub();
1413 sub print_and_post {
1414 $lxdebug->enter_sub();
1416 $old_form = new Form;
1418 $form->{print_and_post} = 1;
1422 $lxdebug->leave_sub();
1426 sub use_as_template {
1427 $lxdebug->enter_sub();
1429 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);
1430 $form->{paidaccounts} = 1;
1431 $form->{rowcount}--;
1432 $form->{invdate} = $form->current_date(\%myconfig);
1435 $lxdebug->leave_sub();
1439 $lxdebug->enter_sub();
1441 if ($form->{storno}) {
1442 $form->error($locale->text('Cannot storno storno invoice!'));
1445 if (IS->has_storno(\%myconfig, $form, "ar")) {
1446 $form->error($locale->text("Invoice has already been storno'd!"));
1449 map({ my $key = $_; delete($form->{$key})
1450 unless (grep({ $key eq $_ } qw(login password id stylesheet type))); }
1457 # Payments must not be recorded for the new storno invoice.
1458 $form->{paidaccounts} = 0;
1459 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1461 $form->{storno_id} = $form->{id};
1462 $form->{storno} = 1;
1464 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1465 $form->{rowcount}++;
1468 $lxdebug->leave_sub();
1472 $lxdebug->enter_sub();
1474 $form->{preview} = 1;
1475 $old_form = new Form;
1476 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1478 &print_form($old_form);
1479 $lxdebug->leave_sub();
1484 $lxdebug->enter_sub();
1485 if ($form->{second_run}) {
1486 $form->{print_and_post} = 0;
1493 <form method="post" action="$form->{script}">
1496 # delete action variable
1497 map { delete $form->{$_} } qw(action header);
1499 foreach $key (keys %$form) {
1500 $form->{$key} =~ s/\"/"/g;
1501 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1505 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1508 . $locale->text('Are you sure you want to delete Invoice Number')
1509 . qq| $form->{invnumber}
1513 <input name="action" class="submit" type="submit" value="|
1514 . $locale->text('Yes') . qq|">
1518 $lxdebug->leave_sub();
1522 $lxdebug->enter_sub();
1524 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1526 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1529 $form->{rowcount}--;
1530 $form->{shipto} = 1;
1533 $form->{title} = $locale->text('Add Credit Note');
1534 $form->{script} = 'is.pl';
1539 # bo creates the id, reset it
1540 map { delete $form->{$_} }
1541 qw(id invnumber subject message cc bcc printed emailed queued);
1542 $form->{ $form->{vc} } =~ s/--.*//g;
1543 $form->{type} = "credit_note";
1546 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1548 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1549 qw(creditlimit creditremaining);
1551 $currency = $form->{currency};
1554 $form->{currency} = $currency;
1555 $form->{exchangerate} = "";
1556 $form->{forex} = "";
1557 $form->{exchangerate} = $exchangerate
1561 $form->check_exchangerate(
1562 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1565 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1572 $lxdebug->leave_sub();
1576 $lxdebug->enter_sub();
1577 if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
1578 # saving the history
1579 if(!exists $form->{addition}) {
1580 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1581 $form->{addition} = "DELETED";
1582 $form->save_history($form->dbconnect(\%myconfig));
1584 # /saving the history
1585 $form->redirect($locale->text('Invoice deleted!'));
1587 $form->error($locale->text('Cannot delete invoice!'));
1589 $lxdebug->leave_sub();
1593 $lxdebug->enter_sub();
1598 my $saved_form = save_form();
1603 map({ $saved_vars{$_} = $form->{$_}; } qw(id invnumber));
1604 restore_form($saved_form);
1605 map({ $form->{$_} = $saved_vars{$_}; } qw(id invnumber));
1610 $lxdebug->leave_sub();