@flowselections/logistiek-engine 1.0.133 → 1.0.137
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/MinuutrondeCard.d.ts.map +1 -1
- package/dist-lib/components/MinuutrondeCard.js +1 -1
- package/dist-lib/components/OrderLogboek.d.ts.map +1 -1
- package/dist-lib/components/OrderLogboek.js +1 -1
- package/dist-lib/hooks/useLogisticsTrace.d.ts +2 -0
- package/dist-lib/hooks/useLogisticsTrace.d.ts.map +1 -1
- package/dist-lib/hooks/useLogisticsTrace.js +1 -0
- package/dist-lib/hooks/useMinuutronde.d.ts +2 -0
- package/dist-lib/hooks/useMinuutronde.d.ts.map +1 -1
- package/dist-lib/hooks/useMinuutronde.js +1 -0
- package/dist-lib/integrations/supabase/types.d.ts +75 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/controlScan.server.d.ts.map +1 -1
- package/dist-lib/lib/controlScan.server.js +21 -4
- package/dist-lib/lib/layoutPrint.server.d.ts +31 -0
- package/dist-lib/lib/layoutPrint.server.d.ts.map +1 -1
- package/dist-lib/lib/layoutPrint.server.js +120 -1
- package/dist-lib/lib/moduleVersion.d.ts +1 -1
- package/dist-lib/lib/moduleVersion.js +1 -1
- package/dist-lib/lib/shippingNoteQueue.server.d.ts.map +1 -1
- package/dist-lib/lib/shippingNoteQueue.server.js +33 -7
- package/dist-lib/lib/shippingNoteStates.d.ts +1 -1
- package/dist-lib/lib/shippingNoteStates.d.ts.map +1 -1
- package/dist-lib/lib/shippingNoteStates.js +1 -1
- package/dist-lib/lib/stopReden.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controlScan.server.d.ts","sourceRoot":"","sources":["../../src/lib/controlScan.server.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAK5D,MAAM,WAAW,cAAc;I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,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAC1F,GAAG,GAAE,MAAmB,GACvB,UAAU,GAAG,MAAM,GAAG,IAAI,CAK5B;AA6BD,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,cAAc,EAClB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/B,OAAO,CAAC,cAAc,CAAC,CAwPzB"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// en dubbele scans worden al in de database geblokkeerd. Geen omgevings- of
|
|
15
15
|
// klantwaarden in deze code; de printer komt uit de werkwijze in de database.
|
|
16
16
|
// ============================================================================
|
|
17
|
-
import {
|
|
17
|
+
import { printViaLayoutGecontroleerd, floridayLayout } from "./layoutPrint.server.js";
|
|
18
18
|
import { isFloridayCancelled, FLORIDAY_CANCELLED_REASON } from "./floridayCancellation.server.js";
|
|
19
19
|
import { trace } from "./trace.server.js";
|
|
20
20
|
/** Maximaal aantal wachtrondes op Floriday voordat de controle als mislukt stopt. */
|
|
@@ -84,7 +84,7 @@ export async function runControlScanQueue(sb, options = {}) {
|
|
|
84
84
|
for (const row of rows) {
|
|
85
85
|
try {
|
|
86
86
|
if (!row.is_floriday) {
|
|
87
|
-
await sb.rpc("logistics_control_scan_finish", { _id: row.id, _ok: true, _status: "
|
|
87
|
+
await sb.rpc("logistics_control_scan_finish", { _id: row.id, _ok: true, _status: "in_printwachtrij" });
|
|
88
88
|
run.printed++;
|
|
89
89
|
continue;
|
|
90
90
|
}
|
|
@@ -224,9 +224,24 @@ export async function runControlScanQueue(sb, options = {}) {
|
|
|
224
224
|
run.failed++;
|
|
225
225
|
continue;
|
|
226
226
|
}
|
|
227
|
+
// Layout op id: de actieve Floriday-afleverbrief (bij meerdere de standaard).
|
|
228
|
+
const layout = await floridayLayout(sb, "afleverbrief");
|
|
229
|
+
if (!layout.layoutId) {
|
|
230
|
+
await sb.rpc("logistics_control_scan_finish", {
|
|
231
|
+
_id: row.id,
|
|
232
|
+
_ok: false,
|
|
233
|
+
_status: "mislukt",
|
|
234
|
+
_fulfillment_order_id: fulfillmentOrderId,
|
|
235
|
+
_error_code: "geen_floriday_layout",
|
|
236
|
+
_error: `${layout.reden} Druk daarna op "Opnieuw proberen".`,
|
|
237
|
+
});
|
|
238
|
+
run.failed++;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
227
241
|
// Via de Layout maker; idempotent per controle.
|
|
228
|
-
const printed = await
|
|
242
|
+
const printed = await printViaLayoutGecontroleerd(sb, {
|
|
229
243
|
documenttype: "afleverbrief",
|
|
244
|
+
layoutId: layout.layoutId,
|
|
230
245
|
documentnaam: `Afleverbrief ${row.order_number}`,
|
|
231
246
|
pdfBase64: base64,
|
|
232
247
|
pdfUrl: url,
|
|
@@ -235,6 +250,8 @@ export async function runControlScanQueue(sb, options = {}) {
|
|
|
235
250
|
idempotentieSleutel: `controle-scan:${row.id}`,
|
|
236
251
|
payload: {
|
|
237
252
|
source: "controle_scan",
|
|
253
|
+
documenttype: "afleverbrief",
|
|
254
|
+
layout_id: layout.layoutId,
|
|
238
255
|
is_floriday: true,
|
|
239
256
|
order_id: row.order_id,
|
|
240
257
|
ordernummer: row.order_number,
|
|
@@ -260,7 +277,7 @@ export async function runControlScanQueue(sb, options = {}) {
|
|
|
260
277
|
await sb.rpc("logistics_control_scan_finish", {
|
|
261
278
|
_id: row.id,
|
|
262
279
|
_ok: true,
|
|
263
|
-
_status: "
|
|
280
|
+
_status: "in_printwachtrij",
|
|
264
281
|
_print_job_id: jobId,
|
|
265
282
|
_document_url: url,
|
|
266
283
|
_fulfillment_order_id: fulfillmentOrderId,
|
|
@@ -21,7 +21,38 @@ export type LayoutPrintResult = {
|
|
|
21
21
|
ok: false;
|
|
22
22
|
errorCode: string;
|
|
23
23
|
error: string;
|
|
24
|
+
bestaandJobId?: string | null;
|
|
24
25
|
};
|
|
26
|
+
/** Haalt het bestaande opdracht-id uit een DUBBEL_ORIGINEEL-antwoord (details, hint of tekst). */
|
|
27
|
+
export declare function bestaandOpdrachtId(...bronnen: unknown[]): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Zoekt de actieve Floriday-layout voor een documentsoort op id (bij meerdere:
|
|
30
|
+
* de standaard). Geeft null + leesbare reden als er geen eenduidige layout is.
|
|
31
|
+
*/
|
|
32
|
+
export declare function floridayLayout(sb: SupabaseClient, documenttype: string): Promise<{
|
|
33
|
+
layoutId: string | null;
|
|
34
|
+
reden: string | null;
|
|
35
|
+
}>;
|
|
25
36
|
export declare function foutcode(message: string): string;
|
|
26
37
|
export declare function printViaLayout(sb: SupabaseClient, input: LayoutPrintInput): Promise<LayoutPrintResult>;
|
|
38
|
+
export type GecontroleerdResult = {
|
|
39
|
+
ok: true;
|
|
40
|
+
jobId: string;
|
|
41
|
+
printerId: string | null;
|
|
42
|
+
bestaand: boolean;
|
|
43
|
+
vervangtJobId?: string;
|
|
44
|
+
} | {
|
|
45
|
+
ok: false;
|
|
46
|
+
errorCode: string;
|
|
47
|
+
error: string;
|
|
48
|
+
};
|
|
49
|
+
/** Leest de status van één printopdracht op id (null = niet te lezen). */
|
|
50
|
+
export declare function printJobStatus(sb: SupabaseClient, jobId: string): Promise<string | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Zoals printViaLayout, maar een teruggegeven bestaande opdracht (bestaand of
|
|
53
|
+
* DUBBEL_ORIGINEEL) telt alleen als klaar als die nog wachtend/bezig/voltooid
|
|
54
|
+
* is. Mislukt, verlopen of geannuleerd: één nieuwe opdracht met een nieuwe
|
|
55
|
+
* sleutel. Status niet leesbaar: fail closed (STATUS_ONBEKEND).
|
|
56
|
+
*/
|
|
57
|
+
export declare function printViaLayoutGecontroleerd(sb: SupabaseClient, input: LayoutPrintInput, diepte?: number): Promise<GecontroleerdResult>;
|
|
27
58
|
//# sourceMappingURL=layoutPrint.server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layoutPrint.server.d.ts","sourceRoot":"","sources":["../../src/lib/layoutPrint.server.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oHAAoH;IACpH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,iBAAiB,GACzB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACxE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"layoutPrint.server.d.ts","sourceRoot":"","sources":["../../src/lib/layoutPrint.server.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,EAAE,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AC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAChG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,0EAA0E;AAC1E,wBAAsB,cAAc,CAAC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAI9F;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,EAAE,EAAE,cAAc,EAClB,KAAK,EAAE,gBAAgB,EACvB,MAAM,SAAI,GACT,OAAO,CAAC,mBAAmB,CAAC,CAqC9B"}
|
|
@@ -6,6 +6,51 @@
|
|
|
6
6
|
// standaardregels). Fouten (GEEN_PRINTER, GEEN_LAYOUT, GEEN_EXTERN_DOCUMENT)
|
|
7
7
|
// komen als leesbare fout terug; er is geen stille terugval.
|
|
8
8
|
// ============================================================================
|
|
9
|
+
const UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
|
|
10
|
+
/** Haalt het bestaande opdracht-id uit een DUBBEL_ORIGINEEL-antwoord (details, hint of tekst). */
|
|
11
|
+
export function bestaandOpdrachtId(...bronnen) {
|
|
12
|
+
for (const b of bronnen) {
|
|
13
|
+
if (!b)
|
|
14
|
+
continue;
|
|
15
|
+
if (typeof b === "object") {
|
|
16
|
+
const o = b;
|
|
17
|
+
for (const k of ["bestaande_job_id", "bestaand_job_id", "job_id", "opdracht_id", "existing_job_id"]) {
|
|
18
|
+
const v = o[k];
|
|
19
|
+
if (typeof v === "string" && UUID_RE.test(v))
|
|
20
|
+
return v.match(UUID_RE)[0];
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const t = String(b);
|
|
25
|
+
try {
|
|
26
|
+
const j = JSON.parse(t);
|
|
27
|
+
const id = bestaandOpdrachtId(j);
|
|
28
|
+
if (id)
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
/* geen JSON */
|
|
33
|
+
}
|
|
34
|
+
const m = t.match(UUID_RE);
|
|
35
|
+
if (m)
|
|
36
|
+
return m[0];
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Zoekt de actieve Floriday-layout voor een documentsoort op id (bij meerdere:
|
|
42
|
+
* de standaard). Geeft null + leesbare reden als er geen eenduidige layout is.
|
|
43
|
+
*/
|
|
44
|
+
export async function floridayLayout(sb, documenttype) {
|
|
45
|
+
const { data, error } = await sb.rpc("logistics_floriday_layout_id", {
|
|
46
|
+
p_documenttype: documenttype,
|
|
47
|
+
});
|
|
48
|
+
if (error)
|
|
49
|
+
return { layoutId: null, reden: `De Floriday-layout kon niet worden opgezocht: ${error.message}` };
|
|
50
|
+
const r = (data ?? {});
|
|
51
|
+
const id = typeof r["layout_id"] === "string" ? r["layout_id"] : null;
|
|
52
|
+
return { layoutId: id, reden: id ? null : String(r["reden"] ?? "Geen actieve Floriday-layout gevonden.") };
|
|
53
|
+
}
|
|
9
54
|
const HINT = ' Los dit op bij Layouts en printers en druk daarna op "Opnieuw proberen"; opnieuw scannen is niet nodig.';
|
|
10
55
|
export function foutcode(message) {
|
|
11
56
|
const m = /^([A-Z_]+):/.exec(message.trim());
|
|
@@ -27,10 +72,29 @@ export async function printViaLayout(sb, input) {
|
|
|
27
72
|
_idempotentie_sleutel: input.idempotentieSleutel,
|
|
28
73
|
});
|
|
29
74
|
if (error) {
|
|
30
|
-
|
|
75
|
+
const code = foutcode(error.message);
|
|
76
|
+
if (code === "DUBBEL_ORIGINEEL") {
|
|
77
|
+
const e = error;
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
errorCode: code,
|
|
81
|
+
error: error.message,
|
|
82
|
+
bestaandJobId: bestaandOpdrachtId(e["details"], e["hint"], error.message),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return { ok: false, errorCode: code, error: `${error.message}${HINT}` };
|
|
31
86
|
}
|
|
32
87
|
const rows = Array.isArray(data) ? data : data ? [data] : [];
|
|
33
88
|
const row = (rows[0] ?? null);
|
|
89
|
+
const rowCode = String(row?.["foutcode"] ?? row?.["code"] ?? row?.["status"] ?? "");
|
|
90
|
+
if (rowCode === "DUBBEL_ORIGINEEL") {
|
|
91
|
+
return {
|
|
92
|
+
ok: false,
|
|
93
|
+
errorCode: "DUBBEL_ORIGINEEL",
|
|
94
|
+
error: "Er staat al een origineel klaar voor deze kar en documentsoort.",
|
|
95
|
+
bestaandJobId: bestaandOpdrachtId(row),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
34
98
|
const jobId = row ? String(row["job_id"] ?? "") : "";
|
|
35
99
|
if (!jobId) {
|
|
36
100
|
return {
|
|
@@ -46,3 +110,58 @@ export async function printViaLayout(sb, input) {
|
|
|
46
110
|
bestaand: Boolean(row?.["bestaand"]),
|
|
47
111
|
};
|
|
48
112
|
}
|
|
113
|
+
/** Statussen in de Printwachtrij die als "staat al klaar" tellen. */
|
|
114
|
+
const ACTIEF = new Set(["wachtend", "bezig", "voltooid"]);
|
|
115
|
+
/** Statussen die nooit als klaar tellen: er komt een nieuwe opdracht. */
|
|
116
|
+
const AFGEVALLEN = new Set(["mislukt", "verlopen", "geannuleerd"]);
|
|
117
|
+
/** Leest de status van één printopdracht op id (null = niet te lezen). */
|
|
118
|
+
export async function printJobStatus(sb, jobId) {
|
|
119
|
+
const { data, error } = await sb.rpc("logistics_print_job_state", { p_job_id: jobId });
|
|
120
|
+
if (error || typeof data !== "string" || !data)
|
|
121
|
+
return null;
|
|
122
|
+
return data;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Zoals printViaLayout, maar een teruggegeven bestaande opdracht (bestaand of
|
|
126
|
+
* DUBBEL_ORIGINEEL) telt alleen als klaar als die nog wachtend/bezig/voltooid
|
|
127
|
+
* is. Mislukt, verlopen of geannuleerd: één nieuwe opdracht met een nieuwe
|
|
128
|
+
* sleutel. Status niet leesbaar: fail closed (STATUS_ONBEKEND).
|
|
129
|
+
*/
|
|
130
|
+
export async function printViaLayoutGecontroleerd(sb, input, diepte = 0) {
|
|
131
|
+
const r = await printViaLayout(sb, input);
|
|
132
|
+
let bestaandId = null;
|
|
133
|
+
if (r.ok && r.bestaand)
|
|
134
|
+
bestaandId = r.jobId;
|
|
135
|
+
else if (!r.ok && r.errorCode === "DUBBEL_ORIGINEEL") {
|
|
136
|
+
if (!r.bestaandJobId) {
|
|
137
|
+
return {
|
|
138
|
+
ok: false,
|
|
139
|
+
errorCode: "STATUS_ONBEKEND",
|
|
140
|
+
error: "Layouts en printers meldt dat er al een origineel klaarstaat, maar gaf geen opdracht-id terug; status niet te controleren.",
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
bestaandId = r.bestaandJobId;
|
|
144
|
+
}
|
|
145
|
+
else if (r.ok)
|
|
146
|
+
return r;
|
|
147
|
+
else
|
|
148
|
+
return { ok: false, errorCode: r.errorCode, error: r.error };
|
|
149
|
+
const status = await printJobStatus(sb, bestaandId);
|
|
150
|
+
if (status && ACTIEF.has(status)) {
|
|
151
|
+
return { ok: true, jobId: bestaandId, printerId: r.ok ? r.printerId : null, bestaand: true };
|
|
152
|
+
}
|
|
153
|
+
if (!status || !AFGEVALLEN.has(status)) {
|
|
154
|
+
return {
|
|
155
|
+
ok: false,
|
|
156
|
+
errorCode: "STATUS_ONBEKEND",
|
|
157
|
+
error: `De status van bestaande printopdracht ${bestaandId} is niet te lezen (${status ?? "geen"}).`,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (diepte >= 3) {
|
|
161
|
+
return { ok: false, errorCode: "PRINTFOUT", error: `Printopdracht ${bestaandId} is ${status}; vervangen lukte niet na 3 keer.` };
|
|
162
|
+
}
|
|
163
|
+
const opnieuw = await printViaLayoutGecontroleerd(sb, { ...input, idempotentieSleutel: `${input.idempotentieSleutel}:na:${bestaandId}` }, diepte + 1);
|
|
164
|
+
if (opnieuw.ok && !opnieuw.vervangtJobId)
|
|
165
|
+
return { ...opnieuw, vervangtJobId: bestaandId };
|
|
166
|
+
return opnieuw;
|
|
167
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const MODULE_VERSION = "1.0.
|
|
1
|
+
export declare const MODULE_VERSION = "1.0.137";
|
|
2
2
|
//# sourceMappingURL=moduleVersion.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatisch gegenereerd door prebuild:lib; niet handmatig aanpassen.
|
|
2
|
-
export const MODULE_VERSION = "1.0.
|
|
2
|
+
export const MODULE_VERSION = "1.0.137";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shippingNoteQueue.server.d.ts","sourceRoot":"","sources":["../../src/lib/shippingNoteQueue.server.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAO5D,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAoCD,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,cAAc,EAClB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/B,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"shippingNoteQueue.server.d.ts","sourceRoot":"","sources":["../../src/lib/shippingNoteQueue.server.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAO5D,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAoCD,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,cAAc,EAClB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/B,OAAO,CAAC,eAAe,CAAC,CA2c1B;AAMD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,aAAa,GAAG,IAAI,CAAC;AAElE,qGAAqG;AACrG,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAQ9F;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAG5E;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,mBAAmB,GAAG,MAAM,CAI3E"}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// ============================================================================
|
|
14
14
|
import { trace, newTraceId, classifyError } from "./trace.server.js";
|
|
15
15
|
import { FLOW_NODE } from "./flowNodes.js";
|
|
16
|
-
import {
|
|
16
|
+
import { printViaLayoutGecontroleerd, floridayLayout } from "./layoutPrint.server.js";
|
|
17
17
|
import { SHIPPING_NOTE_DEFINITIEVE_FOUTEN, definitieveFout, parseMaxAttempts } from "./shippingNoteStates.js";
|
|
18
18
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
19
19
|
function pickPdf(result) {
|
|
@@ -48,6 +48,8 @@ export async function runShippingNoteQueue(sb, options = {}) {
|
|
|
48
48
|
run.errors.push("De instelling logistics_shipping_note_max_attempts ontbreekt of is ongeldig (1-200); er worden geen verzendbrieven opgehaald.");
|
|
49
49
|
return run;
|
|
50
50
|
}
|
|
51
|
+
// Verzendbrieven die op een Floriday-layout wachtten, komen vrij zodra die er is.
|
|
52
|
+
await sb.rpc("logistics_slip_note_release_layout").then(() => undefined, () => undefined);
|
|
51
53
|
const { data, error } = await sb.rpc("logistics_slip_note_claim", {
|
|
52
54
|
_limit: options.limit ?? 10,
|
|
53
55
|
_lease_seconds: 120,
|
|
@@ -343,17 +345,33 @@ export async function runShippingNoteQueue(sb, options = {}) {
|
|
|
343
345
|
const slipPayload = slipRow["payload"] ?? {};
|
|
344
346
|
const printPlekId = String(slipPayload["print_plek_id"] ?? "").trim() || null;
|
|
345
347
|
const cartId = slipPayload["cart_id"] ?? row.cart_id;
|
|
346
|
-
|
|
348
|
+
// Layout op id: de actieve Floriday-afleverbrief (bij meerdere de standaard).
|
|
349
|
+
const layout = await floridayLayout(sb, "afleverbrief");
|
|
350
|
+
if (!layout.layoutId) {
|
|
351
|
+
await sb.rpc("logistics_slip_note_hold_layout", { _id: row.id, _reason: layout.reden });
|
|
352
|
+
run.waiting++;
|
|
353
|
+
await trace(sb, {
|
|
354
|
+
...basis,
|
|
355
|
+
step: "Wacht op Floriday-layout",
|
|
356
|
+
status: "wachtend",
|
|
357
|
+
reason: layout.reden ?? "Geen Floriday-layout",
|
|
358
|
+
});
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const printed = await printViaLayoutGecontroleerd(sb, {
|
|
347
362
|
documenttype: "afleverbrief",
|
|
363
|
+
layoutId: layout.layoutId,
|
|
348
364
|
documentnaam: `Verzendbrief ${row.order_number}`,
|
|
349
365
|
pdfBase64: base64,
|
|
350
366
|
pdfUrl: url,
|
|
351
367
|
printPlekId,
|
|
352
368
|
herkomst: "floriday",
|
|
353
369
|
isHerprint: Boolean(slipRow["is_herprint"] ?? false),
|
|
354
|
-
idempotentieSleutel: `verzendbrief-bij-pakbon:${row.slip_job_id}`,
|
|
370
|
+
idempotentieSleutel: `verzendbrief-bij-pakbon:${row.slip_job_id}:${layout.layoutId}`,
|
|
355
371
|
payload: {
|
|
356
372
|
source: "pickstation",
|
|
373
|
+
documenttype: "afleverbrief",
|
|
374
|
+
layout_id: layout.layoutId,
|
|
357
375
|
document_type_code: "verzendbrief",
|
|
358
376
|
trigger: "with_packing_slip",
|
|
359
377
|
is_floriday: true,
|
|
@@ -381,21 +399,29 @@ export async function runShippingNoteQueue(sb, options = {}) {
|
|
|
381
399
|
}
|
|
382
400
|
const jobId = printed.jobId;
|
|
383
401
|
const printerId = printed.printerId;
|
|
402
|
+
const alKlaar = printed.bestaand;
|
|
384
403
|
await sb.rpc("logistics_slip_note_finish", {
|
|
385
404
|
_id: row.id,
|
|
386
405
|
_ok: true,
|
|
387
|
-
_status: "
|
|
406
|
+
_status: "in_printwachtrij",
|
|
388
407
|
_print_job_id: jobId,
|
|
389
408
|
_fulfillment_order_id: fulfillmentOrderId,
|
|
390
409
|
});
|
|
391
410
|
run.printed++;
|
|
392
411
|
await trace(sb, {
|
|
393
412
|
...basis,
|
|
394
|
-
step:
|
|
413
|
+
step: alKlaar
|
|
414
|
+
? `Verzendbrief staat in de printwachtrij (opdracht ${jobId})`
|
|
415
|
+
: `Verzendbrief in de printwachtrij gezet (opdracht ${jobId})`,
|
|
395
416
|
status: "geslaagd",
|
|
396
|
-
decision:
|
|
417
|
+
decision: alKlaar
|
|
418
|
+
? "bestaande opdracht is nog actief; niet opnieuw aangemaakt"
|
|
419
|
+
: printed.vervangtJobId
|
|
420
|
+
? `nieuwe opdracht, vervangt mislukte opdracht ${printed.vervangtJobId}`
|
|
421
|
+
: "samen met de pakbon naar dezelfde printer",
|
|
422
|
+
reason: "De echte printuitkomst volgt uit Layouts en printers.",
|
|
397
423
|
...(fulfillmentOrderId ? { externalRef: fulfillmentOrderId } : {}),
|
|
398
|
-
output: { printJobId: jobId, printerId, cartId },
|
|
424
|
+
output: { printJobId: jobId, printerId, cartId, vervangtJobId: printed.vervangtJobId ?? null },
|
|
399
425
|
});
|
|
400
426
|
}
|
|
401
427
|
catch (e) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SHIPPING_NOTE_STATUSSEN: readonly ["wachtend", "wacht_op_vrijgave", "geprint", "mislukt"];
|
|
1
|
+
export declare const SHIPPING_NOTE_STATUSSEN: readonly ["wachtend", "wacht_op_vrijgave", "in_printwachtrij", "geprint", "mislukt"];
|
|
2
2
|
export type ShippingNoteStatusWaarde = (typeof SHIPPING_NOTE_STATUSSEN)[number];
|
|
3
3
|
/** Definitieve fouten: direct mislukt, nooit opnieuw proberen. */
|
|
4
4
|
export declare const SHIPPING_NOTE_DEFINITIEVE_FOUTEN: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shippingNoteStates.d.ts","sourceRoot":"","sources":["../../src/lib/shippingNoteStates.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"shippingNoteStates.d.ts","sourceRoot":"","sources":["../../src/lib/shippingNoteStates.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,uBAAuB,sFAAuF,CAAC;AAC5H,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhF,kEAAkE;AAClE,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;CAanC,CAAC;AACX,MAAM,MAAM,2BAA2B,GAAG,MAAM,OAAO,gCAAgC,CAAC;AAExF,gFAAgF;AAChF,eAAO,MAAM,8BAA8B,yCAAyC,CAAC;AACrF,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAChD,eAAO,MAAM,8BAA8B,MAAM,CAAC;AAElD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAG9D;AAED,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,2BAA2B,GAAG,IAAI,CAKnF"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Toegestane waarden van de verzendbriefwachtrij (09-10-2026).
|
|
3
3
|
// Zelfde waarden als in de database (logistics_slip_shipping_note, module_runtime_config).
|
|
4
4
|
// ============================================================================
|
|
5
|
-
export const SHIPPING_NOTE_STATUSSEN = ["wachtend", "wacht_op_vrijgave", "geprint", "mislukt"];
|
|
5
|
+
export const SHIPPING_NOTE_STATUSSEN = ["wachtend", "wacht_op_vrijgave", "in_printwachtrij", "geprint", "mislukt"];
|
|
6
6
|
/** Definitieve fouten: direct mislukt, nooit opnieuw proberen. */
|
|
7
7
|
export const SHIPPING_NOTE_DEFINITIEVE_FOUTEN = {
|
|
8
8
|
geen_order_id: {
|
|
@@ -160,7 +160,7 @@ export function verzendbriefStop(d) {
|
|
|
160
160
|
if (!d || !d.gevonden)
|
|
161
161
|
return null;
|
|
162
162
|
const status = (d.status ?? "").toLowerCase();
|
|
163
|
-
if (status === "geprint" || status === "klaar")
|
|
163
|
+
if (status === "in_printwachtrij" || status === "geprint" || status === "klaar")
|
|
164
164
|
return null;
|
|
165
165
|
const feiten = [];
|
|
166
166
|
if (d.status)
|