@flowselections/floriday-verkoop-module 1.0.166 → 1.0.168

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 (114) hide show
  1. package/dist-lib/components/verkoop/CreateOrderPage.d.ts.map +1 -1
  2. package/dist-lib/components/verkoop/CreateOrderPage.js +155 -34
  3. package/dist-lib/components/verkoop/EditLocalOrderDialog.d.ts.map +1 -1
  4. package/dist-lib/components/verkoop/EditLocalOrderDialog.js +63 -8
  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/OrderCarrierPicker.d.ts.map +1 -1
  8. package/dist-lib/components/verkoop/OrderCarrierPicker.js +1 -0
  9. package/dist-lib/components/verkoop/OrderTransportCard.d.ts +9 -0
  10. package/dist-lib/components/verkoop/OrderTransportCard.d.ts.map +1 -1
  11. package/dist-lib/components/verkoop/OrderTransportCard.js +21 -2
  12. package/dist-lib/components/verkoop/SalesOrderDetailPage.d.ts.map +1 -1
  13. package/dist-lib/components/verkoop/SalesOrderDetailPage.js +13 -8
  14. package/dist-lib/components/verkoop/SalesOrderDetailView.d.ts.map +1 -1
  15. package/dist-lib/components/verkoop/SalesOrderDetailView.js +26 -4
  16. package/dist-lib/components/verkoop/SearchableSelect.d.ts.map +1 -1
  17. package/dist-lib/components/verkoop/SearchableSelect.js +11 -3
  18. package/dist-lib/components/verkoop/regel/OrderLineExtrasCard.d.ts +8 -0
  19. package/dist-lib/components/verkoop/regel/OrderLineExtrasCard.d.ts.map +1 -0
  20. package/dist-lib/components/verkoop/regel/OrderLineExtrasCard.js +107 -0
  21. package/dist-lib/components/verkoop/regel/RegelGegevensVelden.d.ts +19 -0
  22. package/dist-lib/components/verkoop/regel/RegelGegevensVelden.d.ts.map +1 -0
  23. package/dist-lib/components/verkoop/regel/RegelGegevensVelden.js +33 -0
  24. package/dist-lib/integrations/supabase/types.d.ts +1492 -68
  25. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  26. package/dist-lib/lib/create-order-customers.d.ts +13 -0
  27. package/dist-lib/lib/create-order-customers.d.ts.map +1 -1
  28. package/dist-lib/lib/create-order-customers.js +41 -0
  29. package/dist-lib/lib/create-order-form.d.ts +30 -1
  30. package/dist-lib/lib/create-order-form.d.ts.map +1 -1
  31. package/dist-lib/lib/create-order-form.js +55 -1
  32. package/dist-lib/lib/create-order.functions.d.ts +16 -7
  33. package/dist-lib/lib/create-order.functions.d.ts.map +1 -1
  34. package/dist-lib/lib/create-order.functions.js +104 -21
  35. package/dist-lib/lib/customer-stickers.d.ts +2 -1
  36. package/dist-lib/lib/customer-stickers.d.ts.map +1 -1
  37. package/dist-lib/lib/customer-stickers.js +2 -2
  38. package/dist-lib/lib/departure-preview.functions.d.ts.map +1 -1
  39. package/dist-lib/lib/departure-preview.functions.js +3 -1
  40. package/dist-lib/lib/engine-tijdlijn.d.ts +11 -0
  41. package/dist-lib/lib/engine-tijdlijn.d.ts.map +1 -1
  42. package/dist-lib/lib/engine-tijdlijn.js +26 -0
  43. package/dist-lib/lib/engine-tijdlijn.server.d.ts +47 -0
  44. package/dist-lib/lib/engine-tijdlijn.server.d.ts.map +1 -1
  45. package/dist-lib/lib/engine-tijdlijn.server.js +119 -0
  46. package/dist-lib/lib/floriday-carrier-notice.d.ts +28 -0
  47. package/dist-lib/lib/floriday-carrier-notice.d.ts.map +1 -0
  48. package/dist-lib/lib/floriday-carrier-notice.js +44 -0
  49. package/dist-lib/lib/floriday-carrier-notice.server.d.ts +8 -0
  50. package/dist-lib/lib/floriday-carrier-notice.server.d.ts.map +1 -0
  51. package/dist-lib/lib/floriday-carrier-notice.server.js +57 -0
  52. package/dist-lib/lib/floriday-external-fulfillment.server.d.ts.map +1 -1
  53. package/dist-lib/lib/floriday-external-fulfillment.server.js +15 -11
  54. package/dist-lib/lib/floriday-mirror.server.d.ts.map +1 -1
  55. package/dist-lib/lib/floriday-mirror.server.js +58 -42
  56. package/dist-lib/lib/kar-handmatig.d.ts +5 -0
  57. package/dist-lib/lib/kar-handmatig.d.ts.map +1 -1
  58. package/dist-lib/lib/kar-handmatig.js +21 -0
  59. package/dist-lib/lib/kar-tekening.d.ts +23 -0
  60. package/dist-lib/lib/kar-tekening.d.ts.map +1 -1
  61. package/dist-lib/lib/kar-tekening.js +51 -1
  62. package/dist-lib/lib/module-version.d.ts +1 -1
  63. package/dist-lib/lib/module-version.js +1 -1
  64. package/dist-lib/lib/order-bijwerken.server.d.ts +20 -0
  65. package/dist-lib/lib/order-bijwerken.server.d.ts.map +1 -0
  66. package/dist-lib/lib/order-bijwerken.server.js +31 -0
  67. package/dist-lib/lib/order-cancel.server.d.ts.map +1 -1
  68. package/dist-lib/lib/order-cancel.server.js +33 -23
  69. package/dist-lib/lib/order-carrier.functions.d.ts.map +1 -1
  70. package/dist-lib/lib/order-carrier.functions.js +4 -13
  71. package/dist-lib/lib/order-cf-merge.d.ts +17 -0
  72. package/dist-lib/lib/order-cf-merge.d.ts.map +1 -0
  73. package/dist-lib/lib/order-cf-merge.js +51 -0
  74. package/dist-lib/lib/order-item-packing.functions.d.ts +20 -0
  75. package/dist-lib/lib/order-item-packing.functions.d.ts.map +1 -1
  76. package/dist-lib/lib/order-item-packing.functions.js +26 -5
  77. package/dist-lib/lib/order-line-extras.d.ts +157 -0
  78. package/dist-lib/lib/order-line-extras.d.ts.map +1 -0
  79. package/dist-lib/lib/order-line-extras.functions.d.ts +55 -0
  80. package/dist-lib/lib/order-line-extras.functions.d.ts.map +1 -0
  81. package/dist-lib/lib/order-line-extras.functions.js +184 -0
  82. package/dist-lib/lib/order-line-extras.js +281 -0
  83. package/dist-lib/lib/order-nav.d.ts +8 -0
  84. package/dist-lib/lib/order-nav.d.ts.map +1 -1
  85. package/dist-lib/lib/order-nav.js +13 -0
  86. package/dist-lib/lib/order-pickup.functions.d.ts.map +1 -1
  87. package/dist-lib/lib/order-pickup.functions.js +5 -9
  88. package/dist-lib/lib/order-status.d.ts +9 -1
  89. package/dist-lib/lib/order-status.d.ts.map +1 -1
  90. package/dist-lib/lib/order-status.js +8 -0
  91. package/dist-lib/lib/order-transport.functions.d.ts +9 -0
  92. package/dist-lib/lib/order-transport.functions.d.ts.map +1 -1
  93. package/dist-lib/lib/order-transport.functions.js +21 -3
  94. package/dist-lib/lib/order-transport.server.d.ts +1 -0
  95. package/dist-lib/lib/order-transport.server.d.ts.map +1 -1
  96. package/dist-lib/lib/order-transport.server.js +15 -1
  97. package/dist-lib/lib/own-transport.d.ts +6 -0
  98. package/dist-lib/lib/own-transport.d.ts.map +1 -1
  99. package/dist-lib/lib/own-transport.js +12 -0
  100. package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
  101. package/dist-lib/lib/salesorders-list.server.js +41 -3
  102. package/dist-lib/lib/salesorders.functions.d.ts.map +1 -1
  103. package/dist-lib/lib/salesorders.functions.js +12 -2
  104. package/dist-lib/lib/useBufferEvents.d.ts.map +1 -1
  105. package/dist-lib/lib/useBufferEvents.js +2 -1
  106. package/dist-lib/lib/useLocalSalesOrderDetailQuery.d.ts.map +1 -1
  107. package/dist-lib/lib/useLocalSalesOrderDetailQuery.js +7 -1
  108. package/dist-lib/lib/useSalesOrderDetailQuery.d.ts.map +1 -1
  109. package/dist-lib/lib/useSalesOrderDetailQuery.js +5 -0
  110. package/dist-lib/lib/voorraad-vrij.d.ts +30 -0
  111. package/dist-lib/lib/voorraad-vrij.d.ts.map +1 -0
  112. package/dist-lib/lib/voorraad-vrij.js +64 -0
  113. package/package.json +4 -4
  114. package/schema/verkoop.sql +630 -0
