b2m-utils 0.0.290 → 0.0.292

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.
@@ -578,7 +578,15 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
578
578
  switch (fee_1.feeCalculationTypeId) {
579
579
  case FeeCalculationTypeEnum.TOTAL_PERCENTAGE:
580
580
  if (allFees && Array.isArray(allFees) && (allFees === null || allFees === void 0 ? void 0 : allFees.length) > 0) {
581
- var filteredFees = allFees.filter(function (i) { var _a, _b, _c; return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.id) !== fee_1.id && ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== FeeEnum.ICMS && ((_c = i.fee) === null || _c === void 0 ? void 0 : _c.parentId) !== fee_1.parentId; });
581
+ // Filtrar fees excluindo a própria fee, ICMS e fees irmãs
582
+ // IMPORTANTE: Também excluir outras fees TOTAL_PERCENTAGE para evitar recursão infinita
583
+ var filteredFees = allFees.filter(function (i) {
584
+ var _a, _b, _c, _d;
585
+ return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.id) !== fee_1.id &&
586
+ ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== FeeEnum.ICMS &&
587
+ ((_c = i.fee) === null || _c === void 0 ? void 0 : _c.parentId) !== fee_1.parentId &&
588
+ ((_d = i.fee) === null || _d === void 0 ? void 0 : _d.feeCalculationTypeId) !== FeeCalculationTypeEnum.TOTAL_PERCENTAGE;
589
+ });
582
590
  var filteredFeesResults = filterSiblingFees(filteredFees.map(function (it) {
583
591
  return calculateFee(it, cte, allFees, debug, allFeesForCalc);
584
592
  }));
@@ -996,8 +1004,17 @@ var calculateIcms = function (totalFromAllFees, icmsRate) {
996
1004
  var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc) {
997
1005
  var results = new Map();
998
1006
  // Separar fees em dois grupos
999
- var nonPercentageFees = allFees.filter(function (i) { var _a; return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) !== FeeCalculationTypeEnum.TOTAL_PERCENTAGE; });
1000
- var percentageFees = allFees.filter(function (i) { var _a; return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === FeeCalculationTypeEnum.TOTAL_PERCENTAGE; });
1007
+ // IMPORTANTE: ICMS não deve ser calculado aqui, ele tem tratamento especial no calculateFee
1008
+ var nonPercentageFees = allFees.filter(function (i) {
1009
+ var _a, _b;
1010
+ return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) !== FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
1011
+ ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== FeeEnum.ICMS;
1012
+ });
1013
+ var percentageFees = allFees.filter(function (i) {
1014
+ var _a, _b;
1015
+ return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
1016
+ ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== FeeEnum.ICMS;
1017
+ });
1001
1018
  // Se não houver fees percentuais, retornar vazio
1002
1019
  if (percentageFees.length === 0) {
1003
1020
  return results;
Binary file