estadisticas terminadas con detalle del mejor vendedor

This commit is contained in:
Carlos Sandoval
2024-06-30 03:09:38 -06:00
parent d81f706053
commit 8e6571fbc9
15 changed files with 469 additions and 311 deletions
+51 -3
View File
@@ -872,8 +872,9 @@ namespace compabetov2.database
}
}
public static bool devolverImporteDAO(List<DetalleImporte> importes)
public static bool devolverImporteDAO(VentaModel venta, List<DetalleImporte> importes)
{
var db_conexion = new Conexion();
try
{
@@ -885,7 +886,28 @@ namespace compabetov2.database
{
try
{
string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fecha) VALUES (@fk_importe,@cantidad,@precio,@fecha)";
string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);";
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fk_venta) VALUES (@fk_importe,@cantidad,@precio,@fk_venta)";
// CREACION DE LA VENTA
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();
//CONSEGUIR EL ID DE LA VENTA PARA RELACIONARLO CON DETALLE VENTA
SQLiteCommand commandConsulta = new SQLiteCommand(sqlIdVenta, conexion);
SQLiteDataReader reader = commandConsulta.ExecuteReader();
long idVenta = -1;
while (reader.Read())
{
idVenta = reader.GetInt64(0);
}
//creacion del importe
foreach (DetalleImporte importe in importes)
{
@@ -895,7 +917,7 @@ namespace compabetov2.database
commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte);
commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.cantidad);
commandDetalleImporte.Parameters.AddWithValue("@precio", importe.precioImporte);
commandDetalleImporte.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
commandDetalleImporte.Parameters.AddWithValue("@fk_venta", idVenta);
commandDetalleImporte.ExecuteNonQuery();
}
}
@@ -1917,6 +1939,32 @@ namespace compabetov2.database
}
}
public static SQLiteDataReader conseguirImportesVentaDAO(VentaModel venta)
{
SQLiteDataReader reader = null;
var db_conexion = new Conexion();
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "SELECT * FROM detalle_importe WHERE fk_venta = @fk_venta;";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@fk_venta", venta.id);
reader = command.ExecuteReader();
return reader;
}
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return reader;
}
}
private static void crearDB()
{
var db_conexion = new Conexion();
+54 -27
View File
@@ -209,9 +209,9 @@ namespace compabetov2.database
return DAO.crearVentaDAO(venta, detalleVentas,importes);
}
public static bool devolverImporte(List<DetalleImporte> importes)
public static bool devolverImporte(VentaModel venta,List<DetalleImporte> importes)
{
return DAO.devolverImporteDAO(importes);
return DAO.devolverImporteDAO(venta,importes);
}
public static bool insertarMerma(Merma merma)
@@ -427,49 +427,76 @@ namespace compabetov2.database
return DAO.concluirEnvioDAO(envio, detallesEnvio, importes);
}
public static List<VentaModel> conseguirVentasMes(DateTime fecha)
public static Dictionary<string, List<Dictionary<string, dynamic>>> estadisticas(DateTime fecha)
{
List<VentaModel> ventasMes = new List<VentaModel>();
SQLiteDataReader readerVentas = DAO.conseguirVentasMesDAO(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>>();
while (readerVentas.Read())
{
VentaModel venta = new VentaModel(
readerVentas.GetDecimal(2),//total
(int)readerVentas.GetInt64(0),//id
readerVentas.GetString(1),//fecha
readerVentas.GetString(3)//resposable
);
ventasMes.Add(venta);
}
return ventasMes;
}
public static List<VentaModel> conseguirVentasDia(DateTime fecha)
{
List<VentaModel> ventasDia = new List<VentaModel>();
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)
readerVentas.GetDecimal(2),//total
(int)readerVentas.GetInt64(0),//id
readerVentas.GetString(1),//fecha
readerVentas.GetString(3)//responzable
);
List<DetalleVentaModel> detallesVenta = new List<DetalleVentaModel>();
SQLiteDataReader readerDetalleVenta = DAO.conseguirDetalleVenta(venta);
while (readerDetalleVenta.Read())
{
decimal precioCompra = readerDetalleVenta.GetDecimal(3);
DetalleVentaModel detalleVenta = new DetalleVentaModel(
(int)readerDetalleVenta.GetInt64(2),// cantidad
new Variante((int)readerDetalleVenta.GetInt64(5),//id
readerDetalleVenta["nombre"].ToString(),//nombre
readerDetalleVenta.GetDecimal(4),//precioVenta
(int)readerDetalleVenta.GetInt64(8),//cantidad
"",//img
(int)readerDetalleVenta.GetInt64(10),//fkProducto
precioCompra)
);
detallesVenta.Add(detalleVenta);
}
List<DetalleImporte> importes = new List<DetalleImporte>();
SQLiteDataReader readerImporte = DAO.conseguirImportesVentaDAO(venta);
while (readerImporte.Read())
{
DetalleImporte importe = new DetalleImporte(
(int)readerImporte.GetInt64(1),//fkImporte
(int)readerImporte.GetInt64(2),//cantidad
readerImporte.GetDecimal(3),//precio
(int)readerImporte.GetInt64(4)//fkVenta
);
importes.Add(importe);
}
string[] fecha_hora = venta.fecha.Split(' ');
string fechaVentaStr = fecha_hora[0];
dicVenta.Add("venta", venta);
dicVenta.Add("detalles", detallesVenta as List<DetalleVentaModel>);
dicVenta.Add("importes", importes);
DateTime.TryParseExact(fechaVentaStr, formato, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fechaVenta);
if (fecha.Day == fechaVenta.Day)
{
ventasDia.Add(venta);
listDia.Add(dicVenta);
}
listMes.Add(dicVenta);
}
return ventasDia;
resumen.Add("mes", listMes);
resumen.Add("dia", listDia);
return resumen;
}
public static List<Variante> conseguirProductosFiltrados(string nombreProducto)