@flowselections/floriday-verkoop-module 1.0.136 → 1.0.138
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/EditLocalOrderDialog.d.ts.map +1 -1
- package/dist-lib/components/verkoop/EditLocalOrderDialog.js +10 -2
- package/dist-lib/components/verkoop/SalesOrderDetailView.d.ts.map +1 -1
- package/dist-lib/components/verkoop/SalesOrderDetailView.js +7 -2
- package/dist-lib/integrations/supabase/types.d.ts +1249 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/create-order.functions.d.ts +6 -0
- package/dist-lib/lib/create-order.functions.d.ts.map +1 -1
- package/dist-lib/lib/create-order.functions.js +97 -32
- package/dist-lib/lib/module-version.d.ts +1 -1
- package/dist-lib/lib/module-version.js +1 -1
- package/dist-lib/lib/order-price-lock.check.d.ts +2 -0
- package/dist-lib/lib/order-price-lock.check.d.ts.map +1 -0
- package/dist-lib/lib/order-price-lock.check.js +27 -0
- package/dist-lib/lib/order-price-lock.d.ts +21 -0
- package/dist-lib/lib/order-price-lock.d.ts.map +1 -0
- package/dist-lib/lib/order-price-lock.js +28 -0
- package/dist-lib/lib/order-price-lock.server.d.ts +2 -0
- package/dist-lib/lib/order-price-lock.server.d.ts.map +1 -0
- package/dist-lib/lib/order-price-lock.server.js +21 -0
- package/dist-lib/lib/own-transport.d.ts +11 -0
- package/dist-lib/lib/own-transport.d.ts.map +1 -0
- package/dist-lib/lib/own-transport.js +10 -0
- package/dist-lib/lib/salesorders-list.server.d.ts.map +1 -1
- package/dist-lib/lib/salesorders-list.server.js +3 -0
- package/dist-lib/lib/stock-product-link.check.js +10 -2
- package/dist-lib/lib/stock-product-link.d.ts +2 -0
- package/dist-lib/lib/stock-product-link.d.ts.map +1 -1
- package/dist-lib/lib/stock-product-link.js +8 -7
- package/dist-lib/lib/stock-product-link.server.d.ts +2 -0
- package/dist-lib/lib/stock-product-link.server.d.ts.map +1 -1
- package/dist-lib/lib/stock-product-link.server.js +33 -0
- package/package.json +1 -1
|
@@ -222,6 +222,7 @@ export declare const getLocalOrderForEdit: import("@tanstack/start-client-core")
|
|
|
222
222
|
status: string | null;
|
|
223
223
|
planLockedAt: string | null;
|
|
224
224
|
canEditProducts: boolean;
|
|
225
|
+
priceLock: string | null;
|
|
225
226
|
items: {
|
|
226
227
|
id: string;
|
|
227
228
|
productId: string | null;
|
|
@@ -230,6 +231,7 @@ export declare const getLocalOrderForEdit: import("@tanstack/start-client-core")
|
|
|
230
231
|
unit: string | null;
|
|
231
232
|
plantsPerCrate: number | null;
|
|
232
233
|
needsSticker: boolean;
|
|
234
|
+
unitPrice: number | null;
|
|
233
235
|
shippedQuantity: number;
|
|
234
236
|
plannedQuantity: number;
|
|
235
237
|
minQuantity: number;
|
|
@@ -247,6 +249,10 @@ export declare const updateLocalOrder: import("@tanstack/start-client-core").Opt
|
|
|
247
249
|
itemId: string;
|
|
248
250
|
quantity: number;
|
|
249
251
|
}[] | undefined;
|
|
252
|
+
prices?: {
|
|
253
|
+
itemId: string;
|
|
254
|
+
unitPrice: number;
|
|
255
|
+
}[] | undefined;
|
|
250
256
|
removeItemIds?: string[] | undefined;
|
|
251
257
|
newItems?: {
|
|
252
258
|
productId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-order.functions.d.ts","sourceRoot":"","sources":["../../src/lib/create-order.functions.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,2BAA2B;;;;;;GA+CpC,CAAC;AAIL,eAAO,MAAM,2BAA2B;;;;0CAElB,OAAO;;;;GAoDzB,CAAC;AAWL,eAAO,MAAM,0BAA0B;;;;;;YA+D7B,MAAM;iBACD,MAAM;sBACD,MAAM,GAAG,IAAI;cACrB,MAAM;oBACA,MAAM,GAAG,IAAI;0BACP,MAAM,GAAG,IAAI;0BACb,MAAM,GAAG,IAAI;yBACd,MAAM,GAAG,IAAI;wBACd,MAAM;wBACN,MAAM;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;AAEL;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;8CAER,OAAO;;;;GAyB7B,CAAC;AAkDL,eAAO,MAAM,oBAAoB;;;;8CAEP,OAAO;;;aA2JG,MAAM;iBACQ,MAAM,GAAG,IAAI;kBACX,MAAM;;YAEnB,MAAM,GAAG,IAAI;;;;;YA6B7B,MAAM;mBACS,MAAM,GAAG,IAAI;qBACT,MAAM;;cAErB,MAAM,GAAG,IAAI;;;;;;;;GAUpC,CAAC;AAIL,eAAO,MAAM,gBAAgB;;;;8CAEH,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmT7B,CAAC;AAKL,eAAO,MAAM,kBAAkB;;;;8CAEL,OAAO;;;;;;;;WAUM,MAAM;YAAU,MAAM,GAAG,IAAI;WAmBhE,CAAC;AAOL,eAAO,MAAM,2BAA2B;;;;8CAEd,OAAO;;;;gBAIgC,MAAM,EAAE;GAoCrE,CAAC"}
|
|
@@ -136,7 +136,7 @@ export const listProductsForCreateOrder = createServerFn({ method: "GET" })
|
|
|
136
136
|
.range(0, 9999),
|
|
137
137
|
context.supabase
|
|
138
138
|
.from("products")
|
|
139
|
-
.select("id, product, unit, sale_price, plants_per_crate, crates_per_layer, layers_per_cart, quantity, custom_fields, trade_item_key")
|
|
139
|
+
.select("id, product, unit, sale_price, plants_per_crate, crates_per_layer, layers_per_cart, quantity, custom_fields, trade_item_key, floriday_trade_item_id")
|
|
140
140
|
.range(0, 4999),
|
|
141
141
|
]);
|
|
142
142
|
// Supabase geeft standaard max. 1000 rijen terug. Voor productgroepen kan de
|
|
@@ -225,6 +225,14 @@ export const listProductsForCreateOrder = createServerFn({ method: "GET" })
|
|
|
225
225
|
// of het bare Floriday-id.
|
|
226
226
|
const mirrorProductIdsByDraft = new Map();
|
|
227
227
|
const mirrorProductIdsByFloriday = new Map();
|
|
228
|
+
// Canoniek eigen artikel per Floriday-id (geen spiegel): daar staat de echte voorraad.
|
|
229
|
+
const ownByFloriday = new Map();
|
|
230
|
+
for (const p of Array.isArray(productsRes.data) ? productsRes.data : []) {
|
|
231
|
+
const src = String((p.custom_fields ?? {}).source ?? "");
|
|
232
|
+
const ti = p.floriday_trade_item_id;
|
|
233
|
+
if (ti && !/^sales-module-.*-mirror$/.test(src))
|
|
234
|
+
ownByFloriday.set(String(ti), p.id);
|
|
235
|
+
}
|
|
228
236
|
for (const p of Array.isArray(productsRes.data) ? productsRes.data : []) {
|
|
229
237
|
const cf = (p.custom_fields ?? {});
|
|
230
238
|
const pid = p.id;
|
|
@@ -250,7 +258,9 @@ export const listProductsForCreateOrder = createServerFn({ method: "GET" })
|
|
|
250
258
|
const id = r.floriday_id;
|
|
251
259
|
const articleCode = d.supplierArticleCode ?? null;
|
|
252
260
|
const mirrorKeys = (mirrorProductIdsByFloriday.get(id) ?? []).map((pid) => `product:${pid}`);
|
|
253
|
-
const
|
|
261
|
+
const own = ownByFloriday.get(id);
|
|
262
|
+
// Eigen artikel bestaat → alleen de canonieke voorraadregel, nooit de spiegel.
|
|
263
|
+
const sAgg = own ? stockOfAliases([`product:${own}`, id]) : stockOfAliases([id, ...mirrorKeys]);
|
|
254
264
|
const physical = sAgg.physical;
|
|
255
265
|
const reserved = sAgg.reserved;
|
|
256
266
|
const available = Math.max(0, physical - reserved);
|
|
@@ -742,6 +752,16 @@ export const createManualOrder = createServerFn({ method: "POST" })
|
|
|
742
752
|
// Alleen voor de terugval bij een oude Engine (custom_fields.carrier).
|
|
743
753
|
let fallbackCarrierId = null;
|
|
744
754
|
let ownTransportInfo = null;
|
|
755
|
+
// Eigen vervoer: vastleggen als de Engine-vervoerder met soort eigen_vervoer
|
|
756
|
+
// (carriers.carrier_kind), zodat de Engine geen favoriet kiest en niet
|
|
757
|
+
// bundelt met vervoerdersorders. Ontbreekt die, dan geen vervoerder.
|
|
758
|
+
let ownCarrierId = null;
|
|
759
|
+
if (ownTransport) {
|
|
760
|
+
const { data: oc } = await context.supabase
|
|
761
|
+
.from("carriers").select("id").eq("carrier_kind", "eigen_vervoer").is("archived_at", null)
|
|
762
|
+
.order("name", { ascending: true }).limit(1).maybeSingle();
|
|
763
|
+
ownCarrierId = oc?.id ?? null;
|
|
764
|
+
}
|
|
745
765
|
let momentKey = null;
|
|
746
766
|
let deliveryTime = null;
|
|
747
767
|
let lateSignup = null;
|
|
@@ -817,7 +837,12 @@ export const createManualOrder = createServerFn({ method: "POST" })
|
|
|
817
837
|
const { loadStockLinks } = await import("./stock-product-link.server.js");
|
|
818
838
|
const { fillLineFromStock } = await import("./stock-product-link.js");
|
|
819
839
|
const links = await loadStockLinks(supabaseAdmin, data.lines.map((l) => l.product_id));
|
|
820
|
-
|
|
840
|
+
// 1.0.136: bestaat er al een voorraadartikel (eerst floriday_trade_item_id,
|
|
841
|
+
// dan products.id), dan krijgt de regel dat artikel en maken we géén spiegel.
|
|
842
|
+
data.lines = data.lines.map((l) => {
|
|
843
|
+
const link = links.get(l.product_id);
|
|
844
|
+
return { ...fillLineFromStock(l, link), product_id: link?.stockProductId ?? l.product_id };
|
|
845
|
+
});
|
|
821
846
|
}
|
|
822
847
|
const productIds = Array.from(new Set(data.lines.map((l) => l.product_id)));
|
|
823
848
|
const [existingProductsRes, draftsRes, floridayRes, groupsRes] = await Promise.all([
|
|
@@ -907,8 +932,8 @@ export const createManualOrder = createServerFn({ method: "POST" })
|
|
|
907
932
|
const orderPayload = {
|
|
908
933
|
// Vervoerder via de Engine in dezelfde transactie (logistics_set_order_carrier);
|
|
909
934
|
// geen custom_fields.carrier meer, behalve als terugval bij een oude Engine.
|
|
910
|
-
manual_carrier_id: carrierId,
|
|
911
|
-
fallback_carrier_id: fallbackCarrierId,
|
|
935
|
+
manual_carrier_id: carrierId ?? ownCarrierId,
|
|
936
|
+
fallback_carrier_id: fallbackCarrierId ?? ownCarrierId,
|
|
912
937
|
set_by_user_id: context.userId ?? null,
|
|
913
938
|
customer_name: data.customerName,
|
|
914
939
|
customer_id: data.customerId,
|
|
@@ -1166,6 +1191,8 @@ const UpdateLocalOrderInput = z.object({
|
|
|
1166
1191
|
quantity: z.number().int().positive(),
|
|
1167
1192
|
}))
|
|
1168
1193
|
.optional(),
|
|
1194
|
+
// Prijs per bestaande regel (alleen HO/AO/MO, niet na een definitieve factuur).
|
|
1195
|
+
prices: z.array(z.object({ itemId: z.string().uuid(), unitPrice: z.number().min(0).max(1000000) })).max(500).optional(),
|
|
1169
1196
|
// Regels verwijderen — alleen zolang de order niet in het Pickstation is
|
|
1170
1197
|
// geprint (orders.plan_locked_at is leeg).
|
|
1171
1198
|
removeItemIds: z.array(z.string().uuid()).optional(),
|
|
@@ -1209,7 +1236,7 @@ export const getLocalOrderForEdit = createServerFn({ method: "POST" })
|
|
|
1209
1236
|
}
|
|
1210
1237
|
const { data: items, error: iErr } = await context.supabase
|
|
1211
1238
|
.from("order_items")
|
|
1212
|
-
.select("id, product_id, product_name, quantity, unit, needs_sticker, plants_per_crate, products(plants_per_crate)")
|
|
1239
|
+
.select("id, product_id, product_name, quantity, unit, needs_sticker, unit_price, plants_per_crate, products(plants_per_crate)")
|
|
1213
1240
|
.eq("order_id", data.orderId)
|
|
1214
1241
|
.is("quarantined_at", null)
|
|
1215
1242
|
.order("id");
|
|
@@ -1350,6 +1377,17 @@ export const getLocalOrderForEdit = createServerFn({ method: "POST" })
|
|
|
1350
1377
|
status: order.status,
|
|
1351
1378
|
planLockedAt: order.plan_locked_at ?? null,
|
|
1352
1379
|
canEditProducts: !order.plan_locked_at,
|
|
1380
|
+
// Prijs wijzigen: null = mag; anders de reden (definitieve factuur / Twinfield).
|
|
1381
|
+
priceLock: await (async () => {
|
|
1382
|
+
try {
|
|
1383
|
+
const { supabaseAdmin } = await import("../integrations/supabase/client.server.js");
|
|
1384
|
+
const { loadPriceLock } = await import("./order-price-lock.server.js");
|
|
1385
|
+
return await loadPriceLock(context.supabase, supabaseAdmin, order.id, false);
|
|
1386
|
+
}
|
|
1387
|
+
catch (e) {
|
|
1388
|
+
return `Factuurstand onbekend: ${e?.message ?? "fout"}`;
|
|
1389
|
+
}
|
|
1390
|
+
})(),
|
|
1353
1391
|
items: rows.map((it) => {
|
|
1354
1392
|
// Eerst de vastgelegde verpakking van de regel zelf; onbekend = null.
|
|
1355
1393
|
let ppc = posOrNull(it.plants_per_crate) ?? posOrNull(it.products?.plants_per_crate);
|
|
@@ -1375,6 +1413,7 @@ export const getLocalOrderForEdit = createServerFn({ method: "POST" })
|
|
|
1375
1413
|
unit: it.unit,
|
|
1376
1414
|
plantsPerCrate: ppc,
|
|
1377
1415
|
needsSticker: it.needs_sticker === true,
|
|
1416
|
+
unitPrice: it.unit_price == null ? null : Number(it.unit_price),
|
|
1378
1417
|
shippedQuantity: shipped,
|
|
1379
1418
|
plannedQuantity: planned,
|
|
1380
1419
|
minQuantity: shipped + planned,
|
|
@@ -1408,7 +1447,7 @@ export const updateLocalOrder = createServerFn({ method: "POST" })
|
|
|
1408
1447
|
// voorraadcontrole, herberekening of nieuwe planning.
|
|
1409
1448
|
const { data: currentRows, error: cErr } = await supabaseAdmin
|
|
1410
1449
|
.from("order_items")
|
|
1411
|
-
.select("id, quantity, needs_sticker")
|
|
1450
|
+
.select("id, quantity, needs_sticker, unit_price")
|
|
1412
1451
|
.eq("order_id", data.orderId);
|
|
1413
1452
|
if (cErr)
|
|
1414
1453
|
throw stockError(cErr.message);
|
|
@@ -1416,6 +1455,14 @@ export const updateLocalOrder = createServerFn({ method: "POST" })
|
|
|
1416
1455
|
r.id,
|
|
1417
1456
|
{ quantity: Number(r.quantity ?? 0), needsSticker: r.needs_sticker === true },
|
|
1418
1457
|
]));
|
|
1458
|
+
const priceById = new Map((currentRows ?? []).map((r) => [r.id, Number(r.unit_price ?? 0)]));
|
|
1459
|
+
const priceChanges = (data.prices ?? []).filter((p) => priceById.has(p.itemId) && !removeIds.includes(p.itemId) && Math.abs((priceById.get(p.itemId) ?? 0) - p.unitPrice) > 0.00001);
|
|
1460
|
+
if (priceChanges.length > 0) {
|
|
1461
|
+
const { loadPriceLock } = await import("./order-price-lock.server.js");
|
|
1462
|
+
const lock = await loadPriceLock(context.supabase, supabaseAdmin, data.orderId, false);
|
|
1463
|
+
if (lock)
|
|
1464
|
+
throw stockError(lock);
|
|
1465
|
+
}
|
|
1419
1466
|
const changedItems = (data.items ?? []).filter((i) => {
|
|
1420
1467
|
const cur = currentById.get(i.itemId);
|
|
1421
1468
|
return !cur || cur.quantity !== i.quantity;
|
|
@@ -1430,7 +1477,7 @@ export const updateLocalOrder = createServerFn({ method: "POST" })
|
|
|
1430
1477
|
String(data.deliveryDate).slice(0, 10) !== String(order.delivery_date ?? "").slice(0, 10);
|
|
1431
1478
|
if (!dateChanged)
|
|
1432
1479
|
data.deliveryDate = undefined;
|
|
1433
|
-
const realChange = changedItems.length > 0 || removeIds.length > 0 || newItems.length > 0 || dateChanged;
|
|
1480
|
+
const realChange = priceChanges.length > 0 || changedItems.length > 0 || removeIds.length > 0 || newItems.length > 0 || dateChanged;
|
|
1434
1481
|
// Producten wijzigen mag alleen zolang er nog niets is geprint in het
|
|
1435
1482
|
// Pickstation (orders.plan_locked_at).
|
|
1436
1483
|
if ((removeIds.length > 0 || newItems.length > 0) && order.plan_locked_at) {
|
|
@@ -1549,32 +1596,42 @@ export const updateLocalOrder = createServerFn({ method: "POST" })
|
|
|
1549
1596
|
if (newDate !== String(order.delivery_date ?? "").slice(0, 10) && cf?.delivery_location) {
|
|
1550
1597
|
const { loadDeparturePreview, deliveryTimeForMoment } = await import("./departure-preview.server.js");
|
|
1551
1598
|
const { decidePreview } = await import("./departure-preview.js");
|
|
1552
|
-
const
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
if (d.kind === "blocked")
|
|
1560
|
-
throw stockError(d.reason);
|
|
1561
|
-
// Vervoerder al vertrokken: ook bij wijzigen nooit doorlaten.
|
|
1562
|
-
if (d.kind === "departed") {
|
|
1563
|
-
throw stockError(d.firstDate ? `${d.reason} De eerstvolgende leverdatum is ${d.firstDate}.` : d.reason);
|
|
1599
|
+
const { resolveCarrierOne } = await import("./carrier-resolve.server.js");
|
|
1600
|
+
const { ownTransportDateDecision } = await import("./own-transport.js");
|
|
1601
|
+
const resolved = await resolveCarrierOne(context.supabase, data.orderId, { id: cf?.carrier ?? null, name: null });
|
|
1602
|
+
const ownDec = ownTransportDateDecision({ ownTransport: !!cf?.own_transport, carrierKind: resolved.carrierKind });
|
|
1603
|
+
if (ownDec.skipDeparture) {
|
|
1604
|
+
newMoment = null;
|
|
1605
|
+
newDeliveryTime = null;
|
|
1564
1606
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1607
|
+
else {
|
|
1608
|
+
const preview = await loadDeparturePreview(context.supabase, {
|
|
1609
|
+
carrierId: resolved.carrierId ?? cf?.carrier ?? null,
|
|
1610
|
+
deliveryLocation: String(cf.delivery_location),
|
|
1611
|
+
deliveryDate: newDate,
|
|
1612
|
+
momentKey: null,
|
|
1613
|
+
});
|
|
1614
|
+
const d = decidePreview(preview);
|
|
1615
|
+
if (d.kind === "blocked")
|
|
1616
|
+
throw stockError(d.reason);
|
|
1617
|
+
// Vervoerder al vertrokken: ook bij wijzigen nooit doorlaten.
|
|
1618
|
+
if (d.kind === "departed") {
|
|
1619
|
+
throw stockError(d.firstDate ? `${d.reason} De eerstvolgende leverdatum is ${d.firstDate}.` : d.reason);
|
|
1568
1620
|
}
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1621
|
+
if (d.kind === "late") {
|
|
1622
|
+
if (!data.acceptLateSignup) {
|
|
1623
|
+
throw stockError(d.firstDate ? `${d.reason} De eerste haalbare leverdatum is ${d.firstDate}.` : d.reason);
|
|
1624
|
+
}
|
|
1625
|
+
const by = context.claims?.email ?? null;
|
|
1626
|
+
lateOverride = {
|
|
1627
|
+
by_user_id: context.userId ?? null, by_email: by, by_name: by,
|
|
1628
|
+
at: new Date().toISOString(), delivery_date: newDate,
|
|
1629
|
+
signup_deadline: preview?.chosen?.signupDeadline ?? null, reason: d.reason, source: "manual",
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
newMoment = d.momentKey;
|
|
1633
|
+
newDeliveryTime = await deliveryTimeForMoment(context.supabase, resolved.carrierId ?? cf?.carrier ?? null, newMoment);
|
|
1575
1634
|
}
|
|
1576
|
-
newMoment = d.momentKey;
|
|
1577
|
-
newDeliveryTime = await deliveryTimeForMoment(context.supabase, cf?.carrier ?? null, newMoment);
|
|
1578
1635
|
}
|
|
1579
1636
|
const { error: uErr } = await supabaseAdmin.from("orders")
|
|
1580
1637
|
.update({
|
|
@@ -1598,7 +1655,15 @@ export const updateLocalOrder = createServerFn({ method: "POST" })
|
|
|
1598
1655
|
throw stockError(`Aantal bijwerken faalde: ${iErr.message}`);
|
|
1599
1656
|
}
|
|
1600
1657
|
}
|
|
1601
|
-
|
|
1658
|
+
for (const pc of priceChanges) {
|
|
1659
|
+
const { error: pErr } = await supabaseAdmin.from("order_items")
|
|
1660
|
+
.update({ unit_price: pc.unitPrice })
|
|
1661
|
+
.eq("id", pc.itemId)
|
|
1662
|
+
.eq("order_id", data.orderId);
|
|
1663
|
+
if (pErr)
|
|
1664
|
+
throw stockError(`Prijs bijwerken faalde: ${pErr.message}`);
|
|
1665
|
+
}
|
|
1666
|
+
if ((data.items?.length ?? 0) > 0 || removeIds.length > 0 || newItems.length > 0 || priceChanges.length > 0) {
|
|
1602
1667
|
// Hertellen ordertotaal op basis van items × unit_price.
|
|
1603
1668
|
const { data: itemsAll } = await supabaseAdmin
|
|
1604
1669
|
.from("order_items")
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const MODULE_VERSION = "1.0.
|
|
1
|
+
export declare const MODULE_VERSION = "1.0.138";
|
|
2
2
|
//# sourceMappingURL=module-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-price-lock.check.d.ts","sourceRoot":"","sources":["../../src/lib/order-price-lock.check.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Draai: bun src/lib/order-price-lock.check.ts
|
|
2
|
+
import { orderUuid, priceLockReason, PRICE_LOCK_ERP_TEXT, PRICE_LOCK_FLORIDAY_TEXT, PRICE_LOCK_TWINFIELD_TEXT } from "./order-price-lock.js";
|
|
3
|
+
import { ownTransportDateDecision } from "./own-transport.js";
|
|
4
|
+
let failed = 0;
|
|
5
|
+
function check(name, got, want) {
|
|
6
|
+
const ok = JSON.stringify(got) === JSON.stringify(want);
|
|
7
|
+
if (!ok)
|
|
8
|
+
failed++;
|
|
9
|
+
console.log(`${ok ? "OK " : "FOUT"} ${name}: ${JSON.stringify(got)}${ok ? "" : ` (verwacht ${JSON.stringify(want)})`}`);
|
|
10
|
+
}
|
|
11
|
+
check("Floriday-order geweigerd", priceLockReason({ isFloriday: true, erpInvoices: [], links: [] }), PRICE_LOCK_FLORIDAY_TEXT);
|
|
12
|
+
check("definitieve ERP-factuur → eerst crediteren", priceLockReason({ isFloriday: false, erpInvoices: [{ invoice_number: "FS-1", kind: "factuur", status: "definitief" }], links: [] }), PRICE_LOCK_ERP_TEXT);
|
|
13
|
+
check("gecrediteerd → toegestaan", priceLockReason({ isFloriday: false, erpInvoices: [{ invoice_number: "FS-1", kind: "factuur", status: "definitief" }, { invoice_number: "FS-2", kind: "credit", status: "definitief" }], links: [] }), null);
|
|
14
|
+
check("ERP-concept → toegestaan", priceLockReason({ isFloriday: false, erpInvoices: [{ invoice_number: null, kind: "factuur", status: "concept" }], links: [] }), null);
|
|
15
|
+
check("oude Twinfield-concept 40 (AO-2601453)", priceLockReason({ isFloriday: false, erpInvoices: [], links: [{ status: "sent", invoice_number: "40" }] }), PRICE_LOCK_TWINFIELD_TEXT);
|
|
16
|
+
check("link met ERP-nummer is geen Twinfield", priceLockReason({ isFloriday: false, erpInvoices: [{ invoice_number: "FS-1", kind: "factuur", status: "concept" }], links: [{ status: "sent", invoice_number: "FS-1" }] }), null);
|
|
17
|
+
check("zonder Facturatie → toegestaan", priceLockReason({ isFloriday: false, erpInvoices: null, links: null }), null);
|
|
18
|
+
check("local:-id → uuid", orderUuid("local:6f1c2b9e-1111-4222-8333-944455556666"), "6f1c2b9e-1111-4222-8333-944455556666");
|
|
19
|
+
check("Floriday-id zonder uuid → null", orderUuid("FO-2601463"), null);
|
|
20
|
+
check("eigen vervoer: geen vertrekcontrole", ownTransportDateDecision({ ownTransport: true, carrierKind: "extern" }), { skipDeparture: true, clearMoment: true });
|
|
21
|
+
check("klant haalt op: geen vertrekcontrole", ownTransportDateDecision({ ownTransport: false, carrierKind: "klant_haalt_op" }), { skipDeparture: true, clearMoment: true });
|
|
22
|
+
check("externe vervoerder: wel controle", ownTransportDateDecision({ ownTransport: false, carrierKind: "extern" }), { skipDeparture: false, clearMoment: false });
|
|
23
|
+
if (failed) {
|
|
24
|
+
console.error(`${failed} fout(en)`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
console.log("Alles OK");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const PRICE_LOCK_ERP_TEXT = "Er staat al een definitieve factuur; eerst crediteren.";
|
|
2
|
+
export declare const PRICE_LOCK_TWINFIELD_TEXT = "Er staat al een factuur in Twinfield; verwijder of crediteer die eerst.";
|
|
3
|
+
export declare const PRICE_LOCK_FLORIDAY_TEXT = "Bij Floriday-orders blijft de prijs uit Floriday staan.";
|
|
4
|
+
export type PriceLockInput = {
|
|
5
|
+
isFloriday: boolean;
|
|
6
|
+
/** null = Facturatie niet aanwezig (functie of tabel ontbreekt). */
|
|
7
|
+
erpInvoices: Array<{
|
|
8
|
+
invoice_number: string | null;
|
|
9
|
+
kind: string | null;
|
|
10
|
+
status: string | null;
|
|
11
|
+
}> | null;
|
|
12
|
+
/** null = koppeltabel niet aanwezig. */
|
|
13
|
+
links: Array<{
|
|
14
|
+
status: string | null;
|
|
15
|
+
invoice_number: string | null;
|
|
16
|
+
}> | null;
|
|
17
|
+
};
|
|
18
|
+
export declare function priceLockReason(i: PriceLockInput): string | null;
|
|
19
|
+
/** "local:<uuid>" of "<uuid>" → uuid; anders null. */
|
|
20
|
+
export declare function orderUuid(id: unknown): string | null;
|
|
21
|
+
//# sourceMappingURL=order-price-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-price-lock.d.ts","sourceRoot":"","sources":["../../src/lib/order-price-lock.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,2DAA2D,CAAC;AAC5F,eAAO,MAAM,yBAAyB,4EAA4E,CAAC;AACnH,eAAO,MAAM,wBAAwB,4DAA4D,CAAC;AAElG,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,oEAAoE;IACpE,WAAW,EAAE,KAAK,CAAC;QAAE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;IACzG,wCAAwC;IACxC,KAAK,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;CAC/E,CAAC;AAIF,wBAAgB,eAAe,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,CAehE;AAED,sDAAsD;AACtD,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAGpD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Mag de prijs van een bestaande order nog gewijzigd worden? (client-safe, puur)
|
|
2
|
+
// Alleen HO/AO/MO; Floriday-orders houden de prijs uit Floriday.
|
|
3
|
+
export const PRICE_LOCK_ERP_TEXT = "Er staat al een definitieve factuur; eerst crediteren.";
|
|
4
|
+
export const PRICE_LOCK_TWINFIELD_TEXT = "Er staat al een factuur in Twinfield; verwijder of crediteer die eerst.";
|
|
5
|
+
export const PRICE_LOCK_FLORIDAY_TEXT = "Bij Floriday-orders blijft de prijs uit Floriday staan.";
|
|
6
|
+
const FINAL = new Set(["definitief", "geboekt"]);
|
|
7
|
+
export function priceLockReason(i) {
|
|
8
|
+
if (i.isFloriday)
|
|
9
|
+
return PRICE_LOCK_FLORIDAY_TEXT;
|
|
10
|
+
if (i.erpInvoices) {
|
|
11
|
+
const finals = i.erpInvoices.filter((r) => (r.kind ?? "factuur") !== "credit" && FINAL.has(String(r.status ?? "").toLowerCase())).length;
|
|
12
|
+
const credits = i.erpInvoices.filter((r) => r.kind === "credit" && FINAL.has(String(r.status ?? "").toLowerCase())).length;
|
|
13
|
+
if (finals > credits)
|
|
14
|
+
return PRICE_LOCK_ERP_TEXT;
|
|
15
|
+
}
|
|
16
|
+
if (i.links && i.erpInvoices) {
|
|
17
|
+
const known = new Set(i.erpInvoices.map((r) => String(r.invoice_number ?? "").trim()).filter(Boolean));
|
|
18
|
+
const legacy = i.links.some((l) => l.status === "sent" && !!String(l.invoice_number ?? "").trim() && !known.has(String(l.invoice_number).trim()));
|
|
19
|
+
if (legacy)
|
|
20
|
+
return PRICE_LOCK_TWINFIELD_TEXT;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/** "local:<uuid>" of "<uuid>" → uuid; anders null. */
|
|
25
|
+
export function orderUuid(id) {
|
|
26
|
+
const s = String(id ?? "").replace(/^local:/, "").trim();
|
|
27
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s) ? s : null;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-price-lock.server.d.ts","sourceRoot":"","sources":["../../src/lib/order-price-lock.server.ts"],"names":[],"mappings":"AAIA,wBAAsB,aAAa,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAY7H"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Leest factuurstand voor de prijsvergrendeling (alleen lezen). Shell zonder Facturatie → null.
|
|
2
|
+
import { rpcErrorKind } from "./erp-invoice-view.js";
|
|
3
|
+
import { priceLockReason } from "./order-price-lock.js";
|
|
4
|
+
export async function loadPriceLock(userClient, admin, orderId, isFloriday) {
|
|
5
|
+
if (isFloriday)
|
|
6
|
+
return priceLockReason({ isFloriday, erpInvoices: null, links: null });
|
|
7
|
+
let erp = null;
|
|
8
|
+
const r = await userClient.rpc("erp_invoices_for_order", { p_order_id: orderId });
|
|
9
|
+
if (r.error) {
|
|
10
|
+
const kind = rpcErrorKind(r.error);
|
|
11
|
+
if (kind !== "missing")
|
|
12
|
+
throw new Error(`Factuurstand lezen faalde: ${r.error.message}`);
|
|
13
|
+
}
|
|
14
|
+
else
|
|
15
|
+
erp = Array.isArray(r.data) ? r.data : [];
|
|
16
|
+
let links = null;
|
|
17
|
+
const l = await admin.from("order_invoice_links").select("status, invoice_number").eq("order_id", orderId);
|
|
18
|
+
if (!l.error)
|
|
19
|
+
links = l.data ?? [];
|
|
20
|
+
return priceLockReason({ isFloriday, erpInvoices: erp, links });
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const OWN_CARRIER_KINDS: Set<string>;
|
|
2
|
+
export declare function isOwnTransportKind(kind: string | null | undefined): boolean;
|
|
3
|
+
/** Bij eigen vervoer of zelf ophalen: geen vertrekcontrole en geen ophaalmoment. */
|
|
4
|
+
export declare function ownTransportDateDecision(p: {
|
|
5
|
+
ownTransport: boolean;
|
|
6
|
+
carrierKind: string | null | undefined;
|
|
7
|
+
}): {
|
|
8
|
+
skipDeparture: boolean;
|
|
9
|
+
clearMoment: boolean;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=own-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"own-transport.d.ts","sourceRoot":"","sources":["../../src/lib/own-transport.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,iBAAiB,aAA+C,CAAC;AAE9E,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE3E;AAED,oFAAoF;AACpF,wBAAgB,wBAAwB,CAAC,CAAC,EAAE;IAAE,YAAY,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CAAE;;;EAG5G"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Eigen vervoer / zelf ophalen (client-safe, puur). De soort komt van carriers.carrier_kind (Engine-gegevens).
|
|
2
|
+
export const OWN_CARRIER_KINDS = new Set(["eigen_vervoer", "klant_haalt_op"]);
|
|
3
|
+
export function isOwnTransportKind(kind) {
|
|
4
|
+
return OWN_CARRIER_KINDS.has(String(kind ?? "").toLowerCase());
|
|
5
|
+
}
|
|
6
|
+
/** Bij eigen vervoer of zelf ophalen: geen vertrekcontrole en geen ophaalmoment. */
|
|
7
|
+
export function ownTransportDateDecision(p) {
|
|
8
|
+
const own = p.ownTransport || isOwnTransportKind(p.carrierKind);
|
|
9
|
+
return { skipDeparture: own, clearMoment: own };
|
|
10
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"salesorders-list.server.d.ts","sourceRoot":"","sources":["../../src/lib/salesorders-list.server.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAEvB,MAAM,uBAAuB,CAAC;AAK/B,OAAO,EAAiB,KA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AK,EAAE,MAAM,GAAG,IAAI,GACnB,qBAAqB,CAIvB"}
|
|
@@ -1194,6 +1194,9 @@ export async function buildSalesOrdersList(supabase, params, connectionSupabase
|
|
|
1194
1194
|
const idFor = (o) => o.id.startsWith("local:")
|
|
1195
1195
|
? o.id.slice("local:".length)
|
|
1196
1196
|
: (localRowByFoId.get(o.id)?.id ? String(localRowByFoId.get(o.id).id) : null);
|
|
1197
|
+
// orders.id per zichtbare order (ook bij Floriday-orders), voor het factuurblok.
|
|
1198
|
+
for (const o of visible)
|
|
1199
|
+
o.orderRowId = idFor(o);
|
|
1197
1200
|
const ids = visible.map(idFor).filter((v) => !!v);
|
|
1198
1201
|
if (ids.length) {
|
|
1199
1202
|
// Ophaalmoment uit de Engine (nooit zelf rekenen).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Draai: bun src/lib/stock-product-link.check.ts
|
|
2
|
-
import { fallbackPrice, fillLineFromStock, linkStockProducts } from "./stock-product-link.js";
|
|
2
|
+
import { canonicalProductId, fallbackPrice, fillLineFromStock, linkStockProducts } from "./stock-product-link.js";
|
|
3
3
|
let failed = 0;
|
|
4
4
|
function check(name, got, want) {
|
|
5
5
|
const g = JSON.stringify(got), w = JSON.stringify(want);
|
|
@@ -17,7 +17,7 @@ const packs = [{ product_id: STOCK, is_primary: true, sort_order: 0, vbn_package
|
|
|
17
17
|
const link = linkStockProducts([TI], products, packs).get(TI);
|
|
18
18
|
check("trade-item-id → voorraadartikel via floriday_trade_item_id", link?.stockProductId, STOCK);
|
|
19
19
|
check("primaire belading", link?.primary, { vbn_package_code: "18", load_carrier_type: "DANISH_TROLLEY", plants_per_crate: 12, crates_per_layer: 5, layers_per_cart: 8 });
|
|
20
|
-
check("
|
|
20
|
+
check("eigen artikel via eigen id", linkStockProducts([STOCK], products, packs).get(STOCK)?.stockProductId, STOCK);
|
|
21
21
|
const line = fillLineFromStock({ vbn_package_code: null, load_carrier_type: null, packing_source: null }, link);
|
|
22
22
|
check("lege regel krijgt belading", [line.vbn_package_code, line.load_carrier_type, line.plants_per_crate, line.packing_source], ["18", "DANISH_TROLLEY", 12, "product_primary"]);
|
|
23
23
|
const chosen = fillLineFromStock({ vbn_package_code: "575", load_carrier_type: "AUCTION_TROLLEY", plants_per_crate: 6, packing_source: "chosen" }, link);
|
|
@@ -25,6 +25,14 @@ check("gekozen belading blijft", [chosen.vbn_package_code, chosen.load_carrier_t
|
|
|
25
25
|
check("handmatig zonder prijsgroep → artikelprijs", fallbackPrice("manual", null, link), { price: 1.25, source: "artikel" });
|
|
26
26
|
check("prijsgroep gaat voor", fallbackPrice("manual", 2, link), { price: 2, source: "prijsgroep" });
|
|
27
27
|
check("Floriday-order nooit artikelprijs", fallbackPrice("floriday", null, link), null);
|
|
28
|
+
const OWN2 = "aaaa0000-0000-0000-0000-000000000000";
|
|
29
|
+
const both = [
|
|
30
|
+
{ id: TI, sale_price: null, floriday_trade_item_id: null, is_mirror: false },
|
|
31
|
+
{ id: OWN2, sale_price: 1.4, floriday_trade_item_id: TI, is_mirror: false },
|
|
32
|
+
];
|
|
33
|
+
check("floriday_trade_item_id gaat vóór products.id", linkStockProducts([TI], both, []).get(TI)?.stockProductId, OWN2);
|
|
34
|
+
check("bestaand eigen artikel → geen spiegel, regel krijgt eigen artikel", canonicalProductId(TI, linkStockProducts([TI], both, []).get(TI)), OWN2);
|
|
35
|
+
check("niets gevonden → gekozen id (spiegel)", canonicalProductId("x", linkStockProducts(["x"], both, []).get("x")), "x");
|
|
28
36
|
if (failed) {
|
|
29
37
|
console.error(`${failed} fout(en)`);
|
|
30
38
|
process.exit(1);
|
|
@@ -42,4 +42,6 @@ export declare function fallbackPrice(orderKind: "manual" | "floriday", groupPri
|
|
|
42
42
|
price: number;
|
|
43
43
|
source: string;
|
|
44
44
|
} | null;
|
|
45
|
+
/** Gekozen id → canoniek product-id; bestaat er geen artikel, dan het gekozen id (spiegel volgt). */
|
|
46
|
+
export declare function canonicalProductId(id: string, link: StockLink | undefined): string;
|
|
45
47
|
//# sourceMappingURL=stock-product-link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stock-product-link.d.ts","sourceRoot":"","sources":["../../src/lib/stock-product-link.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stock-product-link.d.ts","sourceRoot":"","sources":["../../src/lib/stock-product-link.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACnC,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACzC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC,CAAC;AACF,MAAM,MAAM,SAAS,GAAG;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE;QACP,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;QAChC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;QACjC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;QAChC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;QAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;KAChC,GAAG,IAAI,CAAC;CACV,CAAC;AAOF,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAWxE;AAED,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAmBvH;AAED,sGAAsG;AACtG,wBAAgB,iBAAiB,CAAC,CAAC,SAAS;IAC1C,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAC/E,cAAc,CAAC,EAAE,iBAAiB,GAAG,UAAU,GAAG,QAAQ,GAAG,IAAI,CAAC;CACnE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,CAAC,CAa1C;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,SAAS,EAAE,QAAQ,GAAG,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAIhK;AAED,qGAAqG;AACrG,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAElF"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Koppeling orderregel → voorraadartikel (client-safe, pure logica).
|
|
2
2
|
// Contract gelijk aan Engine 1.0.215 (logistics_ladingdrager_voor_regel):
|
|
3
|
-
// 1) products.
|
|
4
|
-
// 2) anders products.
|
|
3
|
+
// 1) eigen artikel: products.floriday_trade_item_id = gekozen id (geen spiegel)
|
|
4
|
+
// 2) anders products.id = gekozen id
|
|
5
|
+
// Volgorde gelijk aan Voorraad (voorraad_canoniek_artikel), sinds 1.0.136.
|
|
5
6
|
// Een spiegelrij (custom_fields.source = 'sales-module-*-mirror') zonder
|
|
6
7
|
// primaire verpakking telt niet als voorraadartikel bij stap 1.
|
|
7
8
|
// Verpakkingen hangen aan products.id (product_packings.product_id).
|
|
@@ -38,16 +39,12 @@ export function linkStockProducts(ids, products, packings) {
|
|
|
38
39
|
const mk = (p) => ({ stockProductId: p.id, salePrice: pos(p.sale_price), primary: primaryPacking(packsBy.get(p.id) ?? []) });
|
|
39
40
|
const out = new Map();
|
|
40
41
|
for (const id of ids) {
|
|
41
|
-
const direct = byId.get(id);
|
|
42
|
-
if (direct && !(direct.is_mirror && !(packsBy.get(direct.id)?.length))) {
|
|
43
|
-
out.set(id, mk(direct));
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
42
|
const viaTi = byTradeItem.get(id);
|
|
47
43
|
if (viaTi) {
|
|
48
44
|
out.set(id, mk(viaTi));
|
|
49
45
|
continue;
|
|
50
46
|
}
|
|
47
|
+
const direct = byId.get(id);
|
|
51
48
|
if (direct)
|
|
52
49
|
out.set(id, mk(direct));
|
|
53
50
|
}
|
|
@@ -77,3 +74,7 @@ export function fallbackPrice(orderKind, groupPrice, link) {
|
|
|
77
74
|
return null;
|
|
78
75
|
return link?.salePrice ? { price: link.salePrice, source: "artikel" } : null;
|
|
79
76
|
}
|
|
77
|
+
/** Gekozen id → canoniek product-id; bestaat er geen artikel, dan het gekozen id (spiegel volgt). */
|
|
78
|
+
export function canonicalProductId(id, link) {
|
|
79
|
+
return link?.stockProductId ?? id;
|
|
80
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type StockLink } from "./stock-product-link.js";
|
|
2
|
+
export type CanonicalSource = "voorraad_canoniek_artikel" | "terugval";
|
|
3
|
+
export declare let lastCanonicalSource: CanonicalSource;
|
|
2
4
|
export declare function loadStockLinks(sb: any, ids: string[]): Promise<Map<string, StockLink>>;
|
|
3
5
|
//# sourceMappingURL=stock-product-link.server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stock-product-link.server.d.ts","sourceRoot":"","sources":["../../src/lib/stock-product-link.server.ts"],"names":[],"mappings":"AACA,OAAO,EAAuD,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE3G,wBAAsB,cAAc,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"stock-product-link.server.d.ts","sourceRoot":"","sources":["../../src/lib/stock-product-link.server.ts"],"names":[],"mappings":"AACA,OAAO,EAAuD,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE3G,MAAM,MAAM,eAAe,GAAG,2BAA2B,GAAG,UAAU,CAAC;AACvE,eAAO,IAAI,mBAAmB,EAAE,eAA4B,CAAC;AAc7D,wBAAsB,cAAc,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAkC5F"}
|
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
// Leest products + product_packings en koppelt via stock-product-link.ts.
|
|
2
2
|
import { linkStockProducts } from "./stock-product-link.js";
|
|
3
|
+
export let lastCanonicalSource = "terugval";
|
|
4
|
+
/** Probeert eerst de functie van Voorraad; ontbreekt die of faalt hij → null (terugval). */
|
|
5
|
+
async function viaVoorraad(sb, ids) {
|
|
6
|
+
const out = new Map();
|
|
7
|
+
for (const id of ids) {
|
|
8
|
+
const { data, error } = await sb.rpc("voorraad_canoniek_artikel", { p_id: id });
|
|
9
|
+
if (error)
|
|
10
|
+
return null;
|
|
11
|
+
const v = typeof data === "string" ? data : (data?.product_id ?? data?.id ?? (Array.isArray(data) ? data[0]?.product_id ?? data[0]?.id : null));
|
|
12
|
+
if (v)
|
|
13
|
+
out.set(id, String(v));
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
3
17
|
export async function loadStockLinks(sb, ids) {
|
|
4
18
|
const uniq = Array.from(new Set(ids.filter(Boolean)));
|
|
5
19
|
if (!uniq.length)
|
|
6
20
|
return new Map();
|
|
21
|
+
const canon = await viaVoorraad(sb, uniq);
|
|
22
|
+
lastCanonicalSource = canon ? "voorraad_canoniek_artikel" : "terugval";
|
|
23
|
+
if (canon && canon.size) {
|
|
24
|
+
const targets = Array.from(new Set(canon.values()));
|
|
25
|
+
const { data: rows } = await sb.from("products").select("id, sale_price, floriday_trade_item_id, custom_fields").in("id", targets);
|
|
26
|
+
const { data: packs } = await sb
|
|
27
|
+
.from("product_packings")
|
|
28
|
+
.select("product_id, is_primary, sort_order, vbn_package_code, load_carrier, pieces_per_package, packages_per_layer, layers_per_load_carrier")
|
|
29
|
+
.in("product_id", targets);
|
|
30
|
+
const prods = (rows ?? []).map((r) => ({ id: r.id, sale_price: r.sale_price, floriday_trade_item_id: null, is_mirror: false }));
|
|
31
|
+
const out = new Map();
|
|
32
|
+
const one = linkStockProducts(targets, prods, (packs ?? []));
|
|
33
|
+
for (const [id, t] of canon) {
|
|
34
|
+
const l = one.get(t);
|
|
35
|
+
if (l)
|
|
36
|
+
out.set(id, l);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
7
40
|
const [a, b] = await Promise.all([
|
|
8
41
|
sb.from("products").select("id, sale_price, floriday_trade_item_id, custom_fields").in("id", uniq),
|
|
9
42
|
sb.from("products").select("id, sale_price, floriday_trade_item_id, custom_fields").in("floriday_trade_item_id", uniq),
|