@flowselections/floriday-verkoop-module 1.0.167 → 1.0.169

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.
Files changed (58) hide show
  1. package/dist-lib/components/verkoop/CreateOrderPage.d.ts.map +1 -1
  2. package/dist-lib/components/verkoop/CreateOrderPage.js +57 -20
  3. package/dist-lib/components/verkoop/EditLocalOrderDialog.d.ts.map +1 -1
  4. package/dist-lib/components/verkoop/EditLocalOrderDialog.js +79 -13
  5. package/dist-lib/components/verkoop/KarTekeningSection.d.ts.map +1 -1
  6. package/dist-lib/components/verkoop/KarTekeningSection.js +11 -4
  7. package/dist-lib/components/verkoop/SalesOrderDetailView.js +1 -1
  8. package/dist-lib/components/verkoop/SearchableSelect.d.ts.map +1 -1
  9. package/dist-lib/components/verkoop/SearchableSelect.js +11 -3
  10. package/dist-lib/components/verkoop/regel/OrderLineExtrasCard.d.ts +3 -1
  11. package/dist-lib/components/verkoop/regel/OrderLineExtrasCard.d.ts.map +1 -1
  12. package/dist-lib/components/verkoop/regel/OrderLineExtrasCard.js +34 -15
  13. package/dist-lib/components/verkoop/regel/RegelGegevensVelden.d.ts +12 -2
  14. package/dist-lib/components/verkoop/regel/RegelGegevensVelden.d.ts.map +1 -1
  15. package/dist-lib/components/verkoop/regel/RegelGegevensVelden.js +23 -9
  16. package/dist-lib/components/verkoop/regel/StickerKeuzeRegels.d.ts +19 -0
  17. package/dist-lib/components/verkoop/regel/StickerKeuzeRegels.d.ts.map +1 -0
  18. package/dist-lib/components/verkoop/regel/StickerKeuzeRegels.js +30 -0
  19. package/dist-lib/integrations/supabase/types.d.ts +471 -0
  20. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  21. package/dist-lib/lib/create-order-form.d.ts +23 -0
  22. package/dist-lib/lib/create-order-form.d.ts.map +1 -1
  23. package/dist-lib/lib/create-order-form.js +38 -0
  24. package/dist-lib/lib/create-order.functions.d.ts +9 -0
  25. package/dist-lib/lib/create-order.functions.d.ts.map +1 -1
  26. package/dist-lib/lib/create-order.functions.js +30 -8
  27. package/dist-lib/lib/customer-stickers.d.ts +2 -1
  28. package/dist-lib/lib/customer-stickers.d.ts.map +1 -1
  29. package/dist-lib/lib/customer-stickers.js +2 -2
  30. package/dist-lib/lib/engine-tijdlijn.d.ts +11 -0
  31. package/dist-lib/lib/engine-tijdlijn.d.ts.map +1 -1
  32. package/dist-lib/lib/engine-tijdlijn.js +26 -0
  33. package/dist-lib/lib/engine-tijdlijn.server.d.ts +47 -0
  34. package/dist-lib/lib/engine-tijdlijn.server.d.ts.map +1 -1
  35. package/dist-lib/lib/engine-tijdlijn.server.js +119 -0
  36. package/dist-lib/lib/kar-tekening.d.ts +23 -0
  37. package/dist-lib/lib/kar-tekening.d.ts.map +1 -1
  38. package/dist-lib/lib/kar-tekening.js +51 -1
  39. package/dist-lib/lib/module-version.d.ts +1 -1
  40. package/dist-lib/lib/module-version.js +1 -1
  41. package/dist-lib/lib/order-item-packing.functions.d.ts +3 -0
  42. package/dist-lib/lib/order-item-packing.functions.d.ts.map +1 -1
  43. package/dist-lib/lib/order-item-packing.functions.js +9 -1
  44. package/dist-lib/lib/order-line-extras.d.ts +95 -1
  45. package/dist-lib/lib/order-line-extras.d.ts.map +1 -1
  46. package/dist-lib/lib/order-line-extras.functions.d.ts +20 -1
  47. package/dist-lib/lib/order-line-extras.functions.d.ts.map +1 -1
  48. package/dist-lib/lib/order-line-extras.functions.js +118 -5
  49. package/dist-lib/lib/order-line-extras.js +177 -0
  50. package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
  51. package/dist-lib/lib/salesorders-list.server.js +37 -1
  52. package/dist-lib/lib/salesorders.functions.d.ts.map +1 -1
  53. package/dist-lib/lib/salesorders.functions.js +5 -0
  54. package/dist-lib/lib/voorraad-vrij.d.ts +11 -0
  55. package/dist-lib/lib/voorraad-vrij.d.ts.map +1 -1
  56. package/dist-lib/lib/voorraad-vrij.js +31 -1
  57. package/package.json +2 -2
  58. package/schema/verkoop.sql +155 -150
@@ -1 +1 @@
1
- {"version":3,"file":"CreateOrderPage.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/CreateOrderPage.tsx"],"names":[],"mappings":"AA0HA,wBAAgB,eAAe,gCAo9C9B"}
1
+ {"version":3,"file":"CreateOrderPage.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/CreateOrderPage.tsx"],"names":[],"mappings":"AA+HA,wBAAgB,eAAe,gCAogD9B"}
@@ -14,18 +14,19 @@ import { useDebouncedValue } from "../../lib/use-debounced-value.js";
14
14
  import { korteMelding } from "../../lib/korte-melding.js";
15
15
  import { AlertTriangle, ArrowLeft, CheckCircle2, ChevronUp, Loader2, Plus, Trash2 } from "lucide-react";
16
16
  import { isOwnTransportKind, ownPickupLabel, vervoerSoort, vervoerderKeuzes, vertrekControle, voorbeeldVervoerderId, vervoerFout, datumLabel, klantHaaltOpTekst, AFLEVER_NIET_NODIG, OPHAALTIJD_ONTBREEKT, EIGEN_VERVOER_WERKWIJZE } from "../../lib/own-transport.js";
17
- import { missingItems, lineTotal, dateWithWeekday, eur, attentionItems, selectionKey, resetOnSelectionChange, applyFirstFeasible, prijsSleutel, PRIJS_FOUT_TEXT, PRIJS_ONBEKEND_TEXT, bekendePrijs, regelMistPrijs, groepLeden, groepZonderLedenTekst } from "../../lib/create-order-form.js";
17
+ import { missingItems, lineTotal, dateWithWeekday, eur, attentionItems, selectionKey, resetOnSelectionChange, applyFirstFeasible, prijsSleutel, PRIJS_FOUT_TEXT, PRIJS_ONBEKEND_TEXT, bekendePrijs, regelMistPrijs, groepLeden, groepZonderLedenTekst, prijsInvoer, actueelOordeel, previewDirect } from "../../lib/create-order-form.js";
18
18
  import { useServerFn } from "@tanstack/react-start";
19
19
  import { SearchableSelect } from "./SearchableSelect.js";
20
20
  import { toISODate } from "../../lib/carrier-availability.js";
21
21
  import { getDeparturePreview } from "../../lib/departure-preview.functions.js";
22
+ import { beschikbaarTekst } from "../../lib/voorraad-vrij.js";
22
23
  import { getProductPlannability } from "../../lib/product-plannable.functions.js";
23
24
  import { decidePreview, momentLabel, firstDateText, LATE_CONFIRM } from "../../lib/departure-preview.js";
24
25
  import { ConfirmDialog } from "./ConfirmDialog.js";
25
26
  import { listCustomersForCreateOrder, ensureCustomerFromTwinfield, listProductsForCreateOrder, listDeliveryLocationsForCustomerCO, listPickupLocationsCO, getLastPickupLocationCO, listCarriersForCreateOrder, getOrderPickDaysCO, listBeladingOptionsForProducts, createManualOrder, getOrderPrices, } from "../../lib/create-order.functions.js";
26
27
  import { checkOrderStockAllowed } from "../../lib/logistics-stock.functions.js";
27
- import { listLineStickerOptions, getLineFieldDefinitions } from "../../lib/order-line-extras.functions.js";
28
- import { geldigeStickerKeuze, isTimeoutFout, normRegelVelden, opmerkingNorm, regelVeldenTekst, standaardRegelVelden, stickerOntbreekt } from "../../lib/order-line-extras.js";
28
+ import { listLineStickerOptions, getLineFieldDefinitions, getStickerKeuze } from "../../lib/order-line-extras.functions.js";
29
+ import { stickerUploadPad, geldigeStickerKeuze, isTimeoutFout, normRegelVelden, opmerkingNorm, regelVeldenTekst, standaardRegelVelden, stickerOntbreekt } from "../../lib/order-line-extras.js";
29
30
  import { klantPad } from "../../lib/kar-handmatig.js";
30
31
  import { RegelGegevensVelden } from "./regel/RegelGegevensVelden.js";
31
32
  import { useAllowedLoadCarriers } from "../../lib/useAllowedLoadCarriers.js";
@@ -60,6 +61,14 @@ export function CreateOrderPage() {
60
61
  const fetchBeladingen = useServerFn(listBeladingOptionsForProducts);
61
62
  const fetchCreate = useServerFn(createManualOrder);
62
63
  const fetchStickerOptions = useServerFn(listLineStickerOptions);
64
+ const fetchStickerKeuze = useServerFn(getStickerKeuze);
65
+ // Pot-/fuststickerregels alleen als de Engine de stickerkeuze levert; anders de oude keuze.
66
+ const stickerKeuzeQ = useQuery({
67
+ queryKey: ["sticker-keuze-beschikbaar"],
68
+ staleTime: 10 * 60000,
69
+ queryFn: () => fetchStickerKeuze({ data: { orderItemIds: [] } }),
70
+ });
71
+ const stickerNieuw = stickerKeuzeQ.data?.available === true;
63
72
  const fetchFieldDefs = useServerFn(getLineFieldDefinitions);
64
73
  const loadCarriersEngine = useAllowedLoadCarriers();
65
74
  // Fouten niet inslikken: elke query toont zijn fout boven het formulier.
@@ -326,17 +335,20 @@ export function CreateOrderPage() {
326
335
  enabled: selectedProductIds.length > 0,
327
336
  staleTime: 30000,
328
337
  queryFn: async () => {
338
+ // Per regel onthouden waarvoor het oordeel gevraagd is (zie actueelOordeel).
339
+ const gevraagd = Object.fromEntries(plannableRegels.map((r) => [r.key, JSON.stringify(r)]));
329
340
  try {
330
- return await fetchPlannability({ data: { productIds: selectedProductIds.filter((x) => /^[0-9a-f-]{36}$/i.test(x)), regels: plannableRegels } });
341
+ return { ...(await fetchPlannability({ data: { productIds: selectedProductIds.filter((x) => /^[0-9a-f-]{36}$/i.test(x)), regels: plannableRegels } })), gevraagd };
331
342
  }
332
343
  catch {
333
- return { impossible: {}, available: false };
344
+ return { impossible: {}, available: false, gevraagd };
334
345
  }
335
346
  },
336
347
  });
337
- const impossibleByLine = plannableQ.data?.impossibleByLine ?? {};
348
+ const regelNu = useMemo(() => Object.fromEntries(plannableRegels.map((r) => [r.key, JSON.stringify(r)])), [plannableRegels]);
349
+ const impossibleByLine = actueelOordeel(plannableQ.data?.impossibleByLine, plannableQ.data?.gevraagd, regelNu);
338
350
  const missingByProduct = plannableQ.data?.missing ?? {};
