b2m-utils 0.0.271 → 0.0.273

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
@@ -586,6 +586,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
586
586
  var filteredFeesResults = filterSiblingFees(filteredFees.map(function (it) {
587
587
  return calculateFee(it, cte, allFees, debug, allFeesForCalc);
588
588
  }));
589
+ console.log({
590
+ filteredFeesResults: filteredFeesResults,
591
+ });
589
592
  var totalFromAllFees = filteredFeesResults.map(function (result) {
590
593
  if (result === null || result === void 0 ? void 0 : result.totalToCalc) {
591
594
  return result.totalToCalc;
@@ -1276,18 +1279,16 @@ var getLaneFromRatecard = function (cte) {
1276
1279
  };
1277
1280
 
1278
1281
  var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1279
- var _a, _b, _c, _d, _e, _f;
1282
+ var _a, _b, _c;
1280
1283
  var results = [];
1281
- // Separar ICMS e TOTAL_PERCENTAGE das outras fees
1284
+ // Separar ICMS das outras fees
1282
1285
  var icmsFee = feesToCalc.find(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) === exports.FeeEnum.ICMS; });
1283
- var totalPercentageFees = feesToCalc.filter(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE; });
1284
- var regularFees = feesToCalc.filter(function (f) {
1285
- var _a, _b;
1286
- return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) !== exports.FeeEnum.ICMS &&
1287
- ((_b = f.fee) === null || _b === void 0 ? void 0 : _b.feeCalculationTypeId) !== exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE;
1286
+ var nonIcmsFees = feesToCalc.filter(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) !== exports.FeeEnum.ICMS; });
1287
+ console.log({
1288
+ nonIcmsFees: nonIcmsFees,
1288
1289
  });
1289
1290
  var _loop_1 = function (item) {
1290
- var feeTotal = calculateFee(item, cte, regularFees, false, allFeesForCalc);
1291
+ var feeTotal = calculateFee(item, cte, feesToCalc, false, allFeesForCalc);
1291
1292
  if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
1292
1293
  var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
1293
1294
  var totalToPush = totalFee;
@@ -1296,8 +1297,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1296
1297
  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; });
1297
1298
  if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
1298
1299
  var siblingFeesResults = [];
1299
- for (var _h = 0, siblingFees_1 = siblingFees; _h < siblingFees_1.length; _h++) {
1300
- var item_1 = siblingFees_1[_h];
1300
+ for (var _d = 0, siblingFees_1 = siblingFees; _d < siblingFees_1.length; _d++) {
1301
+ var item_1 = siblingFees_1[_d];
1301
1302
  var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
1302
1303
  siblingFeesResults.push(result);
1303
1304
  }
@@ -1324,55 +1325,12 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1324
1325
  }
1325
1326
  }
1326
1327
  };
1327
- // PRIMEIRA PASSADA: Calcular fees regulares (exceto ICMS e TOTAL_PERCENTAGE)
1328
- for (var _i = 0, regularFees_1 = regularFees; _i < regularFees_1.length; _i++) {
1329
- var item = regularFees_1[_i];
1328
+ // PRIMEIRA PASSADA: Calcular todas as fees exceto ICMS
1329
+ for (var _i = 0, nonIcmsFees_1 = nonIcmsFees; _i < nonIcmsFees_1.length; _i++) {
1330
+ var item = nonIcmsFees_1[_i];
1330
1331
  _loop_1(item);
1331
1332
  }
1332
- var _loop_2 = function (item) {
1333
- var feeTotal = calculateFee(item, cte, regularFees, false, allFeesForCalc);
1334
- if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
1335
- var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
1336
- var totalToPush = totalFee;
1337
- if ((_d = item.fee) === null || _d === void 0 ? void 0 : _d.parentId) {
1338
- var fee_2 = item.fee;
1339
- 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; });
1340
- if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
1341
- var siblingFeesResults = [];
1342
- for (var _j = 0, siblingFees_2 = siblingFees; _j < siblingFees_2.length; _j++) {
1343
- var siblingItem = siblingFees_2[_j];
1344
- var result = calculateFee(siblingItem, cte, regularFees, false, allFeesForCalc);
1345
- siblingFeesResults.push(result);
1346
- }
1347
- siblingFeesResults.sort(function (a, b) {
1348
- if ((b === null || b === void 0 ? void 0 : b.totalFee) && (a === null || a === void 0 ? void 0 : a.totalFee)) {
1349
- return +(b === null || b === void 0 ? void 0 : b.totalFee) - +(a === null || a === void 0 ? void 0 : a.totalFee);
1350
- }
1351
- return 0;
1352
- });
1353
- if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
1354
- if (((_e = siblingFeesResults[0]) === null || _e === void 0 ? void 0 : _e.totalFee) && ((_f = siblingFeesResults[0]) === null || _f === void 0 ? void 0 : _f.totalFee) > totalFee) {
1355
- totalToPush = 0;
1356
- }
1357
- }
1358
- }
1359
- }
1360
- if (!isNaN(+totalToPush)) {
1361
- results.push({
1362
- total: +(totalToPush).toFixed(2),
1363
- resultFee: resultFee,
1364
- feeValue: feeValue,
1365
- feeId: item.feeId,
1366
- });
1367
- }
1368
- }
1369
- };
1370
- // SEGUNDA PASSADA: Calcular fees TOTAL_PERCENTAGE com base nas fees regulares já calculadas
1371
- for (var _g = 0, totalPercentageFees_1 = totalPercentageFees; _g < totalPercentageFees_1.length; _g++) {
1372
- var item = totalPercentageFees_1[_g];
1373
- _loop_2(item);
1374
- }
1375
- // TERCEIRA PASSADA: Calcular ICMS com base nos resultados já filtrados
1333
+ // SEGUNDA PASSADA: Calcular ICMS com base nos resultados já filtrados
1376
1334
  if (icmsFee) {
1377
1335
  // Coletar apenas os valores das fees que realmente contam (total > 0)
1378
1336
  var valuesForIcms = results
package/build/index.js.gz CHANGED
Binary file