venta envio lista y bug del stcok en vender arreglado
This commit is contained in:
+43
-16
@@ -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);",
|
||||
|
||||
@@ -9,10 +9,10 @@ namespace compabetov2.database.modelos
|
||||
public class DetalleEnvioModel
|
||||
{
|
||||
public int idEnvio;
|
||||
public Producto producto;
|
||||
public Variante producto;
|
||||
public int cantidad;
|
||||
|
||||
public DetalleEnvioModel(int idEnvio, Producto producto, int cantidad)
|
||||
public DetalleEnvioModel(int idEnvio, Variante producto, int cantidad)
|
||||
{
|
||||
this.idEnvio = idEnvio;
|
||||
this.producto = producto;
|
||||
|
||||
@@ -20,5 +20,10 @@ namespace compabetov2.database.modelos
|
||||
this.idVenta = id;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public DetalleEnvioModel convertirADetalleEnvio()
|
||||
{
|
||||
return new DetalleEnvioModel(-1,this.producto,this.cantidad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -352,11 +352,11 @@ namespace compabetov2.database
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
int idProducto = (int)reader.GetInt64(0);
|
||||
int idVariante = (int)reader.GetInt64(0);
|
||||
DetalleEnvioModel detalleEnvio = new DetalleEnvioModel(
|
||||
idEnvio,
|
||||
new Producto(idProducto, reader["nombre"].ToString()),
|
||||
(int)reader.GetInt64(2)
|
||||
new Variante(idVariante, reader["nombre"].ToString(),0,(int)reader.GetInt64(2),"", (int)reader.GetInt64(3)),//fkproducto
|
||||
(int)reader.GetInt64(4)//cantidad
|
||||
);
|
||||
detallesEnvio.Add(detalleEnvio);
|
||||
}
|
||||
@@ -370,9 +370,9 @@ namespace compabetov2.database
|
||||
}
|
||||
|
||||
|
||||
public static bool cancelarEnvio(int idEnvio)
|
||||
public static bool cancelarEnvio(Envio envio, List<DetalleEnvioModel> detalles)
|
||||
{
|
||||
return DAO.cancelarEnvioDAO(idEnvio);
|
||||
return DAO.cancelarEnvioDAO(envio, detalles);
|
||||
}
|
||||
|
||||
public static bool concluirEnvio(Envio envio, List<DetalleEnvioModel> detallesEnvio)
|
||||
|
||||
Reference in New Issue
Block a user