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 convert_from_do_ids convert_from_oe_ids),
619 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
621 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
625 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
626 <input type="hidden" name="follow_up_trans_type_1" value="sales_invoice">
627 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
628 <input type="hidden" name="follow_up_rowcount" value="1">
630 <input type="hidden" name="lizenzen" value="$lizenzen">
632 <div class="listtop" width="100%">$form->{title}</div>
640 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">
641 <input type="hidden" name="customer_id" value="$form->{customer_id}">
642 <input type="hidden" name="oldcustomer" value="$form->{oldcustomer}">
643 <input type="hidden" name="selectcustomer" value="$form->{selectcustomer}">
648 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
649 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
654 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
655 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
656 <input type="hidden" name="selectAR" value="$form->{selectAR}">
662 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
663 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
667 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
669 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
672 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
673 <td colspan="3"><input name="shipvia" size="35" value="$form->{shipvia}"></td>
676 <th align="right">| . $locale->text('Transaction description') . qq|</th>
677 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
684 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
686 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
687 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
691 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
693 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
694 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
701 <td align="right" valign="top">
706 if ($form->{type} eq "credit_note") {
708 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
709 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
712 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
717 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
718 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
721 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
725 <th align="right">| . $locale->text('Due Date') . qq|</th>
729 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
734 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
735 <td><input name="ordnumber" size="11" value="$form->{ordnumber}"></td>
738 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
739 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
740 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
743 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
744 <td><input name="quonumber" size="11" value="$form->{quonumber}"></td>
747 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
748 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
749 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
752 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
753 <td><input name="cusordnumber" size="11" value="$form->{cusordnumber}"></td>
756 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
757 <td>$globalprojectnumber</td>
771 print qq|<input type="hidden" name="webdav" value="$webdav">|;
773 $lxdebug->leave_sub();
777 $lxdebug->enter_sub();
779 $auth->assert('invoice_edit');
781 $form->{invtotal} = $form->{invsubtotal};
783 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
786 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
789 $rows = ($rows > $introws) ? $rows : $introws;
791 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
793 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
795 $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
798 if ($form->{taxaccounts}) {
800 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
801 . $locale->text('Tax Included') . qq|</b><br><br>|;
804 if (!$form->{taxincluded}) {
806 foreach $item (split / /, $form->{taxaccounts}) {
807 if ($form->{"${item}_base"}) {
808 $form->{"${item}_total"} =
810 $form->{"${item}_base"} * $form->{"${item}_rate"},
812 $form->{invtotal} += $form->{"${item}_total"};
813 $form->{"${item}_total"} =
814 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
818 <th align="right">$form->{"${item}_description"} |
819 . $form->{"${item}_rate"} * 100 .qq|%</th>
820 <td align="right">$form->{"${item}_total"}</td>
826 $form->{invsubtotal} =
827 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
831 <th align="right">| . $locale->text('Subtotal') . qq|</th>
832 <td align="right">$form->{invsubtotal}</td>
838 if ($form->{taxincluded}) {
839 foreach $item (split / /, $form->{taxaccounts}) {
840 if ($form->{"${item}_base"}) {
841 $form->{"${item}_total"} =
843 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
844 (1 + $form->{"${item}_rate"})
847 $form->{"${item}_netto"} =
849 ($form->{"${item}_base"} - $form->{"${item}_total"}),
851 $form->{"${item}_total"} =
852 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
853 $form->{"${item}_netto"} =
854 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
858 <th align="right">Enthaltene $form->{"${item}_description"} |
859 . $form->{"${item}_rate"} * 100 .qq|%</th>
860 <td align="right">$form->{"${item}_total"}</td>
863 <th align="right">Nettobetrag</th>
864 <td align="right">$form->{"${item}_netto"}</td>
872 $form->{oldinvtotal} = $form->{invtotal};
874 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
876 my $follow_ups_block;
878 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
880 if (@{ $follow_ups} ) {
881 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
882 $follow_ups_block = qq|
884 <td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
898 <th align="left">| . $locale->text('Notes') . qq|</th>
899 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
900 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
905 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
914 <th align=left>| . $locale->text('Ertrag') . qq|</th>
915 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
918 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
919 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
921 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
922 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
931 <th align="right">| . $locale->text('Total') . qq|</th>
932 <td align="right">$form->{invtotal}</td>
944 <td><hr size="3" noshade></td>
947 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
950 <td align="left" width="30%"><b>Dateiname</b></td>
951 <td align="left" width="70%"><b>Webdavlink</b></td>
953 foreach $file (@{ $form->{WEBDAV} }) {
956 <td align="left">$file->{name}</td>
957 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
968 if ($form->{type} eq "credit_note") {
973 <tr class="listheading">
974 <th colspan="6" class="listheading">|
975 . $locale->text('Payments') . qq|</th>
983 <tr class="listheading">
984 <th colspan="6" class="listheading">|
985 . $locale->text('Incoming Payments') . qq|</th>
990 if ($form->{currency} eq $form->{defaultcurrency}) {
991 @column_index = qw(datepaid source memo paid AR_paid);
993 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
996 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
997 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
998 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
999 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
1000 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
1001 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
1006 map { print "$column_data{$_}\n" } @column_index;
1014 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1015 for $i (1 .. $form->{paidaccounts}) {
1020 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1021 $form->{"selectAR_paid_$i"} =~
1022 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1025 $totalpaid += $form->{"paid_$i"};
1026 if ($form->{"paid_$i"}) {
1027 $form->{"paid_$i"} =
1028 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1030 $form->{"exchangerate_$i"} =
1031 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1033 if ($form->{"exchangerate_$i"} == 0) {
1034 $form->{"exchangerate_$i"} = "";
1036 $exchangerate = qq| |;
1037 if ($form->{currency} ne $form->{defaultcurrency}) {
1038 if ($form->{"forex_$i"}) {
1039 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1041 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1045 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1047 $column_data{"paid_$i"} =
1048 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
1049 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1050 $column_data{"AR_paid_$i"} =
1051 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1052 $column_data{"datepaid_$i"} =
1053 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)\">
1054 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1055 $column_data{"source_$i"} =
1056 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1057 $column_data{"memo_$i"} =
1058 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1060 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1063 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1066 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
1072 <td align="center">| . $locale->text('Total') . qq|</td>
1073 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
1078 <td align="center">| . $locale->text('Missing amount') . qq|</td>
1079 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
1083 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1084 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1089 <td><hr size="3" noshade></td>
1103 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1104 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1107 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
1110 <input class="submit" type="submit" accesskey="u" 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('Print') . qq|">
1116 <input class="submit" type="submit" name="action" value="|
1117 . $locale->text('E-mail') . qq|"> |;
1118 print qq|<input class="submit" type="submit" name="action" value="|
1119 . $locale->text('Storno') . qq|"> | if ($show_storno);
1120 print qq|<input class="submit" type="submit" name="action" value="|
1121 . $locale->text('Post Payment') . qq|">
1123 print qq|<input class="submit" type="submit" name="action" value="|
1124 . $locale->text('Use As Template') . qq|">
1126 if ($form->{id} && !($form->{type} eq "credit_note")) {
1128 <input class="submit" type="submit" name="action" value="|
1129 . $locale->text('Credit Note') . qq|">
1132 if ($form->{radier}) {
1134 <input class="submit" type="submit" name="action" value="|
1135 . $locale->text('Delete') . qq|">
1140 if ($invdate > $closedto) {
1142 <input class="submit" type="submit" name="action" value="|
1143 . $locale->text('Order') . qq|">
1148 <input type="button" class="submit" onclick="follow_up_window()" value="|
1149 . $locale->text('Follow-Up')
1153 if ($invdate > $closedto) {
1154 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1155 . $locale->text('Update') . qq|">
1156 <input class="submit" type="submit" name="action" value="|
1157 . $locale->text('Ship to') . qq|">
1158 <input class="submit" type="submit" name="action" value="|
1159 . $locale->text('Preview') . qq|">
1160 <input class="submit" type="submit" name="action" value="|
1161 . $locale->text('E-mail') . qq|">
1162 <input class="submit" type="submit" name="action" value="|
1163 . $locale->text('Print and Post') . qq|">
1164 <input class="submit" type="submit" name="action" value="|
1165 . $locale->text('Post') . qq|"> | .
1166 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1167 '-class' => 'submit'));
1171 # button for saving history
1172 if($form->{id} ne "") {
1174 <input type="button" class="submit" onclick="set_history_window(|
1176 . qq|);" name="history" id="history" value="|
1177 . $locale->text('history')
1180 # /button for saving history
1182 # mark_as_paid button
1183 if($form->{id} ne "") {
1184 print qq|<input type="submit" class="submit" name="action" value="|
1185 . $locale->text('mark as paid') . qq|">|;
1187 # /mark_as_paid button
1188 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1191 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1193 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1194 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1195 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
1204 $lxdebug->leave_sub();
1208 $lxdebug->enter_sub();
1210 $auth->assert('invoice_edit');
1212 &mark_as_paid_common(\%myconfig,"ar");
1214 $lxdebug->leave_sub();
1218 $lxdebug->enter_sub();
1220 $auth->assert('invoice_edit');
1222 my ($recursive_call) = shift;
1224 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
1226 $form->{print_and_post} = 0 if $form->{second_run};
1227 $taxincluded = "checked" if $form->{taxincluded};
1228 $form->{update} = 1;
1230 &check_name(customer);
1232 $form->{taxincluded} ||= $taxincluded;
1234 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1235 $form->{exchangerate} = $form->{forex} if $form->{forex};
1237 for $i (1 .. $form->{paidaccounts}) {
1238 next unless $form->{"paid_$i"};
1239 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1240 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1241 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1244 $i = $form->{rowcount};
1245 $exchangerate = $form->{exchangerate} || 1;
1247 # if last row empty, check the form otherwise retrieve new item
1248 if ( ($form->{"partnumber_$i"} eq "")
1249 && ($form->{"description_$i"} eq "")
1250 && ($form->{"partsgroup_$i"} eq "")) {
1252 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1257 IS->retrieve_item(\%myconfig, \%$form);
1259 $rows = scalar @{ $form->{item_list} };
1261 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
1264 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1273 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1275 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1276 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1278 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1279 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1281 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1283 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1284 $decimalplaces = max 2, length $1;
1287 $form->{"sellprice_$i"} = $sellprice;
1289 # if there is an exchange rate adjust sellprice
1290 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1291 $form->{"sellprice_$i"} /= $exchangerate;
1294 $form->{"listprice_$i"} /= $exchangerate;
1296 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1297 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1298 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1299 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1301 $form->{creditremaining} -= $amount;
1303 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
1305 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1308 if ($form->{"inventory_accno_$i"} ne "") {
1309 $form->{"lizenzen_$i"} = qq|<option></option>|;
1310 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1311 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1313 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
1317 # get pricegroups for parts
1318 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1320 # build up html code for prices_$i
1321 &set_pricegroup($i);
1328 # ok, so this is a new part
1329 # ask if it is a part or service item
1331 if ( $form->{"partsgroup_$i"}
1332 && ($form->{"partsnumber_$i"} eq "")
1333 && ($form->{"description_$i"} eq "")) {
1334 $form->{rowcount}--;
1335 $form->{"discount_$i"} = "";
1339 $form->{"id_$i"} = 0;
1344 $lxdebug->leave_sub();
1348 $lxdebug->enter_sub();
1350 $auth->assert('invoice_edit');
1352 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1353 for $i (1 .. $form->{paidaccounts}) {
1354 if ($form->{"paid_$i"}) {
1355 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1357 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1359 $form->error($locale->text('Cannot post payment for a closed period!'))
1360 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1362 if ($form->{currency} ne $form->{defaultcurrency}) {
1363 $form->{"exchangerate_$i"} = $form->{exchangerate}
1364 if ($invdate == $datepaid);
1365 $form->isblank("exchangerate_$i",
1366 $locale->text('Exchangerate for payment missing!'));
1371 ($form->{AR}) = split /--/, $form->{AR};
1372 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1374 $form->redirect($locale->text('Payment posted!'))
1375 if (IS->post_payment(\%myconfig, \%$form));
1376 $form->error($locale->text('Cannot post payment!'));
1379 $lxdebug->leave_sub();
1383 $lxdebug->enter_sub();
1385 $auth->assert('invoice_edit');
1387 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1388 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1389 $form->isblank("customer", $locale->text('Customer missing!'));
1390 $form->error($locale->text('Cannot post invoice for a closed period!'))
1391 if ($form->date_closed($form->{"invdate"}, \%myconfig));
1393 $form->{invnumber} =~ s/^\s*//g;
1394 $form->{invnumber} =~ s/\s*$//g;
1396 # if oldcustomer ne customer redo form
1397 if (&check_name(customer)) {
1401 if ($form->{second_run}) {
1402 $form->{print_and_post} = 0;
1407 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1408 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1410 $form->error($locale->text('Cannot post invoice for a closed period!'))
1411 if ($invdate <= $closedto);
1413 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1414 if ($form->{currency} ne $form->{defaultcurrency});
1416 for $i (1 .. $form->{paidaccounts}) {
1417 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1418 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1420 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1422 $form->error($locale->text('Cannot post payment for a closed period!'))
1423 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1425 if ($form->{currency} ne $form->{defaultcurrency}) {
1426 $form->{"exchangerate_$i"} = $form->{exchangerate}
1427 if ($invdate == $datepaid);
1428 $form->isblank("exchangerate_$i",
1429 $locale->text('Exchangerate for payment missing!'));
1434 ($form->{AR}) = split /--/, $form->{AR};
1435 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1436 $form->{storno} ||= 0;
1438 $form->{label} = $locale->text('Invoice');
1440 $form->{id} = 0 if $form->{postasnew};
1442 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1443 if ($form->{postasnew}) {
1444 if ($form->{type} eq "credit_note") {
1445 undef($form->{cnnumber});
1447 undef($form->{invnumber});
1452 $form->error($locale->text('Cannot post invoice!'))
1453 unless IS->post_invoice(\%myconfig, \%$form);
1454 remove_draft() if $form->{remove_draft};
1456 if(!exists $form->{addition}) {
1457 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1458 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1459 $form->{storno} ? "STORNO" :
1461 $form->save_history($form->dbconnect(\%myconfig));
1464 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1467 $lxdebug->leave_sub();
1470 sub print_and_post {
1471 $lxdebug->enter_sub();
1473 $auth->assert('invoice_edit');
1475 $old_form = new Form;
1477 $form->{print_and_post} = 1;
1481 $lxdebug->leave_sub();
1485 sub use_as_template {
1486 $lxdebug->enter_sub();
1488 $auth->assert('invoice_edit');
1490 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);
1491 $form->{paidaccounts} = 1;
1492 $form->{rowcount}--;
1493 $form->{invdate} = $form->current_date(\%myconfig);
1496 $lxdebug->leave_sub();
1500 $lxdebug->enter_sub();
1502 $auth->assert('invoice_edit');
1504 if ($form->{storno}) {
1505 $form->error($locale->text('Cannot storno storno invoice!'));
1508 if (IS->has_storno(\%myconfig, $form, "ar")) {
1509 $form->error($locale->text("Invoice has already been storno'd!"));
1512 map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
1518 # Payments must not be recorded for the new storno invoice.
1519 $form->{paidaccounts} = 0;
1520 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1522 $form->{storno_id} = $form->{id};
1523 $form->{storno} = 1;
1525 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1526 $form->{rowcount}++;
1529 $lxdebug->leave_sub();
1533 $lxdebug->enter_sub();
1535 $auth->assert('invoice_edit');
1537 $form->{preview} = 1;
1538 $old_form = new Form;
1539 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1541 &print_form($old_form);
1542 $lxdebug->leave_sub();
1547 $lxdebug->enter_sub();
1549 $auth->assert('invoice_edit');
1551 if ($form->{second_run}) {
1552 $form->{print_and_post} = 0;
1559 <form method="post" action="$form->{script}">
1562 # delete action variable
1563 map { delete $form->{$_} } qw(action header);
1565 foreach $key (keys %$form) {
1566 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1567 $form->{$key} =~ s/\"/"/g;
1568 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1572 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1575 . $locale->text('Are you sure you want to delete Invoice Number')
1576 . qq| $form->{invnumber}
1580 <input name="action" class="submit" type="submit" value="|
1581 . $locale->text('Yes') . qq|">
1585 $lxdebug->leave_sub();
1589 $lxdebug->enter_sub();
1591 $auth->assert('invoice_edit');
1593 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1595 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1598 $form->{rowcount}--;
1599 $form->{shipto} = 1;
1602 $form->{title} = $locale->text('Add Credit Note');
1603 $form->{script} = 'is.pl';
1608 # bo creates the id, reset it
1609 map { delete $form->{$_} }
1610 qw(id invnumber subject message cc bcc printed emailed queued);
1611 $form->{ $form->{vc} } =~ s/--.*//g;
1612 $form->{type} = "credit_note";
1615 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1617 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1618 qw(creditlimit creditremaining);
1620 $currency = $form->{currency};
1623 $form->{currency} = $currency;
1624 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
1625 $form->{exchangerate} = $form->{forex} || '';
1627 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1634 $lxdebug->leave_sub();
1638 $lxdebug->enter_sub();
1640 $auth->assert('invoice_edit');
1642 if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
1643 # saving the history
1644 if(!exists $form->{addition}) {
1645 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1646 $form->{addition} = "DELETED";
1647 $form->save_history($form->dbconnect(\%myconfig));
1649 # /saving the history
1650 $form->redirect($locale->text('Invoice deleted!'));
1652 $form->error($locale->text('Cannot delete invoice!'));
1654 $lxdebug->leave_sub();
1658 $lxdebug->enter_sub();
1660 $auth->assert('invoice_edit');
1665 my $saved_form = save_form();
1669 restore_form($saved_form, 0, qw(id invnumber));
1674 $lxdebug->leave_sub();