@flowselections/floriday-afhandeling-module 1.0.109 → 1.0.110
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 +49 -1
- 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/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.map +1 -1
- package/dist-lib/components/afhandeling/ScanControleView.js +107 -10
- 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/integrations/supabase/types.d.ts +2630 -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/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/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/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/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/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 +3 -1
- package/schema/90_afhandeling.sql +1625 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Badge, Button, Dialog, DialogContent, DialogHeader, DialogTitle, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, toast, } from "@flowselections/core";
|
|
4
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
5
|
+
import { useServerFn } from "@tanstack/react-start";
|
|
6
|
+
import { CheckCircle2, PencilLine, RefreshCw, Scale } from "lucide-react";
|
|
7
|
+
import { FloridayBriefHerprint } from "./FloridayBriefHerprint.js";
|
|
8
|
+
import { supabase } from "../../integrations/supabase/moduleClient.js";
|
|
9
|
+
import { CorrectieDialog } from "./CorrectieDialog.js";
|
|
10
|
+
import { callServerFn } from "../../lib/serverFnError.js";
|
|
11
|
+
import { floridayCorrectiesLijst, floridayCorrectieVersturen, floridayOrderGelijk, } from "../../lib/correcties.functions.js";
|
|
12
|
+
import { STAND_TEKST, standVanKoppeling } from "../../lib/floridayCorrectie.js";
|
|
13
|
+
import { doorvoerOpnieuw, doorvoerZinnen, floridayOpnieuw, REDEN_TEKST, SOORT_TEKST, waardeTekst } from "../../lib/correctieTekst.js";
|
|
14
|
+
const fmt = (iso) => new Date(iso).toLocaleString("nl-NL", { timeZone: "Europe/Amsterdam", weekday: "short", day: "numeric", month: "short", hour: "2-digit", minute: "2-digit" });
|
|
15
|
+
const FL_SOORT = { fewer_packages: "Minder fusten", extra_layers: "Platen", load_carrier_type: "Andere ladingdrager", delivery_location: "Afleverlocatie" };
|
|
16
|
+
const VELD = { fusten: "fusten", platen: "platen", loadCarrierType: "soort ladingdrager", aantal_ladingdragers: "aantal ladingdragers", ontbreekt_in_floriday: "ontbreekt bij Floriday" };
|
|
17
|
+
/** Per levering: ladingdragers corrigeren, eigen log, en bij Floriday-orders de stand bij Floriday. */
|
|
18
|
+
export function LeveringCorrigerenDialog({ orderId, onClose, onGewijzigd }) {
|
|
19
|
+
const [kar, setKar] = useState(null);
|
|
20
|
+
const [gelijk, setGelijk] = useState(null);
|
|
21
|
+
const versturen = useServerFn(floridayCorrectieVersturen);
|
|
22
|
+
const lijstFn = useServerFn(floridayCorrectiesLijst);
|
|
23
|
+
const gelijkFn = useServerFn(floridayOrderGelijk);
|
|
24
|
+
const detailQ = useQuery({
|
|
25
|
+
queryKey: ["afh-levering-detail", orderId],
|
|
26
|
+
queryFn: async () => {
|
|
27
|
+
const { data, error } = await supabase.rpc("afh_levering_detail", { p_order_id: orderId });
|
|
28
|
+
if (error)
|
|
29
|
+
throw new Error(error.message);
|
|
30
|
+
return data;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const isFl = detailQ.data?.order?.is_floriday === true;
|
|
34
|
+
const flQ = useQuery({
|
|
35
|
+
queryKey: ["afh-floriday-correcties", orderId],
|
|
36
|
+
enabled: isFl,
|
|
37
|
+
queryFn: () => callServerFn(() => lijstFn({ data: { orderId } }), "floridayCorrectiesLijst"),
|
|
38
|
+
});
|
|
39
|
+
const ververs = () => { void detailQ.refetch(); if (isFl)
|
|
40
|
+
void flQ.refetch(); onGewijzigd?.(); };
|
|
41
|
+
const opnieuwFl = useMutation({
|
|
42
|
+
mutationFn: (id) => callServerFn(() => versturen({ data: { correctieId: id } }), "floridayCorrectieVersturen", { maxAttempts: 1, timeoutMs: 30000 }),
|
|
43
|
+
onSuccess: (r) => { (r.ok ? toast.success : toast.error)(r.melding); ververs(); },
|
|
44
|
+
onError: (e) => { console.error("[correctie] opnieuw naar Floriday", e); toast.error("Opnieuw versturen is niet gelukt. Probeer het straks opnieuw."); },
|
|
45
|
+
});
|
|
46
|
+
const opnieuwDoor = useMutation({
|
|
47
|
+
mutationFn: async (id) => {
|
|
48
|
+
const { data, error } = await supabase.rpc("afh_correctie_doorvoeren", { p_correctie_id: id });
|
|
49
|
+
if (error)
|
|
50
|
+
throw new Error(error.message);
|
|
51
|
+
return data;
|
|
52
|
+
},
|
|
53
|
+
onSuccess: (r) => {
|
|
54
|
+
if (!r.ok)
|
|
55
|
+
toast.error(r.melding ?? "Opnieuw doorvoeren is niet gelukt.");
|
|
56
|
+
else
|
|
57
|
+
toast.success(doorvoerZinnen(r.doorvoer).join(". ") || "Doorgevoerd.");
|
|
58
|
+
ververs();
|
|
59
|
+
},
|
|
60
|
+
onError: (e) => { console.error("[correctie] doorvoeren", e); toast.error(e.message || "Opnieuw doorvoeren is niet gelukt."); },
|
|
61
|
+
});
|
|
62
|
+
const vergelijk = useMutation({
|
|
63
|
+
mutationFn: () => callServerFn(() => gelijkFn({ data: { orderId } }), "floridayOrderGelijk", { maxAttempts: 1 }),
|
|
64
|
+
onSuccess: (r) => { setGelijk(r); if (!r.ok)
|
|
65
|
+
toast.error(r.melding ?? "Vergelijken met Floriday lukte niet."); },
|
|
66
|
+
onError: (e) => { console.error("[correctie] vergelijken", e); toast.error("Vergelijken met Floriday lukte niet. Probeer het opnieuw."); },
|
|
67
|
+
});
|
|
68
|
+
const d = detailQ.data;
|
|
69
|
+
const karren = (d?.karren ?? []).map((k) => ({
|
|
70
|
+
cartId: k.cart_id, nummer: k.nummer, soort: k.soort,
|
|
71
|
+
partijen: k.items.map((i) => ({ orderItemId: i.order_item_id, naam: i.product ?? "Partij", fusten: i.fusten })),
|
|
72
|
+
}));
|
|
73
|
+
return (_jsx(Dialog, { open: true, onOpenChange: (v) => !v && onClose(), children: _jsxs(DialogContent, { className: "max-w-3xl", children: [_jsx(DialogHeader, { children: _jsxs(DialogTitle, { children: ["Levering ", d?.order?.order_number ?? "", d?.order?.customer_name ? ` – ${d.order.customer_name}` : ""] }) }), detailQ.isError && _jsx("p", { className: "text-sm text-destructive", children: "De levering kon niet worden opgehaald. Probeer het opnieuw." }), d && !d.ok && _jsx("p", { className: "text-sm text-destructive", children: d.reden }), d?.ok && (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "space-y-2", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "font-medium", children: "Ladingdragers" }), karren.length > 0 && _jsxs(Button, { size: "sm", variant: "outline", onClick: () => setKar("kies"), children: [_jsx(PencilLine, { className: "h-4 w-4 mr-2" }), "Levering corrigeren"] })] }), karren.length === 0 ? _jsx("p", { className: "text-sm text-muted-foreground", children: "Er zijn geen ladingdragers meer bekend voor deze order." }) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "Ladingdrager" }), _jsx(TableHead, { children: "Wat erop staat" }), _jsx(TableHead, {})] }) }), _jsx(TableBody, { children: karren.map((k) => (_jsxs(TableRow, { children: [_jsxs(TableCell, { className: "font-medium", children: [k.soort, " ", k.nummer] }), _jsx(TableCell, { className: "text-sm", children: k.partijen.map((p) => `${p.naam} (${p.fusten} fust)`).join(", ") || "—" }), _jsx(TableCell, { className: "text-right", children: _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setKar(k), children: "Corrigeren" }) })] }, k.cartId))) })] }))] }), _jsxs("div", { className: "space-y-2", children: [_jsx("div", { className: "font-medium", children: "Correcties" }), d.correcties.length === 0 ? _jsx("p", { className: "text-sm text-muted-foreground", children: "Nog geen correcties." }) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "Wanneer" }), _jsx(TableHead, { children: "Wat" }), _jsx(TableHead, { children: "Reden" }), _jsx(TableHead, { children: "Stand" }), _jsx(TableHead, {})] }) }), _jsx(TableBody, { children: d.correcties.map((c) => (_jsxs(TableRow, { children: [_jsxs(TableCell, { className: "whitespace-nowrap", children: [fmt(c.created_at), _jsx("div", { className: "text-xs text-muted-foreground", children: c.door_naam ?? "—" })] }), _jsxs(TableCell, { children: [SOORT_TEKST[c.soort] ?? c.soort, _jsxs("div", { className: "text-xs", children: [_jsx("span", { className: "line-through text-muted-foreground", children: waardeTekst(c.soort, c.oud) }), " \u2192 ", waardeTekst(c.soort, c.nieuw)] })] }), _jsxs(TableCell, { children: [REDEN_TEKST[c.reden] ?? c.reden, c.toelichting ? ` – ${c.toelichting}` : ""] }), _jsx(TableCell, { className: "text-xs", children: doorvoerZinnen(c.doorvoer).map((z) => _jsx("div", { children: z }, z)) }), _jsxs(TableCell, { className: "text-right space-y-1", children: [floridayOpnieuw(c.doorvoer) && (_jsxs(Button, { size: "sm", variant: "outline", disabled: opnieuwFl.isPending, onClick: () => opnieuwFl.mutate(c.id), children: [_jsx(RefreshCw, { className: "h-4 w-4 mr-2" }), "Opnieuw naar Floriday"] })), doorvoerOpnieuw(c.doorvoer) && (_jsx(Button, { size: "sm", variant: "ghost", disabled: opnieuwDoor.isPending, onClick: () => opnieuwDoor.mutate(c.id), children: "Opnieuw doorvoeren" }))] })] }, c.id))) })] }))] }), isFl && (_jsxs("div", { className: "space-y-2", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx("div", { className: "font-medium", children: "Bij Floriday" }), _jsxs("div", { className: "flex flex-wrap items-start gap-2", children: [_jsxs(Button, { size: "sm", variant: "outline", disabled: vergelijk.isPending, onClick: () => vergelijk.mutate(), children: [_jsx(Scale, { className: "h-4 w-4 mr-2" }), vergelijk.isPending ? "Vergelijken…" : "Gelijk aan Floriday?"] }), _jsx(FloridayBriefHerprint, { orderId: orderId, size: "sm" })] })] }), gelijk?.ok && (gelijk.gelijk === true ? _jsxs("p", { className: "text-sm", children: [_jsx(CheckCircle2, { className: "inline h-4 w-4 mr-1" }), "Gelijk aan Floriday."] })
|
|
74
|
+
: gelijk.gelijk == null ? _jsx("p", { className: "text-sm text-muted-foreground", children: gelijk.melding ?? "Nog niet te vergelijken." })
|
|
75
|
+
: (_jsxs("div", { className: "text-sm", children: [_jsx("p", { className: "font-medium", children: "Niet gelijk aan Floriday:" }), _jsx("ul", { className: "list-disc pl-5", children: (gelijk.verschillen ?? []).map((v, i) => (_jsxs("li", { children: [v.ladingdrager ? `Ladingdrager ${v.ladingdrager}: ` : "", VELD[v.veld] ?? v.veld, v.onze != null || v.floriday != null ? ` – bij ons ${v.onze ?? "—"}, bij Floriday ${v.floriday ?? "—"}` : ""] }, i))) })] }))), flQ.isLoading && _jsx("p", { className: "text-sm text-muted-foreground", children: "Correcties bij Floriday ophalen\u2026" }), flQ.isError && _jsx("p", { className: "text-sm text-destructive", children: "De correcties bij Floriday konden niet worden opgehaald. Probeer het opnieuw." }), flQ.data && !flQ.data.ok && _jsx("p", { className: "text-sm text-muted-foreground", children: flQ.data.melding }), flQ.data?.ok && (flQ.data.items.length === 0 ? _jsx("p", { className: "text-sm text-muted-foreground", children: "Floriday heeft geen correcties voor deze levering." }) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "Wanneer" }), _jsx(TableHead, { children: "Wat" }), _jsx(TableHead, { children: "Door" }), _jsx(TableHead, { children: "Stand" })] }) }), _jsx(TableBody, { children: flQ.data.items.map((x) => {
|
|
76
|
+
const st = standVanKoppeling(x.status);
|
|
77
|
+
return (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "whitespace-nowrap", children: fmt(x.aangemaakt) }), _jsxs(TableCell, { children: [FL_SOORT[x.soort] ?? x.soort, x.reden ? _jsx("div", { className: "text-xs text-muted-foreground", children: x.reden }) : null] }), _jsx(TableCell, { children: x.door ?? "—" }), _jsxs(TableCell, { children: [_jsx(Badge, { variant: st === "geslaagd" ? "default" : st === "mislukt" || st === "geweigerd" ? "destructive" : "secondary", children: STAND_TEKST[st] }), x.floridayReden && _jsx("div", { className: "text-xs text-muted-foreground", children: x.floridayReden })] })] }, x.id));
|
|
78
|
+
}) })] })))] }))] })), kar && (_jsx(CorrectieDialog, { open: true, onClose: () => setKar(null), orderId: orderId, cartId: kar === "kies" ? null : kar.cartId, partijen: kar === "kies" ? undefined : kar.partijen, karren: kar === "kies" ? karren : undefined, onKlaar: ververs }))] }) }));
|
|
79
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NuVersturenButton.d.ts","sourceRoot":"","sources":["../../../src/components/afhandeling/NuVersturenButton.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NuVersturenButton.d.ts","sourceRoot":"","sources":["../../../src/components/afhandeling/NuVersturenButton.tsx"],"names":[],"mappings":"AAiBA,wFAAwF;AAExF,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,KAAsB,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,+BAuJ3G"}
|
|
@@ -8,6 +8,7 @@ import { Send, Loader2, CheckCircle2, XCircle } from "lucide-react";
|
|
|
8
8
|
import { prepareFloridayLoading, sendFloridayLoading, } from "../../lib/floridayLoading.functions.js";
|
|
9
9
|
import { platenTekst } from "../../lib/extraPlaten.js";
|
|
10
10
|
import { label as labelFor } from "../../lib/labels.js";
|
|
11
|
+
import { beoordeelSend, terugkoppelingRegel } from "../../lib/floridayTerugkoppeling.js";
|
|
11
12
|
/** "Nu versturen": toont eerst een samenvatting met controles en vraagt bevestiging. */
|
|
12
13
|
export function NuVersturenButton({ orderRef, label = "Nu versturen" }) {
|
|
13
14
|
const prepare = useServerFn(prepareFloridayLoading);
|
|
@@ -15,7 +16,7 @@ export function NuVersturenButton({ orderRef, label = "Nu versturen" }) {
|
|
|
15
16
|
const [loading, setLoading] = useState(false);
|
|
16
17
|
const [sending, setSending] = useState(false);
|
|
17
18
|
const [preview, setPreview] = useState(null);
|
|
18
|
-
const [sent, setSent] = useState(
|
|
19
|
+
const [sent, setSent] = useState(null);
|
|
19
20
|
const queryClient = useQueryClient();
|
|
20
21
|
const load = async () => setPreview(await prepare({ data: { orderRef } }));
|
|
21
22
|
const meldFout = (e, standaard) => {
|
|
@@ -43,17 +44,36 @@ export function NuVersturenButton({ orderRef, label = "Nu versturen" }) {
|
|
|
43
44
|
try {
|
|
44
45
|
const r = await send({ data: { orderRef } });
|
|
45
46
|
const results = Array.isArray(r?.results) ? r.results : [];
|
|
46
|
-
|
|
47
|
+
if (!results.length) {
|
|
48
|
+
toast.error("Er is niets verstuurd: de opdracht was leeg. Neem contact op met de beheerder.");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
let allOk = true;
|
|
52
|
+
let stand = "verstuurd";
|
|
47
53
|
for (const x of results) {
|
|
48
|
-
|
|
54
|
+
const soort = beoordeelSend(x.httpStatus, { ok: x.httpStatus === 200, code: x.code }).soort;
|
|
55
|
+
if (soort === "geaccepteerd")
|
|
49
56
|
toast.success(x.message);
|
|
57
|
+
else if (soort === "wacht_op_akkoord") {
|
|
58
|
+
toast.info(x.message);
|
|
59
|
+
stand = "wacht";
|
|
60
|
+
}
|
|
61
|
+
else if (soort === "niet_verstuurd_uit") {
|
|
62
|
+
toast.warning(x.message);
|
|
63
|
+
if (stand !== "wacht")
|
|
64
|
+
stand = "uit";
|
|
65
|
+
}
|
|
66
|
+
else if (soort === "later_opnieuw" || soort === "al_bezig" || soort === "tegengehouden") {
|
|
67
|
+
allOk = false;
|
|
68
|
+
toast.warning(x.message);
|
|
69
|
+
}
|
|
50
70
|
else {
|
|
51
71
|
allOk = false;
|
|
52
72
|
meldFout(new Error(x.message), "Versturen mislukt");
|
|
53
73
|
}
|
|
54
74
|
}
|
|
55
75
|
if (allOk) {
|
|
56
|
-
setSent(
|
|
76
|
+
setSent(stand);
|
|
57
77
|
setPreview(null);
|
|
58
78
|
void queryClient.invalidateQueries();
|
|
59
79
|
return;
|
|
@@ -69,9 +89,14 @@ export function NuVersturenButton({ orderRef, label = "Nu versturen" }) {
|
|
|
69
89
|
};
|
|
70
90
|
return (_jsxs(_Fragment, { children: [_jsxs(Button, { size: "sm", variant: "outline", onClick: open, disabled: loading, children: [loading ? _jsx(Loader2, { className: "h-3 w-3 mr-1 animate-spin" }) : _jsx(Send, { className: "h-3 w-3 mr-1" }), label] }), _jsx(AlertDialog, { open: !!preview, onOpenChange: (o) => !o && !sending && setPreview(null), children: _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: "Belading naar Floriday versturen?" }), _jsx(AlertDialogDescription, { children: "Na versturen maakt Floriday de verzendbrief, vooraanmelding en fustafrekening. Dit kun je niet terugdraaien." })] }), preview && (_jsxs("div", { className: "space-y-2 text-sm", children: [_jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "Orders:" }), " ", preview.orderRefs.join(", ")] }), _jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "Leveringen:" }), " ", preview.shipments.length] }), _jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "Karren:" }), " ", preview.cartCount, preview.carriers.some((c) => c.shared) ? " (waarvan gedeeld)" : ""] }), Array.isArray(preview.carriers) && preview.carriers.length > 0 && (_jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "Karkenmerk naar Floriday:" }), " ", _jsx("ul", { className: "mt-1 space-y-0.5", children: preview.carriers.map((c, i) => (_jsxs("li", { children: [_jsx("span", { className: "font-mono", children: c.loadCarrierReference || "—" }), " \u00B7 ", c.karTekst ?? platenTekst(c.additionalLayers)] }, (c.loadCarrierReference || "") + i))) })] })), _jsxs("div", { children: [_jsx("span", { className: "text-muted-foreground", children: "Regels:" }), " ", preview.lineCount] }), _jsx("ul", { className: "space-y-1", children: preview.orders.map((o) => (_jsxs("li", { className: "flex items-center gap-2", children: [o.controlled
|
|
71
91
|
? _jsx(CheckCircle2, { className: "h-3.5 w-3.5 text-primary" })
|
|
72
|
-
: _jsx(XCircle, { className: "h-3.5 w-3.5 text-destructive" }), _jsxs("span", { children: [o.orderRef, ": ", o.cartsControlled, " van ", o.cartsTotal, " karren goedgekeurd op de Scan-controle", o.controlled ? " — klaar voor verzending" : "", !o.controlled && o.pickStatus && o.pickStatus !== "geen_pickrij" ? ` · ${labelFor("pickStatus", o.pickStatus)}` : "", o.autoStatus ? ` · auto-verwerking: ${o.autoStatus}` : ""] })] }, o.orderRef))) }), preview.shipments.filter((sh) => sh.floridayStatus || preview.lastAttempts.some((a) => a.fulfillmentOrderId === sh.fulfillmentOrderId && (a.code === "created" || a.code === "already_fulfilled"))).map((sh) => (_jsxs("div", { className: "rounded border border-border p-2", children: ["Gemeld bij Floriday", sh.floridayStatus ? ` (Floriday: ${sh.floridayStatus})` : "", " \u00B7", " ", sh.deliveryNoteReady === true ? "verzendbrief klaar" : "verzendbrief wordt automatisch geprint"] }, sh.fulfillmentOrderId))), preview.
|
|
92
|
+
: _jsx(XCircle, { className: "h-3.5 w-3.5 text-destructive" }), _jsxs("span", { children: [o.orderRef, ": ", o.cartsControlled, " van ", o.cartsTotal, " karren goedgekeurd op de Scan-controle", o.controlled ? " — klaar voor verzending" : "", !o.controlled && o.pickStatus && o.pickStatus !== "geen_pickrij" ? ` · ${labelFor("pickStatus", o.pickStatus)}` : "", o.autoStatus ? ` · auto-verwerking: ${o.autoStatus}` : ""] })] }, o.orderRef))) }), preview.shipments.filter((sh) => sh.floridayStatus || preview.lastAttempts.some((a) => a.fulfillmentOrderId === sh.fulfillmentOrderId && (a.code === "created" || a.code === "already_fulfilled"))).map((sh) => (_jsxs("div", { className: "rounded border border-border p-2", children: ["Gemeld bij Floriday", sh.floridayStatus ? ` (Floriday: ${sh.floridayStatus})` : "", " \u00B7", " ", sh.deliveryNoteReady === true ? "verzendbrief klaar" : "verzendbrief wordt automatisch geprint"] }, sh.fulfillmentOrderId))), preview.shipments.map((sh) => {
|
|
93
|
+
if (!sh.terugkoppeling)
|
|
94
|
+
return sh.terugkoppelingFout ? _jsx("div", { className: "text-destructive", children: sh.terugkoppelingFout }, `tk-${sh.fulfillmentOrderId}`) : null;
|
|
95
|
+
const r = terugkoppelingRegel(sh.terugkoppeling);
|
|
96
|
+
return (_jsxs("div", { children: [_jsx("div", { className: r.toon === "fout" ? "text-destructive" : r.toon === "ok" ? "text-primary" : "text-foreground", children: r.tekst }), sh.terugkoppelingFout ? _jsx("div", { className: "text-destructive", children: sh.terugkoppelingFout }) : null] }, `tk-${sh.fulfillmentOrderId}`));
|
|
97
|
+
}), preview.lastAttempts.length > 0 && (_jsxs("div", { className: "rounded border border-border p-2", children: [_jsx("div", { className: "text-muted-foreground mb-1", children: "Laatste pogingen" }), preview.lastAttempts.slice(0, 4).map((a) => (_jsxs("div", { children: [fmtDayTime(a.createdAt), " \u00B7 versturen \u00B7 ", a.code === "created" || a.code === "already_fulfilled" ? "geaccepteerd" : (a.message ?? a.code)?.replace(/\s*\[[^\]]+\]$/, "")] }, a.createdAt + a.step)))] })), preview.blockers.length > 0 && (_jsx("ul", { className: "list-disc pl-5 text-destructive", children: preview.blockers.map((b) => {
|
|
73
98
|
// Begrijpelijke zin, technische code klein eronder.
|
|
74
99
|
const m = /^(.*?)\s*\[([^\]]+)\]$/s.exec(b);
|
|
75
100
|
return (_jsxs("li", { children: [m ? m[1] : b, m ? _jsx("div", { className: "text-xs text-muted-foreground", children: m[2] }) : null] }, b));
|
|
76
|
-
}) }))] })), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { disabled: sending, children: "Annuleren" }), _jsxs(Button, { onClick: doSend, disabled: !preview?.canSend || sending || sent, children: [sending ? _jsx(Loader2, { className: "h-3 w-3 mr-1 animate-spin" }) : null, sent ? "Gemeld bij Floriday" : "Versturen"] })] })] }) })] }));
|
|
101
|
+
}) }))] })), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { disabled: sending, children: "Annuleren" }), _jsxs(Button, { onClick: doSend, disabled: !preview?.canSend || sending || !!sent, children: [sending ? _jsx(Loader2, { className: "h-3 w-3 mr-1 animate-spin" }) : null, sent === "wacht" ? "Wacht op akkoord" : sent === "uit" ? "Niet verstuurd (uit)" : sent ? "Gemeld bij Floriday" : "Versturen"] })] })] }) })] }));
|
|
77
102
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** In de controle: orderverloop, documenten en kar-tekening uit de Engine (alleen lezen, plus CMR opnieuw printen). */
|
|
2
|
+
export declare function OrderInzicht({ orderId, cartId }: {
|
|
3
|
+
orderId: string;
|
|
4
|
+
cartId?: string | null;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
//# sourceMappingURL=OrderInzicht.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrderInzicht.d.ts","sourceRoot":"","sources":["../../../src/components/afhandeling/OrderInzicht.tsx"],"names":[],"mappings":"AAwBA,uHAAuH;AACvH,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,+BAwI5F"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { Badge, Button, toast } from "@flowselections/core";
|
|
4
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
5
|
+
import { AlertTriangle, CheckCircle2, Circle, Printer } from "lucide-react";
|
|
6
|
+
import { supabase } from "../../integrations/supabase/moduleClient.js";
|
|
7
|
+
import { leesCmrMelding, leesDocumenten, leesTijdlijn, veiligeSvg } from "../../lib/orderInzicht.js";
|
|
8
|
+
const tijdNl = (iso) => {
|
|
9
|
+
if (!iso)
|
|
10
|
+
return null;
|
|
11
|
+
const d = new Date(iso);
|
|
12
|
+
return Number.isNaN(d.getTime()) ? null
|
|
13
|
+
: d.toLocaleString("nl-NL", { timeZone: "Europe/Amsterdam", weekday: "short", day: "numeric", month: "short", hour: "2-digit", minute: "2-digit" });
|
|
14
|
+
};
|
|
15
|
+
const KLEUR = { groen: "default", oranje: "destructive", grijs: "outline" };
|
|
16
|
+
function SvgTekening({ svg, titel }) {
|
|
17
|
+
const veilig = useMemo(() => veiligeSvg(svg), [svg]);
|
|
18
|
+
if (!veilig)
|
|
19
|
+
return _jsx("div", { className: "text-xs text-muted-foreground", children: "Tekening niet beschikbaar." });
|
|
20
|
+
return _jsx("div", { role: "img", "aria-label": titel, className: "w-full [&_svg]:h-auto [&_svg]:w-full", dangerouslySetInnerHTML: { __html: veilig } });
|
|
21
|
+
}
|
|
22
|
+
/** In de controle: orderverloop, documenten en kar-tekening uit de Engine (alleen lezen, plus CMR opnieuw printen). */
|
|
23
|
+
export function OrderInzicht({ orderId, cartId }) {
|
|
24
|
+
const qc = useQueryClient();
|
|
25
|
+
const tijdlijnQ = useQuery({
|
|
26
|
+
queryKey: ["logistics-order-tijdlijn", orderId],
|
|
27
|
+
queryFn: async () => {
|
|
28
|
+
const { data, error } = await supabase.rpc("logistics_order_tijdlijn", { p_order_id: orderId });
|
|
29
|
+
if (error)
|
|
30
|
+
throw new Error(error.message);
|
|
31
|
+
return leesTijdlijn(data);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const docsQ = useQuery({
|
|
35
|
+
queryKey: ["logistics-order-documenten", orderId],
|
|
36
|
+
queryFn: async () => {
|
|
37
|
+
const { data, error } = await supabase.rpc("logistics_order_documenten", { p_order_id: orderId });
|
|
38
|
+
if (error)
|
|
39
|
+
throw new Error(error.message);
|
|
40
|
+
return leesDocumenten(data);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const tekeningQ = useQuery({
|
|
44
|
+
queryKey: ["logistics-kar-tekening-v2", orderId],
|
|
45
|
+
queryFn: async () => {
|
|
46
|
+
const { data, error } = await supabase.rpc("logistics_kar_tekening_v2", { p_order_id: orderId, p_variant: "scherm", p_opties: {} });
|
|
47
|
+
if (error)
|
|
48
|
+
throw new Error(error.message);
|
|
49
|
+
return (data ?? {});
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
// Open CMR-melding van deze zending (bv. geen printer op de printplek), bewaard door afh_cmr_printen.
|
|
53
|
+
const cmrMeldingQ = useQuery({
|
|
54
|
+
queryKey: ["afh-cmr-melding", orderId],
|
|
55
|
+
queryFn: async () => {
|
|
56
|
+
const { data, error } = await supabase.rpc("afh_cmr_melding", { p_order_id: orderId });
|
|
57
|
+
if (error)
|
|
58
|
+
throw new Error(error.message);
|
|
59
|
+
return leesCmrMelding(data);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const cmrM = useMutation({
|
|
63
|
+
mutationFn: async () => {
|
|
64
|
+
const { data, error } = await supabase.rpc("afh_cmr_printen", { p_order_id: orderId, p_herprint: true });
|
|
65
|
+
if (error)
|
|
66
|
+
throw new Error(error.message);
|
|
67
|
+
return data;
|
|
68
|
+
},
|
|
69
|
+
onSuccess: (r) => {
|
|
70
|
+
(r?.ok ? toast.success : toast.error)(r?.melding ?? (r?.ok ? "CMR is naar de printer gestuurd." : "CMR niet geprint."));
|
|
71
|
+
void qc.invalidateQueries({ queryKey: ["logistics-order-documenten", orderId] });
|
|
72
|
+
void qc.invalidateQueries({ queryKey: ["afh-cmr-melding", orderId] });
|
|
73
|
+
void qc.invalidateQueries({ queryKey: ["afh-cmr-aandacht"] });
|
|
74
|
+
},
|
|
75
|
+
onError: (e) => { console.error("[cmr]", e); toast.error("CMR printen is niet gelukt. Probeer het opnieuw of neem contact op met de beheerder."); },
|
|
76
|
+
});
|
|
77
|
+
const t = tijdlijnQ.data;
|
|
78
|
+
const docs = docsQ.data;
|
|
79
|
+
const tek = tekeningQ.data;
|
|
80
|
+
return (_jsxs("div", { className: "space-y-4 border-t pt-3", children: [_jsxs("section", { className: "space-y-2", children: [_jsx("div", { className: "text-sm font-medium", children: "Orderverloop" }), tijdlijnQ.isLoading ? _jsx("p", { className: "text-sm text-muted-foreground", children: "Laden\u2026" })
|
|
81
|
+
: tijdlijnQ.isError || !t?.ok ? _jsx("p", { className: "text-sm text-destructive", children: t?.reden ?? "Het orderverloop kon niet worden opgehaald." })
|
|
82
|
+
: (_jsx("ol", { className: "flex flex-wrap gap-x-4 gap-y-2", children: t.stappen.map((s) => (_jsxs("li", { className: "flex items-start gap-1.5 text-sm", title: s.reden ?? undefined, children: [s.klaar ? _jsx(CheckCircle2, { className: "mt-0.5 h-4 w-4 text-primary", "aria-label": "klaar" }) : _jsx(Circle, { className: "mt-0.5 h-4 w-4 text-muted-foreground", "aria-label": "nog niet" }), _jsxs("span", { children: [_jsx("span", { className: s.klaar ? "font-medium" : "text-muted-foreground", children: s.naam }), tijdNl(s.tijd) && _jsx("span", { className: "block text-xs text-muted-foreground", children: tijdNl(s.tijd) })] })] }, s.stap))) })), t?.floriday && _jsx(Badge, { variant: KLEUR[t.floriday.kleur] ?? "outline", children: t.floriday.tekst })] }), _jsxs("section", { className: "space-y-2", children: [_jsx("div", { className: "text-sm font-medium", children: "Documenten" }), docsQ.isLoading ? _jsx("p", { className: "text-sm text-muted-foreground", children: "Laden\u2026" })
|
|
83
|
+
: docsQ.isError || !docs ? _jsx("p", { className: "text-sm text-destructive", children: "De documenten van deze order konden niet worden opgehaald." })
|
|
84
|
+
: (_jsx("ul", { className: "space-y-1 text-sm", children: docs.map((d) => (_jsxs("li", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "font-medium", children: d.naam }), _jsxs("span", { className: d.status === "mislukt" || d.status === "geen_layout" || d.status === "geblokkeerd" ? "text-destructive" : "text-muted-foreground", children: [d.statusTekst, d.printplek ? ` · ${d.printplek}` : ""] }), d.printplekReden && _jsx("span", { className: "text-destructive", children: d.printplekReden }), d.document === "cmr" && cmrMeldingQ.data && (_jsxs("span", { className: "flex items-center gap-1 text-destructive", children: [_jsx(AlertTriangle, { className: "h-4 w-4" }), cmrMeldingQ.data.melding] })), d.document === "cmr" && (_jsxs(Button, { size: "sm", variant: "outline", disabled: cmrM.isPending, onClick: () => cmrM.mutate(), children: [_jsx(Printer, { className: "h-4 w-4 mr-2" }), d.status === "geprint" ? "CMR opnieuw printen" : "CMR printen"] }))] }, d.document))) }))] }), _jsxs("section", { className: "space-y-2", children: [_jsx("div", { className: "text-sm font-medium", children: "Kar-tekening" }), tekeningQ.isLoading ? _jsx("p", { className: "text-sm text-muted-foreground", children: "Laden\u2026" })
|
|
85
|
+
: tekeningQ.isError || !tek?.ok ? _jsx("p", { className: "text-sm text-destructive", children: tek?.reden ?? "De kar-tekening kon niet worden opgehaald." })
|
|
86
|
+
: (_jsxs(_Fragment, { children: [(tek.meldingen ?? []).filter((m) => typeof m === "string").map((m) => (_jsx("p", { className: "text-sm text-muted-foreground", children: m }, m))), (tek.dragers ?? []).length === 0 ? _jsx("p", { className: "text-sm text-muted-foreground", children: "Geen ladingdragers bekend." }) : (_jsx("div", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4", children: (tek.dragers ?? []).map((d, i) => {
|
|
87
|
+
const deze = Boolean(cartId && d.id === cartId);
|
|
88
|
+
return (_jsxs("div", { className: `rounded-md border p-2 space-y-1 ${deze ? "border-primary ring-1 ring-primary" : ""}`, children: [_jsxs("div", { className: "flex items-center justify-between gap-1 text-xs", children: [_jsx("span", { className: "font-medium", children: d.label ?? d.naam ?? "Ladingdrager" }), deze && _jsx(Badge, { variant: "default", children: "Deze kar" })] }), d.svg ? _jsx(SvgTekening, { svg: d.svg, titel: d.label ?? "Ladingdrager" }) : _jsx("div", { className: "text-xs text-muted-foreground", children: "Geen tekening." }), d.markering_reden && (_jsxs("p", { className: "flex items-center gap-1 text-xs text-destructive", children: [_jsx(AlertTriangle, { className: "h-3 w-3" }), d.markering_reden] }))] }, d.id ?? i));
|
|
89
|
+
}) }))] }))] })] }));
|
|
90
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScanControleView.d.ts","sourceRoot":"","sources":["../../../src/components/afhandeling/ScanControleView.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ScanControleView.d.ts","sourceRoot":"","sources":["../../../src/components/afhandeling/ScanControleView.tsx"],"names":[],"mappings":"AAsGA,wBAAgB,gBAAgB,gCAke/B"}
|
|
@@ -3,8 +3,14 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
|
|
3
3
|
import { label } from "../../lib/labels.js";
|
|
4
4
|
import { supabase } from "../../integrations/supabase/moduleClient.js";
|
|
5
5
|
import { Button, Badge, Card, Input, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, toast, } from "@flowselections/core";
|
|
6
|
-
import { AlertTriangle, CheckCircle2, RefreshCw, ScanLine } from "lucide-react";
|
|
6
|
+
import { AlertTriangle, Camera, CheckCircle2, PencilLine, Printer, RefreshCw, ScanLine } from "lucide-react";
|
|
7
|
+
import { CameraScanner } from "./CameraScanner.js";
|
|
8
|
+
import { CorrectieDialog } from "./CorrectieDialog.js";
|
|
7
9
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
10
|
+
import { FloridayBriefHerprint } from "./FloridayBriefHerprint.js";
|
|
11
|
+
import { OrderInzicht } from "./OrderInzicht.js";
|
|
12
|
+
import { goedkeurMelding } from "../../lib/orderInzicht.js";
|
|
13
|
+
import { goedkeurFout, kloptNietUitkomst } from "../../lib/controleAfwijking.js";
|
|
8
14
|
const AFGEROND_STATUS = "geprint";
|
|
9
15
|
function statusVariant(status) {
|
|
10
16
|
if (status === AFGEROND_STATUS)
|
|
@@ -27,6 +33,10 @@ export function ScanControleView() {
|
|
|
27
33
|
const [barcode, setBarcode] = useState("");
|
|
28
34
|
const [lookup, setLookup] = useState(null);
|
|
29
35
|
const inputRef = useRef(null);
|
|
36
|
+
const [camera, setCamera] = useState(false);
|
|
37
|
+
const [correctie, setCorrectie] = useState(false);
|
|
38
|
+
// Beslismoment 6 staat uit en de controleur meldt dat de kar niet klopt: goedkeuren pas na opnieuw scannen.
|
|
39
|
+
const [klopNiet, setKlopNiet] = useState(false);
|
|
30
40
|
const settingsQ = useQuery({
|
|
31
41
|
queryKey: ["logistics-control-settings"],
|
|
32
42
|
queryFn: async () => {
|
|
@@ -122,19 +132,100 @@ export function ScanControleView() {
|
|
|
122
132
|
onSuccess: (res) => {
|
|
123
133
|
void qc.invalidateQueries({ queryKey: ["logistics-control-scan-overview"] });
|
|
124
134
|
if (!res.ok) {
|
|
125
|
-
|
|
126
|
-
|
|
135
|
+
const fout = goedkeurFout(res);
|
|
136
|
+
if (fout.kloptNiet) {
|
|
137
|
+
// De database weigert: er staat een melding "Kar klopt niet" open. Kar blijft zichtbaar, blokkade aan.
|
|
138
|
+
setKlopNiet(true);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
setLookup((prev) => (prev ? { ...prev, ...res } : res));
|
|
142
|
+
}
|
|
143
|
+
toast.error(fout.tekst);
|
|
127
144
|
return;
|
|
128
145
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
146
|
+
// Documenten na goedkeuren (afleverbrief eigen order, CMR bij export) volgens de Engine-documentenlijst; geen Engine-printopdracht nodig.
|
|
147
|
+
const orderId = res.orderId ?? lookup?.orderId ?? null;
|
|
148
|
+
if (!orderId) {
|
|
149
|
+
toast.error("Goedgekeurd, maar de order is onbekend; afleverbrief en CMR zijn niet geprint. Neem contact op met de beheerder.");
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
void (async () => {
|
|
153
|
+
const { data, error } = await supabase.rpc("afh_documenten_na_goedkeuren", {
|
|
154
|
+
p_order_id: orderId, p_cart_id: res.cart?.cartId ?? lookup?.cart?.cartId ?? null,
|
|
155
|
+
});
|
|
156
|
+
if (error)
|
|
157
|
+
throw new Error(error.message);
|
|
158
|
+
return data;
|
|
159
|
+
})()
|
|
160
|
+
.then((d) => {
|
|
161
|
+
const m = goedkeurMelding(d);
|
|
162
|
+
(m.fout ? toast.error : toast.success)(m.tekst);
|
|
163
|
+
void qc.invalidateQueries({ queryKey: ["afh-cmr-aandacht"] });
|
|
164
|
+
void qc.invalidateQueries({ queryKey: ["afh-cmr-melding", orderId] });
|
|
165
|
+
})
|
|
166
|
+
.catch((e) => { console.error("[documenten na goedkeuren]", e); toast.error("Goedgekeurd, maar de documenten zijn niet geprint. Print ze opnieuw of neem contact op met de beheerder."); });
|
|
167
|
+
}
|
|
132
168
|
setLookup(null);
|
|
133
169
|
setBarcode("");
|
|
134
170
|
inputRef.current?.focus();
|
|
135
171
|
},
|
|
136
172
|
onError: (err) => toast.error(err.message),
|
|
137
173
|
});
|
|
174
|
+
// Koppelprompt #36: "Kar klopt niet" vastleggen bij de Engine; de database weigert dan goedkeuren (stand uit).
|
|
175
|
+
const klopNietM = useMutation({
|
|
176
|
+
mutationFn: async (v) => {
|
|
177
|
+
const { data, error } = await supabase.rpc("logistics_control_klopt_niet", { p_barcode: v.code, p_reden: v.reden });
|
|
178
|
+
if (error)
|
|
179
|
+
throw new Error(error.message);
|
|
180
|
+
return (data ?? null);
|
|
181
|
+
},
|
|
182
|
+
onSuccess: (res) => {
|
|
183
|
+
const u = kloptNietUitkomst(res);
|
|
184
|
+
if (!u.vastgelegd)
|
|
185
|
+
console.error("[kar klopt niet] niet vastgelegd", res);
|
|
186
|
+
setKlopNiet(u.blokkeer);
|
|
187
|
+
(u.vastgelegd ? toast.info : toast.error)(u.tekst);
|
|
188
|
+
},
|
|
189
|
+
onError: (err) => {
|
|
190
|
+
console.error("[kar klopt niet]", err);
|
|
191
|
+
setKlopNiet(true);
|
|
192
|
+
toast.error(kloptNietUitkomst(null).tekst);
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
// Kar opnieuw gescand: open melding "Kar klopt niet" afhandelen bij de Engine.
|
|
196
|
+
const opnieuwM = useMutation({
|
|
197
|
+
mutationFn: async (code) => {
|
|
198
|
+
const { data, error } = await supabase.rpc("logistics_control_opnieuw_gescand", { p_barcode: code });
|
|
199
|
+
if (error)
|
|
200
|
+
throw new Error(error.message);
|
|
201
|
+
return (data ?? null);
|
|
202
|
+
},
|
|
203
|
+
onSuccess: (res) => {
|
|
204
|
+
if (!res || res.ok !== true) {
|
|
205
|
+
console.error("[kar opnieuw gescand]", res);
|
|
206
|
+
setKlopNiet(true);
|
|
207
|
+
toast.error(`Het opnieuw scannen is niet vastgelegd${res?.reden || res?.error ? `: ${res.reden ?? res.error}` : ""}. Scan de kar nog een keer.`);
|
|
208
|
+
}
|
|
209
|
+
else if ((res.afgehandeld ?? 0) > 0) {
|
|
210
|
+
toast.success('De melding "Kar klopt niet" is afgehandeld. Je kunt de kar nu goedkeuren.');
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
onError: (err) => {
|
|
214
|
+
console.error("[kar opnieuw gescand]", err);
|
|
215
|
+
setKlopNiet(true);
|
|
216
|
+
toast.error("Het opnieuw scannen is niet vastgelegd. Scan de kar nog een keer of neem contact op met de beheerder.");
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
const briefM = useMutation({
|
|
220
|
+
mutationFn: async (v) => {
|
|
221
|
+
if (!v.orderId)
|
|
222
|
+
return { ok: false, melding: "Order onbekend; de afleverbrief is niet geprint." };
|
|
223
|
+
const { data, error } = await supabase.rpc("afh_afleverbrief_printen", { p_order_id: v.orderId, p_cart_id: v.cartId, p_herprint: v.herprint });
|
|
224
|
+
if (error)
|
|
225
|
+
throw new Error(error.message);
|
|
226
|
+
return data;
|
|
227
|
+
},
|
|
228
|
+
});
|
|
138
229
|
const retryM = useMutation({
|
|
139
230
|
mutationFn: async (id) => {
|
|
140
231
|
const { data, error } = await supabase.rpc("logistics_control_scan_retry", { _id: id });
|
|
@@ -151,7 +242,7 @@ export function ScanControleView() {
|
|
|
151
242
|
},
|
|
152
243
|
onError: (err) => toast.error(err.message),
|
|
153
244
|
});
|
|
154
|
-
const bezig = lookupM.isPending || approveM.isPending;
|
|
245
|
+
const bezig = lookupM.isPending || approveM.isPending || opnieuwM.isPending || klopNietM.isPending;
|
|
155
246
|
const rows = overviewQ.data ?? [];
|
|
156
247
|
const stats = useMemo(() => ({
|
|
157
248
|
totaal: rows.length,
|
|
@@ -164,7 +255,10 @@ export function ScanControleView() {
|
|
|
164
255
|
if (!c || !postKlaar)
|
|
165
256
|
return;
|
|
166
257
|
setLookup(null);
|
|
167
|
-
|
|
258
|
+
setKlopNiet(false);
|
|
259
|
+
// Echte scan (invoer of camera) = kar opnieuw gescand: daarna de Engine laten weten dat een open melding vervalt.
|
|
260
|
+
lookupM.mutate(c, { onSuccess: (res) => { if (res.ok)
|
|
261
|
+
opnieuwM.mutate(res.barcode ?? c); } });
|
|
168
262
|
}
|
|
169
263
|
if (settingsQ.isLoading) {
|
|
170
264
|
return _jsx("div", { className: "text-sm text-muted-foreground", children: "Controlepost laden\u2026" });
|
|
@@ -178,9 +272,12 @@ export function ScanControleView() {
|
|
|
178
272
|
: "printer voor de verzendbrief onbekend", settings?.printsShippingNote === false ? " · de controlepost print zelf geen verzendbrief" : ""] }), _jsxs(Card, { className: "p-4 space-y-3", children: [_jsxs("form", { className: "flex gap-2", onSubmit: (e) => {
|
|
179
273
|
e.preventDefault();
|
|
180
274
|
scan(barcode);
|
|
181
|
-
}, children: [_jsx(Input, { ref: inputRef, autoFocus: true, value: barcode, onChange: (e) => setBarcode(e.target.value), placeholder: "Scan de barcode op de pakbon\u2026", disabled: bezig }), _jsxs(Button, { type: "submit", disabled: bezig || !barcode.trim(), children: [_jsx(ScanLine, { className: "h-4 w-4 mr-2" }), lookupM.isPending ? "Zoeken…" : "Opzoeken"] })] }), lookup && !lookup.ok && (_jsx("div", { className: "rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive", children: lookup.error ?? "Deze barcode is niet herkend." })), lookup?.ok && (_jsxs("div", { className: "rounded-md border p-3 space-y-3", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "font-semibold", children: lookup.order?.orderNumber ?? "—" }), _jsx(Badge, { variant: lookup.isFloriday ? "default" : "outline", children: lookup.isFloriday ? "Floriday-order (FO)" : "Eigen order" }), _jsx(Badge, { variant: "secondary", children: cart?.cartLabel ?? "Kar onbekend" }), lookup.alreadyControlled && (_jsxs(Badge, { variant: "destructive", children: ["Al gecontroleerd \u2014 ", lookup.scan?.status] }))] }), _jsxs("div", { className: "text-sm text-muted-foreground", children: [lookup.order?.customerName ?? "—", cart?.cartNumber ? ` · karnummer ${cart.cartNumber}` : "", typeof cart?.occupancyPct === "number" ? ` · ${Math.round(cart.occupancyPct)}% vol` : ""] }), _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "Product" }), _jsx(TableHead, { className: "text-right", children: "Fusten" }), _jsx(TableHead, { className: "text-right", children: "Aantal" })] }) }), _jsx(TableBody, { children: (cart?.items ?? []).length === 0 ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 3, className: "text-sm text-muted-foreground", children: "Geen belading gevonden op deze kar." }) })) : ((cart?.items ?? []).map((it, i) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: it.productName ?? "—" }), _jsx(TableCell, { className: "text-right", children: it.crates ?? "—" }), _jsx(TableCell, { className: "text-right", children: it.quantity ?? "—" })] }, it.itemId ?? i)))) })] }), _jsxs("div", { className: "flex gap-2", children: [_jsxs(Button, { disabled: approveM.isPending, onClick: () => approveM.mutate({ code: lookup.barcode ?? barcode, allowReprint: false }), children: [_jsx(CheckCircle2, { className: "h-4 w-4 mr-2" }), approveM.isPending ? "Bezig…" : "Goedkeuren"] }), lookup.alreadyControlled && (_jsx(Button, { variant: "outline", disabled:
|
|
275
|
+
}, children: [_jsx(Input, { ref: inputRef, autoFocus: true, value: barcode, onChange: (e) => setBarcode(e.target.value), placeholder: "Scan de barcode op de pakbon\u2026", disabled: bezig }), _jsx(Button, { type: "button", variant: "outline", disabled: bezig, onClick: () => setCamera(true), "aria-label": "Scan met de camera", children: _jsx(Camera, { className: "h-4 w-4" }) }), _jsxs(Button, { type: "submit", disabled: bezig || !barcode.trim(), children: [_jsx(ScanLine, { className: "h-4 w-4 mr-2" }), lookupM.isPending ? "Zoeken…" : "Opzoeken"] })] }), lookup && !lookup.ok && (_jsx("div", { className: "rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive", children: lookup.error ?? "Deze barcode is niet herkend." })), lookup?.ok && (_jsxs("div", { className: "rounded-md border p-3 space-y-3", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "font-semibold", children: lookup.order?.orderNumber ?? "—" }), _jsx(Badge, { variant: lookup.isFloriday ? "default" : "outline", children: lookup.isFloriday ? "Floriday-order (FO)" : "Eigen order" }), _jsx(Badge, { variant: "secondary", children: cart?.cartLabel ?? "Kar onbekend" }), lookup.alreadyControlled && (_jsxs(Badge, { variant: "destructive", children: ["Al gecontroleerd \u2014 ", lookup.scan?.status] }))] }), _jsxs("div", { className: "text-sm text-muted-foreground", children: [lookup.order?.customerName ?? "—", cart?.cartNumber ? ` · karnummer ${cart.cartNumber}` : "", typeof cart?.occupancyPct === "number" ? ` · ${Math.round(cart.occupancyPct)}% vol` : ""] }), _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "Product" }), _jsx(TableHead, { className: "text-right", children: "Fusten" }), _jsx(TableHead, { className: "text-right", children: "Aantal" })] }) }), _jsx(TableBody, { children: (cart?.items ?? []).length === 0 ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 3, className: "text-sm text-muted-foreground", children: "Geen belading gevonden op deze kar." }) })) : ((cart?.items ?? []).map((it, i) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: it.productName ?? "—" }), _jsx(TableCell, { className: "text-right", children: it.crates ?? "—" }), _jsx(TableCell, { className: "text-right", children: it.quantity ?? "—" })] }, it.itemId ?? i)))) })] }), klopNiet && (_jsxs("div", { className: "flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive", children: [_jsx(AlertTriangle, { className: "mt-0.5 h-4 w-4 shrink-0" }), _jsx("span", { children: "Goedkeuren kan pas als de kar klopt. Laad de ontbrekende fusten bij en scan de kar opnieuw." })] })), _jsxs("div", { className: "flex gap-2", children: [_jsxs(Button, { disabled: approveM.isPending || opnieuwM.isPending || klopNietM.isPending || klopNiet, onClick: () => approveM.mutate({ code: lookup.barcode ?? barcode, allowReprint: false }), children: [_jsx(CheckCircle2, { className: "h-4 w-4 mr-2" }), approveM.isPending ? "Bezig…" : "Goedkeuren"] }), lookup.alreadyControlled && lookup.isFloriday && lookup.orderId && (_jsx(FloridayBriefHerprint, { orderId: lookup.orderId })), lookup.alreadyControlled && !lookup.isFloriday && (_jsxs(Button, { variant: "outline", disabled: briefM.isPending, onClick: () => briefM.mutateAsync({ orderId: lookup.orderId ?? null, cartId: lookup.cart?.cartId ?? null, herprint: true })
|
|
276
|
+
.then((b) => (b.ok === false ? toast.error(b.melding ?? "Opnieuw printen is niet gelukt.") : toast.success(b.melding ?? "Opnieuw geprint.")))
|
|
277
|
+
.catch((e) => { console.error("[afleverbrief]", e); toast.error("Opnieuw printen is niet gelukt. Probeer het opnieuw."); }), children: [_jsx(Printer, { className: "h-4 w-4 mr-2" }), "Afleverbrief opnieuw printen"] })), lookup.orderId && (_jsxs(Button, { variant: "outline", onClick: () => setCorrectie(true), children: [_jsx(PencilLine, { className: "h-4 w-4 mr-2" }), "Corrigeren"] })), _jsx(Button, { variant: "ghost", disabled: approveM.isPending, onClick: () => {
|
|
182
278
|
setLookup(null);
|
|
279
|
+
setKlopNiet(false);
|
|
183
280
|
setBarcode("");
|
|
184
281
|
inputRef.current?.focus();
|
|
185
|
-
}, children: "Annuleren" })] })] }))] }), _jsxs("div", { className: "flex flex-wrap gap-3", children: [_jsxs(Card, { className: "p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: "Gescand vandaag" }), _jsx("div", { className: "text-2xl font-semibold", children: stats.totaal })] }), _jsxs(Card, { className: "p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: "Geprint" }), _jsx("div", { className: "text-2xl font-semibold", children: stats.geprint })] }), _jsxs(Card, { className: "p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: "In behandeling" }), _jsx("div", { className: "text-2xl font-semibold", children: stats.wacht })] }), _jsxs(Card, { className: "p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: "Mislukt" }), _jsx("div", { className: "text-2xl font-semibold", children: stats.mislukt })] })] }), _jsx(Card, { className: "p-0 overflow-hidden", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "Ordernummer" }), _jsx(TableHead, { children: "Soort" }), _jsx(TableHead, { children: "Status" }), _jsx(TableHead, { children: "Melding" }), _jsx(TableHead, { children: "Bijgewerkt" }), _jsx(TableHead, {})] }) }), _jsx(TableBody, { children: overviewQ.isLoading ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 6, className: "text-sm text-muted-foreground", children: "Laden\u2026" }) })) : rows.length === 0 ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 6, className: "text-sm text-muted-foreground", children: "Vandaag nog niets gescand." }) })) : (rows.map((r) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: r.orderNumber ?? "—" }), _jsx(TableCell, { children: r.isFloriday ? "FO" : "Eigen" }), _jsx(TableCell, { children: _jsx(Badge, { variant: statusVariant(r.status), children: label("scanStatus", r.status) }) }), _jsx(TableCell, { className: "text-sm text-muted-foreground", children: r.error ?? "—" }), _jsx(TableCell, { children: tijd(r.updatedAt) }), _jsx(TableCell, { className: "text-right", children: r.status === "mislukt" && (_jsxs(Button, { size: "sm", variant: "outline", disabled: retryM.isPending, onClick: () => retryM.mutate(r.id), children: [_jsx(RefreshCw, { className: "h-4 w-4 mr-2" }), "Opnieuw proberen"] })) })] }, r.id)))) })] }) })] }));
|
|
282
|
+
}, children: "Annuleren" })] }), lookup.orderId && _jsx(OrderInzicht, { orderId: lookup.orderId, cartId: lookup.cart?.cartId ?? null })] }))] }), _jsx(CameraScanner, { open: camera, onClose: () => setCamera(false), onScan: (c) => { setBarcode(c); scan(c); } }), correctie && lookup?.orderId && (_jsx(CorrectieDialog, { open: true, onClose: () => setCorrectie(false), orderId: lookup.orderId, cartId: lookup.cart?.cartId ?? null, partijen: (lookup.cart?.items ?? []).filter((i) => i.orderItemId && i.belongsToOrder !== false).map((i) => ({ orderItemId: i.orderItemId, naam: i.productName ?? "Partij", fusten: i.crates ?? 0 })), onKlaar: () => lookupM.mutate(lookup.barcode ?? barcode), onKlopNiet: (reden) => { setKlopNiet(true); klopNietM.mutate({ code: lookup.barcode ?? barcode, reden }); } })), _jsxs("div", { className: "flex flex-wrap gap-3", children: [_jsxs(Card, { className: "p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: "Gescand vandaag" }), _jsx("div", { className: "text-2xl font-semibold", children: stats.totaal })] }), _jsxs(Card, { className: "p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: "Geprint" }), _jsx("div", { className: "text-2xl font-semibold", children: stats.geprint })] }), _jsxs(Card, { className: "p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: "In behandeling" }), _jsx("div", { className: "text-2xl font-semibold", children: stats.wacht })] }), _jsxs(Card, { className: "p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: "Mislukt" }), _jsx("div", { className: "text-2xl font-semibold", children: stats.mislukt })] })] }), _jsx(Card, { className: "p-0 overflow-hidden", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "Ordernummer" }), _jsx(TableHead, { children: "Soort" }), _jsx(TableHead, { children: "Status" }), _jsx(TableHead, { children: "Melding" }), _jsx(TableHead, { children: "Bijgewerkt" }), _jsx(TableHead, {})] }) }), _jsx(TableBody, { children: overviewQ.isLoading ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 6, className: "text-sm text-muted-foreground", children: "Laden\u2026" }) })) : rows.length === 0 ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 6, className: "text-sm text-muted-foreground", children: "Vandaag nog niets gescand." }) })) : (rows.map((r) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: r.orderNumber ?? "—" }), _jsx(TableCell, { children: r.isFloriday ? "FO" : "Eigen" }), _jsx(TableCell, { children: _jsx(Badge, { variant: statusVariant(r.status), children: label("scanStatus", r.status) }) }), _jsx(TableCell, { className: "text-sm text-muted-foreground", children: r.error ?? "—" }), _jsx(TableCell, { children: tijd(r.updatedAt) }), _jsx(TableCell, { className: "text-right", children: r.status === "mislukt" && (_jsxs(Button, { size: "sm", variant: "outline", disabled: retryM.isPending, onClick: () => retryM.mutate(r.id), children: [_jsx(RefreshCw, { className: "h-4 w-4 mr-2" }), "Opnieuw proberen"] })) })] }, r.id)))) })] }) })] }));
|
|
186
283
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Stand van beslismoment 8 (Floriday-terugkoppeling) voor één levering; niets tonen = nog niet aangeboden. */
|
|
2
|
+
export declare function TerugkoppelingStand({ orderRef, deliveryOrderId }: {
|
|
3
|
+
orderRef?: string | null;
|
|
4
|
+
deliveryOrderId?: string | null;
|
|
5
|
+
}): import("react").JSX.Element | null;
|
|
6
|
+
//# sourceMappingURL=TerugkoppelingStand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TerugkoppelingStand.d.ts","sourceRoot":"","sources":["../../../src/components/afhandeling/TerugkoppelingStand.tsx"],"names":[],"mappings":"AAcA,+GAA+G;AAC/G,wBAAgB,mBAAmB,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,sCA+C/H"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { useServerFn } from "@tanstack/react-start";
|
|
5
|
+
import { CheckCircle2, Clock, AlertTriangle, Info } from "lucide-react";
|
|
6
|
+
import { floridayTerugkoppelingStand } from "../../lib/terugkoppeling.functions.js";
|
|
7
|
+
import { terugkoppelingRegel } from "../../lib/floridayTerugkoppeling.js";
|
|
8
|
+
const TOON = {
|
|
9
|
+
ok: { cls: "text-primary", Icon: CheckCircle2 },
|
|
10
|
+
wacht: { cls: "text-foreground", Icon: Clock },
|
|
11
|
+
fout: { cls: "text-destructive", Icon: AlertTriangle },
|
|
12
|
+
neutraal: { cls: "text-muted-foreground", Icon: Info },
|
|
13
|
+
};
|
|
14
|
+
/** Stand van beslismoment 8 (Floriday-terugkoppeling) voor één levering; niets tonen = nog niet aangeboden. */
|
|
15
|
+
export function TerugkoppelingStand({ orderRef, deliveryOrderId }) {
|
|
16
|
+
const lees = useServerFn(floridayTerugkoppelingStand);
|
|
17
|
+
const queryClient = useQueryClient();
|
|
18
|
+
const q = useQuery({
|
|
19
|
+
queryKey: ["floriday-terugkoppeling", deliveryOrderId ?? null, orderRef ?? null],
|
|
20
|
+
enabled: !!(orderRef || deliveryOrderId),
|
|
21
|
+
staleTime: 60000,
|
|
22
|
+
refetchInterval: 120000,
|
|
23
|
+
retry: 1,
|
|
24
|
+
queryFn: () => lees({ data: { orderRef: orderRef ?? null, deliveryOrderId: deliveryOrderId ?? null } }),
|
|
25
|
+
});
|
|
26
|
+
// Net vastgelegd als aangenomen (na akkoord verstuurd): dagoverzicht verversen, zodat "Nu versturen" verdwijnt.
|
|
27
|
+
const vastgelegd = q.data?.vastgelegd === true;
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (vastgelegd)
|
|
30
|
+
void queryClient.invalidateQueries({ queryKey: ["day-cart-contents"] });
|
|
31
|
+
}, [vastgelegd, queryClient]);
|
|
32
|
+
if (q.isError) {
|
|
33
|
+
console.error("[terugkoppeling] stand niet op te halen", q.error);
|
|
34
|
+
return _jsx("span", { className: "text-xs text-destructive", children: "Stand van de Floriday-terugkoppeling niet op te halen. Probeer het straks opnieuw." });
|
|
35
|
+
}
|
|
36
|
+
const d = q.data;
|
|
37
|
+
if (!d)
|
|
38
|
+
return null;
|
|
39
|
+
if (!d.ok) {
|
|
40
|
+
return (_jsxs("span", { className: "inline-flex items-center gap-1 text-xs text-muted-foreground", children: [_jsx(AlertTriangle, { className: "h-3 w-3", "aria-hidden": true }), d.melding] }));
|
|
41
|
+
}
|
|
42
|
+
if (!d.item)
|
|
43
|
+
return null;
|
|
44
|
+
const r = terugkoppelingRegel(d.item);
|
|
45
|
+
const { cls, Icon } = TOON[r.toon];
|
|
46
|
+
return (_jsxs("span", { className: "inline-flex flex-col gap-0.5", children: [_jsxs("span", { className: `inline-flex items-center gap-1 text-xs ${cls}`, children: [_jsx(Icon, { className: "h-3 w-3", "aria-hidden": true }), r.tekst] }), d.vastlegFout ? (_jsxs("span", { className: "inline-flex items-center gap-1 text-xs text-destructive", children: [_jsx(AlertTriangle, { className: "h-3 w-3", "aria-hidden": true }), d.vastlegFout] })) : null] }));
|
|
47
|
+
}
|