5092

Three-Way Match with Tolerances

Algorithm
Hard
Pro
matching
tolerances
allocation

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 as 0).
  • 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 as 0) and Verdict (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:

  1. Process the invoice lines in ascending "Line No." order.
  2. 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.
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
  • 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.

$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