Example #1
0
        public ActionResult AddMovimientoInv(MovimientoInvDTO dto)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            if (getCurrentUser().IdRol == 4) { return RedirectToAction("MovimientoInvs", "Admin"); }
            try
            {
                string sTipoMovimientoInv = dto.IdTipoMovimientoInv == 1 ? "Ingreso" : "Egreso";

                MovimientoInvBL objBL = new MovimientoInvBL();
                if (dto.IdMovimientoInv == 0)
                {
                    //Verificar que el stock no sea negativo
                    if(dto.IdTipoMovimientoInv == 2)
                    {
                        int sumaLote = objBL.get_Stock_De_Lote_En_Empresa(dto.IdEmpresa, dto.SerieLote) + (dto.Cantidad * -1);
                        if (sumaLote < 0)
                        {
                            createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_ITEMS_LIMIT);
                            return RedirectToAction("Inventarios" + sTipoMovimientoInv, "Admin");
                        }
                        else if (objBL.add(dto))
                        {
                            createResponseMessage(CONSTANTES.SUCCESS);
                            return RedirectToAction("Inventarios" + sTipoMovimientoInv, "Admin");
                        }
                    } else if (objBL.add(dto))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("Inventarios" + sTipoMovimientoInv, "Admin");
                    }
                }
                else if (dto.IdMovimientoInv != 0)
                {
                    if (dto.IdTipoMovimientoInv == 2)
                    {
                        int sumaLote = objBL.get_Stock_De_Lote_En_Empresa(dto.IdEmpresa, dto.SerieLote) + (dto.Cantidad * -1);
                        if (sumaLote < 0)
                        {
                            createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_ITEMS_LIMIT);
                            return RedirectToAction("Inventarios" + sTipoMovimientoInv, "Admin");
                        }
                        else if (objBL.update(dto))
                        {
                            createResponseMessage(CONSTANTES.SUCCESS);
                            return RedirectToAction("Inventarios" + sTipoMovimientoInv, "Admin");
                        }
                    } else if (objBL.update(dto))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("Inventarios" + sTipoMovimientoInv, "Admin");
                    }
                    else
                    {
                        createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                    }

                }
                else
                {
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
                }
            }
            catch (Exception e)
            {
                if (dto.IdMovimientoInv != 0)
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
            }
            TempData["MovimientoInv"] = dto;
            return RedirectToAction("MovimientoInv");
        }
