@flowselections/floriday-verkoop-module 1.0.127 → 1.0.129
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/CreateOrderPage.d.ts.map +1 -1
- package/dist-lib/components/verkoop/CreateOrderPage.js +19 -2
- package/dist-lib/components/verkoop/EditLocalOrderDialog.d.ts.map +1 -1
- package/dist-lib/components/verkoop/EditLocalOrderDialog.js +3 -2
- package/dist-lib/components/verkoop/OrderKarindelingCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderKarindelingCard.js +5 -2
- package/dist-lib/components/verkoop/OrderLinePackingCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderLinePackingCard.js +7 -1
- package/dist-lib/components/verkoop/OrderShipmentsCard.js +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailView.js +1 -1
- package/dist-lib/components/verkoop/SalesOrdersTable.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrdersTable.js +2 -1
- package/dist-lib/integrations/supabase/types.d.ts +730 -122
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.js +1 -0
- package/dist-lib/lib/cron/index.d.ts +1 -0
- package/dist-lib/lib/cron/index.d.ts.map +1 -1
- package/dist-lib/lib/cron/index.js +1 -0
- package/dist-lib/lib/cron/sync-salesorders-now.d.ts +2 -0
- package/dist-lib/lib/cron/sync-salesorders-now.d.ts.map +1 -0
- package/dist-lib/lib/cron/sync-salesorders-now.js +52 -0
- package/dist-lib/lib/delivery-location.check.d.ts +2 -0
- package/dist-lib/lib/delivery-location.check.d.ts.map +1 -0
- package/dist-lib/lib/delivery-location.check.js +29 -0
- package/dist-lib/lib/delivery-location.server.d.ts +35 -0
- package/dist-lib/lib/delivery-location.server.d.ts.map +1 -0
- package/dist-lib/lib/delivery-location.server.js +171 -0
- package/dist-lib/lib/floriday-mirror.server.d.ts +7 -0
- package/dist-lib/lib/floriday-mirror.server.d.ts.map +1 -1
- package/dist-lib/lib/floriday-mirror.server.js +38 -5
- package/dist-lib/lib/floriday-status.server.d.ts.map +1 -1
- package/dist-lib/lib/floriday-status.server.js +2 -0
- package/dist-lib/lib/module-version.d.ts +1 -1
- package/dist-lib/lib/module-version.js +1 -1
- package/dist-lib/lib/order-addresses.functions.d.ts +1 -0
- package/dist-lib/lib/order-addresses.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-addresses.functions.js +28 -29
- package/dist-lib/lib/order-item-packing.functions.d.ts +6 -0
- package/dist-lib/lib/order-item-packing.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-item-packing.functions.js +18 -1
- package/dist-lib/lib/plan-coverage.d.ts +15 -0
- package/dist-lib/lib/plan-coverage.d.ts.map +1 -1
- package/dist-lib/lib/plan-coverage.js +16 -0
- package/dist-lib/lib/product-plannable.functions.d.ts +14 -0
- package/dist-lib/lib/product-plannable.functions.d.ts.map +1 -0
- package/dist-lib/lib/product-plannable.functions.js +24 -0
- package/dist-lib/lib/salesorders-list.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.functions.js +15 -1
- package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.server.js +10 -0
- package/dist-lib/lib/salesorders-mapping.d.ts +2 -0
- package/dist-lib/lib/salesorders-mapping.d.ts.map +1 -1
- package/package.json +9 -1
- package/schema/verkoop.sql +98 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { replanCartsCron, replanCartsCronHint } from "./replan-carts.js";
|
|
2
2
|
export { syncSalesOrdersCron, syncSalesOrdersCronHint } from "./sync-salesorders.js";
|
|
3
3
|
export { invoiceDueCron, invoiceDueCronHint } from "./invoice-due.js";
|
|
4
|
+
export { syncSalesOrdersNowCron } from "./sync-salesorders-now.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/cron/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/cron/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { replanCartsCron, replanCartsCronHint } from "./replan-carts.js";
|
|
2
2
|
export { syncSalesOrdersCron, syncSalesOrdersCronHint } from "./sync-salesorders.js";
|
|
3
3
|
export { invoiceDueCron, invoiceDueCronHint } from "./invoice-due.js";
|
|
4
|
+
export { syncSalesOrdersNowCron } from "./sync-salesorders-now.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-salesorders-now.d.ts","sourceRoot":"","sources":["../../../src/lib/cron/sync-salesorders-now.ts"],"names":[],"mappings":"AAUA,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2CrG"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Directe omzetting: de databasetrigger op floriday_salesorders_cache stuurt
|
|
2
|
+
// per statement alle nieuwe of inhoudelijk gewijzigde salesOrderIds in één
|
|
3
|
+
// verzoek hierheen. Zelfde controle als de minuutronde (apikey). Daarna wordt
|
|
4
|
+
// de Engine gewekt (logistics_plan_enqueue gebeurt in de spiegeling zelf).
|
|
5
|
+
// De minuutronde blijft het vangnet: mislukt dit, dan alleen een logregel.
|
|
6
|
+
const MAX_IDS = 200;
|
|
7
|
+
const RETRIES = 3;
|
|
8
|
+
const RETRY_MS = 1500;
|
|
9
|
+
export async function syncSalesOrdersNowCron(request, _supabase) {
|
|
10
|
+
const apikey = request.headers.get("apikey") ?? request.headers.get("x-api-key");
|
|
11
|
+
const expected = process.env.SUPABASE_PUBLISHABLE_KEY;
|
|
12
|
+
if (!expected || !apikey || apikey !== expected) {
|
|
13
|
+
return new Response("Unauthorized", { status: 401 });
|
|
14
|
+
}
|
|
15
|
+
let ids = [];
|
|
16
|
+
try {
|
|
17
|
+
const body = await request.json();
|
|
18
|
+
ids = Array.isArray(body?.salesOrderIds) ? body.salesOrderIds.map(String).filter(Boolean) : [];
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
ids = [];
|
|
22
|
+
}
|
|
23
|
+
ids = Array.from(new Set(ids)).slice(0, MAX_IDS);
|
|
24
|
+
if (!ids.length)
|
|
25
|
+
return Response.json({ ok: true, skipped: "geen-ids" });
|
|
26
|
+
const started = Date.now();
|
|
27
|
+
const { mirrorFloridayOrdersByIds } = await import("../floriday-mirror.server.js");
|
|
28
|
+
let result = null;
|
|
29
|
+
// Loopt de minuutronde net, dan kort wachten; anders pakt die ronde het op.
|
|
30
|
+
for (let i = 0; i < RETRIES; i++) {
|
|
31
|
+
result = await mirrorFloridayOrdersByIds(ids);
|
|
32
|
+
if (result?.skipped_reason !== "already-running")
|
|
33
|
+
break;
|
|
34
|
+
await new Promise((r) => setTimeout(r, RETRY_MS));
|
|
35
|
+
}
|
|
36
|
+
const orderIds = Array.isArray(result?.enqueuedOrderIds) ? result.enqueuedOrderIds : [];
|
|
37
|
+
if (orderIds.length) {
|
|
38
|
+
const { wakeEnginePlanNow } = await import("../engine-wake.server.js");
|
|
39
|
+
wakeEnginePlanNow(orderIds, new URL(request.url).origin, "floriday-direct");
|
|
40
|
+
}
|
|
41
|
+
console.log(`[sync-salesorders-now] ids=${ids.length} verwerkt=${result?.processed ?? 0} nieuw=${result?.inserted ?? 0} gewijzigd=${result?.updated ?? 0} aangemeld=${orderIds.length} ${Date.now() - started}ms${result?.skipped_reason ? ` overgeslagen=${result.skipped_reason}` : ""}`);
|
|
42
|
+
return Response.json({
|
|
43
|
+
ok: result?.ok !== false,
|
|
44
|
+
ids: ids.length,
|
|
45
|
+
processed: result?.processed ?? 0,
|
|
46
|
+
inserted: result?.inserted ?? 0,
|
|
47
|
+
updated: result?.updated ?? 0,
|
|
48
|
+
enqueued: orderIds.length,
|
|
49
|
+
skipped: result?.skipped_reason ?? null,
|
|
50
|
+
ms: Date.now() - started,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery-location.check.d.ts","sourceRoot":"","sources":["../../src/lib/delivery-location.check.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Draaien: bun src/lib/delivery-location.check.ts
|
|
2
|
+
import { pickDeliveryLocation, deliveryLocationLabel } from "./delivery-location.server.js";
|
|
3
|
+
import { parseGeenIndeling, parseAdditionalLayers } from "./plan-coverage.js";
|
|
4
|
+
let fail = 0;
|
|
5
|
+
const eq = (n, got, want) => {
|
|
6
|
+
const ok = JSON.stringify(got) === JSON.stringify(want);
|
|
7
|
+
if (!ok)
|
|
8
|
+
fail++;
|
|
9
|
+
console.log(`${ok ? "ok " : "FOUT"} ${n}: ${JSON.stringify(got)}`);
|
|
10
|
+
};
|
|
11
|
+
const ref = (p) => ({ key: "o", gln: null, locationId: null, floridayAddress: null, floridayName: null, buyerOrgId: null, customerId: null, ...p });
|
|
12
|
+
const addr = { addressLine: "Legmeerdijk 313", city: "AALSMEER", postalCode: "1431 GB", countryCode: "NL" };
|
|
13
|
+
const fl = [
|
|
14
|
+
{ gln_code: "8713783885413", floriday_id: "x", is_deleted: true, data: { name: "C046 - 88O", organizationId: "andere", address: addr } },
|
|
15
|
+
{ gln_code: "8713783885413", floriday_id: "y", is_deleted: false, data: { name: "C046 - 88", organizationId: "koper", address: addr } },
|
|
16
|
+
];
|
|
17
|
+
const klant = [{ id: "k", customer_id: "c", gln: "8713783885413", name: "Royal FloraHolland Naaldwijk", city: "Honselersdijk" }];
|
|
18
|
+
eq("FO-2601460: GLN → Floriday-locatie van de koper", deliveryLocationLabel(pickDeliveryLocation(ref({ gln: "8713783885413", buyerOrgId: "koper" }), fl, klant)), "Legmeerdijk 313 (C046 - 88), Aalsmeer");
|
|
19
|
+
eq("adres in de Floriday-levering gaat voor", pickDeliveryLocation(ref({ gln: "8713783885413", floridayAddress: { addressLine: "Elders 1", city: "Rijsenhout" } }), fl, klant)?.source, "floriday_levering");
|
|
20
|
+
eq("geen Floriday-locatie → klantlocatie", pickDeliveryLocation(ref({ gln: "8713783885413" }), [], klant)?.source, "klantlocatie");
|
|
21
|
+
eq("geen afleverlocatie → niets (scherm toont klantadres)", pickDeliveryLocation(ref({}), fl, klant), null);
|
|
22
|
+
eq("geenIndeling gelezen", parseGeenIndeling({ code: "LD01", tekst: "Past niet", actie: "Belading aanpassen", actieUrl: "/x" }), { code: "LD01", tekst: "Past niet", actie: "Belading aanpassen", actieUrl: "/x" });
|
|
23
|
+
eq("geenIndeling ontbreekt → null", parseGeenIndeling(undefined), null);
|
|
24
|
+
eq("additionalLayers heel getal", parseAdditionalLayers(2), 2);
|
|
25
|
+
eq("additionalLayers ontbreekt/breuk → null", [parseAdditionalLayers(undefined), parseAdditionalLayers(1.5), parseAdditionalLayers("2")], [null, null, null]);
|
|
26
|
+
if (fail) {
|
|
27
|
+
console.error(`${fail} fout(en)`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface DeliveryLocation {
|
|
2
|
+
name: string | null;
|
|
3
|
+
line: string | null;
|
|
4
|
+
postalCode: string | null;
|
|
5
|
+
city: string | null;
|
|
6
|
+
country: string | null;
|
|
7
|
+
gln: string | null;
|
|
8
|
+
source: "floriday_levering" | "floriday_locatie" | "klantlocatie" | "alleen_gln";
|
|
9
|
+
}
|
|
10
|
+
/** Titelcase voor plaatsnamen in hoofdletters ("AALSMEER" → "Aalsmeer"). */
|
|
11
|
+
export declare function niceCity(c: string | null): string | null;
|
|
12
|
+
/** "Legmeerdijk 313 (C046 - 88), Aalsmeer" */
|
|
13
|
+
export declare function deliveryLocationLabel(l: DeliveryLocation | null | undefined): string | null;
|
|
14
|
+
export interface DeliveryRef {
|
|
15
|
+
key: string;
|
|
16
|
+
gln: string | null;
|
|
17
|
+
locationId: string | null;
|
|
18
|
+
floridayAddress: any | null;
|
|
19
|
+
floridayName: string | null;
|
|
20
|
+
buyerOrgId: string | null;
|
|
21
|
+
customerId: string | null;
|
|
22
|
+
}
|
|
23
|
+
/** Kern: refs → locatie. Pure op de aangeleverde rijen (testbaar). */
|
|
24
|
+
export declare function pickDeliveryLocation(ref: DeliveryRef, floridayLocations: {
|
|
25
|
+
gln_code: string | null;
|
|
26
|
+
floriday_id: string | null;
|
|
27
|
+
data: any;
|
|
28
|
+
is_deleted: boolean | null;
|
|
29
|
+
}[], customerLocations: any[]): DeliveryLocation | null;
|
|
30
|
+
/**
|
|
31
|
+
* Afleverlocaties voor lokale order-id's (orders.id). Vier gebundelde reads,
|
|
32
|
+
* ongeacht het aantal orders. Fout → lege map (scherm valt terug).
|
|
33
|
+
*/
|
|
34
|
+
export declare function loadDeliveryLocations(supabase: any, orderIds: string[]): Promise<Map<string, DeliveryLocation>>;
|
|
35
|
+
//# sourceMappingURL=delivery-location.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery-location.server.d.ts","sourceRoot":"","sources":["../../src/lib/delivery-location.server.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,MAAM,EAAE,mBAAmB,GAAG,kBAAkB,GAAG,cAAc,GAAG,YAAY,CAAC;CAClF;AAUD,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAGxD;AAED,8CAA8C;AAC9C,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAM3F;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,eAAe,EAAE,GAAG,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAcD,sEAAsE;AACtE,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,WAAW,EAChB,iBAAiB,EAAE;IAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC;IAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,EAAE,EACnH,iBAAiB,EAAE,GAAG,EAAE,GACvB,gBAAgB,GAAG,IAAI,CAkDzB;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,GAAG,EACb,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAiFxC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Afleverlocatie per order: GLN/locatie-id → naam en adres.
|
|
2
|
+
// Volgorde: (1) adres in de Floriday-levering zelf, (2) Floriday-locaties
|
|
3
|
+
// (voorkeur: locatie van de koper, niet verwijderd), (3) klantlocaties
|
|
4
|
+
// (voorkeur: locatie van de gekoppelde klant). Klantadres is nooit een
|
|
5
|
+
// afleverlocatie; dat kiest het scherm alleen als hier niets uitkomt.
|
|
6
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
7
|
+
function s(v) {
|
|
8
|
+
if (v == null)
|
|
9
|
+
return null;
|
|
10
|
+
const t = String(v).trim();
|
|
11
|
+
return t ? t : null;
|
|
12
|
+
}
|
|
13
|
+
/** Titelcase voor plaatsnamen in hoofdletters ("AALSMEER" → "Aalsmeer"). */
|
|
14
|
+
export function niceCity(c) {
|
|
15
|
+
if (!c)
|
|
16
|
+
return c;
|
|
17
|
+
return c === c.toUpperCase() ? c.toLowerCase().replace(/(^|[\s-])\p{L}/gu, (m) => m.toUpperCase()) : c;
|
|
18
|
+
}
|
|
19
|
+
/** "Legmeerdijk 313 (C046 - 88), Aalsmeer" */
|
|
20
|
+
export function deliveryLocationLabel(l) {
|
|
21
|
+
if (!l)
|
|
22
|
+
return null;
|
|
23
|
+
const head = [l.line, l.name ? `(${l.name})` : null].filter(Boolean).join(" ");
|
|
24
|
+
const city = niceCity(l.city);
|
|
25
|
+
const out = [head || null, city].filter(Boolean).join(", ");
|
|
26
|
+
return out || (l.gln ? `GLN ${l.gln}` : null);
|
|
27
|
+
}
|
|
28
|
+
function fromFloridayData(d, gln) {
|
|
29
|
+
const a = d?.address ?? {};
|
|
30
|
+
return {
|
|
31
|
+
name: s(d?.name),
|
|
32
|
+
line: s(a.addressLine),
|
|
33
|
+
postalCode: s(a.postalCode),
|
|
34
|
+
city: s(a.city),
|
|
35
|
+
country: s(a.countryCode ?? a.country),
|
|
36
|
+
gln: s(d?.gln) ?? gln,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Kern: refs → locatie. Pure op de aangeleverde rijen (testbaar). */
|
|
40
|
+
export function pickDeliveryLocation(ref, floridayLocations, customerLocations) {
|
|
41
|
+
const fa = ref.floridayAddress;
|
|
42
|
+
if (fa && (s(fa.addressLine) || s(fa.city))) {
|
|
43
|
+
return {
|
|
44
|
+
...fromFloridayData({ address: fa, name: ref.floridayName }, ref.gln),
|
|
45
|
+
source: "floriday_levering",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const fl = floridayLocations
|
|
49
|
+
.filter((r) => (ref.gln && r.gln_code === ref.gln) ||
|
|
50
|
+
(ref.locationId && (r.floriday_id === ref.locationId || r.data?.locationId === ref.locationId)))
|
|
51
|
+
.sort((a, b) => score(b) - score(a));
|
|
52
|
+
function score(r) {
|
|
53
|
+
let n = 0;
|
|
54
|
+
if (!r.is_deleted && r.data?.isDeleted !== true)
|
|
55
|
+
n += 2;
|
|
56
|
+
if (ref.buyerOrgId && r.data?.organizationId === ref.buyerOrgId)
|
|
57
|
+
n += 4;
|
|
58
|
+
if (ref.locationId && (r.floriday_id === ref.locationId || r.data?.locationId === ref.locationId))
|
|
59
|
+
n += 8;
|
|
60
|
+
return n;
|
|
61
|
+
}
|
|
62
|
+
if (fl[0])
|
|
63
|
+
return { ...fromFloridayData(fl[0].data, ref.gln), source: "floriday_locatie" };
|
|
64
|
+
const cl = customerLocations
|
|
65
|
+
.filter((r) => (ref.locationId && (r.id === ref.locationId || r.floriday_location_id === ref.locationId)) ||
|
|
66
|
+
(ref.gln && r.gln === ref.gln))
|
|
67
|
+
.sort((a, b) => Number(b.customer_id === ref.customerId) - Number(a.customer_id === ref.customerId));
|
|
68
|
+
const r = cl[0];
|
|
69
|
+
if (r) {
|
|
70
|
+
return {
|
|
71
|
+
name: s(r.name),
|
|
72
|
+
line: s(r.address_line) ?? s([s(r.street), s(r.house_number)].filter(Boolean).join(" ")),
|
|
73
|
+
postalCode: s(r.postal_code),
|
|
74
|
+
city: s(r.city),
|
|
75
|
+
country: s(r.country),
|
|
76
|
+
gln: s(r.gln) ?? ref.gln,
|
|
77
|
+
source: "klantlocatie",
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (ref.gln) {
|
|
81
|
+
return { name: null, line: null, postalCode: null, city: null, country: null, gln: ref.gln, source: "alleen_gln" };
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Afleverlocaties voor lokale order-id's (orders.id). Vier gebundelde reads,
|
|
87
|
+
* ongeacht het aantal orders. Fout → lege map (scherm valt terug).
|
|
88
|
+
*/
|
|
89
|
+
export async function loadDeliveryLocations(supabase, orderIds) {
|
|
90
|
+
const out = new Map();
|
|
91
|
+
const ids = Array.from(new Set(orderIds.filter((x) => UUID_RE.test(x))));
|
|
92
|
+
if (!ids.length)
|
|
93
|
+
return out;
|
|
94
|
+
try {
|
|
95
|
+
const { data: orders } = await supabase
|
|
96
|
+
.from("orders")
|
|
97
|
+
.select("id, customer_id, custom_fields")
|
|
98
|
+
.in("id", ids);
|
|
99
|
+
const refs = [];
|
|
100
|
+
const sids = new Set();
|
|
101
|
+
for (const o of (orders ?? [])) {
|
|
102
|
+
const cf = o.custom_fields ?? {};
|
|
103
|
+
const raw = s(cf.delivery_location_gln ?? cf.delivery_location ?? cf.delivery_location_id);
|
|
104
|
+
const sid = s(cf.floriday_sales_order_id);
|
|
105
|
+
if (sid)
|
|
106
|
+
sids.add(sid);
|
|
107
|
+
refs.push({
|
|
108
|
+
key: String(o.id),
|
|
109
|
+
gln: s(cf.delivery_location_gln) ?? (raw && /^\d{13}$/.test(raw) ? raw : null),
|
|
110
|
+
locationId: raw && !/^\d{13}$/.test(raw) ? raw : s(cf.delivery_location_id),
|
|
111
|
+
floridayAddress: null,
|
|
112
|
+
floridayName: null,
|
|
113
|
+
buyerOrgId: s(cf.floriday_customer_id),
|
|
114
|
+
customerId: s(o.customer_id),
|
|
115
|
+
// tijdelijk: sid voor koppeling
|
|
116
|
+
...(sid ? { _sid: sid } : {}),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (sids.size) {
|
|
120
|
+
const { data: so } = await supabase
|
|
121
|
+
.from("floriday_salesorders_cache")
|
|
122
|
+
.select("floriday_id, data")
|
|
123
|
+
.in("floriday_id", Array.from(sids));
|
|
124
|
+
const bySid = new Map();
|
|
125
|
+
for (const r of (so ?? []))
|
|
126
|
+
bySid.set(String(r.floriday_id), r.data?.delivery?.location ?? null);
|
|
127
|
+
for (const r of refs) {
|
|
128
|
+
const loc = r._sid ? bySid.get(r._sid) : null;
|
|
129
|
+
if (loc) {
|
|
130
|
+
r.floridayAddress = loc.address ?? null;
|
|
131
|
+
r.floridayName = s(loc.name);
|
|
132
|
+
r.gln = r.gln ?? s(loc.gln);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const glns = Array.from(new Set(refs.map((r) => r.gln).filter(Boolean)));
|
|
137
|
+
const locIds = Array.from(new Set(refs.map((r) => r.locationId).filter(Boolean)));
|
|
138
|
+
const [fl, cl] = await Promise.all([
|
|
139
|
+
glns.length || locIds.length
|
|
140
|
+
? supabase
|
|
141
|
+
.from("floriday_delivery_locations_cache")
|
|
142
|
+
.select("gln_code, floriday_id, data, is_deleted")
|
|
143
|
+
.or([
|
|
144
|
+
glns.length ? `gln_code.in.(${glns.join(",")})` : null,
|
|
145
|
+
locIds.length ? `floriday_id.in.(${locIds.join(",")})` : null,
|
|
146
|
+
].filter(Boolean).join(","))
|
|
147
|
+
: Promise.resolve({ data: [] }),
|
|
148
|
+
glns.length || locIds.length
|
|
149
|
+
? supabase
|
|
150
|
+
.from("customer_delivery_locations")
|
|
151
|
+
.select("id, customer_id, floriday_location_id, name, address_line, street, house_number, postal_code, city, country, gln")
|
|
152
|
+
.or([
|
|
153
|
+
glns.length ? `gln.in.(${glns.join(",")})` : null,
|
|
154
|
+
locIds.length ? `floriday_location_id.in.(${locIds.join(",")})` : null,
|
|
155
|
+
locIds.filter((x) => UUID_RE.test(x)).length
|
|
156
|
+
? `id.in.(${locIds.filter((x) => UUID_RE.test(x)).join(",")})`
|
|
157
|
+
: null,
|
|
158
|
+
].filter(Boolean).join(","))
|
|
159
|
+
: Promise.resolve({ data: [] }),
|
|
160
|
+
]);
|
|
161
|
+
for (const r of refs) {
|
|
162
|
+
const l = pickDeliveryLocation(r, (fl.data ?? []), (cl.data ?? []));
|
|
163
|
+
if (l)
|
|
164
|
+
out.set(r.key, l);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
console.warn("[delivery-location] opvraging mislukt:", e?.message);
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
@@ -7,6 +7,8 @@ export interface MirrorResult {
|
|
|
7
7
|
unchanged?: number;
|
|
8
8
|
failed: number;
|
|
9
9
|
enqueued?: number;
|
|
10
|
+
/** Orders die in deze ronde bij de planwachtrij zijn aangemeld. */
|
|
11
|
+
enqueuedOrderIds?: string[];
|
|
10
12
|
/** Per gewijzigde order welke velden echt veranderden. */
|
|
11
13
|
changes?: {
|
|
12
14
|
order_id: string;
|
|
@@ -17,4 +19,9 @@ export interface MirrorResult {
|
|
|
17
19
|
}
|
|
18
20
|
export declare const DEFAULT_MIRROR_BATCH = 200;
|
|
19
21
|
export declare function mirrorFloridayOrdersFromCron(limit?: number, since?: string | null): Promise<MirrorResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Gerichte spiegeling (direct na de cache-upsert): alleen deze salesOrderIds
|
|
24
|
+
* plus echte groepsgenoten. Zelfde logica en slot als de minuutronde.
|
|
25
|
+
*/
|
|
26
|
+
export declare function mirrorFloridayOrdersByIds(ids: string[]): Promise<MirrorResult>;
|
|
20
27
|
//# 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":"AAuKA,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,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;
|
|
1
|
+
{"version":3,"file":"floriday-mirror.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-mirror.server.ts"],"names":[],"mappings":"AAuKA,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;AA85CD,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,yBAI5D"}
|
|
@@ -151,7 +151,7 @@ function pickString(value) {
|
|
|
151
151
|
// terwijl ze dit spiegelen aanroept). Faalt gesloten: geen slot = geen ronde.
|
|
152
152
|
const MIRROR_LOCK_KEY = "verkoop:floriday-mirror";
|
|
153
153
|
const MIRROR_LOCK_SECONDS = 600;
|
|
154
|
-
async function mirrorInternal(limit, since = null) {
|
|
154
|
+
async function mirrorInternal(limit, since = null, onlyIds = null) {
|
|
155
155
|
const { supabaseAdmin } = await import("../integrations/supabase/client.server.js");
|
|
156
156
|
const empty = (reason, ok) => ({
|
|
157
157
|
ok, processed: 0, inserted: 0, updated: 0, skipped: 0, failed: 0, errors: ok ? [] : [reason], skipped_reason: reason,
|
|
@@ -162,7 +162,7 @@ async function mirrorInternal(limit, since = null) {
|
|
|
162
162
|
if (acquired !== true)
|
|
163
163
|
return empty("already-running", true);
|
|
164
164
|
try {
|
|
165
|
-
return await mirrorUnlocked(limit, since);
|
|
165
|
+
return await mirrorUnlocked(limit, since, onlyIds);
|
|
166
166
|
}
|
|
167
167
|
finally {
|
|
168
168
|
try {
|
|
@@ -173,7 +173,7 @@ async function mirrorInternal(limit, since = null) {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
async function mirrorUnlocked(limit, since) {
|
|
176
|
+
async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
177
177
|
const { supabaseAdmin } = await import("../integrations/supabase/client.server.js");
|
|
178
178
|
const { loadFloridayFulfillmentStates, expectedPackagesFromSalesOrder, isFullyFulfilled, } = await import("./floriday-fulfillment-status.server.js");
|
|
179
179
|
const cutoffIso = new Date(Date.now() - LOOKBACK_DAYS * 24 * 60 * 60 * 1000).toISOString();
|
|
@@ -185,7 +185,9 @@ async function mirrorUnlocked(limit, since) {
|
|
|
185
185
|
.select("floriday_id, data, updated_at, buyer_organization_id")
|
|
186
186
|
.eq("is_deleted", false)
|
|
187
187
|
.gte("data->delivery->>latestDeliveryDateTime", cutoffIso);
|
|
188
|
-
if (
|
|
188
|
+
if (onlyIds)
|
|
189
|
+
cacheQuery = cacheQuery.in("floriday_id", onlyIds);
|
|
190
|
+
else if (since)
|
|
189
191
|
cacheQuery = cacheQuery.gt("updated_at", since);
|
|
190
192
|
const { data: baseRows, error: cacheErr } = await cacheQuery
|
|
191
193
|
.order("updated_at", { ascending: false })
|
|
@@ -193,7 +195,25 @@ async function mirrorUnlocked(limit, since) {
|
|
|
193
195
|
if (cacheErr)
|
|
194
196
|
throw new Error(cacheErr.message);
|
|
195
197
|
let cacheRows = (baseRows ?? []);
|
|
196
|
-
|
|
198
|
+
// Gerichte modus: echte groepsgenoten (salesOrderGroupId) meenemen, zodat een
|
|
199
|
+
// groep nooit half wordt gespiegeld. customerOrderId bundelt nooit.
|
|
200
|
+
if (onlyIds && cacheRows.length) {
|
|
201
|
+
const groups = Array.from(new Set(cacheRows.map((r) => r?.data?.salesOrderGroupId).filter(Boolean).map(String)));
|
|
202
|
+
if (groups.length) {
|
|
203
|
+
const have = new Set(cacheRows.map((r) => String(r.floriday_id)));
|
|
204
|
+
const { data: sib, error: sErr } = await supabaseAdmin
|
|
205
|
+
.from("floriday_salesorders_cache")
|
|
206
|
+
.select("floriday_id, data, updated_at, buyer_organization_id")
|
|
207
|
+
.eq("is_deleted", false)
|
|
208
|
+
.in("data->>salesOrderGroupId", groups);
|
|
209
|
+
if (sErr)
|
|
210
|
+
throw new Error(sErr.message);
|
|
211
|
+
for (const r of (sib ?? []))
|
|
212
|
+
if (!have.has(String(r.floriday_id)))
|
|
213
|
+
cacheRows.push(r);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (since && !onlyIds) {
|
|
197
217
|
const { data: idxRows, error: idxErr } = await supabaseAdmin
|
|
198
218
|
.from("verkoop_fulfillment_index")
|
|
199
219
|
.select("sales_order_id")
|
|
@@ -1426,6 +1446,7 @@ async function mirrorUnlocked(limit, since) {
|
|
|
1426
1446
|
// expliciet aanmelden bij de planwachtrij van de logistiek-engine. Mislukt
|
|
1427
1447
|
// dat, dan verschijnt het als duidelijke fout in het syncresultaat.
|
|
1428
1448
|
let enqueued = 0;
|
|
1449
|
+
const enqueuedOrderIds = [];
|
|
1429
1450
|
const toEnqueue = Array.from(new Set(changedOrderIds)).filter((id) => affectedOrderIds.includes(id));
|
|
1430
1451
|
for (const oid of toEnqueue) {
|
|
1431
1452
|
const fields = Array.from(changedFieldsByOrder.get(oid) ?? []).sort();
|
|
@@ -1441,6 +1462,7 @@ async function mirrorUnlocked(limit, since) {
|
|
|
1441
1462
|
}
|
|
1442
1463
|
else {
|
|
1443
1464
|
enqueued++;
|
|
1465
|
+
enqueuedOrderIds.push(oid);
|
|
1444
1466
|
}
|
|
1445
1467
|
}
|
|
1446
1468
|
// Orders zonder karindeling en zonder aanmelding worden door de
|
|
@@ -1463,6 +1485,7 @@ async function mirrorUnlocked(limit, since) {
|
|
|
1463
1485
|
skipped,
|
|
1464
1486
|
failed,
|
|
1465
1487
|
enqueued,
|
|
1488
|
+
enqueuedOrderIds,
|
|
1466
1489
|
changes: Array.from(changedFieldsByOrder.entries())
|
|
1467
1490
|
.slice(0, 50)
|
|
1468
1491
|
.map(([order_id, f]) => ({ order_id, fields: Array.from(f).sort() })),
|
|
@@ -1473,3 +1496,13 @@ export const DEFAULT_MIRROR_BATCH = DEFAULT_BATCH;
|
|
|
1473
1496
|
export async function mirrorFloridayOrdersFromCron(limit = DEFAULT_BATCH, since = null) {
|
|
1474
1497
|
return mirrorInternal(limit, since);
|
|
1475
1498
|
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Gerichte spiegeling (direct na de cache-upsert): alleen deze salesOrderIds
|
|
1501
|
+
* plus echte groepsgenoten. Zelfde logica en slot als de minuutronde.
|
|
1502
|
+
*/
|
|
1503
|
+
export async function mirrorFloridayOrdersByIds(ids) {
|
|
1504
|
+
const clean = Array.from(new Set(ids.map((x) => String(x).trim()).filter(Boolean))).slice(0, 200);
|
|
1505
|
+
if (!clean.length)
|
|
1506
|
+
return { ok: true, processed: 0, inserted: 0, updated: 0, skipped: 0, failed: 0, errors: [] };
|
|
1507
|
+
return mirrorInternal(clean.length + 50, null, clean);
|
|
1508
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floriday-status.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-status.server.ts"],"names":[],"mappings":"AAOA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAoBvF,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC1C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,wBAAsB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,
|
|
1
|
+
{"version":3,"file":"floriday-status.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-status.server.ts"],"names":[],"mappings":"AAOA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAoBvF,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC1C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,wBAAsB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqDjG"}
|
|
@@ -48,6 +48,8 @@ export async function loadFloridayStatuses(salesOrderIds) {
|
|
|
48
48
|
"x-floriday-caller": "verkoop",
|
|
49
49
|
},
|
|
50
50
|
body,
|
|
51
|
+
// Weergave mag de lijst niet ophouden: na 800 ms "stand onbekend".
|
|
52
|
+
signal: AbortSignal.timeout(800),
|
|
51
53
|
});
|
|
52
54
|
const json = await res.json().catch(() => null);
|
|
53
55
|
if (!res.ok || json?.ok === false) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const MODULE_VERSION = "1.0.
|
|
1
|
+
export declare const MODULE_VERSION = "1.0.128";
|
|
2
2
|
//# sourceMappingURL=module-version.d.ts.map
|
|
@@ -18,6 +18,7 @@ export declare const getOrderAddresses: import("@tanstack/start-client-core").Op
|
|
|
18
18
|
}, undefined, undefined, undefined>], (input: unknown) => {
|
|
19
19
|
orderId: string;
|
|
20
20
|
}, Promise<{
|
|
21
|
+
buyerGln: string | null;
|
|
21
22
|
delivery: OrderAddress | null;
|
|
22
23
|
pickup: OrderAddress | null;
|
|
23
24
|
}>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-addresses.functions.d.ts","sourceRoot":"","sources":["../../src/lib/order-addresses.functions.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;
|
|
1
|
+
{"version":3,"file":"order-addresses.functions.d.ts","sourceRoot":"","sources":["../../src/lib/order-addresses.functions.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AASD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;;8CAEJ,OAAO;;;cAmBjB,MAAM,GAAG,IAAI;cACb,YAAY,GAAG,IAAI;YACrB,YAAY,GAAG,IAAI;GAyD7B,CAAC"}
|
|
@@ -3,7 +3,6 @@ import { createServerFn } from "@tanstack/react-start";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
5
5
|
import { resolveOrderRow } from "./order-row.server.js";
|
|
6
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
7
6
|
function s(v) {
|
|
8
7
|
if (v == null)
|
|
9
8
|
return null;
|
|
@@ -35,36 +34,14 @@ export const getOrderAddresses = createServerFn({ method: "GET" })
|
|
|
35
34
|
order = null;
|
|
36
35
|
}
|
|
37
36
|
if (!order)
|
|
38
|
-
return { delivery: null, pickup: null };
|
|
37
|
+
return { delivery: null, pickup: null, buyerGln: null };
|
|
39
38
|
const cf = (order.custom_fields ?? {});
|
|
40
39
|
const deliveryRef = s(cf.delivery_location ?? cf.delivery_location_id ?? cf.delivery_location_gln);
|
|
41
40
|
const pickupRef = s(cf.pickup_location ?? cf.pickup_location_id);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.from("customer_delivery_locations")
|
|
47
|
-
.select("name, address_line, street, house_number, postal_code, city, country, gln")
|
|
48
|
-
.eq("id", deliveryRef)
|
|
49
|
-
.maybeSingle()
|
|
50
|
-
: await supabase
|
|
51
|
-
.from("customer_delivery_locations")
|
|
52
|
-
.select("name, address_line, street, house_number, postal_code, city, country, gln")
|
|
53
|
-
.or(`floriday_location_id.eq.${deliveryRef},gln.eq.${deliveryRef}`)
|
|
54
|
-
.maybeSingle();
|
|
55
|
-
const r = dl.data;
|
|
56
|
-
if (r) {
|
|
57
|
-
delivery = {
|
|
58
|
-
name: s(r.name),
|
|
59
|
-
line: s(r.address_line) ??
|
|
60
|
-
s([s(r.street), s(r.house_number)].filter(Boolean).join(" ")),
|
|
61
|
-
postalCode: s(r.postal_code),
|
|
62
|
-
city: s(r.city),
|
|
63
|
-
country: s(r.country),
|
|
64
|
-
gln: s(r.gln),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
41
|
+
// Afleverlocatie: Floriday-levering → Floriday-locaties → klantlocaties.
|
|
42
|
+
const { loadDeliveryLocations } = await import("./delivery-location.server.js");
|
|
43
|
+
const resolved = deliveryRef ? (await loadDeliveryLocations(supabase, [String(order.id)])).get(String(order.id)) : undefined;
|
|
44
|
+
const delivery = resolved ?? null;
|
|
68
45
|
let pickup = null;
|
|
69
46
|
if (pickupRef) {
|
|
70
47
|
const wh = await supabase
|
|
@@ -86,5 +63,27 @@ export const getOrderAddresses = createServerFn({ method: "GET" })
|
|
|
86
63
|
};
|
|
87
64
|
}
|
|
88
65
|
}
|
|
89
|
-
|
|
66
|
+
// Koper-GLN: gekoppelde klant, anders de Floriday-koper van de order.
|
|
67
|
+
let buyerGln = null;
|
|
68
|
+
try {
|
|
69
|
+
if (order.customer_id) {
|
|
70
|
+
const { data: cu } = await supabase.from("customers").select("gln").eq("id", order.customer_id).maybeSingle();
|
|
71
|
+
buyerGln = s(cu?.gln);
|
|
72
|
+
}
|
|
73
|
+
const org = s(cf.floriday_customer_id);
|
|
74
|
+
if (!buyerGln && org) {
|
|
75
|
+
const { data: fc } = await supabase
|
|
76
|
+
.from("floriday_customers_cache")
|
|
77
|
+
.select("data")
|
|
78
|
+
.eq("organization_id", org)
|
|
79
|
+
.limit(1)
|
|
80
|
+
.maybeSingle();
|
|
81
|
+
const d = fc?.data ?? {};
|
|
82
|
+
buyerGln = s(d.companyGln ?? d.gln);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
buyerGln = null;
|
|
87
|
+
}
|
|
88
|
+
return { delivery, pickup, buyerGln };
|
|
90
89
|
});
|
|
@@ -9,6 +9,12 @@ export interface OrderItemPackingRow {
|
|
|
9
9
|
lockedByName: string | null;
|
|
10
10
|
/** Sticker nodig op deze orderregel (alleen weergave). */
|
|
11
11
|
needsSticker: boolean;
|
|
12
|
+
/** Belading uit de Floriday-verkooporder (alleen FO; null = onbekend). */
|
|
13
|
+
floridayPacking: {
|
|
14
|
+
plantsPerCrate: number | null;
|
|
15
|
+
cratesPerLayer: number | null;
|
|
16
|
+
layersPerCart: number | null;
|
|
17
|
+
} | null;
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
20
|
* Belading per bestelregel van één order, inclusief de handmatige
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-item-packing.functions.d.ts","sourceRoot":"","sources":["../../src/lib/order-item-packing.functions.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,0DAA0D;IAC1D,YAAY,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"order-item-packing.functions.d.ts","sourceRoot":"","sources":["../../src/lib/order-item-packing.functions.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,0DAA0D;IAC1D,YAAY,EAAE,OAAO,CAAC;IACtB,0EAA0E;IAC1E,eAAe,EAAE;QAAE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CACxH;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;8CAEP,OAAO;;;WAYU,mBAAmB,EAAE;GA2D5D,CAAC;AASL,yDAAyD;AACzD,eAAO,MAAM,mBAAmB;;;;8CAEN,OAAO;;;;;;;;GAa7B,CAAC;AAEL,kFAAkF;AAClF,eAAO,MAAM,yBAAyB;;;;8CAEZ,OAAO;;;;;GAY7B,CAAC"}
|
|
@@ -35,12 +35,28 @@ export const listOrderItemPacking = createServerFn({ method: "GET" })
|
|
|
35
35
|
return { items: [] };
|
|
36
36
|
const { data: rows, error } = await supabase
|
|
37
37
|
.from("order_items")
|
|
38
|
-
.select("id, product_name, quantity, plants_per_crate, crates_per_layer, layers_per_cart, packing_locked_at, packing_locked_by, needs_sticker")
|
|
38
|
+
.select("id, product_name, quantity, plants_per_crate, crates_per_layer, layers_per_cart, packing_locked_at, packing_locked_by, needs_sticker, source_line_key")
|
|
39
39
|
.eq("order_id", orderRowId)
|
|
40
40
|
.is("quarantined_at", null)
|
|
41
41
|
.order("product_name", { ascending: true });
|
|
42
42
|
if (error)
|
|
43
43
|
throw new Error(`Bestelregels laden faalde: ${error.message}`);
|
|
44
|
+
// Floriday-belading per bestelling (custom_fields.floriday_lines).
|
|
45
|
+
const floridayBySid = new Map();
|
|
46
|
+
{
|
|
47
|
+
const { data: ord } = await supabase.from("orders").select("custom_fields").eq("id", orderRowId).maybeSingle();
|
|
48
|
+
const lines = Array.isArray(ord?.custom_fields?.floriday_lines) ? ord.custom_fields.floriday_lines : [];
|
|
49
|
+
const n = (v) => (typeof v === "number" && v > 0 ? v : null);
|
|
50
|
+
for (const l of lines) {
|
|
51
|
+
const p = l?.packing ?? {};
|
|
52
|
+
if (l?.sales_order_id)
|
|
53
|
+
floridayBySid.set(String(l.sales_order_id), {
|
|
54
|
+
plantsPerCrate: n(p.pieces_per_package),
|
|
55
|
+
cratesPerLayer: n(p.packages_per_layer),
|
|
56
|
+
layersPerCart: n(p.layers_per_load_carrier),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
44
60
|
const lockedBy = Array.from(new Set((rows ?? []).map((r) => r.packing_locked_by).filter(Boolean)));
|
|
45
61
|
const nameById = new Map();
|
|
46
62
|
if (lockedBy.length > 0) {
|
|
@@ -65,6 +81,7 @@ export const listOrderItemPacking = createServerFn({ method: "GET" })
|
|
|
65
81
|
? nameById.get(r.packing_locked_by) ?? "Onbekende medewerker"
|
|
66
82
|
: null,
|
|
67
83
|
needsSticker: r.needs_sticker === true,
|
|
84
|
+
floridayPacking: r.source_line_key ? floridayBySid.get(String(r.source_line_key)) ?? null : null,
|
|
68
85
|
})),
|
|
69
86
|
};
|
|
70
87
|
});
|