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