This commit overhauls the order management system to use item-level status tracking instead of a single order-level status: - Remove deprecated `orders.status` field and add `invoiced` and quote match audit fields - Add `isOrderComplete` utility with tests to validate fully delivered orders - Add purchase order PDF rendering support and tooling - Add geo coordinate fields for companies/customers with map link UI - Add REST management APIs for customers, companies, and suppliers - Update customer/company services to use relation fields instead of free text - Add status pill and tab filter components for item status visualization - Add quote-to-order matching logic and unit tests - Update all pages, components, and tests to match the new schema - Include all required PocketBase migrations and schema updates
22 lines
1 KiB
TypeScript
22 lines
1 KiB
TypeScript
import type { OrderItem } from "@/lib/types";
|
|
|
|
/**
|
|
* An order is "Complete" iff it has at least one line item and every
|
|
* line item is `delivered`. This is the only order-level indicator we
|
|
* render — there is no stored `orders.status` field to keep in sync.
|
|
*
|
|
* Why this is its own helper instead of inlined at the call site:
|
|
* - Centralises the rule (one place to change if "complete" ever
|
|
* gains another condition, e.g. "all items delivered AND invoiced").
|
|
* - Locks the contract with a unit test (see order-completion.test.ts).
|
|
* - Pure function — easy to test without touching PocketBase.
|
|
*
|
|
* Note: an order with **zero** items is intentionally NOT complete.
|
|
* The /orders list treats no-items as a degenerate case (the row
|
|
* collapses to an empty item list) — we don't want an empty draft
|
|
* order to wear a green "Complete" badge.
|
|
*/
|
|
export function isOrderComplete(items: OrderItem[] | null | undefined): boolean {
|
|
if (!items || items.length === 0) return false;
|
|
return items.every((i) => i.item_status === "delivered");
|
|
}
|