b2m-utils 0.0.230 → 0.0.231
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/functions/calculateIcms/index.d.ts +20 -0
- package/build/functions/getCtesFeesResult/index.d.ts +1 -1
- package/build/functions/index.d.ts +1 -0
- package/build/index.esm.js +69 -10
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +69 -9
- package/build/index.js.gz +0 -0
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -824,6 +824,41 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
824
824
|
}
|
|
825
825
|
};
|
|
826
826
|
|
|
827
|
+
/**
|
|
828
|
+
* Calcula o valor do ICMS baseado no total das outras taxas
|
|
829
|
+
*
|
|
830
|
+
* @param totalFromAllFees - Array com os valores das outras taxas
|
|
831
|
+
* @param icmsRate - Alíquota do ICMS (ex: 0.12 para 12%)
|
|
832
|
+
* @returns Objeto com o valor calculado e detalhes do cálculo
|
|
833
|
+
*/
|
|
834
|
+
var calculateIcms = function (totalFromAllFees, icmsRate) {
|
|
835
|
+
// Filtra valores válidos e soma
|
|
836
|
+
var totalValueFromAllFees = totalFromAllFees
|
|
837
|
+
.filter(function (value) { return !isNaN(+value) && +value > 0; })
|
|
838
|
+
.reduce(function (previous, current) { return +previous + +current; }, 0);
|
|
839
|
+
// Verifica se há valor válido para cálculo
|
|
840
|
+
if (!totalValueFromAllFees || isNaN(+totalValueFromAllFees)) {
|
|
841
|
+
return {
|
|
842
|
+
total: 0,
|
|
843
|
+
totalValueFromAllFees: 0,
|
|
844
|
+
valueToDivide: 0,
|
|
845
|
+
firstTotal: 0,
|
|
846
|
+
isValid: false
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
// Cálculo do ICMS: (soma / (1 - alíquota)) * alíquota
|
|
850
|
+
var valueToDivide = (1 - icmsRate).toFixed(2);
|
|
851
|
+
var firstTotal = +totalValueFromAllFees / +valueToDivide;
|
|
852
|
+
var total = +firstTotal * icmsRate;
|
|
853
|
+
return {
|
|
854
|
+
total: total,
|
|
855
|
+
totalValueFromAllFees: totalValueFromAllFees,
|
|
856
|
+
valueToDivide: valueToDivide,
|
|
857
|
+
firstTotal: firstTotal,
|
|
858
|
+
isValid: true
|
|
859
|
+
};
|
|
860
|
+
};
|
|
861
|
+
|
|
827
862
|
var verifyConditionalFee = function (conditionalFeeToVerify, cte) {
|
|
828
863
|
var _a;
|
|
829
864
|
if (conditionalFeeToVerify === null || conditionalFeeToVerify === void 0 ? void 0 : conditionalFeeToVerify.id) {
|
|
@@ -1051,10 +1086,13 @@ var getLaneFromRatecard = function (cte) {
|
|
|
1051
1086
|
};
|
|
1052
1087
|
|
|
1053
1088
|
var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
1054
|
-
var _a, _b, _c
|
|
1089
|
+
var _a, _b, _c;
|
|
1055
1090
|
var results = [];
|
|
1091
|
+
// Separar ICMS das outras fees
|
|
1092
|
+
var icmsFee = feesToCalc.find(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) === exports.FeeEnum.ICMS; });
|
|
1093
|
+
var nonIcmsFees = feesToCalc.filter(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) !== exports.FeeEnum.ICMS; });
|
|
1056
1094
|
var _loop_1 = function (item) {
|
|
1057
|
-
var feeTotal = calculateFee(item, cte, feesToCalc,
|
|
1095
|
+
var feeTotal = calculateFee(item, cte, feesToCalc, false, allFeesForCalc);
|
|
1058
1096
|
if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
|
|
1059
1097
|
var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
|
|
1060
1098
|
var totalToPush = totalFee;
|
|
@@ -1063,9 +1101,9 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1063
1101
|
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; });
|
|
1064
1102
|
if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
|
|
1065
1103
|
var siblingFeesResults = [];
|
|
1066
|
-
for (var
|
|
1067
|
-
var item_1 = siblingFees_1[
|
|
1068
|
-
var result = calculateFee(item_1, cte);
|
|
1104
|
+
for (var _d = 0, siblingFees_1 = siblingFees; _d < siblingFees_1.length; _d++) {
|
|
1105
|
+
var item_1 = siblingFees_1[_d];
|
|
1106
|
+
var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
|
|
1069
1107
|
siblingFeesResults.push(result);
|
|
1070
1108
|
}
|
|
1071
1109
|
siblingFeesResults.sort(function (a, b) {
|
|
@@ -1083,18 +1121,39 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1083
1121
|
}
|
|
1084
1122
|
if (!isNaN(+totalToPush)) {
|
|
1085
1123
|
results.push({
|
|
1086
|
-
total: totalToPush,
|
|
1124
|
+
total: +(totalToPush).toFixed(2),
|
|
1087
1125
|
resultFee: resultFee,
|
|
1088
1126
|
feeValue: feeValue,
|
|
1089
|
-
feeId:
|
|
1127
|
+
feeId: item.feeId,
|
|
1090
1128
|
});
|
|
1091
1129
|
}
|
|
1092
1130
|
}
|
|
1093
1131
|
};
|
|
1094
|
-
|
|
1095
|
-
|
|
1132
|
+
// PRIMEIRA PASSADA: Calcular todas as fees exceto ICMS
|
|
1133
|
+
for (var _i = 0, nonIcmsFees_1 = nonIcmsFees; _i < nonIcmsFees_1.length; _i++) {
|
|
1134
|
+
var item = nonIcmsFees_1[_i];
|
|
1096
1135
|
_loop_1(item);
|
|
1097
1136
|
}
|
|
1137
|
+
// SEGUNDA PASSADA: Calcular ICMS com base nos resultados já filtrados
|
|
1138
|
+
if (icmsFee) {
|
|
1139
|
+
// Coletar apenas os valores das fees que realmente contam (total > 0)
|
|
1140
|
+
var valuesForIcms = results
|
|
1141
|
+
.filter(function (r) { return r.total > 0; })
|
|
1142
|
+
.map(function (r) { return r.total; });
|
|
1143
|
+
var icmsRate = (cte.icmsIncidence !== undefined && cte.icmsIncidence !== null && !isNaN(+cte.icmsIncidence))
|
|
1144
|
+
? +(cte.icmsIncidence) / 100
|
|
1145
|
+
: icmsFee.value || 0;
|
|
1146
|
+
// Usar calculateIcms diretamente
|
|
1147
|
+
var icmsCalculation = calculateIcms(valuesForIcms, icmsRate);
|
|
1148
|
+
if (icmsCalculation.isValid && !isNaN(+icmsCalculation.total)) {
|
|
1149
|
+
results.push({
|
|
1150
|
+
total: +(icmsCalculation.total).toFixed(2),
|
|
1151
|
+
resultFee: "(".concat(icmsCalculation.totalValueFromAllFees.toFixed(2), " / ").concat(icmsCalculation.valueToDivide, ") x ").concat(icmsRate, " = ").concat(icmsCalculation.total.toFixed(2)),
|
|
1152
|
+
feeValue: icmsRate,
|
|
1153
|
+
feeId: icmsFee.feeId,
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1098
1157
|
return results;
|
|
1099
1158
|
};
|
|
1100
1159
|
|
|
@@ -7619,6 +7678,7 @@ var setFormattedDatesInObjects = function (objectFormat) { return __awaiter(void
|
|
|
7619
7678
|
|
|
7620
7679
|
exports.applyRedeliveryMultiplier = applyRedeliveryMultiplier;
|
|
7621
7680
|
exports.calculateFee = calculateFee;
|
|
7681
|
+
exports.calculateIcms = calculateIcms;
|
|
7622
7682
|
exports.convertNumberToCurrency = convertNumberToCurrency;
|
|
7623
7683
|
exports.filterSiblingFees = filterSiblingFees;
|
|
7624
7684
|
exports.formatDateString = formatDateString;
|
package/build/index.js.gz
CHANGED
|
Binary file
|