todo lo relacionado a cuentas funcionando

This commit is contained in:
carlos
2024-02-14 21:58:41 -06:00
parent c2008264f2
commit 736d8be03c
10 changed files with 23 additions and 56 deletions
+11 -10
View File
@@ -942,7 +942,7 @@ namespace compabetov2.database
try
{
string sqlCuenta = "INSERT INTO cuenta (total, fecha, estado, descripcion,cliente) VALUES(@total, @fecha, 'ACTIVO', @descripcion,@cliente);";
string sqlDetalle = "INSERT INTO detalle_cuenta (fk_cuenta, fk_producto, cantidad) VALUES(@fk_cuenta, @fk_producto, @cantidad);";
string sqlDetalle = "INSERT INTO detalle_cuenta (fk_cuenta, fk_variante, cantidad) VALUES(@fk_cuenta, @fk_variante, @cantidad);";
string sqlIdCuenta = "SELECT idCuenta FROM cuenta ORDER BY idCuenta DESC LIMIT 1";
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
string sqlProductoUpdate = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto";
@@ -967,13 +967,13 @@ namespace compabetov2.database
{
SQLiteCommand commandDetalle = new SQLiteCommand(sqlDetalle, conexion);
commandDetalle.Parameters.AddWithValue("@fk_cuenta", idCuenta);
commandDetalle.Parameters.AddWithValue("@fk_producto", detalleCuenta.producto.idProducto);
commandDetalle.Parameters.AddWithValue("@fk_variante", detalleCuenta.producto.idVariante);
commandDetalle.Parameters.AddWithValue("@cantidad", detalleCuenta.cantidad);
commandDetalle.ExecuteNonQuery();
//modificar stock
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.idProducto);
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.fkProducto);
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
int stockActual = -1;
@@ -984,8 +984,8 @@ namespace compabetov2.database
}
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleCuenta.cantidad);
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.idProducto);
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - (detalleCuenta.cantidad * detalleCuenta.producto.cantidad));
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.fkProducto);
commandProdcutoUpdate.ExecuteNonQuery();
}
@@ -1018,7 +1018,8 @@ namespace compabetov2.database
conexion.Open();
string sql = "Select p.idproducto, p.nombre , dc.cantidad from detalle_cuenta dc, Producto p WHERE dc.fk_producto = p.idproducto and dc.fk_cuenta = @fk_cuenta;";
string sql = "Select v.idVariante , v.nombre ,v.cantidad ,v.fk_producto , dc.cantidad from detalle_cuenta dc, variantes v " +
"WHERE dc.fk_variante = v.idVariante and dc.fk_cuenta = @fk_cuenta;";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@fk_cuenta", idCuenta);
reader = command.ExecuteReader();
@@ -1086,7 +1087,7 @@ namespace compabetov2.database
try
{
string sqlVenta = "INSERT INTO venta (fecha, total) VALUES(@fecha, @total);";
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 sqlCuenta = "UPDATE cuenta SET estado ='SALDADO' WHERE idCuenta = @idCuenta;";
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
@@ -1112,7 +1113,7 @@ namespace compabetov2.database
{
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleCuenta.producto.idProducto);
commandEmpleado.Parameters.AddWithValue("@fk_variante", detalleCuenta.producto.idVariante);
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleCuenta.cantidad);
commandEmpleado.ExecuteNonQuery();
}
@@ -1637,8 +1638,8 @@ namespace compabetov2.database
"CREATE TABLE cuenta (idCuenta INTEGER PRIMARY KEY AUTOINCREMENT, total DECIMAL(10,2), fecha TEXT, estado TEXT DEFAULT 'ACTIVO', descripcion TEXT, cliente TEXT DEFAULT '')",
"CREATE TABLE detalle_cuenta (fk_cuenta INTEGER, fk_producto INTEGER,cantidad INTEGER, PRIMARY KEY (fk_cuenta, fk_producto), " +
"FOREIGN KEY (fk_cuenta) REFERENCES Cuenta(idCuenta),FOREIGN KEY (fk_producto) REFERENCES producto(idproducto))",
"CREATE TABLE detalle_cuenta (fk_cuenta INTEGER, fk_variante INTEGER,cantidad INTEGER, PRIMARY KEY (fk_cuenta, fk_variante), " +
"FOREIGN KEY (fk_cuenta) REFERENCES Cuenta(idCuenta),FOREIGN KEY (fk_variante) REFERENCES variantes(idVariante))",
"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)",