Example #2
0
 public bool update(MovimientoInvDTO MovimientoInv)
 {
     using (var context = getContext())
     {
         try
         {
             var row = context.MovimientoInv.Where(x => x.IdMovimientoInv == MovimientoInv.IdMovimientoInv).SingleOrDefault();
             row.IdFormaMovimientoInv = MovimientoInv.IdFormaMovimientoInv;
             row.IdItem = MovimientoInv.IdItem;
             row.IdEntidadResponsable = MovimientoInv.IdEntidadResponsable;
             row.IdUbicacion = MovimientoInv.IdUbicacion;
             row.NroDocumento = MovimientoInv.NroDocumento;
             row.GuiaRemision = MovimientoInv.GuiaRemision;
             row.SerieLote = MovimientoInv.SerieLote;
             row.Cantidad = MovimientoInv.Cantidad;
             row.UnidadMedida = MovimientoInv.UnidadMedida;
             row.FechaInicial = MovimientoInv.FechaInicial;
             row.FechaFin = MovimientoInv.FechaFin;
             row.Comentario = MovimientoInv.Comentario;
             row.Estado = MovimientoInv.Estado;
             row.UsuarioCreacion = MovimientoInv.UsuarioCreacion;
             row.IdEmpresa = MovimientoInv.IdEmpresa;
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Example #3
0
        public ActionResult MovimientoInv(int? id = null, int? idTipo = null)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            ViewBag.Title = "Movimiento de Inventario";

            int tipo = 1;
            if (idTipo != null) { tipo = idTipo.GetValueOrDefault(); }
            MenuNavBarSelected(9, tipo - 1);

            UsuarioDTO user = getCurrentUser();

            MovimientoInvBL objBL = new MovimientoInvBL();

            ViewBag.lstTipoMovimientoInv = objBL.getTipoMovimientoInv();
            ViewBag.lstFormaMovimiento = objBL.getFormaMovimientoInvPorTipo(tipo);
            //ViewBag.lstItems = objBL.getItemsEnEmpresa(user.IdEmpresa);
            ViewBag.lstItems = objBL.getItemsEnEmpresa_PorTipoMov(user.IdEmpresa, (int)idTipo);
            ViewBag.lstProveedores = objBL.getProveedoresEnEmpresa(user.IdEmpresa);
            //Lotes de salida Lista
            ViewBag.lstLotes = objBL.getLotesEnEmpresa(user.IdEmpresa);
            //Ubicaciones
            ViewBag.lstUbicaciones = objBL.getUbicacionesEnEmpresa(user.IdEmpresa);

            var objSent = TempData["MovimientoInv"];
            if (objSent != null) { TempData["MovimientoInv"] = null; return View(objSent); }

            MovimientoInvDTO obj;
            if (id != null && id != 0)
            {
                obj = objBL.getMovimientoInvEnEmpresa((int)user.IdEmpresa, (int)id);
                if (obj == null) return RedirectToAction("MovimientoInvs");
                if (obj.IdEmpresa != user.IdEmpresa) return RedirectToAction("MovimientoInvs");
                obj.UsuarioCreacion = user.IdUsuario;

                //lstLotes.Add(new Select2DTO_B() { text = obj.SerieLote });
                ViewBag.lstLotes = objBL.getLotesEnEmpresa(user.IdEmpresa, obj.IdItem, obj.SerieLote);
                
                if (idTipo.GetValueOrDefault() == 1) { ViewBag.lstUbicaciones = objBL.getUbicacionesEnEmpresa(user.IdEmpresa); }
                else if (idTipo.GetValueOrDefault() == 2) { ViewBag.lstUbicaciones = objBL.getUbicacionesEnEmpresa(user.IdEmpresa, obj.SerieLote); }

                return View(obj);
            }
            obj = new MovimientoInvDTO();
            obj.IdTipoMovimientoInv = tipo;
            obj.IdEmpresa = user.IdEmpresa;
            obj.UsuarioCreacion = user.IdUsuario;
            obj.FechaInicial = DateTime.Now;

            //if (idTipo.GetValueOrDefault() == 1) { ViewBag.lstUbicaciones = objBL.getUbicacionesEnEmpresa(user.IdEmpresa); }
            //else if (idTipo.GetValueOrDefault() == 2) { ViewBag.lstUbicaciones = new List<Select2DTO_B>(); }

            return View(obj);
        }
Example #4
0
 public bool add(MovimientoInvDTO MovimientoInv)
 {
     using (var context = getContext())
     {
         try
         {
             MovimientoInv nuevo = new MovimientoInv();
             nuevo.IdFormaMovimientoInv = MovimientoInv.IdFormaMovimientoInv;
             nuevo.IdItem = MovimientoInv.IdItem;
             nuevo.IdEntidadResponsable = MovimientoInv.IdEntidadResponsable;
             nuevo.IdUbicacion = MovimientoInv.IdUbicacion;
             nuevo.NroDocumento = MovimientoInv.NroDocumento;
             nuevo.GuiaRemision = MovimientoInv.GuiaRemision;
             nuevo.SerieLote = MovimientoInv.SerieLote;
             nuevo.Cantidad = MovimientoInv.Cantidad;
             nuevo.UnidadMedida = MovimientoInv.UnidadMedida;
             nuevo.FechaInicial = MovimientoInv.FechaInicial;
             nuevo.FechaFin = MovimientoInv.FechaFin;
             nuevo.Comentario = MovimientoInv.Comentario;
             nuevo.Estado = true;
             nuevo.UsuarioCreacion = MovimientoInv.UsuarioCreacion;
             nuevo.IdEmpresa = MovimientoInv.IdEmpresa;
             context.MovimientoInv.Add(nuevo);
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }