protected void btn_excel2_Click(object sender, EventArgs e)
        {
            Response.Clear();

            Response.AddHeader("content-disposition", "attachment;filename=SOPRODI_2_" + DateTime.Now.ToShortDateString() + ".xls");

            Response.Charset = "";

            // If you want the option to open the Excel file without saving than

            // comment out the line below

            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.ContentType = "application/vnd.xls";

            System.IO.StringWriter stringWrite = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htmlWrite =
                new HtmlTextWriter(stringWrite);

            G_PRODUCTOS.Columns[0].Visible = false;

            G_PRODUCTOS.RenderControl(htmlWrite);

            Response.Write(stringWrite.ToString());

            Response.End();
        }
Exemple #2
0
        private void CARGAR_DIARIO2()
        {
            cont_det            = 1;
            G_PRODUCTOS.Visible = true;
            DataTable productos_diario = ReporteRNegocio.listar_diario2(USER);

            colum = productos_diario.Columns.Count;
            productos_diario.Columns.Add("Total");
            G_PRODUCTOS.DataSource = productos_diario;
            G_PRODUCTOS.DataBind();

            ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script> new Tablesort(document.getElementById('ContentPlaceHolder_Contenido_G_PRODUCTOS')); </script>", false);
        }
        protected void btn_productos_Click(object sender, EventArgs e)
        {
            //if (l_vendedores.Text != "" && l_clientes.Text != "" && txt_desde.Text != "" && txt_hasta.Text != "" && l_grupos.Text != "")
            //{
            string vendedores = agregra_comillas(l_vendedores.Text);
            string clientes   = agregra_comillas(l_clientes.Text);
            string desde      = txt_desde.Text;
            string hasta      = txt_hasta.Text;
            string grupos     = agregra_comillas(l_grupos.Text);;

            string grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario(User.Identity.Name.ToString()));

            if (grupos_del_usuario == "")
            {
                grupos_del_usuario = agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(User.Identity.Name.ToString()));
            }


            DataTable dt2; DataView dtv = new DataView();

            dt2 = ReporteRNegocio.carga_grupos(txt_desde.Text, txt_hasta.Text, grupos_del_usuario);
            if (dt2.Rows.Count <= 0)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script language='javascript'>NO_GRUPOS();</script>", false);
            }
            else
            {
                string es_vendedor = ReporteRNegocio.esvendedor(USER);
                where = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103)  and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";
                if (grupos != "")
                {
                    where = where + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where = where + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where = where + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }

                if (clientes != "")
                {
                    where = where + " and rutcliente in (" + clientes + ") ";
                }
                if (vendedores != "")
                {
                    where = where + " and codvendedor in (" + vendedores + ") ";
                }
                if (es_vendedor == "2")
                {
                    where += " and codvendedor in ('" + USER + "')";
                }

                div_productos.Visible = true;
                string periodos = ReporteRNegocio.listar_periodos_(" where FechaFactura >= CONVERT(datetime,'" + desde + "', 103)  and FechaFactura <= CONVERT(datetime,'" + hasta + "',103)");
                productos = ReporteRNegocio.listar_resumen_productos(periodos, where);
                PERIODOS  = periodos;
                DataView  view           = new DataView(productos);
                DataTable distinctValues = view.ToTable(true, "NombreCliente");

                productos.Columns.Add("Total");

                int colum = productos.Columns.Count;

                DataView dv = productos.DefaultView;
                dv.Sort   = "NombreCliente ASC";
                productos = dv.ToTable();

                Session["TaskTable"] = productos;

                header_sum             = true;
                cont_det               = 1;
                G_PRODUCTOS.DataSource = productos;
                //G_PRODUCTOS.Columns[colum - 1].Visible = false;
                //G_PRODUCTOS.Columns[colum - 2].Visible = false;
                G_PRODUCTOS.DataBind();

                //VOLVER A CARGAR LOS MULTISELECT

                DataTable dt = new DataTable();

                try
                {
                    dt = ReporteRNegocio.carga_grupos(desde, hasta, grupos_del_usuario);
                    //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                    DataView dv2 = dt.DefaultView;
                    dv2.Sort = "user1";
                    dt       = dv2.ToTable();
                    d_grupos_usuario.DataSource     = dt;
                    d_grupos_usuario.DataTextField  = "user1";
                    d_grupos_usuario.DataValueField = "user1";
                    //d_vendedor_.SelectedIndex = -1;
                    d_grupos_usuario.DataBind();


                    foreach (ListItem item in d_grupos_usuario.Items)
                    {
                        if (l_grupos.Text.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                    }
                }
                catch { }

                string where2 = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103) " +
                                " and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";

                if (grupos != "")
                {
                    where2 = where2 + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }

                if (es_vendedor == "2")
                {
                    where2 += " and codvendedor in ('" + USER + "')";
                }

                try
                {
                    dt = ReporteRNegocio.listar_ALL_vendedores(where2);
                    //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                    DataView dv2 = dt.DefaultView;
                    dv2.Sort = "cod_vend";
                    dt       = dv2.ToTable();
                    d_vendedor_.DataSource     = dt;
                    d_vendedor_.DataTextField  = "nom_vend";
                    d_vendedor_.DataValueField = "cod_vend";
                    //d_vendedor_.SelectedIndex = -1;
                    d_vendedor_.DataBind();


                    foreach (ListItem item in d_vendedor_.Items)
                    {
                        if (l_vendedores.Text.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                    }
                }
                catch { }
                where2 = "";
                where2 = " where FechaFactura >= CONVERT(datetime,'" + desde + "', 103) " +
                         " and FechaFactura <= CONVERT(datetime,'" + hasta + "',103) ";

                if (grupos != "")
                {
                    where2 = where2 + " and user1 in (" + grupos + ") ";
                }
                else if (es_vendedor != "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario(USER)) + ")";
                }
                else if (es_vendedor == "2")
                {
                    where2 = where2 + " and user1 in (" + agregra_comillas(ReporteRNegocio.grupos_usuario_v_report(USER)) + ")";
                }
                if (vendedores != "")
                {
                    where2 += " and codvendedor in (" + vendedores + ")";
                }
                if (es_vendedor == "2")
                {
                    where2 += " and codvendedor in ('" + USER + "')";
                }

                try
                {
                    dt = ReporteRNegocio.listar_ALL_cliente2(where2);
                    //dt.Rows.Add(new Object[] { "-1", "-- Todos --" });
                    DataView dv3 = dt.DefaultView;
                    dv3.Sort                 = "nom_cliente";
                    dt                       = dv3.ToTable();
                    d_cliente.DataSource     = dt;
                    d_cliente.DataTextField  = "nom_cliente";
                    d_cliente.DataValueField = "rut_cliente";
                    //d_vendedor_.SelectedIndex = -1;
                    d_cliente.DataBind();


                    foreach (ListItem item in d_cliente.Items)
                    {
                        if (l_clientes.Text.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                    }
                }
                catch { }

                ScriptManager.RegisterStartupScript(Page, this.GetType(), "teeee", "<script> new Tablesort(document.getElementById('ContentPlaceHolder_Contenido_G_PRODUCTOS')); </script>", false);
            }
        }
