Exception when it will generate bank bill with Boleto.Net

Asked

Viewed 4,336 times

4

I have a system that generates Santander billets using a specific DLL that was downloaded from the internet. The name is "Boleto.net". I need to create a Bradesco ticket. I changed where I passed the data from Santander to the data from Bradesco, but at the time of generating the receipt of an error saying that the value was not passed to a specific object. What the TipoArquivo of Bradesco to pass the validation in the boleto?

        public BoletoBancario GerarBoletoBradesco(BoletoModel bol)
        {
            BoletoBancario boletoBancario = new BoletoBancario();

            boletoBancario.CodigoBanco = 237;

            ContaBancaria cb = new ContaBancaria();

            cb.Agencia = bol.cedente.Agencia;
            if (bol.cedente.DigAgencia != "")
                cb.DigitoAgencia = bol.cedente.DigAgencia;

            cb.Conta = bol.cedente.Conta;
            if (bol.cedente.DigConta != "")
            cb.DigitoConta = bol.cedente.DigConta;

            Cedente c = new Cedente();
            c.CPFCNPJ = bol.cedente.CNPJ;
            c.Nome = bol.cedente.Nome;
            c.Carteira = bol.Carteira;
            c.ContaBancaria = cb;
            c.Codigo = bol.cedente.Codigo;
            if (bol.cedente.DigCedente != "")
                c.DigitoCedente = int.Parse(bol.cedente.DigCedente);    
            //Até o momento o Convênio é o mesmo número do código do cedente
            c.Convenio = int.Parse(c.Codigo);

            BoletoNet.Boleto b = new BoletoNet.Boleto(bol.DataVencimento, bol.ValorBoleto, bol.Carteira, 
                bol.NossoNumero, c);

            b.NumeroDocumento = bol.NumeroDocumento;
            b.DataProcessamento = DateTime.Now.Date;
            b.DataDocumento = bol.DataDocumento;
            b.JurosMora = bol.ValorMulta;

            BoletoNet.Endereco end = new BoletoNet.Endereco();
            end.Bairro = "";
            end.End = bol.sacado.Endereco;
            end.CEP = bol.sacado.CEP;
            end.Cidade = bol.sacado.Cidade;
            end.Complemento = "";
            end.Email = "";
            end.Logradouro = "";
            end.Numero = "";
            end.UF = bol.sacado.UF;

            BoletoNet.Sacado s = new BoletoNet.Sacado(bol.sacado.CNPJCPF, bol.sacado.Nome, end);
            b.Sacado = s;

            //Aqui passa o codigo do banco bradesco
            //b.EspecieDocumento = new EspecieDocumento_Santander("17");
            b.EspecieDocumento = new EspecieDocumento_Bradesco("13");

            Instrucao objInst1 = new Instrucao(237);
            objInst1.Descricao = bol.infAdicional.Instrucao1;
            Instrucao objInst2 = new Instrucao(237);
            objInst2.Descricao = bol.infAdicional.Instrucao2;
            Instrucao objInst3 = new Instrucao(237);
            objInst3.Descricao = bol.infAdicional.Instrucao3;
            Instrucao objInst4 = new Instrucao(237);
            objInst4.Descricao = bol.infAdicional.Instrucao4;

            b.Instrucoes.Add(objInst1);
            b.Instrucoes.Add(objInst2);
            b.Instrucoes.Add(objInst3);
            b.Instrucoes.Add(objInst4);

            //Importante para o calculo do digito verificador
            //b.PercentualIOS = 0;

            boletoBancario.Boleto = b;
            boletoBancario.MostrarCodigoCarteira = true;
            boletoBancario.Boleto.Valida();

            return boletoBancario;
        }

public ActionResult GeraRemessa()
        {
            BoletoNet.Boletos lb = new BoletoNet.Boletos();
            BoletoNet.Cedente cd = new BoletoNet.Cedente();
            foreach (var item in listaBoletos)
            {
                Boleto bol = new Boleto();
                BoletoNet.BoletoBancario bolBanc = new BoletoNet.BoletoBancario();
                //bolBanc = bol.GerarBoleto(RetornarItemList(item.NumeroDocumento));
                bolBanc = bol.GerarBoletoBradesco(RetornarItemList(item.NumeroDocumento));
                cd = bolBanc.Cedente;
                lb.Add(bolBanc.Boleto);
                break;

            }

            System.IO.FileStream arq = new System.IO.FileStream("C:\\Temp\\arqRemessa.txt", System.IO.FileMode.Append);

            cd.Endereco = new BoletoNet.Endereco
            {
                Bairro = "Teste",
                CEP = "02764-020",
                Cidade = "São Paulo",
                End = "Teste end",
                Logradouro = "Rua",
                Numero= "4",
                UF= "SP"
            };

            BoletoNet.ArquivoRemessa arqRem = new BoletoNet.ArquivoRemessa(BoletoNet.TipoArquivo.Outro);

            arqRem.GerarArquivoRemessa("3480291", new BoletoNet.Banco(237), cd, lb,
                arq, 1);


            return View("/home/index");
        }

