protected void btnRegistrar_Click(object sender, EventArgs e)
        {
            var               almacen    = ddlAlmacen.SelectedItem.Value;
            var               producto   = ddlProducto.SelectedItem.Value;
            var               movimiento = ddlMovimiento.SelectedItem.Value;
            DateTime          fechact    = DateTime.Now;
            ControllerAlmacen ctrlAlm    = new ControllerAlmacen();
            CultureInfo       culture    = new CultureInfo("en-US");

            var cantidadExistente = (from existe in contexto.tblStock
                                     where existe.fkProducto == Int32.Parse(producto)
                                     select existe);

            var actualizar = 1;

            foreach (tblStock ord in cantidadExistente)
            {
                actualizar += 1;
                var suma = decimal.Parse(txtCantidad.Text, culture) + ord.dblCantidad;

                tblMovimiento mov = new tblMovimiento();
                mov.strTipo    = movimiento;
                mov.fecha      = fechact;
                mov.dblValAnt  = ord.dblCantidad;
                mov.dblValNvo  = suma;
                mov.fkStock    = ord.idStock;
                mov.fkEmpleado = Int32.Parse(lbEmpleado.Text);

                ord.dblCantidad = suma;

                ctrlAlm.InsertarMovimientoAlmacen(mov);
                contexto.SubmitChanges();
                this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "exito()", true);
                this.LimpiarCampos();
            }
            if (actualizar == 1)
            {
                tblStock stock = new tblStock();
                stock.dblCantidad = decimal.Parse(txtCantidad.Text, culture);
                stock.fkProducto  = Int32.Parse(producto);
                ctrlAlm.InsertarEntradaAlmacen(stock);

                tblMovimiento mov = new tblMovimiento();
                mov.strTipo    = movimiento;
                mov.fecha      = fechact;
                mov.dblValAnt  = 0;
                mov.dblValNvo  = Int32.Parse(txtCantidad.Text);
                mov.fkStock    = stock.idStock;
                mov.fkEmpleado = Int32.Parse(lbEmpleado.Text);

                ctrlAlm.InsertarMovimientoAlmacen(mov);
                this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "exito()", true);
                this.LimpiarCampos();
            }
        }
        protected void btnRegistrar_Click(object sender, EventArgs e)
        {
            var               almacen    = ddlAlmacen.SelectedItem.Value;
            var               producto   = ddlProducto.SelectedItem.Value;
            var               movimiento = ddlMovimiento.SelectedItem.Value;
            DateTime          fechact    = DateTime.Now;
            ControllerAlmacen ctrlAlm    = new ControllerAlmacen();
            CultureInfo       culture    = new CultureInfo("en-US");

            var cantidadExistente = (from existe in contexto.tblStock
                                     where existe.fkProducto == Int32.Parse(producto)
                                     select existe);

            var existente = (from existe in contexto.tblStock
                             where existe.fkProducto == Int32.Parse(producto)
                             select existe).FirstOrDefault();


            if (existente == null)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "fallo()", true);
            }
            else
            {
                foreach (tblStock ord in cantidadExistente)
                {
                    var resta = ord.dblCantidad - decimal.Parse(txtCantidad.Text, culture);

                    if (resta >= 0)
                    {
                        tblMovimiento mov = new tblMovimiento();
                        mov.strTipo    = movimiento;
                        mov.fecha      = fechact;
                        mov.dblValAnt  = ord.dblCantidad;
                        mov.dblValNvo  = resta;
                        mov.fkStock    = ord.idStock;
                        mov.fkEmpleado = Int32.Parse(lbEmpleado.Text);
                        mov.strNumVen  = txtOrdenCompra.Text;
                        mov.strFactura = txtFactura.Text;

                        ctrlAlm.InsertarMovimientoAlmacen(mov);
                        ord.dblCantidad = resta;
                        contexto.SubmitChanges();
                        this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "exito()", true);
                        this.LimpiarCampos();
                    }
                    else
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "alerta()", true);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public bool InsertarMovimientoAlmacen(tblMovimiento _TBL_Movimiento)
        {
            bool respuesta = false;

            try
            {
                contexto.tblMovimiento.InsertOnSubmit(_TBL_Movimiento);
                contexto.SubmitChanges();
                respuesta = true;
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
                respuesta = false;
            }
            return(respuesta);
        }
        protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
        {
            string cod;

            if (e.CommandName == "Seleccionar")
            {
                DataList2.SelectedIndex = e.Item.ItemIndex;

                cod = ((Label)this.DataList2.SelectedItem.FindControl("idVentaLabel")).Text;
                Session["desgloce_req_alm"] = cod;

                Response.Redirect("/Almacen/DesgloceRequisicionAlmacen.aspx");
            }

            else if (e.CommandName == "Finalizar")
            {
                string confirmValue = Request.Form["confirm_value"];

                if (confirmValue == "Si")
                {
                    ControllerAlmacen ctrlAlm = new ControllerAlmacen();
                    tblVenta          ven     = new tblVenta();
                    DateTime          fechact = DateTime.Now;

                    DataList2.SelectedIndex = e.Item.ItemIndex;

                    cod = ((Label)this.DataList2.SelectedItem.FindControl("idVentaLabel")).Text;

                    var Productos = (from prod in contexto.tblDetalleVenta
                                     where prod.fkVenta == Int32.Parse(cod)
                                     select prod);

                    foreach (tblDetalleVenta det in Productos)
                    {
                        var cantidadExistente = (from existe in contexto.tblStock
                                                 where existe.fkProducto == det.fkProducto
                                                 select existe);

                        var existente = (from existe in contexto.tblStock
                                         where existe.fkProducto == det.fkProducto
                                         select existe).FirstOrDefault();


                        if (existente == null)
                        {
                            Response.Redirect("/Almacen/AlertaFallo.aspx");
                        }
                        else
                        {
                            foreach (tblStock ord in cantidadExistente)
                            {
                                var resta = ord.dblCantidad - det.intCantidad;

                                if (resta >= 0)
                                {
                                    tblMovimiento mov = new tblMovimiento();
                                    mov.strTipo    = "VENTA NUMERO " + cod;
                                    mov.fecha      = fechact;
                                    mov.dblValAnt  = ord.dblCantidad;
                                    mov.dblValNvo  = resta;
                                    mov.fkStock    = ord.idStock;
                                    mov.fkEmpleado = Int32.Parse(lbEmpleado.Text);
                                    mov.strNumVen  = cod;
                                    mov.strFactura = "";

                                    ctrlAlm.InsertarMovimientoAlmacen(mov);
                                    ord.dblCantidad = resta;
                                    contexto.SubmitChanges();
                                    ven.idVenta   = Convert.ToInt32(cod);
                                    ven.strEstado = "FINALIZADO";

                                    ctrlAlm.EditarFinalizado(ven);
                                    Response.Redirect("/Almacen/AlertaExito.aspx");
                                }
                                else
                                {
                                    Response.Redirect("/Almacen/AlertaAlerta.aspx");
                                }
                            }
                        }
                    }
                }
            }

            else if (e.CommandName == "Pendiente")
            {
                string confirmValue = Request.Form["confirm_value"];

                if (confirmValue == "Si")
                {
                    ControllerAlmacen ctrlAlm = new ControllerAlmacen();
                    tblVenta          ven     = new tblVenta();

                    DataList2.SelectedIndex = e.Item.ItemIndex;

                    cod           = ((Label)this.DataList2.SelectedItem.FindControl("idVentaLabel")).Text;
                    ven.idVenta   = Convert.ToInt32(cod);
                    ven.strEstado = "PENDIENTE";

                    ctrlAlm.EditarPendiente(ven);
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Se regreso a estado PENDIENTE la requisición')", true);
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Se cancelo la finalización de la requisición')", true);
                }
            }

            Response.Redirect("/Almacen/RequisicionAlmacen.aspx");
        }
