private void BuscarVentas(string tipo_busqueda, string texto_busqueda)
        {
            try
            {
                string fecha1 = this.date1.Value.ToShortDateString();
                string fecha2 = this.date2.Value.ToShortDateString();
                string hora1  = this.ListaHora1.SelectedValue.ToString();
                string hora2  = this.ListaHora2.SelectedValue.ToString();

                DataTable tablaVenta =
                    NVentas.BuscarVenta(tipo_busqueda, texto_busqueda, fecha1, fecha2, hora1, hora2);
                this.dgvVentas.DataSource = tablaVenta;
                if (tablaVenta != null)
                {
                    this.btnResumen.Enabled = true;
                    string[] columns_header =
                    {
                        "Id venta",  "Id pedido",    "Fecha",       "Hora",          "Total parcial", "Propina",        "Subtotal",
                        "Descuento", "Bono o cupón", "Total",       "Observaciones", "Id cliente",    "Nombre cliente",
                        "Id mesa",   "Mesa",         "Id empleado", "Empleado"
                    };
                    bool[] columns_visible =
                    {
                        false, false, true,  true,  true, true,  true, true,
                        false, true,  false, false, true, false, true, false, true
                    };
                    this.dgvVentas =
                        DatagridString.ChangeHeaderTextAndVisible(this.dgvVentas, columns_header, columns_visible);

                    //this.dgvVentas.Columns["Hora_venta"].DefaultCellStyle.Format = "HH:mm";

                    this.resumenVenta.ObtenerVenta(Convert.ToDateTime(fecha1), Convert.ToDateTime(fecha2),
                                                   hora1, hora2);
                }
                else
                {
                    this.btnResumen.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                Mensajes.MensajeErrorCompleto(this.Name, "BuscarVentas", "Hubo un error al buscar una venta", ex.Message);
            }
        }
Ejemplo n.º 2
0
        public void ObtenerVenta(DateTime fecha1, DateTime fecha2, string hora1, string hora2)
        {
            try
            {
                DataTable table = NVentas.BuscarVenta("RESUMEN VENTA", "",
                                                      fecha1.ToShortDateString(), fecha2.ToShortDateString(),
                                                      hora1, hora2);
                if (table != null)
                {
                    int cantidadVentas        = Convert.ToInt32(table.Rows[0]["Cantidad_ventas"]);
                    int totalVentas           = Convert.ToInt32(table.Rows[0]["Total_ventas"]);
                    int totalPropinas         = Convert.ToInt32(table.Rows[0]["Total_propinas"]);
                    int totalVentasSinPropina = Convert.ToInt32(table.Rows[0]["Total_ventas_sin_propina"]);
                    int pagosEfectivo         = Convert.ToInt32(table.Rows[0]["Pagos_efectivo"]);
                    int pagosTarjeta          = Convert.ToInt32(table.Rows[0]["Pagos_tarjeta"]);

                    StringBuilder builder = new StringBuilder();
                    builder.Append("Entre " + fecha1.ToLongDateString() + " y " + fecha2.ToLongDateString() +
                                   " se realizaron " + cantidadVentas + " ventas");
                    builder.Append(Environment.NewLine);
                    builder.Append("El total de ventas fue de " + totalVentas.ToString("C"));
                    builder.Append(Environment.NewLine);
                    builder.Append("El total de propinas fue de " + totalPropinas.ToString("C"));
                    builder.Append(Environment.NewLine);
                    builder.Append("El total de ventas sin propinas fue de " + totalVentasSinPropina.ToString("C"));
                    builder.Append(Environment.NewLine);

                    if (pagosEfectivo > 0)
                    {
                        int totalPagosEfectivo = Convert.ToInt32(table.Rows[0]["Total_ventas_efectivo"]);
                        builder.Append("Pagos en efectivo: " + pagosEfectivo + " por un valor de " + totalPagosEfectivo.ToString("C2"));
                    }
                    else
                    {
                        builder.Append("No hubo pagos en efectivo");
                    }

                    builder.Append(Environment.NewLine);

                    if (pagosTarjeta > 0)
                    {
                        int totalPagosTarjeta = Convert.ToInt32(table.Rows[0]["Total_ventas_tarjeta"]);
                        builder.Append("Pagos con tarjeta: " + pagosTarjeta + " por un valor de " + totalPagosTarjeta.ToString("C2"));
                    }
                    else
                    {
                        builder.Append("No se encontraron pagos con tarjeta");
                    }

                    this.txtResumen.Text = Convert.ToString(builder);
                }
                else
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append("Entre " + fecha1.ToLongDateString() + " y " + fecha2.ToLongDateString() +
                                   " no se realizaron ventas");
                }
            }
            catch (Exception ex)
            {
                Mensajes.MensajeErrorForm("Hubo un error al obtener la venta Detalle:" + ex.Message);
            }
        }