339
- const missingByLine = plannableQ.data?.missingByLine ?? {};
351
+ const missingByLine = actueelOordeel(plannableQ.data?.missingByLine, plannableQ.data?.gevraagd, regelNu);
340
352
  const beladingByProduct = beladingQ.data?.byProduct ?? {};
341
353
  // Zodra de lijst binnen is: zorg dat de gekozen belading een geldige optie is.
342
354
  useEffect(() => {
@@ -374,6 +386,8 @@ export function CreateOrderPage() {
374
386
  const deliveryLocQ = useQuery({
375
387
  queryKey: ["co-delivery-locations", customerId],
376
388
  enabled: !!customerId,
389
+ staleTime: LIST_STALE,
390
+ gcTime: 30 * 60000,
377
391
  queryFn: async () => {
378
392
  try {
379
393
  return await fetchDeliveryLocations({ data: { customerId: customerId } });
@@ -461,13 +475,21 @@ export function CreateOrderPage() {
461
475
  : null, [canPickDate, isReservation, carrierId, deliveryLocationId, deliveryDate, momentKey, controle, selKey]);
462
476
  const [debouncedInput, setDebouncedInput] = useState(previewInput);
463
477
  useEffect(() => {
478
+ // Andere klant/locatie of nog geen datum: direct vragen (geen typen om op te wachten).
479
+ if (previewDirect(debouncedInput, previewInput)) {
480
+ setDebouncedInput(previewInput);
481
+ return;
482
+ }
464
483
  const t = setTimeout(() => setDebouncedInput(previewInput), 300);
465
484
  return () => clearTimeout(t);
485
+ // eslint-disable-next-line react-hooks/exhaustive-deps
466
486
  }, [previewInput]);
467
487
  const previewQ = useQuery({
468
488
  queryKey: ["co-departure-preview", debouncedInput],
469
489
  enabled: !!debouncedInput,
470
- staleTime: 15000,
490
+ // Per klant/locatie onthouden: terug naar dezelfde klant = direct ingevuld.
491
+ staleTime: 2 * 60000,
492
+ gcTime: 30 * 60000,
471
493
  queryFn: async () => {
472
494
  const { selKey: _k, ...input } = debouncedInput;
473
495
  try {
@@ -635,7 +657,12 @@ export function CreateOrderPage() {
635
657
  crates_per_layer: l.belading?.crates_per_layer ?? p?.crates_per_layer ?? undefined,
636
658
  layers_per_cart: l.belading?.layers_per_cart ?? p?.layers_per_cart ?? undefined,
637
659
  article_code: p?.article_code ?? undefined,
638
- needs_sticker: l.needs_sticker === true,
660
+ needs_sticker: stickerNieuw ? (l.pot_modus ?? "auto") !== "uit" : l.needs_sticker === true,
661
+ ...(stickerNieuw ? {
662
+ pot_sticker_modus: l.pot_modus ?? "auto",
663
+ fust_sticker_modus: l.fust_modus ?? "auto",
664
+ sticker_reden: (l.sticker_reden ?? "").trim() || null,
665
+ } : {}),
639
666
  // Verpakking-snapshot: fust, ladingdrager en herkomst van de keuze.
640
667
  vbn_package_code: l.belading?.crate_code ?? null,
641
668
  load_carrier_type: l.belading?.cart_code ?? null,
@@ -645,8 +672,8 @@ export function CreateOrderPage() {
645
672
  // Regelgegevens: opmerking, extra velden en stickerkeuze (op de pakbon).
646
673
  line_note: opmerkingNorm(l.line_note),
647
674
  line_fields: normRegelVelden(l.line_fields),
648
- product_sticker_id: l.product_sticker_id ?? null,
649
- fust_sticker_id: l.fust_sticker_id ?? null,
675
+ product_sticker_id: stickerNieuw ? (l.pot_modus === "handmatig" ? l.product_sticker_id ?? null : null) : l.product_sticker_id ?? null,
676
+ fust_sticker_id: stickerNieuw ? (l.fust_modus === "handmatig" ? l.fust_sticker_id ?? null : null) : l.fust_sticker_id ?? null,
650
677
  };
651
678
  }),
652
679
  };
@@ -916,8 +943,8 @@ export function CreateOrderPage() {
916
943
  value: p.id,
917
944
  label: `${code}${p.product}`,
918
945
  image: p.image_url ?? null,
919
- hint: p.in_stock
920
- ? `${size}Beschikbaar: ${p.available_stock} ${p.unit || "stuks"}${p.plants_per_crate ? ` · ${p.plants_per_crate}/fust` : ""}`
946
+ hint: p.in_stock || p.stock_uitleg?.liggend > 0
947
+ ? `${size}${beschikbaarTekst(p.available_stock, p.unit || "stuks", p.stock_uitleg)}${p.plants_per_crate ? ` · ${p.plants_per_crate}/fust` : ""}`
921
948
  : `${size}Niet op voorraad${p.plants_per_crate ? ` · ${p.plants_per_crate}/fust` : ""}`,
922
949
  search: [p.article_code, p.product].filter(Boolean).join(" "),
923
950
  muted: !p.in_stock,
@@ -934,7 +961,7 @@ export function CreateOrderPage() {
934
961
  return;
935
962
  }
936
963
  kiesRegelProduct(idx, v);
937
- } }), impossible && _jsxs("div", { className: "mt-1 text-xs text-destructive", children: ["Niet in te delen met deze belading: ", korteMelding(impossible) ?? "kies een andere belading."] }), missingLine && korteMelding(missingLine) && _jsxs("div", { className: "mt-1 text-xs text-muted-foreground", children: ["Let op: ", korteMelding(missingLine)] })] }), _jsxs("label", { className: "order-3 flex h-9 min-w-11 shrink-0 cursor-pointer items-center gap-2 [@media(pointer:coarse)]:h-11 @[60rem]:order-none @[60rem]:justify-center", children: [_jsx("input", { type: "checkbox", className: "h-4 w-4 accent-primary [@media(pointer:coarse)]:h-6 [@media(pointer:coarse)]:w-6", "aria-label": "Sticker nodig", title: "Sticker nodig", checked: line.needs_sticker === true, disabled: !line.product_id, onChange: (e) => { const next = [...lines]; next[idx] = { ...next[idx], needs_sticker: e.target.checked, sticker_manual_for: line.product_id }; setLines(next); } }), _jsx("span", { className: "text-sm @[60rem]:sr-only", children: "Sticker nodig" })] }), _jsxs("div", { className: "order-3 min-w-0 grow basis-[13rem] @[60rem]:order-none @[60rem]:basis-auto", children: [_jsx("div", { className: "mb-1 text-xs text-muted-foreground @[60rem]:sr-only", children: "Belading" }), _jsx(SearchableSelect, { value: effBelading ? beladingKey(effBelading) : null, placeholder: !line.product_id ? "Kies eerst product" : effBelading ? beladingLabel(effBelading) : loadingBeladingen ? "Laden…" : noBeladingen ? "Geen belading" : "Kies belading…", disabled: !line.product_id || (loadingBeladingen && !effBelading) || noBeladingen, allowClear: false, emptyLabel: "Geen belading gekoppeld aan dit product", options: Array.from(optionMap.entries()).map(([key, b]) => ({
964
+ } }), impossible && _jsxs("div", { className: "mt-1 text-xs text-destructive", children: ["Niet in te delen met deze belading: ", korteMelding(impossible) ?? "kies een andere belading."] }), missingLine && korteMelding(missingLine) && _jsxs("div", { className: "mt-1 text-xs text-muted-foreground", children: ["Let op: ", korteMelding(missingLine)] })] }), stickerNieuw ? (_jsx("div", { className: "order-3 flex h-9 min-w-11 shrink-0 items-center text-xs text-muted-foreground @[60rem]:order-none @[60rem]:justify-center", title: "Potsticker", children: !line.product_id ? "—" : (line.pot_modus ?? "auto") === "uit" ? "Uit" : line.pot_modus === "handmatig" ? "Gekozen" : "Auto" })) : (_jsxs("label", { className: "order-3 flex h-9 min-w-11 shrink-0 cursor-pointer items-center gap-2 [@media(pointer:coarse)]:h-11 @[60rem]:order-none @[60rem]:justify-center", children: [_jsx("input", { type: "checkbox", className: "h-4 w-4 accent-primary [@media(pointer:coarse)]:h-6 [@media(pointer:coarse)]:w-6", "aria-label": "Sticker nodig", title: "Sticker nodig", checked: line.needs_sticker === true, disabled: !line.product_id, onChange: (e) => { const next = [...lines]; next[idx] = { ...next[idx], needs_sticker: e.target.checked, sticker_manual_for: line.product_id }; setLines(next); } }), _jsx("span", { className: "text-sm @[60rem]:sr-only", children: "Sticker nodig" })] })), _jsxs("div", { className: "order-3 min-w-0 grow basis-[13rem] @[60rem]:order-none @[60rem]:basis-auto", children: [_jsx("div", { className: "mb-1 text-xs text-muted-foreground @[60rem]:sr-only", children: "Belading" }), _jsx(SearchableSelect, { value: effBelading ? beladingKey(effBelading) : null, placeholder: !line.product_id ? "Kies eerst product" : effBelading ? beladingLabel(effBelading) : loadingBeladingen ? "Laden…" : noBeladingen ? "Geen belading" : "Kies belading…", disabled: !line.product_id || (loadingBeladingen && !effBelading) || noBeladingen, allowClear: false, emptyLabel: "Geen belading gekoppeld aan dit product", options: Array.from(optionMap.entries()).map(([key, b]) => ({
938
965
  value: key,
939
966
  label: beladingLabel(b),
940
967
  badge: key === defaultKey ? "Standaard" : null,
@@ -963,36 +990,46 @@ export function CreateOrderPage() {
963
990
  const cr = raw ? Math.max(1, Math.floor(Number(raw))) : null;
964
991
  next[idx] = { ...next[idx], quantity: cr === null ? null : cr * ppc };
965
992
  setLines(next);
966
- }, placeholder: ppc === null ? "—" : "Fusten", title: ppc === null ? "Kies eerst een belading" : `${ppc} planten per fust` })] }), _jsxs("div", { className: "grow basis-[7.5rem] @[60rem]:basis-auto order-3 @[60rem]:order-none", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground @[60rem]:sr-only", children: "Stuks" }), _jsx("div", { className: "flex h-9 items-center text-sm tabular-nums text-foreground @[60rem]:justify-end", children: line.product_id && plants ? plants.toLocaleString("nl-NL") : "—" })] }), _jsxs("div", { className: "min-w-0 grow basis-[7.5rem] @[60rem]:basis-auto order-3 @[60rem]:order-none", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground @[60rem]:sr-only", children: "Beschikbaar" }), product ? (_jsxs("div", { className: `flex min-h-9 items-center gap-1 text-sm tabular-nums ${overStock ? (stockBlocked ? "text-destructive" : "text-warning-soft-foreground") : "text-foreground"}`, children: [overStock && _jsx(AlertTriangle, { className: "h-3.5 w-3.5 shrink-0" }), _jsxs("span", { className: "truncate", children: [(available ?? 0).toLocaleString("nl-NL"), " ", unit] })] })) : _jsx("div", { className: "flex h-9 items-center text-sm text-muted-foreground", children: "\u2014" }), overStock && (_jsx("div", { className: `text-xs ${stockBlocked ? "text-destructive" : "text-warning-soft-foreground"}`, children: shortage ? `Tekort ${shortage.missing.toLocaleString("nl-NL")}` : "Meer dan beschikbaar" }))] }), _jsxs("label", { className: "grow basis-[7.5rem] @[60rem]:basis-auto order-3 @[60rem]:order-none", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground @[60rem]:sr-only", children: "Prijs per stuk" }), _jsx(Input, { type: "number", min: 0, step: "0.01", inputMode: "decimal", className: "h-9 tabular-nums [@media(pointer:coarse)]:h-11", value: line.unit_price ?? "", onChange: (e) => { const next = [...lines]; next[idx] = { ...next[idx], unit_price: e.target.value === "" ? null : Number(e.target.value), price_mode: "manual", price_source: "Handmatig", price_error: false, price_zero_ok: false }; setLines(next); }, placeholder: "\u20AC", "aria-invalid": noPrice || line.price_error }), line.price_error ? (_jsx("span", { className: "mt-1 block text-xs text-destructive", children: PRIJS_FOUT_TEXT })) : noPrice && !pricePending ? (_jsxs("span", { className: "mt-1 block text-xs text-destructive", children: [PRIJS_ONBEKEND_TEXT, line.unit_price != null && Number(line.unit_price) === 0 && (_jsxs("span", { className: "mt-1 flex items-center gap-1.5 text-foreground [@media(pointer:coarse)]:min-h-11", children: [_jsx("input", { type: "checkbox", className: "h-4 w-4", checked: !!line.price_zero_ok, onChange: (e) => { const next = [...lines]; next[idx] = { ...next[idx], price_zero_ok: e.target.checked }; setLines(next); } }), "Prijs 0 is juist"] }))] })) : line.price_zero_ok && Number(line.unit_price) === 0 ? (_jsx("span", { className: "mt-1 block text-xs text-muted-foreground", children: "Prijs 0 bevestigd" })) : line.price_source ? (_jsx("span", { className: "mt-1 block truncate text-xs text-muted-foreground", title: line.price_source, children: line.price_source })) : null, line.product_id && (line.price_mode === "manual" || line.price_error) && (_jsx("button", { type: "button", className: "mt-0.5 block text-xs font-medium text-primary hover:underline [@media(pointer:coarse)]:min-h-11", onClick: (e) => { e.preventDefault(); const next = [...lines]; next[idx] = { ...next[idx], price_mode: "auto", price_key: null, price_error: false }; setLines(next); }, children: "Prijs opnieuw ophalen" }))] }), _jsxs("div", { className: "grow basis-[7.5rem] @[60rem]:basis-auto order-3 @[60rem]:order-none", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground @[60rem]:sr-only", children: "Totaal" }), _jsx("div", { className: "flex h-9 items-center text-sm font-medium tabular-nums text-foreground @[60rem]:justify-end", children: line.product_id ? eur(lineInfo[idx].total) : "—" })] }), _jsx("div", { className: "order-2 flex shrink-0 justify-end @[60rem]:order-none", children: _jsx(Button, { variant: "ghost", size: "icon", className: "h-9 w-9 [@media(pointer:coarse)]:h-11 [@media(pointer:coarse)]:w-11", onClick: () => setLines(lines.filter((_, i) => i !== idx)), "aria-label": "Regel verwijderen", children: _jsx(Trash2, { className: "h-4 w-4" }) }) }), line.product_id && (() => {
993
+ }, placeholder: ppc === null ? "—" : "Fusten", title: ppc === null ? "Kies eerst een belading" : `${ppc} planten per fust` })] }), _jsxs("div", { className: "grow basis-[7.5rem] @[60rem]:basis-auto order-3 @[60rem]:order-none", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground @[60rem]:sr-only", children: "Stuks" }), _jsx("div", { className: "flex h-9 items-center text-sm tabular-nums text-foreground @[60rem]:justify-end", children: line.product_id && plants ? plants.toLocaleString("nl-NL") : "—" })] }), _jsxs("div", { className: "min-w-0 grow basis-[7.5rem] @[60rem]:basis-auto order-3 @[60rem]:order-none", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground @[60rem]:sr-only", children: "Beschikbaar" }), product ? (_jsxs("div", { className: `flex min-h-9 items-center gap-1 text-sm tabular-nums ${overStock ? (stockBlocked ? "text-destructive" : "text-warning-soft-foreground") : "text-foreground"}`, children: [overStock && _jsx(AlertTriangle, { className: "h-3.5 w-3.5 shrink-0" }), _jsxs("span", { className: "truncate", children: [(available ?? 0).toLocaleString("nl-NL"), " ", unit] })] })) : _jsx("div", { className: "flex h-9 items-center text-sm text-muted-foreground", children: "\u2014" }), product && (available ?? 0) <= 0 && product.stock_uitleg?.liggend > 0 && (_jsxs("div", { className: "text-xs text-muted-foreground", title: "Zelfde getallen als in Voorraad", children: [product.stock_uitleg.liggend.toLocaleString("nl-NL"), " op voorraad, ", product.stock_uitleg.gereserveerd.toLocaleString("nl-NL"), " gereserveerd"] })), overStock && (_jsx("div", { className: `text-xs ${stockBlocked ? "text-destructive" : "text-warning-soft-foreground"}`, children: shortage ? `Tekort ${shortage.missing.toLocaleString("nl-NL")}` : "Meer dan beschikbaar" }))] }), _jsxs("label", { className: "grow basis-[7.5rem] @[60rem]:basis-auto order-3 @[60rem]:order-none", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground @[60rem]:sr-only", children: "Prijs per stuk" }), _jsx(Input, { type: "number", min: 0, step: "0.01", inputMode: "decimal", className: "h-9 tabular-nums [@media(pointer:coarse)]:h-11", value: line.unit_price ?? "", onChange: (e) => { const next = [...lines]; next[idx] = { ...next[idx], unit_price: prijsInvoer(e.target.value), price_mode: "manual", price_source: "Handmatig", price_error: false, price_zero_ok: false }; setLines(next); }, placeholder: "\u20AC", "aria-invalid": noPrice || line.price_error }), line.price_error ? (_jsx("span", { className: "mt-1 block text-xs text-destructive", children: PRIJS_FOUT_TEXT })) : noPrice && !pricePending ? (_jsxs("span", { className: "mt-1 block text-xs text-destructive", children: [PRIJS_ONBEKEND_TEXT, line.unit_price != null && Number(line.unit_price) === 0 && (_jsxs("span", { className: "mt-1 flex items-center gap-1.5 text-foreground [@media(pointer:coarse)]:min-h-11", children: [_jsx("input", { type: "checkbox", className: "h-4 w-4", checked: !!line.price_zero_ok, onChange: (e) => { const next = [...lines]; next[idx] = { ...next[idx], price_zero_ok: e.target.checked }; setLines(next); } }), "Prijs 0 is juist"] }))] })) : line.price_zero_ok && Number(line.unit_price) === 0 ? (_jsx("span", { className: "mt-1 block text-xs text-muted-foreground", children: "Prijs 0 bevestigd" })) : line.price_source ? (_jsx("span", { className: "mt-1 block truncate text-xs text-muted-foreground", title: line.price_source, children: line.price_source })) : null, line.product_id && (line.price_mode === "manual" || line.price_error) && (_jsx("button", { type: "button", className: "mt-0.5 block text-xs font-medium text-primary hover:underline [@media(pointer:coarse)]:min-h-11", onClick: (e) => { e.preventDefault(); const next = [...lines]; next[idx] = { ...next[idx], price_mode: "auto", price_key: null, price_error: false }; setLines(next); }, children: "Prijs opnieuw ophalen" }))] }), _jsxs("div", { className: "grow basis-[7.5rem] @[60rem]:basis-auto order-3 @[60rem]:order-none", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground @[60rem]:sr-only", children: "Totaal" }), _jsx("div", { className: "flex h-9 items-center text-sm font-medium tabular-nums text-foreground @[60rem]:justify-end", children: line.product_id ? eur(lineInfo[idx].total) : "—" })] }), _jsx("div", { className: "order-2 flex shrink-0 justify-end @[60rem]:order-none", children: _jsx(Button, { variant: "ghost", size: "icon", className: "h-9 w-9 [@media(pointer:coarse)]:h-11 [@media(pointer:coarse)]:w-11", onClick: () => setLines(lines.filter((_, i) => i !== idx)), "aria-label": "Regel verwijderen", children: _jsx(Trash2, { className: "h-4 w-4" }) }) }), line.product_id && (() => {
967
994
  const opts = stickerOpts[line.product_id] ?? null;
968
- const ontbreekt = stickerOntbreekt(line, customerIsUuid ? opts : null);
995
+ const ontbreekt = !stickerNieuw && stickerOntbreekt(line, customerIsUuid ? opts : null);
969
996
  const open = line.details_open === true || ontbreekt;
970
997
  const naam = (id, lijst) => (id ? lijst?.find((o) => o.id === id)?.naam ?? null : null);
971
998
  const samenvatting = [
972
- naam(line.product_sticker_id, opts?.product) ? `Productsticker: ${naam(line.product_sticker_id, opts?.product)}` : null,
973
- naam(line.fust_sticker_id, opts?.fust) ? `Fuststicker: ${naam(line.fust_sticker_id, opts?.fust)}` : null,
999
+ ...(stickerNieuw
1000
+ ? [["Potsticker", line.pot_modus, line.product_sticker_id, opts?.product], ["Fuststicker", line.fust_modus, line.fust_sticker_id, opts?.fust]].map(([lbl, m, id, lijst]) => m === "uit" ? `${lbl}: niet printen` : m === "handmatig" ? `${lbl}: ${naam(id, lijst) ?? "handmatig gekozen"}` : null)
1001
+ : [
1002
+ naam(line.product_sticker_id, opts?.product) ? `Productsticker: ${naam(line.product_sticker_id, opts?.product)}` : null,
1003
+ naam(line.fust_sticker_id, opts?.fust) ? `Fuststicker: ${naam(line.fust_sticker_id, opts?.fust)}` : null,
1004
+ ]),
974
1005
  regelVeldenTekst(line.line_fields),
975
1006
  line.line_note?.trim() ? `Opmerking: ${line.line_note.trim()}` : null,
976
1007
  ].filter(Boolean).join(" · ");
977
1008
  return (_jsxs("div", { className: "order-4 basis-full @[60rem]:order-none @[60rem]:col-span-full", children: [_jsxs("button", { type: "button", className: "flex min-h-9 w-full items-center gap-2 text-left text-xs text-muted-foreground hover:text-foreground [@media(pointer:coarse)]:min-h-11", "aria-expanded": open, onClick: () => { const next = [...lines]; next[idx] = { ...next[idx], details_open: !open }; setLines(next); }, children: [_jsx(ChevronUp, { className: `h-3.5 w-3.5 shrink-0 transition-transform ${open ? "" : "rotate-180"}`, "aria-hidden": true }), _jsx("span", { className: "font-medium text-foreground", children: "Sticker, opmerking en extra velden" }), ontbreekt && _jsxs("span", { className: "inline-flex items-center gap-1 text-warning-soft-foreground", children: [_jsx(AlertTriangle, { className: "h-3.5 w-3.5", "aria-hidden": true }), " sticker ontbreekt"] }), !open && samenvatting && _jsx("span", { className: "min-w-0 truncate", children: samenvatting })] }), open && (_jsxs("div", { className: "mt-2 rounded-lg bg-muted/40 p-3", children: [stickerFout && _jsx("div", { className: "mb-2 text-xs text-destructive", children: stickerFout }), !customerIsUuid && _jsx("div", { className: "mb-2 text-xs text-muted-foreground", children: "Kies eerst een klant om stickers en extra velden te zien." }), _jsx(RegelGegevensVelden, { idPrefix: `regel-${idx}`, value: {
978
1009
  productStickerId: line.product_sticker_id ?? null,
979
1010
  fustStickerId: line.fust_sticker_id ?? null,
1011
+ potModus: line.pot_modus ?? "auto",
1012
+ fustModus: line.fust_modus ?? "auto",
1013
+ stickerReden: line.sticker_reden ?? "",
980
1014
  note: line.line_note ?? "",
981
1015
  fields: line.line_fields ?? [],
982
- }, opties: customerIsUuid ? opts : null, optiesLaden: customerIsUuid && stickerQ.isFetching && !opts, definities: fieldDefs, needsSticker: line.needs_sticker === true, klantLink: stickerKlantLink, onChange: (patch) => {
1016
+ }, opties: customerIsUuid ? opts : null, optiesLaden: customerIsUuid && stickerQ.isFetching && !opts, definities: fieldDefs, needsSticker: line.needs_sticker === true, klantLink: stickerKlantLink, nieuweStickerweergave: stickerNieuw, stickerKeuze: null, uploadPad: stickerUploadPad(stickerKlantLink, line.product_id), onChange: (patch) => {
983
1017
  const next = [...lines];
984
1018
  const cur = next[idx];
985
1019
  next[idx] = {
986
1020
  ...cur,
987
1021
  ...(patch.productStickerId !== undefined ? { product_sticker_id: patch.productStickerId, sticker_choice_for: cur.product_id } : {}),
988
1022
  ...(patch.fustStickerId !== undefined ? { fust_sticker_id: patch.fustStickerId, sticker_choice_for: cur.product_id } : {}),
1023
+ ...(patch.potModus !== undefined ? { pot_modus: patch.potModus } : {}),
1024
+ ...(patch.fustModus !== undefined ? { fust_modus: patch.fustModus } : {}),
1025
+ ...(patch.stickerReden !== undefined ? { sticker_reden: patch.stickerReden } : {}),
989
1026
  ...(patch.note !== undefined ? { line_note: patch.note } : {}),
990
1027
  ...(patch.fields !== undefined ? { line_fields: patch.fields } : {}),
991
1028
  };
992
1029
  setLines(next);
993
1030
  } })] }))] }));
994
1031
  })()] }, idx));
