X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FWH.pm;h=158b216434e10c20d891f2585b8f02fe093aaf7a;hb=60dcd6c0c1abb2e06d31c4d46863fc09556ccd7b;hp=918607284edab0a4af3fe03fc57eff16946010f9;hpb=f4d3d78c7f58e7a991f34bfea9990569c6df5100;p=kivitendo-erp.git diff --git a/SL/WH.pm b/SL/WH.pm index 918607284..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,8 +810,9 @@ sub get_warehouse_report { "chargeid" => "c.id", "warehousedescription" => "w.description", "partunit" => "p.unit", - "stock_value" => "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", ); $form->{l_classification_id} = 'Y'; $form->{l_part_type} = 'Y'; @@ -1126,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__ @@ -1279,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