@flowselections/floriday-verkoop-module 1.0.139 → 1.0.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/components/verkoop/SalesOrdersFilters.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrdersFilters.js +1 -1
- package/dist-lib/components/verkoop/VerkoopOrdersPage.js +1 -1
- package/dist-lib/lib/order-progress.check.js +7 -0
- package/dist-lib/lib/reference-cache.check.d.ts +2 -0
- package/dist-lib/lib/reference-cache.check.d.ts.map +1 -0
- package/dist-lib/lib/reference-cache.check.js +31 -0
- package/dist-lib/lib/reference-cache.server.d.ts +17 -0
- package/dist-lib/lib/reference-cache.server.d.ts.map +1 -0
- package/dist-lib/lib/reference-cache.server.js +65 -0
- package/dist-lib/lib/salesorders-list.server.d.ts +1 -1
- package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.server.js +175 -129
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SalesOrdersFilters.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/SalesOrdersFilters.tsx"],"names":[],"mappings":"AA6BA,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACnE;AA6BD,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,IAAa,GACd,EAAE;IACD,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACrC,+
|
|
1
|
+
{"version":3,"file":"SalesOrdersFilters.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/SalesOrdersFilters.tsx"],"names":[],"mappings":"AA6BA,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACnE;AA6BD,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,IAAa,GACd,EAAE;IACD,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACrC,+BA0NA"}
|
|
@@ -89,7 +89,7 @@ export function SalesOrdersFilters({ value, onChange, part = "both", }) {
|
|
|
89
89
|
return (_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [part !== "search" && (_jsxs("div", { className: "flex h-9 items-center gap-1 rounded-md border border-border bg-card px-1", children: [showArrows && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", onClick: () => shiftPeriod(-1), className: "inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground", "aria-label": "Vorige", children: _jsx(ChevronLeft, { className: "h-4 w-4" }) }), _jsx("button", { type: "button", onClick: () => shiftPeriod(1), className: "inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground", "aria-label": "Volgende", children: _jsx(ChevronRight, { className: "h-4 w-4" }) })] })), period === "month" ? (_jsxs(Select, { value: `${monthYear}-${month}`, onValueChange: (v) => {
|
|
90
90
|
const [y, m] = v.split("-").map(Number);
|
|
91
91
|
onChange({ ...value, month: m, monthYear: y });
|
|
92
|
-
}, children: [_jsx(SelectTrigger, { className: "h-7 w-36 border-0 bg-transparent px-2 text-sm font-medium text-foreground shadow-none focus:ring-0", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: monthOptions.map((opt) => (_jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value))) })] })) : period === "day" ? (_jsx(Input, { type: "date", value: day, onChange: (e) => onChange({ ...value, day: e.target.value }), className: "h-7 w-40 border-0 bg-transparent px-2 text-sm font-medium text-foreground shadow-none focus-visible:ring-0" })) : period === "custom" ? (_jsxs("div", { className: "flex items-center gap-1 px-2", children: [_jsx(Input, { type: "date", value: value.customFrom ?? todayYmd, onChange: (e) => onChange({ ...value, customFrom: e.target.value }), className: "h-7 w-36 border-0 bg-transparent px-1 text-sm font-medium text-foreground shadow-none focus-visible:ring-0" }), _jsx("span", { className: "text-muted-foreground", children: "\u2013" }), _jsx(Input, { type: "date", value: value.customTo ?? todayYmd, onChange: (e) => onChange({ ...value, customTo: e.target.value }), className: "h-7 w-36 border-0 bg-transparent px-1 text-sm font-medium text-foreground shadow-none focus-visible:ring-0" })] })) : period === "last7" || period === "last30" ? (_jsx("span", { className: "px-2 text-sm font-medium text-foreground whitespace-nowrap", children: period === "last7" ? "Afgelopen 7 dagen" : "Afgelopen 30 dagen" })) : (_jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "px-2 text-sm font-medium text-foreground whitespace-nowrap rounded hover:bg-accent h-7", "aria-label": "Kies week", children: ["Week ", week, " - ", year] }) }), _jsx(PopoverContent, { className: "w-auto p-0 pointer-events-auto", align: "start", children: _jsx(WeekCalendar, { week: week, year: year, onSelect: (w, y) => onChange({ ...value, week: w, year: y }) }) })] })), _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { type: "button", className: "inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground", "aria-label": "Periode-opties", children: _jsx(MoreVertical, { className: "h-4 w-4" }) }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-56", children: [_jsxs(DropdownMenuRadioGroup, { value: period, onValueChange: (v) => handlePeriodChange(v), children: [_jsx(DropdownMenuRadioItem, { value: "day", children: "Dag" }), _jsx(DropdownMenuRadioItem, { value: "week", children: "Week" }), _jsx(DropdownMenuRadioItem, { value: "month", children: "Maand" }), _jsx(DropdownMenuRadioItem, { value: "last7", children: "Afgelopen 7 dagen" }), _jsx(DropdownMenuRadioItem, { value: "last30", children: "Afgelopen 30 dagen" }), _jsx(DropdownMenuRadioItem, { value: "custom", children: "Aangepast tijdsbestek" })] }), _jsx(DropdownMenuSeparator, {}), _jsxs("div", { className: "px-2 py-1.5 text-sm text-muted-foreground inline-flex items-center gap-1", children: [periodLabel(), _jsx(ChevronDown, { className: "h-3.5 w-3.5" })] })] })] })] })), part !== "period" && (_jsxs("div", { className: "flex h-9 w-full items-center overflow-hidden rounded-md border border-border bg-card sm:w-auto", children: [_jsx(Input, { placeholder: part === "search" ? "Zoek op ordernummer, klant, artikel of referentie" : "Op briefnummer zoeken", "aria-label": "Zoeken", value: search, onChange: (e) => setSearch(e.target.value), onKeyDown: (e) => {
|
|
92
|
+
}, children: [_jsx(SelectTrigger, { className: "h-7 w-36 border-0 bg-transparent px-2 text-sm font-medium text-foreground shadow-none focus:ring-0", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: monthOptions.map((opt) => (_jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value))) })] })) : period === "day" ? (_jsx(Input, { type: "date", value: day, onChange: (e) => onChange({ ...value, day: e.target.value }), className: "h-7 w-40 border-0 bg-transparent px-2 text-sm font-medium text-foreground shadow-none focus-visible:ring-0" })) : period === "custom" ? (_jsxs("div", { className: "flex items-center gap-1 px-2", children: [_jsx(Input, { type: "date", value: value.customFrom ?? todayYmd, onChange: (e) => onChange({ ...value, customFrom: e.target.value }), className: "h-7 w-36 border-0 bg-transparent px-1 text-sm font-medium text-foreground shadow-none focus-visible:ring-0" }), _jsx("span", { className: "text-muted-foreground", children: "\u2013" }), _jsx(Input, { type: "date", value: value.customTo ?? todayYmd, onChange: (e) => onChange({ ...value, customTo: e.target.value }), className: "h-7 w-36 border-0 bg-transparent px-1 text-sm font-medium text-foreground shadow-none focus-visible:ring-0" })] })) : period === "last7" || period === "last30" ? (_jsx("span", { className: "px-2 text-sm font-medium text-foreground whitespace-nowrap", children: period === "last7" ? "Afgelopen 7 dagen" : "Afgelopen 30 dagen" })) : (_jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "px-2 text-sm font-medium text-foreground whitespace-nowrap rounded hover:bg-accent h-7", "aria-label": "Kies week", children: ["Week ", week, " - ", year] }) }), _jsx(PopoverContent, { className: "w-auto p-0 pointer-events-auto", align: "start", children: _jsx(WeekCalendar, { week: week, year: year, onSelect: (w, y) => onChange({ ...value, week: w, year: y }) }) })] })), (value.dateField ?? "delivery") === "ordered" && (_jsx("span", { className: "pr-1 text-sm text-muted-foreground whitespace-nowrap", "aria-label": "Periode op besteldatum", children: "\u00B7 besteldatum" })), _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { type: "button", className: "inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground", "aria-label": "Periode-opties", children: _jsx(MoreVertical, { className: "h-4 w-4" }) }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-56", children: [_jsxs(DropdownMenuRadioGroup, { value: period, onValueChange: (v) => handlePeriodChange(v), children: [_jsx(DropdownMenuRadioItem, { value: "day", children: "Dag" }), _jsx(DropdownMenuRadioItem, { value: "week", children: "Week" }), _jsx(DropdownMenuRadioItem, { value: "month", children: "Maand" }), _jsx(DropdownMenuRadioItem, { value: "last7", children: "Afgelopen 7 dagen" }), _jsx(DropdownMenuRadioItem, { value: "last30", children: "Afgelopen 30 dagen" }), _jsx(DropdownMenuRadioItem, { value: "custom", children: "Aangepast tijdsbestek" })] }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuRadioGroup, { value: value.dateField ?? "delivery", onValueChange: (v) => onChange({ ...value, dateField: v === "ordered" ? "ordered" : "delivery" }), children: [_jsx(DropdownMenuRadioItem, { value: "delivery", children: "Op leverdatum" }), _jsx(DropdownMenuRadioItem, { value: "ordered", children: "Op besteldatum" })] }), _jsx(DropdownMenuSeparator, {}), _jsxs("div", { className: "px-2 py-1.5 text-sm text-muted-foreground inline-flex items-center gap-1", children: [periodLabel(), (value.dateField ?? "delivery") === "ordered" ? " · besteldatum" : "", _jsx(ChevronDown, { className: "h-3.5 w-3.5" })] })] })] })] })), part !== "period" && (_jsxs("div", { className: "flex h-9 w-full items-center overflow-hidden rounded-md border border-border bg-card sm:w-auto", children: [_jsx(Input, { placeholder: part === "search" ? "Zoek op ordernummer, klant, artikel of referentie" : "Op briefnummer zoeken", "aria-label": "Zoeken", value: search, onChange: (e) => setSearch(e.target.value), onKeyDown: (e) => {
|
|
93
93
|
if (e.key === "Enter")
|
|
94
94
|
onChange({ ...value, search });
|
|
95
95
|
}, onBlur: () => onChange({ ...value, search }), className: "h-9 border-0 shadow-none focus-visible:ring-0 " + (part === "search" ? "min-w-0 flex-1 sm:w-80" : "w-56") }), _jsx("button", { type: "button", onClick: () => onChange({ ...value, search }), className: "inline-flex h-9 w-10 items-center justify-center bg-primary text-primary-foreground hover:opacity-90", "aria-label": "Zoeken", children: _jsx(Search, { className: "h-4 w-4" }) })] }))] }));
|
|
@@ -431,7 +431,7 @@ export function VerkoopOrdersPage() {
|
|
|
431
431
|
? new Date(syncHealth.lastSuccessAt).toLocaleString("nl-NL")
|
|
432
432
|
: "nog nooit", syncHealth.lastError ? ` — ${syncHealth.lastError}` : "", syncHealth.failingComponents && syncHealth.failingComponents.length > 0
|
|
433
433
|
? ` — onderdelen die stilliggen: ${syncHealth.failingComponents.join(", ")}`
|
|
434
|
-
: ""] })] }), _jsx("span", { className: "text-xs text-muted-foreground", children: "Handmatig ophalen kan via Instellingen \u203A Floriday." })] })), _jsxs("section", { "aria-label": "Kerncijfers", className: "shrink-0 grid grid-cols-2 gap-3 lg:grid-cols-4", children: [_jsx(KpiTile, { title: "Omzet", loading: isLoading, value: _jsx(Crossfade, { value: eur0(totals.revenue) }), sub: `excl. btw · gem. ${eur0(totals.orderCount ? totals.revenue / totals.orderCount : 0)} per order` }), _jsx(KpiTile, { title: "Orders", loading: isLoading, value: _jsx(Crossfade, { value: statusCounts.all.toLocaleString("nl-NL") }), sub: `${statusCounts.incoming} inkomend · ${statusCounts.topick} te picken` }), _jsx(KpiTile, { title: "Fust", loading: isLoading, value: _jsx(Crossfade, { value: totals.fustCount.toLocaleString("nl-NL") }), sub: tab === "all" ? "in deze periode" : "in dit tabblad" }), _jsx(KpiTile, { title: "Actie nodig", loading: isLoading, value: _jsx(Crossfade, { value: (statusCounts.backlog + statusCounts.problem).toLocaleString("nl-NL") }), sub: _jsxs("span", { className: "flex flex-wrap items-center gap-x-1", children: [_jsxs("button", { type: "button", "aria-pressed": tab === "backlog", onClick: () => toggleTab("backlog"), className: "rounded-sm font-medium text-destructive underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", children: [statusCounts.backlog, " te laat"] }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }),
|
|
434
|
+
: ""] })] }), _jsx("span", { className: "text-xs text-muted-foreground", children: "Handmatig ophalen kan via Instellingen \u203A Floriday." })] })), _jsxs("section", { "aria-label": "Kerncijfers", className: "shrink-0 grid grid-cols-2 gap-3 lg:grid-cols-4", children: [_jsx(KpiTile, { title: "Omzet", loading: isLoading, value: _jsx(Crossfade, { value: eur0(totals.revenue) }), sub: `excl. btw · gem. ${eur0(totals.orderCount ? totals.revenue / totals.orderCount : 0)} per order` }), _jsx(KpiTile, { title: "Orders", loading: isLoading, value: _jsx(Crossfade, { value: statusCounts.all.toLocaleString("nl-NL") }), sub: `${statusCounts.incoming} inkomend · ${statusCounts.topick} te picken` }), _jsx(KpiTile, { title: "Fust", loading: isLoading, value: _jsx(Crossfade, { value: totals.fustCount.toLocaleString("nl-NL") }), sub: tab === "all" ? "in deze periode" : "in dit tabblad" }), _jsx(KpiTile, { title: "Actie nodig", loading: isLoading, value: _jsx(Crossfade, { value: (statusCounts.backlog + statusCounts.problem).toLocaleString("nl-NL") }), sub: _jsxs("span", { className: "flex flex-wrap items-center gap-x-1", children: [_jsxs("button", { type: "button", "aria-pressed": tab === "backlog", onClick: () => toggleTab("backlog"), className: "rounded-sm font-medium text-destructive underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", children: [statusCounts.backlog, " te laat"] }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsx("button", { type: "button", "aria-pressed": tab === "problem", onClick: () => toggleTab("problem"), className: "rounded-sm font-medium text-warning underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", children: features.pickProgress ? `${statusCounts.problem} probleem` : "probleem onbekend" })] }) })] }), _jsx(StatusTabs, { tab: tab, counts: statusCounts, onChange: setTab }), _jsxs("div", { className: "shrink-0 flex flex-wrap items-center gap-2", children: [_jsx("div", { className: "min-w-0 flex-1 sm:flex-none", children: _jsx(SalesOrdersFilters, { value: filters, onChange: setFilters, part: "search" }) }), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => setFilterPanelOpen(true), "aria-label": "Filters", children: [_jsx(Filter, { className: "mr-2 h-4 w-4" }), "Filters", activeFilterCount > 0 && (_jsx("span", { className: "ml-2 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-[11px] font-semibold text-primary-foreground", children: activeFilterCount }))] }), tab === "backlog" && (_jsx(FilterChip, { label: "Te laat", onClear: () => setTab("topick") })), tab === "problem" && _jsx(FilterChip, { label: "Probleem", onClear: () => setTab("all") }), (filters.search || activeFilterCount > 0) && (_jsx(Button, { variant: "ghost", size: "sm", onClick: clearAll, children: "Alles wissen" }))] }), _jsx("div", { className: "shrink-0", children: _jsx(StockConsumptionAlertsBanner, {}) }), error && !data && (_jsxs("div", { role: "alert", className: "shrink-0 flex items-start gap-3 rounded-lg border border-destructive/30 bg-destructive-soft p-4 text-sm", children: [_jsx(AlertTriangle, { className: "mt-0.5 h-5 w-5 shrink-0 text-destructive" }), _jsxs("div", { className: "flex-1", children: [_jsx("div", { className: "font-medium text-destructive-soft-foreground", children: isSessionError(error) ? "Je inlogsessie is verlopen" : "Orders konden niet geladen worden" }), _jsx("div", { className: "mt-1 text-muted-foreground", children: isSessionError(error) ? "Log opnieuw in om de orders te zien." : error.message })] }), isSessionError(error) ? (_jsx(Button, { size: "sm", variant: "outline", onClick: () => navigate({ to: "/login" }), children: "Opnieuw inloggen" })) : (_jsx(Button, { size: "sm", variant: "outline", onClick: () => refetch(), disabled: isFetching, children: "Opnieuw proberen" }))] })), (warnings.length > 0 || truncated) && (_jsxs("div", { className: "shrink-0 flex items-start gap-3 rounded-lg border border-border bg-warning-soft p-3 text-sm", children: [_jsx(AlertTriangle, { className: "mt-0.5 h-4 w-4 shrink-0 text-warning-soft-foreground" }), _jsxs("div", { className: "space-y-1 text-warning-soft-foreground", children: [warnings.map((w) => (_jsx("div", { children: w }, w))), truncated && (_jsx("div", { children: "Niet alle orders konden worden meegenomen. Kies een kortere periode voor een volledig overzicht." }))] })] })), selectedRows.length > 0 && (_jsxs("div", { ref: (el) => {
|
|
435
435
|
if (el && !el.dataset.shown) {
|
|
436
436
|
el.dataset.shown = "1";
|
|
437
437
|
animateIn(el, { duration: 180, y: 8 });
|
|
@@ -51,6 +51,13 @@ check("probleem: verzonden telt niet", hasProblem([toProgressMember({ orderNumbe
|
|
|
51
51
|
check("probleem: geannuleerd telt niet", hasProblem([toProgressMember({ orderNumber: "P2", stage: "cancelled", karUnknown: true })]), false);
|
|
52
52
|
check("probleem: open met blokkade telt", hasProblem([toProgressMember({ orderNumber: "P3", stage: "topick", karUnknown: true })]), true);
|
|
53
53
|
check("probleem: open ERP zonder prijs telt", hasProblem([toProgressMember({ orderNumber: "P4", stage: "picked", invoiceRoute: "erp", missingPrice: true })]), true);
|
|
54
|
+
// Telling en icoon zeggen hetzelfde (HO-2601466/1457: open, te picken, geblokkeerd).
|
|
55
|
+
{
|
|
56
|
+
const blockedRow = { orderNumber: "HO-2601466", stage: "topick", pickProgress: { cartsTotal: 1, cartsPrinted: 0, cartsScanned: 0, firstPrintedAt: null, lastScannedAt: null, pickDate: null, blocked: true, blockedReason: "Kan niet worden ingedeeld", archived: false } };
|
|
57
|
+
const m = [toProgressMember(blockedRow)];
|
|
58
|
+
check("probleem: geblokkeerd in pickvoortgang telt", hasProblem(m), true);
|
|
59
|
+
check("icoon Gepickt is fout bij dezelfde order", rowSteps(m, F).picked, "error");
|
|
60
|
+
}
|
|
54
61
|
check("achterstand → te laat", rowSteps([toProgressMember({ orderNumber: "E", stage: "topick", backlog: true })], F).picked, "late");
|
|
55
62
|
// Tooltip: eerste 5 en "+n meer" vanaf 7.
|
|
56
63
|
check("6 orders allemaal tonen", limitMembers([1, 2, 3, 4, 5, 6]).more, 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-cache.check.d.ts","sourceRoot":"","sources":["../../src/lib/reference-cache.check.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Draai: bun src/lib/reference-cache.check.ts
|
|
2
|
+
import { _resetRefCache, cachedRef, invalidateRefCache, refCacheKey } from "./reference-cache.server.js";
|
|
3
|
+
let failed = 0;
|
|
4
|
+
function check(name, got, want) {
|
|
5
|
+
const ok = JSON.stringify(got) === JSON.stringify(want);
|
|
6
|
+
if (!ok)
|
|
7
|
+
failed++;
|
|
8
|
+
console.log(`${ok ? "OK " : "FOUT"} ${name}: ${JSON.stringify(got)}${ok ? "" : ` (verwacht ${JSON.stringify(want)})`}`);
|
|
9
|
+
}
|
|
10
|
+
const a = refCacheKey({ supabaseUrl: "https://shell-a.example.test" });
|
|
11
|
+
const b = refCacheKey({ supabaseUrl: "https://shell-b.example.test" });
|
|
12
|
+
check("sleutel bevat projectadres + versie", a, "https://shell-a.example.test|v2");
|
|
13
|
+
check("geen adres → geen cache", refCacheKey({}), null);
|
|
14
|
+
_resetRefCache();
|
|
15
|
+
await cachedRef(a, "carriers", async () => "A");
|
|
16
|
+
await cachedRef(b, "carriers", async () => "B");
|
|
17
|
+
check("shell A krijgt eigen waarde", await cachedRef(a, "carriers", async () => "X"), "A");
|
|
18
|
+
check("shell B krijgt eigen waarde", await cachedRef(b, "carriers", async () => "X"), "B");
|
|
19
|
+
invalidateRefCache(a);
|
|
20
|
+
check("ongeldig maken raakt alleen A", await cachedRef(a, "carriers", async () => "A2"), "A2");
|
|
21
|
+
check("B blijft staan", await cachedRef(b, "carriers", async () => "X"), "B");
|
|
22
|
+
let calls = 0;
|
|
23
|
+
await cachedRef(null, "carriers", async () => ++calls);
|
|
24
|
+
await cachedRef(null, "carriers", async () => ++calls);
|
|
25
|
+
check("zonder sleutel elke keer lezen", calls, 2);
|
|
26
|
+
check("verlopen na 60 s", await cachedRef(b, "carriers", async () => "B2", 60000, () => Date.now() + 61000), "B2");
|
|
27
|
+
if (failed) {
|
|
28
|
+
console.error(`${failed} controle(s) mislukt`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
console.log("Alle cachecontroles geslaagd");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const REF_CACHE_VERSION = 2;
|
|
2
|
+
export declare const REF_CACHE_TTL_MS: number;
|
|
3
|
+
/** Projectadres (origin) van een Supabase-client, of null als onbekend. */
|
|
4
|
+
export declare function projectUrlOf(client: unknown): string | null;
|
|
5
|
+
/** Cachesleutel: projectadres + versie, of null (dan geen cache). */
|
|
6
|
+
export declare function refCacheKey(client: unknown): string | null;
|
|
7
|
+
/**
|
|
8
|
+
* Haalt `name` uit de cache van `key`, of laadt hem. Alleen een geslaagde
|
|
9
|
+
* lading wordt bewaard. Mislukt het laden en is er een oude waarde, dan wordt
|
|
10
|
+
* die teruggegeven; anders gaat de fout door.
|
|
11
|
+
*/
|
|
12
|
+
export declare function cachedRef<T>(key: string | null, name: string, load: () => Promise<T>, ttlMs?: number, now?: () => number): Promise<T>;
|
|
13
|
+
/** Maakt de cache van één project ongeldig (bij een realtime-seintje). */
|
|
14
|
+
export declare function invalidateRefCache(key: string | null): void;
|
|
15
|
+
/** Alleen voor tests. */
|
|
16
|
+
export declare function _resetRefCache(): void;
|
|
17
|
+
//# sourceMappingURL=reference-cache.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-cache.server.d.ts","sourceRoot":"","sources":["../../src/lib/reference-cache.server.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,eAAO,MAAM,gBAAgB,QAAY,CAAC;AAQ1C,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAS3D;AAED,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAG1D;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,KAAK,SAAmB,EACxB,GAAG,GAAE,MAAM,MAAiB,GAC3B,OAAO,CAAC,CAAC,CAAC,CAiBZ;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,QAEpD;AAED,yBAAyB;AACzB,wBAAgB,cAAc,SAE7B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Korte servercache voor referentiegegevens die zelden veranderen
|
|
2
|
+
// (vervoerders, productgroepen, fustomschrijvingen, Floriday-instellingen).
|
|
3
|
+
//
|
|
4
|
+
// De sleutel is het Supabase-projectadres van het verzoek plus een
|
|
5
|
+
// versiesleutel. Zo komen gegevens van twee shells nooit door elkaar, ook niet
|
|
6
|
+
// als één serverproces meerdere shells bedient. Het adres komt uit de client
|
|
7
|
+
// van het verzoek (niet uit de code). Is er geen adres, dan wordt er niets
|
|
8
|
+
// bewaard (fail closed: gewoon elke keer lezen).
|
|
9
|
+
export const REF_CACHE_VERSION = 2;
|
|
10
|
+
export const REF_CACHE_TTL_MS = 60 * 1000;
|
|
11
|
+
const stores = new Map();
|
|
12
|
+
/** Projectadres (origin) van een Supabase-client, of null als onbekend. */
|
|
13
|
+
export function projectUrlOf(client) {
|
|
14
|
+
const c = client;
|
|
15
|
+
const raw = c?.supabaseUrl ?? c?.rest?.url ?? null;
|
|
16
|
+
if (typeof raw !== "string" || !raw)
|
|
17
|
+
return null;
|
|
18
|
+
try {
|
|
19
|
+
return new URL(raw).origin.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Cachesleutel: projectadres + versie, of null (dan geen cache). */
|
|
26
|
+
export function refCacheKey(client) {
|
|
27
|
+
const origin = projectUrlOf(client);
|
|
28
|
+
return origin ? `${origin}|v${REF_CACHE_VERSION}` : null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Haalt `name` uit de cache van `key`, of laadt hem. Alleen een geslaagde
|
|
32
|
+
* lading wordt bewaard. Mislukt het laden en is er een oude waarde, dan wordt
|
|
33
|
+
* die teruggegeven; anders gaat de fout door.
|
|
34
|
+
*/
|
|
35
|
+
export async function cachedRef(key, name, load, ttlMs = REF_CACHE_TTL_MS, now = Date.now) {
|
|
36
|
+
if (!key)
|
|
37
|
+
return load();
|
|
38
|
+
let store = stores.get(key);
|
|
39
|
+
if (!store) {
|
|
40
|
+
store = new Map();
|
|
41
|
+
stores.set(key, store);
|
|
42
|
+
}
|
|
43
|
+
const hit = store.get(name);
|
|
44
|
+
if (hit && now() - hit.at < ttlMs)
|
|
45
|
+
return hit.value;
|
|
46
|
+
try {
|
|
47
|
+
const value = await load();
|
|
48
|
+
store.set(name, { at: now(), value });
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
if (hit)
|
|
53
|
+
return hit.value;
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Maakt de cache van één project ongeldig (bij een realtime-seintje). */
|
|
58
|
+
export function invalidateRefCache(key) {
|
|
59
|
+
if (key)
|
|
60
|
+
stores.delete(key);
|
|
61
|
+
}
|
|
62
|
+
/** Alleen voor tests. */
|
|
63
|
+
export function _resetRefCache() {
|
|
64
|
+
stores.clear();
|
|
65
|
+
}
|
|
@@ -38,7 +38,7 @@ export interface ListResult {
|
|
|
38
38
|
/** Welke leesfuncties van Facturatie/Engine beschikbaar waren. */
|
|
39
39
|
features: ProgressFeatures;
|
|
40
40
|
}
|
|
41
|
-
export declare function invalidateReferenceCache(): void;
|
|
41
|
+
export declare function invalidateReferenceCache(key?: string | null): void;
|
|
42
42
|
export interface ListTiming {
|
|
43
43
|
kind: string;
|
|
44
44
|
totalMs: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"salesorders-list.server.d.ts","sourceRoot":"","sources":["../../src/lib/salesorders-list.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"salesorders-list.server.d.ts","sourceRoot":"","sources":["../../src/lib/salesorders-list.server.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAEvB,MAAM,uBAAuB,CAAC;AAK/B,OAAO,EAAiB,KAAK,mBAAmB,EAAE,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAGxG,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjF,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAI1B,4EAA4E;AAC5E,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,GAAG,cAAc,GAAG,UAAU,GAAG,SAAS,CAAC;AAEjG,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACxC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,WAAW,EAAE,SAAS,GAAG,MAAM,CAAC;IAChC,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,yDAAyD;IACzD,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,kEAAkE;IAClE,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AA6GD,wBAAgB,wBAAwB,CAAC,GAAG,GAAE,MAAM,GAAG,IAAW,QAEjE;AAkBD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACvC;AAoDD;+EAC+E;AAC/E,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAgB3G;AA+BD,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,UAAU,EAClB,kBAAkB,GAAE,cAAyB,GAC5C,OAAO,CAAC,UAAU,CAAC,CA60CrB;AAsDD,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,MAAM,EAAE,EACb,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACzC,KAAK,EAAE,MAAM,GAAG,IAAI,GACnB,qBAAqB,CAIvB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { invoiceStateLabel } from "./invoice-timing.js";
|
|
2
|
+
import { cachedRef, invalidateRefCache, refCacheKey } from "./reference-cache.server.js";
|
|
2
3
|
import { loadReviewDismissals, isReviewDismissed } from "./review-dismissals.server.js";
|
|
3
4
|
import { orderFust } from "./order-fust.js";
|
|
4
5
|
import { posOrNull } from "./packing-snapshot.js";
|
|
@@ -112,34 +113,28 @@ async function chunked(ids, size, fn) {
|
|
|
112
113
|
}
|
|
113
114
|
return out;
|
|
114
115
|
}
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
export function invalidateReferenceCache() {
|
|
121
|
-
crateDescCache = null;
|
|
122
|
-
carrierNamesCache = null;
|
|
123
|
-
groupPackingCache = null;
|
|
116
|
+
// ── korte servercache voor stabiele referentiedata ────────────────────────
|
|
117
|
+
// Per Supabase-project (+ versiesleutel), 60 s; zie reference-cache.server.ts.
|
|
118
|
+
// Realtime-seintjes in de lijst sturen refreshReference mee.
|
|
119
|
+
export function invalidateReferenceCache(key = null) {
|
|
120
|
+
invalidateRefCache(key);
|
|
124
121
|
}
|
|
125
|
-
async function loadCarrierNames(supabase) {
|
|
126
|
-
if (carrierNamesCache && Date.now() - carrierNamesCache.at < TTL_MS)
|
|
127
|
-
return carrierNamesCache.value;
|
|
128
|
-
const map = new Map();
|
|
122
|
+
async function loadCarrierNames(supabase, cacheKey) {
|
|
129
123
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
124
|
+
return await cachedRef(cacheKey, "carrierNames", async () => {
|
|
125
|
+
const map = new Map();
|
|
126
|
+
const { data, error } = await supabase.from("carriers").select("id, name").limit(2000);
|
|
127
|
+
if (error)
|
|
128
|
+
throw new Error(error.message);
|
|
129
|
+
for (const c of (data ?? []))
|
|
130
|
+
map.set(String(c.id), String(c.name ?? ""));
|
|
131
|
+
return map;
|
|
132
|
+
});
|
|
136
133
|
}
|
|
137
134
|
catch {
|
|
138
135
|
/* vervoerdernamen zijn optioneel */
|
|
139
|
-
|
|
140
|
-
return carrierNamesCache.value;
|
|
136
|
+
return new Map();
|
|
141
137
|
}
|
|
142
|
-
return map;
|
|
143
138
|
}
|
|
144
139
|
function makeTimer() {
|
|
145
140
|
const start = Date.now();
|
|
@@ -213,44 +208,44 @@ export function overviewWindowFor(deliveries) {
|
|
|
213
208
|
};
|
|
214
209
|
return { from: shift(min, -60), to: shift(max, 14) };
|
|
215
210
|
}
|
|
216
|
-
async function loadCrateDescriptions(supabase, warnings) {
|
|
217
|
-
if (crateDescCache && Date.now() - crateDescCache.at < TTL_MS)
|
|
218
|
-
return crateDescCache.value;
|
|
219
|
-
const map = new Map();
|
|
211
|
+
async function loadCrateDescriptions(supabase, warnings, cacheKey) {
|
|
220
212
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
213
|
+
return await cachedRef(cacheKey, "crateDescriptions", async () => {
|
|
214
|
+
const map = new Map();
|
|
215
|
+
const { data, error } = await supabase
|
|
216
|
+
.from("floricode_records")
|
|
217
|
+
.select("data")
|
|
218
|
+
.eq("resource", "LoadCarrier")
|
|
219
|
+
.limit(5000);
|
|
220
|
+
if (error)
|
|
221
|
+
throw new Error(error.message);
|
|
222
|
+
for (const row of data ?? []) {
|
|
223
|
+
const d = row.data ?? {};
|
|
224
|
+
if (d?.code == null)
|
|
225
|
+
continue;
|
|
226
|
+
const desc = typeof d.description === "string" ? d.description.trim() : "";
|
|
227
|
+
if (desc)
|
|
228
|
+
map.set(String(d.code), desc);
|
|
229
|
+
}
|
|
230
|
+
return map;
|
|
231
|
+
});
|
|
237
232
|
}
|
|
238
233
|
catch (e) {
|
|
239
234
|
warnings.push(`Fustomschrijvingen niet geladen: ${e.message}`);
|
|
240
|
-
|
|
241
|
-
return crateDescCache.value;
|
|
235
|
+
return new Map();
|
|
242
236
|
}
|
|
243
|
-
return map;
|
|
244
237
|
}
|
|
245
238
|
// ── hoofdfunctie ──────────────────────────────────────────────────────────
|
|
246
239
|
export async function buildSalesOrdersList(supabase, params, connectionSupabase = supabase) {
|
|
247
240
|
const warnings = [];
|
|
248
241
|
const t = makeTimer();
|
|
242
|
+
// Cachesleutel = projectadres van dit verzoek + versie (vóór het omwikkelen).
|
|
243
|
+
const cacheKey = refCacheKey(supabase);
|
|
249
244
|
// Teller van database-aanroepen per lading (meting).
|
|
250
245
|
supabase = countingClient(supabase, t.db);
|
|
251
246
|
connectionSupabase = countingClient(connectionSupabase, t.db);
|
|
252
247
|
if (params.refreshReference)
|
|
253
|
-
invalidateReferenceCache();
|
|
248
|
+
invalidateReferenceCache(cacheKey);
|
|
254
249
|
const pageSize = Math.min(PAGE_SIZE_MAX, Math.max(1, Math.floor(params.pageSize || 20)));
|
|
255
250
|
const page = Math.max(1, Math.floor(params.page || 1));
|
|
256
251
|
const dateColumn = params.dateField === "delivery"
|
|
@@ -258,23 +253,34 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
258
253
|
: "data->>orderDateTime";
|
|
259
254
|
// 1 + 2) Omgeving, connectie en Floriday-orders — tegelijk met 3 (lokale orders).
|
|
260
255
|
const floridayTask = t.time("1_2_floriday", async () => {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
256
|
+
const settings = await cachedRef(cacheKey, "floridaySettings", async () => {
|
|
257
|
+
const envRes = await supabase
|
|
258
|
+
.from("floriday_settings")
|
|
259
|
+
.select("active_environment")
|
|
260
|
+
.eq("id", 1)
|
|
261
|
+
.maybeSingle();
|
|
262
|
+
if (envRes.error)
|
|
263
|
+
throw new Error(envRes.error.message);
|
|
264
|
+
const rawEnv = String(envRes.data?.active_environment ?? "staging");
|
|
265
|
+
const environment = rawEnv === "production" || rawEnv === "prod" || rawEnv === "live" ? "live" : "staging";
|
|
266
|
+
// De connectietabel bevat ook gevoelige velden en is daarom bewust niet
|
|
267
|
+
// rechtstreeks leesbaar voor browsers. Alleen deze veilige selectie loopt
|
|
268
|
+
// via de serverclient; alle orderdata blijft onder de rechten van de gebruiker.
|
|
269
|
+
const connRes = await connectionSupabase
|
|
270
|
+
.from("floriday_connections")
|
|
271
|
+
.select("id, organization_name, label")
|
|
272
|
+
.eq("is_active", true)
|
|
273
|
+
.eq("environment", environment)
|
|
274
|
+
.limit(1);
|
|
275
|
+
if (connRes.error)
|
|
276
|
+
throw new Error(connRes.error.message);
|
|
277
|
+
return { environment, conn: (connRes.data ?? [])[0] };
|
|
278
|
+
}).catch((e) => {
|
|
279
|
+
warnings.push(`Floriday-koppeling niet gelezen: ${e.message}`);
|
|
280
|
+
return { environment: "staging", conn: undefined };
|
|
281
|
+
});
|
|
282
|
+
const environment = settings.environment;
|
|
283
|
+
const conn = settings.conn;
|
|
278
284
|
const sellerFallback = conn?.organization_name ?? conn?.label ?? null;
|
|
279
285
|
let truncated = false;
|
|
280
286
|
const foRows = [];
|
|
@@ -356,12 +362,32 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
356
362
|
return (localRes.data ?? []);
|
|
357
363
|
});
|
|
358
364
|
// Vervoerdernamen: vaste referentiedata, 10 min in het servergeheugen.
|
|
359
|
-
const carrierNamesTask = loadCarrierNames(supabase);
|
|
365
|
+
const carrierNamesTask = loadCarrierNames(supabase, cacheKey);
|
|
360
366
|
const [{ environment, sellerFallback, foRows, truncated }, localOrderRows] = await Promise.all([
|
|
361
367
|
floridayTask,
|
|
362
368
|
localTask,
|
|
363
369
|
]);
|
|
364
370
|
t.mark("1_3_bronnen");
|
|
371
|
+
// 12a-ophalen) Engine-overzicht start direct na de bronnen, tegelijk met de
|
|
372
|
+
// referentiegegevens (stap 5). Venster uit de ruwe leverdatums; toepassen
|
|
373
|
+
// gebeurt later (12a) op de DTO's.
|
|
374
|
+
const earlyOverviewWindow = overviewWindowFor([
|
|
375
|
+
...localOrderRows.map((r) => (r?.delivery_date ? String(r.delivery_date) : null)),
|
|
376
|
+
...foRows.map((r) => r?.data?.delivery?.latestDeliveryDateTime ? String(r.data.delivery.latestDeliveryDateTime) : null),
|
|
377
|
+
]);
|
|
378
|
+
const overviewFetch = localOrderRows.length || foRows.length
|
|
379
|
+
? t.time("12a_overzicht", async () => {
|
|
380
|
+
try {
|
|
381
|
+
const { data, error } = await supabase.rpc("logistics_order_overview", { p_from: earlyOverviewWindow.from, p_to: earlyOverviewWindow.to });
|
|
382
|
+
if (error)
|
|
383
|
+
return { rows: [], error: String(error.message) };
|
|
384
|
+
return { rows: Array.isArray(data) ? data : [], error: null };
|
|
385
|
+
}
|
|
386
|
+
catch (e) {
|
|
387
|
+
return { rows: [], error: e?.message ?? String(e) };
|
|
388
|
+
}
|
|
389
|
+
})
|
|
390
|
+
: Promise.resolve({ rows: [], error: null });
|
|
365
391
|
// 3b) Vervoerders + verzendmomenten (best-effort, alleen voor deze orders).
|
|
366
392
|
// Loopt tegelijk met stap 5 (zie Promise.all hieronder).
|
|
367
393
|
const carrierNameById = await carrierNamesTask;
|
|
@@ -476,8 +502,8 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
476
502
|
throw new Error(error.message);
|
|
477
503
|
return (data ?? []);
|
|
478
504
|
}, []),
|
|
479
|
-
loadCrateDescriptions(supabase, warnings),
|
|
480
|
-
safe("Productgroepen", () => loadGroupPacking(supabase), new Map()),
|
|
505
|
+
loadCrateDescriptions(supabase, warnings, cacheKey),
|
|
506
|
+
safe("Productgroepen", () => loadGroupPacking(supabase, cacheKey), new Map()),
|
|
481
507
|
]);
|
|
482
508
|
t.mark("3b_5_referentie");
|
|
483
509
|
const orderNumberByFoId = orderNumberRows;
|
|
@@ -923,15 +949,14 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
923
949
|
// en Pick — we tellen hier niets zelf meer voor de weergave.
|
|
924
950
|
// Alleen het venster van de getoonde orders (leverdatums, met marge voor de
|
|
925
951
|
// pickdag) i.p.v. de hele historie. Ontbreekt een leverdatum: geen venster.
|
|
926
|
-
const
|
|
927
|
-
const overviewTask = t.time("12a_overzicht", async () => {
|
|
952
|
+
const overviewTask = (async () => {
|
|
928
953
|
if (all.length === 0)
|
|
929
954
|
return;
|
|
930
955
|
try {
|
|
931
|
-
const
|
|
932
|
-
if (
|
|
933
|
-
throw new Error(
|
|
934
|
-
const overview =
|
|
956
|
+
const fetched = await overviewFetch;
|
|
957
|
+
if (fetched.error)
|
|
958
|
+
throw new Error(fetched.error);
|
|
959
|
+
const overview = fetched.rows;
|
|
935
960
|
const engineByOrderId = new Map();
|
|
936
961
|
for (const row of overview) {
|
|
937
962
|
if (row?.order_uuid)
|
|
@@ -963,7 +988,7 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
963
988
|
catch (e) {
|
|
964
989
|
warnings.push(`Engine-orderoverzicht niet beschikbaar: ${e?.message ?? e}`);
|
|
965
990
|
}
|
|
966
|
-
});
|
|
991
|
+
})();
|
|
967
992
|
// 12a-ter) Ladingdragers en indelingsstatus komen uit de Engine
|
|
968
993
|
// (logistics_order_plan_coverage), alleen voor de zichtbare rijen — zie stap 14.
|
|
969
994
|
// 12a-bis) Ophaalmoment komt uit de Engine, alleen voor zichtbare rijen (stap 14).
|
|
@@ -1140,14 +1165,12 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
1140
1165
|
}
|
|
1141
1166
|
}
|
|
1142
1167
|
});
|
|
1143
|
-
await Promise.all([overviewTask, dismissalsTask, backlogTask]);
|
|
1144
|
-
t.mark("12_engine");
|
|
1145
1168
|
// 12i) Factuurstand (Facturatie) voor alle orders in de periode (nodig voor
|
|
1146
|
-
// de telling "Gefactureerd"), per 500 id's, hooguit 1,5 s
|
|
1147
|
-
//
|
|
1169
|
+
// de telling "Gefactureerd"), per 500 id's, hooguit 1,5 s — tegelijk met
|
|
1170
|
+
// de Engine-stappen hierboven.
|
|
1148
1171
|
const features = { erpInvoices: false, pickProgress: false };
|
|
1149
|
-
|
|
1150
|
-
|
|
1172
|
+
const invoiceTask = !params.all && !params.localOrderId && all.length
|
|
1173
|
+
? t.time("12i_factuur", async () => {
|
|
1151
1174
|
const ids = Array.from(new Set(all.map((o) => o.orderRowId).filter((v) => !!v)));
|
|
1152
1175
|
const res = await loadInvoiceStatuses(supabase, ids);
|
|
1153
1176
|
features.erpInvoices = res.available;
|
|
@@ -1156,8 +1179,10 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
1156
1179
|
for (const o of all)
|
|
1157
1180
|
if (o.orderRowId)
|
|
1158
1181
|
o.erpInvoice = res.invoices.get(o.orderRowId) ?? null;
|
|
1159
|
-
})
|
|
1160
|
-
|
|
1182
|
+
})
|
|
1183
|
+
: Promise.resolve();
|
|
1184
|
+
await Promise.all([overviewTask, dismissalsTask, backlogTask, invoiceTask]);
|
|
1185
|
+
t.mark("12_engine");
|
|
1161
1186
|
const membersOf = (g) => g.map((m) => toProgressMember(m));
|
|
1162
1187
|
// 13) Filteren (zoek + status), tellen, pagineren — op samengevouwen rijen.
|
|
1163
1188
|
const search = (params.search ?? "").trim().toLowerCase();
|
|
@@ -1200,35 +1225,48 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
1200
1225
|
return stageOf(members) === params.tab;
|
|
1201
1226
|
};
|
|
1202
1227
|
const withoutTab = groups.filter((g) => matchesSearch(g) && matchesStatusFilter(g));
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
if (
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1228
|
+
const rowIdOf = (o) => o.id.startsWith("local:")
|
|
1229
|
+
? o.id.slice("local:".length)
|
|
1230
|
+
: (localRowByFoId.get(o.id)?.id ? String(localRowByFoId.get(o.id).id) : null);
|
|
1231
|
+
const pageOf = (list) => params.all ? list.slice(0, EXPORT_CAP) : list.slice((page - 1) * pageSize, page * pageSize);
|
|
1232
|
+
// 13p) Pickvoortgang (Engine): precies één aanroep per lijstverzoek, voor de
|
|
1233
|
+
// zichtbare rijen (incl. bufferleden) plus alle OPEN orders in de periode
|
|
1234
|
+
// (incoming/topick), zodat de telling "probleem" dezelfde blokkades ziet
|
|
1235
|
+
// als de iconen. Ontdubbeld, hooguit 500 id's (zichtbare rijen eerst),
|
|
1236
|
+
// hooguit 1,5 s; te laat → onderdeel valt terug, lijst laadt door.
|
|
1237
|
+
let pickTask = Promise.resolve();
|
|
1238
|
+
const pickProgressFor = !params.all && !params.localOrderId;
|
|
1239
|
+
if (pickProgressFor) {
|
|
1240
|
+
const openIds = withoutTab
|
|
1241
|
+
.filter((g) => { const st = stageOf(g); return st === "incoming" || st === "topick"; })
|
|
1242
|
+
.flat()
|
|
1243
|
+
.map(rowIdOf);
|
|
1244
|
+
const pageIds = params.tab === "problem" ? [] : pageOf(withoutTab.filter(matchesTab)).flat().map(rowIdOf);
|
|
1245
|
+
const pickIds = Array.from(new Set([...pageIds, ...openIds].filter((v) => !!v))).slice(0, 500);
|
|
1246
|
+
if (pickIds.length) {
|
|
1247
|
+
pickTask = t.time("13p_pickvoortgang", async () => {
|
|
1248
|
+
const res = await loadPickProgress(supabase, pickIds);
|
|
1249
|
+
features.pickProgress = res.available;
|
|
1250
|
+
warnings.push(...res.warnings);
|
|
1251
|
+
if (res.available)
|
|
1252
|
+
for (const g of withoutTab)
|
|
1253
|
+
for (const o of g) {
|
|
1254
|
+
const oid = rowIdOf(o);
|
|
1255
|
+
if (oid && res.pick.has(oid))
|
|
1256
|
+
o.pickProgress = res.pick.get(oid) ?? null;
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
else {
|
|
1261
|
+
features.pickProgress = true;
|
|
1262
|
+
}
|
|
1227
1263
|
}
|
|
1264
|
+
// Tabblad "Probleem" hangt van de blokkades af: dan eerst de pickvoortgang.
|
|
1265
|
+
if (params.tab === "problem")
|
|
1266
|
+
await pickTask;
|
|
1267
|
+
const filteredGroups = withoutTab.filter(matchesTab);
|
|
1228
1268
|
const totalCount = filteredGroups.length;
|
|
1229
|
-
const pageGroups =
|
|
1230
|
-
? filteredGroups.slice(0, EXPORT_CAP)
|
|
1231
|
-
: filteredGroups.slice((page - 1) * pageSize, page * pageSize);
|
|
1269
|
+
const pageGroups = pageOf(filteredGroups);
|
|
1232
1270
|
t.mark("13_filter");
|
|
1233
1271
|
// 14) Indelingsstatus + karren uit de Engine (logistics_order_plan_coverage),
|
|
1234
1272
|
// alleen voor de zichtbare rijen, in één keer opgehaald. Deze module telt
|
|
@@ -1246,19 +1284,6 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
1246
1284
|
o.orderRowId = idFor(o);
|
|
1247
1285
|
const ids = visible.map(idFor).filter((v) => !!v);
|
|
1248
1286
|
if (ids.length) {
|
|
1249
|
-
// Pickvoortgang alleen voor de zichtbare rijen (incl. bufferleden), max 1,5 s.
|
|
1250
|
-
if (!params.localOrderId)
|
|
1251
|
-
enrichTasks.push(t.time("14e_pickvoortgang", async () => {
|
|
1252
|
-
const res = await loadPickProgress(supabase, ids);
|
|
1253
|
-
features.pickProgress = res.available;
|
|
1254
|
-
warnings.push(...res.warnings);
|
|
1255
|
-
if (res.available)
|
|
1256
|
-
for (const o of visible) {
|
|
1257
|
-
const oid = idFor(o);
|
|
1258
|
-
if (oid)
|
|
1259
|
-
o.pickProgress = res.pick.get(oid) ?? null;
|
|
1260
|
-
}
|
|
1261
|
-
}));
|
|
1262
1287
|
// Ophaalmoment uit de Engine (nooit zelf rekenen).
|
|
1263
1288
|
enrichTasks.push(t.time("14a_vertrek", async () => {
|
|
1264
1289
|
try {
|
|
@@ -1400,8 +1425,34 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
1400
1425
|
}));
|
|
1401
1426
|
}
|
|
1402
1427
|
}
|
|
1403
|
-
await Promise.all(enrichTasks);
|
|
1428
|
+
await Promise.all([...enrichTasks, pickTask]);
|
|
1404
1429
|
t.mark("14_15_verrijking");
|
|
1430
|
+
// Tellingen na de pickvoortgang: KPI en iconen gebruiken dezelfde regel
|
|
1431
|
+
// (hasProblem in order-progress.ts).
|
|
1432
|
+
const statusCounts = {
|
|
1433
|
+
all: withoutTab.length,
|
|
1434
|
+
incoming: 0,
|
|
1435
|
+
topick: 0,
|
|
1436
|
+
backlog: 0,
|
|
1437
|
+
picked: 0,
|
|
1438
|
+
shipped: 0,
|
|
1439
|
+
cancelled: 0,
|
|
1440
|
+
not_reported: 0,
|
|
1441
|
+
invoiced: 0,
|
|
1442
|
+
problem: 0,
|
|
1443
|
+
};
|
|
1444
|
+
for (const g of withoutTab) {
|
|
1445
|
+
if (isNotReportedGroup(g))
|
|
1446
|
+
statusCounts.not_reported++;
|
|
1447
|
+
if (isBacklogGroup(g))
|
|
1448
|
+
statusCounts.backlog++;
|
|
1449
|
+
if (isInvoicedGroup(g))
|
|
1450
|
+
statusCounts.invoiced++;
|
|
1451
|
+
if (isProblemGroup(g))
|
|
1452
|
+
statusCounts.problem++;
|
|
1453
|
+
// Onbekende achterstand valt hier vanzelf terug onder "Te picken".
|
|
1454
|
+
statusCounts[stageOf(g)]++;
|
|
1455
|
+
}
|
|
1405
1456
|
const rows = pageGroups.map((g) => {
|
|
1406
1457
|
const row = mergeGroup(g);
|
|
1407
1458
|
const ids = Array.from(new Set(g.flatMap((m) => m.floridayStatusIds ?? [])));
|
|
@@ -1429,13 +1480,8 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
1429
1480
|
};
|
|
1430
1481
|
}
|
|
1431
1482
|
// Belading per productgroep: vaste referentiedata, 10 min in het servergeheugen.
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
if (groupPackingCache && Date.now() - groupPackingCache.at < TTL_MS)
|
|
1435
|
-
return groupPackingCache.value;
|
|
1436
|
-
const value = await loadGroupPackingUncached(supabase);
|
|
1437
|
-
groupPackingCache = { at: Date.now(), value };
|
|
1438
|
-
return value;
|
|
1483
|
+
async function loadGroupPacking(supabase, cacheKey) {
|
|
1484
|
+
return cachedRef(cacheKey, "groupPacking", () => loadGroupPackingUncached(supabase));
|
|
1439
1485
|
}
|
|
1440
1486
|
// Belading per productgroep (op naam), gebruikt voor "[Groep] X"-regels.
|
|
1441
1487
|
async function loadGroupPackingUncached(supabase) {
|