@flowselections/e-mail-installatie-techniek 1.0.7 → 1.4.1
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/README.md +68 -0
- package/dist-lib/components/WerkbonPostvakInstelling.d.ts +2 -0
- package/dist-lib/components/WerkbonPostvakInstelling.d.ts.map +1 -0
- package/dist-lib/components/WerkbonPostvakInstelling.js +76 -0
- package/dist-lib/components/mail/CompetentiePicker.d.ts +9 -0
- package/dist-lib/components/mail/CompetentiePicker.d.ts.map +1 -0
- package/dist-lib/components/mail/CompetentiePicker.js +49 -0
- package/dist-lib/components/mail/MailPane.d.ts.map +1 -1
- package/dist-lib/components/mail/MailPane.js +13 -9
- package/dist-lib/components/mail/WerkbonProposalDialog.d.ts.map +1 -1
- package/dist-lib/components/mail/WerkbonProposalDialog.js +32 -4
- package/dist-lib/components/mail/WerkbonProposalForm.d.ts +3 -1
- package/dist-lib/components/mail/WerkbonProposalForm.d.ts.map +1 -1
- package/dist-lib/components/mail/WerkbonProposalForm.js +180 -59
- package/dist-lib/hooks/useAutoAnalyse.d.ts.map +1 -1
- package/dist-lib/hooks/useAutoAnalyse.js +36 -25
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +4 -0
- package/dist-lib/integrations/supabase/previewAuthStorage.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/previewAuthStorage.js +2 -1
- package/dist-lib/integrations/supabase/types.d.ts +38687 -18814
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.js +2 -0
- package/dist-lib/lib/aantal-paginate.test.d.ts +2 -0
- package/dist-lib/lib/aantal-paginate.test.d.ts.map +1 -0
- package/dist-lib/lib/aantal-paginate.test.js +39 -0
- package/dist-lib/lib/aantal.d.ts +2 -0
- package/dist-lib/lib/aantal.d.ts.map +1 -0
- package/dist-lib/lib/aantal.js +10 -0
- package/dist-lib/lib/competenties.d.ts +12 -0
- package/dist-lib/lib/competenties.d.ts.map +1 -0
- package/dist-lib/lib/competenties.functions.d.ts +13 -0
- package/dist-lib/lib/competenties.functions.d.ts.map +1 -0
- package/dist-lib/lib/competenties.functions.js +22 -0
- package/dist-lib/lib/competenties.js +24 -0
- package/dist-lib/lib/competenties.test.d.ts +2 -0
- package/dist-lib/lib/competenties.test.d.ts.map +1 -0
- package/dist-lib/lib/competenties.test.js +15 -0
- package/dist-lib/lib/klant-match.d.ts +38 -0
- package/dist-lib/lib/klant-match.d.ts.map +1 -0
- package/dist-lib/lib/klant-match.js +88 -0
- package/dist-lib/lib/klant-match.test.d.ts +2 -0
- package/dist-lib/lib/klant-match.test.d.ts.map +1 -0
- package/dist-lib/lib/klant-match.test.js +76 -0
- package/dist-lib/lib/klanten.functions.d.ts +15 -0
- package/dist-lib/lib/klanten.functions.d.ts.map +1 -1
- package/dist-lib/lib/klanten.functions.js +75 -51
- package/dist-lib/lib/paginate.d.ts +10 -0
- package/dist-lib/lib/paginate.d.ts.map +1 -0
- package/dist-lib/lib/paginate.js +18 -0
- package/dist-lib/lib/rekenregels-gelijk.test.d.ts +2 -0
- package/dist-lib/lib/rekenregels-gelijk.test.d.ts.map +1 -0
- package/dist-lib/lib/rekenregels-gelijk.test.js +63 -0
- package/dist-lib/lib/rekenregels.d.ts +44 -0
- package/dist-lib/lib/rekenregels.d.ts.map +1 -0
- package/dist-lib/lib/rekenregels.js +159 -0
- package/dist-lib/lib/rekenregels.test.d.ts +2 -0
- package/dist-lib/lib/rekenregels.test.d.ts.map +1 -0
- package/dist-lib/lib/rekenregels.test.js +74 -0
- package/dist-lib/lib/werkbon-approve-rows.d.ts +64 -0
- package/dist-lib/lib/werkbon-approve-rows.d.ts.map +1 -0
- package/dist-lib/lib/werkbon-approve-rows.js +56 -0
- package/dist-lib/lib/werkbon-approve-rows.test.d.ts +2 -0
- package/dist-lib/lib/werkbon-approve-rows.test.d.ts.map +1 -0
- package/dist-lib/lib/werkbon-approve-rows.test.js +103 -0
- package/dist-lib/lib/werkbon-postvak-settings.d.ts +15 -0
- package/dist-lib/lib/werkbon-postvak-settings.d.ts.map +1 -0
- package/dist-lib/lib/werkbon-postvak-settings.functions.d.ts +14 -0
- package/dist-lib/lib/werkbon-postvak-settings.functions.d.ts.map +1 -0
- package/dist-lib/lib/werkbon-postvak-settings.functions.js +24 -0
- package/dist-lib/lib/werkbon-postvak-settings.js +59 -0
- package/dist-lib/lib/werkbon-proposals.functions.d.ts +38 -0
- package/dist-lib/lib/werkbon-proposals.functions.d.ts.map +1 -1
- package/dist-lib/lib/werkbon-proposals.functions.js +153 -93
- package/package.json +131 -7
- package/supabase/werkbon-postvak-installatie.sql +758 -0
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { parseBedragNaarCenten } from "../../lib/rekenregels";
|
|
4
|
+
import { parseAantal } from "../../lib/aantal";
|
|
3
5
|
import { Check, ChevronsUpDown, Plus, Search, Trash2, UserPlus } from "lucide-react";
|
|
4
6
|
import { Button, Input, Label, Popover, PopoverContent, PopoverTrigger, Textarea, } from "@flowselections/core";
|
|
5
7
|
import { useServerFn } from "@tanstack/react-start";
|
|
6
8
|
import { computeWerkbonTravel, getWerkbonLinesTotal, formatEuroCents, searchArtikelen, getArtikelFotos, } from "../../lib/werkbon-proposals.functions";
|
|
9
|
+
import { getKlantStatus } from "../../lib/klanten.functions";
|
|
10
|
+
import { CompetentiePicker } from "./CompetentiePicker";
|
|
7
11
|
function Section({ title, children }) {
|
|
8
12
|
return (_jsxs("section", { className: "space-y-3 rounded-md border border-border p-4", children: [_jsx("h3", { className: "text-sm font-semibold", children: title }), children] }));
|
|
9
13
|
}
|
|
@@ -30,13 +34,15 @@ function OptionPicker({ items, value, placeholder, noun, disabled, header, onSel
|
|
|
30
34
|
setOpen(next);
|
|
31
35
|
if (!next)
|
|
32
36
|
setSearch("");
|
|
33
|
-
}, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { type: "button", disabled: disabled, className: "flex h-9 w-full items-center justify-between rounded-md border border-input bg-background px-3 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", children: [_jsx("span", { className: selected
|
|
37
|
+
}, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { type: "button", disabled: disabled, className: "flex h-9 w-full items-center justify-between rounded-md border border-input bg-background px-3 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", children: [_jsx("span", { className: selected
|
|
38
|
+
? "flex min-w-0 items-center gap-2"
|
|
39
|
+
: "truncate text-muted-foreground", children: selected ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "truncate", children: selected.label }), selected.badge ? (_jsx("span", { className: "shrink-0 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-primary", children: selected.badge })) : null] })) : (placeholder) }), _jsx(ChevronsUpDown, { className: "ml-2 h-4 w-4 shrink-0 text-muted-foreground" })] }) }), _jsxs(PopoverContent, { align: "start", className: "z-[200] w-[--radix-popover-trigger-width] min-w-[16rem] p-0", children: [header ? _jsx("div", { className: "border-b border-border p-2", children: header(close) }) : null, _jsxs("div", { className: "flex items-center gap-2 border-b border-border px-3 py-2", children: [_jsx(Search, { className: "h-4 w-4 shrink-0 text-muted-foreground" }), _jsx("input", { value: search, onChange: (e) => setSearch(e.target.value), placeholder: `Zoek in ${safeItems.length} ${noun}…`, className: "h-7 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground" })] }), _jsxs("div", { className: "max-h-64 overflow-y-auto p-1", children: [_jsxs("button", { type: "button", onClick: () => {
|
|
34
40
|
onClear();
|
|
35
41
|
close();
|
|
36
42
|
}, className: "flex w-full items-center justify-between gap-2 rounded-sm px-3 py-2 text-left text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground", children: [_jsx("span", { children: "\u2014 Geen koppeling \u2014" }), value == null ? _jsx(Check, { className: "h-4 w-4 shrink-0" }) : null] }), safeItems.length === 0 ? (_jsxs("p", { className: "px-3 py-4 text-center text-sm text-muted-foreground", children: ["Er zijn nog geen ", noun, " ingericht."] })) : filtered.length === 0 ? (_jsxs("p", { className: "px-3 py-4 text-center text-sm text-muted-foreground", children: ["Geen ", noun, " gevonden."] })) : (filtered.map((item) => (_jsxs("button", { type: "button", onClick: () => {
|
|
37
43
|
onSelect(item.id);
|
|
38
44
|
close();
|
|
39
|
-
}, className: "flex w-full items-center justify-between gap-2 rounded-sm px-3 py-2 text-left text-sm hover:bg-accent hover:text-accent-foreground", children: [_jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "
|
|
45
|
+
}, className: "flex w-full items-center justify-between gap-2 rounded-sm px-3 py-2 text-left text-sm hover:bg-accent hover:text-accent-foreground", children: [_jsxs("span", { className: "min-w-0", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [_jsx("span", { className: "truncate", children: item.label }), item.badge ? (_jsx("span", { className: "shrink-0 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-primary", children: item.badge })) : null] }), item.hint ? (_jsx("span", { className: "block truncate text-xs text-muted-foreground", children: item.hint })) : null] }), item.id === value ? _jsx(Check, { className: "h-4 w-4 shrink-0" }) : null] }, item.id))))] })] })] }));
|
|
40
46
|
}
|
|
41
47
|
function CustomerPicker({ customers, value, onSelect, onClear, onNewCustomer, }) {
|
|
42
48
|
return (_jsx(OptionPicker, { items: customers, value: value, placeholder: "Kies klant\u2026", noun: "klanten", onSelect: onSelect, onClear: onClear, header: (close) => (_jsxs(Button, { type: "button", className: "w-full justify-start gap-2", onClick: () => {
|
|
@@ -179,12 +185,25 @@ function toDateInput(value) {
|
|
|
179
185
|
const d = new Date(value);
|
|
180
186
|
return Number.isNaN(d.getTime()) ? "" : d.toISOString().slice(0, 10);
|
|
181
187
|
}
|
|
182
|
-
export function WerkbonProposalForm({ value, options, saving, analysing = false, onChange, onConfirm, onReject, onNewCustomer, readOnly = false, }) {
|
|
188
|
+
export function WerkbonProposalForm({ value, options, saving, analysing = false, onChange, onConfirm, onReject, onNewCustomer, readOnly = false, showCompetenties = false, }) {
|
|
183
189
|
const lines = Array.isArray(value.lines) ? value.lines : [];
|
|
190
|
+
const [invalidFields, setInvalidFields] = useState(() => new Set());
|
|
191
|
+
const markInvalid = useCallback((key, bad) => {
|
|
192
|
+
setInvalidFields((prev) => {
|
|
193
|
+
if (prev.has(key) === bad)
|
|
194
|
+
return prev;
|
|
195
|
+
const next = new Set(prev);
|
|
196
|
+
if (bad)
|
|
197
|
+
next.add(key);
|
|
198
|
+
else
|
|
199
|
+
next.delete(key);
|
|
200
|
+
return next;
|
|
201
|
+
});
|
|
202
|
+
}, []);
|
|
184
203
|
// Totaal van pakketten + materialen t.o.v. het mandaat (prijzen uit de database).
|
|
185
204
|
const fetchTotal = useServerFn(getWerkbonLinesTotal);
|
|
186
205
|
const [totalCents, setTotalCents] = useState(null);
|
|
187
|
-
const linesKey = JSON.stringify(lines.map((l) => [l.line_type, l.package_id, (l.article_number ?? "").trim(), l.quantity]));
|
|
206
|
+
const linesKey = JSON.stringify(lines.map((l) => [l.line_type, l.package_id, (l.article_number ?? "").trim(), l.quantity, l.extra_quarters ?? 0]));
|
|
188
207
|
useEffect(() => {
|
|
189
208
|
let cancelled = false;
|
|
190
209
|
const t = setTimeout(() => {
|
|
@@ -204,8 +223,38 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
204
223
|
};
|
|
205
224
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
206
225
|
}, [linesKey]);
|
|
226
|
+
// Risico- / geblokkeerd-status van de gekozen klant.
|
|
227
|
+
const fetchKlantStatus = useServerFn(getKlantStatus);
|
|
228
|
+
const [klantStatus, setKlantStatus] = useState(null);
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
const id = value.customer_id;
|
|
231
|
+
if (!id) {
|
|
232
|
+
setKlantStatus(null);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
let cancelled = false;
|
|
236
|
+
fetchKlantStatus({ data: { customer_id: id } })
|
|
237
|
+
.then((r) => {
|
|
238
|
+
if (!cancelled)
|
|
239
|
+
setKlantStatus(r ?? null);
|
|
240
|
+
})
|
|
241
|
+
.catch(() => {
|
|
242
|
+
if (!cancelled)
|
|
243
|
+
setKlantStatus(null);
|
|
244
|
+
});
|
|
245
|
+
return () => {
|
|
246
|
+
cancelled = true;
|
|
247
|
+
};
|
|
248
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
249
|
+
}, [value.customer_id]);
|
|
250
|
+
const klantBlocked = klantStatus?.status === "blocked";
|
|
251
|
+
const klantRisk = klantStatus?.status === "risk";
|
|
252
|
+
const klantNotes = (() => {
|
|
253
|
+
const list = [klantStatus?.reason, ...(Array.isArray(klantStatus?.notes) ? klantStatus.notes : [])]
|
|
254
|
+
.filter((n) => !!n);
|
|
255
|
+
return Array.from(new Set(list));
|
|
256
|
+
})();
|
|
207
257
|
const mandateCents = Number(value.budget_mandate_cents ?? 0) || 0;
|
|
208
|
-
const showMandate = mandateCents > 0 && totalCents != null && totalCents >= mandateCents * 0.9;
|
|
209
258
|
const overMandate = mandateCents > 0 && totalCents != null ? Math.max(0, totalCents - mandateCents) : 0;
|
|
210
259
|
const pkgList = Array.isArray(options?.packages) ? options.packages : [];
|
|
211
260
|
// Alleen werktijd telt mee; reistijd uit rijpakketten niet.
|
|
@@ -215,11 +264,22 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
215
264
|
const p = pkgList.find((x) => x.id === l.package_id);
|
|
216
265
|
const m = Math.max(0, Number(p?.duration_minutes ?? 0) - Number(p?.travel_minutes ?? 0));
|
|
217
266
|
const q = l.quantity == null ? 1 : Number(l.quantity);
|
|
218
|
-
|
|
267
|
+
const extra = Math.max(0, Number(l.extra_quarters ?? 0) || 0) * 15;
|
|
268
|
+
return sum + (Number.isFinite(m) && Number.isFinite(q) ? m * q : 0) + extra;
|
|
219
269
|
}, 0);
|
|
220
270
|
// Reistijd automatisch berekenen en rijpakketten zetten.
|
|
221
271
|
const computeTravel = useServerFn(computeWerkbonTravel);
|
|
222
|
-
const travelPkg = pkgList.find((p) => (p.travel_minutes ?? 0) > 0) ?? null;
|
|
272
|
+
const travelPkg = pkgList.find((p) => (p.travel_minutes ?? 0) > 0 && !p.badge) ?? null;
|
|
273
|
+
// Reistijd die al in basispakketten zit (blijft altijd staan).
|
|
274
|
+
const basisTravel = lines.reduce((sum, l) => {
|
|
275
|
+
if (l.line_type !== "package" || !l.package_id)
|
|
276
|
+
return sum;
|
|
277
|
+
const p = pkgList.find((x) => x.id === l.package_id);
|
|
278
|
+
if (!p?.badge)
|
|
279
|
+
return sum;
|
|
280
|
+
const q = l.quantity == null ? 1 : Number(l.quantity) || 0;
|
|
281
|
+
return sum + (Number(p.travel_minutes ?? 0) || 0) * q;
|
|
282
|
+
}, 0);
|
|
223
283
|
const [travel, setTravel] = useState(null);
|
|
224
284
|
const latest = useRef({ lines, onChange });
|
|
225
285
|
latest.current = { lines, onChange };
|
|
@@ -238,35 +298,6 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
238
298
|
if (cancelled)
|
|
239
299
|
return;
|
|
240
300
|
setTravel(res);
|
|
241
|
-
const per = Number(travelPkg?.travel_minutes ?? 0);
|
|
242
|
-
if (!res?.round_trip_minutes || !travelPkg || per <= 0)
|
|
243
|
-
return;
|
|
244
|
-
const qty = Math.ceil(res.round_trip_minutes / per);
|
|
245
|
-
const cur = Array.isArray(latest.current.lines) ? latest.current.lines : [];
|
|
246
|
-
const idx = cur.findIndex((l) => l.line_type === "package" && l.package_id === travelPkg.id);
|
|
247
|
-
if (idx >= 0) {
|
|
248
|
-
if (cur[idx].quantity === qty)
|
|
249
|
-
return;
|
|
250
|
-
latest.current.onChange({
|
|
251
|
-
lines: cur.map((l, i) => (i === idx ? { ...l, quantity: qty } : l)),
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
latest.current.onChange({
|
|
256
|
-
lines: [
|
|
257
|
-
...cur,
|
|
258
|
-
{
|
|
259
|
-
line_type: "package",
|
|
260
|
-
package_id: travelPkg.id,
|
|
261
|
-
description: "",
|
|
262
|
-
article_number: "",
|
|
263
|
-
quantity: qty,
|
|
264
|
-
unit: "",
|
|
265
|
-
note: "Reistijd (automatisch)",
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
301
|
}
|
|
271
302
|
catch {
|
|
272
303
|
if (!cancelled)
|
|
@@ -279,6 +310,45 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
279
310
|
};
|
|
280
311
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
281
312
|
}, [address, value.technician_id, readOnly, travelPkg?.id]);
|
|
313
|
+
// Rijpakketten alleen voor de reistijd boven wat de basispakketten al dekken.
|
|
314
|
+
const roundTrip = travel?.round_trip_minutes ?? null;
|
|
315
|
+
useEffect(() => {
|
|
316
|
+
if (readOnly || !roundTrip || !travelPkg)
|
|
317
|
+
return;
|
|
318
|
+
const per = Number(travelPkg.travel_minutes ?? 0);
|
|
319
|
+
if (per <= 0)
|
|
320
|
+
return;
|
|
321
|
+
const qty = Math.ceil(Math.max(0, roundTrip - basisTravel) / per);
|
|
322
|
+
const cur = Array.isArray(latest.current.lines) ? latest.current.lines : [];
|
|
323
|
+
const idx = cur.findIndex((l) => l.line_type === "package" && l.package_id === travelPkg.id);
|
|
324
|
+
if (idx >= 0) {
|
|
325
|
+
if (qty === 0) {
|
|
326
|
+
latest.current.onChange({ lines: cur.filter((_, i) => i !== idx) });
|
|
327
|
+
}
|
|
328
|
+
else if (cur[idx].quantity !== qty) {
|
|
329
|
+
latest.current.onChange({
|
|
330
|
+
lines: cur.map((l, i) => (i === idx ? { ...l, quantity: qty } : l)),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else if (qty > 0) {
|
|
335
|
+
latest.current.onChange({
|
|
336
|
+
lines: [
|
|
337
|
+
...cur,
|
|
338
|
+
{
|
|
339
|
+
line_type: "package",
|
|
340
|
+
package_id: travelPkg.id,
|
|
341
|
+
description: "",
|
|
342
|
+
article_number: "",
|
|
343
|
+
quantity: qty,
|
|
344
|
+
unit: "",
|
|
345
|
+
note: "Reistijd (automatisch)",
|
|
346
|
+
},
|
|
347
|
+
],
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
351
|
+
}, [roundTrip, basisTravel, travelPkg?.id, readOnly]);
|
|
282
352
|
const applyLines = (next) => {
|
|
283
353
|
const diff = Math.round(packageMinutes(next) - packageMinutes(lines));
|
|
284
354
|
if (diff === 0) {
|
|
@@ -311,6 +381,7 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
311
381
|
};
|
|
312
382
|
const fetchFotos = useServerFn(getArtikelFotos);
|
|
313
383
|
const [fotos, setFotos] = useState({});
|
|
384
|
+
const [prijzen, setPrijzen] = useState({});
|
|
314
385
|
const packageLines = lines
|
|
315
386
|
.map((l, i) => ({ l, i }))
|
|
316
387
|
.filter(({ l }) => l.line_type === "package");
|
|
@@ -360,6 +431,14 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
360
431
|
next[c] = got[c] ?? "";
|
|
361
432
|
return next;
|
|
362
433
|
});
|
|
434
|
+
const gotP = res?.prijzen && typeof res.prijzen === "object" ? res.prijzen : {};
|
|
435
|
+
setPrijzen((pr) => {
|
|
436
|
+
const next = { ...pr };
|
|
437
|
+
for (const c of missing)
|
|
438
|
+
if (!(c in next))
|
|
439
|
+
next[c] = gotP[c] ?? null;
|
|
440
|
+
return next;
|
|
441
|
+
});
|
|
363
442
|
})
|
|
364
443
|
.catch(() => { });
|
|
365
444
|
return () => {
|
|
@@ -367,19 +446,13 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
367
446
|
};
|
|
368
447
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
369
448
|
}, [materialCodesKey]);
|
|
370
|
-
return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "min-h-0 flex-1 space-y-4 overflow-y-auto p-5", children: [_jsx("h2", { className: "text-base font-semibold", children: "Werkbonvoorstel" }),
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
} }) })] }), _jsxs(Section, { title: "Opdracht", children: [_jsx(Field, { label: "Klacht / melding", children: _jsx(Textarea, { rows: 4, value: value.complaint_description ?? "", placeholder: "Wat is er aan de hand?", onChange: (e) => onChange({ complaint_description: e.target.value || null }) }) }), _jsx(Field, { label: "Omschrijving voor de monteur", children: _jsx(Textarea, { rows: 4, value: value.technician_task_description ?? "", placeholder: "Wat moet er gebeuren?", onChange: (e) => onChange({ technician_task_description: e.target.value || null }) }) })] }), _jsxs(Section, { title: "Pakketten toevoegen", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { className: "text-xs text-muted-foreground", children: "Werkzaamheden" }), packageLines.length === 0 && (_jsx("p", { className: "text-xs text-muted-foreground", children: "Nog geen werkzaamheden." })), !readOnly && travel && (_jsx("p", { className: travel.error ? "text-xs text-destructive" : "text-xs text-muted-foreground", children: travel.error
|
|
449
|
+
return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "min-h-0 flex-1 space-y-4 overflow-y-auto p-5", children: [_jsx("h2", { className: "text-base font-semibold", children: "Werkbonvoorstel" }), (klantRisk || klantBlocked) && (_jsxs("div", { role: "alert", className: `rounded-md border p-3 text-sm ${klantBlocked
|
|
450
|
+
? "border-destructive/50 bg-destructive/10 text-destructive"
|
|
451
|
+
: "border-orange-400/60 bg-orange-500/10 text-orange-700 dark:text-orange-300"}`, children: [_jsx("p", { className: "font-semibold", children: klantBlocked ? "Deze klant is geblokkeerd" : "Let op: dit is een risicoklant" }), klantNotes.length > 0 && (_jsx("ul", { className: "mt-1 list-disc space-y-0.5 pl-5", children: klantNotes.map((n, i) => (_jsx("li", { children: n }, i))) }))] })), _jsxs(Section, { title: "Klant & locatie", children: [_jsxs(Field, { label: "Klant", required: true, empty: !value.customer_id, children: [_jsx(CustomerPicker, { customers: Array.isArray(options.customers) ? options.customers : [], value: value.customer_id, onSelect: (id) => onChange({ customer_id: id }), onClear: () => onChange({ customer_id: null }), onNewCustomer: onNewCustomer }), !value.customer_id && !readOnly && (_jsxs("div", { className: "mt-1.5 flex items-center justify-between gap-2", children: [_jsx("span", { className: "text-xs font-medium text-destructive", children: "Klant niet bekend" }), _jsxs(Button, { type: "button", size: "sm", variant: "outline", className: "gap-1.5", onClick: onNewCustomer, children: [_jsx(UserPlus, { className: "h-3.5 w-3.5" }), "Nieuwe klant toevoegen"] })] }))] }), _jsx(Field, { label: "Werkadres", children: _jsx(Input, { value: value.work_address ?? "", placeholder: "Straat, postcode, plaats", onChange: (e) => onChange({ work_address: e.target.value || null }) }) }), _jsx(Field, { label: "kamer/ruimte nummer", children: _jsx(Input, { value: value.room_number ?? "", placeholder: "Bijv. 2.14", onChange: (e) => onChange({ room_number: e.target.value || null }) }) })] }), _jsxs(Section, { title: "Project & referentie", children: [_jsx(Field, { label: "Externe referentie", children: _jsx(Input, { value: value.externe_referentie ?? "", placeholder: "Referentie van de klant", onChange: (e) => onChange({ externe_referentie: e.target.value || null }) }) }), _jsxs(Field, { label: "Budgetmandaat (\u20AC)", children: [_jsx(ParsedInput, { inputMode: "decimal", placeholder: "0", display: value.budget_mandate_cents == null
|
|
452
|
+
? ""
|
|
453
|
+
: (value.budget_mandate_cents / 100).toLocaleString("nl-NL", { minimumFractionDigits: 2, maximumFractionDigits: 2 }), parse: (t) => (t.trim() === "" ? null : parseBedragNaarCenten(t) ?? Number.NaN), invalidText: "Ongeldig bedrag, bijvoorbeeld 1.250,00", onInvalid: (bad) => markInvalid("mandaat", bad), onValue: (c) => onChange({ budget_mandate_cents: c }) }), mandateCents > 0 && (_jsx(MandaatBalk, { totalCents: totalCents ?? 0, mandateCents: mandateCents }))] })] }), _jsxs(Section, { title: "Opdracht", children: [_jsx(Field, { label: "Klacht / melding", children: _jsx(Textarea, { rows: 4, value: value.complaint_description ?? "", placeholder: "Wat is er aan de hand?", onChange: (e) => onChange({ complaint_description: e.target.value || null }) }) }), _jsx(Field, { label: "Omschrijving voor de monteur", children: _jsx(Textarea, { rows: 4, value: value.technician_task_description ?? "", placeholder: "Wat moet er gebeuren?", onChange: (e) => onChange({ technician_task_description: e.target.value || null }) }) })] }), _jsxs(Section, { title: "Pakketten toevoegen", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { className: "text-xs text-muted-foreground", children: "Werkzaamheden" }), packageLines.length === 0 && (_jsx("p", { className: "text-xs text-muted-foreground", children: "Nog geen werkzaamheden." })), !readOnly && travel && (_jsx("p", { className: travel.error ? "text-xs text-destructive" : "text-xs text-muted-foreground", children: travel.error
|
|
376
454
|
? travel.error
|
|
377
|
-
: `Reistijd: ${fmtMin(travel.one_way_minutes ?? 0)} enkele reis (${fmtMin(travel.round_trip_minutes ?? 0)} heen en terug) vanaf ${travel.origin_label ?? "de zaak"}` })), packageLines.map(({ l, i }) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_5rem_auto] gap-2 rounded-md border border-border p-3", children: [_jsxs("div", { className: "min-w-0 space-y-1", children: [_jsx(OptionPicker, { value: l.package_id, items: options.packages, placeholder: "Kies een werkzaamheid\u2026", noun: "werkzaamheden", onSelect: (id) => updateLine(i, { package_id: id, quantity: l.quantity ?? 1 }), onClear: () => updateLine(i, { package_id: null }) }), l.description && !l.package_id && (_jsxs("p", { className: "truncate text-xs text-muted-foreground", children: ["Uit de mail: ", l.description] }))] }), _jsx(
|
|
378
|
-
const n = Number(e.target.value);
|
|
379
|
-
updateLine(i, {
|
|
380
|
-
quantity: e.target.value === "" || Number.isNaN(n) ? null : n,
|
|
381
|
-
});
|
|
382
|
-
} }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "Regel verwijderen", onClick: () => applyLines(lines.filter((_, x) => x !== i)), children: _jsx(Trash2, { className: "h-4 w-4" }) })] }, `pkg-${i}`))), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => addLine("package"), children: [_jsx(Plus, { className: "mr-2 h-4 w-4" }), "Werkzaamheid toevoegen"] })] }), _jsxs("div", { className: "space-y-2 pt-2", children: [_jsx(Label, { className: "text-xs text-muted-foreground", children: "Materialen" }), materialLines.map(({ l, i }) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,2fr)_5rem_minmax(0,1fr)_auto] gap-2 rounded-md border border-border p-3", children: [_jsxs("div", { className: "min-w-0 space-y-1", children: [_jsx(ArtikelPicker, { value: l.description, disabled: readOnly, suggestQuery: l.description ||
|
|
455
|
+
: `Reistijd: ${fmtMin(travel.one_way_minutes ?? 0)} enkele reis (${fmtMin(travel.round_trip_minutes ?? 0)} heen en terug) vanaf ${travel.origin_label ?? "de zaak"}` })), packageLines.map(({ l, i }) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_5rem_auto] gap-2 rounded-md border border-border p-3", children: [_jsxs("div", { className: "min-w-0 space-y-1", children: [_jsx(OptionPicker, { value: l.package_id, items: options.packages, placeholder: "Kies een werkzaamheid\u2026", noun: "werkzaamheden", onSelect: (id) => updateLine(i, { package_id: id, quantity: l.quantity ?? 1 }), onClear: () => updateLine(i, { package_id: null }) }), l.description && !l.package_id && (_jsxs("p", { className: "truncate text-xs text-muted-foreground", children: ["Uit de mail: ", l.description] })), _jsx(PackageLineInfo, { line: l, pkg: pkgList.find((x) => x.id === l.package_id) ?? null, readOnly: !!readOnly, onQuarters: (q) => updateLine(i, { extra_quarters: q }) })] }), _jsx(ParsedInput, { inputMode: "decimal", placeholder: "Aantal", display: l.quantity == null ? "" : String(l.quantity).replace(".", ","), parse: parseAantal, invalidText: "Ongeldig aantal", onInvalid: (bad) => markInvalid(`pkg-${i}`, bad), onValue: (n) => updateLine(i, { quantity: n }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "Regel verwijderen", onClick: () => applyLines(lines.filter((_, x) => x !== i)), children: _jsx(Trash2, { className: "h-4 w-4" }) })] }, `pkg-${i}`))), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => addLine("package"), children: [_jsx(Plus, { className: "mr-2 h-4 w-4" }), "Werkzaamheid toevoegen"] })] }), _jsxs("div", { className: "space-y-2 pt-2", children: [_jsx(Label, { className: "text-xs text-muted-foreground", children: "Materialen" }), materialLines.map(({ l, i }) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,2fr)_5rem_minmax(0,1fr)_auto] gap-2 rounded-md border border-border p-3", children: [_jsxs("div", { className: "min-w-0 space-y-1", children: [_jsx(ArtikelPicker, { value: l.description, disabled: readOnly, suggestQuery: l.description ||
|
|
383
456
|
value.technician_task_description ||
|
|
384
457
|
value.complaint_description ||
|
|
385
458
|
"", onPick: (a) => {
|
|
@@ -387,18 +460,21 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
387
460
|
if (photoUrl && a.artikelcode) {
|
|
388
461
|
setFotos((f) => ({ ...f, [a.artikelcode]: photoUrl }));
|
|
389
462
|
}
|
|
463
|
+
if (a.artikelcode)
|
|
464
|
+
setPrijzen((pr) => ({ ...pr, [a.artikelcode]: a.prijs_cent ?? null }));
|
|
390
465
|
updateLine(i, {
|
|
391
466
|
description: a.naam || a.omschrijving || a.artikelcode,
|
|
392
467
|
article_number: a.artikelcode,
|
|
393
468
|
unit: a.eenheid || l.unit,
|
|
394
469
|
quantity: l.quantity ?? 1,
|
|
395
470
|
});
|
|
396
|
-
}, onFreeText: (t) => updateLine(i, { description: t }) }), l.article_number ? (_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsxs("p", { className: "truncate text-xs text-muted-foreground", children: ["Artikelcode: ", l.article_number
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
471
|
+
}, onFreeText: (t) => updateLine(i, { description: t }) }), l.article_number ? (_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsxs("p", { className: "truncate text-xs text-muted-foreground", children: ["Artikelcode: ", l.article_number, " · ", (() => {
|
|
472
|
+
const pc = prijzen[l.article_number];
|
|
473
|
+
if (pc == null)
|
|
474
|
+
return l.article_number in prijzen ? "geen prijs" : "";
|
|
475
|
+
const q = l.quantity == null ? 1 : Number(l.quantity) || 0;
|
|
476
|
+
return `${euro(pc)} × ${q} = ${euro(pc * q)}`;
|
|
477
|
+
})()] }), _jsx(ArtikelFoto, { url: fotos[l.article_number] ?? null, className: "h-8 w-8 shrink-0" })] })) : null] }), _jsx(ParsedInput, { inputMode: "decimal", placeholder: "Aantal", display: l.quantity == null ? "" : String(l.quantity).replace(".", ","), parse: parseAantal, invalidText: "Ongeldig aantal", onInvalid: (bad) => markInvalid(`mat-${i}`, bad), onValue: (n) => updateLine(i, { quantity: n }) }), _jsx(Input, { placeholder: "Eenheid", value: l.unit, onChange: (e) => updateLine(i, { unit: e.target.value }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "Regel verwijderen", onClick: () => applyLines(lines.filter((_, x) => x !== i)), children: _jsx(Trash2, { className: "h-4 w-4" }) })] }, `mat-${i}`))), !readOnly && (_jsxs("div", { className: "grid grid-cols-[minmax(0,2fr)_5rem_minmax(0,1fr)_auto] gap-2 rounded-md border border-border p-3", children: [_jsx("div", { className: "min-w-0", children: _jsx(ArtikelPicker, { value: "", suggestQuery: value.technician_task_description || value.complaint_description || "", onPick: (artikel) => {
|
|
402
478
|
const photoUrl = artikel.photo_url;
|
|
403
479
|
if (photoUrl && artikel.artikelcode) {
|
|
404
480
|
setFotos((current) => ({
|
|
@@ -411,12 +487,57 @@ export function WerkbonProposalForm({ value, options, saving, analysing = false,
|
|
|
411
487
|
estimated_duration_minutes: combineDuration(e.target.value, durationMinutes(value.estimated_duration_minutes)),
|
|
412
488
|
}) }), _jsx("span", { className: "text-xs text-muted-foreground", children: "uur" })] }), _jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(Input, { inputMode: "numeric", placeholder: "0", "aria-label": "Minuten", value: durationMinutes(value.estimated_duration_minutes), onChange: (e) => onChange({
|
|
413
489
|
estimated_duration_minutes: combineDuration(durationHours(value.estimated_duration_minutes), e.target.value),
|
|
414
|
-
}) }), _jsx("span", { className: "text-xs text-muted-foreground", children: "min" })] })] }) })] }), _jsx(Field, { label: "Monteur", children: _jsx(OptionPicker, { value: value.technician_id, items: options.technicians, placeholder: "Kies een monteur\u2026", noun: "monteurs", onSelect: (id) => onChange({ technician_id: id }), onClear: () => onChange({ technician_id: null }) }) })] }), _jsx(Section, { title: "Interne notities", children: _jsx(Textarea, { rows: 3, value: value.internal_notes ?? "", placeholder: "Alleen zichtbaar voor collega's", onChange: (e) => onChange({ internal_notes: e.target.value || null }) }) })] }), !readOnly &&
|
|
415
|
-
? "border-destructive/40 bg-destructive/10 text-destructive"
|
|
416
|
-
: "border-border bg-muted/50 text-muted-foreground"}`, children: ["Totaal: ", formatEuroCents(totalCents ?? 0), " van mandaat ", formatEuroCents(mandateCents), overMandate > 0 && (_jsxs("span", { className: "font-semibold", children: [" \u2014 ", formatEuroCents(overMandate), " boven het mandaat"] }))] })), !readOnly && (_jsxs("div", { className: "grid shrink-0 grid-cols-[minmax(0,1fr)_auto] gap-2 border-t border-border p-4", children: [_jsx(Button, { className: "w-full", onClick: onConfirm, disabled: saving ||
|
|
490
|
+
}) }), _jsx("span", { className: "text-xs text-muted-foreground", children: "min" })] })] }) })] }), _jsx(Field, { label: "Monteur", children: _jsx(OptionPicker, { value: value.technician_id, items: options.technicians, placeholder: "Kies een monteur\u2026", noun: "monteurs", onSelect: (id) => onChange({ technician_id: id }), onClear: () => onChange({ technician_id: null }) }) })] }), _jsx(Section, { title: "Interne notities", children: _jsx(Textarea, { rows: 3, value: value.internal_notes ?? "", placeholder: "Alleen zichtbaar voor collega's", onChange: (e) => onChange({ internal_notes: e.target.value || null }) }) }), showCompetenties && (_jsx(Section, { title: "Vereiste competenties", children: _jsx(CompetentiePicker, { value: value.vereiste_competentie_ids ?? [], disabled: readOnly || saving, onChange: (ids) => onChange({ vereiste_competentie_ids: ids }) }) }))] }), !readOnly && mandateCents > 0 && (_jsx("div", { className: "shrink-0 border-t border-border px-4 py-2", children: _jsx(MandaatBalk, { totalCents: totalCents ?? 0, mandateCents: mandateCents }) })), !readOnly && klantBlocked && (_jsxs("div", { className: "shrink-0 border-t border-destructive/40 bg-destructive/10 px-4 py-2 text-sm text-destructive", children: [_jsx("p", { className: "font-semibold", children: "Hier kan je geen werkbon van aanmaken" }), klantNotes[0] && _jsxs("p", { children: ["Reden: ", klantNotes[0]] })] })), !readOnly && (_jsxs("div", { className: "grid shrink-0 grid-cols-[minmax(0,1fr)_auto] gap-2 border-t border-border p-4", children: [_jsx(Button, { className: "w-full", onClick: onConfirm, disabled: saving ||
|
|
417
491
|
analysing ||
|
|
418
492
|
overMandate > 0 ||
|
|
493
|
+
klantBlocked ||
|
|
494
|
+
invalidFields.size > 0 ||
|
|
419
495
|
!value.customer_id ||
|
|
420
496
|
value.estimated_duration_minutes == null ||
|
|
421
497
|
value.estimated_duration_minutes <= 0, children: "Werkbon aanmaken" }), _jsx(Button, { variant: "outline", onClick: onReject, disabled: saving, children: "Afwijzen" })] }))] }));
|
|
422
498
|
}
|
|
499
|
+
const euro = (cents) => new Intl.NumberFormat("nl-NL", { style: "currency", currency: "EUR" }).format(cents / 100);
|
|
500
|
+
function PackageLineInfo({ line, pkg, readOnly, onQuarters, }) {
|
|
501
|
+
if (!pkg)
|
|
502
|
+
return null;
|
|
503
|
+
const qty = line.quantity == null ? 1 : Number(line.quantity) || 0;
|
|
504
|
+
const price = Number(pkg.price_cents ?? 0) || 0;
|
|
505
|
+
const isBasis = !!pkg.badge;
|
|
506
|
+
const quarters = Math.max(0, Number(line.extra_quarters ?? 0) || 0);
|
|
507
|
+
const qPrice = pkg.extra_quarter_price_cents;
|
|
508
|
+
const quartersCents = quarters * (Number(qPrice ?? 0) || 0);
|
|
509
|
+
const travel = Number(pkg.travel_minutes ?? 0) || 0;
|
|
510
|
+
const lineTotal = price * qty + quartersCents;
|
|
511
|
+
return (_jsxs("div", { className: "space-y-1 pt-1 text-xs text-muted-foreground", children: [_jsxs("p", { children: [euro(price), " \u00D7 ", qty, " = ", _jsx("span", { className: "font-medium text-foreground", children: euro(price * qty) }), travel > 0 ? ` · Reistijd: ${travel * qty} min` : ""] }), isBasis && (_jsxs("div", { className: "space-y-1 rounded-md bg-muted/50 p-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-foreground", children: "Extra kwartieren" }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "h-6 w-6", disabled: readOnly || quarters <= 0, onClick: () => onQuarters(quarters - 1 > 0 ? quarters - 1 : null), "aria-label": "Kwartier eraf", children: "\u2212" }), _jsx("span", { className: "w-6 text-center font-medium text-foreground", children: quarters }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "h-6 w-6", disabled: readOnly, onClick: () => onQuarters(quarters + 1), "aria-label": "Kwartier erbij", children: "+" })] }), quarters > 0 && (_jsxs("p", { children: [quarters, " \u00D7 15 min = ", quarters * 15, " min \u00B7", " ", qPrice == null
|
|
512
|
+
? "kwartierprijs niet ingesteld"
|
|
513
|
+
: `${quarters} × ${euro(qPrice)} = ${euro(quartersCents)}`] })), _jsxs("p", { children: ["Regeltotaal: ", _jsx("span", { className: "font-medium text-foreground", children: euro(lineTotal) })] })] }))] }));
|
|
514
|
+
}
|
|
515
|
+
function MandaatBalk({ totalCents, mandateCents }) {
|
|
516
|
+
const pct = mandateCents > 0 ? (totalCents / mandateCents) * 100 : 0;
|
|
517
|
+
const over = Math.max(0, totalCents - mandateCents);
|
|
518
|
+
const bar = pct > 100 ? "bg-destructive" : pct >= 75 ? "bg-orange-500" : "bg-primary";
|
|
519
|
+
const txt = pct > 100 ? "text-destructive" : pct >= 75 ? "text-orange-700" : "text-muted-foreground";
|
|
520
|
+
return (_jsxs("div", { className: "space-y-1 pt-1", children: [_jsxs("p", { className: `text-xs ${txt}`, children: [formatEuroCents(totalCents), " van ", formatEuroCents(mandateCents), " (", Math.round(pct), "%)", over > 0 && _jsxs("span", { className: "font-semibold", children: [" \u2014 ", formatEuroCents(over), " boven het mandaat"] })] }), _jsx("div", { className: "h-2 w-full overflow-hidden rounded-full bg-muted", children: _jsx("div", { className: `h-full ${bar} transition-all`, style: { width: `${Math.min(100, pct)}%` } }) })] }));
|
|
521
|
+
}
|
|
522
|
+
// Invoerveld dat de getypte tekst vasthoudt en pas een geldige waarde
|
|
523
|
+
// doorgeeft; ongeldige invoer geeft een melding en blokkeert aanmaken.
|
|
524
|
+
function ParsedInput({ display, parse, onValue, onInvalid, invalidText, placeholder, inputMode, }) {
|
|
525
|
+
const [text, setText] = useState(null);
|
|
526
|
+
const shown = text ?? display;
|
|
527
|
+
const parsed = text == null ? 0 : parse(text);
|
|
528
|
+
const bad = parsed != null && Number.isNaN(parsed);
|
|
529
|
+
useEffect(() => {
|
|
530
|
+
onInvalid(bad);
|
|
531
|
+
}, [bad, onInvalid]);
|
|
532
|
+
useEffect(() => () => onInvalid(false), [onInvalid]);
|
|
533
|
+
return (_jsxs("div", { className: "min-w-0", children: [_jsx(Input, { inputMode: inputMode, placeholder: placeholder, value: shown, "aria-invalid": bad || undefined, className: bad ? "border-destructive" : undefined, onChange: (e) => {
|
|
534
|
+
const t = e.target.value;
|
|
535
|
+
setText(t);
|
|
536
|
+
const n = parse(t);
|
|
537
|
+
if (n == null || !Number.isNaN(n))
|
|
538
|
+
onValue(n);
|
|
539
|
+
}, onBlur: () => {
|
|
540
|
+
if (!bad)
|
|
541
|
+
setText(null);
|
|
542
|
+
} }), bad && _jsx("p", { className: "mt-1 text-xs text-destructive", children: invalidText })] }));
|
|
543
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoAnalyse.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoAnalyse.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"useAutoAnalyse.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoAnalyse.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAC;AAU5C,wBAAgB,cAAc,CAC5B,KAAK,EAAE,UAAU,EAAE,EACnB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EACzC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,IAAI,GACjB,MAAM,EAAE,CAsGV"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { useEffect, useRef, useState } from "react";
|
|
6
6
|
import { useServerFn } from "@tanstack/react-start";
|
|
7
7
|
import { runAiChat } from "@flowselections/ai-authenticatie";
|
|
8
|
-
import { analyseWerkbonMail, getWerkbonProposalForMail, prepareWerkbonAnalyse, } from "../lib/werkbon-proposals.functions";
|
|
8
|
+
import { analyseWerkbonMail, claimWerkbonAnalyse, getWerkbonProposalForMail, prepareWerkbonAnalyse, } from "../lib/werkbon-proposals.functions";
|
|
9
9
|
// Per verversing maximaal zoveel nieuwe analyses, altijd één tegelijk,
|
|
10
10
|
// zodat de AI niet overbelast raakt en de kosten beperkt blijven.
|
|
11
11
|
const MAX_PER_BATCH = 5;
|
|
@@ -17,6 +17,7 @@ export function useAutoAnalyse(mails, summaries, enabled, onDone) {
|
|
|
17
17
|
const prepare = useServerFn(prepareWerkbonAnalyse);
|
|
18
18
|
const aiChat = useServerFn(runAiChat);
|
|
19
19
|
const applyAnalyse = useServerFn(analyseWerkbonMail);
|
|
20
|
+
const claim = useServerFn(claimWerkbonAnalyse);
|
|
20
21
|
const [analysingIds, setAnalysingIds] = useState([]);
|
|
21
22
|
const busyRef = useRef(false);
|
|
22
23
|
// Mails die we deze sessie al geprobeerd hebben niet opnieuw proberen;
|
|
@@ -58,36 +59,46 @@ export function useAutoAnalyse(mails, summaries, enabled, onDone) {
|
|
|
58
59
|
});
|
|
59
60
|
if (!proposal?.id || proposal.analysed || proposal.status !== "pending")
|
|
60
61
|
continue;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
body: mail.text ?? mail.snippet ?? "",
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
let aiResult;
|
|
62
|
+
// Claim in de database: een ander open tabblad analyseert deze mail al.
|
|
63
|
+
const { claimed } = await claim({ data: { proposal_id: proposal.id } });
|
|
64
|
+
if (!claimed)
|
|
65
|
+
continue;
|
|
69
66
|
try {
|
|
70
|
-
|
|
67
|
+
const prep = await prepare({
|
|
68
|
+
data: {
|
|
69
|
+
proposal_id: proposal.id,
|
|
70
|
+
subject: mail.subject,
|
|
71
|
+
body: mail.text ?? mail.snippet ?? "",
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
let aiResult;
|
|
75
|
+
try {
|
|
76
|
+
aiResult = await aiChat({
|
|
77
|
+
data: {
|
|
78
|
+
consumerModuleId: prep.consumerModuleId,
|
|
79
|
+
messages: Array.isArray(prep.messages) ? prep.messages : [],
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
aiResult = { ok: false, message: errorText(error, "De AI kon niet worden bereikt.") };
|
|
85
|
+
}
|
|
86
|
+
await applyAnalyse({
|
|
71
87
|
data: {
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
proposal_id: proposal.id,
|
|
89
|
+
subject: mail.subject,
|
|
90
|
+
body_for_ai: prep.body_for_ai,
|
|
91
|
+
attachment_notes: Array.isArray(prep.attachment_notes) ? prep.attachment_notes : [],
|
|
92
|
+
ai_result: aiResult,
|
|
74
93
|
},
|
|
75
94
|
});
|
|
76
95
|
}
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
finally {
|
|
97
|
+
await claim({ data: { proposal_id: proposal.id, release: true } }).catch((e) => console.error("Claim vrijgeven mislukt", e));
|
|
79
98
|
}
|
|
80
|
-
await applyAnalyse({
|
|
81
|
-
data: {
|
|
82
|
-
proposal_id: proposal.id,
|
|
83
|
-
subject: mail.subject,
|
|
84
|
-
body_for_ai: prep.body_for_ai,
|
|
85
|
-
attachment_notes: Array.isArray(prep.attachment_notes) ? prep.attachment_notes : [],
|
|
86
|
-
ai_result: aiResult,
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
99
|
}
|
|
90
|
-
catch {
|
|
100
|
+
catch (error) {
|
|
101
|
+
console.error("Automatische analyse mislukt", error);
|
|
91
102
|
// De fout blijft bij het voorstel staan; de volgende mail gaat gewoon door.
|
|
92
103
|
}
|
|
93
104
|
}
|
|
@@ -98,6 +109,6 @@ export function useAutoAnalyse(mails, summaries, enabled, onDone) {
|
|
|
98
109
|
setAnalysingIds([]);
|
|
99
110
|
onDoneRef.current();
|
|
100
111
|
});
|
|
101
|
-
}, [mails, summaries, enabled, ensureProposal, prepare, aiChat, applyAnalyse]);
|
|
112
|
+
}, [mails, summaries, enabled, ensureProposal, prepare, aiChat, applyAnalyse, claim]);
|
|
102
113
|
return analysingIds;
|
|
103
114
|
}
|
package/dist-lib/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { WerkbonMailPage } from './components/WerkbonMailPage';
|
|
|
7
7
|
export { WerkbonVerwerktPage } from './components/WerkbonVerwerktPage';
|
|
8
8
|
export { EmailDoeleindeInstelling } from './components/EmailDoeleindeInstelling';
|
|
9
9
|
export { MailAiInstructieInstelling } from './components/MailAiInstructieInstelling';
|
|
10
|
+
export { WerkbonPostvakInstelling } from './components/WerkbonPostvakInstelling';
|
|
10
11
|
export { useEmailPurpose } from './hooks/useEmailPurpose';
|
|
11
12
|
export { DEFAULT_MAIL_AI_PROMPT, DEFAULT_MAIL_AI_REQUIRED_FIELDS, } from './lib/mail-ai-defaults';
|
|
12
13
|
export { EMAIL_PURPOSES, getPurposeDef, directionLabel, getSelectedPurpose, setSelectedPurpose, purposeLabel, PURPOSE_EVENT, } from './lib/email-purposes';
|
package/dist-lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,sBAAsB,EACtB,+BAA+B,GAChC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,cAAc,EACd,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,cAAc,EACd,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,sBAAsB,EACtB,+BAA+B,GAChC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,cAAc,EACd,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,cAAc,EACd,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAM9B,eAAO,MAAM,iBAAiB,EAAE,UAgB/B,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,UAoBlC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,UAYnC,CAAC"}
|
package/dist-lib/index.js
CHANGED
|
@@ -10,11 +10,13 @@ export { WerkbonMailPage } from './components/WerkbonMailPage';
|
|
|
10
10
|
export { WerkbonVerwerktPage } from './components/WerkbonVerwerktPage';
|
|
11
11
|
export { EmailDoeleindeInstelling } from './components/EmailDoeleindeInstelling';
|
|
12
12
|
export { MailAiInstructieInstelling } from './components/MailAiInstructieInstelling';
|
|
13
|
+
export { WerkbonPostvakInstelling } from './components/WerkbonPostvakInstelling';
|
|
13
14
|
export { useEmailPurpose } from './hooks/useEmailPurpose';
|
|
14
15
|
export { DEFAULT_MAIL_AI_PROMPT, DEFAULT_MAIL_AI_REQUIRED_FIELDS, } from './lib/mail-ai-defaults';
|
|
15
16
|
export { EMAIL_PURPOSES, getPurposeDef, directionLabel, getSelectedPurpose, setSelectedPurpose, purposeLabel, PURPOSE_EVENT, } from './lib/email-purposes';
|
|
16
17
|
import { EmailDoeleindeInstelling } from './components/EmailDoeleindeInstelling';
|
|
17
18
|
import { MailAiInstructieInstelling } from './components/MailAiInstructieInstelling';
|
|
19
|
+
import { WerkbonPostvakInstelling } from './components/WerkbonPostvakInstelling';
|
|
18
20
|
export const werkbonMailModule = {
|
|
19
21
|
id: "werkbon_mail",
|
|
20
22
|
name: "Postvak Werkbonnen",
|
|
@@ -27,6 +29,7 @@ export const werkbonMailModule = {
|
|
|
27
29
|
settingsCards: [
|
|
28
30
|
{ component: EmailDoeleindeInstelling, order: 5 },
|
|
29
31
|
{ component: MailAiInstructieInstelling, order: 6 },
|
|
32
|
+
{ component: WerkbonPostvakInstelling, order: 7 },
|
|
30
33
|
],
|
|
31
34
|
};
|
|
32
35
|
export const werkbonPostvakModule = {
|
|
@@ -45,6 +48,7 @@ export const werkbonPostvakModule = {
|
|
|
45
48
|
settingsCards: [
|
|
46
49
|
{ component: EmailDoeleindeInstelling, order: 5 },
|
|
47
50
|
{ component: MailAiInstructieInstelling, order: 6 },
|
|
51
|
+
{ component: WerkbonPostvakInstelling, order: 7 },
|
|
48
52
|
],
|
|
49
53
|
};
|
|
50
54
|
export const werkbonVerwerktModule = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"previewAuthStorage.d.ts","sourceRoot":"","sources":["../../../src/integrations/supabase/previewAuthStorage.ts"],"names":[],"mappings":"AAEA,kHAAkH;AAClH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACjE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD;AA6BD;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,kBAAkB,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"previewAuthStorage.d.ts","sourceRoot":"","sources":["../../../src/integrations/supabase/previewAuthStorage.ts"],"names":[],"mappings":"AAEA,kHAAkH;AAClH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACjE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD;AA6BD;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,kBAAkB,GAAG,SAAS,CAuGvE"}
|
|
@@ -24,9 +24,10 @@ export function brokeredPreviewStorage() {
|
|
|
24
24
|
const onPreviewZone = PREVIEW_ZONES.some((z) => host === z || host.endsWith('.' + z));
|
|
25
25
|
// Read the id only from non-user-controlled host positions, so a user-named
|
|
26
26
|
// preview--<name> host can't smuggle another project's id.
|
|
27
|
-
const UUID = '[0-9a-f]{8}-[0-9a-f]{4}-
|
|
27
|
+
const UUID = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
|
|
28
28
|
const projectId = onPreviewZone
|
|
29
29
|
? (new RegExp('^(?:id-preview(?:-[a-z0-9]+)?|project)--(' + UUID + ')(?:-dev)?(?=\\.|$)', 'i').exec(host)?.[1]
|
|
30
|
+
?? new RegExp('^live--(' + UUID + ')(?:-thr_[a-z0-9]+)?(?=\\.|$)', 'i').exec(host)?.[1]
|
|
30
31
|
?? new RegExp('^(' + UUID + ')(?=[.-])', 'i').exec(host)?.[1])
|
|
31
32
|
: undefined;
|
|
32
33
|
// lib.dom types window.parent and location.ancestorOrigins as always set, but a
|