thm-p3-configurator 0.0.349 → 0.0.352

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.
@@ -162,6 +162,15 @@ const authenticatedProxyApi = exports.authenticatedProxyApi = {
162
162
  method: 'GET'
163
163
  });
164
164
  },
165
+ getBusinessBranches: _ref2 => {
166
+ let {
167
+ searchTerm,
168
+ formula
169
+ } = _ref2;
170
+ return authenticatedClient("api/v1/branches/zakelijk?searchTerm=".concat(searchTerm, "&formula=").concat(formula), {
171
+ method: 'GET'
172
+ });
173
+ },
165
174
  getMyBranchesByFormula: formula => authenticatedClient("api/v1/profile/".concat(formula, "/branches"), {
166
175
  method: 'GET'
167
176
  }),
@@ -183,23 +192,23 @@ const authenticatedProxyApi = exports.authenticatedProxyApi = {
183
192
  getAppointmentRequestById: id => authenticatedClient("api/v1/appointment-requests/".concat(id), {
184
193
  method: 'GET'
185
194
  }),
186
- getDossiers: _ref2 => {
195
+ getDossiers: _ref3 => {
187
196
  let {
188
197
  term,
189
198
  offset = 0,
190
199
  limit = 10,
191
200
  branchId,
192
201
  formula
193
- } = _ref2;
202
+ } = _ref3;
194
203
  return authenticatedClient("api/v1/dossiers?term=".concat(term, "&offset=").concat(offset, "&limit=").concat(limit).concat(branchId ? "&branchId=".concat(branchId) : '').concat(formula ? "&formula=".concat(formula) : ''), {
195
204
  method: 'GET'
196
205
  });
197
206
  },
198
- putDossierById: _ref3 => {
207
+ putDossierById: _ref4 => {
199
208
  let {
200
209
  id,
201
210
  payload
202
- } = _ref3;
211
+ } = _ref4;
203
212
  return authenticatedClient("api/v1/dossiers/".concat(id), {
204
213
  method: 'PUT',
205
214
  data: payload
@@ -237,11 +246,11 @@ const authenticatedProxyApi = exports.authenticatedProxyApi = {
237
246
  'Content-Type': 'application/json'
238
247
  }
239
248
  }),
240
- putQuotationById: _ref4 => {
249
+ putQuotationById: _ref5 => {
241
250
  let {
242
251
  payload,
243
252
  id
244
- } = _ref4;
253
+ } = _ref5;
245
254
  return authenticatedClient("api/v1/quotations/".concat(id), {
246
255
  method: 'PUT',
247
256
  data: payload,
@@ -250,11 +259,11 @@ const authenticatedProxyApi = exports.authenticatedProxyApi = {
250
259
  }
251
260
  });
252
261
  },
253
- putAppointmentById: _ref5 => {
262
+ putAppointmentById: _ref6 => {
254
263
  let {
255
264
  payload,
256
265
  id
257
- } = _ref5;
266
+ } = _ref6;
258
267
  return authenticatedClient("api/v1/appointments/".concat(id), {
259
268
  method: 'PUT',
260
269
  data: payload,
@@ -263,11 +272,11 @@ const authenticatedProxyApi = exports.authenticatedProxyApi = {
263
272
  }
264
273
  });
265
274
  },
266
- putAppointmentRequestById: _ref6 => {
275
+ putAppointmentRequestById: _ref7 => {
267
276
  let {
268
277
  payload,
269
278
  id
270
- } = _ref6;
279
+ } = _ref7;
271
280
  return authenticatedClient("api/v1/appointment-requests/".concat(id, "?action=order"), {
272
281
  method: 'PUT',
273
282
  data: payload,
@@ -276,12 +285,12 @@ const authenticatedProxyApi = exports.authenticatedProxyApi = {
276
285
  }
277
286
  });
278
287
  },
279
- getActiveDiscounts: _ref7 => {
288
+ getActiveDiscounts: _ref8 => {
280
289
  let {
281
290
  formulaCode,
282
291
  limit,
283
292
  offset
284
- } = _ref7;
293
+ } = _ref8;
285
294
  return authenticatedClient("api/v1/discounts?limit=".concat(limit, "&offset=").concat(offset, "&formulaCode=").concat(formulaCode), {
286
295
  method: 'GET',
287
296
  headers: {
@@ -16,7 +16,7 @@ require("core-js/modules/web.url-search-params.js");
16
16
  Object.defineProperty(exports, "__esModule", {
17
17
  value: true
18
18
  });
19
- exports.useSingleOrderCart = exports.useSingleOrderBranchesQuery = exports.useSingleOrderBranchTypes = exports.useSingleOrderArticles = exports.useQuestionsQuery = exports.useProductsQuery = exports.useProductFieldLabels = exports.usePrivateDossierByTypeAndIdQuery = exports.usePartBrands = exports.useOrderDataQuery = exports.useMyBranches = exports.useModelsQuery = exports.useMarketingChannels = exports.useCountriesQuery = exports.useBuildYearsQuery = exports.useBrandsQuery = exports.useBranchesQuery = exports.useBranchesByType = exports.useBranchTypes = exports.useBranchByIdOrWidgetId = exports.useArticleTypes = exports.useArticleSubGroups = exports.useArticleGroups = exports.useActiveDiscounts = void 0;
19
+ exports.useSingleOrderCart = exports.useSingleOrderBranchesQuery = exports.useSingleOrderBranchTypes = exports.useSingleOrderArticles = exports.useQuestionsQuery = exports.useProductsQuery = exports.useProductFieldLabels = exports.usePrivateDossierByTypeAndIdQuery = exports.usePartBrands = exports.useOrderDataQuery = exports.useMyBranches = exports.useModelsQuery = exports.useMarketingChannels = exports.useCountriesQuery = exports.useBusinessBranches = exports.useBuildYearsQuery = exports.useBrandsQuery = exports.useBranchesQuery = exports.useBranchesByType = exports.useBranchTypes = exports.useBranchByIdOrWidgetId = exports.useArticleTypes = exports.useArticleSubGroups = exports.useArticleGroups = exports.useActiveDiscounts = void 0;
20
20
  require("core-js/modules/es.symbol.description.js");
21
21
  require("core-js/modules/es.array.sort.js");
22
22
  require("core-js/modules/es.json.stringify.js");
@@ -710,11 +710,38 @@ const useBranchesByType = _ref4 => {
710
710
  branchesByType: branchesByTypeQuery === null || branchesByTypeQuery === void 0 ? void 0 : branchesByTypeQuery.data
711
711
  };
712
712
  };
713
+ exports.useBranchesByType = useBranchesByType;
714
+ const useBusinessBranches = _ref5 => {
715
+ let {
716
+ searchTerm,
717
+ formula: formulaRaw,
718
+ enabled = true
719
+ } = _ref5;
720
+ const formula = formulaRaw == null ? undefined : typeof formulaRaw === 'string' ? formulaRaw : formulaRaw === null || formulaRaw === void 0 ? void 0 : formulaRaw.entityId;
721
+ const businessBranchesQuery = (0, _reactQuery.useQuery)(['businessBranches', searchTerm, formula], {
722
+ queryFn: async () => {
723
+ const response = await _authenticatedProxyApi.authenticatedProxyApi.getBusinessBranches({
724
+ searchTerm,
725
+ formula
726
+ });
727
+ if (response.data.length === 0) {
728
+ return null;
729
+ }
730
+ return response.data;
731
+ },
732
+ enabled: enabled && !!searchTerm && searchTerm.length >= 2
733
+ });
734
+ return {
735
+ isLoadingBusinessBranches: businessBranchesQuery.isLoading,
736
+ businessBranchesError: businessBranchesQuery.isError,
737
+ businessBranches: businessBranchesQuery === null || businessBranchesQuery === void 0 ? void 0 : businessBranchesQuery.data
738
+ };
739
+ };
713
740
 
714
741
  /**
715
742
  * @description finds a branch either by its Id, or its widget id
716
743
  */
717
- exports.useBranchesByType = useBranchesByType;
744
+ exports.useBusinessBranches = useBusinessBranches;
718
745
  const useBranchByIdOrWidgetId = exports.useBranchByIdOrWidgetId = function useBranchByIdOrWidgetId() {
719
746
  let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
720
747
  const branchByIdQuery = (0, _reactQuery.useQuery)(['branchById', id], {
@@ -797,11 +824,11 @@ const useBranchTypes = () => {
797
824
  * Available types: Quotation, appointment request and planned appointment.
798
825
  */
799
826
  exports.useBranchTypes = useBranchTypes;
800
- const usePrivateDossierByTypeAndIdQuery = _ref5 => {
827
+ const usePrivateDossierByTypeAndIdQuery = _ref6 => {
801
828
  let {
802
829
  dossierId,
803
830
  dossierType
804
- } = _ref5;
831
+ } = _ref6;
805
832
  const dossierByIdQuery = (0, _reactQuery.useQuery)([dossierType, dossierId], {
806
833
  enabled: !!dossierId && !!dossierType,
807
834
  cacheTime: 0,
@@ -849,12 +876,12 @@ const usePrivateDossierByTypeAndIdQuery = _ref5 => {
849
876
  * @description Query the discounts from Hyper, allows for pagination and filtering with formula
850
877
  */
851
878
  exports.usePrivateDossierByTypeAndIdQuery = usePrivateDossierByTypeAndIdQuery;
852
- const useActiveDiscounts = _ref6 => {
879
+ const useActiveDiscounts = _ref7 => {
853
880
  let {
854
881
  formulaCode,
855
882
  offset,
856
883
  limit
857
- } = _ref6;
884
+ } = _ref7;
858
885
  const {
859
886
  authenticated,
860
887
  initialized
@@ -178,9 +178,9 @@ const ProductCartSide = () => {
178
178
  }
179
179
  const hasLocationTotal = (cartItem === null || cartItem === void 0 ? void 0 : cartItem.locationTotal) !== undefined && (cartItem === null || cartItem === void 0 ? void 0 : cartItem.locationTotal) !== null;
180
180
 
181
- // GetOrder is the single source of truth for prices
182
- // Fallback to cartItem.consumerTotal for articles without price (e.g. boardComputerUpdate)
183
- const resolvedSalesPrice = Number(product === null || product === void 0 ? void 0 : product.price) || Number(cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerTotal) || 0;
181
+ // GetOrder is the single source of truth for row prices after discounts.
182
+ // Fall back to enriched product pricing only when the order response has no consumer total yet.
183
+ const resolvedSalesPrice = (cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerTotal) != null ? Number(cartItem.consumerTotal) : Number(product === null || product === void 0 ? void 0 : product.price) || 0;
184
184
 
185
185
  // Get prices directly from product objects and calculate excl VAT for location
186
186
  const purchasePrice = hasLocationTotal ? cartItem.locationTotal : 0;
@@ -403,9 +403,9 @@ const ProductCartTable = () => {
403
403
  }
404
404
  const hasLocationTotal = (cartItem === null || cartItem === void 0 ? void 0 : cartItem.locationTotal) !== undefined && (cartItem === null || cartItem === void 0 ? void 0 : cartItem.locationTotal) !== null;
405
405
 
406
- // GetOrder is the single source of truth for prices
407
- // Fallback to cartItem.consumerTotal for articles without price (e.g. boardComputerUpdate)
408
- const salesPriceIncl = Number(product === null || product === void 0 ? void 0 : product.price) || Number(cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerTotal) || 0;
406
+ // GetOrder is the single source of truth for row prices after discounts.
407
+ // Fall back to enriched product pricing only when the order response has no consumer total yet.
408
+ const salesPriceIncl = (cartItem === null || cartItem === void 0 ? void 0 : cartItem.consumerTotal) != null ? Number(cartItem.consumerTotal) : Number(product === null || product === void 0 ? void 0 : product.price) || 0;
409
409
  const salesPrice = salesPriceIncl / _cartTable.VAT_RATE;
410
410
  const purchasePrice = hasLocationTotal ? Number(cartItem.locationTotal) : null;
411
411
 
@@ -669,7 +669,7 @@ const ProductCartTable = () => {
669
669
  var _product$consumerDisc, _product$images, _product$images2;
670
670
  const isVehicleCodingProduct = (product === null || product === void 0 ? void 0 : product.subgroupName) === _constants__.VEHICLE_CODING_SUBGROUP_NAME || (product === null || product === void 0 ? void 0 : product.groupName) === _constants__.VEHICLE_CODING_SUBGROUP_NAME;
671
671
  const isBoardComputerProduct = selectedBoardComputer && String(product.articleNumber) === String(selectedBoardComputer);
672
- const stateDiscountValue = (_product$consumerDisc = product === null || product === void 0 ? void 0 : product.consumerDiscountPercentage) !== null && _product$consumerDisc !== void 0 ? _product$consumerDisc : isVehicleCodingProduct ? vehicleCodingDiscountPercentage || null : null;
672
+ const stateDiscountValue = (_product$consumerDisc = product === null || product === void 0 ? void 0 : product.consumerDiscountPercentage) !== null && _product$consumerDisc !== void 0 ? _product$consumerDisc : isVehicleCodingProduct ? vehicleCodingDiscountPercentage !== null && vehicleCodingDiscountPercentage !== void 0 ? vehicleCodingDiscountPercentage : null : null;
673
673
  const lineDiscountValue = stateDiscountValue;
674
674
  const allowLineDiscountMain = displayMode === _cartTable.CART_TABLE_DISPLAY_MODES.TOGGLED_STANDARD && (isTowmotive || isTowFormula);
675
675
  const discountInputCellMain = allowLineDiscountMain ? {
@@ -198,7 +198,7 @@ const getEmptyCustomerState = () => ({
198
198
  zakelijkContactEMailadres: ''
199
199
  });
200
200
  const InternalAppointmentForm = _ref => {
201
- var _branchTypes$byId$aut, _authSession$branch, _contextCustomer$note2;
201
+ var _branchTypes$byId$aut, _authSession$branch, _authSession$branch2, _contextCustomer$note2;
202
202
  let {
203
203
  onSubmit = payload => {},
204
204
  isError = false,
@@ -433,6 +433,7 @@ const InternalAppointmentForm = _ref => {
433
433
  }
434
434
  }, [customer === null || customer === void 0 ? void 0 : customer.countryId, countryOptions, dispatch]);
435
435
  const isBusinessOwnership = activeOwnershipType === _constants__.VEHICLE_OWNERSHIP_TYPE.Zakelijk;
436
+ const isLeaseOwnership = activeOwnershipType === _constants__.VEHICLE_OWNERSHIP_TYPE.Leasemaatschappij;
436
437
  const isNetherlandsSelected = (0, _react.useMemo)(() => {
437
438
  if (!(selectedCountry !== null && selectedCountry !== void 0 && selectedCountry.label)) return false;
438
439
  return selectedCountry.label.toUpperCase() === 'NEDERLAND';
@@ -635,11 +636,19 @@ const InternalAppointmentForm = _ref => {
635
636
  } = (0, _queries.useBranchesByType)({
636
637
  isTmg,
637
638
  isTowCenterBranch,
638
- searchTerm: companySearchTerm,
639
+ searchTerm: isLeaseOwnership ? companySearchTerm : '',
639
640
  formula,
640
641
  ownershipType: activeOwnershipType,
641
642
  organisationType: branchType
642
643
  });
644
+ const {
645
+ businessBranches,
646
+ isLoadingBusinessBranches
647
+ } = (0, _queries.useBusinessBranches)({
648
+ searchTerm: companySearchTerm,
649
+ formula: authSession === null || authSession === void 0 || (_authSession$branch2 = authSession.branch) === null || _authSession$branch2 === void 0 ? void 0 : _authSession$branch2.formule,
650
+ enabled: isBusinessOwnership
651
+ });
643
652
 
644
653
  /**
645
654
  * @description Autofills the customer form with the current branch data where applicable
@@ -835,7 +844,7 @@ const InternalAppointmentForm = _ref => {
835
844
  form: "quotation",
836
845
  label: "Leasemaatschappij:",
837
846
  errorMessage: errors === null || errors === void 0 ? void 0 : errors['companyName']
838
- }), isCompanyInputFocused && companySearchTerm && companySearchTerm.length >= 3 && branchesByType && branchesByType.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
847
+ }), isCompanyInputFocused && companySearchTerm && companySearchTerm.length >= 3 && businessBranches && businessBranches.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
839
848
  className: (0, _helpers__.withStyle)('dropdown-results position-absolute w-100 border rounded bg-white shadow'),
840
849
  style: {
841
850
  maxHeight: '200px',
@@ -848,9 +857,9 @@ const InternalAppointmentForm = _ref => {
848
857
  onMouseDown: e => {
849
858
  e.preventDefault();
850
859
  }
851
- }, isLoadingBranchesByType && /*#__PURE__*/_react.default.createElement("div", {
860
+ }, isLoadingBusinessBranches && /*#__PURE__*/_react.default.createElement("div", {
852
861
  className: (0, _helpers__.withStyle)('p-2 text-center')
853
- }, /*#__PURE__*/_react.default.createElement("span", null, "Zoeken...")), branchesByType.map(branch => /*#__PURE__*/_react.default.createElement("div", {
862
+ }, /*#__PURE__*/_react.default.createElement("span", null, "Zoeken...")), businessBranches.map(branch => /*#__PURE__*/_react.default.createElement("div", {
854
863
  key: branch.entityId,
855
864
  className: (0, _helpers__.withStyle)('dropdown-item p-2 border-bottom'),
856
865
  style: {
@@ -1090,7 +1099,7 @@ const InternalAppointmentForm = _ref => {
1090
1099
  form: "quotation",
1091
1100
  label: "Bedrijfsnaam:",
1092
1101
  errorMessage: errors === null || errors === void 0 ? void 0 : errors['companyName']
1093
- }), isCompanyInputFocused && companySearchTerm && companySearchTerm.length >= 3 && branchesByType && branchesByType.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
1102
+ }), isCompanyInputFocused && companySearchTerm && companySearchTerm.length >= 3 && businessBranches && businessBranches.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
1094
1103
  className: (0, _helpers__.withStyle)('dropdown-results position-absolute w-100 border rounded bg-white shadow'),
1095
1104
  style: {
1096
1105
  maxHeight: '200px',
@@ -1103,9 +1112,9 @@ const InternalAppointmentForm = _ref => {
1103
1112
  onMouseDown: e => {
1104
1113
  e.preventDefault();
1105
1114
  }
1106
- }, isLoadingBranchesByType && /*#__PURE__*/_react.default.createElement("div", {
1115
+ }, isLoadingBusinessBranches && /*#__PURE__*/_react.default.createElement("div", {
1107
1116
  className: (0, _helpers__.withStyle)('p-2 text-center')
1108
- }, /*#__PURE__*/_react.default.createElement("span", null, "Zoeken...")), branchesByType.map(branch => /*#__PURE__*/_react.default.createElement("div", {
1117
+ }, /*#__PURE__*/_react.default.createElement("span", null, "Zoeken...")), businessBranches.map(branch => /*#__PURE__*/_react.default.createElement("div", {
1109
1118
  key: branch.entityId,
1110
1119
  className: (0, _helpers__.withStyle)('dropdown-item p-2 border-bottom'),
1111
1120
  style: {
@@ -185,7 +185,7 @@ const internalQuotationFormSchema = (0, _yup.object)({
185
185
  })
186
186
  });
187
187
  const InternalQuotationForm = _ref => {
188
- var _branchTypes$byId$aut, _authSession$branch, _contextCustomer$note2;
188
+ var _branchTypes$byId$aut, _authSession$branch, _authSession$branch2, _contextCustomer$note2;
189
189
  let {
190
190
  onSubmit = payload => {},
191
191
  isError = false,
@@ -377,17 +377,27 @@ const InternalQuotationForm = _ref => {
377
377
  }, [isTmg, marketingChannels, channel === null || channel === void 0 ? void 0 : channel.channelId, dispatch]);
378
378
  const formula = (0, _FormulaContext.useFormula)();
379
379
  const isTowmotive = (0, _useIsTowmotive.useIsTowmotive)();
380
+ const isBusinessOwnership = activeOwnershipType === _constants__.VEHICLE_OWNERSHIP_TYPE.Zakelijk;
381
+ const isLeaseOwnership = activeOwnershipType === _constants__.VEHICLE_OWNERSHIP_TYPE.Leasemaatschappij;
380
382
  const {
381
383
  branchesByType,
382
384
  isLoadingBranchesByType
383
385
  } = (0, _queries.useBranchesByType)({
384
386
  isTmg,
385
387
  isTowCenterBranch,
386
- searchTerm: companySearchTerm,
388
+ searchTerm: isLeaseOwnership ? companySearchTerm : '',
387
389
  formula,
388
390
  ownershipType: activeOwnershipType,
389
391
  organisationType: branchType
390
392
  });
393
+ const {
394
+ businessBranches,
395
+ isLoadingBusinessBranches
396
+ } = (0, _queries.useBusinessBranches)({
397
+ searchTerm: companySearchTerm,
398
+ formula: authSession === null || authSession === void 0 || (_authSession$branch2 = authSession.branch) === null || _authSession$branch2 === void 0 ? void 0 : _authSession$branch2.formule,
399
+ enabled: isBusinessOwnership
400
+ });
391
401
  const countryOptions = (0, _react.useMemo)(() => {
392
402
  var _countries$results;
393
403
  if (!(countries !== null && countries !== void 0 && (_countries$results = countries.results) !== null && _countries$results !== void 0 && _countries$results.length)) return [];
@@ -720,7 +730,7 @@ const InternalQuotationForm = _ref => {
720
730
  form: "quotation",
721
731
  label: "Bedrijfsnaam:",
722
732
  errorMessage: errors === null || errors === void 0 ? void 0 : errors['companyName']
723
- }), isCompanyInputFocused && companySearchTerm && companySearchTerm.length >= 3 && branchesByType && branchesByType.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
733
+ }), isCompanyInputFocused && companySearchTerm && companySearchTerm.length >= 3 && businessBranches && businessBranches.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
724
734
  className: (0, _helpers__.withStyle)('dropdown-results position-absolute w-100 border rounded bg-white shadow'),
725
735
  style: {
726
736
  maxHeight: '200px',
@@ -733,9 +743,9 @@ const InternalQuotationForm = _ref => {
733
743
  onMouseDown: e => {
734
744
  e.preventDefault();
735
745
  }
736
- }, isLoadingBranchesByType && /*#__PURE__*/_react.default.createElement("div", {
746
+ }, isLoadingBusinessBranches && /*#__PURE__*/_react.default.createElement("div", {
737
747
  className: (0, _helpers__.withStyle)('p-2 text-center')
738
- }, /*#__PURE__*/_react.default.createElement("span", null, "Zoeken...")), branchesByType.map(branch => /*#__PURE__*/_react.default.createElement("div", {
748
+ }, /*#__PURE__*/_react.default.createElement("span", null, "Zoeken...")), businessBranches.map(branch => /*#__PURE__*/_react.default.createElement("div", {
739
749
  key: branch.entityId,
740
750
  className: (0, _helpers__.withStyle)('dropdown-item p-2 border-bottom'),
741
751
  style: {
@@ -2,11 +2,13 @@
2
2
 
3
3
  require("core-js/modules/es.symbol.description.js");
4
4
  require("core-js/modules/es.array.flat-map.js");
5
+ require("core-js/modules/es.array.includes.js");
5
6
  require("core-js/modules/es.array.unscopables.flat-map.js");
6
7
  require("core-js/modules/es.json.stringify.js");
7
8
  require("core-js/modules/es.object.from-entries.js");
8
9
  require("core-js/modules/es.promise.js");
9
10
  require("core-js/modules/es.regexp.to-string.js");
11
+ require("core-js/modules/es.string.includes.js");
10
12
  require("core-js/modules/esnext.iterator.constructor.js");
11
13
  require("core-js/modules/esnext.iterator.filter.js");
12
14
  require("core-js/modules/esnext.iterator.find.js");
@@ -15,6 +17,8 @@ require("core-js/modules/esnext.iterator.for-each.js");
15
17
  require("core-js/modules/esnext.iterator.map.js");
16
18
  require("core-js/modules/web.dom-collections.iterator.js");
17
19
  require("core-js/modules/web.url-search-params.js");
20
+ require("core-js/modules/es.array.includes.js");
21
+ require("core-js/modules/es.string.includes.js");
18
22
  require("core-js/modules/esnext.iterator.for-each.js");
19
23
  Object.defineProperty(exports, "__esModule", {
20
24
  value: true
@@ -39,11 +43,32 @@ var _index = require("./index");
39
43
  var _thLogoBlack = _interopRequireDefault(require("../../../public/assets/images/th-logo-black.png"));
40
44
  var _index2 = require("../__constants__/index");
41
45
  var _image = require("../__helpers__/image");
46
+ const _excluded = ["pricingPartNumber"];
42
47
  function _interopRequireDefault(e) {
43
48
  return e && e.__esModule ? e : {
44
49
  default: e
45
50
  };
46
51
  }
52
+ function _objectWithoutProperties(e, t) {
53
+ if (null == e) return {};
54
+ var o,
55
+ r,
56
+ i = _objectWithoutPropertiesLoose(e, t);
57
+ if (Object.getOwnPropertySymbols) {
58
+ var s = Object.getOwnPropertySymbols(e);
59
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
60
+ }
61
+ return i;
62
+ }
63
+ function _objectWithoutPropertiesLoose(r, e) {
64
+ if (null == r) return {};
65
+ var t = {};
66
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
67
+ if (e.includes(n)) continue;
68
+ t[n] = r[n];
69
+ }
70
+ return t;
71
+ }
47
72
  function ownKeys(e, r) {
48
73
  var t = Object.keys(e);
49
74
  if (Object.getOwnPropertySymbols) {
@@ -239,7 +264,18 @@ const fetchPartStockLevels = exports.fetchPartStockLevels = async function fetch
239
264
  * @returns {Object} The articles
240
265
  */
241
266
  const enrichArticlesWithBrandsAndPrices = exports.enrichArticlesWithBrandsAndPrices = async function enrichArticlesWithBrandsAndPrices(articles, branchId) {
267
+ var _pricesResponse$data;
242
268
  let formula = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
269
+ const findBrandDataForArticle = function findBrandDataForArticle(article) {
270
+ var _brandRecords$find;
271
+ let brandRecords = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
272
+ return (_brandRecords$find = brandRecords.find(brand => brand.entityId === article.entityId)) !== null && _brandRecords$find !== void 0 ? _brandRecords$find : brandRecords.find(brand => brand.articleNumber === article.articleNumber);
273
+ };
274
+ const findPreferredPricePart = article => {
275
+ var _parts$find;
276
+ const parts = Array.isArray(article === null || article === void 0 ? void 0 : article.parts) ? article.parts : [];
277
+ return (_parts$find = parts.find(part => (part === null || part === void 0 ? void 0 : part.isPreferred) === true)) !== null && _parts$find !== void 0 ? _parts$find : parts.length === 1 ? parts[0] : null;
278
+ };
243
279
  const articleNumbers = [...new Set(articles.map(article => article.articleNumber))];
244
280
  const articleBrandQueryString = new URLSearchParams({
245
281
  articleNumbers: JSON.stringify(articleNumbers)
@@ -250,20 +286,23 @@ const enrichArticlesWithBrandsAndPrices = exports.enrichArticlesWithBrandsAndPri
250
286
  throw new Error('Failed to fetch the brands of the articles');
251
287
  }
252
288
  const articlesWithBrands = articles.map(article => {
289
+ var _ref3, _ref4, _preferredPricePart$p, _preferredPricePart$p2;
290
+ const brandData = findBrandDataForArticle(article, brandResponse.data);
291
+ const preferredPricePart = findPreferredPricePart(article);
292
+ const resolvedBrandNumber = (_ref3 = (_ref4 = (_preferredPricePart$p = preferredPricePart === null || preferredPricePart === void 0 ? void 0 : preferredPricePart.partBrandId) !== null && _preferredPricePart$p !== void 0 ? _preferredPricePart$p : brandData === null || brandData === void 0 ? void 0 : brandData.preferredPartBrandNumber) !== null && _ref4 !== void 0 ? _ref4 : brandData === null || brandData === void 0 ? void 0 : brandData.brandNumber) !== null && _ref3 !== void 0 ? _ref3 : _index2.DEFAULT_ARTICLE_BRAND;
293
+ const pricingPartNumber = (_preferredPricePart$p2 = preferredPricePart === null || preferredPricePart === void 0 ? void 0 : preferredPricePart.partNumber) !== null && _preferredPricePart$p2 !== void 0 ? _preferredPricePart$p2 : article.articleNumber;
253
294
  return _objectSpread(_objectSpread({}, article), {}, {
254
- brand: ((_ref3, _brandData$brandNumbe) => {
255
- const brandData = brandResponse.data.find(brand => brand.articleNumber === article.articleNumber);
256
- return (_ref3 = (_brandData$brandNumbe = brandData === null || brandData === void 0 ? void 0 : brandData.brandNumber) !== null && _brandData$brandNumbe !== void 0 ? _brandData$brandNumbe : brandData === null || brandData === void 0 ? void 0 : brandData.preferredPartBrandNumber) !== null && _ref3 !== void 0 ? _ref3 : _index2.DEFAULT_ARTICLE_BRAND;
257
- })()
295
+ brand: resolvedBrandNumber,
296
+ pricingPartNumber
258
297
  });
259
- }).filter(article => article.brand);
260
- const parts = articlesWithBrands.map(article => {
298
+ }).filter(article => article.brand && article.pricingPartNumber);
299
+ const parts = [...new Map(articlesWithBrands.map(article => {
261
300
  var _article$brand;
262
- return {
263
- partNumber: article.articleNumber,
301
+ return ["".concat(article.pricingPartNumber, ":").concat(article.brand), {
302
+ partNumber: article.pricingPartNumber,
264
303
  brandNumber: (_article$brand = article.brand) !== null && _article$brand !== void 0 ? _article$brand : _index2.DEFAULT_ARTICLE_BRAND
265
- };
266
- });
304
+ }];
305
+ })).values()];
267
306
  const pricesResponse = await _authenticatedProxyApi.authenticatedProxyApi.getArticlePrices(new URLSearchParams((0, _index.removeNullishProps)({
268
307
  branchId,
269
308
  formula,
@@ -272,25 +311,30 @@ const enrichArticlesWithBrandsAndPrices = exports.enrichArticlesWithBrandsAndPri
272
311
  if (!(pricesResponse !== null && pricesResponse !== void 0 && pricesResponse.data)) {
273
312
  throw new Error('No prices available for the given articles');
274
313
  }
275
- const {
276
- consumerPrices = [],
277
- locationPrices = []
278
- } = pricesResponse.data.data;
314
+ const responseData = pricesResponse === null || pricesResponse === void 0 || (_pricesResponse$data = pricesResponse.data) === null || _pricesResponse$data === void 0 ? void 0 : _pricesResponse$data.data;
315
+ const consumerPrices = Array.isArray(responseData === null || responseData === void 0 ? void 0 : responseData.consumerPrices) ? responseData.consumerPrices : [];
316
+ const locationPrices = Array.isArray(responseData === null || responseData === void 0 ? void 0 : responseData.locationPrices) ? responseData.locationPrices : [];
279
317
  const pricesMap = {
280
318
  consumer: Object.fromEntries(consumerPrices.map(price => [price.partNumber, price])),
281
319
  location: Object.fromEntries(locationPrices.map(price => [price.partNumber, price]))
282
320
  };
283
- let currentArticles = articlesWithBrands.map(article => _objectSpread(_objectSpread({}, article), {}, {
284
- consumerPrices: pricesMap.consumer[article.articleNumber],
285
- locationPrices: pricesMap.location[article.articleNumber]
286
- }));
321
+ let currentArticles = articlesWithBrands.map(_ref5 => {
322
+ let {
323
+ pricingPartNumber
324
+ } = _ref5,
325
+ article = _objectWithoutProperties(_ref5, _excluded);
326
+ return _objectSpread(_objectSpread({}, article), {}, {
327
+ consumerPrices: pricesMap.consumer[pricingPartNumber],
328
+ locationPrices: pricesMap.location[pricingPartNumber]
329
+ });
330
+ });
287
331
  return currentArticles;
288
332
  };
289
333
  const formatModelArticle = article => {
290
- var _ref4, _article$name, _ref5, _article$description$, _article$description, _article$boldDescript, _article$boldDescript2, _article$specificatio, _article$images, _article$images2, _article$articleNumbe;
334
+ var _ref6, _article$name, _ref7, _article$description$, _article$description, _article$boldDescript, _article$boldDescript2, _article$specificatio, _article$images, _article$images2, _article$articleNumbe;
291
335
  return _objectSpread(_objectSpread({}, article), {}, {
292
- name: (_ref4 = (_article$name = article.name) !== null && _article$name !== void 0 ? _article$name : article === null || article === void 0 ? void 0 : article.title) !== null && _ref4 !== void 0 ? _ref4 : null,
293
- description: (_ref5 = (_article$description$ = article === null || article === void 0 || (_article$description = article.description) === null || _article$description === void 0 || (_article$description = _article$description.ops) === null || _article$description === void 0 || (_article$description = _article$description[0]) === null || _article$description === void 0 ? void 0 : _article$description.insert) !== null && _article$description$ !== void 0 ? _article$description$ : article === null || article === void 0 ? void 0 : article.remark) !== null && _ref5 !== void 0 ? _ref5 : null,
336
+ name: (_ref6 = (_article$name = article.name) !== null && _article$name !== void 0 ? _article$name : article === null || article === void 0 ? void 0 : article.title) !== null && _ref6 !== void 0 ? _ref6 : null,
337
+ description: (_ref7 = (_article$description$ = article === null || article === void 0 || (_article$description = article.description) === null || _article$description === void 0 || (_article$description = _article$description.ops) === null || _article$description === void 0 || (_article$description = _article$description[0]) === null || _article$description === void 0 ? void 0 : _article$description.insert) !== null && _article$description$ !== void 0 ? _article$description$ : article === null || article === void 0 ? void 0 : article.remark) !== null && _ref7 !== void 0 ? _ref7 : null,
294
338
  subTitle: (_article$boldDescript = article === null || article === void 0 || (_article$boldDescript2 = article.boldDescription) === null || _article$boldDescript2 === void 0 || (_article$boldDescript2 = _article$boldDescript2.ops) === null || _article$boldDescript2 === void 0 || (_article$boldDescript2 = _article$boldDescript2[0]) === null || _article$boldDescript2 === void 0 ? void 0 : _article$boldDescript2.insert) !== null && _article$boldDescript !== void 0 ? _article$boldDescript : null,
295
339
  specifications: Array.isArray(article === null || article === void 0 ? void 0 : article.specifications) ? article === null || article === void 0 ? void 0 : article.specifications.join(' \n ') : (_article$specificatio = article === null || article === void 0 ? void 0 : article.specifications) !== null && _article$specificatio !== void 0 ? _article$specificatio : null,
296
340
  image: article !== null && article !== void 0 && (_article$images = article.images) !== null && _article$images !== void 0 && _article$images[0] ? (0, _image.getImageFromHyper)({
@@ -305,11 +349,11 @@ const formatModelArticle = article => {
305
349
  const formatGenericArticle = article => {
306
350
  var _article$articleNumbe2, _article$type, _article$group, _article$subgroup;
307
351
  const specificationPairs = [['C2 module', article === null || article === void 0 ? void 0 : article.c2Module], ['Check control', article === null || article === void 0 ? void 0 : article.checkControl], ['Direct current', article === null || article === void 0 ? void 0 : article.directCurrent], ['Draw weight', article === null || article === void 0 ? void 0 : article.drawWeight], ['D value', article === null || article === void 0 ? void 0 : article.dValue], ['Foglight shutdown', article === null || article === void 0 ? void 0 : article.foglightShutdown], ['PDC shutdown', article === null || article === void 0 ? void 0 : article.pdcShutdown], ['Switched PSU', article === null || article === void 0 ? void 0 : article.switchedPsu], ['LED', article === null || article === void 0 ? void 0 : article.led]];
308
- const specification = specificationPairs.filter(_ref6 => {
309
- let [_, value] = _ref6;
352
+ const specification = specificationPairs.filter(_ref8 => {
353
+ let [_, value] = _ref8;
310
354
  return value;
311
- }).map(_ref7 => {
312
- let [label, value] = _ref7;
355
+ }).map(_ref9 => {
356
+ let [label, value] = _ref9;
313
357
  return "".concat(label, ": ").concat(value);
314
358
  }).join(' \n ');
315
359
  return _objectSpread(_objectSpread({}, article), {}, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.349",
3
+ "version": "0.0.352",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",