{
 "slug": "accounts-payable-invoice-capture-0302",
 "uc": "UC-0302",
 "webhook": "twwp-accounts-payable-invoice-capture-0302",
 "workflow_id": "twwpuc0302",
 "gate": "the approver signs off (approved=true). A price or quantity mismatch always needs review, even if approved.",
 "tests": [
  {
   "case": "default",
   "input": {
    "email": "Subject: Invoice 77\nSupplier: Delta Office Supplies\nPO: PO-5001\nLine: Printer paper A4 | 10 | 4.5\nLine: Toner black | 2 | 60\nTax: 18%",
    "approved": true,
    "purchase_orders": {
     "PO-5001": [
      {
       "desc": "Printer paper A4",
       "qty": 10,
       "unit": 4.5
      },
      {
       "desc": "Toner black",
       "qty": 2,
       "unit": 55
      }
     ]
    }
   },
   "expected": {
    "status": "needs_review",
    "invoice": {
     "supplier": "Delta Office Supplies",
     "po": "PO-5001",
     "lines": [
      {
       "desc": "Printer paper A4",
       "qty": 10,
       "unit": 4.5
      },
      {
       "desc": "Toner black",
       "qty": 2,
       "unit": 60
      }
     ],
     "net": 165,
     "tax": 29.7,
     "total": 194.7
    },
    "mismatches": [
     "price Toner black: ordered 55, invoiced 60"
    ]
   }
  },
  {
   "case": "clean_unapproved",
   "input": {
    "email": "Supplier: Delta Office Supplies\nPO: PO-5002\nLine: Stapler | 3 | 8\nTax: 18%",
    "approved": false,
    "purchase_orders": {
     "PO-5002": [
      {
       "desc": "Stapler",
       "qty": 3,
       "unit": 8
      }
     ]
    }
   },
   "expected": {
    "status": "awaiting_approver",
    "invoice": {
     "supplier": "Delta Office Supplies",
     "po": "PO-5002",
     "lines": [
      {
       "desc": "Stapler",
       "qty": 3,
       "unit": 8
      }
     ],
     "net": 24,
     "tax": 4.32,
     "total": 28.32
    },
    "mismatches": []
   }
  },
  {
   "case": "clean_approved",
   "input": {
    "email": "Supplier: Delta Office Supplies\nPO: PO-5002\nLine: Stapler | 3 | 8\nTax: 18%",
    "approved": true,
    "purchase_orders": {
     "PO-5002": [
      {
       "desc": "Stapler",
       "qty": 3,
       "unit": 8
      }
     ]
    }
   },
   "expected": {
    "status": "routed_to_payment_local",
    "invoice": {
     "supplier": "Delta Office Supplies",
     "po": "PO-5002",
     "lines": [
      {
       "desc": "Stapler",
       "qty": 3,
       "unit": 8
      }
     ],
     "net": 24,
     "tax": 4.32,
     "total": 28.32
    },
    "match_ok": true
   }
  }
 ]
}