@flowselections/floriday-verkoop-module 1.0.133 → 1.0.134

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.
@@ -0,0 +1,4 @@
1
+ export declare function OrderInvoiceCard({ orderId }: {
2
+ orderId: string;
3
+ }): import("react").JSX.Element | null;
4
+ //# sourceMappingURL=OrderInvoiceCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OrderInvoiceCard.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/OrderInvoiceCard.tsx"],"names":[],"mappings":"AAYA,wBAAgB,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,sCA6EhE"}
@@ -0,0 +1,62 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useQuery } from "@tanstack/react-query";
4
+ import { FileText } from "lucide-react";
5
+ import { supabase } from "../../integrations/supabase/client.js";
6
+ import { canOpenPdf, invoiceDisplay, rpcErrorKind } from "../../lib/erp-invoice-view.js";
7
+ // Factuurblok: leest alleen via de RPC's van Facturatie. Geen Facturatie,
8
+ // geen recht of geen facturen → het blok blijft weg, zonder foutmelding.
9
+ const rpc = supabase.rpc;
10
+ const money = new Intl.NumberFormat("nl-NL", { style: "currency", currency: "EUR" });
11
+ export function OrderInvoiceCard({ orderId }) {
12
+ const [pdfError, setPdfError] = useState(null);
13
+ const [busy, setBusy] = useState(null);
14
+ const q = useQuery({
15
+ queryKey: ["erp-invoices-for-order", orderId],
16
+ retry: false,
17
+ staleTime: 60000,
18
+ queryFn: async () => {
19
+ const { data, error } = await rpc("erp_invoices_for_order", { p_order_id: orderId });
20
+ if (error) {
21
+ if (rpcErrorKind(error) === "other")
22
+ console.warn("Facturen lezen mislukt", error.code ?? "");
23
+ return [];
24
+ }
25
+ return Array.isArray(data) ? data : [];
26
+ },
27
+ });
28
+ const rows = q.data ?? [];
29
+ if (rows.length === 0)
30
+ return null;
31
+ async function openPdf(r) {
32
+ setPdfError(null);
33
+ setBusy(r.id);
34
+ const win = window.open("", "_blank");
35
+ try {
36
+ const { data, error } = await rpc("erp_invoice_pdf_path", { p_invoice_id: r.id });
37
+ const path = typeof data === "string" ? data : null;
38
+ if (error || !canOpenPdf(r.source, path)) {
39
+ win?.close();
40
+ setPdfError(error && rpcErrorKind(error) === "forbidden" ? "Geen recht om deze PDF te openen." : "Geen PDF beschikbaar.");
41
+ return;
42
+ }
43
+ const { data: signed, error: sErr } = await supabase.storage.from("invoices").createSignedUrl(path, 300);
44
+ if (sErr || !signed?.signedUrl) {
45
+ win?.close();
46
+ setPdfError("PDF kon niet worden geopend.");
47
+ return;
48
+ }
49
+ if (win)
50
+ win.location.href = signed.signedUrl;
51
+ else
52
+ window.open(signed.signedUrl, "_blank", "noopener");
53
+ }
54
+ finally {
55
+ setBusy(null);
56
+ }
57
+ }
58
+ return (_jsxs("div", { className: "rounded-lg border bg-card p-4", children: [_jsxs("div", { className: "mb-3 flex items-center gap-2 text-sm font-semibold", children: [_jsx(FileText, { className: "h-4 w-4 text-muted-foreground" }), " Factuur"] }), _jsx("ul", { className: "space-y-2", children: rows.map((r) => {
59
+ const d = invoiceDisplay(r);
60
+ return (_jsxs("li", { className: "flex flex-wrap items-center gap-x-4 gap-y-1 text-sm", children: [_jsx("span", { className: "font-medium", children: d.title }), _jsx("span", { className: "font-mono", children: d.number }), d.statusLabel && _jsxs("span", { className: "text-muted-foreground", children: ["Status: ", d.statusLabel] }), d.paymentLabel && _jsxs("span", { className: "text-muted-foreground", children: ["Betaling: ", d.paymentLabel] }), d.showPdf && d.total != null && _jsx("span", { children: money.format(d.total) }), d.showPdf && (_jsx("button", { type: "button", className: "ml-auto rounded-md border px-2 py-1 text-xs hover:bg-muted disabled:opacity-50", disabled: busy === r.id, onClick: () => openPdf(r), children: "PDF openen" }))] }, r.id));
61
+ }) }), pdfError && _jsx("p", { className: "mt-2 text-xs text-muted-foreground", children: pdfError })] }));
62
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"SalesOrderDetailView.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/SalesOrderDetailView.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AA6JnE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE;IAC1C,KAAK,EAAE,aAAa,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,+BAkBA"}
1
+ {"version":3,"file":"SalesOrderDetailView.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/SalesOrderDetailView.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AA8JnE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE;IAC1C,KAAK,EAAE,aAAa,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,+BAkBA"}
@@ -10,6 +10,7 @@ import { OrderKarindelingCard } from "./OrderKarindelingCard.js";
10
10
  import { OrderLinePackingCard } from "./OrderLinePackingCard.js";
11
11
  import { OrderAfleverbrievenCard } from "./OrderAfleverbrievenCard.js";
12
12
  import { OrderShipmentsCard } from "./OrderShipmentsCard.js";
13
+ import { OrderInvoiceCard } from "./OrderInvoiceCard.js";
13
14
  import { OrderControlStatusCard } from "./OrderControlStatusCard.js";
14
15
  import { OrderCarrierPicker } from "./OrderCarrierPicker.js";
15
16
  import { OrderPickupMomentPicker } from "./OrderPickupMomentPicker.js";
@@ -304,5 +305,5 @@ function SalesOrderDetailViewInner({ floridayLoading, order, sellerFallback, hid
304
305
  .join(" "),
305
306
  resolvedAddresses.pickup.country,
306
307
  ].filter((v) => !!v && v.trim().length > 0)
307
- : [], extra: resolvedAddresses?.pickup?.gln ?? null }) }), _jsx(Row, { label: "Vervoerder", children: _jsx(OrderCarrierPicker, { orderId: String(order.id), locked: !!order.isReservation }) }), _jsx(Row, { label: "Ophaalmoment", children: _jsx(OrderPickupMomentPicker, { orderId: String(order.id) }) })] }), _jsxs("div", { children: [_jsx(SectionTitle, { children: "Klant" }), _jsxs(Row, { label: "Naam", children: [_jsx("span", { className: "font-medium", children: customerName }), customerLegalName && (_jsx("div", { className: "text-xs text-muted-foreground", children: customerLegalName }))] }), !fs && (order.floridayIds?.length ?? 0) > 0 && (_jsx(FloridayStageLine, { status: null, stage: order.stage, floridayFulfilled: order.floridayFulfilled, isFloriday: true })), _jsx(Row, { label: "GLN", children: customerGln }), _jsx(Row, { label: "Administratienummer", children: customerAdmin }), _jsx(Row, { label: "Telefoonnummer", children: customerPhone })] })] }), _jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "rounded-md border border-border p-4", children: [_jsx("div", { className: "mb-3 text-sm font-semibold", children: "Prijs per stuk" }), _jsxs("div", { className: "space-y-2 text-sm", children: [_jsxs("div", { className: "flex justify-between", children: [_jsx("span", { className: "text-muted-foreground", children: "Product" }), _jsxs("span", { children: [oldProductPrice !== null && (_jsx("span", { className: "mr-2 text-destructive line-through", children: eurFlex.format(oldProductPrice) })), eurFlex.format(productUnit)] })] }), _jsxs("div", { className: "flex justify-between", children: [_jsx("span", { className: "text-muted-foreground", children: "Transportkosten" }), _jsx("span", { children: eurFlex.format(transportPerPiece) })] }), _jsxs("div", { className: "flex justify-between", children: [_jsx("span", { className: "text-muted-foreground", children: "Inkoopprijs" }), _jsx("span", { children: eurFlex.format(purchaseUnit) })] }), _jsxs("div", { className: "mt-2 flex justify-between border-t border-border pt-2 font-semibold", children: [_jsx("span", { children: "Totaal" }), _jsxs("span", { children: [_jsx("span", { className: "mr-2 text-xs font-normal text-muted-foreground", children: totalBreakdown ? `(${totalBreakdown})` : null }), eurFlex.format(totalAmount)] })] }), (order.missingPrice || (linesWithoutPrice > 0 && !fs)) && (_jsxs("div", { className: "mt-2 rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", children: ["Geen prijs: ", linesWithoutPrice || "een of meer", " regel(s) zonder prijs. Vul de prijs in voordat de order wordt bevestigd."] }))] })] }), _jsxs("div", { className: "rounded-md border border-border p-4", children: [_jsx("div", { className: "mb-3 text-sm font-semibold", children: "Status" }), _jsxs("div", { className: "space-y-3 text-sm", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Bestelling" }), _jsx("span", { className: `rounded-full px-2 py-0.5 text-xs font-medium ${orderStageBadgeClass(order.stage ?? "incoming")}`, children: bestellingLabel })] }), order.customerReference && (_jsxs("div", { className: "text-xs text-muted-foreground", children: ["Referentie klant: ", _jsx("span", { className: "font-medium text-foreground", children: order.customerReference })] })), order.floridayMissingLineKeyNotice && (_jsx("div", { className: "rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", children: order.floridayMissingLineKeyNotice })), order.floridayExternalFulfilledAt ? (_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Afhandeling" }), _jsxs("span", { className: "text-xs text-foreground", children: ["Afgehandeld in Floriday (niet via het ERP) \u00B7 ", formatMoment(order.floridayExternalFulfilledAt)] })] })) : (order.floridayExternalFulfilledIds?.length ?? 0) > 0 ? (_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Afhandeling" }), _jsxs("span", { className: "text-xs text-foreground", children: [order.floridayExternalFulfilledIds.length, " bestelling(en) afgehandeld in Floriday; de rest loopt door"] })] })) : null, order.floridayFulfilled && (_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Floriday" }), _jsx("span", { className: "rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground", title: "Administratief doorgegeven aan Floriday. Dit bepaalt de orderstatus niet.", children: "Doorgegeven aan Floriday" })] })), hasCorrection && (_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Correctie" }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CheckCircle2, { className: "h-4 w-4 text-emerald-600" }), "Correctie is verwerkt"] })] }))] })] })] })] }), _jsx(OrderLinePackingCard, { orderId: String(order.id) }), _jsx(OrderShipmentsCard, { order: order }), !hideKarindeling && _jsx(OrderKarindelingCard, { order: order }), o?.salesOrderId ? (_jsxs(_Fragment, { children: [_jsx(OrderControlStatusCard, { floridayId: String(o.salesOrderId), isControlled: order.status.isControlled, controlledAt: order.status.controlledAt }), _jsx(OrderAfleverbrievenCard, { salesOrderId: String(o.salesOrderId), orderNumber: order.orderNumber ?? undefined })] })) : null] }));
308
+ : [], extra: resolvedAddresses?.pickup?.gln ?? null }) }), _jsx(Row, { label: "Vervoerder", children: _jsx(OrderCarrierPicker, { orderId: String(order.id), locked: !!order.isReservation }) }), _jsx(Row, { label: "Ophaalmoment", children: _jsx(OrderPickupMomentPicker, { orderId: String(order.id) }) })] }), _jsxs("div", { children: [_jsx(SectionTitle, { children: "Klant" }), _jsxs(Row, { label: "Naam", children: [_jsx("span", { className: "font-medium", children: customerName }), customerLegalName && (_jsx("div", { className: "text-xs text-muted-foreground", children: customerLegalName }))] }), !fs && (order.floridayIds?.length ?? 0) > 0 && (_jsx(FloridayStageLine, { status: null, stage: order.stage, floridayFulfilled: order.floridayFulfilled, isFloriday: true })), _jsx(Row, { label: "GLN", children: customerGln }), _jsx(Row, { label: "Administratienummer", children: customerAdmin }), _jsx(Row, { label: "Telefoonnummer", children: customerPhone })] })] }), _jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "rounded-md border border-border p-4", children: [_jsx("div", { className: "mb-3 text-sm font-semibold", children: "Prijs per stuk" }), _jsxs("div", { className: "space-y-2 text-sm", children: [_jsxs("div", { className: "flex justify-between", children: [_jsx("span", { className: "text-muted-foreground", children: "Product" }), _jsxs("span", { children: [oldProductPrice !== null && (_jsx("span", { className: "mr-2 text-destructive line-through", children: eurFlex.format(oldProductPrice) })), eurFlex.format(productUnit)] })] }), _jsxs("div", { className: "flex justify-between", children: [_jsx("span", { className: "text-muted-foreground", children: "Transportkosten" }), _jsx("span", { children: eurFlex.format(transportPerPiece) })] }), _jsxs("div", { className: "flex justify-between", children: [_jsx("span", { className: "text-muted-foreground", children: "Inkoopprijs" }), _jsx("span", { children: eurFlex.format(purchaseUnit) })] }), _jsxs("div", { className: "mt-2 flex justify-between border-t border-border pt-2 font-semibold", children: [_jsx("span", { children: "Totaal" }), _jsxs("span", { children: [_jsx("span", { className: "mr-2 text-xs font-normal text-muted-foreground", children: totalBreakdown ? `(${totalBreakdown})` : null }), eurFlex.format(totalAmount)] })] }), (order.missingPrice || (linesWithoutPrice > 0 && !fs)) && (_jsxs("div", { className: "mt-2 rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", children: ["Geen prijs: ", linesWithoutPrice || "een of meer", " regel(s) zonder prijs. Vul de prijs in voordat de order wordt bevestigd."] }))] })] }), _jsxs("div", { className: "rounded-md border border-border p-4", children: [_jsx("div", { className: "mb-3 text-sm font-semibold", children: "Status" }), _jsxs("div", { className: "space-y-3 text-sm", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Bestelling" }), _jsx("span", { className: `rounded-full px-2 py-0.5 text-xs font-medium ${orderStageBadgeClass(order.stage ?? "incoming")}`, children: bestellingLabel })] }), order.customerReference && (_jsxs("div", { className: "text-xs text-muted-foreground", children: ["Referentie klant: ", _jsx("span", { className: "font-medium text-foreground", children: order.customerReference })] })), order.floridayMissingLineKeyNotice && (_jsx("div", { className: "rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive", children: order.floridayMissingLineKeyNotice })), order.floridayExternalFulfilledAt ? (_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Afhandeling" }), _jsxs("span", { className: "text-xs text-foreground", children: ["Afgehandeld in Floriday (niet via het ERP) \u00B7 ", formatMoment(order.floridayExternalFulfilledAt)] })] })) : (order.floridayExternalFulfilledIds?.length ?? 0) > 0 ? (_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Afhandeling" }), _jsxs("span", { className: "text-xs text-foreground", children: [order.floridayExternalFulfilledIds.length, " bestelling(en) afgehandeld in Floriday; de rest loopt door"] })] })) : null, order.floridayFulfilled && (_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Floriday" }), _jsx("span", { className: "rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground", title: "Administratief doorgegeven aan Floriday. Dit bepaalt de orderstatus niet.", children: "Doorgegeven aan Floriday" })] })), hasCorrection && (_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-muted-foreground", children: "Correctie" }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CheckCircle2, { className: "h-4 w-4 text-emerald-600" }), "Correctie is verwerkt"] })] }))] })] })] })] }), _jsx(OrderLinePackingCard, { orderId: String(order.id) }), _jsx(OrderShipmentsCard, { order: order }), _jsx(OrderInvoiceCard, { orderId: String(order.id) }), !hideKarindeling && _jsx(OrderKarindelingCard, { order: order }), o?.salesOrderId ? (_jsxs(_Fragment, { children: [_jsx(OrderControlStatusCard, { floridayId: String(o.salesOrderId), isControlled: order.status.isControlled, controlledAt: order.status.controlledAt }), _jsx(OrderAfleverbrievenCard, { salesOrderId: String(o.salesOrderId), orderNumber: order.orderNumber ?? undefined })] })) : null] }));
308
309
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SalesOrdersTable.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/SalesOrdersTable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAyBjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAkHnE,6EAA6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a,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC/C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC/C,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7C,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAChD,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC7C,qBAuWA"}
@@ -129,7 +129,8 @@ export function SalesOrdersTable({ orders, loading, onSelectOrder, onDeleteOrder
129
129
  .map((u) => `${u.name} (trade-item ${u.tradeItemId ?? "onbekend"})`)
130
130
  .join("\n"), children: [_jsx(AlertTriangle, { className: "mt-0.5 h-3 w-3 shrink-0" }), _jsxs("span", { children: ["Floriday-artikel niet gekoppeld aan product:", " ", row.unlinkedProducts
131
131
  .map((u) => `${u.name} (trade-item ${u.tradeItemId ?? "onbekend"})`)
132
- .join(", ")] })] }))] }), _jsxs(TableCell, { children: [_jsx("div", { className: "font-medium text-foreground", children: row.karUnknown ? (_jsx("span", { className: "text-muted-foreground", children: "Karren onbekend" })) : row.engineCounts && row.karCount > 0 ? (_jsxs(_Fragment, { children: [formatLoadUnits(row.karCount, row.cartTypeName), row.karShared && isBuffer && (_jsx("span", { className: "ml-1 text-xs font-normal text-muted-foreground", children: "(gedeeld met gecombineerde order)" }))] })) : (_jsx("span", { className: "text-muted-foreground", children: "\u2014" })) }), _jsx(PlanCoverageBadge, { coverage: row.planCoverage }), _jsx(FloridayStageLine, { status: statusOf(row).status, loading: statusOf(row).loading, stage: row.stage, floridayFulfilled: isBuffer ? !row.notReportedToFloriday : row.floridayFulfilled, isFloriday: !!row.notReportedToFloriday || (row.floridayIds?.length ?? 0) > 0, notReportedCount: row.notReportedCount, bufferSize: bufferSize })] }), _jsxs(TableCell, { children: [_jsx("div", { className: "font-medium text-foreground", children: formatLoadUnits(row.fustCount, row.mixedPacking ? null : row.crateTypeName) }), row.mixedPacking && (row.articleCount ?? 0) > 1 && (_jsxs("div", { className: "text-xs text-muted-foreground", children: ["Gemengd (", row.articleCount, " artikelen)"] }))] }), _jsx(TableCell, { className: "text-sm text-foreground", children: row.carrierState === "geen" ? (_jsx("a", { href: "/afhandeling/vervoerders", onClick: (e) => e.stopPropagation(), className: "text-xs text-destructive underline", title: row.carrierReason ?? undefined, children: "Geen vervoerder \u2013 stel in bij Afhandeling \u2192 Vervoerders" })) : (_jsxs("div", { title: row.carrierReason ?? undefined, children: [_jsx("div", { children: row.carrierName || _jsx("span", { className: "text-muted-foreground", children: "onbekend" }) }), (row.carrierSource || row.carrierBadge) && (_jsxs("div", { className: "flex items-center gap-1 text-xs text-muted-foreground", children: [row.carrierSource && _jsx("span", { children: row.carrierSource }), row.carrierBadge && (_jsx("span", { className: "rounded border border-border bg-muted px-1 text-[10px] uppercase tracking-wide", children: row.carrierBadge }))] }))] })) }), _jsx(TableCell, { children: _jsx(StatusTag, { order: row }) }), showRevenue && (_jsxs(TableCell, { className: "font-medium text-foreground", children: ["\u20AC ", Math.round(row.revenue ?? 0).toLocaleString("nl-NL")] })), _jsxs(TableCell, { children: [_jsx("div", { className: "text-sm text-foreground", children: ordered.date }), _jsx("div", { className: "text-xs text-muted-foreground", children: isBuffer
132
+ .join(", ")] })] }))] }), _jsxs(TableCell, { children: [_jsx("div", { className: "font-medium text-foreground", children: row.karUnknown ? (_jsx("span", { className: "text-muted-foreground", children: "Karren onbekend" })) : row.engineCounts && row.karCount > 0 ? (_jsxs(_Fragment, { children: [formatLoadUnits(row.karCount, row.cartTypeName), row.karShared && isBuffer && (_jsx("span", { className: "ml-1 text-xs font-normal text-muted-foreground", children: "(gedeeld met gecombineerde order)" }))] })) : (_jsx("span", { className: "text-muted-foreground", children: "\u2014" })) }), _jsx(PlanCoverageBadge, { coverage: row.planCoverage }), _jsx(FloridayStageLine, { status: statusOf(row).status, loading: statusOf(row).loading, stage: row.stage, floridayFulfilled: isBuffer ? !row.notReportedToFloriday : row.floridayFulfilled, isFloriday: !!row.notReportedToFloriday || (row.floridayIds?.length ?? 0) > 0, notReportedCount: row.notReportedCount, bufferSize: bufferSize })] }), _jsxs(TableCell, { children: [_jsx("div", { className: "font-medium text-foreground", children: formatLoadUnits(row.fustCount, row.mixedPacking ? null : row.crateTypeName) }), row.mixedPacking && (row.articleCount ?? 0) > 1 && (_jsxs("div", { className: "text-xs text-muted-foreground", children: ["Gemengd (", row.articleCount, " artikelen)"] }))] }), _jsx(TableCell, { className: "text-sm text-foreground", children: row.carrierState === "geen" ? (_jsx("a", { href: "/afhandeling/vervoerders", onClick: (e) => e.stopPropagation(), className: "text-xs text-destructive underline", title: row.carrierReason ?? undefined, children: "Geen vervoerder \u2013 stel in bij Afhandeling \u2192 Vervoerders" })) : (_jsxs("div", { title: row.carrierReason ?? undefined, children: [_jsx("div", { children: row.carrierName || _jsx("span", { className: "text-muted-foreground", children: "onbekend" }) }), (row.carrierSource || row.carrierBadge) && (_jsxs("div", { className: "flex items-center gap-1 text-xs text-muted-foreground", children: [row.carrierSource &&
133
+ row.carrierSource.trim().toLowerCase() !== (row.carrierBadge ?? "").trim().toLowerCase() && (_jsx("span", { children: row.carrierSource })), row.carrierBadge && (_jsx("span", { className: "rounded border border-border bg-muted px-1 text-[10px] uppercase tracking-wide", children: row.carrierBadge }))] }))] })) }), _jsx(TableCell, { children: _jsx(StatusTag, { order: row }) }), showRevenue && (_jsxs(TableCell, { className: "font-medium text-foreground", children: ["\u20AC ", Math.round(row.revenue ?? 0).toLocaleString("nl-NL")] })), _jsxs(TableCell, { children: [_jsx("div", { className: "text-sm text-foreground", children: ordered.date }), _jsx("div", { className: "text-xs text-muted-foreground", children: isBuffer
133
134
  ? `${bufferSize} orders`
134
135
  : row.orderNumber || ordered.time })] }), _jsx(TableCell, { onClick: (e) => e.stopPropagation(), children: _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { className: "inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground", children: _jsx(MoreVertical, { className: "h-4 w-4" }) }), _jsxs(DropdownMenuContent, { align: "end", children: [_jsx(DropdownMenuItem, { disabled: isBuffer || !row.isLocal, onClick: () => !isBuffer && row.isLocal && onEditOrder?.(row), title: isBuffer
135
136
  ? "Een gecombineerde order kun je niet in één keer bewerken."
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=erp-invoice-view.check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erp-invoice-view.check.d.ts","sourceRoot":"","sources":["../../src/lib/erp-invoice-view.check.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ // Draai: bun src/lib/erp-invoice-view.check.ts
2
+ import { canOpenPdf, invoiceDisplay, paymentLabel, rpcErrorKind } from "./erp-invoice-view.js";
3
+ let failed = 0;
4
+ function check(name, got, want) {
5
+ const g = JSON.stringify(got), w = JSON.stringify(want);
6
+ const ok = g === w;
7
+ if (!ok)
8
+ failed++;
9
+ console.log(`${ok ? "OK " : "FOUT"} ${name}: ${g}${ok ? "" : ` (verwacht ${w})`}`);
10
+ }
11
+ const erp = { id: "1", invoice_number: "FS-2026-00001", kind: "factuur", source: "erp", status: "definitief", twinfield_status: null, payment_status: "onbekend", total: "121.00", invoice_date: null };
12
+ const tw = { ...erp, source: "twinfield_klassiek", total: "50", payment_status: "open" };
13
+ check("onbekend → Onbekend", paymentLabel("onbekend"), "Onbekend");
14
+ check("ERP toont betaalstatus Onbekend", invoiceDisplay(erp).paymentLabel, "Onbekend");
15
+ check("ERP totaal", invoiceDisplay(erp).total, 121);
16
+ check("credit", invoiceDisplay({ ...erp, kind: "credit" }).title, "Creditfactuur");
17
+ check("Twinfield: titel", invoiceDisplay(tw).title, "Factuur in Twinfield");
18
+ check("Twinfield: geen bedrag", invoiceDisplay(tw).total, null);
19
+ check("Twinfield: geen betaalstatus", invoiceDisplay(tw).paymentLabel, null);
20
+ check("Twinfield: geen PDF", canOpenPdf("twinfield_klassiek", "a/b.pdf"), false);
21
+ check("Twinfield concept", invoiceDisplay({ ...tw, twinfield_status: "concept" }).title, "Concept in Twinfield");
22
+ check("Twinfield vervallen", invoiceDisplay({ ...tw, status: "vervallen" }).title, "Vervallen");
23
+ check("PDF-pad null", canOpenPdf("erp", null), false);
24
+ check("PDF-pad aanwezig", canOpenPdf("erp", "x.pdf"), true);
25
+ check("PGRST202 → missing", rpcErrorKind({ code: "PGRST202" }), "missing");
26
+ check("404 → missing", rpcErrorKind({ status: 404 }), "missing");
27
+ check("42501 → forbidden", rpcErrorKind({ code: "42501" }), "forbidden");
28
+ if (failed) {
29
+ console.error(`${failed} controle(s) mislukt`);
30
+ process.exit(1);
31
+ }
32
+ console.log("Alle controles geslaagd");
@@ -0,0 +1,29 @@
1
+ export type ErpInvoiceRow = {
2
+ id: string;
3
+ invoice_number: string | null;
4
+ kind: string | null;
5
+ source: string | null;
6
+ status: string | null;
7
+ twinfield_status: string | null;
8
+ payment_status: string | null;
9
+ total: number | string | null;
10
+ invoice_date: string | null;
11
+ };
12
+ export type InvoiceDisplay = {
13
+ title: string;
14
+ number: string;
15
+ statusLabel: string | null;
16
+ paymentLabel: string | null;
17
+ total: number | null;
18
+ showPdf: boolean;
19
+ };
20
+ /** Fout van Facturatie-RPC: altijd verbergen (geen Facturatie, geen recht, of anders). */
21
+ export declare function rpcErrorKind(err: {
22
+ code?: string;
23
+ message?: string;
24
+ status?: number;
25
+ } | null | undefined): "missing" | "forbidden" | "other";
26
+ export declare function paymentLabel(s: string | null | undefined): string;
27
+ export declare function invoiceDisplay(r: ErpInvoiceRow): InvoiceDisplay;
28
+ export declare function canOpenPdf(source: string | null | undefined, path: string | null | undefined): boolean;
29
+ //# sourceMappingURL=erp-invoice-view.d.ts.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I,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAEtG"}
@@ -0,0 +1,53 @@
1
+ // Weergave van facturen uit Facturatie (alleen lezen, client-safe).
2
+ // Contract: RPC erp_invoices_for_order / erp_invoice_pdf_path (Facturatie 1.0.63).
3
+ /** Fout van Facturatie-RPC: altijd verbergen (geen Facturatie, geen recht, of anders). */
4
+ export function rpcErrorKind(err) {
5
+ if (!err)
6
+ return "other";
7
+ const msg = String(err.message ?? "").toLowerCase();
8
+ if (err.code === "PGRST202" || err.code === "42883" || err.status === 404 || msg.includes("does not exist") || msg.includes("could not find the function"))
9
+ return "missing";
10
+ if (err.code === "42501" || err.status === 403)
11
+ return "forbidden";
12
+ return "other";
13
+ }
14
+ const PAYMENT = {
15
+ onbekend: "Onbekend",
16
+ open: "Open",
17
+ deels_betaald: "Deels betaald",
18
+ betaald: "Betaald",
19
+ vervallen: "Vervallen",
20
+ };
21
+ export function paymentLabel(s) {
22
+ const k = String(s ?? "").trim().toLowerCase();
23
+ if (!k)
24
+ return "Onbekend";
25
+ return PAYMENT[k] ?? k.charAt(0).toUpperCase() + k.slice(1).replace(/_/g, " ");
26
+ }
27
+ function cap(s) {
28
+ return s.charAt(0).toUpperCase() + s.slice(1).replace(/_/g, " ");
29
+ }
30
+ export function invoiceDisplay(r) {
31
+ const number = r.invoice_number ?? "—";
32
+ const isCredit = r.kind === "credit";
33
+ if (r.source === "twinfield_klassiek") {
34
+ let title = isCredit ? "Creditfactuur in Twinfield" : "Factuur in Twinfield";
35
+ if (r.status === "vervallen")
36
+ title = "Vervallen";
37
+ else if (r.twinfield_status === "concept")
38
+ title = "Concept in Twinfield";
39
+ return { title, number, statusLabel: null, paymentLabel: null, total: null, showPdf: false };
40
+ }
41
+ const t = r.total == null || r.total === "" ? null : Number(r.total);
42
+ return {
43
+ title: isCredit ? "Creditfactuur" : "Factuur",
44
+ number,
45
+ statusLabel: r.status ? cap(r.status) : null,
46
+ paymentLabel: paymentLabel(r.payment_status),
47
+ total: t != null && Number.isFinite(t) ? t : null,
48
+ showPdf: true,
49
+ };
50
+ }
51
+ export function canOpenPdf(source, path) {
52
+ return source !== "twinfield_klassiek" && !!path && String(path).trim() !== "";
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-verkoop-module",
3
- "version": "1.0.133",
3
+ "version": "1.0.134",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "type": "module",