importe en venta hecho

This commit is contained in:
carlos
2024-06-09 16:55:52 -06:00
parent 91d1661d9a
commit 7569ef0f5a
27 changed files with 987 additions and 74 deletions
+93 -33
View File
@@ -575,35 +575,6 @@ namespace compabetov2.database
}
}
public static bool insertarCategoriaDAO(Categoria categoria)
{
var db_conexion = new Conexion();
try
{
using (SQLiteConnection conexion = db_conexion.get_connection())
{
conexion.Open();
string sql = "INSERT INTO Categoria (nombre, descripcion) " +
"VALUES (@nombre, @descripcion)";
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
{
command.Parameters.AddWithValue("@nombre", categoria.nombre);
command.Parameters.AddWithValue("@descripcion", categoria.descripcion);
int filasAfectadas = command.ExecuteNonQuery();
if (filasAfectadas > 0) { return true; }
else { return false; }
}
}
}
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
public static bool insertarClienteDAO(Cliente cliente)
{
@@ -767,7 +738,7 @@ namespace compabetov2.database
}
}
public static bool crearVentaDAO(VentaModel venta, List<DetalleVentaModel> detalleVentas)
public static bool crearVentaDAO(VentaModel venta, List<DetalleVentaModel> detalleVentas, List<DetalleImporte> importes)
{
var db_conexion = new Conexion();
try
@@ -785,14 +756,16 @@ namespace compabetov2.database
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
string sqlProductoUpdate = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto";
string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fecha) VALUES (@fk_importe,@cantidad,@precio,@fecha)";
// CREACION DE LA VENTA
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
commandVenta.Parameters.AddWithValue("@total", venta.total);
commandVenta.Parameters.AddWithValue("@responzable", venta.responzable);
commandVenta.ExecuteNonQuery();
//CONSEGUIR EL ID DE LA VENTA PARA RELACIONARLO CON DETALLE VENTA
SQLiteCommand commandConsulta = new SQLiteCommand(sqlIdVenta, conexion);
SQLiteDataReader reader = commandConsulta.ExecuteReader();
@@ -802,6 +775,7 @@ namespace compabetov2.database
idVenta = reader.GetInt64(0);
}
// CREACION DE DETALLE VENTA
foreach (DetalleVentaModel detalleVenta in detalleVentas)
{
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
@@ -821,10 +795,74 @@ namespace compabetov2.database
}
//ACTUALIZACION DE STOCK
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - (detalleVenta.cantidad * detalleVenta.producto.cantidad));
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.fkProducto);
commandProdcutoUpdate.ExecuteNonQuery();
}
//creacion del importe
foreach (DetalleImporte importe in importes)
{
if (importe.catidad != 0)
{
SQLiteCommand commandDetalleImporte = new SQLiteCommand(sqlImporte, conexion);
commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte);
commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.catidad);
commandDetalleImporte.Parameters.AddWithValue("@precio", importe.precioImporte);
commandDetalleImporte.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
commandDetalleImporte.ExecuteNonQuery();
}
}
transaccion.Commit();
return true;
}
catch (SQLiteException ex)
{
transaccion.Rollback();
MessageBox.Show(ex.Message);
return false;
}
}
}
}
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
public static bool devolverImporteDAO(List<DetalleImporte> importes)
{
var db_conexion = new Conexion();
try
{
using (SQLiteConnection conexion = db_conexion.get_connection())
{
conexion.Open();
using (var transaccion = conexion.BeginTransaction())
{
try
{
string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fecha) VALUES (@fk_importe,@cantidad,@precio,@fecha)";
//creacion del importe
foreach (DetalleImporte importe in importes)
{
if (importe.catidad != 0)
{
SQLiteCommand commandDetalleImporte = new SQLiteCommand(sqlImporte, conexion);
commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte);
commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.catidad);
commandDetalleImporte.Parameters.AddWithValue("@precio", importe.precioImporte);
commandDetalleImporte.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
commandDetalleImporte.ExecuteNonQuery();
}
}
transaccion.Commit();
@@ -1389,8 +1427,6 @@ 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", envio.id);
@@ -1604,6 +1640,30 @@ namespace compabetov2.database
}
}
public static SQLiteDataReader conseguirImportesDAO()
{
SQLiteDataReader reader = null;
var db_conexion = new Conexion();
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "SELECT * FROM importe";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
reader = command.ExecuteReader();
return reader;
}
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return reader;
}
}
private static void crearDB()
{
var db_conexion = new Conexion();
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace compabetov2.database.modelos
{
public class DetalleImporte
{
public int fkImporte;
public int catidad;
public decimal precioImporte;
public DetalleImporte(int fkImporte, int cantidad, decimal precioImporte)
{
this.fkImporte = fkImporte;
this.catidad = cantidad;
this.precioImporte = precioImporte;
}
}
}
+25
View File
@@ -0,0 +1,25 @@
using compabetov2.Ventas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace compabetov2.database.modelos
{
internal class ImporteModel
{
public int idImporte;
public string tipo;
public decimal precioImporte;
public string img;
public ImporteModel(int idImporte, string tipo, decimal precioImporte, string img) {
this.idImporte = idImporte;
this.tipo = tipo;
this.img = img;
this.precioImporte = precioImporte;
}
}
}
+4 -1
View File
@@ -12,12 +12,15 @@ namespace compabetov2.database.modelos
public string fecha;
public decimal total;
public string responzable;
public int importe;
public VentaModel(decimal total = 0, int id = -1, string fecha = "", string responzable = "") {
public VentaModel(decimal total = 0, int id = -1, string fecha = "", string responzable = "", int importe = 0)
{
this.id = id;
this.fecha = fecha;
this.total = total;
this.responzable = responzable;
this.importe = importe;
}
}
}
+25 -7
View File
@@ -69,11 +69,6 @@ namespace compabetov2.database
{
return DAO.insertarProductoDAO(producto);
}
public static bool insertarCategoriaDAO(Categoria categoria)
{
return DAO.insertarCategoriaDAO(categoria);
}
public static bool insertarCliente(Cliente cliente)
{
@@ -202,9 +197,14 @@ namespace compabetov2.database
return mermas;
}
public static bool crearVentaDAO(VentaModel venta, List<DetalleVentaModel> detalleVentas)
public static bool crearVentaDAO(VentaModel venta, List<DetalleVentaModel> detalleVentas, List<DetalleImporte> importes)
{
return DAO.crearVentaDAO(venta, detalleVentas);
return DAO.crearVentaDAO(venta, detalleVentas,importes);
}
public static bool devolverImporte(List<DetalleImporte> importes)
{
return DAO.devolverImporteDAO(importes);
}
public static bool insertarMerma(Merma merma)
@@ -520,5 +520,23 @@ namespace compabetov2.database
return variantes;
}
public static List<ImporteModel> conseguirImportes()
{
List<ImporteModel> importes = new List<ImporteModel>();
SQLiteDataReader reader = DAO.conseguirImportesDAO();
while (reader.Read())
{
ImporteModel importe = new ImporteModel(
(int)reader.GetInt64(0), //id
reader.GetString(1), //tipo
reader.GetDecimal(2), //precion
reader.GetString(3) //imagen
);
importes.Add(importe);
}
return importes;
}
}
}