Ejemplo n.º 1
0
        private void btnCobrar_Click(object sender, EventArgs e)
        {
            if (dgvGrilla.RowCount > 0)
            {
                if (ckbTarjeta.Checked == false && ckbPedido.Checked == false && ckbNormal.Checked == false && ckbCtaCte.Checked == false && ckbGuardar.Checked == false)
                {
                    MessageBox.Show("Seleccione el Tipo de Pago, Tarjeta, Contado, Pedido.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }

                if (ckbNormal.Checked || ckbTarjeta.Checked)
                {
                    if (MessageBox.Show("Esta Seguro de Continuar?", "Pregunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (ventaDto.ClienteId == 0)
                        {
                            ventaDto.ClienteId = 0;
                        }

                        ventaDto.Fecha = DateTime.Now;
                        ventaDto.Total = _total;


                        var ventaId = ventaServicio.NuevaVenta(ventaDto);

                        string descripcion = string.Empty;

                        foreach (var item in ListaVenta)
                        {
                            var producto = productoServicio.ObtenerPorId(item.Id);

                            var producto_venta = new Producto_Venta_Dto
                            {
                                Cantidad    = item.Cantidad,
                                Descripcion = item.Descripcion,
                                Estado      = AccesoDatos.EstadoPedido.Terminado,
                                ProductoId  = item.Id,
                                Talle       = item.Talle,
                                Precio      = item.Precio * item.Cantidad,
                                VentaId     = ventaId,
                                TalleId     = ((TalleDto)cmbTalle.SelectedItem).Id
                            };

                            // descontar stock
                            productoServicio.BajarStock(producto.Id, item.Cantidad);
                            //

                            descripcion = $"{descripcion} - {producto_venta.Descripcion}";

                            producto_vent.NuevoProductoVenta(producto_venta);
                        }

                        var detalle = new DetalleCajaDto
                        {
                            Fecha       = DateTime.Now.ToLongDateString(),
                            Total       = _total,
                            Descripcion = $"Venta {descripcion}",
                            CajaId      = detalleCajaServicio.BuscarCajaAbierta(),
                        };

                        TipoPago(detalle);

                        detalleCajaServicio.AgregarDetalleCaja(detalle);

                        cajaServicio.SumarDineroACaja(_total);

                        //MessageBox.Show("Felicidades, Cobro Aceptado!", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information);

#pragma warning disable CS0436 // El tipo 'Afirmacion' de 'C:\Users\Pepe\Source\Repos\JoseSabeckis\KosakoJean\Presentacion.Core\Mensaje\Afirmacion.cs' está en conflicto con el tipo importado 'Afirmacion' de 'Presentacion, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se usará el tipo definido en 'C:\Users\Pepe\Source\Repos\JoseSabeckis\KosakoJean\Presentacion.Core\Mensaje\Afirmacion.cs'.
                        var mensaje = new Afirmacion("Genial", $"Cobro Aceptado!\n\nGanancia: $ {_total}\n{detalle.TipoPago}");
#pragma warning restore CS0436 // El tipo 'Afirmacion' de 'C:\Users\Pepe\Source\Repos\JoseSabeckis\KosakoJean\Presentacion.Core\Mensaje\Afirmacion.cs' está en conflicto con el tipo importado 'Afirmacion' de 'Presentacion, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Se usará el tipo definido en 'C:\Users\Pepe\Source\Repos\JoseSabeckis\KosakoJean\Presentacion.Core\Mensaje\Afirmacion.cs'.
                        mensaje.ShowDialog();

                        foreach (var item in ListaVenta)
                        {
                            item.Precio = item.Cantidad * item.Precio;
                        }


                        if (ckbTicket.Checked)
                        {
                            VerTicket(ListaVenta.ToList());
                        }

                        //limpiar
                        btnLimpiar.PerformClick();
                    }
                }
                else
                {
                    if (ckbPedido.Checked)
                    {
                        bool Bandera = false;

                        foreach (var item in ListaVenta)
                        {
                            if (productoServicio.ObtenerPorId(item.ProductoId).Creacion)
                            {
                                Bandera = true;
                            }
                        }

                        if (!Bandera)
                        {
                            if (MessageBox.Show("Esta Por Crear Un Pedido Sin Ninguna Prenda Para Fabricar, Desea Continuar?", "Pregunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                            {
                                return;
                            }
                        }

                        var pedidos = new Pedido.Pedido(ListaVenta, _total, ventaServicio.ObtenerClienteName(ventaDto.ClienteId), _clienteId, txtDescripcion.Text);
                        pedidos.ShowDialog();

                        if (pedidos.semaforo)
                        {
                            if (ckbTicket.Checked)
                            {
                                VerTicket(ListaVenta.ToList());
                            }

                            btnLimpiar.PerformClick();
                        }
                    }

                    if (ckbCtaCte.Checked || ckbGuardar.Checked)
                    {
                        foreach (var item in ListaVenta)
                        {
                            var producto = productoServicio.ObtenerPorId(item.Id);

                            var producto_venta = new Producto_Venta_Dto
                            {
                                Cantidad    = item.Cantidad,
                                Descripcion = item.Descripcion,
                                Estado      = AccesoDatos.EstadoPedido.Terminado,
                                ProductoId  = item.Id,
                                Talle       = item.Talle,
                                Precio      = item.Precio * item.Cantidad,
                                VentaId     = 0,
                                TalleId     = ((TalleDto)cmbTalle.SelectedItem).Id
                            };

                            ListaCtaCte.Add(producto_venta);
                        }

                        var cuenta = new CtaCteClientePedido(_clienteId, _total, ListaCtaCte, ListaVenta);
                        cuenta.ShowDialog();

                        if (cuenta.semaforo)
                        {
                            if (ckbTicket.Checked)
                            {
                                VerTicket(ListaVenta.ToList());
                            }

                            btnLimpiar.PerformClick();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Cargue la Grilla", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            btnSeleccionProducto.Select();
        }