b2m-utils 0.0.302 → 0.0.303
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.esm.js +8 -25
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +8 -25
- package/build/index.js.gz +0 -0
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -1447,7 +1447,7 @@ var getLaneFromRatecard = function (cte) {
|
|
|
1447
1447
|
};
|
|
1448
1448
|
|
|
1449
1449
|
var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
1450
|
-
var _a, _b, _c, _d
|
|
1450
|
+
var _a, _b, _c, _d;
|
|
1451
1451
|
var results = [];
|
|
1452
1452
|
// Separar fees por tipo: normais, TOTAL_PERCENTAGE e ICMS
|
|
1453
1453
|
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; });
|
|
@@ -1458,8 +1458,6 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1458
1458
|
f.feeId !== exports.FeeEnum.ICMS &&
|
|
1459
1459
|
((_b = f.fee) === null || _b === void 0 ? void 0 : _b.feeCalculationTypeId) !== exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE;
|
|
1460
1460
|
});
|
|
1461
|
-
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1462
|
-
console.log("\n\uD83D\uDCE6 [getCtesFeesResult] Calculando ".concat(normalFees.length, " fees normais"));
|
|
1463
1461
|
var _loop_1 = function (item) {
|
|
1464
1462
|
var feeTotal = calculateFee(item, cte, feesToCalc, false, allFeesForCalc);
|
|
1465
1463
|
if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
|
|
@@ -1476,8 +1474,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1476
1474
|
});
|
|
1477
1475
|
if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
|
|
1478
1476
|
var siblingFeesResults = [];
|
|
1479
|
-
for (var
|
|
1480
|
-
var item_1 = siblingFees_1[
|
|
1477
|
+
for (var _f = 0, siblingFees_1 = siblingFees; _f < siblingFees_1.length; _f++) {
|
|
1478
|
+
var item_1 = siblingFees_1[_f];
|
|
1481
1479
|
var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
|
|
1482
1480
|
siblingFeesResults.push(result);
|
|
1483
1481
|
}
|
|
@@ -1489,14 +1487,12 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1489
1487
|
});
|
|
1490
1488
|
if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
|
|
1491
1489
|
if (((_b = siblingFeesResults[0]) === null || _b === void 0 ? void 0 : _b.totalFee) && ((_c = siblingFeesResults[0]) === null || _c === void 0 ? void 0 : _c.totalFee) > totalFee) {
|
|
1492
|
-
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)"));
|
|
1493
1490
|
totalToPush = 0;
|
|
1494
1491
|
}
|
|
1495
1492
|
}
|
|
1496
1493
|
}
|
|
1497
1494
|
}
|
|
1498
1495
|
if (!isNaN(+totalToPush) && totalToPush > 0) {
|
|
1499
|
-
console.log(" \u2705 ".concat((_e = item.fee) === null || _e === void 0 ? void 0 : _e.name, ": R$ ").concat(totalToPush.toFixed(2)));
|
|
1500
1496
|
results.push({
|
|
1501
1497
|
total: +(totalToPush).toFixed(2),
|
|
1502
1498
|
resultFee: resultFee,
|
|
@@ -1506,15 +1502,13 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1506
1502
|
}
|
|
1507
1503
|
}
|
|
1508
1504
|
};
|
|
1505
|
+
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1509
1506
|
for (var _i = 0, normalFees_1 = normalFees; _i < normalFees_1.length; _i++) {
|
|
1510
1507
|
var item = normalFees_1[_i];
|
|
1511
1508
|
_loop_1(item);
|
|
1512
1509
|
}
|
|
1513
|
-
console.log("\uD83D\uDCCA Total parcial (fees normais): R$ ".concat(results.reduce(function (sum, r) { return sum + r.total; }, 0).toFixed(2)));
|
|
1514
1510
|
// PASSADA 2: Calcular fees TOTAL_PERCENTAGE de forma iterativa
|
|
1515
1511
|
if (totalPercentageFees.length > 0) {
|
|
1516
|
-
console.log("\n\uD83D\uDD04 [getCtesFeesResult] Calculando ".concat(totalPercentageFees.length, " fees TOTAL_PERCENTAGE"));
|
|
1517
|
-
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(', ')));
|
|
1518
1512
|
// Criar Map com valores já calculados das fees normais (respeitando lógica de siblings)
|
|
1519
1513
|
var preCalculatedValues_1 = new Map();
|
|
1520
1514
|
results.forEach(function (r) {
|
|
@@ -1524,15 +1518,12 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1524
1518
|
preCalculatedValues_1.set(fee.fee.id, r.total);
|
|
1525
1519
|
}
|
|
1526
1520
|
});
|
|
1527
|
-
console.log("\uD83D\uDCCA Usando ".concat(preCalculatedValues_1.size, " valores pr\u00E9-calculados"));
|
|
1528
1521
|
var percentageFeesCache = calculateTotalPercentageFees(feesToCalc, cte, allFeesForCalc, preCalculatedValues_1);
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
if ((_f = item.fee) === null || _f === void 0 ? void 0 : _f.id) {
|
|
1522
|
+
for (var _e = 0, totalPercentageFees_1 = totalPercentageFees; _e < totalPercentageFees_1.length; _e++) {
|
|
1523
|
+
var item = totalPercentageFees_1[_e];
|
|
1524
|
+
if ((_d = item.fee) === null || _d === void 0 ? void 0 : _d.id) {
|
|
1533
1525
|
var cachedResult = percentageFeesCache.get(item.fee.id);
|
|
1534
1526
|
if (cachedResult && cachedResult.totalFee && cachedResult.totalFee > 0) {
|
|
1535
|
-
console.log(" ".concat(item.fee.name, ": R$ ").concat(cachedResult.totalFee.toFixed(2)));
|
|
1536
1527
|
results.push({
|
|
1537
1528
|
total: Number(cachedResult.totalFee.toFixed(2)),
|
|
1538
1529
|
resultFee: cachedResult.resultFee || '',
|
|
@@ -1545,20 +1536,15 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1545
1536
|
}
|
|
1546
1537
|
// PASSADA 3: Calcular ICMS com base em todas as fees anteriores (normais + TOTAL_PERCENTAGE)
|
|
1547
1538
|
if (icmsFee) {
|
|
1548
|
-
console.log("\n\uD83D\uDCB0 [getCtesFeesResult] Calculando ICMS");
|
|
1549
1539
|
// Coletar apenas os valores das fees que realmente contam (total > 0)
|
|
1550
1540
|
var valuesForIcms = results
|
|
1551
1541
|
.filter(function (r) { return r.total > 0; })
|
|
1552
1542
|
.map(function (r) { return r.total; });
|
|
1553
|
-
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)));
|
|
1554
1543
|
var icmsRate = (cte.icmsIncidence !== undefined && cte.icmsIncidence !== null && !isNaN(+cte.icmsIncidence))
|
|
1555
1544
|
? +(cte.icmsIncidence) / 100
|
|
1556
1545
|
: icmsFee.value || 0;
|
|
1557
|
-
console.log("\uD83D\uDCC8 Al\u00EDquota ICMS: ".concat((icmsRate * 100).toFixed(2), "%"));
|
|
1558
1546
|
// Usar calculateIcms diretamente
|
|
1559
1547
|
var icmsCalculation = calculateIcms(valuesForIcms, icmsRate);
|
|
1560
|
-
console.log("\u2705 ICMS calculado: R$ ".concat(icmsCalculation.total.toFixed(2)));
|
|
1561
|
-
console.log("\uD83D\uDCCB Total de fees no results antes do ICMS: ".concat(results.length));
|
|
1562
1548
|
if (icmsCalculation.isValid && !isNaN(+icmsCalculation.total)) {
|
|
1563
1549
|
results.push({
|
|
1564
1550
|
total: +(icmsCalculation.total).toFixed(2),
|
|
@@ -1566,11 +1552,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1566
1552
|
feeValue: icmsRate,
|
|
1567
1553
|
feeId: icmsFee.feeId,
|
|
1568
1554
|
});
|
|
1569
|
-
console.log("\uD83D\uDCCB Total de fees no results depois do ICMS: ".concat(results.length));
|
|
1570
1555
|
}
|
|
1571
1556
|
}
|
|
1572
|
-
console.log("\n\uD83C\uDFAF [getCtesFeesResult] Total final: R$ ".concat(results.reduce(function (sum, r) { return sum + r.total; }, 0).toFixed(2)));
|
|
1573
|
-
console.log("\uD83D\uDCCB Breakdown: ".concat(results.map(function (r) { return "R$ ".concat(r.total.toFixed(2)); }).join(' + '), "\n"));
|
|
1574
1557
|
return results;
|
|
1575
1558
|
};
|
|
1576
1559
|
|
|
@@ -8027,7 +8010,7 @@ var renderChargedValue = function (value, cte, feeName) {
|
|
|
8027
8010
|
console.log('🔍 ICMS rateio habilitado:', isIcmsApportionmentEnabled);
|
|
8028
8011
|
console.log('🔍 feeName contém ICMS:', feeName === null || feeName === void 0 ? void 0 : feeName.toUpperCase().includes('ICMS'));
|
|
8029
8012
|
// Se for ICMS e o rateio estiver habilitado, calcular e mostrar o rateio
|
|
8030
|
-
if (isIcmsApportionmentEnabled
|
|
8013
|
+
if (isIcmsApportionmentEnabled) {
|
|
8031
8014
|
console.log('✅ Aplicando rateio de ICMS');
|
|
8032
8015
|
// Obter a alíquota de ICMS do CTE (icmsIncidence já vem em decimal, ex: 0.12 para 12%)
|
|
8033
8016
|
var icmsRate = cte.icmsIncidence ? Number(cte.icmsIncidence) : 0.12; // Default 12%
|
package/build/index.js.gz
CHANGED
|
Binary file
|