estadisticas del mes

This commit is contained in:
carlos
2024-01-28 22:51:04 -06:00
parent ccbdc1d323
commit c81f56bf7b
22 changed files with 592 additions and 68 deletions
+32 -6
View File
@@ -777,7 +777,7 @@ namespace compabetov2.database
{
try
{
string sqlVenta = "INSERT INTO venta (fecha, total) VALUES(@fecha, @total);";
string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);";
string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_producto, cantidad) VALUES(@idVenta, @idProducto, @cantidada);";
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
@@ -787,6 +787,7 @@ namespace compabetov2.database
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
commandVenta.Parameters.AddWithValue("@total", venta.total);
commandVenta.Parameters.AddWithValue("@responzable", venta.responzable);
commandVenta.ExecuteNonQuery();
SQLiteCommand commandConsulta = new SQLiteCommand(sqlIdVenta, conexion);
@@ -1137,7 +1138,7 @@ namespace compabetov2.database
}
public static SQLiteDataReader filtrarVentaFechaMesDAO(DateTime fecha)
public static SQLiteDataReader conseguirVentasMesDAO(DateTime fecha)
{
SQLiteDataReader reader = null;
var db_conexion = new Conexion();
@@ -1147,9 +1148,9 @@ namespace compabetov2.database
conexion.Open();
string sql = "SELECT * FROM venta WHERE fecha LIKE '%@fecha%'";
string sql = "SELECT * FROM venta WHERE fecha LIKE @fecha";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@fecha", $"{fecha.Month}/{fecha.Year}");
command.Parameters.AddWithValue("@fecha", $"%{fecha.Month}/{fecha.Year}%");
reader = command.ExecuteReader();
return reader;
@@ -1162,7 +1163,32 @@ namespace compabetov2.database
}
}
public static Dictionary<string, dynamic> filtrarVentaFechaMes(DateTime fecha)
public static SQLiteDataReader conseguirDetalleVenta(VentaModel venta)
{
SQLiteDataReader reader = null;
var db_conexion = new Conexion();
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "select * from detalle_venta dv, Producto p WHERE dv.fk_producto = p.idproducto and dv.fk_venta = @idVenta";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@idVenta", venta.id);
reader = command.ExecuteReader();
return reader;
}
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return reader;
}
}
/*public static SQLiteDataReader filtrarVentaFechaMes(DateTime fecha)
{
Dictionary<string, dynamic> estadisticas = new Dictionary<string, dynamic>();
SQLiteDataReader reader = DAO.filtrarVentaFechaMesDAO(fecha);
@@ -1191,7 +1217,7 @@ namespace compabetov2.database
estadisticas.Add("ventasMes", totalMes);
return estadisticas;
}
}*/
public static bool crearEnvio(Envio envio, List<DetalleEnvioModel> detallesEnvio)
{
+2 -2
View File
@@ -8,7 +8,7 @@ namespace compabetov2.database.modelos
{
public class DetalleVentaModel
{
public int id;
public int idVenta;
public int cantidad;
public Producto producto;
@@ -16,7 +16,7 @@ namespace compabetov2.database.modelos
{
this.cantidad = cantidad;
this.producto = producto;
this.id = id;
this.idVenta = id;
}
}
}
+3 -1
View File
@@ -11,11 +11,13 @@ namespace compabetov2.database.modelos
public int id;
public string fecha;
public decimal total;
public string responzable;
public VentaModel(decimal total = 0, int id = -1, string fecha = "") {
public VentaModel(decimal total = 0, int id = -1, string fecha = "", string responzable = "") {
this.id = id;
this.fecha = fecha;
this.total = total;
this.responzable = responzable;
}
}
}
+63 -2
View File
@@ -283,7 +283,7 @@ namespace compabetov2.database
return DAO.saldarCuentaDAO(cuenta, detallesCuentas);
}
public static Dictionary<string, dynamic> filtrarVentaFechaMes(DateTime fecha)
/*public static Dictionary<string, dynamic> filtrarVentaFechaMes(DateTime fecha)
{
Dictionary<string, dynamic> estadisticas = new Dictionary<string, dynamic>();
SQLiteDataReader reader = DAO.filtrarVentaFechaMesDAO(fecha);
@@ -312,7 +312,7 @@ namespace compabetov2.database
MessageBox.Show($"{totalDia} -- {totalMes}");
return estadisticas;
}
}*/
public static bool crearEnvio(Envio envio, List<DetalleEnvioModel> detallesEnvio)
{
@@ -378,5 +378,66 @@ namespace compabetov2.database
{
return DAO.concluirEnvioDAO(envio, detallesEnvio);
}
public static Dictionary<string, List<Dictionary<string,dynamic>>> estadisticas(DateTime fecha)
{
Dictionary<string, List<Dictionary<string, dynamic>>> resumen = new Dictionary<string, List<Dictionary<string, dynamic>>>();
List<Dictionary<string, dynamic>> listMes = new List<Dictionary<string, dynamic>>();
List<Dictionary<string, dynamic>> listDia = new List<Dictionary<string, dynamic>>();
SQLiteDataReader readerVentas = DAO.conseguirVentasMesDAO(fecha);
string formato = "dd/MM/yyyy";
while (readerVentas.Read())
{
Dictionary<string,dynamic> dicVenta = new Dictionary<string,dynamic>();
VentaModel venta = new VentaModel(
readerVentas.GetDecimal(2),
(int)readerVentas.GetInt64(0),
readerVentas.GetString(1),
readerVentas.GetString(3)
);
List<DetalleVentaModel> detallesVenta = new List<DetalleVentaModel>();
SQLiteDataReader readerDetalleVenta = DAO.conseguirDetalleVenta(venta);
while (readerDetalleVenta.Read())
{
DetalleVentaModel detalleVenta = new DetalleVentaModel(
(int)readerDetalleVenta.GetInt64(2),
new Producto(
(int)readerDetalleVenta.GetInt64(1),
readerDetalleVenta["nombre"].ToString(),
readerDetalleVenta["descripcion"].ToString(),
readerDetalleVenta.GetDecimal(6),
readerDetalleVenta["img"].ToString(),
(int)readerDetalleVenta.GetInt64(8)
),
(int)readerDetalleVenta.GetInt64(0)
) ;
detallesVenta.Add( detalleVenta );
}
dicVenta.Add("venta", venta);
dicVenta.Add("detalles", detallesVenta as List<DetalleVentaModel>);
string[] fecha_hora = venta.fecha.Split(' ');
string fechaVentaStr = fecha_hora[0];
DateTime.TryParseExact(fechaVentaStr, formato, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fechaVenta);
if (fecha.Day == fechaVenta.Day)
{
listDia.Add(dicVenta);
}
listMes.Add(dicVenta);
}
resumen.Add("mes", listMes);
resumen.Add("dia", listDia);
return resumen;
}
}
}