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";
72 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
74 $form->error("Access Denied");
80 $lxdebug->leave_sub();
84 $lxdebug->enter_sub();
86 $auth->assert('invoice_edit');
89 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
90 #/show hhistory button
92 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
94 $form->error("Access Denied");
97 if ($form->{print_and_post}) {
98 $form->{action} = "print";
99 $form->{resubmit} = 1;
100 $language_id = $form->{language_id};
101 $printer_id = $form->{printer_id};
105 if ($form->{print_and_post}) {
106 $form->{language_id} = $language_id;
107 $form->{printer_id} = $printer_id;
112 $lxdebug->leave_sub();
116 $lxdebug->enter_sub();
118 $auth->assert('invoice_edit');
120 $form->{vc} = 'customer';
123 $form->{webdav} = $webdav;
124 $form->{lizenzen} = $lizenzen;
126 $form->create_links("AR", \%myconfig, "customer");
128 if ($form->{all_customer}) {
129 unless ($form->{customer_id}) {
130 $form->{customer_id} = $form->{all_customer}->[0]->{id};
131 $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
135 if ($form->{payment_id}) {
136 $payment_id = $form->{payment_id};
138 if ($form->{language_id}) {
139 $language_id = $form->{language_id};
141 if ($form->{taxzone_id}) {
142 $taxzone_id = $form->{taxzone_id};
147 if ($form->{shipto_id}) {
148 $shipto_id = $form->{shipto_id};
151 $cp_id = $form->{cp_id};
152 IS->get_customer(\%myconfig, \%$form);
154 #quote all_customer Bug 133
155 foreach $ref (@{ $form->{all_customer} }) {
156 $ref->{name} = $form->quote($ref->{name});
161 IS->retrieve_invoice(\%myconfig, \%$form);
162 $form->{cp_id} = $cp_id;
165 $form->{payment_id} = $payment_id;
168 $form->{language_id} = $language_id;
171 $form->{taxzone_id} = $taxzone_id;
174 $form->{shipto_id} = $shipto_id;
177 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
180 if ($form->{all_departments}) {
181 $form->{selectdepartment} = "<option>\n";
182 $form->{department} = "$form->{department}--$form->{department_id}";
185 $form->{selectdepartment} .=
186 "<option>$_->{description}--$_->{id}</option>\n"
187 } (@{ $form->{all_departments} });
190 $form->{employee} = "$form->{employee}--$form->{employee_id}";
193 $form->{forex} = $form->{exchangerate};
194 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
196 foreach $key (keys %{ $form->{AR_links} }) {
197 foreach $ref (@{ $form->{AR_links}{$key} }) {
198 $form->{"select$key"} .=
199 "<option>$ref->{accno}--$ref->{description}</option>\n";
202 if ($key eq "AR_paid") {
203 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
204 $form->{"AR_paid_$i"} =
205 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
208 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
209 $form->{"datepaid_$i"} =
210 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
211 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
212 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
213 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
214 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
216 $form->{paidaccounts} = $i;
220 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
225 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
227 $form->{AR} = $form->{AR_1} unless $form->{id};
230 ($form->datetonum($form->{invdate}, \%myconfig) <=
231 $form->datetonum($form->{closedto}, \%myconfig));
233 $lxdebug->leave_sub();
236 sub prepare_invoice {
237 $lxdebug->enter_sub();
239 $auth->assert('invoice_edit');
241 if ($form->{type} eq "credit_note") {
242 $form->{type} = "credit_note";
243 $form->{formname} = "credit_note";
245 $form->{type} = "invoice";
246 $form->{formname} = "invoice";
251 map { $form->{$_} =~ s/\"/"/g }
252 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
254 # # get pricegroups for parts
255 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
259 foreach $ref (@{ $form->{invoice_details} }) {
262 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
263 $form->{"discount_$i"} =
264 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
265 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
267 $decimalplaces = ($dec > 2) ? $dec : 2;
269 $form->{"sellprice_$i"} =
270 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
273 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
274 $dec_qty = length $dec_qty;
277 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
279 map { $form->{"${_}_$i"} =~ s/\"/"/g }
280 qw(partnumber description unit partnotes);
281 $form->{rowcount} = $i;
285 $lxdebug->leave_sub();
289 $lxdebug->enter_sub();
291 $auth->assert('invoice_edit');
293 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
294 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
297 if ($form->{type} eq "credit_note") {
298 $form->{title} = $locale->text('Edit Credit Note');
299 $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
301 $form->{title} = $locale->text('Edit Sales Invoice');
302 $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
305 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
306 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
308 $payment = qq|<option value=""></option>|;
309 foreach $item (@{ $form->{payment_terms} }) {
310 if ($form->{payment_id} eq $item->{id}) {
311 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
313 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
317 my $set_duedate_url = "$form->{script}?action=set_duedate";
319 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
320 push(@ { $form->{AJAX} }, $pjx);
322 my @old_project_ids = ($form->{"globalproject_id"});
323 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
325 $form->get_lists("contacts" => "ALL_CONTACTS",
326 "shipto" => "ALL_SHIPTO",
327 "projects" => { "key" => "ALL_PROJECTS",
329 "old_id" => \@old_project_ids },
330 "employees" => "ALL_SALESMEN",
331 "taxzones" => "ALL_TAXZONES",
332 "currencies" => "ALL_CURRENCIES",
333 "customers" => "ALL_CUSTOMERS",
334 "price_factors" => "ALL_PRICE_FACTORS");
337 my @values = (undef);
338 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
339 push(@values, $item->{"cp_id"});
340 $labels{$item->{"cp_id"}} = join(',', $item->{"cp_name"}, $item->{"cp_givenname"}) . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
343 if (scalar @values > 1) {
346 <th align="right">| . $locale->text('Contact Person') . qq|</th>
347 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
348 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
355 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
356 push(@values, $item->{"id"});
357 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
362 <th align="right">| . $locale->text('Employee') . qq|</th>
363 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
364 '-values' => \@values, '-labels' => \%labels)) . qq|
371 foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
372 push(@values, $item->{name}.qq|--|.$item->{"id"});
373 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
376 $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
379 <th align="right">| . $locale->text('Customer') . qq|</th>
381 (($myconfig{vclimit} <= scalar(@values))
382 ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
383 : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
384 '-onChange' => 'document.getElementById(\'update_button\').click();',
385 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
386 <input type="button" value="?" onclick="show_vc_details('customer')">
391 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
392 push(@values, $item->{"shipto_id"});
393 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
397 if (scalar @values > 1) {
400 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
401 <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
402 '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
408 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
409 push(@values, $item);
410 $labels{$item} = $item;
413 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
415 if (scalar @values) {
418 <th align="right">| . $locale->text('Currency') . qq|</th>
419 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
420 '-values' => \@values, '-labels' => \%labels)) . qq|
427 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
428 push(@values, $item->{"id"});
429 $labels{$item->{"id"}} = $item->{"projectnumber"};
431 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
432 '-labels' => \%labels,
433 '-default' => $form->{"globalproject_id"}));
437 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
438 push(@values, $item->{id});
439 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
443 qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
444 <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
445 '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
451 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
452 push(@values, $item->{"id"});
453 $labels{$item->{"id"}} = $item->{"description"};
456 if (!$form->{"id"}) {
459 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
460 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
461 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
468 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
470 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
471 | . H($labels{$form->{"taxzone_id"}}) . qq|
476 # set option selected
477 foreach $item (qw(AR customer currency department employee)) {
478 $form->{"select$item"} =~ s/ selected//;
479 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
482 $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
484 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
485 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
486 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
489 if ($form->{currency} ne $form->{defaultcurrency}) {
490 if ($form->{forex}) {
491 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
492 <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
494 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
495 <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
498 $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
502 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
503 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
504 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
507 | if $form->{selectdepartment};
509 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
511 if ($form->{business}) {
514 <th align="right">| . $locale->text('Customer type') . qq|</th>
515 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
516 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
522 if ($form->{max_dunning_level}) {
525 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
527 <b>$form->{max_dunning_level}</b>;
528 | . $locale->text('Dunning Amount') . qq|: <b>|
529 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
536 $form->{fokus} = "invoice.customer";
538 # use JavaScript Calendar or not
539 $form->{jsscript} = 1;
541 if ($form->{type} eq "credit_note") {
543 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
544 <input type="button" name="invdate" id="trigger1" value="|
545 . $locale->text('button') . qq|"></td>|;
549 Form->write_trigger(\%myconfig, "1",
554 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
555 <input type="button" name="invdate" id="trigger1" value="|
556 . $locale->text('button') . qq|"></td>
559 <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
560 <input type="button" name="duedate" id="trigger2" value="|
561 . $locale->text('button') . qq|"></td>
564 <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
565 <input type="button" name="deliverydate" id="trigger3" value="|
566 . $locale->text('button') . qq|"></td>
571 Form->write_trigger(\%myconfig, "3",
572 "invdate", "BL", "trigger1",
573 "duedate", "BL", "trigger2",
574 "deliverydate", "BL", "trigger3");
577 $credittext = $locale->text('Credit Limit exceeded!!!');
579 my $follow_up_vc = $form->{customer};
580 $follow_up_vc =~ s/--.*?//;
581 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
583 $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
584 : ($form->{resubmit}) ? qq|document.invoice.submit()|
585 : ($creditwarning) ? qq|alert('$credittext')|
587 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
588 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
590 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
591 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
594 $form->write_trigger(\%myconfig, 2,
595 "orddate", "BL", "trigger_orddate",
596 "quodate", "BL", "trigger_quodate");
597 # show history button js
598 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
599 #/show history button js
603 <body onLoad="$onload">
604 <script type="text/javascript" src="js/common.js"></script>
605 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
606 <script type="text/javascript" src="js/vendor_selection.js"></script>
607 <script type="text/javascript" src="js/calculate_qty.js"></script>
608 <script type="text/javascript" src="js/follow_up.js"></script>
610 <form method="post" name="invoice" action="$form->{script}">
613 $form->hide_form(qw(id action type media format queued printed emailed title vc discount
614 creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
615 max_dunning_level dunning_amount
616 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
617 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus),
618 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
620 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
624 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
625 <input type="hidden" name="follow_up_trans_type_1" value="sales_invoice">
626 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
627 <input type="hidden" name="follow_up_rowcount" value="1">
629 <input type="hidden" name="lizenzen" value="$lizenzen">
631 <div class="listtop" width="100%">$form->{title}</div>
639 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">
640 <input type="hidden" name="customer_id" value="$form->{customer_id}">
641 <input type="hidden" name="oldcustomer" value="$form->{oldcustomer}">
642 <input type="hidden" name="selectcustomer" value="$form->{selectcustomer}">
647 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
648 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
653 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
654 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
655 <input type="hidden" name="selectAR" value="$form->{selectAR}">
661 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
662 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
666 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
668 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
671 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
672 <td colspan="3"><input name="shipvia" size="35" value="$form->{shipvia}"></td>
675 <th align="right">| . $locale->text('Transaction description') . qq|</th>
676 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
683 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
685 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
686 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
690 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
692 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
693 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
700 <td align="right" valign="top">
705 if ($form->{type} eq "credit_note") {
707 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
708 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
711 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
716 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
717 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
720 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
724 <th align="right">| . $locale->text('Due Date') . qq|</th>
728 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
733 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
734 <td><input name="ordnumber" size="11" value="$form->{ordnumber}"></td>
737 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
738 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
739 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
742 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
743 <td><input name="quonumber" size="11" value="$form->{quonumber}"></td>
746 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
747 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
748 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
751 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
752 <td><input name="cusordnumber" size="11" value="$form->{cusordnumber}"></td>
755 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
756 <td>$globalprojectnumber</td>
770 print qq|<input type="hidden" name="webdav" value="$webdav">|;
772 $lxdebug->leave_sub();
776 $lxdebug->enter_sub();
778 $auth->assert('invoice_edit');
780 $form->{invtotal} = $form->{invsubtotal};
782 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
785 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
788 $rows = ($rows > $introws) ? $rows : $introws;
790 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
792 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
794 $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
797 if ($form->{taxaccounts}) {
799 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
800 . $locale->text('Tax Included') . qq|</b><br><br>|;
803 if (!$form->{taxincluded}) {
805 foreach $item (split / /, $form->{taxaccounts}) {
806 if ($form->{"${item}_base"}) {
807 $form->{"${item}_total"} =
809 $form->{"${item}_base"} * $form->{"${item}_rate"},
811 $form->{invtotal} += $form->{"${item}_total"};
812 $form->{"${item}_total"} =
813 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
817 <th align="right">$form->{"${item}_description"} |
818 . $form->{"${item}_rate"} * 100 .qq|%</th>
819 <td align="right">$form->{"${item}_total"}</td>
825 $form->{invsubtotal} =
826 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
830 <th align="right">| . $locale->text('Subtotal') . qq|</th>
831 <td align="right">$form->{invsubtotal}</td>
837 if ($form->{taxincluded}) {
838 foreach $item (split / /, $form->{taxaccounts}) {
839 if ($form->{"${item}_base"}) {
840 $form->{"${item}_total"} =
842 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
843 (1 + $form->{"${item}_rate"})
846 $form->{"${item}_netto"} =
848 ($form->{"${item}_base"} - $form->{"${item}_total"}),
850 $form->{"${item}_total"} =
851 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
852 $form->{"${item}_netto"} =
853 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
857 <th align="right">Enthaltene $form->{"${item}_description"} |
858 . $form->{"${item}_rate"} * 100 .qq|%</th>
859 <td align="right">$form->{"${item}_total"}</td>
862 <th align="right">Nettobetrag</th>
863 <td align="right">$form->{"${item}_netto"}</td>
871 $form->{oldinvtotal} = $form->{invtotal};
873 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
875 my $follow_ups_block;
877 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
879 if (@{ $follow_ups} ) {
880 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
881 $follow_ups_block = qq|
883 <td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
897 <th align="left">| . $locale->text('Notes') . qq|</th>
898 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
899 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
904 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
913 <th align=left>| . $locale->text('Ertrag') . qq|</th>
914 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
917 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
918 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
920 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
921 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
930 <th align="right">| . $locale->text('Total') . qq|</th>
931 <td align="right">$form->{invtotal}</td>
943 <td><hr size="3" noshade></td>
946 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
949 <td align="left" width="30%"><b>Dateiname</b></td>
950 <td align="left" width="70%"><b>Webdavlink</b></td>
952 foreach $file (@{ $form->{WEBDAV} }) {
955 <td align="left">$file->{name}</td>
956 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
967 if ($form->{type} eq "credit_note") {
972 <tr class="listheading">
973 <th colspan="6" class="listheading">|
974 . $locale->text('Payments') . qq|</th>
982 <tr class="listheading">
983 <th colspan="6" class="listheading">|
984 . $locale->text('Incoming Payments') . qq|</th>
989 if ($form->{currency} eq $form->{defaultcurrency}) {
990 @column_index = qw(datepaid source memo paid AR_paid);
992 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
995 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
996 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
997 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
998 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
999 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
1000 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
1005 map { print "$column_data{$_}\n" } @column_index;
1013 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1014 for $i (1 .. $form->{paidaccounts}) {
1019 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1020 $form->{"selectAR_paid_$i"} =~
1021 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1024 $totalpaid += $form->{"paid_$i"};
1025 if ($form->{"paid_$i"}) {
1026 $form->{"paid_$i"} =
1027 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1029 $form->{"exchangerate_$i"} =
1030 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1032 if ($form->{"exchangerate_$i"} == 0) {
1033 $form->{"exchangerate_$i"} = "";
1035 $exchangerate = qq| |;
1036 if ($form->{currency} ne $form->{defaultcurrency}) {
1037 if ($form->{"forex_$i"}) {
1038 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1040 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1044 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1046 $column_data{"paid_$i"} =
1047 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
1048 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1049 $column_data{"AR_paid_$i"} =
1050 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1051 $column_data{"datepaid_$i"} =
1052 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)\">
1053 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1054 $column_data{"source_$i"} =
1055 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1056 $column_data{"memo_$i"} =
1057 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1059 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1062 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1065 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
1071 <td align="center">| . $locale->text('Total') . qq|</td>
1072 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
1077 <td align="center">| . $locale->text('Missing amount') . qq|</td>
1078 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
1082 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1083 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1088 <td><hr size="3" noshade></td>
1102 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1103 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1106 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
1109 <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
1110 . $locale->text('Update') . qq|">
1111 <input class="submit" type="submit" name="action" value="|
1112 . $locale->text('Ship to') . qq|">
1113 <input class="submit" type="submit" name="action" value="|
1114 . $locale->text('Print') . qq|">
1115 <input class="submit" type="submit" name="action" value="|
1116 . $locale->text('E-mail') . qq|"> |;
1117 print qq|<input class="submit" type="submit" name="action" value="|
1118 . $locale->text('Storno') . qq|"> | if ($show_storno);
1119 print qq|<input class="submit" type="submit" name="action" value="|
1120 . $locale->text('Post Payment') . qq|">
1122 print qq|<input class="submit" type="submit" name="action" value="|
1123 . $locale->text('Use As Template') . qq|">
1125 if ($form->{id} && !($form->{type} eq "credit_note")) {
1127 <input class="submit" type="submit" name="action" value="|
1128 . $locale->text('Credit Note') . qq|">
1131 if ($form->{radier}) {
1133 <input class="submit" type="submit" name="action" value="|
1134 . $locale->text('Delete') . qq|">
1139 if ($invdate > $closedto) {
1141 <input class="submit" type="submit" name="action" value="|
1142 . $locale->text('Order') . qq|">
1147 <input type="button" class="submit" onclick="follow_up_window()" value="|
1148 . $locale->text('Follow-Up')
1152 if ($invdate > $closedto) {
1153 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1154 . $locale->text('Update') . qq|">
1155 <input class="submit" type="submit" name="action" value="|
1156 . $locale->text('Ship to') . qq|">
1157 <input class="submit" type="submit" name="action" value="|
1158 . $locale->text('Preview') . qq|">
1159 <input class="submit" type="submit" name="action" value="|
1160 . $locale->text('E-mail') . qq|">
1161 <input class="submit" type="submit" name="action" value="|
1162 . $locale->text('Print and Post') . qq|">
1163 <input class="submit" type="submit" name="action" value="|
1164 . $locale->text('Post') . qq|"> | .
1165 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1166 '-class' => 'submit'));
1170 # button for saving history
1171 if($form->{id} ne "") {
1173 <input type="button" class="submit" onclick="set_history_window(|
1175 . qq|);" name="history" id="history" value="|
1176 . $locale->text('history')
1179 # /button for saving history
1181 # mark_as_paid button
1182 if($form->{id} ne "") {
1183 print qq|<input type="submit" class="submit" name="action" value="|
1184 . $locale->text('mark as paid') . qq|">|;
1186 # /mark_as_paid button
1187 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1190 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1192 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1193 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1194 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
1203 $lxdebug->leave_sub();
1207 $lxdebug->enter_sub();
1209 $auth->assert('invoice_edit');
1211 &mark_as_paid_common(\%myconfig,"ar");
1213 $lxdebug->leave_sub();
1217 $lxdebug->enter_sub();
1219 $auth->assert('invoice_edit');
1221 my ($recursive_call) = shift;
1223 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
1225 $form->{print_and_post} = 0 if $form->{second_run};
1226 $taxincluded = "checked" if $form->{taxincluded};
1227 $form->{update} = 1;
1229 &check_name(customer);
1231 $form->{taxincluded} ||= $taxincluded;
1233 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1234 $form->{exchangerate} = $form->{forex} if $form->{forex};
1236 for $i (1 .. $form->{paidaccounts}) {
1237 next unless $form->{"paid_$i"};
1238 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1239 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1240 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1243 $i = $form->{rowcount};
1244 $exchangerate = $form->{exchangerate} || 1;
1246 # if last row empty, check the form otherwise retrieve new item
1247 if ( ($form->{"partnumber_$i"} eq "")
1248 && ($form->{"description_$i"} eq "")
1249 && ($form->{"partsgroup_$i"} eq "")) {
1251 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1256 IS->retrieve_item(\%myconfig, \%$form);
1258 $rows = scalar @{ $form->{item_list} };
1260 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
1263 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1272 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1274 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1275 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1277 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1278 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1280 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1282 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1283 $decimalplaces = max 2, length $1;
1286 $form->{"sellprice_$i"} = $sellprice;
1288 # if there is an exchange rate adjust sellprice
1289 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1290 $form->{"sellprice_$i"} /= $exchangerate;
1293 $form->{"listprice_$i"} /= $exchangerate;
1295 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1296 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1297 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1298 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1300 $form->{creditremaining} -= $amount;
1302 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
1304 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1307 if ($form->{"inventory_accno_$i"} ne "") {
1308 $form->{"lizenzen_$i"} = qq|<option></option>|;
1309 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1310 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1312 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
1316 # get pricegroups for parts
1317 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1319 # build up html code for prices_$i
1320 &set_pricegroup($i);
1327 # ok, so this is a new part
1328 # ask if it is a part or service item
1330 if ( $form->{"partsgroup_$i"}
1331 && ($form->{"partsnumber_$i"} eq "")
1332 && ($form->{"description_$i"} eq "")) {
1333 $form->{rowcount}--;
1334 $form->{"discount_$i"} = "";
1338 $form->{"id_$i"} = 0;
1343 $lxdebug->leave_sub();
1347 $lxdebug->enter_sub();
1349 $auth->assert('invoice_edit');
1351 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1352 for $i (1 .. $form->{paidaccounts}) {
1353 if ($form->{"paid_$i"}) {
1354 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1356 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1358 $form->error($locale->text('Cannot post payment for a closed period!'))
1359 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1361 if ($form->{currency} ne $form->{defaultcurrency}) {
1362 $form->{"exchangerate_$i"} = $form->{exchangerate}
1363 if ($invdate == $datepaid);
1364 $form->isblank("exchangerate_$i",
1365 $locale->text('Exchangerate for payment missing!'));
1370 ($form->{AR}) = split /--/, $form->{AR};
1371 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1373 $form->redirect($locale->text('Payment posted!'))
1374 if (IS->post_payment(\%myconfig, \%$form));
1375 $form->error($locale->text('Cannot post payment!'));
1378 $lxdebug->leave_sub();
1382 $lxdebug->enter_sub();
1384 $auth->assert('invoice_edit');
1386 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1387 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1388 $form->isblank("customer", $locale->text('Customer missing!'));
1389 $form->error($locale->text('Cannot post invoice for a closed period!'))
1390 if ($form->date_closed($form->{"invdate"}, \%myconfig));
1392 $form->{invnumber} =~ s/^\s*//g;
1393 $form->{invnumber} =~ s/\s*$//g;
1395 # if oldcustomer ne customer redo form
1396 if (&check_name(customer)) {
1400 if ($form->{second_run}) {
1401 $form->{print_and_post} = 0;
1406 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1407 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1409 $form->error($locale->text('Cannot post invoice for a closed period!'))
1410 if ($invdate <= $closedto);
1412 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1413 if ($form->{currency} ne $form->{defaultcurrency});
1415 for $i (1 .. $form->{paidaccounts}) {
1416 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1417 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1419 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1421 $form->error($locale->text('Cannot post payment for a closed period!'))
1422 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1424 if ($form->{currency} ne $form->{defaultcurrency}) {
1425 $form->{"exchangerate_$i"} = $form->{exchangerate}
1426 if ($invdate == $datepaid);
1427 $form->isblank("exchangerate_$i",
1428 $locale->text('Exchangerate for payment missing!'));
1433 ($form->{AR}) = split /--/, $form->{AR};
1434 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1435 $form->{storno} ||= 0;
1437 $form->{label} = $locale->text('Invoice');
1439 $form->{id} = 0 if $form->{postasnew};
1441 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1442 if ($form->{postasnew}) {
1443 if ($form->{type} eq "credit_note") {
1444 undef($form->{cnnumber});
1446 undef($form->{invnumber});
1451 $form->error($locale->text('Cannot post invoice!'))
1452 unless IS->post_invoice(\%myconfig, \%$form);
1453 remove_draft() if $form->{remove_draft};
1455 if(!exists $form->{addition}) {
1456 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1457 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1458 $form->{storno} ? "STORNO" :
1460 $form->save_history($form->dbconnect(\%myconfig));
1463 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1466 $lxdebug->leave_sub();
1469 sub print_and_post {
1470 $lxdebug->enter_sub();
1472 $auth->assert('invoice_edit');
1474 $old_form = new Form;
1476 $form->{print_and_post} = 1;
1480 $lxdebug->leave_sub();
1484 sub use_as_template {
1485 $lxdebug->enter_sub();
1487 $auth->assert('invoice_edit');
1489 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);
1490 $form->{paidaccounts} = 1;
1491 $form->{rowcount}--;
1492 $form->{invdate} = $form->current_date(\%myconfig);
1495 $lxdebug->leave_sub();
1499 $lxdebug->enter_sub();
1501 $auth->assert('invoice_edit');
1503 if ($form->{storno}) {
1504 $form->error($locale->text('Cannot storno storno invoice!'));
1507 if (IS->has_storno(\%myconfig, $form, "ar")) {
1508 $form->error($locale->text("Invoice has already been storno'd!"));
1511 map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
1517 # Payments must not be recorded for the new storno invoice.
1518 $form->{paidaccounts} = 0;
1519 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1521 $form->{storno_id} = $form->{id};
1522 $form->{storno} = 1;
1524 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1525 $form->{rowcount}++;
1528 $lxdebug->leave_sub();
1532 $lxdebug->enter_sub();
1534 $auth->assert('invoice_edit');
1536 $form->{preview} = 1;
1537 $old_form = new Form;
1538 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1540 &print_form($old_form);
1541 $lxdebug->leave_sub();
1546 $lxdebug->enter_sub();
1548 $auth->assert('invoice_edit');
1550 if ($form->{second_run}) {
1551 $form->{print_and_post} = 0;
1558 <form method="post" action="$form->{script}">
1561 # delete action variable
1562 map { delete $form->{$_} } qw(action header);
1564 foreach $key (keys %$form) {
1565 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1566 $form->{$key} =~ s/\"/"/g;
1567 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1571 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1574 . $locale->text('Are you sure you want to delete Invoice Number')
1575 . qq| $form->{invnumber}
1579 <input name="action" class="submit" type="submit" value="|
1580 . $locale->text('Yes') . qq|">
1584 $lxdebug->leave_sub();
1588 $lxdebug->enter_sub();
1590 $auth->assert('invoice_edit');
1592 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1594 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1597 $form->{rowcount}--;
1598 $form->{shipto} = 1;
1601 $form->{title} = $locale->text('Add Credit Note');
1602 $form->{script} = 'is.pl';
1607 # bo creates the id, reset it
1608 map { delete $form->{$_} }
1609 qw(id invnumber subject message cc bcc printed emailed queued);
1610 $form->{ $form->{vc} } =~ s/--.*//g;
1611 $form->{type} = "credit_note";
1614 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1616 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1617 qw(creditlimit creditremaining);
1619 $currency = $form->{currency};
1622 $form->{currency} = $currency;
1623 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
1624 $form->{exchangerate} = $form->{forex} || '';
1626 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1633 $lxdebug->leave_sub();
1637 $lxdebug->enter_sub();
1639 $auth->assert('invoice_edit');
1641 if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
1642 # saving the history
1643 if(!exists $form->{addition}) {
1644 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1645 $form->{addition} = "DELETED";
1646 $form->save_history($form->dbconnect(\%myconfig));
1648 # /saving the history
1649 $form->redirect($locale->text('Invoice deleted!'));
1651 $form->error($locale->text('Cannot delete invoice!'));
1653 $lxdebug->leave_sub();
1657 $lxdebug->enter_sub();
1659 $auth->assert('invoice_edit');
1664 my $saved_form = save_form();
1668 restore_form($saved_form, 0, qw(id invnumber));
1673 $lxdebug->leave_sub();