Пример #1
0
 public ActionResult EliminarArticulo(VentasAgregarViewModel aVM)
 {
     if (ModelState.IsValid)
     {
         if (aVM.ArticuloIdAgregar == 0)
         {
             ViewBag.Error = "No pudo eliminarse el artículo, vuelva a intentarlo.";
         }
         else
         {
             if (aVM.Items.Any(a => a.ArticuloID == aVM.ArticuloIdAgregar))
             {
                 ModelState.Clear();
                 var item = aVM.Items.Find(a => a.ArticuloID == aVM.ArticuloIdAgregar);
                 aVM.Items.Remove(item);
                 aVM.ArticuloIdAgregar = 0;
             }
             else
             {
                 ViewBag.Error = "No pudo eliminarse el artículo, vuelva a intentarlo.";
             }
         }
     }
     else
     {
         ViewBag.Error = "No pudo eliminarse el artículo, vuelva a intentarlo.";
     }
     return(View("Agregar", aVM));
 }
Пример #2
0
        public ActionResult Agregar(VentasAgregarViewModel aVM, string mensaje)
        {
            //Valido que no se pueda realizar una venta cuando la sucursal es "Depósito"
            sucID = (int)System.Web.HttpContext.Current.Session["SucursalActual"];
            if (sucID == 1)
            {
                return(RedirectToAction("ErrorPermisoNuevaVenta", "Base"));
            }

            if (aVM == null)
            {
                aVM = new VentasAgregarViewModel();
            }

            if (mensaje != "" && mensaje != null)
            {
                ViewBag.Informacion = mensaje;
            }
            if (System.Web.HttpContext.Current.Session["SaldoAFavor"] != null)
            {
                aVM.SaldoAFavor = decimal.Parse(System.Web.HttpContext.Current.Session["SaldoAFavor"].ToString());
            }

            return(View(aVM));
        }
Пример #3
0
 public ActionResult AplicarDescuento(VentasAgregarViewModel aVM)
 {
     if (ModelState.IsValid)
     {
         //if (aVM.ArticuloIdAgregar == null || aVM.ArticuloIdAgregar == 0)
         //{
         //    ViewBag.Error = "No pudo agregarse el artículo, vuelva a intentarlo.";
         //}
         //else
         //{
         //    aVM.Items.Add(_ventaItemsServicios.AgregarArticuloEnVenta(aVM.ArticuloIdAgregar));
         //}
     }
     else
     {
         ViewBag.Error = "No pudo aplicarse el descuento, vuelva a intentarlo.";
     }
     return(View("Agregar", aVM));
 }
Пример #4
0
 public ActionResult RestarArticulo(VentasAgregarViewModel aVM)
 {
     if (ModelState.IsValid)
     {
         if (aVM.ArticuloIdAgregar == 0)
         {
             ViewBag.Error = "No pudo restarse el artículo, vuelva a intentarlo.";
         }
         else
         {
             if (aVM.Items.Any(a => a.ArticuloID == aVM.ArticuloIdAgregar))
             {
                 var cantActual = aVM.Items.Find(a => a.ArticuloID == aVM.ArticuloIdAgregar).Cantidad;
                 if (cantActual <= 1)
                 {
                     ViewBag.Error = "La cantidad del artículo no puede ser 0.";
                 }
                 else
                 {
                     ModelState.Clear();
                     aVM.Items.Find(a => a.ArticuloID == aVM.ArticuloIdAgregar).Cantidad = cantActual - 1;
                     aVM.ArticuloIdAgregar = 0;
                 }
             }
             else
             {
                 ViewBag.Error = "No pudo restarse el artículo, vuelva a intentarlo.";
             }
         }
     }
     else
     {
         ViewBag.Error = "No pudo restarse el artículo, vuelva a intentarlo.";
     }
     return(View("Agregar", aVM));
 }
Пример #5
0
        public ActionResult AgregarArticulo(VentasAgregarViewModel aVM, string articulo)
        {
            if (aVM.ArticuloIdAgregar != 0)
            {
                if (articulo != "" && articulo != null)
                {
                    var art = _articulosServicios.GetByNameOrCode(articulo);
                    aVM.ArticuloIdAgregar = art.FirstOrDefault().Id; //Int64.Parse(articulo);
                }
            }


            if (ModelState.IsValid)
            {
                if (System.Web.HttpContext.Current.Session["SaldoAFavor"] != null)
                {
                    aVM.SaldoAFavor = decimal.Parse(System.Web.HttpContext.Current.Session["SaldoAFavor"].ToString());
                }
                //VentasAgregarViewModel aVM = new VentasAgregarViewModel();
                if (aVM.ArticuloIdAgregar == 0)
                {
                    var items = System.Web.HttpContext.Current.Session["ListaItemsVentaActual"];
                    aVM.Items = (List <VentaItem>)items;
                    try
                    {
                        if (aVM.Items.Count < 1)
                        {
                            ViewBag.Error = "No pudo agregarse el artículo, vuelva a intentarlo.";
                        }
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Error = "No pudo agregarse el artículo, vuelva a intentarlo.";
                        aVM.Items     = new List <VentaItem>();
                    }
                }
                else
                {
                    decimal cantStock = _stockArticuloSucursalServicios.GetStock(aVM.ArticuloIdAgregar, sucID);
                    if (cantStock > 0)
                    {
                        if (aVM.Items.Any(a => a.ArticuloID == aVM.ArticuloIdAgregar))
                        {
                            ModelState.Clear();
                            var cantActual = aVM.Items.Find(a => a.ArticuloID == aVM.ArticuloIdAgregar).Cantidad;
                            if (cantActual >= cantStock)
                            {
                                ViewBag.Error = "No hay stock suficiente para el artículo seleccionado.";
                            }
                            else
                            {
                                aVM.Items.Find(a => a.ArticuloID == aVM.ArticuloIdAgregar).Cantidad = cantActual + 1;
                            }
                            aVM.ArticuloIdAgregar = 0;
                        }
                        else
                        {
                            aVM.Items.Add(_ventaItemsServicios.AgregarArticuloEnVenta(aVM.ArticuloIdAgregar));
                            ModelState.Clear();
                            aVM.ArticuloIdAgregar = 0;
                        }
                        System.Web.HttpContext.Current.Session["ListaItemsVentaActual"] = aVM.Items;
                    }
                    else
                    {
                        ViewBag.Error = "No hay stock suficiente para el artículo seleccionado.";
                    }
                }
            }
            else
            {
                ViewBag.Error = "No pudo agregarse el artículo, vuelva a intentarlo.";
            }
            return(View("Agregar", aVM));
        }