@flowselections/floriday-verkoop-module 1.0.130 → 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 +25 -4
- package/dist-lib/components/verkoop/EngineActieButtons.d.ts +7 -0
- package/dist-lib/components/verkoop/EngineActieButtons.d.ts.map +1 -0
- package/dist-lib/components/verkoop/EngineActieButtons.js +22 -0
- package/dist-lib/components/verkoop/FloridayStageLine.d.ts +3 -1
- package/dist-lib/components/verkoop/FloridayStageLine.d.ts.map +1 -1
- package/dist-lib/components/verkoop/FloridayStageLine.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/OrderKarindelingCard.d.ts +4 -0
- package/dist-lib/components/verkoop/OrderKarindelingCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderKarindelingCard.js +17 -1
- package/dist-lib/components/verkoop/OrderLinePackingCard.d.ts.map +1 -1
- package/dist-lib/components/verkoop/OrderLinePackingCard.js +22 -5
- package/dist-lib/components/verkoop/SalesOrderDetailPage.js +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailView.d.ts +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailView.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailView.js +25 -2
- package/dist-lib/components/verkoop/SalesOrdersTable.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrdersTable.js +24 -2
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +2 -0
- package/dist-lib/integrations/supabase/types.d.ts +326 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/delivery-location.check.js +2 -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/floriday-line-key.check.js +19 -0
- package/dist-lib/lib/floriday-line-key.d.ts +20 -0
- package/dist-lib/lib/floriday-line-key.d.ts.map +1 -1
- package/dist-lib/lib/floriday-line-key.js +24 -0
- package/dist-lib/lib/floriday-mirror.server.d.ts.map +1 -1
- package/dist-lib/lib/floriday-mirror.server.js +50 -4
- package/dist-lib/lib/floriday-status.server.d.ts +1 -1
- package/dist-lib/lib/floriday-status.server.d.ts.map +1 -1
- package/dist-lib/lib/floriday-status.server.js +3 -3
- 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/order-fust.check.d.ts +2 -0
- package/dist-lib/lib/order-fust.check.d.ts.map +1 -0
- package/dist-lib/lib/order-fust.check.js +19 -0
- package/dist-lib/lib/order-fust.d.ts +19 -0
- package/dist-lib/lib/order-fust.d.ts.map +1 -0
- package/dist-lib/lib/order-fust.js +21 -0
- package/dist-lib/lib/order-item-packing.functions.d.ts +22 -0
- package/dist-lib/lib/order-item-packing.functions.d.ts.map +1 -1
- package/dist-lib/lib/order-item-packing.functions.js +29 -1
- package/dist-lib/lib/plan-coverage-v204.check.d.ts +2 -0
- package/dist-lib/lib/plan-coverage-v204.check.d.ts.map +1 -0
- package/dist-lib/lib/plan-coverage-v204.check.js +29 -0
- package/dist-lib/lib/plan-coverage.d.ts +37 -0
- package/dist-lib/lib/plan-coverage.d.ts.map +1 -1
- package/dist-lib/lib/plan-coverage.js +69 -1
- 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 +12 -0
- package/dist-lib/lib/product-plannable.functions.d.ts.map +1 -1
- package/dist-lib/lib/product-plannable.functions.js +66 -4
- package/dist-lib/lib/salesorders-list.functions.d.ts +18 -1
- package/dist-lib/lib/salesorders-list.functions.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.functions.js +23 -0
- package/dist-lib/lib/salesorders-list.server.d.ts +2 -0
- package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.server.js +46 -12
- package/dist-lib/lib/salesorders-mapping.d.ts +10 -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 +8 -9
- package/dist-lib/lib/useEngineMelding.d.ts +9 -0
- package/dist-lib/lib/useEngineMelding.d.ts.map +1 -0
- package/dist-lib/lib/useEngineMelding.js +20 -0
- package/package.json +1 -1
- package/schema/verkoop.sql +18 -2
|
@@ -19,7 +19,8 @@ eq("FO-2601460: GLN → Floriday-locatie van de koper", deliveryLocationLabel(pi
|
|
|
19
19
|
eq("adres in de Floriday-levering gaat voor", pickDeliveryLocation(ref({ gln: "8713783885413", floridayAddress: { addressLine: "Elders 1", city: "Rijsenhout" } }), fl, klant)?.source, "floriday_levering");
|
|
20
20
|
eq("geen Floriday-locatie → klantlocatie", pickDeliveryLocation(ref({ gln: "8713783885413" }), [], klant)?.source, "klantlocatie");
|
|
21
21
|
eq("geen afleverlocatie → niets (scherm toont klantadres)", pickDeliveryLocation(ref({}), fl, klant), null);
|
|
22
|
-
eq("geenIndeling gelezen (1.0.201)", parseGeenIndeling({ code: "LD01", soort: "belading", tekst: "Past niet", actie: "belading_aanpassen", actieLabel: "Belading aanpassen", actieUrl: "/x" }), { code: "LD01", soort: "belading", tekst: "Past niet", actie: "belading_aanpassen", actieLabel: "Belading aanpassen", actieUrl: "/x" });
|
|
22
|
+
eq("geenIndeling gelezen (1.0.201)", parseGeenIndeling({ code: "LD01", soort: "belading", tekst: "Past niet", actie: "belading_aanpassen", actieLabel: "Belading aanpassen", actieUrl: "/x" }), { code: "LD01", soort: "belading", tekst: "Past niet", actie: "belading_aanpassen", actieLabel: "Belading aanpassen", actieUrl: "/x", regels: [] });
|
|
23
|
+
eq("geenIndeling.regels als lijst", parseGeenIndeling({ code: "LD02", regels: ["Fust te hoog", " ", "Laag te vol"] })?.regels, ["Fust te hoog", "Laag te vol"]);
|
|
23
24
|
eq("actieUrl buiten de shell genegeerd", parseGeenIndeling({ code: "X", actieUrl: "https://elders.example/x" })?.actieUrl, null);
|
|
24
25
|
eq("actieUrl //host genegeerd", parseGeenIndeling({ code: "X", actieUrl: "//elders/x" })?.actieUrl, null);
|
|
25
26
|
eq("blokkade op kar → Ingedeeld met blokkade", labelWithBlokkade("ingedeeld", "Ingedeeld", true), "Ingedeeld met blokkade");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delivery-location.server.d.ts","sourceRoot":"","sources":["../../src/lib/delivery-location.server.ts"],"names":[],"mappings":"AAMA,MAAM,W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B,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
|
|
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);
|
|
@@ -29,3 +29,22 @@ if (fail) {
|
|
|
29
29
|
process.exit(1);
|
|
30
30
|
}
|
|
31
31
|
console.log("Alle controles geslaagd");
|
|
32
|
+
// Vangnet sleutelloze regels (bun src/lib/floriday-line-key.check.ts)
|
|
33
|
+
{
|
|
34
|
+
const { adoptUnkeyedLines } = await import("./floriday-line-key.js");
|
|
35
|
+
const fail = (m) => { throw new Error(m); };
|
|
36
|
+
const n = [{ foId: "a", productId: "p1", quantity: 48 }];
|
|
37
|
+
const one = adoptUnkeyedLines(n, [{ id: "u1", product_id: "p1", quantity: 48 }]);
|
|
38
|
+
if (one.adopt.get("a")?.id !== "u1" || one.doubt.size)
|
|
39
|
+
fail("precies één match moet worden overgenomen");
|
|
40
|
+
const none = adoptUnkeyedLines(n, [{ id: "u1", product_id: "p1", quantity: 47 }]);
|
|
41
|
+
if (none.adopt.size || none.doubt.size)
|
|
42
|
+
fail("ander aantal mag niet worden overgenomen");
|
|
43
|
+
const two = adoptUnkeyedLines(n, [{ id: "u1", product_id: "p1", quantity: 48 }, { id: "u2", product_id: "p1", quantity: 48 }]);
|
|
44
|
+
if (two.adopt.size || two.doubt.get("a")?.length !== 2)
|
|
45
|
+
fail("twee matches = twijfel, niets overnemen");
|
|
46
|
+
const once = adoptUnkeyedLines([...n, { foId: "b", productId: "p1", quantity: 48 }], [{ id: "u1", product_id: "p1", quantity: 48 }]);
|
|
47
|
+
if (once.adopt.size !== 1 || once.adopt.get("a")?.id !== "u1")
|
|
48
|
+
fail("sleutelloze regel hooguit één keer toewijzen");
|
|
49
|
+
console.log("vangnet sleutelloze regels: ok");
|
|
50
|
+
}
|
|
@@ -9,4 +9,24 @@ export declare function splitByLineKey<T extends {
|
|
|
9
9
|
};
|
|
10
10
|
/** Idempotentiesleutel voor de melding "Afgehandeld in Floriday" (id's gesorteerd). */
|
|
11
11
|
export declare function externalFulfilledIdempotencyKey(orderId: string, salesOrderIds: string[]): string;
|
|
12
|
+
/**
|
|
13
|
+
* Vangnet voor regels zonder herkomstsleutel (restant van de oude overname die
|
|
14
|
+
* wiste en opnieuw toevoegde zonder source_line_key). Per nieuwe Floriday-regel:
|
|
15
|
+
* precies één sleutelloze regel met hetzelfde product én aantal → overnemen
|
|
16
|
+
* (sleutel invullen) in plaats van een tweede regel ernaast. Meerdere kandidaten
|
|
17
|
+
* → "twijfel": niets schrijven, wel loggen. Geen kandidaat → gewoon nieuw.
|
|
18
|
+
* Een sleutelloze regel wordt hooguit één keer toegewezen.
|
|
19
|
+
*/
|
|
20
|
+
export declare function adoptUnkeyedLines<N extends {
|
|
21
|
+
foId: string;
|
|
22
|
+
productId: string | null;
|
|
23
|
+
quantity: number;
|
|
24
|
+
}, U extends {
|
|
25
|
+
id: string;
|
|
26
|
+
product_id: string | null;
|
|
27
|
+
quantity: number | null;
|
|
28
|
+
}>(newLines: N[], unkeyed: U[]): {
|
|
29
|
+
adopt: Map<string, U>;
|
|
30
|
+
doubt: Map<string, U[]>;
|
|
31
|
+
};
|
|
12
32
|
//# sourceMappingURL=floriday-line-key.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floriday-line-key.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-line-key.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,uBAAuB,mFAC8C,CAAC;AAEnF,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAE3D;AAED,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG;IAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAAC,OAAO,EAAE,CAAC,EAAE,CAAA;CAAE,CAKpG;AAED,uFAAuF;AACvF,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,CAEhG"}
|
|
1
|
+
{"version":3,"file":"floriday-line-key.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-line-key.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,uBAAuB,mFAC8C,CAAC;AAEnF,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAE3D;AAED,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG;IAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAAC,OAAO,EAAE,CAAC,EAAE,CAAA;CAAE,CAKpG;AAED,uFAAuF;AACvF,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,CAEhG;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EACtE,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAC5E,QAAQ,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG;IAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAA;CAAE,CAgBjF"}
|
|
@@ -18,3 +18,27 @@ export function splitByLineKey(lines) {
|
|
|
18
18
|
export function externalFulfilledIdempotencyKey(orderId, salesOrderIds) {
|
|
19
19
|
return `extern-afgehandeld:${orderId}:${[...new Set(salesOrderIds)].sort().join(",")}`;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Vangnet voor regels zonder herkomstsleutel (restant van de oude overname die
|
|
23
|
+
* wiste en opnieuw toevoegde zonder source_line_key). Per nieuwe Floriday-regel:
|
|
24
|
+
* precies één sleutelloze regel met hetzelfde product én aantal → overnemen
|
|
25
|
+
* (sleutel invullen) in plaats van een tweede regel ernaast. Meerdere kandidaten
|
|
26
|
+
* → "twijfel": niets schrijven, wel loggen. Geen kandidaat → gewoon nieuw.
|
|
27
|
+
* Een sleutelloze regel wordt hooguit één keer toegewezen.
|
|
28
|
+
*/
|
|
29
|
+
export function adoptUnkeyedLines(newLines, unkeyed) {
|
|
30
|
+
const adopt = new Map();
|
|
31
|
+
const doubt = new Map();
|
|
32
|
+
const used = new Set();
|
|
33
|
+
const match = (n) => unkeyed.filter((u) => !used.has(u.id) && String(u.product_id ?? "") === String(n.productId ?? "") && Number(u.quantity ?? NaN) === Number(n.quantity));
|
|
34
|
+
for (const n of newLines) {
|
|
35
|
+
const c = match(n);
|
|
36
|
+
if (c.length === 1) {
|
|
37
|
+
adopt.set(n.foId, c[0]);
|
|
38
|
+
used.add(c[0].id);
|
|
39
|
+
}
|
|
40
|
+
else if (c.length > 1)
|
|
41
|
+
doubt.set(n.foId, c);
|
|
42
|
+
}
|
|
43
|
+
return { adopt, doubt };
|
|
44
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floriday-mirror.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-mirror.server.ts"],"names":[],"mappings":"AAuKA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,0DAA0D;IAC1D,OAAO,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IACnD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"floriday-mirror.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-mirror.server.ts"],"names":[],"mappings":"AAuKA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,0DAA0D;IAC1D,OAAO,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IACnD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AA08CD,eAAO,MAAM,oBAAoB,MAAgB,CAAC;AAElD,wBAAsB,4BAA4B,CAAC,KAAK,SAAgB,EAAE,KAAK,GAAE,MAAM,GAAG,IAAW,yBAEpG;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,yBAI5D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { diffBuyerChanges } from "./floriday-change-diff.js";
|
|
2
|
-
import { MISSING_LINE_KEY_NOTICE, splitByLineKey } from "./floriday-line-key.js";
|
|
2
|
+
import { MISSING_LINE_KEY_NOTICE, adoptUnkeyedLines, splitByLineKey } from "./floriday-line-key.js";
|
|
3
3
|
import { keepOrSetCustomer, promoteCustomers } from "./floriday-promote-customer.js";
|
|
4
4
|
import { fillOnlyEmpty, snapshotFromFloridayOrder } from "./packing-snapshot.js";
|
|
5
5
|
// Spiegelt Floriday-verkooporders (FO's) uit `floriday_salesorders_cache`
|
|
@@ -1174,21 +1174,67 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
1174
1174
|
// het Floriday-artikel — dat loopt uitsluitend via de voorraad-module.
|
|
1175
1175
|
const lockedByKey = new Map();
|
|
1176
1176
|
const existingLineByKey = new Map();
|
|
1177
|
+
const unkeyedRows = [];
|
|
1177
1178
|
{
|
|
1178
1179
|
const { data: itemRows, error: lockErr } = await supabaseAdmin.from("order_items")
|
|
1179
|
-
.select("source_line_key, product_id, product_name, quantity, unit, unit_price, plants_per_crate, crates_per_layer, layers_per_cart, vbn_package_code, load_carrier_type, packing_source, packing_locked_at")
|
|
1180
|
+
.select("id, source_line_key, product_id, product_name, quantity, unit, unit_price, plants_per_crate, crates_per_layer, layers_per_cart, vbn_package_code, load_carrier_type, packing_source, packing_locked_at, quarantined_at")
|
|
1180
1181
|
.eq("order_id", orderId);
|
|
1181
1182
|
if (lockErr)
|
|
1182
1183
|
throw new Error(`bestaande orderregels lezen: ${lockErr.message}`);
|
|
1183
1184
|
for (const r of (itemRows ?? [])) {
|
|
1184
1185
|
const k = String(r.source_line_key ?? "");
|
|
1185
|
-
if (!k)
|
|
1186
|
+
if (!k) {
|
|
1187
|
+
if (!r.quarantined_at)
|
|
1188
|
+
unkeyedRows.push(r);
|
|
1186
1189
|
continue;
|
|
1190
|
+
}
|
|
1187
1191
|
existingLineByKey.set(k, r);
|
|
1188
1192
|
if (r.packing_locked_at)
|
|
1189
1193
|
lockedByKey.set(k, r);
|
|
1190
1194
|
}
|
|
1191
1195
|
}
|
|
1196
|
+
// Vangnet: een regel zonder sleutel (oude overname) met precies hetzelfde
|
|
1197
|
+
// product en aantal wordt overgenomen (sleutel invullen) in plaats van er
|
|
1198
|
+
// een tweede regel naast te zetten. Twijfel (meerdere kandidaten): niets
|
|
1199
|
+
// schrijven voor die Floriday-regel, wel een logregel.
|
|
1200
|
+
const doubtFoIds = new Set();
|
|
1201
|
+
if (unkeyedRows.length > 0) {
|
|
1202
|
+
const fresh = splitByLineKey(group)
|
|
1203
|
+
.valid.filter((l) => !existingLineByKey.has(l.foId))
|
|
1204
|
+
.map((l) => ({ foId: l.foId, productId: l.productId ?? null, quantity: Math.max(0, l.numberOfPieces) }));
|
|
1205
|
+
const { adopt, doubt } = adoptUnkeyedLines(fresh, unkeyedRows);
|
|
1206
|
+
for (const [foId, u] of adopt) {
|
|
1207
|
+
const { data: upd, error: adErr } = await supabaseAdmin.from("order_items")
|
|
1208
|
+
.update({ source_line_key: foId })
|
|
1209
|
+
.eq("id", u.id)
|
|
1210
|
+
.is("source_line_key", null)
|
|
1211
|
+
.select("id");
|
|
1212
|
+
if (adErr)
|
|
1213
|
+
throw new Error(`regel zonder sleutel overnemen: ${adErr.message}`);
|
|
1214
|
+
if (!upd?.length)
|
|
1215
|
+
continue;
|
|
1216
|
+
existingLineByKey.set(foId, { ...u, source_line_key: foId });
|
|
1217
|
+
if (u.packing_locked_at)
|
|
1218
|
+
lockedByKey.set(foId, { ...u, source_line_key: foId });
|
|
1219
|
+
await supabaseAdmin.from("floriday_merge_log").insert({
|
|
1220
|
+
action: "line_key_adopted",
|
|
1221
|
+
kept_order_id: orderId,
|
|
1222
|
+
floriday_sales_order_ids: [foId],
|
|
1223
|
+
lines: [{ id: u.id, product_id: u.product_id, quantity: u.quantity }],
|
|
1224
|
+
reason: "Regel zonder Floriday-koppeling overgenomen (zelfde product en aantal)",
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
for (const [foId, cands] of doubt) {
|
|
1228
|
+
doubtFoIds.add(foId);
|
|
1229
|
+
await supabaseAdmin.from("floriday_merge_log").insert({
|
|
1230
|
+
action: "line_key_doubt",
|
|
1231
|
+
kept_order_id: orderId,
|
|
1232
|
+
floriday_sales_order_ids: [foId],
|
|
1233
|
+
lines: cands.map((u) => ({ id: u.id, product_id: u.product_id, quantity: u.quantity })),
|
|
1234
|
+
reason: "Meerdere regels zonder koppeling passen; niets geschreven, handmatig beoordelen",
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1192
1238
|
// Eén orderregel per Floriday-verkooporder in deze groep. Bijwerken op
|
|
1193
1239
|
// een vaste herkomstsleutel (source_line_key = Floriday sales order id),
|
|
1194
1240
|
// nooit meer wissen-en-opnieuw-toevoegen: dat veroorzaakte duplicaten
|
|
@@ -1199,7 +1245,7 @@ async function mirrorUnlocked(limit, since, onlyIds = null) {
|
|
|
1199
1245
|
// sales order; een bestaande regel houdt zijn verpakking. Alleen een
|
|
1200
1246
|
// leeg veld wordt aangevuld met een echte waarde (bijv. klokorder
|
|
1201
1247
|
// waarvan de Engine/Floriday later lagen meldt). Nooit overschrijven.
|
|
1202
|
-
const lineRows = splitByLineKey(group).valid.map((l) => {
|
|
1248
|
+
const lineRows = splitByLineKey(group).valid.filter((l) => !doubtFoIds.has(l.foId)).map((l) => {
|
|
1203
1249
|
const locked = lockedByKey.get(l.foId);
|
|
1204
1250
|
const prev = existingLineByKey.get(l.foId);
|
|
1205
1251
|
// Regels van vóór 1.0.105 (geen packing_source) blijven helemaal
|
|
@@ -3,5 +3,5 @@ export interface FloridayStatusResult {
|
|
|
3
3
|
entries: Map<string, FloridayStatusEntry>;
|
|
4
4
|
error: string | null;
|
|
5
5
|
}
|
|
6
|
-
export declare function loadFloridayStatuses(salesOrderIds: string[]): Promise<FloridayStatusResult>;
|
|
6
|
+
export declare function loadFloridayStatuses(salesOrderIds: string[], timeoutMs?: number): Promise<FloridayStatusResult>;
|
|
7
7
|
//# sourceMappingURL=floriday-status.server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floriday-status.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-status.server.ts"],"names":[],"mappings":"AAOA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAoBvF,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC1C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,wBAAsB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,
|
|
1
|
+
{"version":3,"file":"floriday-status.server.d.ts","sourceRoot":"","sources":["../../src/lib/floriday-status.server.ts"],"names":[],"mappings":"AAOA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAoBvF,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC1C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,wBAAsB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,SAAS,SAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqDlH"}
|
|
@@ -16,7 +16,7 @@ async function hmacHex(secret, payload) {
|
|
|
16
16
|
.map((b) => b.toString(16).padStart(2, "0"))
|
|
17
17
|
.join("");
|
|
18
18
|
}
|
|
19
|
-
export async function loadFloridayStatuses(salesOrderIds) {
|
|
19
|
+
export async function loadFloridayStatuses(salesOrderIds, timeoutMs = 800) {
|
|
20
20
|
const entries = new Map();
|
|
21
21
|
const now = Date.now();
|
|
22
22
|
const wanted = [];
|
|
@@ -48,8 +48,8 @@ export async function loadFloridayStatuses(salesOrderIds) {
|
|
|
48
48
|
"x-floriday-caller": "verkoop",
|
|
49
49
|
},
|
|
50
50
|
body,
|
|
51
|
-
// Weergave
|
|
52
|
-
signal: AbortSignal.timeout(
|
|
51
|
+
// Weergave: begrensde wachttijd, daarna "stand onbekend".
|
|
52
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
53
53
|
});
|
|
54
54
|
const json = await res.json().catch(() => null);
|
|
55
55
|
if (!res.ok || json?.ok === false) {
|
|
@@ -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,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;
|
|
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,E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M,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" | "
|
|
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
|
+
});
|