public static void CancelarPedido(Formulario formulario,
                                          List <LineaDePedido> ListaDetallesFact,
                                          List <EspecificacionDeProducto> ListaProducto,
                                          TextBox txtSubTotalFactura,
                                          TextBox txtTOTALFactura,
                                          TextBox txtIvaFact,
                                          NumericUpDown nudImporteFact,
                                          TextBox txtVueltoFAct,
                                          Button btnAgregarfactura,
                                          DataGridView dgvListaProducto,
                                          DataGridView dgvGrillaFactura)
        {
            foreach (var itemDetalle in ListaDetallesFact)
            {
                foreach (var itemProducto in ListaProducto)
                {
                    if (itemDetalle.Codigo == itemProducto.ProdCodigo)
                    {
                        itemProducto.ProdStock += itemDetalle.Cantidad;
                    }
                }
            }

            txtSubTotalFactura.Text   = "0";
            txtTOTALFactura.Text      = "0";
            txtIvaFact.Text           = "0";
            nudImporteFact.Value      = 0;
            txtVueltoFAct.Text        = "0";
            btnAgregarfactura.Enabled = true;

            ListaDetallesFact.Clear();
            Facturacion.cargargrillaproducto(formulario, ListaProducto, dgvListaProducto);
            Facturacion.cargarGrillaFact(formulario, ListaDetallesFact, dgvGrillaFactura);
        }
        public static void AgregarPedido(Formulario formulario,
                                         TextBox txtCodigoProductoFactura,
                                         List <EspecificacionDeProducto> ListaProducto,
                                         EspecificacionDeProducto ProdActual,
                                         NumericUpDown nudCantidadDetallesFAct,
                                         DataGridView dgvListaProducto,
                                         Button btnGuardarFactura,
                                         NumericUpDown nudImporteFact,
                                         List <LineaDePedido> ListaDetallesFact,
                                         TextBox txtDescripcionProductoFactura,
                                         DataGridView dgvGrillaFactura,
                                         NumericUpDown nudPrecioProducto,
                                         bool FactA,
                                         bool FactB,
                                         bool FactC,
                                         TextBox txtIvaFact,
                                         EspecificacionDeProducto factura, TextBox txtSubTotalFactura,
                                         TextBox txtTOTALFactura)
        {
            if (string.IsNullOrEmpty(formulario.cmbProductoStock.SelectedValue.ToString()))
            {
                MessageBox.Show("Seleccione un producto");
            }
            else
            {
                if (string.IsNullOrEmpty(txtCodigoProductoFactura.Text))
                {
                    MessageBox.Show("El producto no existe");
                }
                else
                {
                    ProdActual = Facturacion.BuscarProd(formulario.txtCodigoProductoFactura.Text, ListaProducto);

                    AgregarEspecificacionProducto(formulario, ProdActual, Convert.ToInt32(nudCantidadDetallesFAct.Value), nudCantidadDetallesFAct, ProdActual,
                                                  ListaDetallesFact, txtDescripcionProductoFactura, dgvGrillaFactura, txtCodigoProductoFactura,
                                                  nudPrecioProducto, ListaProducto, dgvListaProducto, FactA, FactB, FactC, txtIvaFact, factura,
                                                  txtSubTotalFactura, txtTOTALFactura);

                    Facturacion.cargargrillaproducto(formulario, ListaProducto, dgvListaProducto);
                    nudCantidadDetallesFAct.Value = 1;
                    FacturaABC(FactA, FactB, FactC, txtIvaFact, ListaDetallesFact, txtSubTotalFactura, txtTOTALFactura);

                    ExiteProductosListaFact(txtTOTALFactura, nudImporteFact);
                    btnGuardarFactura.Enabled = true;
                    nudImporteFact.Enabled    = true;
                }
            }
        }
        public static void ConfirmarFinalizarTurno(
            List <Turno> ListaTurno,
            TextBox txtTurno,
            Button btnTurno,
            List <Pedido> ListaFacturaEmpleado,
            TextBox txtTotalTurno,
            TabControl tabControl1,
            ComboBox cmbProductoStock,
            NumericUpDown nudCantidadDetallesFAct,
            Button btnAgregarfactura,
            Button btnCancelarFactura,
            CheckBox cbLechuga,
            CheckBox cbTomate,
            CheckBox cbAderezos,
            CheckBox cbPicante,
            CheckBox cbJamon,
            CheckBox cbQueso,
            CheckBox cbHuevo,
            Button btnFinalizarTurno)
        {
            decimal totalRecaudadoTurno = 0;

            foreach (Turno turno in ListaTurno)
            {
                if (turno.FechaHoraInicio != DateTime.MinValue && turno.FechaHoraFin == DateTime.MinValue)
                {
                    turno.FechaHoraFin = DateTime.Now;

                    txtTurno.Text = "";
                    btnTurno.Text = "Iniciar Turno";

                    foreach (var venta in ListaFacturaEmpleado)
                    {
                        totalRecaudadoTurno = totalRecaudadoTurno + venta.Total;
                    }

                    Facturacion.EnableComponent(false, cmbProductoStock, nudCantidadDetallesFAct, btnAgregarfactura,
                                                btnCancelarFactura, cbLechuga, cbTomate, cbAderezos, cbPicante, cbJamon, cbQueso, cbHuevo,
                                                btnFinalizarTurno);
                    break;
                }
            }

            txtTotalTurno.Text        = totalRecaudadoTurno.ToString();
            tabControl1.SelectedIndex = 0;
        }
        public static void CargarProductoSeleccionado(ComboBox cmbProductoStock,
                                                      CheckBox cbLechuga,
                                                      CheckBox cbTomate,
                                                      CheckBox cbAderezos,
                                                      CheckBox cbPicante,
                                                      CheckBox cbJamon,
                                                      CheckBox cbQueso,
                                                      CheckBox cbHuevo,
                                                      EspecificacionDeProducto ProdActual,
                                                      List <EspecificacionDeProducto> ListaProducto,
                                                      TextBox txtCodigoProductoFactura,
                                                      TextBox txtDescripcionProductoFactura,
                                                      NumericUpDown nudPrecioProducto)
        {
            cbLechuga.Checked  = true;
            cbTomate.Checked   = true;
            cbAderezos.Checked = true;
            cbPicante.Checked  = false;
            cbJamon.Checked    = false;
            cbQueso.Checked    = false;
            cbHuevo.Checked    = false;

            if (cmbProductoStock.SelectedValue.ToString() == "Papas Fritas")
            {
                cbLechuga.Enabled  = false;
                cbTomate.Enabled   = false;
                cbAderezos.Enabled = false;
                cbPicante.Enabled  = false;
                cbJamon.Enabled    = false;
                cbQueso.Enabled    = true;
                cbHuevo.Enabled    = false;
            }
            else if (cmbProductoStock.SelectedValue.ToString() == "Gaseosa 350 cc.")
            {
                cbLechuga.Enabled  = false;
                cbTomate.Enabled   = false;
                cbAderezos.Enabled = false;
                cbPicante.Enabled  = false;
                cbJamon.Enabled    = false;
                cbQueso.Enabled    = false;
                cbHuevo.Enabled    = false;
            }
            else
            {
                cbLechuga.Enabled  = true;
                cbTomate.Enabled   = true;
                cbAderezos.Enabled = true;
                cbPicante.Enabled  = true;
                cbJamon.Enabled    = true;
                cbQueso.Enabled    = true;
                cbHuevo.Enabled    = true;
            }

            ProdActual = new EspecificacionDeProducto();
            ProdActual = Facturacion.BuscarProd(Convert.ToString(cmbProductoStock.Text), ListaProducto);

            if (ProdActual != null)
            {
                txtCodigoProductoFactura.Text      = Convert.ToString(ProdActual.ProdCodigo);
                txtDescripcionProductoFactura.Text = ProdActual.ProdDescripcion;
                nudPrecioProducto.Value            = ProdActual.ProdPrecio;
            }
        }
        //--------------------------------------------------
        //Función para agregar los datos al detalles factura
        public static void AgregarEspecificacionProducto(Formulario formulario,
                                                         EspecificacionDeProducto codiProd,
                                                         int cantidadProd,
                                                         NumericUpDown nudCantidadDetallesFAct,
                                                         EspecificacionDeProducto ProdActual,
                                                         List <LineaDePedido> ListaDetallesFact,
                                                         TextBox txtDescripcionProductoFactura,
                                                         DataGridView dgvGrillaFactura,
                                                         TextBox txtCodigoProductoFactura,
                                                         NumericUpDown nudPrecioProducto,
                                                         List <EspecificacionDeProducto> ListaProducto,
                                                         DataGridView dgvListaProducto,
                                                         bool FactA,
                                                         bool FactB,
                                                         bool FactC,
                                                         TextBox txtIvaFact,
                                                         EspecificacionDeProducto factura,
                                                         TextBox txtSubTotalFactura,
                                                         TextBox txtTOTALFactura)
        {
            //Verifica  si existe un producto en la lista de detalles
            if (ExisteProd(factura, ListaDetallesFact, txtDescripcionProductoFactura))
            {
                //Verifica el stock
                if (nudCantidadDetallesFAct.Value <= ProdActual.ProdStock)
                {
                    foreach (var busc in ListaDetallesFact)
                    {
                        //Verifica que cod de la lista es igual al del producto a agregar, le suma la cantidad y calcula nuevamente el subtotal
                        if (busc.Descripcion == txtDescripcionProductoFactura.Text)
                        {
                            busc.Cantidad       += cantidadProd;
                            busc.SubTotal        = busc.Cantidad * busc.Precio;
                            ProdActual.ProdStock = ProdActual.ProdStock - cantidadProd;
                            FacturaABC(FactA, FactB, FactC, txtIvaFact, ListaDetallesFact, txtSubTotalFactura, txtTOTALFactura);
                        }

                        Facturacion.cargarGrillaFact(formulario, ListaDetallesFact, dgvGrillaFactura);
                    }
                }
                else
                {
                    MessageBox.Show("No hay Stock del producto");
                }
            }
            else
            //Si el producto es nuevo en la lista de detalles
            {
                //Verifica el stock
                if (nudCantidadDetallesFAct.Value <= ProdActual.ProdStock)
                {
                    LineaDePedido ObjDetalle = new LineaDePedido();

                    ObjDetalle.Codigo      = txtCodigoProductoFactura.Text;
                    ObjDetalle.Descripcion = txtDescripcionProductoFactura.Text;
                    ObjDetalle.Precio      = nudPrecioProducto.Value;
                    ObjDetalle.Cantidad    = Convert.ToInt32(nudCantidadDetallesFAct.Value);
                    ObjDetalle.SubTotal    = ObjDetalle.Precio * ObjDetalle.Cantidad;
                    ProdActual.ProdStock   = ProdActual.ProdStock - Convert.ToInt32(nudCantidadDetallesFAct.Value);
                    ListaDetallesFact.Add(ObjDetalle);
                    Facturacion.cargarGrillaFact(formulario, ListaDetallesFact, dgvGrillaFactura);
                    Facturacion.cargargrillaproducto(formulario, ListaProducto, dgvListaProducto);
                }
                else
                {
                    MessageBox.Show("No hay Stock del producto");
                }
            }
        }