@flowselections/floriday-voorraad 1.0.113 → 1.0.117

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 (25) hide show
  1. package/dist-lib/components/voorraad/ArtikelWizard.d.ts.map +1 -1
  2. package/dist-lib/components/voorraad/ArtikelWizard.js +63 -7
  3. package/dist-lib/components/voorraad/PublishProgressCard.d.ts +5 -0
  4. package/dist-lib/components/voorraad/PublishProgressCard.d.ts.map +1 -1
  5. package/dist-lib/components/voorraad/PublishProgressCard.js +16 -1
  6. package/dist-lib/components/voorraad/VoorraadPage.d.ts +13 -0
  7. package/dist-lib/components/voorraad/VoorraadPage.d.ts.map +1 -1
  8. package/dist-lib/components/voorraad/VoorraadPage.js +33 -20
  9. package/dist-lib/components/voorraad/__tests__/count-stock-free.test.d.ts +2 -0
  10. package/dist-lib/components/voorraad/__tests__/count-stock-free.test.d.ts.map +1 -0
  11. package/dist-lib/components/voorraad/__tests__/count-stock-free.test.js +12 -0
  12. package/dist-lib/integrations/supabase/types.d.ts +371 -0
  13. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  14. package/dist-lib/lib/__tests__/floricode-required-features.test.js +7 -3
  15. package/dist-lib/lib/__tests__/publish-114.test.d.ts +2 -0
  16. package/dist-lib/lib/__tests__/publish-114.test.d.ts.map +1 -0
  17. package/dist-lib/lib/__tests__/publish-114.test.js +31 -0
  18. package/dist-lib/lib/__tests__/publish-packing-block.test.d.ts +2 -0
  19. package/dist-lib/lib/__tests__/publish-packing-block.test.d.ts.map +1 -0
  20. package/dist-lib/lib/__tests__/publish-packing-block.test.js +14 -0
  21. package/dist-lib/lib/publish-errors.d.ts +15 -1
  22. package/dist-lib/lib/publish-errors.d.ts.map +1 -1
  23. package/dist-lib/lib/publish-errors.js +64 -2
  24. package/package.json +1 -1
  25. package/sql/AGENTS.md +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"ArtikelWizard.d.ts","sourceRoot":"","sources":["../../../src/components/voorraad/ArtikelWizard.tsx"],"names":[],"mappings":"AA+MA,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EAAE,cAAc,EACvB,WAAW,EACX,SAAS,EACT,WAAW,GACZ,GAAE;IACD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,+BA0tEL"}
