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 #======================================================================
38 use List::Util qw(max sum);
40 require "bin/mozilla/io.pl";
41 require "bin/mozilla/invoice_io.pl";
42 require "bin/mozilla/arap.pl";
43 require "bin/mozilla/drafts.pl";
50 $lxdebug->enter_sub();
52 $auth->assert('invoice_edit');
54 return $lxdebug->leave_sub() if (load_draft_maybe());
56 if ($form->{type} eq "credit_note") {
57 $form->{title} = $locale->text('Add Credit Note');
59 if ($form->{storno}) {
60 $form->{title} = $locale->text('Add Storno Credit Note');
63 $form->{title} = $locale->text('Add Sales Invoice');
68 $form->{callback} = "$form->{script}?action=add&type=$form->{type}" unless $form->{callback};
70 $form{jsscript} = "date";
76 $lxdebug->leave_sub();
80 $lxdebug->enter_sub();
82 $auth->assert('invoice_edit');
85 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
86 #/show hhistory button
89 if ($form->{print_and_post}) {
90 $form->{action} = "print";
91 $form->{resubmit} = 1;
92 $language_id = $form->{language_id};
93 $printer_id = $form->{printer_id};
97 if ($form->{print_and_post}) {
98 $form->{language_id} = $language_id;
99 $form->{printer_id} = $printer_id;
104 $lxdebug->leave_sub();
108 $lxdebug->enter_sub();
110 $auth->assert('invoice_edit');
112 $form->{vc} = 'customer';
115 $form->{webdav} = $webdav;
116 $form->{lizenzen} = $lizenzen;
118 $form->create_links("AR", \%myconfig, "customer");
120 if ($form->{all_customer}) {
121 unless ($form->{customer_id}) {
122 $form->{customer_id} = $form->{all_customer}->[0]->{id};
123 $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
127 if ($form->{payment_id}) {
128 $payment_id = $form->{payment_id};
130 if ($form->{language_id}) {
131 $language_id = $form->{language_id};
133 if ($form->{taxzone_id}) {
134 $taxzone_id = $form->{taxzone_id};
139 if ($form->{shipto_id}) {
140 $shipto_id = $form->{shipto_id};
143 $cp_id = $form->{cp_id};
144 IS->get_customer(\%myconfig, \%$form);
146 #quote all_customer Bug 133
147 foreach $ref (@{ $form->{all_customer} }) {
148 $ref->{name} = $form->quote($ref->{name});
153 IS->retrieve_invoice(\%myconfig, \%$form);
154 $form->{cp_id} = $cp_id;
157 $form->{payment_id} = $payment_id;
160 $form->{language_id} = $language_id;
163 $form->{taxzone_id} = $taxzone_id;
166 $form->{shipto_id} = $shipto_id;
169 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
172 if ($form->{all_departments}) {
173 $form->{selectdepartment} = "<option>\n";
174 $form->{department} = "$form->{department}--$form->{department_id}";
177 $form->{selectdepartment} .=
178 "<option>$_->{description}--$_->{id}</option>\n"
179 } (@{ $form->{all_departments} });
182 $form->{employee} = "$form->{employee}--$form->{employee_id}";
185 $form->{forex} = $form->{exchangerate};
186 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
188 foreach $key (keys %{ $form->{AR_links} }) {
189 foreach $ref (@{ $form->{AR_links}{$key} }) {
190 $form->{"select$key"} .=
191 "<option>$ref->{accno}--$ref->{description}</option>\n";
194 if ($key eq "AR_paid") {
195 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
196 $form->{"AR_paid_$i"} =
197 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
200 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
201 $form->{"datepaid_$i"} =
202 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
203 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
204 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
205 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
206 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
208 $form->{paidaccounts} = $i;
212 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
217 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
219 $form->{AR} = $form->{AR_1} unless $form->{id};
222 ($form->datetonum($form->{invdate}, \%myconfig) <=
223 $form->datetonum($form->{closedto}, \%myconfig));
225 $lxdebug->leave_sub();
228 sub prepare_invoice {
229 $lxdebug->enter_sub();
231 $auth->assert('invoice_edit');
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 $auth->assert('invoice_edit');
285 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
286 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
289 if ($form->{type} eq "credit_note") {
290 $form->{title} = $locale->text('Edit Credit Note');
291 $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
293 $form->{title} = $locale->text('Edit Sales Invoice');
294 $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
297 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
298 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
300 $payment = qq|<option value=""></option>|;
301 foreach $item (@{ $form->{payment_terms} }) {
302 if ($form->{payment_id} eq $item->{id}) {
303 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
305 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
309 my $set_duedate_url = "$form->{script}?action=set_duedate";
311 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
312 push(@ { $form->{AJAX} }, $pjx);
314 my @old_project_ids = ($form->{"globalproject_id"});
315 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
317 $form->get_lists("contacts" => "ALL_CONTACTS",
318 "shipto" => "ALL_SHIPTO",
319 "projects" => { "key" => "ALL_PROJECTS",
321 "old_id" => \@old_project_ids },
322 "employees" => "ALL_SALESMEN",
323 "taxzones" => "ALL_TAXZONES",
324 "currencies" => "ALL_CURRENCIES",
325 "customers" => "ALL_CUSTOMERS",
326 "price_factors" => "ALL_PRICE_FACTORS");
329 my @values = (undef);
330 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
331 push(@values, $item->{"cp_id"});
332 $labels{$item->{"cp_id"}} = join(',', $item->{"cp_name"}, $item->{"cp_givenname"}) . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
335 if (scalar @values > 1) {
338 <th align="right">| . $locale->text('Contact Person') . qq|</th>
339 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
340 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
347 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
348 push(@values, $item->{"id"});
349 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
354 <th align="right">| . $locale->text('Employee') . qq|</th>
355 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
356 '-values' => \@values, '-labels' => \%labels)) . qq|
363 foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
364 push(@values, $item->{name}.qq|--|.$item->{"id"});
365 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
368 $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
371 <th align="right">| . $locale->text('Customer') . qq|</th>
373 (($myconfig{vclimit} <= scalar(@values))
374 ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
375 : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
376 '-onChange' => 'document.getElementById(\'update_button\').click();',
377 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
378 <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')">
383 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
384 push(@values, $item->{"shipto_id"});
385 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
389 if (scalar @values > 1) {
392 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
393 <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
394 '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
400 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
401 push(@values, $item);
402 $labels{$item} = $item;
405 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
407 if (scalar @values) {
410 <th align="right">| . $locale->text('Currency') . qq|</th>
411 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
412 '-values' => \@values, '-labels' => \%labels)) . qq|
419 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
420 push(@values, $item->{"id"});
421 $labels{$item->{"id"}} = $item->{"projectnumber"};
423 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
424 '-labels' => \%labels,
425 '-default' => $form->{"globalproject_id"}));
429 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
430 push(@values, $item->{id});
431 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
435 qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
436 <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
437 '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
443 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
444 push(@values, $item->{"id"});
445 $labels{$item->{"id"}} = $item->{"description"};
448 if (!$form->{"id"}) {
451 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
452 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
453 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
460 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
462 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
463 | . H($labels{$form->{"taxzone_id"}}) . qq|
468 # set option selected
469 foreach $item (qw(AR customer currency department employee)) {
470 $form->{"select$item"} =~ s/ selected//;
471 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
474 $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
476 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
477 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
478 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
481 if ($form->{currency} ne $form->{defaultcurrency}) {
482 if ($form->{forex}) {
483 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
484 <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
486 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
487 <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
490 $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
494 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
495 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
496 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
499 | if $form->{selectdepartment};
501 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
503 if ($form->{business}) {
506 <th align="right">| . $locale->text('Customer type') . qq|</th>
507 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
508 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
514 if ($form->{max_dunning_level}) {
517 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
519 <b>$form->{max_dunning_level}</b>;
520 | . $locale->text('Dunning Amount') . qq|: <b>|
521 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
528 $form->{fokus} = "invoice.customer";
530 # use JavaScript Calendar or not
531 $form->{jsscript} = 1;
533 if ($form->{type} eq "credit_note") {
535 <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
536 <input type="button" name="invdate" id="trigger1" value="|
537 . $locale->text('button') . qq|"></td>|;
541 Form->write_trigger(\%myconfig, "1",
546 <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
547 <input type="button" name="invdate" id="trigger1" value="|
548 . $locale->text('button') . qq|"></td>
551 <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
552 <input type="button" name="duedate" id="trigger2" value="|
553 . $locale->text('button') . qq|"></td>
556 <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
557 <input type="button" name="deliverydate" id="trigger3" value="|
558 . $locale->text('button') . qq|"></td>
563 Form->write_trigger(\%myconfig, "3",
564 "invdate", "BL", "trigger1",
565 "duedate", "BL", "trigger2",
566 "deliverydate", "BL", "trigger3");
569 $credittext = $locale->text('Credit Limit exceeded!!!');
571 my $follow_up_vc = $form->{customer};
572 $follow_up_vc =~ s/--.*?//;
573 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
575 $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
576 : ($form->{resubmit}) ? qq|document.invoice.submit()|
577 : ($creditwarning) ? qq|alert('$credittext')|
579 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
580 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
582 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
583 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
586 $form->write_trigger(\%myconfig, 2,
587 "orddate", "BL", "trigger_orddate",
588 "quodate", "BL", "trigger_quodate");
589 # show history button js
590 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
591 #/show history button js
595 <body onLoad="$onload">
596 <script type="text/javascript" src="js/common.js"></script>
597 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
598 <script type="text/javascript" src="js/vendor_selection.js"></script>
599 <script type="text/javascript" src="js/calculate_qty.js"></script>
600 <script type="text/javascript" src="js/follow_up.js"></script>
602 <form method="post" name="invoice" action="$form->{script}">
605 $form->hide_form(qw(id action type media format queued printed emailed title vc discount
606 creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
607 max_dunning_level dunning_amount
608 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
609 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
610 convert_from_do_ids convert_from_oe_ids),
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="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
618 <input type="hidden" name="follow_up_trans_type_1" value="sales_invoice">
619 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
620 <input type="hidden" name="follow_up_rowcount" value="1">
622 <input type="hidden" name="lizenzen" value="$lizenzen">
624 <div class="listtop" width="100%">$form->{title}</div>
632 <input type="hidden" name="customer_klass" value="| . H($form->{customer_klass}) . qq|">
633 <input type="hidden" name="customer_id" value="| . H($form->{customer_id}) . qq|">
634 <input type="hidden" name="oldcustomer" value="| . H($form->{oldcustomer}) . qq|">
635 <input type="hidden" name="selectcustomer" value="| . H($form->{selectcustomer}) . qq|">
640 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
641 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
646 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
647 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
648 <input type="hidden" name="selectAR" value="$form->{selectAR}">
654 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
655 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
659 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
661 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
664 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
665 <td colspan="3"><input name="shipvia" size="35" value="$form->{shipvia}"></td>
668 <th align="right">| . $locale->text('Transaction description') . qq|</th>
669 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
676 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
678 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
679 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
683 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
685 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
686 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
693 <td align="right" valign="top">
698 if ($form->{type} eq "credit_note") {
700 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
701 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
704 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
709 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
710 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
713 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
717 <th align="right">| . $locale->text('Due Date') . qq|</th>
721 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
726 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
727 <td><input name="ordnumber" size="11" value="$form->{ordnumber}"></td>
730 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
731 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
732 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
735 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
736 <td><input name="quonumber" size="11" value="$form->{quonumber}"></td>
739 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
740 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
741 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
744 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
745 <td><input name="cusordnumber" size="11" value="$form->{cusordnumber}"></td>
748 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
749 <td>$globalprojectnumber</td>
763 print qq|<input type="hidden" name="webdav" value="$webdav">|;
765 $lxdebug->leave_sub();
769 $lxdebug->enter_sub();
771 $auth->assert('invoice_edit');
773 $form->{invtotal} = $form->{invsubtotal};
775 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
778 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
781 $rows = ($rows > $introws) ? $rows : $introws;
783 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
785 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
787 $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
790 if ($form->{taxaccounts}) {
792 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
793 . $locale->text('Tax Included') . qq|</b><br><br>|;
796 if (!$form->{taxincluded}) {
798 foreach $item (split / /, $form->{taxaccounts}) {
799 if ($form->{"${item}_base"}) {
800 $form->{"${item}_total"} =
802 $form->{"${item}_base"} * $form->{"${item}_rate"},
804 $form->{invtotal} += $form->{"${item}_total"};
805 $form->{"${item}_total"} =
806 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
810 <th align="right">$form->{"${item}_description"} |
811 . $form->{"${item}_rate"} * 100 .qq|%</th>
812 <td align="right">$form->{"${item}_total"}</td>
818 $form->{invsubtotal} =
819 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
823 <th align="right">| . $locale->text('Subtotal') . qq|</th>
824 <td align="right">$form->{invsubtotal}</td>
830 if ($form->{taxincluded}) {
831 foreach $item (split / /, $form->{taxaccounts}) {
832 if ($form->{"${item}_base"}) {
833 $form->{"${item}_total"} =
835 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
836 (1 + $form->{"${item}_rate"})
839 $form->{"${item}_netto"} =
841 ($form->{"${item}_base"} - $form->{"${item}_total"}),
843 $form->{"${item}_total"} =
844 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
845 $form->{"${item}_netto"} =
846 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
850 <th align="right">Enthaltene $form->{"${item}_description"} |
851 . $form->{"${item}_rate"} * 100 .qq|%</th>
852 <td align="right">$form->{"${item}_total"}</td>
855 <th align="right">Nettobetrag</th>
856 <td align="right">$form->{"${item}_netto"}</td>
864 $form->{oldinvtotal} = $form->{invtotal};
866 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
868 my $follow_ups_block;
870 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
872 if (@{ $follow_ups} ) {
873 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
874 $follow_ups_block = qq|
876 <td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
890 <th align="left">| . $locale->text('Notes') . qq|</th>
891 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
892 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
897 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
906 <th align=left>| . $locale->text('Ertrag') . qq|</th>
907 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
910 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
911 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
913 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
914 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
923 <th align="right">| . $locale->text('Total') . qq|</th>
924 <td align="right">$form->{invtotal}</td>
936 <td><hr size="3" noshade></td>
939 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
942 <td align="left" width="30%"><b>Dateiname</b></td>
943 <td align="left" width="70%"><b>Webdavlink</b></td>
945 foreach $file (@{ $form->{WEBDAV} }) {
948 <td align="left">$file->{name}</td>
949 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
960 if ($form->{type} eq "credit_note") {
965 <tr class="listheading">
966 <th colspan="6" class="listheading">|
967 . $locale->text('Payments') . qq|</th>
975 <tr class="listheading">
976 <th colspan="6" class="listheading">|
977 . $locale->text('Incoming Payments') . qq|</th>
982 if ($form->{currency} eq $form->{defaultcurrency}) {
983 @column_index = qw(datepaid source memo paid AR_paid);
985 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
988 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
989 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
990 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
991 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
992 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
993 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
998 map { print "$column_data{$_}\n" } @column_index;
1006 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1007 for $i (1 .. $form->{paidaccounts}) {
1012 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1013 $form->{"selectAR_paid_$i"} =~
1014 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1017 $totalpaid += $form->{"paid_$i"};
1018 if ($form->{"paid_$i"}) {
1019 $form->{"paid_$i"} =
1020 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1022 $form->{"exchangerate_$i"} =
1023 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1025 if ($form->{"exchangerate_$i"} == 0) {
1026 $form->{"exchangerate_$i"} = "";
1028 $exchangerate = qq| |;
1029 if ($form->{currency} ne $form->{defaultcurrency}) {
1030 if ($form->{"forex_$i"}) {
1031 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1033 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1037 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1039 $column_data{"paid_$i"} =
1040 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
1041 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1042 $column_data{"AR_paid_$i"} =
1043 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1044 $column_data{"datepaid_$i"} =
1045 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)\">
1046 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1047 $column_data{"source_$i"} =
1048 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1049 $column_data{"memo_$i"} =
1050 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1052 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1055 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1058 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
1064 <td align="center">| . $locale->text('Total') . qq|</td>
1065 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
1070 <td align="center">| . $locale->text('Missing amount') . qq|</td>
1071 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
1075 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1076 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1081 <td><hr size="3" noshade></td>
1095 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1096 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1099 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
1102 <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
1103 . $locale->text('Update') . qq|">
1104 <input class="submit" type="submit" name="action" value="|
1105 . $locale->text('Ship to') . qq|">
1106 <input class="submit" type="submit" name="action" value="|
1107 . $locale->text('Print') . qq|">
1108 <input class="submit" type="submit" name="action" value="|
1109 . $locale->text('E-mail') . qq|"> |;
1110 print qq|<input class="submit" type="submit" name="action" value="|
1111 . $locale->text('Storno') . qq|"> | if ($show_storno);
1112 print qq|<input class="submit" type="submit" name="action" value="|
1113 . $locale->text('Post Payment') . qq|">
1115 print qq|<input class="submit" type="submit" name="action" value="|
1116 . $locale->text('Use As Template') . qq|">
1118 if ($form->{id} && !($form->{type} eq "credit_note")) {
1120 <input class="submit" type="submit" name="action" value="|
1121 . $locale->text('Credit Note') . qq|">
1124 if ($form->{radier}) {
1126 <input class="submit" type="submit" name="action" value="|
1127 . $locale->text('Delete') . qq|">
1132 if ($invdate > $closedto) {
1134 <input class="submit" type="submit" name="action" value="|
1135 . $locale->text('Order') . qq|">
1140 <input type="button" class="submit" onclick="follow_up_window()" value="|
1141 . $locale->text('Follow-Up')
1145 if ($invdate > $closedto) {
1146 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1147 . $locale->text('Update') . qq|">
1148 <input class="submit" type="submit" name="action" value="|
1149 . $locale->text('Ship to') . qq|">
1150 <input class="submit" type="submit" name="action" value="|
1151 . $locale->text('Preview') . qq|">
1152 <input class="submit" type="submit" name="action" value="|
1153 . $locale->text('E-mail') . qq|">
1154 <input class="submit" type="submit" name="action" value="|
1155 . $locale->text('Print and Post') . qq|">
1156 <input class="submit" type="submit" name="action" value="|
1157 . $locale->text('Post') . qq|"> | .
1158 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1159 '-class' => 'submit'));
1163 # button for saving history
1164 if($form->{id} ne "") {
1166 <input type="button" class="submit" onclick="set_history_window(|
1168 . qq|);" name="history" id="history" value="|
1169 . $locale->text('history')
1172 # /button for saving history
1174 # mark_as_paid button
1175 if($form->{id} ne "") {
1176 print qq|<input type="submit" class="submit" name="action" value="|
1177 . $locale->text('mark as paid') . qq|">|;
1179 # /mark_as_paid button
1180 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1183 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1185 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1186 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1187 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
1196 $lxdebug->leave_sub();
1200 $lxdebug->enter_sub();
1202 $auth->assert('invoice_edit');
1204 &mark_as_paid_common(\%myconfig,"ar");
1206 $lxdebug->leave_sub();
1210 $lxdebug->enter_sub();
1212 $auth->assert('invoice_edit');
1214 my ($recursive_call) = shift;
1216 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
1218 $form->{print_and_post} = 0 if $form->{second_run};
1219 $taxincluded = "checked" if $form->{taxincluded};
1220 $form->{update} = 1;
1222 &check_name(customer);
1224 $form->{taxincluded} ||= $taxincluded;
1226 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1227 $form->{exchangerate} = $form->{forex} if $form->{forex};
1229 for $i (1 .. $form->{paidaccounts}) {
1230 next unless $form->{"paid_$i"};
1231 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1232 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1233 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1236 $i = $form->{rowcount};
1237 $exchangerate = $form->{exchangerate} || 1;
1239 # if last row empty, check the form otherwise retrieve new item
1240 if ( ($form->{"partnumber_$i"} eq "")
1241 && ($form->{"description_$i"} eq "")
1242 && ($form->{"partsgroup_$i"} eq "")) {
1244 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1249 IS->retrieve_item(\%myconfig, \%$form);
1251 $rows = scalar @{ $form->{item_list} };
1253 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
1256 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1265 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1267 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1268 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1270 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1271 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1273 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1275 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1276 $decimalplaces = max 2, length $1;
1279 $form->{"sellprice_$i"} = $sellprice;
1281 # if there is an exchange rate adjust sellprice
1282 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1283 $form->{"sellprice_$i"} /= $exchangerate;
1286 $form->{"listprice_$i"} /= $exchangerate;
1288 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1289 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1290 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1291 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1293 $form->{creditremaining} -= $amount;
1295 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
1297 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1300 if ($form->{"inventory_accno_$i"} ne "") {
1301 $form->{"lizenzen_$i"} = qq|<option></option>|;
1302 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1303 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1305 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
1309 # get pricegroups for parts
1310 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1312 # build up html code for prices_$i
1313 &set_pricegroup($i);
1320 # ok, so this is a new part
1321 # ask if it is a part or service item
1323 if ( $form->{"partsgroup_$i"}
1324 && ($form->{"partsnumber_$i"} eq "")
1325 && ($form->{"description_$i"} eq "")) {
1326 $form->{rowcount}--;
1327 $form->{"discount_$i"} = "";
1331 $form->{"id_$i"} = 0;
1336 $lxdebug->leave_sub();
1340 $lxdebug->enter_sub();
1342 $auth->assert('invoice_edit');
1344 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1345 for $i (1 .. $form->{paidaccounts}) {
1346 if ($form->{"paid_$i"}) {
1347 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1349 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1351 $form->error($locale->text('Cannot post payment for a closed period!'))
1352 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1354 if ($form->{currency} ne $form->{defaultcurrency}) {
1355 $form->{"exchangerate_$i"} = $form->{exchangerate}
1356 if ($invdate == $datepaid);
1357 $form->isblank("exchangerate_$i",
1358 $locale->text('Exchangerate for payment missing!'));
1363 ($form->{AR}) = split /--/, $form->{AR};
1364 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1366 $form->redirect($locale->text('Payment posted!'))
1367 if (IS->post_payment(\%myconfig, \%$form));
1368 $form->error($locale->text('Cannot post payment!'));
1371 $lxdebug->leave_sub();
1375 $lxdebug->enter_sub();
1377 $auth->assert('invoice_edit');
1379 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1380 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1381 $form->isblank("customer", $locale->text('Customer missing!'));
1382 $form->error($locale->text('Cannot post invoice for a closed period!'))
1383 if ($form->date_closed($form->{"invdate"}, \%myconfig));
1385 $form->{invnumber} =~ s/^\s*//g;
1386 $form->{invnumber} =~ s/\s*$//g;
1388 # if oldcustomer ne customer redo form
1389 if (&check_name(customer)) {
1393 if ($form->{second_run}) {
1394 $form->{print_and_post} = 0;
1399 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1400 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1402 $form->error($locale->text('Cannot post invoice for a closed period!'))
1403 if ($invdate <= $closedto);
1405 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1406 if ($form->{currency} ne $form->{defaultcurrency});
1408 for $i (1 .. $form->{paidaccounts}) {
1409 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1410 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1412 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1414 $form->error($locale->text('Cannot post payment for a closed period!'))
1415 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1417 if ($form->{currency} ne $form->{defaultcurrency}) {
1418 $form->{"exchangerate_$i"} = $form->{exchangerate}
1419 if ($invdate == $datepaid);
1420 $form->isblank("exchangerate_$i",
1421 $locale->text('Exchangerate for payment missing!'));
1426 ($form->{AR}) = split /--/, $form->{AR};
1427 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1428 $form->{storno} ||= 0;
1430 $form->{label} = $locale->text('Invoice');
1432 $form->{id} = 0 if $form->{postasnew};
1434 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1435 if ($form->{postasnew}) {
1436 if ($form->{type} eq "credit_note") {
1437 undef($form->{cnnumber});
1439 undef($form->{invnumber});
1444 $form->error($locale->text('Cannot post invoice!'))
1445 unless IS->post_invoice(\%myconfig, \%$form);
1446 remove_draft() if $form->{remove_draft};
1448 if(!exists $form->{addition}) {
1449 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1450 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1451 $form->{storno} ? "STORNO" :
1453 $form->save_history($form->dbconnect(\%myconfig));
1456 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1459 $lxdebug->leave_sub();
1462 sub print_and_post {
1463 $lxdebug->enter_sub();
1465 $auth->assert('invoice_edit');
1467 $old_form = new Form;
1469 $form->{print_and_post} = 1;
1473 $lxdebug->leave_sub();
1477 sub use_as_template {
1478 $lxdebug->enter_sub();
1480 $auth->assert('invoice_edit');
1482 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);
1483 $form->{paidaccounts} = 1;
1484 $form->{rowcount}--;
1485 $form->{invdate} = $form->current_date(\%myconfig);
1488 $lxdebug->leave_sub();
1492 $lxdebug->enter_sub();
1494 $auth->assert('invoice_edit');
1496 if ($form->{storno}) {
1497 $form->error($locale->text('Cannot storno storno invoice!'));
1500 if (IS->has_storno(\%myconfig, $form, "ar")) {
1501 $form->error($locale->text("Invoice has already been storno'd!"));
1504 map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
1510 # Payments must not be recorded for the new storno invoice.
1511 $form->{paidaccounts} = 0;
1512 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1514 $form->{storno_id} = $form->{id};
1515 $form->{storno} = 1;
1517 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1518 $form->{rowcount}++;
1521 $lxdebug->leave_sub();
1525 $lxdebug->enter_sub();
1527 $auth->assert('invoice_edit');
1529 $form->{preview} = 1;
1530 $old_form = new Form;
1531 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1533 &print_form($old_form);
1534 $lxdebug->leave_sub();
1539 $lxdebug->enter_sub();
1541 $auth->assert('invoice_edit');
1543 if ($form->{second_run}) {
1544 $form->{print_and_post} = 0;
1551 <form method="post" action="$form->{script}">
1554 # delete action variable
1555 map { delete $form->{$_} } qw(action header);
1557 foreach $key (keys %$form) {
1558 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1559 $form->{$key} =~ s/\"/"/g;
1560 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1564 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1567 . $locale->text('Are you sure you want to delete Invoice Number')
1568 . qq| $form->{invnumber}
1572 <input name="action" class="submit" type="submit" value="|
1573 . $locale->text('Yes') . qq|">
1577 $lxdebug->leave_sub();
1581 $lxdebug->enter_sub();
1583 $auth->assert('invoice_edit');
1585 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1587 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1590 $form->{rowcount}--;
1591 $form->{shipto} = 1;
1594 $form->{title} = $locale->text('Add Credit Note');
1595 $form->{script} = 'is.pl';
1600 # bo creates the id, reset it
1601 map { delete $form->{$_} }
1602 qw(id invnumber subject message cc bcc printed emailed queued);
1603 $form->{ $form->{vc} } =~ s/--.*//g;
1604 $form->{type} = "credit_note";
1607 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1609 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1610 qw(creditlimit creditremaining);
1612 $currency = $form->{currency};
1615 $form->{currency} = $currency;
1616 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
1617 $form->{exchangerate} = $form->{forex} || '';
1619 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1626 $lxdebug->leave_sub();
1630 $lxdebug->enter_sub();
1632 $auth->assert('invoice_edit');
1634 if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
1635 # saving the history
1636 if(!exists $form->{addition}) {
1637 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1638 $form->{addition} = "DELETED";
1639 $form->save_history($form->dbconnect(\%myconfig));
1641 # /saving the history
1642 $form->redirect($locale->text('Invoice deleted!'));
1644 $form->error($locale->text('Cannot delete invoice!'));
1646 $lxdebug->leave_sub();
1650 $lxdebug->enter_sub();
1652 $auth->assert('invoice_edit');
1657 my $saved_form = save_form();
1661 restore_form($saved_form, 0, qw(id invnumber));
1666 $lxdebug->leave_sub();