todo lo relacionado a cuentas funcionando
This commit is contained in:
+11
-10
@@ -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)",
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace compabetov2.database.modelos
|
||||
public class DetalleCuentaModel
|
||||
{
|
||||
public int idCuenta;
|
||||
public Producto producto;
|
||||
public Variante producto;
|
||||
public int cantidad;
|
||||
public string nombreProducto;
|
||||
|
||||
public DetalleCuentaModel(Producto producto, int cantidad, int idCuenta =-1, string nombreProducto = "")
|
||||
public DetalleCuentaModel(Variante producto, int cantidad, int idCuenta =-1, string nombreProducto = "")
|
||||
{
|
||||
this.idCuenta = idCuenta;
|
||||
this.producto = producto;
|
||||
|
||||
@@ -25,5 +25,10 @@ namespace compabetov2.database.modelos
|
||||
{
|
||||
return new DetalleEnvioModel(-1,this.producto,this.cantidad);
|
||||
}
|
||||
|
||||
public DetalleCuentaModel convertirADetalleCuenta()
|
||||
{
|
||||
return new DetalleCuentaModel(this.producto, this.cantidad, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -262,10 +262,10 @@ namespace compabetov2.database
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
int idProducto = (int)reader.GetInt64(0);
|
||||
int idVariaante = (int)reader.GetInt64(0);
|
||||
DetalleCuentaModel detalleCuenta = new DetalleCuentaModel(
|
||||
new Producto(idProducto, reader["nombre"].ToString()),
|
||||
(int)reader.GetInt64(2)
|
||||
new Variante(idVariaante, reader["nombre"].ToString(),0,(int)reader.GetInt64(2),"",(int)reader.GetInt64(3)),
|
||||
(int)reader.GetInt64(4)
|
||||
);
|
||||
detallesCuentas.Add(detalleCuenta);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user