b2m-utils 0.0.295 → 0.0.296

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.
@@ -1374,7 +1374,7 @@ var getLaneFromRatecard = function (cte) {
1374
1374
  };
1375
1375
 
1376
1376
  var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1377
- var _a, _b, _c, _d;
1377
+ var _a, _b, _c, _d, _e, _f;
1378
1378
  var results = [];
1379
1379
  // Separar fees por tipo: normais, TOTAL_PERCENTAGE e ICMS
1380
1380
  var icmsFee = feesToCalc.find(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) === FeeEnum.ICMS || f.feeId === FeeEnum.ICMS; });
@@ -1385,6 +1385,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1385
1385
  f.feeId !== FeeEnum.ICMS &&
1386
1386
  ((_b = f.fee) === null || _b === void 0 ? void 0 : _b.feeCalculationTypeId) !== FeeCalculationTypeEnum.TOTAL_PERCENTAGE;
1387
1387
  });
1388
+ // PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
1389
+ console.log("\n\uD83D\uDCE6 [getCtesFeesResult] Calculando ".concat(normalFees.length, " fees normais"));
1388
1390
  var _loop_1 = function (item) {
1389
1391
  var feeTotal = calculateFee(item, cte, feesToCalc, false, allFeesForCalc);
1390
1392
  if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
@@ -1401,8 +1403,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1401
1403
  });
1402
1404
  if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
1403
1405
  var siblingFeesResults = [];
1404
- for (var _f = 0, siblingFees_1 = siblingFees; _f < siblingFees_1.length; _f++) {
1405
- var item_1 = siblingFees_1[_f];
1406
+ for (var _h = 0, siblingFees_1 = siblingFees; _h < siblingFees_1.length; _h++) {
1407
+ var item_1 = siblingFees_1[_h];
1406
1408
  var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
1407
1409
  siblingFeesResults.push(result);
1408
1410
  }
@@ -1414,12 +1416,14 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1414
1416
  });
1415
1417
  if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
1416
1418
  if (((_b = siblingFeesResults[0]) === null || _b === void 0 ? void 0 : _b.totalFee) && ((_c = siblingFeesResults[0]) === null || _c === void 0 ? void 0 : _c.totalFee) > totalFee) {
1419
+ console.log(" \u26A0\uFE0F ".concat((_d = item.fee) === null || _d === void 0 ? void 0 : _d.name, ": R$ ").concat(totalFee.toFixed(2), " \u2192 R$ 0.00 (sibling maior)"));
1417
1420
  totalToPush = 0;
1418
1421
  }
1419
1422
  }
1420
1423
  }
1421
1424
  }
