Hi everyone,
I want to do some control in the sales orders posting.
Let’s say I have an order with 5 lines, and the 3rd line presents a negative inventory.
I want to be able to block the posting of the whole sales order (no shipment header or lines are generated).
How can I do that?
I tried to do some workaround in CU 22 in the function InsertItemLedgEntry
.
.
.
//this is standard code
IF “Job No.” <> ‘’ THEN BEGIN
ItemLedgEntry.“Job No.” := “Job No.”;
ItemLedgEntry.“Job Task No.” := “Job Task No.”;
END;
//my code starts here
IF ((ItemLedgEntry.“Entry Type” IN
[ItemLedgEntry.“Entry Type”::“Negative Adjmt.”,
ItemLedgEntry.“Entry Type”::Sale,ItemLedgEntry.“Entry Type”::Purchase
]) AND (ItemLedgEntry.Quantity <0) )THEN
BEGIN
lItem.GET(ItemLedgEntry.“Item No.”);
lItem.SETFILTER(“Location Filter”,ItemLedgEntry.“Location Code”);
lItem.CALCFIELDS(Inventory);
END;
IF (lItem.Inventory < ABS(ItemLedgEntry.Quantity)) THEN
ERROR(Error0001, lItem.“No.”,ABS(ItemLedgEntry.Quantity),lItem.Inventory);
END;
//my code ends here
//this is standard code
ItemLedgEntry.INSERT;
InsertItemReg(ItemLedgEntry.“Entry No.”,0,0,0);
END;
With this code, I get the error message and the posting stops, but when I look at table 32 (Item Ledger entry), I find that the two lines (with no negative inventory) have been posted.
How shall I do to prevent the posting of the whole order if there is one or more lines with negative inventory?
Thanks in advance