1
+ {"version":3,"file":"ArtikelWizard.d.ts","sourceRoot":"","sources":["../../../src/components/voorraad/ArtikelWizard.tsx"],"names":[],"mappings":"AA+MA,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EAAE,cAAc,EACvB,WAAW,EACX,SAAS,EACT,WAAW,GACZ,GAAE;IACD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,+BAwwEL"}
@@ -1195,6 +1195,7 @@ export function ArtikelWizard({ draftId: initialDraftId, tradeItemId, productId,
1195
1195
  }
1196
1196
  // Publiceren begint altijd met een lokale opslag, zodat een afgebroken of
1197
1197
  // mislukte publicatie nooit tot verlies van ingevoerde gegevens leidt.
1198
+ let savedLocalId = draftId ?? null;
1198
1199
  try {
1199
1200
  const localId = await upsertLocalTradeItem({
1200
1201
  id: draftId,
@@ -1203,6 +1204,8 @@ export function ArtikelWizard({ draftId: initialDraftId, tradeItemId, productId,
1203
1204
  floridayTradeItemId: (publishedTradeItemId || draftFloridayId || null),
1204
1205
  sync: { dirty: true, last_error: null },
1205
1206
  });
1207
+ if (localId)
1208
+ savedLocalId = localId;
1206
1209
  if (localId && localId !== draftId)
1207
1210
  setDraftId(localId);
1208
1211
  }
@@ -1210,6 +1213,50 @@ export function ArtikelWizard({ draftId: initialDraftId, tradeItemId, productId,
1210
1213
  toast.error(`Lokaal opslaan mislukt: ${e.message}`);
1211
1214
  return;
1212
1215
  }
1216
+ /**
1217
+ * Na een mislukte eerste publicatie: zet de ingevoerde voorraad en prijs op
1218
+ * het lokale artikel, alleen als daar nog niets staat (nooit overschrijven).
1219
+ */
1220
+ const keepLocalInputAfterFailure = async () => {
1221
+ if (!savedLocalId)
1222
+ return;
1223
+ try {
1224
+ const { data: prod } = await supabase
1225
+ .from("products")
1226
+ .select("sale_price")
1227
+ .eq("id", savedLocalId)
1228
+ .maybeSingle();
1229
+ if (data.salePricePerPiece > 0 && !(Number(prod?.sale_price) > 0)) {
1230
+ await supabase
1231
+ .from("products")
1232
+ .update({ sale_price: data.salePricePerPiece })
1233
+ .eq("id", savedLocalId);
1234
+ }
1235
+ if (data.saleStockPieces > 0) {
1236
+ const { data: cur } = await supabase.rpc("get_product_stock", {
1237
+ p_product_id: savedLocalId,
1238
+ });
1239
+ const row = Array.isArray(cur) ? cur[0] : cur;
1240
+ if (!(Number(row?.physical_stock) > 0)) {
1241
+ const { error } = await supabase.rpc("set_product_stock", {
1242
+ p_product_id: savedLocalId,
1243
+ p_physical_stock: Math.trunc(data.saleStockPieces),
1244
+ p_minimum_stock: null,
1245
+ p_incoming_stock: null,
1246
+ p_notes: "Ingevoerd in wizard; publiceren mislukt",
1247
+ p_change_source: "NEW_ARTICLE",
1248
+ });
1249
+ if (error)
1250
+ throw new Error(error.message);
1251
+ }
1252
+ }
1253
+ }
1254
+ catch (e) {
1255
+ toast.error("Voorraad of prijs kon niet lokaal bewaard worden", {
1256
+ description: e.message,
1257
+ });
1258
+ }
1259
+ };
1213
1260
  try {
1214
1261
  const serverConnection = await getFloridayReadinessFn();
1215
1262
  const browserEnvironment = activeConnection?.active_environment;
@@ -1304,6 +1351,9 @@ export function ArtikelWizard({ draftId: initialDraftId, tradeItemId, productId,
1304
1351
  return { tradeItemId: createdId };
1305
1352
  }, stepOpts);
1306
1353
  if (!core.ok) {
1354
+ // 1.0.114: lokale invoer nooit verliezen door een mislukte publicatie.
1355
+ if (!publishedTradeItemId)
1356
+ await keepLocalInputAfterFailure();
1307
1357
  await handleStepFailure(core.error);
1308
1358
  if (jobId)
1309
1359
  await finishPublishJob(jobId);
@@ -2592,9 +2642,10 @@ function PackingConfigDialog({ open, onOpenChange, initial, isFirst, packagingTy
2592
2642
  source: "VBN",
2593
2643
  loadCarrier: "AUCTION_TROLLEY",
2594
2644
  packagingType: "",
2595
- unitsPerPackage: 1,
2596
- packagesPerLayer: 1,
2597
- layersPerLoadCarrier: 1,
2645
+ // Geen standaardwaarden: de gebruiker vult alle drie aantallen zelf in.
2646
+ unitsPerPackage: 0,
2647
+ packagesPerLayer: 0,
2648
+ layersPerLoadCarrier: 0,
2598
2649
  isCustomerSpecific: false,
2599
2650
  customerOrganizationIds: [],
2600
2651
  isPrimary: isFirst,
@@ -2635,7 +2686,12 @@ function PackingConfigDialog({ open, onOpenChange, initial, isFirst, packagingTy
2635
2686
  const materialInvalid = draft.source === "SUPPLIER" &&
2636
2687
  !!(draft.packagingMaterialId ?? "").trim() &&
2637
2688
  !materialIsUuid;
2638
- const canSave = draft.loadCarrier.length > 0 &&
2689
+ // 1.0.114: aantallen worden nooit vooraf ingevuld; alle drie verplicht ≥ 1.
2690
+ const countsComplete = draft.unitsPerPackage >= 1 &&
2691
+ draft.packagesPerLayer >= 1 &&
2692
+ draft.layersPerLoadCarrier >= 1;
2693
+ const canSave = countsComplete &&
2694
+ draft.loadCarrier.length > 0 &&
2639
2695
  (hasCustomPkg || draft.packagingType.length > 0) &&
2640
2696
  !materialInvalid &&
2641
2697
  (draft.source === "VBN" || Boolean(draft.packagingSupplierId)) &&
@@ -2693,7 +2749,7 @@ function PackingConfigDialog({ open, onOpenChange, initial, isFirst, packagingTy
2693
2749
  ? (packagingTypes.find((r) => codeOf(r) === draft.packagingType)
2694
2750
  ? `${labelOf(packagingTypes.find((r) => codeOf(r) === draft.packagingType))} (${draft.packagingType})`
2695
2751
  : draft.packagingType)
2696
- : "Selecteer fust..." }), _jsx(ChevronDown, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })] }) }), _jsxs(PopoverContent, { className: "w-[380px] p-0", align: "start", children: [_jsx("div", { className: "border-b p-2", children: _jsx(Input, { placeholder: "Zoek op naam of code...", value: pkgSearch, onChange: (e) => setPkgSearch(e.target.value) }) }), _jsx("div", { className: "max-h-64 overflow-y-auto", children: filteredPkg.length === 0 ? (_jsx("div", { className: "px-3 py-4 text-center text-xs text-muted-foreground", children: "Geen resultaten" })) : (filteredPkg.map((r) => (_jsxs("button", { type: "button", onClick: () => patch("packagingType", codeOf(r)), className: `flex w-full items-start gap-2 px-3 py-2 text-left text-sm hover:bg-muted ${draft.packagingType === codeOf(r) ? "bg-muted" : ""}`, children: [_jsx("span", { className: "font-mono text-xs text-muted-foreground w-14 shrink-0", children: codeOf(r) }), _jsx("span", { className: "truncate", children: labelOf(r) })] }, r.record_id)))) })] })] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { className: "text-xs", children: "Ladingdrager" }), _jsxs(Select, { value: draft.loadCarrier || "AUCTION_TROLLEY", onValueChange: (v) => patch("loadCarrier", v), children: [_jsx(SelectTrigger, { children: _jsx(SelectValue, { placeholder: "Kies een ladingdrager" }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "AUCTION_TROLLEY", children: "Stapelwagen" }), _jsx(SelectItem, { value: "DANISH_TROLLEY", children: "Deense container" }), _jsx(SelectItem, { value: "EURO_TROLLEY", children: "Euro-rolcontainer" }), _jsx(SelectItem, { value: "PALLET", children: "Pallet" }), _jsx(SelectItem, { value: "EURO_PALLET", children: "Euro-pallet" }), _jsx(SelectItem, { value: "NONE", children: "Geen ladingdrager" })] })] })] })] }), _jsxs("div", { className: "grid grid-cols-3 gap-3", children: [_jsxs("div", { className: "space-y-1", children: [_jsx(Label, { className: "text-xs", children: "Stuks per fust" }), _jsx(Input, { type: "number", min: 1, value: draft.unitsPerPackage, onChange: (e) => patch("unitsPerPackage", Number(e.target.value) || 1) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { className: "text-xs", children: "Fusten per laag" }), _jsx(Input, { type: "number", min: 1, value: draft.packagesPerLayer, onChange: (e) => patch("packagesPerLayer", Number(e.target.value) || 1) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { className: "text-xs", children: "Lagen per drager" }), _jsx(Input, { type: "number", min: 1, value: draft.layersPerLoadCarrier, onChange: (e) => patch("layersPerLoadCarrier", Number(e.target.value) || 1) })] })] }), _jsxs("div", { className: "rounded-md border p-3 space-y-3", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: "Klantspecifieke belading" }), _jsx("div", { className: "text-xs text-muted-foreground", children: "Alleen zichtbaar voor geselecteerde klantorganisaties." })] }), _jsx(Switch, { checked: draft.isCustomerSpecific, onCheckedChange: (v) => patch("isCustomerSpecific", Boolean(v)) })] }), draft.isCustomerSpecific && (_jsx("div", { className: "max-h-40 overflow-y-auto rounded border divide-y", children: floridayCustomers.length === 0 ? (_jsx("div", { className: "p-3 text-xs text-muted-foreground", children: "Geen klantorganisaties geladen." })) : (floridayCustomers.map((c) => (_jsxs("label", { className: "flex items-center gap-2 px-3 py-2 text-sm hover:bg-muted cursor-pointer", children: [_jsx("input", { type: "checkbox", checked: draft.customerOrganizationIds.includes(c.id), onChange: () => toggleCustomer(c.id) }), _jsx("span", { className: "truncate", children: c.name })] }, c.id)))) }))] }), _jsxs("div", { className: "rounded-md border p-3 space-y-2", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: "Foto van dit fust (optioneel)" }), _jsx("div", { className: "text-xs text-muted-foreground", children: "JPG of PNG \u00B7 min. 640 \u00D7 640 px \u00B7 max. 5 MB" })] }), _jsx(Button, { type: "button", variant: "outline", size: "sm", disabled: uploadingPhoto || !activeId, onClick: () => photoInputRef.current?.click(), children: uploadingPhoto ? (_jsxs(_Fragment, { children: [_jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), " Uploaden"] })) : (_jsxs(_Fragment, { children: [_jsx(Upload, { className: "mr-2 h-4 w-4" }), " Foto kiezen"] })) }), _jsx("input", { ref: photoInputRef, type: "file", accept: "image/png,image/jpeg", className: "hidden", onChange: (e) => {
2752
+ : "Selecteer fust..." }), _jsx(ChevronDown, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })] }) }), _jsxs(PopoverContent, { className: "w-[380px] p-0", align: "start", children: [_jsx("div", { className: "border-b p-2", children: _jsx(Input, { placeholder: "Zoek op naam of code...", value: pkgSearch, onChange: (e) => setPkgSearch(e.target.value) }) }), _jsx("div", { className: "max-h-64 overflow-y-auto", children: filteredPkg.length === 0 ? (_jsx("div", { className: "px-3 py-4 text-center text-xs text-muted-foreground", children: "Geen resultaten" })) : (filteredPkg.map((r) => (_jsxs("button", { type: "button", onClick: () => patch("packagingType", codeOf(r)), className: `flex w-full items-start gap-2 px-3 py-2 text-left text-sm hover:bg-muted ${draft.packagingType === codeOf(r) ? "bg-muted" : ""}`, children: [_jsx("span", { className: "font-mono text-xs text-muted-foreground w-14 shrink-0", children: codeOf(r) }), _jsx("span", { className: "truncate", children: labelOf(r) })] }, r.record_id)))) })] })] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { className: "text-xs", children: "Ladingdrager" }), _jsxs(Select, { value: draft.loadCarrier || "AUCTION_TROLLEY", onValueChange: (v) => patch("loadCarrier", v), children: [_jsx(SelectTrigger, { children: _jsx(SelectValue, { placeholder: "Kies een ladingdrager" }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "AUCTION_TROLLEY", children: "Stapelwagen" }), _jsx(SelectItem, { value: "DANISH_TROLLEY", children: "Deense container" }), _jsx(SelectItem, { value: "EURO_TROLLEY", children: "Euro-rolcontainer" }), _jsx(SelectItem, { value: "PALLET", children: "Pallet" }), _jsx(SelectItem, { value: "EURO_PALLET", children: "Euro-pallet" }), _jsx(SelectItem, { value: "NONE", children: "Geen ladingdrager" })] })] })] })] }), _jsxs("div", { className: "grid grid-cols-3 gap-3", children: [_jsxs("div", { className: "space-y-1", children: [_jsx(Label, { className: "text-xs", children: "Stuks per fust" }), _jsx(Input, { type: "number", min: 1, placeholder: "Invullen", value: draft.unitsPerPackage > 0 ? draft.unitsPerPackage : "", onChange: (e) => patch("unitsPerPackage", Math.max(0, Math.floor(Number(e.target.value) || 0))) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { className: "text-xs", children: "Fusten per laag" }), _jsx(Input, { type: "number", min: 1, placeholder: "Invullen", value: draft.packagesPerLayer > 0 ? draft.packagesPerLayer : "", onChange: (e) => patch("packagesPerLayer", Math.max(0, Math.floor(Number(e.target.value) || 0))) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { className: "text-xs", children: "Lagen per drager" }), _jsx(Input, { type: "number", min: 1, placeholder: "Invullen", value: draft.layersPerLoadCarrier > 0 ? draft.layersPerLoadCarrier : "", onChange: (e) => patch("layersPerLoadCarrier", Math.max(0, Math.floor(Number(e.target.value) || 0))) })] }), !countsComplete && (_jsx("p", { className: "col-span-3 text-xs text-muted-foreground", children: "Vul stuks per fust, fusten per laag en lagen per drager in; er wordt niets vooraf ingevuld." }))] }), _jsxs("div", { className: "rounded-md border p-3 space-y-3", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: "Klantspecifieke belading" }), _jsx("div", { className: "text-xs text-muted-foreground", children: "Alleen zichtbaar voor geselecteerde klantorganisaties." })] }), _jsx(Switch, { checked: draft.isCustomerSpecific, onCheckedChange: (v) => patch("isCustomerSpecific", Boolean(v)) })] }), draft.isCustomerSpecific && (_jsx("div", { className: "max-h-40 overflow-y-auto rounded border divide-y", children: floridayCustomers.length === 0 ? (_jsx("div", { className: "p-3 text-xs text-muted-foreground", children: "Geen klantorganisaties geladen." })) : (floridayCustomers.map((c) => (_jsxs("label", { className: "flex items-center gap-2 px-3 py-2 text-sm hover:bg-muted cursor-pointer", children: [_jsx("input", { type: "checkbox", checked: draft.customerOrganizationIds.includes(c.id), onChange: () => toggleCustomer(c.id) }), _jsx("span", { className: "truncate", children: c.name })] }, c.id)))) }))] }), _jsxs("div", { className: "rounded-md border p-3 space-y-2", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: "Foto van dit fust (optioneel)" }), _jsx("div", { className: "text-xs text-muted-foreground", children: "JPG of PNG \u00B7 min. 640 \u00D7 640 px \u00B7 max. 5 MB" })] }), _jsx(Button, { type: "button", variant: "outline", size: "sm", disabled: uploadingPhoto || !activeId, onClick: () => photoInputRef.current?.click(), children: uploadingPhoto ? (_jsxs(_Fragment, { children: [_jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), " Uploaden"] })) : (_jsxs(_Fragment, { children: [_jsx(Upload, { className: "mr-2 h-4 w-4" }), " Foto kiezen"] })) }), _jsx("input", { ref: photoInputRef, type: "file", accept: "image/png,image/jpeg", className: "hidden", onChange: (e) => {
2697
2753
  onUploadPhoto(e.target.files?.[0]);
2698
2754
  e.target.value = "";
2699
2755
  } })] }), (draft.photoPreviewUrl || draft.photoUrl) && (_jsxs("div", { className: "relative inline-block", children: [_jsx("img", { src: draft.photoPreviewUrl || draft.photoUrl, alt: "Belading foto", className: "h-24 rounded-md border object-cover" }), _jsx("button", { type: "button", onClick: () => setDraft((d) => ({
@@ -2859,9 +2915,9 @@ function StepAanbieden({ data, update, priceGroups, parentProductId }) {
2859
2915
  }
2860
2916
  update("priceGroupPrices", next);
2861
2917
  };
2862
- return (_jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "rounded-md border bg-muted/30 p-3 text-sm text-muted-foreground", children: ["Zet dit product direct in de verkoop bij je gekoppelde Floriday-klanten. We sturen een ", _jsx("code", { children: "TradeItem" }), " + ", _jsx("code", { children: "CustomerOffer" }), " met vaste basisprijs per stuk en publiceren de opgegeven voorraad via de continuous-stock feed. Prijzen per prijsgroep worden als aparte", " ", _jsx("code", { children: "weekly-supply-lines" }), " naar Floriday gepusht."] }), _jsxs("div", { className: "flex items-center justify-between rounded-md border p-3", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: "Direct aanbieden voor verkoop" }), _jsx("div", { className: "text-xs text-muted-foreground", children: data.offerForSale
2918
+ return (_jsxs("div", { className: "space-y-6", children: [_jsx("div", { className: "rounded-md border bg-muted/30 p-3 text-sm text-muted-foreground", children: "Zet dit product direct in de verkoop bij je gekoppelde Floriday-klanten. Na publiceren staat het artikel bij Floriday, krijgen je klanten een aanbod met de basisprijs per stuk, en wordt je voorraad doorgegeven. Prijzen per prijsgroep worden apart doorgegeven als prijs per week." }), _jsxs("div", { className: "flex items-center justify-between rounded-md border p-3", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: "Direct aanbieden voor verkoop" }), _jsx("div", { className: "text-xs text-muted-foreground", children: data.offerForSale
2863
2919
  ? "Aanbod wordt aangemaakt direct na publiceren."
2864
- : "Alleen artikel publiceren, geen aanbod aanmaken." })] }), _jsx(Switch, { checked: data.offerForSale, onCheckedChange: (v) => update("offerForSale", Boolean(v)) })] }), data.offerForSale && (_jsxs(_Fragment, { children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: "Voorraad (stuks)" }), _jsx(Input, { type: "number", inputMode: "numeric", min: 0, step: 1, value: stockStr, onChange: (e) => update("saleStockPieces", Math.max(0, Math.floor(Number(e.target.value) || 0))) }), _jsx("p", { className: "text-xs text-muted-foreground", children: "Wordt als fysieke voorraad geboekt en via continuous-stock naar Floriday gepusht." })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: "Basisprijs per stuk (EUR, excl. btw)" }), _jsx(Input, { type: "number", inputMode: "decimal", min: 0, step: "0.01", value: priceStr, onChange: (e) => update("salePricePerPiece", Number(e.target.value) || 0) }), _jsxs("p", { className: "text-xs text-muted-foreground", children: ["Wordt gepusht als ", _jsx("code", { children: "weekly-base-supply" }), " \u2014 de standaard catalogusprijs voor klanten zonder eigen prijsgroep."] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: "Aanbod geldig vanaf" }), _jsx(Input, { type: "date", value: data.offerStartDate, onChange: (e) => update("offerStartDate", e.target.value) }), _jsx("p", { className: "text-xs text-muted-foreground", children: "Aanbod loopt automatisch tot 1 jaar na deze datum." })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: "Zichtbaar voor" }), _jsx("div", { className: "rounded-md border bg-muted/20 px-3 py-2 text-sm", children: data.customerOrganizationIds.length
2920
+ : "Alleen artikel publiceren, geen aanbod aanmaken." })] }), _jsx(Switch, { checked: data.offerForSale, onCheckedChange: (v) => update("offerForSale", Boolean(v)) })] }), data.offerForSale && (_jsxs(_Fragment, { children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: "Voorraad (stuks)" }), _jsx(Input, { type: "number", inputMode: "numeric", min: 0, step: 1, value: stockStr, onChange: (e) => update("saleStockPieces", Math.max(0, Math.floor(Number(e.target.value) || 0))) }), _jsx("p", { className: "text-xs text-muted-foreground", children: "Wordt als liggende voorraad geboekt en daarna aan Floriday doorgegeven. Mislukt het publiceren, dan blijft dit aantal hier bewaard." })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: "Basisprijs per stuk (EUR, excl. btw)" }), _jsx(Input, { type: "number", inputMode: "decimal", min: 0, step: "0.01", value: priceStr, onChange: (e) => update("salePricePerPiece", Number(e.target.value) || 0) }), _jsx("p", { className: "text-xs text-muted-foreground", children: "De standaardprijs per week voor klanten zonder eigen prijsgroep. Prijzen per prijsgroep vul je hieronder apart in." })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: "Aanbod geldig vanaf" }), _jsx(Input, { type: "date", value: data.offerStartDate, onChange: (e) => update("offerStartDate", e.target.value) }), _jsx("p", { className: "text-xs text-muted-foreground", children: "Aanbod loopt automatisch tot 1 jaar na deze datum." })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { children: "Zichtbaar voor" }), _jsx("div", { className: "rounded-md border bg-muted/20 px-3 py-2 text-sm", children: data.customerOrganizationIds.length
2865
2921
  ? `${data.customerOrganizationIds.length} geselecteerde klant(en)`
2866
2922
  : "Alle gekoppelde Floriday-klanten" }), _jsxs("p", { className: "text-xs text-muted-foreground", children: ["Klantselectie beheer je in de stap ", _jsx("em", { children: "Klanten" }), "."] })] })] }), _jsxs("div", { className: "space-y-2 rounded-md border p-4", children: [_jsxs("div", { className: "flex items-baseline justify-between", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: "Prijzen per Floriday-prijsgroep" }), _jsx("div", { className: "text-xs text-muted-foreground", children: "Laat leeg om voor die groep g\u00E9\u00E9n afwijkende prijs te publiceren. Basisprijs blijft dan gelden." })] }), _jsxs("div", { className: "text-xs text-muted-foreground", children: [priceGroups.length, " groep", priceGroups.length === 1 ? "" : "en"] })] }), priceGroups.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground py-4", children: "Geen actieve prijsgroepen gevonden voor deze Floriday-koppeling." })) : (_jsx("div", { className: "grid gap-3 sm:grid-cols-2 pt-2", children: priceGroups.map((g) => {
