@flowselections/floriday-afhandeling-module 1.0.71 → 1.0.73
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/DagDetailDialog.d.ts.map +1 -1
- package/dist-lib/components/afhandeling/DagDetailDialog.js +50 -24
- package/dist-lib/components/settings/AfhandelingSettingsCard.d.ts.map +1 -1
- package/dist-lib/components/settings/AfhandelingSettingsCard.js +1 -1
- package/dist-lib/lib/documentKeuze.d.ts +24 -0
- package/dist-lib/lib/documentKeuze.d.ts.map +1 -0
- package/dist-lib/lib/documentKeuze.functions.d.ts +14 -0
- package/dist-lib/lib/documentKeuze.functions.d.ts.map +1 -0
- package/dist-lib/lib/documentKeuze.functions.js +28 -0
- package/dist-lib/lib/documentKeuze.js +28 -0
- package/dist-lib/lib/documentKeuze.test.d.ts +2 -0
- package/dist-lib/lib/documentKeuze.test.d.ts.map +1 -0
- package/dist-lib/lib/documentKeuze.test.js +23 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DagDetailDialog.d.ts","sourceRoot":"","sources":["../../../src/components/afhandeling/DagDetailDialog.tsx"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"DagDetailDialog.d.ts","sourceRoot":"","sources":["../../../src/components/afhandeling/DagDetailDialog.tsx"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAiMjE,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,uFAAuF;IACvF,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAUD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,sCAG1D"}
|
|
@@ -53,7 +53,8 @@ import { toDayKey } from "../../lib/logisticsEngine/capacity.js";
|
|
|
53
53
|
import { VerzetOrderDialog } from "./VerzetOrderDialog.js";
|
|
54
54
|
import { markOrderShipped } from "../../lib/orderFulfilment.functions.js";
|
|
55
55
|
import { getDeliveryNotePdf } from "../../lib/deliveryNote.functions.js";
|
|
56
|
-
import {
|
|
56
|
+
import { getDocumentVoorOrder } from "../../lib/documentKeuze.functions.js";
|
|
57
|
+
import { kiesVerzendActie, AUTOMATISCH_DOCUMENT_TEKST } from "../../lib/documentKeuze.js";
|
|
57
58
|
import { setPickDay } from "../../lib/logisticsEngine/reschedule.js";
|
|
58
59
|
import { clearDayStaffPlan, computeCapacity, getDayStaffPlan, getEngineStaffDefaults, setDayStaffPlan, toDateKey, } from "../../lib/logisticsEngine/staffPlanning.js";
|
|
59
60
|
function voortgang(status) {
|
|
@@ -439,7 +440,18 @@ async function printDocumentenVoorOrder(p, fetchLines, fetchCarts, fetchDelivery
|
|
|
439
440
|
let printed = 0;
|
|
440
441
|
let failed = 0;
|
|
441
442
|
const skipped = [];
|
|
442
|
-
|
|
443
|
+
let pakbonKeuze;
|
|
444
|
+
try {
|
|
445
|
+
pakbonKeuze = await fetchShippingNoteLayout({ data: { orderId: p.order.id, documenttype: "pakbon" } });
|
|
446
|
+
}
|
|
447
|
+
catch (err) {
|
|
448
|
+
pakbonKeuze = { ok: false, layoutId: null, bron: null, documenttype: null, reden: err instanceof Error ? err.message : "Het document kon niet worden bepaald." };
|
|
449
|
+
}
|
|
450
|
+
if (!pakbonKeuze.ok) {
|
|
451
|
+
failed += engineCarts.length;
|
|
452
|
+
reasons.push(`Pakbon ${p.order.orderNumber} niet geprint: ${pakbonKeuze.reden}`);
|
|
453
|
+
}
|
|
454
|
+
await Promise.all((pakbonKeuze.ok ? engineCarts : []).map(async (engineCart, idx) => {
|
|
443
455
|
const nr = String(engineCart.cartNumber).padStart(2, "0");
|
|
444
456
|
const cartNumber = `${p.order.orderNumber}-${nr}`;
|
|
445
457
|
const ci = infoById.get(engineCart.cartId);
|
|
@@ -451,6 +463,7 @@ async function printDocumentenVoorOrder(p, fetchLines, fetchCarts, fetchDelivery
|
|
|
451
463
|
const opdracht = (isHerprint) => printLayoutDocument({
|
|
452
464
|
documenttype: "pakbon",
|
|
453
465
|
documentnaam: `PAK-${p.order.orderNumber}-${nr}`,
|
|
466
|
+
layoutId: pakbonKeuze.layoutId ?? undefined,
|
|
454
467
|
isHerprint,
|
|
455
468
|
volgStatus: false,
|
|
456
469
|
payload: pakbonPayload({ cartId: ci.cartId, barcode: ci.barcode, cartNumber, cartIndex: idx + 1, cartTotal, order: orderInfo, pickDate, lines: pakbonLines }),
|
|
@@ -474,16 +487,19 @@ async function printDocumentenVoorOrder(p, fetchLines, fetchCarts, fetchDelivery
|
|
|
474
487
|
console.warn("[print-all] pakbon mislukt", cartNumber, err);
|
|
475
488
|
}
|
|
476
489
|
}));
|
|
477
|
-
//
|
|
490
|
+
// Verzenddocument op de achtergrond: precies één per order, automatisch bepaald uit de order.
|
|
478
491
|
const achtergrond = (async () => {
|
|
479
492
|
try {
|
|
480
|
-
const
|
|
493
|
+
const actie = kiesVerzendActie(await fetchShippingNoteLayout({ data: { orderId: p.order.id, documenttype: "verzenddocument" } }));
|
|
481
494
|
let jobId = null;
|
|
482
|
-
if (
|
|
495
|
+
if (actie.soort === "overslaan") {
|
|
496
|
+
return { printed: 0, failed: 1, reasons: [`Verzenddocument ${p.order.orderNumber} niet geprint: ${actie.reden}`] };
|
|
497
|
+
}
|
|
498
|
+
else if (actie.soort === "layout") {
|
|
483
499
|
jobId = await printLayoutDocument({
|
|
484
|
-
documenttype:
|
|
500
|
+
documenttype: actie.documenttype,
|
|
485
501
|
documentnaam: `AFL-${p.order.orderNumber}`,
|
|
486
|
-
layoutId:
|
|
502
|
+
layoutId: actie.layoutId,
|
|
487
503
|
volgStatus: false,
|
|
488
504
|
payload: { order: { ...orderInfo, cartIndex: 1, cartTotal, cartNumber: p.order.orderNumber } },
|
|
489
505
|
});
|
|
@@ -491,7 +507,7 @@ async function printDocumentenVoorOrder(p, fetchLines, fetchCarts, fetchDelivery
|
|
|
491
507
|
else {
|
|
492
508
|
const { pdf } = await fetchDeliveryNote({ data: { orderRef: p.order.orderNumber } });
|
|
493
509
|
if (!pdf)
|
|
494
|
-
return { printed: 0, failed: 1, reasons: [`
|
|
510
|
+
return { printed: 0, failed: 1, reasons: [`Verzenddocument ${p.order.orderNumber} niet geprint: Floriday heeft de verzendbrief nog niet geleverd.`] };
|
|
495
511
|
jobId = await printPdfDocument({ documenttype: "afleverbrief", documentnaam: `AFL-${p.order.orderNumber}`, pdfBase64: pdf.base64, volgStatus: false });
|
|
496
512
|
}
|
|
497
513
|
return jobId ? { printed: 1, failed: 0, reasons: [] } : { printed: 0, failed: 1, reasons: ["de Printwachtrij gaf geen opdracht-id terug."] };
|
|
@@ -524,7 +540,7 @@ function BufferGroup({ bufferId, orders: dayOrders }) {
|
|
|
524
540
|
const fetchLines = useServerFn(getOrderLines);
|
|
525
541
|
const fetchCarts = useServerFn(getOrderCartIds);
|
|
526
542
|
const fetchDeliveryNote = useServerFn(getDeliveryNotePdf);
|
|
527
|
-
const fetchShippingNoteLayout = useServerFn(
|
|
543
|
+
const fetchShippingNoteLayout = useServerFn(getDocumentVoorOrder);
|
|
528
544
|
const fetchPakbonInfo = useServerFn(getPakbonCartInfo);
|
|
529
545
|
const shipState = useContext(ShipStateCtx);
|
|
530
546
|
// Tel op unieke kar-id: een gedeelde bufferkar telt één keer.
|
|
@@ -670,7 +686,7 @@ function OrderRow({ planned: p, cartsToday, engineStatus, }) {
|
|
|
670
686
|
const fetchLines = useServerFn(getOrderLines);
|
|
671
687
|
const fetchCarts = useServerFn(getOrderCartIds);
|
|
672
688
|
const fetchDeliveryNote = useServerFn(getDeliveryNotePdf);
|
|
673
|
-
const fetchShippingNoteLayout = useServerFn(
|
|
689
|
+
const fetchShippingNoteLayout = useServerFn(getDocumentVoorOrder);
|
|
674
690
|
const archivedQ = useOrderArchived(p.order.id);
|
|
675
691
|
const shipStateRow = useContext(ShipStateCtx).get(refKey(p.order.orderNumber));
|
|
676
692
|
const fetchPakbonInfo = useServerFn(getPakbonCartInfo);
|
|
@@ -785,7 +801,7 @@ function KarRow({ cart: c, cartTotal, selected, onToggle, }) {
|
|
|
785
801
|
const [bezig, setBezig] = useState(null);
|
|
786
802
|
const fetchLines = useServerFn(getOrderLines);
|
|
787
803
|
const fetchDeliveryNote = useServerFn(getDeliveryNotePdf);
|
|
788
|
-
const fetchShippingNoteLayout = useServerFn(
|
|
804
|
+
const fetchShippingNoteLayout = useServerFn(getDocumentVoorOrder);
|
|
789
805
|
const fetchPakbonInfo = useServerFn(getPakbonCartInfo);
|
|
790
806
|
const printPakbon = async () => {
|
|
791
807
|
if (bezig)
|
|
@@ -815,8 +831,14 @@ function KarRow({ cart: c, cartTotal, selected, onToggle, }) {
|
|
|
815
831
|
if (!ci)
|
|
816
832
|
throw new Error(`Pakbon ${c.cartNumber} kan nog niet worden geprint: de kar is nog niet ingedeeld. Probeer het over een minuut opnieuw.`);
|
|
817
833
|
const nr = String(c.cartIndex + 1).padStart(2, "0");
|
|
834
|
+
if (!p?.order.id)
|
|
835
|
+
throw new Error(`Pakbon ${c.cartNumber} niet geprint: de order is niet gevonden.`);
|
|
836
|
+
const keuze = await fetchShippingNoteLayout({ data: { orderId: p.order.id, documenttype: "pakbon" } });
|
|
837
|
+
if (!keuze.ok)
|
|
838
|
+
throw new Error(`Pakbon ${c.cartNumber} niet geprint: ${keuze.reden}`);
|
|
818
839
|
await printLayoutDocument({
|
|
819
840
|
documenttype: "pakbon",
|
|
841
|
+
layoutId: keuze.layoutId ?? undefined,
|
|
820
842
|
documentnaam: `PAK-${c.orderRef}-${nr}`,
|
|
821
843
|
isHerprint: true,
|
|
822
844
|
volgStatus: false,
|
|
@@ -851,35 +873,39 @@ function KarRow({ cart: c, cartTotal, selected, onToggle, }) {
|
|
|
851
873
|
return;
|
|
852
874
|
setBezig("brief");
|
|
853
875
|
try {
|
|
854
|
-
// 1) De layout die de Engine koppelt aan "Verzendbrief voor BVO orders".
|
|
855
876
|
const p = c.order;
|
|
856
|
-
|
|
857
|
-
|
|
877
|
+
if (!p?.order.id)
|
|
878
|
+
throw new Error(`Verzenddocument ${c.orderRef} niet geprint: de order is niet gevonden.`);
|
|
879
|
+
const actie = kiesVerzendActie(await fetchShippingNoteLayout({ data: { orderId: p.order.id, documenttype: "verzenddocument" } }));
|
|
880
|
+
if (actie.soort === "overslaan") {
|
|
881
|
+
toast.error(`Verzenddocument ${c.orderRef} niet geprint: ${actie.reden}`);
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
if (actie.soort === "layout") {
|
|
858
885
|
await printLayoutDocument({
|
|
859
|
-
documenttype:
|
|
886
|
+
documenttype: actie.documenttype,
|
|
860
887
|
documentnaam: `AFL-${c.orderRef}`,
|
|
861
|
-
layoutId:
|
|
888
|
+
layoutId: actie.layoutId,
|
|
862
889
|
isHerprint: true,
|
|
863
890
|
payload: {
|
|
864
891
|
order: {
|
|
865
|
-
id: p
|
|
892
|
+
id: p.order.id,
|
|
866
893
|
orderNumber: c.orderRef,
|
|
867
894
|
customerName: c.customerName,
|
|
868
|
-
country: p
|
|
869
|
-
deliveryDate: p
|
|
895
|
+
country: p.order.country ?? null,
|
|
896
|
+
deliveryDate: p.order.deliveryDate ?? null,
|
|
870
897
|
cartIndex: c.cartIndex,
|
|
871
898
|
cartTotal,
|
|
872
899
|
cartNumber: c.cartNumber,
|
|
873
900
|
},
|
|
874
901
|
},
|
|
875
902
|
});
|
|
876
|
-
toast.success(`
|
|
903
|
+
toast.success(`Verzenddocument ${c.orderRef} is naar de printer gestuurd.`);
|
|
877
904
|
return;
|
|
878
905
|
}
|
|
879
|
-
// 2) Geen eigen layout ingesteld: dan de Floriday-brief, als die er is.
|
|
880
906
|
const { pdf } = await fetchDeliveryNote({ data: { orderRef: c.orderRef } });
|
|
881
907
|
if (!pdf) {
|
|
882
|
-
toast.error(
|
|
908
|
+
toast.error(`Verzenddocument ${c.orderRef} niet geprint: Floriday heeft de verzendbrief nog niet geleverd.`);
|
|
883
909
|
return;
|
|
884
910
|
}
|
|
885
911
|
await printPdfDocument({
|
|
@@ -888,7 +914,7 @@ function KarRow({ cart: c, cartTotal, selected, onToggle, }) {
|
|
|
888
914
|
isHerprint: true,
|
|
889
915
|
pdfBase64: pdf.base64,
|
|
890
916
|
});
|
|
891
|
-
toast.success(`
|
|
917
|
+
toast.success(`Verzenddocument ${c.orderRef} is naar de printer gestuurd.`);
|
|
892
918
|
}
|
|
893
919
|
catch (err) {
|
|
894
920
|
toast.error(printFoutMelding(err));
|
|
@@ -899,7 +925,7 @@ function KarRow({ cart: c, cartTotal, selected, onToggle, }) {
|
|
|
899
925
|
};
|
|
900
926
|
return (_jsxs("div", { className: `rounded-md border p-3 ${selected ? "border-primary bg-primary/5" : ""}`, children: [_jsxs("div", { className: "flex items-start gap-3", children: [_jsx(Checkbox, { checked: selected, onCheckedChange: onToggle, className: "mt-1" }), _jsxs("div", { className: "grid flex-1 gap-3 lg:grid-cols-[1fr_1.4fr_1fr_auto] lg:items-center", children: [_jsx(Field, { label: "Karnummer", value: c.cartNumber }), _jsx(Field, { label: "Klant", value: c.customerName }), _jsx(Field, { label: "Bestelling", value: c.orderRef }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(Badge, { variant: voortgang(c.status).variant, children: voortgang(c.status).label }), c.coverageLabel && _jsx(Badge, { variant: "secondary", children: c.coverageLabel }), c.hasContent ? (_jsxs(_Fragment, { children: [c.shared && _jsx(Badge, { variant: "outline", children: "Gedeelde bufferkar" }), _jsxs(Badge, { variant: "outline", children: [c.occupancy ?? "—", "%", c.layerUtilization != null
|
|
901
927
|
? ` · ${Number(c.layerUtilization.toFixed(1)).toLocaleString("nl-NL")}% van de kar`
|
|
902
|
-
: ""] }), _jsxs(Badge, { variant: "outline", children: [c.layers ?? "—", c.maxLayers != null ? ` / ${c.maxLayers}` : "", " lagen"] }), _jsxs(Badge, { variant: "outline", children: [c.crates ?? "—", " fusten"] }), _jsxs(Badge, { variant: "outline", children: [c.plants ?? "—", " planten"] })] })) : (_jsx(Badge, { variant: "outline", className: "text-muted-foreground", children: c.contentLoading ? "Karinhoud laden…" : c.coverageLabel ? "Geen kar in deze indeling" : "Nog geen karindeling" })), _jsxs(Button, { size: "sm", variant: "outline", disabled: bezig !== null, onClick: printPakbon, title:
|
|
928
|
+
: ""] }), _jsxs(Badge, { variant: "outline", children: [c.layers ?? "—", c.maxLayers != null ? ` / ${c.maxLayers}` : "", " lagen"] }), _jsxs(Badge, { variant: "outline", children: [c.crates ?? "—", " fusten"] }), _jsxs(Badge, { variant: "outline", children: [c.plants ?? "—", " planten"] })] })) : (_jsx(Badge, { variant: "outline", className: "text-muted-foreground", children: c.contentLoading ? "Karinhoud laden…" : c.coverageLabel ? "Geen kar in deze indeling" : "Nog geen karindeling" })), _jsxs(Button, { size: "sm", variant: "outline", disabled: bezig !== null, onClick: printPakbon, title: `Pakbon van deze kar opnieuw printen. ${AUTOMATISCH_DOCUMENT_TEKST}`, children: [_jsx(Printer, { className: "mr-1 h-3.5 w-3.5" }), bezig === "pakbon" ? "Bezig…" : "Pakbon"] }), _jsxs(Button, { size: "sm", variant: "outline", disabled: bezig !== null, onClick: printVerzendbrief, title: `Verzenddocument van deze bestelling printen. ${AUTOMATISCH_DOCUMENT_TEKST}`, children: [_jsx(Printer, { className: "mr-1 h-3.5 w-3.5" }), bezig === "brief" ? "Bezig…" : "Verzendbrief"] }), _jsxs(Button, { size: "sm", variant: "outline", onClick: () => setVerzetOpen(true), title: "Ophaaldag of ophaaltijd van de bestelling van deze kar wijzigen", children: [_jsx(CalendarClock, { className: "mr-1 h-3.5 w-3.5" }), "Verzetten"] })] })] })] }), _jsx(VerzetOrderDialog, { open: verzetOpen, orderRef: c.orderRef, carrierTarget: {
|
|
903
929
|
carrierId: c.order?.order.carrierId ?? null,
|
|
904
930
|
country: c.order?.order.country ?? null,
|
|
905
931
|
province: c.order?.order.province ?? null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AfhandelingSettingsCard.d.ts","sourceRoot":"","sources":["../../../src/components/settings/AfhandelingSettingsCard.tsx"],"names":[],"mappings":"AAuBA,wBAAgB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"AfhandelingSettingsCard.d.ts","sourceRoot":"","sources":["../../../src/components/settings/AfhandelingSettingsCard.tsx"],"names":[],"mappings":"AAuBA,wBAAgB,uBAAuB,gCAkKtC"}
|
|
@@ -79,7 +79,7 @@ export function AfhandelingSettingsCard() {
|
|
|
79
79
|
toast.error(e instanceof Error ? e.message : "Opslaan mislukt");
|
|
80
80
|
},
|
|
81
81
|
});
|
|
82
|
-
return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CalendarClock, { className: "h-5 w-5 text-primary" }), _jsx(CardTitle, { children: "Afhandeling \u2014 Planning" })] }), _jsx(CardDescription, { children: "De pickplanning (pickdagen, picktijd en verdeling over de week) wordt volledig bepaald door de planning. Hieronder staan alleen de instellingen van deze module zelf." })] }), _jsxs(CardContent, { className: "space-y-5", children: [_jsxs("div", { className: "rounded-md border p-4 space-y-4", children: [_jsxs("div", { className: "flex items-start justify-between gap-4", children: [_jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Mail, { className: "h-4 w-4 text-primary" }), _jsx(Label, { htmlFor: "mailEnabled", className: "font-semibold", children: "Aanmeldmail vervoerders" })] }), _jsx("p", { className: "text-xs text-muted-foreground max-w-prose", children: "Verstuurt automatisch een mail met de te verwachten karren naar de vervoerder v\u00F3\u00F3r de aanmelddeadline van het ophaalmoment. E\u00E9n mail per ophaaldag/-moment per vervoerder." })] }), _jsx(Switch, { id: "mailEnabled", checked: mailEnabled, onCheckedChange: setMailEnabled })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "mailLead", children: "Minuten v\u00F3\u00F3r aanmelddeadline versturen" }), _jsx(Input, { id: "mailLead", type: "number", min: 0, max: 1440, value: mailLead, disabled: !mailEnabled, onChange: (e) => setMailLead(Math.max(0, Math.min(1440, Math.floor(Number(e.target.value)) || 0))) })] }), _jsx("div", { className: "space-y-1 text-sm", children: _jsxs("div", { children: [_jsx("strong", { children: "Verzendadres:" }), " ", cron.data?.senderEmail ? cron.data.senderEmail : _jsx("span", { className: "text-muted-foreground", children: "nog geen verbonden adres" }), " ", _jsx("span", { className: "text-xs text-muted-foreground", children: "(instellen bij E-mailkoppeling)" })] }) }), _jsxs("details", { className: "text-xs text-muted-foreground", children: [_jsx("summary", { className: "cursor-pointer", children: "Details voor beheer" }), _jsxs("div", { className: "mt-2 space-y-2", children: [_jsx(Label, { htmlFor: "mailPurpose", children: "Doeleinde in E-mailkoppeling" }), _jsx(Input, { id: "mailPurpose", value: mailPurpose, disabled: !mailEnabled, onChange: (e) => setMailPurpose(e.target.value) }), _jsxs("p", { children: ["Standaard: ", _jsx("code", { children: "afhandeling_carrier_signup" }), "."] })] })] })] }), _jsx(SignupStatusBlock, { status: cron.data ?? null, loading: cron.isLoading, failed: cron.isError }), _jsxs("div", { className: "rounded-md bg-muted/50 p-3 text-xs text-muted-foreground", children: [_jsx("strong", { children: "Ophaaltijd" }), " en ", _jsx("strong", { children: "Aanmeldtijd" }), " stel je per vervoerder in (werkdagen v\u00F3\u00F3r bezorgdag). De vervoerder die als ", _jsx("strong", { children: "standaard" }), " is gemarkeerd, wordt gebruikt voor orders zonder eigen vervoerder."] }), _jsx(Button, { onClick: () => mutation.mutate(), disabled: mutation.isPending, children: mutation.isPending ? "Opslaan…" : "Opslaan" })] })] }));
|
|
82
|
+
return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CalendarClock, { className: "h-5 w-5 text-primary" }), _jsx(CardTitle, { children: "Afhandeling \u2014 Planning" })] }), _jsx(CardDescription, { children: "De pickplanning (pickdagen, picktijd en verdeling over de week) wordt volledig bepaald door de planning. Hieronder staan alleen de instellingen van deze module zelf. Printen: het document wordt automatisch bepaald uit de order." })] }), _jsxs(CardContent, { className: "space-y-5", children: [_jsxs("div", { className: "rounded-md border p-4 space-y-4", children: [_jsxs("div", { className: "flex items-start justify-between gap-4", children: [_jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Mail, { className: "h-4 w-4 text-primary" }), _jsx(Label, { htmlFor: "mailEnabled", className: "font-semibold", children: "Aanmeldmail vervoerders" })] }), _jsx("p", { className: "text-xs text-muted-foreground max-w-prose", children: "Verstuurt automatisch een mail met de te verwachten karren naar de vervoerder v\u00F3\u00F3r de aanmelddeadline van het ophaalmoment. E\u00E9n mail per ophaaldag/-moment per vervoerder." })] }), _jsx(Switch, { id: "mailEnabled", checked: mailEnabled, onCheckedChange: setMailEnabled })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "mailLead", children: "Minuten v\u00F3\u00F3r aanmelddeadline versturen" }), _jsx(Input, { id: "mailLead", type: "number", min: 0, max: 1440, value: mailLead, disabled: !mailEnabled, onChange: (e) => setMailLead(Math.max(0, Math.min(1440, Math.floor(Number(e.target.value)) || 0))) })] }), _jsx("div", { className: "space-y-1 text-sm", children: _jsxs("div", { children: [_jsx("strong", { children: "Verzendadres:" }), " ", cron.data?.senderEmail ? cron.data.senderEmail : _jsx("span", { className: "text-muted-foreground", children: "nog geen verbonden adres" }), " ", _jsx("span", { className: "text-xs text-muted-foreground", children: "(instellen bij E-mailkoppeling)" })] }) }), _jsxs("details", { className: "text-xs text-muted-foreground", children: [_jsx("summary", { className: "cursor-pointer", children: "Details voor beheer" }), _jsxs("div", { className: "mt-2 space-y-2", children: [_jsx(Label, { htmlFor: "mailPurpose", children: "Doeleinde in E-mailkoppeling" }), _jsx(Input, { id: "mailPurpose", value: mailPurpose, disabled: !mailEnabled, onChange: (e) => setMailPurpose(e.target.value) }), _jsxs("p", { children: ["Standaard: ", _jsx("code", { children: "afhandeling_carrier_signup" }), "."] })] })] })] }), _jsx(SignupStatusBlock, { status: cron.data ?? null, loading: cron.isLoading, failed: cron.isError }), _jsxs("div", { className: "rounded-md bg-muted/50 p-3 text-xs text-muted-foreground", children: [_jsx("strong", { children: "Ophaaltijd" }), " en ", _jsx("strong", { children: "Aanmeldtijd" }), " stel je per vervoerder in (werkdagen v\u00F3\u00F3r bezorgdag). De vervoerder die als ", _jsx("strong", { children: "standaard" }), " is gemarkeerd, wordt gebruikt voor orders zonder eigen vervoerder."] }), _jsx(Button, { onClick: () => mutation.mutate(), disabled: mutation.isPending, children: mutation.isPending ? "Opslaan…" : "Opslaan" })] })] }));
|
|
83
83
|
}
|
|
84
84
|
function SignupStatusBlock({ status, loading, failed, }) {
|
|
85
85
|
if (loading)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type DocumentSoort = "pakbon" | "productiebon" | "verzenddocument" | "sticker" | "traysticker" | "eigen_sticker";
|
|
2
|
+
export interface DocumentKeuze {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
layoutId: string | null;
|
|
5
|
+
bron: "floriday" | "eigen" | null;
|
|
6
|
+
documenttype: string | null;
|
|
7
|
+
reden: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare const AUTOMATISCH_DOCUMENT_TEKST = "Het document wordt automatisch bepaald uit de order.";
|
|
10
|
+
/** Zet het antwoord van de functie om; alles wat niet klopt telt als ok=false (fail closed). */
|
|
11
|
+
export declare function leesDocumentKeuze(raw: unknown, soort: string): DocumentKeuze;
|
|
12
|
+
export type VerzendActie = {
|
|
13
|
+
soort: "overslaan";
|
|
14
|
+
reden: string;
|
|
15
|
+
} | {
|
|
16
|
+
soort: "floriday_pdf";
|
|
17
|
+
} | {
|
|
18
|
+
soort: "layout";
|
|
19
|
+
layoutId: string;
|
|
20
|
+
documenttype: string;
|
|
21
|
+
};
|
|
22
|
+
/** Precies één verzenddocument per order: Floriday-order = Floriday-PDF, eigen order = afleverbrief-layout. */
|
|
23
|
+
export declare function kiesVerzendActie(k: DocumentKeuze): VerzendActie;
|
|
24
|
+
//# sourceMappingURL=documentKeuze.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentKeuze.d.ts","sourceRoot":"","sources":["../../src/lib/documentKeuze.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,aAAa,GACrB,QAAQ,GACR,cAAc,GACd,iBAAiB,GACjB,SAAS,GACT,aAAa,GACb,eAAe,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,IAAI,CAAC;IAClC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,0BAA0B,yDAAyD,CAAC;AAEjG,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAc5E;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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type DocumentKeuze } from "./documentKeuze.js";
|
|
2
|
+
/** Vraagt bij de Engine welk document (layout) bij deze order hoort. */
|
|
3
|
+
export declare const getDocumentVoorOrder: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
4
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
5
|
+
userId: string;
|
|
6
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
7
|
+
}, undefined, undefined, undefined>], (d: {
|
|
8
|
+
orderId: string;
|
|
9
|
+
documenttype: string;
|
|
10
|
+
}) => {
|
|
11
|
+
orderId: string;
|
|
12
|
+
documenttype: string;
|
|
13
|
+
}, Promise<DocumentKeuze>>;
|
|
14
|
+
//# sourceMappingURL=documentKeuze.functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentKeuze.functions.d.ts","sourceRoot":"","sources":["../../src/lib/documentKeuze.functions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKxE,wEAAwE;AACxE,eAAO,MAAM,oBAAoB;;;;0CAEX;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE;;;0BAoB3D,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
2
|
+
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
3
|
+
import { leesDocumentKeuze } from "./documentKeuze.js";
|
|
4
|
+
const SOORTEN = ["pakbon", "productiebon", "verzenddocument", "sticker", "traysticker", "eigen_sticker"];
|
|
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
|
+
/** Vraagt bij de Engine welk document (layout) bij deze order hoort. */
|
|
7
|
+
export const getDocumentVoorOrder = createServerFn({ method: "POST" })
|
|
8
|
+
.middleware([requireSupabaseAuth])
|
|
9
|
+
.inputValidator((d) => {
|
|
10
|
+
if (!SOORTEN.includes(d?.documenttype))
|
|
11
|
+
throw new Error("Onbekende documentsoort.");
|
|
12
|
+
return { orderId: String(d.orderId ?? ""), documenttype: d.documenttype };
|
|
13
|
+
})
|
|
14
|
+
.handler(async ({ data, context }) => {
|
|
15
|
+
if (!UUID.test(data.orderId)) {
|
|
16
|
+
return leesDocumentKeuze({ ok: false, reden: "De order is niet gevonden; het document kan niet worden bepaald." }, data.documenttype);
|
|
17
|
+
}
|
|
18
|
+
const sb = context.supabase;
|
|
19
|
+
const { data: res, error } = await sb.rpc("logistics_document_for_order", {
|
|
20
|
+
p_order_id: data.orderId,
|
|
21
|
+
p_documenttype: data.documenttype,
|
|
22
|
+
});
|
|
23
|
+
if (error) {
|
|
24
|
+
console.warn("[documentkeuze]", error.message);
|
|
25
|
+
return leesDocumentKeuze({ ok: false, reden: "Het document kon niet worden bepaald. Probeer het zo opnieuw." }, data.documenttype);
|
|
26
|
+
}
|
|
27
|
+
return leesDocumentKeuze(res, data.documenttype);
|
|
28
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Gedeelde, browser-veilige logica rond de automatische documentkeuze
|
|
2
|
+
// (logistics_document_for_order). Geen eigen layoutkeuze meer.
|
|
3
|
+
export const AUTOMATISCH_DOCUMENT_TEKST = "Het document wordt automatisch bepaald uit de order.";
|
|
4
|
+
/** Zet het antwoord van de functie om; alles wat niet klopt telt als ok=false (fail closed). */
|
|
5
|
+
export function leesDocumentKeuze(raw, soort) {
|
|
6
|
+
const r = raw && typeof raw === "object" ? raw : null;
|
|
7
|
+
if (!r)
|
|
8
|
+
return { ok: false, layoutId: null, bron: null, documenttype: null, reden: `Geen antwoord over het document (${soort}).` };
|
|
9
|
+
const layoutId = typeof r.layout_id === "string" && r.layout_id ? r.layout_id : null;
|
|
10
|
+
const bron = r.bron === "floriday" || r.bron === "eigen" ? r.bron : null;
|
|
11
|
+
const ok = r.ok === true && !!layoutId;
|
|
12
|
+
const reden = typeof r.reden === "string" && r.reden ? r.reden : null;
|
|
13
|
+
return {
|
|
14
|
+
ok,
|
|
15
|
+
layoutId,
|
|
16
|
+
bron,
|
|
17
|
+
documenttype: typeof r.documenttype === "string" ? r.documenttype : null,
|
|
18
|
+
reden: ok ? null : reden ?? `Het document (${soort}) kan niet worden bepaald.`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Precies één verzenddocument per order: Floriday-order = Floriday-PDF, eigen order = afleverbrief-layout. */
|
|
22
|
+
export function kiesVerzendActie(k) {
|
|
23
|
+
if (!k.ok || !k.layoutId)
|
|
24
|
+
return { soort: "overslaan", reden: k.reden ?? "Het verzenddocument kan niet worden bepaald." };
|
|
25
|
+
if (k.bron === "floriday")
|
|
26
|
+
return { soort: "floriday_pdf" };
|
|
27
|
+
return { soort: "layout", layoutId: k.layoutId, documenttype: k.documenttype ?? "afleverbrief" };
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentKeuze.test.d.ts","sourceRoot":"","sources":["../../src/lib/documentKeuze.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { kiesVerzendActie, leesDocumentKeuze } from "./documentKeuze.js";
|
|
3
|
+
describe("automatische documentkeuze", () => {
|
|
4
|
+
it("ok=false: niet printen, reden doorgeven", () => {
|
|
5
|
+
const k = leesDocumentKeuze({ ok: false, layout_id: null, reden: "Maak een layout" }, "pakbon");
|
|
6
|
+
expect(k.ok).toBe(false);
|
|
7
|
+
expect(kiesVerzendActie(k)).toEqual({ soort: "overslaan", reden: "Maak een layout" });
|
|
8
|
+
});
|
|
9
|
+
it("Floriday-order: wat Floriday levert", () => {
|
|
10
|
+
const k = leesDocumentKeuze({ ok: true, layout_id: "L1", bron: "floriday", documenttype: "afleverbrief" }, "verzenddocument");
|
|
11
|
+
expect(kiesVerzendActie(k)).toEqual({ soort: "floriday_pdf" });
|
|
12
|
+
});
|
|
13
|
+
it("eigen order: afleverbrief-layout", () => {
|
|
14
|
+
const k = leesDocumentKeuze({ ok: true, layout_id: "L2", bron: "eigen", documenttype: "afleverbrief" }, "verzenddocument");
|
|
15
|
+
expect(kiesVerzendActie(k)).toEqual({ soort: "layout", layoutId: "L2", documenttype: "afleverbrief" });
|
|
16
|
+
});
|
|
17
|
+
it("ok=true zonder layout geldt als niet printen", () => {
|
|
18
|
+
expect(leesDocumentKeuze({ ok: true }, "pakbon").ok).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
it("geen antwoord geldt als niet printen", () => {
|
|
21
|
+
expect(leesDocumentKeuze(null, "pakbon").ok).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|