I have got a task that when we press Create Pick in the Warehouse Shipment the process will be that we must pick according to Expiration date then if we have the Item in 2 different bin we must get the one with higher ranking before looking at the lot No. or Package No.
[EventSubscriber(ObjectType::Codeunit, 7312, 'OnBeforeTempWhseActivLineInsert', '', false, false)]
local procedure FillRBinCode(var TempWarehouseActivityLine: Record "Warehouse Activity Line"; ActionType: Integer)
var
WarEntry: Record "Warehouse Entry";
i: Integer;
BinList: List of [Code[20]];
RankingList: List of [Integer];
BinContent: Record "Bin Content";
HighestBinRanking: Integer;
IndexOfHBR: Integer;
TempBinContent: Record "Bin Content";
ArrLength: Integer;
QuantityTempWhseActivityLine: Decimal;
TempWhseActLine: Record "Xee_Temporary Whse Pick Lines";
TempWhseActLineF: Record "Xee_Temporary Whse Pick Lines";
TotalQty: Decimal;
begin
if ActionType = TempWarehouseActivityLine."Action Type"::Take.AsInteger() then begin
WarEntry.SetCurrentKey("Location Code", "Item No.", "Lot No.", "Bin Type Code");
WarEntry.SetRange("Location Code", TempWarehouseActivityLine."Location Code");
WarEntry.SetRange("Item No.", TempWarehouseActivityLine."Item No.");
WarEntry.SetRange("Lot No.", TempWarehouseActivityLine."Lot No.");
WarEntry.SetRange("Package No.", TempWarehouseActivityLine."Package No.");
WarEntry.SetFilter(Quantity, '>0');
WarEntry.SetRange("Bin Type Code", 'PUTPICK');
if WarEntry.FindFirst() then
repeat
BinContent.SetFilter("Location Code", TempWarehouseActivityLine."Location Code");
BinContent.SetFilter("Bin Code", WarEntry."Bin Code");
BinContent.SetFilter("Item No.", WarEntry."Item No.");
BinContent.SetFilter("Variant Code", TempWarehouseActivityLine."Variant Code");
if BinContent.FindFirst() then
repeat
BinContent.CalcFields("Pick Qty.", Quantity, "Pick Quantity (Base)","Quantity (Base)");
if BinContent."Quantity (Base)" < TempWarehouseActivityLine."Qty. (Base)" then
begin
Error(Error_XeeZ);
end;
TotalQty := 0;
TempWhseActLineF.Reset();
TempWhseActLineF.SetFilter("Item No.", BinContent."Item No.");
TempWhseActLineF.SetRange("Bin Code", BinContent."Bin Code");
TempWhseActLineF.SetRange("Lot No.", TempWarehouseActivityLine."Lot No.");
TempWhseActLineF.SetRange("Package No.", TempWarehouseActivityLine."Package No.");
if TempWhseActLineF.FindLast() then;
if not (BinList.Contains(WarEntry."Bin Code")) and (TotalQty <> BinContent."Quantity (Base)")
then begin
BinList.Add(WarEntry."Bin Code");
RankingList.Add(BinContent."Bin Ranking");
end;
until BinContent.Next() = 0;
until WarEntry.next = 0;
HighestBinRanking := 0;
for i := 1 to RankingList.Count do begin
if RankingList.Get(i) > HighestBinRanking then begin
HighestBinRanking := RankingList.Get(i);
IndexOfHBR := i;
end;
end;
if IndexOfHBR <> 0 then begin
TempBinContent.SetFilter("Location Code", TempWarehouseActivityLine."Location Code");
TempBinContent.SetFilter("Bin Code", BinList.Get(IndexOfHBR));
TempBinContent.SetFilter("Item No.", WarEntry."Item No.");
TempBinContent.SetFilter("Variant Code", TempWarehouseActivityLine."Variant Code");
if TempBinContent.FindFirst() then begin
TempWarehouseActivityLine."Bin Code" := TempBinContent."Bin Code";
TempWarehouseActivityLine."Zone Code" := BinContent."Zone Code";
TempWarehouseActivityLine."Bin Ranking" := BinContent."Bin Ranking";
end;
end;
end;
end;
this code works when I have same expiration date and same Lot No., If I have same expiration but different Lot. No. the system will neglect the Bin Ranking and chooses to the smallest Lot No.