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"};
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,
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;
=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<warehouse_id>, C<bin_id>, C<chargenumber>.
+If there is one bin and warehouse with a positive qty, this fields are returned:
+C<qty> C<warehouse_id>, C<bin_id>, C<chargenumber>.
+Otherwise returns undef.
=head3 Prerequisites
'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.',