X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FWH.pm;h=158b216434e10c20d891f2585b8f02fe093aaf7a;hb=7520cd583a92860e2a33ee0b3155fd1695cc21bf;hp=dacddcca274d8df1fc6223ee8a1ed72fd122d479;hpb=be8c4415c90cb11cbf45132b63482f420b41070b;p=kivitendo-erp.git diff --git a/SL/WH.pm b/SL/WH.pm index dacddcca2..158b21643 100644 --- a/SL/WH.pm +++ b/SL/WH.pm @@ -35,9 +35,13 @@ package WH; +use Carp qw(croak); + use SL::AM; use SL::DBUtils; +use SL::DB::Inventory; use SL::Form; +use SL::Locale::String qw(t8); use SL::Util qw(trim); use warnings; @@ -56,7 +60,6 @@ sub transfer { require SL::DB::TransferType; require SL::DB::Part; require SL::DB::Employee; - require SL::DB::Inventory; my $employee = SL::DB::Manager::Employee->find_by(login => $::myconfig{login}); my ($now) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT current_date|); @@ -807,7 +810,7 @@ sub get_warehouse_report { "chargeid" => "c.id", "warehousedescription" => "w.description", "partunit" => "p.unit", - "stock_value" => $form->{stock_value_basis} eq 'list_price' ? "p.listprice / COALESCE(pfac.factor, 1)" : "p.lastcost / COALESCE(pfac.factor, 1)", + "stock_value" => ($form->{stock_value_basis} // '') eq 'list_price' ? "p.listprice / COALESCE(pfac.factor, 1)" : "p.lastcost / COALESCE(pfac.factor, 1)", "purchase_price" => "p.lastcost", "list_price" => "p.listprice", ); @@ -1127,6 +1130,31 @@ $main::lxdebug->enter_sub(); return ($max_qty_parts, $error); } +sub get_wh_and_bin_for_charge { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + my %bin_qty; + + croak t8('Need charge number!') unless $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_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 undef; +} 1; __END__ @@ -1280,6 +1308,16 @@ The typical params would be: 'comment' => $form->{comment} ); + +=head2 get_wh_and_bin_for_charge 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. +If there is one bin and warehouse with a positive qty, this fields are returned: +C C, C, C. +Otherwise returns undef. + + =head3 Prerequisites All of these prerequisites have to be trueish, otherwise the function will exit