venta envio lista y bug del stcok en vender arreglado
This commit is contained in:
+4
-2
@@ -175,9 +175,10 @@ namespace compabetov2
|
|||||||
{
|
{
|
||||||
DialogResult result = MessageBox.Show($"¿Está seguro de que desea eliminar este envio?",
|
DialogResult result = MessageBox.Show($"¿Está seguro de que desea eliminar este envio?",
|
||||||
"Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
"Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||||
|
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
|
||||||
if (result == DialogResult.Yes)
|
if (result == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
if (service.cancelarEnvio(envio.id))
|
if (service.cancelarEnvio(envio, detalles))
|
||||||
{
|
{
|
||||||
llenarPanel();
|
llenarPanel();
|
||||||
}
|
}
|
||||||
@@ -291,7 +292,8 @@ namespace compabetov2
|
|||||||
string mensaje = "";
|
string mensaje = "";
|
||||||
foreach (DetalleEnvioModel detalle in detalles)
|
foreach (DetalleEnvioModel detalle in detalles)
|
||||||
{
|
{
|
||||||
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n";
|
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n" +
|
||||||
|
$"Total: {envio.total}";
|
||||||
}
|
}
|
||||||
MessageBox.Show(mensaje);
|
MessageBox.Show(mensaje);
|
||||||
});
|
});
|
||||||
|
|||||||
+7
-43
@@ -675,7 +675,7 @@ namespace compabetov2
|
|||||||
return resultado;
|
return resultado;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button7_Click(object sender, EventArgs e)
|
/*private void button7_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
|
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
|
||||||
if (detalleVentas.Count > 0)
|
if (detalleVentas.Count > 0)
|
||||||
@@ -731,7 +731,7 @@ namespace compabetov2
|
|||||||
}
|
}
|
||||||
|
|
||||||
return detalleVentas;
|
return detalleVentas;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void button6_Click(object sender, EventArgs e)
|
private void button6_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@@ -836,49 +836,13 @@ namespace compabetov2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DetalleEnvioModel> listaProductosEnvio()
|
|
||||||
{
|
|
||||||
List<DetalleEnvioModel> detallesEnvio = new List<DetalleEnvioModel>();
|
|
||||||
int contador_saltar_2_vueltas = 1;
|
|
||||||
foreach (var item in flowLayoutPanel2.Controls)
|
|
||||||
{
|
|
||||||
if (contador_saltar_2_vueltas <= 3)
|
|
||||||
{
|
|
||||||
contador_saltar_2_vueltas++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TableLayoutPanel panelProducto = item as TableLayoutPanel;
|
|
||||||
TableLayoutPanel panelInfo = panelProducto.Controls[1] as TableLayoutPanel;
|
|
||||||
PictureBox pic = panelProducto.Controls[0] as PictureBox;
|
|
||||||
Label idLabel = null;
|
|
||||||
foreach (Control control in pic.Controls)
|
|
||||||
{
|
|
||||||
if (control is Label)
|
|
||||||
{
|
|
||||||
idLabel = (Label)control;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int idProducto = int.Parse(idLabel.Text);
|
|
||||||
Producto producto = new Producto(idProducto);
|
|
||||||
|
|
||||||
Label Lbcantidad = panelInfo.Controls[2] as Label;
|
|
||||||
string textcantidad = Lbcantidad.Text;
|
|
||||||
string[] cantidadCadenas = textcantidad.Split(' ');
|
|
||||||
int cantidad = int.Parse(cantidadCadenas[1]);
|
|
||||||
|
|
||||||
DetalleEnvioModel detalleEnvio = new DetalleEnvioModel(-1, producto, cantidad);
|
|
||||||
|
|
||||||
|
|
||||||
detallesEnvio.Add(detalleEnvio);
|
|
||||||
}
|
|
||||||
|
|
||||||
return detallesEnvio;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void btnEnviar_Click(object sender, EventArgs e)
|
private void btnEnviar_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
List<DetalleEnvioModel> detallesEnvio = listaProductosEnvio();
|
List<DetalleEnvioModel> detallesEnvio = new List<DetalleEnvioModel>();
|
||||||
|
foreach(DetalleVentaModel detalleVenta in carrito)
|
||||||
|
{
|
||||||
|
detallesEnvio.Add(detalleVenta.convertirADetalleEnvio());
|
||||||
|
}
|
||||||
string responsable = responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text;
|
string responsable = responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text;
|
||||||
Envio envio = new Envio(-1, DateTime.Now.ToString(), "", "", responsable, "", "", total);
|
Envio envio = new Envio(-1, DateTime.Now.ToString(), "", "", responsable, "", "", total);
|
||||||
if (detallesEnvio.Count > 0)
|
if (detallesEnvio.Count > 0)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+43
-16
@@ -820,7 +820,7 @@ namespace compabetov2.database
|
|||||||
}
|
}
|
||||||
|
|
||||||
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
|
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.Parameters.AddWithValue("@idproducto", detalleVenta.producto.fkProducto);
|
||||||
commandProdcutoUpdate.ExecuteNonQuery();
|
commandProdcutoUpdate.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
@@ -1262,7 +1262,7 @@ namespace compabetov2.database
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sqlEnvio = "INSERT INTO envios (fecha, direccion, telefono,responzable,total,cliente) VALUES(@fecha,@direccion , @telefono, @responzable, @total,@cliente);";
|
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";
|
string sqlIdCuenta = "SELECT idEnvios FROM envios ORDER BY idEnvios DESC LIMIT 1";
|
||||||
|
|
||||||
SQLiteCommand commandCuenta = new SQLiteCommand(sqlEnvio, conexion);
|
SQLiteCommand commandCuenta = new SQLiteCommand(sqlEnvio, conexion);
|
||||||
@@ -1287,7 +1287,7 @@ namespace compabetov2.database
|
|||||||
{
|
{
|
||||||
SQLiteCommand commandDetalle = new SQLiteCommand(sqlDetalle, conexion);
|
SQLiteCommand commandDetalle = new SQLiteCommand(sqlDetalle, conexion);
|
||||||
commandDetalle.Parameters.AddWithValue("@fk_envios", idEnvio);
|
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.Parameters.AddWithValue("@cantidad", detalleEnvio.cantidad);
|
||||||
commandDetalle.ExecuteNonQuery();
|
commandDetalle.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
@@ -1345,7 +1345,8 @@ namespace compabetov2.database
|
|||||||
|
|
||||||
conexion.Open();
|
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);
|
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||||
command.Parameters.AddWithValue("@fk_envios", idEnvio);
|
command.Parameters.AddWithValue("@fk_envios", idEnvio);
|
||||||
reader = command.ExecuteReader();
|
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();
|
var db_conexion = new Conexion();
|
||||||
try
|
try
|
||||||
@@ -1416,13 +1417,28 @@ namespace compabetov2.database
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sqlCuenta = "UPDATE envios SET estado = @estado WHERE idEnvios = @idEnvios;";
|
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);
|
SQLiteCommand command = new SQLiteCommand(sqlCuenta, conexion);
|
||||||
command.Parameters.AddWithValue("@idEnvios", idEnvio);
|
command.Parameters.AddWithValue("@idEnvios", envio.id);
|
||||||
command.Parameters.AddWithValue("@estado", "CANCELADO");
|
command.Parameters.AddWithValue("@estado", "CANCELADO");
|
||||||
|
|
||||||
command.ExecuteNonQuery();
|
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();
|
transaccion.Commit();
|
||||||
return true;
|
return true;
|
||||||
@@ -1457,10 +1473,11 @@ namespace compabetov2.database
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);";
|
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 sqlEnvio = "UPDATE envios SET estado ='CONCLUIDO' WHERE idEnvios = @idEnvios;";
|
||||||
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
|
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);
|
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
|
||||||
commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
|
commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
|
||||||
@@ -1476,17 +1493,27 @@ namespace compabetov2.database
|
|||||||
SQLiteDataReader reader = commandConsulta.ExecuteReader();
|
SQLiteDataReader reader = commandConsulta.ExecuteReader();
|
||||||
|
|
||||||
long idVenta = -1;
|
long idVenta = -1;
|
||||||
while (reader.Read())
|
while (reader.Read()) idVenta = reader.GetInt64(0);
|
||||||
{
|
|
||||||
idVenta = reader.GetInt64(0);
|
|
||||||
}
|
|
||||||
foreach (DetalleEnvioModel detalleEnvio in detallesEnvio)
|
foreach (DetalleEnvioModel detalleEnvio in detallesEnvio)
|
||||||
{
|
{
|
||||||
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
|
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
|
||||||
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
|
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.Parameters.AddWithValue("@cantidada", detalleEnvio.cantidad);
|
||||||
commandEmpleado.ExecuteNonQuery();
|
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();
|
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 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), " +
|
"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_producto) REFERENCES producto(idproducto))",
|
"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 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);",
|
"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 class DetalleEnvioModel
|
||||||
{
|
{
|
||||||
public int idEnvio;
|
public int idEnvio;
|
||||||
public Producto producto;
|
public Variante producto;
|
||||||
public int cantidad;
|
public int cantidad;
|
||||||
|
|
||||||
public DetalleEnvioModel(int idEnvio, Producto producto, int cantidad)
|
public DetalleEnvioModel(int idEnvio, Variante producto, int cantidad)
|
||||||
{
|
{
|
||||||
this.idEnvio = idEnvio;
|
this.idEnvio = idEnvio;
|
||||||
this.producto = producto;
|
this.producto = producto;
|
||||||
|
|||||||
@@ -20,5 +20,10 @@ namespace compabetov2.database.modelos
|
|||||||
this.idVenta = id;
|
this.idVenta = id;
|
||||||
this.total = total;
|
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())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
int idProducto = (int)reader.GetInt64(0);
|
int idVariante = (int)reader.GetInt64(0);
|
||||||
DetalleEnvioModel detalleEnvio = new DetalleEnvioModel(
|
DetalleEnvioModel detalleEnvio = new DetalleEnvioModel(
|
||||||
idEnvio,
|
idEnvio,
|
||||||
new Producto(idProducto, reader["nombre"].ToString()),
|
new Variante(idVariante, reader["nombre"].ToString(),0,(int)reader.GetInt64(2),"", (int)reader.GetInt64(3)),//fkproducto
|
||||||
(int)reader.GetInt64(2)
|
(int)reader.GetInt64(4)//cantidad
|
||||||
);
|
);
|
||||||
detallesEnvio.Add(detalleEnvio);
|
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)
|
public static bool concluirEnvio(Envio envio, List<DetalleEnvioModel> detallesEnvio)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user