Exemplo n.º 1
0
        public ArticuloVenta genera_articulo(objeto_venta articulo)
        {
            var art = new ArticuloVenta
            {
                Codigo             = articulo.Codigo,
                CantidadBuenEstado = articulo.CantidadBuenEstado,
                CantidadDefectuoso = articulo.CantidadDefectuoso,
                Precio             = articulo.PrecioBuenEstado,
                PrecioDefectuoso   = articulo.PrecioDefectuoso,
            };

            return(art);
        }
Exemplo n.º 2
0
        protected void gridProductos_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = Utilerias.StrToInt(gridProductos.DataKeys[e.RowIndex].Value.ToString());

            ArticuloVenta obj = uow.ArticuloVentaBusinessLogic.GetByID(id);



            uow.ArticuloVentaBusinessLogic.Delete(obj);
            uow.SaveChanges();
            BindGridProductosVenta();
            txtCode.Text = string.Empty;
            txtCode.Focus();
        }
Exemplo n.º 3
0
        protected void gridProductos_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string        M           = string.Empty;
            int           idArticulo  = Utilerias.StrToInt(gridProductos.DataKeys[e.RowIndex].Value.ToString());
            ArticuloVenta objArticulo = uow.ArticuloVentaBusinessLogic.GetByID(idArticulo);

            string[] idsProducto = _ProductosVenta.Value.Split('|');

            uow.ArticuloVentaBusinessLogic.Delete(objArticulo);
            uow.SaveChanges();

            //SI HUBO ERORRES AL ELIMINAR REGISTROS PREVIOS
            if (uow.Errors.Count > 0)
            {
                foreach (string m in uow.Errors)
                {
                    M += m;
                }

                //Se muestra el error
                divMsgError.Style.Add("display", "block");
                divMsgSuccess.Style.Add("display", "none");
                lblMsgError.Text = M;

                return;
            }

            _ProductosVenta.Value = string.Empty;

            foreach (string id in idsProducto)
            {
                if (!id.Equals(idArticulo))
                {
                    if (_ProductosVenta.Value.Equals(string.Empty))
                    {
                        _ProductosVenta.Value = id;
                    }
                    else
                    {
                        _ProductosVenta.Value += "|" + id;
                    }
                }
            }

            BindGridProductosVenta();

            OcultarError();
        }
