b2m-utils 0.0.301 → 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 +27 -26
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +27 -26
- 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
|
|
|
@@ -7993,7 +7976,9 @@ var normalizeString = function (str) {
|
|
|
7993
7976
|
* ```
|
|
7994
7977
|
*/
|
|
7995
7978
|
var renderChargedValue = function (value, cte, feeName) {
|
|
7979
|
+
var _a;
|
|
7996
7980
|
var numericValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
7981
|
+
console.log('🔍 renderChargedValue - feeName:', feeName, 'value:', numericValue);
|
|
7997
7982
|
if (isNaN(numericValue)) {
|
|
7998
7983
|
return 'R$ 0,00';
|
|
7999
7984
|
}
|
|
@@ -8001,30 +7986,46 @@ var renderChargedValue = function (value, cte, feeName) {
|
|
|
8001
7986
|
var formattedValue = convertNumberToCurrency(numericValue, 'pt-br');
|
|
8002
7987
|
// Se não houver CTE ou ratecard, retornar apenas o valor formatado
|
|
8003
7988
|
if (!cte) {
|
|
7989
|
+
console.log('⚠️ CTE não fornecido');
|
|
8004
7990
|
return formattedValue;
|
|
8005
7991
|
}
|
|
8006
7992
|
// Buscar ratecard (pode estar em Ratecard ou ratecard)
|
|
8007
7993
|
var ratecard = getRatecardFromCte(cte);
|
|
7994
|
+
console.log('🔍 Ratecard encontrado:', ratecard ? 'SIM' : 'NÃO');
|
|
8008
7995
|
if (!ratecard || !ratecard.ratecard_config_values) {
|
|
7996
|
+
console.log('⚠️ Ratecard ou ratecard_config_values não encontrado');
|
|
7997
|
+
console.log(' - ratecard:', !!ratecard);
|
|
7998
|
+
console.log(' - ratecard_config_values:', ratecard === null || ratecard === void 0 ? void 0 : ratecard.ratecard_config_values);
|
|
8009
7999
|
return formattedValue;
|
|
8010
8000
|
}
|
|
8011
8001
|
// Buscar configurações do ratecard
|
|
8012
8002
|
var configs = ratecard.ratecard_config_values;
|
|
8003
|
+
console.log('✅ Configurações encontradas:', configs.length);
|
|
8013
8004
|
// Verificar se o rateio de ICMS está habilitado
|
|
8014
8005
|
var icmsApportionmentConfig = configs.find(function (config) { var _a; return ((_a = config.ratecard_configs) === null || _a === void 0 ? void 0 : _a.configKey) === exports.RatecardConfigKeyEnum.ICMS_APPORTIONMENT_ENABLED; });
|
|
8006
|
+
console.log('🔍 Config ICMS encontrada:', icmsApportionmentConfig);
|
|
8007
|
+
console.log(' - configKey:', (_a = icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.ratecard_configs) === null || _a === void 0 ? void 0 : _a.configKey);
|
|
8008
|
+
console.log(' - configValue:', icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.configValue);
|
|
8015
8009
|
var isIcmsApportionmentEnabled = (icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.configValue) === 'true';
|
|
8010
|
+
console.log('🔍 ICMS rateio habilitado:', isIcmsApportionmentEnabled);
|
|
8011
|
+
console.log('🔍 feeName contém ICMS:', feeName === null || feeName === void 0 ? void 0 : feeName.toUpperCase().includes('ICMS'));
|
|
8016
8012
|
// Se for ICMS e o rateio estiver habilitado, calcular e mostrar o rateio
|
|
8017
|
-
if (isIcmsApportionmentEnabled
|
|
8013
|
+
if (isIcmsApportionmentEnabled) {
|
|
8014
|
+
console.log('✅ Aplicando rateio de ICMS');
|
|
8018
8015
|
// Obter a alíquota de ICMS do CTE (icmsIncidence já vem em decimal, ex: 0.12 para 12%)
|
|
8019
8016
|
var icmsRate = cte.icmsIncidence ? Number(cte.icmsIncidence) : 0.12; // Default 12%
|
|
8017
|
+
console.log(' - icmsRate:', icmsRate);
|
|
8020
8018
|
// Calcular o ICMS baseado no valor cobrado
|
|
8021
8019
|
// A função calculateIcms espera um array de valores e a alíquota
|
|
8022
8020
|
var icmsResult = calculateIcms([numericValue], icmsRate);
|
|
8021
|
+
console.log(' - icmsResult.total:', icmsResult.total);
|
|
8023
8022
|
// Valor cobrado menos o ICMS calculado
|
|
8024
8023
|
var valueAfterIcms = numericValue - icmsResult.total;
|
|
8025
8024
|
var formattedValueAfterIcms = convertNumberToCurrency(valueAfterIcms, 'pt-br');
|
|
8026
8025
|
var formattedIcms = convertNumberToCurrency(icmsResult.total, 'pt-br');
|
|
8027
|
-
|
|
8026
|
+
var result = "".concat(formattedValue, " - ").concat(formattedIcms, " = ").concat(formattedValueAfterIcms, " (rateado)");
|
|
8027
|
+
console.log(' - resultado:', result);
|
|
8028
|
+
return result;
|
|
8028
8029
|
}
|
|
8029
8030
|
// Aqui você pode adicionar outras lógicas baseadas em outras configurações
|
|
8030
8031
|
// Por exemplo, se houver configuração de arredondamento, aplicar aqui
|
package/build/index.js.gz
CHANGED
|
Binary file
|