b2m-utils 0.0.310 → 0.0.312
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/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 +35 -0
- package/build/functions/calculateFeesTotal/index.d.ts +3 -2
- package/build/functions/calculateTotalPercentageFees/index.d.ts +2 -1
- package/build/functions/index.d.ts +2 -0
- package/build/index.esm.js +193 -7
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +195 -6
- 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 { Ratecard } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Constrói um Map de exclusões de fees baseado nas configurações do tarifário
|
|
4
|
+
* @param ratecard - Tarifário contendo as configurações de fees
|
|
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: (ratecard?: Ratecard) => Map<number, Set<number>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Cte, RatecardLaneFee, Ratecard } 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
|
+
/** Tarifário (opcional, será extraído do CTE se não fornecido) */
|
|
21
|
+
ratecard?: Ratecard;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Calcula todas as fees em 3 passadas (normais, TOTAL_PERCENTAGE, ICMS) e retorna um cache detalhado
|
|
25
|
+
* com totalFee, totalToCalc e resultFee para cada fee.
|
|
26
|
+
*
|
|
27
|
+
* Esta função centraliza a lógica de cálculo que estava duplicada em vários lugares do ModalCte.
|
|
28
|
+
*/
|
|
29
|
+
export declare const calculateFeesCacheWithDetails: (options: CalculateFeesCacheOptions) => {
|
|
30
|
+
[index: number]: FeeCalculationResult;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Calcula o total de fees usando calculateFeesCacheWithDetails
|
|
34
|
+
*/
|
|
35
|
+
export declare const calculateFeesTotalFromCache: (options: CalculateFeesCacheOptions) => number;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Cte, RatecardLaneFee } from "../../types";
|
|
1
|
+
import { Cte, RatecardLaneFee, Ratecard } from "../../types";
|
|
2
2
|
/**
|
|
3
3
|
* Calcula o total de fees de forma consistente, usando cálculo iterativo para TOTAL_PERCENTAGE
|
|
4
4
|
* @param fees - Array de fees a calcular
|
|
5
5
|
* @param cte - CTE para cálculo
|
|
6
6
|
* @param allFeesForCalc - Todas as fees disponíveis para cálculo
|
|
7
|
+
* @param ratecard - Tarifário (opcional, será extraído do CTE se não fornecido)
|
|
7
8
|
* @returns Total calculado
|
|
8
9
|
*/
|
|
9
|
-
export declare const calculateFeesTotal: (fees: RatecardLaneFee[], cte: Cte, allFeesForCalc?: RatecardLaneFee[]) => number;
|
|
10
|
+
export declare const calculateFeesTotal: (fees: RatecardLaneFee[], cte: Cte, allFeesForCalc?: RatecardLaneFee[], ratecard?: Ratecard) => 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
|
@@ -187,6 +187,7 @@ var FeeEnum;
|
|
|
187
187
|
FeeEnum[FeeEnum["TRT_PERCENTAGE_TOTAL"] = 169] = "TRT_PERCENTAGE_TOTAL";
|
|
188
188
|
FeeEnum[FeeEnum["TDA_PERCENTAGE_TOTAL"] = 170] = "TDA_PERCENTAGE_TOTAL";
|
|
189
189
|
FeeEnum[FeeEnum["TDE_PERCENTAGE_TOTAL"] = 171] = "TDE_PERCENTAGE_TOTAL";
|
|
190
|
+
FeeEnum[FeeEnum["APPOINTMENT_BY_INVOICE_QUANTITY"] = 172] = "APPOINTMENT_BY_INVOICE_QUANTITY";
|
|
190
191
|
})(FeeEnum || (FeeEnum = {}));
|
|
191
192
|
|
|
192
193
|
var FreightRegionEnum;
|
|
@@ -251,6 +252,8 @@ var RatecardFeeConfigKeyEnum;
|
|
|
251
252
|
(function (RatecardFeeConfigKeyEnum) {
|
|
252
253
|
// Configurações de fração de peso
|
|
253
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";
|
|
254
257
|
})(RatecardFeeConfigKeyEnum || (RatecardFeeConfigKeyEnum = {}));
|
|
255
258
|
|
|
256
259
|
var RatecardFeeConfigTypeEnum;
|
|
@@ -413,6 +416,62 @@ var applyRedeliveryMultiplier = function (total, cte) {
|
|
|
413
416
|
};
|
|
414
417
|
};
|
|
415
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Constrói um Map de exclusões de fees baseado nas configurações do tarifário
|
|
421
|
+
* @param ratecard - Tarifário contendo as configurações de fees
|
|
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 (ratecard) {
|
|
425
|
+
var _a;
|
|
426
|
+
var exclusionsMap = new Map();
|
|
427
|
+
console.log('[buildFeeExclusionsMap] Iniciando construção do mapa de exclusões', {
|
|
428
|
+
ratecardId: ratecard === null || ratecard === void 0 ? void 0 : ratecard.id,
|
|
429
|
+
hasConfigs: !!(ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardFeeConfig),
|
|
430
|
+
configsCount: ((_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardFeeConfig) === null || _a === void 0 ? void 0 : _a.length) || 0
|
|
431
|
+
});
|
|
432
|
+
if (!(ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardFeeConfig)) {
|
|
433
|
+
console.log('[buildFeeExclusionsMap] Nenhuma configuração encontrada, retornando mapa vazio');
|
|
434
|
+
return exclusionsMap;
|
|
435
|
+
}
|
|
436
|
+
// Iterar sobre todas as configurações de fees do ratecard
|
|
437
|
+
ratecard.RatecardFeeConfig.forEach(function (config) {
|
|
438
|
+
var _a, _b;
|
|
439
|
+
// Verificar se é uma configuração de exclusão
|
|
440
|
+
if (((_a = config.feeConfig) === null || _a === void 0 ? void 0 : _a.configKey) === RatecardFeeConfigKeyEnum.EXCLUDE_FROM_TOTAL_PERCENTAGE &&
|
|
441
|
+
config.configValue &&
|
|
442
|
+
config.feeId) {
|
|
443
|
+
console.log('[buildFeeExclusionsMap] Configuração de exclusão encontrada', {
|
|
444
|
+
feeId: config.feeId,
|
|
445
|
+
feeName: (_b = config.fee) === null || _b === void 0 ? void 0 : _b.name,
|
|
446
|
+
configValue: config.configValue
|
|
447
|
+
});
|
|
448
|
+
// Parse dos IDs separados por vírgula
|
|
449
|
+
var excludedIds = config.configValue
|
|
450
|
+
.split(',')
|
|
451
|
+
.map(function (id) { return parseInt(id.trim(), 10); })
|
|
452
|
+
.filter(function (id) { return !isNaN(id); });
|
|
453
|
+
if (excludedIds.length > 0) {
|
|
454
|
+
exclusionsMap.set(config.feeId, new Set(excludedIds));
|
|
455
|
+
console.log('[buildFeeExclusionsMap] Exclusões adicionadas ao mapa', {
|
|
456
|
+
feeId: config.feeId,
|
|
457
|
+
excludedIds: Array.from(excludedIds)
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
console.log('[buildFeeExclusionsMap] Mapa de exclusões construído', {
|
|
463
|
+
totalExclusions: exclusionsMap.size,
|
|
464
|
+
exclusionsMap: Array.from(exclusionsMap.entries()).map(function (_a) {
|
|
465
|
+
var feeId = _a[0], excludedIds = _a[1];
|
|
466
|
+
return ({
|
|
467
|
+
feeId: feeId,
|
|
468
|
+
excludedIds: Array.from(excludedIds)
|
|
469
|
+
});
|
|
470
|
+
})
|
|
471
|
+
});
|
|
472
|
+
return exclusionsMap;
|
|
473
|
+
};
|
|
474
|
+
|
|
416
475
|
/******************************************************************************
|
|
417
476
|
Copyright (c) Microsoft Corporation.
|
|
418
477
|
|
|
@@ -989,8 +1048,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
989
1048
|
* para resolver a interdependência entre elas (ex: TRT e GAC)
|
|
990
1049
|
* @param currentValues - Opcional: Map de feeId -> valor atual (para usar valores já calculados/editados)
|
|
991
1050
|
* @param manuallyEditedFeeIds - Opcional: Set de feeIds que foram editadas manualmente e não devem ser recalculadas
|
|
1051
|
+
* @param feeExclusions - Opcional: Map de feeId -> Set de feeIds excluídos da base de cálculo
|
|
992
1052
|
*/
|
|
993
|
-
var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, currentValues, manuallyEditedFeeIds) {
|
|
1053
|
+
var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, currentValues, manuallyEditedFeeIds, feeExclusions) {
|
|
994
1054
|
var results = new Map();
|
|
995
1055
|
// Separar fees em dois grupos
|
|
996
1056
|
// IMPORTANTE: ICMS não deve ser calculado aqui, ele tem tratamento especial no calculateFee
|
|
@@ -1051,11 +1111,20 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
|
|
|
1051
1111
|
results.set(pf.fee.id, __assign(__assign({}, pf), { totalFee: manualValue, totalToCalc: manualValue, resultFee: "".concat(convertNumberToCurrency(manualValue, 'pt-br'), " (editado manualmente)") }));
|
|
1052
1112
|
return;
|
|
1053
1113
|
}
|
|
1054
|
-
// Calcular base: fees não-percentuais + outras fees percentuais (exceto ela mesma)
|
|
1114
|
+
// Calcular base: fees não-percentuais + outras fees percentuais (exceto ela mesma e excluídas)
|
|
1115
|
+
var excludedFeeIds = (feeExclusions === null || feeExclusions === void 0 ? void 0 : feeExclusions.get(pf.fee.id)) || new Set();
|
|
1116
|
+
console.log('[calculateTotalPercentageFees] Calculando fee TOTAL_PERCENTAGE', {
|
|
1117
|
+
feeId: pf.fee.id,
|
|
1118
|
+
feeName: pf.fee.name,
|
|
1119
|
+
percentValue: pf.value,
|
|
1120
|
+
hasExclusions: excludedFeeIds.size > 0,
|
|
1121
|
+
excludedFeeIds: Array.from(excludedFeeIds),
|
|
1122
|
+
iteration: iteration
|
|
1123
|
+
});
|
|
1055
1124
|
var basePercentage = Array.from(previousValues.entries())
|
|
1056
1125
|
.filter(function (_a) {
|
|
1057
1126
|
var feeId = _a[0];
|
|
1058
|
-
return feeId !== pf.fee.id;
|
|
1127
|
+
return feeId !== pf.fee.id && !excludedFeeIds.has(feeId);
|
|
1059
1128
|
})
|
|
1060
1129
|
.reduce(function (sum, _a) {
|
|
1061
1130
|
var value = _a[1];
|
|
@@ -1064,6 +1133,23 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
|
|
|
1064
1133
|
var baseValue = baseNonPercentage + basePercentage;
|
|
1065
1134
|
var percentValue = (+pf.value / 100);
|
|
1066
1135
|
var calculatedValue = baseValue * percentValue;
|
|
1136
|
+
console.log('[calculateTotalPercentageFees] Base calculada', {
|
|
1137
|
+
feeId: pf.fee.id,
|
|
1138
|
+
feeName: pf.fee.name,
|
|
1139
|
+
baseNonPercentage: baseNonPercentage,
|
|
1140
|
+
basePercentage: basePercentage,
|
|
1141
|
+
baseValue: baseValue,
|
|
1142
|
+
percentValue: "".concat(pf.value, "%"),
|
|
1143
|
+
calculatedValue: calculatedValue,
|
|
1144
|
+
allPreviousValues: Array.from(previousValues.entries()).map(function (_a) {
|
|
1145
|
+
var id = _a[0], val = _a[1];
|
|
1146
|
+
return ({
|
|
1147
|
+
feeId: id,
|
|
1148
|
+
value: val,
|
|
1149
|
+
excluded: excludedFeeIds.has(id)
|
|
1150
|
+
});
|
|
1151
|
+
})
|
|
1152
|
+
});
|
|
1067
1153
|
previousValues.set(pf.fee.id, calculatedValue);
|
|
1068
1154
|
// Armazenar resultado
|
|
1069
1155
|
results.set(pf.fee.id, __assign(__assign({}, pf), { totalFee: calculatedValue, totalToCalc: calculatedValue, resultFee: "".concat(convertNumberToCurrency(baseValue, 'pt-br'), " x ").concat(+pf.value, "% = ").concat(convertNumberToCurrency(calculatedValue, 'pt-br')) }));
|
|
@@ -1132,17 +1218,116 @@ var calculateIcms = function (totalFromAllFees, icmsRate) {
|
|
|
1132
1218
|
};
|
|
1133
1219
|
};
|
|
1134
1220
|
|
|
1221
|
+
/**
|
|
1222
|
+
* Calcula todas as fees em 3 passadas (normais, TOTAL_PERCENTAGE, ICMS) e retorna um cache detalhado
|
|
1223
|
+
* com totalFee, totalToCalc e resultFee para cada fee.
|
|
1224
|
+
*
|
|
1225
|
+
* Esta função centraliza a lógica de cálculo que estava duplicada em vários lugares do ModalCte.
|
|
1226
|
+
*/
|
|
1227
|
+
var calculateFeesCacheWithDetails = function (options) {
|
|
1228
|
+
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, ratecard = options.ratecard;
|
|
1229
|
+
var cache = {};
|
|
1230
|
+
// Filtrar fees não excluídas
|
|
1231
|
+
var nonExcludedFees = fees.filter(function (_, idx) { return !excludedIndexes.has(idx); });
|
|
1232
|
+
// Obter ratecard se não foi fornecido
|
|
1233
|
+
var ratecardToUse = ratecard || getRatecardFromCte(cte) || undefined;
|
|
1234
|
+
// Construir mapa de exclusões a partir das configurações do ratecard
|
|
1235
|
+
var feeExclusions = buildFeeExclusionsMap(ratecardToUse);
|
|
1236
|
+
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1237
|
+
fees.forEach(function (fee, idx) {
|
|
1238
|
+
var _a, _b;
|
|
1239
|
+
if (excludedIndexes.has(idx))
|
|
1240
|
+
return;
|
|
1241
|
+
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) !== FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
|
|
1242
|
+
((_b = fee.fee) === null || _b === void 0 ? void 0 : _b.id) !== FeeEnum.ICMS) {
|
|
1243
|
+
var calculated = calculateFee(fee, cte, nonExcludedFees, true, allFeesForCalc);
|
|
1244
|
+
if (calculated) {
|
|
1245
|
+
cache[idx] = {
|
|
1246
|
+
totalFee: Number((calculated.totalFee || 0).toFixed(2)),
|
|
1247
|
+
totalToCalc: Number((calculated.totalToCalc || 0).toFixed(2)),
|
|
1248
|
+
resultFee: calculated.resultFee || '',
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
// PASSADA 2: Calcular TOTAL_PERCENTAGE de forma iterativa com exclusões
|
|
1254
|
+
var percentageFeesCache = calculateTotalPercentageFees(nonExcludedFees, cte, allFeesForCalc, preCalculatedValues, manuallyEditedFeeIds, feeExclusions);
|
|
1255
|
+
fees.forEach(function (fee, idx) {
|
|
1256
|
+
var _a, _b;
|
|
1257
|
+
if (excludedIndexes.has(idx))
|
|
1258
|
+
return;
|
|
1259
|
+
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)) {
|
|
1260
|
+
var cachedResult = percentageFeesCache.get(fee.fee.id);
|
|
1261
|
+
if (cachedResult) {
|
|
1262
|
+
cache[idx] = {
|
|
1263
|
+
totalFee: Number((cachedResult.totalFee || 0).toFixed(2)),
|
|
1264
|
+
totalToCalc: Number((cachedResult.totalToCalc || 0).toFixed(2)),
|
|
1265
|
+
resultFee: cachedResult.resultFee || '',
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
// PASSADA 3: Calcular ICMS
|
|
1271
|
+
fees.forEach(function (fee, idx) {
|
|
1272
|
+
var _a;
|
|
1273
|
+
if (excludedIndexes.has(idx))
|
|
1274
|
+
return;
|
|
1275
|
+
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === FeeEnum.ICMS) {
|
|
1276
|
+
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))
|
|
1277
|
+
? +(cte.icmsIncidence) / 100
|
|
1278
|
+
: fee.value || 0;
|
|
1279
|
+
var valuesWithoutIcms = Object.entries(cache)
|
|
1280
|
+
.filter(function (_a) {
|
|
1281
|
+
var _b;
|
|
1282
|
+
var key = _a[0];
|
|
1283
|
+
var feeIdx = Number(key);
|
|
1284
|
+
var f = fees[feeIdx];
|
|
1285
|
+
return ((_b = f.fee) === null || _b === void 0 ? void 0 : _b.id) !== FeeEnum.ICMS;
|
|
1286
|
+
})
|
|
1287
|
+
.map(function (_a) {
|
|
1288
|
+
var calcFee = _a[1];
|
|
1289
|
+
return (calcFee === null || calcFee === void 0 ? void 0 : calcFee.totalToCalc) || 0;
|
|
1290
|
+
})
|
|
1291
|
+
.filter(function (val) { return val > 0; });
|
|
1292
|
+
var icmsCalculation = calculateIcms(valuesWithoutIcms, icmsRate);
|
|
1293
|
+
if (icmsCalculation.isValid) {
|
|
1294
|
+
var resultFee = icmsCalculation.totalValueFromAllFees && icmsCalculation.valueToDivide
|
|
1295
|
+
? "(".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' }))
|
|
1296
|
+
: '';
|
|
1297
|
+
cache[idx] = {
|
|
1298
|
+
totalFee: Number(icmsCalculation.total.toFixed(2)),
|
|
1299
|
+
totalToCalc: Number(icmsCalculation.total.toFixed(2)),
|
|
1300
|
+
resultFee: resultFee,
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
});
|
|
1305
|
+
return cache;
|
|
1306
|
+
};
|
|
1307
|
+
/**
|
|
1308
|
+
* Calcula o total de fees usando calculateFeesCacheWithDetails
|
|
1309
|
+
*/
|
|
1310
|
+
var calculateFeesTotalFromCache = function (options) {
|
|
1311
|
+
var cache = calculateFeesCacheWithDetails(options);
|
|
1312
|
+
return Object.values(cache).reduce(function (sum, calcFee) { return sum + ((calcFee === null || calcFee === void 0 ? void 0 : calcFee.totalToCalc) || 0); }, 0);
|
|
1313
|
+
};
|
|
1314
|
+
|
|
1135
1315
|
/**
|
|
1136
1316
|
* Calcula o total de fees de forma consistente, usando cálculo iterativo para TOTAL_PERCENTAGE
|
|
1137
1317
|
* @param fees - Array de fees a calcular
|
|
1138
1318
|
* @param cte - CTE para cálculo
|
|
1139
1319
|
* @param allFeesForCalc - Todas as fees disponíveis para cálculo
|
|
1320
|
+
* @param ratecard - Tarifário (opcional, será extraído do CTE se não fornecido)
|
|
1140
1321
|
* @returns Total calculado
|
|
1141
1322
|
*/
|
|
1142
|
-
var calculateFeesTotal = function (fees, cte, allFeesForCalc) {
|
|
1323
|
+
var calculateFeesTotal = function (fees, cte, allFeesForCalc, ratecard) {
|
|
1143
1324
|
if (!fees || fees.length === 0)
|
|
1144
1325
|
return 0;
|
|
1145
1326
|
var cache = {};
|
|
1327
|
+
// Obter ratecard se não foi fornecido
|
|
1328
|
+
var ratecardToUse = ratecard || getRatecardFromCte(cte) || undefined;
|
|
1329
|
+
// Construir mapa de exclusões a partir das configurações do ratecard
|
|
1330
|
+
var feeExclusions = buildFeeExclusionsMap(ratecardToUse);
|
|
1146
1331
|
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1147
1332
|
fees.forEach(function (fee, idx) {
|
|
1148
1333
|
var _a, _b;
|
|
@@ -1151,8 +1336,8 @@ var calculateFeesTotal = function (fees, cte, allFeesForCalc) {
|
|
|
1151
1336
|
cache[idx] = calculateFee(fee, cte, fees, true, allFeesForCalc);
|
|
1152
1337
|
}
|
|
1153
1338
|
});
|
|
1154
|
-
// PASSADA 2: Calcular TOTAL_PERCENTAGE de forma iterativa
|
|
1155
|
-
var percentageFeesCache = calculateTotalPercentageFees(fees, cte, allFeesForCalc);
|
|
1339
|
+
// PASSADA 2: Calcular TOTAL_PERCENTAGE de forma iterativa com exclusões
|
|
1340
|
+
var percentageFeesCache = calculateTotalPercentageFees(fees, cte, allFeesForCalc, undefined, undefined, feeExclusions);
|
|
1156
1341
|
fees.forEach(function (fee, idx) {
|
|
1157
1342
|
var _a, _b;
|
|
1158
1343
|
if (((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.feeCalculationTypeId) === FeeCalculationTypeEnum.TOTAL_PERCENTAGE &&
|
|
@@ -1269,6 +1454,7 @@ var getFilteredFeesToAudit = function (_a) {
|
|
|
1269
1454
|
FeeEnum.COLLECT_PERCENTAGE_TOTAL,
|
|
1270
1455
|
FeeEnum.COLLECT_REVERSE_PERCENTAGE_TOTAL,
|
|
1271
1456
|
FeeEnum.APPOINTMENT_MIN_VALUE,
|
|
1457
|
+
FeeEnum.APPOINTMENT_BY_INVOICE_QUANTITY,
|
|
1272
1458
|
];
|
|
1273
1459
|
if (collectAndAppointmentFees.includes((_a = i.fee) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
1274
1460
|
switch ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) {
|
|
@@ -8277,5 +8463,5 @@ var isTariffMatch = function (chargedName, auditedTariffName) {
|
|
|
8277
8463
|
});
|
|
8278
8464
|
};
|
|
8279
8465
|
|
|
8280
|
-
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 };
|
|
8466
|
+
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 };
|
|
8281
8467
|
//# sourceMappingURL=index.esm.js.map
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|