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
package/build/index.js
CHANGED
|
@@ -422,28 +422,57 @@ var applyRedeliveryMultiplier = function (total, cte) {
|
|
|
422
422
|
|
|
423
423
|
/**
|
|
424
424
|
* Constrói um Map de exclusões de fees baseado nas configurações do tarifário
|
|
425
|
-
* @param
|
|
425
|
+
* @param ratecard - Tarifário contendo as configurações de fees
|
|
426
426
|
* @returns Map onde a chave é o feeId e o valor é um Set de feeIds excluídos da base de cálculo
|
|
427
427
|
*/
|
|
428
|
-
var buildFeeExclusionsMap = function (
|
|
428
|
+
var buildFeeExclusionsMap = function (ratecard) {
|
|
429
|
+
var _a;
|
|
429
430
|
var exclusionsMap = new Map();
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
431
|
+
console.log('[buildFeeExclusionsMap] Iniciando construção do mapa de exclusões', {
|
|
432
|
+
ratecardId: ratecard === null || ratecard === void 0 ? void 0 : ratecard.id,
|
|
433
|
+
hasConfigs: !!(ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardFeeConfig),
|
|
434
|
+
configsCount: ((_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardFeeConfig) === null || _a === void 0 ? void 0 : _a.length) || 0
|
|
435
|
+
});
|
|
436
|
+
if (!(ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardFeeConfig)) {
|
|
437
|
+
console.log('[buildFeeExclusionsMap] Nenhuma configuração encontrada, retornando mapa vazio');
|
|
438
|
+
return exclusionsMap;
|
|
439
|
+
}
|
|
440
|
+
// Iterar sobre todas as configurações de fees do ratecard
|
|
441
|
+
ratecard.RatecardFeeConfig.forEach(function (config) {
|
|
442
|
+
var _a, _b;
|
|
443
|
+
// Verificar se é uma configuração de exclusão
|
|
444
|
+
if (((_a = config.feeConfig) === null || _a === void 0 ? void 0 : _a.configKey) === exports.RatecardFeeConfigKeyEnum.EXCLUDE_FROM_TOTAL_PERCENTAGE &&
|
|
445
|
+
config.configValue &&
|
|
446
|
+
config.feeId) {
|
|
447
|
+
console.log('[buildFeeExclusionsMap] Configuração de exclusão encontrada', {
|
|
448
|
+
feeId: config.feeId,
|
|
449
|
+
feeName: (_b = config.fee) === null || _b === void 0 ? void 0 : _b.name,
|
|
450
|
+
configValue: config.configValue
|
|
451
|
+
});
|
|
437
452
|
// Parse dos IDs separados por vírgula
|
|
438
|
-
var excludedIds =
|
|
453
|
+
var excludedIds = config.configValue
|
|
439
454
|
.split(',')
|
|
440
455
|
.map(function (id) { return parseInt(id.trim(), 10); })
|
|
441
456
|
.filter(function (id) { return !isNaN(id); });
|
|
442
457
|
if (excludedIds.length > 0) {
|
|
443
|
-
exclusionsMap.set(
|
|
458
|
+
exclusionsMap.set(config.feeId, new Set(excludedIds));
|
|
459
|
+
console.log('[buildFeeExclusionsMap] Exclusões adicionadas ao mapa', {
|
|
460
|
+
feeId: config.feeId,
|
|
461
|
+
excludedIds: Array.from(excludedIds)
|
|
462
|
+
});
|
|
444
463
|
}
|
|
445
464
|
}
|
|
446
465
|
});
|
|
466
|
+
console.log('[buildFeeExclusionsMap] Mapa de exclusões construído', {
|
|
467
|
+
totalExclusions: exclusionsMap.size,
|
|
468
|
+
exclusionsMap: Array.from(exclusionsMap.entries()).map(function (_a) {
|
|
469
|
+
var feeId = _a[0], excludedIds = _a[1];
|
|
470
|
+
return ({
|
|
471
|
+
feeId: feeId,
|
|
472
|
+
excludedIds: Array.from(excludedIds)
|
|
473
|
+
});
|
|
474
|
+
})
|
|
475
|
+
});
|
|
447
476
|
return exclusionsMap;
|
|
448
477
|
};
|
|
449
478
|
|
|
@@ -1088,6 +1117,14 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
|
|
|
1088
1117
|
}
|
|
1089
1118
|
// Calcular base: fees não-percentuais + outras fees percentuais (exceto ela mesma e excluídas)
|
|
1090
1119
|
var excludedFeeIds = (feeExclusions === null || feeExclusions === void 0 ? void 0 : feeExclusions.get(pf.fee.id)) || new Set();
|
|
1120
|
+
console.log('[calculateTotalPercentageFees] Calculando fee TOTAL_PERCENTAGE', {
|
|
1121
|
+
feeId: pf.fee.id,
|
|
1122
|
+
feeName: pf.fee.name,
|
|
1123
|
+
percentValue: pf.value,
|
|
1124
|
+
hasExclusions: excludedFeeIds.size > 0,
|
|
1125
|
+
excludedFeeIds: Array.from(excludedFeeIds),
|
|
1126
|
+
iteration: iteration
|
|
1127
|
+
});
|
|
1091
1128
|
var basePercentage = Array.from(previousValues.entries())
|
|
1092
1129
|
.filter(function (_a) {
|
|
1093
1130
|
var feeId = _a[0];
|
|
@@ -1100,6 +1137,23 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, curre
|
|
|
1100
1137
|
var baseValue = baseNonPercentage + basePercentage;
|
|
1101
1138
|
var percentValue = (+pf.value / 100);
|
|
1102
1139
|
var calculatedValue = baseValue * percentValue;
|
|
1140
|
+
console.log('[calculateTotalPercentageFees] Base calculada', {
|
|
1141
|
+
feeId: pf.fee.id,
|
|
1142
|
+
feeName: pf.fee.name,
|
|
1143
|
+
baseNonPercentage: baseNonPercentage,
|
|
1144
|
+
basePercentage: basePercentage,
|
|
1145
|
+
baseValue: baseValue,
|
|
1146
|
+
percentValue: "".concat(pf.value, "%"),
|
|
1147
|
+
calculatedValue: calculatedValue,
|
|
1148
|
+
allPreviousValues: Array.from(previousValues.entries()).map(function (_a) {
|
|
1149
|
+
var id = _a[0], val = _a[1];
|
|
1150
|
+
return ({
|
|
1151
|
+
feeId: id,
|
|
1152
|
+
value: val,
|
|
1153
|
+
excluded: excludedFeeIds.has(id)
|
|
1154
|
+
});
|
|
1155
|
+
})
|
|
1156
|
+
});
|
|
1103
1157
|
previousValues.set(pf.fee.id, calculatedValue);
|
|
1104
1158
|
// Armazenar resultado
|
|
1105
1159
|
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')) }));
|
|
@@ -1175,12 +1229,14 @@ var calculateIcms = function (totalFromAllFees, icmsRate) {
|
|
|
1175
1229
|
* Esta função centraliza a lógica de cálculo que estava duplicada em vários lugares do ModalCte.
|
|
1176
1230
|
*/
|
|
1177
1231
|
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;
|
|
1232
|
+
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;
|
|
1179
1233
|
var cache = {};
|
|
1180
1234
|
// Filtrar fees não excluídas
|
|
1181
1235
|
var nonExcludedFees = fees.filter(function (_, idx) { return !excludedIndexes.has(idx); });
|
|
1182
|
-
//
|
|
1183
|
-
var
|
|
1236
|
+
// Obter ratecard se não foi fornecido
|
|
1237
|
+
var ratecardToUse = ratecard || getRatecardFromCte(cte) || undefined;
|
|
1238
|
+
// Construir mapa de exclusões a partir das configurações do ratecard
|
|
1239
|
+
var feeExclusions = buildFeeExclusionsMap(ratecardToUse);
|
|
1184
1240
|
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1185
1241
|
fees.forEach(function (fee, idx) {
|
|
1186
1242
|
var _a, _b;
|
|
@@ -1265,14 +1321,17 @@ var calculateFeesTotalFromCache = function (options) {
|
|
|
1265
1321
|
* @param fees - Array de fees a calcular
|
|
1266
1322
|
* @param cte - CTE para cálculo
|
|
1267
1323
|
* @param allFeesForCalc - Todas as fees disponíveis para cálculo
|
|
1324
|
+
* @param ratecard - Tarifário (opcional, será extraído do CTE se não fornecido)
|
|
1268
1325
|
* @returns Total calculado
|
|
1269
1326
|
*/
|
|
1270
|
-
var calculateFeesTotal = function (fees, cte, allFeesForCalc) {
|
|
1327
|
+
var calculateFeesTotal = function (fees, cte, allFeesForCalc, ratecard) {
|
|
1271
1328
|
if (!fees || fees.length === 0)
|
|
1272
1329
|
return 0;
|
|
1273
1330
|
var cache = {};
|
|
1274
|
-
//
|
|
1275
|
-
var
|
|
1331
|
+
// Obter ratecard se não foi fornecido
|
|
1332
|
+
var ratecardToUse = ratecard || getRatecardFromCte(cte) || undefined;
|
|
1333
|
+
// Construir mapa de exclusões a partir das configurações do ratecard
|
|
1334
|
+
var feeExclusions = buildFeeExclusionsMap(ratecardToUse);
|
|
1276
1335
|
// PASSADA 1: Calcular fees normais (não TOTAL_PERCENTAGE, não ICMS)
|
|
1277
1336
|
fees.forEach(function (fee, idx) {
|
|
1278
1337
|
var _a, _b;
|
package/build/index.js.gz
CHANGED
|
Binary file
|