Three-Way Match with Tolerances
Accounts payable never pays an invoice on the vendor's word alone: every invoice line must be proven against what was ordered (the purchase order fixes the agreed price) and what actually arrived (the receipts fix the quantity on the dock). That control is the classic three-way match — and real vendors make it messy: deliveries split across several receipts, prices a cent off, a little over-invoicing that is fine in total but suspicious in any single slice. Your job is the matching engine with the tolerance rules that separate noise from real exceptions.
Requirements
The starter ships three tables and an enum — keep their fields, keys and values exactly as shipped; the grading tests seed them and read them back:
- Table
"Match PO Line"— one row per item on the purchase order:"Item No."(Code[20], primary key) and"Unit Cost"(Decimal, the agreed price). - Table
"Match Receipt"— one row per receipt of an item:"Receipt No."(Code[20], primary key),"Item No."(Code[20]),"Receipt Date"(Date),Quantity(Decimal, what arrived) and"Matched Quantity"(Decimal, what your code has consumed — arrives as0). - Table
"Match Invoice Line"— one row per invoice line:"Line No."(Integer, primary key),"Item No."(Code[20]),Quantity(Decimal, what the vendor bills),"Unit Cost"(Decimal, the billed price),"Matched Quantity"(Decimal, arrives as0) andVerdict(Enum "Match Verdict", arrives blank). - Enum
"Match Verdict"— values" "(blank),Matched,"Price Exception","Qty Exception","No Receipt".
Create a codeunit named "Three-Way Match" with one public procedure:
procedure MatchInvoice(var MatchPOLine: Record "Match PO Line"; var MatchReceipt: Record "Match Receipt"; var MatchInvoiceLine: Record "Match Invoice Line")Rules:
- Process the invoice lines in ascending
"Line No."order. - Each line allocates quantity from the receipts of its own item, oldest first: ascending
"Receipt Date", ties broken by ascending"Receipt No.". The physical order of rows in either buffer must never influence the result.
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
- 19 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