995
- }) }), _jsxs("div", { className: "mt-3 flex flex-col gap-3 border-t border-border pt-3 sm:flex-row sm:items-center sm:justify-between", children: [_jsxs(Button, { variant: "outline", className: "h-9 w-full sm:w-auto [@media(pointer:coarse)]:h-11", onClick: addLine, children: [_jsx(Plus, { className: "mr-1 h-4 w-4" }), " Regel toevoegen"] }), _jsxs("div", { className: "flex flex-wrap items-center gap-x-5 gap-y-1 text-sm tabular-nums", children: [_jsxs("span", { className: "text-muted-foreground", children: ["Fusten ", _jsx("span", { className: "font-medium text-foreground", children: totals.crates })] }), _jsxs("span", { className: "text-muted-foreground", children: ["Stuks ", _jsx("span", { className: "font-medium text-foreground", children: totals.stuks.toLocaleString("nl-NL") })] }), _jsxs("span", { className: "text-muted-foreground", children: ["Totaal ", _jsx("span", { className: "font-semibold text-foreground", children: eur(totals.amount) })] })] })] }), stockCheck && stockCheck.shortages.length > 0 && !stockBlocked && (_jsx("div", { className: "mt-3 rounded-lg bg-warning-soft p-2.5 text-xs text-warning-soft-foreground", children: "Uitleveren zonder voorraad staat aan: de bestelling kan met tekort worden aangemaakt." }))] }), _jsxs("section", { className: cardCls, children: [_jsx("h2", { className: h2, children: "Aanvullend" }), _jsxs("div", { className: "mt-4 grid gap-4", children: [_jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { className: fieldLabel, children: "Referentie klant" }), _jsx(Input, { value: customerReference, maxLength: 100, className: "h-9 [@media(pointer:coarse)]:h-11", onChange: (e) => setCustomerReference(e.target.value), placeholder: "Optioneel, bijvoorbeeld het bestelnummer van je klant" })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { className: fieldLabel, children: "Opmerkingen" }), _jsx(Textarea, { value: notes, onChange: (e) => setNotes(e.target.value), placeholder: "Optionele notities bij deze bestelling", rows: 3 })] })] })] })] }), _jsx("aside", { className: "min-w-0", children: _jsxs("div", { className: `${cardCls} space-y-4 xl:sticky xl:top-4`, children: [_jsx("h2", { className: h2, children: "Samenvatting" }), summaryRows, missingBlock, attentionBlock, createButton(), _jsx(Button, { variant: "ghost", className: "h-9 w-full [@media(pointer:coarse)]:h-11", onClick: () => navigate({ to: "/floriday-verkoop/verkooporders" }), disabled: createMut.isPending, children: "Annuleren" })] }) })] }), _jsxs("div", { className: "sticky bottom-0 z-30 -mx-4 border-t border-border bg-background/95 px-4 pt-3 backdrop-blur sm:-mx-6 sm:px-6 xl:hidden", style: { paddingBottom: "max(12px, env(safe-area-inset-bottom))" }, children: [mobileSummaryOpen && (_jsxs("div", { className: "mb-3 max-h-[50vh] space-y-3 overflow-y-auto", children: [summaryRows, missingBlock, attentionBlock] })), _jsxs("button", { type: "button", className: "mb-2 flex w-full items-center justify-between gap-3 text-left [@media(pointer:coarse)]:min-h-11", onClick: () => setMobileSummaryOpen((o) => !o), "aria-expanded": mobileSummaryOpen, children: [_jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "block truncate text-xs text-muted-foreground", children: momentText ? `Ophalen: ${momentText.replace(/^ophalen /, "")}` : missing.length > 0 ? `${missing.length} ontbreekt nog` : attention.length > 0 ? `${attention.length} aandachtspunt${attention.length === 1 ? "" : "en"}` : "Alles is compleet" }), _jsx("span", { className: "block text-base font-semibold tabular-nums text-foreground", children: eur(totals.amount) })] }), _jsx(ChevronUp, { className: `h-5 w-5 shrink-0 text-muted-foreground transition-transform ${mobileSummaryOpen ? "" : "rotate-180"}` })] }), createButton("h-12")] }), groepKeuze && (() => {
1032
+ }) }), _jsxs("div", { className: "mt-3 flex flex-col gap-3 border-t border-border pt-3 sm:flex-row sm:items-center sm:justify-between", children: [_jsxs(Button, { variant: "outline", className: "h-9 w-full sm:w-auto [@media(pointer:coarse)]:h-11", onClick: addLine, children: [_jsx(Plus, { className: "mr-1 h-4 w-4" }), " Regel toevoegen"] }), _jsxs("div", { className: "flex flex-wrap items-center gap-x-5 gap-y-1 text-sm tabular-nums", children: [_jsxs("span", { className: "text-muted-foreground", children: ["Fusten ", _jsx("span", { className: "font-medium text-foreground", children: totals.crates })] }), _jsxs("span", { className: "text-muted-foreground", children: ["Stuks ", _jsx("span", { className: "font-medium text-foreground", children: totals.stuks.toLocaleString("nl-NL") })] }), _jsxs("span", { className: "text-muted-foreground", children: ["Totaal ", _jsx("span", { className: "font-semibold text-foreground", children: eur(totals.amount) })] })] })] }), stockCheck && stockCheck.shortages.length > 0 && !stockBlocked && (_jsx("div", { className: "mt-3 rounded-lg bg-warning-soft p-2.5 text-xs text-warning-soft-foreground", children: "Uitleveren zonder voorraad staat aan: de bestelling kan met tekort worden aangemaakt." }))] }), _jsxs("section", { className: cardCls, children: [_jsx("h2", { className: h2, children: "Aanvullend" }), _jsxs("div", { className: "mt-4 grid gap-4", children: [_jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { className: fieldLabel, children: "Referentie klant" }), _jsx(Input, { value: customerReference, maxLength: 100, className: "h-9 [@media(pointer:coarse)]:h-11", onChange: (e) => setCustomerReference(e.target.value), placeholder: "Optioneel, bijvoorbeeld het bestelnummer van je klant" })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { className: fieldLabel, children: "Opmerkingen" }), _jsx(Textarea, { value: notes, onChange: (e) => setNotes(e.target.value), placeholder: "Optionele notities bij deze bestelling", rows: 3 })] })] })] })] }), _jsx("aside", { className: "hidden min-w-0 xl:block", children: _jsxs("div", { className: `${cardCls} space-y-4 xl:sticky xl:top-4`, children: [_jsx("h2", { className: h2, children: "Samenvatting" }), summaryRows, missingBlock, attentionBlock, createButton(), _jsx(Button, { variant: "ghost", className: "h-9 w-full [@media(pointer:coarse)]:h-11", onClick: () => navigate({ to: "/floriday-verkoop/verkooporders" }), disabled: createMut.isPending, children: "Annuleren" })] }) })] }), _jsxs("div", { className: "sticky bottom-0 z-30 -mx-4 border-t border-border bg-background/95 px-4 pt-3 backdrop-blur sm:-mx-6 sm:px-6 xl:hidden", style: { paddingBottom: "max(12px, env(safe-area-inset-bottom))" }, children: [mobileSummaryOpen && (_jsxs("div", { className: "mb-3 max-h-[50vh] space-y-3 overflow-y-auto", children: [summaryRows, missingBlock, attentionBlock] })), _jsxs("button", { type: "button", className: "mb-2 flex w-full items-center justify-between gap-3 text-left [@media(pointer:coarse)]:min-h-11", onClick: () => setMobileSummaryOpen((o) => !o), "aria-expanded": mobileSummaryOpen, children: [_jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "block truncate text-xs text-muted-foreground", children: momentText ? `Ophalen: ${momentText.replace(/^ophalen /, "")}` : missing.length > 0 ? `${missing.length} ontbreekt nog` : attention.length > 0 ? `${attention.length} aandachtspunt${attention.length === 1 ? "" : "en"}` : "Alles is compleet" }), _jsx("span", { className: "block text-base font-semibold tabular-nums text-foreground", children: eur(totals.amount) })] }), _jsx(ChevronUp, { className: `h-5 w-5 shrink-0 text-muted-foreground transition-transform ${mobileSummaryOpen ? "" : "rotate-180"}` })] }), createButton("h-12")] }), groepKeuze && (() => {
996
1033
  const leden = groepLeden(groepKeuze.groep, products);
997
1034
  const groepNaam = String(groepKeuze.groep.product ?? "").replace(/^\s*\[Groep\]\s*/i, "");
998
1035
  return (_jsx(Dialog, { open: true, onOpenChange: (o) => { if (!o)
@@ -1 +1 @@
1
- {"version":3,"file":"EditLocalOrderDialog.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/EditLocalOrderDialog.tsx"],"names":[],"mappings":"AAuDA,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,IAAI,EACJ,YAAY,GACb,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,sCAunBA"}
1
+ {"version":3,"file":"EditLocalOrderDialog.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/EditLocalOrderDialog.tsx"],"names":[],"mappings":"AAkEA,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,IAAI,EACJ,YAAY,GACb,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,sCAwtBA"}
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useState } from "react";
3
3
  import { markIndelingBezig } from "../../lib/indeling-bezig.js";
4
4
  import { tekortMelding } from "../../lib/korte-melding.js";
@@ -6,7 +6,9 @@ import { Button, Input, toast } from "@flowselections/core";
6
6
  import { Trash2 } from "lucide-react";
7
7
  import { useServerFn } from "@tanstack/react-start";
8
8
  import { useQuery, useQueryClient } from "@tanstack/react-query";
9
- import { getLocalOrderForEdit, updateLocalOrder, listProductsForCreateOrder, } from "../../lib/create-order.functions.js";
9
+ import { getLocalOrderForEdit, updateLocalOrder, listProductsForCreateOrder, getOrderPrices, } from "../../lib/create-order.functions.js";
10
+ import { bekendePrijs, prijsInvoer, prijsRegelFout, prijsSleutel, PRIJS_FOUT_TEXT, PRIJS_ONBEKEND_TEXT } from "../../lib/create-order-form.js";
11
+ import { beschikbaarTekst } from "../../lib/voorraad-vrij.js";
10
12
  import { checkEditOrderStock } from "../../lib/logistics-stock.functions.js";
11
13
  import { bewerkTekortMelding, regelPerSleutel } from "../../lib/bewerk-voorraad.js";
12
14
  import { SearchableSelect } from "./SearchableSelect.js";
@@ -14,6 +16,8 @@ import { datumLabel } from "../../lib/own-transport.js";
14
16
  import { getKarTekening } from "../../lib/kar-tekening.functions.js";
15
17
  import { EXTRA_KAR_MELDING } from "../../lib/kar-handmatig.js";
16
18
  import { KarSlotMelding } from "./KarSlotMelding.js";
19
+ import { getStickerKeuze } from "../../lib/order-line-extras.functions.js";
20
+ import { OrderLineExtrasCard } from "./regel/OrderLineExtrasCard.js";
17
21
  /** Positief geheel getal of null — ontbrekende belading blijft onbekend. */
18
22
  const pos = (v) => {
19
23
  const n = Number(v);
@@ -27,6 +31,7 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
27
31
  const [saving, setSaving] = useState(false);
28
32
  const [error, setError] = useState(null);
29
33
  const [deliveryDate, setDeliveryDate] = useState("");
34
+ const [customerId, setCustomerId] = useState(null);
30
35
  const [isReservation, setIsReservation] = useState(false);
31
36
  const [vervoerSoortV, setVervoerSoortV] = useState(null);
32
37
  const [floridayCarrierNotice, setFloridayCarrierNotice] = useState(null);
@@ -38,6 +43,15 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
38
43
  const [newItems, setNewItems] = useState([]);
39
44
  // Handmatig aangepaste kar (slot) uit de tekening van de Engine; oudere Engine → geen slot.
40
45
  const tekeningFn = useServerFn(getKarTekening);
46
+ // Pot-/fuststicker per regel uit de Engine; ontbreekt die, dan het oude vinkje "Sticker nodig".
47
+ const stickerKeuzeFn = useServerFn(getStickerKeuze);
48
+ const stickerKeuzeQ = useQuery({
49
+ queryKey: ["sticker-keuze-beschikbaar"],
50
+ enabled: open,
51
+ staleTime: 10 * 60000,
52
+ queryFn: () => stickerKeuzeFn({ data: { orderItemIds: [] } }),
53
+ });
54
+ const stickerNieuw = stickerKeuzeQ.data?.available === true;
41
55
  const slotQ = useQuery({
42
56
  queryKey: ["kar-tekening", orderId, "bewerken"],
43
57
  enabled: open && !!orderId,
@@ -58,6 +72,7 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
58
72
  if (cancelled)
59
73
  return;
60
74
  setDeliveryDate((r.deliveryDate ?? "").slice(0, 10));
75
+ setCustomerId(r.customerId ?? null);
61
76
  setIsReservation(!!r.isReservation);
62
77
  setVervoerSoortV(r.vervoerSoort ?? null);
63
78
  setFloridayCarrierNotice(r.floridayCarrierNotice ?? null);
@@ -102,7 +117,7 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
102
117
  .map((p) => ({
103
118
  value: p.id,
104
119
  label: p.product,
105
- hint: p.in_stock ? `${p.available_stock} beschikbaar` : "niet op voorraad",
120
+ hint: p.in_stock || (p.stock_uitleg?.liggend ?? 0) > 0 ? beschikbaarTekst(p.available_stock, p.unit || "stuks", p.stock_uitleg) : "Niet op voorraad",
106
121
  muted: !p.in_stock,
107
122
  })), [products, usedProductIds]);
108
123
  const addProduct = (productId) => {
@@ -125,15 +140,54 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
125
140
  productId,
126
141
  productName: p.product,
127
142
  unit: p.unit ?? "stuks",
128
- unitPrice: p.sale_price ?? null,
143
+ // Prijs komt uit dezelfde prijsbepaling als Nieuwe bestelling (hieronder), nooit uit een oude lijst.
144
+ unitPrice: null,
129
145
  plantsPerCrate: ppc,
130
146
  cratesPerLayer: cpl,
131
147
  layersPerCart: lpc,
132
148
  quantity: ppc,
133
149
  needsSticker: false,
150
+ priceMode: "auto",
151
+ priceSource: null,
152
+ priceKey: null,
153
+ priceError: false,
134
154
  },
135
155
  ]);
136
156
  };
157
+ // Automatische prijs per nieuwe regel via getOrderPrices (prijsgroep/klantprijs →
158
+ // verkoopprijs artikel → geen prijs). Opnieuw bij een ander aantal of andere datum;
159
+ // een zelf ingevulde prijs blijft staan.
160
+ const fetchOrderPrices = useServerFn(getOrderPrices);
161
+ const priceWanted = newItems
162
+ .map((n) => ({ n, key: n.priceMode === "manual" ? null : prijsSleutel(customerId, n.productId, deliveryDate, n.quantity) }))
163
+ .filter((x) => x.key && x.key !== x.n.priceKey);
164
+ const priceWantedKey = priceWanted.map((x) => `${x.n.key}:${x.key}`).join(",");
165
+ useEffect(() => {
166
+ if (!open || !customerId || priceWanted.length === 0)
167
+ return;
168
+ const todo = priceWanted.map((x) => ({ itemKey: x.n.key, key: x.key, productId: x.n.productId, quantity: x.n.quantity > 0 ? x.n.quantity : undefined }));
169
+ const t = setTimeout(() => {
170
+ const apply = (res) => {
171
+ setNewItems((cur) => cur.map((n) => {
172
+ const i = todo.findIndex((x) => x.itemKey === n.key);
173
+ if (i < 0 || n.priceMode === "manual")
174
+ return n;
175
+ if (prijsSleutel(customerId, n.productId, deliveryDate, n.quantity) !== todo[i].key)
176
+ return n;
177
+ const r = res?.[i];
178
+ if (!r || !r.ok)
179
+ return { ...n, priceError: true, priceKey: todo[i].key, priceSource: null, unitPrice: null };
180
+ const b = bekendePrijs(r.prijs);
181
+ return { ...n, priceError: false, priceKey: todo[i].key, unitPrice: b.unit_price, priceSource: b.price_source };
182
+ }));
183
+ };
184
+ fetchOrderPrices({ data: { customerId, onDate: deliveryDate || undefined, lines: todo.map(({ productId, quantity }) => ({ productId, quantity })) } })
185
+ .then(apply)
186
+ .catch((e) => { console.error("[orderprijs bewerken]", e); apply(null); });
187
+ }, 250);
188
+ return () => clearTimeout(t);
189
+ // eslint-disable-next-line react-hooks/exhaustive-deps
190
+ }, [open, priceWantedKey, customerId, deliveryDate]);
137
191
  // Voorraadcontrole bij bewerken: deze order telt niet mee (voorraad_beschikbaar_v2).
138
192
  // Ontbreekt die functie, dan de oude controle als terugval (modus "terugval").
139
193
  const fetchStockCheck = useServerFn(checkEditOrderStock);
@@ -217,6 +271,13 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
217
271
  return;
218
272
  }
219
273
  }
