Exemplo n.º 1
0
        public ActionResult get_articulo(string articulo)
        {
            Dat_Articulo_Stock        stk_articulo    = new Dat_Articulo_Stock();
            List <Ent_Articulo_Stock> listar_articulo = null;
            Ent_Articulo_Info         info_articulo   = null;
            string  mensaje      = "";
            string  estado       = "0";
            decimal total_precio = 0;
            decimal total_costo  = 0;

            try
            {
                info_articulo   = new Ent_Articulo_Info();
                listar_articulo = stk_articulo.listar_stock(articulo, ref info_articulo);

                if (listar_articulo.Count == 0)
                {
                    estado  = "0";
                    mensaje = "No hay stock del articulo ingresado";
                }
                else
                {
                    total_precio = listar_articulo.Where(c => c.id_almacen == "AQ").Sum(t => t.total) * info_articulo.precio;
                    total_costo  = listar_articulo.Where(c => c.id_almacen == "AQ").Sum(t => t.total) * info_articulo.costo;


                    estado  = "1";
                    mensaje = "";
                }

                Session[_session_stock_x_articulo]        = listar_articulo;
                Session[_session_stock_x_articulo_filtro] = listar_articulo.Where(s => s.id_almacen == "AQ").ToList();
            }
            catch
            {
            }

            return(Json(new { estado = estado, mensaje = mensaje, info = info_articulo, total_precio = total_precio, total_costo = total_costo }));
        }
Exemplo n.º 2
0
        public List <Ent_Articulo_Stock> listar_stock(string articulo, ref Ent_Articulo_Info info_articulo)
        {
            string sqlquery = "USP_MVC_CONSULTAR_ARTICULO";
            List <Ent_Articulo_Stock> listar = null;

            try
            {
                using (SqlConnection cn = new SqlConnection(Ent_Conexion.conexion))
                {
                    using (SqlCommand cmd = new SqlCommand(sqlquery, cn))
                    {
                        cmd.CommandTimeout = 0;
                        cmd.CommandType    = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@articulo", articulo);
                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            DataSet ds = new DataSet();
                            da.Fill(ds);

                            DataTable dtinfo = ds.Tables[0];
                            DataTable dtstk  = ds.Tables[1];
                            listar = new List <Ent_Articulo_Stock>();

                            if (ds.Tables.Count == 0)
                            {
                            }
                            else
                            {
                                if (dtinfo.Rows.Count > 0)
                                {
                                    info_articulo.codigo      = dtinfo.Rows[0]["Codigo"].ToString();
                                    info_articulo.descripcion = dtinfo.Rows[0]["descripcion"].ToString();
                                    info_articulo.marca       = dtinfo.Rows[0]["marca"].ToString();
                                    info_articulo.linea       = dtinfo.Rows[0]["linea"].ToString();
                                    info_articulo.color       = dtinfo.Rows[0]["color"].ToString();
                                    info_articulo.temporada   = dtinfo.Rows[0]["temporada"].ToString();
                                    info_articulo.precio      = Convert.ToDecimal(dtinfo.Rows[0]["precio"]);
                                    info_articulo.costo       = Convert.ToDecimal(dtinfo.Rows[0]["costo"]);
                                    info_articulo.foto        = dtinfo.Rows[0]["foto"].ToString();

                                    listar = (from row in dtstk.AsEnumerable()
                                              group row by new
                                    {
                                        idalmacen = row.Field <string>("id_almacen"),
                                        almacen = row.Field <string>("almacen"),
                                        articulo = row.Field <string>("articulo")
                                    } into g
                                              select new Ent_Articulo_Stock()
                                    {
                                        id_almacen = g.Key.idalmacen,
                                        almacen = g.Key.almacen,
                                        articulo = g.Key.articulo,
                                        total = g.Sum(s => s.Field <decimal>("cantidad")),
                                        list_talla = (from DataRow fila in
                                                      dtstk.AsEnumerable().Where(b => b.Field <string>("almacen") == g.Key.almacen &&
                                                                                 b.Field <string>("articulo") == g.Key.articulo)
                                                      select new Ent_Articulo_Talla()
                                        {
                                            talla = fila["talla"].ToString(),
                                            cantidad = Convert.ToInt32(fila["cantidad"]),
                                        }
                                                      ).ToList(),
                                        list_pedido_sep = (from DataRow fila in
                                                           dtstk.AsEnumerable().Where(b => b.Field <string>("almacen") == g.Key.almacen &&
                                                                                      b.Field <string>("articulo") == g.Key.articulo &&
                                                                                      b.Field <string>("ped_sep").Length > 0
                                                                                      )
                                                           select new Ent_Pedido_Sep()
                                        {
                                            talla = fila["talla"].ToString(),
                                            ped_sep = fila["ped_sep"].ToString(),
                                        }
                                                           ).ToList()
                                    }
                                              ).ToList();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                listar = new List <Ent_Articulo_Stock>();
            }
            return(listar);
        }