thm-p3-configurator 0.0.288 → 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.
|
@@ -168,6 +168,7 @@ const ProductCartTable = () => {
|
|
|
168
168
|
selectedBranch,
|
|
169
169
|
vehicleCodingDiscountPercentage,
|
|
170
170
|
consumerDiscounts,
|
|
171
|
+
touchedConsumerDiscounts,
|
|
171
172
|
montageRate,
|
|
172
173
|
isMontageTariffFixed
|
|
173
174
|
}, dispatch] = (0, _OrderSessionContext.useOrderSession)();
|
|
@@ -207,7 +208,8 @@ const ProductCartTable = () => {
|
|
|
207
208
|
type: _OrderSessionContext.orderSessionActions.SET_CONSUMER_DISCOUNT_PERCENTAGE,
|
|
208
209
|
payload: {
|
|
209
210
|
articleNumber,
|
|
210
|
-
percentage: parsed
|
|
211
|
+
percentage: parsed,
|
|
212
|
+
userModified: true
|
|
211
213
|
}
|
|
212
214
|
});
|
|
213
215
|
if (isVehicleCoding) {
|
|
@@ -285,19 +287,44 @@ const ProductCartTable = () => {
|
|
|
285
287
|
const montageTotalExcl = Number((totals === null || totals === void 0 ? void 0 : totals.totalMontageExclVat) || 0);
|
|
286
288
|
const montageHourlyExcl = montageHours > 0 ? montageTotalExcl / montageHours : null;
|
|
287
289
|
(0, _react.useEffect)(() => {
|
|
288
|
-
if (!
|
|
289
|
-
|
|
290
|
-
|
|
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) {
|
|
291
307
|
dispatch({
|
|
292
308
|
type: _OrderSessionContext.orderSessionActions.SET_CONSUMER_DISCOUNT_PERCENTAGE,
|
|
293
309
|
payload: {
|
|
294
|
-
articleNumber
|
|
295
|
-
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
|
|
296
323
|
}
|
|
297
324
|
});
|
|
298
325
|
}
|
|
299
326
|
});
|
|
300
|
-
}, [cart, consumerDiscounts, dispatch,
|
|
327
|
+
}, [cart, consumerDiscounts, touchedConsumerDiscounts, dispatch, products]);
|
|
301
328
|
(0, _react.useEffect)(() => {
|
|
302
329
|
const rateFromApi = totals === null || totals === void 0 ? void 0 : totals.montageRate;
|
|
303
330
|
const uiRate = (0, _montageRate.toUiMontageRate)(rateFromApi);
|
|
@@ -345,7 +372,7 @@ const ProductCartTable = () => {
|
|
|
345
372
|
};
|
|
346
373
|
}, [marketCorrection, totals]);
|
|
347
374
|
const getItemPrices = (cartItem, product) => {
|
|
348
|
-
var _product$
|
|
375
|
+
var _product$consumerPric6, _product$consumerPric7;
|
|
349
376
|
if (!cartItem) {
|
|
350
377
|
return {
|
|
351
378
|
purchasePrice: 0,
|
|
@@ -372,9 +399,9 @@ const ProductCartTable = () => {
|
|
|
372
399
|
// TMG-style case (used for TOGGLED_TMG display mode)
|
|
373
400
|
// This provides more robust price calculations with proper fallbacks
|
|
374
401
|
if (useTmgDisplayMode && isToggled && product !== null && product !== void 0 && product.consumerPrices) {
|
|
375
|
-
var _product$locationPric, _ref, _ref2, _product$
|
|
402
|
+
var _product$locationPric, _ref, _ref2, _product$consumerPric3, _product$consumerPric4;
|
|
376
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);
|
|
377
|
-
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;
|
|
378
405
|
const salesPrice = salesPriceRaw && !Number.isNaN(Number(salesPriceRaw)) ? Number(salesPriceRaw) : 0;
|
|
379
406
|
return {
|
|
380
407
|
purchasePrice,
|
|
@@ -392,12 +419,22 @@ const ProductCartTable = () => {
|
|
|
392
419
|
let salesPriceIncl = 0;
|
|
393
420
|
if (APP_CONFIG.internal) {
|
|
394
421
|
purchasePrice = locationTotal;
|
|
395
|
-
|
|
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
|
+
}
|
|
396
431
|
} else {
|
|
397
432
|
purchasePrice = (product === null || product === void 0 ? void 0 : product.price) || 0;
|
|
398
433
|
salesPrice = (product === null || product === void 0 ? void 0 : product.price) || 0;
|
|
399
434
|
}
|
|
400
|
-
|
|
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;
|
|
401
438
|
const salesPriceNumber = Number(salesPrice) || 0;
|
|
402
439
|
salesPriceIncl = consumerPriceInclVat > 0 ? Number(consumerPriceInclVat) : salesPriceNumber > 0 ? salesPriceNumber * _cartTable.VAT_RATE : 0;
|
|
403
440
|
return {
|
|
@@ -428,10 +465,17 @@ const ProductCartTable = () => {
|
|
|
428
465
|
const extras = Object.keys(selectedExtras);
|
|
429
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()))) || [] : [];
|
|
430
467
|
const enhanceProduct = product => {
|
|
431
|
-
var
|
|
468
|
+
var _cartItem$consumerDis2, _product$consumerPric8, _product$consumerPric9;
|
|
432
469
|
const cartItem = cartLookup === null || cartLookup === void 0 ? void 0 : cartLookup[product.articleNumber];
|
|
433
470
|
const priceInfo = getItemPrices(cartItem, product);
|
|
434
|
-
const
|
|
471
|
+
const storedDiscount = consumerDiscounts === null || consumerDiscounts === void 0 ? void 0 : consumerDiscounts[product.articleNumber];
|
|
472
|
+
const isTouched = (touchedConsumerDiscounts === null || touchedConsumerDiscounts === void 0 ? void 0 : touchedConsumerDiscounts[product.articleNumber]) === true;
|
|
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;
|
|
475
|
+
|
|
476
|
+
// If user explicitly modified this discount, use stored value (even if 0)
|
|
477
|
+
// Otherwise use cart value if non-zero, else product default
|
|
478
|
+
const consumerDiscountPercentage = isTouched ? storedDiscount !== null && storedDiscount !== void 0 ? storedDiscount : 0 : cartDiscount || productDefault || 0;
|
|
435
479
|
return _objectSpread(_objectSpread({}, product), {}, {
|
|
436
480
|
priceInfo,
|
|
437
481
|
consumerDiscountPercentage
|
|
@@ -441,7 +485,7 @@ const ProductCartTable = () => {
|
|
|
441
485
|
mainProducts: rawMainProducts.map(enhanceProduct),
|
|
442
486
|
accessoireProducts: rawAccessoireProducts.map(enhanceProduct)
|
|
443
487
|
};
|
|
444
|
-
}, [products, selectedTowbar, selectedCombiset, selectedCableset, selectedBoardComputer, selectedExtras, cartLookup, consumerDiscounts, useTmgDisplayMode, isToggled]);
|
|
488
|
+
}, [products, selectedTowbar, selectedCombiset, selectedCableset, selectedBoardComputer, selectedExtras, cartLookup, consumerDiscounts, touchedConsumerDiscounts, useTmgDisplayMode, isToggled]);
|
|
445
489
|
|
|
446
490
|
// Calculate subtotals
|
|
447
491
|
const subtotals = (0, _react.useMemo)(() => {
|
|
@@ -136,6 +136,7 @@ const INITIAL_ORDER_SESSION_STATE = {
|
|
|
136
136
|
customerAgreed: undefined,
|
|
137
137
|
vehicleCodingDiscountPercentage: null,
|
|
138
138
|
consumerDiscounts: {},
|
|
139
|
+
touchedConsumerDiscounts: {},
|
|
139
140
|
montageRate: null,
|
|
140
141
|
isMontageTariffFixed: false,
|
|
141
142
|
vehicle: {
|
|
@@ -841,12 +842,16 @@ const orderSessionReducer = (state, action) => {
|
|
|
841
842
|
{
|
|
842
843
|
const {
|
|
843
844
|
articleNumber,
|
|
844
|
-
percentage
|
|
845
|
+
percentage,
|
|
846
|
+
userModified = false
|
|
845
847
|
} = action.payload;
|
|
846
848
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
847
849
|
consumerDiscounts: _objectSpread(_objectSpread({}, state.consumerDiscounts), {}, {
|
|
848
850
|
[articleNumber]: percentage
|
|
849
851
|
}),
|
|
852
|
+
touchedConsumerDiscounts: userModified ? _objectSpread(_objectSpread({}, state.touchedConsumerDiscounts), {}, {
|
|
853
|
+
[articleNumber]: true
|
|
854
|
+
}) : state.touchedConsumerDiscounts,
|
|
850
855
|
isTouched: true
|
|
851
856
|
});
|
|
852
857
|
}
|