b2m-utils 0.0.226 → 0.0.228

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/build/index.js CHANGED
@@ -540,8 +540,23 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
540
540
  currency: 'BRL',
541
541
  });
542
542
  var result = "".concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
543
+ // Se for FTL com distância e tiver intervalo de KM, adicionar informação na descrição
544
+ if ((cte === null || cte === void 0 ? void 0 : cte.ratecardModalId) === exports.RatecardModalEnum.ROAD_DOMESTIC_FTL && (cte === null || cte === void 0 ? void 0 : cte.distance) && (ratecardLaneFee.minKm || ratecardLaneFee.maxKm)) {
545
+ var kmRange = ratecardLaneFee.maxKm
546
+ ? "".concat(ratecardLaneFee.minKm || 0, "-").concat(ratecardLaneFee.maxKm, " km")
547
+ : "".concat(ratecardLaneFee.minKm, "+ km");
548
+ result = "".concat(cte.distance, " km (").concat(kmRange, ") = ").concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
549
+ }
550
+ // Se houver taxedWeight e tiver intervalo de peso, adicionar informação na descrição
551
+ else if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && (ratecardLaneFee.minWeight || ratecardLaneFee.maxWeight)) {
552
+ var weightRange = ratecardLaneFee.maxWeight
553
+ ? "".concat(ratecardLaneFee.minWeight || 0, "-").concat(ratecardLaneFee.maxWeight, " kg")
554
+ : "".concat(ratecardLaneFee.minWeight, "+ kg");
555
+ result = "".concat(cte.taxedWeight, " kg (").concat(weightRange, ") = ").concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
556
+ }
543
557
  totalFee = total;
544
558
  resultFee = result;
559
+ // Lógica de intervalo de peso
545
560
  if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && !ratecardLaneFee.maxWeight && ratecardLaneFee.minWeight && Math.ceil(+cte.taxedWeight) >= +ratecardLaneFee.minWeight) {
546
561
  // Não tem maxWeight - é o último intervalo
547
562
  // Encontrar todas as taxas do mesmo tipo que têm maxWeight
@@ -581,37 +596,77 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
581
596
  resultFee = result_4;
582
597
  }
583
598
  }
599
+ // Lógica de intervalo de KM para FTL
600
+ else if ((cte === null || cte === void 0 ? void 0 : cte.ratecardModalId) === exports.RatecardModalEnum.ROAD_DOMESTIC_FTL && (cte === null || cte === void 0 ? void 0 : cte.distance) && !ratecardLaneFee.maxKm && ratecardLaneFee.minKm && +cte.distance >= +ratecardLaneFee.minKm) {
601
+ // Não tem maxKm - é o último intervalo
602
+ // Encontrar todas as taxas do mesmo tipo que têm maxKm
603
+ var feesWithMaxKm = allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.filter(function (fee) {
604
+ var _a, _b;
605
+ return ((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.id) &&
606
+ fee.maxKm &&
607
+ (cte === null || cte === void 0 ? void 0 : cte.distance) &&
608
+ +fee.maxKm < +cte.distance;
609
+ });
610
+ // Ordenar pelo maxKm do maior para o menor
611
+ feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
612
+ // Pegar o primeiro (maior maxKm)
613
+ var highestIntervalFee = feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm[0];
614
+ if (highestIntervalFee) {
615
+ // Calcula baseado na taxa do intervalo mais alto que tem maxKm
616
+ var total_5 = +highestIntervalFee.value;
617
+ // Calcular diferença de distância
618
+ var kmDifference = Number((((cte === null || cte === void 0 ? void 0 : cte.distance) || 0) - (highestIntervalFee.maxKm || 0)).toFixed(2));
619
+ // Calcular valor adicional pela diferença de km
620
+ var additionalValue = kmDifference * +ratecardLaneFee.value;
621
+ // Somar ao total
622
+ total_5 += additionalValue;
623
+ // Aplicar multiplicador de redelivery ao valor final
624
+ var _k = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _k.adjustedTotal, redeliveryInfo_5 = _k.redeliveryInfo;
625
+ total_5 = adjustedTotal_5;
626
+ var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
627
+ style: 'currency',
628
+ currency: 'BRL',
629
+ });
630
+ var resultCurrency_5 = (+total_5).toLocaleString('pt-br', {
631
+ style: 'currency',
632
+ currency: 'BRL',
633
+ });
634
+ var result_5 = "".concat(cte.distance, " km = ").concat(valueCurrency_3, " + ").concat(kmDifference, " km x ").concat(convertNumberToCurrency(+ratecardLaneFee.value, 'pt-br')).concat(redeliveryInfo_5, " = ").concat(resultCurrency_5);
635
+ totalFee = total_5;
636
+ resultFee = result_5;
637
+ }
638
+ }
584
639
  break;