274
+ {
275
+ const fout = prijsRegelFout(newItems.map((n) => ({ product_name: n.productName, unit_price: n.unitPrice })));
276
+ if (fout) {
277
+ toast.error(fout);
278
+ return;
279
+ }
280
+ }
220
281
  for (const n of newItems) {
221
282
  const ppc = Math.max(1, n.plantsPerCrate);
222
283
  if (n.quantity < ppc || n.quantity % ppc !== 0) {
@@ -275,12 +336,14 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
275
336
  plantsPerCrate: n.plantsPerCrate,
276
337
  cratesPerLayer: n.cratesPerLayer,
277
338
  layersPerCart: n.layersPerCart,
278
- needsSticker: n.needsSticker,
339
+ needsSticker: stickerNieuw ? true : n.needsSticker,
279
340
  }))
280
341
  : undefined,
281
- stickers: items
282
- .filter((i) => !removedIds.includes(i.id))
283
- .map((i) => ({ itemId: i.id, needsSticker: i.needsSticker })),
342
+ stickers: stickerNieuw
343
+ ? undefined
344
+ : items
345
+ .filter((i) => !removedIds.includes(i.id))
346
+ .map((i) => ({ itemId: i.id, needsSticker: i.needsSticker })),
284
347
  },
285
348
  });
