use DateTime;
use List::MoreUtils qw(uniq);
use List::Util qw(max sum);
+use English qw(-no_match_vars);
use SL::DB::Default;
use SL::DB::Customer;
max_dunning_level dunning_amount
shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
shiptoemail shiptodepartment_1 shiptodepartment_2 shiptocp_gender message email subject cc bcc taxaccounts cursor_fokus
- convert_from_do_ids convert_from_oe_ids convert_from_ar_ids
+ convert_from_do_ids convert_from_oe_ids convert_from_ar_ids useasnew
+ invoice_id
show_details
), @custom_hiddens,
map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
- $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer));
+ $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part));
$form->header();
my $rows = scalar @{ $form->{item_list} };
- # Falls kein Kundenrabatt vorhanden ist, den aktuellen Rabatt nicht mit 0% überschreiben,
- # da hier der Anwender schon manual einen Wert eingetragen haben könnte (analog zu qty) Bugfix: 1412
- if ($form->{customer_discount}){
- $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{customer_discount} * 100);
- }
+ $form->{"discount_$i"} = $form->parse_amount(\%myconfig, $form->{"discount_$i"}) / 100.0;
+ $form->{"discount_$i"} ||= $form->{customer_discount};
if ($rows) {
$form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
if ($rows > 1) {
- select_item(mode => 'IS');
+ select_item(mode => 'IS', pre_entered_qty => $form->{"qty_$i"});
::end_of_request();
} else {
$form->{"listprice_$i"} /= $exchangerate;
- my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
+ my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"});
map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice lastcost);
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
+ $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
+ $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100.0);
}
&display_form;
}
relink_accounts();
- $form->error($locale->text('Cannot post invoice!'))
- unless IS->post_invoice(\%myconfig, \%$form);
+
+ # If transfer_out is requested, get rose db handle and do post and
+ # transfer out in one transaction. Otherwise just post the invoice.
+ if ($::instance_conf->get_is_transfer_out && $form->{type} ne 'credit_note' && !$form->{storno}) {
+ require SL::DB::Inventory;
+ my $rose_db = SL::DB::Inventory->new->db;
+ my @errors;
+
+ if (!$rose_db->with_transaction(sub {
+ if (!eval {
+ if (!IS->post_invoice(\%myconfig, \%$form, $rose_db->dbh)) {
+ push @errors, $locale->text('Cannot post invoice!');
+ die 'posting error';
+ }
+ my $err = IS->transfer_out(\%$form, $rose_db->dbh);
+ if (@{ $err }) {
+ push @errors, @{ $err };
+ die 'transfer error';
+ }
+
+ 1;
+ }) {
+ push @errors, $EVAL_ERROR;
+ die 'transaction error';
+ }
+
+ 1;
+ })) {
+ push @errors, $rose_db->error;
+ $form->error($locale->text('Cannot post invoice and/or transfer out! Error message:') . "\n" . join("\n", @errors));
+ }
+ } else {
+ if (!IS->post_invoice(\%myconfig, \%$form)) {
+ $form->error($locale->text('Cannot post invoice!'));
+ }
+ }
+
remove_draft() if $form->{remove_draft};
if(!exists $form->{addition}) {
$form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
$form->{exchangerate} = $form->{forex} if $form->{forex};
+ $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
+
+ $form->{useasnew} = 1;
&display_form;
$main::lxdebug->leave_sub();
$form->error($locale->text('Cannot storno invoice for a closed period!'));
}
+ # save the history of invoice being stornoed
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = "STORNO";
+ $form->save_history;
+
map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password type))); } keys(%{ $form }));
invoice_links();
$form->{invnumber} = "Storno zu " . $form->{invnumber};
$form->{invdate} = DateTime->today->to_lxoffice;
$form->{rowcount}++;
+ # set new ids for storno invoice
+ delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
post();
$main::lxdebug->leave_sub();
$form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"};
}
}
+ # set new persistent ids for credit note and link previous invoice id
+ $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
my $currency = $form->{currency};
&invoice_links;