Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion NFe.Danfe.App.Teste.Html/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ private void DanfeA4_Click(object sender, RoutedEventArgs e)
if (proc.NFe.infNFe.ide.mod != ModeloDocumento.NFe)
throw new Exception("O XML informado não é um NFe!");

var danfe = new DanfeNFe(proc.NFe, Status.Autorizada, "55512121121211", "Emissor Fiscal DSBR Brasil - www.dsbrbrasil.com.br");
var creditos = "Emissor Fiscal DSBR Brasil - www.dsbrbrasil.com.br";
//Com protocolo no XML, imprime número e data/hora de autorização; sem ele (pré-visualização), o campo fica vazio
var danfe = string.IsNullOrWhiteSpace(proc.protNFe?.infProt?.nProt)
? new DanfeNFe(proc.NFe, Status.Autorizada, (string) null, creditos)
: new DanfeNFe(proc.NFe, Status.Autorizada, proc.protNFe, creditos);
IDanfeHtml2 d1 = new DanfeNfeHtml2(danfe);
var doc = d1.ObterDocHtmlAsync().Result;

Expand Down
61 changes: 61 additions & 0 deletions NFe.Danfe.Html/CrossCutting/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,74 @@
using System;
using System.Reflection;
using System.Text.RegularExpressions;
using NFe.Classes.Informacoes.Detalhe.Tributacao.Compartilhado.InformacoesIbsCbs;
using NFe.Classes.Informacoes.Detalhe.Tributacao.Estadual.Tipos;
using NFe.Classes.Informacoes.Detalhe.Tributacao.Federal.Tipos;

namespace NFe.Danfe.Html.CrossCutting
{
internal static class Extensions
{
/// <summary>
/// Alíquota a ser impressa no DANFE para IBS UF, IBS Município e CBS (NT 2026.010).
/// Quando o grupo gRed é informado (redução de alíquota ou compra governamental) imprime a alíquota efetiva
/// (pAliqEfet), senão a alíquota vigente.
/// </summary>
/// <param name="aliquota">Alíquota vigente (pIBSUF, pIBSMun ou pCBS)</param>
/// <param name="gRed">Grupo de redução de alíquota</param>
public static decimal ObterAliquotaEfetiva(this decimal aliquota, gRed gRed)
{
return gRed != null ? gRed.pAliqEfet : aliquota;
}

/// <summary>
/// Descrição do código de regime tributário no formato "3 - REGIME NORMAL"
/// </summary>
public static string CrtDescricao(this NFe.Classes.Informacoes.Emitente.CRT crt)
{
string descricao;
switch (crt)
{
case NFe.Classes.Informacoes.Emitente.CRT.SimplesNacional:
descricao = "SIMPLES NACIONAL";
break;
case NFe.Classes.Informacoes.Emitente.CRT.SimplesNacionalExcessoSublimite:
descricao = "SIMPLES NACIONAL - EXCESSO DE SUBLIMITE";
break;
case NFe.Classes.Informacoes.Emitente.CRT.RegimeNormal:
descricao = "REGIME NORMAL";
break;
case NFe.Classes.Informacoes.Emitente.CRT.SimplesNacionalMei:
descricao = "SIMPLES NACIONAL - MEI";
break;
default:
return string.Empty;
}

return $"{(int) crt} - {descricao}";
}

/// <summary>
/// Indica se o grupo do ICMS do item traz valores (base de cálculo, alíquota ou valor do ICMS)
/// </summary>
public static bool PossuiValoresIcms(this ICMSBasico icms)
{
return TemValor(icms, "vBC") || TemValor(icms, "pICMS") || TemValor(icms, "vICMS");
}

private static bool TemValor(object instance, string propName)
{
try
{
var property = instance.GetType().GetProperty(propName, BindingFlags.Public | BindingFlags.Instance);
return property != null && property.GetValue(instance, null) != null;
}
catch (Exception)
{
return false;
}
}

public static string orig(this ICMSBasico icms)
{
return GetOrigIcms(icms, "orig");
Expand Down
7 changes: 2 additions & 5 deletions NFe.Danfe.Html/CrossCutting/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
TimeZoneInfo horaBrasilia = TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time");
return TimeZoneInfo.ConvertTimeFromUtc(data, horaBrasilia);
}
catch (Exception ex)

Check warning on line 41 in NFe.Danfe.Html/CrossCutting/Utils.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The variable 'ex' is declared but never used
{
return DateTime.Now;

Expand Down Expand Up @@ -267,16 +267,13 @@
}

/// <summary>
/// Formatar numero para exibição da DANFE
/// Formatar quantidade para exibição da DANFE (2 casas, com o zero inteiro: 0,00)
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string FormatarNumeroQuantidadeDanfe(this decimal value)
{
var str = FormatarNumero(value);
str = str.Replace(".", ",");
double.TryParse(str, out var result);
return result.ToString("#.000").Trim();
return FormatarNumeroDanfe(value);
}

}
Expand Down
Loading
Loading