From dce9bfb04addceedd9d46a382d97efc9972937fb Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 13 Aug 2026 13:02:37 +0200 Subject: [PATCH] feat(invoicing, dn): add surplus tracking, fix qty, update branding - Fix resolveInvoiceLineDefaults to prioritize customer order quantity over supplier-collected quantity, ensuring invoices reflect what the customer actually ordered - Add surplusQty utility function to calculate supplier MOQ overflow that should be booked to stock via /api/v1/stock/surplus-book - Add surplus stock indicators in order and delivery note modals with descriptive tooltips explaining the surplus amount - Expand supported letterhead codes to include WESTSCOTT GROUP, and configure all delivery notes to use the Westcott Group letterhead globally per business branding rules - Improve error handling and logging in the delivery notes API POST route to include PocketBase error details and request context for easier debugging - Add comprehensive unit tests for the updated invoice line logic and new surplusQty function to prevent regressions --- src/app/(app)/invoicing/page.tsx | 27 ++++++++++- src/app/(app)/invoicing/view-model.test.ts | 53 ++++++++++++++++++++++ src/app/(app)/invoicing/view-model.ts | 28 ++++++++++-- src/app/api/v1/delivery-notes/route.ts | 22 +++++++-- src/lib/letterhead.ts | 17 ++++--- src/lib/server/delivery-notes-service.ts | 46 +++++++++++++++++-- 6 files changed, 172 insertions(+), 21 deletions(-) diff --git a/src/app/(app)/invoicing/page.tsx b/src/app/(app)/invoicing/page.tsx index b8e89da..9018f5a 100644 --- a/src/app/(app)/invoicing/page.tsx +++ b/src/app/(app)/invoicing/page.tsx @@ -29,6 +29,7 @@ import { matchesSearch, resolveInvoicePdfUrl, resolveInvoiceLineDefaults, + surplusQty, type InvoiceLineOverride, type InvoicingRow, } from "./view-model"; @@ -837,6 +838,7 @@ function SingleOrderQbModal({ const priceId = `invoice-price-${row.id}`; const included = includedRowIds.has(row.id); const label = itemLabel(row); + const surplus = surplusQty(row); return (