Ejemplo n.º 5
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            var         vacio   = 0.0000;
            CultureInfo culture = new CultureInfo("en-US");

            this.Calcular();

            //Advertencia si el campo no se a calculado correctamente
            if (double.Parse(lblTotal2.Text) == vacio)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "fallo()", true);
                this.Calcular();
            }

            //Advertencia si hay campos vacios de dinero, hora y fecha.
            else if (string.IsNullOrWhiteSpace(txtDinero.Text) ||
                     string.IsNullOrWhiteSpace(txtHora.Text) ||
                     string.IsNullOrWhiteSpace(fechaEntrega.Text))
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "vacio()", true);
                this.Calcular();
            }

            //Advertencia si el dinero no es el suficiente para liquidar la cuenta
            else if (double.Parse(txtDinero.Text, culture) >= double.Parse(lblTotal2.Text, culture))
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "fallo()", true);
                this.Calcular();
            }


            else
            {
                DateTime          fechact = DateTime.Now;
                ControllerCliente ctrlCli = new ControllerCliente();
                var      CanStock         = 0;
                tblVenta ven     = new tblVenta();
                var      ExStock = 0;

                //Si cae en que el cliente es mostrador significa que la venta
                //se esta realizando al momento y eso va a afectar en el descuento del inventario
                if ((Session["cliente"].ToString() == "MOSTRADOR"))
                {
                    foreach (GridViewRow row in GridView1.Rows)
                    {
                        var existente = (from existe in contexto.tblStock
                                         where existe.fkProducto == int.Parse(row.Cells[1].Text)
                                         select existe).FirstOrDefault();

                        var cantidadExistente = (from existe in contexto.tblStock
                                                 where existe.fkProducto == int.Parse(row.Cells[1].Text)
                                                 select existe);

                        //Si cae aqui significa que no hay un historial en stock
                        if (existente == null)
                        {
                            CanStock++;
                        }
                        else
                        {
                            foreach (tblStock ord in cantidadExistente)
                            {
                                //Aqui se hace la resta de la catidad solicitada menos lo que esxita en stock
                                var resta = ord.dblCantidad - int.Parse(((TextBox)row.Cells[3].FindControl("TextBox1")).Text);

                                if (resta >= 0)
                                {
                                }
                                else
                                {
                                    ExStock++;
                                }
                            }
                        }
                    }
                    //Alertas en caso de que haya caido en las validaciones anteriores
                    if (CanStock > 0)
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "falloCantidad()", true);
                    }
                    //Alertas en caso de que haya caido en las validaciones anteriores
                    else if (ExStock > 0)
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "alerta()", true);
                    }

                    else
                    {
                        ven.Fecha    = fechact;
                        ven.dblTotal = decimal.Parse(lblTotal2.Text, culture);
                        //ven.dblSubTotal = decimal.Parse(lblSubTotal.Text);
                        //ven.dblIGV = decimal.Parse(lblIGV.Text);
                        ven.strEstado      = "FINALIZADO";
                        ven.dblAbono       = decimal.Parse(txtDinero.Text, culture);;
                        ven.dblInteres     = null;
                        ven.strFechaEntega = fechaEntrega.Text;
                        ven.strHoraEntega  = txtHora.Text;
                        ven.fkCliente      = null;
                        ctrlCli.InsertarVenta(ven);

                        foreach (GridViewRow row in GridView1.Rows)
                        {
                            var cantidadExistente = (from existe in contexto.tblStock
                                                     where existe.fkProducto == int.Parse(row.Cells[1].Text)
                                                     select existe);

                            foreach (tblStock ord in cantidadExistente)
                            {
                                var resta = ord.dblCantidad - int.Parse(((TextBox)row.Cells[3].FindControl("TextBox1")).Text);

                                ControllerAlmacen ctrlAlm = new ControllerAlmacen();
                                tblMovimiento     mov     = new tblMovimiento();
                                mov.strTipo    = "VENTA NUMERO " + ven.idVenta;
                                mov.fecha      = fechact;
                                mov.dblValAnt  = ord.dblCantidad;
                                mov.dblValNvo  = resta;
                                mov.fkStock    = ord.idStock;
                                mov.fkEmpleado = Int32.Parse(Session["id"].ToString());
                                mov.strNumVen  = ven.idVenta.ToString();
                                mov.strFactura = "";

                                ctrlAlm.InsertarMovimientoAlmacen(mov);
                                ord.dblCantidad = resta;
                                contexto.SubmitChanges();
                            }


                            ControllerCliente ctrlClie = new ControllerCliente();
                            tblDetalleVenta   detalle  = new tblDetalleVenta();
                            detalle.Fecha       = fechact;
                            detalle.intCantidad = int.Parse(((TextBox)row.Cells[3].FindControl("TextBox1")).Text);
                            detalle.fkProducto  = int.Parse(row.Cells[1].Text);
                            detalle.dblPrecio   = decimal.Parse(((TextBox)row.Cells[4].FindControl("TextBox2")).Text, culture);
                            detalle.fkVenta     = ven.idVenta;
                            detalle.fkEmpleado  = int.Parse(Session["id"].ToString());
                            ctrlClie.InsertarDetalle(detalle);
                        }
                        Session["contado"] = null;
                        this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "exito()", true);
                    }
                }
                else
                {
                    ven.Fecha    = fechact;
                    ven.dblTotal = decimal.Parse(lblTotal2.Text);
                    //ven.dblSubTotal = decimal.Parse(lblSubTotal.Text);
                    //ven.dblIGV = decimal.Parse(lblIGV.Text);
                    ven.strEstado      = "PENDIENTE";
                    ven.dblAbono       = decimal.Parse(txtDinero.Text, culture);;
                    ven.dblInteres     = null;
                    ven.strFechaEntega = fechaEntrega.Text;
                    ven.strHoraEntega  = txtHora.Text;
                    ven.fkCliente      = int.Parse(Session["cliente"].ToString());
                    ctrlCli.InsertarVenta(ven);

                    foreach (GridViewRow row in GridView1.Rows)
                    {
                        ControllerCliente ctrlClie = new ControllerCliente();
                        tblDetalleVenta   detalle  = new tblDetalleVenta();
                        detalle.Fecha       = fechact;
                        detalle.intCantidad = int.Parse(((TextBox)row.Cells[3].FindControl("TextBox1")).Text);
                        detalle.fkProducto  = int.Parse(row.Cells[1].Text);
                        detalle.dblPrecio   = decimal.Parse(((TextBox)row.Cells[4].FindControl("TextBox2")).Text, culture);
                        detalle.fkVenta     = ven.idVenta;
                        detalle.fkEmpleado  = int.Parse(Session["id"].ToString());
                        ctrlClie.InsertarDetalle(detalle);
                    }
                    Session["contado"] = null;
                    this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "exito()", true);
                }

                this.Limpiar();
            }
        }