// GET: Recebimentos/Create
        public ActionResult Create()
        {
            var model = new Recebimentos();

            model.Data = DateTime.Now;

            ViewBag.Vendas = new SelectList(db.Vendas.ToList().OrderBy(i => i.PedidoId), "PedidoId", "PedidoId");
            return(View(model));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Recebimentos recebimentos = db.Recebimentos.Find(id);

            db.Recebimentos.Remove(recebimentos);
            db.SaveChanges();
            AlternarPago(recebimentos);
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit(Recebimentos recebimentos)
 {
     recebimentos.Valor = recebimentos.Valor / 100;
     if (ModelState.IsValid)
     {
         db.Entry(recebimentos).State = EntityState.Modified;
         db.SaveChanges();
         AlternarPago(recebimentos);
         return(RedirectToAction("Index"));
     }
     return(View(recebimentos));
 }
        public ActionResult Create(Recebimentos recebimentos)
        {
            recebimentos.Valor = recebimentos.Valor / 100;
            if (ModelState.IsValid)
            {
                db.Recebimentos.Add(recebimentos);
                db.SaveChanges();
                AlternarPago(recebimentos);
                return(RedirectToAction("Index"));
            }

            return(View(recebimentos));
        }
        // GET: Recebimentos/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Recebimentos recebimentos = db.Recebimentos.Find(id);

            if (recebimentos == null)
            {
                return(HttpNotFound());
            }
            return(View(recebimentos));
        }
        // GET: Recebimentos/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Recebimentos recebimentos = db.Recebimentos.Find(id);

            ViewBag.Vendas = new SelectList(db.Vendas.ToList().OrderBy(i => i.PedidoId), "PedidoId", "PedidoId");
            if (recebimentos == null)
            {
                return(HttpNotFound());
            }
            return(View(recebimentos));
        }
        public void AlternarPago(Recebimentos recebimento)
        {
            var venda = db.Vendas.Find(recebimento.PedidoId);
            var valor = db.Database.SqlQuery <decimal>("SELECT SUM(Valor) FROM dbo.Recebimentos WHERE PedidoId = " + venda.PedidoId + " GROUP BY PedidoId").SingleOrDefault();

            if (venda.ValorTotal <= valor)
            {
                venda.Pago = true;
            }
            else
            {
                venda.Pago = false;
            }
            db.Entry(venda).State = EntityState.Modified;
            db.SaveChanges();
        }
 private void bt_retroceder_Click(object sender, EventArgs e)
 {
     Recebimentos recebimentos = new Recebimentos();
     recebimentos.Show();
     this.Hide();
 }