Exemple #4
0
        public void FiltrarProductos()
        {
            G_PRODUCTOS.Columns[8].Visible  = false;
            G_PRODUCTOS.Columns[9].Visible  = false;
            G_PRODUCTOS.Columns[10].Visible = false;
            G_PRODUCTOS.Columns[11].Visible = false;


            DBUtil db = new DBUtil();

            string columnas          = "";
            int    contador_columnas = 0;
            string precioabuscar     = "";
            string stockabuscar      = " 'XXXXXX' ";

            foreach (ListItem item in CB_BODEGA.Items)
            {
                if (item.Selected)
                {
                    contador_columnas++;
                    columnas += columnas == "" ? item.Text : ", " + item.Text;
                    if (item.Value == "ARICA")
                    {
                        precioabuscar += ", stock.arica_vent as 'precioventa" + contador_columnas + "', ISNULL(CAST((stock.arica_vent/und.unidad_equivale) as numeric), stock.arica_vent) as 'preciounitario" + contador_columnas + "' ";
                        stockabuscar  += ", 'ARICASOP' ";
                    }
                    else if (item.Value == "ETREDIRECT")
                    {
                        precioabuscar += ", stock.entrega_directa_V_RM as 'precioventa" + contador_columnas + "' , ISNULL(CAST((stock.entrega_directa_V_RM/und.unidad_equivale)  as numeric), 0) as 'preciounitario" + contador_columnas + "' ";
                    }
                    else if (item.Value == "IQUIQUE")
                    {
                        precioabuscar += ", stock.iquique as 'precioventa" + contador_columnas + "' , ISNULL(CAST((stock.iquique/und.unidad_equivale)  as numeric), stock.iquique) as 'preciounitario" + contador_columnas + "'  ";
                        stockabuscar  += ", 'ARICASOP' ";
                    }
                    else if (item.Value == "LOSANGELES")
                    {
                        precioabuscar += ", stock.bod_LA_vent as 'precioventa" + contador_columnas + "' , ISNULL(CAST((stock.bod_LA_vent/und.unidad_equivale)  as numeric), 0) as 'preciounitario" + contador_columnas + "'  ";
                        stockabuscar  += ", 'LOSANGELES' ";
                    }
                    else if (item.Value == "LZ_DESPACHO")
                    {
                        precioabuscar += ", stock.reparto_RM_V as 'precioventa" + contador_columnas + "' , ISNULL(CAST((stock.reparto_RM_V/und.unidad_equivale)  as numeric), 0) as 'preciounitario" + contador_columnas + "'  ";
                        stockabuscar  += ", 'ZARATESOP' ";
                    }
                    else if (item.Value == "ZARATE")
                    {
                        precioabuscar += ", stock.bod_LZ_vent as 'precioventa" + contador_columnas + "' , ISNULL(CAST((stock.bod_LZ_vent/und.unidad_equivale)  as numeric), 0) as 'preciounitario" + contador_columnas + "'  ";
                        stockabuscar  += ", 'ZARATESOP' ";
                    }
                    // 3
                    if (contador_columnas == 1)
                    {
                        G_PRODUCTOS.Columns[6].HeaderText = "($ Venta) " + item.Text;
                        G_PRODUCTOS.Columns[7].HeaderText = "($ Unit.) " + item.Text;
                    }
                    if (contador_columnas == 2)
                    {
                        G_PRODUCTOS.Columns[8].HeaderText = "($ Venta) " + item.Text;
                        G_PRODUCTOS.Columns[9].HeaderText = "($ Unit.) " + item.Text;
                        G_PRODUCTOS.Columns[8].Visible    = true;
                        G_PRODUCTOS.Columns[9].Visible    = true;
                    }
                    if (contador_columnas == 3)
                    {
                        G_PRODUCTOS.Columns[10].HeaderText = "($ Venta) " + item.Text;
                        G_PRODUCTOS.Columns[11].HeaderText = "($ Unit.) " + item.Text;
                        G_PRODUCTOS.Columns[10].Visible    = true;
                        G_PRODUCTOS.Columns[11].Visible    = true;
                    }
                }
            }
            if (contador_columnas > 3)
            {
                //alert("No se pueden seleccionar mas de 3 columnas de precio", "Atención", "rojo", 3000);
            }
            else if (contador_columnas >= 1)
            {
                if (contador_columnas == 1)
                {
                    precioabuscar += ", 0 as 'precioventa2', 0 as 'preciounitario2', 0 as 'precioventa3', 0 as 'preciounitario3' ";
                }
                else if (contador_columnas == 2)
                {
                    precioabuscar += ", 0 as 'precioventa3', 0 as 'preciounitario3' ";
                }

                //LB_BODEGA.Text = ": " + columnas;

                string query = "";
                query += " select X.* from (select stock.cod_producto, stock.producto, isnull(cat.nom_categ,'Sin Categoría') as 'nom_categ', ";
                // STOCK
                if (stockabuscar != " 'XXXXXX' ")
                {
                    query += " (select isnull(sum(sdc.TOTAL),0) from Stock_diario_CALCULADO sdc where sdc.invtid = stock.cod_producto and siteid in (" + stockabuscar + ")) as stock, ";
                }
                else
                {
                    query += " 99999 as stock, ";
                }
                query += " (select top(1) isnull([stkunit],'N/A') from Stock_diario_CALCULADO sdc where sdc.invtid = stock.cod_producto) as medida, " +
                         //
                         " isnull(catprod.id_categoria,19) as 'id_categoria', isnull(und.unidad_equivale,1) as unidad_equivale " + precioabuscar + " from Stock_Excel_2 stock" +
                         " left join Categoria_producto catprod on catprod.id_producto = stock.cod_producto " +
                         " left join categoria cat on cat.id = catprod.id_categoria " +
                         " left join unidad_stock_sp und on und.cod_prod = stock.cod_producto " +
                         " where stock.fecha = (select MAX(fecha) from stock_excel_2)) as X ";
                //if (stockabuscar != " 'XXXXXX' ")
                //{
                //    query += " where X.stock > 0  ";
                //}
                query += " order by X.stock desc, X.producto ";

                G_PRODUCTOS.DataSource = db.consultar(query);
                G_PRODUCTOS.DataBind();

                //if (stockabuscar != " 'XXXXXX' ")
                //{
                //    //
                //    query = query.Replace(" where X.stock > 0  ", "  where X.stock <= 0 ");
                //    G_PRODUCTOS2.DataSource = db.consultar(query);
                //    G_PRODUCTOS2.DataBind();
                //}
                //else
                //{
                //    query = query.Replace(" where X.stock > 0  ", "  where 1=2 ");
                //    G_PRODUCTOS2.DataSource = db.consultar(query);
                //    G_PRODUCTOS2.DataBind();
                //}

                string fecha = db.Scalar("select CONVERT(varchar,MAX(fecha), 103) from stock_excel_2").ToString();
                LB_FECHA_PRECIOS.Text = "FECHA LISTA DE PRECIO: " + fecha;
                //ScriptManager.RegisterStartupScript(this, typeof(Page), "AbreModal", "<script>javascript:abremodalproductos();</script>", false);
            }
            else
            {
                //alert("Seleccione al menos una columna precio", "Atención", "rojo", 2000);
            }

            // QUERY ANTIGUA DE RESPALDO
            //***************************
            //query += "select X.* from (select stock.cod_producto, stock.producto, isnull(cat.nom_categ,'Sin Categoría') as 'nom_categ', " +
            //   // STOCK
            //   " (select isnull(sum(sdc.TOTAL),0) from Stock_diario_CALCULADO sdc where sdc.invtid = stock.cod_producto) as stock, " +
            //   " (select top(1) isnull([stkunit],'N/A') from Stock_diario_CALCULADO sdc where sdc.invtid = stock.cod_producto) as medida, " +
            //   //
            //   " isnull(catprod.id_categoria,19) as 'id_categoria', isnull(und.unidad_equivale,1) as unidad_equivale " + precioabuscar + " from Stock_Excel_2 stock" +
            //   " left join Categoria_producto catprod on catprod.id_producto = stock.cod_producto " +
            //   " left join categoria cat on cat.id = catprod.id_categoria " +
            //   " left join unidad_stock_sp und on und.cod_prod = stock.cod_producto " +
            //   " where stock.fecha = (select MAX(fecha) from stock_excel_2)) as X where X.stock > 0 " +
            //   " order by X.nom_categ, X.producto ";
        }