b2m-utils 0.0.270 → 0.0.271
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 +58 -10
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +58 -10
- package/build/index.js.gz +0 -0
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -1276,13 +1276,18 @@ var getLaneFromRatecard = function (cte) {
|
|
|
1276
1276
|
};
|
|
1277
1277
|
|
|
1278
1278
|
var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
1279
|
-
var _a, _b, _c;
|
|
1279
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1280
1280
|
var results = [];
|
|
1281
|
-
// Separar ICMS das outras fees
|
|
1281
|
+
// Separar ICMS e TOTAL_PERCENTAGE das outras fees
|
|
1282
1282
|
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
|
|
1283
|
+
var totalPercentageFees = feesToCalc.filter(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE; });
|
|
1284
|
+
var regularFees = feesToCalc.filter(function (f) {
|
|
1285
|
+
var _a, _b;
|
|
1286
|
+
return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) !== exports.FeeEnum.ICMS &&
|
|
1287
|
+
((_b = f.fee) === null || _b === void 0 ? void 0 : _b.feeCalculationTypeId) !== exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE;
|
|
1288
|
+
});
|
|
1284
1289
|
var _loop_1 = function (item) {
|
|
1285
|
-
var feeTotal = calculateFee(item, cte,
|
|
1290
|
+
var feeTotal = calculateFee(item, cte, regularFees, false, allFeesForCalc);
|
|
1286
1291
|
if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
|
|
1287
1292
|
var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
|
|
1288
1293
|
var totalToPush = totalFee;
|
|
@@ -1291,8 +1296,8 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1291
1296
|
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
1297
|
if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
|
|
1293
1298
|
var siblingFeesResults = [];
|
|
1294
|
-
for (var
|
|
1295
|
-
var item_1 = siblingFees_1[
|
|
1299
|
+
for (var _h = 0, siblingFees_1 = siblingFees; _h < siblingFees_1.length; _h++) {
|
|
1300
|
+
var item_1 = siblingFees_1[_h];
|
|
1296
1301
|
var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
|
|
1297
1302
|
siblingFeesResults.push(result);
|
|
1298
1303
|
}
|
|
@@ -1319,12 +1324,55 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1319
1324
|
}
|
|
1320
1325
|
}
|
|
1321
1326
|
};
|
|
1322
|
-
// PRIMEIRA PASSADA: Calcular
|
|
1323
|
-
for (var _i = 0,
|
|
1324
|
-
var item =
|
|
1327
|
+
// PRIMEIRA PASSADA: Calcular fees regulares (exceto ICMS e TOTAL_PERCENTAGE)
|
|
1328
|
+
for (var _i = 0, regularFees_1 = regularFees; _i < regularFees_1.length; _i++) {
|
|
1329
|
+
var item = regularFees_1[_i];
|
|
1325
1330
|
_loop_1(item);
|
|
1326
1331
|
}
|
|
1327
|
-
|
|
1332
|
+
var _loop_2 = function (item) {
|
|
1333
|
+
var feeTotal = calculateFee(item, cte, regularFees, false, allFeesForCalc);
|
|
1334
|
+
if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
|
|
1335
|
+
var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
|
|
1336
|
+
var totalToPush = totalFee;
|
|
1337
|
+
if ((_d = item.fee) === null || _d === void 0 ? void 0 : _d.parentId) {
|
|
1338
|
+
var fee_2 = item.fee;
|
|
1339
|
+
var siblingFees = totalPercentageFees === null || totalPercentageFees === void 0 ? void 0 : totalPercentageFees.filter(function (i) { var _a, _b; return ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.parentId) === fee_2.parentId && ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) !== fee_2.id; });
|
|
1340
|
+
if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
|
|
1341
|
+
var siblingFeesResults = [];
|
|
1342
|
+
for (var _j = 0, siblingFees_2 = siblingFees; _j < siblingFees_2.length; _j++) {
|
|
1343
|
+
var siblingItem = siblingFees_2[_j];
|
|
1344
|
+
var result = calculateFee(siblingItem, cte, regularFees, false, allFeesForCalc);
|
|
1345
|
+
siblingFeesResults.push(result);
|
|
1346
|
+
}
|
|
1347
|
+
siblingFeesResults.sort(function (a, b) {
|
|
1348
|
+
if ((b === null || b === void 0 ? void 0 : b.totalFee) && (a === null || a === void 0 ? void 0 : a.totalFee)) {
|
|
1349
|
+
return +(b === null || b === void 0 ? void 0 : b.totalFee) - +(a === null || a === void 0 ? void 0 : a.totalFee);
|
|
1350
|
+
}
|
|
1351
|
+
return 0;
|
|
1352
|
+
});
|
|
1353
|
+
if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
|
|
1354
|
+
if (((_e = siblingFeesResults[0]) === null || _e === void 0 ? void 0 : _e.totalFee) && ((_f = siblingFeesResults[0]) === null || _f === void 0 ? void 0 : _f.totalFee) > totalFee) {
|
|
1355
|
+
totalToPush = 0;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
if (!isNaN(+totalToPush)) {
|
|
1361
|
+
results.push({
|
|
1362
|
+
total: +(totalToPush).toFixed(2),
|
|
1363
|
+
resultFee: resultFee,
|
|
1364
|
+
feeValue: feeValue,
|
|
1365
|
+
feeId: item.feeId,
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
// SEGUNDA PASSADA: Calcular fees TOTAL_PERCENTAGE com base nas fees regulares já calculadas
|
|
1371
|
+
for (var _g = 0, totalPercentageFees_1 = totalPercentageFees; _g < totalPercentageFees_1.length; _g++) {
|
|
1372
|
+
var item = totalPercentageFees_1[_g];
|
|
1373
|
+
_loop_2(item);
|
|
1374
|
+
}
|
|
1375
|
+
// TERCEIRA PASSADA: Calcular ICMS com base nos resultados já filtrados
|
|
1328
1376
|
if (icmsFee) {
|
|
1329
1377
|
// Coletar apenas os valores das fees que realmente contam (total > 0)
|
|
1330
1378
|
var valuesForIcms = results
|
package/build/index.js.gz
CHANGED
|
Binary file
|