diff --git a/Estadiscticas.Designer.cs b/Estadiscticas.Designer.cs index edd06e4..ed7fd3d 100644 --- a/Estadiscticas.Designer.cs +++ b/Estadiscticas.Designer.cs @@ -48,16 +48,19 @@ 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(); - this.lbTotalMes = new System.Windows.Forms.Label(); + this.lbUtilidadDia = new System.Windows.Forms.Label(); + this.lbUtilidadMes = new System.Windows.Forms.Label(); this.lbVendedorMes = new System.Windows.Forms.Label(); this.lbProductoMes = new System.Windows.Forms.Label(); 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.lbGananciasBrutasDia = new System.Windows.Forms.Label(); + this.lbGananciasBrutasMes = new System.Windows.Forms.Label(); + this.lbTotalImporteDia = new System.Windows.Forms.Label(); this.btnVentasDia = new System.Windows.Forms.Button(); this.btnVentasMes = new System.Windows.Forms.Button(); + this.lbEnviosDia = new System.Windows.Forms.Label(); + this.lbTotalImporteMes = new System.Windows.Forms.Label(); + this.lbEnvioMes = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.dgvDia)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvMes)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); @@ -160,7 +163,7 @@ this.label2.BackColor = System.Drawing.Color.Transparent; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.ForeColor = System.Drawing.Color.Transparent; - this.label2.Location = new System.Drawing.Point(27, 387); + this.label2.Location = new System.Drawing.Point(33, 482); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(121, 17); this.label2.TabIndex = 4; @@ -176,7 +179,7 @@ this.dataGridViewTextBoxColumn3, this.dataGridViewTextBoxColumn4, this.totalNetoMes}); - this.dgvMes.Location = new System.Drawing.Point(24, 406); + this.dgvMes.Location = new System.Drawing.Point(30, 501); this.dgvMes.Name = "dgvMes"; this.dgvMes.RowHeadersWidth = 51; this.dgvMes.Size = new System.Drawing.Size(599, 150); @@ -251,29 +254,30 @@ this.lbVendedorDia.Text = "Mejor vendedos:"; this.lbVendedorDia.Click += new System.EventHandler(this.lbVendedorDia_Click); // - // lbTotalDia + // lbUtilidadDia // - this.lbTotalDia.AutoSize = true; - this.lbTotalDia.BackColor = System.Drawing.Color.Transparent; - this.lbTotalDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lbTotalDia.ForeColor = System.Drawing.Color.Transparent; - this.lbTotalDia.Location = new System.Drawing.Point(333, 356); - this.lbTotalDia.Name = "lbTotalDia"; - this.lbTotalDia.Size = new System.Drawing.Size(90, 17); - this.lbTotalDia.TabIndex = 8; - this.lbTotalDia.Text = "Total del dia:"; + this.lbUtilidadDia.AutoSize = true; + this.lbUtilidadDia.BackColor = System.Drawing.Color.Transparent; + this.lbUtilidadDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbUtilidadDia.ForeColor = System.Drawing.Color.Transparent; + this.lbUtilidadDia.Location = new System.Drawing.Point(419, 355); + this.lbUtilidadDia.Name = "lbUtilidadDia"; + this.lbUtilidadDia.Size = new System.Drawing.Size(105, 17); + this.lbUtilidadDia.TabIndex = 8; + this.lbUtilidadDia.Text = "Utilidad del dia:"; + this.lbUtilidadDia.Click += new System.EventHandler(this.lbTotalDia_Click); // - // lbTotalMes + // lbUtilidadMes // - this.lbTotalMes.AutoSize = true; - 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(333, 575); - this.lbTotalMes.Name = "lbTotalMes"; - this.lbTotalMes.Size = new System.Drawing.Size(97, 17); - this.lbTotalMes.TabIndex = 9; - this.lbTotalMes.Text = "Total del Mes:"; + this.lbUtilidadMes.AutoSize = true; + this.lbUtilidadMes.BackColor = System.Drawing.Color.Transparent; + this.lbUtilidadMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbUtilidadMes.ForeColor = System.Drawing.Color.Transparent; + this.lbUtilidadMes.Location = new System.Drawing.Point(419, 664); + this.lbUtilidadMes.Name = "lbUtilidadMes"; + this.lbUtilidadMes.Size = new System.Drawing.Size(112, 17); + this.lbUtilidadMes.TabIndex = 9; + this.lbUtilidadMes.Text = "Utilidad del mes:"; // // lbVendedorMes // @@ -281,7 +285,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(659, 457); + this.lbVendedorMes.Location = new System.Drawing.Point(665, 552); this.lbVendedorMes.Name = "lbVendedorMes"; this.lbVendedorMes.Size = new System.Drawing.Size(111, 17); this.lbVendedorMes.TabIndex = 11; @@ -294,7 +298,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(657, 387); + this.lbProductoMes.Location = new System.Drawing.Point(663, 482); this.lbProductoMes.Name = "lbProductoMes"; this.lbProductoMes.Size = new System.Drawing.Size(153, 17); this.lbProductoMes.TabIndex = 10; @@ -306,7 +310,7 @@ this.pictureBox2.BackColor = System.Drawing.Color.Transparent; 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.Location = new System.Drawing.Point(911, 680); this.pictureBox2.Margin = new System.Windows.Forms.Padding(2); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(75, 56); @@ -314,45 +318,45 @@ this.pictureBox2.TabStop = false; this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click); // - // lbDiaSEnvio + // lbGananciasBrutasDia // - this.lbDiaSEnvio.AutoSize = true; - this.lbDiaSEnvio.BackColor = System.Drawing.Color.Transparent; - this.lbDiaSEnvio.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lbDiaSEnvio.ForeColor = System.Drawing.Color.Transparent; - this.lbDiaSEnvio.Location = new System.Drawing.Point(266, 373); - this.lbDiaSEnvio.Name = "lbDiaSEnvio"; - this.lbDiaSEnvio.Size = new System.Drawing.Size(157, 17); - this.lbDiaSEnvio.TabIndex = 29; - this.lbDiaSEnvio.Text = "Total del dia sin envios:"; + this.lbGananciasBrutasDia.AutoSize = true; + this.lbGananciasBrutasDia.BackColor = System.Drawing.Color.Transparent; + this.lbGananciasBrutasDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbGananciasBrutasDia.ForeColor = System.Drawing.Color.Transparent; + this.lbGananciasBrutasDia.Location = new System.Drawing.Point(358, 398); + this.lbGananciasBrutasDia.Name = "lbGananciasBrutasDia"; + this.lbGananciasBrutasDia.Size = new System.Drawing.Size(166, 17); + this.lbGananciasBrutasDia.TabIndex = 29; + this.lbGananciasBrutasDia.Text = "Ganancias brutas del dia"; // - // lbMesSEnvio + // lbGananciasBrutasMes // - this.lbMesSEnvio.AutoSize = true; - 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(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:"; + this.lbGananciasBrutasMes.AutoSize = true; + this.lbGananciasBrutasMes.BackColor = System.Drawing.Color.Transparent; + this.lbGananciasBrutasMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbGananciasBrutasMes.ForeColor = System.Drawing.Color.Transparent; + this.lbGananciasBrutasMes.Location = new System.Drawing.Point(352, 719); + this.lbGananciasBrutasMes.Name = "lbGananciasBrutasMes"; + this.lbGananciasBrutasMes.Size = new System.Drawing.Size(171, 17); + this.lbGananciasBrutasMes.TabIndex = 30; + this.lbGananciasBrutasMes.Text = "Ganancias Brutas del dia:"; // - // lbTotalDiaNeto + // lbTotalImporteDia // - 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:"; + this.lbTotalImporteDia.AutoSize = true; + this.lbTotalImporteDia.BackColor = System.Drawing.Color.Transparent; + this.lbTotalImporteDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbTotalImporteDia.ForeColor = System.Drawing.SystemColors.ButtonHighlight; + this.lbTotalImporteDia.Location = new System.Drawing.Point(70, 356); + this.lbTotalImporteDia.Name = "lbTotalImporteDia"; + this.lbTotalImporteDia.Size = new System.Drawing.Size(133, 16); + this.lbTotalImporteDia.TabIndex = 31; + this.lbTotalImporteDia.Text = "Total Importe del dia:"; // // btnVentasDia // - this.btnVentasDia.Location = new System.Drawing.Point(876, 232); + this.btnVentasDia.Location = new System.Drawing.Point(660, 313); this.btnVentasDia.Name = "btnVentasDia"; this.btnVentasDia.Size = new System.Drawing.Size(110, 23); this.btnVentasDia.TabIndex = 32; @@ -362,7 +366,7 @@ // // btnVentasMes // - this.btnVentasMes.Location = new System.Drawing.Point(876, 421); + this.btnVentasMes.Location = new System.Drawing.Point(666, 611); this.btnVentasMes.Name = "btnVentasMes"; this.btnVentasMes.Size = new System.Drawing.Size(110, 23); this.btnVentasMes.TabIndex = 33; @@ -370,6 +374,42 @@ this.btnVentasMes.UseVisualStyleBackColor = true; this.btnVentasMes.Click += new System.EventHandler(this.btnVentasMes_Click); // + // lbEnviosDia + // + this.lbEnviosDia.AutoSize = true; + this.lbEnviosDia.BackColor = System.Drawing.Color.Transparent; + this.lbEnviosDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbEnviosDia.ForeColor = System.Drawing.SystemColors.ButtonHighlight; + this.lbEnviosDia.Location = new System.Drawing.Point(70, 399); + this.lbEnviosDia.Name = "lbEnviosDia"; + this.lbEnviosDia.Size = new System.Drawing.Size(147, 16); + this.lbEnviosDia.TabIndex = 34; + this.lbEnviosDia.Text = "Total de envios del dia:"; + // + // lbTotalImporteMes + // + this.lbTotalImporteMes.AutoSize = true; + this.lbTotalImporteMes.BackColor = System.Drawing.Color.Transparent; + this.lbTotalImporteMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbTotalImporteMes.ForeColor = System.Drawing.SystemColors.ButtonHighlight; + this.lbTotalImporteMes.Location = new System.Drawing.Point(84, 665); + this.lbTotalImporteMes.Name = "lbTotalImporteMes"; + this.lbTotalImporteMes.Size = new System.Drawing.Size(140, 16); + this.lbTotalImporteMes.TabIndex = 35; + this.lbTotalImporteMes.Text = "Total Importe del mes:"; + // + // lbEnvioMes + // + this.lbEnvioMes.AutoSize = true; + this.lbEnvioMes.BackColor = System.Drawing.Color.Transparent; + this.lbEnvioMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbEnvioMes.ForeColor = System.Drawing.SystemColors.ButtonHighlight; + this.lbEnvioMes.Location = new System.Drawing.Point(70, 719); + this.lbEnvioMes.Name = "lbEnvioMes"; + this.lbEnvioMes.Size = new System.Drawing.Size(154, 16); + this.lbEnvioMes.TabIndex = 36; + this.lbEnvioMes.Text = "Total de envios del mes:"; + // // Estadiscticas // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -379,16 +419,19 @@ this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.ClientSize = new System.Drawing.Size(1038, 772); this.ControlBox = false; + this.Controls.Add(this.lbEnvioMes); + this.Controls.Add(this.lbTotalImporteMes); + this.Controls.Add(this.lbEnviosDia); 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.lbTotalImporteDia); + this.Controls.Add(this.lbGananciasBrutasMes); + this.Controls.Add(this.lbGananciasBrutasDia); this.Controls.Add(this.pictureBox2); this.Controls.Add(this.lbVendedorMes); this.Controls.Add(this.lbProductoMes); - this.Controls.Add(this.lbTotalMes); - this.Controls.Add(this.lbTotalDia); + this.Controls.Add(this.lbUtilidadMes); + this.Controls.Add(this.lbUtilidadDia); this.Controls.Add(this.lbVendedorDia); this.Controls.Add(this.lbProductDia); this.Controls.Add(this.dgvMes); @@ -419,13 +462,13 @@ private System.Windows.Forms.DataGridView dgvMes; private System.Windows.Forms.Label lbProductDia; private System.Windows.Forms.Label lbVendedorDia; - private System.Windows.Forms.Label lbTotalDia; - private System.Windows.Forms.Label lbTotalMes; + private System.Windows.Forms.Label lbUtilidadDia; + private System.Windows.Forms.Label lbUtilidadMes; private System.Windows.Forms.Label lbVendedorMes; private System.Windows.Forms.Label lbProductoMes; private System.Windows.Forms.PictureBox pictureBox2; - private System.Windows.Forms.Label lbDiaSEnvio; - private System.Windows.Forms.Label lbMesSEnvio; + private System.Windows.Forms.Label lbGananciasBrutasDia; + private System.Windows.Forms.Label lbGananciasBrutasMes; private System.Windows.Forms.DataGridViewTextBoxColumn Producto; private System.Windows.Forms.DataGridViewTextBoxColumn Precio; private System.Windows.Forms.DataGridViewTextBoxColumn precioCompra; @@ -438,8 +481,11 @@ 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.Label lbTotalImporteDia; private System.Windows.Forms.Button btnVentasDia; private System.Windows.Forms.Button btnVentasMes; + private System.Windows.Forms.Label lbEnviosDia; + private System.Windows.Forms.Label lbTotalImporteMes; + private System.Windows.Forms.Label lbEnvioMes; } } \ No newline at end of file diff --git a/Estadiscticas.cs b/Estadiscticas.cs index bd77ad5..cccc074 100644 --- a/Estadiscticas.cs +++ b/Estadiscticas.cs @@ -10,13 +10,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Xml.Serialization.Configuration; namespace compabetov2 { public partial class Estadiscticas : Form { - private List ventasDia; - private List ventasMes; + Dictionary>> resumen; + decimal costosCompraProductos; + decimal ganaciaBrutaProductos; public Estadiscticas() { @@ -35,120 +37,102 @@ namespace compabetov2 string fechaBuscaStr = dtpBuscar.Text; DateTime.TryParseExact(fechaBuscaStr, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fechaBuscar); - ventasDia = service.conseguirVentasDia(fechaBuscar); - ventasMes = service.conseguirVentasMes(fechaBuscar); + resumen = service.estadisticas(fechaBuscar); List productosMes = estadisticasMes(); List productosDia = estadisticasDia(); - decimal totalmes = totalMes(); - decimal totaldia = totalDia(); - - decimal totaldianeto = totalDiaNeto(); + decimal importeMes = calcularImporte(resumen["mes"]); + decimal importeDia = calcularImporte(resumen["dia"]); + Dictionary> envios = service.conseguirEnvioMes(fechaBuscar); + int enviosMes = cantidadEnvios(envios["mes"]); + int enviosDia = cantidadEnvios(envios["dia"]); + + + decimal utilidadMes = calcularUtilidad(resumen["mes"], importeMes, enviosMes); + Dictionary estadisticas = new Dictionary { { "mes", new Dictionary{ { "productos", productosMes }, { "productoMasVendido", prodctoMasVendido(productosMes) }, - { "mejorVendedor", mejorVenderdorMes() }, - { "totalMes", totalmes }, - { "EnvioCantidad", totalMesSinEnvio(envios) }, + { "mejorVendedor", "yo"/*mejorVenderdorMes()*/ }, + { "EnvioCantidad", enviosMes }, + { "totalImportes", importeMes }, } }, { "dia", new Dictionary{ { "productos", productosDia }, { "productoMasVendido", prodctoMasVendido(productosDia) }, - { "mejorVendedor", mejorVenderdorDia() }, - { "totalDia", totalDia()}, - { "totalNetoDia", totaldianeto }, - { "EnvioCantidad", totalDiaSinEnvio(envios) }, + { "mejorVendedor", "yo"/*mejorVenderdorMes()*/ }, + { "EnvioCantidad", enviosDia }, + { "totalImportes", importeDia }, } } }; mostrarDatos(estadisticas); } - private int totalMesSinEnvio(Dictionary> envios) - { - return envios["mes"].Count; + private int cantidadEnvios(List envios) + { + return envios.Count; } - private int totalDiaSinEnvio(Dictionary> envios) + private decimal calcularUtilidad(List> resumen, decimal totalImportes, int cantidadEnvios) { - return envios["dia"].Count; - } + decimal utilidad = 0; - private decimal totalMes() - { - decimal total = 0; - foreach(VentaModel venta in ventasMes) + costosCompraProductos = 0; + ganaciaBrutaProductos = 0; + + + foreach (Dictionary venta_y_detalles in resumen) { - total += venta.total; - } - - return total; - } - - private decimal totalDia() - { - decimal total = 0; - - foreach (VentaModel venta in ventasDia) - { - 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) + foreach(DetalleVentaModel detalle in venta_y_detalles["detalles"]) { - totalDetalle += detalle.cantidad * (detalle.producto.precio - detalle.producto.precioCompra); + ganaciaBrutaProductos += detalle.cantidad * detalle.producto.precio; + costosCompraProductos += detalle.cantidad * detalle.producto.precioCompra; } - total += totalDetalle; } - return total; + + utilidad = ganaciaBrutaProductos - costosCompraProductos; + ganaciaBrutaProductos += totalImportes + (cantidadEnvios * 10); + utilidad += totalImportes + (cantidadEnvios * 10); + return utilidad; } private List estadisticasMes() { + List> mes = resumen["mes"]; List detallesMes = new List(); - //recorre las ventas del mes - foreach (VentaModel venta in ventasMes) + foreach (Dictionary venta_y_detalles in mes) { - //consigue los detalles de la venta - List detallesVenta = service.conseguirDetallesVenta(venta); - //recorre los detalles de la venta - foreach (DetalleVentaModel detalle in detallesVenta) + foreach (DetalleVentaModel detallesVenta in venta_y_detalles["detalles"]) { int totalElementos = detallesMes.Count; + int contador = 0; for (int i = 0; i <= totalElementos; i++) { - //si no encuentra el producto lo agrega + contador++; + //si no existe el producto lo agrega if (i == totalElementos) { - DetalleVentaModel detalleAgregar = new DetalleVentaModel(detalle.cantidad, detalle.producto, detalle.idVenta); + 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(detalle.producto.nombre)) + //si existe el producto solo aumenta la cantidad + if (producto.producto.nombre.Equals(detallesVenta.producto.nombre)) { - producto.cantidad += detalle.cantidad; + producto.cantidad += detallesVenta.cantidad; break; } + } } } @@ -158,36 +142,34 @@ namespace compabetov2 private List estadisticasDia() { + //solo copie y pegue le metodo estadisticas dia y cambie el key en resumen de mes a dia + List> dia = resumen["dia"]; 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); + foreach (Dictionary venta_y_detalles in dia) { - //recorre los detalles de la venta - foreach (DetalleVentaModel detalle in detallesVenta) + foreach (DetalleVentaModel detallesVenta in venta_y_detalles["detalles"]) { int totalElementos = detallesDia.Count; int contador = 0; for (int i = 0; i <= totalElementos; i++) { contador++; - //si no encuentra el producto lo agrega + //si no existe el producto lo agrega if (i == totalElementos) { - DetalleVentaModel detalleAgregar = new DetalleVentaModel(detalle.cantidad, detalle.producto, detalle.idVenta); + DetalleVentaModel detalleAgregar = new DetalleVentaModel(detallesVenta.cantidad, detallesVenta.producto, detallesVenta.idVenta); detallesDia.Add(detalleAgregar); break; } DetalleVentaModel producto = detallesDia[i]; - //si encuentra el produco solo aumneta la cantidad - if (producto.producto.nombre.Equals(detalle.producto.nombre)) + //si existe el producto solo aumenta la cantidad + if (producto.producto.nombre.Equals(detallesVenta.producto.nombre)) { - producto.cantidad += detalle.cantidad; + producto.cantidad += detallesVenta.cantidad; break; } + } } } @@ -235,11 +217,13 @@ namespace compabetov2 // Agregar la nueva fila al DataGridView dgvMes.Rows.Add(nuevaFila); } - decimal totalSinEnvioMes = estadisticas["mes"]["totalMes"] - (estadisticas["mes"]["EnvioCantidad"] *10); - lbTotalMes.Text = $"Total de mes: ${estadisticas["mes"]["totalMes"]}"; + + lbUtilidadMes.Text = $"Utilidad del mes: ${calcularUtilidad(resumen["mes"], estadisticas["mes"]["totalImportes"], estadisticas["mes"]["EnvioCantidad"])}"; lbProductoMes.Text = $"Producto mas vendido: {estadisticas["mes"]["productoMasVendido"]}"; lbVendedorMes.Text = $"Mejor vendedor: {estadisticas["mes"]["mejorVendedor"]}"; - lbMesSEnvio.Text = $"Total del mes sin envios: ${totalSinEnvioMes}"; + lbGananciasBrutasMes.Text = $"Ganancias Brutas mes: ${ganaciaBrutaProductos}"; + lbTotalImporteMes.Text = $"Total importe del Mes: ${estadisticas["mes"]["totalImportes"]}"; + lbEnvioMes.Text = $"Total de envios del mes: ${estadisticas["mes"]["EnvioCantidad"] * 10}"; //dia List detallesDia = estadisticas["dia"]["productos"]; @@ -278,12 +262,12 @@ namespace compabetov2 dgvDia.Rows.Add(nuevaFila); } - decimal totalSinEnvioDia = estadisticas["dia"]["totalDia"] - (estadisticas["dia"]["EnvioCantidad"] * 10); - lbTotalDia.Text = $"Total de dia: ${estadisticas["dia"]["totalDia"]}"; + lbUtilidadDia.Text = $"Utilidad del dia: ${calcularUtilidad(resumen["dia"], estadisticas["dia"]["totalImportes"], estadisticas["dia"]["EnvioCantidad"])}"; 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"]}"; + lbGananciasBrutasDia.Text = $"Ganancias Brutas dia: ${ganaciaBrutaProductos}"; + lbTotalImporteDia.Text = $"Total importe del dia: ${estadisticas["dia"]["totalImportes"]}"; + lbEnviosDia.Text = $"Total de envios del dia: ${estadisticas["dia"]["EnvioCantidad"] * 10}"; } @@ -293,10 +277,11 @@ namespace compabetov2 string mejorVendedor = ""; int contadorNumeroVentas = 0; - Dictionary empleados = new Dictionary(); - foreach(VentaModel venta in ventasMes) + List> mes = resumen["mes"]; + Dictionary empleados = new Dictionary(); + foreach (Dictionary venta_y_detalle in mes) { - + VentaModel venta = venta_y_detalle["venta"]; if (empleados.ContainsKey(venta.responzable)) { empleados[venta.responzable] += 1; @@ -342,10 +327,11 @@ namespace compabetov2 string mejorVendedor = ""; int contadorNumeroVentas = 0; + List> dia = resumen["dia"]; Dictionary empleados = new Dictionary(); - foreach (VentaModel venta in ventasDia) + foreach (Dictionary venta_y_detalle in dia) { - + VentaModel venta = venta_y_detalle["venta"]; if (empleados.ContainsKey(venta.responzable)) { empleados[venta.responzable] += 1; @@ -368,6 +354,23 @@ namespace compabetov2 return mejorVendedor; } + private decimal calcularImporte(List> resumen) + { + decimal totalImporte = 0; + + foreach(Dictionary informacion in resumen) + { + List importes = informacion["importes"]; + + foreach(DetalleImporte importe in importes) + { + totalImporte += importe.cantidad * importe.precioImporte; + } + } + + return totalImporte; + } + private void label5_Click(object sender, EventArgs e) { @@ -410,16 +413,21 @@ namespace compabetov2 private void btnVentasDia_Click(object sender, EventArgs e) { - RegistroVentas ventana = new RegistroVentas(ventasDia,this); + RegistroVentas ventana = new RegistroVentas(resumen["dia"],this); ventana.Owner = this; ventana.Show(); } private void btnVentasMes_Click(object sender, EventArgs e) { - RegistroVentas ventana = new RegistroVentas(ventasMes, this); + RegistroVentas ventana = new RegistroVentas(resumen["mes"], this); ventana.Owner = this; ventana.Show(); } + + private void lbTotalDia_Click(object sender, EventArgs e) + { + + } } } diff --git a/Estadiscticas.resx b/Estadiscticas.resx index 60ffc58..a4d2de6 100644 --- a/Estadiscticas.resx +++ b/Estadiscticas.resx @@ -135,42 +135,6 @@ True - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - True diff --git a/RegistroVentas.Designer.cs b/RegistroVentas.Designer.cs index c6907b9..61532de 100644 --- a/RegistroVentas.Designer.cs +++ b/RegistroVentas.Designer.cs @@ -39,7 +39,7 @@ 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.Size = new System.Drawing.Size(422, 547); this.panelVentas.TabIndex = 0; // // lbContador @@ -84,7 +84,9 @@ this.Controls.Add(this.lbContador); this.Controls.Add(this.panelVentas); this.Name = "RegistroVentas"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "RegistroVentas"; + this.Load += new System.EventHandler(this.RegistroVentas_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/RegistroVentas.cs b/RegistroVentas.cs index 9f3ed72..ceb4c80 100644 --- a/RegistroVentas.cs +++ b/RegistroVentas.cs @@ -14,27 +14,39 @@ namespace compabetov2 { public partial class RegistroVentas : Form { - List ventas; + List> ventasYDetalles; Estadiscticas ventanaPadre; - public RegistroVentas(List ventas,Estadiscticas ventanaPadre) + int cantidadVentas; + int cotaInferior = 0; + int cotaSuperior; + public RegistroVentas(List> ventasYDetalles, Estadiscticas ventanaPadre) { InitializeComponent(); this.ventanaPadre = ventanaPadre; - this.ventas = ventas; + this.ventasYDetalles = ventasYDetalles; + cantidadVentas = ventasYDetalles.Count; + lbContador.Text = $"0 - {cantidadVentas}"; + cotaSuperior = cantidadVentas > 20 ? 20 : cantidadVentas; llenarPanel(); } private void llenarPanel() { - foreach(VentaModel venta in ventas) + panelVentas.Controls.Clear(); + + for(int i = cotaInferior; i < cotaSuperior; i++) { + Dictionary ventaYDetalles = ventasYDetalles[i]; + VentaModel venta = ventaYDetalles["venta"]; + 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; + carta.RowStyles.Add(new RowStyle(SizeType.Percent, 70F)); + carta.RowStyles.Add(new RowStyle(SizeType.Percent, 30F)); + carta.Width = 385; + carta.Height = 150; + carta.BackColor = Color.FromArgb(200, 200, 200); FlowLayoutPanel infoPanel = new FlowLayoutPanel(); infoPanel.FlowDirection = FlowDirection.TopDown; @@ -42,27 +54,25 @@ namespace compabetov2 Label lbFecha = new Label(); lbFecha.Text = $"Fecha: {venta.fecha}"; - lbFecha.Font = new Font(lbFecha.Font.FontFamily, 12); + lbFecha.Font = new Font(lbFecha.Font.FontFamily, 16); lbFecha.Width = 700; Label lbResponzable = new Label(); - lbResponzable.Text = $"Responzable: {venta.responzable}"; - lbResponzable.Font = new Font(lbResponzable.Font.FontFamily, 12); + lbResponzable.Text = $"Responsable: {venta.responzable}"; + lbResponzable.Font = new Font(lbResponzable.Font.FontFamily, 16); lbResponzable.Width = 700; Label lbTotal = new Label(); lbTotal.Text = $"Total: {venta.total}"; - lbTotal.Font = new Font(lbTotal.Font.FontFamily, 12); + lbTotal.Font = new Font(lbTotal.Font.FontFamily, 16); lbTotal.Width = 700; TableLayoutPanel botonesPanel = new TableLayoutPanel(); botonesPanel.RowCount = 1; - botonesPanel.ColumnCount = 4; + botonesPanel.ColumnCount = 2; 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.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); botonesPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); Button btnDetalles = new Button(); @@ -74,6 +84,26 @@ namespace compabetov2 btnDetalles.Font = new Font(btnDetalles.Font.FontFamily, 16); btnDetalles.ForeColor = Color.White; btnDetalles.Click += new EventHandler(delegate (object sender, EventArgs e) + { + List detalles = ventaYDetalles["detalles"]; + string mensaje = ""; + foreach (DetalleVentaModel detalle in detalles) + { + mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n"; + } + mensaje += $"Total: {venta.total}"; + MessageBox.Show(mensaje); + }); + + Button btnImprimir = new Button(); + btnImprimir.Text = "Ticket"; + btnImprimir.Dock = DockStyle.Fill; + btnImprimir.FlatStyle = FlatStyle.Flat; + btnImprimir.FlatAppearance.BorderSize = 0; + btnImprimir.BackColor = Color.Yellow; + btnImprimir.Font = new Font(btnImprimir.Font.FontFamily, 16); + btnImprimir.ForeColor = Color.Black; + btnImprimir.Click += new EventHandler(delegate (object sender, EventArgs e) { }); @@ -82,20 +112,49 @@ namespace compabetov2 infoPanel.Controls.Add(lbResponzable); botonesPanel.Controls.Add(btnDetalles, 0, 0); + botonesPanel.Controls.Add(btnImprimir, 1, 0); carta.Controls.Add(infoPanel, 0, 0); carta.Controls.Add(botonesPanel, 0, 1); panelVentas.Controls.Add(carta); } + + foreach (Dictionary ventaYDetalles in ventasYDetalles) + { + VentaModel venta = ventaYDetalles["venta"]; + + + } } private void btnMenos_Click(object sender, EventArgs e) { + cotaInferior -= 20; + cotaInferior = cotaInferior > 0 ? cotaInferior : 0; + + cotaSuperior -= 20; + cotaSuperior = cotaInferior == 0 ? 20 : cotaSuperior; + + llenarPanel(); + lbContador.Text = $"{cotaInferior} - {cantidadVentas}"; } private void btnMas_Click(object sender, EventArgs e) + { + cotaSuperior += 20; + cotaSuperior = cotaSuperior > cantidadVentas ? cantidadVentas : cotaSuperior; + + cotaInferior += 20; + cotaInferior = cotaSuperior == cantidadVentas ? cotaSuperior - 20 : cotaInferior; + + llenarPanel(); + lbContador.Text = $"{cotaInferior} - {cantidadVentas}"; + + } + + private void RegistroVentas_Load(object sender, EventArgs e) { } diff --git a/Ventas/vender.Designer.cs b/Ventas/vender.Designer.cs index 76297f3..9680030 100644 --- a/Ventas/vender.Designer.cs +++ b/Ventas/vender.Designer.cs @@ -70,9 +70,10 @@ this.lblfecha.AutoSize = true; this.lblfecha.Font = new System.Drawing.Font("Microsoft Sans Serif", 30F); this.lblfecha.ForeColor = System.Drawing.Color.Navy; - this.lblfecha.Location = new System.Drawing.Point(619, 128); + this.lblfecha.Location = new System.Drawing.Point(464, 104); + this.lblfecha.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.lblfecha.Name = "lblfecha"; - this.lblfecha.Size = new System.Drawing.Size(159, 58); + this.lblfecha.Size = new System.Drawing.Size(126, 46); this.lblfecha.TabIndex = 13; this.lblfecha.Text = "label2"; this.lblfecha.TextAlign = System.Drawing.ContentAlignment.TopCenter; @@ -83,9 +84,10 @@ this.lblhora.AutoSize = true; this.lblhora.Font = new System.Drawing.Font("Microsoft Sans Serif", 60F); this.lblhora.ForeColor = System.Drawing.Color.MediumBlue; - this.lblhora.Location = new System.Drawing.Point(807, 9); + this.lblhora.Location = new System.Drawing.Point(605, 7); + this.lblhora.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.lblhora.Name = "lblhora"; - this.lblhora.Size = new System.Drawing.Size(318, 113); + this.lblhora.Size = new System.Drawing.Size(249, 91); this.lblhora.TabIndex = 12; this.lblhora.Text = "label1"; this.lblhora.Click += new System.EventHandler(this.lblhora_Click); @@ -96,10 +98,10 @@ this.flowLayoutPanel2.Controls.Add(this.panel1); this.flowLayoutPanel2.Controls.Add(this.label1); this.flowLayoutPanel2.Controls.Add(this.labeltotal); - this.flowLayoutPanel2.Location = new System.Drawing.Point(1605, -1); - this.flowLayoutPanel2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.flowLayoutPanel2.Location = new System.Drawing.Point(1204, -1); + this.flowLayoutPanel2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.flowLayoutPanel2.Name = "flowLayoutPanel2"; - this.flowLayoutPanel2.Size = new System.Drawing.Size(324, 1191); + this.flowLayoutPanel2.Size = new System.Drawing.Size(243, 968); this.flowLayoutPanel2.TabIndex = 11; this.flowLayoutPanel2.Paint += new System.Windows.Forms.PaintEventHandler(this.flowLayoutPanel2_Paint); // @@ -107,17 +109,17 @@ // this.panel1.BackColor = System.Drawing.Color.Transparent; this.panel1.Controls.Add(this.pictureBox9); - this.panel1.Location = new System.Drawing.Point(3, 2); - this.panel1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panel1.Location = new System.Drawing.Point(2, 2); + this.panel1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(312, 263); + this.panel1.Size = new System.Drawing.Size(234, 214); this.panel1.TabIndex = 8; // // pictureBox9 // this.pictureBox9.Image = global::compabetov2.Properties.Resources.HomeroMenu; - this.pictureBox9.Location = new System.Drawing.Point(64, 34); - this.pictureBox9.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBox9.Location = new System.Drawing.Point(48, 28); + this.pictureBox9.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pictureBox9.Name = "pictureBox9"; this.pictureBox9.Size = new System.Drawing.Size(190, 197); this.pictureBox9.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -130,9 +132,10 @@ this.label1.BackColor = System.Drawing.Color.Transparent; this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F); this.label1.ForeColor = System.Drawing.Color.AliceBlue; - this.label1.Location = new System.Drawing.Point(3, 267); + this.label1.Location = new System.Drawing.Point(2, 218); + this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(102, 39); + this.label1.Size = new System.Drawing.Size(83, 31); this.label1.TabIndex = 17; this.label1.Text = "Total:"; this.label1.Click += new System.EventHandler(this.label1_Click); @@ -143,9 +146,10 @@ this.labeltotal.BackColor = System.Drawing.Color.Transparent; this.labeltotal.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F); this.labeltotal.ForeColor = System.Drawing.Color.AliceBlue; - this.labeltotal.Location = new System.Drawing.Point(111, 267); + this.labeltotal.Location = new System.Drawing.Point(89, 218); + this.labeltotal.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.labeltotal.Name = "labeltotal"; - this.labeltotal.Size = new System.Drawing.Size(0, 39); + this.labeltotal.Size = new System.Drawing.Size(0, 31); this.labeltotal.TabIndex = 18; // // flowLayoutPanel1 @@ -157,26 +161,26 @@ this.flowLayoutPanel1.Controls.Add(this.button3); this.flowLayoutPanel1.Controls.Add(this.button5); this.flowLayoutPanel1.Location = new System.Drawing.Point(-1, 2); - this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Size = new System.Drawing.Size(324, 1199); + this.flowLayoutPanel1.Size = new System.Drawing.Size(243, 974); this.flowLayoutPanel1.TabIndex = 8; // // panel2 // this.panel2.BackColor = System.Drawing.Color.Transparent; this.panel2.Controls.Add(this.pictureBox7); - this.panel2.Location = new System.Drawing.Point(3, 2); - this.panel2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panel2.Location = new System.Drawing.Point(2, 2); + this.panel2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(312, 263); + this.panel2.Size = new System.Drawing.Size(234, 214); this.panel2.TabIndex = 8; // // pictureBox7 // this.pictureBox7.Image = global::compabetov2.Properties.Resources.HomeroMenu; - this.pictureBox7.Location = new System.Drawing.Point(64, 34); - this.pictureBox7.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBox7.Location = new System.Drawing.Point(48, 28); + this.pictureBox7.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pictureBox7.Name = "pictureBox7"; this.pictureBox7.Size = new System.Drawing.Size(190, 197); this.pictureBox7.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -192,11 +196,11 @@ this.button1.ForeColor = System.Drawing.SystemColors.ButtonHighlight; this.button1.Image = global::compabetov2.Properties.Resources.Menui1; this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.button1.Location = new System.Drawing.Point(3, 269); - this.button1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.button1.Location = new System.Drawing.Point(2, 220); + this.button1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button1.Name = "button1"; - this.button1.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0); - this.button1.Size = new System.Drawing.Size(312, 114); + this.button1.Padding = new System.Windows.Forms.Padding(38, 0, 0, 0); + this.button1.Size = new System.Drawing.Size(234, 93); this.button1.TabIndex = 8; this.button1.Text = "Menú"; this.button1.UseVisualStyleBackColor = false; @@ -211,11 +215,11 @@ this.button2.ForeColor = System.Drawing.SystemColors.ButtonHighlight; this.button2.Image = global::compabetov2.Properties.Resources.estadisticasi; this.button2.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.button2.Location = new System.Drawing.Point(3, 387); - this.button2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.button2.Location = new System.Drawing.Point(2, 317); + this.button2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button2.Name = "button2"; - this.button2.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0); - this.button2.Size = new System.Drawing.Size(312, 114); + this.button2.Padding = new System.Windows.Forms.Padding(38, 0, 0, 0); + this.button2.Size = new System.Drawing.Size(234, 93); this.button2.TabIndex = 9; this.button2.Text = "Reportes"; this.button2.UseVisualStyleBackColor = false; @@ -230,11 +234,11 @@ this.button3.ForeColor = System.Drawing.SystemColors.ButtonHighlight; this.button3.Image = global::compabetov2.Properties.Resources.productoi; this.button3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.button3.Location = new System.Drawing.Point(3, 505); - this.button3.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.button3.Location = new System.Drawing.Point(2, 414); + this.button3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button3.Name = "button3"; - this.button3.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0); - this.button3.Size = new System.Drawing.Size(312, 114); + this.button3.Padding = new System.Windows.Forms.Padding(38, 0, 0, 0); + this.button3.Size = new System.Drawing.Size(234, 93); this.button3.TabIndex = 10; this.button3.Text = "Productos"; this.button3.UseVisualStyleBackColor = false; @@ -248,11 +252,11 @@ this.button5.ForeColor = System.Drawing.SystemColors.ButtonHighlight; this.button5.Image = global::compabetov2.Properties.Resources.sesionc; this.button5.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.button5.Location = new System.Drawing.Point(3, 623); - this.button5.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.button5.Location = new System.Drawing.Point(2, 511); + this.button5.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button5.Name = "button5"; - this.button5.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0); - this.button5.Size = new System.Drawing.Size(312, 114); + this.button5.Padding = new System.Windows.Forms.Padding(38, 0, 0, 0); + this.button5.Size = new System.Drawing.Size(234, 93); this.button5.TabIndex = 12; this.button5.Text = "Salir"; this.button5.UseVisualStyleBackColor = false; @@ -260,20 +264,20 @@ // flowLayoutPanel3 // this.flowLayoutPanel3.AutoScroll = true; - this.flowLayoutPanel3.Location = new System.Drawing.Point(329, 343); - this.flowLayoutPanel3.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.flowLayoutPanel3.Location = new System.Drawing.Point(247, 279); + this.flowLayoutPanel3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.flowLayoutPanel3.Name = "flowLayoutPanel3"; - this.flowLayoutPanel3.Size = new System.Drawing.Size(1273, 730); + this.flowLayoutPanel3.Size = new System.Drawing.Size(955, 593); this.flowLayoutPanel3.TabIndex = 14; this.flowLayoutPanel3.Paint += new System.Windows.Forms.PaintEventHandler(this.flowLayoutPanel3_Paint); // // txtbusqueda // this.txtbusqueda.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.txtbusqueda.Location = new System.Drawing.Point(329, 219); - this.txtbusqueda.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.txtbusqueda.Location = new System.Drawing.Point(247, 178); + this.txtbusqueda.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.txtbusqueda.Name = "txtbusqueda"; - this.txtbusqueda.Size = new System.Drawing.Size(703, 36); + this.txtbusqueda.Size = new System.Drawing.Size(528, 30); this.txtbusqueda.TabIndex = 15; this.txtbusqueda.TextChanged += new System.EventHandler(this.txtbusqueda_TextChanged); // @@ -283,10 +287,10 @@ this.bntImprimir.Enabled = false; this.bntImprimir.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F); this.bntImprimir.ForeColor = System.Drawing.Color.Transparent; - this.bntImprimir.Location = new System.Drawing.Point(1055, 210); - this.bntImprimir.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.bntImprimir.Location = new System.Drawing.Point(791, 171); + this.bntImprimir.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.bntImprimir.Name = "bntImprimir"; - this.bntImprimir.Size = new System.Drawing.Size(151, 54); + this.bntImprimir.Size = new System.Drawing.Size(113, 44); this.bntImprimir.TabIndex = 17; this.bntImprimir.Text = "Vender"; this.bntImprimir.UseVisualStyleBackColor = false; @@ -296,10 +300,10 @@ // this.responsablecb.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F); this.responsablecb.FormattingEnabled = true; - this.responsablecb.Location = new System.Drawing.Point(1371, 218); - this.responsablecb.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.responsablecb.Location = new System.Drawing.Point(1028, 177); + this.responsablecb.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.responsablecb.Name = "responsablecb"; - this.responsablecb.Size = new System.Drawing.Size(227, 37); + this.responsablecb.Size = new System.Drawing.Size(171, 33); this.responsablecb.TabIndex = 18; this.responsablecb.SelectedIndexChanged += new System.EventHandler(this.responsablecb_SelectedIndexChanged); // @@ -309,10 +313,9 @@ this.btnFiar.Enabled = false; this.btnFiar.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F); this.btnFiar.ForeColor = System.Drawing.Color.Transparent; - this.btnFiar.Location = new System.Drawing.Point(1213, 210); - this.btnFiar.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.btnFiar.Location = new System.Drawing.Point(910, 171); this.btnFiar.Name = "btnFiar"; - this.btnFiar.Size = new System.Drawing.Size(151, 54); + this.btnFiar.Size = new System.Drawing.Size(113, 44); this.btnFiar.TabIndex = 19; this.btnFiar.Text = "Cuenta"; this.btnFiar.UseVisualStyleBackColor = false; @@ -324,10 +327,10 @@ this.btnEnviar.Enabled = false; this.btnEnviar.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F); this.btnEnviar.ForeColor = System.Drawing.Color.Transparent; - this.btnEnviar.Location = new System.Drawing.Point(1213, 273); - this.btnEnviar.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.btnEnviar.Location = new System.Drawing.Point(910, 222); + this.btnEnviar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnEnviar.Name = "btnEnviar"; - this.btnEnviar.Size = new System.Drawing.Size(151, 54); + this.btnEnviar.Size = new System.Drawing.Size(113, 44); this.btnEnviar.TabIndex = 20; this.btnEnviar.Text = "Enviar"; this.btnEnviar.UseVisualStyleBackColor = false; @@ -338,10 +341,10 @@ this.btnImporte.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(27)))), ((int)(((byte)(104)))), ((int)(((byte)(255))))); this.btnImporte.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F); this.btnImporte.ForeColor = System.Drawing.Color.Transparent; - this.btnImporte.Location = new System.Drawing.Point(1056, 273); - this.btnImporte.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.btnImporte.Location = new System.Drawing.Point(792, 222); + this.btnImporte.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnImporte.Name = "btnImporte"; - this.btnImporte.Size = new System.Drawing.Size(151, 54); + this.btnImporte.Size = new System.Drawing.Size(113, 44); this.btnImporte.TabIndex = 21; this.btnImporte.Text = "Importe"; this.btnImporte.UseVisualStyleBackColor = false; @@ -349,9 +352,9 @@ // // vender // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1767, 772); + this.ClientSize = new System.Drawing.Size(1166, 627); this.ControlBox = false; this.Controls.Add(this.btnImporte); this.Controls.Add(this.btnEnviar); @@ -364,7 +367,7 @@ this.Controls.Add(this.lblhora); this.Controls.Add(this.flowLayoutPanel2); this.Controls.Add(this.flowLayoutPanel1); - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.Name = "vender"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Load += new System.EventHandler(this.vender_Load); diff --git a/Ventas/vender.cs b/Ventas/vender.cs index 6d93327..fcf1ed1 100644 --- a/Ventas/vender.cs +++ b/Ventas/vender.cs @@ -558,7 +558,8 @@ namespace compabetov2 DialogResult resultado = MessageBox.Show("¿Quieres hacer la devolucion del importe?", "Confirmación devolucion de importe", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultado == DialogResult.Yes) { - if (service.devolverImporte(importes)) + VentaModel venta = new VentaModel(total,-1,DateTime.Now.ToString(),responsablecb.Text); + if (service.devolverImporte(venta, importes)) { MessageBox.Show("Importe devuelto"); llenarLayout(); diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index 27c6cd2..c0f84ce 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 6675008..cb9c431 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 ab7e110..acf9349 100644 Binary files a/bin/Debug/data.db and b/bin/Debug/data.db differ diff --git a/database/DAO.cs b/database/DAO.cs index faa6e3e..b949225 100644 --- a/database/DAO.cs +++ b/database/DAO.cs @@ -872,8 +872,9 @@ namespace compabetov2.database } } - public static bool devolverImporteDAO(List importes) + public static bool devolverImporteDAO(VentaModel venta, List importes) { + var db_conexion = new Conexion(); try { @@ -885,7 +886,28 @@ namespace compabetov2.database { try { - string sqlImporte = "INSERT INTO detalle_importe (fk_importe,cantidad,precio,fecha) VALUES (@fk_importe,@cantidad,@precio,@fecha)"; + string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);"; + 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)"; + + // 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(); + + long idVenta = -1; + while (reader.Read()) + { + idVenta = reader.GetInt64(0); + } + + //creacion del importe foreach (DetalleImporte importe in importes) { @@ -895,7 +917,7 @@ namespace compabetov2.database commandDetalleImporte.Parameters.AddWithValue("@fk_importe", importe.fkImporte); 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(); } } @@ -1917,6 +1939,32 @@ namespace compabetov2.database } } + + public static SQLiteDataReader conseguirImportesVentaDAO(VentaModel venta) + { + SQLiteDataReader reader = null; + var db_conexion = new Conexion(); + try + { + SQLiteConnection conexion = db_conexion.get_connection(); + + conexion.Open(); + + string sql = "SELECT * FROM detalle_importe WHERE fk_venta = @fk_venta;"; + SQLiteCommand command = new SQLiteCommand(sql, conexion); + command.Parameters.AddWithValue("@fk_venta", venta.id); + reader = command.ExecuteReader(); + + return reader; + + } + catch (SQLiteException ex) + { + MessageBox.Show(ex.Message); + return reader; + } + } + private static void crearDB() { var db_conexion = new Conexion(); diff --git a/database/service.cs b/database/service.cs index 7d89124..ea51aaa 100644 --- a/database/service.cs +++ b/database/service.cs @@ -209,9 +209,9 @@ namespace compabetov2.database return DAO.crearVentaDAO(venta, detalleVentas,importes); } - public static bool devolverImporte(List importes) + public static bool devolverImporte(VentaModel venta,List importes) { - return DAO.devolverImporteDAO(importes); + return DAO.devolverImporteDAO(venta,importes); } public static bool insertarMerma(Merma merma) @@ -427,49 +427,76 @@ namespace compabetov2.database return DAO.concluirEnvioDAO(envio, detallesEnvio, importes); } - public static List conseguirVentasMes(DateTime fecha) + public static Dictionary>> estadisticas(DateTime fecha) { - List ventasMes = new List(); - SQLiteDataReader readerVentas = DAO.conseguirVentasMesDAO(fecha); + Dictionary>> resumen = new Dictionary>>(); + List> listMes = new List>(); + List> listDia = new List>(); - 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), - readerVentas.GetString(1), - readerVentas.GetString(3) + readerVentas.GetDecimal(2),//total + (int)readerVentas.GetInt64(0),//id + readerVentas.GetString(1),//fecha + readerVentas.GetString(3)//responzable + ); + + List detallesVenta = new List(); + SQLiteDataReader readerDetalleVenta = DAO.conseguirDetalleVenta(venta); + while (readerDetalleVenta.Read()) + { + decimal precioCompra = readerDetalleVenta.GetDecimal(3); + DetalleVentaModel detalleVenta = new DetalleVentaModel( + (int)readerDetalleVenta.GetInt64(2),// cantidad + 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) ); + detallesVenta.Add(detalleVenta); + } + + List importes = new List(); + SQLiteDataReader readerImporte = DAO.conseguirImportesVentaDAO(venta); + + while (readerImporte.Read()) + { + DetalleImporte importe = new DetalleImporte( + (int)readerImporte.GetInt64(1),//fkImporte + (int)readerImporte.GetInt64(2),//cantidad + readerImporte.GetDecimal(3),//precio + (int)readerImporte.GetInt64(4)//fkVenta + ); + importes.Add(importe); + } string[] fecha_hora = venta.fecha.Split(' '); string fechaVentaStr = fecha_hora[0]; + dicVenta.Add("venta", venta); + dicVenta.Add("detalles", detallesVenta as List); + dicVenta.Add("importes", importes); + DateTime.TryParseExact(fechaVentaStr, formato, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fechaVenta); if (fecha.Day == fechaVenta.Day) { - ventasDia.Add(venta); + listDia.Add(dicVenta); } + listMes.Add(dicVenta); } - return ventasDia; + + resumen.Add("mes", listMes); + resumen.Add("dia", listDia); + + return resumen; } public static List conseguirProductosFiltrados(string nombreProducto) diff --git a/obj/Debug/compabetov2.csproj.GenerateResource.cache b/obj/Debug/compabetov2.csproj.GenerateResource.cache index 2e04e31..e35ac7e 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 27c6cd2..c0f84ce 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 6675008..cb9c431 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