@flowselections/floriday-verkoop-module 1.0.51 → 1.0.53

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.
@@ -23,7 +23,7 @@ export async function replanScopeInternal(scope) {
23
23
  throw new Error("replanScopeInternal: geen scope");
24
24
  let ordersQuery = supabaseAdmin
25
25
  .from("orders")
26
- .select("id, custom_fields, plan_locked_at")
26
+ .select("id, order_number, custom_fields, plan_locked_at")
27
27
  .is("deleted_at", null);
28
28
  ordersQuery = bufferId
29
29
  ? ordersQuery.eq("buffer_id", bufferId)
@@ -31,6 +31,11 @@ export async function replanScopeInternal(scope) {
31
31
  const { data: orders } = await ordersQuery;
32
32
  const orderRows = (orders ?? []);
33
33
  const orderIds = orderRows.map((o) => o.id);
34
+ const orderNumberById = new Map();
35
+ for (const o of orderRows) {
36
+ if (o.order_number)
37
+ orderNumberById.set(o.id, String(o.order_number));
38
+ }
34
39
  if (orderRows.some((o) => o.plan_locked_at)) {
35
40
  return {
36
41
  ok: true,
@@ -53,26 +58,100 @@ export async function replanScopeInternal(scope) {
53
58
  throw new Error(itErr.message);
54
59
  // Onbekend blijft onbekend: geen ?? 1. De planner blokkeert regels
55
60
  // zonder (volledige) belading in plaats van 1×1×1 te plannen.
56
- const pick = (a, b) => {
57
- for (const v of [a, b]) {
58
- if (v === null || v === undefined)
59
- continue;
60
- const n = Number(v);
61
- if (Number.isFinite(n) && n > 0)
62
- return Math.round(n);
61
+ const pos = (v) => {
62
+ if (v === null || v === undefined)
63
+ return null;
64
+ const n = Number(v);
65
+ return Number.isFinite(n) && n > 0 ? Math.round(n) : null;
66
+ };
67
+ /** Een bron telt alleen als álle drie de velden gevuld zijn (> 0). */
68
+ const completeSource = (plants_per_crate, crates_per_layer, layers_per_cart) => {
69
+ const a = pos(plants_per_crate);
70
+ const b = pos(crates_per_layer);
71
+ const c = pos(layers_per_cart);
72
+ return a && b && c ? { plants_per_crate: a, crates_per_layer: b, layers_per_cart: c } : null;
73
+ };
74
+ // Beladingbron per order: custom_fields.floriday_packing bevat de belading
75
+ // zoals die in Floriday op de order staat. Dat zijn de packing-VELDEN
76
+ // (pieces_per_package / packages_per_layer / layers_per_load_carrier) —
77
+ // géén voorgekauwde karrenlijst; de karindeling rekenen we zelf.
78
+ const floridayByOrder = new Map();
79
+ const loadCarrierByOrder = new Map();
80
+ for (const o of orderRows) {
81
+ const fp = (o.custom_fields ?? {})?.floriday_packing ?? null;
82
+ if (!fp)
83
+ continue;
84
+ const bel = completeSource(fp.pieces_per_package, fp.packages_per_layer, fp.layers_per_load_carrier);
85
+ if (bel)
86
+ floridayByOrder.set(o.id, bel);
87
+ const lc = typeof fp.load_carrier === "string" ? fp.load_carrier.trim() : "";
88
+ if (lc)
89
+ loadCarrierByOrder.set(o.id, lc.toUpperCase());
90
+ }
91
+ // ── Ladingdragerprofiel ────────────────────────────────────────────────
92
+ // Vertrouw NIET op de kolomdefault 'trolley' van order_carts: die verbergt
93
+ // dat er geen profielkeuze is gemaakt. Zonder profiel plannen we niet.
94
+ const { data: carrierProfiles } = await supabaseAdmin
95
+ .from("load_carrier_types")
96
+ .select("id, code, name, layers_per_carrier, is_active, is_default");
97
+ const activeProfiles = (carrierProfiles ?? []).filter((p) => p.is_active);
98
+ const defaultProfile = activeProfiles.find((p) => p.is_default) ??
99
+ activeProfiles.find((p) => String(p.code).toLowerCase() === "trolley") ??
100
+ null;
101
+ /** Floriday-ladingdragercode → code in load_carrier_types. */
102
+ const CARRIER_CODE_MAP = {
103
+ DANISH_TROLLEY: ["danish_container", "danish_trolley"],
104
+ DANISH_TROLLEY_NON_CC_RFID: ["danish_container"],
105
+ DANISH_TROLLEY_WATER_TRAY: ["danish_container"],
106
+ ONE_THIRD_DANISH_TROLLEY: ["danish_container"],
107
+ AUCTION_TROLLEY: ["auction_trolley", "trolley"],
108
+ EURO_TROLLEY: ["euro_rolcontainer", "trolley"],
109
+ ROLL_CONTAINER: ["euro_rolcontainer"],
110
+ EURO_PALLET: ["euro_pallet", "pallet"],
111
+ HT_EURO_PALLET: ["euro_pallet", "pallet"],
112
+ PALLET: ["pallet"],
113
+ BLOCK_PALLET: ["pallet"],
114
+ NONE: ["loose"],
115
+ };
116
+ const profileFor = (loadCarrier) => {
117
+ if (!loadCarrier)
118
+ return defaultProfile;
119
+ const direct = activeProfiles.find((p) => String(p.code).toUpperCase() === loadCarrier.toUpperCase());
120
+ if (direct)
121
+ return direct;
122
+ for (const code of CARRIER_CODE_MAP[loadCarrier.toUpperCase()] ?? []) {
123
+ const hit = activeProfiles.find((p) => String(p.code).toLowerCase() === code);
124
+ if (hit)
125
+ return hit;
63
126
  }
64
- return null;
127
+ return defaultProfile;
65
128
  };
129
+ let usedFloridayPacking = false;
66
130
  const inputs = (items ?? []).map((it) => {
67
131
  const prod = it.products ?? {};
132
+ // Volgorde: floriday_packing → orderregel → product. Niet coalescen per
133
+ // veld: een half-Floriday/half-orderregel-belading is geen belading.
134
+ const fromFloriday = floridayByOrder.get(it.order_id) ?? null;
135
+ const bel = fromFloriday ??
136
+ completeSource(it.plants_per_crate, it.crates_per_layer, it.layers_per_cart) ??
137
+ completeSource(prod.plants_per_crate, prod.crates_per_layer, prod.layers_per_cart);
138
+ if (bel && fromFloriday)
139
+ usedFloridayPacking = true;
140
+ const loadCarrier = loadCarrierByOrder.get(it.order_id) ?? null;
141
+ // layers_per_cart = LEAST(profiel, bron) — identiek aan logistics_plan_buffer_sql.
142
+ const profileLayers = pos(profileFor(loadCarrier)?.layers_per_carrier);
143
+ const layers = bel?.layers_per_cart != null && profileLayers != null
144
+ ? Math.min(bel.layers_per_cart, profileLayers)
145
+ : (bel?.layers_per_cart ?? null);
68
146
  return {
69
147
  order_item_id: it.id,
70
148
  product_id: it.product_id,
71
149
  product_name: it.product_name,
72
150
  plants: Math.max(0, Number(it.quantity ?? 0)),
73
- plants_per_crate: pick(it.plants_per_crate, prod.plants_per_crate),
74
- crates_per_layer: pick(it.crates_per_layer, prod.crates_per_layer),
75
- layers_per_cart: pick(it.layers_per_cart, prod.layers_per_cart),
151
+ plants_per_crate: bel?.plants_per_crate ?? null,
152
+ crates_per_layer: bel?.crates_per_layer ?? null,
153
+ layers_per_cart: layers,
154
+ load_carrier: loadCarrier,
76
155
  };
77
156
  });
78
157
  // Item → order-map voor het toewijzen van cart.order_id bij homogene karren.
@@ -81,48 +160,25 @@ export async function replanScopeInternal(scope) {
81
160
  itemToOrder.set(it.id, it.order_id);
82
161
  }
83
162
  // Bestaande karren in de scope tellen (voor waarschuwing) en wissen.
163
+ // Nummering én delete-scope liggen altijd op bufferniveau als de order een
164
+ // buffer heeft; order-scope is uitsluitend terugval.
165
+ if (!bufferId) {
166
+ console.warn("[cart-replan] geen buffer voor order %s — nummering en delete vallen terug op order-scope", soloOrderId);
167
+ }
84
168
  const cartScope = (q) => bufferId ? q.eq("buffer_id", bufferId) : q.eq("order_id", soloOrderId);
85
169
  const { data: existingCarts } = await cartScope(supabaseAdmin.from("order_carts").select("id, source"));
86
170
  const replacedManualCount = (existingCarts ?? []).filter((c) => c.source === "manual").length;
87
171
  const { error: delErr } = await cartScope(supabaseAdmin.from("order_carts").delete());
88
172
  if (delErr)
89
173
  throw new Error(delErr.message);
90
- // Floriday-packingConfiguration-fallback: alleen als de buffer precies één
91
- // order bevat én die order een volledig Floriday-packingConfiguration heeft.
92
- let usedFloridayPacking = false;
93
- let plannedCarts = [];
174
+ // De karindeling wordt hier altijd zelf gerekend. custom_fields.floriday_packing
175
+ // levert alleen de belading-VELDEN (pieces_per_package / packages_per_layer /
176
+ // layers_per_load_carrier) — de mirror schrijft nooit een voorgekauwde
177
+ // carts-array, dus die tak bestaat bewust niet meer.
178
+ const plannedCarts = [];
94
179
  const warnings = [];
95
180
  let blockedItems = [];
96
- const solo = orderRows.length === 1 ? orderRows[0] : null;
97
- const soloCustom = solo?.custom_fields ?? {};
98
- const floridayPacking = soloCustom?.floriday_packing ?? null;
99
- const isFo = solo && (soloCustom?.source === "floriday" || floridayPacking?.pieces_per_package);
100
- if (isFo && floridayPacking && Array.isArray(floridayPacking.carts)) {
101
- usedFloridayPacking = true;
102
- plannedCarts = floridayPacking.carts.map((c, idx) => {
103
- const cItems = (c.items ?? []).map((i) => ({
104
- order_item_id: i.order_item_id,
105
- product_id: i.product_id ?? null,
106
- product_name: i.product_name ?? "—",
107
- crates: Number(i.crates ?? 0),
108
- plants: Number(i.plants ?? Number(i.crates ?? 0) * Number(i.plants_per_crate ?? 1)),
109
- plants_per_crate: Math.max(1, Number(i.plants_per_crate ?? 1)),
110
- crates_per_layer: Math.max(1, Number(i.crates_per_layer ?? 1)),
111
- layers_per_cart: Math.max(1, Number(i.layers_per_cart ?? 1)),
112
- layer_fraction: Number(i.layer_fraction ?? 1),
113
- layer_share_pct: Number(i.layer_share_pct ?? 100),
114
- }));
115
- return {
116
- cart_number: idx + 1,
117
- source: "auto",
118
- is_complete: !!c.is_complete,
119
- occupancy_pct: Number(c.occupancy_pct ?? 100),
120
- total_layers_used: Number(c.total_layers_used ?? 1),
121
- items: cItems,
122
- };
123
- });
124
- }
125
- else {
181
+ {
126
182
  const [{ data: settings }, { data: overrides }] = await Promise.all([
127
183
  supabaseAdmin.from("cart_planning_settings").select("*").eq("id", 1).maybeSingle(),
128
184
  supabaseAdmin.from("cart_planning_product_overrides").select("product_id, never_mix"),
@@ -130,13 +186,50 @@ export async function replanScopeInternal(scope) {
130
186
  const neverMix = new Set((overrides ?? [])
131
187
  .filter((o) => o.never_mix && o.product_id)
132
188
  .map((o) => o.product_id));
133
- const result = planCarts(inputs, {
134
- maxPartySharePerLayerPct: settings?.max_party_share_per_layer_pct ?? 50,
135
- maxBeladingenPerLayer: settings?.max_beladingen_per_layer ?? 2,
136
- neverMixProductIds: neverMix,
137
- });
138
- plannedCarts = result.carts;
139
- warnings.push(...result.warnings);
189
+ // Ladingdrager is een HARDE partitie: één planner-run per load_carrier.
190
+ // Items zonder load_carrier (lokale orders) vormen hun eigen partitie op
191
+ // het defaultprofiel.
192
+ const partitions = new Map();
193
+ for (const input of inputs) {
194
+ const key = input.load_carrier ?? "";
195
+ const list = partitions.get(key);
196
+ if (list)
197
+ list.push(input);
198
+ else
199
+ partitions.set(key, [input]);
200
+ }
201
+ const allBlocked = [];
202
+ let nextCartNumber = 1;
203
+ for (const [key, partitionInputs] of partitions) {
204
+ const profile = profileFor(key || null);
205
+ if (!profile) {
206
+ // Geen actief profiel én geen 'trolley': niet plannen, wel blokkeren.
207
+ for (const i of partitionInputs) {
208
+ allBlocked.push({
209
+ order_item_id: i.order_item_id,
210
+ product_id: i.product_id,
211
+ product_name: i.product_name,
212
+ reason: "geen_belading",
213
+ missing: ["load_carrier_profile"],
214
+ });
215
+ }
216
+ warnings.push(`Geen actief ladingdragerprofiel gevonden${key ? ` voor ${key}` : ""} — karindeling overgeslagen.`);
217
+ continue;
218
+ }
219
+ const result = planCarts(partitionInputs, {
220
+ maxPartySharePerLayerPct: settings?.max_party_share_per_layer_pct ?? 50,
221
+ maxBeladingenPerLayer: settings?.max_beladingen_per_layer ?? 2,
222
+ neverMixProductIds: neverMix,
223
+ startCartNumber: nextCartNumber,
224
+ });
225
+ for (const cart of result.carts) {
226
+ nextCartNumber = Math.max(nextCartNumber, cart.cart_number + 1);
227
+ plannedCarts.push({ cart, profile });
228
+ }
229
+ warnings.push(...result.warnings);
230
+ allBlocked.push(...result.blocked);
231
+ }
232
+ const result = { blocked: allBlocked };
140
233
  // Regels zonder (volledige) belading: NOOIT karren maken. Meld de
141
234
  // blokkade aan de logistiek-engine zodat die zichtbaar wordt in
142
235
  // logistics_plan_queue / logistics_events / logistics_decisions.
@@ -154,9 +247,25 @@ export async function replanScopeInternal(scope) {
154
247
  missing: b.missing,
155
248
  }));
156
249
  if (blockedOrderIds.length > 0) {
250
+ const FIELD_LABELS = {
251
+ plants_per_crate: "planten per fust",
252
+ crates_per_layer: "fusten per laag",
253
+ layers_per_cart: "lagen per kar",
254
+ };
255
+ const nummers = blockedOrderIds
256
+ .map((id) => orderNumberById.get(id) ?? id.slice(0, 8))
257
+ .join(", ");
258
+ const velden = [
259
+ ...new Set(blockedItems.flatMap((b) => b.missing)),
260
+ ]
261
+ .map((f) => FIELD_LABELS[f] ?? f)
262
+ .join(", ");
263
+ const reason = `Karindeling geblokkeerd voor order(s) ${nummers}: ` +
264
+ `${blockedItems.length} orderregel(s) zonder volledige belading` +
265
+ (velden ? ` (ontbreekt: ${velden})` : "") + ".";
157
266
  const { error: blockErr } = await supabaseAdmin.rpc("logistics_plan_block", {
158
267
  p_order_ids: blockedOrderIds,
159
- p_reason: "belading_onbekend",
268
+ p_reason: reason,
160
269
  p_details: { source: "floriday-verkoop-module/cart-replan", items: blockedItems },
161
270
  });
162
271
  if (blockErr) {
@@ -169,7 +278,7 @@ export async function replanScopeInternal(scope) {
169
278
  }
170
279
  }
171
280
  let cartsCreated = 0;
172
- for (const cart of plannedCarts) {
281
+ for (const { cart, profile } of plannedCarts) {
173
282
  // Bepaal cart.order_id: null bij mix van orders, anders die ene order.
174
283
  const orderIdsOnCart = new Set();
175
284
  for (const i of cart.items) {
@@ -189,6 +298,10 @@ export async function replanScopeInternal(scope) {
189
298
  source: usedFloridayPacking ? "floriday" : "auto",
190
299
  occupancy_pct: cart.occupancy_pct,
191
300
  total_layers_used: cart.total_layers_used,
301
+ // Profiel expliciet meegeven; nooit leunen op de kolomdefault.
302
+ carrier_type: profile.code,
303
+ carrier_type_id: profile.id,
304
+ max_layers: profile.layers_per_carrier ?? null,
192
305
  algorithm_version: CART_PLANNER_VERSION,
193
306
  })
194
307
  .select("id")
@@ -0,0 +1,10 @@
1
+ type MinimalClient = {
2
+ from: (table: string) => any;
3
+ };
4
+ /**
5
+ * Vertaalt Floriday sales-order-ids naar centrale ordernummers.
6
+ * Eén batch-query per 400 ids; ids zonder maprij ontbreken in de Map.
7
+ */
8
+ export declare function resolveOrderNumbers(supabase: MinimalClient, foIds: Iterable<string>): Promise<Map<string, string>>;
9
+ export {};
10
+ //# sourceMappingURL=order-numbers.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-numbers.server.d.ts","sourceRoot":"","sources":["../../src/lib/order-numbers.server.ts"],"names":[],"mappings":"AAKA,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;CAC9B,CAAC;AAIF;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,GACtB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAoB9B"}
@@ -0,0 +1,30 @@
1
+ // Eén bron voor het ophalen van centrale ordernummers van Floriday-orders.
2
+ // floriday_order_number_map is leidend; deze helper wordt gebruikt door de
3
+ // lijstquery, het orderdetail én de buffer-siblings, zodat er nooit meer
4
+ // verschillende implementaties naast elkaar bestaan.
5
+ const CHUNK = 400;
6
+ /**
7
+ * Vertaalt Floriday sales-order-ids naar centrale ordernummers.
8
+ * Eén batch-query per 400 ids; ids zonder maprij ontbreken in de Map.
9
+ */
10
+ export async function resolveOrderNumbers(supabase, foIds) {
11
+ const ids = Array.from(new Set(Array.from(foIds).map((v) => String(v ?? "")).filter((v) => v.length > 0)));
12
+ const out = new Map();
13
+ if (ids.length === 0)
14
+ return out;
15
+ for (let i = 0; i < ids.length; i += CHUNK) {
16
+ const chunk = ids.slice(i, i + CHUNK);
17
+ const { data, error } = await supabase
18
+ .from("floriday_order_number_map")
19
+ .select("floriday_id, order_number")
20
+ .in("floriday_id", chunk);
21
+ if (error)
22
+ throw new Error(error.message);
23
+ for (const row of (data ?? [])) {
24
+ const num = String(row?.order_number ?? "").trim();
25
+ if (num)
26
+ out.set(String(row.floriday_id), num);
27
+ }
28
+ }
29
+ return out;
30
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"salesorders-list.server.d.ts","sourceRoot":"","sources":["../../src/lib/salesorders-list.server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAEvB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjF,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,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;CACf;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;CACpB;AA8ID,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CAgtBrB"}
1
+ {"version":3,"file":"salesorders-list.server.d.ts","sourceRoot":"","sources":["../../src/lib/salesorders-list.server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAEvB,MAAM,uBAAuB,CAAC;AAO/B,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjF,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,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;CACf;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;CACpB;AA8ID,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CAqsBrB"}
@@ -4,6 +4,7 @@ import { normalizeLoadCarrierCode } from "./load-carriers";
4
4
  import { normalizeTime, resolveDeliveryTimeForDate } from "./carrier-availability";
5
5
  import { expandOrderItemsForPlanner } from "./expand-group-order-items";
6
6
  import { planCarts } from "./cart-planner";
7
+ import { resolveOrderNumbers } from "./order-numbers.server";
7
8
  import { mergeStages, resolveOrderStage } from "./order-status";
8
9
  const FO_CAP = 20000;
9
10
  const LOCAL_CAP = 5000;
@@ -261,15 +262,7 @@ export async function buildSalesOrdersList(supabase, params) {
261
262
  }
262
263
  };
263
264
  const [orderNumberRows, customerRows, floridayCustomerRows, tradeItemRows, carrierRows, crateDescriptions, groupPacking,] = await Promise.all([
264
- safe("Ordernummers", () => chunked(foIdsForNumbers, 400, async (chunk) => {
265
- const { data, error } = await supabase
266
- .from("floriday_order_number_map")
267
- .select("floriday_id, order_number")
268
- .in("floriday_id", chunk);
269
- if (error)
270
- throw new Error(error.message);
271
- return (data ?? []);
272
- }), []),
265
+ safe("Ordernummers", () => resolveOrderNumbers(supabase, foIdsForNumbers), new Map()),
273
266
  safe("Klanten", async () => {
274
267
  const orFilter = [
275
268
  neededOrgIds.length ? `floriday_organization_id.in.(${neededOrgIds.join(",")})` : null,
@@ -318,10 +311,7 @@ export async function buildSalesOrdersList(supabase, params) {
318
311
  loadCrateDescriptions(supabase, warnings),
319
312
  safe("Productgroepen", () => loadGroupPacking(supabase), new Map()),
320
313
  ]);
321
- const orderNumberByFoId = new Map();
322
- for (const m of orderNumberRows) {
323
- orderNumberByFoId.set(String(m.floriday_id), String(m.order_number ?? ""));
324
- }
314
+ const orderNumberByFoId = orderNumberRows;
325
315
  const carrierById = new Map();
326
316
  for (const c of carrierRows)
327
317
  carrierById.set(String(c.id), c);