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";
56 $main::lxdebug->enter_sub();
58 my $form = $main::form;
59 my $locale = $main::locale;
61 $main::auth->assert('invoice_edit');
63 return $main::lxdebug->leave_sub() if (load_draft_maybe());
65 if ($form->{type} eq "credit_note") {
66 $form->{title} = $locale->text('Add Credit Note');
68 if ($form->{storno}) {
69 $form->{title} = $locale->text('Add Storno Credit Note');
72 $form->{title} = $locale->text('Add Sales Invoice');
77 $form->{callback} = "$form->{script}?action=add&type=$form->{type}" unless $form->{callback};
79 $form->{jsscript} = "date";
85 $main::lxdebug->leave_sub();
89 $main::lxdebug->enter_sub();
91 my $form = $main::form;
93 $main::auth->assert('invoice_edit');
96 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
97 #/show hhistory button
100 my ($language_id, $printer_id);
101 if ($form->{print_and_post}) {
102 $form->{action} = "print";
103 $form->{resubmit} = 1;
104 $language_id = $form->{language_id};
105 $printer_id = $form->{printer_id};
109 if ($form->{print_and_post}) {
110 $form->{language_id} = $language_id;
111 $form->{printer_id} = $printer_id;
116 $main::lxdebug->leave_sub();
120 $main::lxdebug->enter_sub();
122 my $form = $main::form;
123 my %myconfig = %main::myconfig;
125 $main::auth->assert('invoice_edit');
127 $form->{vc} = 'customer';
130 $form->{webdav} = $main::webdav;
131 $form->{lizenzen} = $main::lizenzen;
133 $form->create_links("AR", \%myconfig, "customer");
135 if ($form->{all_customer}) {
136 unless ($form->{customer_id}) {
137 $form->{customer_id} = $form->{all_customer}->[0]->{id};
138 $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
143 if ($form->{payment_id}) {
144 $payment_id = $form->{payment_id};
147 if ($form->{language_id}) {
148 $language_id = $form->{language_id};
151 if ($form->{taxzone_id}) {
152 $taxzone_id = $form->{taxzone_id};
159 if ($form->{shipto_id}) {
160 $shipto_id = $form->{shipto_id};
163 my $cp_id = $form->{cp_id};
164 IS->get_customer(\%myconfig, \%$form);
166 #quote all_customer Bug 133
167 foreach my $ref (@{ $form->{all_customer} }) {
168 $ref->{name} = $form->quote($ref->{name});
173 IS->retrieve_invoice(\%myconfig, \%$form);
174 $form->{cp_id} = $cp_id;
177 $form->{payment_id} = $payment_id;
180 $form->{language_id} = $language_id;
183 $form->{taxzone_id} = $taxzone_id;
186 $form->{shipto_id} = $shipto_id;
189 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
192 if ($form->{all_departments}) {
193 $form->{selectdepartment} = "<option>\n";
194 $form->{department} = "$form->{department}--$form->{department_id}";
197 $form->{selectdepartment} .=
198 "<option>$_->{description}--$_->{id}</option>\n"
199 } (@{ $form->{all_departments} });
202 $form->{employee} = "$form->{employee}--$form->{employee_id}";
205 $form->{forex} = $form->{exchangerate};
206 my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
208 foreach my $key (keys %{ $form->{AR_links} }) {
209 foreach my $ref (@{ $form->{AR_links}{$key} }) {
210 $form->{"select$key"} .=
211 "<option>$ref->{accno}--$ref->{description}</option>\n";
214 if ($key eq "AR_paid") {
215 next unless $form->{acc_trans}{$key};
216 for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
217 $form->{"AR_paid_$i"} =
218 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
221 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
222 $form->{"datepaid_$i"} =
223 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
224 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
225 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
226 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
227 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
229 $form->{paidaccounts} = $i;
233 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
238 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
240 $form->{AR} = $form->{AR_1} unless $form->{id};
243 ($form->datetonum($form->{invdate}, \%myconfig) <=
244 $form->datetonum($form->{closedto}, \%myconfig));
246 $main::lxdebug->leave_sub();
249 sub prepare_invoice {
250 $main::lxdebug->enter_sub();
252 my $form = $main::form;
253 my %myconfig = %main::myconfig;
255 $main::auth->assert('invoice_edit');
257 if ($form->{type} eq "credit_note") {
258 $form->{type} = "credit_note";
259 $form->{formname} = "credit_note";
261 $form->{type} = "invoice";
262 $form->{formname} = "invoice";
269 foreach my $ref (@{ $form->{invoice_details} }) {
272 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
274 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
275 my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
277 my $decimalplaces = ($dec > 2) ? $dec : 2;
279 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
280 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
281 $dec_qty = length $dec_qty;
283 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
285 $form->{rowcount} = $i;
289 # get pricegroups for parts
290 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
291 set_pricegroup($_) for 1 .. $form->{rowcount};
293 $main::lxdebug->leave_sub();
297 $main::lxdebug->enter_sub();
299 my $form = $main::form;
300 my %myconfig = %main::myconfig;
301 my $locale = $main::locale;
302 my $cgi = $main::cgi;
304 $main::auth->assert('invoice_edit');
306 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
307 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
310 if ($form->{type} eq "credit_note") {
311 $form->{title} = $locale->text('Edit Credit Note');
312 $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
314 $form->{title} = $locale->text('Edit Sales Invoice');
315 $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
318 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
319 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
321 $payment = qq|<option value=""></option>|;
322 foreach my $item (@{ $form->{payment_terms} }) {
323 if ($form->{payment_id} eq $item->{id}) {
324 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
326 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
330 my $set_duedate_url = "$form->{script}?action=set_duedate";
332 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
333 push(@ { $form->{AJAX} }, $pjx);
335 my @old_project_ids = ($form->{"globalproject_id"});
336 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
338 $form->get_lists("contacts" => "ALL_CONTACTS",
339 "shipto" => "ALL_SHIPTO",
340 "projects" => { "key" => "ALL_PROJECTS",
342 "old_id" => \@old_project_ids },
343 "employees" => "ALL_SALESMEN",
344 "taxzones" => "ALL_TAXZONES",
345 "currencies" => "ALL_CURRENCIES",
346 "customers" => "ALL_CUSTOMERS",
347 "price_factors" => "ALL_PRICE_FACTORS");
350 my @values = (undef);
351 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
352 push(@values, $item->{"cp_id"});
353 $labels{$item->{"cp_id"}} = join(',', $item->{"cp_name"}, $item->{"cp_givenname"}) . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
356 if (scalar @values > 1) {
359 <th align="right">| . $locale->text('Contact Person') . qq|</th>
360 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
361 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
368 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
369 push(@values, $item->{"id"});
370 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
375 <th align="right">| . $locale->text('Employee') . qq|</th>
376 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
377 '-values' => \@values, '-labels' => \%labels)) . qq|
384 foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
385 push(@values, $item->{name}.qq|--|.$item->{"id"});
386 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
389 $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
392 <th align="right">| . $locale->text('Customer') . qq|</th>
394 (($myconfig{vclimit} <= scalar(@values))
395 ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
396 : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
397 '-onChange' => 'document.getElementById(\'update_button\').click();',
398 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
399 <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')">
404 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
405 push(@values, $item->{"shipto_id"});
406 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
410 if (scalar @values > 1) {
413 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
414 <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
415 '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
421 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
422 push(@values, $item);
423 $labels{$item} = $item;
426 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
428 if (scalar @values) {
431 <th align="right">| . $locale->text('Currency') . qq|</th>
432 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
433 '-values' => \@values, '-labels' => \%labels)) . qq|
440 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
441 push(@values, $item->{"id"});
442 $labels{$item->{"id"}} = $item->{"projectnumber"};
444 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
445 '-labels' => \%labels,
446 '-default' => $form->{"globalproject_id"}));
450 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
451 push(@values, $item->{id});
452 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
456 qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
457 <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
458 '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
464 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
465 push(@values, $item->{"id"});
466 $labels{$item->{"id"}} = $item->{"description"};
470 if (!$form->{"id"}) {
473 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
474 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
475 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
482 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
484 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
485 | . H($labels{$form->{"taxzone_id"}}) . qq|
490 # set option selected
491 foreach my $item (qw(AR customer currency department employee)) {
492 $form->{"select$item"} =~ s/ selected//;
493 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
496 my $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
498 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
499 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
500 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
502 my $exchangerate = "";
503 if ($form->{currency} ne $form->{defaultcurrency}) {
504 if ($form->{forex}) {
505 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
506 <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
508 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
509 <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
512 $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
516 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
517 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
518 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
521 | if $form->{selectdepartment};
523 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
526 if ($form->{business}) {
529 <th align="right">| . $locale->text('Customer type') . qq|</th>
530 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
531 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
538 if ($form->{max_dunning_level}) {
541 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
543 <b>$form->{max_dunning_level}</b>;
544 | . $locale->text('Dunning Amount') . qq|: <b>|
545 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
552 $form->{fokus} = "invoice.customer";
554 # use JavaScript Calendar or not
555 $form->{jsscript} = 1;
557 my ($button1, $button2, $button3);
558 if ($form->{type} eq "credit_note") {
560 <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
561 <input type="button" name="invdate_button" id="trigger1" value="|
562 . $locale->text('button') . qq|"></td>|;
566 Form->write_trigger(\%myconfig, "1",
571 <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
572 <input type="button" name="invdate_button" id="trigger1" value="|
573 . $locale->text('button') . qq|"></td>
576 <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
577 <input type="button" name="duedate_button" id="trigger2" value="|
578 . $locale->text('button') . qq|"></td>
581 <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
582 <input type="button" name="deliverydate_button" id="trigger3" value="|
583 . $locale->text('button') . qq|"></td>
588 Form->write_trigger(\%myconfig, "3",
589 "invdate", "BL", "trigger1",
590 "duedate", "BL", "trigger2",
591 "deliverydate", "BL", "trigger3");
594 my $credittext = $locale->text('Credit Limit exceeded!!!');
596 my $follow_up_vc = $form->{customer};
597 $follow_up_vc =~ s/--\d*\s*$//;
598 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
600 my $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
601 : ($form->{resubmit}) ? qq|document.invoice.submit()|
602 : ($creditwarning) ? qq|alert('$credittext')|
604 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
605 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
607 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
608 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
611 $form->write_trigger(\%myconfig, 2,
612 "orddate", "BL", "trigger_orddate",
613 "quodate", "BL", "trigger_quodate");
614 # show history button js
615 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
616 #/show history button js
620 <body onLoad="$onload">
621 <script type="text/javascript" src="js/common.js"></script>
622 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
623 <script type="text/javascript" src="js/vendor_selection.js"></script>
624 <script type="text/javascript" src="js/calculate_qty.js"></script>
625 <script type="text/javascript" src="js/follow_up.js"></script>
627 <form method="post" name="invoice" action="$form->{script}">
630 $form->hide_form(qw(id action type media format queued printed emailed title vc discount
631 creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
632 max_dunning_level dunning_amount
633 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
634 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
635 convert_from_do_ids convert_from_oe_ids),
636 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
638 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
642 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
643 <input type="hidden" name="follow_up_trans_type_1" value="sales_invoice">
644 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
645 <input type="hidden" name="follow_up_rowcount" value="1">
647 <input type="hidden" name="lizenzen" value="$main::lizenzen">
649 <div class="listtop" width="100%">$form->{title}</div>
657 <input type="hidden" name="customer_klass" value="| . H($form->{customer_klass}) . qq|">
658 <input type="hidden" name="customer_id" value="| . H($form->{customer_id}) . qq|">
659 <input type="hidden" name="oldcustomer" value="| . H($form->{oldcustomer}) . qq|">
660 <input type="hidden" name="selectcustomer" value="| . H($form->{selectcustomer}) . qq|">
665 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
666 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
671 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
672 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
673 <input type="hidden" name="selectAR" value="$form->{selectAR}">
679 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
680 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
684 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
686 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
690 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
692 $cgi->textfield("-name" => "shipvia", "-size" => 35, "-value" => $form->{shipvia}) .
696 <th align="right">| . $locale->text('Transaction description') . qq|</th>
697 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
704 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
706 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
707 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
711 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
713 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
714 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
721 <td align="right" valign="top">
727 #ergänzung in der maske um das feld Lieferscheinnummer (Delivery Order Number), meiner meinung nach sinnvoll ueber dem feld lieferscheindatum 12.02.2009 jb
728 if ($form->{type} eq "credit_note") {
730 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
732 $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .
736 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
741 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
743 $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .
747 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
751 <th align="right">| . $locale->text('Due Date') . qq|</th>
755 <th align="right" nowrap>| . $locale->text('Delivery Order Number') . qq|</th>
757 $cgi->textfield("-name" => "donumber", "-size" => 11, "-value" => $form->{donumber}) .
761 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
766 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
768 $cgi->textfield("-name" => "ordnumber", "-size" => 11, "-value" => $form->{ordnumber}) .
772 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
773 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
774 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
777 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
779 $cgi->textfield("-name" => "quonumber", "-size" => 11, "-value" => $form->{quonumber}) .
783 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
784 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
785 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
788 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
790 $cgi->textfield("-name" => "cusordnumber", "-size" => 11, "-value" => $form->{cusordnumber}) .
794 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
795 <td>$globalprojectnumber</td>
809 print qq|<input type="hidden" name="webdav" value="$main::webdav">|;
811 $main::lxdebug->leave_sub();
815 $main::lxdebug->enter_sub();
817 my $form = $main::form;
818 my %myconfig = %main::myconfig;
819 my $locale = $main::locale;
820 my $cgi = $main::cgi;
822 $main::auth->assert('invoice_edit');
824 $form->{invtotal} = $form->{invsubtotal};
826 my ($rows, $introws);
827 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
830 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
833 $rows = ($rows > $introws) ? $rows : $introws;
835 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
837 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
839 $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
841 my $taxincluded = "";
842 if ($form->{taxaccounts}) {
844 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
845 . $locale->text('Tax Included') . qq|</b><br><br>|;
848 my ($tax, $subtotal);
849 if (!$form->{taxincluded}) {
851 foreach my $item (split / /, $form->{taxaccounts}) {
852 if ($form->{"${item}_base"}) {
853 $form->{"${item}_total"} =
855 $form->{"${item}_base"} * $form->{"${item}_rate"},
857 $form->{invtotal} += $form->{"${item}_total"};
858 $form->{"${item}_total"} =
859 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
863 <th align="right">$form->{"${item}_description"} |
864 . $form->{"${item}_rate"} * 100 .qq|%</th>
865 <td align="right">$form->{"${item}_total"}</td>
871 $form->{invsubtotal} =
872 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
876 <th align="right">| . $locale->text('Subtotal') . qq|</th>
877 <td align="right">$form->{invsubtotal}</td>
883 if ($form->{taxincluded}) {
884 foreach my $item (split / /, $form->{taxaccounts}) {
885 if ($form->{"${item}_base"}) {
886 $form->{"${item}_total"} =
888 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
889 (1 + $form->{"${item}_rate"})
892 $form->{"${item}_netto"} =
894 ($form->{"${item}_base"} - $form->{"${item}_total"}),
896 $form->{"${item}_total"} =
897 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
898 $form->{"${item}_netto"} =
899 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
903 <th align="right">Enthaltene $form->{"${item}_description"} |
904 . $form->{"${item}_rate"} * 100 .qq|%</th>
905 <td align="right">$form->{"${item}_total"}</td>
908 <th align="right">Nettobetrag</th>
909 <td align="right">$form->{"${item}_netto"}</td>
917 $form->{oldinvtotal} = $form->{invtotal};
919 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
921 my $follow_ups_block;
923 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
925 if (@{ $follow_ups} ) {
926 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
927 $follow_ups_block = qq|
929 <td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
943 <th align="left">| . $locale->text('Notes') . qq|</th>
944 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
945 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
950 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value, 'invdate__' + invdate.value],['duedate'])">$payment
959 <th align=left>| . $locale->text('Ertrag') . qq|</th>
960 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
963 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
964 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
966 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
967 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
976 <th align="right">| . $locale->text('Total') . qq|</th>
977 <td align="right">$form->{invtotal}</td>
990 <td><hr size="3" noshade></td>
993 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
996 <td align="left" width="30%"><b>Dateiname</b></td>
997 <td align="left" width="70%"><b>Webdavlink</b></td>
999 foreach my $file (@{ $form->{WEBDAV} }) {
1002 <td align="left">$file->{name}</td>
1003 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
1014 if ($form->{type} eq "credit_note") {
1018 <table width="100%">
1019 <tr class="listheading">
1020 <th colspan="6" class="listheading">|
1021 . $locale->text('Payments') . qq|</th>
1028 <table width="100%">
1029 <tr class="listheading">
1030 <th colspan="6" class="listheading">|
1031 . $locale->text('Incoming Payments') . qq|</th>
1037 if ($form->{currency} eq $form->{defaultcurrency}) {
1038 @column_index = qw(datepaid source memo paid AR_paid);
1040 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
1044 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
1045 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
1046 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
1047 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
1048 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
1049 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
1054 map { print "$column_data{$_}\n" } @column_index;
1062 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1063 for my $i (1 .. $form->{paidaccounts}) {
1068 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1069 $form->{"selectAR_paid_$i"} =~
1070 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1073 $totalpaid += $form->{"paid_$i"};
1074 if ($form->{"paid_$i"}) {
1075 $form->{"paid_$i"} =
1076 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1078 $form->{"exchangerate_$i"} =
1079 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1081 if ($form->{"exchangerate_$i"} == 0) {
1082 $form->{"exchangerate_$i"} = "";
1084 my $exchangerate = qq| |;
1085 if ($form->{currency} ne $form->{defaultcurrency}) {
1086 if ($form->{"forex_$i"}) {
1087 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1089 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1093 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1095 $column_data{"paid_$i"} =
1096 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
1097 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1098 $column_data{"AR_paid_$i"} =
1099 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1100 $column_data{"datepaid_$i"} =
1101 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)\">
1102 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1103 $column_data{"source_$i"} =
1104 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1105 $column_data{"memo_$i"} =
1106 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1108 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1111 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1114 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
1120 <td align="center">| . $locale->text('Total') . qq|</td>
1121 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
1126 <td align="center">| . $locale->text('Missing amount') . qq|</td>
1127 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
1131 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1132 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1137 <td><hr size="3" noshade></td>
1151 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1152 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1155 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar") && (($totalpaid == 0) || ($totalpaid eq ""));
1158 <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
1159 . $locale->text('Update') . qq|">
1160 <input class="submit" type="submit" name="action" value="|
1161 . $locale->text('Ship to') . qq|">
1162 <input class="submit" type="submit" name="action" value="|
1163 . $locale->text('Print') . qq|">
1164 <input class="submit" type="submit" name="action" value="|
1165 . $locale->text('E-mail') . qq|"> |;
1166 print qq|<input class="submit" type="submit" name="action" value="|
1167 . $locale->text('Storno') . qq|"> | if ($show_storno);
1168 print qq|<input class="submit" type="submit" name="action" value="|
1169 . $locale->text('Post Payment') . qq|">
1171 print qq|<input class="submit" type="submit" name="action" value="|
1172 . $locale->text('Use As Template') . qq|">
1174 if ($form->{id} && !($form->{type} eq "credit_note")) {
1176 <input class="submit" type="submit" name="action" value="|
1177 . $locale->text('Credit Note') . qq|">
1180 if ($form->{radier}) {
1182 <input class="submit" type="submit" name="action" value="|
1183 . $locale->text('Delete') . qq|">
1188 if ($invdate > $closedto) {
1190 <input class="submit" type="submit" name="action" value="|
1191 . $locale->text('Order') . qq|">
1196 <input type="button" class="submit" onclick="follow_up_window()" value="|
1197 . $locale->text('Follow-Up')
1201 if ($invdate > $closedto) {
1202 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1203 . $locale->text('Update') . qq|">
1204 <input class="submit" type="submit" name="action" value="|
1205 . $locale->text('Ship to') . qq|">
1206 <input class="submit" type="submit" name="action" value="|
1207 . $locale->text('Preview') . qq|">
1208 <input class="submit" type="submit" name="action" value="|
1209 . $locale->text('E-mail') . qq|">
1210 <input class="submit" type="submit" name="action" value="|
1211 . $locale->text('Print and Post') . qq|">
1212 <input class="submit" type="submit" name="action" value="|
1213 . $locale->text('Post') . qq|"> | .
1214 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1215 '-class' => 'submit'));
1219 # button for saving history
1220 if($form->{id} ne "") {
1222 <input type="button" class="submit" onclick="set_history_window(|
1224 . qq|);" name="history" id="history" value="|
1225 . $locale->text('history')
1228 # /button for saving history
1230 # mark_as_paid button
1231 if($form->{id} ne "") {
1232 print qq|<input type="submit" class="submit" name="action" value="|
1233 . $locale->text('mark as paid') . qq|">|;
1235 # /mark_as_paid button
1236 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1239 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1241 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1242 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1243 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
1244 . $cgi->hidden('-name' => 'customer_discount', '-value' => [$form->{customer_discount}])
1253 $main::lxdebug->leave_sub();
1257 $main::lxdebug->enter_sub();
1259 my $form = $main::form;
1260 my %myconfig = %main::myconfig;
1262 $main::auth->assert('invoice_edit');
1264 &mark_as_paid_common(\%myconfig,"ar");
1266 $main::lxdebug->leave_sub();
1270 $main::lxdebug->enter_sub();
1272 my $form = $main::form;
1273 my %myconfig = %main::myconfig;
1275 $main::auth->assert('invoice_edit');
1277 my ($recursive_call) = shift;
1279 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
1281 $form->{print_and_post} = 0 if $form->{second_run};
1282 my $taxincluded = "checked" if $form->{taxincluded};
1283 $form->{update} = 1;
1285 &check_name("customer");
1287 $form->{taxincluded} ||= $taxincluded;
1289 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1290 $form->{exchangerate} = $form->{forex} if $form->{forex};
1292 for my $i (1 .. $form->{paidaccounts}) {
1293 next unless $form->{"paid_$i"};
1294 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1295 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1296 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1299 my $i = $form->{rowcount};
1300 my $exchangerate = $form->{exchangerate} || 1;
1302 # if last row empty, check the form otherwise retrieve new item
1303 if ( ($form->{"partnumber_$i"} eq "")
1304 && ($form->{"description_$i"} eq "")
1305 && ($form->{"partsgroup_$i"} eq "")) {
1307 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1312 IS->retrieve_item(\%myconfig, \%$form);
1314 my $rows = scalar @{ $form->{item_list} };
1316 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{customer_discount} * 100);
1319 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1328 my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1330 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1331 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1333 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1334 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1336 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1338 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1339 my $decimalplaces = max 2, length $1;
1342 $form->{"sellprice_$i"} = $sellprice;
1344 # if there is an exchange rate adjust sellprice
1345 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1346 $form->{"sellprice_$i"} /= $exchangerate;
1349 $form->{"listprice_$i"} /= $exchangerate;
1351 my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1352 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1353 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1354 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1356 $form->{creditremaining} -= $amount;
1358 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
1360 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1362 if ($main::lizenzen) {
1363 if ($form->{"inventory_accno_$i"} ne "") {
1364 $form->{"lizenzen_$i"} = qq|<option></option>|;
1365 foreach my $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1366 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1368 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
1372 # get pricegroups for parts
1373 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1375 # build up html code for prices_$i
1376 &set_pricegroup($i);
1383 # ok, so this is a new part
1384 # ask if it is a part or service item
1386 if ( $form->{"partsgroup_$i"}
1387 && ($form->{"partsnumber_$i"} eq "")
1388 && ($form->{"description_$i"} eq "")) {
1389 $form->{rowcount}--;
1390 $form->{"discount_$i"} = "";
1394 $form->{"id_$i"} = 0;
1399 $main::lxdebug->leave_sub();
1403 $main::lxdebug->enter_sub();
1405 my $form = $main::form;
1406 my %myconfig = %main::myconfig;
1407 my $locale = $main::locale;
1409 $main::auth->assert('invoice_edit');
1413 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1414 for my $i (1 .. $form->{paidaccounts}) {
1415 if ($form->{"paid_$i"}) {
1416 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1418 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1420 $form->error($locale->text('Cannot post payment for a closed period!'))
1421 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1423 if ($form->{currency} ne $form->{defaultcurrency}) {
1424 $form->{"exchangerate_$i"} = $form->{exchangerate}
1425 if ($invdate == $datepaid);
1426 $form->isblank("exchangerate_$i",
1427 $locale->text('Exchangerate for payment missing!'));
1432 ($form->{AR}) = split /--/, $form->{AR};
1433 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1435 $form->redirect($locale->text('Payment posted!'))
1436 if (IS->post_payment(\%myconfig, \%$form));
1437 $form->error($locale->text('Cannot post payment!'));
1440 $main::lxdebug->leave_sub();
1444 $main::lxdebug->enter_sub();
1446 my $form = $main::form;
1447 my %myconfig = %main::myconfig;
1448 my $locale = $main::locale;
1450 $main::auth->assert('invoice_edit');
1452 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1453 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1454 $form->isblank("customer", $locale->text('Customer missing!'));
1455 $form->error($locale->text('Cannot post invoice for a closed period!'))
1456 if ($form->date_closed($form->{"invdate"}, \%myconfig));
1458 $form->{invnumber} =~ s/^\s*//g;
1459 $form->{invnumber} =~ s/\s*$//g;
1461 # if oldcustomer ne customer redo form
1462 if (&check_name('customer')) {
1466 if ($form->{second_run}) {
1467 $form->{print_and_post} = 0;
1472 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1473 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1475 $form->error($locale->text('Cannot post invoice for a closed period!'))
1476 if ($invdate <= $closedto);
1478 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1479 if ($form->{currency} ne $form->{defaultcurrency});
1481 for my $i (1 .. $form->{paidaccounts}) {
1482 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1483 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1485 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1487 $form->error($locale->text('Cannot post payment for a closed period!'))
1488 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1490 if ($form->{currency} ne $form->{defaultcurrency}) {
1491 $form->{"exchangerate_$i"} = $form->{exchangerate}
1492 if ($invdate == $datepaid);
1493 $form->isblank("exchangerate_$i",
1494 $locale->text('Exchangerate for payment missing!'));
1499 ($form->{AR}) = split /--/, $form->{AR};
1500 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1501 $form->{storno} ||= 0;
1503 $form->{label} = $locale->text('Invoice');
1505 $form->{id} = 0 if $form->{postasnew};
1507 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1508 if ($form->{postasnew}) {
1509 if ($form->{type} eq "credit_note") {
1510 undef($form->{cnnumber});
1512 undef($form->{invnumber});
1517 $form->error($locale->text('Cannot post invoice!'))
1518 unless IS->post_invoice(\%myconfig, \%$form);
1519 remove_draft() if $form->{remove_draft};
1521 if(!exists $form->{addition}) {
1522 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1523 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1524 $form->{storno} ? "STORNO" :
1526 $form->save_history($form->dbconnect(\%myconfig));
1529 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1532 $main::lxdebug->leave_sub();
1535 sub print_and_post {
1536 $main::lxdebug->enter_sub();
1538 my $form = $main::form;
1540 $main::auth->assert('invoice_edit');
1542 my $old_form = new Form;
1544 $form->{print_and_post} = 1;
1548 $main::lxdebug->leave_sub();
1552 sub use_as_template {
1553 $main::lxdebug->enter_sub();
1555 my $form = $main::form;
1556 my %myconfig = %main::myconfig;
1558 $main::auth->assert('invoice_edit');
1560 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);
1561 $form->{paidaccounts} = 1;
1562 $form->{rowcount}--;
1563 $form->{invdate} = $form->current_date(\%myconfig);
1566 $main::lxdebug->leave_sub();
1570 $main::lxdebug->enter_sub();
1572 my $form = $main::form;
1573 my %myconfig = %main::myconfig;
1574 my $locale = $main::locale;
1576 $main::auth->assert('invoice_edit');
1578 if ($form->{storno}) {
1579 $form->error($locale->text('Cannot storno storno invoice!'));
1582 if (IS->has_storno(\%myconfig, $form, "ar")) {
1583 $form->error($locale->text("Invoice has already been storno'd!"));
1586 map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
1592 # Payments must not be recorded for the new storno invoice.
1593 $form->{paidaccounts} = 0;
1594 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1596 $form->{storno_id} = $form->{id};
1597 $form->{storno} = 1;
1599 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1600 $form->{rowcount}++;
1603 $main::lxdebug->leave_sub();
1607 $main::lxdebug->enter_sub();
1609 my $form = $main::form;
1611 $main::auth->assert('invoice_edit');
1613 $form->{preview} = 1;
1614 my $old_form = new Form;
1615 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1617 &print_form($old_form);
1618 $main::lxdebug->leave_sub();
1623 $main::lxdebug->enter_sub();
1625 my $form = $main::form;
1626 my $locale = $main::locale;
1628 $main::auth->assert('invoice_edit');
1630 if ($form->{second_run}) {
1631 $form->{print_and_post} = 0;
1638 <form method="post" action="$form->{script}">
1641 # delete action variable
1642 map { delete $form->{$_} } qw(action header);
1644 foreach my $key (keys %$form) {
1645 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1646 $form->{$key} =~ s/\"/"/g;
1647 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1651 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1654 . $locale->text('Are you sure you want to delete Invoice Number')
1655 . qq| $form->{invnumber}
1659 <input name="action" class="submit" type="submit" value="|
1660 . $locale->text('Yes') . qq|">
1664 $main::lxdebug->leave_sub();
1668 $main::lxdebug->enter_sub();
1670 my $form = $main::form;
1671 my %myconfig = %main::myconfig;
1672 my $locale = $main::locale;
1674 $main::auth->assert('invoice_edit');
1676 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1678 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1681 $form->{rowcount}--;
1682 $form->{shipto} = 1;
1685 $form->{title} = $locale->text('Add Credit Note');
1686 $form->{script} = 'is.pl';
1688 our $buysell = 'buy';
1691 # bo creates the id, reset it
1692 map { delete $form->{$_} }
1693 qw(id invnumber subject message cc bcc printed emailed queued);
1694 $form->{ $form->{vc} } =~ s/--.*//g;
1695 $form->{type} = "credit_note";
1698 map { $form->{"select$_"} = "" } ($form->{vc}, 'currency');
1700 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1701 qw(creditlimit creditremaining);
1703 my $currency = $form->{currency};
1706 $form->{currency} = $currency;
1707 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
1708 $form->{exchangerate} = $form->{forex} || '';
1710 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1717 $main::lxdebug->leave_sub();
1721 $main::lxdebug->enter_sub();
1723 my $form = $main::form;
1724 my %myconfig = %main::myconfig;
1725 my $locale = $main::locale;
1727 $main::auth->assert('invoice_edit');
1729 if (IS->delete_invoice(\%myconfig, \%$form, $main::spool)) {
1730 # saving the history
1731 if(!exists $form->{addition}) {
1732 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1733 $form->{addition} = "DELETED";
1734 $form->save_history($form->dbconnect(\%myconfig));
1736 # /saving the history
1737 $form->redirect($locale->text('Invoice deleted!'));
1739 $form->error($locale->text('Cannot delete invoice!'));
1741 $main::lxdebug->leave_sub();
1745 $main::lxdebug->enter_sub();
1747 my $form = $main::form;
1749 $main::auth->assert('invoice_edit');
1754 my $saved_form = save_form();
1758 restore_form($saved_form, 0, qw(id invnumber));
1763 $main::lxdebug->leave_sub();