585
640
  case exports.FeeCalculationTypeEnum.COMMODITY_VALUE:
586
641
  if (value) {
587
642
  var commodityValue = (_a = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _a !== void 0 ? _a : 0;
588
- var total_5 = +commodityValue * (+value / 100);
589
- var _k = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _k.adjustedTotal, redeliveryInfo_5 = _k.redeliveryInfo;
590
- total_5 = adjustedTotal_5;
591
- var resultCurrency_5 = (+total_5).toLocaleString('pt-br', {
643
+ var total_6 = +commodityValue * (+value / 100);
644
+ var _l = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _l.adjustedTotal, redeliveryInfo_6 = _l.redeliveryInfo;
645
+ total_6 = adjustedTotal_6;
646
+ var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
592
647
  style: 'currency',
593
648
  currency: 'BRL',
594
649
  });
595
- var result_5 = "".concat(convertNumberToCurrency(+commodityValue, 'pt-br'), " x ").concat(value, "%").concat(redeliveryInfo_5, " = ").concat(resultCurrency_5);
596
- totalFee = total_5;
597
- resultFee = result_5;
650
+ var result_6 = "".concat(convertNumberToCurrency(+commodityValue, 'pt-br'), " x ").concat(value, "%").concat(redeliveryInfo_6, " = ").concat(resultCurrency_6);
651
+ totalFee = total_6;
652
+ resultFee = result_6;
598
653
  }
599
654
  break;
600
655
  case exports.FeeCalculationTypeEnum.TAXED_WEIGHT:
601
656
  if (value) {
602
657
  var taxedWeight = (_b = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _b !== void 0 ? _b : 0;
603
- var total_6 = +taxedWeight * +value;
604
- var _l = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _l.adjustedTotal, redeliveryInfo_6 = _l.redeliveryInfo;
605
- total_6 = adjustedTotal_6;
606
- var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
658
+ var total_7 = +taxedWeight * +value;
659
+ var _m = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _m.adjustedTotal, redeliveryInfo_7 = _m.redeliveryInfo;
660
+ total_7 = adjustedTotal_7;
661
+ var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
607
662
  style: 'currency',
608
663
  currency: 'BRL',
609
664
  });
610
- var result_6 = "".concat(taxedWeight, " kg x ").concat(convertNumberToCurrency(+value, 'pt-br', {
665
+ var result_7 = "".concat(taxedWeight, " kg x ").concat(convertNumberToCurrency(+value, 'pt-br', {
611
666
  minimumFractionDigits: 4,
612
- })).concat(redeliveryInfo_6, " = ").concat(resultCurrency_6);
613
- totalFee = total_6;
614
- resultFee = result_6;
667
+ })).concat(redeliveryInfo_7, " = ").concat(resultCurrency_7);
668
+ totalFee = total_7;
669
+ resultFee = result_7;
615
670
  }
616
671
  break;
