X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Fis.pl;fp=bin%2Fmozilla%2Fis.pl;h=0bcd3c3609c8b4711a7f2f463d89cf72895894f1;hb=9d07c34f5b429bfc118629d74b376479c37a8383;hp=95185519eaeb1284aead6ed4443d1d3fd8759618;hpb=40ebe601936458cebc78a48a20b2cc5e67f6c1da;p=kivitendo-erp.git diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 95185519e..0bcd3c360 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; @@ -778,8 +779,34 @@ 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) { + require SL::DB::Inventory; + my $rose_db = SL::DB::Inventory->new->db; + my $error; + + if (!$rose_db->with_transaction(sub { + if (!eval { + IS->post_invoice(\%myconfig, \%$form, $rose_db->dbh); + IS->transfer_out(\%$form); + 1; + }) { + $error = $EVAL_ERROR; + return; + } + + 1; + })) { + $form->error($locale->text("Cannot post invoice and/or transfer out!\nError was:\n") . $locale->text($error)); + } + } else { + if (!IS->post_invoice(\%myconfig, \%$form)) { + $form->error($locale->text('Cannot post invoice!')); + } + } + remove_draft() if $form->{remove_draft}; if(!exists $form->{addition}) {