@flowselections/floriday-verkoop-module 1.0.53 → 1.0.54
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/OrderKarindelingCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderKarindelingCard.js +65 -183
- package/dist-lib/lib/cart-replan.functions.d.ts +16 -0
- package/dist-lib/lib/cart-replan.functions.d.ts.map +1 -1
- package/dist-lib/lib/cart-replan.functions.js +76 -3
- package/package.json +1 -1
|
@@ -401,22 +401,95 @@ export async function drainCartReplanQueue(limit = 50) {
|
|
|
401
401
|
// ─── Lezen — voor de UI ─────────────────────────────────────────────────────
|
|
402
402
|
// Retourneert alle karren van de buffer waarin de order valt, zodat karren
|
|
403
403
|
// die items van meerdere orders bevatten volledig zichtbaar zijn.
|
|
404
|
+
// Levert ook de order-context (nummers per orderregel) en, als er geen karren
|
|
405
|
+
// zijn, de laatste blokkadereden uit de engine (logistics_decisions /
|
|
406
|
+
// logistics_plan_queue). De UI berekent NIETS zelf: hij toont wat er staat.
|
|
404
407
|
export const listOrderCarts = createServerFn({ method: "GET" })
|
|
405
408
|
.middleware([requireSupabaseAuth])
|
|
406
409
|
.inputValidator((input) => z.object({ orderId: z.string().uuid() }).parse(input))
|
|
407
410
|
.handler(async ({ data, context }) => {
|
|
408
411
|
const { data: order } = await context.supabase
|
|
409
412
|
.from("orders")
|
|
410
|
-
.select("buffer_id")
|
|
413
|
+
.select("buffer_id, plan_locked_at")
|
|
411
414
|
.eq("id", data.orderId)
|
|
412
415
|
.maybeSingle();
|
|
413
416
|
const bufferId = order?.buffer_id;
|
|
414
|
-
const
|
|
417
|
+
const planLockedAt = order?.plan_locked_at ?? null;
|
|
418
|
+
const select = "id, order_id, buffer_id, cart_number, source, is_complete, occupancy_pct, total_layers_used, algorithm_version, carrier_type, max_layers, notes, order_cart_items(id, order_item_id, product_id, product_name, crates, plants_per_crate, crates_per_layer, layers_per_cart, layer_fraction, layer_share_pct)";
|
|
415
419
|
const base = context.supabase.from("order_carts").select(select);
|
|
416
420
|
const { data: carts } = await (bufferId
|
|
417
421
|
? base.eq("buffer_id", bufferId)
|
|
418
422
|
: base.eq("order_id", data.orderId)).order("cart_number");
|
|
419
|
-
|
|
423
|
+
// Orders in de scope + ordernummer per orderregel (voor de badges).
|
|
424
|
+
let orders = [];
|
|
425
|
+
if (bufferId) {
|
|
426
|
+
const { data: sibs } = await context.supabase
|
|
427
|
+
.from("orders")
|
|
428
|
+
.select("id, order_number")
|
|
429
|
+
.eq("buffer_id", bufferId)
|
|
430
|
+
.is("deleted_at", null);
|
|
431
|
+
orders = (sibs ?? []).map((o) => ({
|
|
432
|
+
id: o.id,
|
|
433
|
+
order_number: o.order_number ?? null,
|
|
434
|
+
}));
|
|
435
|
+
}
|
|
436
|
+
if (orders.length === 0) {
|
|
437
|
+
const { data: own } = await context.supabase
|
|
438
|
+
.from("orders")
|
|
439
|
+
.select("id, order_number")
|
|
440
|
+
.eq("id", data.orderId)
|
|
441
|
+
.maybeSingle();
|
|
442
|
+
if (own) {
|
|
443
|
+
orders = [{ id: own.id, order_number: own.order_number ?? null }];
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
const orderIds = orders.map((o) => o.id);
|
|
447
|
+
let itemOrders = [];
|
|
448
|
+
if (orderIds.length > 0) {
|
|
449
|
+
const { data: its } = await context.supabase
|
|
450
|
+
.from("order_items")
|
|
451
|
+
.select("id, order_id")
|
|
452
|
+
.in("order_id", orderIds);
|
|
453
|
+
itemOrders = (its ?? []).map((i) => ({
|
|
454
|
+
id: i.id,
|
|
455
|
+
order_id: i.order_id,
|
|
456
|
+
}));
|
|
457
|
+
}
|
|
458
|
+
// Blokkadereden alleen ophalen als er niets gepland staat.
|
|
459
|
+
let blocked = null;
|
|
460
|
+
if ((carts ?? []).length === 0 && orderIds.length > 0) {
|
|
461
|
+
const { data: dec } = await context.supabase
|
|
462
|
+
.from("logistics_decisions")
|
|
463
|
+
.select("subject_id, slot, explanation, result, created_at")
|
|
464
|
+
.in("subject_id", orderIds)
|
|
465
|
+
.order("created_at", { ascending: false })
|
|
466
|
+
.limit(1);
|
|
467
|
+
const d = (dec ?? [])[0];
|
|
468
|
+
if (d) {
|
|
469
|
+
blocked = {
|
|
470
|
+
reason: d.result?.reason ?? d.slot ?? null,
|
|
471
|
+
explanation: d.explanation ?? null,
|
|
472
|
+
at: d.created_at ?? null,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (!blocked) {
|
|
476
|
+
const { data: q } = await context.supabase
|
|
477
|
+
.from("logistics_plan_queue")
|
|
478
|
+
.select("order_id, status, reason, error, updated_at")
|
|
479
|
+
.in("order_id", orderIds)
|
|
480
|
+
.order("updated_at", { ascending: false })
|
|
481
|
+
.limit(1);
|
|
482
|
+
const r = (q ?? [])[0];
|
|
483
|
+
if (r && (r.error || r.reason)) {
|
|
484
|
+
blocked = {
|
|
485
|
+
reason: r.reason ?? null,
|
|
486
|
+
explanation: r.error ?? null,
|
|
487
|
+
at: r.updated_at ?? null,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return { carts: carts ?? [], bufferId, planLockedAt, orders, itemOrders, blocked };
|
|
420
493
|
});
|
|
421
494
|
export const replanBufferForOrder = createServerFn({ method: "POST" })
|
|
422
495
|
.middleware([requireSupabaseAuth])
|