X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=bin%2Fmozilla%2Fis.pl;h=a83f7718082ced86e42c65d66d04669604cb9e09;hb=2f6636f68edda5b8a47afd16fda868033a7076ec;hp=4adc9f7083620e5b905840eb316fe9c6f1303d6d;hpb=ed76c91e9b0870269fd66b3b6d13dbeb68c9c153;p=kivitendo-erp.git diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 4adc9f708..a83f77180 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -39,6 +39,7 @@ use Data::Dumper; 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; @@ -380,7 +381,7 @@ sub form_header { 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, @@ -553,11 +554,8 @@ sub update { 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"}); @@ -567,7 +565,7 @@ sub update { if ($rows > 1) { - select_item(mode => 'IS'); + select_item(mode => 'IS', pre_entered_qty => $form->{"qty_$i"}); ::end_of_request(); } else { @@ -608,7 +606,7 @@ sub update { $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}; @@ -617,7 +615,8 @@ sub update { 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; @@ -778,8 +777,43 @@ sub post { } 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}) { @@ -834,8 +868,10 @@ sub use_as_new { $form->{employee_id} = SL::DB::Manager::Employee->current->id; $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy'); $form->{exchangerate} = $form->{forex} if $form->{forex}; - delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"}; + $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"}; + + $form->{useasnew} = 1; &display_form; $main::lxdebug->leave_sub(); @@ -983,11 +1019,6 @@ sub credit_note { # map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } # qw(creditlimit creditremaining); - for my $i (1 .. $form->{rowcount}) { - for (qw(listprice)) { - $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"};