diff --git a/Estadiscticas.Designer.cs b/Estadiscticas.Designer.cs index c190fae..edd06e4 100644 --- a/Estadiscticas.Designer.cs +++ b/Estadiscticas.Designer.cs @@ -32,16 +32,20 @@ this.dgvDia = new System.Windows.Forms.DataGridView(); this.Producto = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Precio = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.precioCompra = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Cantidad = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Total = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.totalNeto = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.btnBuscar = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.dgvMes = new System.Windows.Forms.DataGridView(); this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.PrecioCompraMes = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.totalNetoMes = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.lbProductDia = new System.Windows.Forms.Label(); this.lbVendedorDia = new System.Windows.Forms.Label(); this.lbTotalDia = new System.Windows.Forms.Label(); @@ -51,6 +55,9 @@ this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.lbDiaSEnvio = new System.Windows.Forms.Label(); this.lbMesSEnvio = new System.Windows.Forms.Label(); + this.lbTotalDiaNeto = new System.Windows.Forms.Label(); + this.btnVentasDia = new System.Windows.Forms.Button(); + this.btnVentasMes = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dgvDia)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvMes)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); @@ -70,13 +77,16 @@ this.dgvDia.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Producto, this.Precio, + this.precioCompra, this.Cantidad, - this.Total}); + this.Total, + this.totalNeto}); this.dgvDia.Location = new System.Drawing.Point(24, 199); this.dgvDia.Name = "dgvDia"; this.dgvDia.RowHeadersWidth = 51; - this.dgvDia.Size = new System.Drawing.Size(443, 150); + this.dgvDia.Size = new System.Drawing.Size(599, 150); this.dgvDia.TabIndex = 1; + this.dgvDia.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvDia_CellContentClick); // // Producto // @@ -84,7 +94,7 @@ this.Producto.MinimumWidth = 6; this.Producto.Name = "Producto"; this.Producto.ReadOnly = true; - this.Producto.Width = 125; + this.Producto.Width = 250; // // Precio // @@ -92,7 +102,13 @@ this.Precio.MinimumWidth = 6; this.Precio.Name = "Precio"; this.Precio.ReadOnly = true; - this.Precio.Width = 125; + this.Precio.Width = 50; + // + // precioCompra + // + this.precioCompra.HeaderText = "Precio Compra"; + this.precioCompra.Name = "precioCompra"; + this.precioCompra.Width = 50; // // Cantidad // @@ -100,14 +116,20 @@ this.Cantidad.MinimumWidth = 6; this.Cantidad.Name = "Cantidad"; this.Cantidad.ReadOnly = true; - this.Cantidad.Width = 125; + this.Cantidad.Width = 50; // // Total // this.Total.HeaderText = "Total"; this.Total.MinimumWidth = 6; this.Total.Name = "Total"; - this.Total.Width = 125; + this.Total.Width = 70; + // + // totalNeto + // + this.totalNeto.HeaderText = "Total Neto"; + this.totalNeto.Name = "totalNeto"; + this.totalNeto.Width = 70; // // btnBuscar // @@ -150,12 +172,14 @@ this.dgvMes.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGridViewTextBoxColumn1, this.dataGridViewTextBoxColumn2, + this.PrecioCompraMes, this.dataGridViewTextBoxColumn3, - this.dataGridViewTextBoxColumn4}); + this.dataGridViewTextBoxColumn4, + this.totalNetoMes}); this.dgvMes.Location = new System.Drawing.Point(24, 406); this.dgvMes.Name = "dgvMes"; this.dgvMes.RowHeadersWidth = 51; - this.dgvMes.Size = new System.Drawing.Size(443, 150); + this.dgvMes.Size = new System.Drawing.Size(599, 150); this.dgvMes.TabIndex = 5; // // dataGridViewTextBoxColumn1 @@ -164,7 +188,7 @@ this.dataGridViewTextBoxColumn1.MinimumWidth = 6; this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; this.dataGridViewTextBoxColumn1.ReadOnly = true; - this.dataGridViewTextBoxColumn1.Width = 125; + this.dataGridViewTextBoxColumn1.Width = 250; // // dataGridViewTextBoxColumn2 // @@ -172,7 +196,13 @@ this.dataGridViewTextBoxColumn2.MinimumWidth = 6; this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; this.dataGridViewTextBoxColumn2.ReadOnly = true; - this.dataGridViewTextBoxColumn2.Width = 125; + this.dataGridViewTextBoxColumn2.Width = 50; + // + // PrecioCompraMes + // + this.PrecioCompraMes.HeaderText = "Precio Compra"; + this.PrecioCompraMes.Name = "PrecioCompraMes"; + this.PrecioCompraMes.Width = 50; // // dataGridViewTextBoxColumn3 // @@ -180,14 +210,20 @@ this.dataGridViewTextBoxColumn3.MinimumWidth = 6; this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3"; this.dataGridViewTextBoxColumn3.ReadOnly = true; - this.dataGridViewTextBoxColumn3.Width = 125; + this.dataGridViewTextBoxColumn3.Width = 50; // // dataGridViewTextBoxColumn4 // this.dataGridViewTextBoxColumn4.HeaderText = "Total"; this.dataGridViewTextBoxColumn4.MinimumWidth = 6; this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4"; - this.dataGridViewTextBoxColumn4.Width = 125; + this.dataGridViewTextBoxColumn4.Width = 70; + // + // totalNetoMes + // + this.totalNetoMes.HeaderText = "Total Neto"; + this.totalNetoMes.Name = "totalNetoMes"; + this.totalNetoMes.Width = 70; // // lbProductDia // @@ -195,7 +231,7 @@ this.lbProductDia.BackColor = System.Drawing.Color.Transparent; this.lbProductDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbProductDia.ForeColor = System.Drawing.Color.Transparent; - this.lbProductDia.Location = new System.Drawing.Point(586, 197); + this.lbProductDia.Location = new System.Drawing.Point(657, 199); this.lbProductDia.Name = "lbProductDia"; this.lbProductDia.Size = new System.Drawing.Size(153, 17); this.lbProductDia.TabIndex = 6; @@ -208,7 +244,7 @@ this.lbVendedorDia.BackColor = System.Drawing.Color.Transparent; this.lbVendedorDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbVendedorDia.ForeColor = System.Drawing.Color.Transparent; - this.lbVendedorDia.Location = new System.Drawing.Point(586, 257); + this.lbVendedorDia.Location = new System.Drawing.Point(657, 261); this.lbVendedorDia.Name = "lbVendedorDia"; this.lbVendedorDia.Size = new System.Drawing.Size(113, 17); this.lbVendedorDia.TabIndex = 7; @@ -233,7 +269,7 @@ this.lbTotalMes.BackColor = System.Drawing.Color.Transparent; this.lbTotalMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbTotalMes.ForeColor = System.Drawing.Color.Transparent; - this.lbTotalMes.Location = new System.Drawing.Point(330, 560); + this.lbTotalMes.Location = new System.Drawing.Point(333, 575); this.lbTotalMes.Name = "lbTotalMes"; this.lbTotalMes.Size = new System.Drawing.Size(97, 17); this.lbTotalMes.TabIndex = 9; @@ -245,7 +281,7 @@ this.lbVendedorMes.BackColor = System.Drawing.Color.Transparent; this.lbVendedorMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbVendedorMes.ForeColor = System.Drawing.Color.Transparent; - this.lbVendedorMes.Location = new System.Drawing.Point(588, 454); + this.lbVendedorMes.Location = new System.Drawing.Point(659, 457); this.lbVendedorMes.Name = "lbVendedorMes"; this.lbVendedorMes.Size = new System.Drawing.Size(111, 17); this.lbVendedorMes.TabIndex = 11; @@ -258,7 +294,7 @@ this.lbProductoMes.BackColor = System.Drawing.Color.Transparent; this.lbProductoMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbProductoMes.ForeColor = System.Drawing.Color.Transparent; - this.lbProductoMes.Location = new System.Drawing.Point(588, 396); + this.lbProductoMes.Location = new System.Drawing.Point(657, 387); this.lbProductoMes.Name = "lbProductoMes"; this.lbProductoMes.Size = new System.Drawing.Size(153, 17); this.lbProductoMes.TabIndex = 10; @@ -271,7 +307,7 @@ this.pictureBox2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.pictureBox2.Image = global::compabetov2.Properties.Resources.check1; this.pictureBox2.Location = new System.Drawing.Point(785, 560); - this.pictureBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.pictureBox2.Margin = new System.Windows.Forms.Padding(2); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(75, 56); this.pictureBox2.TabIndex = 28; @@ -296,12 +332,44 @@ this.lbMesSEnvio.BackColor = System.Drawing.Color.Transparent; this.lbMesSEnvio.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbMesSEnvio.ForeColor = System.Drawing.Color.Transparent; - this.lbMesSEnvio.Location = new System.Drawing.Point(270, 577); + this.lbMesSEnvio.Location = new System.Drawing.Point(266, 601); this.lbMesSEnvio.Name = "lbMesSEnvio"; this.lbMesSEnvio.Size = new System.Drawing.Size(164, 17); this.lbMesSEnvio.TabIndex = 30; this.lbMesSEnvio.Text = "Total del mes sin envios:"; // + // lbTotalDiaNeto + // + this.lbTotalDiaNeto.AutoSize = true; + this.lbTotalDiaNeto.BackColor = System.Drawing.Color.Transparent; + this.lbTotalDiaNeto.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbTotalDiaNeto.ForeColor = System.Drawing.SystemColors.ButtonHighlight; + this.lbTotalDiaNeto.Location = new System.Drawing.Point(70, 356); + this.lbTotalDiaNeto.Name = "lbTotalDiaNeto"; + this.lbTotalDiaNeto.Size = new System.Drawing.Size(114, 16); + this.lbTotalDiaNeto.TabIndex = 31; + this.lbTotalDiaNeto.Text = "Total neto del dia:"; + // + // btnVentasDia + // + this.btnVentasDia.Location = new System.Drawing.Point(876, 232); + this.btnVentasDia.Name = "btnVentasDia"; + this.btnVentasDia.Size = new System.Drawing.Size(110, 23); + this.btnVentasDia.TabIndex = 32; + this.btnVentasDia.Text = "Ventas del dia"; + this.btnVentasDia.UseVisualStyleBackColor = true; + this.btnVentasDia.Click += new System.EventHandler(this.btnVentasDia_Click); + // + // btnVentasMes + // + this.btnVentasMes.Location = new System.Drawing.Point(876, 421); + this.btnVentasMes.Name = "btnVentasMes"; + this.btnVentasMes.Size = new System.Drawing.Size(110, 23); + this.btnVentasMes.TabIndex = 33; + this.btnVentasMes.Text = "Ventas del Mes"; + this.btnVentasMes.UseVisualStyleBackColor = true; + this.btnVentasMes.Click += new System.EventHandler(this.btnVentasMes_Click); + // // Estadiscticas // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -309,8 +377,11 @@ this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(27)))), ((int)(((byte)(104)))), ((int)(((byte)(255))))); this.BackgroundImage = global::compabetov2.Properties.Resources.Form; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.ClientSize = new System.Drawing.Size(955, 627); + this.ClientSize = new System.Drawing.Size(1038, 772); this.ControlBox = false; + this.Controls.Add(this.btnVentasMes); + this.Controls.Add(this.btnVentasDia); + this.Controls.Add(this.lbTotalDiaNeto); this.Controls.Add(this.lbMesSEnvio); this.Controls.Add(this.lbDiaSEnvio); this.Controls.Add(this.pictureBox2); @@ -342,18 +413,10 @@ private System.Windows.Forms.DateTimePicker dtpBuscar; private System.Windows.Forms.DataGridView dgvDia; - private System.Windows.Forms.DataGridViewTextBoxColumn Producto; - private System.Windows.Forms.DataGridViewTextBoxColumn Precio; - private System.Windows.Forms.DataGridViewTextBoxColumn Cantidad; - private System.Windows.Forms.DataGridViewTextBoxColumn Total; private System.Windows.Forms.Button btnBuscar; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.DataGridView dgvMes; - private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn1; - private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; - private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn3; - private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn4; private System.Windows.Forms.Label lbProductDia; private System.Windows.Forms.Label lbVendedorDia; private System.Windows.Forms.Label lbTotalDia; @@ -363,5 +426,20 @@ private System.Windows.Forms.PictureBox pictureBox2; private System.Windows.Forms.Label lbDiaSEnvio; private System.Windows.Forms.Label lbMesSEnvio; + private System.Windows.Forms.DataGridViewTextBoxColumn Producto; + private System.Windows.Forms.DataGridViewTextBoxColumn Precio; + private System.Windows.Forms.DataGridViewTextBoxColumn precioCompra; + private System.Windows.Forms.DataGridViewTextBoxColumn Cantidad; + private System.Windows.Forms.DataGridViewTextBoxColumn Total; + private System.Windows.Forms.DataGridViewTextBoxColumn totalNeto; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn1; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; + private System.Windows.Forms.DataGridViewTextBoxColumn PrecioCompraMes; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn3; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn4; + private System.Windows.Forms.DataGridViewTextBoxColumn totalNetoMes; + private System.Windows.Forms.Label lbTotalDiaNeto; + private System.Windows.Forms.Button btnVentasDia; + private System.Windows.Forms.Button btnVentasMes; } } \ No newline at end of file diff --git a/Estadiscticas.cs b/Estadiscticas.cs index 4f3c930..bd77ad5 100644 --- a/Estadiscticas.cs +++ b/Estadiscticas.cs @@ -15,7 +15,9 @@ namespace compabetov2 { public partial class Estadiscticas : Form { - Dictionary>> resumen; + private List ventasDia; + private List ventasMes; + public Estadiscticas() { InitializeComponent(); @@ -33,11 +35,15 @@ namespace compabetov2 string fechaBuscaStr = dtpBuscar.Text; DateTime.TryParseExact(fechaBuscaStr, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fechaBuscar); - resumen = service.estadisticas(fechaBuscar); + ventasDia = service.conseguirVentasDia(fechaBuscar); + ventasMes = service.conseguirVentasMes(fechaBuscar); + List productosMes = estadisticasMes(); List productosDia = estadisticasDia(); decimal totalmes = totalMes(); decimal totaldia = totalDia(); + + decimal totaldianeto = totalDiaNeto(); Dictionary> envios = service.conseguirEnvioMes(fechaBuscar); Dictionary estadisticas = new Dictionary @@ -55,6 +61,7 @@ namespace compabetov2 { "productoMasVendido", prodctoMasVendido(productosDia) }, { "mejorVendedor", mejorVenderdorDia() }, { "totalDia", totalDia()}, + { "totalNetoDia", totaldianeto }, { "EnvioCantidad", totalDiaSinEnvio(envios) }, } } @@ -74,74 +81,118 @@ namespace compabetov2 } private decimal totalMes() - { - List> mes = resumen["mes"]; - - return calcularTotal(mes); - } - - private decimal totalDia() - { - List> dia = resumen["dia"]; - - return calcularTotal(dia); - } - - private decimal calcularTotal(List> resumen) { decimal total = 0; - foreach (Dictionary venta_y_detalles in resumen) + foreach(VentaModel venta in ventasMes) { - VentaModel venta = venta_y_detalles["venta"]; - total += venta.total; } return total; } - private List estadisticasDia() + private decimal totalDia() { - //solo copie y pegue le metodo estadisticas dia y cambie el key en resumen de mes a dia - List> mes = resumen["dia"]; + decimal total = 0; - List detallesMes = new List(); - foreach (Dictionary venta_y_detalles in mes) + foreach (VentaModel venta in ventasDia) { - foreach (DetalleVentaModel detallesVenta in venta_y_detalles["detalles"]) + total += venta.total; + } + + return total; + } + + private decimal totalDiaNeto() + { + decimal total = 0; + foreach (VentaModel venta in ventasDia) + { + List detalles = service.conseguirDetallesVenta(venta); + decimal totalDetalle = 0; + foreach(DetalleVentaModel detalle in detalles) + { + totalDetalle += detalle.cantidad * (detalle.producto.precio - detalle.producto.precioCompra); + } + total += totalDetalle; + } + return total; + } + + private List estadisticasMes() + { + List detallesMes = new List(); + //recorre las ventas del mes + foreach (VentaModel venta in ventasMes) + { + //consigue los detalles de la venta + List detallesVenta = service.conseguirDetallesVenta(venta); + + //recorre los detalles de la venta + foreach (DetalleVentaModel detalle in detallesVenta) { int totalElementos = detallesMes.Count; - int contador = 0; for (int i = 0; i <= totalElementos; i++) { - contador++; + //si no encuentra el producto lo agrega if (i == totalElementos) { - DetalleVentaModel detalleAgregar = new DetalleVentaModel(detallesVenta.cantidad, detallesVenta.producto, detallesVenta.idVenta); + DetalleVentaModel detalleAgregar = new DetalleVentaModel(detalle.cantidad, detalle.producto, detalle.idVenta); detallesMes.Add(detalleAgregar); break; } DetalleVentaModel producto = detallesMes[i]; - - if (producto.producto.nombre.Equals(detallesVenta.producto.nombre)) + //si encuentra el produco solo aumneta la cantidad + if (producto.producto.nombre.Equals(detalle.producto.nombre)) { - producto.cantidad += detallesVenta.cantidad; + producto.cantidad += detalle.cantidad; + break; + } + } + } + } + + return detallesMes; + } + + private List estadisticasDia() + { + List detallesDia = new List(); + //recorre las ventas del mes + foreach (VentaModel venta in ventasDia) + { + //consigue los detalles de la venta + List detallesVenta = service.conseguirDetallesVenta(venta); + + //recorre los detalles de la venta + foreach (DetalleVentaModel detalle in detallesVenta) + { + int totalElementos = detallesDia.Count; + int contador = 0; + for (int i = 0; i <= totalElementos; i++) + { + contador++; + //si no encuentra el producto lo agrega + if (i == totalElementos) + { + DetalleVentaModel detalleAgregar = new DetalleVentaModel(detalle.cantidad, detalle.producto, detalle.idVenta); + detallesDia.Add(detalleAgregar); break; } - //si no existe el producto lo agrega - + DetalleVentaModel producto = detallesDia[i]; + //si encuentra el produco solo aumneta la cantidad + if (producto.producto.nombre.Equals(detalle.producto.nombre)) + { + producto.cantidad += detalle.cantidad; + break; + } } - - if (contador == 0) - { - detallesMes.Add(detallesVenta); - } - } } - return detallesMes; + + return detallesDia; } private void mostrarDatos(Dictionary estadisticas) @@ -159,20 +210,27 @@ namespace compabetov2 // Crear celdas para la nueva fila DataGridViewCell productoN = new DataGridViewTextBoxCell(); DataGridViewCell precio = new DataGridViewTextBoxCell(); + DataGridViewCell precioCompra = new DataGridViewTextBoxCell(); DataGridViewCell cantidad = new DataGridViewTextBoxCell(); DataGridViewCell total = new DataGridViewTextBoxCell(); + DataGridViewCell totalNeto = new DataGridViewTextBoxCell(); // Establecer los valores de las celdas (puedes ajustar según tu necesidad) productoN.Value = $"{producto.producto.nombre}"; precio.Value = $"{producto.producto.precio}"; + precioCompra.Value = $"{producto.producto.precioCompra}"; cantidad.Value = $"{producto.cantidad}"; total.Value = $"{producto.cantidad * producto.producto.precio}"; + + totalNeto.Value = $"{producto.cantidad * (producto.producto.precio - producto.producto.precioCompra)}"; // Agregar las celdas a la fila nuevaFila.Cells.Add(productoN); nuevaFila.Cells.Add(precio); + nuevaFila.Cells.Add(precioCompra); nuevaFila.Cells.Add(cantidad); nuevaFila.Cells.Add(total); + nuevaFila.Cells.Add(totalNeto); // Agregar la nueva fila al DataGridView dgvMes.Rows.Add(nuevaFila); @@ -195,20 +253,26 @@ namespace compabetov2 // Crear celdas para la nueva fila DataGridViewCell productoN = new DataGridViewTextBoxCell(); DataGridViewCell precio = new DataGridViewTextBoxCell(); + DataGridViewCell precioCompra = new DataGridViewTextBoxCell(); DataGridViewCell cantidad = new DataGridViewTextBoxCell(); DataGridViewCell total = new DataGridViewTextBoxCell(); + DataGridViewCell totalNeto = new DataGridViewTextBoxCell(); // Establecer los valores de las celdas (puedes ajustar según tu necesidad) productoN.Value = $"{producto.producto.nombre}"; precio.Value = $"{producto.producto.precio}"; + precioCompra.Value = $"{producto.producto.precioCompra}"; cantidad.Value = $"{producto.cantidad}"; total.Value = $"{producto.cantidad * producto.producto.precio}"; + totalNeto.Value = $"{producto.cantidad * (producto.producto.precio - producto.producto.precioCompra)}"; // Agregar las celdas a la fila nuevaFila.Cells.Add(productoN); nuevaFila.Cells.Add(precio); + nuevaFila.Cells.Add(precioCompra); nuevaFila.Cells.Add(cantidad); nuevaFila.Cells.Add(total); + nuevaFila.Cells.Add(totalNeto); // Agregar la nueva fila al DataGridView dgvDia.Rows.Add(nuevaFila); @@ -219,61 +283,19 @@ namespace compabetov2 lbProductDia.Text = $"Producto mas vendido: {estadisticas["dia"]["productoMasVendido"]}"; lbVendedorDia.Text = $"Mejor vendedor: {estadisticas["dia"]["mejorVendedor"]}"; lbDiaSEnvio.Text = $"Total del dia sin envios: ${totalSinEnvioDia}"; + lbTotalDiaNeto.Text = $"Total neto del dia: ${estadisticas["dia"]["totalNetoDia"]}"; } - private List estadisticasMes() - { - List> mes = resumen["mes"]; - - List detallesMes = new List(); - foreach (Dictionary venta_y_detalles in mes) - { - foreach (DetalleVentaModel detallesVenta in venta_y_detalles["detalles"]) - { - int totalElementos = detallesMes.Count; - int contador = 0; - for(int i = 0; i <= totalElementos; i++) { - contador++; - //si no encuentra el producto lo agrega - if (i == totalElementos) - { - DetalleVentaModel detalleAgregar = new DetalleVentaModel(detallesVenta.cantidad, detallesVenta.producto, detallesVenta.idVenta); - detallesMes.Add(detalleAgregar); - break; - } - - DetalleVentaModel producto = detallesMes[i]; - //si encuentra el produco solo aumneta la cantidad - if (producto.producto.nombre.Equals(detallesVenta.producto.nombre)) - { - producto.cantidad += detallesVenta.cantidad; - break; - } - - //si no existe el producto lo agrega - - } - - if(contador == 0) - { - detallesMes.Add(detallesVenta); - } - - } - } - return detallesMes; - } + private string mejorVenderdorMes() { - List> mes = resumen["mes"]; string mejorVendedor = ""; int contadorNumeroVentas = 0; Dictionary empleados = new Dictionary(); - foreach(Dictionary venta_y_detalle in mes) + foreach(VentaModel venta in ventasMes) { - VentaModel venta = venta_y_detalle["venta"]; if (empleados.ContainsKey(venta.responzable)) { @@ -303,7 +325,6 @@ namespace compabetov2 string productoMasVendido = ""; int cantidadProducto = 0; - foreach(DetalleVentaModel producto in productos) { if(producto.cantidad > cantidadProducto) @@ -318,14 +339,12 @@ namespace compabetov2 private string mejorVenderdorDia() { - List> mes = resumen["dia"]; string mejorVendedor = ""; int contadorNumeroVentas = 0; Dictionary empleados = new Dictionary(); - foreach (Dictionary venta_y_detalle in mes) + foreach (VentaModel venta in ventasDia) { - VentaModel venta = venta_y_detalle["venta"]; if (empleados.ContainsKey(venta.responzable)) { @@ -383,5 +402,24 @@ namespace compabetov2 { this.Close(); } + + private void dgvDia_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + + private void btnVentasDia_Click(object sender, EventArgs e) + { + RegistroVentas ventana = new RegistroVentas(ventasDia,this); + ventana.Owner = this; + ventana.Show(); + } + + private void btnVentasMes_Click(object sender, EventArgs e) + { + RegistroVentas ventana = new RegistroVentas(ventasMes, this); + ventana.Owner = this; + ventana.Show(); + } } } diff --git a/Estadiscticas.resx b/Estadiscticas.resx index 3d753bc..60ffc58 100644 --- a/Estadiscticas.resx +++ b/Estadiscticas.resx @@ -123,22 +123,70 @@ True + + True + True True + + True + + + True + + + True + + + True + + + True + + + True + + + True + True True + + True + True True + + True + + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/RegistroVentas.Designer.cs b/RegistroVentas.Designer.cs new file mode 100644 index 0000000..c6907b9 --- /dev/null +++ b/RegistroVentas.Designer.cs @@ -0,0 +1,100 @@ +namespace compabetov2 +{ + partial class RegistroVentas + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panelVentas = new System.Windows.Forms.FlowLayoutPanel(); + this.lbContador = new System.Windows.Forms.Label(); + this.btnMenos = new System.Windows.Forms.Button(); + this.btnMas = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // panelVentas + // + this.panelVentas.AutoScroll = true; + this.panelVentas.Location = new System.Drawing.Point(23, 48); + this.panelVentas.Name = "panelVentas"; + this.panelVentas.Size = new System.Drawing.Size(393, 547); + this.panelVentas.TabIndex = 0; + // + // lbContador + // + this.lbContador.AutoSize = true; + this.lbContador.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbContador.Location = new System.Drawing.Point(171, 13); + this.lbContador.Name = "lbContador"; + this.lbContador.Size = new System.Drawing.Size(96, 24); + this.lbContador.TabIndex = 0; + this.lbContador.Text = "1000-1000"; + // + // btnMenos + // + this.btnMenos.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnMenos.Location = new System.Drawing.Point(77, 12); + this.btnMenos.Name = "btnMenos"; + this.btnMenos.Size = new System.Drawing.Size(75, 30); + this.btnMenos.TabIndex = 1; + this.btnMenos.Text = "-"; + this.btnMenos.UseVisualStyleBackColor = true; + this.btnMenos.Click += new System.EventHandler(this.btnMenos_Click); + // + // btnMas + // + this.btnMas.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnMas.Location = new System.Drawing.Point(292, 13); + this.btnMas.Name = "btnMas"; + this.btnMas.Size = new System.Drawing.Size(75, 30); + this.btnMas.TabIndex = 2; + this.btnMas.Text = "+"; + this.btnMas.UseVisualStyleBackColor = true; + this.btnMas.Click += new System.EventHandler(this.btnMas_Click); + // + // RegistroVentas + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(447, 607); + this.Controls.Add(this.btnMas); + this.Controls.Add(this.btnMenos); + this.Controls.Add(this.lbContador); + this.Controls.Add(this.panelVentas); + this.Name = "RegistroVentas"; + this.Text = "RegistroVentas"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.FlowLayoutPanel panelVentas; + private System.Windows.Forms.Label lbContador; + private System.Windows.Forms.Button btnMenos; + private System.Windows.Forms.Button btnMas; + } +} \ No newline at end of file diff --git a/RegistroVentas.cs b/RegistroVentas.cs new file mode 100644 index 0000000..9f3ed72 --- /dev/null +++ b/RegistroVentas.cs @@ -0,0 +1,103 @@ +using compabetov2.database; +using compabetov2.database.modelos; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace compabetov2 +{ + public partial class RegistroVentas : Form + { + List ventas; + Estadiscticas ventanaPadre; + public RegistroVentas(List ventas,Estadiscticas ventanaPadre) + { + InitializeComponent(); + this.ventanaPadre = ventanaPadre; + this.ventas = ventas; + llenarPanel(); + } + + private void llenarPanel() + { + foreach(VentaModel venta in ventas) + { + TableLayoutPanel carta = new TableLayoutPanel(); + carta.ColumnCount = 1; + carta.RowCount = 2; + carta.RowStyles.Add(new RowStyle(SizeType.Percent, 75F)); + carta.RowStyles.Add(new RowStyle(SizeType.Percent, 25F)); + carta.Width = 700; + carta.Height = 170; + + FlowLayoutPanel infoPanel = new FlowLayoutPanel(); + infoPanel.FlowDirection = FlowDirection.TopDown; + infoPanel.Dock = DockStyle.Fill; + + Label lbFecha = new Label(); + lbFecha.Text = $"Fecha: {venta.fecha}"; + lbFecha.Font = new Font(lbFecha.Font.FontFamily, 12); + lbFecha.Width = 700; + + Label lbResponzable = new Label(); + lbResponzable.Text = $"Responzable: {venta.responzable}"; + lbResponzable.Font = new Font(lbResponzable.Font.FontFamily, 12); + lbResponzable.Width = 700; + + Label lbTotal = new Label(); + lbTotal.Text = $"Total: {venta.total}"; + lbTotal.Font = new Font(lbTotal.Font.FontFamily, 12); + lbTotal.Width = 700; + + TableLayoutPanel botonesPanel = new TableLayoutPanel(); + botonesPanel.RowCount = 1; + botonesPanel.ColumnCount = 4; + botonesPanel.Dock = DockStyle.Fill; + botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); + botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); + botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); + botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); + botonesPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); + + Button btnDetalles = new Button(); + btnDetalles.Text = "Detalles"; + btnDetalles.Dock = DockStyle.Fill; + btnDetalles.FlatStyle = FlatStyle.Flat; + btnDetalles.FlatAppearance.BorderSize = 0; + btnDetalles.BackColor = Color.FromArgb(33, 90, 255); + btnDetalles.Font = new Font(btnDetalles.Font.FontFamily, 16); + btnDetalles.ForeColor = Color.White; + btnDetalles.Click += new EventHandler(delegate (object sender, EventArgs e) + { + }); + + infoPanel.Controls.Add(lbFecha); + infoPanel.Controls.Add(lbTotal); + infoPanel.Controls.Add(lbResponzable); + + botonesPanel.Controls.Add(btnDetalles, 0, 0); + + carta.Controls.Add(infoPanel, 0, 0); + carta.Controls.Add(botonesPanel, 0, 1); + + panelVentas.Controls.Add(carta); + } + } + + private void btnMenos_Click(object sender, EventArgs e) + { + + } + + private void btnMas_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/RegistroVentas.resx b/RegistroVentas.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RegistroVentas.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index a386c42..27c6cd2 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 411459f..6675008 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 f91eca4..ab7e110 100644 Binary files a/bin/Debug/data.db and b/bin/Debug/data.db differ diff --git a/compabetov2.csproj b/compabetov2.csproj index 5fad195..b67e6c0 100644 --- a/compabetov2.csproj +++ b/compabetov2.csproj @@ -273,6 +273,12 @@ + + Form + + + RegistroVentas.cs + Form @@ -395,6 +401,9 @@ Resources.resx True + + RegistroVentas.cs + datosCuenta.cs diff --git a/database/service.cs b/database/service.cs index b1eb888..7d89124 100644 --- a/database/service.cs +++ b/database/service.cs @@ -427,18 +427,32 @@ namespace compabetov2.database return DAO.concluirEnvioDAO(envio, detallesEnvio, importes); } - public static Dictionary>> estadisticas(DateTime fecha) + public static List conseguirVentasMes(DateTime fecha) { - Dictionary>> resumen = new Dictionary>>(); - List> listMes = new List>(); - List> listDia = new List>(); + List ventasMes = new List(); + SQLiteDataReader readerVentas = DAO.conseguirVentasMesDAO(fecha); + + while (readerVentas.Read()) + { + VentaModel venta = new VentaModel( + readerVentas.GetDecimal(2),//total + (int)readerVentas.GetInt64(0),//id + readerVentas.GetString(1),//fecha + readerVentas.GetString(3)//resposable + ); + ventasMes.Add(venta); + } + return ventasMes; + } + + public static List conseguirVentasDia(DateTime fecha) + { + List ventasDia = new List(); SQLiteDataReader readerVentas = DAO.conseguirVentasMesDAO(fecha); string formato = "dd/MM/yyyy"; while (readerVentas.Read()) { - Dictionary dicVenta = new Dictionary(); - VentaModel venta = new VentaModel( readerVentas.GetDecimal(2), (int)readerVentas.GetInt64(0), @@ -446,45 +460,16 @@ namespace compabetov2.database readerVentas.GetString(3) ); - List detallesVenta = new List(); - 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), - readerDetalleVenta["nombre"].ToString(), - readerDetalleVenta.GetDecimal(5), - (int)readerDetalleVenta.GetInt64(6), - "", - (int)readerDetalleVenta.GetInt64(8), - precioCompra) - ); - detallesVenta.Add( detalleVenta ); - } - - dicVenta.Add("venta", venta); - dicVenta.Add("detalles", detallesVenta as List); - string[] fecha_hora = venta.fecha.Split(' '); string fechaVentaStr = fecha_hora[0]; DateTime.TryParseExact(fechaVentaStr, formato, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fechaVenta); if (fecha.Day == fechaVenta.Day) { - listDia.Add(dicVenta); + ventasDia.Add(venta); } - - listMes.Add(dicVenta); } - - - - resumen.Add("mes", listMes); - resumen.Add("dia", listDia); - - return resumen; + return ventasDia; } public static List conseguirProductosFiltrados(string nombreProducto) @@ -519,6 +504,30 @@ namespace compabetov2.database return productos; } + public static List conseguirDetallesVenta(VentaModel venta) + { + List detallesVenta = new List(); + SQLiteDataReader readerDetalleVenta = DAO.conseguirDetalleVenta(venta); + while (readerDetalleVenta.Read()) + { + decimal precioCompra = readerDetalleVenta.GetDecimal(3); + Variante variante = new Variante( + (int)readerDetalleVenta.GetInt64(5),//id + readerDetalleVenta["nombre"].ToString(),//nombre + readerDetalleVenta.GetDecimal(4),//precioVenta + (int)readerDetalleVenta.GetInt64(8),//cantidad + "",//img + (int)readerDetalleVenta.GetInt64(10),//fkProducto + precioCompra); + + DetalleVentaModel detalleVenta = new DetalleVentaModel( + (int)readerDetalleVenta.GetInt64(2), + variante + ); + detallesVenta.Add( detalleVenta ); + } + return detallesVenta; + } public static Dictionary> conseguirEnvioMes(DateTime fecha) { diff --git a/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/obj/Debug/DesignTimeResolveAssemblyReferences.cache index 363616f..4382aa9 100644 Binary files a/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache index 6814a2c..52fce8f 100644 --- a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache +++ b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -71f328ca57677b5d4698632bb6522f64a4fe76d47ddec8e1718dc439db6af453 +4bc0b21d4c0f19e1e9ae1bfa37f9e96b5658ecea100004a31759a9d5405753d7 diff --git a/obj/Debug/compabetov2.csproj.FileListAbsolute.txt b/obj/Debug/compabetov2.csproj.FileListAbsolute.txt index 4474bb6..7231569 100644 --- a/obj/Debug/compabetov2.csproj.FileListAbsolute.txt +++ b/obj/Debug/compabetov2.csproj.FileListAbsolute.txt @@ -165,3 +165,4 @@ C:\Users\Googl\Source\Repos\aspermaster23yeh\compabetoOG\obj\Debug\compabetov2.a C:\Users\Googl\Source\Repos\aspermaster23yeh\compabetoOG\obj\Debug\compabetov2.admin.editarvariante.resources C:\Users\Googl\Source\Repos\aspermaster23yeh\compabetoOG\obj\Debug\compabetov2.admin.Variantes.resources C:\Users\carsu\source\repos\compabetoOG\obj\Debug\compabetov2.admin.editarvariante.resources +C:\Users\carsu\source\repos\compabetoOG\obj\Debug\compabetov2.RegistroVentas.resources diff --git a/obj/Debug/compabetov2.csproj.GenerateResource.cache b/obj/Debug/compabetov2.csproj.GenerateResource.cache index 491d4e3..2e04e31 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 a386c42..27c6cd2 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 411459f..6675008 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