286
349
  markIndelingBezig(queryClient, orderId);
@@ -303,19 +366,22 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
303
366
  setSaving(false);
304
367
  }
305
368
  };
306
- return (_jsx("div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4", onClick: () => !saving && onOpenChange(false), children: _jsxs("div", { className: "flex w-full max-w-4xl max-h-[90vh] flex-col rounded-lg border border-border bg-card shadow-lg", onClick: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "shrink-0 p-6 pb-4", children: [_jsx("h2", { className: "text-lg font-semibold text-foreground", children: "Bestelling bewerken" }), _jsxs("p", { className: "mt-1 text-sm text-muted-foreground", children: ["Pas de ", datumLabel(vervoerSoortV).toLowerCase(), " en het aantal planten of fusten per regel aan. Voorraad en karindeling worden automatisch bijgewerkt."] })] }), _jsxs("div", { className: "flex-1 overflow-y-auto px-6 pb-4 min-h-0", children: [loading ? (_jsx("div", { className: "text-sm text-muted-foreground", children: "Laden\u2026" })) : error ? (_jsx("div", { className: "rounded border border-destructive/30 bg-destructive/5 p-3 text-sm text-destructive", children: error })) : (_jsxs("fieldset", { disabled: !!shippedLock, className: "min-w-0", children: [slotDragers.length > 0 && (_jsxs("div", { className: "mb-4 space-y-2", children: [_jsx(KarSlotMelding, { slot: slotDragers[0], orderId: orderId }), _jsx("div", { className: "rounded border border-border bg-muted/40 px-3 py-2 text-sm text-foreground", children: EXTRA_KAR_MELDING })] })), shippedLock && (_jsx("div", { className: "mb-4 rounded border border-border bg-muted/40 px-3 py-2 text-sm text-foreground", children: shippedLock })), _jsxs("div", { className: "space-y-4", children: [floridayCarrierNotice && (_jsxs("div", { role: "status", className: "rounded border border-warning/40 bg-warning-soft px-3 py-2 text-sm text-warning-soft-foreground", children: [_jsx("span", { className: "font-medium", children: "Vervoer:" }), " ", floridayCarrierNotice] })), !isReservation && (_jsxs("div", { children: [_jsx("label", { className: "mb-1 block text-sm font-medium text-foreground", children: datumLabel(vervoerSoortV) }), _jsx(Input, { type: "date", value: deliveryDate, onChange: (e) => setDeliveryDate(e.target.value) })] })), isReservation && (_jsx("div", { className: "rounded border border-border bg-muted/40 px-3 py-2 text-xs text-muted-foreground", children: "Dit is een reservering \u2014 er is nog geen leverdatum. Voeg een bezorgmoment toe om (deels) uit te leveren." })), _jsxs("div", { children: [_jsx("div", { className: "mb-2 text-sm font-medium text-foreground", children: "Regels" }), _jsxs("div", { className: "grid grid-cols-12 gap-2 px-1 text-xs text-muted-foreground", children: [_jsx("div", { className: "col-span-5", children: "Product" }), _jsx("div", { className: "col-span-1 text-center", children: "Sticker" }), _jsx("div", { className: "col-span-3", children: "Planten" }), _jsx("div", { className: "col-span-3", children: "Fusten" })] }), _jsxs("div", { className: "mt-1 space-y-2", children: [priceLock && _jsxs("div", { className: "text-xs text-muted-foreground", children: ["Prijs wijzigen kan niet: ", priceLock] }), items.map((it, idx) => {
369
+ return (_jsx("div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4", onClick: () => !saving && onOpenChange(false), children: _jsxs("div", { className: "flex w-full max-w-4xl max-h-[90vh] flex-col rounded-lg border border-border bg-card shadow-lg", onClick: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "shrink-0 p-6 pb-4", children: [_jsx("h2", { className: "text-lg font-semibold text-foreground", children: "Bestelling bewerken" }), _jsxs("p", { className: "mt-1 text-sm text-muted-foreground", children: ["Pas de ", datumLabel(vervoerSoortV).toLowerCase(), " en het aantal planten of fusten per regel aan. Voorraad en karindeling worden automatisch bijgewerkt."] })] }), _jsxs("div", { className: "flex-1 overflow-y-auto px-6 pb-4 min-h-0", children: [loading ? (_jsx("div", { className: "text-sm text-muted-foreground", children: "Laden\u2026" })) : error ? (_jsx("div", { className: "rounded border border-destructive/30 bg-destructive/5 p-3 text-sm text-destructive", children: error })) : (_jsxs("fieldset", { disabled: !!shippedLock, className: "min-w-0", children: [slotDragers.length > 0 && (_jsxs("div", { className: "mb-4 space-y-2", children: [_jsx(KarSlotMelding, { slot: slotDragers[0], orderId: orderId }), _jsx("div", { className: "rounded border border-border bg-muted/40 px-3 py-2 text-sm text-foreground", children: EXTRA_KAR_MELDING })] })), shippedLock && (_jsx("div", { className: "mb-4 rounded border border-border bg-muted/40 px-3 py-2 text-sm text-foreground", children: shippedLock })), _jsxs("div", { className: "space-y-4", children: [floridayCarrierNotice && (_jsxs("div", { role: "status", className: "rounded border border-warning/40 bg-warning-soft px-3 py-2 text-sm text-warning-soft-foreground", children: [_jsx("span", { className: "font-medium", children: "Vervoer:" }), " ", floridayCarrierNotice] })), !isReservation && (_jsxs("div", { children: [_jsx("label", { className: "mb-1 block text-sm font-medium text-foreground", children: datumLabel(vervoerSoortV) }), _jsx(Input, { type: "date", value: deliveryDate, onChange: (e) => setDeliveryDate(e.target.value) })] })), isReservation && (_jsx("div", { className: "rounded border border-border bg-muted/40 px-3 py-2 text-xs text-muted-foreground", children: "Dit is een reservering \u2014 er is nog geen leverdatum. Voeg een bezorgmoment toe om (deels) uit te leveren." })), _jsxs("div", { children: [_jsx("div", { className: "mb-2 text-sm font-medium text-foreground", children: "Regels" }), _jsxs("div", { className: "grid grid-cols-12 gap-2 px-1 text-xs text-muted-foreground", children: [_jsx("div", { className: "col-span-5", children: "Product" }), _jsx("div", { className: "col-span-1 text-center", children: stickerNieuw ? "" : "Sticker" }), _jsx("div", { className: "col-span-3", children: "Planten" }), _jsx("div", { className: "col-span-3", children: "Fusten" })] }), _jsxs("div", { className: "mt-1 space-y-2", children: [priceLock && _jsxs("div", { className: "text-xs text-muted-foreground", children: ["Prijs wijzigen kan niet: ", priceLock] }), items.map((it, idx) => {
307
370
  const ppc = it.plantsPerCrate;
308
371
  const fusten = ppc !== null ? Math.ceil(it.quantity / ppc) : 0;
309
372
  const removed = removedIds.includes(it.id);
310
- return (_jsxs("div", { className: `grid grid-cols-12 items-start gap-2 rounded border border-border p-2 ${removed ? "opacity-50" : ""}`, children: [_jsxs("div", { className: "col-span-4 min-w-0 text-sm", children: [_jsx("div", { className: `truncate font-medium text-foreground ${removed ? "line-through" : ""}`, children: it.productName }), ppc === null ? (_jsx("div", { className: "text-xs text-destructive", children: "Belading onbekend \u2014 deze regel kan niet opgeslagen worden" })) : (_jsxs("div", { className: "text-xs text-muted-foreground", children: [ppc, " planten per fust"] })), _jsxs("label", { className: "mt-1 flex items-center gap-1 text-xs text-muted-foreground", children: ["Prijs per stuk \u20AC", _jsx(Input, { type: "number", min: 0, step: 0.01, className: "h-7 w-24", "aria-label": "Prijs per stuk", value: it.unitPrice ?? "", disabled: removed || !!priceLock, title: priceLock ?? undefined, onChange: (e) => setItems((prev) => prev.map((p, i) => (i === idx ? { ...p, unitPrice: e.target.value === "" ? null : Number(e.target.value) } : p))) })] }), it.minQuantity > 0 && (_jsxs("div", { className: "text-xs text-primary", children: ["min. ", it.minQuantity, " (reeds ", it.shippedQuantity, " geleverd, ", it.plannedQuantity, " gepland)"] })), stockNote(`item:${it.id}`, it.productId)] }), _jsx("div", { className: "col-span-1 flex h-10 items-center justify-center", children: _jsx("input", { type: "checkbox", className: "h-4 w-4 accent-primary", "aria-label": "Sticker nodig", checked: it.needsSticker, disabled: removed, onChange: (e) => setItems((prev) => prev.map((p, i) => (i === idx ? { ...p, needsSticker: e.target.checked } : p))) }) }), _jsx("div", { className: "col-span-3", children: _jsx(Input, { type: "number", min: 0, step: ppc ?? 1, value: it.quantity, disabled: removed, onChange: (e) => setPlants(idx, Number(e.target.value)) }) }), _jsx("div", { className: "col-span-3", children: _jsx(Input, { type: "number", min: 0, step: 1, value: ppc === null ? "" : fusten, disabled: removed || ppc === null, onChange: (e) => setFusten(idx, Number(e.target.value)) }) }), _jsx("div", { className: "col-span-1 flex justify-end", children: canEditProducts && (_jsx(Button, { variant: "ghost", size: "sm", title: removed ? "Verwijderen ongedaan maken" : "Regel verwijderen", onClick: () => setRemovedIds((prev) => prev.includes(it.id)
373
+ return (_jsxs("div", { className: `grid grid-cols-12 items-start gap-2 rounded border border-border p-2 ${removed ? "opacity-50" : ""}`, children: [_jsxs("div", { className: "col-span-4 min-w-0 text-sm", children: [_jsx("div", { className: `truncate font-medium text-foreground ${removed ? "line-through" : ""}`, children: it.productName }), ppc === null ? (_jsx("div", { className: "text-xs text-destructive", children: "Belading onbekend \u2014 deze regel kan niet opgeslagen worden" })) : (_jsxs("div", { className: "text-xs text-muted-foreground", children: [ppc, " planten per fust"] })), _jsxs("label", { className: "mt-1 flex items-center gap-1 text-xs text-muted-foreground", children: ["Prijs per stuk \u20AC", _jsx(Input, { type: "number", min: 0, step: 0.01, className: "h-7 w-24", "aria-label": "Prijs per stuk", value: it.unitPrice ?? "", disabled: removed || !!priceLock, title: priceLock ?? undefined, onChange: (e) => setItems((prev) => prev.map((p, i) => (i === idx ? { ...p, unitPrice: prijsInvoer(e.target.value) } : p))) })] }), it.minQuantity > 0 && (_jsxs("div", { className: "text-xs text-primary", children: ["min. ", it.minQuantity, " (reeds ", it.shippedQuantity, " geleverd, ", it.plannedQuantity, " gepland)"] })), stockNote(`item:${it.id}`, it.productId)] }), _jsx("div", { className: "col-span-1 flex h-10 items-center justify-center", children: !stickerNieuw && (_jsx("input", { type: "checkbox", className: "h-4 w-4 accent-primary", "aria-label": "Sticker nodig", checked: it.needsSticker, disabled: removed, onChange: (e) => setItems((prev) => prev.map((p, i) => (i === idx ? { ...p, needsSticker: e.target.checked } : p))) })) }), _jsx("div", { className: "col-span-3", children: _jsx(Input, { type: "number", min: 0, step: ppc ?? 1, value: it.quantity, disabled: removed, onChange: (e) => setPlants(idx, Number(e.target.value)) }) }), _jsx("div", { className: "col-span-3", children: _jsx(Input, { type: "number", min: 0, step: 1, value: ppc === null ? "" : fusten, disabled: removed || ppc === null, onChange: (e) => setFusten(idx, Number(e.target.value)) }) }), _jsx("div", { className: "col-span-1 flex justify-end", children: canEditProducts && (_jsx(Button, { variant: "ghost", size: "sm", title: removed ? "Verwijderen ongedaan maken" : "Regel verwijderen", onClick: () => setRemovedIds((prev) => prev.includes(it.id)
311
374
  ? prev.filter((x) => x !== it.id)
312
375
  : [...prev, it.id]), children: _jsx(Trash2, { className: "h-4 w-4" }) })) })] }, it.id));
313
- }), newItems.some((n) => !(Number(n.unitPrice) > 0)) && (_jsxs("div", { className: "rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive", children: ["Geen prijs: ", newItems.filter((n) => !(Number(n.unitPrice) > 0)).length, " nieuwe regel(s) zonder prijs in artikel of prijsgroep."] })), newItems.map((n, idx) => {
376
+ }), newItems.map((n, idx) => {
314
377
  const ppc = Math.max(1, n.plantsPerCrate);
315
378
  const fusten = Math.ceil(n.quantity / ppc);
316
379
  const setNewQty = (plants) => setNewItems((prev) => prev.map((p, i) => i === idx
317
380
  ? { ...p, quantity: Number.isFinite(plants) ? Math.max(0, plants) : 0 }
318
381
  : p));
319
- return (_jsxs("div", { className: "grid grid-cols-12 items-start gap-2 rounded border border-primary/40 bg-primary/5 p-2", children: [_jsxs("div", { className: "col-span-4 min-w-0 text-sm", children: [_jsx("div", { className: "truncate font-medium text-foreground", children: n.productName }), _jsxs("div", { className: "text-xs text-muted-foreground", children: ["nieuw \u00B7 ", ppc, " planten per fust"] }), stockNote(`new:${n.key}`, n.productId)] }), _jsx("div", { className: "col-span-1 flex h-10 items-center justify-center", children: _jsx("input", { type: "checkbox", className: "h-4 w-4 accent-primary", "aria-label": "Sticker nodig", checked: n.needsSticker, onChange: (e) => setNewItems((prev) => prev.map((p, i) => (i === idx ? { ...p, needsSticker: e.target.checked } : p))) }) }), _jsx("div", { className: "col-span-3", children: _jsx(Input, { type: "number", min: 0, step: ppc, value: n.quantity, onChange: (e) => setNewQty(Number(e.target.value)) }) }), _jsx("div", { className: "col-span-3", children: _jsx(Input, { type: "number", min: 0, step: 1, value: fusten, onChange: (e) => setNewQty(Math.max(0, Number(e.target.value)) * ppc) }) }), _jsx("div", { className: "col-span-1 flex justify-end", children: _jsx(Button, { variant: "ghost", size: "sm", title: "Regel verwijderen", onClick: () => setNewItems((prev) => prev.filter((_, i) => i !== idx)), children: _jsx(Trash2, { className: "h-4 w-4" }) }) })] }, n.key));
320
- }), items.length === 0 && newItems.length === 0 && (_jsx("div", { className: "text-sm text-muted-foreground", children: "Geen regels op deze bestelling." }))] }), canEditProducts ? (_jsxs("div", { className: "mt-3", children: [_jsx("div", { className: "mb-1 text-xs text-muted-foreground", children: "Product toevoegen" }), _jsx(SearchableSelect, { value: null, options: productOptions, allowClear: false, placeholder: productsQ.isLoading ? "Producten laden…" : "Zoek een product…", onChange: addProduct, disabled: productsQ.isLoading })] })) : (_jsx("div", { className: "mt-3 rounded border border-border bg-muted/40 px-3 py-2 text-xs text-muted-foreground", children: "Producten kunnen niet meer gewijzigd worden: deze bestelling is al geprint in het Pickstation. Aantallen aanpassen kan wel." }))] })] })] })), stockCheck?.modus === "terugval" && stockCheck.shortages.length > 0 && (_jsx("div", { className: "mt-4 rounded-md border border-border bg-muted/40 p-3 text-sm text-muted-foreground", children: "Voorraad kan bij bewerken nog niet exact worden gecontroleerd; de eigen reservering van deze bestelling telt nog mee." }))] }), _jsxs("div", { className: "shrink-0 border-t border-border p-6 pt-4 flex justify-end gap-2", children: [_jsx(Button, { variant: "outline", size: "sm", onClick: () => onOpenChange(false), disabled: saving, children: "Annuleren" }), _jsx(Button, { size: "sm", onClick: handleSave, disabled: saving || loading || !!error || !!shippedLock, children: saving ? "Bezig…" : "Opslaan" })] })] }) }));
382
+ return (_jsxs("div", { className: "grid grid-cols-12 items-start gap-2 rounded border border-primary/40 bg-primary/5 p-2", children: [_jsxs("div", { className: "col-span-4 min-w-0 text-sm", children: [_jsx("div", { className: "truncate font-medium text-foreground", children: n.productName }), _jsxs("div", { className: "text-xs text-muted-foreground", children: ["nieuw \u00B7 ", ppc, " planten per fust"] }), (() => {
383
+ const pending = n.priceMode === "auto" && !n.priceError && n.priceKey !== prijsSleutel(customerId, n.productId, deliveryDate, n.quantity);
384
+ return (_jsxs(_Fragment, { children: [_jsxs("label", { className: "mt-1 flex items-center gap-1 text-xs text-muted-foreground", children: ["Prijs per stuk \u20AC", _jsx(Input, { type: "number", min: 0, step: 0.01, inputMode: "decimal", className: "h-7 w-24", "aria-label": `Prijs per stuk ${n.productName}`, placeholder: pending ? "…" : "—", value: n.unitPrice ?? "", "aria-invalid": !pending && !(Number(n.unitPrice) > 0), onChange: (e) => setNewItems((prev) => prev.map((p, i) => (i === idx ? { ...p, unitPrice: prijsInvoer(e.target.value), priceMode: "manual", priceSource: "Handmatig", priceError: false } : p))) })] }), n.priceError ? (_jsx("div", { className: "text-xs text-destructive", children: PRIJS_FOUT_TEXT })) : pending ? (_jsx("div", { className: "text-xs text-muted-foreground", children: "Prijs ophalen\u2026" })) : !(Number(n.unitPrice) > 0) ? (_jsx("div", { className: "text-xs text-destructive", children: PRIJS_ONBEKEND_TEXT })) : n.priceSource ? (_jsx("div", { className: "text-xs text-muted-foreground", children: n.priceSource })) : null] }));
385
+ })(), stockNote(`new:${n.key}`, n.productId)] }), _jsx("div", { className: "col-span-1 flex h-10 items-center justify-center", children: !stickerNieuw && (_jsx("input", { type: "checkbox", className: "h-4 w-4 accent-primary", "aria-label": "Sticker nodig", checked: n.needsSticker, onChange: (e) => setNewItems((prev) => prev.map((p, i) => (i === idx ? { ...p, needsSticker: e.target.checked } : p))) })) }), _jsx("div", { className: "col-span-3", children: _jsx(Input, { type: "number", min: 0, step: ppc, value: n.quantity, onChange: (e) => setNewQty(Number(e.target.value)) }) }), _jsx("div", { className: "col-span-3", children: _jsx(Input, { type: "number", min: 0, step: 1, value: fusten, onChange: (e) => setNewQty(Math.max(0, Number(e.target.value)) * ppc) }) }), _jsx("div", { className: "col-span-1 flex justify-end", children: _jsx(Button, { variant: "ghost", size: "sm", title: "Regel verwijderen", onClick: () => setNewItems((prev) => prev.filter((_, i) => i !== idx)), children: _jsx(Trash2, { className: "h-4 w-4" }) }) })] }, n.key));
386
+ }), items.length === 0 && newItems.length === 0 && (_jsx("div", { className: "text-sm text-muted-foreground", children: "Geen regels op deze bestelling." }))] }), canEditProducts ? (_jsxs("div", { className: "mt-3", children: [_jsx("div", { className: "mb-1 text-xs text-muted-foreground", children: "Product toevoegen" }), _jsx(SearchableSelect, { value: null, options: productOptions, allowClear: false, placeholder: productsQ.isLoading ? "Producten laden…" : "Zoek een product…", onChange: addProduct, disabled: productsQ.isLoading })] })) : (_jsx("div", { className: "mt-3 rounded border border-border bg-muted/40 px-3 py-2 text-xs text-muted-foreground", children: "Producten kunnen niet meer gewijzigd worden: deze bestelling is al geprint in het Pickstation. Aantallen aanpassen kan wel." }))] })] })] })), stickerNieuw && (_jsxs("div", { className: "mt-4", children: [_jsx(OrderLineExtrasCard, { orderId: orderId, pickProgress: null, pickKnown: false, pickControleOpServer: true }), newItems.length > 0 && _jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: "Nieuwe regels krijgen hun pot- en fuststicker na opslaan; daarna kun je die hier aanpassen." })] })), stockCheck?.modus === "terugval" && stockCheck.shortages.length > 0 && (_jsx("div", { className: "mt-4 rounded-md border border-border bg-muted/40 p-3 text-sm text-muted-foreground", children: "Voorraad kan bij bewerken nog niet exact worden gecontroleerd; de eigen reservering van deze bestelling telt nog mee." }))] }), _jsxs("div", { className: "shrink-0 border-t border-border p-6 pt-4 flex justify-end gap-2", children: [_jsx(Button, { variant: "outline", size: "sm", onClick: () => onOpenChange(false), disabled: saving, children: "Annuleren" }), _jsx(Button, { size: "sm", onClick: handleSave, disabled: saving || loading || !!error || !!shippedLock, children: saving ? "Bezig…" : "Opslaan" })] })] }) }));
321
387
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KarTekeningSection.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/KarTekeningSection.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAgJ,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAoB,MAAM,oBAAoB,CAAC;AAOnO,wBAAgB,mBAAmB,gCAiBlC;AAED,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;CACvB;AAED,+DAA+D;AAC/D,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,IAAI,EAAE;IACJ,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IACjC,2FAA2F;IAC3F,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;CAC3C,GACA,gBAAgB,CAqGlB"}
1
+ {"version":3,"file":"KarTekeningSection.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/KarTekeningSection.tsx"],"names":[],"mappings":"AAYA,OAAO,EAA8L,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAoB,MAAM,oBAAoB,CAAC;AAOjR,wBAAgB,mBAAmB,gCAiBlC;AAED,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;CACvB;AAED,+DAA+D;AAC/D,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,IAAI,EAAE;IACJ,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IACjC,2FAA2F;IAC3F,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;CAC3C,GACA,gBAAgB,CAqGlB"}
@@ -11,7 +11,7 @@ import { AlertTriangle, Info, Loader2, PencilRuler } from "lucide-react";
11
11
  import { useRouter } from "@tanstack/react-router";
12
12
  import { karBewerkenPad, karBewerkenStand } from "../../lib/engine-tijdlijn.js";
13
13
  import { getIndelingStand, getKarTekening } from "../../lib/kar-tekening.functions.js";
14
- import { dragerTitel, dragersKop, gedeeldTekst, markeringTekst, lagenTekst, langBezig, POLL_MS, regelBeladingTekst, statusLabel, toonDozen, toonStand } from "../../lib/kar-tekening.js";
14
+ import { artikelKleur, legendaTekst, legendaVoorRegel, dragerTitel, dragersKop, gedeeldTekst, markeringTekst, lagenTekst, langBezig, POLL_MS, regelBeladingTekst, statusLabel, toonDozen, toonStand } from "../../lib/kar-tekening.js";
15
15
  import { bezigKey } from "../../lib/indeling-bezig.js";
16
16
  import { korteMelding } from "../../lib/korte-melding.js";
17
17
  import { SafeSvg } from "./SafeSvg.js";
@@ -138,15 +138,22 @@ function IndelingAanpassen({ tek, orderDbId }) {
138
138
  }
139
139
  function TekeningInhoud({ tek, orderId, orderDbId, floriday, onLagen, regels }) {
140
140
  const [groot, setGroot] = useState(null);
141
- return (_jsxs("div", { className: "space-y-3", children: [tek.meldingen.length > 0 && (_jsx("ul", { className: "space-y-1 rounded-lg border border-border bg-muted/40 px-3 py-2 text-xs text-foreground", children: tek.meldingen.map((m, i) => (_jsxs("li", { className: "flex items-start gap-1.5", children: [_jsx(Info, { className: "mt-0.5 h-3 w-3 shrink-0 text-muted-foreground", "aria-hidden": true }), m] }, i))) })), _jsx(IndelingAanpassen, { tek: tek, orderDbId: orderDbId }), _jsx("div", { className: "-mx-1 flex gap-2 overflow-x-auto px-1 pb-1", children: tek.dragers.map((d) => (_jsx("button", { type: "button", onClick: () => setGroot(d), className: "shrink-0 rounded-lg border border-border bg-card p-1 transition-shadow hover:border-ring/50 hover:shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-ring", "aria-label": `Grote tekening van ${dragerTitel(d)}`, title: dragerTitel(d), children: d.svg ? _jsx(SafeSvg, { svg: d.svg, className: "h-16 w-12 [&>svg]:h-full [&>svg]:w-full", label: dragerTitel(d) }) : _jsx("div", { className: "flex h-16 w-12 items-center justify-center text-xs tabular-nums text-muted-foreground", children: d.nummer ?? "—" }) }, d.id))) }), tek.dragers.length === 0 && tek.svg_rij && _jsx(SafeSvg, { svg: tek.svg_rij, className: "overflow-x-auto", label: "Overzicht van de indeling" }), _jsx("div", { className: "grid gap-3 md:grid-cols-2", children: tek.dragers.map((d) => _jsx(DragerKaart, { d: d, orderId: orderId, regels: regels?.get(d.id) ?? [], floriday: floriday, onGroot: () => setGroot(d), onLagen: onLagen }, d.id)) }), _jsx(Dialog, { open: !!groot, onOpenChange: (v) => { if (!v)
141
+ return (_jsxs("div", { className: "space-y-3", children: [tek.meldingen.length > 0 && (_jsx("ul", { className: "space-y-1 rounded-lg border border-border bg-muted/40 px-3 py-2 text-xs text-foreground", children: tek.meldingen.map((m, i) => (_jsxs("li", { className: "flex items-start gap-1.5", children: [_jsx(Info, { className: "mt-0.5 h-3 w-3 shrink-0 text-muted-foreground", "aria-hidden": true }), m] }, i))) })), _jsx(IndelingAanpassen, { tek: tek, orderDbId: orderDbId }), _jsx("div", { className: "-mx-1 flex gap-2 overflow-x-auto px-1 pb-1", children: tek.dragers.map((d) => (_jsx("button", { type: "button", onClick: () => setGroot(d), className: "shrink-0 rounded-lg border border-border bg-card p-1 transition-shadow hover:border-ring/50 hover:shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-ring", "aria-label": `Grote tekening van ${dragerTitel(d)}`, title: dragerTitel(d), children: d.svg ? _jsx(SafeSvg, { svg: d.svg, className: "h-16 w-12 [&>svg]:h-full [&>svg]:w-full", label: dragerTitel(d) }) : _jsx("div", { className: "flex h-16 w-12 items-center justify-center text-xs tabular-nums text-muted-foreground", children: d.nummer ?? "—" }) }, d.id))) }), tek.dragers.length === 0 && tek.svg_rij && _jsx(SafeSvg, { svg: tek.svg_rij, className: "overflow-x-auto", label: "Overzicht van de indeling" }), _jsx("div", { className: "grid gap-3 md:grid-cols-2", children: tek.dragers.map((d) => _jsx(DragerKaart, { d: d, kleuren: tek.kleuren, orderId: orderId, regels: regels?.get(d.id) ?? [], floriday: floriday, onGroot: () => setGroot(d), onLagen: onLagen }, d.id)) }), _jsx(Dialog, { open: !!groot, onOpenChange: (v) => { if (!v)
142
142
  setGroot(null); }, children: _jsxs(DialogContent, { className: "max-w-2xl", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: groot ? dragerTitel(groot) : "" }) }), groot?.svg ? _jsx(SafeSvg, { svg: groot.svg, className: "max-h-[70vh] overflow-auto [&>svg]:h-auto [&>svg]:w-full", label: dragerTitel(groot) }) : _jsx("p", { className: "text-sm text-muted-foreground", children: "Geen tekening beschikbaar." })] }) })] }));
143
143
  }
144
- function DragerKaart({ d, orderId, regels, floriday, onGroot, onLagen }) {
144
+ function DragerKaart({ d, kleuren, orderId, regels, floriday, onGroot, onLagen }) {
145
145
  const pct = d.vulgraad_pct != null ? Math.max(0, Math.min(100, Math.round(d.vulgraad_pct))) : null;
146
146
  const status = statusLabel(d.status);
147
147
  const dozen = toonDozen(regels);
148
148
  const gedeeld = gedeeldTekst(d.gedeeld_met);
149
149
  const lagen = lagenTekst(d.lagen_gebruikt, d.lagen_max);
150
150
  const rood = markeringTekst(d);
151
- return (_jsxs("div", { className: `min-w-0 space-y-2 rounded-xl border bg-card p-3 shadow-sm ${rood ? "border-destructive" : "border-border"}`, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "font-medium text-foreground", children: dragerTitel(d) }), rood && _jsxs(Badge, { variant: "destructive", className: "rounded-full", children: [_jsx(AlertTriangle, { className: "mr-1 h-3 w-3", "aria-hidden": true }), rood] }), status && _jsx(Badge, { variant: "outline", className: "rounded-full", children: status }), floriday && d.floriday_gelijk === true && _jsx(Badge, { variant: "secondary", className: "rounded-full", children: "Floriday gelijk" }), gedeeld && _jsx(Badge, { variant: "outline", className: "rounded-full", children: gedeeld })] }), (d.nummer != null || d.letters.length > 0) && (_jsx("div", { className: "text-xs tabular-nums text-muted-foreground", children: karKop({ nummer: d.nummer, vulgraad_pct: d.vulgraad_pct, letters: d.letters, naam: d.naam }) })), _jsx(KarSlotMelding, { slot: d, orderId: orderId, compact: true }), pct != null && (_jsxs("div", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [_jsx("div", { className: "h-2 flex-1 overflow-hidden rounded-full bg-muted", role: "progressbar", "aria-valuenow": pct, "aria-valuemin": 0, "aria-valuemax": 100, "aria-label": "Vulgraad", children: _jsx("div", { className: "h-full rounded-full bg-primary", style: { width: `${pct}%` } }) }), _jsxs("span", { className: "tabular-nums", children: [pct, "%"] })] })), lagen && _jsx("div", { className: "text-xs tabular-nums text-muted-foreground", children: lagen }), d.waarschuwingen.length > 0 && (_jsx("ul", { className: "space-y-0.5 text-xs text-foreground", children: d.waarschuwingen.map((w, i) => (_jsxs("li", { className: "flex items-start gap-1", children: [_jsx(AlertTriangle, { className: "mt-0.5 h-3 w-3 shrink-0 text-warning" }), w] }, i))) })), d.svg && (_jsx("button", { type: "button", onClick: onGroot, className: "block w-full rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-ring", "aria-label": `Grote tekening van ${dragerTitel(d)}`, children: _jsx(SafeSvg, { svg: d.svg, className: "max-h-64 overflow-hidden [&>svg]:mx-auto [&>svg]:h-auto [&>svg]:max-h-64 [&>svg]:w-full", label: dragerTitel(d) }) })), regels.length > 0 && (_jsx("div", { className: "overflow-x-auto", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "Artikel" }), _jsx(TableHead, { children: "Fusten" }), dozen && _jsx(TableHead, { children: "Dozen" }), _jsx(TableHead, { children: "Belading" })] }) }), _jsx(TableBody, { children: regels.map((a) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "min-w-0", children: a.product }), _jsx(TableCell, { className: "tabular-nums", children: a.fusten ?? "—" }), dozen && _jsx(TableCell, { className: "tabular-nums", children: a.dozen ?? "—" }), _jsx(TableCell, { className: "text-xs text-muted-foreground", children: regelBeladingTekst(a, d) })] }, a.key))) })] }) })), onLagen && d.soort === "layered" && (_jsx(Button, { variant: "outline", size: "sm", className: "h-8", onClick: () => onLagen(d), children: "Lagen bekijken" }))] }));
151
+ return (_jsxs("div", { className: `min-w-0 space-y-2 rounded-xl border bg-card p-3 shadow-sm ${rood ? "border-destructive" : "border-border"}`, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "font-medium text-foreground", children: dragerTitel(d) }), rood && _jsxs(Badge, { variant: "destructive", className: "rounded-full", children: [_jsx(AlertTriangle, { className: "mr-1 h-3 w-3", "aria-hidden": true }), rood] }), status && _jsx(Badge, { variant: "outline", className: "rounded-full", children: status }), floriday && d.floriday_gelijk === true && _jsx(Badge, { variant: "secondary", className: "rounded-full", children: "Floriday gelijk" }), gedeeld && _jsx(Badge, { variant: "outline", className: "rounded-full", children: gedeeld })] }), (d.nummer != null || d.letters.length > 0) && (_jsx("div", { className: "text-xs tabular-nums text-muted-foreground", children: karKop({ nummer: d.nummer, vulgraad_pct: d.vulgraad_pct, letters: d.letters, naam: d.naam }) })), _jsx(KarSlotMelding, { slot: d, orderId: orderId, compact: true }), pct != null && (_jsxs("div", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [_jsx("div", { className: "h-2 flex-1 overflow-hidden rounded-full bg-muted", role: "progressbar", "aria-valuenow": pct, "aria-valuemin": 0, "aria-valuemax": 100, "aria-label": "Vulgraad", children: _jsx("div", { className: "h-full rounded-full bg-primary", style: { width: `${pct}%` } }) }), _jsxs("span", { className: "tabular-nums", children: [pct, "%"] })] })), lagen && _jsx("div", { className: "text-xs tabular-nums text-muted-foreground", children: lagen }), d.waarschuwingen.length > 0 && (_jsx("ul", { className: "space-y-0.5 text-xs text-foreground", children: d.waarschuwingen.map((w, i) => (_jsxs("li", { className: "flex items-start gap-1", children: [_jsx(AlertTriangle, { className: "mt-0.5 h-3 w-3 shrink-0 text-warning" }), w] }, i))) })), d.svg && (_jsx("button", { type: "button", onClick: onGroot, className: "block w-full rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-ring", "aria-label": `Grote tekening van ${dragerTitel(d)}`, children: _jsx(SafeSvg, { svg: d.svg, className: "max-h-64 overflow-hidden [&>svg]:mx-auto [&>svg]:h-auto [&>svg]:max-h-64 [&>svg]:w-full", label: dragerTitel(d) }) })), d.legenda.length > 0 && (_jsx("ul", { className: "flex flex-wrap gap-x-3 gap-y-1 text-xs text-foreground", "aria-label": "Legenda", children: d.legenda.map((l) => (_jsxs("li", { className: "flex items-center gap-1.5", children: [_jsx(ArtikelLetter, { letter: l.letter, kleur: artikelKleur(l.letter, kleuren) }), _jsx("span", { className: "min-w-0 break-words", children: legendaTekst(l).replace(/^\S+ = /, "") })] }, l.letter))) })), regels.length > 0 && (_jsx("div", { className: "overflow-x-auto", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [d.legenda.length > 0 && _jsx(TableHead, { className: "w-10", children: _jsx("span", { className: "sr-only", children: "Letter" }) }), _jsx(TableHead, { children: "Artikel" }), _jsx(TableHead, { children: "Fusten" }), dozen && _jsx(TableHead, { children: "Dozen" }), _jsx(TableHead, { children: "Belading" })] }) }), _jsx(TableBody, { children: regels.map((a) => (_jsxs(TableRow, { children: [d.legenda.length > 0 && (() => {
152
+ const l = legendaVoorRegel(a.product, d.legenda);
153
+ return _jsx(TableCell, { children: l ? _jsx(ArtikelLetter, { letter: l.letter, kleur: artikelKleur(l.letter, kleuren) }) : _jsx("span", { className: "text-muted-foreground", children: "\u2014" }) });
154
+ })(), _jsx(TableCell, { className: "min-w-0", children: a.product }), _jsx(TableCell, { className: "tabular-nums", children: a.fusten ?? "—" }), dozen && _jsx(TableCell, { className: "tabular-nums", children: a.dozen ?? "—" }), _jsx(TableCell, { className: "text-xs text-muted-foreground", children: regelBeladingTekst(a, d) })] }, a.key))) })] }) })), onLagen && d.soort === "layered" && (_jsx(Button, { variant: "outline", size: "sm", className: "h-8", onClick: () => onLagen(d), children: "Lagen bekijken" }))] }));
155
+ }
156
+ /** Letter van een artikel met zijn kleur (zelfde letters als de legenda op de pakbon). */
157
+ function ArtikelLetter({ letter, kleur }) {
158
+ return (_jsxs("span", { className: "relative inline-flex h-5 min-w-5 shrink-0 items-center justify-center overflow-hidden rounded px-1 text-[11px] font-semibold text-foreground ring-1 ring-border", children: [_jsx("span", { "aria-hidden": true, className: "absolute inset-0 opacity-40", style: { backgroundColor: kleur } }), _jsx("span", { className: "relative", children: letter })] }));
152
159
  }