@flowselections/floriday-verkoop-module 1.0.19 → 1.0.20

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.
Files changed (32) hide show
  1. package/dist-lib/integrations/supabase/auth-middleware.d.ts +6 -0
  2. package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
  3. package/dist-lib/integrations/supabase/client.d.ts +6 -0
  4. package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
  5. package/dist-lib/integrations/supabase/client.server.d.ts +6 -0
  6. package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
  7. package/dist-lib/integrations/supabase/types.d.ts +6 -0
  8. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  9. package/dist-lib/lib/cart-lock.functions.d.ts +6 -0
  10. package/dist-lib/lib/cart-lock.functions.d.ts.map +1 -1
  11. package/dist-lib/lib/cart-replan.functions.d.ts +12 -0
  12. package/dist-lib/lib/cart-replan.functions.d.ts.map +1 -1
  13. package/dist-lib/lib/create-order.functions.d.ts +72 -0
  14. package/dist-lib/lib/create-order.functions.d.ts.map +1 -1
  15. package/dist-lib/lib/create-order.functions.js +34 -25
  16. package/dist-lib/lib/floriday-auto-fulfillment.functions.d.ts +18 -0
  17. package/dist-lib/lib/floriday-auto-fulfillment.functions.d.ts.map +1 -1
  18. package/dist-lib/lib/floriday-logistic-labels.functions.d.ts +6 -0
  19. package/dist-lib/lib/floriday-logistic-labels.functions.d.ts.map +1 -1
  20. package/dist-lib/lib/floriday-public.functions.d.ts +42 -0
  21. package/dist-lib/lib/floriday-public.functions.d.ts.map +1 -1
  22. package/dist-lib/lib/floriday-writes.functions.d.ts +30 -0
  23. package/dist-lib/lib/floriday-writes.functions.d.ts.map +1 -1
  24. package/dist-lib/lib/order-shipments.functions.d.ts +24 -0
  25. package/dist-lib/lib/order-shipments.functions.d.ts.map +1 -1
  26. package/dist-lib/lib/salesorders.functions.d.ts +18 -0
  27. package/dist-lib/lib/salesorders.functions.d.ts.map +1 -1
  28. package/dist-lib/lib/tradeitems.functions.d.ts +6 -0
  29. package/dist-lib/lib/tradeitems.functions.d.ts.map +1 -1
  30. package/dist-lib/lib/useSalesOrdersQuery.d.ts.map +1 -1
  31. package/dist-lib/lib/useSalesOrdersQuery.js +62 -3
  32. package/package.json +1 -1
@@ -49,7 +49,7 @@ export const listProductsForCreateOrder = createServerFn({ method: "GET" })
49
49
  .range(0, 9999),
50
50
  context.supabase
51
51
  .from("products")
52
- .select("id, product, unit, sale_price, plants_per_crate, crates_per_layer, layers_per_cart, quantity, custom_fields")
52
+ .select("id, product, unit, sale_price, plants_per_crate, crates_per_layer, layers_per_cart, quantity, custom_fields, trade_item_key")
53
53
  .range(0, 4999),
54
54
  ]);
55
55
  // Supabase geeft standaard max. 1000 rijen terug. Voor productgroepen kan de
@@ -242,6 +242,13 @@ export const listProductsForCreateOrder = createServerFn({ method: "GET" })
242
242
  for (const p of Array.isArray(productsRes.data) ? productsRes.data : []) {
243
243
  productsById.set(p.id, p);
244
244
  }
