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 keyQuantity—Decimal, the quantity originally received; never changes after the receipt"Remaining Quantity"—Decimal, what is still on the layer;0means 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): DecimalWhenever 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.
PostReceiptappends a new layer and returns its entry no.: one above the highest existing"Entry No."(1into an empty buffer). The layer storesQuantityand"Remaining Quantity"= the received quantity,"Unit Cost"as given, and"Remaining Value"= the received quantity times the unit cost, rounded.
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.
Already on Pro? Sign in