Skip to content

Commit bdcac10

Browse files
authored
Merge pull request #1657 from guidi/fix/danfe-quest-pdf-contingencia
Fix/danfe quest pdf contingencia
2 parents 3ad4ee1 + f67f0ad commit bdcac10

2 files changed

Lines changed: 48 additions & 8 deletions

File tree

NFe.Danfe.AppTeste.QuestPdf/MainWindow.xaml.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
/********************************************************************************/
3333

3434
using Microsoft.Win32;
35-
using NFe.Classes;
3635
using NFe.Danfe.QuestPdf.ImpressaoNfce;
3736
using QuestPDF.Fluent;
3837
using QuestPDF.Infrastructure;
@@ -156,8 +155,7 @@ private static byte[] ConverterParaPngBytes(BitmapImage bitmap)
156155

157156
private void GerarDanfeNfce(string caminhoXml, TamanhoImpressao tamanho)
158157
{
159-
var proc = new nfeProc().CarregarDeArquivoXml(caminhoXml);
160-
var xml = proc.ObterXmlString();
158+
var xml = File.ReadAllText(caminhoXml);
161159

162160
var documento = new DanfeNfceDocument(xml, _logoMarcaBytes);
163161
documento.TamanhoImpressao(tamanho);

NFe.Danfe.QuestPdf/ImpressaoNfce/DanfeNfceDocument.cs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using DFe.Utils;
33
using NFe.Classes;
44
using NFe.Classes.Informacoes.Destinatario;
5+
using NFe.Classes.Informacoes.Identificacao.Tipos;
56
using NFe.Classes.Informacoes.Pagamento;
67
using NFe.Utils;
78
using NFe.Utils.InformacoesSuplementares;
@@ -350,6 +351,27 @@ private void Rodape(IContainer container)
350351

351352
column.Item().LineHorizontal(1);
352353

354+
if (DeveExibirMensagemContingencia())
355+
{
356+
column.Item().Row(r =>
357+
{
358+
r.RelativeItem().AlignCenter().Column(c =>
359+
{
360+
c.Item().AlignCenter().Text("EMITIDA EM CONTINGÊNCIA").FontSize(_tamanhoFontePadrao).ExtraBlack();
361+
});
362+
});
363+
364+
column.Item().Row(r =>
365+
{
366+
r.RelativeItem().AlignCenter().Column(c =>
367+
{
368+
c.Item().AlignCenter().Text("Pendente de autorização").FontSize(_tamanhoFontePadrao).ExtraBlack();
369+
});
370+
});
371+
372+
column.Item().LineHorizontal(1);
373+
}
374+
353375
column.Item().Row(r =>
354376
{
355377
r.RelativeItem().AlignCenter().Column(c =>
@@ -373,11 +395,18 @@ private void Rodape(IContainer container)
373395
t.Cell().AlignCenter().Image(ImagemQrCode());
374396
t.Cell().AlignLeft().Column(c =>
375397
{
376-
c.Item().Text($"Série: {_nfe.infNFe.ide.serie:D3}").FontSize(_tamanhoFontePadrao);
377-
c.Item().Text($"Número: {_nfe.infNFe.ide.nNF:D9}").FontSize(_tamanhoFontePadrao);
378-
c.Item().Text($"Emissão: {_nfeProc.NFe.infNFe.ide.dhEmi:G}").FontSize(_tamanhoFontePadrao);
379-
c.Item().Text($"Protocolo: {_nfeProc.protNFe.infProt.nProt}").FontSize(_tamanhoFontePadrao);
380-
c.Item().Text($"Autorização: {_nfeProc.protNFe.infProt.dhRecbto:G}").FontSize(_tamanhoFontePadrao);
398+
if (_nfe?.infNFe?.ide != null)
399+
{
400+
c.Item().Text($"Série: {_nfe.infNFe.ide.serie:D3}").FontSize(_tamanhoFontePadrao);
401+
c.Item().Text($"Número: {_nfe.infNFe.ide.nNF:D9}").FontSize(_tamanhoFontePadrao);
402+
c.Item().Text($"Emissão: {_nfe.infNFe.ide.dhEmi:G}").FontSize(_tamanhoFontePadrao);
403+
}
404+
405+
if (DeveExibirDadosProtocolo())
406+
{
407+
c.Item().Text($"Protocolo: {_nfeProc!.protNFe!.infProt.nProt}").FontSize(_tamanhoFontePadrao);
408+
c.Item().Text($"Autorização: {_nfeProc!.protNFe!.infProt.dhRecbto:G}").FontSize(_tamanhoFontePadrao);
409+
}
381410
});
382411
});
383412
});
@@ -532,6 +561,8 @@ private void CarregarXml(string xml)
532561
{
533562
try
534563
{
564+
_nfeProc = null;
565+
_nfe = null;
535566
_nfeProc = FuncoesXml.XmlStringParaClasse<nfeProc>(xml);
536567
_nfe = _nfeProc.NFe;
537568
}
@@ -541,6 +572,7 @@ private void CarregarXml(string xml)
541572
{
542573
NFe.Classes.NFe nfe = FuncoesXml.XmlStringParaClasse<NFe.Classes.NFe>(xml);
543574
_nfe = nfe;
575+
_nfeProc = null;
544576
}
545577
catch (Exception)
546578
{
@@ -550,6 +582,16 @@ private void CarregarXml(string xml)
550582
}
551583
}
552584

585+
private bool DeveExibirMensagemContingencia()
586+
{
587+
return _nfe?.infNFe?.ide?.tpEmis == TipoEmissao.teOffLine && _nfeProc == null;
588+
}
589+
590+
private bool DeveExibirDadosProtocolo()
591+
{
592+
return _nfeProc?.protNFe?.infProt != null && !DeveExibirMensagemContingencia();
593+
}
594+
553595
private string ObtemDescricao(FormaPagamento? formaPagamento)
554596
{
555597
var existeEnum = Enum

0 commit comments

Comments
 (0)