Gapless by Law
In most countries the tax auditor gets to run one very cheap query: sort the year's invoice numbers and look for holes. Every hole is a conversation — was an invoice destroyed, or did your software just burn the number when a posting crashed? The naive poster grabs the next number first and does the risky work afterwards, and every failed posting costs a number. The lawful poster assigns the final number at the last possible moment, inside the same indivisible write as the invoice itself, so a failed posting never consumes one. You build the lawful one.
The starter ships three finished data objects. Do not rename them or their fields — the grading tests bind to every name below character for character.
The objects you get
- Table
"Draft Invoice"— primary key"Draft No."(Code[20]); fields"Customer No."(Code[20]),Amount(Decimal),"Final Invoice No."(Integer,0until the draft is posted). - Table
"Final Invoice"— primary key"Invoice No."(Integer); fields"Draft No."(Code[20]),"Customer No."(Code[20]),Amount(Decimal). - Table
"Invoice Sequence"— primary key"Sequence Code"(Code[20]); field"Last Used No."(Integer).
Requirements
Implement both procedures in the codeunit "Gapless Poster":
procedure Post(DraftNo: Code[20]): Integer
procedure PostAll(): IntegerRules:
- Numbering — final invoice numbers come from the
"Invoice Sequence"row whose"Sequence Code"isINVOICE. Every posting attempt draws the row's current"Last Used No."plus one, and a successful posting saves the drawn number back to the row. If the row does not exist yet, the first successful posting uses1and creates the row with"Last Used No."1. - Posting a draft — a successful
Postcreates exactly one"Final Invoice"whose"Invoice No."is the drawn number, copies"Draft No.","Customer No."andAmountfrom the draft, stamps the draft's"Final Invoice No."with the same number, and returns that number. The draft record stays — posting never deletes drafts.
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