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;
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}) {