617
672
  /*if (ratecardLaneFee.minWeight && cte?.taxedWeight) {
@@ -7197,94 +7252,58 @@ var getFilteredFeesToAudit = function (_a) {
7197
7252
  };
7198
7253
 
7199
7254
  var getLaneFromRatecard = function (cte) {
7200
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
7255
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
7201
7256
  var ratecard = getRatecardFromCte(cte);
7202
- console.log('🔍 Ratecard encontrado:', {
7203
- id: ratecard === null || ratecard === void 0 ? void 0 : ratecard.id,
7204
- name: ratecard === null || ratecard === void 0 ? void 0 : ratecard.name,
7205
- modalId: ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId,
7206
- modalName: (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.modal) === null || _a === void 0 ? void 0 : _a.name,
7207
- originCities: ratecard === null || ratecard === void 0 ? void 0 : ratecard.ratecard_origin_cities,
7208
- lanesCount: (_b = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _b === void 0 ? void 0 : _b.length
7209
- });
7210
7257
  var cityOriginId = cte.cityOriginId, cityDestination = cte.cityDestination;
7211
- var destinationUf = (_c = cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.state) === null || _c === void 0 ? void 0 : _c.uf;
7258
+ var destinationUf = (_a = cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.state) === null || _a === void 0 ? void 0 : _a.uf;
7212
7259
  // Encontrar a ratecardRegion da cidade de destino
7213
- var destinationRatecardRegionId = (_e = (_d = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardRegionCity) === null || _d === void 0 ? void 0 : _d.find(function (regionCity) { return regionCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); })) === null || _e === void 0 ? void 0 : _e.ratecardRegionId;
7214
- if (!(ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) || ((_f = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _f === void 0 ? void 0 : _f.length) === 0) {
7215
- console.log('❌ Nenhuma lane encontrada no ratecard');
7260
+ var destinationRatecardRegionId = (_c = (_b = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardRegionCity) === null || _b === void 0 ? void 0 : _b.find(function (regionCity) { return regionCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); })) === null || _c === void 0 ? void 0 : _c.ratecardRegionId;
7261
+ if (!(ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) || ((_d = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _d === void 0 ? void 0 : _d.length) === 0) {
7216
7262
  return undefined;
7217
7263
  }
7218
- console.log('📍 Dados do CTE:', {
7219
- cityOriginId: cityOriginId,
7220
- cityOriginName: (_g = cte.cityOrigin) === null || _g === void 0 ? void 0 : _g.name,
7221
- cityOriginUf: (_j = (_h = cte.cityOrigin) === null || _h === void 0 ? void 0 : _h.state) === null || _j === void 0 ? void 0 : _j.uf,
7222
- cityDestinationId: cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id,
7223
- cityDestinationName: cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.name,
7224
- destinationUf: destinationUf
7225
- });
7226
7264
  // Lógica diferenciada por modal
7227
7265
  switch (ratecard.modalId) {
7228
7266
  case exports.RatecardModalEnum.ROAD_DOMESTIC_FTL:
7229
- console.log('🚛 Modal FTL detectado - iniciando busca de lane');
7230
7267
  // FTL: Verificar rota por UF de destino
7231
7268
  if (destinationUf) {
7232
- console.log('1️⃣ Tentando rota direta por UF de destino:', destinationUf);
7233
7269
  var directLane = ratecard.RatecardLane.find(function (i) {
7234
7270
  return i.ufDestination === destinationUf && i.ratecardRegionId === destinationRatecardRegionId;
7235
7271
  });
7236
7272
  if (directLane) {
7237
- console.log('✅ Rota direta encontrada!', directLane.id);
7238
7273
  return directLane;
7239
7274
  }
7240
- console.log('⚠️ Rota direta não encontrada');
7241
7275
  // Fallback: Verificar se existe lane única com fees de KM e cidade origem no ratecard_origin_cities
7242
7276
  var uniqueLane = ratecard.RatecardLane[0];
7243
7277
  // Verificar se a lane tem fees com intervalo de KM
7244
- var hasKmFees = (_k = uniqueLane === null || uniqueLane === void 0 ? void 0 : uniqueLane.RatecardLaneFee) === null || _k === void 0 ? void 0 : _k.some(function (fee) { return fee.minKm !== null; });
7245
- console.log('2️⃣ Verificando fallback com KM - hasKmFees:', hasKmFees);
7278
+ var hasKmFees = (_e = uniqueLane === null || uniqueLane === void 0 ? void 0 : uniqueLane.RatecardLaneFee) === null || _e === void 0 ? void 0 : _e.some(function (fee) { return fee.minKm !== null; });
7246
7279
  // Verificar se a cidade de origem está no ratecard_origin_cities
7247
- var hasOriginCity = (_l = ratecard.ratecard_origin_cities) === null || _l === void 0 ? void 0 : _l.some(function (originCity) { return originCity.cityId === cityOriginId; });
7248
- console.log(' Cidade origem em ratecard_origin_cities:', hasOriginCity);
7280
+ var hasOriginCity = (_f = ratecard.ratecard_origin_cities) === null || _f === void 0 ? void 0 : _f.some(function (originCity) { return originCity.cityId === cityOriginId; });
7249
7281
  if (hasKmFees && hasOriginCity) {
7250
- console.log('✅ Fallback com KM encontrado!');
7251
7282
  // Mockar informações para exibição no frontend
7252
7283
  return __assign(__assign({}, uniqueLane), { city: cte.cityOrigin, ufDestination: destinationUf, ratecardRegion: uniqueLane.ratecardRegion || { name: destinationUf } });
7253
7284
  }
7254
- console.log('⚠️ Fallback com KM não aplicável');
7255
7285
  // Rota inversa FTL: Verificar se cidade de destino está em ratecard_origin_cities
7256
- var originUf_1 = (_o = (_m = cte.cityOrigin) === null || _m === void 0 ? void 0 : _m.state) === null || _o === void 0 ? void 0 : _o.uf;
7257
- console.log('3️⃣ Tentando rota inversa - originUf:', originUf_1);
7286
+ var originUf_1 = (_h = (_g = cte.cityOrigin) === null || _g === void 0 ? void 0 : _g.state) === null || _h === void 0 ? void 0 : _h.uf;
7258
7287
  if (originUf_1) {
7259
7288
  // Verificar se existe lane com ufDestination = originUf
7260
7289
  var reverseLane = ratecard.RatecardLane.find(function (i) {
7261
7290
  return i.ufDestination === originUf_1;
7262
7291
  });
7263
- console.log(' Lane com ufDestination =', originUf_1, ':', reverseLane ? 'encontrada' : 'não encontrada');
7264
7292
  if (reverseLane) {
7265
7293
  // Verificar se a cidade de destino está no ratecard_origin_cities
7266
- var hasDestinationCity = (_p = ratecard.ratecard_origin_cities) === null || _p === void 0 ? void 0 : _p.some(function (originCity) { return originCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); });
7267
- console.log(' Cidade destino em ratecard_origin_cities:', hasDestinationCity);
7294
+ var hasDestinationCity = (_j = ratecard.ratecard_origin_cities) === null || _j === void 0 ? void 0 : _j.some(function (originCity) { return originCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); });
7268
7295
  if (hasDestinationCity) {
7269
- console.log('✅ Rota inversa encontrada!', reverseLane.id);
7270
7296
  return reverseLane;
7271
7297
  }
7272
7298
  }
7273
- console.log('⚠️ Rota inversa não encontrada');
7274
7299
  // Fallback inverso: Lane única com cidade de destino em ratecard_origin_cities
7275
- console.log('4️⃣ Tentando fallback inverso com KM');
7276
- var hasDestinationCityInOrigins = (_q = ratecard.ratecard_origin_cities) === null || _q === void 0 ? void 0 : _q.some(function (originCity) { return originCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); });
7277
- console.log(' Cidade destino em ratecard_origin_cities:', hasDestinationCityInOrigins);
7278
- console.log(' hasKmFees:', hasKmFees);
7300
+ var hasDestinationCityInOrigins = (_k = ratecard.ratecard_origin_cities) === null || _k === void 0 ? void 0 : _k.some(function (originCity) { return originCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); });
7279
7301
  if (hasKmFees && hasDestinationCityInOrigins) {
7280
- console.log('✅ Fallback inverso com KM encontrado!');
7281
7302
  // Mockar informações para exibição no frontend (rota inversa)
7282
7303
  return __assign(__assign({}, uniqueLane), { city: cityDestination, ufDestination: originUf_1, ratecardRegion: uniqueLane.ratecardRegion || { name: originUf_1 } });
7283
7304
  }
7284
- console.log('⚠️ Fallback inverso não aplicável');
7285
7305
  }
7286
7306
  }
7287
- console.log('❌ Nenhuma lane FTL encontrada');
7288
7307
  break;
7289
7308
  case exports.RatecardModalEnum.ROAD_DOMESTIC_LTL:
7290
7309
  default:
@@ -7299,9 +7318,9 @@ var getLaneFromRatecard = function (cte) {
7299
7318
  }
7300
7319
  // Se não encontrar rota direta, buscar rota inversa (Destino -> Origem)
7301
7320
  // Para isso, precisamos encontrar a UF da origem e sua ratecardRegion
7302
- var originUf_2 = (_s = (_r = cte.cityOrigin) === null || _r === void 0 ? void 0 : _r.state) === null || _s === void 0 ? void 0 : _s.uf;
7321
+ var originUf_2 = (_m = (_l = cte.cityOrigin) === null || _l === void 0 ? void 0 : _l.state) === null || _m === void 0 ? void 0 : _m.uf;
7303
7322
  // Encontrar a ratecardRegion da cidade de origem
7304
- var originRatecardRegionId_1 = (_u = (_t = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardRegionCity) === null || _t === void 0 ? void 0 : _t.find(function (regionCity) { return regionCity.cityId === cityOriginId; })) === null || _u === void 0 ? void 0 : _u.ratecardRegionId;
7323
+ var originRatecardRegionId_1 = (_p = (_o = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardRegionCity) === null || _o === void 0 ? void 0 : _o.find(function (regionCity) { return regionCity.cityId === cityOriginId; })) === null || _p === void 0 ? void 0 : _p.ratecardRegionId;
7305
7324
  if (originUf_2) {
7306
7325
  var reverseLane = ratecard.RatecardLane.find(function (i) {
7307
7326
  return i.cityOriginId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id) && i.ufDestination === originUf_2 && i.ratecardRegionId === originRatecardRegionId_1;
package/build/index.js.gz CHANGED
Binary file