1422
- if (!isNaN(+totalToPush)) {
1425
+ if (!isNaN(+totalToPush) && totalToPush > 0) {
1426
+ console.log(" \u2705 ".concat((_e = item.fee) === null || _e === void 0 ? void 0 : _e.name, ": R$ ").concat(totalToPush.toFixed(2)));
1423
1427
  results.push({
1424
1428
  total: +(totalToPush).toFixed(2),
1425
1429
  resultFee: resultFee,
@@ -1429,20 +1433,20 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1429
1433
  }
1430
1434
  }
1431
1435
  };
1432
- // PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
1433
1436
  for (var _i = 0, normalFees_1 = normalFees; _i < normalFees_1.length; _i++) {
1434
1437
  var item = normalFees_1[_i];
1435
1438
  _loop_1(item);
1436
1439
  }
1440
+ console.log("\uD83D\uDCCA Total parcial (fees normais): R$ ".concat(results.reduce(function (sum, r) { return sum + r.total; }, 0).toFixed(2)));
1437
1441
  // PASSADA 2: Calcular fees TOTAL_PERCENTAGE de forma iterativa
1438
1442
  if (totalPercentageFees.length > 0) {
1439
1443
  console.log("\n\uD83D\uDD04 [getCtesFeesResult] Calculando ".concat(totalPercentageFees.length, " fees TOTAL_PERCENTAGE"));
1440
1444
  console.log("\uD83D\uDCCB Fees: ".concat(totalPercentageFees.map(function (f) { var _a; return "".concat((_a = f.fee) === null || _a === void 0 ? void 0 : _a.name, " (").concat(f.value, "%)"); }).join(', ')));
1441
1445
  var percentageFeesCache = calculateTotalPercentageFees(feesToCalc, cte, allFeesForCalc);
1442
1446
  console.log("\u2705 Cache gerado com ".concat(percentageFeesCache.size, " fees"));
1443
- for (var _e = 0, totalPercentageFees_1 = totalPercentageFees; _e < totalPercentageFees_1.length; _e++) {
1444
- var item = totalPercentageFees_1[_e];
1445
- if ((_d = item.fee) === null || _d === void 0 ? void 0 : _d.id) {
1447
+ for (var _g = 0, totalPercentageFees_1 = totalPercentageFees; _g < totalPercentageFees_1.length; _g++) {
1448
+ var item = totalPercentageFees_1[_g];
1449
+ if ((_f = item.fee) === null || _f === void 0 ? void 0 : _f.id) {
1446
1450
  var cachedResult = percentageFeesCache.get(item.fee.id);
1447
1451
  if (cachedResult && cachedResult.totalFee && cachedResult.totalFee > 0) {
1448
1452
  console.log(" ".concat(item.fee.name, ": R$ ").concat(cachedResult.totalFee.toFixed(2)));
@@ -1458,15 +1462,20 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1458
1462
  }
1459
1463
  // PASSADA 3: Calcular ICMS com base em todas as fees anteriores (normais + TOTAL_PERCENTAGE)
1460
1464
  if (icmsFee) {
1465
+ console.log("\n\uD83D\uDCB0 [getCtesFeesResult] Calculando ICMS");
1461
1466
  // Coletar apenas os valores das fees que realmente contam (total > 0)
1462
1467
  var valuesForIcms = results
1463
1468
  .filter(function (r) { return r.total > 0; })
1464
1469
  .map(function (r) { return r.total; });
1470
+ console.log("\uD83D\uDCCA Valores para ICMS: ".concat(valuesForIcms.map(function (v) { return "R$ ".concat(v.toFixed(2)); }).join(' + '), " = R$ ").concat(valuesForIcms.reduce(function (a, b) { return a + b; }, 0).toFixed(2)));
1465
1471
  var icmsRate = (cte.icmsIncidence !== undefined && cte.icmsIncidence !== null && !isNaN(+cte.icmsIncidence))
1466
1472
  ? +(cte.icmsIncidence) / 100
1467
1473
  : icmsFee.value || 0;
1474
+ console.log("\uD83D\uDCC8 Al\u00EDquota ICMS: ".concat((icmsRate * 100).toFixed(2), "%"));
1468
1475
  // Usar calculateIcms diretamente
1469
1476
  var icmsCalculation = calculateIcms(valuesForIcms, icmsRate);
1477
+ console.log("\u2705 ICMS calculado: R$ ".concat(icmsCalculation.total.toFixed(2)));
1478
+ console.log("\uD83D\uDCCB Total de fees no results antes do ICMS: ".concat(results.length));
1470
1479
  if (icmsCalculation.isValid && !isNaN(+icmsCalculation.total)) {
1471
1480
  results.push({
1472
1481
  total: +(icmsCalculation.total).toFixed(2),
@@ -1474,8 +1483,11 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
1474
1483
  feeValue: icmsRate,
1475
1484
  feeId: icmsFee.feeId,
1476
1485
  });
1486
+ console.log("\uD83D\uDCCB Total de fees no results depois do ICMS: ".concat(results.length));
1477
1487
  }
1478
1488
  }
1489
+ console.log("\n\uD83C\uDFAF [getCtesFeesResult] Total final: R$ ".concat(results.reduce(function (sum, r) { return sum + r.total; }, 0).toFixed(2)));
1490
+ console.log("\uD83D\uDCCB Breakdown: ".concat(results.map(function (r) { return "R$ ".concat(r.total.toFixed(2)); }).join(' + '), "\n"));
1479
1491
  return results;
1480
1492
  };
1481
1493
 
Binary file