Exemplo n.º 1
0
        public async Task <ActionResult <detalle_venta> > PostDetalleVenta(detalle_venta detVenta)
        {
            _context.Detalle_Ventas.Add(detVenta);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDetalleVenta", new { id = detVenta.id_detalle_venta }, detVenta));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Putdetalle_venta(int id, detalle_venta detalle_Venta)
        {
            if (id != detalle_Venta.id_detalle_venta)
            {
                return(BadRequest());
            }

            //MI ENTIDAD YA TIENE LAS PROPIEDADDES O INFO QUE VOY A GUARDAR EN MY DB
            _context.Entry(detalle_Venta).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!detalle_ventaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
        void GuardarDetalle()
        {
            if (autoProducto.SelectedItem == null)
            {
                MessageBox.Show("Selecciona un prodcuto");
            }
            else
            {
                if (txtCantidad.Text == "")
                {
                    MessageBox.Show("Ingresa la cantidad del producto");
                }
                else
                {
                    dynamic producto = autoProducto.SelectedItem;
                    if (producto.existencias > 0)
                    {
                        if (producto.existencias > Int32.Parse(txtCantidad.Text))
                        {
                            int           idp    = producto.id_producto;
                            Decimal       precio = producto.precio;
                            detalle_venta dv     = new detalle_venta
                            {
                                venta_id    = idv,
                                producto_id = idp,
                                cantidad    = Int32.Parse(txtCantidad.Text),
                                precio      = precio,
                                subtotal    = Int32.Parse(txtCantidad.Text) * precio
                            };
                            BaseDatos.GetBaseDatos().detalle_venta.Add(dv);
                            BaseDatos.GetBaseDatos().SaveChanges();

                            var prd = BaseDatos.GetBaseDatos().productoes.Find(idp);
                            prd.existencias = prd.existencias - Int32.Parse(txtCantidad.Text);
                            BaseDatos.GetBaseDatos().SaveChanges();

                            totalven                  = totalven + (Int32.Parse(txtCantidad.Text) * precio);
                            txtTotal.Text             = totalven.ToString();
                            autoProducto.SelectedItem = null;
                            VistaGrid();
                            Limpiardetalle();
                        }
                        else
                        {
                            MessageBox.Show("Solo cuentas con: " + producto.existencias + "existencias");
                            txtCantidad.Text = String.Empty;
                        }
                    }
                    else
                    {
                        MessageBox.Show("No cuentas con existencias de: " + producto.nombre);
                        txtCantidad.Text          = String.Empty;
                        autoProducto.SelectedItem = null;
                        autoProducto.SearchText   = String.Empty;
                        txtPrecio.Text            = String.Empty;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            detalle_venta detalle_venta = db.detalle_venta.Find(id);

            db.detalle_venta.Remove(detalle_venta);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "iddetalle_venta,idventa,idarticulo,cantidad,precio_venta,descuento")] detalle_venta detalle_venta)
 {
     if (ModelState.IsValid)
     {
         db.Entry(detalle_venta).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.idarticulo = new SelectList(db.articuloes, "idarticulo", "codigo", detalle_venta.idarticulo);
     ViewBag.idventa    = new SelectList(db.ventas, "idventa", "tipo_comprobante", detalle_venta.idventa);
     return(View(detalle_venta));
 }
Exemplo n.º 6
0
        // GET: /Detalle_Venta/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            detalle_venta detalle_venta = db.detalle_venta.Find(id);

            if (detalle_venta == null)
            {
                return(HttpNotFound());
            }
            return(View(detalle_venta));
        }
Exemplo n.º 7
0
        // GET: /Detalle_Venta/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            detalle_venta detalle_venta = db.detalle_venta.Find(id);

            if (detalle_venta == null)
            {
                return(HttpNotFound());
            }
            ViewBag.idarticulo = new SelectList(db.articuloes, "idarticulo", "codigo", detalle_venta.idarticulo);
            ViewBag.idventa    = new SelectList(db.ventas, "idventa", "tipo_comprobante", detalle_venta.idventa);
            return(View(detalle_venta));
        }
Exemplo n.º 8
0
 public async Task <IActionResult> PutDetalleVenta(int id, detalle_venta detVenta)
 {
     if (id != detVenta.id_detalle_venta)
     {
         return(BadRequest());
     }
     _context.Entry(detVenta).State = EntityState.Modified;
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!DetalleVentaExists(id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(NoContent());
 }
Exemplo n.º 9
0
        public ActionResult Anular(int?id)
        {
            ViewBag.Error = "";
            if (id != null)
            {
                venta Venta = db.venta.Find(id);
                if (Venta != null)
                {
                    try
                    {
                        db.venta.Remove(Venta);
                        //primero debemos selecionar todos los detalles de compra para luego sacar el producto a reestaurar

                        var sale = (from detalle in db.detalle_venta
                                    where detalle.id_venta == id
                                    select new
                        {
                            id_detalle = detalle.id_detalle_venta
                        }).ToArray();
                        //instancias a las clases de prodcuto detalle venta y detalle producto que es quien nos interesa
                        detalle_venta    dv = new detalle_venta();
                        detalle_producto dp = new detalle_producto();

                        foreach (var item in sale)
                        {
                            dv = db.detalle_venta.Where(x => x.id_detalle_venta == item.id_detalle).SingleOrDefault();
                            //dp = db.detalle_producto.Where(x => x.id_producto == dv.id_producto).SingleOrDefault();
                            var detProd = (from table in db.detalle_producto
                                           where table.id_producto == dv.id_producto && table.stock < (table.numero_caja * table.undxcajas)
                                           select new
                            {
                                id_detalle_producto = table.id_detalle_producto               //ya obtuvimos los de detalle con stock y activos, para luegos restarlos
                            }).OrderByDescending(x => x.id_detalle_producto).ToArray();

                            int cantTemp = dv.cantidad; int stockAct, diferencia;
                            foreach (var d in detProd)
                            {
                                var detalle_productoreestar = db.detalle_producto.Where(x => x.id_detalle_producto == d.id_detalle_producto).SingleOrDefault();
                                stockAct = Convert.ToInt32(detalle_productoreestar.stock);
                                int stockLimit = Convert.ToInt32(detalle_productoreestar.numero_caja) * Convert.ToInt32(detalle_productoreestar.undxcajas);
                                diferencia = stockLimit - stockAct;
                                if (cantTemp == 0)
                                {
                                    break;
                                }
                                else
                                {
                                    if (cantTemp <= diferencia)
                                    {
                                        detalle_productoreestar.stock = detalle_productoreestar.stock + cantTemp;
                                        cantTemp = 0;
                                        //quiere decir de lo la cantidad alcanza en ese registro
                                        //if (diferencia!=0)//por que si diferencia es igual a 0 quiere decir que ese registro ya esta a tope
                                        //{
                                        //}
                                    }
                                    else
                                    {
                                        detalle_productoreestar.stock = detalle_productoreestar.stock + diferencia;
                                        cantTemp = cantTemp - diferencia;
                                    }
                                }
                            }
                        }
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        ViewBag.Error = "No se pudo eliminar la venta";
                        throw;
                    }
                }
                else
                {
                    //no se encontro la venta para elimnar
                }
            }
            else
            {
                //no se encontro la venta
            }

            return(RedirectToAction("index"));
        }
Exemplo n.º 10
0
        public JsonResult Create(int id_cliente, decimal subtotal, detalle_venta[] detalle)
        {
            ResponseModel result = new ResponseModel();

            result.Respuesta = false;
            detalle_producto detProducto = new detalle_producto();

            //string result = "Error! No se pudo guardar!";
            if (id_cliente != 0 && id_cliente >= 0 && subtotal != 0)
            {
                DateTime fecha_    = DateTime.Now;
                var      UserLogin = (usuario)Session["User"];
                int      idUser    = Convert.ToInt32(UserLogin.id_usuario);
                try
                {
                    var SaveVenta = new venta
                    {
                        id_usuario = idUser,
                        fecha      = fecha_,
                        total      = subtotal,
                        iva        = 0,
                        descuento  = 0,
                        id_cliente = id_cliente,
                        id_estado  = 3,
                    };
                    db.venta.Add(SaveVenta);

                    foreach (var item in detalle)
                    {
                        var Detalle = new detalle_venta
                        {
                            id_producto = item.id_producto,
                            cantidad    = item.cantidad,
                            precio      = item.precio,
                            subtotal    = item.cantidad * item.precio,
                            iva         = 0,
                            descuento   = 0
                        };
                        db.detalle_venta.Add(Detalle);
                        //debemos de bajar el stockdel detalle de producto correspondiente
                        //detProducto = db.detalle_producto.Where(x => x.id_producto == item.id_producto && x.estado==true && x.id_detalle_producto.min).SingleOrDefault();
                        var detProd = (from table in db.detalle_producto
                                       where table.id_producto == item.id_producto && table.stock != 0
                                       select new
                        {
                            id_detalle_producto = table.id_detalle_producto            //ya obtuvimos los de detalle con stock y activos, para luegos restarlos
                        }).ToArray();
                        int stockAct, comprobar = 0, reestante;
                        int CanTemp = item.cantidad;
                        ///vamos a ver cuanto tiene el primer registro con stock activo
                        ///var dp1= db.detalle_producto.Where(x=>x.id_detalle_producto==detProd[0]).
                        foreach (var d in detProd)
                        {
                            var detalle_productoreestar = db.detalle_producto.Where(x => x.id_detalle_producto == d.id_detalle_producto).SingleOrDefault();
                            stockAct = Convert.ToInt32(detalle_productoreestar.stock);
                            if (CanTemp == 0)
                            {
                                comprobar = 1;
                                break;
                            }
                            else
                            {//segui iterando
                                if (CanTemp <= stockAct)
                                {
                                    detalle_productoreestar.stock = detalle_productoreestar.stock - CanTemp;
                                    CanTemp = CanTemp - CanTemp;
                                }
                                else//quiere decir que la cantidad es mayor, para que luego itere al siguiente registro de detalleproducto
                                {
                                    CanTemp = CanTemp - stockAct;
                                    detalle_productoreestar.stock = 0;
                                }
                            }
                        }
                    }
                    db.SaveChanges();
                    result.Respuesta = true;
                    result.Error     = "Venta guardada con exito!";
                }
                catch (Exception)
                {
                    throw;
                    //result.Error = "La Venta no se pudo guardar.";
                }
            }
            else
            {
                result.Respuesta = false;
                result.Error     = "No se pudo guardar la venta";
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }