@flowselections/floriday-klanten-module 1.0.95 → 1.0.96
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/klanten/CustomerAssortmentTab.d.ts.map +1 -1
- package/dist-lib/components/klanten/CustomerAssortmentTab.js +7 -4
- package/dist-lib/lib/customer-assortment.functions.d.ts +2 -0
- package/dist-lib/lib/customer-assortment.functions.d.ts.map +1 -1
- package/dist-lib/lib/customer-assortment.functions.js +108 -32
- package/dist-lib/lib/floriday-catalog-prices.d.ts.map +1 -1
- package/dist-lib/lib/floriday-catalog-prices.js +5 -12
- package/dist-lib/lib/tabel-ontbreekt.d.ts +7 -0
- package/dist-lib/lib/tabel-ontbreekt.d.ts.map +1 -0
- package/dist-lib/lib/tabel-ontbreekt.js +21 -0
- package/dist-lib/lib/voorraad-assortiment.d.ts +25 -0
- package/dist-lib/lib/voorraad-assortiment.d.ts.map +1 -0
- package/dist-lib/lib/voorraad-assortiment.js +84 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomerAssortmentTab.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/CustomerAssortmentTab.tsx"],"names":[],"mappings":"AA0BA,wBAAgB,qBAAqB,CAAC,EACpC,WAAW,EACX,cAAc,GACf,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,+
|
|
1
|
+
{"version":3,"file":"CustomerAssortmentTab.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/CustomerAssortmentTab.tsx"],"names":[],"mappings":"AA0BA,wBAAgB,qBAAqB,CAAC,EACpC,WAAW,EACX,cAAc,GACf,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,+BAyWA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useState } from "react";
|
|
3
3
|
import { formatDateTime } from "../../lib/format-date.js";
|
|
4
4
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
@@ -47,7 +47,8 @@ export function CustomerAssortmentTab({ customerKey, organizationId, }) {
|
|
|
47
47
|
m.set(s.trade_item_key, s);
|
|
48
48
|
return m;
|
|
49
49
|
}, [stickerData]);
|
|
50
|
-
const items = data?.items
|
|
50
|
+
const items = Array.isArray(data?.items) ? data.items : [];
|
|
51
|
+
const bronLabel = data?.bron === "voorraad" ? "Bron: voorraad" : "Bron: Floriday";
|
|
51
52
|
const ownCount = items.filter((i) => i.in_assortment).length;
|
|
52
53
|
const otherCount = items.length - ownCount;
|
|
53
54
|
const hasOwnAssortment = ownCount > 0;
|
|
@@ -94,9 +95,11 @@ export function CustomerAssortmentTab({ customerKey, organizationId, }) {
|
|
|
94
95
|
const currency = pg?.currency ?? "EUR";
|
|
95
96
|
const defaultFormat = stickerData?.format ?? null;
|
|
96
97
|
if (items.length === 0) {
|
|
97
|
-
return (_jsx(Card, { children: _jsxs(CardContent, { className: "py-10 text-center space-y-1", children: [_jsx("p", { className: "text-
|
|
98
|
+
return (_jsx(Card, { children: _jsxs(CardContent, { className: "py-10 text-center space-y-1", children: [_jsx("p", { className: "text-xs text-muted-foreground", children: bronLabel }), data?.bron === "voorraad" ? (_jsx("p", { className: "text-sm font-medium", children: data?.melding === "geen_voorraadmodule"
|
|
99
|
+
? "Er is geen voorraad gevonden in deze omgeving."
|
|
100
|
+
: "Er staan nog geen artikelen in de voorraad." })) : (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-sm font-medium", children: "Nog geen assortiment beschikbaar" }), _jsx("p", { className: "text-xs text-muted-foreground", children: "Er staan nog geen handelsartikelen uit Floriday klaar voor deze klant." })] }))] }) }));
|
|
98
101
|
}
|
|
99
|
-
return (_jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground", children: [_jsxs("span", { children: [_jsx("strong", { className: "text-foreground", children: ownCount }), " geselecteerd assortiment"] }), _jsxs("span", { children: [_jsx("strong", { className: "text-foreground", children: data?.summary.total ?? 0 }), " artikelen in ons aanbod"] }), _jsxs("span", { children: [_jsx("strong", { className: "text-foreground", children: data?.summary.priced ?? 0 }), " met klantprijs"] }), pg ? (_jsxs("span", { children: ["Prijsgroep: ", _jsx("strong", { className: "text-foreground", children: pg.name }), pg.pricing_mode === "calculated" && pg.calc_value
|
|
102
|
+
return (_jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground", children: [_jsx("span", { className: "font-medium text-foreground", children: bronLabel }), _jsxs("span", { children: [_jsx("strong", { className: "text-foreground", children: ownCount }), " geselecteerd assortiment"] }), _jsxs("span", { children: [_jsx("strong", { className: "text-foreground", children: data?.summary.total ?? 0 }), " artikelen in ons aanbod"] }), _jsxs("span", { children: [_jsx("strong", { className: "text-foreground", children: data?.summary.priced ?? 0 }), " met klantprijs"] }), pg ? (_jsxs("span", { children: ["Prijsgroep: ", _jsx("strong", { className: "text-foreground", children: pg.name }), pg.pricing_mode === "calculated" && pg.calc_value
|
|
100
103
|
? ` (${pg.calc_type === "surcharge" ? "toeslag" : "korting"} ${pg.calc_value}${pg.calc_value_type === "percentage" ? "%" : ` ${currency}`})`
|
|
101
104
|
: ""] })) : (_jsx("span", { className: "text-warning-soft-foreground", children: "Geen prijsgroep ingesteld voor deze klant" })), data?.summary.last_synced_at && (_jsxs("span", { children: ["laatste sync: ", formatDateTime(data.summary.last_synced_at)] }))] }), _jsxs("div", { className: "flex flex-wrap items-center gap-2 text-xs text-muted-foreground", children: [_jsxs("span", { children: ["Stickerformaat:", " ", _jsx("strong", { className: "text-foreground", children: defaultFormat
|
|
102
105
|
? `${defaultFormat.width_mm} × ${defaultFormat.height_mm} mm`
|
|
@@ -43,6 +43,8 @@ export type CustomerAssortmentResult = {
|
|
|
43
43
|
in_assortment: number;
|
|
44
44
|
last_synced_at: string | null;
|
|
45
45
|
};
|
|
46
|
+
bron: "voorraad" | "floriday";
|
|
47
|
+
melding: "geen_voorraadmodule" | null;
|
|
46
48
|
};
|
|
47
49
|
export declare const listCustomerAssortment: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
48
50
|
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer-assortment.functions.d.ts","sourceRoot":"","sources":["../../src/lib/customer-assortment.functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"customer-assortment.functions.d.ts","sourceRoot":"","sources":["../../src/lib/customer-assortment.functions.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,sBAAsB,GAAG;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,aAAa,GAAG,UAAU,GAAG,IAAI,CAAC;IACnD,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAGF,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,sBAAsB,EAAE,CAAC;IAChC,UAAU,EAAE;QACV,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,IAAI,CAAC;IACT,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,MAAM,CAAC;QACtB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;KAC/B,CAAC;IACF,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAC9B,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACvC,CAAC;AAuCF,eAAO,MAAM,sBAAsB;;;;8CAET,OAAO;;;qCA+U7B,CAAC"}
|
|
@@ -4,6 +4,8 @@ import { z } from "zod";
|
|
|
4
4
|
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
5
5
|
import { computePrice } from "./pricing.js";
|
|
6
6
|
import { loadFloridayCatalogPrices } from "./floriday-catalog-prices.js";
|
|
7
|
+
import { isTabelOntbreekt } from "./tabel-ontbreekt.js";
|
|
8
|
+
import { laadVoorraadAssortiment } from "./voorraad-assortiment.js";
|
|
7
9
|
function str(...vals) {
|
|
8
10
|
for (const v of vals) {
|
|
9
11
|
if (typeof v === "string" && v.trim())
|
|
@@ -79,13 +81,6 @@ export const listCustomerAssortment = createServerFn({ method: "POST" })
|
|
|
79
81
|
if (r?.in_assortment !== false)
|
|
80
82
|
ownAssortment.add(String(r.trade_item_key));
|
|
81
83
|
}
|
|
82
|
-
// 2) Alle Floriday-handelsartikelen uit de cache
|
|
83
|
-
const { data: cacheRows, error: cacheErr } = await fetchAllPagedResult((from, to) => sb
|
|
84
|
-
.from("floriday_trade_items_cache")
|
|
85
|
-
.select("floriday_id, data, fetched_at")
|
|
86
|
-
.eq("is_deleted", false).range(from, to));
|
|
87
|
-
if (cacheErr)
|
|
88
|
-
throw new Error(cacheErr.message);
|
|
89
84
|
// 3) Handmatige prijzen per artikel binnen de prijsgroep
|
|
90
85
|
const manual = new Map();
|
|
91
86
|
if (group?.id) {
|
|
@@ -102,6 +97,109 @@ export const listCustomerAssortment = createServerFn({ method: "POST" })
|
|
|
102
97
|
});
|
|
103
98
|
}
|
|
104
99
|
}
|
|
100
|
+
const calc = group
|
|
101
|
+
? {
|
|
102
|
+
pricing_mode: group.pricing_mode === "calculated" ? "calculated" : "manual",
|
|
103
|
+
calc_type: group.calc_type ?? null,
|
|
104
|
+
calc_value_type: group.calc_value_type ?? null,
|
|
105
|
+
calc_value: group.calc_value != null ? Number(group.calc_value) : null,
|
|
106
|
+
handling_fee: group.handling_fee != null ? Number(group.handling_fee) : null,
|
|
107
|
+
distribute_over: group.distribute_over ?? null,
|
|
108
|
+
rounding: group.rounding ?? "none",
|
|
109
|
+
rounding_step: group.rounding_step != null ? Number(group.rounding_step) : null,
|
|
110
|
+
}
|
|
111
|
+
: null;
|
|
112
|
+
const priceGroupOut = group
|
|
113
|
+
? {
|
|
114
|
+
id: group.id,
|
|
115
|
+
name: group.name,
|
|
116
|
+
currency: group.currency ?? "EUR",
|
|
117
|
+
pricing_mode: group.pricing_mode,
|
|
118
|
+
calc_type: group.calc_type ?? null,
|
|
119
|
+
calc_value_type: group.calc_value_type ?? null,
|
|
120
|
+
calc_value: group.calc_value != null ? Number(group.calc_value) : null,
|
|
121
|
+
handling_fee: group.handling_fee != null ? Number(group.handling_fee) : null,
|
|
122
|
+
rounding: group.rounding ?? "none",
|
|
123
|
+
}
|
|
124
|
+
: null;
|
|
125
|
+
// Geen Floriday-klant: assortiment uit de voorraad (products)
|
|
126
|
+
if (!orgId || !orgId.trim()) {
|
|
127
|
+
const { rijen, geenVoorraadModule } = await laadVoorraadAssortiment(sb);
|
|
128
|
+
const cur = group?.currency ?? "EUR";
|
|
129
|
+
const vItems = rijen.map((r) => {
|
|
130
|
+
const man = manual.get(r.key) ?? null;
|
|
131
|
+
const base = r.sale_price;
|
|
132
|
+
let price = null;
|
|
133
|
+
let discountAmount = 0;
|
|
134
|
+
let handlingPerUnit = 0;
|
|
135
|
+
let source = null;
|
|
136
|
+
if (man) {
|
|
137
|
+
price = man.price;
|
|
138
|
+
source = group?.name ? `Prijsgroep ${group.name}` : "Prijsgroep";
|
|
139
|
+
}
|
|
140
|
+
else if (base != null && calc) {
|
|
141
|
+
const c = computePrice(base, calc, {
|
|
142
|
+
unitsPerFust: r.plants_per_crate ?? 1,
|
|
143
|
+
packagesPerLayer: r.crates_per_layer ?? 1,
|
|
144
|
+
layersPerCarrier: r.layers_per_cart ?? 1,
|
|
145
|
+
});
|
|
146
|
+
price = c.rounded;
|
|
147
|
+
discountAmount = c.discountAmount;
|
|
148
|
+
handlingPerUnit = c.handlingPerUnit;
|
|
149
|
+
source = group?.name ? `Prijsgroep ${group.name}` : "Berekende prijs";
|
|
150
|
+
}
|
|
151
|
+
else if (base != null) {
|
|
152
|
+
price = base;
|
|
153
|
+
source = "Eigen artikelprijs";
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
key: r.key,
|
|
157
|
+
trade_item_id: r.key,
|
|
158
|
+
name: r.name,
|
|
159
|
+
supplier_article_code: r.article_number,
|
|
160
|
+
vbn_code: null,
|
|
161
|
+
image_url: r.image_url,
|
|
162
|
+
botanical_name: null,
|
|
163
|
+
country_of_origin: null,
|
|
164
|
+
packaging: null,
|
|
165
|
+
pieces_per_package: r.plants_per_crate,
|
|
166
|
+
packages_per_layer: r.crates_per_layer,
|
|
167
|
+
layers_per_carrier: r.layers_per_cart,
|
|
168
|
+
restricted: false,
|
|
169
|
+
base_price: base,
|
|
170
|
+
base_price_source: source,
|
|
171
|
+
price,
|
|
172
|
+
currency: man?.currency ?? cur,
|
|
173
|
+
unit: group?.unit ?? null,
|
|
174
|
+
discount_amount: discountAmount,
|
|
175
|
+
handling_per_unit: handlingPerUnit,
|
|
176
|
+
floriday_source: null,
|
|
177
|
+
floriday_source_label: null,
|
|
178
|
+
in_assortment: ownAssortment.has(r.key),
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
vItems.sort((a, b) => a.name.localeCompare(b.name, "nl"));
|
|
182
|
+
return {
|
|
183
|
+
items: vItems,
|
|
184
|
+
priceGroup: priceGroupOut,
|
|
185
|
+
summary: {
|
|
186
|
+
total: vItems.length,
|
|
187
|
+
priced: vItems.filter((i) => i.price != null).length,
|
|
188
|
+
restricted: 0,
|
|
189
|
+
in_assortment: vItems.filter((i) => i.in_assortment).length,
|
|
190
|
+
last_synced_at: null,
|
|
191
|
+
},
|
|
192
|
+
bron: "voorraad",
|
|
193
|
+
melding: geenVoorraadModule ? "geen_voorraadmodule" : null,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
// 2) Alle Floriday-handelsartikelen uit de cache
|
|
197
|
+
const { data: cacheRows, error: cacheErr } = await fetchAllPagedResult((from, to) => sb
|
|
198
|
+
.from("floriday_trade_items_cache")
|
|
199
|
+
.select("floriday_id, data, fetched_at")
|
|
200
|
+
.eq("is_deleted", false).range(from, to));
|
|
201
|
+
if (cacheErr && !isTabelOntbreekt(cacheErr))
|
|
202
|
+
throw new Error(cacheErr.message);
|
|
105
203
|
// 4) Basisprijzen uit eigen producten (gekoppeld op trade item)
|
|
106
204
|
const { data: prods } = await sb
|
|
107
205
|
.from("products")
|
|
@@ -175,18 +273,6 @@ export const listCustomerAssortment = createServerFn({ method: "POST" })
|
|
|
175
273
|
}
|
|
176
274
|
// 6) Catalogusprijzen uit de Floriday-authenticatiemodule (supply lines)
|
|
177
275
|
const catalog = await loadFloridayCatalogPrices(sb, { priceGroupNames: floridayGroupNames });
|
|
178
|
-
const calc = group
|
|
179
|
-
? {
|
|
180
|
-
pricing_mode: group.pricing_mode === "calculated" ? "calculated" : "manual",
|
|
181
|
-
calc_type: group.calc_type ?? null,
|
|
182
|
-
calc_value_type: group.calc_value_type ?? null,
|
|
183
|
-
calc_value: group.calc_value != null ? Number(group.calc_value) : null,
|
|
184
|
-
handling_fee: group.handling_fee != null ? Number(group.handling_fee) : null,
|
|
185
|
-
distribute_over: group.distribute_over ?? null,
|
|
186
|
-
rounding: group.rounding ?? "none",
|
|
187
|
-
rounding_step: group.rounding_step != null ? Number(group.rounding_step) : null,
|
|
188
|
-
}
|
|
189
|
-
: null;
|
|
190
276
|
const currency = group?.currency ?? "EUR";
|
|
191
277
|
const items = [];
|
|
192
278
|
let restrictedCount = 0;
|
|
@@ -269,19 +355,7 @@ export const listCustomerAssortment = createServerFn({ method: "POST" })
|
|
|
269
355
|
items.sort((a, b) => a.name.localeCompare(b.name, "nl"));
|
|
270
356
|
return {
|
|
271
357
|
items,
|
|
272
|
-
priceGroup:
|
|
273
|
-
? {
|
|
274
|
-
id: group.id,
|
|
275
|
-
name: group.name,
|
|
276
|
-
currency: group.currency ?? "EUR",
|
|
277
|
-
pricing_mode: group.pricing_mode,
|
|
278
|
-
calc_type: group.calc_type ?? null,
|
|
279
|
-
calc_value_type: group.calc_value_type ?? null,
|
|
280
|
-
calc_value: group.calc_value != null ? Number(group.calc_value) : null,
|
|
281
|
-
handling_fee: group.handling_fee != null ? Number(group.handling_fee) : null,
|
|
282
|
-
rounding: group.rounding ?? "none",
|
|
283
|
-
}
|
|
284
|
-
: null,
|
|
358
|
+
priceGroup: priceGroupOut,
|
|
285
359
|
summary: {
|
|
286
360
|
total: items.length,
|
|
287
361
|
priced: items.filter((i) => i.price != null).length,
|
|
@@ -289,5 +363,7 @@ export const listCustomerAssortment = createServerFn({ method: "POST" })
|
|
|
289
363
|
in_assortment: items.filter((i) => i.in_assortment).length,
|
|
290
364
|
last_synced_at: lastSynced,
|
|
291
365
|
},
|
|
366
|
+
bron: "floriday",
|
|
367
|
+
melding: null,
|
|
292
368
|
};
|
|
293
369
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floriday-catalog-prices.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-catalog-prices.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"floriday-catalog-prices.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-catalog-prices.ts"],"names":[],"mappings":"AACA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,gBAAgB,CAAC;IAC/C,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AA2BF;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,EAAE,EAAE,GAAG,EACP,IAAI,GAAE;IAAE,eAAe,CAAC,EAAE,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC;IAAC,YAAY,CAAC,EAAE,IAAI,CAAA;CAAO,GAClF,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAoEpC"}
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Leeslogica voor Floriday-catalogusprijzen.
|
|
3
|
-
*
|
|
4
|
-
* Bron: public.floriday_catalog_prices_cache — gevuld door de Floriday-
|
|
5
|
-
* authenticatiemodule (supply lines). Deze module is read-only: nooit zelf
|
|
6
|
-
* vullen of muteren.
|
|
7
|
-
*
|
|
8
|
-
* Keuzeregel per artikel: klantgroepprijs > weekprijs > basisprijs.
|
|
9
|
-
* Weekprijzen matchen op ISO jaar/week of op valid_from/valid_to rondom de
|
|
10
|
-
* leverdatum.
|
|
11
|
-
*/
|
|
1
|
+
import { isTabelOntbreekt } from "./tabel-ontbreekt.js";
|
|
12
2
|
function isoYearWeek(d) {
|
|
13
3
|
const t = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
|
|
14
4
|
const day = t.getUTCDay() || 7;
|
|
@@ -52,8 +42,11 @@ export async function loadFloridayCatalogPrices(sb, opts = {}) {
|
|
|
52
42
|
.select("trade_item_id, supplier_article_code, price, currency, price_type, price_group_name, sales_unit, year, week, valid_from, valid_to")
|
|
53
43
|
.eq("is_deleted", false)
|
|
54
44
|
.range(from, from + pageSize - 1);
|
|
55
|
-
if (error)
|
|
45
|
+
if (error) {
|
|
46
|
+
if (isTabelOntbreekt(error))
|
|
47
|
+
break;
|
|
56
48
|
throw new Error(error.message);
|
|
49
|
+
}
|
|
57
50
|
const rows = data ?? [];
|
|
58
51
|
for (const row of rows) {
|
|
59
52
|
const id = row?.trade_item_id ? String(row.trade_item_id) : null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Herkent alleen een ontbrekende tabel (andere module niet geïnstalleerd).
|
|
3
|
+
* Bewust NIET de losse tekst "schema cache": die komt ook voor bij een
|
|
4
|
+
* ontbrekende kolom (PGRST204), en dat moet een gewone fout blijven.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isTabelOntbreekt(error: unknown): boolean;
|
|
7
|
+
//# sourceMappingURL=tabel-ontbreekt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabel-ontbreekt.d.ts","sourceRoot":"","sources":["../../src/lib/tabel-ontbreekt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAUxD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Herkent alleen een ontbrekende tabel (andere module niet geïnstalleerd).
|
|
3
|
+
* Bewust NIET de losse tekst "schema cache": die komt ook voor bij een
|
|
4
|
+
* ontbrekende kolom (PGRST204), en dat moet een gewone fout blijven.
|
|
5
|
+
*/
|
|
6
|
+
export function isTabelOntbreekt(error) {
|
|
7
|
+
if (!error || typeof error !== "object")
|
|
8
|
+
return false;
|
|
9
|
+
const e = error;
|
|
10
|
+
const code = typeof e.code === "string" ? e.code : "";
|
|
11
|
+
if (code === "42P01" || code === "PGRST205")
|
|
12
|
+
return true;
|
|
13
|
+
if (code === "PGRST204")
|
|
14
|
+
return false;
|
|
15
|
+
const msg = typeof e.message === "string" ? e.message : "";
|
|
16
|
+
if (/relation\s+"?[^"]*"?\s+does not exist/i.test(msg))
|
|
17
|
+
return true;
|
|
18
|
+
if (/could not find the table/i.test(msg))
|
|
19
|
+
return true;
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type VoorraadRij = {
|
|
2
|
+
key: string;
|
|
3
|
+
name: string;
|
|
4
|
+
article_number: string | null;
|
|
5
|
+
image_url: string | null;
|
|
6
|
+
plants_per_crate: number | null;
|
|
7
|
+
crates_per_layer: number | null;
|
|
8
|
+
layers_per_cart: number | null;
|
|
9
|
+
sale_price: number | null;
|
|
10
|
+
};
|
|
11
|
+
/** Sleutel: actief Floriday-handelsartikel → trade_item_key → products.id. */
|
|
12
|
+
export declare function voorraadSleutel(p: any, geldigeFloridayIds: Set<string>): string | null;
|
|
13
|
+
/** Slaat gearchiveerde producten over en voegt partijen met dezelfde sleutel samen. */
|
|
14
|
+
export declare function bouwVoorraadRijen(products: unknown, geldigeFloridayIds: Set<string>): VoorraadRij[];
|
|
15
|
+
/** Leest een tabel van een andere module; ontbreekt die tabel, dan null (anders fout). */
|
|
16
|
+
export declare function leesOptioneleTabel(page: (from: number, to: number) => PromiseLike<{
|
|
17
|
+
data: unknown;
|
|
18
|
+
error: any;
|
|
19
|
+
}>): Promise<any[] | null>;
|
|
20
|
+
export type VoorraadLaad = {
|
|
21
|
+
rijen: VoorraadRij[];
|
|
22
|
+
geenVoorraadModule: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function laadVoorraadAssortiment(sb: any): Promise<VoorraadLaad>;
|
|
25
|
+
//# sourceMappingURL=voorraad-assortiment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voorraad-assortiment.d.ts","sourceRoot":"","sources":["../../src/lib/voorraad-assortiment.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAaF,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI,CAItF;AAED,uFAAuF;AACvF,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,WAAW,EAAE,CAgCnG;AAED,0FAA0F;AAC1F,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,WAAW,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,GAAG,CAAA;CAAE,CAAC,GAC7E,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAOvB;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAAC,kBAAkB,EAAE,OAAO,CAAA;CAAE,CAAC;AAEjF,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,CAS5E"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { fetchAllPagedResult } from "./fetch-all-paged.js";
|
|
2
|
+
import { isTabelOntbreekt } from "./tabel-ontbreekt.js";
|
|
3
|
+
function s(v) {
|
|
4
|
+
if (typeof v === "string" && v.trim())
|
|
5
|
+
return v.trim();
|
|
6
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
7
|
+
return String(v);
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
function n(v) {
|
|
11
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
12
|
+
return v;
|
|
13
|
+
if (typeof v === "string" && v.trim() && !Number.isNaN(Number(v)))
|
|
14
|
+
return Number(v);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
/** Sleutel: actief Floriday-handelsartikel → trade_item_key → products.id. */
|
|
18
|
+
export function voorraadSleutel(p, geldigeFloridayIds) {
|
|
19
|
+
const fl = s(p?.floriday_trade_item_id);
|
|
20
|
+
if (fl && geldigeFloridayIds.has(fl))
|
|
21
|
+
return fl;
|
|
22
|
+
return s(p?.trade_item_key) ?? s(p?.id);
|
|
23
|
+
}
|
|
24
|
+
/** Slaat gearchiveerde producten over en voegt partijen met dezelfde sleutel samen. */
|
|
25
|
+
export function bouwVoorraadRijen(products, geldigeFloridayIds) {
|
|
26
|
+
const lijst = Array.isArray(products) ? products : [];
|
|
27
|
+
const map = new Map();
|
|
28
|
+
for (const p of lijst) {
|
|
29
|
+
if (!p || typeof p !== "object")
|
|
30
|
+
continue;
|
|
31
|
+
if (p.gearchiveerd_at != null && p.gearchiveerd_at !== "")
|
|
32
|
+
continue;
|
|
33
|
+
const key = voorraadSleutel(p, geldigeFloridayIds);
|
|
34
|
+
if (!key)
|
|
35
|
+
continue;
|
|
36
|
+
const nieuw = {
|
|
37
|
+
key,
|
|
38
|
+
name: s(p.product) ?? s(p.article_number) ?? key,
|
|
39
|
+
article_number: s(p.article_number),
|
|
40
|
+
image_url: s(p.image_url),
|
|
41
|
+
plants_per_crate: n(p.plants_per_crate),
|
|
42
|
+
crates_per_layer: n(p.crates_per_layer),
|
|
43
|
+
layers_per_cart: n(p.layers_per_cart),
|
|
44
|
+
sale_price: n(p.sale_price),
|
|
45
|
+
};
|
|
46
|
+
const oud = map.get(key);
|
|
47
|
+
if (!oud) {
|
|
48
|
+
map.set(key, nieuw);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
map.set(key, {
|
|
52
|
+
key,
|
|
53
|
+
name: oud.name !== key ? oud.name : nieuw.name,
|
|
54
|
+
article_number: oud.article_number ?? nieuw.article_number,
|
|
55
|
+
image_url: oud.image_url ?? nieuw.image_url,
|
|
56
|
+
plants_per_crate: oud.plants_per_crate ?? nieuw.plants_per_crate,
|
|
57
|
+
crates_per_layer: oud.crates_per_layer ?? nieuw.crates_per_layer,
|
|
58
|
+
layers_per_cart: oud.layers_per_cart ?? nieuw.layers_per_cart,
|
|
59
|
+
sale_price: oud.sale_price ?? nieuw.sale_price,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return [...map.values()];
|
|
63
|
+
}
|
|
64
|
+
/** Leest een tabel van een andere module; ontbreekt die tabel, dan null (anders fout). */
|
|
65
|
+
export async function leesOptioneleTabel(page) {
|
|
66
|
+
const { data, error } = await fetchAllPagedResult(page);
|
|
67
|
+
if (error) {
|
|
68
|
+
if (isTabelOntbreekt(error))
|
|
69
|
+
return null;
|
|
70
|
+
throw new Error(error.message ?? "Lezen mislukt");
|
|
71
|
+
}
|
|
72
|
+
return Array.isArray(data) ? data : [];
|
|
73
|
+
}
|
|
74
|
+
export async function laadVoorraadAssortiment(sb) {
|
|
75
|
+
const products = await leesOptioneleTabel((from, to) => sb.from("products").select("*").range(from, to));
|
|
76
|
+
if (products === null)
|
|
77
|
+
return { rijen: [], geenVoorraadModule: true };
|
|
78
|
+
const cache = await leesOptioneleTabel((from, to) => sb.from("floriday_trade_items_cache").select("floriday_id").eq("is_deleted", false).range(from, to));
|
|
79
|
+
const geldig = new Set();
|
|
80
|
+
for (const r of cache ?? [])
|
|
81
|
+
if (r?.floriday_id)
|
|
82
|
+
geldig.add(String(r.floriday_id));
|
|
83
|
+
return { rijen: bouwVoorraadRijen(products, geldig), geenVoorraadModule: false };
|
|
84
|
+
}
|