From 4b2e8d6817f9240e9a1fe9e95afb73aaa337c3df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Fri, 28 Aug 2020 17:20:38 +0200 Subject: [PATCH] =?utf8?q?Feature:=20Auslagern=20=C3=BCber=20Rechnung=20in?= =?utf8?q?kl.=20Seriennummer=20Lagermenge=20ber=C3=BCcksichtigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/IS.pm | 9 ++++++--- SL/WH.pm | 23 +++++++++++++++++------ locale/de/all | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/SL/IS.pm b/SL/IS.pm index c743f3bf0..a99b43f77 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -1462,7 +1462,7 @@ sub transfer_out { foreach my $i (1 .. $form->{rowcount}) { next if !$form->{"id_$i"}; - my ($err, $wh_id, $bin_id, $chargenumber); + my ($err, $qty, $wh_id, $bin_id, $chargenumber); if ($::instance_conf->get_sales_serial_eq_charge) { next unless $form->{"serialnumber_$i"}; @@ -1472,8 +1472,11 @@ sub transfer_out { last; } foreach my $serial (@serials) { - ($wh_id, $bin_id, $chargenumber) = WH->get_wh_and_bin_for_charge(chargenumber => $serial); - + ($qty, $wh_id, $bin_id, $chargenumber) = WH->get_wh_and_bin_for_charge(chargenumber => $serial); + if (!$qty) { + push @errors, $::locale->text("Not enough in stock for the serial number #1", $serial); + last; + } push @transfers, { 'parts_id' => $form->{"id_$i"}, 'qty' => 1, diff --git a/SL/WH.pm b/SL/WH.pm index 979d4de19..158b21643 100644 --- a/SL/WH.pm +++ b/SL/WH.pm @@ -1135,15 +1135,25 @@ sub get_wh_and_bin_for_charge { my $self = shift; my %params = @_; + my %bin_qty; croak t8('Need charge number!') unless $params{chargenumber}; - my $inv_item= SL::DB::Manager::Inventory->get_first(where => [chargenumber => $params{chargenumber} ]); + my $inv_items = SL::DB::Manager::Inventory->get_all(where => [chargenumber => $params{chargenumber} ]); - croak t8("Invalid charge number: #1", $params{chargenumber}) unless (ref $inv_item eq 'SL::DB::Inventory'); + croak t8("Invalid charge number: #1", $params{chargenumber}) unless (ref @{$inv_items}[0] eq 'SL::DB::Inventory'); + # add all qty for one bin and add wh_id + ($bin_qty{$_->bin_id}{qty}, $bin_qty{$_->bin_id}{wh}) = ($bin_qty{$_->bin_id}{qty} + $_->qty, $_->warehouse_id) for @{ $inv_items }; + + while (my ($bin, $value) = each (%bin_qty)) { + if ($value->{qty} > 0) { + $main::lxdebug->leave_sub(); + return ($value->{qty}, $value->{wh}, $bin, $params{chargenumber}); + } + } $main::lxdebug->leave_sub(); - return ($inv_item->warehouse_id, $inv_item->bin_id, $inv_item->chargenumber); + return undef; } 1; @@ -1301,10 +1311,11 @@ The typical params would be: =head2 get_wh_and_bin_for_charge C<$params{chargenumber}> -Gets the first inventory entry with the mandatory chargenumber: C<$params{chargenumber}>. +Gets the current qty from the inventory entries with the mandatory chargenumber: C<$params{chargenumber}>. Croaks if the chargenumber is missing or no entry currently exists. -From the found inventory entry the following values and in this order are returned: -C, C, C. +If there is one bin and warehouse with a positive qty, this fields are returned: +C C, C, C. +Otherwise returns undef. =head3 Prerequisites diff --git a/locale/de/all b/locale/de/all index 04b0e2406..859b7bd31 100755 --- a/locale/de/all +++ b/locale/de/all @@ -2123,6 +2123,7 @@ $self->{texts} = { 'Not Discountable' => 'Nicht rabattierfähig', 'Not delivered' => 'Nicht geliefert', 'Not done yet' => 'Noch nicht fertig', + 'Not enough in stock for the serial number #1' => 'Nicht genug auf Lager von der Seriennummer #1', 'Not obsolete' => 'Gültig', 'Note' => 'Hinweis', 'Note that parameter names must not be quoted.' => 'Beachten Sie, dass Parameternamen nicht in Anführungszeichen stehen dürfen.', -- 2.20.1