b2m-utils 0.0.276 → 0.0.278
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 +36 -8
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +36 -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
|
@@ -592,6 +592,11 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
592
592
|
}
|
|
593
593
|
return 0;
|
|
594
594
|
});
|
|
595
|
+
console.log({
|
|
596
|
+
filteredFees: filteredFees_1,
|
|
597
|
+
filteredFeesResults: filteredFeesResults,
|
|
598
|
+
totalFromAllFees: totalFromAllFees,
|
|
599
|
+
});
|
|
595
600
|
if (totalFromAllFees && (totalFromAllFees === null || totalFromAllFees === void 0 ? void 0 : totalFromAllFees.length) > 0) {
|
|
596
601
|
var totalValueFromAllFees = totalFromAllFees.filter(function (i) { return !isNaN(+i) && +i > 0; }).reduce(function (previous, current) {
|
|
597
602
|
if (!isNaN(+previous) && !isNaN(+current)) {
|
|
@@ -1278,9 +1283,14 @@ var getLaneFromRatecard = function (cte) {
|
|
|
1278
1283
|
var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
1279
1284
|
var _a, _b, _c;
|
|
1280
1285
|
var results = [];
|
|
1281
|
-
// Separar
|
|
1286
|
+
// Separar fees por tipo: normais, TOTAL_PERCENTAGE e ICMS
|
|
1282
1287
|
var icmsFee = feesToCalc.find(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) === exports.FeeEnum.ICMS; });
|
|
1283
|
-
var
|
|
1288
|
+
var totalPercentageFees = feesToCalc.filter(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE; });
|
|
1289
|
+
var normalFees = feesToCalc.filter(function (f) {
|
|
1290
|
+
var _a, _b;
|
|
1291
|
+
return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) !== exports.FeeEnum.ICMS &&
|
|
1292
|
+
((_b = f.fee) === null || _b === void 0 ? void 0 : _b.feeCalculationTypeId) !== exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE;
|
|
1293
|
+
});
|
|
1284
1294
|
var _loop_1 = function (item) {
|
|
1285
1295
|
var feeTotal = calculateFee(item, cte, feesToCalc, false, allFeesForCalc);
|
|
1286
1296
|
if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
|
|
@@ -1291,8 +1301,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1291
1301
|
var siblingFees = feesToCalc === null || feesToCalc === void 0 ? void 0 : feesToCalc.filter(function (i) { var _a, _b; return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.parentId) === fee_1.parentId && ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== fee_1.id; });
|
|
1292
1302
|
if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
|
|
1293
1303
|
var siblingFeesResults = [];
|
|
1294
|
-
for (var
|
|
1295
|
-
var item_1 = siblingFees_1[
|
|
1304
|
+
for (var _e = 0, siblingFees_1 = siblingFees; _e < siblingFees_1.length; _e++) {
|
|
1305
|
+
var item_1 = siblingFees_1[_e];
|
|
1296
1306
|
var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
|
|
1297
1307
|
siblingFeesResults.push(result);
|
|
1298
1308
|
}
|
|
@@ -1319,12 +1329,30 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1319
1329
|
}
|
|
1320
1330
|
}
|
|
1321
1331
|
};
|
|
1322
|
-
//
|
|
1323
|
-
for (var _i = 0,
|
|
1324
|
-
var item =
|
|
1332
|
+
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1333
|
+
for (var _i = 0, normalFees_1 = normalFees; _i < normalFees_1.length; _i++) {
|
|
1334
|
+
var item = normalFees_1[_i];
|
|
1325
1335
|
_loop_1(item);
|
|
1326
1336
|
}
|
|
1327
|
-
//
|
|
1337
|
+
// PASSADA 2: Calcular fees TOTAL_PERCENTAGE usando a soma das fees normais já calculadas
|
|
1338
|
+
for (var _d = 0, totalPercentageFees_1 = totalPercentageFees; _d < totalPercentageFees_1.length; _d++) {
|
|
1339
|
+
var item = totalPercentageFees_1[_d];
|
|
1340
|
+
// Calcular soma das fees normais (excluindo TOTAL_PERCENTAGE e ICMS)
|
|
1341
|
+
var totalWithoutPercentageFees = results
|
|
1342
|
+
.filter(function (r) { return r.total > 0; })
|
|
1343
|
+
.reduce(function (sum, r) { return sum + r.total; }, 0);
|
|
1344
|
+
var percentage = item.value || 0;
|
|
1345
|
+
var calculatedValue = (totalWithoutPercentageFees * percentage) / 100;
|
|
1346
|
+
if (!isNaN(+calculatedValue) && calculatedValue > 0) {
|
|
1347
|
+
results.push({
|
|
1348
|
+
total: +(calculatedValue).toFixed(2),
|
|
1349
|
+
resultFee: "".concat(convertNumberToCurrency(totalWithoutPercentageFees, 'pt-br'), " x ").concat(percentage, "% = ").concat(convertNumberToCurrency(calculatedValue, 'pt-br')),
|
|
1350
|
+
feeValue: percentage,
|
|
1351
|
+
feeId: item.feeId,
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
// PASSADA 3: Calcular ICMS com base em todas as fees anteriores (normais + TOTAL_PERCENTAGE)
|
|
1328
1356
|
if (icmsFee) {
|
|
1329
1357
|
// Coletar apenas os valores das fees que realmente contam (total > 0)
|
|
1330
1358
|
var valuesForIcms = results
|
package/build/index.js.gz
CHANGED
|
Binary file
|