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/enums/FeeEnum.d.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RatecardLaneFee } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Constrói um Map de exclusões de fees baseado nas configurações do tarifário
|
|
4
|
+
* @param fees - Array de fees do tarifário
|
|
5
|
+
* @returns Map onde a chave é o feeId e o valor é um Set de feeIds excluídos da base de cálculo
|
|
6
|
+
*/
|
|
7
|
+
export declare const buildFeeExclusionsMap: (fees: RatecardLaneFee[]) => Map<number, Set<number>>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Cte, RatecardLaneFee } from "../../types";
|
|
2
|
+
export interface FeeCalculationResult {
|
|
3
|
+
totalFee: number;
|
|
4
|
+
totalToCalc: number;
|
|
5
|
+
resultFee: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CalculateFeesCacheOptions {
|
|
8
|
+
/** Fees a serem calculadas */
|
|
9
|
+
fees: RatecardLaneFee[];
|
|
10
|
+
/** CTE para cálculo */
|
|
11
|
+
cte: Cte;
|
|
12
|
+
/** Todas as fees disponíveis para cálculo */
|
|
13
|
+
allFeesForCalc?: RatecardLaneFee[];
|
|
14
|
+
/** Índices de fees excluídas (não serão calculadas) */
|
|
15
|
+
excludedIndexes?: Set<number>;
|
|
16
|
+
/** Valores pré-calculados para usar ao invés de calcular novamente */
|
|
17
|
+
preCalculatedValues?: Map<number, number>;
|
|
18
|
+
/** IDs de fees que foram editadas manualmente e não devem ser recalculadas */
|
|
19
|
+
manuallyEditedFeeIds?: Set<number>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Calcula todas as fees em 3 passadas (normais, TOTAL_PERCENTAGE, ICMS) e retorna um cache detalhado
|
|
23
|
+
* com totalFee, totalToCalc e resultFee para cada fee.
|
|
24
|
+
*
|
|
25
|
+
* Esta função centraliza a lógica de cálculo que estava duplicada em vários lugares do ModalCte.
|
|
26
|
+
*/
|
|
27
|
+
export declare const calculateFeesCacheWithDetails: (options: CalculateFeesCacheOptions) => {
|
|
28
|
+
[index: number]: FeeCalculationResult;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Calcula o total de fees usando calculateFeesCacheWithDetails
|
|
32
|
+
*/
|
|
33
|
+
export declare const calculateFeesTotalFromCache: (options: CalculateFeesCacheOptions) => number;
|
|
@@ -5,5 +5,6 @@ import { RatecardLaneFeeWithFeeResult } from "../filterSiblingFees";
|
|
|
5
5
|
* para resolver a interdependência entre elas (ex: TRT e GAC)
|
|
6
6
|
* @param currentValues - Opcional: Map de feeId -> valor atual (para usar valores já calculados/editados)
|
|
7
7
|
* @param manuallyEditedFeeIds - Opcional: Set de feeIds que foram editadas manualmente e não devem ser recalculadas
|
|
8
|
+
* @param feeExclusions - Opcional: Map de feeId -> Set de feeIds excluídos da base de cálculo
|
|
8
9
|
*/
|
|
9
|
-
export declare const calculateTotalPercentageFees: (allFees: RatecardLaneFee[], cte: Cte, allFeesForCalc?: RatecardLaneFee[], currentValues?: Map<number, number>, manuallyEditedFeeIds?: Set<number
|
|
10
|
+
export declare const calculateTotalPercentageFees: (allFees: RatecardLaneFee[], cte: Cte, allFeesForCalc?: RatecardLaneFee[], currentValues?: Map<number, number>, manuallyEditedFeeIds?: Set<number>, feeExclusions?: Map<number, Set<number>>) => Map<number, RatecardLaneFeeWithFeeResult>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './applyRedeliveryMultiplier';
|
|
2
|
+
export * from './buildFeeExclusionsMap';
|
|
2
3
|
export * from './calculateFee';
|
|
4
|
+
export * from './calculateFeesCacheWithDetails';
|
|
3
5
|
export * from './calculateFeesTotal';
|
|
4
6
|
export * from './calculateIcms';
|
|
5
7
|
export * from './calculateTotalPercentageFees';
|
package/build/index.esm.js
CHANGED
|
@@ -145,6 +145,7 @@ var FeeCalculationTypeEnum;
|
|
|
145
145
|
FeeCalculationTypeEnum[FeeCalculationTypeEnum["MIN_VALUE"] = 10] = "MIN_VALUE";
|
|
146
146
|
FeeCalculationTypeEnum[FeeCalculationTypeEnum["SUM_CONTAINERS"] = 11] = "SUM_CONTAINERS";
|
|
147
147
|
FeeCalculationTypeEnum[FeeCalculationTypeEnum["VOLUMES_QUANTITY"] = 12] = "VOLUMES_QUANTITY";
|
|
148
|
+
FeeCalculationTypeEnum[FeeCalculationTypeEnum["INVOICE_QUANTITY"] = 13] = "INVOICE_QUANTITY";
|
|
148
149
|
})(FeeCalculationTypeEnum || (FeeCalculationTypeEnum = {}));
|
|
149
150
|
|
|
150
151
|
var FeeCategoryEnum;
|
|
@@ -186,6 +187,7 @@ var FeeEnum;
|
|
|
186
187
|
FeeEnum[FeeEnum["TRT_PERCENTAGE_TOTAL"] = 169] = "TRT_PERCENTAGE_TOTAL";
|
|
187
188
|
FeeEnum[FeeEnum["TDA_PERCENTAGE_TOTAL"] = 170] = "TDA_PERCENTAGE_TOTAL";
|
|
188
189
|
FeeEnum[FeeEnum["TDE_PERCENTAGE_TOTAL"] = 171] = "TDE_PERCENTAGE_TOTAL";
|
|
190
|
+
FeeEnum[FeeEnum["APPOINTMENT_BY_INVOICE_QUANTITY"] = 172] = "APPOINTMENT_BY_INVOICE_QUANTITY";
|
|
189
191
|
})(FeeEnum || (FeeEnum = {}));
|
|
190
192
|
|
|
191
193
|
var FreightRegionEnum;
|
|
@@ -250,6 +252,8 @@ var RatecardFeeConfigKeyEnum;
|
|
|
250
252
|
(function (RatecardFeeConfigKeyEnum) {
|
|
251
253
|
// Configurações de fração de peso
|
|
252
254
|
RatecardFeeConfigKeyEnum["MIN_WEIGHT_FOR_FRACTION"] = "min_weight_for_fraction";
|
|
255
|
+
// Configurações de exclusão de fees
|
|
256
|
+
RatecardFeeConfigKeyEnum["EXCLUDE_FROM_TOTAL_PERCENTAGE"] = "exclude_from_total_percentage";
|
|
253
257
|
})(RatecardFeeConfigKeyEnum || (RatecardFeeConfigKeyEnum = {}));
|
|
254
258
|
|
|
255
259
|
var RatecardFeeConfigTypeEnum;
|
|
@@ -412,6 +416,33 @@ var applyRedeliveryMultiplier = function (total, cte) {
|
|
|
412
416
|
};
|
|
413
417
|
};
|
|
414
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Constrói um Map de exclusões de fees baseado nas configurações do tarifário
|
|
421
|
+
* @param fees - Array de fees do tarifário
|
|
422
|
+
* @returns Map onde a chave é o feeId e o valor é um Set de feeIds excluídos da base de cálculo
|
|
423
|
+
*/
|
|
424
|
+
var buildFeeExclusionsMap = function (fees) {
|
|
425
|
+
var exclusionsMap = new Map();
|
|
426
|
+
fees.forEach(function (fee) {
|
|
427
|
+
var _a;
|
|
428
|
+
if (!((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) || !fee.fee.RatecardFeeConfig)
|
|
429
|
+
return;
|
|
430
|
+
// Procurar pela configuração de exclusão
|
|
431
|
+
var excludeConfig = fee.fee.RatecardFeeConfig.find(function (config) { var _a; return ((_a = config.feeConfig) === null || _a === void 0 ? void 0 : _a.configKey) === RatecardFeeConfigKeyEnum.EXCLUDE_FROM_TOTAL_PERCENTAGE; });
|
|
432
|
+
if (excludeConfig === null || excludeConfig === void 0 ? void 0 : excludeConfig.configValue) {
|
|
433
|
+
// Parse dos IDs separados por vírgula
|
|
434
|
+
var excludedIds = excludeConfig.configValue
|
|
435
|
+
.split(',')
|
|
436
|
+
.map(function (id) { return parseInt(id.trim(), 10); })
|
|
437
|
+
.filter(function (id) { return !isNaN(id); });
|
|
438
|
+
if (excludedIds.length > 0) {
|
|
439
|
+
exclusionsMap.set(fee.fee.id, new Set(excludedIds));
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
return exclusionsMap;
|
|
444
|
+
};
|
|
445
|
+
|
|
415
446
|
/******************************************************************************
|
|
416
447
|
Copyright (c) Microsoft Corporation.
|
|
417
448
|
|
|
@@ -530,7 +561,7 @@ var filterSiblingFees = function (fees) {
|
|
|
530
561
|
};
|
|
531
562
|
|
|
532
563
|
var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCalc) {
|
|
533
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
564
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
534
565
|
if (debug === void 0) { debug = false; }
|
|
535
566
|
if (ratecardLaneFee.fee) {
|
|
536
567
|
// Buscar o ratecard correto do CTE usando getRatecardFromCte
|
|
@@ -614,7 +645,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
614
645
|
if (totalValueFromAllFees && !isNaN(+totalValueFromAllFees)) {
|
|
615
646
|
var valueToMultiply = (+value / 100);
|
|
616
647
|
var total_1 = +totalValueFromAllFees * valueToMultiply;
|
|
617
|
-
var
|
|
648
|
+
var _l = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _l.adjustedTotal, redeliveryInfo_1 = _l.redeliveryInfo;
|
|
618
649
|
total_1 = adjustedTotal_1;
|
|
619
650
|
var totalValueFromAllFeesCurrency = convertNumberToCurrency(+totalValueFromAllFees, 'pt-br');
|
|
620
651
|
var resultCurrency_1 = (+total_1).toLocaleString('pt-BR', {
|
|
@@ -637,7 +668,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
637
668
|
var shouldApplyFraction = +cte.taxedWeight > minWeightForFraction;
|
|
638
669
|
var fractions = shouldApplyFraction ? Math.ceil(+cte.taxedWeight / 100) : 1;
|
|
639
670
|
var total_2 = fractions * value;
|
|
640
|
-
var
|
|
671
|
+
var _m = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _m.adjustedTotal, redeliveryInfo_2 = _m.redeliveryInfo;
|
|
641
672
|
total_2 = adjustedTotal_2;
|
|
642
673
|
var valueCurrency_1 = (+value).toLocaleString('pt-br', {
|
|
643
674
|
style: 'currency',
|
|
@@ -658,7 +689,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
658
689
|
if (value && (cte === null || cte === void 0 ? void 0 : cte.freightValue)) {
|
|
659
690
|
if (!isNaN(+value) && !isNaN(+cte.freightValue)) {
|
|
660
691
|
var total_3 = +cte.freightValue * (+value / 100);
|
|
661
|
-
var
|
|
692
|
+
var _o = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _o.adjustedTotal, redeliveryInfo_3 = _o.redeliveryInfo;
|
|
662
693
|
total_3 = adjustedTotal_3;
|
|
663
694
|
var freightValueCurrency = (+cte.freightValue).toLocaleString('pt-br', {
|
|
664
695
|
style: 'currency',
|
|
@@ -693,7 +724,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
693
724
|
case FeeCalculationTypeEnum.MIN_VALUE:
|
|
694
725
|
case FeeCalculationTypeEnum.FIXED:
|
|
695
726
|
var total = +value;
|
|
696
|
-
var
|
|
727
|
+
var _p = applyRedeliveryMultiplier(total, cte), adjustedTotal = _p.adjustedTotal, redeliveryInfo = _p.redeliveryInfo;
|
|
697
728
|
total = adjustedTotal;
|
|
698
729
|
var valueCurrency = (+value).toLocaleString('pt-br', {
|
|
699
730
|
style: 'currency',
|
|
@@ -745,7 +776,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
745
776
|
// Somar ao total
|
|
746
777
|
total_4 += additionalValue;
|
|
747
778
|
// Aplicar multiplicador de redelivery ao valor final
|
|
748
|
-
var
|
|
779
|
+
var _q = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _q.adjustedTotal, redeliveryInfo_4 = _q.redeliveryInfo;
|
|
749
780
|
total_4 = adjustedTotal_4;
|
|
750
781
|
var valueCurrency_2 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
751
782
|
style: 'currency',
|
|
@@ -787,7 +818,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
787
818
|
// Somar ao total
|
|
788
819
|
total_5 += additionalValue;
|
|
789
820
|
// Aplicar multiplicador de redelivery ao valor final
|
|
790
|
-
var
|
|
821
|
+
var _r = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _r.adjustedTotal, redeliveryInfo_5 = _r.redeliveryInfo;
|
|
791
822
|
total_5 = adjustedTotal_5;
|
|
792
823
|
var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
793
824
|
style: 'currency',
|
|
@@ -807,7 +838,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
807
838
|
if (value) {
|
|
808
839
|
var commodityValue = (_d = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _d !== void 0 ? _d : 0;
|
|
809
840
|
var total_6 = +commodityValue * (+value / 100);
|
|
810
|
-
var
|
|
841
|
+
var _s = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _s.adjustedTotal, redeliveryInfo_6 = _s.redeliveryInfo;
|
|
811
842
|
total_6 = adjustedTotal_6;
|
|
812
843
|
var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
|
|
813
844
|
style: 'currency',
|
|
@@ -822,7 +853,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
822
853
|
if (value) {
|
|
823
854
|
var taxedWeight = (_e = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _e !== void 0 ? _e : 0;
|
|
824
855
|
var total_7 = +taxedWeight * +value;
|
|
825
|
-
var
|
|
856
|
+
var _t = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _t.adjustedTotal, redeliveryInfo_7 = _t.redeliveryInfo;
|
|
826
857
|
total_7 = adjustedTotal_7;
|
|
827
858
|
var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
|
|
828
859
|
style: 'currency',
|
|
@@ -839,7 +870,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
839
870
|
if (value && (cte === null || cte === void 0 ? void 0 : cte.commodityVolumes)) {
|
|
840
871
|
var commodityVolumes = (_f = cte.commodityVolumes) !== null && _f !== void 0 ? _f : 0;
|
|
841
872
|
var total_8 = +commodityVolumes * +value;
|
|
842
|
-
var
|
|
873
|
+
var _u = applyRedeliveryMultiplier(total_8, cte), adjustedTotal_8 = _u.adjustedTotal, redeliveryInfo_8 = _u.redeliveryInfo;
|
|
843
874
|
total_8 = adjustedTotal_8;
|
|
844
875
|
var resultCurrency_8 = (+total_8).toLocaleString('pt-br', {
|
|
845
876
|
style: 'currency',
|
|
@@ -850,6 +881,21 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
850
881
|
resultFee = result_8;
|
|
851
882
|
}
|
|
852
883
|
break;
|
|
884
|
+
case FeeCalculationTypeEnum.INVOICE_QUANTITY:
|
|
885
|
+
if (value && (cte === null || cte === void 0 ? void 0 : cte.cte_invoices)) {
|
|
886
|
+
var invoiceCount = (_h = (_g = cte.cte_invoices) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0;
|
|
887
|
+
var total_9 = +invoiceCount * +value;
|
|
888
|
+
var _v = applyRedeliveryMultiplier(total_9, cte), adjustedTotal_9 = _v.adjustedTotal, redeliveryInfo_9 = _v.redeliveryInfo;
|
|
889
|
+
total_9 = adjustedTotal_9;
|
|
890
|
+
var resultCurrency_9 = (+total_9).toLocaleString('pt-br', {
|
|
891
|
+
style: 'currency',
|
|
892
|
+
currency: 'BRL',
|
|
893
|
+
});
|
|
894
|
+
var result_9 = "".concat(invoiceCount, " ").concat(invoiceCount === 1 ? 'nota fiscal' : 'notas fiscais', " x ").concat(convertNumberToCurrency(+value, 'pt-br')).concat(redeliveryInfo_9, " = ").concat(resultCurrency_9);
|
|
895
|
+
totalFee = total_9;
|
|
896
|
+
resultFee = result_9;
|
|
897
|
+
}
|
|
898
|
+
break;
|
|
853
899
|
/*if (ratecardLaneFee.minWeight && cte?.taxedWeight) {
|
|
854
900
|
|
|
855
901
|
if (+ratecardLaneFee.minWeight <= +cte.taxedWeight) {
|
|
@@ -952,7 +998,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
952
998
|
return 0;
|
|
953
999
|
});
|
|
954
1000
|
if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
|
|
955
|
-
if (((
|
|
1001
|
+
if (((_j = siblingFeesResults[0]) === null || _j === void 0 ? void 0 : _j.totalFee) && ((_k = siblingFeesResults[0]) === null || _k === void 0 ? void 0 : _k.totalFee) > totalFee) {
|
|
956
1002
|
totalToCalc = 0;
|
|
957
1003
|
}
|
|
958
1004
|
}
|
|
@@ -973,8 +1019,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
973
1019
|
* para resolver a interdependência entre elas (ex: TRT e GAC)
|
|
974
1020
|
* @param currentValues - Opcional: Map de feeId -> valor atual (para usar valores já calculados/editados)
|
|
975
1021
|
* @param manuallyEditedFeeIds - Opcional: Set de feeIds que foram editadas manualmente e não devem ser recalculadas
|
|
1022
|
+
* @param feeExclusions - Opcional: Map de feeId -> Set de feeIds excluídos da base de cálculo
|
|
976
1023
|
*/
|
|
977
|
-
var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, currentValues, manuallyEditedFeeIds) {
|
|
1024
|
+
var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, currentValues, manuallyEditedFeeIds, feeExclusions) {
|
|
978
1025
|
var results = new Map();
|
|
979
1026
|
// Separar fees em dois grupos
|
|
980
1027
|
// IMPORTANTE: ICMS não deve ser calculado aqui, ele tem tratamento especial no calculateFee
|
|
@@ -1035,11 +1082,12 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
|
|
|
1035
1082
|
results.set(pf.fee.id, __assign(__assign({}, pf), { totalFee: manualValue, totalToCalc: manualValue, resultFee: "".concat(convertNumberToCurrency(manualValue, 'pt-br'), " (editado manualmente)") }));
|
|
1036
1083
|
return;
|
|
1037
1084
|
}
|
|
1038
|
-
// Calcular base: fees não-percentuais + outras fees percentuais (exceto ela mesma)
|
|
1085
|
+
// Calcular base: fees não-percentuais + outras fees percentuais (exceto ela mesma e excluídas)
|
|
1086
|
+
var excludedFeeIds = (feeExclusions === null || feeExclusions === void 0 ? void 0 : feeExclusions.get(pf.fee.id)) || new Set();
|
|
1039
1087
|
var basePercentage = Array.from(previousValues.entries())
|
|
1040
1088
|
.filter(function (_a) {
|
|
1041
1089
|
var feeId = _a[0];
|
|
1042
|
-
return feeId !== pf.fee.id;
|
|
1090
|
+
return feeId !== pf.fee.id && !excludedFeeIds.has(feeId);
|
|
1043
1091
|
})
|
|
1044
1092
|
.reduce(function (sum, _a) {
|
|
1045
1093
|
var value = _a[1];
|
|
@@ -1116,6 +1164,98 @@ var calculateIcms = function (totalFromAllFees, icmsRate) {
|
|
|
1116
1164
|
};
|
|
1117
1165
|
};
|
|
1118
1166
|
|
|
1167
|
+
/**
|
|
1168
|
+
* Calcula todas as fees em 3 passadas (normais, TOTAL_PERCENTAGE, ICMS) e retorna um cache detalhado
|
|
1169
|
+
* com totalFee, totalToCalc e resultFee para cada fee.
|
|
1170
|
+
*
|
|
1171
|
+
* Esta função centraliza a lógica de cálculo que estava duplicada em vários lugares do ModalCte.
|
|
1172
|
+
*/
|
|
1173
|
+
var calculateFeesCacheWithDetails = function (options) {
|
|
1174
|
+
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;
|
|
1175
|
+
var cache = {};
|
|
1176
|
+
// Filtrar fees não excluídas
|
|
1177
|
+
var nonExcludedFees = fees.filter(function (_, idx) { return !excludedIndexes.has(idx); });
|
|
1178
|
+
// Construir mapa de exclusões a partir das configurações
|
|
1179
|
+
var feeExclusions = buildFeeExclusionsMap(fees);
|
|
1180
|
+
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1181
|
+
fees.forEach(function (fee, idx) {
|
|
1182
|
+
var _a, _b;
|
|
1183
|
+
if (excludedIndexes.has(idx))
|
|
1184
|
+
return;
|
|
1185
|
+
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) !== FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
|
|
1186
|
+
((_b = fee.fee) === null || _b === void 0 ? void 0 : _b.id) !== FeeEnum.ICMS) {
|
|
1187
|
+
var calculated = calculateFee(fee, cte, nonExcludedFees, true, allFeesForCalc);
|
|
1188
|
+
if (calculated) {
|
|
1189
|
+
cache[idx] = {
|
|
1190
|
+
totalFee: Number((calculated.totalFee || 0).toFixed(2)),
|
|
1191
|
+
totalToCalc: Number((calculated.totalToCalc || 0).toFixed(2)),
|
|
1192
|
+
resultFee: calculated.resultFee || '',
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
// PASSADA 2: Calcular TOTAL_PERCENTAGE de forma iterativa com exclusões
|
|
1198
|
+
var percentageFeesCache = calculateTotalPercentageFees(nonExcludedFees, cte, allFeesForCalc, preCalculatedValues, manuallyEditedFeeIds, feeExclusions);
|
|
1199
|
+
fees.forEach(function (fee, idx) {
|
|
1200
|
+
var _a, _b;
|
|
1201
|
+
if (excludedIndexes.has(idx))
|
|
1202
|
+
return;
|
|
1203
|
+
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === FeeCalculationTypeEnum.TOTAL_PERCENTAGE && ((_b = fee.fee) === null || _b === void 0 ? void 0 : _b.id)) {
|
|
1204
|
+
var cachedResult = percentageFeesCache.get(fee.fee.id);
|
|
1205
|
+
if (cachedResult) {
|
|
1206
|
+
cache[idx] = {
|
|
1207
|
+
totalFee: Number((cachedResult.totalFee || 0).toFixed(2)),
|
|
1208
|
+
totalToCalc: Number((cachedResult.totalToCalc || 0).toFixed(2)),
|
|
1209
|
+
resultFee: cachedResult.resultFee || '',
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
// PASSADA 3: Calcular ICMS
|
|
1215
|
+
fees.forEach(function (fee, idx) {
|
|
1216
|
+
var _a;
|
|
1217
|
+
if (excludedIndexes.has(idx))
|
|
1218
|
+
return;
|
|
1219
|
+
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === FeeEnum.ICMS) {
|
|
1220
|
+
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))
|
|
1221
|
+
? +(cte.icmsIncidence) / 100
|
|
1222
|
+
: fee.value || 0;
|
|
1223
|
+
var valuesWithoutIcms = Object.entries(cache)
|
|
1224
|
+
.filter(function (_a) {
|
|
1225
|
+
var _b;
|
|
1226
|
+
var key = _a[0];
|
|
1227
|
+
var feeIdx = Number(key);
|
|
1228
|
+
var f = fees[feeIdx];
|
|
1229
|
+
return ((_b = f.fee) === null || _b === void 0 ? void 0 : _b.id) !== FeeEnum.ICMS;
|
|
1230
|
+
})
|
|
1231
|
+
.map(function (_a) {
|
|
1232
|
+
var calcFee = _a[1];
|
|
1233
|
+
return (calcFee === null || calcFee === void 0 ? void 0 : calcFee.totalToCalc) || 0;
|
|
1234
|
+
})
|
|
1235
|
+
.filter(function (val) { return val > 0; });
|
|
1236
|
+
var icmsCalculation = calculateIcms(valuesWithoutIcms, icmsRate);
|
|
1237
|
+
if (icmsCalculation.isValid) {
|
|
1238
|
+
var resultFee = icmsCalculation.totalValueFromAllFees && icmsCalculation.valueToDivide
|
|
1239
|
+
? "(".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' }))
|
|
1240
|
+
: '';
|
|
1241
|
+
cache[idx] = {
|
|
1242
|
+
totalFee: Number(icmsCalculation.total.toFixed(2)),
|
|
1243
|
+
totalToCalc: Number(icmsCalculation.total.toFixed(2)),
|
|
1244
|
+
resultFee: resultFee,
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
return cache;
|
|
1250
|
+
};
|
|
1251
|
+
/**
|
|
1252
|
+
* Calcula o total de fees usando calculateFeesCacheWithDetails
|
|
1253
|
+
*/
|
|
1254
|
+
var calculateFeesTotalFromCache = function (options) {
|
|
1255
|
+
var cache = calculateFeesCacheWithDetails(options);
|
|
1256
|
+
return Object.values(cache).reduce(function (sum, calcFee) { return sum + ((calcFee === null || calcFee === void 0 ? void 0 : calcFee.totalToCalc) || 0); }, 0);
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1119
1259
|
/**
|
|
1120
1260
|
* Calcula o total de fees de forma consistente, usando cálculo iterativo para TOTAL_PERCENTAGE
|
|
1121
1261
|
* @param fees - Array de fees a calcular
|
|
@@ -1127,6 +1267,8 @@ var calculateFeesTotal = function (fees, cte, allFeesForCalc) {
|
|
|
1127
1267
|
if (!fees || fees.length === 0)
|
|
1128
1268
|
return 0;
|
|
1129
1269
|
var cache = {};
|
|
1270
|
+
// Construir mapa de exclusões a partir das configurações
|
|
1271
|
+
var feeExclusions = buildFeeExclusionsMap(fees);
|
|
1130
1272
|
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1131
1273
|
fees.forEach(function (fee, idx) {
|
|
1132
1274
|
var _a, _b;
|
|
@@ -1135,8 +1277,8 @@ var calculateFeesTotal = function (fees, cte, allFeesForCalc) {
|
|
|
1135
1277
|
cache[idx] = calculateFee(fee, cte, fees, true, allFeesForCalc);
|
|
1136
1278
|
}
|
|
1137
1279
|
});
|
|
1138
|
-
// PASSADA 2: Calcular TOTAL_PERCENTAGE de forma iterativa
|
|
1139
|
-
var percentageFeesCache = calculateTotalPercentageFees(fees, cte, allFeesForCalc);
|
|
1280
|
+
// PASSADA 2: Calcular TOTAL_PERCENTAGE de forma iterativa com exclusões
|
|
1281
|
+
var percentageFeesCache = calculateTotalPercentageFees(fees, cte, allFeesForCalc, undefined, undefined, feeExclusions);
|
|
1140
1282
|
fees.forEach(function (fee, idx) {
|
|
1141
1283
|
var _a, _b;
|
|
1142
1284
|
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
|
|
@@ -1253,6 +1395,7 @@ var getFilteredFeesToAudit = function (_a) {
|
|
|
1253
1395
|
FeeEnum.COLLECT_PERCENTAGE_TOTAL,
|
|
1254
1396
|
FeeEnum.COLLECT_REVERSE_PERCENTAGE_TOTAL,
|
|
1255
1397
|
FeeEnum.APPOINTMENT_MIN_VALUE,
|
|
1398
|
+
FeeEnum.APPOINTMENT_BY_INVOICE_QUANTITY,
|
|
1256
1399
|
];
|
|
1257
1400
|
if (collectAndAppointmentFees.includes((_a = i.fee) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
1258
1401
|
switch ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) {
|
|
@@ -8261,5 +8404,5 @@ var isTariffMatch = function (chargedName, auditedTariffName) {
|
|
|
8261
8404
|
});
|
|
8262
8405
|
};
|
|
8263
8406
|
|
|
8264
|
-
export { ApplicationColumnNameEnum, ApplicationEnum, CarrierDocumentConfigTypeKeyEnum, CountryEnum, CteStatusEnum, CteVehicleTypeEnum, CurrencyEnum, DocumentTypeEnum, DomainConfigurationEnum, DomainTypeEnum, EXPORT_CTE_COLUMN_LABELS, EXPORT_CTE_TYPE_LABELS, ExportCteColumn, ExportCteTypeEnum, FeeCalculationTypeEnum, FeeCategoryEnum, FeeEnum, FreightRegionEnum, ImapHostsEnum, InputTypeEnum, ModalEnum, NotificationTypeEnum, PermissionEnum, RatecardConditionalFeeTypeEnum, RatecardConfigKeyEnum, RatecardFeeConfigKeyEnum, RatecardFeeConfigTypeEnum, RatecardModalEnum, SlaRegionEnum, SpotStatusEnum, TARIFF_MAPPING, TrackProcessProviderTypeEnum, addTariffMapping, applyRedeliveryMultiplier, buildDynamicMapping, calculateFee, calculateFeesTotal, calculateIcms, calculateTotalPercentageFees, convertNumberToCurrency, filterSiblingFees, findAuditedMatch, formatDateString, getAllFeesForCalculation, getAuditTotalFromCte, getConfigurationFromDomain, getContractFromFreight, getContractRouteFromFreight, getCookies, getCteDateRange, getCteLane, getCteLaneFeesTotal, getCtesFeesResult, getDataFromToken, getFilteredFeesToAudit, getFormattedFreightPlaceName, getLaneFeesToCalc, getLaneFromRatecard, getNormalizedCityName, getRatecardFromCte, getRouteDeliveryTimeFromFreight, getRouteOnTimeFromFreight, getTariffVariations, isTariffMatch, matchAllTariffs, normalizeString, parseAliases, renderChargedValue, setFormattedDatesInObjects, verifyConditionalFee, verifyDefaultFees };
|
|
8407
|
+
export { ApplicationColumnNameEnum, ApplicationEnum, CarrierDocumentConfigTypeKeyEnum, CountryEnum, CteStatusEnum, CteVehicleTypeEnum, CurrencyEnum, DocumentTypeEnum, DomainConfigurationEnum, DomainTypeEnum, EXPORT_CTE_COLUMN_LABELS, EXPORT_CTE_TYPE_LABELS, ExportCteColumn, ExportCteTypeEnum, FeeCalculationTypeEnum, FeeCategoryEnum, FeeEnum, FreightRegionEnum, ImapHostsEnum, InputTypeEnum, ModalEnum, NotificationTypeEnum, PermissionEnum, RatecardConditionalFeeTypeEnum, RatecardConfigKeyEnum, RatecardFeeConfigKeyEnum, RatecardFeeConfigTypeEnum, RatecardModalEnum, SlaRegionEnum, SpotStatusEnum, TARIFF_MAPPING, TrackProcessProviderTypeEnum, addTariffMapping, applyRedeliveryMultiplier, buildDynamicMapping, buildFeeExclusionsMap, calculateFee, calculateFeesCacheWithDetails, calculateFeesTotal, calculateFeesTotalFromCache, calculateIcms, calculateTotalPercentageFees, convertNumberToCurrency, filterSiblingFees, findAuditedMatch, formatDateString, getAllFeesForCalculation, getAuditTotalFromCte, getConfigurationFromDomain, getContractFromFreight, getContractRouteFromFreight, getCookies, getCteDateRange, getCteLane, getCteLaneFeesTotal, getCtesFeesResult, getDataFromToken, getFilteredFeesToAudit, getFormattedFreightPlaceName, getLaneFeesToCalc, getLaneFromRatecard, getNormalizedCityName, getRatecardFromCte, getRouteDeliveryTimeFromFreight, getRouteOnTimeFromFreight, getTariffVariations, isTariffMatch, matchAllTariffs, normalizeString, parseAliases, renderChargedValue, setFormattedDatesInObjects, verifyConditionalFee, verifyDefaultFees };
|
|
8265
8408
|
//# sourceMappingURL=index.esm.js.map
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|