todo lo relacionado a cuentas funcionando
This commit is contained in:
+2
-41
@@ -740,7 +740,8 @@ namespace compabetov2
|
|||||||
|
|
||||||
private void btnFiar_Click(object sender, EventArgs e)
|
private void btnFiar_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
List<DetalleCuentaModel> detallesCuenta = listaProductosCuenta();
|
List<DetalleCuentaModel> detallesCuenta = new List<DetalleCuentaModel>();
|
||||||
|
foreach (DetalleVentaModel detalleVenta in carrito) detallesCuenta.Add(detalleVenta.convertirADetalleCuenta());
|
||||||
|
|
||||||
|
|
||||||
if (detallesCuenta.Count > 0)
|
if (detallesCuenta.Count > 0)
|
||||||
@@ -758,46 +759,6 @@ namespace compabetov2
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DetalleCuentaModel> listaProductosCuenta()
|
|
||||||
{
|
|
||||||
List<DetalleCuentaModel> detallesCuentas = new List<DetalleCuentaModel>();
|
|
||||||
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]);
|
|
||||||
|
|
||||||
DetalleCuentaModel detalleCuenta = new DetalleCuentaModel(producto, cantidad);
|
|
||||||
|
|
||||||
|
|
||||||
detallesCuentas.Add(detalleCuenta);
|
|
||||||
}
|
|
||||||
|
|
||||||
return detallesCuentas;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void responsablecb_SelectedIndexChanged(object sender, EventArgs e)
|
private void responsablecb_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Verificar si hay un elemento seleccionado en el ComboBox
|
// Verificar si hay un elemento seleccionado en el ComboBox
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+11
-10
@@ -942,7 +942,7 @@ namespace compabetov2.database
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sqlCuenta = "INSERT INTO cuenta (total, fecha, estado, descripcion,cliente) VALUES(@total, @fecha, 'ACTIVO', @descripcion,@cliente);";
|
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 sqlIdCuenta = "SELECT idCuenta FROM cuenta ORDER BY idCuenta DESC LIMIT 1";
|
||||||
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
|
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
|
||||||
string sqlProductoUpdate = "UPDATE Producto SET stock = @stock 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);
|
SQLiteCommand commandDetalle = new SQLiteCommand(sqlDetalle, conexion);
|
||||||
commandDetalle.Parameters.AddWithValue("@fk_cuenta", idCuenta);
|
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.Parameters.AddWithValue("@cantidad", detalleCuenta.cantidad);
|
||||||
commandDetalle.ExecuteNonQuery();
|
commandDetalle.ExecuteNonQuery();
|
||||||
|
|
||||||
//modificar stock
|
//modificar stock
|
||||||
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
|
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
|
||||||
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.idProducto);
|
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.fkProducto);
|
||||||
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
|
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
|
||||||
|
|
||||||
int stockActual = -1;
|
int stockActual = -1;
|
||||||
@@ -984,8 +984,8 @@ namespace compabetov2.database
|
|||||||
}
|
}
|
||||||
|
|
||||||
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
|
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
|
||||||
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleCuenta.cantidad);
|
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - (detalleCuenta.cantidad * detalleCuenta.producto.cantidad));
|
||||||
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.idProducto);
|
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleCuenta.producto.fkProducto);
|
||||||
commandProdcutoUpdate.ExecuteNonQuery();
|
commandProdcutoUpdate.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1018,7 +1018,8 @@ namespace compabetov2.database
|
|||||||
|
|
||||||
conexion.Open();
|
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);
|
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||||
command.Parameters.AddWithValue("@fk_cuenta", idCuenta);
|
command.Parameters.AddWithValue("@fk_cuenta", idCuenta);
|
||||||
reader = command.ExecuteReader();
|
reader = command.ExecuteReader();
|
||||||
@@ -1086,7 +1087,7 @@ namespace compabetov2.database
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sqlVenta = "INSERT INTO venta (fecha, total) VALUES(@fecha, @total);";
|
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 sqlCuenta = "UPDATE cuenta SET estado ='SALDADO' WHERE idCuenta = @idCuenta;";
|
||||||
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
|
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);
|
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
|
||||||
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
|
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.Parameters.AddWithValue("@cantidada", detalleCuenta.cantidad);
|
||||||
commandEmpleado.ExecuteNonQuery();
|
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 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), " +
|
"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_producto) REFERENCES producto(idproducto))",
|
"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)",
|
"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 class DetalleCuentaModel
|
||||||
{
|
{
|
||||||
public int idCuenta;
|
public int idCuenta;
|
||||||
public Producto producto;
|
public Variante producto;
|
||||||
public int cantidad;
|
public int cantidad;
|
||||||
public string nombreProducto;
|
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.idCuenta = idCuenta;
|
||||||
this.producto = producto;
|
this.producto = producto;
|
||||||
|
|||||||
@@ -25,5 +25,10 @@ namespace compabetov2.database.modelos
|
|||||||
{
|
{
|
||||||
return new DetalleEnvioModel(-1,this.producto,this.cantidad);
|
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())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
int idProducto = (int)reader.GetInt64(0);
|
int idVariaante = (int)reader.GetInt64(0);
|
||||||
DetalleCuentaModel detalleCuenta = new DetalleCuentaModel(
|
DetalleCuentaModel detalleCuenta = new DetalleCuentaModel(
|
||||||
new Producto(idProducto, reader["nombre"].ToString()),
|
new Variante(idVariaante, reader["nombre"].ToString(),0,(int)reader.GetInt64(2),"",(int)reader.GetInt64(3)),
|
||||||
(int)reader.GetInt64(2)
|
(int)reader.GetInt64(4)
|
||||||
);
|
);
|
||||||
detallesCuentas.Add(detalleCuenta);
|
detallesCuentas.Add(detalleCuenta);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user