@flowselections/floriday-verkoop-module 1.0.142 → 1.0.143
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/components/verkoop/CreateOrderPage.d.ts.map +1 -1
- package/dist-lib/components/verkoop/CreateOrderPage.js +274 -203
- package/dist-lib/components/verkoop/EngineBufferCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/EngineBufferCard.js +2 -4
- package/dist-lib/components/verkoop/FloridaySyncSettings.d.ts.map +1 -1
- package/dist-lib/components/verkoop/FloridaySyncSettings.js +2 -1
- package/dist-lib/components/verkoop/OrderControlStatusCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderControlStatusCard.js +2 -10
- package/dist-lib/components/verkoop/OrderKarindelingCard.d.ts +7 -1
- package/dist-lib/components/verkoop/OrderKarindelingCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderKarindelingCard.js +4 -3
- package/dist-lib/components/verkoop/OrderLinePackingCard.js +2 -2
- package/dist-lib/components/verkoop/OrderPickupMomentPicker.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderPickupMomentPicker.js +4 -8
- package/dist-lib/components/verkoop/OrderShipmentsCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderShipmentsCard.js +2 -4
- package/dist-lib/components/verkoop/SalesOrderDetailPage.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailPage.js +15 -7
- package/dist-lib/components/verkoop/SalesOrderDetailView.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailView.js +24 -15
- package/dist-lib/components/verkoop/SalesOrdersTable.js +3 -3
- package/dist-lib/components/verkoop/SearchableSelect.d.ts +10 -1
- package/dist-lib/components/verkoop/SearchableSelect.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SearchableSelect.js +13 -4
- package/dist-lib/components/verkoop/VerkoopOrdersPage.d.ts.map +1 -1
- package/dist-lib/components/verkoop/VerkoopOrdersPage.js +3 -2
- package/dist-lib/components/verkoop/v3/OrderProgress.d.ts.map +1 -1
- package/dist-lib/components/verkoop/v3/OrderProgress.js +3 -8
- package/dist-lib/components/verkoop/v3/OrderStepper.d.ts.map +1 -1
- package/dist-lib/components/verkoop/v3/OrderStepper.js +2 -4
- package/dist-lib/integrations/supabase/types.d.ts +16 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/buffer-carts.d.ts +15 -0
- package/dist-lib/lib/buffer-carts.d.ts.map +1 -1
- package/dist-lib/lib/buffer-carts.js +21 -0
- package/dist-lib/lib/buffer-pick-progress.check.d.ts +2 -0
- package/dist-lib/lib/buffer-pick-progress.check.d.ts.map +1 -0
- package/dist-lib/lib/buffer-pick-progress.check.js +11 -0
- package/dist-lib/lib/create-order-customers.d.ts +8 -0
- package/dist-lib/lib/create-order-customers.d.ts.map +1 -0
- package/dist-lib/lib/create-order-customers.js +18 -0
- package/dist-lib/lib/create-order-form.check.d.ts +2 -0
- package/dist-lib/lib/create-order-form.check.d.ts.map +1 -0
- package/dist-lib/lib/create-order-form.check.js +27 -0
- package/dist-lib/lib/create-order-form.d.ts +22 -0
- package/dist-lib/lib/create-order-form.d.ts.map +1 -0
- package/dist-lib/lib/create-order-form.js +52 -0
- package/dist-lib/lib/create-order.functions.d.ts +21 -1
- package/dist-lib/lib/create-order.functions.d.ts.map +1 -1
- package/dist-lib/lib/create-order.functions.js +66 -19
- package/dist-lib/lib/delivery-format.check.js +6 -2
- package/dist-lib/lib/delivery-format.d.ts +14 -0
- package/dist-lib/lib/delivery-format.d.ts.map +1 -1
- package/dist-lib/lib/delivery-format.js +28 -0
- package/dist-lib/lib/floriday-invoice-line.check.d.ts +2 -0
- package/dist-lib/lib/floriday-invoice-line.check.d.ts.map +1 -0
- package/dist-lib/lib/floriday-invoice-line.check.js +18 -0
- package/dist-lib/lib/floriday-status.d.ts +6 -0
- package/dist-lib/lib/floriday-status.d.ts.map +1 -1
- package/dist-lib/lib/floriday-status.js +26 -0
- package/dist-lib/lib/nl-datetime.check.d.ts +2 -0
- package/dist-lib/lib/nl-datetime.check.d.ts.map +1 -0
- package/dist-lib/lib/nl-datetime.check.js +14 -0
- package/dist-lib/lib/nl-datetime.d.ts +6 -0
- package/dist-lib/lib/nl-datetime.d.ts.map +1 -0
- package/dist-lib/lib/nl-datetime.js +39 -0
- package/dist-lib/lib/order-pickup.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-pickup.functions.js +4 -57
- package/dist-lib/lib/order-pickup.server.d.ts +38 -0
- package/dist-lib/lib/order-pickup.server.d.ts.map +1 -0
- package/dist-lib/lib/order-pickup.server.js +76 -0
- package/dist-lib/lib/pickup-seed.check.d.ts +2 -0
- package/dist-lib/lib/pickup-seed.check.d.ts.map +1 -0
- package/dist-lib/lib/pickup-seed.check.js +18 -0
- package/dist-lib/lib/salesorders-list.functions.d.ts +24 -1
- package/dist-lib/lib/salesorders-list.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.functions.js +11 -6
- package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.server.js +4 -4
- package/dist-lib/lib/salesorders-mapping.d.ts +4 -0
- package/dist-lib/lib/salesorders-mapping.d.ts.map +1 -1
- package/dist-lib/lib/salesorders.functions.d.ts +7 -0
- package/dist-lib/lib/salesorders.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders.functions.js +17 -5
- package/dist-lib/lib/useLocalSalesOrderDetailQuery.d.ts +24 -1
- package/dist-lib/lib/useLocalSalesOrderDetailQuery.d.ts.map +1 -1
- package/dist-lib/lib/usePickupMoment.d.ts +44 -0
- package/dist-lib/lib/usePickupMoment.d.ts.map +1 -0
- package/dist-lib/lib/usePickupMoment.js +46 -0
- package/package.json +1 -1
|
@@ -1,14 +1,16 @@
|
|
|
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
|
+
import { fmtNL } from "../../lib/nl-datetime.js";
|
|
2
3
|
// Handmatig aanmaken van een bestelling — gebruikt exact dezelfde workflow,
|
|
3
4
|
// server-fns en validaties als de Mailbox-module. Beide modules leunen op
|
|
4
5
|
// gedeelde queries (klanten, producten met voorraad, afleverlocaties,
|
|
5
6
|
// afhaallocaties, vervoerders). Ophaalmoment en haalbare leverdatum komen
|
|
6
7
|
// van de Logistiek Engine (logistics_departure_preview).
|
|
7
8
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
-
import { Button,
|
|
9
|
-
import { Link, useNavigate } from "@tanstack/react-router";
|
|
9
|
+
import { Button, Input, Label, Textarea, toast, } from "@flowselections/core";
|
|
10
|
+
import { Link, useBlocker, useNavigate } from "@tanstack/react-router";
|
|
10
11
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
11
|
-
import { ArrowLeft, Plus, Trash2 } from "lucide-react";
|
|
12
|
+
import { AlertTriangle, ArrowLeft, CheckCircle2, ChevronUp, Loader2, Plus, Trash2 } from "lucide-react";
|
|
13
|
+
import { missingItems, lineTotal, dateWithWeekday, eur } from "../../lib/create-order-form.js";
|
|
12
14
|
import { useServerFn } from "@tanstack/react-start";
|
|
13
15
|
import { SearchableSelect } from "./SearchableSelect.js";
|
|
14
16
|
import { toISODate } from "../../lib/carrier-availability.js";
|
|
@@ -16,7 +18,7 @@ import { getDeparturePreview } from "../../lib/departure-preview.functions.js";
|
|
|
16
18
|
import { getProductPlannability } from "../../lib/product-plannable.functions.js";
|
|
17
19
|
import { decidePreview, momentLabel, firstDateText, LATE_CONFIRM } from "../../lib/departure-preview.js";
|
|
18
20
|
import { ConfirmDialog } from "./ConfirmDialog.js";
|
|
19
|
-
import { listCustomersForCreateOrder, ensureCustomerFromTwinfield, listProductsForCreateOrder, listCustomerStickerProducts, listDeliveryLocationsForCustomerCO, listPickupLocationsCO, listCarriersForCreateOrder, getOrderPickDaysCO, listBeladingOptionsForProducts, createManualOrder, getEffectivePrices, } from "../../lib/create-order.functions.js";
|
|
21
|
+
import { listCustomersForCreateOrder, ensureCustomerFromTwinfield, listProductsForCreateOrder, listCustomerStickerProducts, listDeliveryLocationsForCustomerCO, listPickupLocationsCO, getLastPickupLocationCO, listCarriersForCreateOrder, getOrderPickDaysCO, listBeladingOptionsForProducts, createManualOrder, getEffectivePrices, } from "../../lib/create-order.functions.js";
|
|
20
22
|
import { checkOrderStockAllowed } from "../../lib/logistics-stock.functions.js";
|
|
21
23
|
import { useAllowedLoadCarriers } from "../../lib/useAllowedLoadCarriers.js";
|
|
22
24
|
const beladingKey = (b) => `${b.plants_per_crate}x${b.crates_per_layer}x${b.layers_per_cart}`;
|
|
@@ -37,9 +39,6 @@ const completeBelading = (src) => {
|
|
|
37
39
|
return null;
|
|
38
40
|
return { plants_per_crate: ppc, crates_per_layer: cpl, layers_per_cart: lpc };
|
|
39
41
|
};
|
|
40
|
-
function ReadOnlyField({ label, value }) {
|
|
41
|
-
return (_jsxs("div", { className: "space-y-0.5", children: [_jsx("div", { className: "text-[11px] uppercase tracking-wide text-muted-foreground", children: label }), _jsx("div", { className: "text-sm", children: value && String(value).trim() !== "" ? value : _jsx("span", { className: "text-muted-foreground", children: "\u2014" }) })] }));
|
|
42
|
-
}
|
|
43
42
|
export function CreateOrderPage() {
|
|
44
43
|
const navigate = useNavigate();
|
|
45
44
|
const qc = useQueryClient();
|
|
@@ -55,10 +54,12 @@ export function CreateOrderPage() {
|
|
|
55
54
|
const fetchStickerProducts = useServerFn(listCustomerStickerProducts);
|
|
56
55
|
const loadCarriersEngine = useAllowedLoadCarriers();
|
|
57
56
|
// Fouten niet inslikken: elke query toont zijn fout boven het formulier.
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
57
|
+
// Keuzelijsten na de eerste keer onthouden (in het geheugen van de pagina).
|
|
58
|
+
const LIST_STALE = 5 * 60000;
|
|
59
|
+
const customersQ = useQuery({ queryKey: ["co-customers"], queryFn: () => fetchCustomers(), staleTime: LIST_STALE, gcTime: 30 * 60000 });
|
|
60
|
+
const productsQ = useQuery({ queryKey: ["co-products"], queryFn: () => fetchProducts(), staleTime: LIST_STALE, gcTime: 30 * 60000 });
|
|
61
|
+
const pickupQ = useQuery({ queryKey: ["co-pickup"], queryFn: () => fetchPickupLocations(), staleTime: LIST_STALE, gcTime: 30 * 60000 });
|
|
62
|
+
const carriersQ = useQuery({ queryKey: ["co-carriers"], queryFn: () => fetchCarriers(), staleTime: LIST_STALE, gcTime: 30 * 60000 });
|
|
62
63
|
const pickDaysQ = useQuery({
|
|
63
64
|
queryKey: ["co-pickdays"],
|
|
64
65
|
queryFn: async () => { try {
|
|
@@ -338,8 +339,7 @@ export function CreateOrderPage() {
|
|
|
338
339
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
339
340
|
}, [preview]);
|
|
340
341
|
const fmtDate = (iso) => {
|
|
341
|
-
|
|
342
|
-
return new Date(y, (m ?? 1) - 1, d ?? 1).toLocaleDateString("nl-NL", { weekday: "long", day: "numeric", month: "long" });
|
|
342
|
+
return fmtNL(iso.slice(0, 10), { weekday: "long", day: "numeric", month: "long" }) ?? iso;
|
|
343
343
|
};
|
|
344
344
|
// ---- Voorraadcontrole (Logistics Engine) -------------------------------
|
|
345
345
|
// De Engine beslist of een order met producten zonder voorraad aangemaakt
|
|
@@ -477,6 +477,7 @@ export function CreateOrderPage() {
|
|
|
477
477
|
return await fetchCreate({ data: payload });
|
|
478
478
|
},
|
|
479
479
|
onSuccess: (res) => {
|
|
480
|
+
createdRef.current = true;
|
|
480
481
|
toast.success("Bestelling aangemaakt — karindeling is automatisch berekend");
|
|
481
482
|
if (res?.carrierAdminNotice)
|
|
482
483
|
toast.warning(`Voor beheer: ${res.carrierAdminNotice}`);
|
|
@@ -505,194 +506,264 @@ export function CreateOrderPage() {
|
|
|
505
506
|
toast.error(msg ?? "De order is niet aangemaakt. Controleer de regels en probeer opnieuw.");
|
|
506
507
|
},
|
|
507
508
|
});
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
509
|
+
// ---- Afhaallocatie: één eigen locatie → die; anders de laatst gebruikte
|
|
510
|
+
// bij deze klant (uit bestaande orders), mits die nog actief in de lijst staat.
|
|
511
|
+
const fetchLastPickup = useServerFn(getLastPickupLocationCO);
|
|
512
|
+
const lastPickupQ = useQuery({
|
|
513
|
+
queryKey: ["co-last-pickup", customerId],
|
|
514
|
+
enabled: !!customerId && !String(customerId).startsWith("twinfield:"),
|
|
515
|
+
staleTime: 60000,
|
|
516
|
+
queryFn: async () => {
|
|
517
|
+
try {
|
|
518
|
+
return await fetchLastPickup({ data: { customerId: customerId } });
|
|
519
|
+
}
|
|
520
|
+
catch {
|
|
521
|
+
return { pickupLocationId: null };
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
const [pickupFromLast, setPickupFromLast] = useState(false);
|
|
526
|
+
const pickupTouched = useRef(false);
|
|
527
|
+
useEffect(() => {
|
|
528
|
+
if (pickupTouched.current || pickupLocations.length === 0)
|
|
529
|
+
return;
|
|
530
|
+
if (pickupLocations.length === 1) {
|
|
531
|
+
if (!pickupLocationId)
|
|
532
|
+
setPickupLocationId(pickupLocations[0].id);
|
|
533
|
+
setPickupFromLast(false);
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
const last = lastPickupQ.data?.pickupLocationId ?? null;
|
|
537
|
+
if (last && pickupLocations.some((l) => l.id === last)) {
|
|
538
|
+
setPickupLocationId(last);
|
|
539
|
+
setPickupFromLast(true);
|
|
540
|
+
}
|
|
541
|
+
else if (pickupFromLast) {
|
|
542
|
+
setPickupLocationId(null);
|
|
543
|
+
setPickupFromLast(false);
|
|
544
|
+
}
|
|
545
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
546
|
+
}, [pickupLocations.length, lastPickupQ.data, customerId]);
|
|
547
|
+
// ---- Toetsenbord: product → fusten, Enter in fusten → nieuwe regel.
|
|
548
|
+
const productRefs = useRef([]);
|
|
549
|
+
const crateRefs = useRef([]);
|
|
550
|
+
const focusNext = useRef(null);
|
|
551
|
+
useEffect(() => {
|
|
552
|
+
const f = focusNext.current;
|
|
553
|
+
if (!f)
|
|
554
|
+
return;
|
|
555
|
+
focusNext.current = null;
|
|
556
|
+
const el = f.kind === "product" ? productRefs.current[f.idx] : crateRefs.current[f.idx];
|
|
557
|
+
setTimeout(() => el?.focus(), 30);
|
|
558
|
+
});
|
|
559
|
+
const emptyLine = () => ({ product_id: null, product_name: "", quantity: null, unit: "stuks", unit_price: null, belading: null });
|
|
560
|
+
const addLine = () => {
|
|
561
|
+
focusNext.current = { kind: "product", idx: lines.length };
|
|
562
|
+
setLines([...lines, emptyLine()]);
|
|
563
|
+
};
|
|
564
|
+
// ---- Weergave-afleidingen
|
|
565
|
+
const selectedCustomer = customers.find((c) => c.id === customerId) ?? null;
|
|
566
|
+
const customerLabel = (c) => String(c?.commercial_name || c?.company_name || "Onbekend");
|
|
567
|
+
const customerSub = (c) => [c?.city, c?.twinfield_code ? `Debiteur ${c.twinfield_code}` : null].filter(Boolean).join(" · ");
|
|
568
|
+
const lineInfo = lines.map((l) => {
|
|
569
|
+
const product = l.product_id ? products.find((p) => p.id === l.product_id) : null;
|
|
570
|
+
const eff = completeBelading(l.belading) ?? completeBelading(product);
|
|
571
|
+
const ppc = eff?.plants_per_crate ?? null;
|
|
572
|
+
const crates = l.quantity != null && ppc ? Math.ceil(l.quantity / ppc) : null;
|
|
573
|
+
return { product, eff, ppc, crates, stuks: l.quantity ?? 0, total: lineTotal(l.quantity, l.unit_price) };
|
|
574
|
+
});
|
|
575
|
+
const validLines = lines.filter((l) => l.product_id && (l.quantity ?? 0) > 0);
|
|
576
|
+
const totals = lines.reduce((a, l, i) => l.product_id ? { crates: a.crates + (lineInfo[i].crates ?? 0), stuks: a.stuks + lineInfo[i].stuks, amount: a.amount + lineInfo[i].total } : a, { crates: 0, stuks: 0, amount: 0 });
|
|
577
|
+
const carrierName = (id) => carriers.find((c) => c.id === id)?.name ?? null;
|
|
578
|
+
const carrierText = isReservation
|
|
579
|
+
? "Nog niet van toepassing"
|
|
580
|
+
: ownTransport ? "Eigen vervoer / zelf afleveren"
|
|
581
|
+
: carrierId ? carrierName(carrierId) ?? "Onbekend"
|
|
582
|
+
: preview?.carrierId ? `Automatisch: ${carrierName(preview.carrierId) ?? "onbekend"}`
|
|
583
|
+
: "Automatisch";
|
|
584
|
+
const momentText = isReservation ? null : ownTransport ? "Eigen vervoer" : decision && (decision.kind === "ok" || decision.kind === "late") ? decision.text ?? null : null;
|
|
585
|
+
const missing = missingItems({
|
|
586
|
+
customerId, deliveryLocationId, pickupLocationId, isReservation, deliveryDate,
|
|
587
|
+
validLineCount: validLines.length,
|
|
588
|
+
linesWithoutBelading: lines.filter((l, i) => l.product_id && !lineInfo[i].eff).length,
|
|
589
|
+
stockBlocked,
|
|
590
|
+
previewPending: canPickDate && !isReservation && !decision,
|
|
591
|
+
previewBlockedReason: decision && (decision.kind === "blocked" || decision.kind === "departed") ? decision.reason : null,
|
|
592
|
+
});
|
|
593
|
+
const canCreate = missing.length === 0 && !createMut.isPending && !stockQ.isFetching;
|
|
594
|
+
const submit = () => {
|
|
595
|
+
if (!canCreate)
|
|
596
|
+
return;
|
|
597
|
+
if (zeroPriceCount > 0 && !zeroPriceOkRef.current)
|
|
598
|
+
setZeroConfirmOpen(true);
|
|
599
|
+
else
|
|
600
|
+
createMut.mutate(undefined);
|
|
601
|
+
};
|
|
602
|
+
// ---- Waarschuwen bij weggaan met een half ingevuld formulier.
|
|
603
|
+
const createdRef = useRef(false);
|
|
604
|
+
useEffect(() => { if (createMut.isSuccess)
|
|
605
|
+
createdRef.current = true; }, [createMut.isSuccess]);
|
|
606
|
+
const dirty = !!customerId || lines.some((l) => l.product_id) || !!notes.trim() || !!customerReference.trim();
|
|
607
|
+
useBlocker({
|
|
608
|
+
shouldBlockFn: () => {
|
|
609
|
+
if (!dirty || createdRef.current || createMut.isPending)
|
|
610
|
+
return false;
|
|
611
|
+
return !window.confirm("Je bestelling is nog niet aangemaakt. Weet je zeker dat je weg wilt?");
|
|
612
|
+
},
|
|
613
|
+
enableBeforeUnload: () => dirty && !createdRef.current,
|
|
614
|
+
});
|
|
615
|
+
const [mobileSummaryOpen, setMobileSummaryOpen] = useState(false);
|
|
616
|
+
const [deliveryEditOpen, setDeliveryEditOpen] = useState(false);
|
|
617
|
+
const cardCls = "rounded-xl border border-border bg-card p-5 shadow-sm";
|
|
618
|
+
const h2 = "text-base font-semibold text-foreground";
|
|
619
|
+
const fieldLabel = "text-[13px] font-medium text-foreground";
|
|
620
|
+
const summaryRows = (_jsxs("dl", { className: "space-y-3 text-sm", children: [_jsxs("div", { children: [_jsx("dt", { className: "text-xs text-muted-foreground", children: "Klant" }), _jsx("dd", { className: "font-medium text-foreground", children: selectedCustomer ? customerLabel(selectedCustomer) : "—" }), selectedCustomer && customerSub(selectedCustomer) && _jsx("dd", { className: "text-xs text-muted-foreground", children: customerSub(selectedCustomer) })] }), _jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_auto] gap-2", children: [_jsx("dt", { className: "text-muted-foreground", children: "Leverdatum" }), _jsx("dd", { className: "text-right tabular-nums text-foreground", children: isReservation ? "Reservering" : dateWithWeekday(deliveryDate) ?? "—" })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("dt", { className: "text-muted-foreground", children: "Ophaalmoment" }), !isReservation && !ownTransport && preview && preview.moments.length > 1 && decision && (decision.kind === "ok" || decision.kind === "late") ? (_jsx("select", { className: "h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground", value: momentKey ?? decision.momentKey ?? "", onChange: (e) => setMomentKey(e.target.value || null), "aria-label": "Ophaalmoment kiezen", children: preview.moments.map((m) => (_jsxs("option", { value: m.momentKey, disabled: !m.feasible, children: [momentLabel(m), m.feasible ? "" : " (niet haalbaar)"] }, m.momentKey))) })) : (_jsx("dd", { className: "text-foreground", children: momentText ?? (canPickDate && !isReservation && !decision
|
|
621
|
+
? _jsx("span", { className: "inline-block h-4 w-40 animate-pulse rounded bg-muted align-middle", "aria-label": "Ophaalmoment laden" })
|
|
622
|
+
: "—") }))] }), _jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_auto] gap-2", children: [_jsx("dt", { className: "text-muted-foreground", children: "Vervoerder" }), _jsx("dd", { className: "truncate text-right text-foreground", children: carrierText })] }), _jsxs("div", { className: "border-t border-border pt-3 grid grid-cols-[minmax(0,1fr)_auto] gap-y-1.5 gap-x-2 tabular-nums", children: [_jsx("dt", { className: "text-muted-foreground", children: "Regels" }), _jsx("dd", { className: "text-right", children: validLines.length }), _jsx("dt", { className: "text-muted-foreground", children: "Fusten" }), _jsx("dd", { className: "text-right", children: totals.crates }), _jsx("dt", { className: "text-muted-foreground", children: "Stuks" }), _jsx("dd", { className: "text-right", children: totals.stuks.toLocaleString("nl-NL") })] }), _jsxs("div", { className: "border-t border-border pt-3 grid grid-cols-[minmax(0,1fr)_auto] gap-2", children: [_jsx("dt", { className: "font-semibold text-foreground", children: "Totaal" }), _jsx("dd", { className: "text-right text-lg font-semibold tabular-nums text-foreground", children: eur(totals.amount) })] })] }));
|
|
623
|
+
const missingBlock = missing.length > 0 ? (_jsxs("div", { className: "rounded-lg border border-border bg-muted/40 p-3 text-sm", children: [_jsx("div", { className: "mb-1 font-medium text-foreground", children: "Ontbreekt nog" }), _jsx("ul", { className: "space-y-1 text-muted-foreground", children: missing.map((m) => (_jsxs("li", { className: "flex items-start gap-2", children: [_jsx("span", { className: "mt-2 h-1 w-1 shrink-0 rounded-full bg-muted-foreground" }), m] }, m))) })] })) : (_jsxs("div", { className: "flex items-center gap-2 rounded-lg bg-primary/10 p-3 text-sm font-medium text-primary", children: [_jsx(CheckCircle2, { className: "h-4 w-4 shrink-0" }), " Alles is compleet"] }));
|
|
624
|
+
const createButton = (cls = "") => (_jsx(Button, { className: `h-10 w-full ${cls}`, onClick: submit, disabled: !canCreate, title: stockBlocked ? "Onvoldoende voorraad; pas de aantallen aan." : undefined, children: createMut.isPending ? _jsxs(_Fragment, { children: [_jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), "Bezig\u2026"] })
|
|
625
|
+
: stockQ.isFetching ? "Voorraad controleren…" : "Bestelling aanmaken" }));
|
|
626
|
+
const deliveryAddr = (l) => [
|
|
627
|
+
l.address_line || [l.street, l.house_number].filter(Boolean).join(" "),
|
|
628
|
+
l.postal_code, l.city, l.country,
|
|
629
|
+
].filter(Boolean).join(", ");
|
|
630
|
+
return (_jsxs("main", { className: "mx-auto max-w-[1280px] space-y-4 p-4 pb-40 sm:p-6 md:pb-6", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-3", children: [_jsx(Button, { asChild: true, variant: "ghost", size: "icon", className: "h-9 w-9 shrink-0", "aria-label": "Terug naar verkooporders", children: _jsx(Link, { to: "/floriday-verkoop/verkooporders", children: _jsx(ArrowLeft, { className: "h-4 w-4" }) }) }), _jsx("h1", { className: "truncate text-xl font-bold text-foreground sm:text-2xl", children: "Nieuwe bestelling" })] }), loadErrors.length > 0 && (_jsx("div", { className: "rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive", children: loadErrors.map((m) => _jsx("div", { children: m }, m)) })), _jsxs("div", { className: "grid gap-4 md:grid-cols-[minmax(0,1fr)_300px] lg:grid-cols-[minmax(0,1fr)_340px]", children: [_jsxs("div", { className: "min-w-0 space-y-4", children: [_jsxs("section", { className: cardCls, children: [_jsx("h2", { className: h2, children: "Ordergegevens" }), _jsxs("div", { className: "mt-4 grid gap-4 lg:grid-cols-2", children: [_jsxs("div", { className: "space-y-1.5 lg:col-span-2", children: [_jsxs(Label, { className: fieldLabel, children: ["Klant ", _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(SearchableSelect, { value: customerId, placeholder: customersQ.isLoading ? "Laden…" : "Zoek op naam, plaats of debiteurnummer", options: customers.map((c) => ({
|
|
631
|
+
value: c.id,
|
|
632
|
+
label: customerLabel(c),
|
|
633
|
+
hint: customerSub(c) || (c.commercial_name && c.company_name !== c.commercial_name ? c.company_name : null),
|
|
634
|
+
search: [c.commercial_name, c.company_name, c.city, c.twinfield_code].filter(Boolean).join(" "),
|
|
635
|
+
badge: c.blocked ? "Geblokkeerd" : null,
|
|
636
|
+
})), renderValue: (o) => (_jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "block truncate text-foreground", children: o?.label }), o?.hint && _jsx("span", { className: "block truncate text-xs text-muted-foreground", children: o.hint })] })), className: "h-auto min-h-9 py-1.5", onChange: (v) => { pickupTouched.current = false; void handleSelectCustomer(v); }, allowClear: false }), selectedCustomer?.blocked && (_jsxs("div", { className: "flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-2.5 text-sm text-destructive", children: [_jsx(AlertTriangle, { className: "mt-0.5 h-4 w-4 shrink-0" }), "Deze klant is geblokkeerd. Controleer bij de administratie of je voor deze klant mag leveren."] }))] }), _jsxs("div", { className: "space-y-1.5 lg:col-span-2", children: [_jsxs(Label, { className: fieldLabel, children: ["Afleverlocatie ", _jsx("span", { className: "text-destructive", children: "*" })] }), selectedLocation && !deliveryEditOpen ? (_jsxs("div", { className: "flex min-h-9 items-center gap-3 rounded-md border border-input px-3 py-1.5", children: [_jsxs("div", { className: "min-w-0 flex-1 text-sm", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [_jsx("span", { className: "truncate text-foreground", children: selectedLocation.name || deliveryAddr(selectedLocation) }), selectedLocation.is_primary && _jsx("span", { className: "shrink-0 rounded-full bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground", children: "Standaard" })] }), selectedLocation.name && _jsx("div", { className: "truncate text-xs text-muted-foreground", children: deliveryAddr(selectedLocation) })] }), deliveryLocations.length > 1 && (_jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "h-8 shrink-0", onClick: () => setDeliveryEditOpen(true), children: "Wijzigen" }))] })) : (_jsx(SearchableSelect, { value: deliveryLocationId, placeholder: !customerId ? "Kies eerst een klant"
|
|
637
|
+
: deliveryLocQ.isFetching && deliveryLocations.length === 0 ? "Laden…"
|
|
638
|
+
: deliveryLocations.length ? "Kies locatie…"
|
|
639
|
+
: "Geen locaties bekend voor deze klant", disabled: !customerId || deliveryLocations.length === 0, allowClear: false, options: deliveryLocations.map((l) => ({
|
|
640
|
+
value: l.id,
|
|
641
|
+
label: l.name || deliveryAddr(l) || "Locatie",
|
|
642
|
+
hint: l.name ? deliveryAddr(l) : undefined,
|
|
643
|
+
badge: l.is_primary ? "Standaard" : null,
|
|
644
|
+
})), onChange: (v) => { setDeliveryLocationId(v); setDeliveryEditOpen(false); } }))] }), _jsxs("div", { className: "space-y-1.5", children: [_jsxs(Label, { className: fieldLabel, children: ["Afhaallocatie ", _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(SearchableSelect, { value: pickupLocationId, placeholder: pickupLocations.length ? "Kies eigen locatie…" : "Geen eigen locaties bekend", disabled: pickupLocations.length === 0, allowClear: false, options: pickupLocations.map((l) => ({ value: l.id, label: l.name })), onChange: (v) => { pickupTouched.current = true; setPickupFromLast(false); setPickupLocationId(v); } }), pickupFromLast && _jsx("div", { className: "text-xs text-muted-foreground", children: "Laatst gebruikt bij deze klant" })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { className: fieldLabel, children: "Vervoerder" }), isReservation ? (_jsx("div", { className: "flex h-9 items-center rounded-md border border-border bg-muted/40 px-3 text-sm text-muted-foreground", children: "Wordt gekozen bij de verzending" })) : (_jsx(SearchableSelect, { value: ownTransport ? "__own__" : carrierId ?? "__auto__", placeholder: !deliveryLocationId ? "Kies eerst een afleverlocatie" : "Automatisch", disabled: !deliveryLocationId, allowClear: false, options: [
|
|
645
|
+
{ value: "__auto__", label: preview?.carrierId && !carrierId && !ownTransport ? `Automatisch: ${carrierName(preview.carrierId) ?? "onbekend"}` : "Automatisch" },
|
|
646
|
+
{ value: "__own__", label: "Eigen vervoer / zelf afleveren" },
|
|
647
|
+
...carriers.map((c) => ({ value: c.id, label: c.name })),
|
|
648
|
+
], onChange: (v) => {
|
|
649
|
+
if (v === "__own__") {
|
|
650
|
+
setOwnTransport(true);
|
|
651
|
+
setCarrierId(null);
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
setOwnTransport(false);
|
|
655
|
+
setCarrierId(!v || v === "__auto__" ? null : v);
|
|
656
|
+
}
|
|
657
|
+
setMomentKey(null);
|
|
658
|
+
} }))] }), _jsxs("div", { className: "space-y-1.5 lg:col-span-2", children: [_jsxs(Label, { className: fieldLabel, children: ["Leverdatum ", !isReservation && _jsx("span", { className: "text-destructive", children: "*" })] }), _jsxs("div", { className: "flex flex-col gap-2 sm:flex-row sm:items-center", children: [_jsx(Input, { type: "date", className: "h-9 sm:w-48", value: !isReservation && canPickDate ? deliveryDate : "", disabled: isReservation || !canPickDate, onChange: (e) => { setDeliveryDate(e.target.value || ""); setMomentKey(null); } }), !isReservation && deliveryDate && canPickDate && (_jsx("span", { className: "text-sm font-medium text-foreground", children: dateWithWeekday(deliveryDate) }))] }), _jsxs("label", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [_jsx("input", { type: "checkbox", checked: isReservation, onChange: (e) => setIsReservation(e.target.checked), className: "h-4 w-4 rounded border-input accent-primary" }), "Reservering (nog geen vaste leverdatum)"] }), !isReservation && !canPickDate && (_jsx("div", { className: "text-xs text-muted-foreground", children: "Kies eerst klant, afleverlocatie en afhaallocatie." })), !isReservation && momentText && (_jsxs("div", { className: "text-xs text-muted-foreground md:hidden", children: ["Ophaalmoment: ", momentText] })), !isReservation && decision?.kind === "blocked" && (_jsx("div", { className: "text-xs text-destructive", children: decision.reason })), !isReservation && decision?.kind === "departed" && (_jsxs("div", { className: "space-y-2 rounded-lg border border-destructive/40 p-2.5 text-xs", children: [_jsx("div", { className: "text-destructive", children: decision.reason }), firstDateText(decision.firstDate, decision.next?.signupDeadline ?? null) && (_jsx("div", { className: "text-muted-foreground", children: firstDateText(decision.firstDate, decision.next?.signupDeadline ?? null) })), _jsxs("div", { className: "flex flex-wrap gap-2", children: [decision.firstDate && (_jsxs(Button, { type: "button", size: "sm", variant: "outline", onClick: () => { setDeliveryDate(decision.firstDate); setMomentKey(null); }, children: ["Gebruik ", fmtDate(decision.firstDate)] })), _jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => { setOwnTransport(true); setCarrierId(null); setMomentKey(null); }, children: "Eigen vervoer / zelf afleveren" })] })] })), !isReservation && decision?.kind === "late" && (_jsxs("div", { className: "space-y-2 rounded-lg border border-destructive/40 p-2.5 text-xs", children: [_jsx("div", { className: "text-destructive", children: decision.reason }), (firstDateText(decision.firstDate, preview?.nextFeasibleMoment?.signupDeadline ?? null) ?? decision.firstReason) && (_jsx("div", { className: "text-muted-foreground", children: firstDateText(decision.firstDate, preview?.nextFeasibleMoment?.signupDeadline ?? null) ?? decision.firstReason })), _jsxs("div", { className: "flex flex-wrap gap-2", children: [decision.firstDate && (_jsxs(Button, { type: "button", size: "sm", variant: "outline", onClick: () => { setDeliveryDate(decision.firstDate); setMomentKey(null); }, children: ["Gebruik ", fmtDate(decision.firstDate)] })), _jsxs(Button, { type: "button", size: "sm", variant: "outline", disabled: createMut.isPending, onClick: () => setLateConfirmOpen(true), children: ["Toch aanmaken voor ", deliveryDate ? fmtDate(deliveryDate) : "de gekozen datum"] })] })] }))] })] })] }), _jsxs("section", { className: cardCls, children: [_jsx("div", { className: "flex items-center justify-between gap-3", children: _jsx("h2", { className: h2, children: "Bestelregels" }) }), _jsxs("div", { className: "mt-4 hidden grid-cols-[minmax(0,2.4fr)_56px_minmax(0,1.6fr)_80px_72px_minmax(0,1fr)_92px_88px_36px] gap-2 px-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground lg:grid", children: [_jsx("div", { children: "Product" }), _jsx("div", { className: "text-center", children: "Sticker" }), _jsx("div", { children: "Belading" }), _jsx("div", { children: "Fusten" }), _jsx("div", { className: "text-right", children: "Stuks" }), _jsx("div", { children: "Beschikbaar" }), _jsx("div", { children: "Prijs/st" }), _jsx("div", { className: "text-right", children: "Totaal" }), _jsx("div", {})] }), _jsx("div", { className: "mt-2 space-y-2 lg:space-y-0 lg:divide-y lg:divide-border", children: lines.map((line, idx) => {
|
|
659
|
+
const { product, eff: effBelading, ppc, crates } = lineInfo[idx];
|
|
660
|
+
const defaultBelading = completeBelading(product);
|
|
661
|
+
const plants = line.quantity ?? null;
|
|
662
|
+
const cratesDisplay = crates == null ? "" : String(crates);
|
|
663
|
+
const productBeladingen = line.product_id ? beladingByProduct[line.product_id] ?? null : null;
|
|
664
|
+
const loadingBeladingen = !!line.product_id && beladingQ.isLoading;
|
|
665
|
+
const optionMap = new Map();
|
|
666
|
+
for (const b of productBeladingen ?? []) {
|
|
667
|
+
optionMap.set(beladingKey(b), {
|
|
668
|
+
plants_per_crate: b.plants_per_crate, crates_per_layer: b.crates_per_layer, layers_per_cart: b.layers_per_cart,
|
|
669
|
+
crate_type_name: b.crate_type_name ?? null, cart_type_name: b.cart_type_name ?? null,
|
|
670
|
+
crate_code: b.crate_code ?? null, cart_code: b.cart_code ?? null, is_default: !!b.is_default,
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
const noBeladingen = !!line.product_id && !loadingBeladingen && optionMap.size === 0;
|
|
674
|
+
const dbDefault = (productBeladingen ?? []).find((b) => b.is_default) ?? null;
|
|
675
|
+
const defaultKey = dbDefault ? beladingKey(dbDefault) : defaultBelading ? beladingKey(defaultBelading) : null;
|
|
676
|
+
const deviates = !!effBelading && !!defaultKey && beladingKey(effBelading) !== defaultKey;
|
|
677
|
+
const shortage = line.product_id ? shortageByProduct.get(line.product_id) : undefined;
|
|
678
|
+
const available = product ? Number(product.available_stock ?? 0) : null;
|
|
679
|
+
const unit = product?.unit || "stuks";
|
|
680
|
+
const overStock = !!product && (plants ?? 0) > 0 && (shortage || (available != null && (plants ?? 0) > available));
|
|
681
|
+
const noPrice = !!line.product_id && !(Number(line.unit_price) > 0);
|
|
682
|
+
const impossible = line.product_id ? impossibleByLine[String(idx)] : undefined;
|
|
683
|
+
const missingLine = line.product_id && !impossible ? (missingByLine[String(idx)] ?? missingByProduct[line.product_id]) : undefined;
|
|
684
|
+
const sizeText = product?.plant_height_cm ? `${product.plant_height_cm} cm` : null;
|
|
685
|
+
return (_jsxs("div", { className: "grid grid-cols-2 items-start gap-2 rounded-lg border border-border p-3 lg:grid-cols-[minmax(0,2.4fr)_56px_minmax(0,1.6fr)_80px_72px_minmax(0,1fr)_92px_88px_36px] lg:rounded-none lg:border-0 lg:px-1 lg:py-2.5", children: [_jsxs("div", { className: "col-span-2 min-w-0 lg:col-span-1", children: [_jsx(SearchableSelect, { ref: (el) => { productRefs.current[idx] = el; }, value: line.product_id, placeholder: "Kies product\u2026", clearLabel: "\u2014 Handmatig \u2014", showImages: true, className: "h-auto min-h-9 py-1", renderValue: (o) => (_jsxs(_Fragment, { children: [o?.image ? _jsx("img", { src: o.image, alt: "", className: "h-8 w-8 shrink-0 rounded-md border border-border object-cover" })
|
|
686
|
+
: _jsx("span", { "aria-hidden": true, className: "h-8 w-8 shrink-0 rounded-md border border-border bg-muted" }), _jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "block truncate text-foreground", children: o?.label }), sizeText && _jsx("span", { className: "block truncate text-xs text-muted-foreground", children: sizeText })] })] })), options: products.map((p) => {
|
|
687
|
+
const code = p.article_code ? `${p.article_code} · ` : "";
|
|
688
|
+
const size = p.plant_height_cm ? `${p.plant_height_cm} cm · ` : "";
|
|
689
|
+
return {
|
|
690
|
+
value: p.id,
|
|
691
|
+
label: `${code}${p.product}`,
|
|
692
|
+
image: p.image_url ?? null,
|
|
693
|
+
hint: p.in_stock
|
|
694
|
+
? `${size}Beschikbaar: ${p.available_stock} ${p.unit || "stuks"}${p.plants_per_crate ? ` · ${p.plants_per_crate}/fust` : ""}`
|
|
695
|
+
: `${size}Niet op voorraad${p.plants_per_crate ? ` · ${p.plants_per_crate}/fust` : ""}`,
|
|
696
|
+
search: [p.article_code, p.product].filter(Boolean).join(" "),
|
|
697
|
+
muted: !p.in_stock,
|
|
604
698
|
};
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
const
|
|
674
|
-
|
|
675
|
-
setLines(next);
|
|
676
|
-
}, placeholder: ppc === null ? "Belading onbekend" : "Fusten", title: ppc === null
|
|
677
|
-
? "Belading onbekend — kies eerst een belading"
|
|
678
|
-
: `${ppc} planten per fust` })] }), _jsxs("label", { className: "col-span-1 lg:col-span-2", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground lg:hidden", children: "Prijs" }), _jsx(Input, { type: "number", min: 0, step: "0.01", value: line.unit_price ?? "", onChange: (e) => {
|
|
679
|
-
const next = [...lines];
|
|
680
|
-
const v = e.target.value === "" ? null : Number(e.target.value);
|
|
681
|
-
next[idx] = { ...next[idx], unit_price: v };
|
|
682
|
-
setLines(next);
|
|
683
|
-
}, placeholder: "\u20AC prijs", "aria-invalid": !!line.product_id && !(Number(line.unit_price) > 0), title: !!line.product_id && !(Number(line.unit_price) > 0) ? "Prijs € 0" : undefined })] }), _jsx(Button, { variant: "ghost", size: "icon", className: "col-span-2 justify-self-end lg:col-span-1 lg:justify-self-auto", onClick: () => setLines(lines.filter((_, i) => i !== idx)), "aria-label": "Regel verwijderen", children: _jsx(Trash2, { className: "h-4 w-4" }) })] }, idx));
|
|
684
|
-
}), lines.some((l, i) => l.product_id && impossibleByLine[String(i)]) && (_jsxs("div", { className: "rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive", children: [_jsx("div", { className: "font-medium", children: "De Engine noemt deze regels onmogelijk met de gekozen belading:" }), _jsx("ul", { className: "mt-1 list-disc pl-5", children: lines.map((l, i) => l.product_id && impossibleByLine[String(i)] ? (_jsxs("li", { children: [l.product_name || "Product", ": ", impossibleByLine[String(i)]] }, i)) : null) })] })), lines.some((l, i) => l.product_id && !impossibleByLine[String(i)] && missingByLine[String(i)]) && (_jsxs("div", { className: "rounded-md border border-border bg-muted/40 px-3 py-2 text-sm text-foreground", children: [_jsx("div", { className: "font-medium", children: "Let op (geen blokkade):" }), _jsx("ul", { className: "mt-1 list-disc pl-5", children: lines.map((l, i) => l.product_id && !impossibleByLine[String(i)] && missingByLine[String(i)] ? (_jsxs("li", { children: [missingByLine[String(i)], " bij artikel ", l.product_name || "Product"] }, i)) : null) })] })), lines.some((l) => l.product_id && !impossibleByLine[String(lines.indexOf(l))] && missingByProduct[l.product_id]) && (_jsxs("div", { className: "rounded-md border border-border bg-muted/40 px-3 py-2 text-sm text-foreground", children: [_jsx("div", { className: "font-medium", children: "Gegevens ontbreken voor de Engine:" }), _jsx("ul", { className: "mt-1 list-disc pl-5", children: lines.filter((l) => l.product_id && !impossibleByLine[String(lines.indexOf(l))] && missingByProduct[l.product_id]).map((l) => (_jsxs("li", { children: [l.product_name || "Product", ": ", missingByProduct[l.product_id]] }, l.product_id))) })] })), lines.some((l) => l.product_id && !(Number(l.unit_price) > 0)) && (_jsxs("div", { className: "rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive", children: ["Prijs \u20AC 0: ", zeroPriceCount, " regel(s) zonder prijs. Er is geen prijs gevonden in prijsgroep of artikel. Vul de prijs in, of bevestig bij het aanmaken dat \u20AC 0 klopt."] })), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => setLines([...lines, { product_id: null, product_name: "", quantity: null, unit: "stuks", unit_price: null, belading: null }]), children: [_jsx(Plus, { className: "h-3 w-3 mr-1" }), " Regel toevoegen"] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { children: "Referentie klant" }), _jsx(Input, { value: customerReference, maxLength: 100, onChange: (e) => setCustomerReference(e.target.value), placeholder: "Optioneel, bijvoorbeeld het bestelnummer van je klant" })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { children: "Opmerkingen" }), _jsx(Textarea, { value: notes, onChange: (e) => setNotes(e.target.value), placeholder: "Optionele notities bij deze bestelling", rows: 3 })] }), stockCheck && stockCheck.shortages.length > 0 && (_jsxs("div", { className: `rounded-md border p-3 text-sm ${stockBlocked
|
|
685
|
-
? "border-destructive/40 bg-destructive/5 text-destructive"
|
|
686
|
-
: "border-amber-500/40 bg-amber-500/5 text-amber-700"}`, children: [_jsx("div", { className: "font-medium", children: stockBlocked
|
|
687
|
-
? "Bestelling geblokkeerd — onvoldoende voorraad"
|
|
688
|
-
: "Let op: tekorten (uitleveren zonder voorraad staat aan)" }), _jsx("ul", { className: "mt-1 space-y-0.5", children: stockCheck.shortages.map((s) => (_jsxs("li", { children: [s.product, ": besteld ", s.wanted, ", beschikbaar ", s.available, ", tekort ", s.missing] }, s.productId))) })] })), _jsxs("div", { className: "flex items-center justify-end gap-2 pt-2", children: [_jsx(Button, { variant: "outline", onClick: () => navigate({ to: "/floriday-verkoop/verkooporders" }), disabled: createMut.isPending, children: "Annuleren" }), _jsx(Button, { onClick: () => {
|
|
689
|
-
if (zeroPriceCount > 0 && !zeroPriceOkRef.current)
|
|
690
|
-
setZeroConfirmOpen(true);
|
|
691
|
-
else
|
|
692
|
-
createMut.mutate(undefined);
|
|
693
|
-
}, disabled: createMut.isPending || stockBlocked || stockQ.isFetching, title: stockBlocked ? "Onvoldoende voorraad; deze order kan zo niet worden aangemaakt. Pas de aantallen aan." : undefined, children: createMut.isPending
|
|
694
|
-
? "Bezig..."
|
|
695
|
-
: stockQ.isFetching
|
|
696
|
-
? "Voorraad controleren..."
|
|
697
|
-
: "Bestelling Aanmaken" })] })] })] }), _jsx(ConfirmDialog, { open: zeroConfirmOpen, onOpenChange: setZeroConfirmOpen, title: "Prijs \u20AC 0 bevestigen?", description: `${zeroPriceCount} regel(s) hebben prijs € 0. Deze regels worden zo gefactureerd. Weet je zeker dat dat klopt?`, confirmLabel: "Ja, prijs \u20AC 0 klopt", onConfirm: () => { zeroPriceOkRef.current = true; createMut.mutate(undefined); } }), _jsx(ConfirmDialog, { open: lateConfirmOpen, onOpenChange: setLateConfirmOpen, title: "Toch aanmaken na de aanmeldtijd?", description: LATE_CONFIRM, confirmLabel: "Toch aanmaken", onConfirm: () => createMut.mutate({ lateConfirmed: true }) })] }));
|
|
699
|
+
}), onChange: (v) => {
|
|
700
|
+
const next = [...lines];
|
|
701
|
+
if (v === null)
|
|
702
|
+
next[idx] = { ...next[idx], product_id: null, belading: null };
|
|
703
|
+
else {
|
|
704
|
+
const p = products.find((x) => x.id === v);
|
|
705
|
+
const b = completeBelading(p);
|
|
706
|
+
const newPpc = b?.plants_per_crate ?? null;
|
|
707
|
+
const currentQ = Number(next[idx].quantity ?? 0);
|
|
708
|
+
const normalizedQ = newPpc === null ? (currentQ > 0 ? currentQ : null) : currentQ > 0 ? Math.ceil(currentQ / newPpc) * newPpc : newPpc;
|
|
709
|
+
next[idx] = {
|
|
710
|
+
...next[idx], product_id: v, product_name: p?.product ?? "",
|
|
711
|
+
unit: next[idx].unit ?? p?.unit ?? "stuks", quantity: normalizedQ, belading: b,
|
|
712
|
+
unit_price: next[idx].unit_price ?? (p?.sale_price != null && Number(p.sale_price) > 0 ? Number(p.sale_price) : null),
|
|
713
|
+
};
|
|
714
|
+
focusNext.current = { kind: "crates", idx };
|
|
715
|
+
}
|
|
716
|
+
setLines(next);
|
|
717
|
+
if (v && customerId && !String(customerId).startsWith("twinfield:")) {
|
|
718
|
+
const lineIdx = idx;
|
|
719
|
+
const hadPrice = next[idx].unit_price;
|
|
720
|
+
fetchEffectivePrices({ data: { customerId, onDate: deliveryDate || undefined, lines: [{ productId: v, quantity: Number(next[idx].quantity ?? 0) || undefined }] } })
|
|
721
|
+
.then((res) => {
|
|
722
|
+
const hit = res?.[v];
|
|
723
|
+
if (!hit)
|
|
724
|
+
return;
|
|
725
|
+
setLines((cur) => {
|
|
726
|
+
const copy = [...cur];
|
|
727
|
+
const ln = copy[lineIdx];
|
|
728
|
+
if (!ln || ln.product_id !== v)
|
|
729
|
+
return cur;
|
|
730
|
+
if (ln.unit_price != null && ln.unit_price !== hadPrice)
|
|
731
|
+
return cur;
|
|
732
|
+
copy[lineIdx] = { ...ln, unit_price: hit.price };
|
|
733
|
+
return copy;
|
|
734
|
+
});
|
|
735
|
+
})
|
|
736
|
+
.catch(() => undefined);
|
|
737
|
+
}
|
|
738
|
+
} }), impossible && _jsxs("div", { className: "mt-1 text-xs text-destructive", children: ["Niet in te delen met deze belading: ", impossible] }), missingLine && _jsxs("div", { className: "mt-1 text-xs text-muted-foreground", children: ["Let op: ", missingLine] })] }), _jsxs("label", { className: "col-span-2 flex h-9 items-center gap-2 lg:col-span-1 lg:justify-center", children: [_jsx("input", { type: "checkbox", className: "h-4 w-4 accent-primary", "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 lg:hidden", children: "Sticker nodig" })] }), _jsxs("div", { className: "col-span-2 min-w-0 lg:col-span-1", children: [_jsx("div", { className: "mb-1 text-xs text-muted-foreground lg:hidden", 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]) => ({
|
|
739
|
+
value: key,
|
|
740
|
+
label: beladingLabel(b),
|
|
741
|
+
badge: key === defaultKey ? "Standaard" : null,
|
|
742
|
+
hint: [`${b.crates_per_layer * b.layers_per_cart} fusten/kar`, beladingTypes(b) || null].filter(Boolean).join(" · "),
|
|
743
|
+
})), onChange: (v) => {
|
|
744
|
+
if (!v)
|
|
745
|
+
return;
|
|
746
|
+
const b = optionMap.get(v);
|
|
747
|
+
if (!b)
|
|
748
|
+
return;
|
|
749
|
+
const next = [...lines];
|
|
750
|
+
const cr = Math.max(1, Math.ceil(Number(next[idx].quantity ?? 0) / (ppc ?? b.plants_per_crate)));
|
|
751
|
+
next[idx] = { ...next[idx], belading: b, quantity: cr * b.plants_per_crate };
|
|
752
|
+
setLines(next);
|
|
753
|
+
} }), noBeladingen ? (_jsx("div", { className: "mt-1 text-xs text-destructive", children: "Geen belading bekend voor dit product." })) : effBelading && (beladingTypes(effBelading) || deviates) ? (_jsxs("div", { className: "mt-1 truncate text-xs text-muted-foreground", children: [beladingTypes(effBelading), deviates ? `${beladingTypes(effBelading) ? " · " : ""}afwijkend van standaard` : ""] })) : null] }), _jsxs("label", { className: "col-span-1 lg:col-span-1", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground lg:hidden", children: "Fusten" }), _jsx(Input, { ref: (el) => { crateRefs.current[idx] = el; }, type: "number", min: 1, step: 1, inputMode: "numeric", className: "h-9 tabular-nums", onKeyDown: (e) => {
|
|
754
|
+
blockDecimal(e);
|
|
755
|
+
if (e.key === "Enter") {
|
|
756
|
+
e.preventDefault();
|
|
757
|
+
addLine();
|
|
758
|
+
}
|
|
759
|
+
}, value: cratesDisplay, disabled: ppc === null, onChange: (e) => {
|
|
760
|
+
if (ppc === null)
|
|
761
|
+
return;
|
|
762
|
+
const next = [...lines];
|
|
763
|
+
const raw = e.target.value.replace(/[.,]/g, "");
|
|
764
|
+
const cr = raw ? Math.max(1, Math.floor(Number(raw))) : null;
|
|
765
|
+
next[idx] = { ...next[idx], quantity: cr === null ? null : cr * ppc };
|
|
766
|
+
setLines(next);
|
|
767
|
+
}, placeholder: ppc === null ? "—" : "Fusten", title: ppc === null ? "Kies eerst een belading" : `${ppc} planten per fust` })] }), _jsxs("div", { className: "col-span-1 lg:col-span-1", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground lg:hidden", children: "Stuks" }), _jsx("div", { className: "flex h-9 items-center text-sm tabular-nums text-foreground lg:justify-end", children: line.product_id && plants ? plants.toLocaleString("nl-NL") : "—" })] }), _jsxs("div", { className: "col-span-1 min-w-0 lg:col-span-1", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground lg:hidden", 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: "col-span-1 lg:col-span-1", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground lg:hidden", children: "Prijs per stuk" }), _jsx(Input, { type: "number", min: 0, step: "0.01", className: "h-9 tabular-nums", value: line.unit_price ?? "", onChange: (e) => { const next = [...lines]; next[idx] = { ...next[idx], unit_price: e.target.value === "" ? null : Number(e.target.value) }; setLines(next); }, placeholder: "\u20AC", "aria-invalid": noPrice }), noPrice && _jsx("span", { className: "mt-1 block text-xs text-destructive", children: "Geen prijs gevonden" })] }), _jsxs("div", { className: "col-span-1 lg:col-span-1", children: [_jsx("span", { className: "mb-1 block text-xs text-muted-foreground lg:hidden", children: "Totaal" }), _jsx("div", { className: "flex h-9 items-center text-sm font-medium tabular-nums text-foreground lg:justify-end", children: line.product_id ? eur(lineInfo[idx].total) : "—" })] }), _jsx("div", { className: "col-span-2 flex justify-end lg:col-span-1", children: _jsx(Button, { variant: "ghost", size: "icon", className: "h-9 w-9", onClick: () => setLines(lines.filter((_, i) => i !== idx)), "aria-label": "Regel verwijderen", children: _jsx(Trash2, { className: "h-4 w-4" }) }) })] }, idx));
|
|
768
|
+
}) }), _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", 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", 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 md:block", children: _jsxs("div", { className: `${cardCls} sticky top-4 space-y-4`, children: [_jsx("h2", { className: h2, children: "Samenvatting" }), summaryRows, missingBlock, createButton(), _jsx(Button, { variant: "ghost", className: "h-9 w-full", onClick: () => navigate({ to: "/floriday-verkoop/verkooporders" }), disabled: createMut.isPending, children: "Annuleren" })] }) })] }), _jsxs("div", { className: "fixed inset-x-0 bottom-0 z-30 border-t border-border bg-background/95 px-4 pt-3 backdrop-blur md: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] })), _jsxs("button", { type: "button", className: "mb-2 flex w-full items-center justify-between gap-3 text-left", 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` : "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")] }), _jsx(ConfirmDialog, { open: zeroConfirmOpen, onOpenChange: setZeroConfirmOpen, title: "Prijs \u20AC 0 bevestigen?", description: `${zeroPriceCount} regel(s) hebben prijs € 0. Deze regels worden zo gefactureerd. Weet je zeker dat dat klopt?`, confirmLabel: "Ja, prijs \u20AC 0 klopt", onConfirm: () => { zeroPriceOkRef.current = true; createMut.mutate(undefined); } }), _jsx(ConfirmDialog, { open: lateConfirmOpen, onOpenChange: setLateConfirmOpen, title: "Toch aanmaken na de aanmeldtijd?", description: LATE_CONFIRM, confirmLabel: "Toch aanmaken", onConfirm: () => createMut.mutate({ lateConfirmed: true }) })] }));
|
|
698
769
|
}
|