diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index 3879607..59390c5 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -1,7 +1,9 @@ { "ExpandedNodes": [ - "" + "", + "\\database", + "\\Ventas" ], - "SelectedNode": "\\Solution.sln", + "SelectedNode": "\\database\\DAO.cs", "PreviewInSolutionExplorer": false } \ No newline at end of file diff --git a/Cuentas/cuentas.cs b/Cuentas/cuentas.cs index 7fc9336..fa4499d 100644 --- a/Cuentas/cuentas.cs +++ b/Cuentas/cuentas.cs @@ -116,11 +116,20 @@ namespace compabetov2 btnVer.Click += new EventHandler(delegate (object sender, EventArgs e) { List detalles = service.conseguirDetalleCuante(cuenta.id); + List importes = service.conseguirImportesCuenta(cuenta.id); string mensaje = $"Cliente: {cuenta.cliente}\n"; foreach (DetalleCuentaModel detalle in detalles) { mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n"; } + + decimal totalImporte = 0; + foreach (DetalleImporteCuenta importe in importes) + { + totalImporte += importe.cantidad * importe.precioImporte; + } + mensaje += $"Importe: {totalImporte}\n"; + MessageBox.Show(mensaje); }); @@ -139,7 +148,8 @@ namespace compabetov2 if (result == DialogResult.Yes) { List detalles = service.conseguirDetalleCuante(cuenta.id); - if (service.saldarCuenta(cuenta, detalles)) + List importes = service.conseguirImportesCuenta(cuenta.id); + if (service.saldarCuenta(cuenta, detalles, importes)) { llenarPanel(); } @@ -196,11 +206,18 @@ namespace compabetov2 btnVer.Click += new EventHandler(delegate (object sender, EventArgs e) { List detalles = service.conseguirDetalleCuante(cuenta.id); + List importes = service.conseguirImportesCuenta(cuenta.id); string mensaje = $"Cliente: {cuenta.cliente}\n"; foreach (DetalleCuentaModel detalle in detalles) { mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n"; } + decimal totalImporte = 0; + foreach (DetalleImporteCuenta importe in importes) + { + totalImporte += importe.cantidad * importe.precioImporte; + } + mensaje += $"Importe: {totalImporte}\n"; MessageBox.Show(mensaje); }); diff --git a/Envios/envios.cs b/Envios/envios.cs index 4136381..257c038 100644 --- a/Envios/envios.cs +++ b/Envios/envios.cs @@ -68,9 +68,10 @@ namespace compabetov2 private void llenarPanel() { panelEnvio.Controls.Clear(); - List envios = service.conseguirEnvio(); - foreach(Envio envio in envios) + List> envios_importes_list = service.conseguirEnvio(); + foreach(Dictionary envio_importes in envios_importes_list) { + Envio envio = envio_importes["envio"]; if (envio.estado.Equals("EN PROCESO")) { TableLayoutPanel carta = new TableLayoutPanel(); @@ -133,11 +134,20 @@ namespace compabetov2 { List detalles = service.conseguirDetalleEnvio(envio.id); string mensaje = ""; + decimal cantidadImportes = 0; foreach (DetalleEnvioModel detalle in detalles) { mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n"; + + foreach(DetalleImporteEnvio importe in envio_importes["importes"]) + { + cantidadImportes = importe.cantidad * importe.precioImporte; + } + } + mensaje += $"Importe: {cantidadImportes}\n"; mensaje += $"Total: {envio.total}"; + MessageBox.Show(mensaje); }); @@ -156,7 +166,7 @@ namespace compabetov2 if (result == DialogResult.Yes) { List detalles = service.conseguirDetalleEnvio(envio.id); - if (service.concluirEnvio(envio, detalles)) + if (service.concluirEnvio(envio, detalles, envio_importes["importes"])) { llenarPanel(); ImprimirTicketConcluido(envio); diff --git a/Ventas/Importe1.cs b/Ventas/Importe1.cs index ce43c0b..83955ef 100644 --- a/Ventas/Importe1.cs +++ b/Ventas/Importe1.cs @@ -156,7 +156,7 @@ namespace compabetov2.Ventas private void modificarCantidad(int cantidad, int idImporte) { - detalles[idImporte-1].catidad = cantidad; + detalles[idImporte-1].cantidad = cantidad; } private void Importe1_Load(object sender, EventArgs e) diff --git a/Ventas/datosCuenta.cs b/Ventas/datosCuenta.cs index 5d4f15c..492f7d4 100644 --- a/Ventas/datosCuenta.cs +++ b/Ventas/datosCuenta.cs @@ -17,12 +17,14 @@ namespace compabetov2.Ventas private Cuenta ventaModel; private List detalles; private vender ventanaPadre; - public datosCuenta(Cuenta ventaModel, List detalles, vender ventanaPadre) + private List importes; + public datosCuenta(Cuenta ventaModel, List detalles, List importes, vender ventanaPadre) { InitializeComponent(); this.ventaModel = ventaModel; this.detalles = detalles; this.ventanaPadre = ventanaPadre; + this.importes = importes; } private void datosCuenta_Load(object sender, EventArgs e) @@ -33,12 +35,13 @@ namespace compabetov2.Ventas private void btnAceptar_Click(object sender, EventArgs e) { ventaModel.cliente = txtCliente.Text; - if (service.crearCuenta(ventaModel, detalles)) + if (service.crearCuenta(ventaModel, detalles, importes)) { MessageBox.Show("Fiado"); ventanaPadre.eliminarProductosTocket(); ventanaPadre.llenarLayout(); ventanaPadre.total = 0; + ventanaPadre.importes.Clear(); Close(); } } diff --git a/Ventas/datosEnvio.cs b/Ventas/datosEnvio.cs index 1a6b758..f3d953f 100644 --- a/Ventas/datosEnvio.cs +++ b/Ventas/datosEnvio.cs @@ -21,13 +21,15 @@ namespace compabetov2.Ventas public string Telefono => txtTelefono.Text; private Envio envio; List detallesEnvio; + List importes; vender ventanaPadre; - public datosEnvio(Envio envio, List detallesEnvio, vender ventanaPadre) + public datosEnvio(Envio envio, List detallesEnvio, List importes, vender ventanaPadre) { InitializeComponent(); this.envio = envio; this.detallesEnvio = detallesEnvio; this.ventanaPadre = ventanaPadre; + this.importes = importes; txtTelefono.KeyPress += new KeyPressEventHandler(txtTelefono_KeyPress); } @@ -38,14 +40,15 @@ namespace compabetov2.Ventas envio.cliente = txtCliente.Text; envio.direccion = txtDireccion.Text; envio.telefono = txtTelefono.Text; - if (service.crearEnvio(envio, detallesEnvio)) + + if (service.crearEnvio(envio, detallesEnvio, importes)) { MessageBox.Show("Envio hecho"); ImprimirTicketEnvio(); ventanaPadre.eliminarProductosTocket(); ventanaPadre.llenarLayout(); ventanaPadre.total = 0; - + ventanaPadre.importes.Clear(); this.Close(); } } @@ -197,7 +200,7 @@ namespace compabetov2.Ventas envio.cliente = txtCliente.Text; envio.direccion = txtDireccion.Text; envio.telefono = txtTelefono.Text; - if (service.crearEnvio(envio, detallesEnvio)) + if (service.crearEnvio(envio, detallesEnvio, importes)) { MessageBox.Show("Envio hecho"); ImprimirTicketEnvio(); diff --git a/Ventas/vender.cs b/Ventas/vender.cs index 490cab5..6d93327 100644 --- a/Ventas/vender.cs +++ b/Ventas/vender.cs @@ -75,7 +75,9 @@ namespace compabetov2 private void FlowLayoutPanel3_MouseUp(object sender, MouseEventArgs e) { - flowLayoutPanel3.Capture = false; + + lastPoint = new Point(e.X, e.Y); + flowLayoutPanel3.Capture = true; } @@ -777,7 +779,7 @@ namespace compabetov2 { Cuenta ventaModel = new Cuenta(total); - datosCuenta datoCuenta = new datosCuenta(ventaModel, detallesCuenta, this); + datosCuenta datoCuenta = new datosCuenta(ventaModel, detallesCuenta,importes, this); datoCuenta.Show(); } @@ -837,7 +839,7 @@ namespace compabetov2 Envio envio = new Envio(-1, DateTime.Now.ToString(), "", "", responsable, "", "", total); if (detallesEnvio.Count > 0) { - datosEnvio datosEnvio = new datosEnvio(envio, detallesEnvio, this); + datosEnvio datosEnvio = new datosEnvio(envio, detallesEnvio,importes ,this); datosEnvio.Show(); } else @@ -879,7 +881,7 @@ namespace compabetov2 decimal totalImporte = 0; foreach(DetalleImporte importe in importes) { - totalImporte += importe.precioImporte * importe.catidad; + totalImporte += importe.precioImporte * importe.cantidad; } total += totalImporte; label1.Text = $"Total: ${total}"; diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index 870fe7a..df18aa2 100644 Binary files a/bin/Debug/compabetov2.exe and b/bin/Debug/compabetov2.exe differ diff --git a/bin/Debug/compabetov2.pdb b/bin/Debug/compabetov2.pdb index 39a2a0d..70cf87a 100644 Binary files a/bin/Debug/compabetov2.pdb and b/bin/Debug/compabetov2.pdb differ diff --git a/bin/Debug/data.db b/bin/Debug/data.db index c782e82..9e77377 100644 Binary files a/bin/Debug/data.db and b/bin/Debug/data.db differ diff --git a/compabetov2.csproj b/compabetov2.csproj index 3fd4e54..191ef8d 100644 --- a/compabetov2.csproj +++ b/compabetov2.csproj @@ -108,6 +108,8 @@ + + diff --git a/database/DAO.cs b/database/DAO.cs index daad4ec..8eacccd 100644 --- a/database/DAO.cs +++ b/database/DAO.cs @@ -440,7 +440,7 @@ namespace compabetov2.database conexion.Open(); - string sql = "SELECT * FROM Producto INNER JOIN Categoria ON Producto.fk_idcategoria = Categoria.idcategoria"; + string sql = "SELECT * FROM Producto"; SQLiteCommand command = new SQLiteCommand(sql, conexion); reader = command.ExecuteReader(); @@ -752,11 +752,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_variante, cantidad) VALUES(@idVenta, @fk_variante, @cantidada);"; + string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_variante, cantidad,precioCompra,precioVenta) VALUES(@idVenta, @fk_variante, @cantidada,@precioCompra,@precioVenta);"; 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)"; + string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fk_venta) VALUES (@fk_importe,@cantidad,@precio,@fk_venta)"; // CREACION DE LA VENTA SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion); @@ -782,6 +782,8 @@ namespace compabetov2.database commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta); commandEmpleado.Parameters.AddWithValue("@fk_variante", detalleVenta.producto.idVariante); commandEmpleado.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad); + commandEmpleado.Parameters.AddWithValue("@precioCompra", detalleVenta.producto.precioCompra); + commandEmpleado.Parameters.AddWithValue("@precioVenta", detalleVenta.producto.precio); commandEmpleado.ExecuteNonQuery(); SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion); @@ -807,13 +809,13 @@ namespace compabetov2.database //creacion del importe foreach (DetalleImporte importe in importes) { - if (importe.catidad != 0) + if (importe.cantidad != 0) { SQLiteCommand commandDetalleImporte = new SQLiteCommand(sqlImporte, conexion); commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte); - commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.catidad); + commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.cantidad); commandDetalleImporte.Parameters.AddWithValue("@precio", importe.precioImporte); - commandDetalleImporte.Parameters.AddWithValue("@fecha", DateTime.Now.ToString()); + commandDetalleImporte.Parameters.AddWithValue("@fk_venta", idVenta); commandDetalleImporte.ExecuteNonQuery(); } } @@ -854,11 +856,11 @@ namespace compabetov2.database //creacion del importe foreach (DetalleImporte importe in importes) { - if (importe.catidad != 0) + if (importe.cantidad != 0) { SQLiteCommand commandDetalleImporte = new SQLiteCommand(sqlImporte, conexion); commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte); - commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.catidad); + commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.cantidad); commandDetalleImporte.Parameters.AddWithValue("@precio", importe.precioImporte); commandDetalleImporte.Parameters.AddWithValue("@fecha", DateTime.Now.ToString()); commandDetalleImporte.ExecuteNonQuery(); @@ -968,7 +970,7 @@ namespace compabetov2.database } } - public static bool crearCuentaDAO(Cuenta cuenta, List detalleCuentas) + public static bool crearCuentaDAO(Cuenta cuenta, List detalleCuentas, List importes) { var db_conexion = new Conexion(); try @@ -986,6 +988,7 @@ namespace compabetov2.database 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"; + string sqlImporte = "INSERT INTO detalle_importe_cuenta (fk_importe, cantidad, precio, fk_cuenta) VALUES(@fk_importe, @cantidad, @precio, @fk_cuenta);"; SQLiteCommand commandCuenta = new SQLiteCommand(sqlCuenta, conexion); commandCuenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString()); @@ -1029,6 +1032,18 @@ namespace compabetov2.database commandProdcutoUpdate.ExecuteNonQuery(); } + foreach(DetalleImporte importe in importes) + { + if(importe.cantidad != 0) { + SQLiteCommand commandImportes = new SQLiteCommand(sqlImporte, conexion); + commandImportes.Parameters.AddWithValue("@fk_importe", importe.fkImporte); + commandImportes.Parameters.AddWithValue("@cantidad", importe.cantidad); + commandImportes.Parameters.AddWithValue("@precio", importe.precioImporte); + commandImportes.Parameters.AddWithValue("@fk_cuenta", idCuenta); + commandImportes.ExecuteNonQuery(); + } + } + transaccion.Commit(); return true; } @@ -1074,6 +1089,31 @@ namespace compabetov2.database } } + public static SQLiteDataReader conseguirImportesCuentaDAO(int idCuenta) + { + SQLiteDataReader reader = null; + var db_conexion = new Conexion(); + try + { + SQLiteConnection conexion = db_conexion.get_connection(); + + conexion.Open(); + + string sql = "SELECT * FROM detalle_importe_cuenta WHERE fk_cuenta = @fk_cuenta;"; + SQLiteCommand command = new SQLiteCommand(sql, conexion); + command.Parameters.AddWithValue("@fk_cuenta", idCuenta); + reader = command.ExecuteReader(); + + return reader; + + } + catch (SQLiteException ex) + { + MessageBox.Show(ex.Message); + return reader; + } + } + public static bool cancelarCuentaDAO(int idCuenta) { var db_conexion = new Conexion(); @@ -1113,7 +1153,7 @@ namespace compabetov2.database } } - public static bool saldarCuentaDAO(Cuenta cuenta, List detallesCuentas) + public static bool saldarCuentaDAO(Cuenta cuenta, List detallesCuentas, List importes) { var db_conexion = new Conexion(); try @@ -1130,6 +1170,8 @@ namespace compabetov2.database 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"; + string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fk_venta) VALUES (@fk_importe,@cantidad,@precio,@fk_venta)"; + SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion); @@ -1158,6 +1200,19 @@ namespace compabetov2.database commandEmpleado.ExecuteNonQuery(); } + foreach (DetalleImporteCuenta importe in importes) + { + if (importe.cantidad != 0) + { + SQLiteCommand commandDetalleImporte = new SQLiteCommand(sqlImporte, conexion); + commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte); + commandDetalleImporte.Parameters.AddWithValue("@cantidad", importe.cantidad); + commandDetalleImporte.Parameters.AddWithValue("@precio", importe.precioImporte); + commandDetalleImporte.Parameters.AddWithValue("@fk_venta", idVenta); + commandDetalleImporte.ExecuteNonQuery(); + } + } + transaccion.Commit(); return true; } @@ -1253,12 +1308,12 @@ namespace compabetov2.database } } - public static bool crearEnvio(Envio envio, List detallesEnvio) + public static bool crearEnvio(Envio envio, List detallesEnvio, List importes) { - return DAO.crearEnvioDAO(envio, detallesEnvio); + return DAO.crearEnvioDAO(envio, detallesEnvio, importes); } - public static bool crearEnvioDAO(Envio envio, List detallesEnvio) + public static bool crearEnvioDAO(Envio envio, List detallesEnvio, List importes) { var db_conexion = new Conexion(); try @@ -1272,8 +1327,9 @@ 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_variante, cantidad) VALUES(@fk_envios, @fk_variante, @cantidad);"; + string sqlDetalle = "INSERT INTO detalle_envios (fk_envios, fk_variante, cantidad,precioVenta,precioCompra) VALUES(@fk_envios, @fk_variante, @cantidad, @precioVenta,@precioCompra);"; string sqlIdCuenta = "SELECT idEnvios FROM envios ORDER BY idEnvios DESC LIMIT 1"; + string sqlImporte = "INSERT INTO detalle_importe_envio (fk_importe, cantidad, precio, fk_envio) VALUES(@fk_importe, @cantidad, @precio, @fk_envio);"; SQLiteCommand commandCuenta = new SQLiteCommand(sqlEnvio, conexion); commandCuenta.Parameters.AddWithValue("@fecha", envio.fecha); @@ -1299,9 +1355,24 @@ namespace compabetov2.database commandDetalle.Parameters.AddWithValue("@fk_envios", idEnvio); commandDetalle.Parameters.AddWithValue("@fk_variante", detalleEnvio.producto.idVariante); commandDetalle.Parameters.AddWithValue("@cantidad", detalleEnvio.cantidad); + commandDetalle.Parameters.AddWithValue("@precioVenta", detalleEnvio.producto.precio); + commandDetalle.Parameters.AddWithValue("@precioCompra", detalleEnvio.producto.precioCompra); commandDetalle.ExecuteNonQuery(); } + //creacion de importes + foreach(DetalleImporte importe in importes) + { + if(importe.cantidad != 0) { + SQLiteCommand commandImportes = new SQLiteCommand(sqlImporte, conexion); + commandImportes.Parameters.AddWithValue("@fk_importe", importe.fkImporte); + commandImportes.Parameters.AddWithValue("@cantidad", importe.cantidad); + commandImportes.Parameters.AddWithValue("@precio", importe.precioImporte); + commandImportes.Parameters.AddWithValue("@fk_envio", idEnvio); + commandImportes.ExecuteNonQuery(); + } + } + transaccion.Commit(); return true; } @@ -1345,6 +1416,31 @@ namespace compabetov2.database } } + public static SQLiteDataReader conseguirImporteEnvio(int idEnvio) + { + SQLiteDataReader reader = null; + var db_conexion = new Conexion(); + try + { + SQLiteConnection conexion = db_conexion.get_connection(); + + conexion.Open(); + + string sql = "SELECT * FROM detalle_importe_envio where fk_envio = @idEnvio"; + SQLiteCommand command = new SQLiteCommand(sql, conexion); + command.Parameters.AddWithValue("@idEnvio", idEnvio); + reader = command.ExecuteReader(); + + return reader; + + } + catch (SQLiteException ex) + { + MessageBox.Show(ex.Message); + return reader; + } + } + public static SQLiteDataReader conseguirDetalleEnvioDAO(int idEnvio) { SQLiteDataReader reader = null; @@ -1515,7 +1611,7 @@ namespace compabetov2.database } - public static bool concluirEnvioDAO(Envio envio, List detallesEnvio) + public static bool concluirEnvioDAO(Envio envio, List detallesEnvio, List importes) { var db_conexion = new Conexion(); try @@ -1534,6 +1630,7 @@ namespace compabetov2.database 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"; + string sqlImporte = "INSERT INTO detalle_importe (fk_importe, cantidad, precio, fk_venta) VALUES(@fk_importe, @cantidad, @precio, @fk_venta);"; SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion); commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString()); @@ -1572,6 +1669,19 @@ namespace compabetov2.database commandActualizarStock.ExecuteNonQuery(); } + foreach(DetalleImporteEnvio importe in importes) + { + if (importe.cantidad != 0) + { + SQLiteCommand commandImporte = new SQLiteCommand(sqlImporte, conexion); + commandImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte); + commandImporte.Parameters.AddWithValue("@cantidad", importe.cantidad); + commandImporte.Parameters.AddWithValue("@precio", importe.precioImporte); + commandImporte.Parameters.AddWithValue("@fk_venta", idVenta); + commandImporte.ExecuteNonQuery(); + } + } + transaccion.Commit(); return true; } diff --git a/database/modelos/DetalleImporte.cs b/database/modelos/DetalleImporte.cs index d7cac40..e18d508 100644 --- a/database/modelos/DetalleImporte.cs +++ b/database/modelos/DetalleImporte.cs @@ -9,14 +9,16 @@ namespace compabetov2.database.modelos public class DetalleImporte { public int fkImporte; - public int catidad; + public int cantidad; public decimal precioImporte; + public int fkVenta; - public DetalleImporte(int fkImporte, int cantidad, decimal precioImporte) + public DetalleImporte(int fkImporte, int cantidad, decimal precioImporte, int fkVenta = -1) { this.fkImporte = fkImporte; - this.catidad = cantidad; + this.cantidad = cantidad; this.precioImporte = precioImporte; + this.fkVenta = fkVenta; } } } diff --git a/database/modelos/DetalleImporteCuenta.cs b/database/modelos/DetalleImporteCuenta.cs new file mode 100644 index 0000000..a54d7a2 --- /dev/null +++ b/database/modelos/DetalleImporteCuenta.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace compabetov2.database.modelos +{ + public class DetalleImporteCuenta + { + public int fkImporte; + public int cantidad; + public decimal precioImporte; + public int fkCuenta; + + public DetalleImporteCuenta(int fkImporte, int cantidad, decimal precioImporte, int fkCuenta = -1) + { + this.fkImporte = fkImporte; + this.cantidad = cantidad; + this.precioImporte = precioImporte; + this.fkCuenta = fkCuenta; + } + } +} diff --git a/database/modelos/DetalleImporteEnvio.cs b/database/modelos/DetalleImporteEnvio.cs new file mode 100644 index 0000000..a0edf99 --- /dev/null +++ b/database/modelos/DetalleImporteEnvio.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace compabetov2.database.modelos +{ + public class DetalleImporteEnvio + { + public int fkImporte; + public int cantidad; + public decimal precioImporte; + public int fkEnvio; + + public DetalleImporteEnvio(int fkImporte, int cantidad, decimal precioImporte, int fkEnvio = -1) + { + this.fkImporte = fkImporte; + this.cantidad = cantidad; + this.precioImporte = precioImporte; + this.fkEnvio = fkEnvio; + } + } +} diff --git a/database/modelos/DetalleVentaModel.cs b/database/modelos/DetalleVentaModel.cs index 52c73cb..8de0221 100644 --- a/database/modelos/DetalleVentaModel.cs +++ b/database/modelos/DetalleVentaModel.cs @@ -13,6 +13,7 @@ namespace compabetov2.database.modelos public Variante producto; public decimal total; + public DetalleVentaModel(int cantidad, Variante producto, int id = -1, decimal total = 0) { this.cantidad = cantidad; diff --git a/database/modelos/Variante.cs b/database/modelos/Variante.cs index bf1ca3a..671547a 100644 --- a/database/modelos/Variante.cs +++ b/database/modelos/Variante.cs @@ -14,8 +14,9 @@ namespace compabetov2.database.modelos public int cantidad; public string img; public int fkProducto; + public decimal precioCompra; - public Variante(int idVariante, string nombre, decimal precio, int cantidad, string img, int fkProducto) + public Variante(int idVariante, string nombre, decimal precio, int cantidad, string img, int fkProducto,decimal precioCompra) { this.idVariante = idVariante; this.nombre = nombre; @@ -23,6 +24,7 @@ namespace compabetov2.database.modelos this.cantidad = cantidad; this.img = img; this.fkProducto = fkProducto; + this.precioCompra = precioCompra; } } } diff --git a/database/service.cs b/database/service.cs index 93e5526..cbd03b2 100644 --- a/database/service.cs +++ b/database/service.cs @@ -45,10 +45,7 @@ namespace compabetov2.database while (reader.Read()) { - Categoria categoria = new Categoria( - int.Parse(reader["idcategoria"].ToString()), - reader["nombre"].ToString(), - reader["descripcion"].ToString()); + Categoria categoria = new Categoria(); Producto producto = new Producto( int.Parse(reader["idproducto"].ToString()), @@ -222,9 +219,9 @@ namespace compabetov2.database return DAO.actualizarMermaDAO(merma); } - public static bool crearCuenta(Cuenta cuenta, List detalleCuentas) + public static bool crearCuenta(Cuenta cuenta, List detalleCuentas, List importes) { - return DAO.crearCuentaDAO(cuenta, detalleCuentas); + return DAO.crearCuentaDAO(cuenta, detalleCuentas, importes); } public static List conseguirCuentaDAO() @@ -263,8 +260,9 @@ namespace compabetov2.database while (reader.Read()) { int idVariaante = (int)reader.GetInt64(0); + decimal precioCompra = reader.GetOrdinal("precioCompra"); DetalleCuentaModel detalleCuenta = new DetalleCuentaModel( - new Variante(idVariaante, reader["nombre"].ToString(),0,(int)reader.GetInt64(2),"",(int)reader.GetInt64(3)), + new Variante(idVariaante, reader["nombre"].ToString(),0,(int)reader.GetInt64(2),"",(int)reader.GetInt64(3), precioCompra), (int)reader.GetInt64(4) ); detallesCuentas.Add(detalleCuenta); @@ -273,14 +271,35 @@ namespace compabetov2.database return detallesCuentas; } + public static List conseguirImportesCuenta(int idCuenta) + { + List importes = new List(); + + SQLiteDataReader reader = DAO.conseguirImportesCuentaDAO(idCuenta); + + while (reader.Read()) + { + int idImporte = (int)reader.GetInt64(1); + DetalleImporteCuenta importe = new DetalleImporteCuenta( + idImporte, + (int)reader.GetInt64(2),//cantidad + (int)reader.GetDecimal(3),// precio + (int)reader.GetInt64(4)//fk_cuenta + ); + importes.Add(importe); + } + + return importes; + } + public static bool cancelarCuenta(int idCuenta) { return DAO.cancelarCuentaDAO(idCuenta); } - public static bool saldarCuenta(Cuenta cuenta, List detallesCuentas) + public static bool saldarCuenta(Cuenta cuenta, List detallesCuentas, List importes) { - return DAO.saldarCuentaDAO(cuenta, detallesCuentas); + return DAO.saldarCuentaDAO(cuenta, detallesCuentas, importes); } /*public static Dictionary filtrarVentaFechaMes(DateTime fecha) @@ -314,18 +333,19 @@ namespace compabetov2.database return estadisticas; }*/ - public static bool crearEnvio(Envio envio, List detallesEnvio) + public static bool crearEnvio(Envio envio, List detallesEnvio, List importes) { - return DAO.crearEnvio(envio, detallesEnvio); + return DAO.crearEnvio(envio, detallesEnvio,importes); } - public static List conseguirEnvio() + public static List> conseguirEnvio() { - List envios = new List(); + List> envios = new List>(); SQLiteDataReader reader = DAO.conseguirEnvioDAO(); while (reader.Read()) { + Dictionary dict = new Dictionary(); decimal total = reader.GetDecimal(6); Envio envio = new Envio( (int)reader.GetInt64(0), @@ -338,7 +358,23 @@ namespace compabetov2.database total ) ; - envios.Add(envio); + dict.Add("envio", envio); + + List importes = new List(); + SQLiteDataReader readerImporte = DAO.conseguirImporteEnvio(envio.id); + while (readerImporte.Read()) + { + decimal precio = readerImporte.GetDecimal(3); + importes.Add(new DetalleImporteEnvio( + (int)readerImporte.GetInt64(1),//id + (int)readerImporte.GetInt64(2),//cantidad + precio,//precio + (int)readerImporte.GetInt64(4)//fk_envio + )); + } + + dict.Add("importes",importes); + envios.Add(dict); } return envios; @@ -353,9 +389,10 @@ namespace compabetov2.database while (reader.Read()) { int idVariante = (int)reader.GetInt64(0); + decimal precioCompra = reader.GetOrdinal("precioCompra"); DetalleEnvioModel detalleEnvio = new DetalleEnvioModel( idEnvio, - new Variante(idVariante, reader["nombre"].ToString(),0,(int)reader.GetInt64(2),"", (int)reader.GetInt64(3)),//fkproducto + new Variante(idVariante, reader["nombre"].ToString(),0,(int)reader.GetInt64(2),"", (int)reader.GetInt64(3), precioCompra),//fkproducto (int)reader.GetInt64(4)//cantidad ); detallesEnvio.Add(detalleEnvio); @@ -375,9 +412,9 @@ namespace compabetov2.database return DAO.cancelarEnvioDAO(envio, detalles); } - public static bool concluirEnvio(Envio envio, List detallesEnvio) + public static bool concluirEnvio(Envio envio, List detallesEnvio, List importes) { - return DAO.concluirEnvioDAO(envio, detallesEnvio); + return DAO.concluirEnvioDAO(envio, detallesEnvio, importes); } public static Dictionary>> estadisticas(DateTime fecha) @@ -403,6 +440,7 @@ namespace compabetov2.database SQLiteDataReader readerDetalleVenta = DAO.conseguirDetalleVenta(venta); while (readerDetalleVenta.Read()) { + decimal precioCompra = readerDetalleVenta.GetOrdinal("precioCompra"); DetalleVentaModel detalleVenta = new DetalleVentaModel( (int)readerDetalleVenta.GetInt64(2), new Variante((int)readerDetalleVenta.GetInt64(3), @@ -410,7 +448,8 @@ namespace compabetov2.database readerDetalleVenta.GetDecimal(5), (int)readerDetalleVenta.GetInt64(6), "", - (int)readerDetalleVenta.GetInt64(8)) + (int)readerDetalleVenta.GetInt64(8), + precioCompra) ); detallesVenta.Add( detalleVenta ); } @@ -449,6 +488,7 @@ namespace compabetov2.database int cantidadIndex = reader.GetOrdinal("cantidad"); int imgIndex = reader.GetOrdinal("img"); int fkProductoIndex = reader.GetOrdinal("fk_producto"); + decimal precioCompra = reader.GetOrdinal("precioCompra"); while (reader.Read()) { @@ -459,7 +499,8 @@ namespace compabetov2.database reader.GetDecimal(precioIndex), reader.GetInt32(cantidadIndex), reader.GetString(imgIndex), - reader.GetInt32(fkProductoIndex) + reader.GetInt32(fkProductoIndex), + precioCompra ); productos.Add(producto); @@ -505,6 +546,7 @@ namespace compabetov2.database while (reader.Read()) { decimal precio = reader.GetDecimal(2); + decimal precioCompra = reader.GetDecimal(6); int cantidad = (int)reader.GetInt64(3); int fkProducto = (int)reader.GetInt64(5); Variante vaiante = new Variante( @@ -513,7 +555,8 @@ namespace compabetov2.database precio, cantidad, reader["img"].ToString(), - fkProducto + fkProducto, + precioCompra ); variantes.Add(vaiante); } diff --git a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache index fc987e0..fc2c8f9 100644 --- a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache +++ b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -7b47ab10239919af7b32ed2b287710792024b987ca7846a8d66ef868f8836793 +589875dc9085d077e48293cb909f4ec97a14e8901c3e585e6068a4b13e6e810b diff --git a/obj/Debug/compabetov2.csproj.GenerateResource.cache b/obj/Debug/compabetov2.csproj.GenerateResource.cache index 068f86f..8077c86 100644 Binary files a/obj/Debug/compabetov2.csproj.GenerateResource.cache and b/obj/Debug/compabetov2.csproj.GenerateResource.cache differ diff --git a/obj/Debug/compabetov2.exe b/obj/Debug/compabetov2.exe index 870fe7a..df18aa2 100644 Binary files a/obj/Debug/compabetov2.exe and b/obj/Debug/compabetov2.exe differ diff --git a/obj/Debug/compabetov2.pdb b/obj/Debug/compabetov2.pdb index 39a2a0d..70cf87a 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