venta envio lista y bug del stcok en vender arreglado

This commit is contained in:
carlos
2024-02-14 20:05:42 -06:00
parent 93d7aef100
commit c2008264f2
12 changed files with 66 additions and 68 deletions
+43 -16
View File
@@ -820,7 +820,7 @@ namespace compabetov2.database
}
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleVenta.cantidad);
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - (detalleVenta.cantidad * detalleVenta.producto.cantidad));
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.fkProducto);
commandProdcutoUpdate.ExecuteNonQuery();
}
@@ -1262,7 +1262,7 @@ namespace compabetov2.database
try
{
string sqlEnvio = "INSERT INTO envios (fecha, direccion, telefono,responzable,total,cliente) VALUES(@fecha,@direccion , @telefono, @responzable, @total,@cliente);";
string sqlDetalle = "INSERT INTO detalle_envios (fk_envios, fk_producto, cantidad) VALUES(@fk_envios, @fk_producto, @cantidad);";
string sqlDetalle = "INSERT INTO detalle_envios (fk_envios, fk_variante, cantidad) VALUES(@fk_envios, @fk_variante, @cantidad);";
string sqlIdCuenta = "SELECT idEnvios FROM envios ORDER BY idEnvios DESC LIMIT 1";
SQLiteCommand commandCuenta = new SQLiteCommand(sqlEnvio, conexion);
@@ -1287,7 +1287,7 @@ namespace compabetov2.database
{
SQLiteCommand commandDetalle = new SQLiteCommand(sqlDetalle, conexion);
commandDetalle.Parameters.AddWithValue("@fk_envios", idEnvio);
commandDetalle.Parameters.AddWithValue("@fk_producto", detalleEnvio.producto.idProducto);
commandDetalle.Parameters.AddWithValue("@fk_variante", detalleEnvio.producto.idVariante);
commandDetalle.Parameters.AddWithValue("@cantidad", detalleEnvio.cantidad);
commandDetalle.ExecuteNonQuery();
}
@@ -1345,7 +1345,8 @@ namespace compabetov2.database
conexion.Open();
string sql = "Select p.idproducto, p.nombre , de.cantidad from detalle_envios de, Producto p WHERE de.fk_producto = p.idproducto and de.fk_envios = @fk_envios;";
string sql = "Select v.idVariante, v.nombre, v.cantidad, v.fk_producto, de.cantidad from detalle_envios de,variantes v " +
"WHERE de.fk_variante = v.idVariante and de.fk_envios = @fk_envios;";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@fk_envios", idEnvio);
reader = command.ExecuteReader();
@@ -1402,7 +1403,7 @@ namespace compabetov2.database
}
}
public static bool cancelarEnvioDAO(int idEnvio)
public static bool cancelarEnvioDAO(Envio envio, List<DetalleEnvioModel> detalles)
{
var db_conexion = new Conexion();
try
@@ -1416,13 +1417,28 @@ namespace compabetov2.database
try
{
string sqlCuenta = "UPDATE envios SET estado = @estado WHERE idEnvios = @idEnvios;";
string sqlStock = "select stock from Producto p where idproducto = @idProducto";
string sqlActualizarStock = "UPDATE Producto set stock = @stock WHERE idproducto = @idProducto";
SQLiteCommand command = new SQLiteCommand(sqlCuenta, conexion);
command.Parameters.AddWithValue("@idEnvios", idEnvio);
command.Parameters.AddWithValue("@idEnvios", envio.id);
command.Parameters.AddWithValue("@estado", "CANCELADO");
command.ExecuteNonQuery();
foreach (DetalleEnvioModel detalleEnvio in detalles)
{
//actualizar stock
SQLiteCommand commandStock = new SQLiteCommand(sqlStock, conexion);
commandStock.Parameters.AddWithValue("@idProducto", detalleEnvio.producto.fkProducto);
SQLiteDataReader readerStock = commandStock.ExecuteReader();
long stock = 0;
while (readerStock.Read()) stock = readerStock.GetInt64(0);
SQLiteCommand commandActualizarStock = new SQLiteCommand(sqlActualizarStock, conexion);
commandActualizarStock.Parameters.AddWithValue("@stock", stock - (detalleEnvio.cantidad * detalleEnvio.producto.cantidad));
commandActualizarStock.Parameters.AddWithValue("@idProducto", detalleEnvio.producto.fkProducto);
commandActualizarStock.ExecuteNonQuery();
}
transaccion.Commit();
return true;
@@ -1457,10 +1473,11 @@ namespace compabetov2.database
try
{
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 sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_variante, cantidad) VALUES(@idVenta, @fk_variante, @cantidada);";
string sqlEnvio = "UPDATE envios SET estado ='CONCLUIDO' WHERE idEnvios = @idEnvios;";
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
string sqlStock = "select stock from Producto p where idproducto = @idProducto";
string sqlActualizarStock = "UPDATE Producto set stock = @stock WHERE idproducto = @idProducto";
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
@@ -1476,17 +1493,27 @@ namespace compabetov2.database
SQLiteDataReader reader = commandConsulta.ExecuteReader();
long idVenta = -1;
while (reader.Read())
{
idVenta = reader.GetInt64(0);
}
while (reader.Read()) idVenta = reader.GetInt64(0);
foreach (DetalleEnvioModel detalleEnvio in detallesEnvio)
{
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleEnvio.producto.idProducto);
commandEmpleado.Parameters.AddWithValue("@fk_variante", detalleEnvio.producto.idVariante);
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleEnvio.cantidad);
commandEmpleado.ExecuteNonQuery();
//actualizar stock
SQLiteCommand commandStock = new SQLiteCommand(sqlStock, conexion);
commandStock.Parameters.AddWithValue("@idProducto", detalleEnvio.producto.fkProducto);
SQLiteDataReader readerStock = commandStock.ExecuteReader();
long stock = 0;
while (readerStock.Read()) stock = readerStock.GetInt64(0);
SQLiteCommand commandActualizarStock = new SQLiteCommand(sqlActualizarStock, conexion);
commandActualizarStock.Parameters.AddWithValue("@stock", stock - (detalleEnvio.cantidad * detalleEnvio.producto.cantidad));
commandActualizarStock.Parameters.AddWithValue("@idProducto", detalleEnvio.producto.fkProducto);
commandActualizarStock.ExecuteNonQuery();
}
transaccion.Commit();
@@ -1615,8 +1642,8 @@ namespace compabetov2.database
"CREATE TABLE envios (idEnvios INTEGER PRIMARY KEY AUTOINCREMENT, fecha TEXT, direccion TEXT, telefono TEXT,responzable TEXT DEFAULT '',estado TEXT DEFAULT 'EN PROCESO', total DECIMAL(10,2) DEFAULT 0,cliente TEXT)",
"CREATE TABLE detalle_envios (fk_envios INTEGER, fk_producto INTEGER,cantidad INTEGER, PRIMARY KEY (fk_envios, fk_producto), " +
"FOREIGN KEY (fk_envios) REFERENCES envios(idEnvios),FOREIGN KEY (fk_producto) REFERENCES producto(idproducto))",
"CREATE TABLE detalle_envios (fk_envios INTEGER, fk_variante INTEGER,cantidad INTEGER, PRIMARY KEY (fk_envios, fk_variante)," +
"FOREIGN KEY (fk_envios) REFERENCES envios(idEnvios),FOREIGN KEY (fk_variante) REFERENCES variantes(idVariante))",
"INSERT INTO Login ( tipo, usuario, contra) VALUES('admin', 'admin', '12345');",
"INSERT INTO Empleado ( nombre, apellidos, calle, fecha_contratacion,estado, colonia, cp, no_ext,no_int, referencia, fecha_nac, telefono,fk_idLogin) VALUES('jefe', '', '', '', '', '', '', '', '', '', '', '',1);",