Ejemplo n.º 1
0
        public void Ganacia(string fechai, string fechaf)
        {
            Reportes.DiarioEnc enc = new Reportes.DiarioEnc();
            enc.fecha = fechai;
            enc.F2    = fechaf;
            fechai   += " 00:00:00";
            fechaf   += " 23:59:59";
            string consulta = "SELECT v.id_venta, vd.id_detalle,Date_format(v.FECHA_H,'%d/%m/%Y') ,COUNT(vd.ID_DETALLE ),SUM((vd.cantidad*vd.precio)),v.Descu, (SUM(((vd.cantidad*vd.precio)-(vd.cantidad*p.precio_c)))-v.descu) AS ganancia FROM venta v " +
                              "INNER JOIN detalle vd ON vd.ID_VENTA = v.ID_VENTA " +
                              "INNER JOIN producto p on vd.ID_PROD = p.ID_PROD " +
                              "WHERE v.FECHA_H >= '" + fechai + "' AND v.FECHA_H <= '" + fechaf + "' " +
                              "GROUP BY v.ID_VENTA";
            DataTable datos = new DataTable();

            datos = buscar(consulta);

            int cont, cant = datos.Rows.Count;

            for (cont = 0; cont < cant; cont++)
            {
                Reportes.DiarioDet detalle = new Reportes.DiarioDet();
                detalle.orden = int.Parse(datos.Rows[cont][0].ToString());
                //Productos vendidos
                detalle.cantidad = int.Parse(datos.Rows[cont][3].ToString());
                //total Vendido
                detalle.precio = decimal.Parse(datos.Rows[cont][4].ToString()) - decimal.Parse(datos.Rows[cont][5].ToString());
                //Ganacia
                detalle.subtotal = decimal.Parse(datos.Rows[cont][6].ToString());
                string f = datos.Rows[cont][2].ToString();
                //DateTime fecha = DateTime.Parse(datos.Rows[cont][2].ToString());
                detalle.marca = f;
                enc.Detalle.Add(detalle);
            }
            Reportes.Ganancia gan = new Reportes.Ganancia();
            gan.Encabezado.Add(enc);
            gan.Detalle = enc.Detalle;
            gan.Show();
        }