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