b2m-utils 0.0.232 → 0.0.235

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.
@@ -417,7 +417,7 @@ var filterSiblingFees = function (fees) {
417
417
  };
418
418
 
419
419
  var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCalc) {
420
- var _a, _b, _c, _d;
420
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
421
421
  if (debug === void 0) { debug = false; }
422
422
  if (ratecardLaneFee.fee) {
423
423
  var value = ratecardLaneFee.value, fee_1 = ratecardLaneFee.fee;
@@ -489,7 +489,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
489
489
  if (totalValueFromAllFees && !isNaN(+totalValueFromAllFees)) {
490
490
  var valueToMultiply = (+value / 100);
491
491
  var total_1 = +totalValueFromAllFees * valueToMultiply;
492
- var _e = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _e.adjustedTotal, redeliveryInfo_1 = _e.redeliveryInfo;
492
+ var _o = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _o.adjustedTotal, redeliveryInfo_1 = _o.redeliveryInfo;
493
493
  total_1 = adjustedTotal_1;
494
494
  var totalValueFromAllFeesCurrency = convertNumberToCurrency(+totalValueFromAllFees, 'pt-br');
495
495
  var resultCurrency_1 = (+total_1).toLocaleString('pt-BR', {
@@ -507,7 +507,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
507
507
  if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && !isNaN(+(cte === null || cte === void 0 ? void 0 : cte.taxedWeight))) {
508
508
  var fractions = Math.ceil(+cte.taxedWeight / 100);
509
509
  var total_2 = fractions * value;
510
- var _f = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _f.adjustedTotal, redeliveryInfo_2 = _f.redeliveryInfo;
510
+ var _p = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _p.adjustedTotal, redeliveryInfo_2 = _p.redeliveryInfo;
511
511
  total_2 = adjustedTotal_2;
512
512
  var valueCurrency_1 = (+value).toLocaleString('pt-br', {
513
513
  style: 'currency',
@@ -526,7 +526,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
526
526
  if (value && (cte === null || cte === void 0 ? void 0 : cte.freightValue)) {
527
527
  if (!isNaN(+value) && !isNaN(+cte.freightValue)) {
528
528
  var total_3 = +cte.freightValue * (+value / 100);
529
- var _g = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _g.adjustedTotal, redeliveryInfo_3 = _g.redeliveryInfo;
529
+ var _q = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _q.adjustedTotal, redeliveryInfo_3 = _q.redeliveryInfo;
530
530
  total_3 = adjustedTotal_3;
531
531
  var freightValueCurrency = (+cte.freightValue).toLocaleString('pt-br', {
532
532
  style: 'currency',
@@ -561,7 +561,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
561
561
  case FeeCalculationTypeEnum.MIN_VALUE:
562
562
  case FeeCalculationTypeEnum.FIXED:
563
563
  var total = +value;
564
- var _h = applyRedeliveryMultiplier(total, cte), adjustedTotal = _h.adjustedTotal, redeliveryInfo = _h.redeliveryInfo;
564
+ var _r = applyRedeliveryMultiplier(total, cte), adjustedTotal = _r.adjustedTotal, redeliveryInfo = _r.redeliveryInfo;
565
565
  total = adjustedTotal;
566
566
  var valueCurrency = (+value).toLocaleString('pt-br', {
567
567
  style: 'currency',
@@ -613,7 +613,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
613
613
  // Somar ao total
614
614
  total_4 += additionalValue;
615
615
  // Aplicar multiplicador de redelivery ao valor final
616
- var _j = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _j.adjustedTotal, redeliveryInfo_4 = _j.redeliveryInfo;
616
+ var _s = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _s.adjustedTotal, redeliveryInfo_4 = _s.redeliveryInfo;
617
617
  total_4 = adjustedTotal_4;
618
618
  var valueCurrency_2 = (+highestIntervalFee.value).toLocaleString('pt-br', {
619
619
  style: 'currency',
@@ -630,19 +630,68 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
630
630
  }
631
631
  // Lógica de intervalo de KM para FTL
632
632
  else if ((cte === null || cte === void 0 ? void 0 : cte.ratecardModalId) === RatecardModalEnum.ROAD_DOMESTIC_FTL && (cte === null || cte === void 0 ? void 0 : cte.distance) && !ratecardLaneFee.maxKm && ratecardLaneFee.minKm && +cte.distance >= +ratecardLaneFee.minKm) {
633
+ console.log('[calculateFee] FTL - Entrando no condicional de intervalo KM', {
634
+ cteId: cte.id,
635
+ cteNumber: cte.number,
636
+ ratecardModalId: cte.ratecardModalId,
637
+ distance: cte.distance,
638
+ ratecardLaneFee: {
639
+ id: ratecardLaneFee.id,
640
+ feeId: (_a = ratecardLaneFee.fee) === null || _a === void 0 ? void 0 : _a.id,
641
+ feeName: (_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.name,
642
+ value: ratecardLaneFee.value,
643
+ minKm: ratecardLaneFee.minKm,
644
+ maxKm: ratecardLaneFee.maxKm,
645
+ laneId: ratecardLaneFee.laneId,
646
+ },
647
+ hasRatecard: !!((_c = cte.carrier) === null || _c === void 0 ? void 0 : _c.Ratecard),
648
+ ratecardCount: (_e = (_d = cte.carrier) === null || _d === void 0 ? void 0 : _d.Ratecard) === null || _e === void 0 ? void 0 : _e.length,
649
+ });
650
+ // Buscar o ratecard correto do CTE usando getRatecardFromCte
651
+ var ratecard = getRatecardFromCte(cte);
652
+ var lane = (_f = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _f === void 0 ? void 0 : _f.find(function (l) { return l.id === ratecardLaneFee.laneId; });
653
+ console.log('[calculateFee] FTL - Ratecard e Lane encontrados', {
654
+ cteId: cte.id,
655
+ ratecardId: ratecard === null || ratecard === void 0 ? void 0 : ratecard.id,
656
+ ratecardName: ratecard === null || ratecard === void 0 ? void 0 : ratecard.name,
657
+ laneId: lane === null || lane === void 0 ? void 0 : lane.id,
658
+ laneFeeCount: (_g = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _g === void 0 ? void 0 : _g.length,
659
+ ratecard: ratecard,
660
+ lane: lane,
661
+ });
633
662
  // Não tem maxKm - é o último intervalo
634
- // Encontrar todas as taxas do mesmo tipo que têm maxKm
635
- var feesWithMaxKm = allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.filter(function (fee) {
663
+ // Encontrar todas as taxas do mesmo tipo que têm maxKm no ratecard
664
+ var feesWithMaxKm = (_h = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _h === void 0 ? void 0 : _h.filter(function (fee) {
636
665
  var _a, _b;
637
666
  return ((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.id) &&
638
667
  fee.maxKm &&
639
668
  (cte === null || cte === void 0 ? void 0 : cte.distance) &&
640
669
  +fee.maxKm < +cte.distance;
641
670
  });
671
+ console.log('[calculateFee] FTL - Fees com maxKm encontradas no ratecard', {
672
+ cteId: cte.id,
673
+ feesWithMaxKmCount: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.length,
674
+ feesWithMaxKm: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.map(function (f) { return ({
675
+ id: f.id,
676
+ value: f.value,
677
+ minKm: f.minKm,
678
+ maxKm: f.maxKm,
679
+ }); }),
680
+ });
642
681
  // Ordenar pelo maxKm do maior para o menor
643
682
  feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
644
683
  // Pegar o primeiro (maior maxKm)
645
684
  var highestIntervalFee = feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm[0];
685
+ console.log('[calculateFee] FTL - Maior intervalo selecionado', {
686
+ cteId: cte.id,
687
+ hasHighestIntervalFee: !!highestIntervalFee,
688
+ highestIntervalFee: highestIntervalFee ? {
689
+ id: highestIntervalFee.id,
690
+ value: highestIntervalFee.value,
691
+ minKm: highestIntervalFee.minKm,
692
+ maxKm: highestIntervalFee.maxKm,
693
+ } : null,
694
+ });
646
695
  if (highestIntervalFee) {
647
696
  // Calcula baseado na taxa do intervalo mais alto que tem maxKm
648
697
  var total_5 = +highestIntervalFee.value;
@@ -653,7 +702,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
653
702
  // Somar ao total
654
703
  total_5 += additionalValue;
655
704
  // Aplicar multiplicador de redelivery ao valor final
656
- var _k = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _k.adjustedTotal, redeliveryInfo_5 = _k.redeliveryInfo;
705
+ var _t = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _t.adjustedTotal, redeliveryInfo_5 = _t.redeliveryInfo;
657
706
  total_5 = adjustedTotal_5;
658
707
  var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
659
708
  style: 'currency',
@@ -671,9 +720,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
671
720
  break;
672
721
  case FeeCalculationTypeEnum.COMMODITY_VALUE:
673
722
  if (value) {
674
- var commodityValue = (_a = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _a !== void 0 ? _a : 0;
723
+ var commodityValue = (_j = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _j !== void 0 ? _j : 0;
675
724
  var total_6 = +commodityValue * (+value / 100);
676
- var _l = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _l.adjustedTotal, redeliveryInfo_6 = _l.redeliveryInfo;
725
+ var _u = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _u.adjustedTotal, redeliveryInfo_6 = _u.redeliveryInfo;
677
726
  total_6 = adjustedTotal_6;
678
727
  var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
679
728
  style: 'currency',
@@ -686,9 +735,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
686
735
  break;
687
736
  case FeeCalculationTypeEnum.TAXED_WEIGHT:
688
737
  if (value) {
689
- var taxedWeight = (_b = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _b !== void 0 ? _b : 0;
738
+ var taxedWeight = (_k = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _k !== void 0 ? _k : 0;
690
739
  var total_7 = +taxedWeight * +value;
691
- var _m = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _m.adjustedTotal, redeliveryInfo_7 = _m.redeliveryInfo;
740
+ var _v = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _v.adjustedTotal, redeliveryInfo_7 = _v.redeliveryInfo;
692
741
  total_7 = adjustedTotal_7;
693
742
  var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
694
743
  style: 'currency',
@@ -804,7 +853,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
804
853
  return 0;
805
854
  });
806
855
  if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
807
- if (((_c = siblingFeesResults[0]) === null || _c === void 0 ? void 0 : _c.totalFee) && ((_d = siblingFeesResults[0]) === null || _d === void 0 ? void 0 : _d.totalFee) > totalFee) {
856
+ if (((_l = siblingFeesResults[0]) === null || _l === void 0 ? void 0 : _l.totalFee) && ((_m = siblingFeesResults[0]) === null || _m === void 0 ? void 0 : _m.totalFee) > totalFee) {
808
857
  totalToCalc = 0;
809
858
  }
810
859
  }
Binary file