From 9897f477b6abe623a047fada63cc0df9bb383b27 Mon Sep 17 00:00:00 2001 From: DEls Date: Thu, 27 Aug 2026 00:41:10 +0200 Subject: [PATCH] feat(purchasing): show 'Supplier unknown' badge when OCR couldn't extract supplier --- .../purchasing/[poId]/po-detail-view.tsx | 14 ++++++++-- .../dashboard/purchasing/purchasing-view.tsx | 18 ++++++++++--- src/lib/utils.ts | 27 +++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/app/dashboard/purchasing/[poId]/po-detail-view.tsx b/src/app/dashboard/purchasing/[poId]/po-detail-view.tsx index f853c68..5e34d27 100644 --- a/src/app/dashboard/purchasing/[poId]/po-detail-view.tsx +++ b/src/app/dashboard/purchasing/[poId]/po-detail-view.tsx @@ -23,7 +23,7 @@ import { DialogTitle, } from "@/components/ui/dialog"; import { SlipPreview } from "@/components/slip-preview"; -import { cn, formatCurrency, formatNumber } from "@/lib/utils"; +import { cn, formatCurrency, formatNumber, isUnknownSupplier } from "@/lib/utils"; import type { DeliveryNoteProcessingStatus } from "@/lib/pb-types"; export interface PoDetailItem { @@ -152,7 +152,17 @@ export function PoDetailView({ detail }: { detail: PoDetail }) {

{detail.poNumber}

- {detail.supplier || "—"} + {isUnknownSupplier(detail.supplier) ? ( + + + Supplier unknown + + ) : ( + {detail.supplier} + )} {detail.projectCode || "—"} diff --git a/src/app/dashboard/purchasing/purchasing-view.tsx b/src/app/dashboard/purchasing/purchasing-view.tsx index a58a0d6..3be7b3a 100644 --- a/src/app/dashboard/purchasing/purchasing-view.tsx +++ b/src/app/dashboard/purchasing/purchasing-view.tsx @@ -26,7 +26,7 @@ import { SelectValue, } from "@/components/ui/select"; import { Pagination } from "@/components/ui/pagination"; -import { cn, formatCurrency, formatNumber } from "@/lib/utils"; +import { cn, formatCurrency, formatNumber, isUnknownSupplier } from "@/lib/utils"; const PAGE_SIZE = 25; const PO_BASE = "/dashboard/purchasing"; @@ -331,9 +331,19 @@ function PoListItem({ po }: { po: PoRow }) {
{po.poNumber} - - {po.supplier || "—"} - + {isUnknownSupplier(po.supplier) ? ( + + + Supplier unknown + + ) : ( + + {po.supplier} + + )} {po.projectCode || "—"} diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c6ec6ac..e0ab6df 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -23,3 +23,30 @@ export function formatCurrency(n: number, currency = "ZAR") { export function formatPercent(n: number, digits = 1) { return `${n.toFixed(digits)}%`; } + +/** + * Strings that mean "OCR could not extract a real supplier" rather than + * a real vendor name. The OCR pipeline writes "Not specified in + * document" verbatim when the supplier line is missing; other placeholders + * ("Unknown", "N/A", "—") cover other pipelines. Anything in this set + * (case-insensitive, trimmed) renders as "Supplier unknown" in the UI + * instead of being displayed as if it were a real supplier. + * + * Kept as a Set literal rather than reading from config so it's easy to + * grep and extend — add more aliases here when OCR pipelines change. + */ +const UNKNOWN_SUPPLIER_ALIASES = new Set([ + "", + "—", + "-", + "n/a", + "na", + "unknown", + "not specified", + "not specified in document", +]); + +export function isUnknownSupplier(supplier: string | undefined | null): boolean { + if (!supplier) return true; + return UNKNOWN_SUPPLIER_ALIASES.has(supplier.trim().toLowerCase()); +}