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., 51 Franklin Street, Fifth Floor, Boston,
29 #======================================================================
31 # Inventory invoicing module
33 #======================================================================
38 use SL::MoreCommon qw(restore_form save_form);
41 use List::MoreUtils qw(uniq);
42 use List::Util qw(max sum);
43 use List::UtilsBy qw(sort_by);
44 use English qw(-no_match_vars);
46 use SL::DB::BankTransactionAccTrans;
49 use SL::DB::Department;
51 use SL::DB::PaymentTerm;
53 require "bin/mozilla/common.pl";
54 require "bin/mozilla/io.pl";
62 sub _may_view_or_edit_this_invoice {
63 return 1 if $::auth->assert('invoice_edit', 1); # may edit all invoices
64 return 0 if !$::form->{id}; # creating new invoices isn't allowed without invoice_edit
65 return 0 if !$::form->{globalproject_id}; # existing records without a project ID are not allowed
66 return SL::DB::Project->new(id => $::form->{globalproject_id})->load->may_employee_view_project_invoices(SL::DB::Manager::Employee->current);
70 my $cache = $::request->cache('is.pl::_assert_access');
72 $cache->{_may_view_or_edit_this_invoice} = _may_view_or_edit_this_invoice() if !exists $cache->{_may_view_or_edit_this_invoice};
73 $::form->show_generic_error($::locale->text("You do not have the permissions to access this function.")) if ! $cache->{_may_view_or_edit_this_invoice};
77 $main::lxdebug->enter_sub();
79 my $form = $main::form;
80 my $locale = $main::locale;
82 $main::auth->assert('invoice_edit');
84 $form->{show_details} = $::myconfig{show_form_details};
86 if ($form->{type} eq "credit_note") {
87 $form->{title} = $locale->text('Add Credit Note');
89 if ($form->{storno}) {
90 $form->{title} = $locale->text('Add Storno Credit Note');
93 } elsif ($form->{type} eq "invoice_for_advance_payment") {
94 $form->{title} = $locale->text('Add Invoice for Advance Payment');
97 $form->{title} = $locale->text('Add Sales Invoice');
102 $form->{callback} = "$form->{script}?action=add&type=$form->{type}" unless $form->{callback};
104 invoice_links(is_new => 1);
108 $main::lxdebug->leave_sub();
112 $main::lxdebug->enter_sub();
114 # Delay access check to after the invoice's been loaded in
115 # "invoice_links" so that project-specific invoice rights can be
118 my $form = $main::form;
119 my $locale = $main::locale;
121 $form->{show_details} = $::myconfig{show_form_details};
122 $form->{taxincluded_changed_by_user} = 1;
124 # show history button
125 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
127 my ($language_id, $printer_id);
128 if ($form->{print_and_post}) {
129 $form->{action} = "print";
130 $form->{resubmit} = 1;
131 $language_id = $form->{language_id};
132 $printer_id = $form->{printer_id};
136 if ($form->{type} eq "credit_note") {
137 $form->{title} = $locale->text('Edit Credit Note');
138 $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
140 } elsif ($form->{type} eq "invoice_for_advance_payment") {
141 $form->{title} = $locale->text('Edit Invoice for Advance Payment');
142 $form->{title} = $locale->text('Edit Storno Invoice for Advance Payment') if $form->{storno};
145 $form->{title} = $locale->text('Edit Sales Invoice');
146 $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
150 if ($form->{print_and_post}) {
151 $form->{language_id} = $language_id;
152 $form->{printer_id} = $printer_id;
157 $main::lxdebug->leave_sub();
161 $main::lxdebug->enter_sub();
163 # Delay access check to after the invoice's been loaded so that
164 # project-specific invoice rights can be evaluated.
167 my $form = $main::form;
168 my %myconfig = %main::myconfig;
170 $form->{vc} = 'customer';
173 $form->create_links("AR", \%myconfig, "customer");
177 my $editing = $form->{id};
179 $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id
180 taxincluded currency cp_id intnotes id shipto_id
183 IS->get_customer(\%myconfig, \%$form);
185 $form->{billing_address_id} = $form->{default_billing_address_id} if $params{is_new};
187 $form->restore_vars(qw(id));
189 IS->retrieve_invoice(\%myconfig, \%$form);
190 $form->restore_vars(qw(payment_id language_id taxzone_id currency intnotes
191 cp_id shipto_id delivery_term_id));
192 $form->restore_vars(qw(taxincluded)) if $form->{id};
193 $form->restore_vars(qw(salesman_id)) if $editing;
195 $form->{employee} = "$form->{employee}--$form->{employee_id}";
198 $form->{forex} = $form->{exchangerate};
199 my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
201 foreach my $key (keys %{ $form->{AR_links} }) {
202 foreach my $ref (@{ $form->{AR_links}{$key} }) {
203 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}</option>\n";
206 if ($key eq "AR_paid") {
207 next unless $form->{acc_trans}{$key};
208 for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
209 $form->{"AR_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
211 $form->{"acc_trans_id_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{acc_trans_id};
213 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
214 $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{transdate};
215 $form->{"gldate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{gldate};
216 $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
217 $form->{"forex_$i"} = $form->{"exchangerate_$i"};
218 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
219 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
221 $form->{paidaccounts} = $i;
224 $form->{$key} = "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
228 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
230 $form->{AR} = $form->{AR_1} unless $form->{id};
232 $form->{locked} = ($form->datetonum($form->{invdate}, \%myconfig)
233 <= $form->datetonum($form->{closedto}, \%myconfig));
235 $main::lxdebug->leave_sub();
238 sub prepare_invoice {
239 $main::lxdebug->enter_sub();
243 my $form = $main::form;
244 my %myconfig = %main::myconfig;
246 if ($form->{type} eq "credit_note") {
247 $form->{type} = "credit_note";
248 $form->{formname} = "credit_note";
250 } elsif ($form->{type} eq "invoice_for_advance_payment") {
251 $form->{type} = "invoice_for_advance_payment";
252 $form->{formname} = "invoice_for_advance_payment";
254 } elsif ($form->{formname} eq "proforma" ) {
255 $form->{type} = "invoice";
258 $form->{type} = "invoice";
259 $form->{formname} = "invoice";
266 foreach my $ref (@{ $form->{invoice_details} }) {
269 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
271 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
272 my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
274 my $decimalplaces = ($dec > 2) ? $dec : 2;
276 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
277 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
278 $dec_qty = length $dec_qty;
280 $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces);
282 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
284 $form->{"sellprice_pg_$i"} = join ('--', $form->{"sellprice_$i"}, $form->{"pricegroup_id_$i"});
286 $form->{rowcount} = $i;
290 $main::lxdebug->leave_sub();
293 sub setup_is_action_bar {
296 my $change_never = $::instance_conf->get_is_changeable == 0;
297 my $change_on_same_day_only = $::instance_conf->get_is_changeable == 2 && ($form->current_date(\%::myconfig) ne $form->{gldate});
298 my $payments_balanced = ($::form->{oldtotalpaid} == 0);
299 my $has_storno = ($::form->{storno} && !$::form->{storno_id});
300 my $may_edit_create = $::auth->assert('invoice_edit', 1);
301 my $factur_x_enabled = $tmpl_var->{invoice_obj} && $tmpl_var->{invoice_obj}->customer->create_zugferd_invoices_for_this_customer;
302 my ($is_linked_bank_transaction, $warn_unlinked_delivery_order);
304 && SL::DB::Default->get->payments_changeable != 0
305 && SL::DB::Manager::BankTransactionAccTrans->find_by(ar_id => $::form->{id})) {
307 $is_linked_bank_transaction = 1;
309 if ($::instance_conf->get_warn_no_delivery_order_for_invoice && !$form->{id}) {
310 $warn_unlinked_delivery_order = 1 unless $form->{convert_from_do_ids};
312 for my $bar ($::request->layout->get('actionbar')) {
316 submit => [ '#form', { action => "update" } ],
317 disabled => !$may_edit_create ? t8('You must not change this invoice.')
318 : $form->{locked} ? t8('The billing period has already been locked.')
320 id => 'update_button',
321 accesskey => 'enter',
327 submit => [ '#form', { action => "post" } ],
328 checks => [ 'kivi.validate_form' ],
329 confirm => t8('The invoice is not linked with a sales delivery order. Post anyway?') x !!$warn_unlinked_delivery_order,
330 disabled => !$may_edit_create ? t8('You must not change this invoice.')
331 : $form->{locked} ? t8('The billing period has already been locked.')
332 : $form->{storno} ? t8('A canceled invoice cannot be posted.')
333 : ($form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.')
334 : ($form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.')
335 : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
340 submit => [ '#form', { action => "post_payment" } ],
341 checks => [ 'kivi.validate_form' ],
342 disabled => !$may_edit_create ? t8('You must not change this invoice.')
343 : !$form->{id} ? t8('This invoice has not been posted yet.')
344 : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
346 only_if => $form->{type} ne "invoice_for_advance_payment",
348 action => [ t8('Mark as paid'),
349 submit => [ '#form', { action => "mark_as_paid" } ],
350 confirm => t8('This will remove the invoice from showing as unpaid even if the unpaid amount does not match the amount. Proceed?'),
351 disabled => !$may_edit_create ? t8('You must not change this invoice.')
352 : !$form->{id} ? t8('This invoice has not been posted yet.')
354 only_if => $::instance_conf->get_is_show_mark_as_paid && $form->{type} ne "invoice_for_advance_payment",
356 ], # end of combobox "Post"
359 action => [ t8('Storno'),
360 submit => [ '#form', { action => "storno" } ],
361 confirm => t8('Do you really want to cancel this invoice?'),
362 checks => [ 'kivi.validate_form' ],
363 disabled => !$may_edit_create ? t8('You must not change this invoice.')
364 : !$form->{id} ? t8('This invoice has not been posted yet.')
365 : $form->{storno} ? t8('Cannot storno storno invoice!')
366 : $form->{locked} ? t8('The billing period has already been locked.')
367 : !$payments_balanced ? t8('Cancelling is disallowed. Either undo or balance the current payments until the open amount matches the invoice amount')
370 action => [ t8('Delete'),
371 submit => [ '#form', { action => "delete" } ],
372 confirm => t8('Do you really want to delete this object?'),
373 checks => [ 'kivi.validate_form' ],
374 disabled => !$may_edit_create ? t8('You must not change this invoice.')
375 : !$form->{id} ? t8('This invoice has not been posted yet.')
376 : $form->{locked} ? t8('The billing period has already been locked.')
377 : $change_never ? t8('Changing invoices has been disabled in the configuration.')
378 : $change_on_same_day_only ? t8('Invoices can only be changed on the day they are posted.')
379 : $has_storno ? t8('Can only delete the "Storno zu" part of the cancellation pair.')
382 ], # end of combobox "Storno"
387 action => [ t8('Workflow') ],
390 submit => [ '#form', { action => "use_as_new" } ],
391 checks => [ 'kivi.validate_form' ],
392 disabled => !$may_edit_create ? t8('You must not change this invoice.')
393 : !$form->{id} ? t8('This invoice has not been posted yet.')
398 submit => [ '#form', { action => "credit_note" } ],
399 checks => [ 'kivi.validate_form' ],
400 disabled => !$may_edit_create ? t8('You must not change this invoice.')
401 : $form->{type} eq "credit_note" ? t8('Credit notes cannot be converted into other credit notes.')
402 : !$form->{id} ? t8('This invoice has not been posted yet.')
403 : $form->{storno} ? t8('A canceled invoice cannot be used. Please undo the cancellation first.')
408 submit => [ '#form', { action => "order" } ],
409 checks => [ 'kivi.validate_form' ],
410 disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
412 ], # end of combobox "Workflow"
415 action => [ t8('Export') ],
417 ($form->{id} ? t8('Print') : t8('Preview')),
418 call => [ 'kivi.SalesPurchase.show_print_dialog', $form->{id} ? 'print' : 'preview' ],
419 checks => [ 'kivi.validate_form' ],
420 disabled => !$may_edit_create ? t8('You must not print this invoice.')
421 : !$form->{id} && $form->{locked} ? t8('The billing period has already been locked.')
424 action => [ t8('Print and Post'),
425 call => [ 'kivi.SalesPurchase.show_print_dialog', 'print_and_post' ],
426 checks => [ 'kivi.validate_form' ],
427 confirm => t8('The invoice is not linked with a sales delivery order. Post anyway?') x !!$warn_unlinked_delivery_order,
428 disabled => !$may_edit_create ? t8('You must not change this invoice.')
429 : $form->{locked} ? t8('The billing period has already been locked.')
430 : $form->{storno} ? t8('A canceled invoice cannot be posted.')
431 : ($form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.')
432 : ($form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.')
433 : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
436 action => [ t8('E Mail'),
437 call => [ 'kivi.SalesPurchase.show_email_dialog' ],
438 checks => [ 'kivi.validate_form' ],
439 disabled => !$may_edit_create ? t8('You must not print this invoice.')
440 : !$form->{id} ? t8('This invoice has not been posted yet.')
441 : $form->{postal_invoice} ? t8('This customer wants a postal invoices.')
444 action => [ t8('Factur-X/ZUGFeRD'),
445 submit => [ '#form', { action => "download_factur_x_xml" } ],
446 checks => [ 'kivi.validate_form' ],
447 disabled => !$may_edit_create ? t8('You must not print this invoice.')
448 : !$form->{id} ? t8('This invoice has not been posted yet.')
449 : !$factur_x_enabled ? t8('Creating Factur-X/ZUGFeRD invoices is not enabled for this customer.')
452 ], # end of combobox "Export"
455 action => [ t8('more') ],
458 call => [ 'set_history_window', $form->{id} * 1, 'glid' ],
459 disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
463 call => [ 'follow_up_window' ],
464 disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
468 call => [ 'kivi.Draft.popup', 'is', 'invoice', $form->{draft_id}, $form->{draft_description} ],
469 disabled => !$may_edit_create ? t8('You must not change this invoice.')
470 : $form->{id} ? t8('This invoice has already been posted.')
471 : $form->{locked} ? t8('The billing period has already been locked.')
474 ], # end of combobox "more"
477 $::request->layout->add_javascripts('kivi.Validator.js');
481 $main::lxdebug->enter_sub();
485 my $form = $main::form;
486 my %myconfig = %main::myconfig;
487 my $locale = $main::locale;
488 my $cgi = $::request->{cgi};
493 $TMPL_VAR{customer_obj} = SL::DB::Customer->load_cached($form->{customer_id}) if $form->{customer_id};
494 $TMPL_VAR{invoice_obj} = SL::DB::Invoice->load_cached($form->{id}) if $form->{id};
496 # only print, no mail
497 $form->{postal_invoice} = $TMPL_VAR{customer_obj}->postal_invoice if ref $TMPL_VAR{customer_obj} eq 'SL::DB::Customer';
499 my $current_employee = SL::DB::Manager::Employee->current;
500 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
501 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
502 $form->{employee_id} ||= $current_employee->id;
503 $form->{salesman_id} ||= $current_employee->id;
505 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
507 $form->get_lists("taxzones" => ($form->{id} ? "ALL_TAXZONES" : "ALL_ACTIVE_TAXZONES"),
508 "currencies" => "ALL_CURRENCIES",
509 "price_factors" => "ALL_PRICE_FACTORS");
511 $form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted;
512 $form->{ALL_LANGUAGES} = SL::DB::Manager::Language->get_all_sorted;
515 my @old_project_ids = uniq grep { $_ } map { $_ * 1 } ($form->{"globalproject_id"}, map { $form->{"project_id_$_"} } 1..$form->{"rowcount"});
516 my @old_ids_cond = @old_project_ids ? (id => \@old_project_ids) : ();
518 if ($::instance_conf->get_customer_projects_only_in_sales) {
521 customer_id => $::form->{customer_id},
522 billable_customer_id => $::form->{customer_id},
527 and => [ active => 1, @customer_cond ],
531 $TMPL_VAR{ALL_PROJECTS} = SL::DB::Manager::Project->get_all_sorted(query => \@conditions);
532 $form->{ALL_PROJECTS} = $TMPL_VAR{ALL_PROJECTS}; # make projects available for second row drop-down in io.pl
533 $TMPL_VAR{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ or => [ id => $::form->{employee_id}, deleted => 0 ] ]);
534 $TMPL_VAR{ALL_SALESMEN} = SL::DB::Manager::Employee->get_all_sorted(query => [ or => [ id => $::form->{salesman_id}, deleted => 0 ] ]);
535 $TMPL_VAR{ALL_SHIPTO} = SL::DB::Manager::Shipto->get_all_sorted(query => [
536 or => [ trans_id => $::form->{"$::form->{vc}_id"} * 1, and => [ shipto_id => $::form->{shipto_id} * 1, trans_id => undef ] ]
538 $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all_sorted(query => [
540 cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
543 cp_id => $::form->{cp_id} * 1
548 # currencies and exchangerate
549 my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
550 my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
551 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
552 $form->{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
553 $TMPL_VAR{currencies} = NTI($::request->{cgi}->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
554 '-values' => \@values, '-labels' => \%labels,
555 '-onchange' => "document.getElementById('update_button').click();"
556 )) if scalar @values;
557 push @custom_hiddens, "forex";
558 push @custom_hiddens, "exchangerate" if $form->{forex};
560 $TMPL_VAR{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update};
561 $TMPL_VAR{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/;
563 # set option selected
564 foreach my $item (qw(AR)) {
565 $form->{"select$item"} =~ s/ selected//;
566 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
569 $TMPL_VAR{is_type_invoice_for_advance_payment} = $form->{type} eq "invoice_for_advance_payment";
570 $TMPL_VAR{is_type_credit_note} = $form->{type} eq "credit_note";
571 $TMPL_VAR{is_format_html} = $form->{format} eq 'html';
572 $TMPL_VAR{dateformat} = $myconfig{dateformat};
573 $TMPL_VAR{numberformat} = $myconfig{numberformat};
576 $TMPL_VAR{HIDDENS} = [qw(
577 id type queued printed emailed vc discount
578 title creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
579 max_dunning_level dunning_amount dunning_description
580 taxaccounts cursor_fokus
581 convert_from_do_ids convert_from_oe_ids convert_from_ar_ids useasnew
585 map { $_.'_rate', $_.'_description', $_.'_taxnumber', $_.'_tax_id' } split / /, $form->{taxaccounts}];
587 $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase kivi.Part kivi.CustomerVendor kivi.Validator ckeditor/ckeditor ckeditor/adapters/jquery kivi.io client_js));
589 $TMPL_VAR{payment_terms_obj} = get_payment_terms_for_invoice();
590 $form->{duedate} = $TMPL_VAR{payment_terms_obj}->calc_date(reference_date => $form->{invdate}, due_date => $form->{duedate})->to_kivitendo if $TMPL_VAR{payment_terms_obj};
592 setup_is_action_bar(\%TMPL_VAR);
596 print $form->parse_html_template("is/form_header", \%TMPL_VAR);
598 $main::lxdebug->leave_sub();
602 my @fields = qw(acc_trans_id gldate datepaid source memo paid AR_paid);
604 grep { $_->{paid} != 0 }
607 +{ map { ($_ => delete($::form->{"${_}_${idx}"})) } @fields }
608 } (1..$::form->{paidaccounts});
610 @payments = sort_by { DateTime->from_kivitendo($_->{datepaid}) } @payments;
612 $::form->{paidaccounts} = max scalar(@payments), 1;
614 foreach my $idx (1 .. scalar(@payments)) {
615 my $payment = $payments[$idx - 1];
616 $::form->{"${_}_${idx}"} = $payment->{$_} for @fields;
621 $main::lxdebug->enter_sub();
625 my $form = $main::form;
626 my %myconfig = %main::myconfig;
627 my $locale = $main::locale;
629 $form->{invtotal} = $form->{invsubtotal};
631 # tax, total and subtotal calculations
632 my ($tax, $subtotal);
633 $form->{taxaccounts_array} = [ split(/ /, $form->{taxaccounts}) ];
635 if( $form->{customer_id} && !$form->{taxincluded_changed_by_user} ) {
636 my $customer = SL::DB::Customer->load_cached($form->{customer_id});
637 $form->{taxincluded} = defined($customer->taxincluded_checked) ? $customer->taxincluded_checked : $myconfig{taxincluded_checked};
640 foreach my $item (@{ $form->{taxaccounts_array} }) {
641 if ($form->{"${item}_base"}) {
642 if ($form->{taxincluded}) {
643 $form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"}
644 / (1 + $form->{"${item}_rate"})), 2);
645 $form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2);
647 $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
648 $form->{invtotal} += $form->{"${item}_total"};
653 my $grossamount = $form->{invtotal};
654 $form->{invtotal} = $form->round_amount( $form->{invtotal}, 2, 1 );
655 $form->{rounding} = $form->round_amount(
656 $form->{invtotal} - $form->round_amount($grossamount, 2),
662 $form->{follow_ups} = FU->follow_ups('trans_id' => $form->{id}, 'not_done' => 1) || [];
663 $form->{follow_ups_unfinished} = ( sum map { $_->{due} * 1 } @{ $form->{follow_ups} } ) || 0;
670 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
671 $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
673 # Standard Konto für Umlaufvermögen
674 my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
676 for my $i (1 .. $form->{paidaccounts}) {
677 $form->{"changeable_$i"} = 1;
678 if (SL::DB::Default->get->payments_changeable == 0) {
680 $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
681 } elsif (SL::DB::Default->get->payments_changeable == 2) {
683 $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') ||
684 ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
687 #deaktivieren von gebuchten Zahlungen ausserhalb der Bücherkontrolle, vorher prüfen ob heute eingegeben
688 if ($form->date_closed($form->{"gldate_$i"})) {
689 $form->{"changeable_$i"} = 0;
692 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
693 if (!$form->{"AR_paid_$i"}) {
694 $form->{"selectAR_paid_$i"} =~ s/option>$accno_arap--(.*?)</option selected>$accno_arap--$1</;
696 $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
699 $totalpaid += $form->{"paid_$i"};
702 $form->{oldinvtotal} = $form->{invtotal};
704 $form->{ALL_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_all_sorted();
706 my $shipto_cvars = SL::DB::Shipto->new->cvars_by_config;
707 foreach my $var (@{ $shipto_cvars }) {
708 my $name = "shiptocvar_" . $var->config->name;
709 $var->value($form->{$name}) if exists $form->{$name};
712 print $form->parse_html_template('is/form_footer', {
713 is_type_invoice_for_advance_payment => ($form->{type} eq "invoice_for_advance_payment"),
714 is_type_credit_note => ($form->{type} eq "credit_note"),
715 totalpaid => $totalpaid,
716 paid_missing => $form->{invtotal} - $totalpaid,
717 print_options => setup_sales_purchase_print_options(),
718 show_storno => $form->{id} && !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar") && !$totalpaid,
719 show_delete => ($::instance_conf->get_is_changeable == 2)
720 ? ($form->current_date(\%myconfig) eq $form->{gldate})
721 : ($::instance_conf->get_is_changeable == 1),
722 today => DateTime->today,
723 vc_obj => $form->{customer_id} ? SL::DB::Customer->load_cached($form->{customer_id}) : undef,
724 shipto_cvars => $shipto_cvars,
726 ##print $form->parse_html_template('is/_payments'); # parser
727 ##print $form->parse_html_template('webdav/_list'); # parser
729 $main::lxdebug->leave_sub();
733 $::auth->assert('invoice_edit');
735 SL::DB::Invoice->new(id => $::form->{id})->load->mark_as_paid;
737 $::form->redirect($::locale->text("Marked as paid"));
741 # unless no lazy implementation of save draft without invdate
742 # set the current date like in version <= 3.4.1
743 $::form->{invdate} = DateTime->today->to_lxoffice;
748 $main::lxdebug->enter_sub();
752 my $form = $main::form;
753 my %myconfig = %main::myconfig;
755 my ($recursive_call) = @_;
757 $form->{print_and_post} = 0 if $form->{second_run};
758 my $taxincluded = $form->{taxincluded} ? "checked" : '';
761 if (($form->{previous_customer_id} || $form->{customer_id}) != $form->{customer_id}) {
762 $::form->{salesman_id} = SL::DB::Manager::Employee->current->id if exists $::form->{salesman_id};
764 IS->get_customer(\%myconfig, $form);
765 $::form->{billing_address_id} = $::form->{default_billing_address_id};
768 $form->{taxincluded} ||= $taxincluded;
770 if (!$form->{forex}) { # read exchangerate from input field (not hidden)
771 $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}) unless $recursive_call;
773 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
774 $form->{exchangerate} = $form->{forex} if $form->{forex};
776 for my $i (1 .. $form->{paidaccounts}) {
777 next unless $form->{"paid_$i"};
778 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
779 $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
780 $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
783 my $i = $form->{rowcount};
784 my $exchangerate = $form->{exchangerate} || 1;
786 # if last row empty, check the form otherwise retrieve new item
787 if ( ($form->{"partnumber_$i"} eq "")
788 && ($form->{"description_$i"} eq "")
789 && ($form->{"partsgroup_$i"} eq "")) {
791 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
796 IS->retrieve_item(\%myconfig, \%$form);
798 my $rows = scalar @{ $form->{item_list} };
800 $form->{"discount_$i"} = $form->parse_amount(\%myconfig, $form->{"discount_$i"}) / 100.0;
801 $form->{"discount_$i"} ||= $form->{customer_discount};
804 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
805 if( !$form->{"qty_$i"} ) {
806 $form->{"qty_$i"} = 1;
811 select_item(mode => 'IS', pre_entered_qty => $form->{"qty_$i"});
812 $::dispatcher->end_request;
816 my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
818 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
819 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
821 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
822 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
824 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
826 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
827 my $decimalplaces = max 2, length $1;
830 $form->{"sellprice_$i"} = $sellprice;
832 my $record = _make_record();
833 my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
834 my $best_price = $price_source->best_price;
835 my $best_discount = $price_source->best_discount;
838 $::form->{"sellprice_$i"} = $best_price->price;
839 $::form->{"active_price_source_$i"} = $best_price->source;
841 if ($best_discount) {
842 $::form->{"discount_$i"} = $best_discount->discount;
843 $::form->{"active_discount_source_$i"} = $best_discount->source;
846 # if there is an exchange rate adjust sellprice
847 $form->{"sellprice_$i"} /= $exchangerate;
850 $form->{"listprice_$i"} /= $exchangerate;
852 my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"});
853 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
854 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
855 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
857 $form->{creditremaining} -= $amount;
859 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice lastcost);
861 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
862 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100.0);
869 # ok, so this is a new part
870 # ask if it is a part or service item
872 if ( $form->{"partsgroup_$i"}
873 && ($form->{"partnumber_$i" } eq "")
874 && ($form->{"description_$i"} eq "")) {
876 $form->{"discount_$i"} = "";
880 $form->{"id_$i"} = 0;
885 $main::lxdebug->leave_sub();
889 $main::lxdebug->enter_sub();
891 my $form = $main::form;
892 my %myconfig = %main::myconfig;
893 my $locale = $main::locale;
895 $main::auth->assert('invoice_edit');
897 $form->mtime_ischanged('ar') ;
898 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
900 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
901 for my $i (1 .. $form->{paidaccounts}) {
902 if ($form->{"paid_$i"}) {
903 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
905 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
908 if ($form->{currency} ne $form->{defaultcurrency}) {
909 $form->{"exchangerate_$i"} = $form->{exchangerate}
910 if ($invdate == $datepaid);
911 $form->isblank("exchangerate_$i",
912 $locale->text('Exchangerate for payment missing!'));
914 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
915 if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
917 #Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen
918 # (Dient zur Prüfung ob ZE oder ZA geprüft werden soll)
919 $form->error($locale->text('Cannot post payment for a closed period!'))
920 if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
924 ($form->{AR}) = split /--/, $form->{AR};
925 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
927 if ( IS->post_payment(\%myconfig, \%$form) ) {
928 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
929 $form->{what_done} = 'invoice';
930 $form->{addition} = "PAYMENT POSTED";
932 $form->redirect($locale->text('Payment posted!'))
934 $form->error($locale->text('Cannot post payment!'));
937 $main::lxdebug->leave_sub();
941 $main::lxdebug->enter_sub();
943 my $form = $main::form;
944 my %myconfig = %main::myconfig;
945 my $locale = $main::locale;
947 $main::auth->assert('invoice_edit');
948 $form->mtime_ischanged('ar');
950 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
951 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
952 $form->isblank("customer_id", $locale->text('Customer missing!'));
953 $form->error($locale->text('Cannot post invoice for a closed period!'))
954 if ($form->date_closed($form->{"invdate"}, \%myconfig));
956 $form->{invnumber} =~ s/^\s*//g;
957 $form->{invnumber} =~ s/\s*$//g;
959 # if oldcustomer ne customer redo form
960 if (($form->{previous_customer_id} || $form->{customer_id}) != $form->{customer_id}) {
962 $::dispatcher->end_request;
965 if ($myconfig{mandatory_departments} && !$form->{department_id}) {
966 $form->{saved_message} = $::locale->text('You have to specify a department.');
971 if ($form->{second_run}) {
972 $form->{print_and_post} = 0;
975 remove_emptied_rows();
978 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
979 my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
981 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
982 if ($form->date_max_future($invdate, \%myconfig));
983 $form->error($locale->text('Cannot post invoice for a closed period!'))
984 if ($invdate <= $closedto);
986 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
987 if ($form->{currency} ne $form->{defaultcurrency});
989 for my $i (1 .. $form->{paidaccounts}) {
990 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
991 my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
993 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
995 $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
996 if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
998 #Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen
999 # (Dient zur Prüfung ob ZE oder ZA geprüft werden soll)
1000 $form->error($locale->text('Cannot post payment for a closed period!'))
1001 if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
1003 if ($form->{currency} ne $form->{defaultcurrency}) {
1004 $form->{"exchangerate_$i"} = $form->{exchangerate}
1005 if ($invdate == $datepaid);
1006 $form->isblank("exchangerate_$i",
1007 $locale->text('Exchangerate for payment missing!'));
1012 ($form->{AR}) = split /--/, $form->{AR};
1013 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1014 $form->{storno} ||= 0;
1016 $form->{label} = $form->{type} eq 'credit_note' ? $locale->text('Credit Note') : $locale->text('Invoice');
1018 $form->{id} = 0 if $form->{postasnew};
1020 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1021 if ($form->{postasnew}) {
1022 if ($form->{type} eq "credit_note") {
1023 undef($form->{cnnumber});
1025 undef($form->{invnumber});
1031 my $terms = get_payment_terms_for_invoice();
1032 $form->{duedate} = $terms->calc_date(reference_date => $form->{invdate}, due_date => $form->{duedate})->to_kivitendo if $terms;
1034 # If transfer_out is requested, get rose db handle and do post and
1035 # transfer out in one transaction. Otherwise just post the invoice.
1036 if ($::instance_conf->get_is_transfer_out && $form->{type} ne 'credit_note' && !$form->{storno}) {
1037 require SL::DB::Inventory;
1038 my $rose_db = SL::DB::Inventory->new->db;
1041 if (!$rose_db->with_transaction(sub {
1043 if (!IS->post_invoice(\%myconfig, \%$form, $rose_db->dbh)) {
1044 push @errors, $locale->text('Cannot post invoice!');
1045 die 'posting error';
1047 my $err = IS->transfer_out(\%$form, $rose_db->dbh);
1049 push @errors, @{ $err };
1050 die 'transfer error';
1055 push @errors, $EVAL_ERROR;
1056 $form->error($locale->text('Cannot post invoice and/or transfer out! Error message:') . "\n" . join("\n", @errors));
1061 push @errors, $rose_db->error;
1062 $form->error($locale->text('Cannot post invoice and/or transfer out! Error message:') . "\n" . join("\n", @errors));
1065 if (!IS->post_invoice(\%myconfig, \%$form)) {
1066 $form->error($locale->text('Cannot post invoice!'));
1070 if(!exists $form->{addition}) {
1071 $form->{snumbers} = 'invnumber' .'_'. $form->{invnumber}; # ($form->{type} eq 'credit_note' ? 'cnnumber' : 'invnumber') .'_'. $form->{invnumber};
1072 $form->{what_done} = 'invoice';
1073 $form->{addition} = $form->{print_and_post} ? "PRINTED AND POSTED" :
1074 $form->{storno} ? "STORNO" :
1076 $form->save_history;
1079 if (!$form->{no_redirect_after_post}) {
1080 $form->{action} = 'edit';
1081 $form->{script} = 'is.pl';
1082 $form->{callback} = build_std_url(qw(action edit id callback saved_message));
1083 $form->redirect($form->{label} . " $form->{invnumber} " . $locale->text('posted!'));
1086 $main::lxdebug->leave_sub();
1089 sub print_and_post {
1090 $main::lxdebug->enter_sub();
1092 my $form = $main::form;
1094 $main::auth->assert('invoice_edit');
1096 my $old_form = Form->new;
1097 $form->{no_redirect_after_post} = 1;
1098 $form->{print_and_post} = 1;
1102 $main::lxdebug->leave_sub();
1107 $main::lxdebug->enter_sub();
1109 my $form = $main::form;
1110 my %myconfig = %main::myconfig;
1112 $main::auth->assert('invoice_edit');
1114 delete @{ $form }{qw(printed emailed queued invnumber invdate exchangerate forex deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno locked)};
1115 $form->{rowcount}--;
1116 $form->{paidaccounts} = 1;
1117 $form->{invdate} = $form->current_date(\%myconfig);
1118 my $terms = get_payment_terms_for_invoice();
1119 $form->{duedate} = $terms ? $terms->calc_date(reference_date => $form->{invdate})->to_kivitendo : $form->{invdate};
1120 $form->{employee_id} = SL::DB::Manager::Employee->current->id;
1121 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1122 $form->{exchangerate} = $form->{forex} if $form->{forex};
1124 $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
1126 $form->{useasnew} = 1;
1129 $main::lxdebug->leave_sub();
1133 $main::lxdebug->enter_sub();
1135 my $form = $main::form;
1136 my %myconfig = %main::myconfig;
1137 my $locale = $main::locale;
1139 $main::auth->assert('invoice_edit');
1141 if ($form->{storno}) {
1142 $form->error($locale->text('Cannot storno storno invoice!'));
1145 if (IS->has_storno(\%myconfig, $form, "ar")) {
1146 $form->error($locale->text("Invoice has already been storno'd!"));
1148 if ($form->datetonum($form->{invdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)) {
1149 $form->error($locale->text('Cannot storno invoice for a closed period!'));
1152 # save the history of invoice being stornoed
1153 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1154 $form->{what_done} = 'invoice';
1155 $form->{addition} = "STORNO";
1156 $form->save_history;
1158 map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password type))); } keys(%{ $form }));
1164 # Payments must not be recorded for the new storno invoice.
1165 $form->{paidaccounts} = 0;
1166 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
1168 # record link invoice to storno
1169 $form->{convert_from_ar_ids} = $form->{id};
1170 $form->{storno_id} = $form->{id};
1171 $form->{storno} = 1;
1173 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1174 $form->{invdate} = DateTime->today->to_lxoffice;
1175 $form->{rowcount}++;
1176 # set new ids for storno invoice
1177 # set new persistent ids for storno invoice items
1178 $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
1181 $main::lxdebug->leave_sub();
1185 $main::lxdebug->enter_sub();
1187 my $form = $main::form;
1189 $main::auth->assert('invoice_edit');
1191 $form->{preview} = 1;
1192 my $old_form = Form->new;
1193 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1195 &print_form($old_form);
1196 $main::lxdebug->leave_sub();
1201 $main::lxdebug->enter_sub();
1203 my $form = $main::form;
1204 my %myconfig = %main::myconfig;
1205 my $locale = $main::locale;
1207 $main::auth->assert('invoice_edit');
1209 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1211 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1213 $form->{convert_from_ar_ids} = $form->{id};
1215 $form->{rowcount}--;
1218 $form->{title} = $locale->text('Add Credit Note');
1219 $form->{script} = 'is.pl';
1221 # Bei Gutschriften bezug zur Rechnungsnummer
1222 $form->{invnumber_for_credit_note} = $form->{invnumber};
1223 # bo creates the id, reset it
1224 map { delete $form->{$_} }
1225 qw(id invnumber subject message cc bcc printed emailed queued);
1226 $form->{ $form->{vc} } =~ s/--.*//g;
1227 $form->{type} = "credit_note";
1230 map { $form->{"select$_"} = "" } ($form->{vc}, 'currency');
1232 # map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1233 # qw(creditlimit creditremaining);
1235 # set new persistent ids for credit note and link previous invoice id
1236 $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
1238 my $currency = $form->{currency};
1241 $form->{currency} = $currency;
1242 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1243 $form->{exchangerate} = $form->{forex} || '';
1245 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1247 # bei Gutschriften werden Zahlungseingänge aus Rechnung nicht übernommen
1248 for my $i (1 .. $form->{paidaccounts}) {
1249 delete $form->{"paid_$i"};
1250 delete $form->{"source_$i"};
1251 delete $form->{"memo_$i"};
1252 delete $form->{"datepaid_$i"};
1253 delete $form->{"gldate_$i"};
1254 delete $form->{"acc_trans_id_$i"};
1255 delete $form->{"AR_paid_$i"};
1257 $form->{paidaccounts} = 1;
1264 $main::lxdebug->leave_sub();
1268 $::lxdebug->enter_sub;
1274 my $new_rowcount = $::form->{"rowcount"} * 1 + 1;
1275 $::form->{"project_id_${new_rowcount}"} = $::form->{"globalproject_id"};
1277 $::form->language_payment(\%::myconfig);
1279 Common::webdav_folder($::form);
1282 display_row(++$::form->{rowcount});
1285 $::lxdebug->leave_sub;
1289 $::auth->assert('invoice_edit');
1291 if (IS->delete_invoice(\%::myconfig, $::form)) {
1292 # saving the history
1293 if(!exists $::form->{addition}) {
1294 $::form->{snumbers} = 'invnumber' .'_'. $::form->{invnumber};
1295 $::form->{what_done} = 'invoice';
1296 $::form->{addition} = "DELETED";
1297 $::form->save_history;
1299 # /saving the history
1300 $::form->redirect($::locale->text('Invoice deleted!'));
1302 $::form->error($::locale->text('Cannot delete invoice!'));
1307 print update ship_to storno post_payment use_as_new credit_note
1308 delete post order preview post_and_e_mail print_and_post
1311 if ($::form->{"action_$action"}) {
1317 $::form->error($::locale->text('No action defined.'));