LotNoInfo.Reset();
LotNoInfo.CalcFields(Inventory);
LotNoInfo.SetFilter(Inventory, '>0');
if LotNoInfo.FindSet() then
repeat
LotNoInfo.CalcFields(Inventory);
if ((LotNoInfo."Expire Date" <= TodayDate) or
(LotNoInfo."Retest Date" <= TodayDate)) and
(LotNoInfo.Inventory > 0) then begin
ItemLedgEntry.Reset();
ItemLedgEntry.SetRange("Item No.", LotNoInfo."Item No.");
ItemLedgEntry.SetRange("Lot No.", LotNoInfo."Lot No.");
ItemLedgEntry.SetFilter("Remaining Quantity", '>0');
if ItemLedgEntry.FindSet() then
repeat
WarehouseEntry.Reset();
WarehouseEntry.SetRange("Item No.", ItemLedgEntry."Item No.");
WarehouseEntry.SetRange("Lot No.", ItemLedgEntry."Lot No.");
WarehouseEntry.SetRange("Location Code", ItemLedgEntry."Location Code");
WarehouseEntry.SetRange("Reference No.", ItemLedgEntry."Document No.");
if WarehouseEntry.FindLast() and (WarehouseEntry."Bin Code" <> '') then begin
LineNo += 10000;
ItemReclassJournalLine.Init();
ItemReclassJournalLine."Entry Type" := ItemReclassJournalLine."Entry Type"::Transfer;
ItemReclassJournalLine."Journal Template Name" := ItemReclassJournalTemplate.Name;
ItemReclassJournalLine."Journal Batch Name" := ItemReclassJournalBatch.Name;
ItemReclassJournalLine."Line No." := LineNo;
ItemReclassJournalLine."Posting Date" := TodayDate;
ItemReclassJournalLine."Document No." := CurrentDocumentNo;
ItemReclassJournalLine.Validate("Item No.", LotNoInfo."Item No.");
ItemReclassJournalLine.Validate("Location Code", ItemLedgEntry."Location Code");
ItemReclassJournalLine.Validate("Variant Code", ItemLedgEntry."Variant Code");
ItemReclassJournalLine.Description := 'asdf';
Quantity := ABS(ItemLedgEntry."Remaining Quantity");
ItemReclassJournalLine.Validate(Quantity, Quantity);
ItemReclassJournalLine.Validate("New Location Code", 'asdf');
ItemReclassJournalLine.Validate("New Bin Code", 'asdf');
ItemReclassJournalLine.Validate("Lot No.", LotNoInfo."Lot No.");
ItemReclassJournalLine.Validate("New Lot No.", LotNoInfo."Lot No.");
ItemReclassJournalLine.Validate("Bin Code", WarehouseEntry."Bin Code");
ItemReclassJournalLine.Insert();
CreateReservationEntry(ItemReclassJournalLine, LotNoInfo."Lot No.", Quantity);
end;
until ItemLedgEntry.Next() = 0;
end;
until LotNoInfo.Next() = 0;
end;
local procedure CreateReservationEntry(ItemReclassJournalLine: Record "Item Journal Line"; LotNo: Code[50]; Quantity: Decimal)
var
ReservEntry: Record "Reservation Entry";
EntryNo: Integer;
begin
Quantity := ABS(Quantity);
EntryNo := 0;
ReservEntry.Reset();
if ReservEntry.FindLast() then
EntryNo := ReservEntry."Entry No.";
EntryNo += 1;
ReservEntry.Init();
ReservEntry."Entry No." := EntryNo;
ReservEntry."Item No." := ItemReclassJournalLine."Item No.";
ReservEntry."Location Code" := ItemReclassJournalLine."Location Code";
ReservEntry."Quantity (Base)" := Quantity;
ReservEntry."Reservation Status" := ReservEntry."Reservation Status"::Surplus;
ReservEntry."Creation Date" := WorkDate();
ReservEntry."Source Type" := DATABASE::"Item Journal Line";
ReservEntry."Source Subtype" := ItemReclassJournalLine."Entry Type".AsInteger();
ReservEntry."Source ID" := ItemReclassJournalLine."Journal Template Name";
ReservEntry."Source Batch Name" := ItemReclassJournalLine."Journal Batch Name";
ReservEntry."Source Ref. No." := ItemReclassJournalLine."Line No.";
ReservEntry."Lot No." := LotNo;
ReservEntry."New Lot No." := LotNo;
ReservEntry.Validate("Item Tracking", ReservEntry."Item Tracking"::"Lot No.");
ReservEntry."Qty. per Unit of Measure" := ItemReclassJournalLine."Qty. per Unit of Measure";
ReservEntry.Positive := false;
ReservEntry.Insert();
end;