public ActionResult Edit(BoletoViewModel model) { if (ModelState.IsValid) { Boletos boleto = BoletoService.getBoleto(model.IDBoleto); model.NumeroBoleto = String.Concat(model.NumeroBoletoPart1, model.NumeroBoletoPart2, model.NumeroBoletoPart3, model.NumeroBoletoPart4, model.NumeroBoletoPart5, model.NumeroBoletoPart6, model.NumeroBoletoPart7, model.NumeroBoletoPart8); BoletoService.deleteBoletoOrcamentos(boleto.BoletosOrcamentos.ToList()); fillBoleto(boleto, model); BoletoService.saveBoleto(boleto); this.addMensagemSucesso("Boleto salvo com sucesso"); } else { return(View(model)); } return(RedirectToAction("Index", "Boleto")); }
public ActionResult Create(BoletoViewModel model) { if (ModelState.IsValid) { model.NumeroBoleto = String.Concat(model.NumeroBoletoPart1, model.NumeroBoletoPart2, model.NumeroBoletoPart3, model.NumeroBoletoPart4, model.NumeroBoletoPart5, model.NumeroBoletoPart6, model.NumeroBoletoPart7, model.NumeroBoletoPart8); if (BoletoService.getBoletos(model.NumeroBoleto).Count > 0) { this.addMensagemErro("Boleto já existe"); return(View(model)); } var boleto = new Boletos(); fillBoleto(boleto, model); BoletoService.saveBoleto(boleto); this.addMensagemSucesso("Boleto criado com sucesso!"); } else { model.ListaStatus = new List <SelectListItem>(); model.ListaStatus.AddRange(EnumHelper.toSelectList(new StatusBoleto())); return(View(model)); } return(RedirectToAction("Index", "Boleto")); }
private void fillBoleto(Boletos boleto, BoletoViewModel model) { boleto.IDCliente = Convert.ToInt32(model.IDCliente); boleto.IDUsuario = visitor.ID; boleto.NumeroBoleto = model.NumeroBoleto; if (model.Preco != null) { boleto.Preco = Convert.ToDouble(model.Preco.Value); } boleto.Status = model.Status.Value; boleto.DataEmissao = model.DataEmissao.Value; boleto.BoletosOrcamentos = new List <BoletosOrcamentos>(); boleto.IDUsuario = visitor.ID; if (model.Pedidos == null) { return; } foreach (var item in model.Pedidos) { boleto.BoletosOrcamentos.Add(new BoletosOrcamentos() { IDOrcamento = item, DataCriacao = DateTime.Now, IDUsuario = visitor.ID }); } }
public ActionResult LoadPedidos(int idCliente) { BoletoViewModel model = new BoletoViewModel(); model.ListaPedidosAberto = OrcamentoService.getPedidos(idCliente, null).Where(c => c.BoletosOrcamentos.Count == 0).Select(p => new OrcamentoBoletoViewModel(getViewModel(p))).ToList(); return(PartialView("_ListPedidos", model)); }
private BoletoViewModel getViewModel(Boletos boleto, bool isIndex) { List <Orcamentos> orcamentos = null; var idOrcamentosRelacionados = new List <int>(); var model = new BoletoViewModel() { IDBoleto = boleto.IDBoleto, IDCliente = boleto.IDCliente, NomeCliente = boleto.Clientes.Nome, DataEmissao = boleto.DataEmissao, NumeroBoleto = boleto.NumeroBoleto, NumeroBoletoPart1 = getSequenceBoleto(boleto.NumeroBoleto, 1), NumeroBoletoPart2 = getSequenceBoleto(boleto.NumeroBoleto, 2), NumeroBoletoPart3 = getSequenceBoleto(boleto.NumeroBoleto, 3), NumeroBoletoPart4 = getSequenceBoleto(boleto.NumeroBoleto, 4), NumeroBoletoPart5 = getSequenceBoleto(boleto.NumeroBoleto, 5), NumeroBoletoPart6 = getSequenceBoleto(boleto.NumeroBoleto, 6), NumeroBoletoPart7 = getSequenceBoleto(boleto.NumeroBoleto, 7), NumeroBoletoPart8 = getSequenceBoleto(boleto.NumeroBoleto, 8), Preco = Convert.ToDouble(boleto.Preco), Status = boleto.Status, DescricaoStatus = EnumHelper.getEnumDescription((StatusBoleto)boleto.Status) }; model.ListaStatus = new List <SelectListItem>(); model.ListaStatus.AddRange(EnumHelper.toSelectList(new StatusBoleto())); if (!isIndex) { //Obtem todos os pedidos aprovados do cliente em específico orcamentos = OrcamentoService.getPedidos(boleto.IDCliente, null); model.ListaPedidosAberto = orcamentos.Select(p => new OrcamentoBoletoViewModel(getViewModel(p))).ToList(); //Obtem os orçamentos já relacionados em outros boletos boleto.BoletosOrcamentos.ForEach(c => idOrcamentosRelacionados.Add(c.IDBoletoOrcamento)); var idOrcamentosNaoRelacionados = orcamentos.Where( c => c.BoletosOrcamentos.Count(d => !idOrcamentosRelacionados.Contains(d.IDBoletoOrcamento)) > 0).Select(e => e.IDOrcamento).ToList(); //Checa os que estão relacionados ao boleto model.ListaPedidosAberto = model.ListaPedidosAberto.GroupJoin(boleto.BoletosOrcamentos, pedido => pedido.IDOrcamento, pedidoSelecionado => pedidoSelecionado.IDOrcamento, (pedido, pedidoSelecionado) => pedidoSelecionado.Select(ps => new OrcamentoBoletoViewModel(pedido, true)) .DefaultIfEmpty(new OrcamentoBoletoViewModel(pedido, false))) .SelectMany(pedidoSelecionado => pedidoSelecionado).ToList(); //Retira os pedidos que estão relacionados a outros boletos model.ListaPedidosAberto.RemoveAll( c => c.IDOrcamento != null && (!c.IsSelected && idOrcamentosNaoRelacionados.Contains(c.IDOrcamento.Value))); } return(model); }
public ActionResult Create() { var model = new BoletoViewModel { ListaStatus = new List <SelectListItem>() }; model.ListaStatus.AddRange(EnumHelper.toSelectList(new StatusBoleto())); return(View(model)); }
public async Task <IActionResult> ObterBoleto([FromBody] BoletoViewModel model) { return(await Task.Run(() => { var dataBytes = _gerenciador.GerarBoletoPdf(model); var nomeArquivo = $"Boleto_{DateTime.Now.Year}{DateTime.Now.Month}{DateTime.Now.Day}{DateTime.Now.Hour}" + $"{DateTime.Now.Minute}{DateTime.Now.Second}"; HttpContext.Response.Headers.Add("Content-Type", "application/pdf"); HttpContext.Response.Headers.Add("Content-Filename", nomeArquivo); HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Filename"); HttpContext.Response.Headers.Add("Content-Disposition", $"attachment; filename=\"{nomeArquivo}.pdf\""); var ms = dataBytes.ToStream(); return File(ms, "application/pdf", $"{nomeArquivo}.pdf"); })); }
public async Task <ActionResult> Create(BoletoViewModel boleto) { try { await _boletoService.Create(HelperMapper.Mapper.Map <Boleto>(boleto)); } catch (Exception) { return(new JsonResult("Oops! algo salio mal.") { StatusCode = 400 }); } return(new JsonResult("OK") { StatusCode = 200 }); }
public string MontaHtmlEmbedded(BoletoViewModel model) { var novoBoletoBancarioPdf = new BoletoBancarioPdf(); if (model == null) { return(null); } var boleto = Popula(model); if (boleto != null) { novoBoletoBancarioPdf.Boleto = boleto; } else { return(null); } return(novoBoletoBancarioPdf.MontaHtmlEmbedded()); }
public byte[] GerarBoletoPdf(BoletoViewModel model) { var novoBoletoBancarioPdf = new BoletoBancarioPdf(); if (model == null) { return(null); } var boleto = Popula(model); if (boleto != null) { novoBoletoBancarioPdf.Boleto = boleto; } else { return(null); } return(novoBoletoBancarioPdf.MontaBytesPDF()); }
public byte[] ObterBoletoHtml(BoletoViewModel model) { var boleto = Popula(model); return(boleto?.ImprimirHtml()); }
private Boleto Popula(BoletoViewModel model) { if (model.Banco.Codigo != null) { var banco = Banco.Instancia(model.Banco.Codigo.Value); banco.Beneficiario = new Beneficiario { Codigo = model.Banco.Beneficiario.Codigo, CPFCNPJ = model.Banco.Beneficiario.CPFCNPJ, Nome = model.Banco.Beneficiario.Nome, Observacoes = model.Banco.Beneficiario.Observacoes, CodigoDV = model.Banco.Beneficiario.CodigoDV, CodigoTransmissao = model.Banco.Beneficiario.CodigoTransmissao, ContaBancaria = new ContaBancaria { Agencia = model.Banco.Beneficiario.ContaBancaria.Agencia, DigitoAgencia = model.Banco.Beneficiario.ContaBancaria.DigitoAgencia, OperacaoConta = model.Banco.Beneficiario.ContaBancaria.OperacaoConta, Conta = model.Banco.Beneficiario.ContaBancaria.Conta, DigitoConta = model.Banco.Beneficiario.ContaBancaria.DigitoConta, CarteiraPadrao = model.Banco.Beneficiario.ContaBancaria.CarteiraPadrao, VariacaoCarteiraPadrao = model.Banco.Beneficiario.ContaBancaria.VariacaoCarteiraPadrao, TipoCarteiraPadrao = (TipoCarteira)Enum.ToObject(typeof(TipoCarteira), (int)model.Banco.Beneficiario.ContaBancaria.TipoCarteiraPadrao), TipoFormaCadastramento = (TipoFormaCadastramento)Enum.ToObject(typeof(TipoFormaCadastramento), (int)model.Banco.Beneficiario.ContaBancaria.TipoFormaCadastramento), TipoImpressaoBoleto = (TipoImpressaoBoleto)Enum.ToObject(typeof(TipoImpressaoBoleto), (int)model.Banco.Beneficiario.ContaBancaria.TipoImpressaoBoleto), TipoDocumento = (TipoDocumento)Enum.ToObject(typeof(TipoDocumento), (int)model.Banco.Beneficiario.ContaBancaria.TipoDocumento) }, Endereco = new Endereco { LogradouroEndereco = model.Banco.Beneficiario.Endereco.LogradouroEndereco, LogradouroNumero = model.Banco.Beneficiario.Endereco.LogradouroNumero, LogradouroComplemento = model.Banco.Beneficiario.Endereco.LogradouroComplemento, Bairro = model.Banco.Beneficiario.Endereco.Bairro, Cidade = model.Banco.Beneficiario.Endereco.Cidade, UF = model.Banco.Beneficiario.Endereco.UF, CEP = model.Banco.Beneficiario.Endereco.CEP } }; banco.FormataBeneficiario(); // 'CRIAÇÃO DO TITULO var titulo = new Boleto(banco) { Pagador = new Pagador() { CPFCNPJ = model.Pagador.CPFCNPJ, Nome = model.Pagador.Nome, Observacoes = model.Pagador.Observacoes, Endereco = new Endereco { Bairro = model.Pagador.Endereco.Bairro, CEP = model.Pagador.Endereco.CEP, Cidade = model.Pagador.Endereco.Cidade, UF = model.Pagador.Endereco.UF, LogradouroEndereco = model.Pagador.Endereco.LogradouroEndereco, LogradouroComplemento = model.Pagador.Endereco.LogradouroComplemento, LogradouroNumero = model.Pagador.Endereco.LogradouroNumero, } }, CodigoMotivoOcorrencia = model.CodigoMotivoOcorrencia, NumeroDocumento = model.NumeroDocumento, NumeroControleParticipante = model.NumeroControleParticipante, NossoNumero = model.NossoNumero, DataEmissao = DateTime.Now.Date, DataVencimento = DateTime.Now.Date.AddDays(30), DataDesconto = DateTime.Now.Date.AddDays(30), ValorDesconto = model.ValorDesconto, ValorTitulo = model.ValorTitulo, Aceite = model.Aceite, EspecieDocumento = (TipoEspecieDocumento)Enum.ToObject(typeof(TipoEspecieDocumento), (int)model.EspecieDocumento), // PARTE DA MULTA DataMulta = DateTime.Now.Date.AddDays(30), PercentualMulta = 2, ValorMulta = model.ValorTitulo * model.PercentualMulta / 100, MensagemInstrucoesCaixa = $"Cobrar multa de {(model.ValorTitulo * model.PercentualMulta / 100).ToString("F", CultureInfo.InvariantCulture)} após a data de vencimento.", // PARTE JUROS DE MORA DataJuros = DateTime.Now.Date.AddDays(30), PercentualJurosDia = 10m / 30, ValorJurosDia = model.ValorTitulo * model.PercentualJurosDia / 100, CodigoProtesto = TipoCodigoProtesto.NaoProtestar, DiasProtesto = 0, CodigoBaixaDevolucao = TipoCodigoBaixaDevolucao.NaoBaixarNaoDevolver, DiasBaixaDevolucao = 0 }; var instrucoes = $"Cobrar juros de {titulo.PercentualJurosDia.ToString("F", CultureInfo.InvariantCulture)} por dia."; if (string.IsNullOrEmpty(titulo.MensagemInstrucoesCaixa)) { titulo.MensagemInstrucoesCaixa = instrucoes; } else { titulo.MensagemInstrucoesCaixa += Environment.NewLine + instrucoes; } titulo.ValidarDados(); return(titulo); } return(null); }
public IActionResult Checkout(Order order) { var cartSessionText = HttpContext.Session.GetString(SessionCart); Cart cart = JsonConvert.DeserializeObject <Cart>(cartSessionText); var customer = _customerService.Get(Convert.ToInt32(User.Identity.AuthenticationType)); if (User?.Identity?.IsAuthenticated == true && customer != null) { if (cart.Itens.Count > 0) { order.CustomerId = customer.CustomerId; order.Itens = cart.Itens; order.OrderDate = DateTime.Now; order.PaymentDate = DateTime.Now; // order.PaymentMethod = Order.EPaymentMethod.Boleto; if (order.PaymentMethod == Order.EPaymentMethod.Boleto) { order.OrderStatus = Order.EStatusOrder.Concluido; } else { order.OrderStatus = Order.EStatusOrder.AguardandoPagamento; } foreach (var item in order.Itens) { var p = _productService.Get(item.Product.ProductId); p.Quantity -= item.Quantity; _productService.Update(p); } order.OrderId = _orderService.Insert(order); order.TicketNumber = 1000000 + order.OrderId; foreach (var item in order.Itens) { item.ProductId = (int)item.Product.ProductId; item.OrderId = (int)order.OrderId; item.Price = item.Product.Price; _cartItemService.Insert(item); } ViewBag.Message = "Compra Realizada com sucesso ! Número do pedido :" + order.TicketNumber; HttpContext.Session.Clear(); if (order.PaymentMethod == Order.EPaymentMethod.Boleto) { BoletoViewModel boleto = new BoletoViewModel(); boleto.Order = order; boleto.Order.Customer = customer; return(View("Boleto", boleto)); } else if (order.PaymentMethod == Order.EPaymentMethod.PagamentoConta) { return(View("WaitingPayment", customer)); } return(View()); } else { return(View()); } } else { return(RedirectToAction("Login", "Account")); } }