Пример #1
0
        public MemoryStream GerarBoleto(BoletoIn boletoIn)
        {
            Cedente cedente = new Cedente(boletoIn.Cedente.CPF,
                                          boletoIn.Cedente.Nome, boletoIn.Cedente.Agencia, boletoIn.Cedente.Conta, boletoIn.Cedente.DigitoConta);

            cedente.Codigo = Convert.ToInt32(boletoIn.Cedente.Codigo).ToString();

            Boleto boleto = new Boleto(Convert.ToDateTime(boletoIn.Vencimento),
                                       Convert.ToDecimal(boletoIn.Valor),
                                       "109", boletoIn.Cedente.NumeroBoleto, cedente);

            boleto.NumeroDocumento = boletoIn.Numero;

            Sacado sacado = new Sacado(boletoIn.Sacado.CPF, boletoIn.Sacado.Nome);

            boleto.Sacado = sacado;
            boleto.Sacado.Endereco.End    = boletoIn.Sacado.Endereco;
            boleto.Sacado.Endereco.Bairro = boletoIn.Sacado.Bairro;
            boleto.Sacado.Endereco.Cidade = boletoIn.Sacado.Cidade;
            boleto.Sacado.Endereco.CEP    = boletoIn.Sacado.CEP;
            boleto.Sacado.Endereco.UF     = boletoIn.Sacado.UF;

            Instrucao_Itau instrucao = new Instrucao_Itau();

            instrucao.Descricao = "Não Receber após o vencimento";
            boleto.Instrucoes.Add(instrucao);

            EspecieDocumento_Itau especieItau     = new EspecieDocumento_Itau("99");
            BoletoBancario        boleto_bancario = new BoletoBancario();

            boleto.EspecieDocumento     = especieItau;
            boleto_bancario.CodigoBanco = 341;

            boleto_bancario.Boleto = boleto;
            boleto_bancario.MostrarCodigoCarteira = true;
            //boleto_bancario.Boleto.Valida();
            boleto_bancario.MostrarComprovanteEntrega = true;

            try
            {
                return(SaveBoletoPDF(boleto_bancario.MontaBytesPDF()));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #2
0
        public MemoryStream GerarBoletoTeste(BoletoIn paramsBoleto)
        {
            String vencimento      = paramsBoleto.Vencimento;
            String valorBoleto     = paramsBoleto.Valor;
            String numeroDocumento = "B20005446";

            //cedente
            String cedente_codigo            = "1111111";
            String cedente_nossoNumeroBoleto = "22222222";
            String cedente_cpfCnpj           = "123.456.789-01";
            String cedente_nome        = "CHRISTOPHER LAMBERT FRIGERIO DE SOUZA.";
            String cedente_agencia     = "1000";
            String cedente_conta       = "22507";
            String cedente_digitoConta = "6";

            //sacado
            String sacado_cpfCnpj  = "000.000.000-00";
            String sacado_nome     = "Christopher Lambert";
            String sacado_endereco = "Rua Domingos da Costa Aroso 149 R/C";
            String sacado_bairro   = "Moreira";
            String sacado_cidade   = "Cidade";
            String sacado_cep      = "4470-313";
            String sacado_uf       = "PR";

            Cedente cedente = new Cedente(cedente_cpfCnpj,
                                          cedente_nome,
                                          cedente_agencia,
                                          cedente_conta,
                                          cedente_digitoConta);

            cedente.Codigo = Convert.ToInt32(cedente_codigo).ToString();

            Boleto boleto = new Boleto(Convert.ToDateTime(vencimento),
                                       Convert.ToDecimal(valorBoleto),
                                       "109",
                                       cedente_nossoNumeroBoleto, cedente);

            boleto.NumeroDocumento = numeroDocumento;

            Sacado sacado = new Sacado(sacado_cpfCnpj, sacado_nome);

            boleto.Sacado = sacado;
            boleto.Sacado.Endereco.End    = sacado_endereco;
            boleto.Sacado.Endereco.Bairro = sacado_bairro;
            boleto.Sacado.Endereco.Cidade = sacado_cidade;
            boleto.Sacado.Endereco.CEP    = sacado_cep;
            boleto.Sacado.Endereco.UF     = sacado_uf;

            Instrucao_Itau instrucao = new Instrucao_Itau();

            instrucao.Descricao = "Não Receber após o vencimento";
            boleto.Instrucoes.Add(instrucao);

            EspecieDocumento_Itau especieItau     = new EspecieDocumento_Itau("99");
            BoletoBancario        boleto_bancario = new BoletoBancario();

            boleto.EspecieDocumento     = especieItau;
            boleto_bancario.CodigoBanco = 341;

            boleto_bancario.Boleto = boleto;
            boleto_bancario.MostrarCodigoCarteira = true;
            //boleto_bancario.Boleto.Valida();
            boleto_bancario.MostrarComprovanteEntrega = true;

            try
            {
                //return SaveBoletoPDF(boleto_bancario.MontaBytesPDF(), false);
                return(SaveBoletoPDF(boleto_bancario.MontaBytesPDF(), true));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #3
0
        public void Gera_Boleto_PDF(DateTime dt1, DateTime dt2)
        {
            dt2 = dt2.AddDays(1);

            List <BOLETOS_CLIENTE> IDS_CLIENTE = new List <BOLETOS_CLIENTE>();

            var query = (from linha in ctx.TB_FINANCEIROs
                         where NUMEROS_FINANCEIRO.Contains(linha.NUMERO_FINANCEIRO)
                         select linha).ToList();

            foreach (var item in query.OrderBy(_ => _.CODIGO_CLIENTE))
            {
                if (!IDS_CLIENTE.Where(_ => _.ID_CLIENTE == item.CODIGO_CLIENTE).Any())
                {
                    if (item.TB_CLIENTE == null)
                    {
                        throw new Exception("T&iacute;tulo n&ordm; [" + item.NUMERO_FINANCEIRO.ToString() +
                                            "] est&aacute; sem cliente definido");
                    }

                    IDS_CLIENTE.Add(new BOLETOS_CLIENTE()
                    {
                        ID_CLIENTE            = item.CODIGO_CLIENTE.Value,
                        NOME_FANTASIA_CLIENTE = string.IsNullOrEmpty(item.TB_CLIENTE.NOMEFANTASIA_CLIENTE) ? "" : item.TB_CLIENTE.NOMEFANTASIA_CLIENTE.Trim(),
                        NOTAS_FISCAIS         = new List <string>(),
                        LINKS_BOLETO          = new List <string>(),
                        VENCIMENTOS           = new List <DateTime>()
                    });
                }

                string vencimento      = ApoioXML.TrataData2(item.DATA_VENCIMENTO);
                string valorBoleto     = item.VALOR_TOTAL.Value.ToString();
                string numeroDocumento = item.NUMERO_NF_SAIDA.ToString(); //"B20005446";

                item.NOSSO_NUMERO_BANCARIO = buscaNossoNumeroBancario();

                //cedente
                String cedente_codigo            = CONTA_CORRENTE.Replace("-", "");
                String cedente_nossoNumeroBoleto = item.NOSSO_NUMERO_BANCARIO.Trim();
                String cedente_cpfCnpj           = emitente.CNPJ_EMITENTE.Trim();
                String cedente_nome    = emitente.NOME_EMITENTE.Trim();
                String cedente_agencia = AGENCIA;
                String cedente_conta   = CONTA_CORRENTE.LastIndexOf("-") > -1 ? CONTA_CORRENTE.Substring(0, CONTA_CORRENTE.LastIndexOf("-")) :
                                         CONTA_CORRENTE;
                String cedente_digitoConta = CONTA_CORRENTE.LastIndexOf("-") > -1 ? CONTA_CORRENTE.Substring(CONTA_CORRENTE.LastIndexOf("-") + 1) :
                                             "";

                if (item.TB_CLIENTE == null)
                {
                    throw new Exception("O t&iacute;tulo de numero [" + item.NUMERO_FINANCEIRO.ToString() + "] est&aacute; sem cliente definido");
                }

                //sacado
                String sacado_cpfCnpj  = item.TB_CLIENTE.CNPJ_CLIENTE.Trim();
                String sacado_nome     = item.TB_CLIENTE.NOME_CLIENTE.Trim();
                String sacado_endereco = item.TB_CLIENTE.ENDERECO_FATURA.Trim();
                String sacado_bairro   = item.TB_CLIENTE.BAIRRO_FATURA.Trim();
                String sacado_cidade   = item.TB_CLIENTE.TB_MUNICIPIO.NOME_MUNICIPIO.Trim();
                String sacado_cep      = item.TB_CLIENTE.CEP_FATURA.Trim();
                String sacado_uf       = item.TB_CLIENTE.TB_MUNICIPIO.TB_UF.SIGLA_UF;

                Cedente cedente = new Cedente(cedente_cpfCnpj,
                                              cedente_nome,
                                              cedente_agencia,
                                              cedente_conta,
                                              cedente_digitoConta);

                cedente.Codigo = Convert.ToInt32(cedente_codigo);
                //cedente.Nome = emitente.NOME_EMITENTE.Trim();
                //cedente.CPFCNPJ = emitente.CNPJ_EMITENTE.Trim();

                //cedente.Endereco = new Endereco();

                //cedente.Endereco.End = string.Concat(emitente.ENDERECO_EMITENTE.Trim(), " ",
                //     emitente.NUMERO_END_EMITENTE.Trim(), " ",
                //     string.IsNullOrEmpty(emitente.COMPLEMENTO_END_EMITENTE) ? "" : emitente.COMPLEMENTO_END_EMITENTE.Trim()).Trim();

                //cedente.Endereco.Bairro = emitente.BAIRRO_EMITENTE.Trim();
                //cedente.Endereco.CEP = emitente.CEP_EMITENTE.Trim();
                //cedente.Endereco.Cidade = emitente.TB_MUNICIPIO.NOME_MUNICIPIO.Trim();
                //cedente.Endereco.UF = emitente.TB_MUNICIPIO.TB_UF.SIGLA_UF;

                Boleto boleto = new Boleto(item.DATA_VENCIMENTO.Value,
                                           item.VALOR_TOTAL.Value,
                                           CARTEIRA,
                                           cedente_nossoNumeroBoleto,
                                           cedente);

                boleto.NumeroDocumento = numeroDocumento;

                Sacado sacado = new Sacado(sacado_cpfCnpj, sacado_nome);
                boleto.Sacado = sacado;
                boleto.Sacado.Endereco.End    = sacado_endereco;
                boleto.Sacado.Endereco.Bairro = sacado_bairro;
                boleto.Sacado.Endereco.Cidade = sacado_cidade;
                boleto.Sacado.Endereco.CEP    = sacado_cep;
                boleto.Sacado.Endereco.UF     = sacado_uf;

                Instrucao_Itau instrucao = new Instrucao_Itau();
                instrucao.Descricao = "APOS O VENCIMENTO COBRAR MULTA DE R$ 2,00";

                boleto.Instrucoes.Add(instrucao);
                EspecieDocumento_Itau especie = new EspecieDocumento_Itau("1");
                boleto.EspecieDocumento  = especie;
                boleto.DataProcessamento = DateTime.Today;
                boleto.DataDocumento     = DateTime.Today;
                boleto.ValorBoleto       = item.VALOR_TOTAL.Value;
                boleto.NumeroDocumento   = item.NUMERO_NF_SAIDA.ToString().PadLeft(10, '0');

                BoletoBancario boleto_bancario = new BoletoBancario();
                boleto_bancario.CodigoBanco           = (short)NUMERO_BANCO;
                boleto_bancario.Boleto                = boleto;
                boleto_bancario.MostrarCodigoCarteira = true;

                // AG. 0189
                // CC 47562-7
                // WILLIAM DA SILVA CARDOZO
                // CPF 286.248.538-18

                boleto_bancario.Boleto.Valida();

                boleto_bancario.MostrarComprovanteEntrega = true;

                Image codigoBarras = boleto_bancario.GeraImagemCodigoBarras(boleto);

                codigoBarras.Save(Path.Combine(ConfigurationManager.AppSettings["PASTA_BOLETO_ITAU"],
                                               "codigoBarras" + item.NUMERO_FINANCEIRO.ToString() + ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);

                string url = string.Concat(ApoioXML.urlBase(), "/Boletos/Itau/");

                string arquivo_Boleto = Path.Combine(ConfigurationManager.AppSettings["PASTA_BOLETO_ITAU"],
                                                     "boleto_" + item.NUMERO_FINANCEIRO.ToString() + ".htm");

                string htmlBoleto = boleto_bancario.MontaHtml(arquivo_Boleto);
                htmlBoleto = htmlBoleto.Replace(ConfigurationManager.AppSettings["PASTA_BOLETO_ITAU"], "");

                string htmlCodigoBarras = htmlBoleto.Substring(htmlBoleto.IndexOf(@"<td class=""EcdBar Al pL10"">"));
                htmlCodigoBarras = htmlCodigoBarras.Substring(0, htmlCodigoBarras.IndexOf("</td>"));
                htmlCodigoBarras = htmlCodigoBarras.Substring(htmlCodigoBarras.IndexOf("<img src=") + 1);
                htmlCodigoBarras = htmlCodigoBarras.Substring(0, htmlCodigoBarras.LastIndexOf(" ") - 1);

                htmlBoleto = htmlBoleto.Replace(htmlCodigoBarras,
                                                string.Concat(@"img src=""", Path.Combine(ApoioXML.urlBase() + "/Boletos/Itau/",
                                                                                          "codigoBarras" + item.NUMERO_FINANCEIRO.ToString() + ".jpg"), @""" alt='Código de Barras'"));

                using (TextWriter tw = new StreamWriter(arquivo_Boleto, false, Encoding.UTF8))
                {
                    tw.Write(htmlBoleto);
                    tw.Close();
                }

                IDS_CLIENTE[IDS_CLIENTE.Count - 1].NOTAS_FISCAIS.Add(item.NUMERO_NF_SAIDA.Value.ToString());
                IDS_CLIENTE[IDS_CLIENTE.Count - 1].LINKS_BOLETO.Add(url + "boleto_" + item.NUMERO_FINANCEIRO.ToString() + ".htm");
                IDS_CLIENTE[IDS_CLIENTE.Count - 1].VENCIMENTOS.Add(item.DATA_VENCIMENTO.Value);
            }

            ctx.SubmitChanges();

            for (int i = 0; i < IDS_CLIENTE.Count(); i++)
            {
                using (Doran_ERP_Servicos_Email.PopMail mail = new Doran_ERP_Servicos_Email.PopMail(ID_USUARIO, ID_CONTA_EMAIL))
                {
                    string FROM_ADDRESS = (from linha in ctx.TB_EMAIL_CONTAs
                                           where linha.ID_CONTA_EMAIL == ID_CONTA_EMAIL
                                           select linha.CONTA_EMAIL).First().Trim();

                    var NOME_CONTATO = from linha in ctx.TB_CLIENTE_CONTATOs
                                       where linha.ID_CLIENTE == IDS_CLIENTE[i].ID_CLIENTE
                                       select linha.NOME_CONTATO_CLIENTE;

                    var EMAIL_CLIENTE = from linha in ctx.TB_CLIENTE_CONTATOs
                                        where linha.ID_CLIENTE == IDS_CLIENTE[i].ID_CLIENTE
                                        select linha.EMAIL_CONTATO_CLIENTE;

                    var ASSINATURA = (from linha in ctx.TB_EMAIL_CONTAs
                                      where linha.ID_CONTA_EMAIL == ID_CONTA_EMAIL
                                      select linha.ASSINATURA).First().Trim();

                    if (!NOME_CONTATO.Any())
                    {
                        throw new Exception("N&atilde;o h&aacute; contato cadastrado para este cliente");
                    }

                    Dictionary <string, object> dados = new Dictionary <string, object>();

                    dados.Add("ID_MESSAGE", 0);
                    dados.Add("ID_CONTA_EMAIL", ID_CONTA_EMAIL);
                    dados.Add("FROM_ADDRESS", FROM_ADDRESS);
                    dados.Add("PRIORITY", 1);
                    dados.Add("SUBJECT", string.Concat("Boleto de cobrança - ", emitente.NOME_FANTASIA_EMITENTE.Trim()));

                    string mensagem = string.Concat(DateTime.Now.Hour >= 0 && DateTime.Now.Hour < 12 ?
                                                    "<span style='font-family: tahoma; font-size: 9pt;'>Bom dia " :
                                                    DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 19 ?
                                                    "<span style='font-family: tahoma; font-size: 9pt;'>Boa tarde " :
                                                    "<span style='font-family: tahoma; font-size: 9pt;'>Boa noite ", NOME_CONTATO.First().Trim(), "<br /><br />",
                                                    "Segue abaixo o(s) link(s) para voc&ecirc; acessar os boletos de cobrança referente a(s) nota(s) fiscal(is) ",
                                                    "<b>[", string.Join(", ", IDS_CLIENTE[i].NOTAS_FISCAIS.ToArray()), "]</b><br /><br />");

                    for (int n = 0; n < IDS_CLIENTE[i].LINKS_BOLETO.Count; n++)
                    {
                        mensagem += string.Concat("<a href='", IDS_CLIENTE[i].LINKS_BOLETO[n], "' target='_blank'>Boleto com vencimento para ",
                                                  ApoioXML.TrataData2(IDS_CLIENTE[i].VENCIMENTOS[n]), "</a><br />");
                    }

                    using (Doran_Relatorio_Entregas_do_Cliente ec = new classes.Doran_Relatorio_Entregas_do_Cliente(IDS_CLIENTE[i].NOME_FANTASIA_CLIENTE, dt1, dt2, ID_EMPRESA))
                    {
                        relatorio_De_Servicos_Do_Cliente = ec.MontaRelatorio();
                    }

                    mensagem += "<br /><br />Segue tamb&eacute;m, o relat&oacute;rio dos seus servi&ccedil;os referente a esta cobran&ccedil;a<br /><br />";

                    mensagem += "<a href='" + relatorio_De_Servicos_Do_Cliente + "'>Relat&oacute;rio dos servi&ccedil;os</a><br />";

                    mensagem += "<br />Obrigado, <br /></span>" + ASSINATURA;

                    dados.Add("BODY", mensagem);
                    dados.Add("RAW_BODY", mensagem);
                    dados.Add("NUMERO_CRM", 0);

                    List <string> TOs = new List <string>();
                    TOs.Add(EMAIL_CLIENTE.First().Trim());

                    List <string> CCs         = new List <string>();
                    List <string> BCCs        = new List <string>();
                    List <string> Attachments = new List <string>();

                    mail.Salva_Mensagem_como_Rascunho(dados, TOs, CCs, BCCs, Attachments);
                }
            }
        }
    protected void btprocessa_Click(object sender, EventArgs e)
    {
        Boolean lOk = true;

        string vencimento      = "10/01/2016";
        String valorBoleto     = "1000.00";
        String numeroDocumento = "B20005446";
        //cedente
        String cedente_codigo            = "1111111";
        String cedente_nossoNumeroBoleto = "22222222";
        String cedente_cpfCnpj           = "123.456.789-01";
        String cedente_nome        = "PAULO FREIRE - FOUR FREIRES INF.";
        String cedente_agencia     = "1000";
        String cedente_conta       = "22507";
        String cedente_digitoConta = "6";
        //sacado
        String  sacado_cpfCnpj  = "000.000.000-00";
        String  sacado_nome     = "Airam Miranda de Almeida";
        String  sacado_endereco = "Rua Iraçi Luchina, 62";
        String  sacado_bairro   = "Bairro Central";
        String  sacado_cidade   = "Rio de Janeiro";
        String  sacado_cep      = "23080-600";
        String  sacado_uf       = "RJ";
        Cedente cedente         = new Cedente(cedente_cpfCnpj, cedente_nome, cedente_agencia, cedente_conta, cedente_digitoConta);

        cedente.Codigo = cedente_codigo;
        Boleto boleto = new Boleto(Convert.ToDateTime(vencimento),
                                   Convert.ToDecimal(valorBoleto), "109",
                                   cedente_nossoNumeroBoleto, cedente);

        boleto.NumeroDocumento = numeroDocumento;
        Sacado sacado = new Sacado(sacado_cpfCnpj, sacado_nome);

        boleto.Sacado = sacado;
        boleto.Sacado.Endereco.End    = sacado_endereco;
        boleto.Sacado.Endereco.Bairro = sacado_bairro;
        boleto.Sacado.Endereco.Cidade = sacado_cidade;
        boleto.Sacado.Endereco.CEP    = sacado_cep;
        boleto.Sacado.Endereco.UF     = sacado_uf;
        Instrucao_Itau instrucao = new Instrucao_Itau();

        instrucao.Descricao = "Não Receber após o vencimento";
        boleto.Instrucoes.Add(instrucao);
        EspecieDocumento_Itau especie = new EspecieDocumento_Itau("99");

        boleto.EspecieDocumento = especie;
        BoletoBancario boleto_bancario = new BoletoBancario();

        boleto_bancario.CodigoBanco           = 341;
        boleto_bancario.Boleto                = boleto;
        boleto_bancario.MostrarCodigoCarteira = true;
        boleto_bancario.Boleto.Valida();
        boleto_bancario.MostrarComprovanteEntrega = false;

        //
        //pnl_dados.Visible = false;
        //
        //return boletoBancario.MontaHtmlEmbedded()
        //
        pnl_boleto.Controls.Add(boleto_bancario);

        //ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( '" + boleto_bancario.MontaHtml() + "', null, 'height=755,width=900,status=yes,resizable=yes,menubar=yes,location=yes' );", true);



        //
        // CRIA LOG ===============================================================================================================================================
        fwObs_Log = "BOLETOS: ";// +cbbanco.Value.ToString();
        SqlParameter[] param_log = { new SqlParameter("@login",    (String)Session["CodUsuario"]),
                                     new SqlParameter("@tabela",   fWtabela),
                                     new SqlParameter("@operacao", "PARCELAS"),
                                     new SqlParameter("@obs",      "GERAÇÃO BOLETOS"),
                                     new SqlParameter("@acao",     fwObs_Log) };
        uLog.MakeLog(param_log);
        // FIM CRIA LOG ===============================================================================================================================================
        //
        //
        btprocessa.Enabled = false;
        //ScriptManager.RegisterStartupScript(UpdatePanel, GetType(), "msgbox", "alert('Configuração Registrada!');", true);
    }