2867
2923
  const val = data.priceGroupPrices?.[g.id];
@@ -9,4 +9,9 @@ export declare function PublishProgressCard({ job, steps, onRetry, retrying, onF
9
9
  retrying?: boolean;
10
10
  onFixStep?: (stepKey: string) => void;
11
11
  }): import("react").JSX.Element | null;
12
+ /**
13
+ * Een job die nog op "running" staat terwijl geen stap meer loopt en er een
14
+ * stap mislukt is, telt als mislukt (scherm nooit blijven hangen op "Bezig").
15
+ */
16
+ export declare function effectiveJobStatus(jobStatus: string, steps: Array<Pick<PublishStepRow, "status" | "step_key">>): string;
12
17
  //# sourceMappingURL=PublishProgressCard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PublishProgressCard.d.ts","sourceRoot":"","sources":["../../../src/components/voorraad/PublishProgressCard.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAoBhF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,GAAG,EACH,KAAK,EACL,OAAO,EACP,QAAQ,EACR,SAAS,GACV,EAAE;IACD,GAAG,EAAE,aAAa,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC,sCAyDA"}
1
+ {"version":3,"file":"PublishProgressCard.d.ts","sourceRoot":"","sources":["../../../src/components/voorraad/PublishProgressCard.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAoBhF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,GAAG,EACH,KAAK,EACL,OAAO,EACP,QAAQ,EACR,SAAS,GACV,EAAE;IACD,GAAG,EAAE,aAAa,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC,sCA0DA;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,UAAU,CAAC,CAAC,GACxD,MAAM,CAMR"}
@@ -26,5 +26,20 @@ export function PublishProgressCard({ job, steps, onRetry, retrying, onFixStep,
26
26
  return null;
27
27
  const visible = steps.filter((s) => s.status !== "skipped");
28
28
  const failed = visible.filter((s) => s.status === "failed");
29
- return (_jsxs(Card, { className: "p-4 space-y-3", children: [_jsxs("div", { className: "flex items-start justify-between gap-3", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: JOB_TITLE[job.status] ?? "Publicatie" }), _jsxs("p", { className: "text-xs text-muted-foreground", children: ["Referentie ", job.reference_code] })] }), job.status !== "running" && failed.length > 0 && onRetry && (_jsxs(Button, { size: "sm", variant: "outline", onClick: onRetry, disabled: retrying, children: [retrying ? (_jsx(Loader2, { className: "mr-1 h-3 w-3 animate-spin" })) : (_jsx(RefreshCw, { className: "mr-1 h-3 w-3" })), "Opnieuw proberen"] }))] }), _jsx("ul", { className: "space-y-2", children: visible.map((s) => (_jsxs("li", { className: "flex items-start gap-2 text-sm", children: [_jsx("span", { className: "mt-0.5", children: _jsx(StatusIcon, { status: s.status }) }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("div", { className: s.status === "done" ? "text-muted-foreground" : "", children: s.label }), s.status === "failed" && s.error_message && (_jsx("div", { className: "text-xs text-destructive", children: s.error_message }))] }), s.status === "failed" && onFixStep && (_jsx(Button, { size: "sm", variant: "ghost", className: "h-6 px-2 text-xs", onClick: () => onFixStep(s.step_key), children: "Oplossen" }))] }, s.id))) })] }));
29
+ const status = effectiveJobStatus(job.status, visible);
30
+ return (_jsxs(Card, { className: "p-4 space-y-3", children: [_jsxs("div", { className: "flex items-start justify-between gap-3", children: [_jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium", children: JOB_TITLE[status] ?? "Publicatie" }), _jsxs("p", { className: "text-xs text-muted-foreground", children: ["Referentie ", job.reference_code] })] }), status !== "running" && failed.length > 0 && onRetry && (_jsxs(Button, { size: "sm", variant: "outline", onClick: onRetry, disabled: retrying, children: [retrying ? (_jsx(Loader2, { className: "mr-1 h-3 w-3 animate-spin" })) : (_jsx(RefreshCw, { className: "mr-1 h-3 w-3" })), "Opnieuw proberen"] }))] }), _jsx("ul", { className: "space-y-2", children: visible.map((s) => (_jsxs("li", { className: "flex items-start gap-2 text-sm", children: [_jsx("span", { className: "mt-0.5", children: _jsx(StatusIcon, { status: s.status }) }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("div", { className: s.status === "done" ? "text-muted-foreground" : "", children: s.label }), s.status === "failed" && s.error_message && (_jsx("div", { className: "text-xs text-destructive", children: s.error_message }))] }), s.status === "failed" && onFixStep && (_jsx(Button, { size: "sm", variant: "ghost", className: "h-6 px-2 text-xs", onClick: () => onFixStep(s.step_key), children: "Oplossen" }))] }, s.id))) })] }));
31
+ }
32
+ /**
33
+ * Een job die nog op "running" staat terwijl geen stap meer loopt en er een
34
+ * stap mislukt is, telt als mislukt (scherm nooit blijven hangen op "Bezig").
35
+ */
36
+ export function effectiveJobStatus(jobStatus, steps) {
37
+ if (jobStatus !== "running")
38
+ return jobStatus;
39
+ const anyRunning = steps.some((s) => s.status === "running");
40
+ if (anyRunning)
41
+ return jobStatus;
42
+ if (steps.some((s) => s.status === "failed" && s.step_key === "trade-item"))
43
+ return "failed";
44
+ return jobStatus;
30
45
  }
@@ -1,2 +1,15 @@
1
+ import type { TradeItem } from "../../lib/floriday-client.js";
2
+ /**
3
+ * "Op voorraad" = artikelen met liggende voorraad (fysiek > 0).
4
+ * "Vrij beschikbaar" = artikelen waarvan liggend min gereserveerd > 0.
5
+ */
6
+ export declare function countStock(items: Array<Pick<TradeItem, "quantity" | "availableQuantity" | "minQuantity">>): {
7
+ total: number;
8
+ inStock: number;
9
+ outOfStock: number;
10
+ belowMin: number;
11
+ fullyReserved: number;
12
+ freeAvailable: number;
13
+ };
1
14
  export declare function VoorraadPage(): import("react").JSX.Element;
2
15
  //# sourceMappingURL=VoorraadPage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VoorraadPage.d.ts","sourceRoot":"","sources":["../../../src/components/voorraad/VoorraadPage.tsx"],"names":[],"mappings":"AA+GA,wBAAgB,YAAY,gCA2W3B"}
1
+ {"version":3,"file":"VoorraadPage.d.ts","sourceRoot":"","sources":["../../../src/components/voorraad/VoorraadPage.tsx"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAqF3D;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,GAAG,mBAAmB,GAAG,aAAa,CAAC,CAAC;;;;;;;EAgBzG;AAED,wBAAgB,YAAY,gCA0W3B"}
@@ -37,13 +37,39 @@ function toneClasses(tone) {
37
37
  return { icon: "bg-primary/10 text-primary", value: "text-foreground" };
38
38
  }
39
39
  }
40
- function KpiCard({ icon, label, count, tone, active, onClick, }) {
40
+ function KpiCard({ icon, label, count, tone, active, onClick, hint, }) {
41
41
  const cls = toneClasses(tone);
42
- return (_jsxs("button", { type: "button", onClick: onClick, className: `text-left rounded-lg border bg-card p-4 transition-colors hover:border-primary/50 ${active ? "border-primary ring-1 ring-primary" : "border-border"}`, children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: `inline-flex h-8 w-8 items-center justify-center rounded-md ${cls.icon}`, children: icon }), _jsx("span", { className: "text-sm font-medium text-foreground", children: label })] }), _jsx("div", { className: `mt-3 text-3xl font-bold tabular-nums ${cls.value}`, children: count })] }));
42
+ return (_jsxs("button", { type: "button", onClick: onClick, title: hint, className: `text-left rounded-lg border bg-card p-4 transition-colors hover:border-primary/50 ${active ? "border-primary ring-1 ring-primary" : "border-border"}`, children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: `inline-flex h-8 w-8 items-center justify-center rounded-md ${cls.icon}`, children: icon }), _jsx("span", { className: "text-sm font-medium text-foreground", children: label })] }), _jsx("div", { className: `mt-3 text-3xl font-bold tabular-nums ${cls.value}`, children: count }), hint && _jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: hint })] }));
43
43
  }
