procedure UndoPostedProductionOrder(ProdOrderNo_P: Code[20]; ProdOrderLines_P: Integer; Qty_P: Decimal; BinCode: Code[20]; MobileUser_P: Code[10]): Text
var
ProdOrderLine: Record "Prod. Order Line";
ProdOrder: Record "Production Order";
ItemJournalLine: Record "Item Journal Line";
MfgSetup: Record "Manufacturing Setup";
ForReservEntry_L: Record "Reservation Entry";
ProductionJrnlMgt: Codeunit "Production Journal Mgt";
ItemJnlPostBatch: Codeunit "Item Jnl.-Post Batch";
CreateReservEntry_L: Codeunit "Create Reserv. Entry";
ProgressBar: Dialog;
GeneratingJnlLinesMsg: Label 'Generating journal lines for reversal.';
Status_L: Enum "Reservation Status";
ToTemplateName: Code[10];
ToBatchName: Code[10];
ErrorOrderLineNotExist: Label 'Prod. Order Line does not exist';
ErrorOrderNotExist: Label 'Production Order does not exist';
begin
if not ProdOrderLine.Get(ProdOrderLine.Status::Released, ProdOrderNo_P, ProdOrderLines_P) then
Error(ErrorOrderLineNotExist);
if not ProdOrder.Get(ProdOrder.Status::Released, ProdOrderNo_P) then
Error(ErrorOrderNotExist);
MfgSetup.Get();
ProductionJrnlMgt.SetTemplateAndBatchName();
ProductionJrnlMgt.InitSetupValues();
ProgressBar.Open(GeneratingJnlLinesMsg);
ProductionJrnlMgt.DeleteJnlLines(ToTemplateName, ToBatchName, ProdOrder."No.", ProdOrderLines_P);
ProductionJrnlMgt.CreateJnlLines(ProdOrder, ProdOrderLines_P);
ItemJournalLine.Reset();
if StrLen(UserId) > 10 then
ItemJournalLine.SetRange("Journal Batch Name", CopyStr(UserId, 1, 10))
else
ItemJournalLine.SetRange("Journal Batch Name", UserId);
ItemJournalLine.SetRange("Order Type", ItemJournalLine."Order Type"::Production);
ItemJournalLine.SetRange("Order No.", ProdOrderNo_P);
ItemJournalLine.SetRange("Order Line No.", ProdOrderLines_P);
if ItemJournalLine.FindSet() then begin
repeat
// ItemJournalLine.Validate("Stop Time", 0);
// ItemJournalLine.Validate("Setup Time", 0);
// ItemJournalLine.Validate("Bin Code", BinCode);
// ItemJournalLine.Modify();
if (ItemJournalLine."Entry Type" = ItemJournalLine."Entry Type"::Output) then begin
ItemJournalLine.Validate(Quantity, -Qty_P);
ItemJournalLine.Modify();
end else if (ItemJournalLine."Entry Type" = ItemJournalLine."Entry Type"::Consumption) then begin
ItemJournalLine.Validate("Entry Type", ItemJournalLine."Entry Type"::"Positive Adjmt.");
ItemJournalLine.Validate(Quantity, Qty_P);
ItemJournalLine.Modify();
CreateReservEntry_L.SetDates(0D, ForReservEntry_L."Expiration Date");
CreateReservEntry_L.CreateReservEntryFor(
Database::"Item Journal Line", ItemJournalLine."Entry Type".AsInteger(),
ItemJournalLine."Journal Template Name", ItemJournalLine."Journal Batch Name", 0, ItemJournalLine."Line No.", ItemJournalLine."Qty. per Unit of Measure",
Qty_P, Qty_P * ItemJournalLine."Qty. per Unit of Measure", ForReservEntry_L);
CreateReservEntry_L.CreateEntry(
ItemJournalLine."Item No.", ItemJournalLine."Variant Code", ItemJournalLine."Location Code", '', 0D, 0D, 0, Status_L::Surplus);
end;
until ItemJournalLine.Next() = 0;
end;
ItemJnlPostBatch.Run(ItemJournalLine);
ProgressBar.Close();
exit('');
end;