245
+ const productsByGroupId = new Map();
246
+ for (const p of Array.isArray(productsRes.data) ? productsRes.data : []) {
247
+ const key = p.trade_item_key;
248
+ if (typeof key === "string" && key.startsWith("group:")) {
249
+ productsByGroupId.set(key.slice("group:".length), p);
250
+ }
251
+ }
245
252
  const packingFromProductRow = (p) => ({
246
253
  plants_per_crate: Math.max(1, Number(p?.plants_per_crate ?? 1)),
247
254
  crates_per_layer: Math.max(1, Number(p?.crates_per_layer ?? 1)),
@@ -277,32 +284,34 @@ export const listProductsForCreateOrder = createServerFn({ method: "GET" })
277
284
  reserved = resSum;
278
285
  available = Math.max(0, physical - reserved);
279
286
  }
280
- // Probeer belading van de bovenste member; val terug op head_trade_item /
281
- // head_product_id als de member niet in byId of products staat.
287
+ // Head eerst — belading van de groep = belading van het hoofdproduct.
288
+ // Volgorde: head_trade_item_floriday_id → head_product_id → group-mirror
289
+ // products-rij (`trade_item_key = 'group:<id>'`) → eerste member.
282
290
  let packing = { plants_per_crate: 1, crates_per_layer: 1, layers_per_cart: 1 };
283
- const candidates = [
284
- members[0]?.trade_item_id ?? null,
285
- r.head_trade_item_floriday_id ?? null,
286
- r.head_product_id ?? null,
287
- ];
288
- for (const cand of candidates) {
291
+ const headFloriday = r.head_trade_item_floriday_id;
292
+ const headProduct = r.head_product_id;
293
+ const groupMirror = productsByGroupId.get(id);
294
+ const firstMemberId = members[0]?.trade_item_id ?? null;
295
+ const tryFromById = (cand) => {
289
296
  if (!cand)
290
- continue;
291
- const fromBy = byId.get(cand);
292
- if (fromBy) {
293
- packing = {
294
- plants_per_crate: fromBy.plants_per_crate,
295
- crates_per_layer: fromBy.crates_per_layer,
296
- layers_per_cart: fromBy.layers_per_cart,
297
- };
298
- break;
299
- }
300
- const fromProd = productsById.get(cand);
301
- if (fromProd) {
302
- packing = packingFromProductRow(fromProd);
303
- break;
304
- }
305
- }
297
+ return null;
298
+ const hit = byId.get(cand);
299
+ if (!hit)
300
+ return null;
301
+ return {
302
+ plants_per_crate: hit.plants_per_crate,
303
+ crates_per_layer: hit.crates_per_layer,
304
+ layers_per_cart: hit.layers_per_cart,
305
+ };
306
+ };
307
+ const tryFromProductRow = (row) => (row ? packingFromProductRow(row) : null);
308
+ packing =
309
+ tryFromById(headFloriday) ??
310
+ tryFromProductRow(headProduct ? productsById.get(headProduct) : null) ??
311
+ tryFromProductRow(groupMirror) ??
312
+ tryFromById(firstMemberId) ??
313
+ tryFromProductRow(firstMemberId ? productsById.get(firstMemberId) : null) ??
314
+ packing;
306
315
  byId.set(id, {
307
316
  id,
308
317
  product: displayName,
@@ -11786,6 +11786,12 @@ export declare const getPreferredWarehouseStatus: import("@tanstack/start-client
11786
11786
  };
11787
11787
  Returns: undefined;
11788
11788
  };
11789
+ sync_product_group_belading: {
11790
+ Args: {
11791
+ _group_id: string;
11792
+ };
11793
+ Returns: undefined;
11794
+ };
11789
11795
  sync_product_packing_from_floriday_cache: {
11790
11796
  Args: {
11791
11797
  p_floriday_id: string;
@@ -23620,6 +23626,12 @@ export declare const getAutoFulfillmentStatus: import("@tanstack/start-client-co
23620
23626
  };
23621
23627
  Returns: undefined;
23622
23628
  };
23629
+ sync_product_group_belading: {
23630
+ Args: {
23631
+ _group_id: string;
23632
+ };
23633
+ Returns: undefined;
23634
+ };
23623
23635
  sync_product_packing_from_floriday_cache: {
23624
23636
  Args: {
23625
23637
  p_floriday_id: string;
@@ -35463,6 +35475,12 @@ export declare const retryAutoFulfillment: import("@tanstack/start-client-core")
35463
35475
  };
35464
35476
  Returns: undefined;
35465
35477
  };
35478
+ sync_product_group_belading: {
35479
+ Args: {
35480
+ _group_id: string;
35481
+ };
35482
+ Returns: undefined;
35483
+ };
35466
35484
  sync_product_packing_from_floriday_cache: {
35467
35485
  Args: {
35468
35486
  p_floriday_id: string;