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