thm-p3-configurator 0.0.289 → 0.0.291
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.
|
@@ -148,7 +148,8 @@ const ProductCartSide = () => {
|
|
|
148
148
|
* @param {Object} cartItem - Cart item object
|
|
149
149
|
* @return {Object} Calculated prices for the item
|
|
150
150
|
*/
|
|
151
|
-
const getItemPrices = cartItem => {
|
|
151
|
+
const getItemPrices = (cartItem, product) => {
|
|
152
|
+
var _ref, _consumerPrices$price, _product$price;
|
|
152
153
|
if (!cartItem) {
|
|
153
154
|
return {
|
|
154
155
|
purchasePrice: 0,
|
|
@@ -158,10 +159,14 @@ const ProductCartSide = () => {
|
|
|
158
159
|
};
|
|
159
160
|
}
|
|
160
161
|
const hasLocationTotal = (cartItem === null || cartItem === void 0 ? void 0 : cartItem.locationTotal) !== undefined && (cartItem === null || cartItem === void 0 ? void 0 : cartItem.locationTotal) !== null;
|
|
162
|
+
const consumerPrices = (product === null || product === void 0 ? void 0 : product.consumerPrices) || null;
|
|
163
|
+
const consumerPriceIncl = (_ref = (_consumerPrices$price = consumerPrices === null || consumerPrices === void 0 ? void 0 : consumerPrices.priceInclVat) !== null && _consumerPrices$price !== void 0 ? _consumerPrices$price : cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerTotal) !== null && _ref !== void 0 ? _ref : null;
|
|
164
|
+
const fallbackSalesPrice = (_product$price = product === null || product === void 0 ? void 0 : product.price) !== null && _product$price !== void 0 ? _product$price : 0;
|
|
165
|
+
const resolvedSalesPrice = consumerPriceIncl !== null && consumerPriceIncl !== undefined ? Number(consumerPriceIncl) : Number(fallbackSalesPrice) || 0;
|
|
161
166
|
|
|
162
167
|
// Get prices directly from product objects and calculate excl VAT for location
|
|
163
168
|
const purchasePrice = hasLocationTotal ? cartItem.locationTotal : 0;
|
|
164
|
-
const salesPrice =
|
|
169
|
+
const salesPrice = resolvedSalesPrice;
|
|
165
170
|
const margin = hasLocationTotal ? salesPrice - purchasePrice : 0;
|
|
166
171
|
const marginPercentage = purchasePrice ? margin / purchasePrice * 100 : 0;
|
|
167
172
|
return {
|
|
@@ -209,7 +214,7 @@ const ProductCartSide = () => {
|
|
|
209
214
|
const {
|
|
210
215
|
purchasePrice,
|
|
211
216
|
salesPrice
|
|
212
|
-
} = getItemPrices(cartItem);
|
|
217
|
+
} = getItemPrices(cartItem, product);
|
|
213
218
|
const isBoardComputerProduct = selectedBoardComputer && String(product.articleNumber) === String(selectedBoardComputer);
|
|
214
219
|
const mainRowPriceText = isToggled ? isBoardComputerProduct && Number(purchasePrice) <= 0 ? 'N.v.t.' : (0, _helpers__.formatPrice)(purchasePrice) : (0, _helpers__.formatPrice)(salesPrice);
|
|
215
220
|
return /*#__PURE__*/_react.default.createElement(_ProductTableStaticRow.default, {
|
|
@@ -245,7 +250,7 @@ const ProductCartSide = () => {
|
|
|
245
250
|
const {
|
|
246
251
|
purchasePrice,
|
|
247
252
|
salesPrice
|
|
248
|
-
} = getItemPrices(cartItem);
|
|
253
|
+
} = getItemPrices(cartItem, product);
|
|
249
254
|
const quantity = selectedExtras[product.articleNumber] || 1;
|
|
250
255
|
const price = isToggled ? purchasePrice : salesPrice;
|
|
251
256
|
const accessoryPriceText = isToggled && Number(purchasePrice) <= 0 ? 'N.v.t.' : (0, _helpers__.formatPrice)(price);
|
|
@@ -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) {
|
|
307
|
+
dispatch({
|
|
308
|
+
type: _OrderSessionContext.orderSessionActions.SET_CONSUMER_DISCOUNT_PERCENTAGE,
|
|
309
|
+
payload: {
|
|
310
|
+
articleNumber,
|
|
311
|
+
percentage: productDefault,
|
|
312
|
+
userModified: false
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
} else if (cartDiscount > 0 && !hasStoredDiscount) {
|
|
316
|
+
// Sync non-zero cart values
|
|
294
317
|
dispatch({
|
|
295
318
|
type: _OrderSessionContext.orderSessionActions.SET_CONSUMER_DISCOUNT_PERCENTAGE,
|
|
296
319
|
payload: {
|
|
297
|
-
articleNumber
|
|
298
|
-
percentage:
|
|
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
|
|
@@ -606,9 +640,6 @@ const ProductCartTable = () => {
|
|
|
606
640
|
const montageRateCellOverrides = APP_CONFIG.internal && !isThc && renderMontageRateInput ? displayMode === _cartTable.CART_TABLE_DISPLAY_MODES.TOGGLED_STANDARD ? {
|
|
607
641
|
// Show input in discount column; keep price column as price
|
|
608
642
|
discountCell: montageRateInputCell
|
|
609
|
-
} : displayMode === _cartTable.CART_TABLE_DISPLAY_MODES.DEFAULT ? {
|
|
610
|
-
// In default view, show input in the same column as vehicle coding
|
|
611
|
-
discountCell: montageRateInputCell
|
|
612
643
|
} : {} : {};
|
|
613
644
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
614
645
|
className: (0, _helpers__.withStyle)('content col-lg')
|
|
@@ -641,7 +672,7 @@ const ProductCartTable = () => {
|
|
|
641
672
|
})),
|
|
642
673
|
className: _cartTable.CART_TABLE_PRICE_CELL_CLASS
|
|
643
674
|
} : {};
|
|
644
|
-
const vehicleCodingInputCell = displayMode === _cartTable.CART_TABLE_DISPLAY_MODES.
|
|
675
|
+
const vehicleCodingInputCell = displayMode === _cartTable.CART_TABLE_DISPLAY_MODES.TOGGLED_STANDARD && isTowmotive && isVehicleCodingProduct ? {
|
|
645
676
|
text: renderVehicleCodingInput(product.articleNumber),
|
|
646
677
|
className: _cartTable.CART_TABLE_PRICE_CELL_CLASS
|
|
647
678
|
} : {};
|
|
@@ -772,6 +803,6 @@ const ProductCartTable = () => {
|
|
|
772
803
|
value: (0, _helpers__.formatPrice)(totals === null || totals === void 0 ? void 0 : totals.totalAfterDiscountInclVat),
|
|
773
804
|
className: 'fw-bold text-end'
|
|
774
805
|
}, showCatalogPrice)]
|
|
775
|
-
})))), APP_CONFIG.internal && /*#__PURE__*/_react.default.createElement(_InternalDiscountForm.default, null)));
|
|
806
|
+
})))), APP_CONFIG.internal && isToggled && /*#__PURE__*/_react.default.createElement(_InternalDiscountForm.default, null)));
|
|
776
807
|
};
|
|
777
808
|
var _default = exports.default = ProductCartTable;
|
|
@@ -319,7 +319,7 @@ const ProductsOverview = () => {
|
|
|
319
319
|
product: a,
|
|
320
320
|
category: productCategory
|
|
321
321
|
}) ? -1 : 0).map(product => {
|
|
322
|
-
var _product$images, _product$images2, _product$locationPric;
|
|
322
|
+
var _product$images, _product$images2, _product$locationPric, _product$consumerPric2, _product$consumerPric3;
|
|
323
323
|
const isRecommended = (0, _product.checkIfTowbarIsRecommended)({
|
|
324
324
|
product,
|
|
325
325
|
category: productCategory
|
|
@@ -392,7 +392,7 @@ const ProductsOverview = () => {
|
|
|
392
392
|
},
|
|
393
393
|
productSpecifications: (0, _product.extractProductSpecsArray)(product),
|
|
394
394
|
showPrice: APP_CONFIG.internal ? true : false,
|
|
395
|
-
productPrice: product.price
|
|
395
|
+
productPrice: (_product$consumerPric2 = product === null || product === void 0 || (_product$consumerPric3 = product.consumerPrices) === null || _product$consumerPric3 === void 0 ? void 0 : _product$consumerPric3.priceInclVat) !== null && _product$consumerPric2 !== void 0 ? _product$consumerPric2 : product.price
|
|
396
396
|
});
|
|
397
397
|
}));
|
|
398
398
|
}));
|