Esempio n. 1
0
        public List <LoteBoleto> ChamarProcedimento(Filtro filtro)
        {
            DateTime dataInicial = Convert.ToDateTime(filtro.ValorPorNome("data_inicial"));
            DateTime dataFinal   = Convert.ToDateTime(filtro.ValorPorNome("data_final"));
            String   tipo        = filtro.ValorPorNome("tipo_pessoa");
            int?     tipoPessoa  = null;

            if (!String.IsNullOrWhiteSpace(tipo))
            {
                tipoPessoa = Convert.ToInt32(tipo);
            }

            ModeloBoleto modeloBoleto = new RepositorioModeloBoleto().BuscarPorId(Convert.ToInt32(filtro.ValorPorNome("modelo_boleto")));

            List <TituloPendente> titulos = GeradorTitulosPendentes.ChamarProcedimento(dataInicial, dataFinal, tipoPessoa).Where(i => i.Direcao == DirecaoCategoria.Recebimento).Where(m => m.ContaId == modeloBoleto.ContaId).ToList();

            var loteboletos = new List <LoteBoleto>();

            foreach (var titulo in titulos)
            {
                loteboletos.Add(
                    new LoteBoleto {
                    TituloId           = titulo.TituloId,
                    TituloRecorrenteId = titulo.TituloRecorrenteId,
                    Boleto             = true,
                    DataVencimento     = titulo.DataVencimento,
                    NomePessoa         = titulo.NomePessoa,
                    Valor             = titulo.Valor.GetValueOrDefault(0.0M),
                    ModeloBoletoId    = modeloBoleto.Id,
                    EmailDestinatario = new RepositorioPessoa().BuscarPorId(titulo.PessoaId).EmailFinanceiro
                });
            }
            return(loteboletos);
        }
Esempio n. 2
0
        public FileResult GerarRemessa(string postedData)
        {
            var    js           = new JavaScriptSerializer();
            var    loteboletos  = js.Deserialize <List <LoteBoleto> >(postedData);
            var    random       = Path.GetRandomFileName().Substring(0, 5);
            Boleto boletoGerado = new Boleto();

            MemoryStream   strm           = new MemoryStream();
            ArquivoRemessa arquivoRemessa = new ArquivoRemessa(TipoArquivo.CNAB400);
            Boletos        boletos        = new Boletos();

            var convenio = new RepositorioModeloBoleto().BuscarPorId(loteboletos.First().ModeloBoletoId).Convenio;

            foreach (var boleto in loteboletos)
            {
                if (boleto.TituloId != null)
                {
                    boletoGerado = Util.GerarBoleto((int)boleto.TituloId, boleto.ModeloBoletoId);
                }
                else
                {
                    boletoGerado = Util.GerarBoleto((int)boleto.TituloRecorrenteId, boleto.Valor, boleto.DataVencimento, boleto.ModeloBoletoId);
                }
                boletos.Add(boletoGerado);
            }

            arquivoRemessa.GerarArquivoRemessa(convenio, boletoGerado.Banco, boletoGerado.Cedente, boletos, strm, 1);

            return(File(strm.ToArray(), "text/plain", "teste.txt"));
        }
Esempio n. 3
0
        public ActionResult GerarBoleto(int tituloId, int modeloBoletoId)
        {
            var boletobancario = Util.GerarBoletoBancario(tituloId, modeloBoletoId);

            ViewBag.BoletoBancario = boletobancario.MontaHtmlEmbedded();
            ViewBag.TituloId       = tituloId;
            var modeloBoleto = new RepositorioModeloBoleto().BuscarPorId(modeloBoletoId);

            ViewBag.Email = new RepositorioRecebimento().BuscarPorId(tituloId).Pessoa.EmailFinanceiro;

            return(View(modeloBoleto));
        }
Esempio n. 4
0
        public ActionResult GerarBoleto(int tituloRecorrenteId, decimal valor, DateTime dataVencimento, int modeloBoletoId)
        {
            var boletobancario = Util.GerarBoletoBancario(tituloRecorrenteId, valor, dataVencimento, modeloBoletoId);

            ViewBag.BoletoBancario = boletobancario.MontaHtmlEmbedded();
            var modeloBoleto = new RepositorioModeloBoleto().BuscarPorId(modeloBoletoId);

            ViewBag.TituloRecorrenteId = tituloRecorrenteId;
            ViewBag.Valor          = valor;
            ViewBag.DataVencimento = dataVencimento;
            ViewBag.Email          = new RepositorioTituloRecorrente().BuscarPorId(tituloRecorrenteId).Pessoa.EmailFinanceiro;
            return(View("~/Views/Recebimento/GerarBoleto.cshtml", modeloBoleto));
        }
Esempio n. 5
0
        public static void EnviarBoletoPorEmail(LoteBoleto loteBoleto, string nomeArquivo)
        {
            string         emailDestinatario = "";
            string         emailRemetente    = "";
            BoletoBancario boleto            = null;
            var            modeloBoleto      = new RepositorioModeloBoleto().BuscarPorId(loteBoleto.ModeloBoletoId);
            string         boletoGeradoId    = null;

            if (loteBoleto.TituloId != null)
            {
                var titulo = new RepositorioRecebimento().BuscarPorId((int)loteBoleto.TituloId);
                emailDestinatario = loteBoleto.EmailDestinatario;
                emailRemetente    = titulo.Empresa.EmailFinanceiro;
                boleto            = Util.GerarBoletoBancario((int)loteBoleto.TituloId, loteBoleto.ModeloBoletoId);
                boletoGeradoId    = new RepositorioBoletoGerado().Listar(b => b.TituloId == titulo.Id).FirstOrDefault().Id.ToString();
            }
            if (loteBoleto.TituloRecorrenteId != null)
            {
                var titulo = new RepositorioTituloRecorrente().BuscarPorId((int)loteBoleto.TituloRecorrenteId);
                emailDestinatario = loteBoleto.EmailDestinatario;
                emailRemetente    = titulo.Empresa.EmailFinanceiro;
                boleto            = Util.GerarBoletoBancario((int)loteBoleto.TituloRecorrenteId, loteBoleto.Valor, loteBoleto.DataVencimento, loteBoleto.ModeloBoletoId);
                boletoGeradoId    = new RepositorioBoletoGerado().Listar(b => b.TituloRecorrenteId == titulo.Id && b.DataVencimento == loteBoleto.DataVencimento).FirstOrDefault().Id.ToString();
            }

            var pdf    = StringToPdf(boleto.MontaHtmlEmbedded(false, true));
            var anexos = new List <Stream>();

            anexos.Add(pdf);

            modeloBoleto.TextoEmail = modeloBoleto.TextoEmail.Replace("#tokenBoleto#", EnderecoHost() + "/AtualizacaoBoleto?tokenBoleto=" + Criptografia.Encriptar(boletoGeradoId));

            var email = new Email(emailDestinatario, modeloBoleto.TextoEmail, modeloBoleto.AssuntoEmail, emailRemetente, anexos, new List <string>()
            {
                Path.GetFileName(nomeArquivo)
            });

            email.DispararMensagem();
        }