b2m-utils 0.0.309 → 0.0.311
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/enums/FeeCalculationTypeEnum.d.ts +2 -1
- package/build/enums/FeeEnum.d.ts +2 -1
- package/build/enums/RatecardFeeConfigKeyEnum.d.ts +2 -1
- package/build/functions/buildFeeExclusionsMap/index.d.ts +7 -0
- package/build/functions/calculateFeesCacheWithDetails/index.d.ts +33 -0
- package/build/functions/calculateTotalPercentageFees/index.d.ts +2 -1
- package/build/functions/index.d.ts +2 -0
- package/build/index.esm.js +160 -17
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +162 -16
- package/build/index.js.gz +0 -0
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -149,6 +149,7 @@ exports.FeeCalculationTypeEnum = void 0;
|
|
|
149
149
|
FeeCalculationTypeEnum[FeeCalculationTypeEnum["MIN_VALUE"] = 10] = "MIN_VALUE";
|
|
150
150
|
FeeCalculationTypeEnum[FeeCalculationTypeEnum["SUM_CONTAINERS"] = 11] = "SUM_CONTAINERS";
|
|
151
151
|
FeeCalculationTypeEnum[FeeCalculationTypeEnum["VOLUMES_QUANTITY"] = 12] = "VOLUMES_QUANTITY";
|
|
152
|
+
FeeCalculationTypeEnum[FeeCalculationTypeEnum["INVOICE_QUANTITY"] = 13] = "INVOICE_QUANTITY";
|
|
152
153
|
})(exports.FeeCalculationTypeEnum || (exports.FeeCalculationTypeEnum = {}));
|
|
153
154
|
|
|
154
155
|
exports.FeeCategoryEnum = void 0;
|
|
@@ -190,6 +191,7 @@ exports.FeeEnum = void 0;
|
|
|
190
191
|
FeeEnum[FeeEnum["TRT_PERCENTAGE_TOTAL"] = 169] = "TRT_PERCENTAGE_TOTAL";
|
|
191
192
|
FeeEnum[FeeEnum["TDA_PERCENTAGE_TOTAL"] = 170] = "TDA_PERCENTAGE_TOTAL";
|
|
192
193
|
FeeEnum[FeeEnum["TDE_PERCENTAGE_TOTAL"] = 171] = "TDE_PERCENTAGE_TOTAL";
|
|
194
|
+
FeeEnum[FeeEnum["APPOINTMENT_BY_INVOICE_QUANTITY"] = 172] = "APPOINTMENT_BY_INVOICE_QUANTITY";
|
|
193
195
|
})(exports.FeeEnum || (exports.FeeEnum = {}));
|
|
194
196
|
|
|
195
197
|
exports.FreightRegionEnum = void 0;
|
|
@@ -254,6 +256,8 @@ exports.RatecardFeeConfigKeyEnum = void 0;
|
|
|
254
256
|
(function (RatecardFeeConfigKeyEnum) {
|
|
255
257
|
// Configurações de fração de peso
|
|
256
258
|
RatecardFeeConfigKeyEnum["MIN_WEIGHT_FOR_FRACTION"] = "min_weight_for_fraction";
|
|
259
|
+
// Configurações de exclusão de fees
|
|
260
|
+
RatecardFeeConfigKeyEnum["EXCLUDE_FROM_TOTAL_PERCENTAGE"] = "exclude_from_total_percentage";
|
|
257
261
|
})(exports.RatecardFeeConfigKeyEnum || (exports.RatecardFeeConfigKeyEnum = {}));
|
|
258
262
|
|
|
259
263
|
exports.RatecardFeeConfigTypeEnum = void 0;
|
|
@@ -416,6 +420,33 @@ var applyRedeliveryMultiplier = function (total, cte) {
|
|
|
416
420
|
};
|
|
417
421
|
};
|
|
418
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Constrói um Map de exclusões de fees baseado nas configurações do tarifário
|
|
425
|
+
* @param fees - Array de fees do tarifário
|
|
426
|
+
* @returns Map onde a chave é o feeId e o valor é um Set de feeIds excluídos da base de cálculo
|
|
427
|
+
*/
|
|
428
|
+
var buildFeeExclusionsMap = function (fees) {
|
|
429
|
+
var exclusionsMap = new Map();
|
|
430
|
+
fees.forEach(function (fee) {
|
|
431
|
+
var _a;
|
|
432
|
+
if (!((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) || !fee.fee.RatecardFeeConfig)
|
|
433
|
+
return;
|
|
434
|
+
// Procurar pela configuração de exclusão
|
|
435
|
+
var excludeConfig = fee.fee.RatecardFeeConfig.find(function (config) { var _a; return ((_a = config.feeConfig) === null || _a === void 0 ? void 0 : _a.configKey) === exports.RatecardFeeConfigKeyEnum.EXCLUDE_FROM_TOTAL_PERCENTAGE; });
|
|
436
|
+
if (excludeConfig === null || excludeConfig === void 0 ? void 0 : excludeConfig.configValue) {
|
|
437
|
+
// Parse dos IDs separados por vírgula
|
|
438
|
+
var excludedIds = excludeConfig.configValue
|
|
439
|
+
.split(',')
|
|
440
|
+
.map(function (id) { return parseInt(id.trim(), 10); })
|
|
441
|
+
.filter(function (id) { return !isNaN(id); });
|
|
442
|
+
if (excludedIds.length > 0) {
|
|
443
|
+
exclusionsMap.set(fee.fee.id, new Set(excludedIds));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
return exclusionsMap;
|
|
448
|
+
};
|
|
449
|
+
|
|
419
450
|
/******************************************************************************
|
|
420
451
|
Copyright (c) Microsoft Corporation.
|
|
421
452
|
|
|
@@ -534,7 +565,7 @@ var filterSiblingFees = function (fees) {
|
|
|
534
565
|
};
|
|
535
566
|
|
|
536
567
|
var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCalc) {
|
|
537
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
568
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
538
569
|
if (debug === void 0) { debug = false; }
|
|
539
570
|
if (ratecardLaneFee.fee) {
|
|
540
571
|
// Buscar o ratecard correto do CTE usando getRatecardFromCte
|
|
@@ -618,7 +649,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
618
649
|
if (totalValueFromAllFees && !isNaN(+totalValueFromAllFees)) {
|
|
619
650
|
var valueToMultiply = (+value / 100);
|
|
620
651
|
var total_1 = +totalValueFromAllFees * valueToMultiply;
|
|
621
|
-
var
|
|
652
|
+
var _l = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _l.adjustedTotal, redeliveryInfo_1 = _l.redeliveryInfo;
|
|
622
653
|
total_1 = adjustedTotal_1;
|
|
623
654
|
var totalValueFromAllFeesCurrency = convertNumberToCurrency(+totalValueFromAllFees, 'pt-br');
|
|
624
655
|
var resultCurrency_1 = (+total_1).toLocaleString('pt-BR', {
|
|
@@ -641,7 +672,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
641
672
|
var shouldApplyFraction = +cte.taxedWeight > minWeightForFraction;
|
|
642
673
|
var fractions = shouldApplyFraction ? Math.ceil(+cte.taxedWeight / 100) : 1;
|
|
643
674
|
var total_2 = fractions * value;
|
|
644
|
-
var
|
|
675
|
+
var _m = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _m.adjustedTotal, redeliveryInfo_2 = _m.redeliveryInfo;
|
|
645
676
|
total_2 = adjustedTotal_2;
|
|
646
677
|
var valueCurrency_1 = (+value).toLocaleString('pt-br', {
|
|
647
678
|
style: 'currency',
|
|
@@ -662,7 +693,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
662
693
|
if (value && (cte === null || cte === void 0 ? void 0 : cte.freightValue)) {
|
|
663
694
|
if (!isNaN(+value) && !isNaN(+cte.freightValue)) {
|
|
664
695
|
var total_3 = +cte.freightValue * (+value / 100);
|
|
665
|
-
var
|
|
696
|
+
var _o = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _o.adjustedTotal, redeliveryInfo_3 = _o.redeliveryInfo;
|
|
666
697
|
total_3 = adjustedTotal_3;
|
|
667
698
|
var freightValueCurrency = (+cte.freightValue).toLocaleString('pt-br', {
|
|
668
699
|
style: 'currency',
|
|
@@ -697,7 +728,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
697
728
|
case exports.FeeCalculationTypeEnum.MIN_VALUE:
|
|
698
729
|
case exports.FeeCalculationTypeEnum.FIXED:
|
|
699
730
|
var total = +value;
|
|
700
|
-
var
|
|
731
|
+
var _p = applyRedeliveryMultiplier(total, cte), adjustedTotal = _p.adjustedTotal, redeliveryInfo = _p.redeliveryInfo;
|
|
701
732
|
total = adjustedTotal;
|
|
702
733
|
var valueCurrency = (+value).toLocaleString('pt-br', {
|
|
703
734
|
style: 'currency',
|
|
@@ -749,7 +780,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
749
780
|
// Somar ao total
|
|
750
781
|
total_4 += additionalValue;
|
|
751
782
|
// Aplicar multiplicador de redelivery ao valor final
|
|
752
|
-
var
|
|
783
|
+
var _q = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _q.adjustedTotal, redeliveryInfo_4 = _q.redeliveryInfo;
|
|
753
784
|
total_4 = adjustedTotal_4;
|
|
754
785
|
var valueCurrency_2 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
755
786
|
style: 'currency',
|
|
@@ -791,7 +822,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
791
822
|
// Somar ao total
|
|
792
823
|
total_5 += additionalValue;
|
|
793
824
|
// Aplicar multiplicador de redelivery ao valor final
|
|
794
|
-
var
|
|
825
|
+
var _r = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _r.adjustedTotal, redeliveryInfo_5 = _r.redeliveryInfo;
|
|
795
826
|
total_5 = adjustedTotal_5;
|
|
796
827
|
var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
797
828
|
style: 'currency',
|
|
@@ -811,7 +842,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
811
842
|
if (value) {
|
|
812
843
|
var commodityValue = (_d = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _d !== void 0 ? _d : 0;
|
|
813
844
|
var total_6 = +commodityValue * (+value / 100);
|
|
814
|
-
var
|
|
845
|
+
var _s = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _s.adjustedTotal, redeliveryInfo_6 = _s.redeliveryInfo;
|
|
815
846
|
total_6 = adjustedTotal_6;
|
|
816
847
|
var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
|
|
817
848
|
style: 'currency',
|
|
@@ -826,7 +857,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
826
857
|
if (value) {
|
|
827
858
|
var taxedWeight = (_e = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _e !== void 0 ? _e : 0;
|
|
828
859
|
var total_7 = +taxedWeight * +value;
|
|
829
|
-
var
|
|
860
|
+
var _t = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _t.adjustedTotal, redeliveryInfo_7 = _t.redeliveryInfo;
|
|
830
861
|
total_7 = adjustedTotal_7;
|
|
831
862
|
var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
|
|
832
863
|
style: 'currency',
|
|
@@ -843,7 +874,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
843
874
|
if (value && (cte === null || cte === void 0 ? void 0 : cte.commodityVolumes)) {
|
|
844
875
|
var commodityVolumes = (_f = cte.commodityVolumes) !== null && _f !== void 0 ? _f : 0;
|
|
845
876
|
var total_8 = +commodityVolumes * +value;
|
|
846
|
-
var
|
|
877
|
+
var _u = applyRedeliveryMultiplier(total_8, cte), adjustedTotal_8 = _u.adjustedTotal, redeliveryInfo_8 = _u.redeliveryInfo;
|
|
847
878
|
total_8 = adjustedTotal_8;
|
|
848
879
|
var resultCurrency_8 = (+total_8).toLocaleString('pt-br', {
|
|
849
880
|
style: 'currency',
|
|
@@ -854,6 +885,21 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
854
885
|
resultFee = result_8;
|
|
855
886
|
}
|
|
856
887
|
break;
|
|
888
|
+
case exports.FeeCalculationTypeEnum.INVOICE_QUANTITY:
|
|
889
|
+
if (value && (cte === null || cte === void 0 ? void 0 : cte.cte_invoices)) {
|
|
890
|
+
var invoiceCount = (_h = (_g = cte.cte_invoices) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0;
|
|
891
|
+
var total_9 = +invoiceCount * +value;
|
|
892
|
+
var _v = applyRedeliveryMultiplier(total_9, cte), adjustedTotal_9 = _v.adjustedTotal, redeliveryInfo_9 = _v.redeliveryInfo;
|
|
893
|
+
total_9 = adjustedTotal_9;
|
|
894
|
+
var resultCurrency_9 = (+total_9).toLocaleString('pt-br', {
|
|
895
|
+
style: 'currency',
|
|
896
|
+
currency: 'BRL',
|
|
897
|
+
});
|
|
898
|
+
var result_9 = "".concat(invoiceCount, " ").concat(invoiceCount === 1 ? 'nota fiscal' : 'notas fiscais', " x ").concat(convertNumberToCurrency(+value, 'pt-br')).concat(redeliveryInfo_9, " = ").concat(resultCurrency_9);
|
|
899
|
+
totalFee = total_9;
|
|
900
|
+
resultFee = result_9;
|
|
901
|
+
}
|
|
902
|
+
break;
|
|
857
903
|
/*if (ratecardLaneFee.minWeight && cte?.taxedWeight) {
|
|
858
904
|
|
|
859
905
|
if (+ratecardLaneFee.minWeight <= +cte.taxedWeight) {
|
|
@@ -956,7 +1002,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
956
1002
|
return 0;
|
|
957
1003
|
});
|
|
958
1004
|
if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
|
|
959
|
-
if (((
|
|
1005
|
+
if (((_j = siblingFeesResults[0]) === null || _j === void 0 ? void 0 : _j.totalFee) && ((_k = siblingFeesResults[0]) === null || _k === void 0 ? void 0 : _k.totalFee) > totalFee) {
|
|
960
1006
|
totalToCalc = 0;
|
|
961
1007
|
}
|
|
962
1008
|
}
|
|
@@ -977,8 +1023,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
977
1023
|
* para resolver a interdependência entre elas (ex: TRT e GAC)
|
|
978
1024
|
* @param currentValues - Opcional: Map de feeId -> valor atual (para usar valores já calculados/editados)
|
|
979
1025
|
* @param manuallyEditedFeeIds - Opcional: Set de feeIds que foram editadas manualmente e não devem ser recalculadas
|
|
1026
|
+
* @param feeExclusions - Opcional: Map de feeId -> Set de feeIds excluídos da base de cálculo
|
|
980
1027
|
*/
|
|
981
|
-
var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, currentValues, manuallyEditedFeeIds) {
|
|
1028
|
+
var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, currentValues, manuallyEditedFeeIds, feeExclusions) {
|
|
982
1029
|
var results = new Map();
|
|
983
1030
|
// Separar fees em dois grupos
|
|
984
1031
|
// IMPORTANTE: ICMS não deve ser calculado aqui, ele tem tratamento especial no calculateFee
|
|
@@ -1039,11 +1086,12 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
|
|
|
1039
1086
|
results.set(pf.fee.id, __assign(__assign({}, pf), { totalFee: manualValue, totalToCalc: manualValue, resultFee: "".concat(convertNumberToCurrency(manualValue, 'pt-br'), " (editado manualmente)") }));
|
|
1040
1087
|
return;
|
|
1041
1088
|
}
|
|
1042
|
-
// Calcular base: fees não-percentuais + outras fees percentuais (exceto ela mesma)
|
|
1089
|
+
// Calcular base: fees não-percentuais + outras fees percentuais (exceto ela mesma e excluídas)
|
|
1090
|
+
var excludedFeeIds = (feeExclusions === null || feeExclusions === void 0 ? void 0 : feeExclusions.get(pf.fee.id)) || new Set();
|
|
1043
1091
|
var basePercentage = Array.from(previousValues.entries())
|
|
1044
1092
|
.filter(function (_a) {
|
|
1045
1093
|
var feeId = _a[0];
|
|
1046
|
-
return feeId !== pf.fee.id;
|
|
1094
|
+
return feeId !== pf.fee.id && !excludedFeeIds.has(feeId);
|
|
1047
1095
|
})
|
|
1048
1096
|
.reduce(function (sum, _a) {
|
|
1049
1097
|
var value = _a[1];
|
|
@@ -1120,6 +1168,98 @@ var calculateIcms = function (totalFromAllFees, icmsRate) {
|
|
|
1120
1168
|
};
|
|
1121
1169
|
};
|
|
1122
1170
|
|
|
1171
|
+
/**
|
|
1172
|
+
* Calcula todas as fees em 3 passadas (normais, TOTAL_PERCENTAGE, ICMS) e retorna um cache detalhado
|
|
1173
|
+
* com totalFee, totalToCalc e resultFee para cada fee.
|
|
1174
|
+
*
|
|
1175
|
+
* Esta função centraliza a lógica de cálculo que estava duplicada em vários lugares do ModalCte.
|
|
1176
|
+
*/
|
|
1177
|
+
var calculateFeesCacheWithDetails = function (options) {
|
|
1178
|
+
var fees = options.fees, cte = options.cte, allFeesForCalc = options.allFeesForCalc, _a = options.excludedIndexes, excludedIndexes = _a === void 0 ? new Set() : _a, preCalculatedValues = options.preCalculatedValues, manuallyEditedFeeIds = options.manuallyEditedFeeIds;
|
|
1179
|
+
var cache = {};
|
|
1180
|
+
// Filtrar fees não excluídas
|
|
1181
|
+
var nonExcludedFees = fees.filter(function (_, idx) { return !excludedIndexes.has(idx); });
|
|
1182
|
+
// Construir mapa de exclusões a partir das configurações
|
|
1183
|
+
var feeExclusions = buildFeeExclusionsMap(fees);
|
|
1184
|
+
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1185
|
+
fees.forEach(function (fee, idx) {
|
|
1186
|
+
var _a, _b;
|
|
1187
|
+
if (excludedIndexes.has(idx))
|
|
1188
|
+
return;
|
|
1189
|
+
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) !== exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
|
|
1190
|
+
((_b = fee.fee) === null || _b === void 0 ? void 0 : _b.id) !== exports.FeeEnum.ICMS) {
|
|
1191
|
+
var calculated = calculateFee(fee, cte, nonExcludedFees, true, allFeesForCalc);
|
|
1192
|
+
if (calculated) {
|
|
1193
|
+
cache[idx] = {
|
|
1194
|
+
totalFee: Number((calculated.totalFee || 0).toFixed(2)),
|
|
1195
|
+
totalToCalc: Number((calculated.totalToCalc || 0).toFixed(2)),
|
|
1196
|
+
resultFee: calculated.resultFee || '',
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
// PASSADA 2: Calcular TOTAL_PERCENTAGE de forma iterativa com exclusões
|
|
1202
|
+
var percentageFeesCache = calculateTotalPercentageFees(nonExcludedFees, cte, allFeesForCalc, preCalculatedValues, manuallyEditedFeeIds, feeExclusions);
|
|
1203
|
+
fees.forEach(function (fee, idx) {
|
|
1204
|
+
var _a, _b;
|
|
1205
|
+
if (excludedIndexes.has(idx))
|
|
1206
|
+
return;
|
|
1207
|
+
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE && ((_b = fee.fee) === null || _b === void 0 ? void 0 : _b.id)) {
|
|
1208
|
+
var cachedResult = percentageFeesCache.get(fee.fee.id);
|
|
1209
|
+
if (cachedResult) {
|
|
1210
|
+
cache[idx] = {
|
|
1211
|
+
totalFee: Number((cachedResult.totalFee || 0).toFixed(2)),
|
|
1212
|
+
totalToCalc: Number((cachedResult.totalToCalc || 0).toFixed(2)),
|
|
1213
|
+
resultFee: cachedResult.resultFee || '',
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
// PASSADA 3: Calcular ICMS
|
|
1219
|
+
fees.forEach(function (fee, idx) {
|
|
1220
|
+
var _a;
|
|
1221
|
+
if (excludedIndexes.has(idx))
|
|
1222
|
+
return;
|
|
1223
|
+
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === exports.FeeEnum.ICMS) {
|
|
1224
|
+
var icmsRate = ((cte === null || cte === void 0 ? void 0 : cte.icmsIncidence) !== undefined && (cte === null || cte === void 0 ? void 0 : cte.icmsIncidence) !== null && !isNaN(+cte.icmsIncidence))
|
|
1225
|
+
? +(cte.icmsIncidence) / 100
|
|
1226
|
+
: fee.value || 0;
|
|
1227
|
+
var valuesWithoutIcms = Object.entries(cache)
|
|
1228
|
+
.filter(function (_a) {
|
|
1229
|
+
var _b;
|
|
1230
|
+
var key = _a[0];
|
|
1231
|
+
var feeIdx = Number(key);
|
|
1232
|
+
var f = fees[feeIdx];
|
|
1233
|
+
return ((_b = f.fee) === null || _b === void 0 ? void 0 : _b.id) !== exports.FeeEnum.ICMS;
|
|
1234
|
+
})
|
|
1235
|
+
.map(function (_a) {
|
|
1236
|
+
var calcFee = _a[1];
|
|
1237
|
+
return (calcFee === null || calcFee === void 0 ? void 0 : calcFee.totalToCalc) || 0;
|
|
1238
|
+
})
|
|
1239
|
+
.filter(function (val) { return val > 0; });
|
|
1240
|
+
var icmsCalculation = calculateIcms(valuesWithoutIcms, icmsRate);
|
|
1241
|
+
if (icmsCalculation.isValid) {
|
|
1242
|
+
var resultFee = icmsCalculation.totalValueFromAllFees && icmsCalculation.valueToDivide
|
|
1243
|
+
? "(".concat(icmsCalculation.totalValueFromAllFees.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }), " / ").concat(icmsCalculation.valueToDivide, ") x ").concat(icmsRate, " = ").concat(icmsCalculation.total.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }))
|
|
1244
|
+
: '';
|
|
1245
|
+
cache[idx] = {
|
|
1246
|
+
totalFee: Number(icmsCalculation.total.toFixed(2)),
|
|
1247
|
+
totalToCalc: Number(icmsCalculation.total.toFixed(2)),
|
|
1248
|
+
resultFee: resultFee,
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
return cache;
|
|
1254
|
+
};
|
|
1255
|
+
/**
|
|
1256
|
+
* Calcula o total de fees usando calculateFeesCacheWithDetails
|
|
1257
|
+
*/
|
|
1258
|
+
var calculateFeesTotalFromCache = function (options) {
|
|
1259
|
+
var cache = calculateFeesCacheWithDetails(options);
|
|
1260
|
+
return Object.values(cache).reduce(function (sum, calcFee) { return sum + ((calcFee === null || calcFee === void 0 ? void 0 : calcFee.totalToCalc) || 0); }, 0);
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1123
1263
|
/**
|
|
1124
1264
|
* Calcula o total de fees de forma consistente, usando cálculo iterativo para TOTAL_PERCENTAGE
|
|
1125
1265
|
* @param fees - Array de fees a calcular
|
|
@@ -1131,6 +1271,8 @@ var calculateFeesTotal = function (fees, cte, allFeesForCalc) {
|
|
|
1131
1271
|
if (!fees || fees.length === 0)
|
|
1132
1272
|
return 0;
|
|
1133
1273
|
var cache = {};
|
|
1274
|
+
// Construir mapa de exclusões a partir das configurações
|
|
1275
|
+
var feeExclusions = buildFeeExclusionsMap(fees);
|
|
1134
1276
|
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1135
1277
|
fees.forEach(function (fee, idx) {
|
|
1136
1278
|
var _a, _b;
|
|
@@ -1139,8 +1281,8 @@ var calculateFeesTotal = function (fees, cte, allFeesForCalc) {
|
|
|
1139
1281
|
cache[idx] = calculateFee(fee, cte, fees, true, allFeesForCalc);
|
|
1140
1282
|
}
|
|
1141
1283
|
});
|
|
1142
|
-
// PASSADA 2: Calcular TOTAL_PERCENTAGE de forma iterativa
|
|
1143
|
-
var percentageFeesCache = calculateTotalPercentageFees(fees, cte, allFeesForCalc);
|
|
1284
|
+
// PASSADA 2: Calcular TOTAL_PERCENTAGE de forma iterativa com exclusões
|
|
1285
|
+
var percentageFeesCache = calculateTotalPercentageFees(fees, cte, allFeesForCalc, undefined, undefined, feeExclusions);
|
|
1144
1286
|
fees.forEach(function (fee, idx) {
|
|
1145
1287
|
var _a, _b;
|
|
1146
1288
|
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === exports.FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
|
|
@@ -1257,6 +1399,7 @@ var getFilteredFeesToAudit = function (_a) {
|
|
|
1257
1399
|
exports.FeeEnum.COLLECT_PERCENTAGE_TOTAL,
|
|
1258
1400
|
exports.FeeEnum.COLLECT_REVERSE_PERCENTAGE_TOTAL,
|
|
1259
1401
|
exports.FeeEnum.APPOINTMENT_MIN_VALUE,
|
|
1402
|
+
exports.FeeEnum.APPOINTMENT_BY_INVOICE_QUANTITY,
|
|
1260
1403
|
];
|
|
1261
1404
|
if (collectAndAppointmentFees.includes((_a = i.fee) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
1262
1405
|
switch ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) {
|
|
@@ -8271,8 +8414,11 @@ exports.TARIFF_MAPPING = TARIFF_MAPPING;
|
|
|
8271
8414
|
exports.addTariffMapping = addTariffMapping;
|
|
8272
8415
|
exports.applyRedeliveryMultiplier = applyRedeliveryMultiplier;
|
|
8273
8416
|
exports.buildDynamicMapping = buildDynamicMapping;
|
|
8417
|
+
exports.buildFeeExclusionsMap = buildFeeExclusionsMap;
|
|
8274
8418
|
exports.calculateFee = calculateFee;
|
|
8419
|
+
exports.calculateFeesCacheWithDetails = calculateFeesCacheWithDetails;
|
|
8275
8420
|
exports.calculateFeesTotal = calculateFeesTotal;
|
|
8421
|
+
exports.calculateFeesTotalFromCache = calculateFeesTotalFromCache;
|
|
8276
8422
|
exports.calculateIcms = calculateIcms;
|
|
8277
8423
|
exports.calculateTotalPercentageFees = calculateTotalPercentageFees;
|
|
8278
8424
|
exports.convertNumberToCurrency = convertNumberToCurrency;
|
package/build/index.js.gz
CHANGED
|
Binary file
|