@flowselections/floriday-verkoop-module 1.0.160 → 1.0.161
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 +1 -0
- package/dist-lib/components/verkoop/OrderKarindelingCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderKarindelingCard.js +7 -2
- package/dist-lib/components/verkoop/OrderTransportCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderTransportCard.js +6 -4
- package/dist-lib/components/verkoop/SalesOrderDetailPage.js +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailView.js +7 -4
- package/dist-lib/components/verkoop/klok/KlokOrderPage.d.ts.map +1 -1
- package/dist-lib/components/verkoop/klok/KlokOrderPage.js +21 -6
- package/dist-lib/components/verkoop/klok/KlokOrdersList.d.ts.map +1 -1
- package/dist-lib/components/verkoop/klok/KlokOrdersList.js +3 -3
- package/dist-lib/integrations/supabase/types.d.ts +531 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/cart-replan.functions.d.ts +6 -0
- package/dist-lib/lib/cart-replan.functions.d.ts.map +1 -1
- package/dist-lib/lib/cart-replan.functions.js +18 -8
- package/dist-lib/lib/cron/sync-salesorders-now.d.ts +1 -0
- package/dist-lib/lib/cron/sync-salesorders-now.d.ts.map +1 -1
- package/dist-lib/lib/cron/sync-salesorders-now.js +26 -2
- package/dist-lib/lib/engine-block-alerts.server.d.ts.map +1 -1
- package/dist-lib/lib/engine-block-alerts.server.js +3 -1
- package/dist-lib/lib/floriday-actual-carriers.d.ts +18 -0
- package/dist-lib/lib/floriday-actual-carriers.d.ts.map +1 -0
- package/dist-lib/lib/floriday-actual-carriers.js +26 -0
- package/dist-lib/lib/floriday-actual-carriers.server.d.ts +6 -0
- package/dist-lib/lib/floriday-actual-carriers.server.d.ts.map +1 -0
- package/dist-lib/lib/floriday-actual-carriers.server.js +31 -0
- package/dist-lib/lib/floriday-backfill.d.ts +26 -0
- package/dist-lib/lib/floriday-backfill.d.ts.map +1 -0
- package/dist-lib/lib/floriday-backfill.js +43 -0
- package/dist-lib/lib/floriday-backfill.server.d.ts +2 -0
- package/dist-lib/lib/floriday-backfill.server.d.ts.map +1 -0
- package/dist-lib/lib/floriday-backfill.server.js +32 -0
- package/dist-lib/lib/floriday-mirror.server.d.ts +2 -1
- package/dist-lib/lib/floriday-mirror.server.d.ts.map +1 -1
- package/dist-lib/lib/floriday-mirror.server.js +30 -49
- package/dist-lib/lib/floriday-status.d.ts +9 -0
- package/dist-lib/lib/floriday-status.d.ts.map +1 -1
- package/dist-lib/lib/floriday-status.js +12 -0
- package/dist-lib/lib/invoice-timing.d.ts +9 -0
- package/dist-lib/lib/invoice-timing.d.ts.map +1 -1
- package/dist-lib/lib/invoice-timing.js +15 -0
- package/dist-lib/lib/invoice-timing.server.d.ts.map +1 -1
- package/dist-lib/lib/invoice-timing.server.js +8 -3
- package/dist-lib/lib/klok-labels.d.ts +4 -1
- package/dist-lib/lib/klok-labels.d.ts.map +1 -1
- package/dist-lib/lib/klok-labels.js +10 -1
- package/dist-lib/lib/list-own-rows.d.ts +9 -0
- package/dist-lib/lib/list-own-rows.d.ts.map +1 -0
- package/dist-lib/lib/list-own-rows.js +20 -0
- package/dist-lib/lib/order-departure.d.ts +1 -1
- package/dist-lib/lib/order-departure.d.ts.map +1 -1
- package/dist-lib/lib/order-departure.js +1 -1
- package/dist-lib/lib/order-status.d.ts +15 -1
- package/dist-lib/lib/order-status.d.ts.map +1 -1
- package/dist-lib/lib/order-status.js +17 -1
- package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.server.js +70 -4
- package/dist-lib/lib/salesorders-mapping.d.ts +2 -0
- package/dist-lib/lib/salesorders-mapping.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-mapping.js +1 -1
- package/dist-lib/lib/salesorders.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders.functions.js +12 -3
- package/dist-lib/lib/sync-melding.d.ts +3 -0
- package/dist-lib/lib/sync-melding.d.ts.map +1 -1
- package/dist-lib/lib/sync-melding.functions.d.ts.map +1 -1
- package/dist-lib/lib/sync-melding.functions.js +1 -0
- package/dist-lib/lib/sync-melding.js +5 -2
- package/package.json +1 -1
- package/schema/verkoop.sql +408 -8
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FloridayCarrier } from "./floriday-actual-carriers.js";
|
|
1
2
|
export type { BlockedItem } from "./cart-replan.server.js";
|
|
2
3
|
export declare const replanOrderCarts: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
3
4
|
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
@@ -29,6 +30,11 @@ export declare const getOrderPlanCoverage: import("@tanstack/start-client-core")
|
|
|
29
30
|
error: string | null;
|
|
30
31
|
sendError: string | null;
|
|
31
32
|
} | null;
|
|
33
|
+
externalFulfilledAt: string | null;
|
|
34
|
+
floriday: {
|
|
35
|
+
carriers: FloridayCarrier[];
|
|
36
|
+
error: string | null;
|
|
37
|
+
} | null;
|
|
32
38
|
}>>;
|
|
33
39
|
export declare const replanBufferForOrder: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
34
40
|
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart-replan.functions.d.ts","sourceRoot":"","sources":["../../src/lib/cart-replan.functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cart-replan.functions.d.ts","sourceRoot":"","sources":["../../src/lib/cart-replan.functions.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAMlE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,eAAO,MAAM,gBAAgB;;;;8CAEH,OAAO;;;;;;;;;;;GAM7B,CAAC;AAML,eAAO,MAAM,oBAAoB;;;;8CAEP,OAAO;;;;;;gBAUA,MAAM,GAAG,IAAI;eAAS,MAAM,GAAG,IAAI;mBAAa,MAAM,GAAG,IAAI;;;;kBA8BhE,eAAe,EAAE;eAAS,MAAM,GAAG,IAAI;;GAMjE,CAAC;AAEL,eAAO,MAAM,oBAAoB;;;;8CAEP,OAAO;;;;;;;;;;;;GAQ7B,CAAC"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// Wordt gebruikt door:
|
|
3
|
-
// - createManualOrder (direct na aanmaak)
|
|
4
|
-
// - handmatige "Herbereken" knop in de order-detail
|
|
5
|
-
// - cron endpoint /api/public/cron/replan-carts (drain van cart_replan_queue)
|
|
1
|
+
import { handledAtForDisplay } from "./floriday-backfill.js";
|
|
6
2
|
import { createServerFn } from "@tanstack/react-start";
|
|
7
3
|
import { z } from "zod";
|
|
8
4
|
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
@@ -32,12 +28,19 @@ export const getOrderPlanCoverage = createServerFn({ method: "GET" })
|
|
|
32
28
|
unknownCoverage("Geen antwoord van de Engine");
|
|
33
29
|
// Uitkomst van de melding "Afgehandeld in Floriday" (alleen lezen).
|
|
34
30
|
let externalEvent = null;
|
|
31
|
+
let externalAt = null;
|
|
32
|
+
let soIds = [];
|
|
35
33
|
try {
|
|
36
34
|
const { data: o } = await context.supabase.from("orders")
|
|
37
|
-
.select("custom_fields")
|
|
35
|
+
.select("custom_fields, floriday_sales_order_id")
|
|
38
36
|
.eq("id", dbOrderId)
|
|
39
37
|
.maybeSingle();
|
|
40
38
|
const cf = (o?.custom_fields ?? {});
|
|
39
|
+
externalAt = handledAtForDisplay(cf);
|
|
40
|
+
soIds = [
|
|
41
|
+
...(Array.isArray(cf.floriday_sales_order_ids) ? cf.floriday_sales_order_ids.map(String) : []),
|
|
42
|
+
...(o?.floriday_sales_order_id ? [String(o.floriday_sales_order_id)] : []),
|
|
43
|
+
];
|
|
41
44
|
const evId = typeof cf.floriday_external_engine_event_id === "string" ? cf.floriday_external_engine_event_id : null;
|
|
42
45
|
const sendError = typeof cf.floriday_external_engine_error === "string" ? cf.floriday_external_engine_error : null;
|
|
43
46
|
if (evId) {
|
|
@@ -51,10 +54,17 @@ export const getOrderPlanCoverage = createServerFn({ method: "GET" })
|
|
|
51
54
|
externalEvent = { status: null, error: null, sendError };
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
catch {
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.error("[karindeling] afhandeling lezen mislukt:", e);
|
|
55
59
|
externalEvent = null;
|
|
56
60
|
}
|
|
57
|
-
|
|
61
|
+
// Proefindeling: werkelijke ladingdragers uit Floriday eronder (alleen lezen).
|
|
62
|
+
let floriday = null;
|
|
63
|
+
if (cov.externalFulfilled?.full === true || externalAt) {
|
|
64
|
+
const { loadFloridayCarriers } = await import("./floriday-actual-carriers.server.js");
|
|
65
|
+
floriday = await loadFloridayCarriers(context.supabase, soIds);
|
|
66
|
+
}
|
|
67
|
+
return { orderId: dbOrderId, coverage: cov, externalEvent, externalFulfilledAt: externalAt, floriday };
|
|
58
68
|
});
|
|
59
69
|
export const replanBufferForOrder = createServerFn({ method: "POST" })
|
|
60
70
|
.middleware([requireSupabaseAuth])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-salesorders-now.d.ts","sourceRoot":"","sources":["../../../src/lib/cron/sync-salesorders-now.ts"],"names":[],"mappings":"AAYA,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"sync-salesorders-now.d.ts","sourceRoot":"","sources":["../../../src/lib/cron/sync-salesorders-now.ts"],"names":[],"mappings":"AAYA,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiFrG;AAOD,oEAAoE;AACpE,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,GACZ;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAI/E"}
|
|
@@ -41,14 +41,37 @@ export async function syncSalesOrdersNowCron(request, _supabase) {
|
|
|
41
41
|
return Response.json({ ok: true, skipped: "niet-in-cache", rejected });
|
|
42
42
|
const started = Date.now();
|
|
43
43
|
const { mirrorFloridayOrdersByIds } = await import("../floriday-mirror.server.js");
|
|
44
|
+
// Inhalen (verkoop_inhaal_uitvoeren): alleen ids die echt in de inhaallijst
|
|
45
|
+
// op "aangevraagd" staan krijgen de backfill-markering.
|
|
46
|
+
let backfill = null;
|
|
47
|
+
if (parsed.backfill) {
|
|
48
|
+
const { data: items, error: itErr } = await supabaseAdmin
|
|
49
|
+
.from("verkoop_inhaal_items")
|
|
50
|
+
.select("sales_order_id, run_id, categorie, sinds")
|
|
51
|
+
.in("sales_order_id", ids)
|
|
52
|
+
.eq("status", "aangevraagd");
|
|
53
|
+
if (itErr) {
|
|
54
|
+
console.error(`[sync-salesorders-now] inhaallijst lezen mislukt: ${itErr.message}`);
|
|
55
|
+
return Response.json({ ok: false, error: "inhaallijst lezen mislukt" }, { status: 503 });
|
|
56
|
+
}
|
|
57
|
+
backfill = new Map((items ?? []).map((r) => [String(r.sales_order_id), { runId: String(r.run_id), categorie: String(r.categorie), sinds: String(r.sinds) }]));
|
|
58
|
+
if (!backfill.size)
|
|
59
|
+
return Response.json({ ok: true, skipped: "niet-in-inhaallijst" });
|
|
60
|
+
}
|
|
61
|
+
const mirrorIds = backfill ? ids.filter((id) => backfill.has(id)) : ids;
|
|
44
62
|
let result = null;
|
|
45
63
|
// Loopt de minuutronde net, dan kort wachten; anders pakt die ronde het op.
|
|
46
64
|
for (let i = 0; i < RETRIES; i++) {
|
|
47
|
-
result = await mirrorFloridayOrdersByIds(
|
|
65
|
+
result = await mirrorFloridayOrdersByIds(mirrorIds, backfill);
|
|
48
66
|
if (result?.skipped_reason !== "already-running")
|
|
49
67
|
break;
|
|
50
68
|
await new Promise((r) => setTimeout(r, RETRY_MS));
|
|
51
69
|
}
|
|
70
|
+
if (backfill) {
|
|
71
|
+
const { recordInhaalUitkomst } = await import("../floriday-backfill.server.js");
|
|
72
|
+
await recordInhaalUitkomst(supabaseAdmin, mirrorIds, result);
|
|
73
|
+
return Response.json({ ok: result?.ok !== false, backfill: true, ids: mirrorIds.length, inserted: result?.inserted ?? 0, ms: Date.now() - started });
|
|
74
|
+
}
|
|
52
75
|
const orderIds = Array.isArray(result?.enqueuedOrderIds) ? result.enqueuedOrderIds : [];
|
|
53
76
|
if (orderIds.length) {
|
|
54
77
|
const { wakeEnginePlanNow } = await import("../engine-wake.server.js");
|
|
@@ -69,11 +92,12 @@ export async function syncSalesOrdersNowCron(request, _supabase) {
|
|
|
69
92
|
}
|
|
70
93
|
const IdsSchema = z.object({
|
|
71
94
|
salesOrderIds: z.array(z.string().trim().min(1).max(100).regex(/^[A-Za-z0-9-]+$/)).max(MAX_IDS),
|
|
95
|
+
backfill: z.boolean().optional(),
|
|
72
96
|
});
|
|
73
97
|
/** Zod-controle: tekst-ID's, hooguit 50 per verzoek, ontdubbeld. */
|
|
74
98
|
export function parseSalesOrderIds(body) {
|
|
75
99
|
const r = IdsSchema.safeParse(body);
|
|
76
100
|
if (!r.success)
|
|
77
101
|
return { ok: false, error: `ongeldige invoer (hooguit ${MAX_IDS} salesOrderIds)` };
|
|
78
|
-
return { ok: true, ids: Array.from(new Set(r.data.salesOrderIds)) };
|
|
102
|
+
return { ok: true, ids: Array.from(new Set(r.data.salesOrderIds)), backfill: r.data.backfill === true };
|
|
79
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-block-alerts.server.d.ts","sourceRoot":"","sources":["../../src/lib/engine-block-alerts.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine-block-alerts.server.d.ts","sourceRoot":"","sources":["../../src/lib/engine-block-alerts.server.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAG3D,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAkE7G"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// - Open alarm sluit vanzelf zodra de Engine definitief = false en status "done" meldt.
|
|
5
5
|
// - Fail closed: lukt een vraag niet, dan geen mail en niets vrijgeven.
|
|
6
6
|
import { decideAlertAction, parseDefinitiveBlock } from "./engine-block-alerts.js";
|
|
7
|
+
import { amsterdamYmd, ymdString } from "./period-range.js";
|
|
7
8
|
export const ENGINE_BLOCK_REASON_KEY = "engine_definitief";
|
|
8
9
|
const MAX_CHECKS = 200;
|
|
9
10
|
export async function checkDefinitiveBlocks() {
|
|
@@ -21,7 +22,8 @@ export async function checkDefinitiveBlocks() {
|
|
|
21
22
|
throw new Error(openErr.message);
|
|
22
23
|
const openIds = new Set((openRows ?? []).map((r) => String(r.order_id)));
|
|
23
24
|
// Open orders vanaf vandaag die de Engine niet als "Ingedeeld" meldt.
|
|
24
|
-
|
|
25
|
+
// delivery_date is tekst 'JJJJ-MM-DD': vergelijk met de Nederlandse kalenderdag.
|
|
26
|
+
const today = ymdString(amsterdamYmd());
|
|
25
27
|
const { data: orders, error: oErr } = await sb
|
|
26
28
|
.from("orders")
|
|
27
29
|
.select("id")
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface FloridayCarrier {
|
|
2
|
+
fulfillmentId: string;
|
|
3
|
+
index: number;
|
|
4
|
+
type: string | null;
|
|
5
|
+
packages: number;
|
|
6
|
+
code: string | null;
|
|
7
|
+
}
|
|
8
|
+
/** Ladingdragers uit fulfillment-orders die bij één van deze verkooporders horen. */
|
|
9
|
+
export declare function floridayCarriersFor(rows: {
|
|
10
|
+
floriday_id: string;
|
|
11
|
+
data: any;
|
|
12
|
+
}[], salesOrderIds: string[]): FloridayCarrier[];
|
|
13
|
+
/** Order geheel afgehandeld in Floriday: kop "Proefindeling", geen pick- of aanmeldacties. */
|
|
14
|
+
export declare function isProefindeling(input: {
|
|
15
|
+
coverageFull?: boolean | null;
|
|
16
|
+
externalFulfilledAt?: string | null;
|
|
17
|
+
}): boolean;
|
|
18
|
+
//# sourceMappingURL=floriday-actual-carriers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floriday-actual-carriers.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-actual-carriers.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,qFAAqF;AACrF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,eAAe,EAAE,CAmB1H;AAED,8FAA8F;AAC9F,wBAAgB,eAAe,CAAC,KAAK,EAAE;IAAE,YAAY,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,OAAO,CAEtH"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Ladingdragers uit fulfillment-orders die bij één van deze verkooporders horen. */
|
|
2
|
+
export function floridayCarriersFor(rows, salesOrderIds) {
|
|
3
|
+
const ids = new Set(salesOrderIds.map(String));
|
|
4
|
+
const out = [];
|
|
5
|
+
for (const row of rows) {
|
|
6
|
+
const carriers = Array.isArray(row?.data?.loadCarriers) ? row.data.loadCarriers : [];
|
|
7
|
+
for (const lc of carriers) {
|
|
8
|
+
const items = Array.isArray(lc?.loadCarrierItems) ? lc.loadCarrierItems : [];
|
|
9
|
+
const mine = items.filter((it) => ids.has(String(it?.salesOrderId ?? "")));
|
|
10
|
+
if (mine.length === 0)
|
|
11
|
+
continue;
|
|
12
|
+
out.push({
|
|
13
|
+
fulfillmentId: String(row.floriday_id),
|
|
14
|
+
index: Number(lc?.sortIndex ?? out.length),
|
|
15
|
+
type: lc?.loadCarrierType ? String(lc.loadCarrierType) : null,
|
|
16
|
+
packages: mine.reduce((s, it) => s + (Number(it?.numberOfPackages) || 0), 0),
|
|
17
|
+
code: lc?.documentReference ? String(lc.documentReference) : (mine[0]?.deliveryNoteCode ? String(mine[0].deliveryNoteCode) : null),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return out.sort((a, b) => a.fulfillmentId.localeCompare(b.fulfillmentId) || a.index - b.index);
|
|
22
|
+
}
|
|
23
|
+
/** Order geheel afgehandeld in Floriday: kop "Proefindeling", geen pick- of aanmeldacties. */
|
|
24
|
+
export function isProefindeling(input) {
|
|
25
|
+
return input.coverageFull === true || !!input.externalFulfilledAt;
|
|
26
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type FloridayCarrier } from "./floriday-actual-carriers.js";
|
|
2
|
+
export declare function loadFloridayCarriers(supabase: any, salesOrderIds: string[]): Promise<{
|
|
3
|
+
carriers: FloridayCarrier[];
|
|
4
|
+
error: string | null;
|
|
5
|
+
}>;
|
|
6
|
+
//# sourceMappingURL=floriday-actual-carriers.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floriday-actual-carriers.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-actual-carriers.server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEvF,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAwBjJ"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Leest de werkelijke Floriday-ladingdragers van een order via de eigen
|
|
2
|
+
// index (verkoop_fulfillment_index) en daarna alleen de gevonden
|
|
3
|
+
// fulfillment-orders — nooit een volledige cachescan.
|
|
4
|
+
import { floridayCarriersFor } from "./floriday-actual-carriers.js";
|
|
5
|
+
export async function loadFloridayCarriers(supabase, salesOrderIds) {
|
|
6
|
+
const ids = Array.from(new Set(salesOrderIds.filter(Boolean)));
|
|
7
|
+
if (ids.length === 0)
|
|
8
|
+
return { carriers: [], error: null };
|
|
9
|
+
const { data: idx, error: e1 } = await supabase
|
|
10
|
+
.from("verkoop_fulfillment_index")
|
|
11
|
+
.select("fulfillment_id")
|
|
12
|
+
.in("sales_order_id", ids)
|
|
13
|
+
.eq("is_deleted", false);
|
|
14
|
+
if (e1) {
|
|
15
|
+
console.error("[proefindeling] index lezen mislukt:", e1.message);
|
|
16
|
+
return { carriers: [], error: "De ladingdragers uit Floriday konden nu niet worden gelezen." };
|
|
17
|
+
}
|
|
18
|
+
const fids = Array.from(new Set((idx ?? []).map((r) => String(r.fulfillment_id))));
|
|
19
|
+
if (fids.length === 0)
|
|
20
|
+
return { carriers: [], error: null };
|
|
21
|
+
const { data: rows, error: e2 } = await supabase
|
|
22
|
+
.from("floriday_fulfillment_orders_cache")
|
|
23
|
+
.select("floriday_id, data")
|
|
24
|
+
.in("floriday_id", fids.slice(0, 200))
|
|
25
|
+
.eq("is_deleted", false);
|
|
26
|
+
if (e2) {
|
|
27
|
+
console.error("[proefindeling] afhandeling lezen mislukt:", e2.message);
|
|
28
|
+
return { carriers: [], error: "De ladingdragers uit Floriday konden nu niet worden gelezen." };
|
|
29
|
+
}
|
|
30
|
+
return { carriers: floridayCarriersFor((rows ?? []), ids), error: null };
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type BackfillInfo = {
|
|
2
|
+
runId: string;
|
|
3
|
+
categorie: string;
|
|
4
|
+
sinds: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function backfillInsertFields(info: BackfillInfo, memberIds: string[], nowIso: string): {
|
|
7
|
+
status: string;
|
|
8
|
+
customFields: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
export declare function isBackfillOrder(customFields: unknown): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Moment waarop de order als afgehandeld geldt voor de weergave: de
|
|
13
|
+
* Floriday-markering, anders het backfill-moment (ook 'herstel_samenvoegen').
|
|
14
|
+
* Alleen weergave: verbergt pick- en aanmeldacties.
|
|
15
|
+
*/
|
|
16
|
+
export declare function handledAtForDisplay(customFields: unknown): string | null;
|
|
17
|
+
/** Uitkomst per aangevraagde salesOrderId na de omzetronde. */
|
|
18
|
+
export declare function inhaalUitkomst(order: {
|
|
19
|
+
id: string;
|
|
20
|
+
custom_fields: unknown;
|
|
21
|
+
} | null, fout: string | null): {
|
|
22
|
+
status: "aangemaakt" | "al_aanwezig" | "fout";
|
|
23
|
+
order_id: string | null;
|
|
24
|
+
melding: string | null;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=floriday-backfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floriday-backfill.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-backfill.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,GACb;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAW3D;AAED,wBAAgB,eAAe,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAQxE;AAED,+DAA+D;AAC/D,wBAAgB,cAAc,CAC5B,KAAK,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,EACpD,IAAI,EAAE,MAAM,GAAG,IAAI,GAClB;IAAE,MAAM,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAGpG"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Inhalen van gemiste Floriday-orders (backfill). Pure helpers, geen servercode.
|
|
2
|
+
// Een ingehaalde order is al via Floriday afgehandeld en afgerekend: hij krijgt
|
|
3
|
+
// in dezelfde INSERT als de orderkop de markering `backfill` en
|
|
4
|
+
// "Afgehandeld in Floriday", zodat triggers van Voorraad en Engine hem meteen
|
|
5
|
+
// overslaan (voorraad_order_is_backfill / logistics_order_is_backfill).
|
|
6
|
+
import { FLORIDAY_EXTERNAL_REASON, SHIPPED_STATUS } from "./floriday-external-fulfillment.js";
|
|
7
|
+
export function backfillInsertFields(info, memberIds, nowIso) {
|
|
8
|
+
return {
|
|
9
|
+
status: SHIPPED_STATUS,
|
|
10
|
+
customFields: {
|
|
11
|
+
backfill: { at: nowIso, run_id: info.runId, categorie: info.categorie, sinds: info.sinds },
|
|
12
|
+
floriday_fulfilled_externally: true,
|
|
13
|
+
floriday_external_fulfilled_at: nowIso,
|
|
14
|
+
floriday_external_fulfilled_notice: FLORIDAY_EXTERNAL_REASON,
|
|
15
|
+
floriday_external_fulfilled_sales_order_ids: [...memberIds],
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function isBackfillOrder(customFields) {
|
|
20
|
+
return !!customFields && typeof customFields === "object" && "backfill" in customFields;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Moment waarop de order als afgehandeld geldt voor de weergave: de
|
|
24
|
+
* Floriday-markering, anders het backfill-moment (ook 'herstel_samenvoegen').
|
|
25
|
+
* Alleen weergave: verbergt pick- en aanmeldacties.
|
|
26
|
+
*/
|
|
27
|
+
export function handledAtForDisplay(customFields) {
|
|
28
|
+
const cf = (customFields && typeof customFields === "object" ? customFields : {});
|
|
29
|
+
if (typeof cf.floriday_external_fulfilled_at === "string" && cf.floriday_external_fulfilled_at)
|
|
30
|
+
return cf.floriday_external_fulfilled_at;
|
|
31
|
+
if (cf.backfill && typeof cf.backfill === "object") {
|
|
32
|
+
return typeof cf.backfill.at === "string" && cf.backfill.at ? cf.backfill.at : "backfill";
|
|
33
|
+
}
|
|
34
|
+
if (cf.backfill)
|
|
35
|
+
return "backfill";
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/** Uitkomst per aangevraagde salesOrderId na de omzetronde. */
|
|
39
|
+
export function inhaalUitkomst(order, fout) {
|
|
40
|
+
if (order)
|
|
41
|
+
return { status: isBackfillOrder(order.custom_fields) ? "aangemaakt" : "al_aanwezig", order_id: order.id, melding: null };
|
|
42
|
+
return { status: "fout", order_id: null, melding: fout ?? "Niet omgezet; geen foutmelding uit de omzetronde." };
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floriday-backfill.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-backfill.server.ts"],"names":[],"mappings":"AAGA,wBAAsB,oBAAoB,CAAC,aAAa,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CA4BxG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Uitkomst van een inhaalaanvraag per salesOrderId vastleggen in verkoop_inhaal_items.
|
|
2
|
+
import { inhaalUitkomst } from "./floriday-backfill.js";
|
|
3
|
+
export async function recordInhaalUitkomst(supabaseAdmin, ids, result) {
|
|
4
|
+
const foutPerId = new Map();
|
|
5
|
+
for (const e of (result?.errors ?? [])) {
|
|
6
|
+
const m = /^([A-Za-z0-9-]+): (.*)$/s.exec(String(e));
|
|
7
|
+
if (m)
|
|
8
|
+
foutPerId.set(m[1], m[2]);
|
|
9
|
+
}
|
|
10
|
+
const algemeen = result?.skipped_reason
|
|
11
|
+
? `Omzetronde overgeslagen: ${result.skipped_reason}`
|
|
12
|
+
: result?.ok === false && !foutPerId.size ? (result?.errors ?? []).join("; ").slice(0, 300) || null : null;
|
|
13
|
+
for (const id of ids) {
|
|
14
|
+
const { data: rows, error } = await supabaseAdmin
|
|
15
|
+
.from("orders")
|
|
16
|
+
.select("id, custom_fields")
|
|
17
|
+
.or(`floriday_sales_order_id.eq.${id},custom_fields->floriday_sales_order_ids.cs.["${id}"]`)
|
|
18
|
+
.is("deleted_at", null)
|
|
19
|
+
.limit(1);
|
|
20
|
+
if (error) {
|
|
21
|
+
console.error(`[inhalen] order zoeken voor ${id} mislukt: ${error.message}`);
|
|
22
|
+
continue; // blijft "aangevraagd" en wordt na 10 minuten als vastgelopen getoond
|
|
23
|
+
}
|
|
24
|
+
const u = inhaalUitkomst((rows ?? [])[0] ?? null, foutPerId.get(id) ?? algemeen);
|
|
25
|
+
const { error: uErr } = await supabaseAdmin
|
|
26
|
+
.from("verkoop_inhaal_items")
|
|
27
|
+
.update({ status: u.status, order_id: u.order_id, melding: u.melding, verwerkt_at: new Date().toISOString() })
|
|
28
|
+
.eq("sales_order_id", id);
|
|
29
|
+
if (uErr)
|
|
30
|
+
console.error(`[inhalen] uitkomst vastleggen voor ${id} mislukt: ${uErr.message}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type BackfillInfo } from "./floriday-backfill.js";
|
|
1
2
|
export interface MirrorResult {
|
|
2
3
|
ok: boolean;
|
|
3
4
|
processed: number;
|
|
@@ -23,5 +24,5 @@ export declare function mirrorFloridayOrdersFromCron(limit?: number, since?: str
|
|
|
23
24
|
* Gerichte spiegeling (direct na de cache-upsert): alleen deze salesOrderIds
|
|
24
25
|
* plus echte groepsgenoten. Zelfde logica en slot als de minuutronde.
|
|
25
26
|
*/
|
|
26
|
-
export declare function mirrorFloridayOrdersByIds(ids: string[]): Promise<MirrorResult>;
|
|
27
|
+
export declare function mirrorFloridayOrdersByIds(ids: string[], backfill?: Map<string, BackfillInfo> | null): Promise<MirrorResult>;
|
|
27
28
|
//# sourceMappingURL=floriday-mirror.server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floriday-mirror.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-mirror.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"floriday-mirror.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-mirror.server.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAuJ9E,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,0DAA0D;IAC1D,OAAO,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IACnD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AA07CD,eAAO,MAAM,oBAAoB,MAAgB,CAAC;AAElD,wBAAsB,4BAA4B,CAAC,KAAK,SAAgB,EAAE,KAAK,GAAE,MAAM,GAAG,IAAW,yBAEpG;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,QAAQ,GAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,IAAW,yBAI/G"}
|
|
@@ -15,6 +15,7 @@ import { fillOnlyEmpty, snapshotFromFloridayOrder } from "./packing-snapshot.js"
|
|
|
15
15
|
import { deriveOrderLevel } from "./floriday-order-level.js";
|
|
16
16
|
import { productNameForStorage } from "./product-name.js";
|
|
17
17
|
import { resolveBufferForOrderInternal } from "./order-buffers.server.js";
|
|
18
|
+
import { backfillInsertFields } from "./floriday-backfill.js";
|
|
18
19
|
const LOOKBACK_DAYS = 14;
|
|
19
20
|
const DEFAULT_BATCH = 200;
|
|
20
21
|
/** Onbekend blijft onbekend: geen stilzwijgende 1. Zelfde helper als de planner. */
|
|
@@ -151,7 +152,7 @@ function pickString(value) {
|
|
|
151
152
|
// terwijl ze dit spiegelen aanroept). Faalt gesloten: geen slot = geen ronde.
|
|
152
153
|
const MIRROR_LOCK_KEY = "verkoop:floriday-mirror";
|
|
153
154
|
const MIRROR_LOCK_SECONDS = 600;
|
|
154
|
-
async function mirrorInternal(limit, since = null, onlyIds = null) {
|
|
155
|
+
async function mirrorInternal(limit, since = null, onlyIds = null, backfill = null) {
|
|
155
156
|
const { supabaseAdmin } = await import("../integrations/supabase/client.server.js");
|
|
156
157
|
const empty = (reason, ok) => ({
|
|
157
158
|
ok, processed: 0, inserted: 0, updated: 0, skipped: 0, failed: 0, errors: ok ? [] : [reason], skipped_reason: reason,
|
|
@@ -162,7 +163,7 @@ async function mirrorInternal(limit, since = null, onlyIds = null) {
|
|
|
162
163
|
if (acquired !== true)
|
|
163
164
|
return empty("already-running", true);
|
|
164
165
|
try {
|
|
165
|
-
return await mirrorUnlocked(limit, since, onlyIds);
|
|
166
|
+
return await mirrorUnlocked(limit, since, onlyIds, backfill);
|
|
166
167
|
}
|
|
167
168
|
finally {
|
|
168
169
|
try {
|
|
@@ -173,7 +174,8 @@ async function mirrorInternal(limit, since = null, onlyIds = null) {
|
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
|
-
async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
177
|
+
async function mirrorUnlocked(limit, since, onlyIds = null, backfill = null) {
|
|
178
|
+
const backfillOrderIds = new Set();
|
|
177
179
|
const { supabaseAdmin } = await import("../integrations/supabase/client.server.js");
|
|
178
180
|
const { loadFloridayFulfillmentStates, expectedPackagesFromSalesOrder, isFullyFulfilled, } = await import("./floriday-fulfillment-status.server.js");
|
|
179
181
|
const cutoffIso = new Date(Date.now() - LOOKBACK_DAYS * 24 * 60 * 60 * 1000).toISOString();
|
|
@@ -339,18 +341,6 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
339
341
|
lineOwnerByFoId.set(String(it.source_line_key), owner);
|
|
340
342
|
}
|
|
341
343
|
}
|
|
342
|
-
// Groepeert de Engine buiten het tijdvenster? Dan zoeken we bestaande orders
|
|
343
|
-
// ook op de Engine-sleutel (de groepssleutel zonder minuut).
|
|
344
|
-
let engineMergeEnabled = false;
|
|
345
|
-
{
|
|
346
|
-
const { data: me, error: meErr } = await supabaseAdmin.rpc("logistics_merge_lines_enabled");
|
|
347
|
-
if (!meErr)
|
|
348
|
-
engineMergeEnabled = me === true;
|
|
349
|
-
}
|
|
350
|
-
const mergeKeyOf = (k) => {
|
|
351
|
-
const parts = String(k ?? "").split("|");
|
|
352
|
-
return parts.length > 1 ? parts.slice(0, -1).join("|") : null;
|
|
353
|
-
};
|
|
354
344
|
// Afhandeling die in Floriday zelf is gedaan (afleverbrieven). Zo'n order is
|
|
355
345
|
// de deur uit, ook al staat de verkooporder in Floriday nog op COMMITTED.
|
|
356
346
|
let fulfillmentStates = new Map();
|
|
@@ -617,34 +607,9 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
617
607
|
}
|
|
618
608
|
}
|
|
619
609
|
}
|
|
620
|
-
//
|
|
621
|
-
//
|
|
622
|
-
|
|
623
|
-
if (engineMergeEnabled && keyedGroups.length > 0) {
|
|
624
|
-
const dates = Array.from(new Set(keyedGroups
|
|
625
|
-
.map((g) => g.group[0]?.deliveryIso?.slice(0, 10))
|
|
626
|
-
.filter((d) => Boolean(d))));
|
|
627
|
-
if (dates.length > 0) {
|
|
628
|
-
const { data: mkRows, error: mkErr } = await supabaseAdmin
|
|
629
|
-
.from("orders")
|
|
630
|
-
.select(ORDER_COLS)
|
|
631
|
-
.eq("order_source", "floriday")
|
|
632
|
-
.in("delivery_date", dates)
|
|
633
|
-
.not("floriday_order_group_key", "is", null)
|
|
634
|
-
.is("deleted_at", null);
|
|
635
|
-
if (mkErr)
|
|
636
|
-
throw new Error(`orders op Engine-sleutel lezen: ${mkErr.message}`);
|
|
637
|
-
for (const o of mkRows ?? []) {
|
|
638
|
-
const mk = mergeKeyOf(o.floriday_order_group_key);
|
|
639
|
-
if (!mk)
|
|
640
|
-
continue;
|
|
641
|
-
const prev = existingByMergeKey.get(mk);
|
|
642
|
-
if (!prev || String(o.order_number ?? "") < String(prev.order_number ?? "")) {
|
|
643
|
-
existingByMergeKey.set(mk, o);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
610
|
+
// De groepssleutel is een ondoorzichtige identiteit (fo|<salesOrderId> of
|
|
611
|
+
// fo|g|<org>|<salesOrderGroupId>); er wordt nooit een samenvoegsleutel van
|
|
612
|
+
// afgeleid door delen eraf te knippen (zie AGENTS.md).
|
|
648
613
|
// Regels in quarantaine zetten (nooit wissen) + logregel + order markeren.
|
|
649
614
|
const quarantineLines = async (args) => {
|
|
650
615
|
let q = supabaseAdmin.from("order_items")
|
|
@@ -809,8 +774,6 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
809
774
|
if (ow)
|
|
810
775
|
mergeCandidates.push(ow);
|
|
811
776
|
}
|
|
812
|
-
const mk = engineMergeEnabled ? mergeKeyOf(groupKey) : null;
|
|
813
|
-
void mk; // Engine-sleutel wordt niet meer gebruikt om een doel te kiezen.
|
|
814
777
|
if (!target) {
|
|
815
778
|
target = mergeCandidates.find((c) => c && !isFrozen(c)) ?? null;
|
|
816
779
|
}
|
|
@@ -1137,6 +1100,9 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
1137
1100
|
}
|
|
1138
1101
|
}
|
|
1139
1102
|
else {
|
|
1103
|
+
// Inhalen: markering in dezelfde INSERT, vóór de orderregels.
|
|
1104
|
+
const bfInfo = backfill?.get(primary.foId) ?? null;
|
|
1105
|
+
const bf = bfInfo ? backfillInsertFields(bfInfo, memberIds, new Date().toISOString()) : null;
|
|
1140
1106
|
const { data: ins, error: iErr } = await supabaseAdmin.from("orders")
|
|
1141
1107
|
.insert({
|
|
1142
1108
|
order_number: orderNumber,
|
|
@@ -1144,13 +1110,14 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
1144
1110
|
customer_id: primary.custId,
|
|
1145
1111
|
order_date: groupLvl.orderDate ?? primary.orderDateIso,
|
|
1146
1112
|
delivery_date: groupLvl.deliveryDate,
|
|
1147
|
-
status: groupLvl.status,
|
|
1113
|
+
status: bf ? bf.status : groupLvl.status,
|
|
1148
1114
|
total: String(totalPrice),
|
|
1149
1115
|
custom_fields: {
|
|
1150
1116
|
...custom_fields,
|
|
1151
1117
|
floriday_status: groupLvl.floridayStatusSummary,
|
|
1152
1118
|
...(groupLvl.mixedDeliveryDates ? { floriday_mixed_delivery_dates: true } : {}),
|
|
1153
1119
|
floriday_groups: { [primary.foId]: memberIds },
|
|
1120
|
+
...(bf ? bf.customFields : {}),
|
|
1154
1121
|
},
|
|
1155
1122
|
order_source: "floriday",
|
|
1156
1123
|
floriday_sales_order_id: primary.foId,
|
|
@@ -1162,6 +1129,8 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
1162
1129
|
if (iErr)
|
|
1163
1130
|
throw new Error(iErr.message);
|
|
1164
1131
|
orderId = ins.id;
|
|
1132
|
+
if (bf)
|
|
1133
|
+
backfillOrderIds.add(orderId);
|
|
1165
1134
|
inserted++;
|
|
1166
1135
|
changedOrderIds.push(orderId);
|
|
1167
1136
|
noteChange(orderId, "nieuw");
|
|
@@ -1405,7 +1374,7 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
1405
1374
|
// ons ERP om in Floriday zijn afgehandeld hoeven niet meer gepland te
|
|
1406
1375
|
// worden.
|
|
1407
1376
|
const externallyHandled = anyFulfilled && !ffPrimary?.createdByErp;
|
|
1408
|
-
if (!externallyHandled) {
|
|
1377
|
+
if (!externallyHandled && !backfillOrderIds.has(orderId)) {
|
|
1409
1378
|
await resolveBufferForOrderInternal(orderId);
|
|
1410
1379
|
affectedOrderIds.push(orderId);
|
|
1411
1380
|
}
|
|
@@ -1457,6 +1426,9 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
1457
1426
|
for (const oid of Array.from(handledOrderIds)) {
|
|
1458
1427
|
if (legacyExternalIds.has(oid))
|
|
1459
1428
|
continue;
|
|
1429
|
+
// Ingehaalde orders zijn al als afgehandeld aangemaakt; geen Engine-melding.
|
|
1430
|
+
if (backfillOrderIds.has(oid))
|
|
1431
|
+
continue;
|
|
1460
1432
|
try {
|
|
1461
1433
|
const { handleFloridayExternalFulfillment } = await import("./floriday-external-fulfillment.server.js");
|
|
1462
1434
|
await handleFloridayExternalFulfillment(oid, fulfillmentStates);
|
|
@@ -1488,6 +1460,15 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
1488
1460
|
onConflict: "order_id",
|
|
1489
1461
|
});
|
|
1490
1462
|
}
|
|
1463
|
+
// Ingehaalde orders: de trigger enqueue_cart_replan zet ze bij het aanmaken
|
|
1464
|
+
// in de herindelwachtrij; weghalen, net als bij volledig afgehandeld.
|
|
1465
|
+
if (backfillOrderIds.size > 0) {
|
|
1466
|
+
const { error: bfqErr } = await supabaseAdmin.from("cart_replan_queue")
|
|
1467
|
+
.delete()
|
|
1468
|
+
.in("order_id", Array.from(backfillOrderIds));
|
|
1469
|
+
if (bfqErr)
|
|
1470
|
+
errors.push(`herindelwachtrij ingehaalde orders opschonen faalde: ${bfqErr.message}`.slice(0, 200));
|
|
1471
|
+
}
|
|
1491
1472
|
// Stap 2: orders die in deze ronde echt zijn aangemaakt of gewijzigd
|
|
1492
1473
|
// expliciet aanmelden bij de planwachtrij van de logistiek-engine. Mislukt
|
|
1493
1474
|
// dat, dan verschijnt het als duidelijke fout in het syncresultaat.
|
|
@@ -1546,9 +1527,9 @@ export async function mirrorFloridayOrdersFromCron(limit = DEFAULT_BATCH, since
|
|
|
1546
1527
|
* Gerichte spiegeling (direct na de cache-upsert): alleen deze salesOrderIds
|
|
1547
1528
|
* plus echte groepsgenoten. Zelfde logica en slot als de minuutronde.
|
|
1548
1529
|
*/
|
|
1549
|
-
export async function mirrorFloridayOrdersByIds(ids) {
|
|
1530
|
+
export async function mirrorFloridayOrdersByIds(ids, backfill = null) {
|
|
1550
1531
|
const clean = Array.from(new Set(ids.map((x) => String(x).trim()).filter(Boolean))).slice(0, 200);
|
|
1551
1532
|
if (!clean.length)
|
|
1552
1533
|
return { ok: true, processed: 0, inserted: 0, updated: 0, skipped: 0, failed: 0, errors: [] };
|
|
1553
|
-
return mirrorInternal(clean.length + 50, null, clean);
|
|
1534
|
+
return mirrorInternal(clean.length + 50, null, clean, backfill);
|
|
1554
1535
|
}
|
|
@@ -51,4 +51,13 @@ export declare function notReportedState(erp: OrderStage | undefined, floriday:
|
|
|
51
51
|
* eigen stand. null = niets extra's ten opzichte van "Afgemeld x van y".
|
|
52
52
|
*/
|
|
53
53
|
export declare function floridayInvoiceLine(raw: string | null | undefined, done: number, total: number): string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Eén toestand voor de Floriday-regel in de factuurkaart. Afgehandeld in
|
|
56
|
+
* Floriday gaat vóór de ruwe Floriday-status: nooit tegelijk "Nog niet
|
|
57
|
+
* afgemeld" en "Al afgehandeld".
|
|
58
|
+
*/
|
|
59
|
+
export declare function floridayInvoiceState(raw: string | null | undefined, done: number, total: number, external: {
|
|
60
|
+
full: boolean;
|
|
61
|
+
count: number;
|
|
62
|
+
}): string | null;
|
|
54
63
|
//# sourceMappingURL=floriday-status.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floriday-status.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-status.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,qBAAqB,GACrB,WAAW,GACX,WAAW,GACX,SAAS,GACT,SAAS,CAAC;AAEd,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,aAAa,EAAE,aAAa,CAAC;IAC7B,mBAAmB,EAAE;QAAE,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,mBAAmB,EA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AAG,SAAS,EAC3D,iBAAiB,EAAE,OAAO,GACzB,gBAAgB,CAMlB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAc9G;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACzC,MAAM,GAAG,IAAI,CAIf"}
|
|
@@ -123,3 +123,15 @@ export function floridayInvoiceLine(raw, done, total) {
|
|
|
123
123
|
return total > 0 && done > 0 && done < total ? null : "Deels afgemeld in Floriday";
|
|
124
124
|
return total > 0 && done === 0 ? null : "Nog niet afgemeld in Floriday";
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Eén toestand voor de Floriday-regel in de factuurkaart. Afgehandeld in
|
|
128
|
+
* Floriday gaat vóór de ruwe Floriday-status: nooit tegelijk "Nog niet
|
|
129
|
+
* afgemeld" en "Al afgehandeld".
|
|
130
|
+
*/
|
|
131
|
+
export function floridayInvoiceState(raw, done, total, external) {
|
|
132
|
+
if (external.full)
|
|
133
|
+
return "Afgehandeld in Floriday";
|
|
134
|
+
if (external.count > 0)
|
|
135
|
+
return `${external.count} bestelling${external.count === 1 ? "" : "en"} afgehandeld in Floriday`;
|
|
136
|
+
return floridayInvoiceLine(raw, done, total);
|
|
137
|
+
}
|