Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions DFe.Utils/ChaveFiscal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ private static string ObterDigitoVerificador(string chave)
//percorrendo cada caractere da chave da direita para esquerda para fazer os cálculos com o peso
for (var i = chave.Length - 1; i != -1; i--)
{
var ch = Convert.ToInt32(chave[i].ToString());
soma += ch*peso;
var valorCaractere = ObterValorDoCaractere(chave[i]);
soma += valorCaractere * peso;
//sempre que for 9 voltamos o peso a 2
if (peso < 9)
peso += 1;
Expand All @@ -115,6 +115,18 @@ private static string ObterDigitoVerificador(string chave)
return dv.ToString();
}

/// <summary>
/// Obtem o valor de um caractere
/// </summary>
/// <param name="caractere"></param>
/// <returns></returns>
private static int ObterValorDoCaractere(char caractere)
{
const int zeroASCII = 48;
var valor = caractere - zeroASCII;
return valor;
}

/// <summary>
/// Informa se a chave de um DF-e é válida
/// </summary>
Expand Down