@flowselections/floriday-verkoop-module 1.0.132 → 1.0.133
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/components/verkoop/CreateOrderPage.d.ts.map +1 -1
- package/dist-lib/components/verkoop/CreateOrderPage.js +4 -1
- package/dist-lib/components/verkoop/InvoiceSignoffSettings.d.ts +2 -0
- package/dist-lib/components/verkoop/InvoiceSignoffSettings.d.ts.map +1 -0
- package/dist-lib/components/verkoop/InvoiceSignoffSettings.js +31 -0
- package/dist-lib/components/verkoop/SalesOrderDetailView.js +1 -1
- package/dist-lib/components/verkoop/SalesOrdersTable.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrdersTable.js +1 -1
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +2 -0
- package/dist-lib/integrations/supabase/types.d.ts +18 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/delivery-location.server.d.ts.map +1 -1
- package/dist-lib/lib/delivery-location.server.js +56 -13
- package/dist-lib/lib/invoice-release.check.d.ts +2 -0
- package/dist-lib/lib/invoice-release.check.d.ts.map +1 -0
- package/dist-lib/lib/invoice-release.check.js +21 -0
- package/dist-lib/lib/invoice-signoff-payload.check.d.ts +2 -0
- package/dist-lib/lib/invoice-signoff-payload.check.d.ts.map +1 -0
- package/dist-lib/lib/invoice-signoff-payload.check.js +27 -0
- package/dist-lib/lib/invoice-signoff-payload.d.ts +4 -0
- package/dist-lib/lib/invoice-signoff-payload.d.ts.map +1 -0
- package/dist-lib/lib/invoice-signoff-payload.js +5 -0
- package/dist-lib/lib/invoice-timing.d.ts +35 -0
- package/dist-lib/lib/invoice-timing.d.ts.map +1 -1
- package/dist-lib/lib/invoice-timing.functions.d.ts +16 -2
- package/dist-lib/lib/invoice-timing.functions.d.ts.map +1 -1
- package/dist-lib/lib/invoice-timing.functions.js +33 -2
- package/dist-lib/lib/invoice-timing.js +29 -0
- package/dist-lib/lib/invoice-timing.server.d.ts +19 -3
- package/dist-lib/lib/invoice-timing.server.d.ts.map +1 -1
- package/dist-lib/lib/invoice-timing.server.js +75 -11
- package/dist-lib/lib/module-version.d.ts +1 -1
- package/dist-lib/lib/module-version.js +1 -1
- package/dist-lib/lib/plan-coverage-v204.check.js +2 -0
- package/dist-lib/lib/plan-coverage.d.ts +9 -2
- package/dist-lib/lib/plan-coverage.d.ts.map +1 -1
- package/dist-lib/lib/plan-coverage.js +15 -3
- package/dist-lib/lib/product-oordeel.d.ts +12 -0
- package/dist-lib/lib/product-oordeel.d.ts.map +1 -0
- package/dist-lib/lib/product-oordeel.js +24 -0
- package/dist-lib/lib/product-plannable.functions.d.ts +2 -0
- package/dist-lib/lib/product-plannable.functions.d.ts.map +1 -1
- package/dist-lib/lib/product-plannable.functions.js +15 -9
- package/dist-lib/lib/salesorders-list.functions.d.ts +1 -1
- package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.server.js +6 -1
- package/dist-lib/lib/salesorders-mapping.d.ts +4 -0
- package/dist-lib/lib/salesorders-mapping.d.ts.map +1 -1
- package/dist-lib/lib/salesorders.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders.functions.js +4 -1
- package/package.json +1 -1
- 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,mB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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
|
|
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.
|
|
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
|
|
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,
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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"}
|
|
@@ -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,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,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" | "
|
|
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" | "
|
|
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":"
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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,
|
|
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,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,CAoD/C;AAID;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,GAAG,EACb,IAAI,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAAE,GACpF,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAqCpC;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,GAAG,EACb,KAAK,SAAM,GACV,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAyCpE;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,6 +1,6 @@
|
|
|
1
1
|
// Server-side toepassing van het instelbare factuurmoment.
|
|
2
|
-
import { DEFAULT_INVOICE_TIMING, computeInvoiceDueAt, normalizeTimeOfDay, } from "./invoice-timing.js";
|
|
3
|
-
/**
|
|
2
|
+
import { DEFAULT_INVOICE_TIMING, computeInvoiceDueAt, decideInvoiceRelease, normalizeTimeOfDay, } from "./invoice-timing.js";
|
|
3
|
+
/** Oude facturatiestatus; wordt niet meer gezet (vrijgave loopt via orders.invoice_ready_at). */
|
|
4
4
|
export const INVOICE_READY_STATUS = "Gereed voor facturatie";
|
|
5
5
|
export async function loadInvoiceTimingSettings(supabase) {
|
|
6
6
|
const { data } = await supabase
|
|
@@ -20,6 +20,7 @@ export async function loadInvoiceTimingSettings(supabase) {
|
|
|
20
20
|
pickupOffsetDays: Number(data.pickup_offset_days ?? 0),
|
|
21
21
|
pickupBusinessDaysOnly: !!data.pickup_business_days_only,
|
|
22
22
|
pickupTimeOfDay: normalizeTimeOfDay(data.pickup_time_of_day),
|
|
23
|
+
invoiceWithoutSignoff: data.invoice_without_signoff === true,
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
function isSelfPickup(customFields) {
|
|
@@ -115,6 +116,7 @@ export async function recomputeInvoiceDueDates(supabase, options = {}) {
|
|
|
115
116
|
else {
|
|
116
117
|
query = query
|
|
117
118
|
.is("cancelled_at", null)
|
|
119
|
+
.is("invoice_ready_at", null)
|
|
118
120
|
.not("status", "in", `(${INVOICED_STATUSES.map((s) => `"${s}"`).join(",")})`)
|
|
119
121
|
.order("id", { ascending: true })
|
|
120
122
|
.limit(CHUNK);
|
|
@@ -150,37 +152,99 @@ export async function recomputeInvoiceDueDates(supabase, options = {}) {
|
|
|
150
152
|
}
|
|
151
153
|
return { updated, checked };
|
|
152
154
|
}
|
|
153
|
-
|
|
155
|
+
const MANUAL_DELIVERED = ["geleverd", "delivered", "verzonden", "shipped"];
|
|
156
|
+
/**
|
|
157
|
+
* Afmeldbronnen per order (alleen lezen):
|
|
158
|
+
* a. logistics_control_scan (order_id, cart_id, approved_at, status) — elke kar uit de
|
|
159
|
+
* Engine-indeling (logistics_order_plan_coverage[_list]) moet een goedgekeurde scan hebben.
|
|
160
|
+
* b. order_shipments.shipped_at, of voor FO verkoop_fulfillment_index (sales_order_id, niet is_deleted).
|
|
161
|
+
* c. orders.status handmatig op geleverd/verzonden.
|
|
162
|
+
*/
|
|
163
|
+
export async function loadSignoffs(supabase, rows) {
|
|
164
|
+
const ids = rows.map((r) => String(r.id));
|
|
165
|
+
const out = new Map();
|
|
166
|
+
if (!ids.length)
|
|
167
|
+
return out;
|
|
168
|
+
const sids = rows.map((r) => r.floriday_sales_order_id).filter(Boolean);
|
|
169
|
+
const [scans, ships, fi] = await Promise.all([
|
|
170
|
+
supabase.from("logistics_control_scan").select("order_id, cart_id, approved_at, status").in("order_id", ids),
|
|
171
|
+
supabase.from("order_shipments").select("order_id, shipped_at").in("order_id", ids).not("shipped_at", "is", null),
|
|
172
|
+
sids.length
|
|
173
|
+
? supabase.from("verkoop_fulfillment_index").select("sales_order_id").in("sales_order_id", sids).eq("is_deleted", false)
|
|
174
|
+
: Promise.resolve({ data: [] }),
|
|
175
|
+
]);
|
|
176
|
+
const { loadPlanCoverage } = await import("./plan-coverage.server.js");
|
|
177
|
+
const coverage = await loadPlanCoverage(supabase, ids, "list");
|
|
178
|
+
const approvedCarts = new Map();
|
|
179
|
+
for (const s of (scans.data ?? [])) {
|
|
180
|
+
if (!s.approved_at || s.status === "geannuleerd" || !s.cart_id)
|
|
181
|
+
continue;
|
|
182
|
+
const k = String(s.order_id);
|
|
183
|
+
if (!approvedCarts.has(k))
|
|
184
|
+
approvedCarts.set(k, new Set());
|
|
185
|
+
approvedCarts.get(k).add(String(s.cart_id));
|
|
186
|
+
}
|
|
187
|
+
const shipped = new Set((ships.data ?? []).map((x) => String(x.order_id)));
|
|
188
|
+
const reported = new Set((fi.data ?? []).map((x) => String(x.sales_order_id)));
|
|
189
|
+
for (const r of rows) {
|
|
190
|
+
const id = String(r.id);
|
|
191
|
+
const cov = coverage.get(id);
|
|
192
|
+
const known = !!cov && cov.state !== "onbekend";
|
|
193
|
+
const carts = known ? cov.carts.map((c) => c.cartId) : [];
|
|
194
|
+
const appr = approvedCarts.get(id) ?? new Set();
|
|
195
|
+
out.set(id, {
|
|
196
|
+
allCartsScanned: carts.length > 0 && carts.every((c) => appr.has(c)),
|
|
197
|
+
reportedOrShipped: shipped.has(id) || (!!r.floriday_sales_order_id && reported.has(r.floriday_sales_order_id)),
|
|
198
|
+
manualDelivered: MANUAL_DELIVERED.includes(String(r.status ?? "").trim().toLowerCase()),
|
|
199
|
+
hasCarts: known ? carts.length > 0 : null,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Geeft orders vrij voor facturatie door orders.invoice_ready_at te vullen.
|
|
206
|
+
* Laat orders.status ONGEMOEID (de logistieke stand blijft zichtbaar).
|
|
207
|
+
*/
|
|
154
208
|
export async function releaseDueInvoices(supabase, limit = 200) {
|
|
155
209
|
const settings = await loadInvoiceTimingSettings(supabase);
|
|
156
210
|
if (!settings.enabled)
|
|
157
|
-
return { released: 0, orderIds: [] };
|
|
211
|
+
return { released: 0, waiting: 0, orderIds: [] };
|
|
212
|
+
const now = new Date();
|
|
158
213
|
const { data, error } = await supabase
|
|
159
214
|
.from("orders")
|
|
160
|
-
.select("id, status, order_source, floriday_sales_order_id")
|
|
215
|
+
.select("id, status, order_source, floriday_sales_order_id, invoice_due_at")
|
|
161
216
|
.is("deleted_at", null)
|
|
162
217
|
.is("cancelled_at", null)
|
|
218
|
+
.is("invoice_ready_at", null)
|
|
163
219
|
.not("invoice_due_at", "is", null)
|
|
164
|
-
.lte("invoice_due_at",
|
|
165
|
-
.neq("status", INVOICE_READY_STATUS)
|
|
220
|
+
.lte("invoice_due_at", now.toISOString())
|
|
166
221
|
.limit(limit);
|
|
167
222
|
if (error)
|
|
168
223
|
throw new Error(error.message);
|
|
169
224
|
const rows = (data ?? []).filter((r) => !r.floriday_sales_order_id &&
|
|
170
225
|
String(r.order_source ?? "").toLowerCase() !== "floriday");
|
|
226
|
+
const signoffs = await loadSignoffs(supabase, rows);
|
|
171
227
|
const orderIds = [];
|
|
228
|
+
let waiting = 0;
|
|
172
229
|
for (const r of rows) {
|
|
173
|
-
|
|
230
|
+
const so = signoffs.get(String(r.id));
|
|
231
|
+
if (!so)
|
|
232
|
+
continue;
|
|
233
|
+
const d = decideInvoiceRelease(r.invoice_due_at, now, so, !!settings.invoiceWithoutSignoff);
|
|
234
|
+
if (!d.release) {
|
|
235
|
+
waiting++;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
174
238
|
const { data: done, error: upErr } = await supabase
|
|
175
239
|
.from("orders")
|
|
176
|
-
.update({
|
|
240
|
+
.update({ invoice_ready_at: now.toISOString(), invoice_ready_note: d.note })
|
|
177
241
|
.eq("id", r.id)
|
|
178
|
-
.
|
|
242
|
+
.is("invoice_ready_at", null)
|
|
179
243
|
.select("id");
|
|
180
244
|
if (!upErr && (done ?? []).length > 0)
|
|
181
245
|
orderIds.push(String(r.id));
|
|
182
246
|
}
|
|
183
|
-
return { released: orderIds.length, orderIds };
|
|
247
|
+
return { released: orderIds.length, waiting, orderIds };
|
|
184
248
|
}
|
|
185
249
|
/** Volledige cyclus: eerst herberekenen, daarna vrijgeven. */
|
|
186
250
|
export async function runInvoiceTimingCycle() {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const MODULE_VERSION = "1.0.
|
|
1
|
+
export declare const MODULE_VERSION = "1.0.134";
|
|
2
2
|
//# sourceMappingURL=module-version.d.ts.map
|
|
@@ -16,6 +16,8 @@ eq("layersUsed", c.lagen, 6.6);
|
|
|
16
16
|
eq("vulgraadPct", c.vulgraad, 83);
|
|
17
17
|
eq("bron", c.capaciteitBron, "product");
|
|
18
18
|
eq("tekst", cartSummary(c), "Deense container + 6 platen · 6,6 van 8 lagen (capaciteit van het product) · 83 %");
|
|
19
|
+
eq("geen dubbele tekst", cartSummary({ ...c, ladingdragerTekst: "Deense container + 6 platen (6,6 lagen, 83 %)" }), "Deense container + 6 platen · 6,6 van 8 lagen (capaciteit van het product) · 83 %");
|
|
20
|
+
eq("karTekst voorrang", cartSummary(parsePlanCoverage({ state: "ingedeeld", carts: [{ cartId: "k", karTekst: "7 lagen · DC + 6 platen · 86 %", maxLayers: 8, vulgraadPct: 86 }] }).carts[0]), "7 lagen · DC + 6 platen · 86 %");
|
|
19
21
|
eq("onbekende bron", parsePlanCoverage({ state: "ingedeeld", carts: [{ cartId: "k", capaciteitBron: "anders" }] }).carts[0].capaciteitBron, null);
|
|
20
22
|
eq("oude naam genegeerd", parsePlanCoverage({ state: "ingedeeld", carts: [{ cartId: "k", capaciteit: 5 }] }).carts[0].capaciteit, null);
|
|
21
23
|
eq("regels", cov.geenIndeling?.regels, ["a", "b"]);
|
|
@@ -24,6 +24,8 @@ export interface PlanCoverageCart {
|
|
|
24
24
|
additionalLayers: number | null;
|
|
25
25
|
/** Leesbare ladingdrager-tekst van de Engine (1.0.201+), bv. "Deense container + 1 plaat (2 lagen, 20 %)". */
|
|
26
26
|
ladingdragerTekst: string | null;
|
|
27
|
+
/** Volledige karregel van de Engine (carts[].karTekst); voorrang boven samengestelde tekst. */
|
|
28
|
+
karTekst: string | null;
|
|
27
29
|
/** Kar te hoog volgens de Engine (1.0.201+); null = niet geleverd. */
|
|
28
30
|
teHoog: boolean | null;
|
|
29
31
|
/** Blokkade op deze kar volgens de Engine (1.0.201+). */
|
|
@@ -105,8 +107,13 @@ export interface IndelingVerouderd {
|
|
|
105
107
|
}
|
|
106
108
|
/** Leest indelingVerouderd: null | { verouderd, producten[], vastliggendeKarren, tekst } (Engine 1.0.204). */
|
|
107
109
|
export declare function parseIndelingVerouderd(v: unknown): IndelingVerouderd | null;
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Eén karregel. Voorkeur: karTekst van de Engine. Anders samengesteld, maar lagen/% niet
|
|
112
|
+
* herhalen als ladingdragerTekst die al bevat (gaf dubbele tekst).
|
|
113
|
+
*/
|
|
114
|
+
export declare function cartSummary(c: Pick<PlanCoverageCart, "ladingdragerTekst" | "capaciteit" | "lagen" | "capaciteitBron" | "vulgraad"> & {
|
|
115
|
+
karTekst?: string | null;
|
|
116
|
+
}): string;
|
|
110
117
|
/** Lijst met korte tekstregels; alles anders genegeerd. */
|
|
111
118
|
export declare function parseRegels(v: unknown): string[];
|
|
112
119
|
/** Alleen interne paden binnen de shell; volledige adressen of "//host" worden genegeerd. */
|