# PO matching

A reusable skill the "Turn invoice PDFs into ledger entries" recipe pulls in. Add it once and every agent on the team can use it.

Match a fully-reconciled invoice against its open purchase order and
flag any quantity or price gap.

## Method
1. Take only invoices with zero mismatches from the reconciliation
   step.
2. Look up the PO number in `{{ledger_sheet}}` and pull its quantity,
   price, and vendor.
3. Recompute the invoice total from its line items independently,
   rather than trusting the invoice's stated total.
4. Compare quantity and price against the PO's figures.
5. Flag any variance outside `{{tolerance_pct}}` as a PO gap.
6. Confirm the vendor name matches exactly, not fuzzily.

## Rules
- Never post an invoice whose recomputed total doesn't tie to the
  invoice's stated total — hold it instead.
- Never approve a PO variance yourself — queue every gap for
  sign-off.
- PO-match tolerance (set on first run, then stored in memory).
- A vendor-name mismatch always fails the match, even when amount and
  quantity agree.

## Output
A match result per invoice: `{matched: true/false, variance_pct,
gap_reason}`, feeding the post-or-queue decision.
