b2m-utils 0.0.234 → 0.0.236

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,34 @@ 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) &&
667
+ cte.vehicleTypeId === ratecardLaneFee.vehicleTypeId &&
653
668
  fee.maxKm &&
654
669
  (cte === null || cte === void 0 ? void 0 : cte.distance) &&
655
670
  +fee.maxKm < +cte.distance;
656
671
  });
657
- console.log('[calculateFee] FTL - Fees com maxKm encontradas', {
672
+ console.log('[calculateFee] FTL - Fees com maxKm encontradas no ratecard', {
658
673
  cteId: cte.id,
659
674
  feesWithMaxKmCount: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.length,
660
675
  feesWithMaxKm: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.map(function (f) { return ({
@@ -664,9 +679,6 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
664
679
  maxKm: f.maxKm,
665
680
  }); }),
666
681
  });
667
- console.log({
668
- cte: cte,
669
- });
670
682
  // Ordenar pelo maxKm do maior para o menor
671
683
  feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
672
684
  // Pegar o primeiro (maior maxKm)
@@ -691,7 +703,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
691
703
  // Somar ao total
692
704
  total_5 += additionalValue;
693
705
  // Aplicar multiplicador de redelivery ao valor final
694
- var _m = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _m.adjustedTotal, redeliveryInfo_5 = _m.redeliveryInfo;
706
+ var _t = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _t.adjustedTotal, redeliveryInfo_5 = _t.redeliveryInfo;
695
707
  total_5 = adjustedTotal_5;
696
708
  var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
697
709
  style: 'currency',
@@ -709,9 +721,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
709
721
  break;
710
722
  case FeeCalculationTypeEnum.COMMODITY_VALUE:
711
723
  if (value) {
712
- var commodityValue = (_c = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _c !== void 0 ? _c : 0;
724
+ var commodityValue = (_j = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _j !== void 0 ? _j : 0;
713
725
  var total_6 = +commodityValue * (+value / 100);
714
- var _o = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _o.adjustedTotal, redeliveryInfo_6 = _o.redeliveryInfo;
726
+ var _u = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _u.adjustedTotal, redeliveryInfo_6 = _u.redeliveryInfo;
715
727
  total_6 = adjustedTotal_6;
716
728
  var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
717
729
  style: 'currency',
@@ -724,9 +736,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
724
736
  break;
725
737
  case FeeCalculationTypeEnum.TAXED_WEIGHT:
726
738
  if (value) {
727
- var taxedWeight = (_d = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _d !== void 0 ? _d : 0;
739
+ var taxedWeight = (_k = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _k !== void 0 ? _k : 0;
728
740
  var total_7 = +taxedWeight * +value;
729
- var _p = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _p.adjustedTotal, redeliveryInfo_7 = _p.redeliveryInfo;
741
+ var _v = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _v.adjustedTotal, redeliveryInfo_7 = _v.redeliveryInfo;
730
742
  total_7 = adjustedTotal_7;
731
743
  var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
732
744
  style: 'currency',
@@ -842,7 +854,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
842
854
  return 0;
843
855
  });
844
856
  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) {
857
+ 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
858
  totalToCalc = 0;
847
859
  }
848
860
  }
Binary file