public ActionResult ImprimirBoleto(string Fatura, string NovaDtVenc = "")
        {
            Boleto bol = new Boleto();
            BoletoNet.BoletoBancario bolBanc = new BoletoNet.BoletoBancario();

            bolBanc = bol.GerarBoletoBradesco(RetornarItemList(Fatura));

            if (NovaDtVenc != "")
            {
                bolBanc.Boleto.DataVencimento = DateTime.Parse(NovaDtVenc);
                bolBanc.Boleto.DataDocumento = DateTime.Now;
            }

            //HTML que monta o boleto.
 // Aqui dá o erro falando que não foi passado o valor pro objeto BoletoNet.Conta
            var htmlBoleto = bolBanc.MontaHtml(Server.MapPath(@"~/Content/Boletos/"), "");
            htmlBoleto = htmlBoleto
            .Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], "\\") // convertendo o caminho absoluto para relativo
            .Replace(System.IO.Path.GetTempPath(), Url.Action("Temporario", "Faturas") + "/?filename=") // convertendo o caminho temporário em relativo
            .Replace(".w666{width:666px}", ".w666{width:21cm}")
            .Replace("<body>", "<body style=\"height:29cm\">")
            //.Replace("</html>", "<a length=\"0\" href=\"/Faturas/PrintBoleto?Fatura=subsFatura\" >Exportar PDF</a></html>")
            .Replace("</html>", "<a length=\"0\" href=\"#\" onclick=\"window.print();\">Imprimir/Exportar PDF</a></html>")
            .Replace("subsFatura", Fatura.Replace("/","%2F"))
            //.Replace("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">", "")
            //.Replace("Imprimir em impressora jato de tinta (ink jet) ou laser em qualidade normal. (Não use modo econômico).<br>Utilize folha A4 (210 x 297 mm) ou Carta (216 x 279 mm) - Corte na linha indicada<br>","")
            //.Replace("&nbsp;","")
            ;
            ViewBag.Boleto = htmlBoleto.ToString();

            return View();

        }
  • Dude, this is not the best place to ask specific questions about boleto.net. But anyway, there is a project with only examples in https://github.com/BoletoNet I hope it helps you

  • Enter your code, give more subsidies so we can help. Ah, I know there’s nothing better ready available, but that code is well done.

  • I’m on @Jéfersonbueno, is that guy I went to do a simple thing and complicated rs. I have this error of an object that talks that is not being passed but actually I have passed value to this object.

  • @Andreeh put the code to try to help. By the way, you downloaded the dll from somewhere or are using the nuget?

  • @Mustache, puts is just making a mistake when it comes to riding the billet. This code was another person who did, I just need to change where today passes data from Santander to Bradesco.

  • @Jéfersonbueno, this code was already done, I took to change the boleto de santander to Bradesco and from what I saw, was downloaded from the net this dll.

  • 1

    If you cannot give us information to help your question will be considered unclear and will be closed. Repeating the same thing doesn’t help anyone, giving relevant information helps. We can’t guess what your problem is without seeing what you’re doing.

  • @bigown, I put the code that passes when I have the boleto printed.

  • What error happens? Where? Give details.

  • @bigown error "The description for the Boletonet.Banco bank was not implemented.". In the "Imprimirboleto" method at the time of montarHtml of this error. But I implemented this object.

Show 5 more comments

1 answer

6


This software is poorly done and incomplete. If you want to use it this way you will have to complete it. See what causes the problem:

switch (Banco.Codigo) {
    case 1:
        descricaoCarteira = new Carteira_BancoBrasil(carteira).Codigo;
        break;
    case 353:
    case 8:
    case 33:
        descricaoCarteira = new Carteira_Santander(carteira).Codigo;
        break;
    case 104:
        descricaoCarteira = new Carteira_Caixa(carteira).Codigo;
        break;
    case 341:
        descricaoCarteira = new Carteira_Itau(carteira).Codigo;
        break;
    default:
        throw new Exception($"A descrição para o banco {Boleto.Banco} não foi implementada."));
        throw new Exception($"A descrição da carteira {carteira} / banco {Banco.Codigo} não foi implementada (marque false na propriedade MostrarCodigoCarteira)"));
}

I put in the Github for future reference.

No Bradesco. You’ll have to add one case there in this code. But of course this is not enough. This should not be treated this way, it hurts several programming principles, but it is what has.

See that in the repository of it there is no implementation of the wallet you want to use. You will have to create one for Bradesco. I believe that it will be easy to copy a file from another bank and adapt only what is necessary. It should be even easier than this but the code does not help, it is poorly architected.

That is, only with the DLL, you will not solve the problem, you will have to tamper with their code. What is absurd. If you do it right, try running Github and see if they accept so others can enjoy your improvement.

But you may have another solution if you can give up a resource. If you change a property, this error code does not execute. See the font you must have created for Bradesco and change the property MostrarCodigoCarteira for false. See where it’s at existing archive of Santander.

The use of exception in this way seems inadequate.

  • beauty, thank you.

  • at what point I can add this excerpt and add the Bradesco case ?

  • Any place where I showed it to you. I edited it to give you another partial solution.

  • 1

    The cool thing is in the guy’s Wiki, he says that the layout for Bradesco is implemented hehehehe. If you want, I change and make a pull request for the author.

  • @Gypsy omorrisonmendez I think the layout That’s right. I didn’t see it, it’s not all the parts. It seems to be optional, so most of them can use it. I didn’t have time to see everything. I even thought of making a Fork and fix some wrong things, but there’s so much trouble just in what I saw that if one day you’re gonna mess with it, you better do it from scratch. You saw the 2 throws in a row? :)

  • Yes. A work of art.

  • @bigown, I changed the Showcode wallet to false and it worked.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.