thm-p3-configurator 0.0.289 → 0.0.290
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.
|
@@ -287,20 +287,44 @@ const ProductCartTable = () => {
|
|
|
287
287
|
const montageTotalExcl = Number((totals === null || totals === void 0 ? void 0 : totals.totalMontageExclVat) || 0);
|
|
288
288
|
const montageHourlyExcl = montageHours > 0 ? montageTotalExcl / montageHours : null;
|
|
289
289
|
(0, _react.useEffect)(() => {
|
|
290
|
-
if (!
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
290
|
+
if (!(cart !== null && cart !== void 0 && cart.length) || !products) return;
|
|
291
|
+
|
|
292
|
+
// Sync product default discounts to consumerDiscounts for API calls
|
|
293
|
+
const allProducts = [...(products.Trekhaak || []), ...(products.Kabelset || []), ...(products.Combiset || []), ...(products['Elektronica boordcomputer updaten'] || []), ...(products.Extras || [])];
|
|
294
|
+
allProducts.forEach(product => {
|
|
295
|
+
var _product$consumerPric, _product$consumerPric2, _cartItem$consumerDis;
|
|
296
|
+
const articleNumber = product === null || product === void 0 ? void 0 : product.articleNumber;
|
|
297
|
+
if (!articleNumber) return;
|
|
298
|
+
const cartItem = cart.find(c => c.articleNumber === articleNumber);
|
|
299
|
+
if (!cartItem) return;
|
|
300
|
+
const isTouched = (touchedConsumerDiscounts === null || touchedConsumerDiscounts === void 0 ? void 0 : touchedConsumerDiscounts[articleNumber]) === true;
|
|
301
|
+
const hasStoredDiscount = (consumerDiscounts === null || consumerDiscounts === void 0 ? void 0 : consumerDiscounts[articleNumber]) !== undefined;
|
|
302
|
+
const productDefault = (_product$consumerPric = product === null || product === void 0 || (_product$consumerPric2 = product.consumerPrices) === null || _product$consumerPric2 === void 0 ? void 0 : _product$consumerPric2.discountPercentage) !== null && _product$consumerPric !== void 0 ? _product$consumerPric : 0;
|
|
303
|
+
const cartDiscount = (_cartItem$consumerDis = cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerDiscountPercentage) !== null && _cartItem$consumerDis !== void 0 ? _cartItem$consumerDis : 0;
|
|
304
|
+
|
|
305
|
+
// If user hasn't touched and no stored discount, sync product default
|
|
306
|
+
if (!isTouched && !hasStoredDiscount && productDefault > 0) {
|
|
294
307
|
dispatch({
|
|
295
308
|
type: _OrderSessionContext.orderSessionActions.SET_CONSUMER_DISCOUNT_PERCENTAGE,
|
|
296
309
|
payload: {
|
|
297
|
-
articleNumber
|
|
298
|
-
percentage:
|
|
310
|
+
articleNumber,
|
|
311
|
+
percentage: productDefault,
|
|
312
|
+
userModified: false
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
} else if (cartDiscount > 0 && !hasStoredDiscount) {
|
|
316
|
+
// Sync non-zero cart values
|
|
317
|
+
dispatch({
|
|
318
|
+
type: _OrderSessionContext.orderSessionActions.SET_CONSUMER_DISCOUNT_PERCENTAGE,
|
|
319
|
+
payload: {
|
|
320
|
+
articleNumber,
|
|
321
|
+
percentage: cartDiscount,
|
|
322
|
+
userModified: false
|
|
299
323
|
}
|
|
300
324
|
});
|
|
301
325
|
}
|
|
302
326
|
});
|
|
303
|
-
}, [cart, consumerDiscounts, dispatch,
|
|
327
|
+
}, [cart, consumerDiscounts, touchedConsumerDiscounts, dispatch, products]);
|
|
304
328
|
(0, _react.useEffect)(() => {
|
|
305
329
|
const rateFromApi = totals === null || totals === void 0 ? void 0 : totals.montageRate;
|
|
306
330
|
const uiRate = (0, _montageRate.toUiMontageRate)(rateFromApi);
|
|
@@ -348,7 +372,7 @@ const ProductCartTable = () => {
|
|
|
348
372
|
};
|
|
349
373
|
}, [marketCorrection, totals]);
|
|
350
374
|
const getItemPrices = (cartItem, product) => {
|
|
351
|
-
var _product$
|
|
375
|
+
var _product$consumerPric6, _product$consumerPric7;
|
|
352
376
|
if (!cartItem) {
|
|
353
377
|
return {
|
|
354
378
|
purchasePrice: 0,
|
|
@@ -375,9 +399,9 @@ const ProductCartTable = () => {
|
|
|
375
399
|
// TMG-style case (used for TOGGLED_TMG display mode)
|
|
376
400
|
// This provides more robust price calculations with proper fallbacks
|
|
377
401
|
if (useTmgDisplayMode && isToggled && product !== null && product !== void 0 && product.consumerPrices) {
|
|
378
|
-
var _product$locationPric, _ref, _ref2, _product$
|
|
402
|
+
var _product$locationPric, _ref, _ref2, _product$consumerPric3, _product$consumerPric4;
|
|
379
403
|
const purchasePrice = locationTotal || Number((product === null || product === void 0 || (_product$locationPric = product.locationPrices) === null || _product$locationPric === void 0 ? void 0 : _product$locationPric.priceExclVat) || 0);
|
|
380
|
-
const salesPriceRaw = (_ref = (_ref2 = (_product$
|
|
404
|
+
const salesPriceRaw = (_ref = (_ref2 = (_product$consumerPric3 = product === null || product === void 0 || (_product$consumerPric4 = product.consumerPrices) === null || _product$consumerPric4 === void 0 ? void 0 : _product$consumerPric4.priceExclVat) !== null && _product$consumerPric3 !== void 0 ? _product$consumerPric3 : (cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerTotal) != null ? Number(cartItem.consumerTotal) / _cartTable.VAT_RATE : null) !== null && _ref2 !== void 0 ? _ref2 : product === null || product === void 0 ? void 0 : product.price) !== null && _ref !== void 0 ? _ref : 0;
|
|
381
405
|
const salesPrice = salesPriceRaw && !Number.isNaN(Number(salesPriceRaw)) ? Number(salesPriceRaw) : 0;
|
|
382
406
|
return {
|
|
383
407
|
purchasePrice,
|
|
@@ -395,12 +419,22 @@ const ProductCartTable = () => {
|
|
|
395
419
|
let salesPriceIncl = 0;
|
|
396
420
|
if (APP_CONFIG.internal) {
|
|
397
421
|
purchasePrice = locationTotal;
|
|
398
|
-
|
|
422
|
+
// When toggled, calculate sales price from cart's consumerTotal (backend-calculated with discount)
|
|
423
|
+
// Fall back to product's priceExclVat if cart doesn't have a value
|
|
424
|
+
if (isToggled) {
|
|
425
|
+
var _ref3, _product$consumerPric5;
|
|
426
|
+
const cartConsumerExcl = cartItem !== null && cartItem !== void 0 && cartItem.consumerTotal ? Number(cartItem.consumerTotal) / _cartTable.VAT_RATE : null;
|
|
427
|
+
salesPrice = (_ref3 = cartConsumerExcl !== null && cartConsumerExcl !== void 0 ? cartConsumerExcl : product === null || product === void 0 || (_product$consumerPric5 = product.consumerPrices) === null || _product$consumerPric5 === void 0 ? void 0 : _product$consumerPric5.priceExclVat) !== null && _ref3 !== void 0 ? _ref3 : 0;
|
|
428
|
+
} else {
|
|
429
|
+
salesPrice = hasLocationTotal ? locationTotal : (cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerTotal) || 0;
|
|
430
|
+
}
|
|
399
431
|
} else {
|
|
400
432
|
purchasePrice = (product === null || product === void 0 ? void 0 : product.price) || 0;
|
|
401
433
|
salesPrice = (product === null || product === void 0 ? void 0 : product.price) || 0;
|
|
402
434
|
}
|
|
403
|
-
|
|
435
|
+
|
|
436
|
+
// Use cart's consumerTotal first (reflects current discount), then fall back to product's priceInclVat
|
|
437
|
+
const consumerPriceInclVat = (cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerTotal) != null ? Number(cartItem.consumerTotal) : (_product$consumerPric6 = product === null || product === void 0 || (_product$consumerPric7 = product.consumerPrices) === null || _product$consumerPric7 === void 0 ? void 0 : _product$consumerPric7.priceInclVat) !== null && _product$consumerPric6 !== void 0 ? _product$consumerPric6 : 0;
|
|
404
438
|
const salesPriceNumber = Number(salesPrice) || 0;
|
|
405
439
|
salesPriceIncl = consumerPriceInclVat > 0 ? Number(consumerPriceInclVat) : salesPriceNumber > 0 ? salesPriceNumber * _cartTable.VAT_RATE : 0;
|
|
406
440
|
return {
|
|
@@ -431,13 +465,13 @@ const ProductCartTable = () => {
|
|
|
431
465
|
const extras = Object.keys(selectedExtras);
|
|
432
466
|
const rawAccessoireProducts = extras.length > 0 ? ((_products$Extras = products.Extras) === null || _products$Extras === void 0 ? void 0 : _products$Extras.filter(p => extras.includes(p.articleNumber.toString()))) || [] : [];
|
|
433
467
|
const enhanceProduct = product => {
|
|
434
|
-
var _cartItem$
|
|
468
|
+
var _cartItem$consumerDis2, _product$consumerPric8, _product$consumerPric9;
|
|
435
469
|
const cartItem = cartLookup === null || cartLookup === void 0 ? void 0 : cartLookup[product.articleNumber];
|
|
436
470
|
const priceInfo = getItemPrices(cartItem, product);
|
|
437
471
|
const storedDiscount = consumerDiscounts === null || consumerDiscounts === void 0 ? void 0 : consumerDiscounts[product.articleNumber];
|
|
438
472
|
const isTouched = (touchedConsumerDiscounts === null || touchedConsumerDiscounts === void 0 ? void 0 : touchedConsumerDiscounts[product.articleNumber]) === true;
|
|
439
|
-
const cartDiscount = (_cartItem$
|
|
440
|
-
const productDefault = (_product$
|
|
473
|
+
const cartDiscount = (_cartItem$consumerDis2 = cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerDiscountPercentage) !== null && _cartItem$consumerDis2 !== void 0 ? _cartItem$consumerDis2 : 0;
|
|
474
|
+
const productDefault = (_product$consumerPric8 = product === null || product === void 0 || (_product$consumerPric9 = product.consumerPrices) === null || _product$consumerPric9 === void 0 ? void 0 : _product$consumerPric9.discountPercentage) !== null && _product$consumerPric8 !== void 0 ? _product$consumerPric8 : 0;
|
|
441
475
|
|
|
442
476
|
// If user explicitly modified this discount, use stored value (even if 0)
|
|
443
477
|
// Otherwise use cart value if non-zero, else product default
|