From: Bernd Bleßmann Date: Thu, 26 Feb 2015 14:35:13 +0000 (+0100) Subject: Auslagern in VK-Rechnung: Beim Buchen einer VK-Rechnung wird ausgelagert. X-Git-Tag: release-3.2.1~46 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=9d07c34f5b429bfc118629d74b376479c37a8383;p=kivitendo-erp.git Auslagern in VK-Rechnung: Beim Buchen einer VK-Rechnung wird ausgelagert. Todo: Es werden noch nicht alle Einstellungen berücksichtigt, die bestimmen, wann von welchem Lager/Lagerplatz ausgelagert wird. --- diff --git a/SL/IS.pm b/SL/IS.pm index 989330c90..6a8ef4635 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -1291,6 +1291,63 @@ SQL return $rc; } +sub transfer_out { + $::lxdebug->enter_sub; + + my ($self, $form) = @_; + + my @transfers; + + foreach my $i (1 .. $form->{rowcount}) { + next if !$form->{"id_$i"}; + my ($wh_id, $bin_id) = _determine_wh_and_bin($::instance_conf, $form->{"id_$i"}); + + if ($wh_id && $bin_id) { + push @transfers, { + 'parts_id' => $form->{"id_$i"}, + 'qty' => $form->{"qty_$i"}, + 'unit' => $form->{"unit_$i"}, + 'transfer_type' => 'shipped', + 'src_warehouse_id' => $wh_id, + 'src_bin_id' => $bin_id, + 'project_id' => $form->{"project_id_$i"}, + 'invoice_id' => $form->{"invoice_id_$i"}, + }; + } + } + + require SL::WH; + WH->transfer(@transfers); + + $::lxdebug->leave_sub; + return 1; +} + +sub _determine_wh_and_bin { + $::lxdebug->enter_sub(2); + + my ($conf, $part_id) = @_; + + my $part = SL::DB::Part->new(id => $part_id)->load; + + if ($part->is_service && !$conf->get_transfer_default_services) { + $::lxdebug->leave_sub(2); + return; + } + + + my $wh_id = $part->warehouse_id; + my $bin_id = $part->bin_id; + + if (!$wh_id && !$bin_id && $conf->get_transfer_default_ignore_onhand) { + $wh_id = $conf->get_warehouse_id_ignore_onhand; + $bin_id = $conf->get_bin_id_ignore_onhand; + } + + $::lxdebug->leave_sub(2); + return ($wh_id, $bin_id); +} + sub _delete_payments { $main::lxdebug->enter_sub(); diff --git a/SL/WH.pm b/SL/WH.pm index 5b24cfd70..a8c1ae3bf 100644 --- a/SL/WH.pm +++ b/SL/WH.pm @@ -110,7 +110,7 @@ sub transfer { trans_id => $trans_id, shippingdate => !$transfer->{shippingdate} || $transfer->{shippingdate} eq 'current_date' ? $now : $transfer->{shippingdate}, - map { $_ => $transfer->{$_} } qw( chargenumber bestbefore oe_id delivery_order_items_stock_id comment), + map { $_ => $transfer->{$_} } qw(chargenumber bestbefore oe_id delivery_order_items_stock_id invoice_id comment), ); if ($unit) { 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}) {