Example #1
0
        public static void EnviarBoletoPorEmail(int tituloRecorrenteId, string nomeArquivo, int modeloBoletoId, decimal valor, DateTime dataVencimento, string emailDestinatario, string AssuntoEmail, string TextoEmail)
        {
            var titulo         = new RepositorioTituloRecorrente().BuscarPorId(tituloRecorrenteId);
            var emailRemetente = titulo.Empresa.EmailFinanceiro;

            var boletoGeradoId = new RepositorioBoletoGerado().Listar(b => b.TituloRecorrenteId == titulo.Id && b.DataVencimento == dataVencimento).FirstOrDefault().Id.ToString();

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

            var boleto = Util.GerarBoletoBancario(tituloRecorrenteId, valor, dataVencimento, modeloBoletoId);
            var pdf    = StringToPdf(boleto.MontaHtmlEmbedded(false, true));
            var anexos = new List <Stream>();

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

            email.DispararMensagem();
        }
Example #2
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();
        }
Example #3
0
        public ActionResult Liquidar(DateTime dataVencimento, int tituloRecorrenteId)
        {
            RepositorioTituloRecorrente repo    = new RepositorioTituloRecorrente();
            TituloRecorrente            tituloR = repo.BuscarPorId(tituloRecorrenteId);

            ViewBag.TipoTitulo        = "TituloPendente";
            ViewBag.ControllerRetorno = Util.NomeControllerAnterior();
            ViewBag.ContaId           = new SelectList(new RepositorioConta().Listar(), "Id", "Nome", tituloR.ContaId);
            TituloViewModel tituloVm =
                new TituloViewModel()
            {
                TituloRecorrenteId = tituloRecorrenteId,
                CategoriaId        = tituloR.CategoriaId,
                Descricao          = tituloR.Nome,
                CentroCustoId      = tituloR.CentroCustoId,
                DataVencimento     = dataVencimento,
                PessoaId           = tituloR.PessoaId,
                Valor = tituloR.Valor
            };

            return(PartialView("~/Views/Titulo/_Liquidar.cshtml", tituloVm));
        }
        public void FaturaPaga(FaturaPaga data)
        {
            string id = data.id;
            var    db = new Contexto();

            var faturaGerada = db.FaturasGeradas.Where(x => x.IuguId == id).FirstOrDefault();

            UsuarioLogado.EmpresaId = faturaGerada.EmpresaId;
            var faturaResponse = BuscarFaturaIUGU(faturaGerada.IuguId);

            if (faturaGerada.TituloId != null)
            {
                var repo   = new RepositorioRecebimento();
                var titulo = repo.BuscarPorId((int)faturaGerada.TituloId);

                if (titulo.Liquidacoes.Count == 0)
                {
                    titulo.Liquidacoes.Add(
                        new Liquidacao()
                    {
                        Data       = DateTime.Parse(faturaResponse.paid_at.Substring(0, 10)).AddDays(2),
                        Valor      = (decimal)faturaResponse.items_total_cents / 100,
                        JurosMulta = faturaResponse.items_total_cents <faturaResponse.total_paid_cents ? (decimal)(faturaResponse.total_paid_cents - faturaResponse.items_total_cents) / 100 : 0,
                                                                       FormaLiquidacao = FormaLiquidacao.Boleto,
                                                                       TituloId = titulo.Id,
                                                                       Desconto = faturaResponse.items_total_cents> faturaResponse.total_paid_cents ? (decimal)(faturaResponse.items_total_cents - faturaResponse.total_paid_cents) / 100 : 0
                    }
                        );
                    repo.Alterar(titulo);
                }
            }
            else
            {
                var repo = new RepositorioTituloRecorrente();

                var             tituloRecorrente = repo.BuscarPorId((int)faturaGerada.TituloRecorrenteId);
                TituloViewModel titulo           = new TituloViewModel();

                titulo.CategoriaId        = tituloRecorrente.CategoriaId;
                titulo.CentroCustoId      = tituloRecorrente.CentroCustoId;
                titulo.ContaId            = tituloRecorrente.ContaId;
                titulo.DataVencimento     = faturaGerada.DataVencimento;
                titulo.PessoaId           = tituloRecorrente.PessoaId;
                titulo.Valor              = (decimal)faturaResponse.items_total_cents / 100;
                titulo.TituloRecorrenteId = tituloRecorrente.Id;
                titulo.Descricao          = tituloRecorrente.Nome;
                titulo.Observacao         = tituloRecorrente.Observacao;

                var liquidacao = new LiquidacaoViewModel()
                {
                    Data       = DateTime.Parse(faturaResponse.paid_at.Substring(0, 10)),
                    Valor      = (decimal)faturaResponse.items_total_cents / 100,
                    JurosMulta = faturaResponse.items_total_cents <faturaResponse.total_paid_cents ? (decimal)(faturaResponse.total_paid_cents - faturaResponse.items_total_cents) / 100 : 0,
                                                                   FormaLiquidacao = FormaLiquidacao.Boleto,
                                                                   Desconto = faturaResponse.items_total_cents> faturaResponse.total_paid_cents ? (decimal)(faturaResponse.items_total_cents - faturaResponse.total_paid_cents) / 100 : 0
                };

                titulo.Liquidacoes.Add(liquidacao);

                var novoTitulo = titulo.ToModel();
                RepositorioRecebimento repoTitulo = new RepositorioRecebimento();
                repoTitulo.Incluir(novoTitulo);
            }
        }