@@ -1 +1 @@
1
- {"version":3,"file":"CreateOrderPage.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/CreateOrderPage.tsx"],"names":[],"mappings":"AA0GA,wBAAgB,eAAe,gCAu1C9B"}
1
+ {"version":3,"file":"CreateOrderPage.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/CreateOrderPage.tsx"],"names":[],"mappings":"AA2HA,wBAAgB,eAAe,gCAo+C9B"}
@@ -8,22 +8,27 @@ import { formatBelading } from "../../lib/belading-format.js";
8
8
  // van de Logistiek Engine (logistics_departure_preview).
9
9
  import { useEffect, useMemo, useRef, useState } from "react";
10
10
  import { Button, Input, Label, Textarea, toast, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@flowselections/core";
11
- import { Link, useBlocker, useNavigate } from "@tanstack/react-router";
11
+ import { Link, useBlocker, useNavigate, useRouter } from "@tanstack/react-router";
12
12
  import { keepPreviousData, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
13
13
  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
- import { isOwnTransportKind, ownPickupLabel, vervoerSoort, vervoerderKeuzes, vertrekControle, 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";
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, 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
- import { listCustomersForCreateOrder, ensureCustomerFromTwinfield, listProductsForCreateOrder, listCustomerStickerProducts, listDeliveryLocationsForCustomerCO, listPickupLocationsCO, getLastPickupLocationCO, listCarriersForCreateOrder, getOrderPickDaysCO, listBeladingOptionsForProducts, createManualOrder, getOrderPrices, } from "../../lib/create-order.functions.js";
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";
28
+ import { listLineStickerOptions, getLineFieldDefinitions } from "../../lib/order-line-extras.functions.js";
29
+ import { geldigeStickerKeuze, isTimeoutFout, normRegelVelden, opmerkingNorm, regelVeldenTekst, standaardRegelVelden, stickerOntbreekt } from "../../lib/order-line-extras.js";
30
+ import { klantPad } from "../../lib/kar-handmatig.js";
31
+ import { RegelGegevensVelden } from "./regel/RegelGegevensVelden.js";
27
32
  import { useAllowedLoadCarriers } from "../../lib/useAllowedLoadCarriers.js";
28
33
  const beladingKey = (b) => `${b.plants_per_crate}x${b.crates_per_layer}x${b.layers_per_cart}`;
29
34
  const beladingLabel = (b) => formatBelading({ perFust: b.plants_per_crate, fustenPerLaag: b.crates_per_layer, lagenPerKar: b.layers_per_cart }) ?? "Belading onbekend";
@@ -55,7 +60,8 @@ export function CreateOrderPage() {
55
60
  const fetchPickDays = useServerFn(getOrderPickDaysCO);
56
61
  const fetchBeladingen = useServerFn(listBeladingOptionsForProducts);
57
62
  const fetchCreate = useServerFn(createManualOrder);
58
- const fetchStickerProducts = useServerFn(listCustomerStickerProducts);
63
+ const fetchStickerOptions = useServerFn(listLineStickerOptions);
64
+ const fetchFieldDefs = useServerFn(getLineFieldDefinitions);
59
65
  const loadCarriersEngine = useAllowedLoadCarriers();
60
66
  // Fouten niet inslikken: elke query toont zijn fout boven het formulier.
61
67
  // Keuzelijsten na de eerste keer onthouden (in het geheugen van de pagina).
@@ -194,21 +200,75 @@ export function CreateOrderPage() {
194
200
  // Standaard stickervinkje: aan als er voor deze klant + dit product een
195
201
  // vaste klantsticker bestaat. Een zelf gezet vinkje blijft staan.
196
202
  const stickerProductKey = Array.from(new Set(lines.map((l) => l.product_id).filter((v) => !!v))).sort();
203
+ // Product- en fuststickers per artikel voor deze klant (met klantstandaard).
204
+ const customerIsUuid = !!customerId && /^[0-9a-f-]{36}$/i.test(customerId);
197
205
  const stickerQ = useQuery({
198
- queryKey: ["co-sticker-products", customerId, stickerProductKey],
199
- enabled: !!customerId && stickerProductKey.length > 0,
206
+ queryKey: ["co-sticker-options", customerId, stickerProductKey],
207
+ enabled: customerIsUuid && stickerProductKey.length > 0,
200
208
  staleTime: 60000,
201
- queryFn: async () => {
202
- try {
203
- return await fetchStickerProducts({ data: { customerId: customerId, productIds: stickerProductKey } });
204
- }
205
- catch {
206
- return { productIds: [] };
207
- }
208
- },
209
+ placeholderData: keepPreviousData,
210
+ queryFn: () => fetchStickerOptions({ data: { customerId: customerId, productIds: stickerProductKey } }),
211
+ });
212
+ if (stickerQ.isError)
213
+ console.error("[stickers] opties laden mislukt:", stickerQ.error);
214
+ const stickerOpts = customerIsUuid ? (stickerQ.data?.byProduct ?? {}) : {};
215
+ const stickerFout = stickerQ.data?.error ?? (stickerQ.isError ? "Stickers van deze klant konden niet worden geladen." : null);
216
+ // Extra regelvelden (definities + klantstandaard) uit Klanten; ontbreekt die functie, dan geen velden.
217
+ const fieldDefsQ = useQuery({
218
+ queryKey: ["co-line-fields", customerId],
219
+ enabled: customerIsUuid,
220
+ staleTime: 5 * 60000,
221
+ queryFn: () => fetchFieldDefs({ data: { customerId: customerId } }),
209
222
  });
223
+ if (fieldDefsQ.isError)
224
+ console.error("[regelvelden] laden mislukt:", fieldDefsQ.error);
225
+ const fieldDefs = customerIsUuid ? (fieldDefsQ.data?.velden ?? []) : [];
226
+ const fieldDefsKey = customerIsUuid && fieldDefsQ.isSuccess ? `${customerId}|${fieldDefs.map((d) => d.key).join(",")}` : null;
227
+ // Nieuwe of andere klant: extra velden vooraf met de klantstandaard vullen (eigen invoer blijft bij dezelfde klant).
228
+ useEffect(() => {
229
+ if (!fieldDefsKey)
230
+ return;
231
+ setLines((cur) => {
232
+ if (!cur.some((l) => l.fields_init_for !== fieldDefsKey))
233
+ return cur;
234
+ return cur.map((l) => (l.fields_init_for === fieldDefsKey ? l : { ...l, line_fields: standaardRegelVelden(fieldDefs), fields_init_for: fieldDefsKey }));
235
+ });
236
+ // eslint-disable-next-line react-hooks/exhaustive-deps
237
+ }, [fieldDefsKey, lines.length]);
238
+ // Stickerkeuze per regel: klantstandaard, tenzij zelf gekozen voor dit product.
239
+ useEffect(() => {
240
+ if (!customerIsUuid || stickerQ.isFetching || !stickerQ.data)
241
+ return;
242
+ setLines((cur) => {
243
+ let changed = false;
244
+ const next = cur.map((l) => {
245
+ if (!l.product_id)
246
+ return l;
247
+ const o = stickerOpts[l.product_id];
248
+ if (!o)
249
+ return l;
250
+ if (l.sticker_choice_for === l.product_id) {
251
+ const ps = geldigeStickerKeuze(l.product_sticker_id ?? "", o.product, o.standaardProduct);
252
+ const fs = geldigeStickerKeuze(l.fust_sticker_id ?? "", o.fust, o.standaardFust);
253
+ if (ps === (l.product_sticker_id ?? null) && fs === (l.fust_sticker_id ?? null))
254
+ return l;
255
+ changed = true;
256
+ return { ...l, product_sticker_id: ps, fust_sticker_id: fs };
257
+ }
258
+ const auto = `auto:${l.product_id}`;
259
+ if (l.sticker_choice_for === auto && (l.product_sticker_id ?? null) === o.standaardProduct && (l.fust_sticker_id ?? null) === o.standaardFust)
260
+ return l;
261
+ changed = true;
262
+ return { ...l, product_sticker_id: o.standaardProduct, fust_sticker_id: o.standaardFust, sticker_choice_for: auto };
263
+ });
264
+ return changed ? next : cur;
265
+ });
266
+ // eslint-disable-next-line react-hooks/exhaustive-deps
267
+ }, [customerIsUuid, stickerQ.data, stickerQ.isFetching, lines.map((l) => `${l.product_id}|${l.sticker_choice_for}`).join(",")]);
268
+ const router = useRouter();
269
+ const stickerKlantLink = klantPad(router, customerIsUuid ? customerId : null);
210
270
  useEffect(() => {
211
- const withSticker = new Set(customerId ? (stickerQ.data?.productIds ?? []) : []);
271
+ const withSticker = new Set(customerId ? Object.entries(stickerOpts).filter(([, o]) => o.product.length > 0).map(([k]) => k) : []);
212
272
  if (customerId && stickerQ.isFetching)
213
273
  return;
214
274
  // Altijd op de nieuwste regels werken: een verouderde kopie wiste eerder een
@@ -223,6 +283,8 @@ export function CreateOrderPage() {
223
283
  const beladingQ = useQuery({
224
284
  queryKey: ["co-beladingen", selectedProductIds.join(",")],
225
285
  enabled: selectedProductIds.length > 0,
286
+ // Vorige opties blijven staan; de belading van het product staat direct op de regel.
287
+ placeholderData: keepPreviousData,
226
288
  // Kort vers houden; bij opslaan controleert de server opnieuw.
227
289
  staleTime: 15000,
228
290
  gcTime: 5 * 60000,
@@ -265,17 +327,20 @@ export function CreateOrderPage() {
265
327
  enabled: selectedProductIds.length > 0,
266
328
  staleTime: 30000,
267
329
  queryFn: async () => {
330
+ // Per regel onthouden waarvoor het oordeel gevraagd is (zie actueelOordeel).
331
+ const gevraagd = Object.fromEntries(plannableRegels.map((r) => [r.key, JSON.stringify(r)]));
268
332
  try {
269
- return await fetchPlannability({ data: { productIds: selectedProductIds.filter((x) => /^[0-9a-f-]{36}$/i.test(x)), regels: plannableRegels } });
333
+ return { ...(await fetchPlannability({ data: { productIds: selectedProductIds.filter((x) => /^[0-9a-f-]{36}$/i.test(x)), regels: plannableRegels } })), gevraagd };
270
334
  }
271
335
  catch {
272
- return { impossible: {}, available: false };
336
+ return { impossible: {}, available: false, gevraagd };
273
337
  }
274
338
  },
275
339
  });
276
- const impossibleByLine = plannableQ.data?.impossibleByLine ?? {};
340
+ const regelNu = useMemo(() => Object.fromEntries(plannableRegels.map((r) => [r.key, JSON.stringify(r)])), [plannableRegels]);
341
+ const impossibleByLine = actueelOordeel(plannableQ.data?.impossibleByLine, plannableQ.data?.gevraagd, regelNu);
277
342
  const missingByProduct = plannableQ.data?.missing ?? {};
278
- const missingByLine = plannableQ.data?.missingByLine ?? {};
343
+ const missingByLine = actueelOordeel(plannableQ.data?.missingByLine, plannableQ.data?.gevraagd, regelNu);
279
344
  const beladingByProduct = beladingQ.data?.byProduct ?? {};
280
345
  // Zodra de lijst binnen is: zorg dat de gekozen belading een geldige optie is.
281
346
  useEffect(() => {
@@ -313,6 +378,8 @@ export function CreateOrderPage() {
313
378
  const deliveryLocQ = useQuery({
314
379
  queryKey: ["co-delivery-locations", customerId],
315
380
  enabled: !!customerId,
381
+ staleTime: LIST_STALE,
382
+ gcTime: 30 * 60000,
316
383
  queryFn: async () => {
317
384
  try {
318
385
  return await fetchDeliveryLocations({ data: { customerId: customerId } });
@@ -386,26 +453,35 @@ export function CreateOrderPage() {
386
453
  // elke toetsaanslag een vraag wordt.
387
454
  const fetchPreview = useServerFn(getDeparturePreview);
388
455
  const previewInput = useMemo(() =>
389
- // Zelf ophalen of eigen vervoer met tijd: geen voorbeeld nodig (de tijd is het moment).
390
- canPickDate && !isReservation && controle !== "geen"
456
+ // Zelf ophalen of eigen vervoer met tijd: de tijd is het moment; het
457
+ // voorbeeld (eigen vervoer) dient dan alleen voor de eerste haalbare dag.
458
+ canPickDate && !isReservation
391
459
  ? {
392
- carrierId: controle === "werkwijze" ? null : carrierId ?? null,
460
+ carrierId: voorbeeldVervoerderId(controle, carrierId, carrierKindOf(carrierId)),
393
461
  deliveryLocation: deliveryLocationId ?? "",
394
462
  deliveryDate: deliveryDate || toISODate(new Date()),
395
- momentKey: controle === "werkwijze" ? null : momentKey,
396
- ownTransport: controle === "werkwijze",
463
+ momentKey: controle === "vervoerder" ? momentKey : null,
464
+ ownTransport: controle !== "vervoerder",
397
465
  selKey,
398
466
  }
399
467
  : null, [canPickDate, isReservation, carrierId, deliveryLocationId, deliveryDate, momentKey, controle, selKey]);
400
468
  const [debouncedInput, setDebouncedInput] = useState(previewInput);
401
469
  useEffect(() => {
470
+ // Andere klant/locatie of nog geen datum: direct vragen (geen typen om op te wachten).
471
+ if (previewDirect(debouncedInput, previewInput)) {
472
+ setDebouncedInput(previewInput);
473
+ return;
474
+ }
402
475
  const t = setTimeout(() => setDebouncedInput(previewInput), 300);
403
476
  return () => clearTimeout(t);
477
+ // eslint-disable-next-line react-hooks/exhaustive-deps
404
478
  }, [previewInput]);
405
479
  const previewQ = useQuery({
406
480
  queryKey: ["co-departure-preview", debouncedInput],
407
481
  enabled: !!debouncedInput,
408
- staleTime: 15000,
482
+ // Per klant/locatie onthouden: terug naar dezelfde klant = direct ingevuld.
483
+ staleTime: 2 * 60000,
484
+ gcTime: 30 * 60000,
409
485
  queryFn: async () => {
410
486
  const { selKey: _k, ...input } = debouncedInput;
411
487
  try {
@@ -580,10 +656,24 @@ export function CreateOrderPage() {
580
656
  packing_source: l.belading
581
657
  ? (l.belading.is_default === false ? "chosen" : "product_primary")
582
658
  : null,
659
+ // Regelgegevens: opmerking, extra velden en stickerkeuze (op de pakbon).
660
+ line_note: opmerkingNorm(l.line_note),
661
+ line_fields: normRegelVelden(l.line_fields),
662
+ product_sticker_id: l.product_sticker_id ?? null,
663
+ fust_sticker_id: l.fust_sticker_id ?? null,
583
664
  };
584
665
  }),
585
666
  };
586
- return await fetchCreate({ data: payload });
667
+ // Time-out: één keer opnieuw met dezelfde sleutel (de server geeft dan dezelfde order terug).
668
+ try {
669
+ return await fetchCreate({ data: payload });
670
+ }
671
+ catch (e) {
672
+ if (!isTimeoutFout(e))
673
+ throw e;
674
+ console.warn("[aanmaken] time-out; één keer opnieuw met dezelfde sleutel", e);
675
+ return await fetchCreate({ data: payload });
676
+ }
587
677
  },
588
678
  onSuccess: (res) => {
589
679
  createdRef.current = true;
@@ -671,7 +761,10 @@ export function CreateOrderPage() {
671
761
  setTimeout(() => { el?.focus(); if (el instanceof HTMLInputElement)
672
762
  el.select(); }, 30);
673
763
  });
674
- const emptyLine = () => ({ product_id: null, product_name: "", quantity: null, unit: "stuks", unit_price: null, belading: null });
764
+ const emptyLine = () => ({
765
+ product_id: null, product_name: "", quantity: null, unit: "stuks", unit_price: null, belading: null,
766
+ ...(fieldDefsKey ? { line_fields: standaardRegelVelden(fieldDefs), fields_init_for: fieldDefsKey } : {}),
767
+ });
675
768
  const addLine = () => {
676
769
  focusNext.current = { kind: "product", idx: lines.length };
677
770
  setLines([...lines, emptyLine()]);
@@ -807,7 +900,7 @@ export function CreateOrderPage() {
807
900
  const plants = line.quantity ?? null;
808
901
  const cratesDisplay = crates == null ? "" : String(crates);
809
902
  const productBeladingen = line.product_id ? beladingByProduct[line.product_id] ?? null : null;
810
- const loadingBeladingen = !!line.product_id && beladingQ.isLoading;
903
+ const loadingBeladingen = !!line.product_id && !productBeladingen && (beladingQ.isLoading || beladingQ.isFetching);
811
904
  const optionMap = new Map();
812
905
  for (const b of productBeladingen ?? []) {
813
906
  optionMap.set(beladingKey(b), {
@@ -837,8 +930,8 @@ export function CreateOrderPage() {
837
930
  value: p.id,
838
931
  label: `${code}${p.product}`,
839
932
  image: p.image_url ?? null,
840
- hint: p.in_stock
841
- ? `${size}Beschikbaar: ${p.available_stock} ${p.unit || "stuks"}${p.plants_per_crate ? ` · ${p.plants_per_crate}/fust` : ""}`
933
+ hint: p.in_stock || p.stock_uitleg?.liggend > 0
934
+ ? `${size}${beschikbaarTekst(p.available_stock, p.unit || "stuks", p.stock_uitleg)}${p.plants_per_crate ? ` · ${p.plants_per_crate}/fust` : ""}`
842
935
  : `${size}Niet op voorraad${p.plants_per_crate ? ` · ${p.plants_per_crate}/fust` : ""}`,
843
936
  search: [p.article_code, p.product].filter(Boolean).join(" "),
844
937
  muted: !p.in_stock,
@@ -855,7 +948,7 @@ export function CreateOrderPage() {
855
948
  return;
856
949
  }
857
950
  kiesRegelProduct(idx, v);
858
- } }), 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" : loadingBeladingen ? "Laden…" : noBeladingen ? "Geen belading" : "Kies belading…", disabled: !line.product_id || loadingBeladingen || noBeladingen, allowClear: false, emptyLabel: "Geen belading gekoppeld aan dit product", options: Array.from(optionMap.entries()).map(([key, b]) => ({
951
+ } }), 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]) => ({
859
952
  value: key,
860
953
  label: beladingLabel(b),
861
954
  badge: key === defaultKey ? "Standaard" : null,
@@ -884,8 +977,36 @@ export function CreateOrderPage() {
884
977
  const cr = raw ? Math.max(1, Math.floor(Number(raw))) : null;
885
978
  next[idx] = { ...next[idx], quantity: cr === null ? null : cr * ppc };
886
979
  setLines(next);
887
- }, 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" }) }) })] }, idx));
888
- }) }), _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 && (() => {
980
+ }, 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 && (() => {
981
+ const opts = stickerOpts[line.product_id] ?? null;
982
+ const ontbreekt = stickerOntbreekt(line, customerIsUuid ? opts : null);
983
+ const open = line.details_open === true || ontbreekt;
984
+ const naam = (id, lijst) => (id ? lijst?.find((o) => o.id === id)?.naam ?? null : null);
985
+ const samenvatting = [
986
+ naam(line.product_sticker_id, opts?.product) ? `Productsticker: ${naam(line.product_sticker_id, opts?.product)}` : null,
987
+ naam(line.fust_sticker_id, opts?.fust) ? `Fuststicker: ${naam(line.fust_sticker_id, opts?.fust)}` : null,
988
+ regelVeldenTekst(line.line_fields),
989
+ line.line_note?.trim() ? `Opmerking: ${line.line_note.trim()}` : null,
990
+ ].filter(Boolean).join(" · ");
991
+ 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: {
992
+ productStickerId: line.product_sticker_id ?? null,
993
+ fustStickerId: line.fust_sticker_id ?? null,
994
+ note: line.line_note ?? "",
995
+ fields: line.line_fields ?? [],
996
+ }, opties: customerIsUuid ? opts : null, optiesLaden: customerIsUuid && stickerQ.isFetching && !opts, definities: fieldDefs, needsSticker: line.needs_sticker === true, klantLink: stickerKlantLink, onChange: (patch) => {
997
+ const next = [...lines];
998
+ const cur = next[idx];
999
+ next[idx] = {
1000
+ ...cur,
1001
+ ...(patch.productStickerId !== undefined ? { product_sticker_id: patch.productStickerId, sticker_choice_for: cur.product_id } : {}),
1002
+ ...(patch.fustStickerId !== undefined ? { fust_sticker_id: patch.fustStickerId, sticker_choice_for: cur.product_id } : {}),
1003
+ ...(patch.note !== undefined ? { line_note: patch.note } : {}),
1004
+ ...(patch.fields !== undefined ? { line_fields: patch.fields } : {}),
1005
+ };
1006
+ setLines(next);
1007
+ } })] }))] }));
1008
+ })()] }, idx));
1009
+ }) }), _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 && (() => {
889
1010
  const leden = groepLeden(groepKeuze.groep, products);
890
1011
  const groepNaam = String(groepKeuze.groep.product ?? "").replace(/^\s*\[Groep\]\s*/i, "");
891
1012
  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,sCAgnBA"}
1
+ {"version":3,"file":"EditLocalOrderDialog.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/EditLocalOrderDialog.tsx"],"names":[],"mappings":"AAgEA,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,sCAmsBA"}
@@ -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";
@@ -27,8 +29,10 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
27
29
  const [saving, setSaving] = useState(false);
28
30
  const [error, setError] = useState(null);
29
31
  const [deliveryDate, setDeliveryDate] = useState("");
32
+ const [customerId, setCustomerId] = useState(null);
30
33
  const [isReservation, setIsReservation] = useState(false);
31
34
  const [vervoerSoortV, setVervoerSoortV] = useState(null);
35
+ const [floridayCarrierNotice, setFloridayCarrierNotice] = useState(null);
32
36
  const [items, setItems] = useState([]);
33
37
  const [canEditProducts, setCanEditProducts] = useState(true);
34
38
  const [priceLock, setPriceLock] = useState(null);
@@ -57,8 +61,10 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
57
61
  if (cancelled)
58
62
  return;
59
63
  setDeliveryDate((r.deliveryDate ?? "").slice(0, 10));
64
+ setCustomerId(r.customerId ?? null);
60
65
  setIsReservation(!!r.isReservation);
61
66
  setVervoerSoortV(r.vervoerSoort ?? null);
67
+ setFloridayCarrierNotice(r.floridayCarrierNotice ?? null);
62
68
  setCanEditProducts(r.canEditProducts !== false);
63
69
  setPriceLock(r.priceLock ?? null);
64
70
  setShippedLock(r.shippedLock ?? null);
@@ -100,7 +106,7 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
100
106
  .map((p) => ({
101
107
  value: p.id,
102
108
  label: p.product,
103
- hint: p.in_stock ? `${p.available_stock} beschikbaar` : "niet op voorraad",
109
+ hint: p.in_stock || (p.stock_uitleg?.liggend ?? 0) > 0 ? beschikbaarTekst(p.available_stock, p.unit || "stuks", p.stock_uitleg) : "Niet op voorraad",
104
110
  muted: !p.in_stock,
105
111
  })), [products, usedProductIds]);
106
112
  const addProduct = (productId) => {
@@ -123,15 +129,54 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
123
129
  productId,
124
130
  productName: p.product,
125
131
  unit: p.unit ?? "stuks",
126
- unitPrice: p.sale_price ?? null,
132
+ // Prijs komt uit dezelfde prijsbepaling als Nieuwe bestelling (hieronder), nooit uit een oude lijst.
133
+ unitPrice: null,
127
134
  plantsPerCrate: ppc,
128
135
  cratesPerLayer: cpl,
129
136
  layersPerCart: lpc,
130
137
  quantity: ppc,
131
138
  needsSticker: false,
139
+ priceMode: "auto",
140
+ priceSource: null,
141
+ priceKey: null,
142
+ priceError: false,
132
143
  },
133
144
  ]);
134
145
  };
146
+ // Automatische prijs per nieuwe regel via getOrderPrices (prijsgroep/klantprijs →
147
+ // verkoopprijs artikel → geen prijs). Opnieuw bij een ander aantal of andere datum;
148
+ // een zelf ingevulde prijs blijft staan.
149
+ const fetchOrderPrices = useServerFn(getOrderPrices);
150
+ const priceWanted = newItems
151
+ .map((n) => ({ n, key: n.priceMode === "manual" ? null : prijsSleutel(customerId, n.productId, deliveryDate, n.quantity) }))
152
+ .filter((x) => x.key && x.key !== x.n.priceKey);
153
+ const priceWantedKey = priceWanted.map((x) => `${x.n.key}:${x.key}`).join(",");
154
+ useEffect(() => {
155
+ if (!open || !customerId || priceWanted.length === 0)
156
+ return;
157
+ 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 }));
158
+ const t = setTimeout(() => {
159
+ const apply = (res) => {
160
+ setNewItems((cur) => cur.map((n) => {
161
+ const i = todo.findIndex((x) => x.itemKey === n.key);
162
+ if (i < 0 || n.priceMode === "manual")
163
+ return n;
164
+ if (prijsSleutel(customerId, n.productId, deliveryDate, n.quantity) !== todo[i].key)
165
+ return n;
166
+ const r = res?.[i];
167
+ if (!r || !r.ok)
168
+ return { ...n, priceError: true, priceKey: todo[i].key, priceSource: null, unitPrice: null };
169
+ const b = bekendePrijs(r.prijs);
170
+ return { ...n, priceError: false, priceKey: todo[i].key, unitPrice: b.unit_price, priceSource: b.price_source };
171
+ }));
172
+ };
173
+ fetchOrderPrices({ data: { customerId, onDate: deliveryDate || undefined, lines: todo.map(({ productId, quantity }) => ({ productId, quantity })) } })
174
+ .then(apply)
175
+ .catch((e) => { console.error("[orderprijs bewerken]", e); apply(null); });
176
+ }, 250);
177
+ return () => clearTimeout(t);
178
+ // eslint-disable-next-line react-hooks/exhaustive-deps
179
+ }, [open, priceWantedKey, customerId, deliveryDate]);
135
180
  // Voorraadcontrole bij bewerken: deze order telt niet mee (voorraad_beschikbaar_v2).
