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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calcula o valor do ICMS baseado no total das outras taxas
|
|
3
|
+
*
|
|
4
|
+
* @param totalFromAllFees - Array com os valores das outras taxas
|
|
5
|
+
* @param icmsRate - Alíquota do ICMS (ex: 0.12 para 12%)
|
|
6
|
+
* @returns Objeto com o valor calculado e detalhes do cálculo
|
|
7
|
+
*/
|
|
8
|
+
export declare const calculateIcms: (totalFromAllFees: number[], icmsRate: number) => {
|
|
9
|
+
total: number;
|
|
10
|
+
totalValueFromAllFees: number;
|
|
11
|
+
valueToDivide: number;
|
|
12
|
+
firstTotal: number;
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
total: number;
|
|
16
|
+
totalValueFromAllFees: number;
|
|
17
|
+
valueToDivide: string;
|
|
18
|
+
firstTotal: number;
|
|
19
|
+
isValid: boolean;
|
|
20
|
+
};
|
package/build/index.esm.js
CHANGED
|
@@ -820,6 +820,41 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
820
820
|
}
|
|
821
821
|
};
|
|
822
822
|
|
|
823
|
+
/**
|
|
824
|
+
* Calcula o valor do ICMS baseado no total das outras taxas
|
|
825
|
+
*
|
|
826
|
+
* @param totalFromAllFees - Array com os valores das outras taxas
|
|
827
|
+
* @param icmsRate - Alíquota do ICMS (ex: 0.12 para 12%)
|
|
828
|
+
* @returns Objeto com o valor calculado e detalhes do cálculo
|
|
829
|
+
*/
|
|
830
|
+
var calculateIcms = function (totalFromAllFees, icmsRate) {
|
|
831
|
+
// Filtra valores válidos e soma
|
|
832
|
+
var totalValueFromAllFees = totalFromAllFees
|
|
833
|
+
.filter(function (value) { return !isNaN(+value) && +value > 0; })
|
|
834
|
+
.reduce(function (previous, current) { return +previous + +current; }, 0);
|
|
835
|
+
// Verifica se há valor válido para cálculo
|
|
836
|
+
if (!totalValueFromAllFees || isNaN(+totalValueFromAllFees)) {
|
|
837
|
+
return {
|
|
838
|
+
total: 0,
|
|
839
|
+
totalValueFromAllFees: 0,
|
|
840
|
+
valueToDivide: 0,
|
|
841
|
+
firstTotal: 0,
|
|
842
|
+
isValid: false
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
// Cálculo do ICMS: (soma / (1 - alíquota)) * alíquota
|
|
846
|
+
var valueToDivide = (1 - icmsRate).toFixed(2);
|
|
847
|
+
var firstTotal = +totalValueFromAllFees / +valueToDivide;
|
|
848
|
+
var total = +firstTotal * icmsRate;
|
|
849
|
+
return {
|
|
850
|
+
total: total,
|
|
851
|
+
totalValueFromAllFees: totalValueFromAllFees,
|
|
852
|
+
valueToDivide: valueToDivide,
|
|
853
|
+
firstTotal: firstTotal,
|
|
854
|
+
isValid: true
|
|
855
|
+
};
|
|
856
|
+
};
|
|
857
|
+
|
|
823
858
|
var verifyConditionalFee = function (conditionalFeeToVerify, cte) {
|
|
824
859
|
var _a;
|
|
825
860
|
if (conditionalFeeToVerify === null || conditionalFeeToVerify === void 0 ? void 0 : conditionalFeeToVerify.id) {
|
|
@@ -1047,10 +1082,13 @@ var getLaneFromRatecard = function (cte) {
|
|
|
1047
1082
|
};
|
|
1048
1083
|
|
|
1049
1084
|
var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
1050
|
-
var _a, _b, _c
|
|
1085
|
+
var _a, _b, _c;
|
|
1051
1086
|
var results = [];
|
|
1087
|
+
// Separar ICMS das outras fees
|
|
1088
|
+
var icmsFee = feesToCalc.find(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) === FeeEnum.ICMS; });
|
|
1089
|
+
var nonIcmsFees = feesToCalc.filter(function (f) { var _a; return ((_a = f.fee) === null || _a === void 0 ? void 0 : _a.id) !== FeeEnum.ICMS; });
|
|
1052
1090
|
var _loop_1 = function (item) {
|
|
1053
|
-
var feeTotal = calculateFee(item, cte, feesToCalc,
|
|
1091
|
+
var feeTotal = calculateFee(item, cte, feesToCalc, false, allFeesForCalc);
|
|
1054
1092
|
if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
|
|
1055
1093
|
var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
|
|
1056
1094
|
var totalToPush = totalFee;
|
|
@@ -1059,9 +1097,9 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1059
1097
|
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; });
|
|
1060
1098
|
if (siblingFees && (siblingFees === null || siblingFees === void 0 ? void 0 : siblingFees.length) > 0) {
|
|
1061
1099
|
var siblingFeesResults = [];
|
|
1062
|
-
for (var
|
|
1063
|
-
var item_1 = siblingFees_1[
|
|
1064
|
-
var result = calculateFee(item_1, cte);
|
|
1100
|
+
for (var _d = 0, siblingFees_1 = siblingFees; _d < siblingFees_1.length; _d++) {
|
|
1101
|
+
var item_1 = siblingFees_1[_d];
|
|
1102
|
+
var result = calculateFee(item_1, cte, feesToCalc, false, allFeesForCalc);
|
|
1065
1103
|
siblingFeesResults.push(result);
|
|
1066
1104
|
}
|
|
1067
1105
|
siblingFeesResults.sort(function (a, b) {
|
|
@@ -1079,18 +1117,39 @@ var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
|
1079
1117
|
}
|
|
1080
1118
|
if (!isNaN(+totalToPush)) {
|
|
1081
1119
|
results.push({
|
|
1082
|
-
total: totalToPush,
|
|
1120
|
+
total: +(totalToPush).toFixed(2),
|
|
1083
1121
|
resultFee: resultFee,
|
|
1084
1122
|
feeValue: feeValue,
|
|
1085
|
-
feeId:
|
|
1123
|
+
feeId: item.feeId,
|
|
1086
1124
|
});
|
|
1087
1125
|
}
|
|
1088
1126
|
}
|
|
1089
1127
|
};
|
|
1090
|
-
|
|
1091
|
-
|
|
1128
|
+
// PRIMEIRA PASSADA: Calcular todas as fees exceto ICMS
|
|
1129
|
+
for (var _i = 0, nonIcmsFees_1 = nonIcmsFees; _i < nonIcmsFees_1.length; _i++) {
|
|
1130
|
+
var item = nonIcmsFees_1[_i];
|
|
1092
1131
|
_loop_1(item);
|
|
1093
1132
|
}
|
|
1133
|
+
// SEGUNDA PASSADA: Calcular ICMS com base nos resultados já filtrados
|
|
1134
|
+
if (icmsFee) {
|
|
1135
|
+
// Coletar apenas os valores das fees que realmente contam (total > 0)
|
|
1136
|
+
var valuesForIcms = results
|
|
1137
|
+
.filter(function (r) { return r.total > 0; })
|
|
1138
|
+
.map(function (r) { return r.total; });
|
|
1139
|
+
var icmsRate = (cte.icmsIncidence !== undefined && cte.icmsIncidence !== null && !isNaN(+cte.icmsIncidence))
|
|
1140
|
+
? +(cte.icmsIncidence) / 100
|
|
1141
|
+
: icmsFee.value || 0;
|
|
1142
|
+
// Usar calculateIcms diretamente
|
|
1143
|
+
var icmsCalculation = calculateIcms(valuesForIcms, icmsRate);
|
|
1144
|
+
if (icmsCalculation.isValid && !isNaN(+icmsCalculation.total)) {
|
|
1145
|
+
results.push({
|
|
1146
|
+
total: +(icmsCalculation.total).toFixed(2),
|
|
1147
|
+
resultFee: "(".concat(icmsCalculation.totalValueFromAllFees.toFixed(2), " / ").concat(icmsCalculation.valueToDivide, ") x ").concat(icmsRate, " = ").concat(icmsCalculation.total.toFixed(2)),
|
|
1148
|
+
feeValue: icmsRate,
|
|
1149
|
+
feeId: icmsFee.feeId,
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1094
1153
|
return results;
|
|
1095
1154
|
};
|
|
1096
1155
|
|
|
@@ -7613,5 +7672,5 @@ var setFormattedDatesInObjects = function (objectFormat) { return __awaiter(void
|
|
|
7613
7672
|
});
|
|
7614
7673
|
}); };
|
|
7615
7674
|
|
|
7616
|
-
export { ApplicationColumnNameEnum, ApplicationEnum, CountryEnum, CteStatusEnum, CteVehicleTypeEnum, CurrencyEnum, DocumentTypeEnum, DomainConfigurationEnum, DomainTypeEnum, FeeCalculationTypeEnum, FeeCategoryEnum, FeeEnum, FreightRegionEnum, ImapHostsEnum, ModalEnum, NotificationTypeEnum, PermissionEnum, RatecardConditionalFeeTypeEnum, RatecardModalEnum, SlaRegionEnum, SpotStatusEnum, TrackProcessProviderTypeEnum, applyRedeliveryMultiplier, calculateFee, convertNumberToCurrency, filterSiblingFees, formatDateString, getAllFeesForCalculation, getAuditTotalFromCte, getConfigurationFromDomain, getContractFromFreight, getContractRouteFromFreight, getCookies, getCteDateRange, getCteLane, getCteLaneFeesTotal, getCtesFeesResult, getDataFromToken, getFilteredFeesToAudit, getFormattedFreightPlaceName, getLaneFeesToCalc, getLaneFromRatecard, getNormalizedCityName, getRatecardFromCte, getRouteDeliveryTimeFromFreight, getRouteOnTimeFromFreight, normalizeString, setFormattedDatesInObjects, verifyConditionalFee, verifyDefaultFees };
|
|
7675
|
+
export { ApplicationColumnNameEnum, ApplicationEnum, CountryEnum, CteStatusEnum, CteVehicleTypeEnum, CurrencyEnum, DocumentTypeEnum, DomainConfigurationEnum, DomainTypeEnum, FeeCalculationTypeEnum, FeeCategoryEnum, FeeEnum, FreightRegionEnum, ImapHostsEnum, ModalEnum, NotificationTypeEnum, PermissionEnum, RatecardConditionalFeeTypeEnum, RatecardModalEnum, SlaRegionEnum, SpotStatusEnum, TrackProcessProviderTypeEnum, applyRedeliveryMultiplier, calculateFee, calculateIcms, convertNumberToCurrency, filterSiblingFees, formatDateString, getAllFeesForCalculation, getAuditTotalFromCte, getConfigurationFromDomain, getContractFromFreight, getContractRouteFromFreight, getCookies, getCteDateRange, getCteLane, getCteLaneFeesTotal, getCtesFeesResult, getDataFromToken, getFilteredFeesToAudit, getFormattedFreightPlaceName, getLaneFeesToCalc, getLaneFromRatecard, getNormalizedCityName, getRatecardFromCte, getRouteDeliveryTimeFromFreight, getRouteOnTimeFromFreight, normalizeString, setFormattedDatesInObjects, verifyConditionalFee, verifyDefaultFees };
|
|
7617
7676
|
//# sourceMappingURL=index.esm.js.map
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|