b2m-utils 0.0.280 → 0.0.281

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
@@ -1281,28 +1281,36 @@ var getLaneFromRatecard = function (cte) {
1281
1281
  };
1282
1282
 
1283
1283
  var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1284
- var _a, _b, _c;
1284
+ var _a, _b, _c, _d;
1285
1285
  var results = [];
1286
1286
  // Separar fees por tipo: normais, TOTAL_PERCENTAGE e ICMS
1287
- var icmsFee = feesToCalc.find(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) === exports.FeeEnum.ICMS; });
1287
+ var icmsFee = feesToCalc.find(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) === exports.FeeEnum.ICMS || f.feeId === exports.FeeEnum.ICMS; });
1288
1288
  var totalPercentageFees = feesToCalc.filter(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE; });
1289
1289
  var normalFees = feesToCalc.filter(function (f) {
1290
1290
  var _a, _b;
1291
1291
  return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) !== exports.FeeEnum.ICMS &&
1292
+ f.feeId !== exports.FeeEnum.ICMS &&
1292
1293
  ((_b = f.fee) === null || _b === void 0 ? void 0 : _b.feeCalculationTypeId) !== exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE;
1293
1294
  });
1295
+ console.log('DEBUG getCtesFeesResult - Separação de fees:', {
1296
+ totalFees: feesToCalc.length,
1297
+ icmsFee: icmsFee ? { feeId: icmsFee.feeId, 'fee.id': (_a = icmsFee.fee) === null || _a === void 0 ? void 0 : _a.id } : null,
1298
+ totalPercentageCount: totalPercentageFees.length,
1299
+ normalFeesCount: normalFees.length,
1300
+ normalFeeIds: normalFees.map(function (f) { var _a; return ({ feeId: f.feeId, 'fee.id': (_a = f.fee) === null || _a === void 0 ? void 0 : _a.id }); })
1301
+ });
1294
1302
  var _loop_1 = function (item) {
1295
1303
  var feeTotal = calculateFee(item, cte, feesToCalc, false, allFeesForCalc);
1296
1304
  if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
1297
1305
  var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
1298
1306
  var totalToPush = totalFee;
1299
- if ((_a = item.fee) === null || _a === void 0 ? void 0 : _a.parentId) {
1307
+ if ((_b = item.fee) === null || _b === void 0 ? void 0 : _b.parentId) {
1300
1308
  var fee_1 = item.fee;
1301
1309
  var siblingFees = feesToCalc === null || feesToCalc === void 0 ? void 0 : feesToCalc.filter(function (i) { var _a, _b; return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.parentId) === fee_1.parentId && ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== fee_1.id; });
1302
1310
  if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
1303
1311
  var siblingFeesResults = [];
1304
- for (var _e = 0, siblingFees_1 = siblingFees; _e < siblingFees_1.length; _e++) {
1305
- var item_1 = siblingFees_1[_e];
1312
+ for (var _f = 0, siblingFees_1 = siblingFees; _f < siblingFees_1.length; _f++) {
1313
+ var item_1 = siblingFees_1[_f];
1306
1314
  var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
1307
1315
  siblingFeesResults.push(result);
1308
1316
  }
@@ -1313,7 +1321,7 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1313
1321
  return 0;
1314
1322
  });
1315
1323
  if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
1316
- if (((_b = siblingFeesResults[0]) === null || _b === void 0 ? void 0 : _b.totalFee) && ((_c = siblingFeesResults[0]) === null || _c === void 0 ? void 0 : _c.totalFee) > totalFee) {
1324
+ if (((_c = siblingFeesResults[0]) === null || _c === void 0 ? void 0 : _c.totalFee) && ((_d = siblingFeesResults[0]) === null || _d === void 0 ? void 0 : _d.totalFee) > totalFee) {
1317
1325
  totalToPush = 0;
1318
1326
  }
1319
1327
  }
@@ -1335,8 +1343,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1335
1343
  _loop_1(item);
1336
1344
  }
1337
1345
  // PASSADA 2: Calcular fees TOTAL_PERCENTAGE usando a soma das fees normais já calculadas
1338
- for (var _d = 0, totalPercentageFees_1 = totalPercentageFees; _d < totalPercentageFees_1.length; _d++) {
1339
- var item = totalPercentageFees_1[_d];
1346
+ for (var _e = 0, totalPercentageFees_1 = totalPercentageFees; _e < totalPercentageFees_1.length; _e++) {
1347
+ var item = totalPercentageFees_1[_e];
1340
1348
  // Calcular soma das fees normais (excluindo TOTAL_PERCENTAGE e ICMS)
1341
1349
  var totalWithoutPercentageFees = results
1342
1350
  .filter(function (r) { return r.total > 0; })
package/build/index.js.gz CHANGED
Binary file