b2m-utils 0.0.313 → 0.0.314

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
@@ -1072,59 +1072,74 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
1072
1072
  if (percentageFees.length === 0) {
1073
1073
  return results;
1074
1074
  }
1075
- // Calcular base das fees não-percentuais
1076
- // Se temos currentValues, usar eles; senão calcular normalmente
1077
- var baseNonPercentage = 0;
1078
- var nonPercentageDetails = [];
1079
- if (currentValues) {
1080
- // Usar valores atuais das fees não-percentuais
1081
- baseNonPercentage = nonPercentageFees.reduce(function (sum, fee) {
1082
- var _a;
1083
- var value = ((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) ? currentValues.get(fee.fee.id) : undefined;
1084
- if (value !== undefined) {
1085
- nonPercentageDetails.push({
1086
- feeId: fee.fee.id,
1087
- feeName: fee.fee.name || 'Unknown',
1088
- value: value
1089
- });
1090
- return sum + value;
1091
- }
1092
- // Se não tem valor atual, calcular
1093
- var calculated = calculateFee(fee, cte, allFees, false, allFeesForCalc);
1094
- var calcValue = (calculated === null || calculated === void 0 ? void 0 : calculated.totalToCalc) || 0;
1095
- if (calcValue > 0) {
1096
- nonPercentageDetails.push({
1097
- feeId: fee.fee.id,
1098
- feeName: fee.fee.name || 'Unknown',
1099
- value: calcValue
1100
- });
1101
- }
1102
- return sum + calcValue;
1103
- }, 0);
1104
- }
1105
- else {
1106
- // Calcular normalmente
1107
- var nonPercentageResults = filterSiblingFees(nonPercentageFees.map(function (it) {
1108
- return calculateFee(it, cte, allFees, false, allFeesForCalc);
1109
- }));
1110
- baseNonPercentage = nonPercentageResults.reduce(function (sum, r) {
1111
- var _a;
1112
- var value = r.totalToCalc || 0;
1113
- if (value > 0 && ((_a = r.fee) === null || _a === void 0 ? void 0 : _a.id)) {
1114
- nonPercentageDetails.push({
1115
- feeId: r.fee.id,
1116
- feeName: r.fee.name || 'Unknown',
1117
- value: value
1118
- });
1119
- }
1120
- return sum + value;
1121
- }, 0);
1122
- }
1123
- console.log('[calculateTotalPercentageFees] Base não-percentual calculada', {
1124
- baseNonPercentage: baseNonPercentage,
1125
- nonPercentageFeesCount: nonPercentageFees.length,
1126
- nonPercentageDetails: nonPercentageDetails
1127
- });
1075
+ // Calcular base das fees não-percentuais para cada fee TOTAL_PERCENTAGE
1076
+ // Cada fee TOTAL_PERCENTAGE terá sua própria baseNonPercentage (excluindo suas fees configuradas)
1077
+ var calculateBaseNonPercentageForFee = function (excludedFeeIds) {
1078
+ var base = 0;
1079
+ var details = [];
1080
+ if (currentValues) {
1081
+ // Usar valores atuais das fees não-percentuais
1082
+ nonPercentageFees.forEach(function (fee) {
1083
+ var _a;
1084
+ if (!((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id))
1085
+ return;
1086
+ var isExcluded = excludedFeeIds.has(fee.fee.id);
1087
+ var value = currentValues.get(fee.fee.id);
1088
+ if (value !== undefined) {
1089
+ details.push({
1090
+ feeId: fee.fee.id,
1091
+ feeName: fee.fee.name || 'Unknown',
1092
+ value: value,
1093
+ excluded: isExcluded
1094
+ });
1095
+ if (!isExcluded) {
1096
+ base += value;
1097
+ }
1098
+ }
1099
+ else {
1100
+ // Se não tem valor atual, calcular
1101
+ var calculated = calculateFee(fee, cte, allFees, false, allFeesForCalc);
1102
+ var calcValue = (calculated === null || calculated === void 0 ? void 0 : calculated.totalToCalc) || 0;
1103
+ if (calcValue > 0) {
1104
+ details.push({
1105
+ feeId: fee.fee.id,
1106
+ feeName: fee.fee.name || 'Unknown',
1107
+ value: calcValue,
1108
+ excluded: isExcluded
1109
+ });
1110
+ if (!isExcluded) {
1111
+ base += calcValue;
1112
+ }
1113
+ }
1114
+ }
1115
+ });
1116
+ }
1117
+ else {
1118
+ // Calcular normalmente
1119
+ var nonPercentageResults = filterSiblingFees(nonPercentageFees.map(function (it) {
1120
+ return calculateFee(it, cte, allFees, false, allFeesForCalc);
1121
+ }));
1122
+ nonPercentageResults.forEach(function (r) {
1123
+ var _a;
1124
+ if (!((_a = r.fee) === null || _a === void 0 ? void 0 : _a.id))
1125
+ return;
1126
+ var isExcluded = excludedFeeIds.has(r.fee.id);
1127
+ var value = r.totalToCalc || 0;
1128
+ if (value > 0) {
1129
+ details.push({
1130
+ feeId: r.fee.id,
1131
+ feeName: r.fee.name || 'Unknown',
1132
+ value: value,
1133
+ excluded: isExcluded
1134
+ });
1135
+ if (!isExcluded) {
1136
+ base += value;
1137
+ }
1138
+ }
1139
+ });
1140
+ }
1141
+ return { base: base, details: details };
1142
+ };
1128
1143
  // Calcular fees percentuais iterativamente até convergir
1129
1144
  var maxIterations = 10;
1130
1145
  var tolerance = 0.01; // Tolerância de 1 centavo
@@ -1155,6 +1170,9 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
1155
1170
  excludedFeeIds: Array.from(excludedFeeIds),
1156
1171
  iteration: iteration
1157
1172
  });
1173
+ // Calcular base não-percentual específica para esta fee (excluindo fees configuradas)
1174
+ var _a = calculateBaseNonPercentageForFee(excludedFeeIds), baseNonPercentage = _a.base, nonPercentageDetails = _a.details;
1175
+ // Calcular base percentual (outras fees TOTAL_PERCENTAGE, exceto ela mesma e excluídas)
1158
1176
  var basePercentage = Array.from(previousValues.entries())
1159
1177
  .filter(function (_a) {
1160
1178
  var feeId = _a[0];
@@ -1171,6 +1189,7 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
1171
1189
  feeId: pf.fee.id,
1172
1190
  feeName: pf.fee.name,
1173
1191
  baseNonPercentage: baseNonPercentage,
1192
+ nonPercentageDetails: nonPercentageDetails,
1174
1193
  basePercentage: basePercentage,
1175
1194
  baseValue: baseValue,
1176
1195
  percentValue: "".concat(pf.value, "%"),
package/build/index.js.gz CHANGED
Binary file