Every Cent of VAT
Round VAT per line and the invoice total drifts a cent or two from what the tax authority computes on the document totals; round per document and the cents have to be pushed back onto the lines somehow — and "somehow" is exactly where audits are lost. Your job is the allocation engine: compute VAT in both modes, and in document mode apportion each rate bucket's VAT back to its lines by largest remainder, so the lines always sum to exactly what the document owes.
Requirements
The starter contains a table named "VAT Allocation Line" — the in-memory document your code works on. Keep its fields and keys exactly as shipped; the grading tests seed it and read it back:
"Line No."—Integer, the primary key"VAT Rate"—Decimal, the line's VAT percentage"Line Amount"—Decimal, the net amount the VAT is computed from"VAT Amount"—Decimal, the output: the VAT your code assigns to the line
It also contains an enum named "VAT Rounding Mode" with the values "Per Line" and "Per Document" — keep it as shipped, too.
Create a codeunit named "VAT Allocation" with one public procedure:
procedure ComputeVat(var VatLine: Record "VAT Allocation Line"; Mode: Enum "VAT Rounding Mode"): DecimalRules:
- A line's raw VAT is
"Line Amount"×"VAT Rate"/ 100, unrounded. - Rounding to cents always means: to the nearest 0.01, an exact half cent rounding up (every amount in this task is non-negative).
- In Per Line mode each line's
"VAT Amount"is its own raw VAT rounded to the nearest cent — every line rounds independently, nothing else happens.
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
- 11 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