Skip to content

Commit

Permalink
Merge branch 'feature/NT2023.005' of https://github.com/lucasmoraes80…
Browse files Browse the repository at this point in the history
…4/DFe.NET into lucasmoraes804-feature/NT2023.005

# Conflicts:
#	Zeus NFe.sln.DotSettings.user
  • Loading branch information
danilobreda committed Apr 20, 2024
2 parents baa60d1 + 62d31d6 commit 1440001
Show file tree
Hide file tree
Showing 26 changed files with 1,323 additions and 21 deletions.
4 changes: 4 additions & 0 deletions NFe.AppTeste/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,10 @@
Margin="375,185,0,0" VerticalAlignment="Top" Width="177" Click="BtnConsultaRecibo_Click" />
<Button x:Name="BtnConsultaGtin" Content="Consultar Gtin" HorizontalAlignment="Left"
Margin="10,210,0,0" VerticalAlignment="Top" Width="177" Click="BtnConsultaGtin_Click" />
<Button x:Name="BtnInsucessoEntrega" Content="Insucesso Entrega NFe" HorizontalAlignment="Left"
Margin="192,210,0,0" VerticalAlignment="Top" Width="177" Click="BtnInsucessoEntrega_Click" />
<Button x:Name="BtnCancInsucessoEntrega" Content="Canc. Insucesso Entrega NFe" HorizontalAlignment="Left"
Margin="375,210,0,0" VerticalAlignment="Top" Width="177" Click="BtnCancInsucessoEntrega_Click" />
</Grid>
</TabItem>

Expand Down
146 changes: 146 additions & 0 deletions NFe.AppTeste/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
using NFe.Utils.Excecoes;
using NFe.Utils.Tributacao.Federal;
using Image = System.Drawing.Image;
using static System.Net.Mime.MediaTypeNames;
using System.Text;
using System.Security.Cryptography;

namespace NFe.AppTeste
{
Expand Down Expand Up @@ -289,6 +292,149 @@ private void BtnConsultaGtin_Click(object sender, RoutedEventArgs e)
}
}

private void BtnInsucessoEntrega_Click(object sender, RoutedEventArgs e)
{
const string titulo = "Insucesso Entrega NFe";

try
{
#region Insucesso Entrega NFe

var idlote = Funcoes.InpuBox(this, titulo, "Identificador de controle do Lote de envio:", "1");
if (string.IsNullOrEmpty(idlote)) throw new Exception("A Id do Lote deve ser informada!");

var sequenciaEvento = Funcoes.InpuBox(this, titulo, "Número sequencial do evento:", "1");
if (string.IsNullOrEmpty(sequenciaEvento))
throw new Exception("O número sequencial deve ser informado!");

var chave = Funcoes.InpuBox(this, titulo, "Chave da NFe:", "35240311656919000154550750000008281647961399");
if (string.IsNullOrEmpty(chave)) throw new Exception("A Chave deve ser informada!");
if (chave.Length != 44) throw new Exception("Chave deve conter 44 caracteres!");

var dhTentativaEntregaStr = Funcoes.InpuBox(this, titulo, "Data da tentativa da entrega da NFe", DateTimeOffset.Now.ToString("dd/MM/yyyy"));
if (string.IsNullOrEmpty(dhTentativaEntregaStr)) throw new Exception("A Data deve ser informada!");

if (!DateTimeOffset.TryParse(dhTentativaEntregaStr, out DateTimeOffset dhTentativaEntrega))
throw new Exception("Data inválida!");

var motivoInsucessoStr = Funcoes.InpuBox(this, titulo, "Motivo do Insucesso da entrega da NFe", "1");
if (!Enum.TryParse(motivoInsucessoStr, out NFe.Classes.Servicos.Evento.MotivoInsucesso motivoInsucesso)) throw new Exception("Motivo deve ser informada!");

string justificativa = null;

if (motivoInsucesso == Classes.Servicos.Evento.MotivoInsucesso.Outros)
justificativa = Funcoes.InpuBox(this, titulo, "Motivo");

var imagemExemploBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAADUlEQVR42gECAP3/AP8BAQEATamDVwAAAABJRU5ErkJggg==";
var concatenacao = chave + imagemExemploBase64;

var hashTentativaEntrega = string.Empty;
using (SHA1 sha1 = SHA1.Create())
{
byte[] inputBytes = Encoding.UTF8.GetBytes(concatenacao);
byte[] hashBytes = sha1.ComputeHash(inputBytes);
// O hash SHA-1 terá 20 bytes
hashTentativaEntrega = Convert.ToBase64String(hashBytes).Trim();
}

int? nTentativa = null;
var nTentativaStr = Funcoes.InpuBox(this, titulo, "Número tentativas de entrega:", "1");
if (!string.IsNullOrEmpty(nTentativaStr)) nTentativa = Convert.ToInt32(nTentativaStr);

DateTimeOffset? dhHashTentativaEntrega = null;
var dhHashTentativaEntregaStr = Funcoes.InpuBox(this, titulo, "Data geração do Hash Tentativa na Entrega:", DateTimeOffset.Now.ToString("dd/MM/yyyy"));
if (!string.IsNullOrEmpty(dhHashTentativaEntregaStr)) dhHashTentativaEntrega = Convert.ToDateTime(dhHashTentativaEntregaStr);

decimal? latGps = null;
var latGpsStr = Funcoes.InpuBox(this, titulo, "Latitude GPS:");
if (!string.IsNullOrEmpty(latGpsStr)) latGps = Convert.ToDecimal(latGpsStr);

decimal? longGps = null;
var longGpsStr = Funcoes.InpuBox(this, titulo, "Latitude GPS:");
if (!string.IsNullOrEmpty(longGpsStr)) longGps = Convert.ToDecimal(longGpsStr);


var servicoNFe = new ServicosNFe(_configuracoes.CfgServico);
var cpfcnpj = string.IsNullOrEmpty(_configuracoes.Emitente.CNPJ)
? _configuracoes.Emitente.CPF
: _configuracoes.Emitente.CNPJ;

var retornoInsucesso = servicoNFe.RecepcaoEventoInsucessoEntrega(Convert.ToInt32(idlote),
Convert.ToInt16(sequenciaEvento), cpfcnpj, chave, dhTentativaEntrega, motivoInsucesso, hashTentativaEntrega, nTentativa,
dhHashTentativaEntrega, latGps, longGps, justificativa);

TrataRetorno(retornoInsucesso);

#endregion
}
catch (ComunicacaoException ex)
{
Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
}
catch (ValidacaoSchemaException ex)
{
Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
}
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.Message))
Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
}
}

