5081

The Cost Layer Engine

Algorithm
Hard
Pro
costing
fifo
lifo
rounding

The Cost Layer Engine

Business Central never costs inventory with one average number: every receipt opens a cost layer, every issue consumes layers in a defined order, and a revaluation restates what is still on the shelf. Your job is that machinery distilled to its core: a layer buffer, FIFO and LIFO application, per-issue COGS, and bookkeeping so exact that not a single cent ever appears or vanishes.

Requirements

The starter contains a table "Cost Layer" and an enum "Cost Flow Method" (values FIFO and LIFO). Keep both exactly as shipped — the grading tests seed and read the table and pass the enum values by name:

  • "Entry No." — Integer, the primary key
  • Quantity — Decimal, the quantity originally received; never changes after the receipt
  • "Remaining Quantity" — Decimal, what is still on the layer; 0 means the layer is consumed
  • "Unit Cost" — Decimal, the layer's current unit cost; revaluation restates it
  • "Remaining Value" — Decimal, the money value of the remaining quantity, always whole cents

Create a codeunit named "Cost Layer Engine" with three public procedures:

procedure PostReceipt(var CostLayer: Record "Cost Layer"; Quantity: Decimal; UnitCost: Decimal): Integer
procedure PostIssue(var CostLayer: Record "Cost Layer"; Quantity: Decimal; Method: Enum "Cost Flow Method"): Decimal
procedure Revalue(var CostLayer: Record "Cost Layer"; EntryNo: Integer; NewUnitCost: Decimal): Decimal

Whenever a rule below says an amount is rounded, it means AL's default Round to 0.01 — to the nearest cent, halves away from zero.

  1. PostReceipt appends a new layer and returns its entry no.: one above the highest existing "Entry No." (1 into an empty buffer). The layer stores Quantity and "Remaining Quantity" = the received quantity, "Unit Cost" as given, and "Remaining Value" = the received quantity times the unit cost, rounded.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 16 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade