b2m-utils 0.0.270 → 0.0.271

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.
@@ -1272,13 +1272,18 @@ var getLaneFromRatecard = function (cte) {
1272
1272
  };
1273
1273
 
1274
1274
  var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1275
- var _a, _b, _c;
1275
+ var _a, _b, _c, _d, _e, _f;
1276
1276
  var results = [];
1277
- // Separar ICMS das outras fees
1277
+ // Separar ICMS e TOTAL_PERCENTAGE das outras fees
1278
1278
  var icmsFee = feesToCalc.find(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) === FeeEnum.ICMS; });
1279
- var nonIcmsFees = feesToCalc.filter(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) !== FeeEnum.ICMS; });
1279
+ var totalPercentageFees = feesToCalc.filter(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === FeeCalculationTypeEnum.TOTAL_PERCENTAGE; });
1280
+ var regularFees = feesToCalc.filter(function (f) {
1281
+ var _a, _b;
1282
+ return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) !== FeeEnum.ICMS &&
1283
+ ((_b = f.fee) === null || _b === void 0 ? void 0 : _b.feeCalculationTypeId) !== FeeCalculationTypeEnum.TOTAL_PERCENTAGE;
1284
+ });
1280
1285
  var _loop_1 = function (item) {
1281
- var feeTotal = calculateFee(item, cte, feesToCalc, false, allFeesForCalc);
1286
+ var feeTotal = calculateFee(item, cte, regularFees, false, allFeesForCalc);
1282
1287
  if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
1283
1288
  var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
1284
1289
  var totalToPush = totalFee;
@@ -1287,8 +1292,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1287
1292
  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; });
1288
1293
  if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
1289
1294
  var siblingFeesResults = [];
1290
- for (var _d = 0, siblingFees_1 = siblingFees; _d < siblingFees_1.length; _d++) {
1291
- var item_1 = siblingFees_1[_d];
1295
+ for (var _h = 0, siblingFees_1 = siblingFees; _h < siblingFees_1.length; _h++) {
1296
+ var item_1 = siblingFees_1[_h];
1292
1297
  var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
1293
1298
  siblingFeesResults.push(result);
1294
1299
  }
@@ -1315,12 +1320,55 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1315
1320
  }
1316
1321
  }
1317
1322
  };
1318
- // PRIMEIRA PASSADA: Calcular todas as fees exceto ICMS
1319
- for (var _i = 0, nonIcmsFees_1 = nonIcmsFees; _i < nonIcmsFees_1.length; _i++) {
1320
- var item = nonIcmsFees_1[_i];
1323
+ // PRIMEIRA PASSADA: Calcular fees regulares (exceto ICMS e TOTAL_PERCENTAGE)
1324
+ for (var _i = 0, regularFees_1 = regularFees; _i < regularFees_1.length; _i++) {
1325
+ var item = regularFees_1[_i];
1321
1326
  _loop_1(item);
1322
1327
  }
1323
- // SEGUNDA PASSADA: Calcular ICMS com base nos resultados já filtrados
1328
+ var _loop_2 = function (item) {
1329
+ var feeTotal = calculateFee(item, cte, regularFees, false, allFeesForCalc);
1330
+ if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
1331
+ var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
1332
+ var totalToPush = totalFee;
1333
+ if ((_d = item.fee) === null || _d === void 0 ? void 0 : _d.parentId) {
1334
+ var fee_2 = item.fee;
1335
+ var siblingFees = totalPercentageFees === null || totalPercentageFees === void 0 ? void 0 : totalPercentageFees.filter(function (i) { var _a, _b; return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.parentId) === fee_2.parentId && ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== fee_2.id; });
1336
+ if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
1337
+ var siblingFeesResults = [];
1338
+ for (var _j = 0, siblingFees_2 = siblingFees; _j < siblingFees_2.length; _j++) {
1339
+ var siblingItem = siblingFees_2[_j];
1340
+ var result = calculateFee(siblingItem, cte, regularFees, false, allFeesForCalc);
1341
+ siblingFeesResults.push(result);
1342
+ }
1343
+ siblingFeesResults.sort(function (a, b) {
1344
+ if ((b === null || b === void 0 ? void 0 : b.totalFee) && (a === null || a === void 0 ? void 0 : a.totalFee)) {
1345
+ return +(b === null || b === void 0 ? void 0 : b.totalFee) - +(a === null || a === void 0 ? void 0 : a.totalFee);
1346
+ }
1347
+ return 0;
1348
+ });
1349
+ if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
1350
+ if (((_e = siblingFeesResults[0]) === null || _e === void 0 ? void 0 : _e.totalFee) && ((_f = siblingFeesResults[0]) === null || _f === void 0 ? void 0 : _f.totalFee) > totalFee) {
1351
+ totalToPush = 0;
1352
+ }
1353
+ }
1354
+ }
1355
+ }
1356
+ if (!isNaN(+totalToPush)) {
1357
+ results.push({
1358
+ total: +(totalToPush).toFixed(2),
1359
+ resultFee: resultFee,
1360
+ feeValue: feeValue,
1361
+ feeId: item.feeId,
1362
+ });
1363
+ }
1364
+ }
1365
+ };
1366
+ // SEGUNDA PASSADA: Calcular fees TOTAL_PERCENTAGE com base nas fees regulares já calculadas
1367
+ for (var _g = 0, totalPercentageFees_1 = totalPercentageFees; _g < totalPercentageFees_1.length; _g++) {
1368
+ var item = totalPercentageFees_1[_g];
1369
+ _loop_2(item);
1370
+ }
1371
+ // TERCEIRA PASSADA: Calcular ICMS com base nos resultados já filtrados
1324
1372
  if (icmsFee) {
1325
1373
  // Coletar apenas os valores das fees que realmente contam (total > 0)
1326
1374
  var valuesForIcms = results
Binary file