Exemplo n.º 4
0
        private bool ExisteProductoEnVenta(int idProducto)
        {
            string[] ids = _ProductosVenta.Value.Split('|');

            foreach (string id in ids)
            {
                int           idArtVenta = Utilerias.StrToInt(id);
                ArticuloVenta artVenta   = uow.ArticuloVentaBusinessLogic.Get(e => e.Id == idArtVenta && e.ArticuloId == idProducto).FirstOrDefault();

                if (artVenta != null)
                {
                    return(true);
                }
                else
                {
                    continue;
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        protected void gridProductos_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string        M           = string.Empty;
            int           idArticulo  = Utilerias.StrToInt(gridProductos.DataKeys[e.RowIndex].Value.ToString());
            ArticuloVenta objArticulo = uow.ArticuloVentaBusinessLogic.GetByID(idArticulo);
            decimal       subtotal;
            decimal       iva = 0;
            decimal       total;

            int cantidad = Utilerias.StrToInt(((HtmlInputGenericControl)gridProductos.Rows[e.RowIndex].FindControl("txtCantidad")).Value);

            if (cantidad == 0)
            {
                cantidad = 1;
            }

            Articulos artCat = uow.ArticulosBL.GetByID(objArticulo.ArticuloId);

            if (cantidad > artCat.CantidadDisponible)
            {
                //gridProductos.EditIndex = -1;
                //BindGridProductosVenta();
                //return;
                cantidad = artCat.CantidadDisponible;
            }


            subtotal = (cantidad) * (artCat.PrecioVenta);
            total    = (cantidad) * (artCat.PrecioVentaIVA);
            iva      = total - subtotal;

            objArticulo.Cantidad = cantidad;
            objArticulo.SubTotal = subtotal;
            objArticulo.IVA      = iva;
            objArticulo.Total    = total;


            uow.ArticuloVentaBusinessLogic.Update(objArticulo);
            uow.SaveChanges();

            //SI HUBO ERORRES
            if (uow.Errors.Count > 0)
            {
                foreach (string m in uow.Errors)
                {
                    M += m;
                }

                //Se muestra el error
                divMsgError.Style.Add("display", "block");
                divMsgSuccess.Style.Add("display", "none");
                lblMsgError.Text = M;

                return;
            }

            // Cancelamos la edicion del grid
            gridProductos.EditIndex = -1;
            BindGridProductosVenta();
            OcultarError();
        }
Exemplo n.º 6
0
        protected void btnAgregarDeCat_Click(object sender, EventArgs e)
        {
            string cadenaValores = _CadValoresSeleccionados.Value;

            if (cadenaValores.Equals(string.Empty))
            {
                return;
            }

            string[]  ids = cadenaValores.Split('|');
            int       idProducto;
            Articulos articulo;
            string    M      = string.Empty;
            int       idUser = Utilerias.StrToInt(Session["IdUser"].ToString());


            foreach (string id in ids)
            {
                //Se valida que el articulo seleccionado no este agregado ya
                //al grid de las ventas
                idProducto = Utilerias.StrToInt(id);

                articulo = uow.ArticulosBL.GetByID(idProducto);

                if (!_ProductosVenta.Value.Equals(string.Empty))
                {
                    if (ExisteProductoEnVenta(articulo.Id))
                    {
                        continue;
                    }
                }


                ArticuloVenta artVenta = new ArticuloVenta();
                artVenta.ArticuloId    = idProducto;
                artVenta.Cantidad      = 1;
                artVenta.Nombre        = articulo.NombreCompleto;
                artVenta.PrecioCompra  = articulo.PrecioCompraIVA;
                artVenta.PrecioVenta   = articulo.PrecioVentaIVA;
                artVenta.EsMedicamento = articulo.esMedicamento;
                artVenta.UsuarioId     = idUser;

                artVenta.SubTotal = articulo.PrecioVenta;
                artVenta.IVA      = articulo.PrecioVentaIVA - articulo.PrecioVenta;
                artVenta.Total    = articulo.PrecioVentaIVA;

                uow.ArticuloVentaBusinessLogic.Insert(artVenta);
                uow.SaveChanges();

                //SI HUBO ERORRES
                if (uow.Errors.Count > 0)
                {
                    foreach (string m in uow.Errors)
                    {
                        M += m;
                    }

                    //Se muestra el error

                    divMsgError.Style.Add("display", "block");
                    divMsgSuccess.Style.Add("display", "none");
                    lblMsgError.Text = M;
                    return;
                }

                if (_ProductosVenta.Value == string.Empty)
                {
                    _ProductosVenta.Value = artVenta.Id.ToString();
                }
                else
                {
                    _ProductosVenta.Value += "|" + artVenta.Id.ToString();
                }
            }

            _CadValoresSeleccionados.Value = string.Empty;

            BindGridProductosVenta();

            OcultarError();

            //if (_SeleccionoDeReceta.Value.Equals("S"))
            //    divGridRecetas.Style.Add("display", "none"); //Se oculta el div de las recetas
            //else
            //    divGridRecetas.Style.Add("display", "block");



            DIVacordeon.Style.Add("display", "none");
            DIVlinkAdd.Style.Add("display", "block");
        }
Exemplo n.º 7
0
        protected void btnAgregar_Click(object sender, EventArgs e)
        {
            Articulos articulo;
            string    M = string.Empty;
            int       idArticulo;
            int       idUser = Utilerias.StrToInt(Session["IdUser"].ToString());

            int idReceta = Utilerias.StrToInt(_IDReceta.Value);

            foreach (ListItem item in checkProductos.Items)
            {
                if (item.Selected)
                {
                    //ddlProductosVenta.Items.Add(new ListItem("Descripcion", item.Value));

                    idArticulo = Utilerias.StrToInt(item.Value);
                    articulo   = uow.ArticulosBL.GetByID(idArticulo);

                    if (!_ProductosVenta.Value.Equals(string.Empty))
                    {
                        if (ExisteProductoEnVenta(articulo.Id))
                        {
                            continue;
                        }
                    }

                    ArticuloVenta artVenta = new ArticuloVenta();
                    artVenta.ArticuloId    = idArticulo;
                    artVenta.Cantidad      = 1;
                    artVenta.Nombre        = articulo.NombreCompleto;
                    artVenta.PrecioCompra  = articulo.PrecioCompraIVA;
                    artVenta.PrecioVenta   = articulo.PrecioVentaIVA;
                    artVenta.EsMedicamento = articulo.esMedicamento;
                    artVenta.RecetaId      = idReceta;
                    artVenta.UsuarioId     = idUser;

                    artVenta.SubTotal = articulo.PrecioVenta;
                    artVenta.IVA      = articulo.PrecioVentaIVA - articulo.PrecioVenta;
                    artVenta.Total    = articulo.PrecioVentaIVA;

                    uow.ArticuloVentaBusinessLogic.Insert(artVenta);
                    uow.SaveChanges();

                    //SI HUBO ERORRES
                    if (uow.Errors.Count > 0)
                    {
                        foreach (string m in uow.Errors)
                        {
                            M += m;
                        }

                        //Se muestra el mensaje de error
                        divMsgError.Style.Add("display", "block");
                        divMsgSuccess.Style.Add("display", "none");
                        lblMsgError.Text = M;

                        return;
                    }

                    if (_ProductosVenta.Value == string.Empty)
                    {
                        _ProductosVenta.Value = artVenta.Id.ToString();
                    }
                    else
                    {
                        _ProductosVenta.Value += "|" + artVenta.Id.ToString();
                    }

                    _SeleccionoDeReceta.Value = "S";
                }
                else
                {
                    _SeleccionoDeReceta.Value = "N";
                }
            }

            if (checkProductos.Items.Count == 0)
            {
                _IDReceta.Value = string.Empty;
            }

            BindGridProductosVenta();

            OcultarError();
        }
Exemplo n.º 8
0
        protected void BtnBuscar_Click(object sender, EventArgs e)
        {
            int idUser = Utilerias.StrToInt(Session["IdUser"].ToString());
            int idProducto;

            List <Articulos> lista = uow.ArticulosBL.Get(p => p.Clave == txtCode.Text).ToList();


            idProducto = 0;
            foreach (Articulos item in lista)
            {
                idProducto = item.Id;
            }


            if (idProducto == 0)
            {
                txtCode.Text = string.Empty;
                txtCode.Focus();
                return;
            }


            ArticuloVenta obj;


            List <ArticuloVenta> listArticulos = uow.ArticuloVentaBusinessLogic.Get(p => p.UsuarioId == idUser && p.ArticuloId == idProducto).ToList();
            Articulos            articulo      = uow.ArticulosBL.GetByID(idProducto);
            int idAV = 0;

            if (listArticulos.Count == 0)
            {
                if (articulo.CantidadEnAlmacen > 0)
                {
                    obj               = new ArticuloVenta();
                    obj.UsuarioId     = idUser;
                    obj.ArticuloId    = idProducto;
                    obj.Nombre        = articulo.NombreCompleto;
                    obj.Cantidad      = 1;
                    obj.EsMedicamento = articulo.esMedicamento;
                    obj.PrecioCompra  = articulo.PrecioCompraIVA;
                    obj.PrecioVenta   = articulo.PrecioVentaIVA;


                    obj.SubTotal = articulo.PrecioVenta;
                    obj.IVA      = articulo.PrecioVentaIVA - articulo.PrecioVenta;
                    obj.Total    = articulo.PrecioVentaIVA;

                    uow.ArticuloVentaBusinessLogic.Insert(obj);
                    uow.SaveChanges();
                }
            }
            else
            {
                foreach (ArticuloVenta item in listArticulos)
                {
                    idAV = item.Id;
                }

                ArticuloVenta articuloventa = uow.ArticuloVentaBusinessLogic.GetByID(idAV);

                decimal subtotal = 0;
                decimal iva      = 0;
                decimal total    = 0;
                int     cantidad = articuloventa.Cantidad;

                if (articulo.CantidadEnAlmacen > cantidad)
                {
                    cantidad++;

                    subtotal = (cantidad) * (articulo.PrecioVenta);
                    total    = (cantidad) * (articulo.PrecioVentaIVA);
                    iva      = total - subtotal;

                    articuloventa.Cantidad = cantidad;
                    articuloventa.SubTotal = subtotal;
                    articuloventa.IVA      = iva;
                    articuloventa.Total    = total;


                    uow.ArticuloVentaBusinessLogic.Update(articuloventa);
                    uow.SaveChanges();
                }
            }


            divMsgError.Style.Add("display", "none");

            BindGridProductosVenta();
            txtCode.Text = string.Empty;
            txtCode.Focus();
        }