44
44
  function availableOf(i) {
45
45
  return i.availableQuantity ?? i.quantity ?? 0;
46
46
  }
47
+ /**
48
+ * "Op voorraad" = artikelen met liggende voorraad (fysiek > 0).
49
+ * "Vrij beschikbaar" = artikelen waarvan liggend min gereserveerd > 0.
50
+ */
51
+ export function countStock(items) {
52
+ let inStock = 0;
53
+ let outOfStock = 0;
54
+ let belowMin = 0;
55
+ let fullyReserved = 0;
56
+ let freeAvailable = 0;
57
+ for (const i of items) {
58
+ const physical = Number(i.quantity ?? 0);
59
+ const avail = availableOf(i);
60
+ if (physical > 0)
61
+ inStock++;
62
+ else
63
+ outOfStock++;
64
+ if (avail > 0)
65
+ freeAvailable++;
66
+ if (physical > 0 && avail <= 0)
67
+ fullyReserved++;
68
+ if ((i.minQuantity ?? 0) > 0 && avail < (i.minQuantity ?? 0))
69
+ belowMin++;
70
+ }
71
+ return { total: items.length, inStock, outOfStock, belowMin, fullyReserved, freeAvailable };
72
+ }
47
73
  export function VoorraadPage() {
48
74
  const auth = useAuthState();
49
75
  const conn = useFloridayConnection();
@@ -80,30 +106,17 @@ export function VoorraadPage() {
80
106
  setDrawerIds(ids);
81
107
  setDrawerOpen(true);
82
108
  };
83
- const counts = useMemo(() => {
84
- let inStock = 0;
85
- let outOfStock = 0;
86
- let belowMin = 0;
87
- for (const i of items) {
88
- const avail = availableOf(i);
89
- if (avail > 0)
90
- inStock++;
91
- else
92
- outOfStock++;
93
- if ((i.minQuantity ?? 0) > 0 && avail < i.minQuantity)
94
- belowMin++;
95
- }
96
- return { total: items.length, inStock, outOfStock, belowMin };
97
- }, [items]);
109
+ const counts = useMemo(() => countStock(items), [items]);
98
110
  const filtered = useMemo(() => {
99
111
  const q = search.trim().toLowerCase();
100
112
  return items.filter((i) => {
101
113
  if (noPriceOnly && !(i.productId && noPriceIds.has(i.productId)))
102
114
  return false;
103
115
  const avail = availableOf(i);
104
- if (stockFilter === "in_stock" && avail <= 0)
116
+ const physicalQty = Number(i.quantity ?? 0);
117
+ if (stockFilter === "in_stock" && physicalQty <= 0)
105
118
  return false;
106
- if (stockFilter === "out_of_stock" && avail > 0)
119
+ if (stockFilter === "out_of_stock" && physicalQty > 0)
107
120
  return false;
108
121
  if (stockFilter === "below_min" &&
109
122
  !((i.minQuantity ?? 0) > 0 && avail < i.minQuantity))
@@ -139,7 +152,7 @@ export function VoorraadPage() {
139
152
  noPriceBreakdown.unit > 0 ? `${noPriceBreakdown.unit} met een andere eenheid dan stuks` : null,
140
153
  ]
141
154
  .filter(Boolean)
142
- .join(", "), "."] }), " ", "Kies \"Toon deze artikelen\", open een artikel en vul bij Artikel regulier de verkoopprijs per stuk (excl. btw) in. De voorraadsturing van elk artikel heeft ook een link \"Prijs invullen\"."] }), _jsx(Button, { variant: "outline", size: "sm", onClick: () => setNoPriceOnly((v) => !v), children: noPriceOnly ? "Alle artikelen tonen" : "Toon deze artikelen" })] })), _jsx(FloridayLeadingSummary, { connectionId: activeId ?? null }), auth.isAdmin && _jsx(FloridayTakeoverPanel, { connectionId: activeId ?? null }), auth.isAdmin && _jsx(StockPushMonitor, { connectionId: activeId ?? null }), _jsx(FloridayConnectionNotice, { status: conn.status, environment: conn.selectedEnvironment, error: connError }), error && (_jsxs("div", { className: "rounded-md border border-destructive/40 bg-destructive/10 text-destructive p-3 text-sm", children: ["Voorraad laden mislukt: ", error] })), _jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4", children: [_jsx(KpiCard, { icon: _jsx(FileText, { className: "h-4 w-4" }), tone: "primary", label: "Artikelen", count: counts.total, active: stockFilter === "all", onClick: () => toggle("all") }), _jsx(KpiCard, { icon: _jsx(CheckCircle2, { className: "h-4 w-4" }), tone: "emerald", label: "Op voorraad", count: counts.inStock, active: stockFilter === "in_stock", onClick: () => toggle("in_stock") }), _jsx(KpiCard, { icon: _jsx(PackageX, { className: "h-4 w-4" }), tone: "rose", label: "Niet op voorraad", count: counts.outOfStock, active: stockFilter === "out_of_stock", onClick: () => toggle("out_of_stock") }), _jsx(KpiCard, { icon: _jsx(AlertTriangle, { className: "h-4 w-4" }), tone: "amber", label: "Onder minimum", count: counts.belowMin, active: stockFilter === "below_min", onClick: () => toggle("below_min") })] }), _jsxs(Card, { className: "overflow-hidden p-0", children: [_jsx("div", { className: "flex flex-wrap items-center gap-1 border-b px-4", children: TABS.map((t) => {
155
+ .join(", "), "."] }), " ", "Kies \"Toon deze artikelen\", open een artikel en vul bij Artikel regulier de verkoopprijs per stuk (excl. btw) in. De voorraadsturing van elk artikel heeft ook een link \"Prijs invullen\"."] }), _jsx(Button, { variant: "outline", size: "sm", onClick: () => setNoPriceOnly((v) => !v), children: noPriceOnly ? "Alle artikelen tonen" : "Toon deze artikelen" })] })), _jsx(FloridayLeadingSummary, { connectionId: activeId ?? null }), auth.isAdmin && _jsx(FloridayTakeoverPanel, { connectionId: activeId ?? null }), auth.isAdmin && _jsx(StockPushMonitor, { connectionId: activeId ?? null }), _jsx(FloridayConnectionNotice, { status: conn.status, environment: conn.selectedEnvironment, error: connError }), error && (_jsxs("div", { className: "rounded-md border border-destructive/40 bg-destructive/10 text-destructive p-3 text-sm", children: ["Voorraad laden mislukt: ", error] })), _jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-4", children: [_jsx(KpiCard, { icon: _jsx(FileText, { className: "h-4 w-4" }), tone: "primary", label: "Artikelen", count: counts.total, active: stockFilter === "all", onClick: () => toggle("all") }), _jsx(KpiCard, { icon: _jsx(CheckCircle2, { className: "h-4 w-4" }), tone: "emerald", label: "Op voorraad", count: counts.inStock, active: stockFilter === "in_stock", onClick: () => toggle("in_stock"), hint: "Artikelen waarvan nu iets op de kwekerij staat." }), _jsx(KpiCard, { icon: _jsx(CheckCircle2, { className: "h-4 w-4" }), tone: "primary", label: "Vrij beschikbaar", count: counts.freeAvailable, active: false, hint: "Artikelen waarvan na aftrek van wat voor orders gereserveerd is nog iets over is." }), _jsx(KpiCard, { icon: _jsx(PackageX, { className: "h-4 w-4" }), tone: "rose", label: "Niet op voorraad", count: counts.outOfStock, active: stockFilter === "out_of_stock", onClick: () => toggle("out_of_stock") }), _jsx(KpiCard, { icon: _jsx(AlertTriangle, { className: "h-4 w-4" }), tone: "amber", label: "Onder minimum", count: counts.belowMin, active: stockFilter === "below_min", onClick: () => toggle("below_min") })] }), _jsxs(Card, { className: "overflow-hidden p-0", children: [_jsx("div", { className: "flex flex-wrap items-center gap-1 border-b px-4", children: TABS.map((t) => {
143
156
  const active = stockFilter === t.id;
144
157
  return (_jsxs("button", { type: "button", onClick: () => setStockFilter(t.id), className: `relative py-3 px-3 text-sm font-medium whitespace-nowrap transition-colors ${active
145
158
  ? "text-foreground"
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=count-stock-free.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"count-stock-free.test.d.ts","sourceRoot":"","sources":["../../../../src/components/voorraad/__tests__/count-stock-free.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { countStock } from "../VoorraadPage.js";
3
+ describe("countStock vrij beschikbaar", () => {
4
+ it("liggend 100 met 100 gereserveerd: op voorraad, niet vrij", () => {
5
+ const c = countStock([{ quantity: 100, availableQuantity: 0, minQuantity: 0 }]);
6
+ expect(c.inStock).toBe(1);
7
+ expect(c.freeAvailable).toBe(0);
8
+ });
9
+ it("liggend 100 met 40 gereserveerd: vrij", () => {
10
+ expect(countStock([{ quantity: 100, availableQuantity: 60, minQuantity: 0 }]).freeAvailable).toBe(1);
11
+ });
12
+ });