Skip to content

Commit

Permalink
Merge pull request #44 from neicecilio/feature/conciliacao-financeira
Browse files Browse the repository at this point in the history
feat:Evento de Conciliação Financeira para NFe (NT 2024.002)
  • Loading branch information
danilobreda authored Oct 2, 2024
2 parents 9376e70 + 05b5621 commit 53b9945
Show file tree
Hide file tree
Showing 24 changed files with 1,319 additions and 11 deletions.
8 changes: 6 additions & 2 deletions NFe.AppTeste/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@
</TabControl>
</StackPanel>
</GroupBox>
<TabControl Name="TabSuperior" Height="291" Margin="510,10,-0,0" VerticalAlignment="Top">
<TabControl Name="TabSuperior" Height="316" Margin="510,10,-0,0" VerticalAlignment="Top">
<TabItem Header="NF-e/NFC-e">
<Grid Background="White">
<Button x:Name="BtnStatusServico" Content="Status do Serviço" HorizontalAlignment="Left"
Expand Down Expand Up @@ -970,11 +970,15 @@
Margin="10,235,0,0" VerticalAlignment="Top" Width="177" Click="BtnComprovanteEntrega_Click" />
<Button x:Name="BtnCancComprovanteEntrega" Content="Canc. Comprovante Entrega NFe" HorizontalAlignment="Left"
Margin="192,235,0,0" VerticalAlignment="Top" Width="177" Click="BtnCancComprovanteEntrega_Click" />
<Button x:Name="BtnConciliacaoFinanceira" Content="Conciliação Financeira NFe" HorizontalAlignment="Left"
Margin="10,260,0,0" VerticalAlignment="Top" Width="177" Click="BtnConciliacaoFinanceira_Click" />
<Button x:Name="BtnCancConciliacaoFinanceira" Content="Canc. Conciliação Financeira NFe" HorizontalAlignment="Left"
Margin="192,260,0,0" VerticalAlignment="Top" Width="177" Click="BtnCancConciliacaoFinanceira_Click" />
</Grid>
</TabItem>

</TabControl>
<TabControl Name="TabInferior" Margin="509,306,0,0">
<TabControl Name="TabInferior" Margin="509,331,0,0">
<TabItem Header="Envio">
<Grid Background="#FFE5E5E5">
<Grid.ColumnDefinitions>
Expand Down
120 changes: 120 additions & 0 deletions NFe.AppTeste/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,126 @@ private void BtnCancComprovanteEntrega_Click(object sender, RoutedEventArgs e)
}
}

private void BtnConciliacaoFinanceira_Click(object sender, RoutedEventArgs e)
{
const string titulo = "Conciliação Financeira NFe";

try
{
#region Conciliação Financeira 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 meioPagamento = Funcoes.InpuBox(this, titulo, "Meio de Pagamento:", "17");
if (string.IsNullOrEmpty(meioPagamento)) throw new Exception("Código do Meio de pagamento deve ser informado!");

var dhPagamentoStr = Funcoes.InpuBox(this, titulo, "Data de Pagamento:", DateTime.Now.ToString("dd/MM/yyyy"));
if (string.IsNullOrEmpty(dhPagamentoStr)) throw new Exception("A data de pagamento deve ser informada!");

if (!DateTime.TryParse(dhPagamentoStr, out DateTime dhPagamento))
throw new Exception("Data inválida!");

decimal? valorPagamento = null;
var valorPagamentoStr = Funcoes.InpuBox(this, titulo, "Valor do Pagamento:", "1");
if (string.IsNullOrEmpty(valorPagamentoStr)) throw new Exception("Valor do pagamento deve ser informado!");
if (!string.IsNullOrEmpty(valorPagamentoStr)) valorPagamento = Convert.ToDecimal(valorPagamentoStr);


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

var _pagamento = new Classes.Servicos.Evento.detPagEvento()
{
tPag = (FormaPagamento)Convert.ToInt32(meioPagamento),
dPag = dhPagamento,
vPag = valorPagamento.GetValueOrDefault()
};
var retornoConciliacao = servicoNFe.RecepcaoEventoConciliacaoFinanceira(Convert.ToInt32(idlote),
Convert.ToInt16(sequenciaEvento), cpfcnpj, chave, new List<Classes.Servicos.Evento.detPagEvento>() { _pagamento }, DFe.Classes.Entidades.Estado.SP);

TrataRetorno(retornoConciliacao);

#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 BtnCancConciliacaoFinanceira_Click(object sender, RoutedEventArgs e)
{
const string titulo = "Cancelar Conciliação Financeira NFe";

try
{
#region Cancelar Conciliação Financeira 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 retornoConciliacao = servicoNFe.RecepcaoEventoCancConciliacaoFinanceira(Convert.ToInt32(idlote),
Convert.ToInt16(sequenciaEvento), cpfcnpj, chave, nProtEvento);

TrataRetorno(retornoConciliacao);

#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
48 changes: 44 additions & 4 deletions NFe.AppTeste/NFe.AppTeste.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<NuGetPackageImportStamp>e0fff804</NuGetPackageImportStamp>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down Expand Up @@ -259,6 +263,12 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\e110750_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\e110751_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\e111500_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down Expand Up @@ -359,6 +369,9 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\envEventoCancEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\envEventoCancEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand All @@ -371,6 +384,9 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\envEventoEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\envEventoEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down Expand Up @@ -419,6 +435,9 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\EventoCancEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\eventoCancEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand All @@ -431,6 +450,9 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\EventoEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\eventoEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down Expand Up @@ -543,6 +565,9 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\leiauteEventoCancEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\leiauteEventoCancEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand All @@ -555,6 +580,9 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\leiauteEventoEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\leiauteEventoEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down Expand Up @@ -675,6 +703,9 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\procEventoCancEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\procEventoCancEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand All @@ -687,6 +718,9 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\procEventoEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\procEventoEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down Expand Up @@ -891,10 +925,16 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\retEventoCancEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\retEventoCancEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Schemas\retEventoEConf_v1.00.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Schemas\retEventoEntregaNFe_v1.00.xsd">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
9 changes: 9 additions & 0 deletions NFe.AppTeste/Schemas/EventoCancEConf_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="leiauteEventoCancEConf_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/EventoEConf_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="leiauteEventoEConf_v1.00.xsd"/>
<xs:element name="evento" type="TEvento">
<xs:annotation>
<xs:documentation>Schema XML de validação do evento de Conciliação Financeira</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
Loading

0 comments on commit 53b9945

Please sign in to comment.