b2m-utils 0.0.291 → 0.0.293

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
@@ -1008,8 +1008,17 @@ var calculateIcms = function (totalFromAllFees, icmsRate) {
1008
1008
  var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc) {
1009
1009
  var results = new Map();
1010
1010
  // Separar fees em dois grupos
1011
- var nonPercentageFees = allFees.filter(function (i) { var _a; return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) !== exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE; });
1012
- var percentageFees = allFees.filter(function (i) { var _a; return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE; });
1011
+ // IMPORTANTE: ICMS não deve ser calculado aqui, ele tem tratamento especial no calculateFee
1012
+ var nonPercentageFees = allFees.filter(function (i) {
1013
+ var _a, _b;
1014
+ return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) !== exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
1015
+ ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== exports.FeeEnum.ICMS;
1016
+ });
1017
+ var percentageFees = allFees.filter(function (i) {
1018
+ var _a, _b;
1019
+ return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
1020
+ ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== exports.FeeEnum.ICMS;
1021
+ });
1013
1022
  // Se não houver fees percentuais, retornar vazio
1014
1023
  if (percentageFees.length === 0) {
1015
1024
  return results;
@@ -1017,11 +1026,13 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc) {
1017
1026
  console.log("\n\uD83D\uDD04 Calculando ".concat(percentageFees.length, " fees TOTAL_PERCENTAGE de forma iterativa"));
1018
1027
  console.log("\uD83D\uDCCB Fees: ".concat(percentageFees.map(function (f) { var _a; return "".concat((_a = f.fee) === null || _a === void 0 ? void 0 : _a.name, " (").concat(f.value, "%)"); }).join(', ')));
1019
1028
  // Calcular fees não-percentuais (base fixa)
1029
+ console.log("\uD83D\uDCCB Fees n\u00E3o-percentuais: ".concat(nonPercentageFees.map(function (f) { var _a; return "".concat((_a = f.fee) === null || _a === void 0 ? void 0 : _a.name); }).join(', ')));
1020
1030
  var nonPercentageResults = filterSiblingFees(nonPercentageFees.map(function (it) {
1021
1031
  return calculateFee(it, cte, allFees, false, allFeesForCalc);
1022
1032
  }));
1023
1033
  var baseNonPercentage = nonPercentageResults.reduce(function (sum, r) { return sum + (r.totalToCalc || 0); }, 0);
1024
1034
  console.log("\uD83D\uDCCA Base n\u00E3o-percentual: R$ ".concat(baseNonPercentage.toFixed(2)));
1035
+ console.log("\uD83D\uDCCA Detalhamento: ".concat(nonPercentageResults.map(function (r) { var _a, _b; return "".concat((_a = r.fee) === null || _a === void 0 ? void 0 : _a.name, "=").concat((_b = r.totalToCalc) === null || _b === void 0 ? void 0 : _b.toFixed(2)); }).join(', ')));
1025
1036
  // Calcular fees percentuais iterativamente até convergir
1026
1037
  var maxIterations = 10;
1027
1038
  var tolerance = 0.01; // Tolerância de 1 centavo
package/build/index.js.gz CHANGED
Binary file