Пример #1
0
        //Para reportes:
        public static List <CompraReporte> getReporteCompraSinFiltro(string orden)
        {
            string        CadenaConexion = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
            SqlConnection cn             = new SqlConnection(CadenaConexion);

            List <CompraReporte> compraReporte = new List <CompraReporte>();

            try
            {
                cn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                cmd.Parameters.Clear();
                cmd.CommandText = "SELECT  c.fecha, c.montoTotal, p.nombre as NombreProveedor, ixc.cantidad, ixc.monto_Parcial, i.nombre as NombreInsumo FROM Compra c INNER JOIN Proveedor p ON c.id_Proveedor= p.id_Proveedor INNER JOIN InsumoXCompra ixc ON ixc.codigo_Compra = c.codigo INNER JOIN Insumo i ON ixc.id_Insumo = i.id_Insumo order by " + orden;
                SqlDataReader dr = cmd.ExecuteReader();


                while (dr.Read())
                {
                    CompraReporte cpr = new CompraReporte();

                    cpr.fechaCompra     = (DateTime)dr["fecha"];
                    cpr.montoTotal      = (int)dr["montoTotal"];
                    cpr.montoParcial    = (int)dr["monto_Parcial"];
                    cpr.nombreProveedor = dr["NombreProveedor"].ToString();
                    cpr.cantidad        = (int)dr["cantidad"];
                    cpr.nombreInsumo    = dr["NombreInsumo"].ToString();

                    compraReporte.Add(cpr);
                }
                dr.Close();
            }

            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (cn != null && cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(compraReporte);
        }
Пример #2
0
        public DataTable ArmarExcel(string operacion, int flagExcel)
        {
            DataTable tablaExcel = new DataTable();

            //Validamos si es un reporte para Venta Minorista o para Compra
            if (flagExcel == Constants.COMPRA_EXCEL)
            {
                var numeroCompra = operacion.Split(',');

                Compra               compraInDB    = new Compra();
                CompraReporte        reporteTemp   = new CompraReporte();
                List <CompraReporte> compraReporte = new List <CompraReporte>();

                //Armamos la lista de compras para el reporte
                foreach (var item in numeroCompra)
                {
                    if (item != string.Empty)
                    {
                        compraInDB = compraBL.GetCompraByNumeroCompra(int.Parse(item));

                        //Guardamos los datos necesarios para el reporte
                        reporteTemp                 = new CompraReporte();
                        reporteTemp.ID              = compraInDB.NumeroCompra;
                        reporteTemp.Nombre          = compraInDB.Proveedor.Nombre == null ? " " : compraInDB.Proveedor.Nombre;
                        reporteTemp.Cuit            = compraInDB.Proveedor.Cuit == null ? " " : compraInDB.Proveedor.Cuit;
                        reporteTemp.Iibb            = compraInDB.Proveedor.Iibb == null ? " " : compraInDB.Proveedor.Iibb;
                        reporteTemp.Fecha           = compraInDB.Fecha.Date.ToString("dd/MM/yyyy");
                        reporteTemp.TipoFactura     = compraInDB.TipoFactura == null ? " " : compraInDB.TipoFactura;
                        reporteTemp.Factura         = compraInDB.Factura == null ? " " : compraInDB.Factura;
                        reporteTemp.SumaTotal       = String.Format("{0:c}", compraInDB.SumaTotal);
                        reporteTemp.DescuentoPorc   = compraInDB.DescuentoPorc;
                        reporteTemp.Descuento       = String.Format("{0:c}", compraInDB.Descuento);
                        reporteTemp.Subtotal        = String.Format("{0:c}", compraInDB.Subtotal);
                        reporteTemp.Iva             = compraInDB.Iva;
                        reporteTemp.ImporteIva      = String.Format("{0:c}", compraInDB.ImporteIva);
                        reporteTemp.ImporteIibbbsas = String.Format("{0:c}", compraInDB.ImporteIibbbsas);
                        reporteTemp.ImporteIibbcaba = String.Format("{0:c}", compraInDB.ImporteIibbcaba);
                        reporteTemp.ImportePercIva  = String.Format("{0:c}", compraInDB.ImportePercIva);
                        reporteTemp.Clasificacion   = compraInDB.Clasificacion.Nombre == null ? " " : compraInDB.Clasificacion.Nombre;
                        reporteTemp.Total           = String.Format("{0:c}", compraInDB.Total);


                        compraReporte.Add(reporteTemp);
                    }
                }

                //Generamos el datatable correspondiente
                tablaExcel.Columns.Add("Id", typeof(int));
                tablaExcel.Columns.Add("Proveedor", typeof(string));
                tablaExcel.Columns.Add("CUIT", typeof(string));
                tablaExcel.Columns.Add("IIBB", typeof(string));
                tablaExcel.Columns.Add("Mes Año", typeof(string));
                tablaExcel.Columns.Add("TIPO", typeof(string));
                tablaExcel.Columns.Add("Factura", typeof(string));
                tablaExcel.Columns.Add("Suma Total", typeof(string));
                tablaExcel.Columns.Add("Descuento %", typeof(double));
                tablaExcel.Columns.Add("Descuento", typeof(string));
                tablaExcel.Columns.Add("Subtotal", typeof(string));
                tablaExcel.Columns.Add("IVA", typeof(string));
                tablaExcel.Columns.Add("Importe IVA", typeof(string));
                tablaExcel.Columns.Add("IIBB BSAS", typeof(string));
                tablaExcel.Columns.Add("IIBB CABA", typeof(string));
                tablaExcel.Columns.Add("Percepción IVA", typeof(string));
                tablaExcel.Columns.Add("Clasificación", typeof(string));
                tablaExcel.Columns.Add("Total", typeof(string));

                foreach (var item in compraReporte)
                {
                    tablaExcel.Rows.Add(item.ID, item.Nombre, item.Cuit, item.Iibb, item.Fecha, item.TipoFactura, item.Factura, item.SumaTotal,
                                        item.DescuentoPorc, item.Descuento, item.Subtotal, item.Iva, item.ImporteIva, item.ImporteIibbbsas,
                                        item.ImporteIibbcaba, item.ImportePercIva, item.Clasificacion, item.Total);
                }

                //var info = CultureInfo.GetCultureInfo("es-AR");

                //var valor = String.Format(info, "{0:C}", 1332.05);

                // Here we add five DataRows.
                //table.Rows.Add(25, "Indocin", "David", valor);
                //table.Rows.Add(50, "Enebrel", "Sam", valor);
                //table.Rows.Add(10, "Hydralazine", "Christoff", valor);
                //table.Rows.Add(21, "Combivent", "Janet", valor);
                //table.Rows.Add(100, "Dilantin", "Melanie", valor);
            }
            else if (flagExcel == Constants.VENTA_MINORISTA_EXCEL)
            {
                var numeroVenta = operacion.Split(',');

                VentaMinorista               ventaMinoristaInDB    = new VentaMinorista();
                VentaMinoristaReporte        reporteTemp           = new VentaMinoristaReporte();
                List <VentaMinoristaReporte> ventaMinoristaReporte = new List <VentaMinoristaReporte>();

                //Armamos la lista de ventas para el reporte
                foreach (var item in numeroVenta)
                {
                    if (item != string.Empty)
                    {
                        ventaMinoristaInDB = ventaMinoristaBL.GetVentaMinoristaByNumeroVenta(int.Parse(item));

                        //Guardamos los datos necesarios para el reporte
                        reporteTemp                   = new VentaMinoristaReporte();
                        reporteTemp.ID                = ventaMinoristaInDB.NumeroVenta;
                        reporteTemp.Fecha             = ventaMinoristaInDB.Fecha.Date.ToString("dd/MM/yyyy") == null ? " " : ventaMinoristaInDB.Fecha.Date.ToString("dd/MM/yyyy");
                        reporteTemp.Local             = ventaMinoristaInDB.Local == null ? " " : ventaMinoristaInDB.Local;
                        reporteTemp.Importe_Informe_Z = String.Format("{0:c}", ventaMinoristaInDB.ImporteInformeZ);
                        reporteTemp.IVA               = Constants.IVA;
                        reporteTemp.Importe_IVA       = String.Format("{0:c}", ventaMinoristaInDB.ImporteIva);
                        reporteTemp.Factura_N         = ventaMinoristaInDB.NumFactura == null ? " " : ventaMinoristaInDB.NumFactura;
                        reporteTemp.Tipo_Factura      = ventaMinoristaInDB.TipoFactura == null ? " " : ventaMinoristaInDB.TipoFactura;
                        reporteTemp.Primer_Numero_Tic = ventaMinoristaInDB.PrimerNumeroTicket;
                        reporteTemp.Ultimo_Numero_Tic = ventaMinoristaInDB.UltimoNumeroTicket;



                        ventaMinoristaReporte.Add(reporteTemp);
                    }
                }

                //Generamos el datatable correspondiente
                tablaExcel.Columns.Add("Id", typeof(int));
                tablaExcel.Columns.Add("Fecha", typeof(string));
                tablaExcel.Columns.Add("Local", typeof(string));
                tablaExcel.Columns.Add("Importe Informe Z", typeof(string));
                tablaExcel.Columns.Add("IVA", typeof(string));
                tablaExcel.Columns.Add("Importe IVA", typeof(string));
                tablaExcel.Columns.Add("Factura nº", typeof(string));
                tablaExcel.Columns.Add("Tipo Factura", typeof(string));
                tablaExcel.Columns.Add("Primer Número Ticket", typeof(string));
                tablaExcel.Columns.Add("Último Número Ticket", typeof(string));

                foreach (var item in ventaMinoristaReporte)
                {
                    tablaExcel.Rows.Add(item.ID, item.Fecha, item.Local, item.Importe_Informe_Z, item.IVA, item.Importe_IVA, item.Factura_N,
                                        item.Tipo_Factura, item.Primer_Numero_Tic, item.Ultimo_Numero_Tic);
                }
            }

            return(tablaExcel);
        }
Пример #3
0
        public static List <CompraReporte> getReporteCompraXFechaXCantidadXNombreProveedor(DateTime fecha, int cantidad, string nombreProveedor)
        {
            string        CadenaConexion = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
            SqlConnection cn             = new SqlConnection(CadenaConexion);

            List <CompraReporte> compraReporte = new List <CompraReporte>();

            try
            {
                cn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                cmd.Parameters.Clear();

                //Consulto por todas las combinaciones posibles
                if (fecha.Year.ToString().CompareTo("1") != 0 && cantidad > 0 && nombreProveedor.CompareTo("") != 0)
                {
                    cmd.CommandText = "SELECT  c.fecha, c.montoTotal, p.nombre as NombreProveedor, ixc.cantidad, ixc.monto_Parcial, i.nombre as NombreInsumo FROM Compra c INNER JOIN Proveedor p ON c.id_Proveedor= p.id_Proveedor INNER JOIN InsumoXCompra ixc ON ixc.codigo_Compra = c.codigo INNER JOIN Insumo i ON ixc.id_Insumo = i.id_Insumo WHERE c.fecha = @fecha and ixc.cantidad= @cantidad and p.nombre= @nombreProveedor";
                }

                if (fecha.Year.ToString().CompareTo("1") != 0 && cantidad == 0 && nombreProveedor.CompareTo("") == 0)
                {
                    cmd.CommandText = "SELECT  c.fecha, c.montoTotal, p.nombre as NombreProveedor, ixc.cantidad, ixc.monto_Parcial, i.nombre as NombreInsumo FROM Compra c INNER JOIN Proveedor p ON c.id_Proveedor= p.id_Proveedor INNER JOIN InsumoXCompra ixc ON ixc.codigo_Compra = c.codigo INNER JOIN Insumo i ON ixc.id_Insumo = i.id_Insumo WHERE c.fecha = @fecha";
                }

                if (fecha.Year.ToString().CompareTo("1") != 0 && cantidad > 0 && nombreProveedor.CompareTo("") == 0)
                {
                    cmd.CommandText = "SELECT  c.fecha, c.montoTotal, p.nombre as NombreProveedor, ixc.cantidad, ixc.monto_Parcial, i.nombre as NombreInsumo FROM Compra c INNER JOIN Proveedor p ON c.id_Proveedor= p.id_Proveedor INNER JOIN InsumoXCompra ixc ON ixc.codigo_Compra = c.codigo INNER JOIN Insumo i ON ixc.id_Insumo = i.id_Insumo WHERE c.fecha = @fecha and ixc.cantidad= @cantidad";
                }

                if (fecha.Year.ToString().CompareTo("1") != 0 && cantidad == 0 && nombreProveedor.CompareTo("") != 0)
                {
                    cmd.CommandText = "SELECT  c.fecha, c.montoTotal, p.nombre as NombreProveedor, ixc.cantidad, ixc.monto_Parcial, i.nombre as NombreInsumo FROM Compra c INNER JOIN Proveedor p ON c.id_Proveedor= p.id_Proveedor INNER JOIN InsumoXCompra ixc ON ixc.codigo_Compra = c.codigo INNER JOIN Insumo i ON ixc.id_Insumo = i.id_Insumo WHERE c.fecha = @fecha and p.nombre= @nombreProveedor";
                }

                if (fecha.Year.ToString().CompareTo("1") == 0 && cantidad > 0 && nombreProveedor.CompareTo("") != 0)
                {
                    cmd.CommandText = "SELECT  c.fecha, c.montoTotal, p.nombre as NombreProveedor, ixc.cantidad, ixc.monto_Parcial, i.nombre as NombreInsumo FROM Compra c INNER JOIN Proveedor p ON c.id_Proveedor= p.id_Proveedor INNER JOIN InsumoXCompra ixc ON ixc.codigo_Compra = c.codigo INNER JOIN Insumo i ON ixc.id_Insumo = i.id_Insumo WHERE ixc.cantidad= @cantidad and p.nombre= @nombreProveedor";
                }

                if (fecha.Year.ToString().CompareTo("1") == 0 && cantidad > 0 && nombreProveedor.CompareTo("") == 0)
                {
                    cmd.CommandText = "SELECT  c.fecha, c.montoTotal, p.nombre as NombreProveedor, ixc.cantidad, ixc.monto_Parcial, i.nombre as NombreInsumo FROM Compra c INNER JOIN Proveedor p ON c.id_Proveedor= p.id_Proveedor INNER JOIN InsumoXCompra ixc ON ixc.codigo_Compra = c.codigo INNER JOIN Insumo i ON ixc.id_Insumo = i.id_Insumo WHERE ixc.cantidad= @cantidad";
                }

                if (fecha.Year.ToString().CompareTo("1") == 0 && cantidad == 0 && nombreProveedor.CompareTo("") != 0)
                {
                    cmd.CommandText = "SELECT  c.fecha, c.montoTotal, p.nombre as NombreProveedor, ixc.cantidad, ixc.monto_Parcial, i.nombre as NombreInsumo FROM Compra c INNER JOIN Proveedor p ON c.id_Proveedor= p.id_Proveedor INNER JOIN InsumoXCompra ixc ON ixc.codigo_Compra = c.codigo INNER JOIN Insumo i ON ixc.id_Insumo = i.id_Insumo WHERE p.nombre= @nombreProveedor";
                }

                if (fecha.Year.ToString().CompareTo("1") != 0)
                {
                    cmd.Parameters.Add(new SqlParameter("@fecha", fecha));
                }
                if (cantidad > 0)
                {
                    cmd.Parameters.Add(new SqlParameter("@cantidad", cantidad));
                }
                if (nombreProveedor.CompareTo("") != 0)
                {
                    cmd.Parameters.Add(new SqlParameter("@nombreProveedor", nombreProveedor));
                }

                SqlDataReader dr = cmd.ExecuteReader();


                while (dr.Read())
                {
                    CompraReporte cpr = new CompraReporte();

                    cpr.fechaCompra     = (DateTime)dr["fecha"];
                    cpr.montoTotal      = (int)dr["montoTotal"];
                    cpr.montoParcial    = (int)dr["monto_Parcial"];
                    cpr.nombreProveedor = dr["NombreProveedor"].ToString();
                    cpr.cantidad        = (int)dr["cantidad"];
                    cpr.nombreInsumo    = dr["NombreInsumo"].ToString();

                    compraReporte.Add(cpr);
                }
                dr.Close();
            }

            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (cn != null && cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(compraReporte);
        }
Пример #4
0
        public void CrearTxtCompra(string compra)
        {
            var numeroCompra = compra.Split(',');

            Compra               compraInDB    = new Compra();
            CompraReporte        reporteTemp   = new CompraReporte();
            List <CompraReporte> compraReporte = new List <CompraReporte>();

            foreach (var item in numeroCompra)
            {
                if (item != string.Empty)
                {
                    compraInDB = compraBL.GetCompraByNumeroCompra(int.Parse(item));

                    //Guardamos los datos necesarios para el reporte
                    reporteTemp                 = new CompraReporte();
                    reporteTemp.ID              = compraInDB.NumeroCompra;
                    reporteTemp.Nombre          = compraInDB.Proveedor.Nombre;
                    reporteTemp.Cuit            = compraInDB.Proveedor.Cuit;
                    reporteTemp.Iibb            = compraInDB.Proveedor.Iibb;
                    reporteTemp.Fecha           = compraInDB.Fecha.Date.ToString("dd/MM/yyyy");
                    reporteTemp.TipoFactura     = compraInDB.TipoFactura;
                    reporteTemp.Factura         = compraInDB.Factura;
                    reporteTemp.SumaTotal       = String.Format("{0:c}", compraInDB.SumaTotal);
                    reporteTemp.DescuentoPorc   = compraInDB.DescuentoPorc;
                    reporteTemp.Descuento       = String.Format("{0:c}", compraInDB.Descuento);
                    reporteTemp.Subtotal        = String.Format("{0:c}", compraInDB.Subtotal);
                    reporteTemp.Iva             = compraInDB.Iva;
                    reporteTemp.ImporteIva      = String.Format("{0:c}", compraInDB.ImporteIva);
                    reporteTemp.ImporteIibbbsas = String.Format("{0:c}", compraInDB.ImporteIibbbsas);
                    reporteTemp.ImporteIibbcaba = String.Format("{0:c}", compraInDB.ImporteIibbcaba);
                    reporteTemp.ImportePercIva  = String.Format("{0:c}", compraInDB.ImportePercIva);
                    reporteTemp.Clasificacion   = compraInDB.Clasificacion.Nombre;
                    reporteTemp.Total           = String.Format("{0:c}", compraInDB.Total);


                    compraReporte.Add(reporteTemp);
                }
            }


            using (StringWriter sw = new StringWriter())
            {
                using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                {
                    StringBuilder sb = new StringBuilder();

                    var tableFormatter = new TableFormatter();

                    sb.Append(tableFormatter.FormatObjects(compraReporte));

                    //Export HTML String as PDF.
                    StringReader sr = new StringReader(sb.ToString());

                    string fecha = string.Format("{0}{1}{2}", DateTime.Now.Date.Day, DateTime.Now.Date.Month, DateTime.Now.Date.Year);

                    HttpContext.Current.Response.ContentType = "text/plain";
                    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=ReporteCompra_" + fecha + ".txt");
                    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    HttpContext.Current.Response.Write(sb.ToString());
                    HttpContext.Current.Response.End();
                }
            }
        }