b2m-utils 0.0.311 → 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/functions/buildFeeExclusionsMap/index.d.ts +3 -3
- package/build/functions/calculateFeesCacheWithDetails/index.d.ts +3 -1
- package/build/functions/calculateFeesTotal/index.d.ts +3 -2
- package/build/index.esm.js +76 -17
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +76 -17
- package/build/index.js.gz +0 -0
- package/build/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ratecard } from "../../types";
|
|
2
2
|
/**
|
|
3
3
|
* Constrói um Map de exclusões de fees baseado nas configurações do tarifário
|
|
4
|
-
* @param
|
|
4
|
+
* @param ratecard - Tarifário contendo as configurações de fees
|
|
5
5
|
* @returns Map onde a chave é o feeId e o valor é um Set de feeIds excluídos da base de cálculo
|
|
6
6
|
*/
|
|
7
|
-
export declare const buildFeeExclusionsMap: (
|
|
7
|
+
export declare const buildFeeExclusionsMap: (ratecard?: Ratecard) => Map<number, Set<number>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cte, RatecardLaneFee } from "../../types";
|
|
1
|
+
import { Cte, RatecardLaneFee, Ratecard } from "../../types";
|
|
2
2
|
export interface FeeCalculationResult {
|
|
3
3
|
totalFee: number;
|
|
4
4
|
totalToCalc: number;
|
|
@@ -17,6 +17,8 @@ export interface CalculateFeesCacheOptions {
|
|
|
17
17
|
preCalculatedValues?: Map<number, number>;
|
|
18
18
|
/** IDs de fees que foram editadas manualmente e não devem ser recalculadas */
|
|
19
19
|
manuallyEditedFeeIds?: Set<number>;
|
|
20
|
+
/** Tarifário (opcional, será extraído do CTE se não fornecido) */
|
|
21
|
+
ratecard?: Ratecard;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* Calcula todas as fees em 3 passadas (normais, TOTAL_PERCENTAGE, ICMS) e retorna um cache detalhado
|
|
@@ -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;
|
package/build/index.esm.js
CHANGED
|
@@ -418,28 +418,57 @@ var applyRedeliveryMultiplier = function (total, cte) {
|
|
|
418
418
|
|
|
419
419
|
/**
|
|
420
420
|
* Constrói um Map de exclusões de fees baseado nas configurações do tarifário
|
|
421
|
-
* @param
|
|
421
|
+
* @param ratecard - Tarifário contendo as configurações de fees
|
|
422
422
|
* @returns Map onde a chave é o feeId e o valor é um Set de feeIds excluídos da base de cálculo
|
|
423
423
|
*/
|
|
424
|
-
var buildFeeExclusionsMap = function (
|
|
424
|
+
var buildFeeExclusionsMap = function (ratecard) {
|
|
425
|
+
var _a;
|
|
425
426
|
var exclusionsMap = new Map();
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
+
});
|
|
433
448
|
// Parse dos IDs separados por vírgula
|
|
434
|
-
var excludedIds =
|
|
449
|
+
var excludedIds = config.configValue
|
|
435
450
|
.split(',')
|
|
436
451
|
.map(function (id) { return parseInt(id.trim(), 10); })
|
|
437
452
|
.filter(function (id) { return !isNaN(id); });
|
|
438
453
|
if (excludedIds.length > 0) {
|
|
439
|
-
exclusionsMap.set(
|
|
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
|
+
});
|
|
440
459
|
}
|
|
441
460
|
}
|
|
442
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
|
+
});
|
|
443
472
|
return exclusionsMap;
|
|
444
473
|
};
|
|
445
474
|
|
|
@@ -1084,6 +1113,14 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
|
|
|
1084
1113
|
}
|
|
1085
1114
|
// Calcular base: fees não-percentuais + outras fees percentuais (exceto ela mesma e excluídas)
|
|
1086
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
|
+
});
|
|
1087
1124
|
var basePercentage = Array.from(previousValues.entries())
|
|
1088
1125
|
.filter(function (_a) {
|
|
1089
1126
|
var feeId = _a[0];
|
|
@@ -1096,6 +1133,23 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
|
|
|
1096
1133
|
var baseValue = baseNonPercentage + basePercentage;
|
|
1097
1134
|
var percentValue = (+pf.value / 100);
|
|
1098
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
|
+
});
|
|
1099
1153
|
previousValues.set(pf.fee.id, calculatedValue);
|
|
1100
1154
|
// Armazenar resultado
|
|
1101
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')) }));
|
|
@@ -1171,12 +1225,14 @@ var calculateIcms = function (totalFromAllFees, icmsRate) {
|
|
|
1171
1225
|
* Esta função centraliza a lógica de cálculo que estava duplicada em vários lugares do ModalCte.
|
|
1172
1226
|
*/
|
|
1173
1227
|
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;
|
|
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;
|
|
1175
1229
|
var cache = {};
|
|
1176
1230
|
// Filtrar fees não excluídas
|
|
1177
1231
|
var nonExcludedFees = fees.filter(function (_, idx) { return !excludedIndexes.has(idx); });
|
|
1178
|
-
//
|
|
1179
|
-
var
|
|
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);
|
|
1180
1236
|
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1181
1237
|
fees.forEach(function (fee, idx) {
|
|
1182
1238
|
var _a, _b;
|
|
@@ -1261,14 +1317,17 @@ var calculateFeesTotalFromCache = function (options) {
|
|
|
1261
1317
|
* @param fees - Array de fees a calcular
|
|
1262
1318
|
* @param cte - CTE para cálculo
|
|
1263
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)
|
|
1264
1321
|
* @returns Total calculado
|
|
1265
1322
|
*/
|
|
1266
|
-
var calculateFeesTotal = function (fees, cte, allFeesForCalc) {
|
|
1323
|
+
var calculateFeesTotal = function (fees, cte, allFeesForCalc, ratecard) {
|
|
1267
1324
|
if (!fees || fees.length === 0)
|
|
1268
1325
|
return 0;
|
|
1269
1326
|
var cache = {};
|
|
1270
|
-
//
|
|
1271
|
-
var
|
|
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);
|
|
1272
1331
|
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1273
1332
|
fees.forEach(function (fee, idx) {
|
|
1274
1333
|
var _a, _b;
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|