Landed Cost Invoice OCR
List Extractions (Inbox)
List landed cost invoice OCR extractions for the inbox queue. Requires Bearer token. Returns a paginated `LengthAwarePaginator` of `LandedCostInvoiceOcrExtractionResource` items. All filters are optional. Useful for the OCR Inbox page that surfaces freight/customs/brokerage/insurance invoices awaiting review.
Upload Landed Cost Invoice PDF
Upload a landed cost invoice PDF to start OCR extraction. Requires Invoice OCR to be enabled in Settings β Invoice OCR (returns 422 if not enabled).
Get Extraction
Retrieve a landed cost invoice OCR extraction record. Eager-loads the matched supplier and any extractionβbill pivots created during apply. Returns extracted header data merged with matched supplier info, line items with per-line cost-category matches (6-tier match: mapped β exact_name β name_substring β keyword β fuzzy_name β fuzzy_mapped β unmatched), candidate targets (inbound shipments / POs / warehouse transfers that fit the supplier + ETA window), and inbound-email source metadata.
Delete Extraction
Soft-delete a landed cost invoice OCR extraction record (and its associated S3 PDF). Confirmed extractions cannot be deleted (returns 422).
Stream Extraction PDF
Stream the original landed cost invoice PDF through the backend (avoids CORS when fetching from S3). Returns Content-Type: application/pdf, `Content-Disposition: inline; filename='landed-cost-invoice.pdf'`. Returns 404 if the underlying S3 object is missing. Cache-Control: private, max-age=300.
Apply Extraction (Create Bills)
Accept the reviewed/edited extraction and create one or more `Bill` records β one per target entity (inbound shipment, purchase order, or warehouse transfer) β each with its own apportionment of the cost lines. Marks the extraction as `confirmed` and persists `Bill` rows linked via the polymorphic `bills.link_type` / `link_id` columns. Bridges supplier β vendor via `VendorRepository::firstOrCreateByName($supplier->name)` since Bills require `vendor_id`.
Re-scan Extraction
Re-run Azure Document Intelligence OCR on the original PDF (e.g., after Azure model improvements, or to retry a failed extraction). Async β returns a `tracked_job_log_id` for progress tracking via the global job tray.
Save Draft (Working State)
Persist in-progress edits to the review form so users can resume later (across browser refresh / device switch). The `working_state` body is an opaque object stored on the extraction β the frontend defines its shape (typically header_overrides, line_overrides, selected_targets, etc.). Returns the updated extraction.
List Cost Category Keyword Aliases
List active cost-category keyword aliases used by the OCR cost-line matcher. Returns an object keyed by `cost_category_id` with arrays of keyword strings. Used by the Settings page that lets users curate which keywords (e.g., 'freight', 'fuel surcharge', 'customs', 'duty', 'clearance') map to which CostCategory.
Replace Cost Category Keyword Aliases
Replace the full set of keyword aliases for a single cost category. Idempotent β the repository diffs the supplied list against the existing rows: removes keywords not in the new list, inserts new ones. Default-flagged keywords (seeded by migration) are preserved if they remain in the new list, or removed if dropped. Keywords are normalized to lowercase + trimmed; duplicates are deduped server-side.