b2m-utils 0.0.231 → 0.0.234

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
@@ -222,12 +222,12 @@ var getRatecardFromCte = function (cte) {
222
222
  var _a, _b, _c, _d, _e, _f, _g;
223
223
  var ratecard = null;
224
224
  if (((_a = cte.carrier) === null || _a === void 0 ? void 0 : _a.Ratecard) && ((_c = (_b = cte.carrier) === null || _b === void 0 ? void 0 : _b.Ratecard) === null || _c === void 0 ? void 0 : _c.length) > 0) {
225
- var today_1 = new Date();
225
+ var emissionDate_1 = cte.emissionDate ? new Date(cte.emissionDate) : new Date();
226
226
  switch (cte.ratecardModalId) {
227
227
  case exports.RatecardModalEnum.ROAD_DOMESTIC_FTL:
228
228
  var ratecardForRoadFTL = cte.carrier.Ratecard.find(function (ratecard) {
229
229
  var _a;
230
- var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && today_1 >= new Date(ratecard.startsAt) && today_1 <= new Date(ratecard.endsAt);
230
+ var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && emissionDate_1 >= new Date(ratecard.startsAt) && emissionDate_1 <= new Date(ratecard.endsAt);
231
231
  var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
232
232
  var hasOriginCity = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.ratecard_origin_cities) === null || _a === void 0 ? void 0 : _a.some(function (city) { return city.cityId === cte.cityOriginId; });
233
233
  return isValidDate && isValidModal && hasOriginCity;
@@ -239,7 +239,7 @@ var getRatecardFromCte = function (cte) {
239
239
  // Rota inversa: Verificar se cidade de destino está em ratecard_origin_cities
240
240
  var reverseRatecardForRoadFTL = cte.carrier.Ratecard.find(function (ratecard) {
241
241
  var _a;
242
- var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && today_1 >= new Date(ratecard.startsAt) && today_1 <= new Date(ratecard.endsAt);
242
+ var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && emissionDate_1 >= new Date(ratecard.startsAt) && emissionDate_1 <= new Date(ratecard.endsAt);
243
243
  var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
244
244
  var hasDestinationCity = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.ratecard_origin_cities) === null || _a === void 0 ? void 0 : _a.some(function (city) { return city.cityId === cte.cityDestinationId; });
245
245
  return isValidDate && isValidModal && hasDestinationCity;
@@ -255,7 +255,7 @@ var getRatecardFromCte = function (cte) {
255
255
  var originUf_1 = (_g = (_f = cte.cityOrigin) === null || _f === void 0 ? void 0 : _f.state) === null || _g === void 0 ? void 0 : _g.uf;
256
256
  var ratecardFromThisYear = cte.carrier.Ratecard.find(function (ratecard) {
257
257
  var _a;
258
- var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && today_1 >= new Date(ratecard.startsAt) && today_1 <= new Date(ratecard.endsAt);
258
+ var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && emissionDate_1 >= new Date(ratecard.startsAt) && emissionDate_1 <= new Date(ratecard.endsAt);
259
259
  var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
260
260
  // Verificar se existe lane com a rota (cityOriginId -> ufDestination)
261
261
  var hasDirectLane = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _a === void 0 ? void 0 : _a.some(function (lane) {
@@ -270,7 +270,7 @@ var getRatecardFromCte = function (cte) {
270
270
  // Rota reversa: Verificar se existe lane com rota inversa (cityDestinationId -> originUf)
271
271
  var reverseRatecardFromThisYear = cte.carrier.Ratecard.find(function (ratecard) {
272
272
  var _a;
273
- var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && today_1 >= new Date(ratecard.startsAt) && today_1 <= new Date(ratecard.endsAt);
273
+ var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && emissionDate_1 >= new Date(ratecard.startsAt) && emissionDate_1 <= new Date(ratecard.endsAt);
274
274
  var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
275
275
  // Verificar se existe lane com a rota inversa (cityDestinationId -> originUf)
276
276
  var hasReverseLane = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _a === void 0 ? void 0 : _a.some(function (lane) {
@@ -421,7 +421,7 @@ var filterSiblingFees = function (fees) {
421
421
  };
422
422
 
423
423
  var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCalc) {
424
- var _a, _b, _c, _d;
424
+ var _a, _b, _c, _d, _e, _f;
425
425
  if (debug === void 0) { debug = false; }
426
426
  if (ratecardLaneFee.fee) {
427
427
  var value = ratecardLaneFee.value, fee_1 = ratecardLaneFee.fee;
@@ -493,7 +493,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
493
493
  if (totalValueFromAllFees && !isNaN(+totalValueFromAllFees)) {
494
494
  var valueToMultiply = (+value / 100);
495
495
  var total_1 = +totalValueFromAllFees * valueToMultiply;
496
- var _e = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _e.adjustedTotal, redeliveryInfo_1 = _e.redeliveryInfo;
496
+ var _g = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _g.adjustedTotal, redeliveryInfo_1 = _g.redeliveryInfo;
497
497
  total_1 = adjustedTotal_1;
498
498
  var totalValueFromAllFeesCurrency = convertNumberToCurrency(+totalValueFromAllFees, 'pt-br');
499
499
  var resultCurrency_1 = (+total_1).toLocaleString('pt-BR', {
@@ -511,7 +511,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
511
511
  if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && !isNaN(+(cte === null || cte === void 0 ? void 0 : cte.taxedWeight))) {
512
512
  var fractions = Math.ceil(+cte.taxedWeight / 100);
513
513
  var total_2 = fractions * value;
514
- var _f = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _f.adjustedTotal, redeliveryInfo_2 = _f.redeliveryInfo;
514
+ var _h = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _h.adjustedTotal, redeliveryInfo_2 = _h.redeliveryInfo;
515
515
  total_2 = adjustedTotal_2;
516
516
  var valueCurrency_1 = (+value).toLocaleString('pt-br', {
517
517
  style: 'currency',
@@ -530,7 +530,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
530
530
  if (value && (cte === null || cte === void 0 ? void 0 : cte.freightValue)) {
531
531
  if (!isNaN(+value) && !isNaN(+cte.freightValue)) {
532
532
  var total_3 = +cte.freightValue * (+value / 100);
533
- var _g = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _g.adjustedTotal, redeliveryInfo_3 = _g.redeliveryInfo;
533
+ var _j = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _j.adjustedTotal, redeliveryInfo_3 = _j.redeliveryInfo;
534
534
  total_3 = adjustedTotal_3;
535
535
  var freightValueCurrency = (+cte.freightValue).toLocaleString('pt-br', {
536
536
  style: 'currency',
@@ -565,7 +565,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
565
565
  case exports.FeeCalculationTypeEnum.MIN_VALUE:
566
566
  case exports.FeeCalculationTypeEnum.FIXED:
567
567
  var total = +value;
568
- var _h = applyRedeliveryMultiplier(total, cte), adjustedTotal = _h.adjustedTotal, redeliveryInfo = _h.redeliveryInfo;
568
+ var _k = applyRedeliveryMultiplier(total, cte), adjustedTotal = _k.adjustedTotal, redeliveryInfo = _k.redeliveryInfo;
569
569
  total = adjustedTotal;
570
570
  var valueCurrency = (+value).toLocaleString('pt-br', {
571
571
  style: 'currency',
@@ -617,7 +617,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
617
617
  // Somar ao total
618
618
  total_4 += additionalValue;
619
619
  // Aplicar multiplicador de redelivery ao valor final
620
- var _j = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _j.adjustedTotal, redeliveryInfo_4 = _j.redeliveryInfo;
620
+ var _l = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _l.adjustedTotal, redeliveryInfo_4 = _l.redeliveryInfo;
621
621
  total_4 = adjustedTotal_4;
622
622
  var valueCurrency_2 = (+highestIntervalFee.value).toLocaleString('pt-br', {
623
623
  style: 'currency',
@@ -634,6 +634,21 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
634
634
  }
635
635
  // Lógica de intervalo de KM para FTL
636
636
  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) {
637
+ console.log('[calculateFee] FTL - Entrando no condicional de intervalo KM', {
638
+ cteId: cte.id,
639
+ cteNumber: cte.number,
640
+ ratecardModalId: cte.ratecardModalId,
641
+ distance: cte.distance,
642
+ ratecardLaneFee: {
643
+ id: ratecardLaneFee.id,
644
+ feeId: (_a = ratecardLaneFee.fee) === null || _a === void 0 ? void 0 : _a.id,
645
+ feeName: (_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.name,
646
+ value: ratecardLaneFee.value,
647
+ minKm: ratecardLaneFee.minKm,
648
+ maxKm: ratecardLaneFee.maxKm,
649
+ },
650
+ allFeesForCalcCount: allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.length,
651
+ });
637
652
  // Não tem maxKm - é o último intervalo
638
653
  // Encontrar todas as taxas do mesmo tipo que têm maxKm
639
654
  var feesWithMaxKm = allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.filter(function (fee) {
@@ -643,10 +658,33 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
643
658
  (cte === null || cte === void 0 ? void 0 : cte.distance) &&
644
659
  +fee.maxKm < +cte.distance;
645
660
  });
661
+ console.log('[calculateFee] FTL - Fees com maxKm encontradas', {
662
+ cteId: cte.id,
663
+ feesWithMaxKmCount: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.length,
664
+ feesWithMaxKm: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.map(function (f) { return ({
665
+ id: f.id,
666
+ value: f.value,
667
+ minKm: f.minKm,
668
+ maxKm: f.maxKm,
669
+ }); }),
670
+ });
671
+ console.log({
672
+ cte: cte,
673
+ });
646
674
  // Ordenar pelo maxKm do maior para o menor
647
675
  feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
648
676
  // Pegar o primeiro (maior maxKm)
649
677
  var highestIntervalFee = feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm[0];
678
+ console.log('[calculateFee] FTL - Maior intervalo selecionado', {
679
+ cteId: cte.id,
680
+ hasHighestIntervalFee: !!highestIntervalFee,
681
+ highestIntervalFee: highestIntervalFee ? {
682
+ id: highestIntervalFee.id,
683
+ value: highestIntervalFee.value,
684
+ minKm: highestIntervalFee.minKm,
685
+ maxKm: highestIntervalFee.maxKm,
686
+ } : null,
687
+ });
650
688
  if (highestIntervalFee) {
651
689
  // Calcula baseado na taxa do intervalo mais alto que tem maxKm
652
690
  var total_5 = +highestIntervalFee.value;
@@ -657,7 +695,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
657
695
  // Somar ao total
658
696
  total_5 += additionalValue;
659
697
  // Aplicar multiplicador de redelivery ao valor final
660
- var _k = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _k.adjustedTotal, redeliveryInfo_5 = _k.redeliveryInfo;
698
+ var _m = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _m.adjustedTotal, redeliveryInfo_5 = _m.redeliveryInfo;
661
699
  total_5 = adjustedTotal_5;
662
700
  var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
663
701
  style: 'currency',
@@ -675,9 +713,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
675
713
  break;
676
714
  case exports.FeeCalculationTypeEnum.COMMODITY_VALUE:
677
715
  if (value) {
678
- var commodityValue = (_a = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _a !== void 0 ? _a : 0;
716
+ var commodityValue = (_c = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _c !== void 0 ? _c : 0;
679
717
  var total_6 = +commodityValue * (+value / 100);
680
- var _l = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _l.adjustedTotal, redeliveryInfo_6 = _l.redeliveryInfo;
718
+ var _o = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _o.adjustedTotal, redeliveryInfo_6 = _o.redeliveryInfo;
681
719
  total_6 = adjustedTotal_6;
682
720
  var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
683
721
  style: 'currency',
@@ -690,9 +728,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
690
728
  break;
691
729
  case exports.FeeCalculationTypeEnum.TAXED_WEIGHT:
692
730
  if (value) {
693
- var taxedWeight = (_b = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _b !== void 0 ? _b : 0;
731
+ var taxedWeight = (_d = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _d !== void 0 ? _d : 0;
694
732
  var total_7 = +taxedWeight * +value;
695
- var _m = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _m.adjustedTotal, redeliveryInfo_7 = _m.redeliveryInfo;
733
+ var _p = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _p.adjustedTotal, redeliveryInfo_7 = _p.redeliveryInfo;
696
734
  total_7 = adjustedTotal_7;
697
735
  var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
698
736
  style: 'currency',
@@ -808,7 +846,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
808
846
  return 0;
809
847
  });
810
848
  if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
811
- if (((_c = siblingFeesResults[0]) === null || _c === void 0 ? void 0 : _c.totalFee) && ((_d = siblingFeesResults[0]) === null || _d === void 0 ? void 0 : _d.totalFee) > totalFee) {
849
+ if (((_e = siblingFeesResults[0]) === null || _e === void 0 ? void 0 : _e.totalFee) && ((_f = siblingFeesResults[0]) === null || _f === void 0 ? void 0 : _f.totalFee) > totalFee) {
812
850
  totalToCalc = 0;
813
851
  }
814
852
  }
package/build/index.js.gz CHANGED
Binary file