b2m-utils 0.0.304 → 0.0.306

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/index.js CHANGED
@@ -1013,12 +1013,25 @@ var calculateTotalPercentageFees = function (allFees, cte, allFeesForCalc, preCa
1013
1013
  // Calcular fees percentuais iterativamente até convergir
1014
1014
  var maxIterations = 10;
1015
1015
  var tolerance = 0.01; // Tolerância de 1 centavo
1016
- // Inicializar com valores zerados
1016
+ // Inicializar com valores zerados ou pré-calculados
1017
1017
  var previousValues = new Map();
1018
- percentageFees.forEach(function (pf) { return previousValues.set(pf.fee.id, 0); });
1018
+ percentageFees.forEach(function (pf) {
1019
+ // Se existe valor pré-calculado (editado manualmente), usar ele
1020
+ var preCalcValue = preCalculatedValues === null || preCalculatedValues === void 0 ? void 0 : preCalculatedValues.get(pf.fee.id);
1021
+ previousValues.set(pf.fee.id, preCalcValue !== undefined ? preCalcValue : 0);
1022
+ });
1019
1023
  var _loop_1 = function (iteration) {
1020
1024
  // Calcular cada fee percentual com base nos valores atuais das outras
1021
1025
  percentageFees.forEach(function (pf) {
1026
+ // Se esta fee tem valor pré-calculado (foi editada manualmente), não recalcular
1027
+ var preCalcValue = preCalculatedValues === null || preCalculatedValues === void 0 ? void 0 : preCalculatedValues.get(pf.fee.id);
1028
+ if (preCalcValue !== undefined) {
1029
+ // Manter o valor editado manualmente
1030
+ previousValues.set(pf.fee.id, preCalcValue);
1031
+ // Armazenar resultado com valor editado
1032
+ results.set(pf.fee.id, __assign(__assign({}, pf), { totalFee: preCalcValue, totalToCalc: preCalcValue, resultFee: "".concat(convertNumberToCurrency(preCalcValue, 'pt-br'), " (editado manualmente)") }));
1033
+ return;
1034
+ }
1022
1035
  // Calcular base: fees não-percentuais + outras fees percentuais (exceto ela mesma)
1023
1036
  var basePercentage = Array.from(previousValues.entries())
1024
1037
  .filter(function (_a) {
@@ -7976,9 +7989,7 @@ var normalizeString = function (str) {
7976
7989
  * ```
7977
7990
  */
7978
7991
  var renderChargedValue = function (value, cte, feeName) {
7979
- var _a;
7980
7992
  var numericValue = typeof value === 'string' ? parseFloat(value) : value;
7981
- console.log('🔍 renderChargedValue - feeName:', feeName, 'value:', numericValue);
7982
7993
  if (isNaN(numericValue)) {
7983
7994
  return 'R$ 0,00';
7984
7995
  }
@@ -7986,46 +7997,29 @@ var renderChargedValue = function (value, cte, feeName) {
7986
7997
  var formattedValue = convertNumberToCurrency(numericValue, 'pt-br');
7987
7998
  // Se não houver CTE ou ratecard, retornar apenas o valor formatado
7988
7999
  if (!cte) {
7989
- console.log('⚠️ CTE não fornecido');
7990
8000
  return formattedValue;
7991
8001
  }
7992
8002
  // Buscar ratecard (pode estar em Ratecard ou ratecard)
7993
8003
  var ratecard = getRatecardFromCte(cte);
7994
- console.log('🔍 Ratecard encontrado:', ratecard ? 'SIM' : 'NÃO');
7995
8004
  if (!ratecard || !ratecard.ratecard_config_values) {
7996
- console.log('⚠️ Ratecard ou ratecard_config_values não encontrado');
7997
- console.log(' - ratecard:', !!ratecard);
7998
- console.log(' - ratecard_config_values:', ratecard === null || ratecard === void 0 ? void 0 : ratecard.ratecard_config_values);
7999
8005
  return formattedValue;
8000
8006
  }
8001
8007
  // Buscar configurações do ratecard
8002
8008
  var configs = ratecard.ratecard_config_values;
8003
- console.log('✅ Configurações encontradas:', configs.length);
8004
8009
  // Verificar se o rateio de ICMS está habilitado
8005
8010
  var icmsApportionmentConfig = configs.find(function (config) { var _a; return ((_a = config.ratecard_configs) === null || _a === void 0 ? void 0 : _a.configKey) === exports.RatecardConfigKeyEnum.ICMS_APPORTIONMENT_ENABLED; });
8006
- console.log('🔍 Config ICMS encontrada:', icmsApportionmentConfig);
8007
- console.log(' - configKey:', (_a = icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.ratecard_configs) === null || _a === void 0 ? void 0 : _a.configKey);
8008
- console.log(' - configValue:', icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.configValue);
8009
8011
  var isIcmsApportionmentEnabled = (icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.configValue) === 'true';
8010
- console.log('🔍 ICMS rateio habilitado:', isIcmsApportionmentEnabled);
8011
- console.log('🔍 feeName contém ICMS:', feeName === null || feeName === void 0 ? void 0 : feeName.toUpperCase().includes('ICMS'));
8012
8012
  // Se for ICMS e o rateio estiver habilitado, calcular e mostrar o rateio
8013
8013
  if (isIcmsApportionmentEnabled) {
8014
- console.log('✅ Aplicando rateio de ICMS');
8015
8014
  // Obter a alíquota de ICMS do CTE (icmsIncidence vem como número, ex: 7 para 7%)
8016
8015
  var icmsIncidence = cte.icmsIncidence ? Number(cte.icmsIncidence) : 12; // Default 12%
8017
- console.log(' - icmsIncidence:', icmsIncidence);
8018
8016
  // Calcular: valor * (100 - icmsIncidence) / 100
8019
8017
  // Exemplo: 5,42 * (100 - 7) / 100 = 5,42 * 0,93 = 5,04
8020
8018
  var multiplier = (100 - icmsIncidence) / 100;
8021
8019
  var valueAfterIcms = numericValue * multiplier;
8022
- console.log(' - multiplier:', multiplier);
8023
- console.log(' - valueAfterIcms:', valueAfterIcms);
8024
8020
  var formattedValueAfterIcms = convertNumberToCurrency(valueAfterIcms, 'pt-br');
8025
8021
  var percentageToShow = (100 - icmsIncidence);
8026
- var result = "".concat(formattedValue, " x ").concat(percentageToShow, "% = ").concat(formattedValueAfterIcms);
8027
- console.log(' - resultado:', result);
8028
- return result;
8022
+ return "".concat(formattedValue, " x ").concat(percentageToShow, "% = ").concat(formattedValueAfterIcms);
8029
8023
  }
8030
8024
  // Aqui você pode adicionar outras lógicas baseadas em outras configurações
8031
8025
  // Por exemplo, se houver configuração de arredondamento, aplicar aqui
package/build/index.js.gz CHANGED
Binary file