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";
268 # # get pricegroups for parts
269 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
273 foreach my $ref (@{ $form->{invoice_details} }) {
276 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
277 $form->{"discount_$i"} =
278 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
279 my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
281 my $decimalplaces = ($dec > 2) ? $dec : 2;
283 $form->{"sellprice_$i"} =
284 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
287 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
288 $dec_qty = length $dec_qty;
291 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
293 $form->{rowcount} = $i;
297 $main::lxdebug->leave_sub();
301 $main::lxdebug->enter_sub();
303 my $form = $main::form;
304 my %myconfig = %main::myconfig;
305 my $locale = $main::locale;
306 my $cgi = $main::cgi;
308 $main::auth->assert('invoice_edit');
310 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
311 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
314 if ($form->{type} eq "credit_note") {
315 $form->{title} = $locale->text('Edit Credit Note');
316 $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
318 $form->{title} = $locale->text('Edit Sales Invoice');
319 $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
322 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
323 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
325 $payment = qq|<option value=""></option>|;
326 foreach my $item (@{ $form->{payment_terms} }) {
327 if ($form->{payment_id} eq $item->{id}) {
328 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
330 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
334 my $set_duedate_url = "$form->{script}?action=set_duedate";
336 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
337 push(@ { $form->{AJAX} }, $pjx);
339 my @old_project_ids = ($form->{"globalproject_id"});
340 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
342 $form->get_lists("contacts" => "ALL_CONTACTS",
343 "shipto" => "ALL_SHIPTO",
344 "projects" => { "key" => "ALL_PROJECTS",
346 "old_id" => \@old_project_ids },
347 "employees" => "ALL_SALESMEN",
348 "taxzones" => "ALL_TAXZONES",
349 "currencies" => "ALL_CURRENCIES",
350 "customers" => "ALL_CUSTOMERS",
351 "price_factors" => "ALL_PRICE_FACTORS");
354 my @values = (undef);
355 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
356 push(@values, $item->{"cp_id"});
357 $labels{$item->{"cp_id"}} = join(',', $item->{"cp_name"}, $item->{"cp_givenname"}) . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
360 if (scalar @values > 1) {
363 <th align="right">| . $locale->text('Contact Person') . qq|</th>
364 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
365 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
372 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
373 push(@values, $item->{"id"});
374 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
379 <th align="right">| . $locale->text('Employee') . qq|</th>
380 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
381 '-values' => \@values, '-labels' => \%labels)) . qq|
388 foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
389 push(@values, $item->{name}.qq|--|.$item->{"id"});
390 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
393 $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
396 <th align="right">| . $locale->text('Customer') . qq|</th>
398 (($myconfig{vclimit} <= scalar(@values))
399 ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
400 : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
401 '-onChange' => 'document.getElementById(\'update_button\').click();',
402 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
403 <input type="button" value="| . $locale->text('Details (one letter abbreviation)') . qq|" onclick="show_vc_details('customer')">
408 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
409 push(@values, $item->{"shipto_id"});
410 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
414 if (scalar @values > 1) {
417 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
418 <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
419 '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
425 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
426 push(@values, $item);
427 $labels{$item} = $item;
430 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
432 if (scalar @values) {
435 <th align="right">| . $locale->text('Currency') . qq|</th>
436 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
437 '-values' => \@values, '-labels' => \%labels)) . qq|
444 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
445 push(@values, $item->{"id"});
446 $labels{$item->{"id"}} = $item->{"projectnumber"};
448 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
449 '-labels' => \%labels,
450 '-default' => $form->{"globalproject_id"}));
454 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
455 push(@values, $item->{id});
456 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
460 qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
461 <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
462 '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
468 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
469 push(@values, $item->{"id"});
470 $labels{$item->{"id"}} = $item->{"description"};
474 if (!$form->{"id"}) {
477 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
478 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
479 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
486 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
488 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
489 | . H($labels{$form->{"taxzone_id"}}) . qq|
494 # set option selected
495 foreach my $item (qw(AR customer currency department employee)) {
496 $form->{"select$item"} =~ s/ selected//;
497 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
500 my $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
502 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
503 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
504 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
506 my $exchangerate = "";
507 if ($form->{currency} ne $form->{defaultcurrency}) {
508 if ($form->{forex}) {
509 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
510 <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
512 $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
513 <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
516 $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
520 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
521 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
522 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
525 | if $form->{selectdepartment};
527 my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
530 if ($form->{business}) {
533 <th align="right">| . $locale->text('Customer type') . qq|</th>
534 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
535 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
542 if ($form->{max_dunning_level}) {
545 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
547 <b>$form->{max_dunning_level}</b>;
548 | . $locale->text('Dunning Amount') . qq|: <b>|
549 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
556 $form->{fokus} = "invoice.customer";
558 # use JavaScript Calendar or not
559 $form->{jsscript} = 1;
561 my ($button1, $button2, $button3);
562 if ($form->{type} eq "credit_note") {
564 <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
565 <input type="button" name="invdate_button" id="trigger1" value="|
566 . $locale->text('button') . qq|"></td>|;
570 Form->write_trigger(\%myconfig, "1",
575 <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
576 <input type="button" name="invdate_button" id="trigger1" value="|
577 . $locale->text('button') . qq|"></td>
580 <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
581 <input type="button" name="duedate_button" id="trigger2" value="|
582 . $locale->text('button') . qq|"></td>
585 <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
586 <input type="button" name="deliverydate_button" id="trigger3" value="|
587 . $locale->text('button') . qq|"></td>
592 Form->write_trigger(\%myconfig, "3",
593 "invdate", "BL", "trigger1",
594 "duedate", "BL", "trigger2",
595 "deliverydate", "BL", "trigger3");
598 my $credittext = $locale->text('Credit Limit exceeded!!!');
600 my $follow_up_vc = $form->{customer};
601 $follow_up_vc =~ s/--\d*\s*$//;
602 my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
604 my $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
605 : ($form->{resubmit}) ? qq|document.invoice.submit()|
606 : ($creditwarning) ? qq|alert('$credittext')|
608 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
609 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
611 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
612 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
615 $form->write_trigger(\%myconfig, 2,
616 "orddate", "BL", "trigger_orddate",
617 "quodate", "BL", "trigger_quodate");
618 # show history button js
619 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
620 #/show history button js
624 <body onLoad="$onload">
625 <script type="text/javascript" src="js/common.js"></script>
626 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
627 <script type="text/javascript" src="js/vendor_selection.js"></script>
628 <script type="text/javascript" src="js/calculate_qty.js"></script>
629 <script type="text/javascript" src="js/follow_up.js"></script>
631 <form method="post" name="invoice" action="$form->{script}">
634 $form->hide_form(qw(id action type media format queued printed emailed title vc discount
635 creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
636 max_dunning_level dunning_amount
637 shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
638 shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
639 convert_from_do_ids convert_from_oe_ids),
640 map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
642 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
646 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
647 <input type="hidden" name="follow_up_trans_type_1" value="sales_invoice">
648 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
649 <input type="hidden" name="follow_up_rowcount" value="1">
651 <input type="hidden" name="lizenzen" value="$main::lizenzen">
653 <div class="listtop" width="100%">$form->{title}</div>
661 <input type="hidden" name="customer_klass" value="| . H($form->{customer_klass}) . qq|">
662 <input type="hidden" name="customer_id" value="| . H($form->{customer_id}) . qq|">
663 <input type="hidden" name="oldcustomer" value="| . H($form->{oldcustomer}) . qq|">
664 <input type="hidden" name="selectcustomer" value="| . H($form->{selectcustomer}) . qq|">
669 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
670 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
675 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
676 <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
677 <input type="hidden" name="selectAR" value="$form->{selectAR}">
683 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
684 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
688 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
690 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
694 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
696 $cgi->textfield("-name" => "shipvia", "-size" => 35, "-value" => $form->{shipvia}) .
700 <th align="right">| . $locale->text('Transaction description') . qq|</th>
701 <td colspan="3">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
708 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
710 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
711 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
715 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
717 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
718 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
725 <td align="right" valign="top">
731 #ergänzung in der maske um das feld Lieferscheinnummer (Delivery Order Number), meiner meinung nach sinnvoll ueber dem feld lieferscheindatum 12.02.2009 jb
732 if ($form->{type} eq "credit_note") {
734 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
736 $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .
740 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
745 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
747 $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .
751 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
755 <th align="right">| . $locale->text('Due Date') . qq|</th>
759 <th align="right" nowrap>| . $locale->text('Delivery Order Number') . qq|</th>
761 $cgi->textfield("-name" => "donumber", "-size" => 11, "-value" => $form->{donumber}) .
765 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
770 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
772 $cgi->textfield("-name" => "ordnumber", "-size" => 11, "-value" => $form->{ordnumber}) .
776 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
777 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
778 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
781 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
783 $cgi->textfield("-name" => "quonumber", "-size" => 11, "-value" => $form->{quonumber}) .
787 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
788 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
789 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
792 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
794 $cgi->textfield("-name" => "cusordnumber", "-size" => 11, "-value" => $form->{cusordnumber}) .
798 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
799 <td>$globalprojectnumber</td>
813 print qq|<input type="hidden" name="webdav" value="$main::webdav">|;
815 $main::lxdebug->leave_sub();
819 $main::lxdebug->enter_sub();
821 my $form = $main::form;
822 my %myconfig = %main::myconfig;
823 my $locale = $main::locale;
824 my $cgi = $main::cgi;
826 $main::auth->assert('invoice_edit');
828 $form->{invtotal} = $form->{invsubtotal};
830 my ($rows, $introws);
831 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
834 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
837 $rows = ($rows > $introws) ? $rows : $introws;
839 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
841 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
843 $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
845 my $taxincluded = "";
846 if ($form->{taxaccounts}) {
848 <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
849 . $locale->text('Tax Included') . qq|</b><br><br>|;
852 my ($tax, $subtotal);
853 if (!$form->{taxincluded}) {
855 foreach my $item (split / /, $form->{taxaccounts}) {
856 if ($form->{"${item}_base"}) {
857 $form->{"${item}_total"} =
859 $form->{"${item}_base"} * $form->{"${item}_rate"},
861 $form->{invtotal} += $form->{"${item}_total"};
862 $form->{"${item}_total"} =
863 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
867 <th align="right">$form->{"${item}_description"} |
868 . $form->{"${item}_rate"} * 100 .qq|%</th>
869 <td align="right">$form->{"${item}_total"}</td>
875 $form->{invsubtotal} =
876 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
880 <th align="right">| . $locale->text('Subtotal') . qq|</th>
881 <td align="right">$form->{invsubtotal}</td>
887 if ($form->{taxincluded}) {
888 foreach my $item (split / /, $form->{taxaccounts}) {
889 if ($form->{"${item}_base"}) {
890 $form->{"${item}_total"} =
892 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
893 (1 + $form->{"${item}_rate"})
896 $form->{"${item}_netto"} =
898 ($form->{"${item}_base"} - $form->{"${item}_total"}),
900 $form->{"${item}_total"} =
901 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
902 $form->{"${item}_netto"} =
903 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
907 <th align="right">Enthaltene $form->{"${item}_description"} |
908 . $form->{"${item}_rate"} * 100 .qq|%</th>
909 <td align="right">$form->{"${item}_total"}</td>
912 <th align="right">Nettobetrag</th>
913 <td align="right">$form->{"${item}_netto"}</td>
921 $form->{oldinvtotal} = $form->{invtotal};
923 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
925 my $follow_ups_block;
927 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
929 if (@{ $follow_ups} ) {
930 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
931 $follow_ups_block = qq|
933 <td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
947 <th align="left">| . $locale->text('Notes') . qq|</th>
948 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
949 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
954 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value, 'invdate__' + invdate.value],['duedate'])">$payment
963 <th align=left>| . $locale->text('Ertrag') . qq|</th>
964 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
967 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
968 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
970 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
971 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
980 <th align="right">| . $locale->text('Total') . qq|</th>
981 <td align="right">$form->{invtotal}</td>
994 <td><hr size="3" noshade></td>
997 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
1000 <td align="left" width="30%"><b>Dateiname</b></td>
1001 <td align="left" width="70%"><b>Webdavlink</b></td>
1003 foreach my $file (@{ $form->{WEBDAV} }) {
1006 <td align="left">$file->{name}</td>
1007 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
1018 if ($form->{type} eq "credit_note") {
1022 <table width="100%">
1023 <tr class="listheading">
1024 <th colspan="6" class="listheading">|
1025 . $locale->text('Payments') . qq|</th>
1032 <table width="100%">
1033 <tr class="listheading">
1034 <th colspan="6" class="listheading">|
1035 . $locale->text('Incoming Payments') . qq|</th>
1041 if ($form->{currency} eq $form->{defaultcurrency}) {
1042 @column_index = qw(datepaid source memo paid AR_paid);
1044 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
1048 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
1049 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
1050 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
1051 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
1052 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
1053 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
1058 map { print "$column_data{$_}\n" } @column_index;
1066 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1067 for my $i (1 .. $form->{paidaccounts}) {
1072 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1073 $form->{"selectAR_paid_$i"} =~
1074 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1077 $totalpaid += $form->{"paid_$i"};
1078 if ($form->{"paid_$i"}) {
1079 $form->{"paid_$i"} =
1080 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1082 $form->{"exchangerate_$i"} =
1083 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1085 if ($form->{"exchangerate_$i"} == 0) {
1086 $form->{"exchangerate_$i"} = "";
1088 my $exchangerate = qq| |;
1089 if ($form->{currency} ne $form->{defaultcurrency}) {
1090 if ($form->{"forex_$i"}) {
1091 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1093 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1097 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1099 $column_data{"paid_$i"} =
1100 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
1101 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1102 $column_data{"AR_paid_$i"} =
1103 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1104 $column_data{"datepaid_$i"} =
1105 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)\">
1106 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1107 $column_data{"source_$i"} =
1108 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1109 $column_data{"memo_$i"} =
1110 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1112 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1115 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1118 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
1124 <td align="center">| . $locale->text('Total') . qq|</td>
1125 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
1130 <td align="center">| . $locale->text('Missing amount') . qq|</td>
1131 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
1135 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1136 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1141 <td><hr size="3" noshade></td>
1155 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1156 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1159 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar") && (($totalpaid == 0) || ($totalpaid eq ""));
1162 <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
1163 . $locale->text('Update') . qq|">
1164 <input class="submit" type="submit" name="action" value="|
1165 . $locale->text('Ship to') . qq|">
1166 <input class="submit" type="submit" name="action" value="|
1167 . $locale->text('Print') . qq|">
1168 <input class="submit" type="submit" name="action" value="|
1169 . $locale->text('E-mail') . qq|"> |;
1170 print qq|<input class="submit" type="submit" name="action" value="|
1171 . $locale->text('Storno') . qq|"> | if ($show_storno);
1172 print qq|<input class="submit" type="submit" name="action" value="|
1173 . $locale->text('Post Payment') . qq|">
1175 print qq|<input class="submit" type="submit" name="action" value="|
1176 . $locale->text('Use As Template') . qq|">
1178 if ($form->{id} && !($form->{type} eq "credit_note")) {
1180 <input class="submit" type="submit" name="action" value="|
1181 . $locale->text('Credit Note') . qq|">
1184 if ($form->{radier}) {
1186 <input class="submit" type="submit" name="action" value="|
1187 . $locale->text('Delete') . qq|">
1192 if ($invdate > $closedto) {
1194 <input class="submit" type="submit" name="action" value="|
1195 . $locale->text('Order') . qq|">
1200 <input type="button" class="submit" onclick="follow_up_window()" value="|
1201 . $locale->text('Follow-Up')
1205 if ($invdate > $closedto) {
1206 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1207 . $locale->text('Update') . qq|">
1208 <input class="submit" type="submit" name="action" value="|
1209 . $locale->text('Ship to') . qq|">
1210 <input class="submit" type="submit" name="action" value="|
1211 . $locale->text('Preview') . qq|">
1212 <input class="submit" type="submit" name="action" value="|
1213 . $locale->text('E-mail') . qq|">
1214 <input class="submit" type="submit" name="action" value="|
1215 . $locale->text('Print and Post') . qq|">
1216 <input class="submit" type="submit" name="action" value="|
1217 . $locale->text('Post') . qq|"> | .
1218 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1219 '-class' => 'submit'));
1223 # button for saving history
1224 if($form->{id} ne "") {
1226 <input type="button" class="submit" onclick="set_history_window(|
1228 . qq|);" name="history" id="history" value="|
1229 . $locale->text('history')
1232 # /button for saving history
1234 # mark_as_paid button
1235 if($form->{id} ne "") {
1236 print qq|<input type="submit" class="submit" name="action" value="|
1237 . $locale->text('mark as paid') . qq|">|;
1239 # /mark_as_paid button
1240 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1243 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1245 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1246 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1247 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
1248 . $cgi->hidden('-name' => 'customer_discount', '-value' => [$form->{customer_discount}])
1257 $main::lxdebug->leave_sub();
1261 $main::lxdebug->enter_sub();
1263 my $form = $main::form;
1264 my %myconfig = %main::myconfig;
1266 $main::auth->assert('invoice_edit');
1268 &mark_as_paid_common(\%myconfig,"ar");
1270 $main::lxdebug->leave_sub();
1274 $main::lxdebug->enter_sub();
1276 my $form = $main::form;
1277 my %myconfig = %main::myconfig;
1279 $main::auth->assert('invoice_edit');
1281 my ($recursive_call) = shift;
1283 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
1285 $form->{print_and_post} = 0 if $form->{second_run};
1286 my $taxincluded = "checked" if $form->{taxincluded};
1287 $form->{update} = 1;
1289 &check_name("customer");
1291 $form->{taxincluded} ||= $taxincluded;
1293 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1294 $form->{exchangerate} = $form->{forex} if $form->{forex};
1296 for my $i (1 .. $form->{paidaccounts}) {
1297 next unless $form->{"paid_$i"};
1298 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
1299 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
1300 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
1303 my $i = $form->{rowcount};
1304 my $exchangerate = $form->{exchangerate} || 1;
1306 # if last row empty, check the form otherwise retrieve new item
1307 if ( ($form->{"partnumber_$i"} eq "")
1308 && ($form->{"description_$i"} eq "")
1309 && ($form->{"partsgroup_$i"} eq "")) {
1311 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1316 IS->retrieve_item(\%myconfig, \%$form);
1318 my $rows = scalar @{ $form->{item_list} };
1320 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{customer_discount} * 100);
1323 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1332 my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1334 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1335 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1337 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1338 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1340 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1342 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1343 my $decimalplaces = max 2, length $1;
1346 $form->{"sellprice_$i"} = $sellprice;
1348 # if there is an exchange rate adjust sellprice
1349 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1350 $form->{"sellprice_$i"} /= $exchangerate;
1353 $form->{"listprice_$i"} /= $exchangerate;
1355 my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1356 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1357 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1358 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1360 $form->{creditremaining} -= $amount;
1362 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
1364 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1366 if ($main::lizenzen) {
1367 if ($form->{"inventory_accno_$i"} ne "") {
1368 $form->{"lizenzen_$i"} = qq|<option></option>|;
1369 foreach my $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1370 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1372 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
1376 # get pricegroups for parts
1377 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1379 # build up html code for prices_$i
1380 &set_pricegroup($i);
1387 # ok, so this is a new part
1388 # ask if it is a part or service item
1390 if ( $form->{"partsgroup_$i"}
1391 && ($form->{"partsnumber_$i"} eq "")
1392 && ($form->{"description_$i"} eq "")) {
1393 $form->{rowcount}--;
1394 $form->{"discount_$i"} = "";
1398 $form->{"id_$i"} = 0;
1403 $main::lxdebug->leave_sub();
1407 $main::lxdebug->enter_sub();
1409 my $form = $main::form;
1410 my %myconfig = %main::myconfig;
1411 my $locale = $main::locale;
1413 $main::auth->assert('invoice_edit');
1417 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1418 for my $i (1 .. $form->{paidaccounts}) {
1419 if ($form->{"paid_$i"}) {
1420 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1422 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1424 $form->error($locale->text('Cannot post payment for a closed period!'))
1425 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1427 if ($form->{currency} ne $form->{defaultcurrency}) {
1428 $form->{"exchangerate_$i"} = $form->{exchangerate}
1429 if ($invdate == $datepaid);
1430 $form->isblank("exchangerate_$i",
1431 $locale->text('Exchangerate for payment missing!'));
1436 ($form->{AR}) = split /--/, $form->{AR};
1437 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1439 $form->redirect($locale->text('Payment posted!'))
1440 if (IS->post_payment(\%myconfig, \%$form));
1441 $form->error($locale->text('Cannot post payment!'));
1444 $main::lxdebug->leave_sub();
1448 $main::lxdebug->enter_sub();
1450 my $form = $main::form;
1451 my %myconfig = %main::myconfig;
1452 my $locale = $main::locale;
1454 $main::auth->assert('invoice_edit');
1456 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1457 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1458 $form->isblank("customer", $locale->text('Customer missing!'));
1459 $form->error($locale->text('Cannot post invoice for a closed period!'))
1460 if ($form->date_closed($form->{"invdate"}, \%myconfig));
1462 $form->{invnumber} =~ s/^\s*//g;
1463 $form->{invnumber} =~ s/\s*$//g;
1465 # if oldcustomer ne customer redo form
1466 if (&check_name('customer')) {
1470 if ($form->{second_run}) {
1471 $form->{print_and_post} = 0;
1476 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1477 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1479 $form->error($locale->text('Cannot post invoice for a closed period!'))
1480 if ($invdate <= $closedto);
1482 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1483 if ($form->{currency} ne $form->{defaultcurrency});
1485 for my $i (1 .. $form->{paidaccounts}) {
1486 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1487 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1489 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1491 $form->error($locale->text('Cannot post payment for a closed period!'))
1492 if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
1494 if ($form->{currency} ne $form->{defaultcurrency}) {
1495 $form->{"exchangerate_$i"} = $form->{exchangerate}
1496 if ($invdate == $datepaid);
1497 $form->isblank("exchangerate_$i",
1498 $locale->text('Exchangerate for payment missing!'));
1503 ($form->{AR}) = split /--/, $form->{AR};
1504 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1505 $form->{storno} ||= 0;
1507 $form->{label} = $locale->text('Invoice');
1509 $form->{id} = 0 if $form->{postasnew};
1511 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1512 if ($form->{postasnew}) {
1513 if ($form->{type} eq "credit_note") {
1514 undef($form->{cnnumber});
1516 undef($form->{invnumber});
1521 $form->error($locale->text('Cannot post invoice!'))
1522 unless IS->post_invoice(\%myconfig, \%$form);
1523 remove_draft() if $form->{remove_draft};
1525 if(!exists $form->{addition}) {
1526 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1527 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1528 $form->{storno} ? "STORNO" :
1530 $form->save_history($form->dbconnect(\%myconfig));
1533 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1536 $main::lxdebug->leave_sub();
1539 sub print_and_post {
1540 $main::lxdebug->enter_sub();
1542 my $form = $main::form;
1544 $main::auth->assert('invoice_edit');
1546 my $old_form = new Form;
1548 $form->{print_and_post} = 1;
1552 $main::lxdebug->leave_sub();
1556 sub use_as_template {
1557 $main::lxdebug->enter_sub();
1559 my $form = $main::form;
1560 my %myconfig = %main::myconfig;
1562 $main::auth->assert('invoice_edit');
1564 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);
1565 $form->{paidaccounts} = 1;
1566 $form->{rowcount}--;
1567 $form->{invdate} = $form->current_date(\%myconfig);
1570 $main::lxdebug->leave_sub();
1574 $main::lxdebug->enter_sub();
1576 my $form = $main::form;
1577 my %myconfig = %main::myconfig;
1578 my $locale = $main::locale;
1580 $main::auth->assert('invoice_edit');
1582 if ($form->{storno}) {
1583 $form->error($locale->text('Cannot storno storno invoice!'));
1586 if (IS->has_storno(\%myconfig, $form, "ar")) {
1587 $form->error($locale->text("Invoice has already been storno'd!"));
1590 map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
1596 # Payments must not be recorded for the new storno invoice.
1597 $form->{paidaccounts} = 0;
1598 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1600 $form->{storno_id} = $form->{id};
1601 $form->{storno} = 1;
1603 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1604 $form->{rowcount}++;
1607 $main::lxdebug->leave_sub();
1611 $main::lxdebug->enter_sub();
1613 my $form = $main::form;
1615 $main::auth->assert('invoice_edit');
1617 $form->{preview} = 1;
1618 my $old_form = new Form;
1619 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1621 &print_form($old_form);
1622 $main::lxdebug->leave_sub();
1627 $main::lxdebug->enter_sub();
1629 my $form = $main::form;
1630 my $locale = $main::locale;
1632 $main::auth->assert('invoice_edit');
1634 if ($form->{second_run}) {
1635 $form->{print_and_post} = 0;
1642 <form method="post" action="$form->{script}">
1645 # delete action variable
1646 map { delete $form->{$_} } qw(action header);
1648 foreach my $key (keys %$form) {
1649 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1650 $form->{$key} =~ s/\"/"/g;
1651 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1655 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1658 . $locale->text('Are you sure you want to delete Invoice Number')
1659 . qq| $form->{invnumber}
1663 <input name="action" class="submit" type="submit" value="|
1664 . $locale->text('Yes') . qq|">
1668 $main::lxdebug->leave_sub();
1672 $main::lxdebug->enter_sub();
1674 my $form = $main::form;
1675 my %myconfig = %main::myconfig;
1676 my $locale = $main::locale;
1678 $main::auth->assert('invoice_edit');
1680 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1682 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1685 $form->{rowcount}--;
1686 $form->{shipto} = 1;
1689 $form->{title} = $locale->text('Add Credit Note');
1690 $form->{script} = 'is.pl';
1692 our $buysell = 'buy';
1695 # bo creates the id, reset it
1696 map { delete $form->{$_} }
1697 qw(id invnumber subject message cc bcc printed emailed queued);
1698 $form->{ $form->{vc} } =~ s/--.*//g;
1699 $form->{type} = "credit_note";
1702 map { $form->{"select$_"} = "" } ($form->{vc}, 'currency');
1704 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1705 qw(creditlimit creditremaining);
1707 my $currency = $form->{currency};
1710 $form->{currency} = $currency;
1711 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
1712 $form->{exchangerate} = $form->{forex} || '';
1714 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1721 $main::lxdebug->leave_sub();
1725 $main::lxdebug->enter_sub();
1727 my $form = $main::form;
1728 my %myconfig = %main::myconfig;
1729 my $locale = $main::locale;
1731 $main::auth->assert('invoice_edit');
1733 if (IS->delete_invoice(\%myconfig, \%$form, $main::spool)) {
1734 # saving the history
1735 if(!exists $form->{addition}) {
1736 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1737 $form->{addition} = "DELETED";
1738 $form->save_history($form->dbconnect(\%myconfig));
1740 # /saving the history
1741 $form->redirect($locale->text('Invoice deleted!'));
1743 $form->error($locale->text('Cannot delete invoice!'));
1745 $main::lxdebug->leave_sub();
1749 $main::lxdebug->enter_sub();
1751 my $form = $main::form;
1753 $main::auth->assert('invoice_edit');
1758 my $saved_form = save_form();
1762 restore_form($saved_form, 0, qw(id invnumber));
1767 $main::lxdebug->leave_sub();