private void BtnCancInsucessoEntrega_Click(object sender, RoutedEventArgs e)
{
const string titulo = "Cancelar Insucesso Entrega NFe";

try
{
#region Cancelar Insucesso Entrega NFe

var idlote = Funcoes.InpuBox(this, titulo, "Identificador de controle do Lote de envio:", "1");
if (string.IsNullOrEmpty(idlote)) throw new Exception("A Id do Lote deve ser informada!");

var sequenciaEvento = Funcoes.InpuBox(this, titulo, "Número sequencial do evento:", "1");
if (string.IsNullOrEmpty(sequenciaEvento))
throw new Exception("O número sequencial deve ser informado!");

var chave = Funcoes.InpuBox(this, titulo, "Chave da NFe:", "35240311656919000154550750000008281647961399");
if (string.IsNullOrEmpty(chave)) throw new Exception("A Chave deve ser informada!");
if (chave.Length != 44) throw new Exception("Chave deve conter 44 caracteres!");

var nProtEvento = Funcoes.InpuBox(this, titulo, "Nº Prot Evento:");

if (string.IsNullOrEmpty(nProtEvento))
throw new Exception("O nº Prot Evento deve ser informado!");



var servicoNFe = new ServicosNFe(_configuracoes.CfgServico);
var cpfcnpj = string.IsNullOrEmpty(_configuracoes.Emitente.CNPJ)
? _configuracoes.Emitente.CPF
: _configuracoes.Emitente.CNPJ;

var retornoInsucesso = servicoNFe.RecepcaoEventoCancInsucessoEntrega(Convert.ToInt32(idlote),
Convert.ToInt16(sequenciaEvento), cpfcnpj, chave, nProtEvento);

TrataRetorno(retornoInsucesso);

#endregion
}
catch (ComunicacaoException ex)
{
Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
}
catch (ValidacaoSchemaException ex)
{
Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
}
catch (Exception ex)
{
if (!string.IsNullOrEmpty(ex.Message))
Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
}
}