136
181
  // Ontbreekt die functie, dan de oude controle als terugval (modus "terugval").
137
182
  const fetchStockCheck = useServerFn(checkEditOrderStock);
@@ -215,6 +260,13 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
215
260
  return;
216
261
  }
217
262
  }
263
+ {
264
+ const fout = prijsRegelFout(newItems.map((n) => ({ product_name: n.productName, unit_price: n.unitPrice })));
265
+ if (fout) {
266
+ toast.error(fout);
267
+ return;
268
+ }
269
+ }
218
270
  for (const n of newItems) {
219
271
  const ppc = Math.max(1, n.plantsPerCrate);
220
272
  if (n.quantity < ppc || n.quantity % ppc !== 0) {
@@ -301,19 +353,22 @@ export function EditLocalOrderDialog({ orderId, open, onOpenChange, }) {
301
353
  setSaving(false);
302
354
  }
303
355
  };
304
- 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: [!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) => {
356
+ 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) => {
305
357
  const ppc = it.plantsPerCrate;
306
358
  const fusten = ppc !== null ? Math.ceil(it.quantity / ppc) : 0;
307
359
  const removed = removedIds.includes(it.id);
308
- 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)
360
+ 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: _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)
309
361
  ? prev.filter((x) => x !== it.id)
310
362
  : [...prev, it.id]), children: _jsx(Trash2, { className: "h-4 w-4" }) })) })] }, it.id));
311
- }), 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) => {
363
+ }), newItems.map((n, idx) => {
312
364
  const ppc = Math.max(1, n.plantsPerCrate);
313
365
  const fusten = Math.ceil(n.quantity / ppc);
314
366
  const setNewQty = (plants) => setNewItems((prev) => prev.map((p, i) => i === idx
315
367
  ? { ...p, quantity: Number.isFinite(plants) ? Math.max(0, plants) : 0 }
316
368
  : p));
317
- 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));
369
+ 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"] }), (() => {
370
+ const pending = n.priceMode === "auto" && !n.priceError && n.priceKey !== prijsSleutel(customerId, n.productId, deliveryDate, n.quantity);
371
+ 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] }));
372
+ })(), 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));
318
373
  }), 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" })] })] }) }));
319
374
  }
@@ -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"}