@flowselections/floriday-verkoop-module 1.0.132 → 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.
Files changed (63) hide show
  1. package/dist-lib/components/verkoop/CreateOrderPage.d.ts.map +1 -1
  2. package/dist-lib/components/verkoop/CreateOrderPage.js +4 -1
  3. package/dist-lib/components/verkoop/InvoiceSignoffSettings.d.ts +2 -0
  4. package/dist-lib/components/verkoop/InvoiceSignoffSettings.d.ts.map +1 -0
  5. package/dist-lib/components/verkoop/InvoiceSignoffSettings.js +31 -0
  6. package/dist-lib/components/verkoop/OrderInvoiceCard.d.ts +4 -0
  7. package/dist-lib/components/verkoop/OrderInvoiceCard.d.ts.map +1 -0
  8. package/dist-lib/components/verkoop/OrderInvoiceCard.js +62 -0
  9. package/dist-lib/components/verkoop/SalesOrderDetailView.d.ts.map +1 -1
  10. package/dist-lib/components/verkoop/SalesOrderDetailView.js +3 -2
  11. package/dist-lib/components/verkoop/SalesOrdersTable.d.ts.map +1 -1
  12. package/dist-lib/components/verkoop/SalesOrdersTable.js +3 -2
  13. package/dist-lib/index.d.ts.map +1 -1
  14. package/dist-lib/index.js +2 -0
  15. package/dist-lib/integrations/supabase/types.d.ts +18 -0
  16. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  17. package/dist-lib/lib/delivery-location.server.d.ts.map +1 -1
  18. package/dist-lib/lib/delivery-location.server.js +56 -13
  19. package/dist-lib/lib/erp-invoice-view.check.d.ts +2 -0
  20. package/dist-lib/lib/erp-invoice-view.check.d.ts.map +1 -0
  21. package/dist-lib/lib/erp-invoice-view.check.js +32 -0
  22. package/dist-lib/lib/erp-invoice-view.d.ts +29 -0
  23. package/dist-lib/lib/erp-invoice-view.d.ts.map +1 -0
  24. package/dist-lib/lib/erp-invoice-view.js +53 -0
  25. package/dist-lib/lib/invoice-release.check.d.ts +2 -0
  26. package/dist-lib/lib/invoice-release.check.d.ts.map +1 -0
  27. package/dist-lib/lib/invoice-release.check.js +21 -0
  28. package/dist-lib/lib/invoice-signoff-payload.check.d.ts +2 -0
  29. package/dist-lib/lib/invoice-signoff-payload.check.d.ts.map +1 -0
  30. package/dist-lib/lib/invoice-signoff-payload.check.js +27 -0
  31. package/dist-lib/lib/invoice-signoff-payload.d.ts +4 -0
  32. package/dist-lib/lib/invoice-signoff-payload.d.ts.map +1 -0
  33. package/dist-lib/lib/invoice-signoff-payload.js +5 -0
  34. package/dist-lib/lib/invoice-timing.d.ts +35 -0
  35. package/dist-lib/lib/invoice-timing.d.ts.map +1 -1
  36. package/dist-lib/lib/invoice-timing.functions.d.ts +16 -2
  37. package/dist-lib/lib/invoice-timing.functions.d.ts.map +1 -1
  38. package/dist-lib/lib/invoice-timing.functions.js +33 -2
  39. package/dist-lib/lib/invoice-timing.js +29 -0
  40. package/dist-lib/lib/invoice-timing.server.d.ts +19 -3
  41. package/dist-lib/lib/invoice-timing.server.d.ts.map +1 -1
  42. package/dist-lib/lib/invoice-timing.server.js +75 -11
  43. package/dist-lib/lib/module-version.d.ts +1 -1
  44. package/dist-lib/lib/module-version.js +1 -1
  45. package/dist-lib/lib/plan-coverage-v204.check.js +2 -0
  46. package/dist-lib/lib/plan-coverage.d.ts +9 -2
  47. package/dist-lib/lib/plan-coverage.d.ts.map +1 -1
  48. package/dist-lib/lib/plan-coverage.js +15 -3
  49. package/dist-lib/lib/product-oordeel.d.ts +12 -0
  50. package/dist-lib/lib/product-oordeel.d.ts.map +1 -0
  51. package/dist-lib/lib/product-oordeel.js +24 -0
  52. package/dist-lib/lib/product-plannable.functions.d.ts +2 -0
  53. package/dist-lib/lib/product-plannable.functions.d.ts.map +1 -1
  54. package/dist-lib/lib/product-plannable.functions.js +15 -9
  55. package/dist-lib/lib/salesorders-list.functions.d.ts +1 -1
  56. package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
  57. package/dist-lib/lib/salesorders-list.server.js +6 -1
  58. package/dist-lib/lib/salesorders-mapping.d.ts +4 -0
  59. package/dist-lib/lib/salesorders-mapping.d.ts.map +1 -1
  60. package/dist-lib/lib/salesorders.functions.d.ts.map +1 -1
  61. package/dist-lib/lib/salesorders.functions.js +4 -1
  62. package/package.json +1 -1
  63. package/schema/verkoop.sql +5 -0
@@ -1 +1 @@
1
- {"version":3,"file":"delivery-location.server.d.ts","sourceRoot":"","sources":["../../src/lib/delivery-location.server.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,MAAM,EAAE,mBAAmB,GAAG,kBAAkB,GAAG,cAAc,GAAG,YAAY,CAAC;CAClF;AAUD,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAGxD;AAED,8CAA8C;AAC9C,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAM3F;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,eAAe,EAAE,GAAG,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAcD,sEAAsE;AACtE,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,WAAW,EAChB,iBAAi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,GAAG,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAcD,sEAAsE;AACtE,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,WAAW,EAChB,iBAAiB,EAAE;IAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC;IAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,EAAE,EACnH,iBAAiB,EAAE,GAAG,EAAE,GACvB,gBAAgB,GAAG,IAAI,CAkDzB;AA0CD;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,GAAG,EACb,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAiFxC"}
@@ -82,13 +82,61 @@ export function pickDeliveryLocation(ref, floridayLocations, customerLocations)
82
82
  }
83
83
  return null;
84
84
  }
85
+ /** Korte cache per order (5 min) zodat herhaald openen van lijst/detail niet steeds opvraagt. */
86
+ const CACHE_MS = 5 * 60000;
87
+ const ORDER_CACHE = new Map();
88
+ /** Alleen de velden die pickDeliveryLocation leest; niet de hele data-kolom. */
89
+ const FL_COLS = "gln_code, floriday_id, is_deleted, d_name:data->name, d_address:data->address, d_gln:data->>gln, d_locationId:data->>locationId, d_organizationId:data->>organizationId, d_isDeleted:data->isDeleted";
90
+ /**
91
+ * Twee losse reads (op gln_code en op floriday_id) i.p.v. één OR, zodat elk zijn eigen
92
+ * index kan gebruiken; samengevoegd en ontdubbeld in code.
93
+ */
94
+ async function loadFloridayLocationRows(supabase, glns, locIds) {
95
+ const reads = await Promise.all([
96
+ glns.length ? supabase.from("floriday_delivery_locations_cache").select(FL_COLS).in("gln_code", glns) : Promise.resolve({ data: [] }),
97
+ locIds.length ? supabase.from("floriday_delivery_locations_cache").select(FL_COLS).in("floriday_id", locIds) : Promise.resolve({ data: [] }),
98
+ ]);
99
+ const seen = new Set();
100
+ const rows = [];
101
+ for (const r of reads.flatMap((x) => (x?.data ?? []))) {
102
+ const k = `${r.floriday_id ?? ""}|${r.gln_code ?? ""}`;
103
+ if (seen.has(k))
104
+ continue;
105
+ seen.add(k);
106
+ rows.push({
107
+ gln_code: r.gln_code ?? null,
108
+ floriday_id: r.floriday_id ?? null,
109
+ is_deleted: r.is_deleted ?? null,
110
+ data: {
111
+ name: r.d_name ?? null,
112
+ address: r.d_address ?? null,
113
+ gln: r.d_gln ?? null,
114
+ locationId: r.d_locationId ?? null,
115
+ organizationId: r.d_organizationId ?? null,
116
+ isDeleted: r.d_isDeleted ?? null,
117
+ },
118
+ });
119
+ }
120
+ return rows;
121
+ }
85
122
  /**
86
123
  * Afleverlocaties voor lokale order-id's (orders.id). Vier gebundelde reads,
87
124
  * ongeacht het aantal orders. Fout → lege map (scherm valt terug).
88
125
  */
89
126
  export async function loadDeliveryLocations(supabase, orderIds) {
90
127
  const out = new Map();
91
- const ids = Array.from(new Set(orderIds.filter((x) => UUID_RE.test(x))));
128
+ const all = Array.from(new Set(orderIds.filter((x) => UUID_RE.test(x))));
129
+ const now = Date.now();
130
+ const ids = [];
131
+ for (const id of all) {
132
+ const hit = ORDER_CACHE.get(id);
133
+ if (hit && hit.until > now) {
134
+ if (hit.loc)
135
+ out.set(id, hit.loc);
136
+ }
137
+ else
138
+ ids.push(id);
139
+ }
92
140
  if (!ids.length)
93
141
  return out;
94
142
  try {
@@ -119,11 +167,11 @@ export async function loadDeliveryLocations(supabase, orderIds) {
119
167
  if (sids.size) {
120
168
  const { data: so } = await supabase
121
169
  .from("floriday_salesorders_cache")
122
- .select("floriday_id, data")
170
+ .select("floriday_id, loc:data->delivery->location")
123
171
  .in("floriday_id", Array.from(sids));
124
172
  const bySid = new Map();
125
173
  for (const r of (so ?? []))
126
- bySid.set(String(r.floriday_id), r.data?.delivery?.location ?? null);
174
+ bySid.set(String(r.floriday_id), r.loc ?? null);
127
175
  for (const r of refs) {
128
176
  const loc = r._sid ? bySid.get(r._sid) : null;
129
177
  if (loc) {
@@ -136,15 +184,7 @@ export async function loadDeliveryLocations(supabase, orderIds) {
136
184
  const glns = Array.from(new Set(refs.map((r) => r.gln).filter(Boolean)));
137
185
  const locIds = Array.from(new Set(refs.map((r) => r.locationId).filter(Boolean)));
138
186
  const [fl, cl] = await Promise.all([
139
- glns.length || locIds.length
140
- ? supabase
141
- .from("floriday_delivery_locations_cache")
142
- .select("gln_code, floriday_id, data, is_deleted")
143
- .or([
144
- glns.length ? `gln_code.in.(${glns.join(",")})` : null,
145
- locIds.length ? `floriday_id.in.(${locIds.join(",")})` : null,
146
- ].filter(Boolean).join(","))
147
- : Promise.resolve({ data: [] }),
187
+ loadFloridayLocationRows(supabase, glns, locIds),
148
188
  glns.length || locIds.length
149
189
  ? supabase
150
190
  .from("customer_delivery_locations")
@@ -159,10 +199,13 @@ export async function loadDeliveryLocations(supabase, orderIds) {
159
199
  : Promise.resolve({ data: [] }),
160
200
  ]);
161
201
  for (const r of refs) {
162
- const l = pickDeliveryLocation(r, (fl.data ?? []), (cl.data ?? []));
202
+ const l = pickDeliveryLocation(r, fl, (cl.data ?? []));
163
203
  if (l)
164
204
  out.set(r.key, l);
205
+ ORDER_CACHE.set(r.key, { loc: l, until: now + CACHE_MS });
165
206
  }
207
+ if (ORDER_CACHE.size > 5000)
208
+ ORDER_CACHE.clear();
166
209
  }
167
210
  catch (e) {
168
211
  console.warn("[delivery-location] opvraging mislukt:", e?.message);
@@ -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.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erp-invoice-view.d.ts","sourceRoot":"","sources":["../../src/lib/erp-invoice-view.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,GAAG,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GACrG,SAAS,GACT,WAAW,GACX,OAAO,CAMV;AAUD,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAIjE;AAMD,wBAAgB,cAAc,CAAC,CAAC,EAAE,aAAa,GAAG,cAAc,CAkB/D;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,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
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=invoice-release.check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-release.check.d.ts","sourceRoot":"","sources":["../../src/lib/invoice-release.check.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ // Test: factuurvrijgave raakt de orderstatus niet en wacht op afmelding (`bun src/lib/invoice-release.check.ts`).
2
+ import { decideInvoiceRelease, INVOICE_NO_SIGNOFF_NOTE, INVOICE_WAIT_TEXT, invoiceStateLabel } from "./invoice-timing.js";
3
+ function eq(name, a, e) {
4
+ if (JSON.stringify(a) !== JSON.stringify(e))
5
+ throw new Error(`${name}: verwacht ${JSON.stringify(e)}, kreeg ${JSON.stringify(a)}`);
6
+ console.log("ok ", name);
7
+ }
8
+ const now = new Date("2026-10-27T14:45:05Z");
9
+ const past = "2026-10-27T14:40:00Z";
10
+ const none = { allCartsScanned: false, reportedOrShipped: false, manualDelivered: false, hasCarts: true };
11
+ eq("moment voorbij, niet gepickt → wacht op levering", decideInvoiceRelease(past, now, none, false), { release: false, wait: INVOICE_WAIT_TEXT });
12
+ eq("moment niet voorbij → niet vrij", decideInvoiceRelease("2026-10-28T00:00:00Z", now, { ...none, manualDelivered: true }, false).release, false);
13
+ eq("a. alle karren gescand → vrij", decideInvoiceRelease(past, now, { ...none, allCartsScanned: true }, false), { release: true, note: null });
14
+ eq("b. verzonden/gemeld → vrij", decideInvoiceRelease(past, now, { ...none, reportedOrShipped: true }, false), { release: true, note: null });
15
+ eq("c. handmatig geleverd → vrij", decideInvoiceRelease(past, now, { ...none, manualDelivered: true }, false), { release: true, note: null });
16
+ eq("geen karindeling, instelling nee → wacht", decideInvoiceRelease(past, now, { ...none, hasCarts: false }, false).release, false);
17
+ eq("geen karindeling, instelling ja → vrij met melding", decideInvoiceRelease(past, now, { ...none, hasCarts: false }, true), { release: true, note: INVOICE_NO_SIGNOFF_NOTE });
18
+ eq("wel karren, instelling ja, niet gescand → wacht", decideInvoiceRelease(past, now, none, true).release, false);
19
+ eq("indeling onbekend, instelling ja → wacht", decideInvoiceRelease(past, now, { ...none, hasCarts: null }, true).release, false);
20
+ eq("label wacht", invoiceStateLabel({ invoice_due_at: past }, now), INVOICE_WAIT_TEXT);
21
+ eq("label klaar", invoiceStateLabel({ invoice_due_at: past, invoice_ready_at: "2026-10-27T14:45:00Z" }, now), "klaar voor facturatie sinds 27-10, 15:45");
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=invoice-signoff-payload.check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-signoff-payload.check.d.ts","sourceRoot":"","sources":["../../src/lib/invoice-signoff-payload.check.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ // Draai: bun src/lib/invoice-signoff-payload.check.ts
2
+ import { buildInvoiceWithoutSignoffPayload } from "./invoice-signoff-payload.js";
3
+ import { buildOordeelRegel, classifyOordeel } from "./product-oordeel.js";
4
+ let failed = 0;
5
+ function check(name, got, want) {
6
+ const g = JSON.stringify(got), w = JSON.stringify(want);
7
+ const ok = g === w;
8
+ if (!ok)
9
+ failed++;
10
+ console.log(`${ok ? "OK " : "FOUT"} ${name}: ${g}${ok ? "" : ` (verwacht ${w})`}`);
11
+ }
12
+ check("aan: alleen invoice_without_signoff", buildInvoiceWithoutSignoffPayload(true), { invoice_without_signoff: true });
13
+ check("uit: alleen invoice_without_signoff", buildInvoiceWithoutSignoffPayload(false), { invoice_without_signoff: false });
14
+ check("sleutels", Object.keys(buildInvoiceWithoutSignoffPayload(true)), ["invoice_without_signoff"]);
15
+ const base = { productId: "p", plantsPerCrate: 12, cratesPerLayer: 5, layersPerCart: 6 };
16
+ check("Floriday-code ongewijzigd", buildOordeelRegel({ ...base, carrierCode: "DANISH_TROLLEY" }).carrier_code, "DANISH_TROLLEY");
17
+ check("Beheer-code ongewijzigd", buildOordeelRegel({ ...base, carrierCode: "danish_container" }).carrier_code, "danish_container");
18
+ check("zonder ladingdrager geen carrier_code", "carrier_code" in buildOordeelRegel({ ...base, carrierCode: null }), false);
19
+ check("lege ladingdrager geen carrier_code", "carrier_code" in buildOordeelRegel({ ...base, carrierCode: " " }), false);
20
+ check("onmogelijk = blokkade", classifyOordeel("onmogelijk"), "blokkade");
21
+ check("mist_gegevens = zacht", classifyOordeel("mist_gegevens"), "zacht");
22
+ check("ok = niets", classifyOordeel("ok"), null);
23
+ if (failed) {
24
+ console.error(`${failed} controle(s) mislukt`);
25
+ process.exit(1);
26
+ }
27
+ console.log("Alle controles geslaagd");
@@ -0,0 +1,4 @@
1
+ export declare function buildInvoiceWithoutSignoffPayload(value: boolean): {
2
+ invoice_without_signoff: boolean;
3
+ };
4
+ //# sourceMappingURL=invoice-signoff-payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-signoff-payload.d.ts","sourceRoot":"","sources":["../../src/lib/invoice-signoff-payload.ts"],"names":[],"mappings":"AAEA,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,uBAAuB,EAAE,OAAO,CAAA;CAAE,CAEtG"}
@@ -0,0 +1,5 @@
1
+ // Payload voor de schakelaar "Factureren zonder afmelding": alleen dat ene veld,
2
+ // zodat de overige factuurinstellingen nooit worden overschreven.
3
+ export function buildInvoiceWithoutSignoffPayload(value) {
4
+ return { invoice_without_signoff: value === true };
5
+ }
@@ -14,8 +14,43 @@ export interface InvoiceTimingSettings {
14
14
  pickupOffsetDays: number;
15
15
  pickupBusinessDaysOnly: boolean;
16
16
  pickupTimeOfDay: string;
17
+ /** Orders zonder karindeling/afmelding toch vrijgeven op het moment (standaard nee). */
18
+ invoiceWithoutSignoff?: boolean;
17
19
  }
18
20
  export declare const DEFAULT_INVOICE_TIMING: InvoiceTimingSettings;
21
+ export declare const INVOICE_WAIT_TEXT = "factuur wacht op levering";
22
+ export declare const INVOICE_NO_SIGNOFF_NOTE = "geen afmelding gevonden, gefactureerd op leverdatum";
23
+ /** Afmeldbronnen voor één order (zie invoice-timing.server.ts loadSignoffs). */
24
+ export interface OrderSignoff {
25
+ /** a. alle karren bij de controlepost gescand (eindscan). */
26
+ allCartsScanned: boolean;
27
+ /** b. gemeld bij Floriday (FO) of verzending met shipped_at. */
28
+ reportedOrShipped: boolean;
29
+ /** c. handmatig op "geleverd" gezet. */
30
+ manualDelivered: boolean;
31
+ /** Heeft de order een karindeling? null = onbekend (Engine niet bereikbaar). */
32
+ hasCarts: boolean | null;
33
+ }
34
+ export type InvoiceReleaseDecision = {
35
+ release: true;
36
+ note: string | null;
37
+ } | {
38
+ release: false;
39
+ wait: string;
40
+ };
41
+ /**
42
+ * Beslist of een order vrij mag voor facturatie. Raakt nooit de orderstatus.
43
+ * - moment niet voorbij → wachten
44
+ * - afgemeld (a, b of c) → vrijgeven
45
+ * - geen karindeling + instelling "Factureren zonder afmelding" → vrijgeven met melding
46
+ * - anders → "factuur wacht op levering"
47
+ */
48
+ export declare function decideInvoiceRelease(dueAt: string | null, now: Date, signoff: OrderSignoff, invoiceWithoutSignoff: boolean): InvoiceReleaseDecision;
49
+ /** Tekst voor lijst/detail. */
50
+ export declare function invoiceStateLabel(o: {
51
+ invoice_due_at?: string | null;
52
+ invoice_ready_at?: string | null;
53
+ }, now?: Date): string | null;
19
54
  /** Beschikbare ijkpunten per order. Ontbrekende waarden -> geen factuurmoment. */
20
55
  export interface InvoiceAnchorInput {
21
56
  createdAt?: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"invoice-timing.d.ts","sourceRoot":"","sources":["../../src/lib/invoice-timing.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GACrB,eAAe,GACf,WAAW,GACX,QAAQ,GACR,SAAS,GACT,mBAAmB,GACnB,aAAa,GACb,eAAe,CAAC;AAEpB,eAAO,MAAM,eAAe,EAAE;IAAE,EAAE,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAQ/E,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,aAAa,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,OAAO,CAAC;IAChC,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,sBAAsB,EAAE,qBAUpC,CAAC;AAEF,kFAAk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kFAAkF;AAClF,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,0CAA0C;IAC1C,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAOzD;AAoDD,2FAA2F;AAC3F,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAS7D;AAqCD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,qBAAqB,GAC9B,MAAM,GAAG,IAAI,CAef;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,SAAS,UAAQ,GAAG,MAAM,CAWhG"}
@@ -10,17 +10,20 @@ export declare const saveInvoiceTimingSettings: import("@tanstack/start-client-c
10
10
  claims: import("@supabase/auth-js").User;
11
11
  }, undefined, undefined, undefined>], (input: unknown) => {
12
12
  enabled: boolean;
13
- anchor: "pickup_date" | "delivery_date" | "picked" | "shipped" | "confirmed" | "order_created" | "expected_delivery";
13
+ anchor: "pickup_date" | "delivery_date" | "order_created" | "confirmed" | "picked" | "shipped" | "expected_delivery";
14
14
  offsetDays: number;
15
15
  businessDaysOnly: boolean;
16
16
  timeOfDay: string;
17
- pickupAnchor: "pickup_date" | "delivery_date" | "picked" | "shipped" | "confirmed" | "order_created" | "expected_delivery";
17
+ pickupAnchor: "pickup_date" | "delivery_date" | "order_created" | "confirmed" | "picked" | "shipped" | "expected_delivery";
18
18
  pickupOffsetDays: number;
19
19
  pickupBusinessDaysOnly: boolean;
20
20
  pickupTimeOfDay: string;
21
+ invoiceWithoutSignoff?: boolean | undefined;
21
22
  }, Promise<{
22
23
  ok: true;
23
24
  recomputed: number;
25
+ released: number;
26
+ waiting: number;
24
27
  }>>;
25
28
  export declare const recomputeInvoiceDueForOrder: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
26
29
  supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
@@ -42,4 +45,15 @@ export declare const getOrderInvoiceMoment: import("@tanstack/start-client-core"
42
45
  status: any;
43
46
  settings: InvoiceTimingSettings;
44
47
  }>>;
48
+ export declare const saveInvoiceWithoutSignoff: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
49
+ supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
50
+ userId: string;
51
+ claims: import("@supabase/auth-js").User;
52
+ }, undefined, undefined, undefined>], (input: unknown) => {
53
+ value: boolean;
54
+ }, Promise<{
55
+ ok: true;
56
+ value: boolean;
57
+ released: number;
58
+ }>>;
45
59
  //# sourceMappingURL=invoice-timing.functions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoice-timing.functions.d.ts","sourceRoot":"","sources":["../../src/lib/invoice-timing.functions.ts"],"names":[],"mappings":"AAKA,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAwB1B,eAAO,MAAM,wBAAwB;;;;gFAKjC,CAAC;AAEL,eAAO,MAAM,yBAAyB;;;;8CAEZ,OAAO;;;;;;;;;;;;;GAwB7B,CAAC;AAEL,eAAO,MAAM,2BAA2B;;;;8CAEd,OAAO;;;;GAa7B,CAAC;AAEL,eAAO,MAAM,qBAAqB;;;;8CAER,OAAO;;;;;;GAkB7B,CAAC"}
1
+ {"version":3,"file":"invoice-timing.functions.d.ts","sourceRoot":"","sources":["../../src/lib/invoice-timing.functions.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAyB1B,eAAO,MAAM,wBAAwB;;;;gFAKjC,CAAC;AAEL,eAAO,MAAM,yBAAyB;;;;8CAEZ,OAAO;;;;;;;;;;;;;;;;GA2B7B,CAAC;AAEL,eAAO,MAAM,2BAA2B;;;;8CAEd,OAAO;;;;GAa7B,CAAC;AAEL,eAAO,MAAM,qBAAqB;;;;8CAER,OAAO;;;;;;GAkB7B,CAAC;AAGL,eAAO,MAAM,yBAAyB;;;;8CAEZ,OAAO;;;;;;GAoB7B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  // Server functions voor het instelbare factuurmoment.
2
2
  import { createServerFn } from "@tanstack/react-start";
3
3
  import { z } from "zod";
4
+ import { buildInvoiceWithoutSignoffPayload } from "./invoice-signoff-payload.js";
4
5
  import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
5
6
  import { resolveOrderRow, assertRowsAffected } from "./order-row.server.js";
6
7
  import { DEFAULT_INVOICE_TIMING, normalizeTimeOfDay, } from "./invoice-timing.js";
@@ -23,6 +24,7 @@ const settingsSchema = z.object({
23
24
  pickupOffsetDays: z.number().int().min(-60).max(60),
24
25
  pickupBusinessDaysOnly: z.boolean(),
25
26
  pickupTimeOfDay: z.string().min(4),
27
+ invoiceWithoutSignoff: z.boolean().optional(),
26
28
  });
27
29
  export const getInvoiceTimingSettings = createServerFn({ method: "GET" })
28
30
  .middleware([requireSupabaseAuth])
@@ -46,6 +48,7 @@ export const saveInvoiceTimingSettings = createServerFn({ method: "POST" })
46
48
  pickup_offset_days: data.pickupOffsetDays,
47
49
  pickup_business_days_only: data.pickupBusinessDaysOnly,
48
50
  pickup_time_of_day: normalizeTimeOfDay(data.pickupTimeOfDay),
51
+ ...(data.invoiceWithoutSignoff !== undefined ? { invoice_without_signoff: data.invoiceWithoutSignoff } : {}),
49
52
  };
50
53
  const { error } = await supabase.from("invoice_timing_settings").upsert(payload, {
51
54
  onConflict: "singleton",
@@ -53,9 +56,11 @@ export const saveInvoiceTimingSettings = createServerFn({ method: "POST" })
53
56
  if (error)
54
57
  throw new Error(error.message);
55
58
  // Direct doorrekenen zodat de orders het nieuwe moment tonen.
56
- const { recomputeInvoiceDueDates } = await import("./invoice-timing.server.js");
59
+ // Direct herberekenen én vrijgeven, niet wachten op de 15-minutenronde.
60
+ const { recomputeInvoiceDueDates, releaseDueInvoices } = await import("./invoice-timing.server.js");
57
61
  const { updated } = await recomputeInvoiceDueDates(supabase);
58
- return { ok: true, recomputed: updated };
62
+ const rel = await releaseDueInvoices(supabase, 200);
63
+ return { ok: true, recomputed: updated, released: rel.released, waiting: rel.waiting };
59
64
  });
60
65
  export const recomputeInvoiceDueForOrder = createServerFn({ method: "POST" })
61
66
  .middleware([requireSupabaseAuth])
@@ -92,3 +97,29 @@ export const getOrderInvoiceMoment = createServerFn({ method: "GET" })
92
97
  settings,
93
98
  };
94
99
  });
100
+ // Alleen de schakelaar "Factureren zonder afmelding"; overige velden blijven onaangeroerd.
101
+ export const saveInvoiceWithoutSignoff = createServerFn({ method: "POST" })
102
+ .middleware([requireSupabaseAuth])
103
+ .inputValidator((input) => z.object({ value: z.boolean() }).parse(input))
104
+ .handler(async ({ data, context }) => {
105
+ const supabase = context.supabase;
106
+ const table = supabase.from("invoice_timing_settings");
107
+ const { data: rows, error: updErr } = await table
108
+ .update(buildInvoiceWithoutSignoffPayload(data.value))
109
+ .eq("singleton", true)
110
+ .select("singleton");
111
+ if (updErr)
112
+ throw new Error(updErr.message);
113
+ if (!rows || rows.length === 0) {
114
+ const { error: insErr } = await supabase.from("invoice_timing_settings").insert({
115
+ singleton: true,
116
+ ...buildInvoiceWithoutSignoffPayload(data.value),
117
+ });
118
+ if (insErr)
119
+ throw new Error(insErr.message);
120
+ }
121
+ const { recomputeInvoiceDueDates, releaseDueInvoices } = await import("./invoice-timing.server.js");
122
+ await recomputeInvoiceDueDates(supabase);
123
+ const rel = await releaseDueInvoices(supabase, 200);
124
+ return { ok: true, value: data.value, released: rel.released };
125
+ });
@@ -20,7 +20,36 @@ export const DEFAULT_INVOICE_TIMING = {
20
20
  pickupOffsetDays: 0,
21
21
  pickupBusinessDaysOnly: false,
22
22
  pickupTimeOfDay: "18:00",
23
+ invoiceWithoutSignoff: false,
23
24
  };
25
+ export const INVOICE_WAIT_TEXT = "factuur wacht op levering";
26
+ export const INVOICE_NO_SIGNOFF_NOTE = "geen afmelding gevonden, gefactureerd op leverdatum";
27
+ /**
28
+ * Beslist of een order vrij mag voor facturatie. Raakt nooit de orderstatus.
29
+ * - moment niet voorbij → wachten
30
+ * - afgemeld (a, b of c) → vrijgeven
31
+ * - geen karindeling + instelling "Factureren zonder afmelding" → vrijgeven met melding
32
+ * - anders → "factuur wacht op levering"
33
+ */
34
+ export function decideInvoiceRelease(dueAt, now, signoff, invoiceWithoutSignoff) {
35
+ if (!dueAt || new Date(dueAt).getTime() > now.getTime())
36
+ return { release: false, wait: "factuurmoment nog niet bereikt" };
37
+ if (signoff.allCartsScanned || signoff.reportedOrShipped || signoff.manualDelivered)
38
+ return { release: true, note: null };
39
+ if (invoiceWithoutSignoff && signoff.hasCarts === false)
40
+ return { release: true, note: INVOICE_NO_SIGNOFF_NOTE };
41
+ return { release: false, wait: INVOICE_WAIT_TEXT };
42
+ }
43
+ /** Tekst voor lijst/detail. */
44
+ export function invoiceStateLabel(o, now = new Date()) {
45
+ if (o.invoice_ready_at) {
46
+ const d = new Date(o.invoice_ready_at);
47
+ return `klaar voor facturatie sinds ${d.toLocaleString("nl-NL", { timeZone: "Europe/Amsterdam", day: "2-digit", month: "2-digit", hour: "2-digit", minute: "2-digit" })}`;
48
+ }
49
+ if (o.invoice_due_at && new Date(o.invoice_due_at).getTime() <= now.getTime())
50
+ return INVOICE_WAIT_TEXT;
51
+ return null;
52
+ }
24
53
  export function normalizeTimeOfDay(value) {
25
54
  const s = String(value ?? "").trim();
26
55
  const m = /^(\d{1,2}):(\d{2})/.exec(s);
@@ -1,5 +1,5 @@
1
- import { type InvoiceTimingSettings } from "./invoice-timing.js";
2
- /** Status die de facturatiemodule oppakt zodra het factuurmoment is bereikt. */
1
+ import { type OrderSignoff, type InvoiceTimingSettings } from "./invoice-timing.js";
2
+ /** Oude facturatiestatus; wordt niet meer gezet (vrijgave loopt via orders.invoice_ready_at). */
3
3
  export declare const INVOICE_READY_STATUS = "Gereed voor facturatie";
4
4
  export declare function loadInvoiceTimingSettings(supabase: any): Promise<InvoiceTimingSettings>;
5
5
  /**
@@ -14,9 +14,25 @@ export declare function recomputeInvoiceDueDates(supabase: any, options?: {
14
14
  updated: number;
15
15
  checked: number;
16
16
  }>;
17
- /** Zet orders waarvan het factuurmoment is bereikt op de facturatiestatus. */
17
+ /**
18
+ * Afmeldbronnen per order (alleen lezen):
19
+ * a. logistics_control_scan (order_id, cart_id, approved_at, status) — elke kar uit de
20
+ * Engine-indeling (logistics_order_plan_coverage[_list]) moet een goedgekeurde scan hebben.
21
+ * b. order_shipments.shipped_at, of voor FO verkoop_fulfillment_index (sales_order_id, niet is_deleted).
22
+ * c. orders.status handmatig op geleverd/verzonden.
23
+ */
24
+ export declare function loadSignoffs(supabase: any, rows: {
25
+ id: string;
26
+ status: string | null;
27
+ floriday_sales_order_id: string | null;
28
+ }[]): Promise<Map<string, OrderSignoff>>;
29
+ /**
30
+ * Geeft orders vrij voor facturatie door orders.invoice_ready_at te vullen.
31
+ * Laat orders.status ONGEMOEID (de logistieke stand blijft zichtbaar).
32
+ */
18
33
  export declare function releaseDueInvoices(supabase: any, limit?: number): Promise<{
19
34
  released: number;
35
+ waiting: number;
20
36
  orderIds: string[];
21
37
  }>;
22
38
  /** Volledige cyclus: eerst herberekenen, daarna vrijgeven. */
@@ -1 +1 @@
1
- {"version":3,"file":"invoice-timing.server.d.ts","sourceRoot":"","sources":["../../src/lib/invoice-timing.server.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAE1B,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,2BAA2B,CAAC;AAE7D,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAkB7F;AA6ED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,GAAG,EACb,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GACpC,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAmD/C;AAED,8EAA8E;AAC9E,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,GAAG,EACb,KAAK,SAAM,GACV,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAgCnD;AAED,8DAA8D;AAC9D,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CAMD"}
1
+ {"version":3,"file":"invoice-timing.server.d.ts","sourceRoot":"","sources":["../../src/lib/invoice-timing.server.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,YAAY,EAIjB,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAE1B,iGAAiG;AACjG,eAAO,MAAM,oBAAoB,2BAA2B,CAAC;AAE7D,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAmB7F;AA6ED;;;;;GAKG;AACH,wBAAsB,w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