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.esm.js
CHANGED
|
@@ -1443,7 +1443,7 @@ var getLaneFromRatecard = function (cte) {
|
|
|
1443
1443
|
};
|
|
1444
1444
|
|
|
1445
1445
|
var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
1446
|
-
var _a, _b, _c, _d
|
|
1446
|
+
var _a, _b, _c, _d;
|
|
1447
1447
|
var results = [];
|
|
1448
1448
|
// Separar fees por tipo: normais, TOTAL_PERCENTAGE e ICMS
|
|
1449
1449
|
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; });
|
|
@@ -1454,8 +1454,6 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1454
1454
|
f.feeId !== FeeEnum.ICMS &&
|
|
1455
1455
|
((_b = f.fee) === null || _b === void 0 ? void 0 : _b.feeCalculationTypeId) !== FeeCalculationTypeEnum.TOTAL_PERCENTAGE;
|
|
1456
1456
|
});
|
|
1457
|
-
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1458
|
-
console.log("\n\uD83D\uDCE6 [getCtesFeesResult] Calculando ".concat(normalFees.length, " fees normais"));
|
|
1459
1457
|
var _loop_1 = function (item) {
|
|
1460
1458
|
var feeTotal = calculateFee(item, cte, feesToCalc, false, allFeesForCalc);
|
|
1461
1459
|
if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
|
|
@@ -1472,8 +1470,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1472
1470
|
});
|
|
1473
1471
|
if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
|
|
1474
1472
|
var siblingFeesResults = [];
|
|
1475
|
-
for (var
|
|
1476
|
-
var item_1 = siblingFees_1[
|
|
1473
|
+
for (var _f = 0, siblingFees_1 = siblingFees; _f < siblingFees_1.length; _f++) {
|
|
1474
|
+
var item_1 = siblingFees_1[_f];
|
|
1477
1475
|
var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
|
|
1478
1476
|
siblingFeesResults.push(result);
|
|
1479
1477
|
}
|
|
@@ -1485,14 +1483,12 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1485
1483
|
});
|
|
1486
1484
|
if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
|
|
1487
1485
|
if (((_b = siblingFeesResults[0]) === null || _b === void 0 ? void 0 : _b.totalFee) && ((_c = siblingFeesResults[0]) === null || _c === void 0 ? void 0 : _c.totalFee) > totalFee) {
|
|
1488
|
-
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)"));
|
|
1489
1486
|
totalToPush = 0;
|
|
1490
1487
|
}
|
|
1491
1488
|
}
|
|
1492
1489
|
}
|
|
1493
1490
|
}
|
|
1494
1491
|
if (!isNaN(+totalToPush) && totalToPush > 0) {
|
|
1495
|
-
console.log(" \u2705 ".concat((_e = item.fee) === null || _e === void 0 ? void 0 : _e.name, ": R$ ").concat(totalToPush.toFixed(2)));
|
|
1496
1492
|
results.push({
|
|
1497
1493
|
total: +(totalToPush).toFixed(2),
|
|
1498
1494
|
resultFee: resultFee,
|
|
@@ -1502,15 +1498,13 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1502
1498
|
}
|
|
1503
1499
|
}
|
|
1504
1500
|
};
|
|
1501
|
+
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1505
1502
|
for (var _i = 0, normalFees_1 = normalFees; _i < normalFees_1.length; _i++) {
|
|
1506
1503
|
var item = normalFees_1[_i];
|
|
1507
1504
|
_loop_1(item);
|
|
1508
1505
|
}
|
|
1509
|
-
console.log("\uD83D\uDCCA Total parcial (fees normais): R$ ".concat(results.reduce(function (sum, r) { return sum + r.total; }, 0).toFixed(2)));
|
|
1510
1506
|
// PASSADA 2: Calcular fees TOTAL_PERCENTAGE de forma iterativa
|
|
1511
1507
|
if (totalPercentageFees.length > 0) {
|
|
1512
|
-
console.log("\n\uD83D\uDD04 [getCtesFeesResult] Calculando ".concat(totalPercentageFees.length, " fees TOTAL_PERCENTAGE"));
|
|
1513
|
-
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(', ')));
|
|
1514
1508
|
// Criar Map com valores já calculados das fees normais (respeitando lógica de siblings)
|
|
1515
1509
|
var preCalculatedValues_1 = new Map();
|
|
1516
1510
|
results.forEach(function (r) {
|
|
@@ -1520,15 +1514,12 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1520
1514
|
preCalculatedValues_1.set(fee.fee.id, r.total);
|
|
1521
1515
|
}
|
|
1522
1516
|
});
|
|
1523
|
-
console.log("\uD83D\uDCCA Usando ".concat(preCalculatedValues_1.size, " valores pr\u00E9-calculados"));
|
|
1524
1517
|
var percentageFeesCache = calculateTotalPercentageFees(feesToCalc, cte, allFeesForCalc, preCalculatedValues_1);
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
if ((_f = item.fee) === null || _f === void 0 ? void 0 : _f.id) {
|
|
1518
|
+
for (var _e = 0, totalPercentageFees_1 = totalPercentageFees; _e < totalPercentageFees_1.length; _e++) {
|
|
1519
|
+
var item = totalPercentageFees_1[_e];
|
|
1520
|
+
if ((_d = item.fee) === null || _d === void 0 ? void 0 : _d.id) {
|
|
1529
1521
|
var cachedResult = percentageFeesCache.get(item.fee.id);
|
|
1530
1522
|
if (cachedResult && cachedResult.totalFee && cachedResult.totalFee > 0) {
|
|
1531
|
-
console.log(" ".concat(item.fee.name, ": R$ ").concat(cachedResult.totalFee.toFixed(2)));
|
|
1532
1523
|
results.push({
|
|
1533
1524
|
total: Number(cachedResult.totalFee.toFixed(2)),
|
|
1534
1525
|
resultFee: cachedResult.resultFee || '',
|
|
@@ -1541,20 +1532,15 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1541
1532
|
}
|
|
1542
1533
|
// PASSADA 3: Calcular ICMS com base em todas as fees anteriores (normais + TOTAL_PERCENTAGE)
|
|
1543
1534
|
if (icmsFee) {
|
|
1544
|
-
console.log("\n\uD83D\uDCB0 [getCtesFeesResult] Calculando ICMS");
|
|
1545
1535
|
// Coletar apenas os valores das fees que realmente contam (total > 0)
|
|
1546
1536
|
var valuesForIcms = results
|
|
1547
1537
|
.filter(function (r) { return r.total > 0; })
|
|
1548
1538
|
.map(function (r) { return r.total; });
|
|
1549
|
-
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)));
|
|
1550
1539
|
var icmsRate = (cte.icmsIncidence !== undefined && cte.icmsIncidence !== null && !isNaN(+cte.icmsIncidence))
|
|
1551
1540
|
? +(cte.icmsIncidence) / 100
|
|
1552
1541
|
: icmsFee.value || 0;
|
|
1553
|
-
console.log("\uD83D\uDCC8 Al\u00EDquota ICMS: ".concat((icmsRate * 100).toFixed(2), "%"));
|
|
1554
1542
|
// Usar calculateIcms diretamente
|
|
1555
1543
|
var icmsCalculation = calculateIcms(valuesForIcms, icmsRate);
|
|
1556
|
-
console.log("\u2705 ICMS calculado: R$ ".concat(icmsCalculation.total.toFixed(2)));
|
|
1557
|
-
console.log("\uD83D\uDCCB Total de fees no results antes do ICMS: ".concat(results.length));
|
|
1558
1544
|
if (icmsCalculation.isValid && !isNaN(+icmsCalculation.total)) {
|
|
1559
1545
|
results.push({
|
|
1560
1546
|
total: +(icmsCalculation.total).toFixed(2),
|
|
@@ -1562,11 +1548,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1562
1548
|
feeValue: icmsRate,
|
|
1563
1549
|
feeId: icmsFee.feeId,
|
|
1564
1550
|
});
|
|
1565
|
-
console.log("\uD83D\uDCCB Total de fees no results depois do ICMS: ".concat(results.length));
|
|
1566
1551
|
}
|
|
1567
1552
|
}
|
|
1568
|
-
console.log("\n\uD83C\uDFAF [getCtesFeesResult] Total final: R$ ".concat(results.reduce(function (sum, r) { return sum + r.total; }, 0).toFixed(2)));
|
|
1569
|
-
console.log("\uD83D\uDCCB Breakdown: ".concat(results.map(function (r) { return "R$ ".concat(r.total.toFixed(2)); }).join(' + '), "\n"));
|
|
1570
1553
|
return results;
|
|
1571
1554
|
};
|
|
1572
1555
|
|
|
@@ -7989,7 +7972,9 @@ var normalizeString = function (str) {
|
|
|
7989
7972
|
* ```
|
|
7990
7973
|
*/
|
|
7991
7974
|
var renderChargedValue = function (value, cte, feeName) {
|
|
7975
|
+
var _a;
|
|
7992
7976
|
var numericValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
7977
|
+
console.log('🔍 renderChargedValue - feeName:', feeName, 'value:', numericValue);
|
|
7993
7978
|
if (isNaN(numericValue)) {
|
|
7994
7979
|
return 'R$ 0,00';
|
|
7995
7980
|
}
|
|
@@ -7997,30 +7982,46 @@ var renderChargedValue = function (value, cte, feeName) {
|
|
|
7997
7982
|
var formattedValue = convertNumberToCurrency(numericValue, 'pt-br');
|
|
7998
7983
|
// Se não houver CTE ou ratecard, retornar apenas o valor formatado
|
|
7999
7984
|
if (!cte) {
|
|
7985
|
+
console.log('⚠️ CTE não fornecido');
|
|
8000
7986
|
return formattedValue;
|
|
8001
7987
|
}
|
|
8002
7988
|
// Buscar ratecard (pode estar em Ratecard ou ratecard)
|
|
8003
7989
|
var ratecard = getRatecardFromCte(cte);
|
|
7990
|
+
console.log('🔍 Ratecard encontrado:', ratecard ? 'SIM' : 'NÃO');
|
|
8004
7991
|
if (!ratecard || !ratecard.ratecard_config_values) {
|
|
7992
|
+
console.log('⚠️ Ratecard ou ratecard_config_values não encontrado');
|
|
7993
|
+
console.log(' - ratecard:', !!ratecard);
|
|
7994
|
+
console.log(' - ratecard_config_values:', ratecard === null || ratecard === void 0 ? void 0 : ratecard.ratecard_config_values);
|
|
8005
7995
|
return formattedValue;
|
|
8006
7996
|
}
|
|
8007
7997
|
// Buscar configurações do ratecard
|
|
8008
7998
|
var configs = ratecard.ratecard_config_values;
|
|
7999
|
+
console.log('✅ Configurações encontradas:', configs.length);
|
|
8009
8000
|
// Verificar se o rateio de ICMS está habilitado
|
|
8010
8001
|
var icmsApportionmentConfig = configs.find(function (config) { var _a; return ((_a = config.ratecard_configs) === null || _a === void 0 ? void 0 : _a.configKey) === RatecardConfigKeyEnum.ICMS_APPORTIONMENT_ENABLED; });
|
|
8002
|
+
console.log('🔍 Config ICMS encontrada:', icmsApportionmentConfig);
|
|
8003
|
+
console.log(' - configKey:', (_a = icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.ratecard_configs) === null || _a === void 0 ? void 0 : _a.configKey);
|
|
8004
|
+
console.log(' - configValue:', icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.configValue);
|
|
8011
8005
|
var isIcmsApportionmentEnabled = (icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.configValue) === 'true';
|
|
8006
|
+
console.log('🔍 ICMS rateio habilitado:', isIcmsApportionmentEnabled);
|
|
8007
|
+
console.log('🔍 feeName contém ICMS:', feeName === null || feeName === void 0 ? void 0 : feeName.toUpperCase().includes('ICMS'));
|
|
8012
8008
|
// Se for ICMS e o rateio estiver habilitado, calcular e mostrar o rateio
|
|
8013
|
-
if (isIcmsApportionmentEnabled
|
|
8009
|
+
if (isIcmsApportionmentEnabled) {
|
|
8010
|
+
console.log('✅ Aplicando rateio de ICMS');
|
|
8014
8011
|
// Obter a alíquota de ICMS do CTE (icmsIncidence já vem em decimal, ex: 0.12 para 12%)
|
|
8015
8012
|
var icmsRate = cte.icmsIncidence ? Number(cte.icmsIncidence) : 0.12; // Default 12%
|
|
8013
|
+
console.log(' - icmsRate:', icmsRate);
|
|
8016
8014
|
// Calcular o ICMS baseado no valor cobrado
|
|
8017
8015
|
// A função calculateIcms espera um array de valores e a alíquota
|
|
8018
8016
|
var icmsResult = calculateIcms([numericValue], icmsRate);
|
|
8017
|
+
console.log(' - icmsResult.total:', icmsResult.total);
|
|
8019
8018
|
// Valor cobrado menos o ICMS calculado
|
|
8020
8019
|
var valueAfterIcms = numericValue - icmsResult.total;
|
|
8021
8020
|
var formattedValueAfterIcms = convertNumberToCurrency(valueAfterIcms, 'pt-br');
|
|
8022
8021
|
var formattedIcms = convertNumberToCurrency(icmsResult.total, 'pt-br');
|
|
8023
|
-
|
|
8022
|
+
var result = "".concat(formattedValue, " - ").concat(formattedIcms, " = ").concat(formattedValueAfterIcms, " (rateado)");
|
|
8023
|
+
console.log(' - resultado:', result);
|
|
8024
|
+
return result;
|
|
8024
8025
|
}
|
|
8025
8026
|
// Aqui você pode adicionar outras lógicas baseadas em outras configurações
|
|
8026
8027
|
// Por exemplo, se houver configuração de arredondamento, aplicar aqui
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|