b2m-utils 0.0.299 → 0.0.301
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/index.d.ts +1 -0
- package/build/functions/renderChargedValue/index.d.ts +20 -0
- package/build/index.esm.js +57 -1
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +57 -0
- package/build/index.js.gz +0 -0
- package/build/index.js.map +1 -1
- package/build/types/Ratecard/index.d.ts +2 -0
- package/build/types/RatecardConfig/index.d.ts +1 -1
- package/build/types/RatecardConfigValue/index.d.ts +2 -2
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -7975,6 +7975,62 @@ var normalizeString = function (str) {
|
|
|
7975
7975
|
return String(str).normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
7976
7976
|
};
|
|
7977
7977
|
|
|
7978
|
+
/**
|
|
7979
|
+
* Renderiza o valor cobrado por uma transportadora considerando configurações do ratecard
|
|
7980
|
+
*
|
|
7981
|
+
* @param value - Valor numérico a ser renderizado
|
|
7982
|
+
* @param cte - Objeto CTE contendo informações do ratecard e suas configurações
|
|
7983
|
+
* @param feeName - Nome da fee/tarifa (opcional, para lógicas específicas por tipo)
|
|
7984
|
+
* @returns String formatada em moeda ou com informações adicionais baseadas nas configs
|
|
7985
|
+
*
|
|
7986
|
+
* @example
|
|
7987
|
+
* ```ts
|
|
7988
|
+
* // Valor simples sem configurações especiais
|
|
7989
|
+
* renderChargedValue(150.50, cte) // "R$ 150,50"
|
|
7990
|
+
*
|
|
7991
|
+
* // Valor com rateio de ICMS habilitado
|
|
7992
|
+
* renderChargedValue(150.50, cteWithIcmsApportionment, 'ICMS') // "R$ 150,50 (rateado)"
|
|
7993
|
+
* ```
|
|
7994
|
+
*/
|
|
7995
|
+
var renderChargedValue = function (value, cte, feeName) {
|
|
7996
|
+
var numericValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
7997
|
+
if (isNaN(numericValue)) {
|
|
7998
|
+
return 'R$ 0,00';
|
|
7999
|
+
}
|
|
8000
|
+
// Converter para moeda
|
|
8001
|
+
var formattedValue = convertNumberToCurrency(numericValue, 'pt-br');
|
|
8002
|
+
// Se não houver CTE ou ratecard, retornar apenas o valor formatado
|
|
8003
|
+
if (!cte) {
|
|
8004
|
+
return formattedValue;
|
|
8005
|
+
}
|
|
8006
|
+
// Buscar ratecard (pode estar em Ratecard ou ratecard)
|
|
8007
|
+
var ratecard = getRatecardFromCte(cte);
|
|
8008
|
+
if (!ratecard || !ratecard.ratecard_config_values) {
|
|
8009
|
+
return formattedValue;
|
|
8010
|
+
}
|
|
8011
|
+
// Buscar configurações do ratecard
|
|
8012
|
+
var configs = ratecard.ratecard_config_values;
|
|
8013
|
+
// Verificar se o rateio de ICMS está habilitado
|
|
8014
|
+
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; });
|
|
8015
|
+
var isIcmsApportionmentEnabled = (icmsApportionmentConfig === null || icmsApportionmentConfig === void 0 ? void 0 : icmsApportionmentConfig.configValue) === 'true';
|
|
8016
|
+
// Se for ICMS e o rateio estiver habilitado, calcular e mostrar o rateio
|
|
8017
|
+
if (isIcmsApportionmentEnabled && (feeName === null || feeName === void 0 ? void 0 : feeName.toUpperCase().includes('ICMS'))) {
|
|
8018
|
+
// Obter a alíquota de ICMS do CTE (icmsIncidence já vem em decimal, ex: 0.12 para 12%)
|
|
8019
|
+
var icmsRate = cte.icmsIncidence ? Number(cte.icmsIncidence) : 0.12; // Default 12%
|
|
8020
|
+
// Calcular o ICMS baseado no valor cobrado
|
|
8021
|
+
// A função calculateIcms espera um array de valores e a alíquota
|
|
8022
|
+
var icmsResult = calculateIcms([numericValue], icmsRate);
|
|
8023
|
+
// Valor cobrado menos o ICMS calculado
|
|
8024
|
+
var valueAfterIcms = numericValue - icmsResult.total;
|
|
8025
|
+
var formattedValueAfterIcms = convertNumberToCurrency(valueAfterIcms, 'pt-br');
|
|
8026
|
+
var formattedIcms = convertNumberToCurrency(icmsResult.total, 'pt-br');
|
|
8027
|
+
return "".concat(formattedValue, " - ").concat(formattedIcms, " = ").concat(formattedValueAfterIcms, " (rateado)");
|
|
8028
|
+
}
|
|
8029
|
+
// Aqui você pode adicionar outras lógicas baseadas em outras configurações
|
|
8030
|
+
// Por exemplo, se houver configuração de arredondamento, aplicar aqui
|
|
8031
|
+
return formattedValue;
|
|
8032
|
+
};
|
|
8033
|
+
|
|
7978
8034
|
var verifyDefaultFees = function (laneFee, conditionalFee) {
|
|
7979
8035
|
var _a, _b;
|
|
7980
8036
|
var defaultConditionalFees = [
|
|
@@ -8242,6 +8298,7 @@ exports.isTariffMatch = isTariffMatch;
|
|
|
8242
8298
|
exports.matchAllTariffs = matchAllTariffs;
|
|
8243
8299
|
exports.normalizeString = normalizeString;
|
|
8244
8300
|
exports.parseAliases = parseAliases;
|
|
8301
|
+
exports.renderChargedValue = renderChargedValue;
|
|
8245
8302
|
exports.setFormattedDatesInObjects = setFormattedDatesInObjects;
|
|
8246
8303
|
exports.verifyConditionalFee = verifyConditionalFee;
|
|
8247
8304
|
exports.verifyDefaultFees = verifyDefaultFees;
|
package/build/index.js.gz
CHANGED
|
Binary file
|