b2m-utils 0.0.234 → 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, _e, _f;
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 _g = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _g.adjustedTotal, redeliveryInfo_1 = _g.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 _h = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _h.adjustedTotal, redeliveryInfo_2 = _h.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 _j = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _j.adjustedTotal, redeliveryInfo_3 = _j.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 _k = applyRedeliveryMultiplier(total, cte), adjustedTotal = _k.adjustedTotal, redeliveryInfo = _k.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 _l = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _l.adjustedTotal, redeliveryInfo_4 = _l.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',
@@ -642,19 +642,33 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
642
642
  value: ratecardLaneFee.value,
643
643
  minKm: ratecardLaneFee.minKm,
644
644
  maxKm: ratecardLaneFee.maxKm,
645
+ laneId: ratecardLaneFee.laneId,
645
646
  },
646
- allFeesForCalcCount: allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.length,
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,
647
661
  });
648
662
  // Não tem maxKm - é o último intervalo
649
- // Encontrar todas as taxas do mesmo tipo que têm maxKm
650
- 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) {
651
665
  var _a, _b;
652
666
  return ((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.id) &&
653
667
  fee.maxKm &&
654
668
  (cte === null || cte === void 0 ? void 0 : cte.distance) &&
655
669
  +fee.maxKm < +cte.distance;
656
670
  });
657
- console.log('[calculateFee] FTL - Fees com maxKm encontradas', {
671
+ console.log('[calculateFee] FTL - Fees com maxKm encontradas no ratecard', {
658
672
  cteId: cte.id,
659
673
  feesWithMaxKmCount: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.length,
660
674
  feesWithMaxKm: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.map(function (f) { return ({
@@ -664,9 +678,6 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
664
678
  maxKm: f.maxKm,
665
679
  }); }),
666
680
  });
667
- console.log({
668
- cte: cte,
669
- });
670
681
  // Ordenar pelo maxKm do maior para o menor
671
682
  feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
672
683
  // Pegar o primeiro (maior maxKm)
@@ -691,7 +702,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
691
702
  // Somar ao total
692
703
  total_5 += additionalValue;
693
704
  // Aplicar multiplicador de redelivery ao valor final
694
- var _m = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _m.adjustedTotal, redeliveryInfo_5 = _m.redeliveryInfo;
705
+ var _t = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _t.adjustedTotal, redeliveryInfo_5 = _t.redeliveryInfo;
695
706
  total_5 = adjustedTotal_5;
696
707
  var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
697
708
  style: 'currency',
@@ -709,9 +720,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
709
720
  break;
710
721
  case FeeCalculationTypeEnum.COMMODITY_VALUE:
711
722
  if (value) {
712
- var commodityValue = (_c = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _c !== void 0 ? _c : 0;
723
+ var commodityValue = (_j = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _j !== void 0 ? _j : 0;
713
724
  var total_6 = +commodityValue * (+value / 100);
714
- var _o = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _o.adjustedTotal, redeliveryInfo_6 = _o.redeliveryInfo;
725
+ var _u = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _u.adjustedTotal, redeliveryInfo_6 = _u.redeliveryInfo;
715
726
  total_6 = adjustedTotal_6;
716
727
  var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
717
728
  style: 'currency',
@@ -724,9 +735,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
724
735
  break;
725
736
  case FeeCalculationTypeEnum.TAXED_WEIGHT:
726
737
  if (value) {
727
- var taxedWeight = (_d = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _d !== void 0 ? _d : 0;
738
+ var taxedWeight = (_k = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _k !== void 0 ? _k : 0;
728
739
  var total_7 = +taxedWeight * +value;
729
- var _p = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _p.adjustedTotal, redeliveryInfo_7 = _p.redeliveryInfo;
740
+ var _v = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _v.adjustedTotal, redeliveryInfo_7 = _v.redeliveryInfo;
730
741
  total_7 = adjustedTotal_7;
731
742
  var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
732
743
  style: 'currency',
@@ -842,7 +853,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
842
853
  return 0;
843
854
  });
844
855
  if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
845
- if (((_e = siblingFeesResults[0]) === null || _e === void 0 ? void 0 : _e.totalFee) && ((_f = siblingFeesResults[0]) === null || _f === void 0 ? void 0 : _f.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) {
846
857
  totalToCalc = 0;
847
858
  }
848
859
  }
Binary file