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
1 change: 0 additions & 1 deletion BoletoBr/BoletoBr.UnitTests/BoletoBrUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="TestsBancosRemessa\TestRemessaBancoSicoob.cs" />
<Compile Include="TestsBancosRemessa\TestRemessaBancoBrasil.cs" />
<Compile Include="TestsBancosRemessa\TestRemessaBradesco.cs" />
<Compile Include="TestsBancosRemessa\TestRemessaCef.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,47 @@
using System.Threading.Tasks;
using BoletoBr.Bancos.Itau;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BoletoBr.Bancos.Bradesco;
using System.IO;
using BoletoBr.Arquivo.CNAB240.Retorno;

namespace BoletoBr.UnitTests.TestsBancosRetorno
{
[TestClass]
public class TestRetornoBancoItau
{

#region CNAB 240
[TestMethod]
public void TestArquivoRetornoCnab240BancoItau()
{
string[] lines = File.ReadAllLines("C:\\Users\\antun\\Downloads\\BL30097A.RET", Encoding.UTF8);
List<string> lstFile = lines.ToList<string>();

var bank = BoletoBr.Fabricas.BancoFactory.ObterBanco("341");
var cnabRetFile = bank.LerArquivoRetorno(lstFile);

//LeitorRetornoCnab240Bradesco leitor = new LeitorRetornoCnab240Bradesco(lstFile);

//var resultado = leitor.ProcessarRetorno();
string conteudo = "";

foreach (LoteRetornoCnab240 loteRetorno in cnabRetFile.RetornoCnab240Especifico.Lotes)
{
conteudo += "Conta Corrente: " + loteRetorno.HeaderLote.ContaCorrente + Environment.NewLine;
foreach (DetalheRetornoCnab240 retorno in loteRetorno.RegistrosDetalheSegmentos)
{
conteudo += "SegmentoE NumeroInscricaoCliente " + retorno.SegmentoE.NumeroInscricaoCliente + " Agência Conta:" + retorno.SegmentoE.AgenciaMantenedoraConta + " Conta corrente:" + retorno.SegmentoE.NumeroContaCorrente +" Data Lançamento " + retorno.SegmentoE.DataLancamento + " HistoricoLancamento:" + retorno.SegmentoE.HistoricoLancamento + " TipoLancamento:" + retorno.SegmentoE.TipoLancamento + " NumeroDocumentoComplemento:" + retorno.SegmentoE.NumeroDocumentoComplemento + " ValorLancamento:" + retorno.SegmentoE.ValorLancamento + Environment.NewLine; ;
}
}
File.WriteAllText("C:\\Users\\antun\\Downloads\\RETAnaliseItau.txt", conteudo);
Assert.AreNotEqual(cnabRetFile.Header, null);
}

#endregion



#region CNAB400

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,37 @@
using System.Threading.Tasks;
using BoletoBr.Bancos.Bradesco;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using BoletoBr.Arquivo.CNAB240.Retorno;

namespace BoletoBr.UnitTests.TestsBancosRetorno
{
[TestClass]
public class TestRetornoBradesco
{
#region CNAB 240
[TestMethod]
public void TestArquivoRetornoCnab240BancoBradesco()
{
string[] lines = File.ReadAllLines("C:\\Users\\antun\\Downloads\\CC1508A0RW450.RET", Encoding.UTF8);
List<string> lstFile = lines.ToList<string>();
LeitorRetornoCnab240Bradesco leitor = new LeitorRetornoCnab240Bradesco(lstFile);

var resultado = leitor.ProcessarRetorno();
string conteudo = "";

foreach (LoteRetornoCnab240 loteRetorno in resultado.Lotes)
{
conteudo += "Empresa: "+ loteRetorno.HeaderLote.NumeroInscricaoEmpresa + " Agência: " + loteRetorno.HeaderLote.CodigoAgencia +" Conta Corrente: " + loteRetorno.HeaderLote.ContaCorrente + Environment.NewLine;
foreach (DetalheRetornoCnab240 retorno in loteRetorno.RegistrosDetalheSegmentos)
{
conteudo += " SegmentoE "+ "Agência: " + retorno.SegmentoE.AgenciaMantenedoraConta + " Conta Corrente: " + retorno.SegmentoE.NumeroContaCorrente + " Digito Conta: " + retorno.SegmentoE.DigitoVerificadorConta + " Data Lançamento: " + retorno.SegmentoE.DataLancamento + " HistoricoLancamento:" + retorno.SegmentoE.HistoricoLancamento + " TipoLancamento:" + retorno.SegmentoE.TipoLancamento + " NumeroDocumentoComplemento:" + retorno.SegmentoE.NumeroDocumentoComplemento + " ValorLancamento:" + retorno.SegmentoE.ValorLancamento + Environment.NewLine; ;
}
}
File.WriteAllText("C:\\Users\\antun\\Downloads\\RETAnaliseBradesco.txt", conteudo);
Assert.AreNotEqual(resultado.Header, null);
}


[TestMethod]
public void TestHeaderArquivoRetornoCnab240BancoBradesco() { }
Expand Down
25 changes: 11 additions & 14 deletions BoletoBr/BoletoBr/Arquivo/CNAB240/Retorno/DetalheRetornoCnab240.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ namespace BoletoBr.Arquivo.CNAB240.Retorno
{
public class DetalheRetornoCnab240
{
#region Propriedades

public DetalheSegmentoTRetornoCnab240 SegmentoT { get; set; }
public DetalheSegmentoURetornoCnab240 SegmentoU { get; set; }
public DetalheSegmentoWRetornoCnab240 SegmentoW { get; set; }
public DetalheSegmentoERetornoCnab240 SegmentoE { get; set; }

#endregion

#region Construtores

public DetalheRetornoCnab240()
{
SegmentoE = new DetalheSegmentoERetornoCnab240();
SegmentoW = new DetalheSegmentoWRetornoCnab240();
SegmentoU = new DetalheSegmentoURetornoCnab240();
SegmentoT = new DetalheSegmentoTRetornoCnab240();
Expand All @@ -34,23 +44,10 @@ public DetalheRetornoCnab240(DetalheSegmentoERetornoCnab240 segmentoE)
}

public DetalheRetornoCnab240(DetalheSegmentoTRetornoCnab240 segmentoT, DetalheSegmentoURetornoCnab240 segmentoU)
{
{
SegmentoT = segmentoT;
SegmentoU = segmentoU;
}

#endregion

#region Propriedades

public DetalheSegmentoTRetornoCnab240 SegmentoT { get; set; }

public DetalheSegmentoURetornoCnab240 SegmentoU { get; set; }

public DetalheSegmentoWRetornoCnab240 SegmentoW { get; set; }

public DetalheSegmentoERetornoCnab240 SegmentoE { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public class DetalheSegmentoERetornoCnab240
/// <summary>
/// N�mero de inscri��o da Empresa ou Pessoa F�sica perante uma Institui��o governamental.
/// </summary>
public long NumeroInscricaoCliente { get; private set; }
/// era long
public string NumeroInscricaoCliente { get; private set; }

/// <summary>
/// C�digo adotado pelo Banco para identificar o Contrato entre este e a Empresa Cliente.
Expand All @@ -73,7 +74,8 @@ public class DetalheSegmentoERetornoCnab240
/// <summary>
/// C�digo adotado pelo Banco respons�vel pela conta, para identificar a qual unidade est� vinculada a conta corrente.
/// </summary>
public int AgenciaMantenedoraConta { get; private set; }
/// era int
public string AgenciaMantenedoraConta { get; private set; }

/// <summary>
/// C�digo adotado pelo Banco respons�vel pela conta corrente, para verifica��o da autenticidade do C�digo da Ag�ncia.
Expand All @@ -83,7 +85,8 @@ public class DetalheSegmentoERetornoCnab240
/// <summary>
/// N�mero adotado pelo Banco, para identificar univocamente a conta corrente utilizada pelo Cliente.
/// </summary>
public long NumeroContaCorrente { get; private set; }
/// era long
public string NumeroContaCorrente { get; private set; }

/// <summary>
/// C�digo adotado pelo respons�vel pela conta corrente, para verifica��o da autenticidade do N�mero da Conta Corrente.
Expand Down Expand Up @@ -248,7 +251,24 @@ public class DetalheSegmentoERetornoCnab240
/// </summary>
public string NumeroDocumentoComplemento { get; private set; }

public void LerDetalheSegmentoERetornoCnab240(string registro)
public string BancoOrigemLancamento { get; private set; }

public string AgenciaOrigemLancamento { get; private set; }

public string AgenciaContaOrigemLancamento { get; private set; }

public string AgenciaDeOrigemLancamento { get; private set; }

public string ContaOrigemLancamento { get; private set; }

public string DigVerifAgenciaContaOrigemLancamento { get; private set; }

public TipoInscricao TipodeIncricaodoEmitente { get; private set; }

public string NumerodeIncricaodoEmitente { get; private set; }


public void LerDetalheSegmentoERetornoBrandescoCnab240(string registro)
{
try
{
Expand All @@ -262,11 +282,11 @@ public void LerDetalheSegmentoERetornoCnab240(string registro)
Segmento = registro.ExtrairValorDaLinha(14, 14);
UsoExclusivoFebrabanCnab = registro.ExtrairValorDaLinha(15, 17);
TipoInscricaoCliente = (TipoInscricao) registro.ExtrairValorDaLinha(18, 18)[0];
NumeroInscricaoCliente = Convert.ToInt32(registro.ExtrairValorDaLinha(19, 32));
NumeroInscricaoCliente = registro.ExtrairValorDaLinha(19, 32);
CodigoConvenioBanco = registro.ExtrairValorDaLinha(33, 52);
AgenciaMantenedoraConta = Convert.ToInt32(registro.ExtrairValorDaLinha(53, 57));
AgenciaMantenedoraConta = registro.ExtrairValorDaLinha(53, 57);
DigitoVerificadorAgencia = registro.ExtrairValorDaLinha(58, 58);
NumeroContaCorrente = Convert.ToInt32(registro.ExtrairValorDaLinha(59, 70));
NumeroContaCorrente = registro.ExtrairValorDaLinha(59, 70);
DigitoVerificadorConta = registro.ExtrairValorDaLinha(71, 71);
DigitoVerificadorAgenciaConta = registro.ExtrairValorDaLinha(72, 72);
NomeEmpresa = registro.ExtrairValorDaLinha(73, 102);
Expand All @@ -275,8 +295,8 @@ public void LerDetalheSegmentoERetornoCnab240(string registro)
TipoComplementoLancamento = (TipoComplementoLancamento) registro.ExtrairValorDaLinha(112, 113)[0];
ComplementoLancamento = registro.ExtrairValorDaLinha(114, 133);
IdentificacaoIsencaoCpmf = (IsencaoCpmf)registro.ExtrairValorDaLinha(134, 134)[0];
DataContabil = Convert.ToDateTime(registro.ExtrairValorDaLinha(135, 142));
DataLancamento = Convert.ToDateTime(registro.ExtrairValorDaLinha(143, 150));
DataContabil = Convert.ToDateTime(registro.ExtrairValorDaLinha(135, 142).ToDateTimeFromDdMmAaaa());
DataLancamento = Convert.ToDateTime(registro.ExtrairValorDaLinha(143, 150).ToDateTimeFromDdMmAaaa());
ValorLancamento = decimal.Parse(registro.ExtrairValorDaLinha(151, 168)) / 100m;
TipoLancamento = (TipoLancamento)registro.ExtrairValorDaLinha(169, 169)[0];
CategoriaLancamento = (CategoriaLancamento)registro.ExtrairValorDaLinha(170, 172)[0];
Expand All @@ -289,6 +309,60 @@ public void LerDetalheSegmentoERetornoCnab240(string registro)
throw new Exception("Erro ao processar arquivo de RETORNO - SEGMENTO E.", ex);
}
}

public void LerDetalheSegmentoERetornoItauCnab240(string registro)
{
try
{
if (registro.ExtrairValorDaLinha(14, 14) != "E")
throw new Exception("Registro inválido. O detalhe não possui as características do segmento E.");

CodigoBanco = Convert.ToInt32(registro.ExtrairValorDaLinha(1, 3));
LoteServico = Convert.ToInt32(registro.ExtrairValorDaLinha(4, 7));
TipoRegistro = registro.ExtrairValorDaLinha(8, 8);
NumeroRegistro = Convert.ToInt32(registro.ExtrairValorDaLinha(9, 13));
Segmento = registro.ExtrairValorDaLinha(14, 14);
TipoLancamento = (TipoLancamento) registro.ExtrairValorDaLinha(15, 15)[0];
//UsoExclusivoFebrabanCnab = registro.ExtrairValorDaLinha(15, 17);
TipoInscricaoCliente = (TipoInscricao)registro.ExtrairValorDaLinha(18, 18)[0];
NumeroInscricaoCliente = registro.ExtrairValorDaLinha(19, 32);
CodigoHistorico = registro.ExtrairValorDaLinha(33, 38);
CodigoConvenioBanco = registro.ExtrairValorDaLinha(48, 52);
AgenciaMantenedoraConta = registro.ExtrairValorDaLinha(54, 57);
DigitoVerificadorAgencia = registro.ExtrairValorDaLinha(58, 58);
NumeroContaCorrente = registro.ExtrairValorDaLinha(66, 70);
DigitoVerificadorConta = registro.ExtrairValorDaLinha(72, 72);
DigitoVerificadorAgenciaConta = registro.ExtrairValorDaLinha(72, 72);
NomeEmpresa = registro.ExtrairValorDaLinha(73, 102);
UsoExclusivoFebrabanCnab2 = registro.ExtrairValorDaLinha(103, 108);
NaturezaLancamento = registro.ExtrairValorDaLinha(109, 111);
TipoComplementoLancamento = (TipoComplementoLancamento)registro.ExtrairValorDaLinha(112, 113)[0];
//ComplementoLancamento = registro.ExtrairValorDaLinha(114, 133);
BancoOrigemLancamento = registro.ExtrairValorDaLinha(114, 116);
AgenciaOrigemLancamento = registro.ExtrairValorDaLinha(117, 121);
AgenciaContaOrigemLancamento = registro.ExtrairValorDaLinha(122, 133);
IdentificacaoIsencaoCpmf = (IsencaoCpmf)registro.ExtrairValorDaLinha(134, 134)[0];
DataContabil = Convert.ToDateTime(registro.ExtrairValorDaLinha(135, 142).ToDateTimeFromDdMmAaaa());
DataLancamento = Convert.ToDateTime(registro.ExtrairValorDaLinha(143, 150).ToDateTimeFromDdMmAaaa());
ValorLancamento = decimal.Parse(registro.ExtrairValorDaLinha(151, 168)) / 100m;
TipoLancamento = (TipoLancamento)registro.ExtrairValorDaLinha(169, 169)[0];
CategoriaLancamento = (CategoriaLancamento)registro.ExtrairValorDaLinha(170, 172)[0];
CodigoHistorico = registro.ExtrairValorDaLinha(173, 176);
HistoricoLancamento = registro.ExtrairValorDaLinha(177, 201);
AgenciaDeOrigemLancamento = registro.ExtrairValorDaLinha(202, 205);
ComplementoLancamento = registro.ExtrairValorDaLinha(206, 207);
ContaOrigemLancamento = registro.ExtrairValorDaLinha(208, 212);
DigVerifAgenciaContaOrigemLancamento = registro.ExtrairValorDaLinha(213, 213);
TipodeIncricaodoEmitente = (TipoInscricao) registro.ExtrairValorDaLinha(214, 214)[0];
NumerodeIncricaodoEmitente = registro.ExtrairValorDaLinha(215, 228);
NumeroDocumentoComplemento = registro.ExtrairValorDaLinha(235, 240);
}
catch (Exception ex)
{
throw new Exception("Erro ao processar arquivo de RETORNO - SEGMENTO E.", ex);
}
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class HeaderLoteRetornoCnab240
public string NumeroRemessaRetorno { get; set; }
public DateTime DataGeracaoGravacao { get; set; }
public DateTime DataDeCredito { get; set; }
public string ComplementoRegistro { get; set; }

#region Banco do Brasil

Expand All @@ -46,7 +47,14 @@ public class HeaderLoteRetornoCnab240
/// C/C = 45981-36
/// Neste caso o DV da Ag/Conta = 6
/// </summary>
public int FormaLancamento { get; set; }
public string DvAgenciaConta { get; set; }
public DateTime DataSaldoInicial { get; set; }
public decimal ValorSaldoInicial { get; set; }
public string SituacaoSaldoInicial { get; set; }
public string PosicaoSaldoInicial { get; set; }
public string MoedaReferenciadaExtrato { get; set; }
public int NumeroSequenciaExtrato { get; set; }

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
namespace BoletoBr.Arquivo.CNAB240.Retorno
using System;

namespace BoletoBr.Arquivo.CNAB240.Retorno
{
public class TrailerLoteRetornoCnab240
{
public int CodigoBanco { get; set; }
public string LoteServico { get; set; }
public int CodigoRegistro { get; set; }
public long QtdRegistrosLote { get; set; }
public long QtdTitulosCobrancaSimples { get; set; }
public int TipoRegistro { get; set; }
public int TipoIncricaoEmpresa { get; set; }
public string NumeroIncricaoEmpresa { get; set; }
public string ConvenioBanco { get; set; }
public string AgenciaConta { get; set; }
public string DigitoAgencia { get; set; }
public string NumeroContaCorrente { get; set; }
public string DigitoContaCorrente { get; set; }
public string DigitoAgenciaConta { get; set; }
public decimal ValorVinculadoDiaAnterior { get; set; }
public decimal ValorLimiteConta { get; set; }
public decimal ValorVinculadoDia { get; set; }
public DateTime DataSaldoFinal { get; set; }
public decimal ValorSaldoFinal { get; set; }
public string SituacaoSaldoFinal { get; set; }
public string PosicaoSaldoFinal { get; set; }
public decimal SomaValoresaDebito { get; set; }
public decimal SomaValoresaCredito { get; set; }
public int QtdRegistrosLote { get; set; }
public int QtdTitulosCobrancaSimples { get; set; }
public decimal ValorTitulosCobrancaSimples { get; set; }
public long QtdTitulosCobrancaCaucionada { get; set; }
public int QtdTitulosCobrancaCaucionada { get; set; }
public decimal ValorTitulosCobrancaCaucionada { get; set; }
public long QtdTitulosCobrancaDescontada { get; set; }
public int QtdTitulosCobrancaDescontada { get; set; }
public decimal ValorTitulosCobrancaDescontada { get; set; }
public decimal TotalValoresNaoContabeis { get; set; }

#region Bradesco

public long QtdTitulosCobrancaVinculada { get; set; }
public int QtdTitulosCobrancaVinculada { get; set; }
public decimal ValorTitulosCobrancaVinculada { get; set; }
public string NumeroAvisoLancamento { get; set; }

Expand Down
Loading