Purchase Invoice OCR
Upload Supplier Invoice PDF
Upload a supplier invoice PDF to start the OCR extraction. Requires Invoice OCR to be enabled in Settings → Invoice OCR (returns 422 if not enabled).
Get Extraction
Retrieve a purchase invoice OCR extraction record. Returns extracted header data merged with matched supplier and PO info, line items with per-line product matches (5-tier match: supplier_sku → SKU → barcode → MPN → fuzzy name), candidate purchase orders for the supplier (with attach-to-existing-invoice metadata), error_message (if failed/duplicate), and inbound-email source metadata.
Delete Extraction
Delete a purchase invoice OCR extraction record and its associated PDF. Confirmed extractions cannot be deleted (returns 422).
Stream Extraction PDF
Stream the original supplier invoice PDF through the backend (avoids CORS when fetching from S3). Returns Content-Type: application/pdf, inline disposition. 404 if the underlying S3 object is missing.
Create Purchase Invoice from Extraction
Accept the reviewed/edited extraction data (header + lines + cost lines) and create a PurchaseInvoice record, marking the extraction as 'confirmed'. The extraction must be in `pending_review` or `duplicate_detected` status (a duplicate-detected extraction is allowed because the user may confirm it is not actually a duplicate and proceed to create a new invoice).
Attach OCR Document to Existing Invoice
Attach the OCR'd PDF to an existing PurchaseInvoice that does not yet have a document. Used when the OCR extraction's PO number matches a PO that has already been invoiced — instead of creating a new invoice, the user can retroactively attach the extracted PDF to the prior invoice as the supporting document.
Re-scan Extraction
Re-dispatch the OCR extraction job for an existing PurchaseInvoiceOcrExtraction. Resets status to 'processing', clears any previous error_message, and re-queues the ProcessSupplierInvoiceEmailOcrJob against the original PDF in S3. Useful when Azure misread the document (wrong supplier match, missing lines) and the user wants to re-run extraction without re-uploading.
Reclassify as Customer PO
Reclassify a Supplier Invoice OCR extraction as a Customer PO. Used when an inbound email was routed to invoices@ but the attached PDF is actually a customer purchase order — the inverse of POST /api/sales-orders/ocr/{id}/reclassify-as-supplier-invoice.