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