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.
package/build/index.js CHANGED
@@ -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, _e, _f;
424
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
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 _g = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _g.adjustedTotal, redeliveryInfo_1 = _g.redeliveryInfo;
496
+ var _o = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _o.adjustedTotal, redeliveryInfo_1 = _o.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 _h = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _h.adjustedTotal, redeliveryInfo_2 = _h.redeliveryInfo;
514
+ var _p = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _p.adjustedTotal, redeliveryInfo_2 = _p.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 _j = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _j.adjustedTotal, redeliveryInfo_3 = _j.redeliveryInfo;
533
+ var _q = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _q.adjustedTotal, redeliveryInfo_3 = _q.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 _k = applyRedeliveryMultiplier(total, cte), adjustedTotal = _k.adjustedTotal, redeliveryInfo = _k.redeliveryInfo;
568
+ var _r = applyRedeliveryMultiplier(total, cte), adjustedTotal = _r.adjustedTotal, redeliveryInfo = _r.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 _l = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _l.adjustedTotal, redeliveryInfo_4 = _l.redeliveryInfo;
620
+ var _s = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _s.adjustedTotal, redeliveryInfo_4 = _s.redeliveryInfo;
621
621
  total_4 = adjustedTotal_4;
622
622
  var valueCurrency_2 = (+highestIntervalFee.value).toLocaleString('pt-br', {
623
623
  style: 'currency',
@@ -646,19 +646,33 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
646
646
  value: ratecardLaneFee.value,
647
647
  minKm: ratecardLaneFee.minKm,
648
648
  maxKm: ratecardLaneFee.maxKm,
649
+ laneId: ratecardLaneFee.laneId,
649
650
  },
650
- allFeesForCalcCount: allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.length,
651
+ hasRatecard: !!((_c = cte.carrier) === null || _c === void 0 ? void 0 : _c.Ratecard),
652
+ ratecardCount: (_e = (_d = cte.carrier) === null || _d === void 0 ? void 0 : _d.Ratecard) === null || _e === void 0 ? void 0 : _e.length,
653
+ });
654
+ // Buscar o ratecard correto do CTE usando getRatecardFromCte
655
+ var ratecard = getRatecardFromCte(cte);
656
+ 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; });
657
+ console.log('[calculateFee] FTL - Ratecard e Lane encontrados', {
658
+ cteId: cte.id,
659
+ ratecardId: ratecard === null || ratecard === void 0 ? void 0 : ratecard.id,
660
+ ratecardName: ratecard === null || ratecard === void 0 ? void 0 : ratecard.name,
661
+ laneId: lane === null || lane === void 0 ? void 0 : lane.id,
662
+ laneFeeCount: (_g = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _g === void 0 ? void 0 : _g.length,
663
+ ratecard: ratecard,
664
+ lane: lane,
651
665
  });
652
666
  // Não tem maxKm - é o último intervalo
653
- // Encontrar todas as taxas do mesmo tipo que têm maxKm
654
- var feesWithMaxKm = allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.filter(function (fee) {
667
+ // Encontrar todas as taxas do mesmo tipo que têm maxKm no ratecard
668
+ var feesWithMaxKm = (_h = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _h === void 0 ? void 0 : _h.filter(function (fee) {
655
669
  var _a, _b;
656
670
  return ((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.id) &&
657
671
  fee.maxKm &&
658
672
  (cte === null || cte === void 0 ? void 0 : cte.distance) &&
659
673
  +fee.maxKm < +cte.distance;
660
674
  });
661
- console.log('[calculateFee] FTL - Fees com maxKm encontradas', {
675
+ console.log('[calculateFee] FTL - Fees com maxKm encontradas no ratecard', {
662
676
  cteId: cte.id,
663
677
  feesWithMaxKmCount: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.length,
664
678
  feesWithMaxKm: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.map(function (f) { return ({
@@ -668,9 +682,6 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
668
682
  maxKm: f.maxKm,
669
683
  }); }),
670
684
  });
671
- console.log({
672
- cte: cte,
673
- });
674
685
  // Ordenar pelo maxKm do maior para o menor
675
686
  feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
676
687
  // Pegar o primeiro (maior maxKm)
@@ -695,7 +706,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
695
706
  // Somar ao total
696
707
  total_5 += additionalValue;
697
708
  // Aplicar multiplicador de redelivery ao valor final
698
- var _m = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _m.adjustedTotal, redeliveryInfo_5 = _m.redeliveryInfo;
709
+ var _t = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _t.adjustedTotal, redeliveryInfo_5 = _t.redeliveryInfo;
699
710
  total_5 = adjustedTotal_5;
700
711
  var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
701
712
  style: 'currency',
@@ -713,9 +724,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
713
724
  break;
714
725
  case exports.FeeCalculationTypeEnum.COMMODITY_VALUE:
715
726
  if (value) {
716
- var commodityValue = (_c = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _c !== void 0 ? _c : 0;
727
+ var commodityValue = (_j = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _j !== void 0 ? _j : 0;
717
728
  var total_6 = +commodityValue * (+value / 100);
718
- var _o = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _o.adjustedTotal, redeliveryInfo_6 = _o.redeliveryInfo;
729
+ var _u = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _u.adjustedTotal, redeliveryInfo_6 = _u.redeliveryInfo;
719
730
  total_6 = adjustedTotal_6;
720
731
  var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
721
732
  style: 'currency',
@@ -728,9 +739,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
728
739
  break;
729
740
  case exports.FeeCalculationTypeEnum.TAXED_WEIGHT:
730
741
  if (value) {
731
- var taxedWeight = (_d = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _d !== void 0 ? _d : 0;
742
+ var taxedWeight = (_k = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _k !== void 0 ? _k : 0;
732
743
  var total_7 = +taxedWeight * +value;
733
- var _p = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _p.adjustedTotal, redeliveryInfo_7 = _p.redeliveryInfo;
744
+ var _v = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _v.adjustedTotal, redeliveryInfo_7 = _v.redeliveryInfo;
734
745
  total_7 = adjustedTotal_7;
735
746
  var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
736
747
  style: 'currency',
@@ -846,7 +857,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
846
857
  return 0;
847
858
  });
848
859
  if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
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) {
860
+ if (((_l = siblingFeesResults[0]) === null || _l === void 0 ? void 0 : _l.totalFee) && ((_m = siblingFeesResults[0]) === null || _m === void 0 ? void 0 : _m.totalFee) > totalFee) {
850
861
  totalToCalc = 0;
851
862
  }
852
863
  }
package/build/index.js.gz CHANGED
Binary file