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";
244 # # get pricegroups for parts
245 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
249 foreach $ref (@{ $form->{invoice_details} }) {
252 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
253 $form->{"discount_$i"} =
254 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
255 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
257 $decimalplaces = ($dec > 2) ? $dec : 2;
259 $form->{"sellprice_$i"} =
260 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
263 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
264 $dec_qty = length $dec_qty;
267 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
269 $form->{rowcount} = $i;
273 $lxdebug->leave_sub();
277 $lxdebug->enter_sub();
279 $auth->assert('invoice_edit');
281 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
282 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
285 if ($form->{type} eq "credit_note") {
286 $form->{title} = $locale->text('Edit Credit Note');
287 $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
289 $form->{title} = $locale->text('Edit Sales Invoice');
290 $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
293 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
294 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
296 $payment = qq|<option value=""></option>|;
297 foreach $item (@{ $form->{payment_terms} }) {
298 if ($form->{payment_id} eq $item->{id}) {
299 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
301 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
305 my $set_duedate_url = "$form->{script}?action=set_duedate";
307 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
308 push(@ { $form->{AJAX} }, $pjx);
310 my @old_project_ids = ($form->{"globalproject_id"});
311 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
313 $form->get_lists("contacts" => "ALL_CONTACTS",
314 "shipto" => "ALL_SHIPTO",
315 "projects" => { "key" => "ALL_PROJECTS",
317 "old_id" => \@old_project_ids },
318 "employees" => "ALL_SALESMEN",
319 "taxzones" => "ALL_TAXZONES",
320 "currencies" => "ALL_CURRENCIES",
321 "customers" => "ALL_CUSTOMERS",
322 "price_factors" => "ALL_PRICE_FACTORS");
325 my @values = (undef);
326 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
327 push(@values, $item->{"cp_id"});
328 $labels{$item->{"cp_id"}} = join(',', $item->{"cp_name"}, $item->{"cp_givenname"}) . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
331 if (scalar @values > 1) {
334 <th align="right">| . $locale->text('Contact Person') . qq|</th>
335 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
336 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
343 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
344 push(@values, $item->{"id"});
345 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
350 <th align="right">| . $locale->text('Employee') . qq|</th>
351 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
352 '-values' => \@values, '-labels' => \%labels)) . qq|
357 $form->{selectcustomer} = $myconfig{vclimit} > scalar(@{ $form->{ALL_CUSTOMERS} });
360 <th align="right">| . $locale->text('Customer') . qq|</th>
362 . $form->parse_html_template('generic/multibox',
363 { 'name' => 'customer',
364 'style' => 'width: 250px',
365 'DATA' => $form->{ALL_CUSTOMERS},
366 'id_sub' => 'vc_keys',
367 'vc_keys' => sub { "$_[0]->{name}--$_[0]->{id}" },
368 'label_key' => 'name',
369 'select' => 'customer_or_vendor_selection_window(\'customer\', \'\', 0, 0);',
370 'limit' => $myconfig{vclimit},
371 'allow_textbox' => 1,
372 'onChange' => "document.getElementById('update_button').click();" })
373 . qq| <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')"></td>|;
377 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
378 push(@values, $item->{"shipto_id"});
379 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
383 if (scalar @values > 1) {
386 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
387 <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
388 '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
394 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
395 push(@values, $item);
396 $labels{$item} = $item;
399 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
401 if (scalar @values) {
404 <th align="right">| . $locale->text('Currency') . qq|</th>
405 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
406 '-values' => \@values, '-labels' => \%labels)) . qq|
413 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
414 push(@values, $item->{"id"});
415 $labels{$item->{"id"}} = $item->{"projectnumber"};
417 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
418 '-labels' => \%labels,
419 '-default' => $form->{"globalproject_id"}));
423 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
424 push(@values, $item->{id});
425 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
429 qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
430 <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
431 '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
437 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
438 push(@values, $item->{"id"});
439 $labels{$item->{"id"}} = $item->{"description"};
442 if (!$form->{"id"}) {
445 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
446 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
447 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
454 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
456 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
457 | . H($labels{$form->{"taxzone_id"}}) . qq|
462 # set option selected
463 foreach $item (qw(AR customer currency department employee)) {
464 $form->{"select$item"} =~ s/ selected//;
465 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
468 $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
470 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
471 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
472 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
475 if ($form->{currency} ne $form->{defaultcurrency}) {
476 if ($form->{forex}) {
477 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
478 <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
480 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
481 <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
484 $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
488 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
489 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
490 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
493 | if $form->{selectdepartment};
495 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
497 if ($form->{business}) {
500 <th align="right">| . $locale->text('Customer type') . qq|</th>
501 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
502 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
508 if ($form->{max_dunning_level}) {
511 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
513 <b>$form->{max_dunning_level}</b>;
514 | . $locale->text('Dunning Amount') . qq|: <b>|
515 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
522 $form->{fokus} = "invoice.customer";
524 # use JavaScript Calendar or not
525 $form->{jsscript} = 1;
527 if ($form->{type} eq "credit_note") {
529 <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
530 <input type="button" name="invdate_button" id="trigger1" value="|
531 . $locale->text('button') . qq|"></td>|;
535 Form->write_trigger(\%myconfig, "1",
540 <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
541 <input type="button" name="invdate_button" id="trigger1" value="|
542 . $locale->text('button') . qq|"></td>
545 <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
546 <input type="button" name="duedate_button" id="trigger2" value="|
547 . $locale->text('button') . qq|"></td>
550 <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
551 <input type="button" name="deliverydate_button" id="trigger3" value="|
552 . $locale->text('button') . qq|"></td>
557 Form->write_trigger(\%myconfig, "3",
558 "invdate", "BL", "trigger1",
559 "duedate", "BL", "trigger2",
560 "deliverydate", "BL", "trigger3");
563 $credittext = $locale->text('Credit Limit exceeded!!!');
565 my $follow_up_vc = $form->{customer};
566 $follow_up_vc =~ s/--\d*\s*$//;
567 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
569 $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
570 : ($form->{resubmit}) ? qq|document.invoice.submit()|
571 : ($creditwarning) ? qq|alert('$credittext')|
573 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
574 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
576 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
577 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
580 $form->write_trigger(\%myconfig, 2,
581 "orddate", "BL", "trigger_orddate",
582 "quodate", "BL", "trigger_quodate");
583 # show history button js
584 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
585 #/show history button js
589 <body onLoad="$onload">
590 <script type="text/javascript" src="js/common.js"></script>
591 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
592 <script type="text/javascript" src="js/customer_or_vendor_selection.js"></script>
593 <script type="text/javascript" src="js/calculate_qty.js"></script>
594 <script type="text/javascript" src="js/follow_up.js"></script>
596 <form method="post" name="invoice" action="$form->{script}">
599 $form->hide_form(qw(id action type media format queued printed emailed title vc discount
600 creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
601 max_dunning_level dunning_amount
602 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
603 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
604 convert_from_do_ids convert_from_oe_ids),
605 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
607 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
611 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
612 <input type="hidden" name="follow_up_trans_type_1" value="sales_invoice">
613 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
614 <input type="hidden" name="follow_up_rowcount" value="1">
616 <input type="hidden" name="lizenzen" value="$lizenzen">
618 <div class="listtop" width="100%">$form->{title}</div>
626 <input type="hidden" name="customer_klass" value="| . H($form->{customer_klass}) . qq|">
627 <input type="hidden" name="customer_id" value="| . H($form->{customer_id}) . qq|">
628 <input type="hidden" name="oldcustomer" value="| . H($form->{oldcustomer}) . qq|">
629 <input type="hidden" name="selectcustomer" value="| . H($form->{selectcustomer}) . qq|">
634 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
635 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
640 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
641 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
642 <input type="hidden" name="selectAR" value="$form->{selectAR}">
648 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
649 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
653 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
655 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
659 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
661 $cgi->textfield("-name" => "shipvia", "-size" => 35, "-value" => $form->{shipvia}) .
665 <th align="right">| . $locale->text('Transaction description') . qq|</th>
666 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
673 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
675 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
676 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
680 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
682 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
683 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
690 <td align="right" valign="top">
696 #ergänzung in der maske um das feld Lieferscheinnummer (Delivery Order Number), meiner meinung nach sinnvoll ueber dem feld lieferscheindatum 12.02.2009 jb
697 if ($form->{type} eq "credit_note") {
699 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
701 $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .
705 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
710 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
712 $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .
716 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
720 <th align="right">| . $locale->text('Due Date') . qq|</th>
724 <th align="right" nowrap>| . $locale->text('Delivery Order Number') . qq|</th>
726 $cgi->textfield("-name" => "donumber", "-size" => 11, "-value" => $form->{donumber}) .
730 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
735 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
737 $cgi->textfield("-name" => "ordnumber", "-size" => 11, "-value" => $form->{ordnumber}) .
741 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
742 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
743 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
746 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
748 $cgi->textfield("-name" => "quonumber", "-size" => 11, "-value" => $form->{quonumber}) .
752 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
753 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
754 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
757 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
759 $cgi->textfield("-name" => "cusordnumber", "-size" => 11, "-value" => $form->{cusordnumber}) .
763 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
764 <td>$globalprojectnumber</td>
778 print qq|<input type="hidden" name="webdav" value="$webdav">|;
780 $lxdebug->leave_sub();
784 $lxdebug->enter_sub();
786 $auth->assert('invoice_edit');
788 $form->{invtotal} = $form->{invsubtotal};
790 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
793 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
796 $rows = ($rows > $introws) ? $rows : $introws;
798 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
800 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
802 $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
805 if ($form->{taxaccounts}) {
807 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
808 . $locale->text('Tax Included') . qq|</b><br><br>|;
811 if (!$form->{taxincluded}) {
813 foreach $item (split / /, $form->{taxaccounts}) {
814 if ($form->{"${item}_base"}) {
815 $form->{"${item}_total"} =
817 $form->{"${item}_base"} * $form->{"${item}_rate"},
819 $form->{invtotal} += $form->{"${item}_total"};
820 $form->{"${item}_total"} =
821 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
825 <th align="right">$form->{"${item}_description"} |
826 . $form->{"${item}_rate"} * 100 .qq|%</th>
827 <td align="right">$form->{"${item}_total"}</td>
833 $form->{invsubtotal} =
834 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
838 <th align="right">| . $locale->text('Subtotal') . qq|</th>
839 <td align="right">$form->{invsubtotal}</td>
845 if ($form->{taxincluded}) {
846 foreach $item (split / /, $form->{taxaccounts}) {
847 if ($form->{"${item}_base"}) {
848 $form->{"${item}_total"} =
850 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
851 (1 + $form->{"${item}_rate"})
854 $form->{"${item}_netto"} =
856 ($form->{"${item}_base"} - $form->{"${item}_total"}),
858 $form->{"${item}_total"} =
859 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
860 $form->{"${item}_netto"} =
861 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
865 <th align="right">Enthaltene $form->{"${item}_description"} |
866 . $form->{"${item}_rate"} * 100 .qq|%</th>
867 <td align="right">$form->{"${item}_total"}</td>
870 <th align="right">Nettobetrag</th>
871 <td align="right">$form->{"${item}_netto"}</td>
879 $form->{oldinvtotal} = $form->{invtotal};
881 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
883 my $follow_ups_block;
885 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
887 if (@{ $follow_ups} ) {
888 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
889 $follow_ups_block = qq|
891 <td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
905 <th align="left">| . $locale->text('Notes') . qq|</th>
906 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
907 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
912 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value, 'invdate__' + invdate.value],['duedate'])">$payment
921 <th align=left>| . $locale->text('Ertrag') . qq|</th>
922 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
925 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
926 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
928 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
929 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
938 <th align="right">| . $locale->text('Total') . qq|</th>
939 <td align="right">$form->{invtotal}</td>
951 <td><hr size="3" noshade></td>
954 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
957 <td align="left" width="30%"><b>Dateiname</b></td>
958 <td align="left" width="70%"><b>Webdavlink</b></td>
960 foreach $file (@{ $form->{WEBDAV} }) {
963 <td align="left">$file->{name}</td>
964 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
975 if ($form->{type} eq "credit_note") {
980 <tr class="listheading">
981 <th colspan="6" class="listheading">|
982 . $locale->text('Payments') . qq|</th>
990 <tr class="listheading">
991 <th colspan="6" class="listheading">|
992 . $locale->text('Incoming Payments') . qq|</th>
997 if ($form->{currency} eq $form->{defaultcurrency}) {
998 @column_index = qw(datepaid source memo paid AR_paid);
1000 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
1003 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
1004 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
1005 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
1006 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
1007 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
1008 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
1013 map { print "$column_data{$_}\n" } @column_index;
1021 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1022 for $i (1 .. $form->{paidaccounts}) {
1027 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1028 $form->{"selectAR_paid_$i"} =~
1029 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1032 $totalpaid += $form->{"paid_$i"};
1033 if ($form->{"paid_$i"}) {
1034 $form->{"paid_$i"} =
1035 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1037 $form->{"exchangerate_$i"} =
1038 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1040 if ($form->{"exchangerate_$i"} == 0) {
1041 $form->{"exchangerate_$i"} = "";
1043 $exchangerate = qq| |;
1044 if ($form->{currency} ne $form->{defaultcurrency}) {
1045 if ($form->{"forex_$i"}) {
1046 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1048 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1052 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1054 $column_data{"paid_$i"} =
1055 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
1056 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1057 $column_data{"AR_paid_$i"} =
1058 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1059 $column_data{"datepaid_$i"} =
1060 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)\">
1061 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1062 $column_data{"source_$i"} =
1063 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1064 $column_data{"memo_$i"} =
1065 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1067 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1070 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1073 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
1079 <td align="center">| . $locale->text('Total') . qq|</td>
1080 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
1085 <td align="center">| . $locale->text('Missing amount') . qq|</td>
1086 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
1090 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1091 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1096 <td><hr size="3" noshade></td>
1110 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1111 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1114 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar") && (($totalpaid == 0) || ($totalpaid eq ""));
1117 <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
1118 . $locale->text('Update') . qq|">
1119 <input class="submit" type="submit" name="action" value="|
1120 . $locale->text('Ship to') . qq|">
1121 <input class="submit" type="submit" name="action" value="|
1122 . $locale->text('Print') . qq|">
1123 <input class="submit" type="submit" name="action" value="|
1124 . $locale->text('E-mail') . qq|"> |;
1125 print qq|<input class="submit" type="submit" name="action" value="|
1126 . $locale->text('Storno') . qq|"> | if ($show_storno);
1127 print qq|<input class="submit" type="submit" name="action" value="|
1128 . $locale->text('Post Payment') . qq|">
1130 print qq|<input class="submit" type="submit" name="action" value="|
1131 . $locale->text('Use As Template') . qq|">
1133 if ($form->{id} && !($form->{type} eq "credit_note")) {
1135 <input class="submit" type="submit" name="action" value="|
1136 . $locale->text('Credit Note') . qq|">
1139 if ($form->{radier}) {
1141 <input class="submit" type="submit" name="action" value="|
1142 . $locale->text('Delete') . qq|">
1147 if ($invdate > $closedto) {
1149 <input class="submit" type="submit" name="action" value="|
1150 . $locale->text('Order') . qq|">
1155 <input type="button" class="submit" onclick="follow_up_window()" value="|
1156 . $locale->text('Follow-Up')
1160 if ($invdate > $closedto) {
1161 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1162 . $locale->text('Update') . qq|">
1163 <input class="submit" type="submit" name="action" value="|
1164 . $locale->text('Ship to') . qq|">
1165 <input class="submit" type="submit" name="action" value="|
1166 . $locale->text('Preview') . qq|">
1167 <input class="submit" type="submit" name="action" value="|
1168 . $locale->text('E-mail') . qq|">
1169 <input class="submit" type="submit" name="action" value="|
1170 . $locale->text('Print and Post') . qq|">
1171 <input class="submit" type="submit" name="action" value="|
1172 . $locale->text('Post') . qq|"> | .
1173 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1174 '-class' => 'submit'));
1178 # button for saving history
1179 if($form->{id} ne "") {
1181 <input type="button" class="submit" onclick="set_history_window(|
1183 . qq|);" name="history" id="history" value="|
1184 . $locale->text('history')
1187 # /button for saving history
1189 # mark_as_paid button
1190 if($form->{id} ne "") {
1191 print qq|<input type="submit" class="submit" name="action" value="|
1192 . $locale->text('mark as paid') . qq|">|;
1194 # /mark_as_paid button
1195 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1198 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1200 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1201 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1202 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
1203 . $cgi->hidden('-name' => 'customer_discount', '-value' => [$form->{customer_discount}])
1212 $lxdebug->leave_sub();
1216 $lxdebug->enter_sub();
1218 $auth->assert('invoice_edit');
1220 &mark_as_paid_common(\%myconfig,"ar");
1222 $lxdebug->leave_sub();
1226 $lxdebug->enter_sub();
1228 $auth->assert('invoice_edit');
1230 my ($recursive_call) = shift;
1232 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
1234 $form->{print_and_post} = 0 if $form->{second_run};
1235 $taxincluded = "checked" if $form->{taxincluded};
1236 $form->{update} = 1;
1238 &check_name(customer);
1240 $form->{taxincluded} ||= $taxincluded;
1242 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1243 $form->{exchangerate} = $form->{forex} if $form->{forex};
1245 for $i (1 .. $form->{paidaccounts}) {
1246 next unless $form->{"paid_$i"};
1247 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1248 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1249 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1252 $i = $form->{rowcount};
1253 $exchangerate = $form->{exchangerate} || 1;
1255 # if last row empty, check the form otherwise retrieve new item
1256 if ( ($form->{"partnumber_$i"} eq "")
1257 && ($form->{"description_$i"} eq "")
1258 && ($form->{"partsgroup_$i"} eq "")) {
1260 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1265 IS->retrieve_item(\%myconfig, \%$form);
1267 $rows = scalar @{ $form->{item_list} };
1269 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{customer_discount} * 100);
1272 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1281 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1283 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1284 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1286 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1287 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1289 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1291 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1292 $decimalplaces = max 2, length $1;
1295 $form->{"sellprice_$i"} = $sellprice;
1297 # if there is an exchange rate adjust sellprice
1298 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1299 $form->{"sellprice_$i"} /= $exchangerate;
1302 $form->{"listprice_$i"} /= $exchangerate;
1304 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1305 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1306 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1307 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1309 $form->{creditremaining} -= $amount;
1311 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
1313 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1316 if ($form->{"inventory_accno_$i"} ne "") {
1317 $form->{"lizenzen_$i"} = qq|<option></option>|;
1318 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1319 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1321 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
1325 # get pricegroups for parts
1326 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1328 # build up html code for prices_$i
1329 &set_pricegroup($i);
1336 # ok, so this is a new part
1337 # ask if it is a part or service item
1339 if ( $form->{"partsgroup_$i"}
1340 && ($form->{"partsnumber_$i"} eq "")
1341 && ($form->{"description_$i"} eq "")) {
1342 $form->{rowcount}--;
1343 $form->{"discount_$i"} = "";
1347 $form->{"id_$i"} = 0;
1352 $lxdebug->leave_sub();
1356 $lxdebug->enter_sub();
1358 $auth->assert('invoice_edit');
1360 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1361 for $i (1 .. $form->{paidaccounts}) {
1362 if ($form->{"paid_$i"}) {
1363 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1365 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1367 $form->error($locale->text('Cannot post payment for a closed period!'))
1368 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1370 if ($form->{currency} ne $form->{defaultcurrency}) {
1371 $form->{"exchangerate_$i"} = $form->{exchangerate}
1372 if ($invdate == $datepaid);
1373 $form->isblank("exchangerate_$i",
1374 $locale->text('Exchangerate for payment missing!'));
1379 ($form->{AR}) = split /--/, $form->{AR};
1380 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1382 $form->redirect($locale->text('Payment posted!'))
1383 if (IS->post_payment(\%myconfig, \%$form));
1384 $form->error($locale->text('Cannot post payment!'));
1387 $lxdebug->leave_sub();
1391 $lxdebug->enter_sub();
1393 $auth->assert('invoice_edit');
1395 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1396 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1397 $form->isblank("customer", $locale->text('Customer missing!'));
1398 $form->error($locale->text('Cannot post invoice for a closed period!'))
1399 if ($form->date_closed($form->{"invdate"}, \%myconfig));
1401 $form->{invnumber} =~ s/^\s*//g;
1402 $form->{invnumber} =~ s/\s*$//g;
1404 # if oldcustomer ne customer redo form
1405 if (&check_name(customer)) {
1409 if ($form->{second_run}) {
1410 $form->{print_and_post} = 0;
1415 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1416 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1418 $form->error($locale->text('Cannot post invoice for a closed period!'))
1419 if ($invdate <= $closedto);
1421 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1422 if ($form->{currency} ne $form->{defaultcurrency});
1424 for $i (1 .. $form->{paidaccounts}) {
1425 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1426 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1428 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1430 $form->error($locale->text('Cannot post payment for a closed period!'))
1431 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1433 if ($form->{currency} ne $form->{defaultcurrency}) {
1434 $form->{"exchangerate_$i"} = $form->{exchangerate}
1435 if ($invdate == $datepaid);
1436 $form->isblank("exchangerate_$i",
1437 $locale->text('Exchangerate for payment missing!'));
1442 ($form->{AR}) = split /--/, $form->{AR};
1443 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1444 $form->{storno} ||= 0;
1446 $form->{label} = $locale->text('Invoice');
1448 $form->{id} = 0 if $form->{postasnew};
1450 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1451 if ($form->{postasnew}) {
1452 if ($form->{type} eq "credit_note") {
1453 undef($form->{cnnumber});
1455 undef($form->{invnumber});
1460 $form->error($locale->text('Cannot post invoice!'))
1461 unless IS->post_invoice(\%myconfig, \%$form);
1462 remove_draft() if $form->{remove_draft};
1464 if(!exists $form->{addition}) {
1465 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1466 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1467 $form->{storno} ? "STORNO" :
1469 $form->save_history($form->dbconnect(\%myconfig));
1472 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1475 $lxdebug->leave_sub();
1478 sub print_and_post {
1479 $lxdebug->enter_sub();
1481 $auth->assert('invoice_edit');
1483 $old_form = new Form;
1485 $form->{print_and_post} = 1;
1489 $lxdebug->leave_sub();
1493 sub use_as_template {
1494 $lxdebug->enter_sub();
1496 $auth->assert('invoice_edit');
1498 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);
1499 $form->{paidaccounts} = 1;
1500 $form->{rowcount}--;
1501 $form->{invdate} = $form->current_date(\%myconfig);
1504 $lxdebug->leave_sub();
1508 $lxdebug->enter_sub();
1510 $auth->assert('invoice_edit');
1512 if ($form->{storno}) {
1513 $form->error($locale->text('Cannot storno storno invoice!'));
1516 if (IS->has_storno(\%myconfig, $form, "ar")) {
1517 $form->error($locale->text("Invoice has already been storno'd!"));
1520 map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
1526 # Payments must not be recorded for the new storno invoice.
1527 $form->{paidaccounts} = 0;
1528 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1530 $form->{storno_id} = $form->{id};
1531 $form->{storno} = 1;
1533 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1534 $form->{rowcount}++;
1537 $lxdebug->leave_sub();
1541 $lxdebug->enter_sub();
1543 $auth->assert('invoice_edit');
1545 $form->{preview} = 1;
1546 $old_form = new Form;
1547 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1549 &print_form($old_form);
1550 $lxdebug->leave_sub();
1555 $lxdebug->enter_sub();
1557 $auth->assert('invoice_edit');
1559 if ($form->{second_run}) {
1560 $form->{print_and_post} = 0;
1567 <form method="post" action="$form->{script}">
1570 # delete action variable
1571 map { delete $form->{$_} } qw(action header);
1573 foreach $key (keys %$form) {
1574 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1575 $form->{$key} =~ s/\"/"/g;
1576 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1580 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1583 . $locale->text('Are you sure you want to delete Invoice Number')
1584 . qq| $form->{invnumber}
1588 <input name="action" class="submit" type="submit" value="|
1589 . $locale->text('Yes') . qq|">
1593 $lxdebug->leave_sub();
1597 $lxdebug->enter_sub();
1599 $auth->assert('invoice_edit');
1601 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1603 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1606 $form->{rowcount}--;
1607 $form->{shipto} = 1;
1610 $form->{title} = $locale->text('Add Credit Note');
1611 $form->{script} = 'is.pl';
1616 # bo creates the id, reset it
1617 map { delete $form->{$_} }
1618 qw(id invnumber subject message cc bcc printed emailed queued);
1619 $form->{ $form->{vc} } =~ s/--.*//g;
1620 $form->{type} = "credit_note";
1623 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1625 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1626 qw(creditlimit creditremaining);
1628 $currency = $form->{currency};
1631 $form->{currency} = $currency;
1632 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
1633 $form->{exchangerate} = $form->{forex} || '';
1635 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1642 $lxdebug->leave_sub();
1646 $lxdebug->enter_sub();
1648 $auth->assert('invoice_edit');
1650 if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
1651 # saving the history
1652 if(!exists $form->{addition}) {
1653 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1654 $form->{addition} = "DELETED";
1655 $form->save_history($form->dbconnect(\%myconfig));
1657 # /saving the history
1658 $form->redirect($locale->text('Invoice deleted!'));
1660 $form->error($locale->text('Cannot delete invoice!'));
1662 $lxdebug->leave_sub();
1666 $lxdebug->enter_sub();
1668 $auth->assert('invoice_edit');
1673 my $saved_form = save_form();
1677 restore_form($saved_form, 0, qw(id invnumber));
1682 $lxdebug->leave_sub();