Purchase invoices, Suppliers 2 with payments, multi-page PO parsing
- Supplier invoices on purchase orders (several per PO), global Upload invoice with search and drag-drop
- PO invoice status line (red/orange/teal), week/month filter, group by supplier, drag-drop PO upload
- Suppliers 2: spend, payable by terms, cash hidden by default, manual payments with surplus/shortfall
- Fix multi-page PO parsing (per-page rows, header filter direction)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 18:29:08 +00:00
|
|
|
/** How far a purchase order has been invoiced. Pure — client-safe. Shared by Purchases and Suppliers 2. */
|
|
|
|
|
|
|
|
|
|
/** Invoiced within this many rand of the PO total counts as fully invoiced (rounding). */
|
|
|
|
|
export const CLOSE_TOLERANCE = 1;
|
|
|
|
|
|
2026-10-29 18:49:05 +00:00
|
|
|
export type InvoiceStatus = "none" | "partial" | "complete" | "over";
|
Purchase invoices, Suppliers 2 with payments, multi-page PO parsing
- Supplier invoices on purchase orders (several per PO), global Upload invoice with search and drag-drop
- PO invoice status line (red/orange/teal), week/month filter, group by supplier, drag-drop PO upload
- Suppliers 2: spend, payable by terms, cash hidden by default, manual payments with surplus/shortfall
- Fix multi-page PO parsing (per-page rows, header filter direction)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 18:29:08 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* red = no invoice; amber = some invoiced but the money does not cover the PO (an invoice with
|
|
|
|
|
* no amount typed in also lands here, since its value is unknown); teal = invoiced to within R1
|
2026-10-29 18:49:05 +00:00
|
|
|
* of the PO total, so it can be closed; purple = invoiced MORE than the PO by over R1. That is
|
|
|
|
|
* never "closed": it is a typo, a duplicate or a changed order, and a person has to look.
|
Purchase invoices, Suppliers 2 with payments, multi-page PO parsing
- Supplier invoices on purchase orders (several per PO), global Upload invoice with search and drag-drop
- PO invoice status line (red/orange/teal), week/month filter, group by supplier, drag-drop PO upload
- Suppliers 2: spend, payable by terms, cash hidden by default, manual payments with surplus/shortfall
- Fix multi-page PO parsing (per-page rows, header filter direction)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 18:29:08 +00:00
|
|
|
*/
|
|
|
|
|
export function invoiceStatusOf(total: number, amounts: (number | null)[]): { status: InvoiceStatus; invoiced: number } {
|
|
|
|
|
const invoiced = amounts.reduce<number>((s, a) => s + (a ?? 0), 0);
|
|
|
|
|
if (amounts.length === 0) return { status: "none", invoiced };
|
2026-10-29 18:49:05 +00:00
|
|
|
if (invoiced - total > CLOSE_TOLERANCE) return { status: "over", invoiced };
|
Purchase invoices, Suppliers 2 with payments, multi-page PO parsing
- Supplier invoices on purchase orders (several per PO), global Upload invoice with search and drag-drop
- PO invoice status line (red/orange/teal), week/month filter, group by supplier, drag-drop PO upload
- Suppliers 2: spend, payable by terms, cash hidden by default, manual payments with surplus/shortfall
- Fix multi-page PO parsing (per-page rows, header filter direction)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 18:29:08 +00:00
|
|
|
if (invoiced > 0 && total - invoiced <= CLOSE_TOLERANCE) return { status: "complete", invoiced };
|
|
|
|
|
return { status: "partial", invoiced };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const STATUS_STYLE: Record<InvoiceStatus, { color: string; label: string }> = {
|
|
|
|
|
none: { color: "#D1495B", label: "No invoice yet" },
|
|
|
|
|
partial: { color: "#EDAE49", label: "Partly invoiced" },
|
|
|
|
|
complete: { color: "#00798C", label: "Fully invoiced — can be closed" },
|
2026-10-29 18:49:05 +00:00
|
|
|
over: { color: "#8B5CF6", label: "Invoiced MORE than the PO — check" },
|
Purchase invoices, Suppliers 2 with payments, multi-page PO parsing
- Supplier invoices on purchase orders (several per PO), global Upload invoice with search and drag-drop
- PO invoice status line (red/orange/teal), week/month filter, group by supplier, drag-drop PO upload
- Suppliers 2: spend, payable by terms, cash hidden by default, manual payments with surplus/shortfall
- Fix multi-page PO parsing (per-page rows, header filter direction)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 18:29:08 +00:00
|
|
|
};
|