private void BtnConsultaXml_Click(object sender, RoutedEventArgs e)
{
try
Expand Down
14 changes: 14 additions & 0 deletions NFe.AppTeste/NFe.AppTeste.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,20 @@
<Name>NFe.Utils</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Schemas\e110192_v1.00.xsd" />
<Content Include="Schemas\e110193_v1.00.xsd" />
<Content Include="Schemas\envEventoCancInsucessoNFe_v1.00.xsd" />
<Content Include="Schemas\envEventoInsucessoNFe_v1.00.xsd" />
<Content Include="Schemas\EventoCancInsucessoNFe_v1.00.xsd" />
<Content Include="Schemas\EventoInsucessoNFe_v1.00.xsd" />
<Content Include="Schemas\leiauteEventoCancInsucessoNFe_v1.00.xsd" />
<Content Include="Schemas\leiauteEventoInsucessoNFe_v1.00.xsd" />
<Content Include="Schemas\procEventoCancInsucessoNFe_v1.00.xsd" />
<Content Include="Schemas\procEventoInsucessoNFe_v1.00.xsd" />
<Content Include="Schemas\retEventoCancInsucessoNFe_v1.00.xsd" />
<Content Include="Schemas\retEventoInsucessoNFe_v1.00.xsd" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
9 changes: 9 additions & 0 deletions NFe.AppTeste/Schemas/EventoCancInsucessoNFe_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteEventoCancInsucessoNFe_v1.00.xsd"/>
<xs:element name="evento" type="TEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do evento de Cancelamento do Comprovante de Entrega da NFe</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
9 changes: 9 additions & 0 deletions NFe.AppTeste/Schemas/EventoInsucessoNFe_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteEventoInsucessoNFe_v1.00.xsd"/>
<xs:element name="evento" type="TEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do evento de Insucesso na entrega da NF-e</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
107 changes: 107 additions & 0 deletions NFe.AppTeste/Schemas/e110192_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 (http://www.altova.com) by [email protected] (PROCERGS) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="tiposBasico_v1.03.xsd"/>
<xs:element name="detEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do evento de Comprovante de Entrega da NF-e</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="descEvento">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Insucesso na Entrega da NF-e"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="cOrgaoAutor" type="TCOrgaoIBGE"/>
<xs:element name="verAplic" type="TVerAplic">
<xs:annotation>
<xs:documentation>Versão do Aplicativo do Autor do Evento</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="dhTentativaEntrega" type="TDateTimeUTC">
<xs:annotation>
<xs:documentation>Data e hora do final da tentativa entrega. Formato AAAA-MMDDThh:mm:ssTZD
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="nTentativa" minOccurs="0">
<xs:simpleType>
<xs:annotation>
<xs:documentation>Número da tentativa de entrega que não teve sucesso</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{1,3}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="tpMotivo">
<xs:simpleType>
<xs:annotation>
<xs:documentation>Motivo do insucesso - 1 – Recebedor não encontrado
2 – Recusa do recebedor
3 – Endereço inexistente
4 – Outros (exige informar justificativa) </xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
<xs:enumeration value="3"/>
<xs:enumeration value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="xJustMotivo" minOccurs="0">
<xs:annotation>
<xs:documentation>Justificativa do motivo do insucesso. Informar apenas para tpMotivo=4 </xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="TString">
<xs:maxLength value="250"/>
<xs:minLength value="25"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="latGPS" type="TLatitude" minOccurs="0">
<xs:annotation>
<xs:documentation>Latitude do ponto de entrega</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="longGPS" type="TLongitude" minOccurs="0">
<xs:annotation>
<xs:documentation>Longitude do ponto de entrega</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="hashTentativaEntrega">
<xs:annotation>
<xs:documentation>Hash (SHA1) no formato Base64 resultante da concatenação: Chave de acesso da NFe + Base64 da imagem capturada da entrega (Exemplo: imagem capturada da assinatura eletrônica, digital do recebedor, foto, etc)</xs:documentation>
<xs:documentation>O hashCSRT é o resultado das funções SHA-1 e base64 do token CSRT fornecido pelo fisco + chave de acesso do DF-e. (Implementação em futura NT)
Observação: 28 caracteres são representados no schema como 20 bytes do tipo base64Binary</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:base64Binary">
<xs:length value="28"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="dhHashTentativaEntrega" type="TDateTimeUTC" minOccurs="0">
<xs:annotation>
<xs:documentation>Data e hora da geração do hash da tentativa de entrega. Formato AAAA-MMDDThh:mm:ssTZD.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="versao" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:enumeration value="1.00"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
40 changes: 40 additions & 0 deletions NFe.AppTeste/Schemas/e110193_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 (http://www.altova.com) by [email protected] (PROCERGS) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="tiposBasico_v1.03.xsd"/>
<xs:element name="detEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do evento de Cancelamento do Comprovante de Entrega da NF-e</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="descEvento">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Cancelamento Insucesso na Entrega da NF-e"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="cOrgaoAutor" type="TCOrgaoIBGE"/>
<xs:element name="verAplic" type="TVerAplic">
<xs:annotation>
<xs:documentation>Versão do Aplicativo do Autor do Evento</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="nProtEvento" type="TProt">
<xs:annotation>
<xs:documentation>Número do Protocolo de Autorização do Evento da NF-e a que se refere este cancelamento.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="versao" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:enumeration value="1.00"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
10 changes: 10 additions & 0 deletions NFe.AppTeste/Schemas/envEventoCancInsucessoNFe_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 (http://www.altova.com) by [email protected] (PROCERGS) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteEventoCancInsucessoNFe_v1.00.xsd"/>
<xs:element name="envEvento" type="TEnvEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do lote de envio do evento de Cancelamento de Insucesso na Entrega da NF-e</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
10 changes: 10 additions & 0 deletions NFe.AppTeste/Schemas/envEventoInsucessoNFe_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 (http://www.altova.com) by [email protected] (PROCERGS) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteEventoInsucessoNFe_v1.00.xsd"/>
<xs:element name="envEvento" type="TEnvEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do lote de envio do evento de Insucesso na Entrega da NF-e</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
Loading

0 comments on commit 1440001

Please sign in to comment.