Item Ledger Entry - OnAfterGetRecord() ValueEntry.SETRANGE("Item Ledger Entry No.","Entry No."); CalcRemainingQty; IF "Remaining Quantity" <> 0 THEN BEGIN IF Item."Costing Method" = Item."Costing Method"::Average THEN TotalInvtValue := AverageCost * TotalInvtQty ELSE BEGIN CalcUnitCost; TotalInvtValue := UnitCost * TotalInvtQty; END; FOR i := 1 TO 5 DO IF ("Posting Date" > PeriodStartDate[i]) AND ("Posting Date" <= PeriodStartDate[i + 1]) THEN IF Item."Costing Method" = Item."Costing Method"::Average THEN InvtValue[i] := AverageCost * InvtQty[i]; END;
CalcUnitCost() WITH ValueEntry DO BEGIN TotalInvoicedQty := 0; ExpectedUnitCost := 0; UnitCost := 0; FOR i := 1 TO 5 DO BEGIN InvtValue[i] := 0; ExpectedInvtValue[i] := 0; END; IF FIND('-') THEN BEGIN REPEAT TotalInvoicedQty := TotalInvoicedQty + "Invoiced Quantity"; FOR i := 1 TO 5 DO IF ("Posting Date" > PeriodStartDate[i]) AND ("Posting Date" <= PeriodStartDate[i + 1]) THEN BEGIN InvtValue[i] := InvtValue[i] + "Cost Amount (Actual)"; ExpectedInvtValue[i] := ExpectedInvtValue[i] + "Cost Amount (Expected)" END; ExpectedUnitCost := ExpectedUnitCost + "Cost Amount (Expected)"; UnitCost := UnitCost + "Cost Amount (Actual)"; UNTIL NEXT = 0; IF TotalInvoicedQty <> 0 THEN UnitCost := UnitCost / TotalInvoicedQty; ExpectedUnitCost := ExpectedUnitCost / "Item Ledger Entry".Quantity; END; IF TotalInvoicedQty <> "Item Ledger Entry".Quantity THEN BEGIN UnitCost := ExpectedUnitCost; FOR i := 1 TO 5 DO InvtValue[i] := ExpectedInvtValue[i]; END; END;
Item Ledger Entry - OnAfterGetRecord() ValueEntry.SETRANGE("Item Ledger Entry No.","Entry No."); CalcRemainingQty; IF "Remaining Quantity" <> 0 THEN BEGIN IF Item."Costing Method" = Item."Costing Method"::Average THEN TotalInvtValue := AverageCost * TotalInvtQty ELSE BEGIN CalcUnitCost; TotalInvtValue := UnitCost * TotalInvtQty; FOR i := 1 TO 5 DO InvtValue[i] := UnitCost * InvtQty[i]; END; FOR i := 1 TO 5 DO IF ("Posting Date" > PeriodStartDate[i]) AND ("Posting Date" <= PeriodStartDate[i + 1]) THEN IF Item."Costing Method" = Item."Costing Method"::Average THEN InvtValue[i] := AverageCost * InvtQty[i]; END;
Comments
In order to tie to the G/L and the actual inventory valuation, you'll need to copy and paste the AdjustItemLedgEntryToAsOfDate function from the Inventory Valuation report to this report.
Then you would call the function to backdate the item ledger to the As of Date.
Takes a bit of figuring out, but it's doable.
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book