@flowselections/floriday-afhandeling-module 1.0.109 → 1.0.111
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/afhandeling/AfgemeldView.d.ts +6 -0
- package/dist-lib/components/afhandeling/AfgemeldView.d.ts.map +1 -0
- package/dist-lib/components/afhandeling/AfgemeldView.js +44 -0
- package/dist-lib/components/afhandeling/CameraScanner.d.ts +7 -0
- package/dist-lib/components/afhandeling/CameraScanner.d.ts.map +1 -0
- package/dist-lib/components/afhandeling/CameraScanner.js +126 -0
- package/dist-lib/components/afhandeling/ControlePage.d.ts.map +1 -1
- package/dist-lib/components/afhandeling/ControlePage.js +52 -13
- package/dist-lib/components/afhandeling/CorrectieDialog.d.ts +24 -0
- package/dist-lib/components/afhandeling/CorrectieDialog.d.ts.map +1 -0
- package/dist-lib/components/afhandeling/CorrectieDialog.js +100 -0
- package/dist-lib/components/afhandeling/DagDetailDialog.d.ts.map +1 -1
- package/dist-lib/components/afhandeling/DagDetailDialog.js +2 -1
- package/dist-lib/components/afhandeling/FloridayBriefHerprint.d.ts +10 -0
- package/dist-lib/components/afhandeling/FloridayBriefHerprint.d.ts.map +1 -0
- package/dist-lib/components/afhandeling/FloridayBriefHerprint.js +47 -0
- package/dist-lib/components/afhandeling/LeveringCorrigerenDialog.d.ts +7 -0
- package/dist-lib/components/afhandeling/LeveringCorrigerenDialog.d.ts.map +1 -0
- package/dist-lib/components/afhandeling/LeveringCorrigerenDialog.js +79 -0
- package/dist-lib/components/afhandeling/LeveringenPage.js +1 -1
- package/dist-lib/components/afhandeling/NuVersturenButton.d.ts.map +1 -1
- package/dist-lib/components/afhandeling/NuVersturenButton.js +31 -6
- package/dist-lib/components/afhandeling/OrderInzicht.d.ts +6 -0
- package/dist-lib/components/afhandeling/OrderInzicht.d.ts.map +1 -0
- package/dist-lib/components/afhandeling/OrderInzicht.js +90 -0
- package/dist-lib/components/afhandeling/ScanControleView.d.ts +2 -0
- package/dist-lib/components/afhandeling/ScanControleView.d.ts.map +1 -1
- package/dist-lib/components/afhandeling/ScanControleView.js +121 -40
- package/dist-lib/components/afhandeling/TerugkoppelingStand.d.ts +6 -0
- package/dist-lib/components/afhandeling/TerugkoppelingStand.d.ts.map +1 -0
- package/dist-lib/components/afhandeling/TerugkoppelingStand.js +47 -0
- package/dist-lib/components/afhandeling/VervoerderForm.d.ts.map +1 -1
- package/dist-lib/components/afhandeling/VervoerderForm.js +26 -3
- package/dist-lib/components/afhandeling/VervoerderUitFloridayPage.d.ts +5 -0
- package/dist-lib/components/afhandeling/VervoerderUitFloridayPage.d.ts.map +1 -0
- package/dist-lib/components/afhandeling/VervoerderUitFloridayPage.js +50 -0
- package/dist-lib/hooks/useOrderPlanning.d.ts +3 -0
- package/dist-lib/hooks/useOrderPlanning.d.ts.map +1 -1
- package/dist-lib/hooks/useOrderPlanning.js +21 -7
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +1 -0
- package/dist-lib/integrations/supabase/types.d.ts +3810 -2
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.js +1 -0
- package/dist-lib/lib/barcodeFormats.d.ts +5 -0
- package/dist-lib/lib/barcodeFormats.d.ts.map +1 -0
- package/dist-lib/lib/barcodeFormats.js +8 -0
- package/dist-lib/lib/barcodeFormats.test.d.ts +2 -0
- package/dist-lib/lib/barcodeFormats.test.d.ts.map +1 -0
- package/dist-lib/lib/barcodeFormats.test.js +10 -0
- package/dist-lib/lib/carriers.functions.d.ts +34 -0
- package/dist-lib/lib/carriers.functions.d.ts.map +1 -1
- package/dist-lib/lib/carriers.functions.js +57 -0
- package/dist-lib/lib/controleAfwijking.d.ts +50 -0
- package/dist-lib/lib/controleAfwijking.d.ts.map +1 -0
- package/dist-lib/lib/controleAfwijking.js +50 -0
- package/dist-lib/lib/controleAfwijking.test.d.ts +2 -0
- package/dist-lib/lib/controleAfwijking.test.d.ts.map +1 -0
- package/dist-lib/lib/controleAfwijking.test.js +53 -0
- package/dist-lib/lib/controleLijst.functions.d.ts +7 -7
- package/dist-lib/lib/controleLijst.functions.d.ts.map +1 -1
- package/dist-lib/lib/controleLijst.functions.js +12 -39
- package/dist-lib/lib/correctieTekst.d.ts +11 -0
- package/dist-lib/lib/correctieTekst.d.ts.map +1 -0
- package/dist-lib/lib/correctieTekst.js +75 -0
- package/dist-lib/lib/correcties.functions.d.ts +80 -0
- package/dist-lib/lib/correcties.functions.d.ts.map +1 -0
- package/dist-lib/lib/correcties.functions.js +188 -0
- package/dist-lib/lib/cronVak.test.d.ts +2 -0
- package/dist-lib/lib/cronVak.test.d.ts.map +1 -0
- package/dist-lib/lib/cronVak.test.js +17 -0
- package/dist-lib/lib/documentKeuze.d.ts +12 -0
- package/dist-lib/lib/documentKeuze.d.ts.map +1 -1
- package/dist-lib/lib/documentKeuze.functions.d.ts +6 -3
- package/dist-lib/lib/documentKeuze.functions.d.ts.map +1 -1
- package/dist-lib/lib/documentKeuze.functions.js +21 -7
- package/dist-lib/lib/documentKeuze.js +23 -4
- package/dist-lib/lib/documentKeuze.test.js +22 -1
- package/dist-lib/lib/floriday.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday.functions.js +40 -42
- package/dist-lib/lib/floridayCorrectie.d.ts +17 -0
- package/dist-lib/lib/floridayCorrectie.d.ts.map +1 -0
- package/dist-lib/lib/floridayCorrectie.js +50 -0
- package/dist-lib/lib/floridayCorrectie.test.d.ts +2 -0
- package/dist-lib/lib/floridayCorrectie.test.d.ts.map +1 -0
- package/dist-lib/lib/floridayCorrectie.test.js +30 -0
- package/dist-lib/lib/floridayCorrecties.server.d.ts +4 -0
- package/dist-lib/lib/floridayCorrecties.server.d.ts.map +1 -0
- package/dist-lib/lib/floridayCorrecties.server.js +33 -0
- package/dist-lib/lib/floridayLoading.functions.d.ts +12 -0
- package/dist-lib/lib/floridayLoading.functions.d.ts.map +1 -1
- package/dist-lib/lib/floridayLoading.functions.js +76 -12
- package/dist-lib/lib/floridayLoadingSend.test.d.ts +2 -0
- package/dist-lib/lib/floridayLoadingSend.test.d.ts.map +1 -0
- package/dist-lib/lib/floridayLoadingSend.test.js +58 -0
- package/dist-lib/lib/floridayTegengehouden.test.d.ts +2 -0
- package/dist-lib/lib/floridayTegengehouden.test.d.ts.map +1 -0
- package/dist-lib/lib/floridayTegengehouden.test.js +63 -0
- package/dist-lib/lib/floridayTerugkoppeling.d.ts +99 -0
- package/dist-lib/lib/floridayTerugkoppeling.d.ts.map +1 -0
- package/dist-lib/lib/floridayTerugkoppeling.js +153 -0
- package/dist-lib/lib/floridayTerugkoppeling.test.d.ts +2 -0
- package/dist-lib/lib/floridayTerugkoppeling.test.d.ts.map +1 -0
- package/dist-lib/lib/floridayTerugkoppeling.test.js +108 -0
- package/dist-lib/lib/floridayTransporteur.d.ts +24 -0
- package/dist-lib/lib/floridayTransporteur.d.ts.map +1 -0
- package/dist-lib/lib/floridayTransporteur.js +31 -0
- package/dist-lib/lib/floridayTransporteur.test.d.ts +2 -0
- package/dist-lib/lib/floridayTransporteur.test.d.ts.map +1 -0
- package/dist-lib/lib/floridayTransporteur.test.js +19 -0
- package/dist-lib/lib/orderInzicht.d.ts +66 -0
- package/dist-lib/lib/orderInzicht.d.ts.map +1 -0
- package/dist-lib/lib/orderInzicht.js +89 -0
- package/dist-lib/lib/orderInzicht.test.d.ts +2 -0
- package/dist-lib/lib/orderInzicht.test.d.ts.map +1 -0
- package/dist-lib/lib/orderInzicht.test.js +66 -0
- package/dist-lib/lib/serverRoutes/autoSend.handler.js +36 -14
- package/dist-lib/lib/terugkoppeling.functions.d.ts +22 -0
- package/dist-lib/lib/terugkoppeling.functions.d.ts.map +1 -0
- package/dist-lib/lib/terugkoppeling.functions.js +67 -0
- package/dist-lib/lib/terugkoppelingAangenomen.d.ts +62 -0
- package/dist-lib/lib/terugkoppelingAangenomen.d.ts.map +1 -0
- package/dist-lib/lib/terugkoppelingAangenomen.js +141 -0
- package/dist-lib/lib/terugkoppelingAangenomen.test.d.ts +2 -0
- package/dist-lib/lib/terugkoppelingAangenomen.test.d.ts.map +1 -0
- package/dist-lib/lib/terugkoppelingAangenomen.test.js +142 -0
- package/package.json +10 -2
- package/schema/90_afhandeling.sql +2640 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type FloridayStand } from "./floridayCorrectie.js";
|
|
2
|
+
export interface FloridayLadingdrager {
|
|
3
|
+
cartId: string | null;
|
|
4
|
+
nummer: number;
|
|
5
|
+
loadCarrierReference: string | null;
|
|
6
|
+
documentReference: string | null;
|
|
7
|
+
loadCarrierType: string | null;
|
|
8
|
+
platen: number;
|
|
9
|
+
fusten: number;
|
|
10
|
+
items: {
|
|
11
|
+
loadCarrierItemId: string;
|
|
12
|
+
fusten: number;
|
|
13
|
+
orderId: string | null;
|
|
14
|
+
orderItemId: string | null;
|
|
15
|
+
product: string | null;
|
|
16
|
+
afleverbrief: string;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
/** Vastgelegde correctie naar Floriday sturen (of opnieuw proberen). */
|
|
20
|
+
export declare const floridayCorrectieVersturen: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
21
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
22
|
+
userId: string;
|
|
23
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
24
|
+
}, undefined, undefined, undefined>], (i: {
|
|
25
|
+
correctieId: string;
|
|
26
|
+
}) => {
|
|
27
|
+
correctieId: string;
|
|
28
|
+
}, Promise<{
|
|
29
|
+
ok: boolean;
|
|
30
|
+
stand: FloridayStand;
|
|
31
|
+
melding: string;
|
|
32
|
+
}>>;
|
|
33
|
+
export interface FloridayCorrectieRij {
|
|
34
|
+
id: string;
|
|
35
|
+
soort: string;
|
|
36
|
+
reden: string | null;
|
|
37
|
+
door: string | null;
|
|
38
|
+
status: string;
|
|
39
|
+
floridayReden: string | null;
|
|
40
|
+
pogingen: number | null;
|
|
41
|
+
aangemaakt: string;
|
|
42
|
+
}
|
|
43
|
+
/** Correcties van deze levering zoals de Floriday-koppeling ze kent (corrections-list). */
|
|
44
|
+
export declare const floridayCorrectiesLijst: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
45
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
46
|
+
userId: string;
|
|
47
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
48
|
+
}, undefined, undefined, undefined>], (i: {
|
|
49
|
+
orderId: string;
|
|
50
|
+
}) => {
|
|
51
|
+
orderId: string;
|
|
52
|
+
}, Promise<{
|
|
53
|
+
ok: boolean;
|
|
54
|
+
melding?: string;
|
|
55
|
+
fulfillmentOrderId?: string;
|
|
56
|
+
items: FloridayCorrectieRij[];
|
|
57
|
+
}>>;
|
|
58
|
+
export interface GelijkUitkomst {
|
|
59
|
+
ok: boolean;
|
|
60
|
+
melding?: string;
|
|
61
|
+
gelijk?: boolean | null;
|
|
62
|
+
verschillen?: {
|
|
63
|
+
ladingdrager: number | null;
|
|
64
|
+
veld: string;
|
|
65
|
+
onze: string | null;
|
|
66
|
+
floriday: string | null;
|
|
67
|
+
}[];
|
|
68
|
+
floridayStand?: string | null;
|
|
69
|
+
}
|
|
70
|
+
/** Onze belading van deze order tegen de kopie van Floriday (order-equal). */
|
|
71
|
+
export declare const floridayOrderGelijk: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
72
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
73
|
+
userId: string;
|
|
74
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
75
|
+
}, undefined, undefined, undefined>], (i: {
|
|
76
|
+
orderId: string;
|
|
77
|
+
}) => {
|
|
78
|
+
orderId: string;
|
|
79
|
+
}, Promise<GelijkUitkomst>>;
|
|
80
|
+
//# sourceMappingURL=correcties.functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correcties.functions.d.ts","sourceRoot":"","sources":["../../src/lib/correcties.functions.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQxH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC1J;AAiDD,wEAAwE;AACxE,eAAO,MAAM,0BAA0B;;;;0CAEjB;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE;;;QACO,OAAO;WAAS,aAAa;aAAW,MAAM;GAsC9F,CAAC;AAEL,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACrE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;CAC3F;AAED,2FAA2F;AAC3F,eAAO,MAAM,uBAAuB;;;;0CAEd;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE;;;QACW,OAAO;cAAY,MAAM;yBAAuB,MAAM;WAAS,oBAAoB,EAAE;GA8BrI,CAAC;AAEL,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACvD,WAAW,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,EAAE,CAAC;IAC5G,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB;;;;0CAEV;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE;;2BAkCrC,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Golf 3: correcties op Floriday-orders via de Floriday-koppeling.
|
|
2
|
+
// Afhandeling legt de correctie vast (afh_levering_corrigeren) en stuurt hem daarna door;
|
|
3
|
+
// de uitkomst gaat terug in afh_levering_correcties (afh_levering_correctie_floriday).
|
|
4
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
5
|
+
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
6
|
+
import { standVanKoppeling, uitkomstVanGateway } from "./floridayCorrectie.js";
|
|
7
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
|
+
const uuid = (v, wat) => {
|
|
9
|
+
if (typeof v !== "string" || !UUID_RE.test(v))
|
|
10
|
+
throw new Error(`${wat} ontbreekt of klopt niet.`);
|
|
11
|
+
return v;
|
|
12
|
+
};
|
|
13
|
+
async function leveringUitDb(sb, orderId) {
|
|
14
|
+
const { data, error } = await sb.rpc("afh_floriday_levering", { p_order_id: orderId });
|
|
15
|
+
if (error)
|
|
16
|
+
throw new Error(error.message);
|
|
17
|
+
return (data ?? { ok: false, reden: "Geen antwoord van de database." });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Beslismoment 8: nog niet aangenomen in het eigen pogingenlog? Dan de terugkoppeling-list lezen;
|
|
21
|
+
* verstuurd / al_verstuurd (na akkoord door de koppeling) wordt vastgelegd als aangenomen, zonder opnieuw te versturen.
|
|
22
|
+
* Geeft true als er (nu of eerder) een aangenomen levering vastligt.
|
|
23
|
+
*/
|
|
24
|
+
async function aangenomenViaTerugkoppeling(sb, orderId, userId) {
|
|
25
|
+
const { aangenomenUitTerugkoppelingVoorOrder } = await import("./terugkoppelingAangenomen.js");
|
|
26
|
+
const r = await aangenomenUitTerugkoppelingVoorOrder(sb, (body) => post("corrections-read", body), orderId, userId);
|
|
27
|
+
if (!r.ok)
|
|
28
|
+
return { gevonden: false, melding: r.melding };
|
|
29
|
+
if (r.vastlegging.stand === "fout")
|
|
30
|
+
return { gevonden: false, melding: r.vastlegging.melding };
|
|
31
|
+
return { gevonden: r.vastlegging.stand === "vastgelegd" || r.vastlegging.stand === "al_vastgelegd" };
|
|
32
|
+
}
|
|
33
|
+
async function levering(sb, orderId, userId) {
|
|
34
|
+
const lev = await leveringUitDb(sb, orderId);
|
|
35
|
+
if (lev.ok || lev.code !== "niet_verstuurd")
|
|
36
|
+
return lev;
|
|
37
|
+
const t = await aangenomenViaTerugkoppeling(sb, orderId, userId);
|
|
38
|
+
if (t.gevonden)
|
|
39
|
+
return leveringUitDb(sb, orderId);
|
|
40
|
+
return t.melding ? { ...lev, reden: `${lev.reden ?? ""} ${t.melding}`.trim() } : lev;
|
|
41
|
+
}
|
|
42
|
+
async function bewaar(sb, correctieId, u) {
|
|
43
|
+
const { error } = await sb.rpc("afh_levering_correctie_floriday", {
|
|
44
|
+
p_correctie_id: correctieId,
|
|
45
|
+
p_uitkomst: { stand: u.stand, melding: u.melding, correctieId: u.correctieId, kanOpnieuw: u.kanOpnieuw },
|
|
46
|
+
});
|
|
47
|
+
if (error) {
|
|
48
|
+
console.error("[correcties] uitkomst niet bewaard", error.message);
|
|
49
|
+
throw new Error("De uitkomst van Floriday is niet opgeslagen; neem contact op met de beheerder.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function post(pad, body) {
|
|
53
|
+
const { correctieGatewayPost } = await import("./floridayCorrecties.server.js");
|
|
54
|
+
return correctieGatewayPost(pad, body);
|
|
55
|
+
}
|
|
56
|
+
/** Vastgelegde correctie naar Floriday sturen (of opnieuw proberen). */
|
|
57
|
+
export const floridayCorrectieVersturen = createServerFn({ method: "POST" })
|
|
58
|
+
.middleware([requireSupabaseAuth])
|
|
59
|
+
.inputValidator((i) => ({ correctieId: uuid(i?.correctieId, "De correctie") }))
|
|
60
|
+
.handler(async ({ data, context }) => {
|
|
61
|
+
const sb = context.supabase;
|
|
62
|
+
const opdracht = async () => {
|
|
63
|
+
const { data: d, error } = await sb.rpc("afh_floriday_correctie_opdracht", { p_correctie_id: data.correctieId });
|
|
64
|
+
if (error)
|
|
65
|
+
throw new Error(error.message);
|
|
66
|
+
return d;
|
|
67
|
+
};
|
|
68
|
+
let opd = await opdracht();
|
|
69
|
+
// Beslismoment 8: levering na akkoord door de koppeling verstuurd? Eerst vastleggen als aangenomen.
|
|
70
|
+
if (!opd?.ok && opd?.code === "niet_verstuurd") {
|
|
71
|
+
const { data: k, error: kErr } = await sb.from("afh_levering_correcties").select("order_id").eq("id", data.correctieId).maybeSingle();
|
|
72
|
+
if (kErr)
|
|
73
|
+
throw new Error(kErr.message);
|
|
74
|
+
if (k?.order_id) {
|
|
75
|
+
const t = await aangenomenViaTerugkoppeling(sb, k.order_id, context.userId ?? null);
|
|
76
|
+
if (t.gevonden)
|
|
77
|
+
opd = await opdracht();
|
|
78
|
+
else if (t.melding)
|
|
79
|
+
opd = { ...opd, reden: `${opd.reden ?? ""} ${t.melding}`.trim() };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!opd?.ok) {
|
|
83
|
+
const u = {
|
|
84
|
+
stand: "mislukt", melding: opd?.reden ?? "De correctie kon niet worden klaargezet voor Floriday.", correctieId: null,
|
|
85
|
+
kanOpnieuw: ["niet_verstuurd", "niet_in_kopie", "geen_omgeving"].includes(opd?.code),
|
|
86
|
+
};
|
|
87
|
+
await bewaar(sb, data.correctieId, u);
|
|
88
|
+
return { ok: false, stand: u.stand, melding: u.melding };
|
|
89
|
+
}
|
|
90
|
+
const body = opd.floridayCorrectieId
|
|
91
|
+
? { action: "fulfillment_correction_retry", environment: opd.environment, payload: { correctieId: opd.floridayCorrectieId } }
|
|
92
|
+
: { action: "fulfillment_correction", environment: opd.environment, payload: opd.payload };
|
|
93
|
+
let u;
|
|
94
|
+
try {
|
|
95
|
+
u = uitkomstVanGateway(await post("write", body));
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
console.error("[correcties] Floriday-koppeling niet bereikbaar", e);
|
|
99
|
+
u = { stand: "mislukt", melding: "De Floriday-koppeling is niet bereikbaar. Probeer het straks opnieuw.", correctieId: null, kanOpnieuw: true };
|
|
100
|
+
}
|
|
101
|
+
await bewaar(sb, data.correctieId, u);
|
|
102
|
+
return { ok: u.stand !== "mislukt" && u.stand !== "geweigerd", stand: u.stand, melding: u.melding };
|
|
103
|
+
});
|
|
104
|
+
/** Correcties van deze levering zoals de Floriday-koppeling ze kent (corrections-list). */
|
|
105
|
+
export const floridayCorrectiesLijst = createServerFn({ method: "POST" })
|
|
106
|
+
.middleware([requireSupabaseAuth])
|
|
107
|
+
.inputValidator((i) => ({ orderId: uuid(i?.orderId, "De order") }))
|
|
108
|
+
.handler(async ({ data, context }) => {
|
|
109
|
+
const sb = context.supabase;
|
|
110
|
+
const lev = await levering(sb, data.orderId, context.userId ?? null);
|
|
111
|
+
if (!lev.ok || !lev.fulfillmentOrderId)
|
|
112
|
+
return { ok: false, melding: lev.reden, items: [] };
|
|
113
|
+
const r = await post("corrections-read", { environment: lev.environment, op: "corrections-list", args: { p_fulfillment_order_id: lev.fulfillmentOrderId } });
|
|
114
|
+
if (!r.body?.ok) {
|
|
115
|
+
console.error("[correcties] corrections-list", r.httpStatus, r.body);
|
|
116
|
+
return { ok: false, melding: r.body?.error ?? "De correcties bij Floriday konden niet worden opgehaald. Probeer het opnieuw.", items: [] };
|
|
117
|
+
}
|
|
118
|
+
const items = (r.body.data?.items ?? []).map((x) => ({
|
|
119
|
+
id: String(x.id), soort: String(x.soort ?? ""), reden: x.reden ?? null, door: x.door ?? null,
|
|
120
|
+
status: x.status, floridayReden: x.floridayReden ?? null, pogingen: x.pogingen ?? null, aangemaakt: x.aangemaakt,
|
|
121
|
+
}));
|
|
122
|
+
// Eigen log bijwerken als Floriday intussen verder is (bijv. in behandeling → verwerkt of afgewezen).
|
|
123
|
+
const { data: eigen, error } = await sb.from("afh_levering_correcties").select("id, doorvoer").eq("order_id", data.orderId);
|
|
124
|
+
if (error)
|
|
125
|
+
console.error("[correcties] eigen log niet te lezen", error.message);
|
|
126
|
+
for (const k of eigen ?? []) {
|
|
127
|
+
const fid = k.doorvoer?.floriday_correctie_id;
|
|
128
|
+
const it = fid ? items.find((x) => x.id === fid) : undefined;
|
|
129
|
+
if (!it)
|
|
130
|
+
continue;
|
|
131
|
+
const stand = standVanKoppeling(it.status);
|
|
132
|
+
if (stand === k.doorvoer?.floriday)
|
|
133
|
+
continue;
|
|
134
|
+
try {
|
|
135
|
+
await bewaar(sb, k.id, { stand, melding: it.floridayReden ?? "", correctieId: fid, kanOpnieuw: stand === "mislukt" || stand === "geweigerd" });
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
// Alleen de maker, planner of beheerder mag de eigen log bijwerken; de lijst blijft wel zichtbaar.
|
|
139
|
+
console.error("[correcties] stand niet bijgewerkt", k.id, e);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { ok: true, fulfillmentOrderId: lev.fulfillmentOrderId, items };
|
|
143
|
+
});
|
|
144
|
+
/** Onze belading van deze order tegen de kopie van Floriday (order-equal). */
|
|
145
|
+
export const floridayOrderGelijk = createServerFn({ method: "POST" })
|
|
146
|
+
.middleware([requireSupabaseAuth])
|
|
147
|
+
.inputValidator((i) => ({ orderId: uuid(i?.orderId, "De order") }))
|
|
148
|
+
.handler(async ({ data, context }) => {
|
|
149
|
+
const sb = context.supabase;
|
|
150
|
+
const lev = await levering(sb, data.orderId, context.userId ?? null);
|
|
151
|
+
if (!lev.ok || !lev.fulfillmentOrderId)
|
|
152
|
+
return { ok: false, melding: lev.reden };
|
|
153
|
+
const { data: det, error } = await sb.rpc("afh_levering_detail", { p_order_id: data.orderId });
|
|
154
|
+
if (error)
|
|
155
|
+
throw new Error(error.message);
|
|
156
|
+
const onzeItems = new Map();
|
|
157
|
+
for (const k of (det?.karren ?? []))
|
|
158
|
+
for (const it of k.items ?? [])
|
|
159
|
+
onzeItems.set(`${k.cart_id}|${it.order_item_id}`, Number(it.fusten ?? 0));
|
|
160
|
+
const platen = new Map();
|
|
161
|
+
for (const c of (det?.correcties ?? []).slice().reverse())
|
|
162
|
+
if (c.soort === "platen" && c.cart_id)
|
|
163
|
+
platen.set(c.cart_id, Number(c.nieuw?.platen));
|
|
164
|
+
const onze = (lev.ladingdragers ?? []).map((ld) => {
|
|
165
|
+
// Regels van deze order uit onze planning (met correcties); regels van andere orders op dezelfde kar zoals Floriday ze kent.
|
|
166
|
+
const fusten = ld.items.reduce((n, it) => {
|
|
167
|
+
const eigen = it.orderId === data.orderId && ld.cartId ? onzeItems.get(`${ld.cartId}|${it.orderItemId}`) : undefined;
|
|
168
|
+
return n + (eigen ?? it.fusten);
|
|
169
|
+
}, 0);
|
|
170
|
+
return { documentReference: ld.documentReference, fusten, ...(ld.cartId && platen.has(ld.cartId) ? { platen: platen.get(ld.cartId) } : {}) };
|
|
171
|
+
});
|
|
172
|
+
const r = await post("corrections-read", {
|
|
173
|
+
environment: lev.environment, op: "order-equal", args: { p_fulfillment_order_id: lev.fulfillmentOrderId, p_onze_belading: onze },
|
|
174
|
+
});
|
|
175
|
+
if (!r.body?.ok) {
|
|
176
|
+
console.error("[correcties] order-equal", r.httpStatus, r.body);
|
|
177
|
+
return { ok: false, melding: r.body?.error ?? "Vergelijken met Floriday lukte niet. Probeer het opnieuw." };
|
|
178
|
+
}
|
|
179
|
+
const d = r.body.data ?? {};
|
|
180
|
+
if (d.ok === false)
|
|
181
|
+
return { ok: false, melding: d.reden ?? "Vergelijken met Floriday lukte niet." };
|
|
182
|
+
const tekst = (w) => (w == null ? null : String(w));
|
|
183
|
+
const verschillen = (d.verschillen ?? []).map((x) => ({
|
|
184
|
+
ladingdrager: typeof x?.ladingdrager === "number" ? x.ladingdrager : null, veld: String(x?.veld ?? ""),
|
|
185
|
+
onze: tekst(x?.onze), floriday: tekst(x?.floriday),
|
|
186
|
+
}));
|
|
187
|
+
return { ok: true, gelijk: d.gelijk ?? null, verschillen, floridayStand: d.floridayStand ?? null, melding: d.reden };
|
|
188
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronVak.test.d.ts","sourceRoot":"","sources":["../../src/lib/cronVak.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import pkg from "../../package.json";
|
|
3
|
+
const crons = (pkg.flowselections.crons) ?? [];
|
|
4
|
+
describe("cronvak Afhandeling (vak 4)", () => {
|
|
5
|
+
it("aanmeldmail-taak draait op 4-59/5", () => {
|
|
6
|
+
const c = crons.find((x) => x.name === "afhandeling-carrier-signups");
|
|
7
|
+
expect(c?.schedule).toBe("4-59/5 * * * *");
|
|
8
|
+
});
|
|
9
|
+
it("geen cron op :00, geen kale */5 en hooguit één per minuut", () => {
|
|
10
|
+
for (const c of crons) {
|
|
11
|
+
const min = c.schedule.split(" ")[0];
|
|
12
|
+
expect(min).not.toBe("0");
|
|
13
|
+
expect(min).not.toBe("*/5");
|
|
14
|
+
expect(min).not.toBe("*");
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -9,6 +9,18 @@ export interface DocumentKeuze {
|
|
|
9
9
|
export declare const AUTOMATISCH_DOCUMENT_TEKST = "Het document wordt automatisch bepaald uit de order.";
|
|
10
10
|
/** Zet het antwoord van de functie om; alles wat niet klopt telt als ok=false (fail closed). */
|
|
11
11
|
export declare function leesDocumentKeuze(raw: unknown, soort: string): DocumentKeuze;
|
|
12
|
+
/**
|
|
13
|
+
* Welke documentsoort Layouts (layout_voor_document) krijgt. Verzenddocument eigen order = afleverbrief
|
|
14
|
+
* (zoals bij goedkeuren); Floriday-order = null: daar komt de verzendbrief van Floriday, geen layout.
|
|
15
|
+
*/
|
|
16
|
+
export declare function layoutsDocumentSoort(soort: DocumentSoort, isFloriday: boolean): string | null;
|
|
17
|
+
/** Floriday-order, verzenddocument: de Floriday-verzendbrief (PDF), zonder layout. */
|
|
18
|
+
export declare const FLORIDAY_VERZENDBRIEF: DocumentKeuze;
|
|
19
|
+
/** Floriday-order herkennen op het Floriday-id (of een Floriday-bron), nooit op het ordernummer. */
|
|
20
|
+
export declare function isFloridayOrder(o: {
|
|
21
|
+
floriday_sales_order_id?: unknown;
|
|
22
|
+
order_source?: unknown;
|
|
23
|
+
} | null | undefined): boolean;
|
|
12
24
|
export type VerzendActie = {
|
|
13
25
|
soort: "overslaan";
|
|
14
26
|
reden: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentKeuze.d.ts","sourceRoot":"","sources":["../../src/lib/documentKeuze.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,aAAa,G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tB;AAED,eAAO,MAAM,0BAA0B,yDAAyD,CAAC;AAEjG,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAc5E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAG7F;AAED,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,EAAE,aAAyG,CAAC;AAE9I,oGAAoG;AACpG,wBAAgB,eAAe,CAAC,CAAC,EAAE;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAI5H;AAED,MAAM,MAAM,YAAY,GACpB;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,KAAK,EAAE,cAAc,CAAA;CAAE,GACzB;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,+GAA+G;AAC/G,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,aAAa,GAAG,YAAY,CAI/D"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { type DocumentKeuze } from "./documentKeuze.js";
|
|
2
|
-
/**
|
|
1
|
+
import { type DocumentKeuze, type DocumentSoort } from "./documentKeuze.js";
|
|
2
|
+
/**
|
|
3
|
+
* Dagdetails: welke layout bij deze order hoort, via Layouts (layout_voor_document), net als bij goedkeuren.
|
|
4
|
+
* Verzenddocument: Floriday-order = Floriday-verzendbrief (geen layout), eigen order = afleverbrief-layout.
|
|
5
|
+
*/
|
|
3
6
|
export declare const getDocumentVoorOrder: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
4
7
|
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
5
8
|
userId: string;
|
|
@@ -9,6 +12,6 @@ export declare const getDocumentVoorOrder: import("@tanstack/start-client-core")
|
|
|
9
12
|
documenttype: string;
|
|
10
13
|
}) => {
|
|
11
14
|
orderId: string;
|
|
12
|
-
documenttype:
|
|
15
|
+
documenttype: DocumentSoort;
|
|
13
16
|
}, Promise<DocumentKeuze>>;
|
|
14
17
|
//# sourceMappingURL=documentKeuze.functions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentKeuze.functions.d.ts","sourceRoot":"","sources":["../../src/lib/documentKeuze.functions.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"documentKeuze.functions.d.ts","sourceRoot":"","sources":["../../src/lib/documentKeuze.functions.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AAczB;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;0CAEX;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE;;kBAEgB,aAAa;0BAyBxF,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createServerFn } from "@tanstack/react-start";
|
|
2
2
|
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
3
|
-
import { leesDocumentKeuze } from "./documentKeuze.js";
|
|
3
|
+
import { FLORIDAY_VERZENDBRIEF, isFloridayOrder, layoutsDocumentSoort, leesDocumentKeuze, } from "./documentKeuze.js";
|
|
4
4
|
const SOORTEN = ["pakbon", "productiebon", "verzenddocument", "sticker", "traysticker", "eigen_sticker"];
|
|
5
5
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Dagdetails: welke layout bij deze order hoort, via Layouts (layout_voor_document), net als bij goedkeuren.
|
|
8
|
+
* Verzenddocument: Floriday-order = Floriday-verzendbrief (geen layout), eigen order = afleverbrief-layout.
|
|
9
|
+
*/
|
|
7
10
|
export const getDocumentVoorOrder = createServerFn({ method: "POST" })
|
|
8
11
|
.middleware([requireSupabaseAuth])
|
|
9
12
|
.inputValidator((d) => {
|
|
@@ -16,12 +19,23 @@ export const getDocumentVoorOrder = createServerFn({ method: "POST" })
|
|
|
16
19
|
return leesDocumentKeuze({ ok: false, reden: "De order is niet gevonden; het document kan niet worden bepaald." }, data.documenttype);
|
|
17
20
|
}
|
|
18
21
|
const sb = context.supabase;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
let isFloriday = false;
|
|
23
|
+
if (data.documenttype === "verzenddocument") {
|
|
24
|
+
const { data: o, error } = await sb.from("orders").select("id, floriday_sales_order_id, order_source").eq("id", data.orderId).maybeSingle();
|
|
25
|
+
if (error) {
|
|
26
|
+
console.warn("[documentkeuze] order", error.message);
|
|
27
|
+
return leesDocumentKeuze({ ok: false, reden: "Het document kon niet worden bepaald. Probeer het zo opnieuw." }, data.documenttype);
|
|
28
|
+
}
|
|
29
|
+
if (!o)
|
|
30
|
+
return leesDocumentKeuze({ ok: false, reden: "De order is niet gevonden; het document kan niet worden bepaald." }, data.documenttype);
|
|
31
|
+
isFloriday = isFloridayOrder(o);
|
|
32
|
+
}
|
|
33
|
+
const soort = layoutsDocumentSoort(data.documenttype, isFloriday);
|
|
34
|
+
if (soort === null)
|
|
35
|
+
return FLORIDAY_VERZENDBRIEF;
|
|
36
|
+
const { data: res, error } = await sb.rpc("layout_voor_document", { p_order_id: data.orderId, p_documenttype: soort });
|
|
23
37
|
if (error) {
|
|
24
|
-
console.warn("[documentkeuze]", error.message);
|
|
38
|
+
console.warn("[documentkeuze] layout_voor_document", error.message);
|
|
25
39
|
return leesDocumentKeuze({ ok: false, reden: "Het document kon niet worden bepaald. Probeer het zo opnieuw." }, data.documenttype);
|
|
26
40
|
}
|
|
27
41
|
return leesDocumentKeuze(res, data.documenttype);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Gedeelde, browser-veilige logica rond de
|
|
2
|
-
// (
|
|
1
|
+
// Gedeelde, browser-veilige logica rond de documentkeuze in Dagdetails.
|
|
2
|
+
// De layout komt van Layouts (layout_voor_document), net als bij goedkeuren. Geen eigen layoutkeuze.
|
|
3
3
|
export const AUTOMATISCH_DOCUMENT_TEKST = "Het document wordt automatisch bepaald uit de order.";
|
|
4
4
|
/** Zet het antwoord van de functie om; alles wat niet klopt telt als ok=false (fail closed). */
|
|
5
5
|
export function leesDocumentKeuze(raw, soort) {
|
|
@@ -18,11 +18,30 @@ export function leesDocumentKeuze(raw, soort) {
|
|
|
18
18
|
reden: ok ? null : reden ?? `Het document (${soort}) kan niet worden bepaald.`,
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Welke documentsoort Layouts (layout_voor_document) krijgt. Verzenddocument eigen order = afleverbrief
|
|
23
|
+
* (zoals bij goedkeuren); Floriday-order = null: daar komt de verzendbrief van Floriday, geen layout.
|
|
24
|
+
*/
|
|
25
|
+
export function layoutsDocumentSoort(soort, isFloriday) {
|
|
26
|
+
if (soort === "verzenddocument")
|
|
27
|
+
return isFloriday ? null : "afleverbrief";
|
|
28
|
+
return soort;
|
|
29
|
+
}
|
|
30
|
+
/** Floriday-order, verzenddocument: de Floriday-verzendbrief (PDF), zonder layout. */
|
|
31
|
+
export const FLORIDAY_VERZENDBRIEF = { ok: true, layoutId: null, bron: "floriday", documenttype: "afleverbrief", reden: null };
|
|
32
|
+
/** Floriday-order herkennen op het Floriday-id (of een Floriday-bron), nooit op het ordernummer. */
|
|
33
|
+
export function isFloridayOrder(o) {
|
|
34
|
+
if (!o)
|
|
35
|
+
return false;
|
|
36
|
+
if (typeof o.floriday_sales_order_id === "string" && o.floriday_sales_order_id.trim())
|
|
37
|
+
return true;
|
|
38
|
+
return typeof o.order_source === "string" && o.order_source.toLowerCase().includes("floriday");
|
|
39
|
+
}
|
|
21
40
|
/** Precies één verzenddocument per order: Floriday-order = Floriday-PDF, eigen order = afleverbrief-layout. */
|
|
22
41
|
export function kiesVerzendActie(k) {
|
|
42
|
+
if (k.ok && k.bron === "floriday")
|
|
43
|
+
return { soort: "floriday_pdf" };
|
|
23
44
|
if (!k.ok || !k.layoutId)
|
|
24
45
|
return { soort: "overslaan", reden: k.reden ?? "Het verzenddocument kan niet worden bepaald." };
|
|
25
|
-
if (k.bron === "floriday")
|
|
26
|
-
return { soort: "floriday_pdf" };
|
|
27
46
|
return { soort: "layout", layoutId: k.layoutId, documenttype: k.documenttype ?? "afleverbrief" };
|
|
28
47
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { kiesVerzendActie, leesDocumentKeuze } from "./documentKeuze.js";
|
|
2
|
+
import { FLORIDAY_VERZENDBRIEF, isFloridayOrder, kiesVerzendActie, layoutsDocumentSoort, leesDocumentKeuze } from "./documentKeuze.js";
|
|
3
3
|
describe("automatische documentkeuze", () => {
|
|
4
4
|
it("ok=false: niet printen, reden doorgeven", () => {
|
|
5
5
|
const k = leesDocumentKeuze({ ok: false, layout_id: null, reden: "Maak een layout" }, "pakbon");
|
|
@@ -21,3 +21,24 @@ describe("automatische documentkeuze", () => {
|
|
|
21
21
|
expect(leesDocumentKeuze(null, "pakbon").ok).toBe(false);
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
|
+
describe("Dagdetails kiest via Layouts (layout_voor_document)", () => {
|
|
25
|
+
it("verzenddocument eigen order = afleverbrief", () => {
|
|
26
|
+
expect(layoutsDocumentSoort("verzenddocument", false)).toBe("afleverbrief");
|
|
27
|
+
});
|
|
28
|
+
it("verzenddocument Floriday-order = geen layout, Floriday-verzendbrief", () => {
|
|
29
|
+
expect(layoutsDocumentSoort("verzenddocument", true)).toBeNull();
|
|
30
|
+
expect(kiesVerzendActie(FLORIDAY_VERZENDBRIEF)).toEqual({ soort: "floriday_pdf" });
|
|
31
|
+
});
|
|
32
|
+
it("pakbon blijft pakbon, ook bij een Floriday-order", () => {
|
|
33
|
+
expect(layoutsDocumentSoort("pakbon", true)).toBe("pakbon");
|
|
34
|
+
});
|
|
35
|
+
it("Floriday-order herkennen op het Floriday-id, niet op leeg", () => {
|
|
36
|
+
expect(isFloridayOrder({ floriday_sales_order_id: "abc", order_source: "manual" })).toBe(true);
|
|
37
|
+
expect(isFloridayOrder({ floriday_sales_order_id: null, order_source: "manual" })).toBe(false);
|
|
38
|
+
expect(isFloridayOrder({ floriday_sales_order_id: " ", order_source: null })).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
it("Layouts zegt nee = niet printen met de reden van Layouts", () => {
|
|
41
|
+
const k = leesDocumentKeuze({ ok: false, layout_id: null, bron: "eigen", reden: "Maak of activeer een afleverbrieflayout" }, "verzenddocument");
|
|
42
|
+
expect(kiesVerzendActie(k)).toEqual({ soort: "overslaan", reden: "Maak of activeer een afleverbrieflayout" });
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floriday.functions.d.ts","sourceRoot":"","sources":["../../src/lib/floriday.functions.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,G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IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACpC,gFAAgF;IAChF,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AA4CD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB;;;;8CAEJ,sBAAsB,GAAG,SAAS,8DAgMxD,CAAC;AAEL,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,+CAA+C;IAC/C,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAGD;;;;;GAKG;AACH,eAAO,MAAM,eAAe;;;;;YAEsB,aAAa,EAAE;YAAU,MAAM;GAqB7E,CAAC"}
|
|
@@ -91,30 +91,6 @@ export const getFloridayOrders = createServerFn({ method: "GET" })
|
|
|
91
91
|
return typeof id === "string" && id ? id : null;
|
|
92
92
|
})
|
|
93
93
|
.filter((v) => !!v)));
|
|
94
|
-
const customerCountryById = new Map();
|
|
95
|
-
if (customerIds.length > 0) {
|
|
96
|
-
const { data: customers } = await supabase
|
|
97
|
-
.from("customers")
|
|
98
|
-
.select("id, country")
|
|
99
|
-
.in("id", customerIds);
|
|
100
|
-
for (const c of customers ?? []) {
|
|
101
|
-
customerCountryById.set(c.id, c.country ?? null);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const deliveryLocationById = new Map();
|
|
105
|
-
if (deliveryLocationIds.length > 0) {
|
|
106
|
-
const { data: locations } = await supabase
|
|
107
|
-
.from("customer_delivery_locations")
|
|
108
|
-
.select("id, country, province, city")
|
|
109
|
-
.in("id", deliveryLocationIds);
|
|
110
|
-
for (const loc of locations ?? []) {
|
|
111
|
-
deliveryLocationById.set(loc.id, {
|
|
112
|
-
country: loc.country ?? null,
|
|
113
|
-
province: loc.province ?? null,
|
|
114
|
-
city: loc.city ?? null,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
94
|
// Floriday sales-order-id's van de orders die de Verkoop-module kent.
|
|
119
95
|
const salesOrderIdByOrderId = new Map();
|
|
120
96
|
for (const row of rows) {
|
|
@@ -123,25 +99,47 @@ export const getFloridayOrders = createServerFn({ method: "GET" })
|
|
|
123
99
|
if (typeof fid === "string" && fid)
|
|
124
100
|
salesOrderIdByOrderId.set(row.id, fid);
|
|
125
101
|
}
|
|
126
|
-
// Stickers alleen opzoeken voor die bekende Floriday-orders.
|
|
127
|
-
const stickerOrderIds = new Set();
|
|
128
102
|
const salesOrderIds = Array.from(new Set(salesOrderIdByOrderId.values()));
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
.select("
|
|
133
|
-
.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
103
|
+
// Land, afleveradres en stickers tegelijk opzoeken (niet na elkaar), zodat de planning snel laadt.
|
|
104
|
+
const [customersRes, locationsRes, stickersRes] = await Promise.all([
|
|
105
|
+
customerIds.length > 0
|
|
106
|
+
? supabase.from("customers").select("id, country").in("id", customerIds)
|
|
107
|
+
: Promise.resolve({ data: [], error: null }),
|
|
108
|
+
deliveryLocationIds.length > 0
|
|
109
|
+
? supabase.from("customer_delivery_locations").select("id, country, province, city").in("id", deliveryLocationIds)
|
|
110
|
+
: Promise.resolve({ data: [], error: null }),
|
|
111
|
+
salesOrderIds.length > 0
|
|
112
|
+
? supabase.from("floriday_customer_stickers_cache").select("sales_order_id, quantity, is_deleted")
|
|
113
|
+
.in("sales_order_id", salesOrderIds).eq("is_deleted", false)
|
|
114
|
+
: Promise.resolve({ data: [], error: null }),
|
|
115
|
+
]);
|
|
116
|
+
const customerCountryById = new Map();
|
|
117
|
+
if (customersRes.error)
|
|
118
|
+
console.warn("[planning-orders] customer lookup failed", { message: customersRes.error.message });
|
|
119
|
+
for (const c of (customersRes.data ?? [])) {
|
|
120
|
+
customerCountryById.set(c.id, c.country ?? null);
|
|
121
|
+
}
|
|
122
|
+
const deliveryLocationById = new Map();
|
|
123
|
+
if (locationsRes.error)
|
|
124
|
+
console.warn("[planning-orders] delivery location lookup failed", { message: locationsRes.error.message });
|
|
125
|
+
for (const loc of (locationsRes.data ?? [])) {
|
|
126
|
+
deliveryLocationById.set(loc.id, {
|
|
127
|
+
country: loc.country ?? null,
|
|
128
|
+
province: loc.province ?? null,
|
|
129
|
+
city: loc.city ?? null,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
// Stickers alleen voor de bekende Floriday-orders.
|
|
133
|
+
const stickerOrderIds = new Set();
|
|
134
|
+
if (stickersRes.error) {
|
|
135
|
+
console.warn("[planning-orders] sticker lookup failed", { message: stickersRes.error.message });
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
for (const st of (stickersRes.data ?? [])) {
|
|
139
|
+
const soId = st.sales_order_id ?? null;
|
|
140
|
+
const qty = Number(st.quantity ?? 1);
|
|
141
|
+
if (soId && (!Number.isFinite(qty) || qty > 0))
|
|
142
|
+
stickerOrderIds.add(soId);
|
|
145
143
|
}
|
|
146
144
|
}
|
|
147
145
|
const orders = rows.map((row) => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface GatewayAntwoord {
|
|
2
|
+
httpStatus: number;
|
|
3
|
+
body: any;
|
|
4
|
+
}
|
|
5
|
+
export type FloridayStand = "verstuurd" | "in_behandeling" | "geslaagd" | "mislukt" | "geweigerd";
|
|
6
|
+
export interface CorrectieUitkomst {
|
|
7
|
+
stand: FloridayStand;
|
|
8
|
+
melding: string;
|
|
9
|
+
/** Id van de correctie bij de Floriday-koppeling (voor "opnieuw proberen"). */
|
|
10
|
+
correctieId: string | null;
|
|
11
|
+
kanOpnieuw: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Status in de correctietabel van de Floriday-koppeling → onze stand. */
|
|
14
|
+
export declare function standVanKoppeling(status: unknown): FloridayStand;
|
|
15
|
+
export declare const STAND_TEKST: Record<FloridayStand, string>;
|
|
16
|
+
export declare function uitkomstVanGateway(r: GatewayAntwoord): CorrectieUitkomst;
|
|
17
|
+
//# sourceMappingURL=floridayCorrectie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"floridayCorrectie.d.ts","sourceRoot":"","sources":["../../src/lib/floridayCorrectie.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC;CACX;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAAC;AAElG,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;CACrB;AAKD,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,CAQhE;AAED,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAMrD,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,eAAe,GAAG,iBAAiB,CA6BxE"}
|