예제 #1
0
        public ActionResult AddCategoria(CategoriaDTO dto)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            if (!this.isAdministrator()) { return RedirectToAction("Index"); }

            try
            {
                CategoriaBL objBL = new CategoriaBL();
                if (dto.IdCategoria == 0)
                {
                    if (objBL.add(dto))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("Categorias");
                    }
                }
                else if (dto.IdCategoria != 0)
                {
                    EmpresaBL empBL = new EmpresaBL();
                    int vPeriodo = empBL.getEmpresa(getCurrentUser().IdEmpresa).IdPeriodo.GetValueOrDefault();

                    if (objBL.update(dto, vPeriodo))
                    {
                        createResponseMessage(CONSTANTES.SUCCESS);
                        return RedirectToAction("Categorias");
                    }
                    else
                    {
                        createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                    }

                }
                else
                {
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
                }
            }
            catch (Exception e)
            {
                if (dto.IdCategoria != 0)
                    createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
                else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
            }
            TempData["Categoria"] = dto;
            return RedirectToAction("Categoria");
        }
예제 #2
0
        public ActionResult Categoria(int? id = null, int? idPadre = null)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            if (!this.isAdministrator()) { return RedirectToAction("Index"); }

            ViewBag.Title = "Categoría";

            MenuNavBarSelected(8, 0);
            UsuarioDTO miUsuario = getCurrentUser();
            EmpresaDTO empresa = (new EmpresaBL()).getEmpresa(miUsuario.IdEmpresa);

            CategoriaBL objBL = new CategoriaBL();
            ViewBag.IdCategoria = id;

            ViewBag.Categorias = CategoriasBucle(empresa.IdEmpresa, (int)empresa.IdPeriodo, null, null);

            ViewBag.NombreCategoria = "Sin Categoría";
            var objSent = TempData["Categoria"];
            if (objSent != null) { TempData["Categoria"] = null; return View(objSent); }

            CategoriaDTO obj;
            if (id != null || id == 0)
            {
                if (idPadre != null)
                {
                    CategoriaDTO objp = new CategoriaDTO();

                    objp.IdCategoria = 0;
                    objp.IdCategoriaPadre = idPadre;
                    objp.Orden = objBL.getUltimoHijo(idPadre.GetValueOrDefault());
                    objp.IdEmpresa = miUsuario.IdEmpresa;

                    ViewBag.NombreCategoria = objBL.getNombreCategoria(objp.IdCategoriaPadre.GetValueOrDefault());
                    return View(objp);
                }
                obj = objBL.getCategoria((int)id);
                if (obj == null) return RedirectToAction("Categorias");
                if (obj.IdEmpresa != miUsuario.IdEmpresa) return RedirectToAction("Categorias");

                ViewBag.NombreCategoria = objBL.getNombreCategoria(obj.IdCategoriaPadre.GetValueOrDefault());
                return View(obj);
            }
            obj = new CategoriaDTO();
            obj.IdEmpresa = miUsuario.IdEmpresa;

            return View(obj);
        }
예제 #3
0
        public bool update(CategoriaDTO Categoria, int idPeriodo)
        {
            using (var context = getContext())
            {
                try
                {
                    var datoRow = context.Categoria.Where(x => x.IdCategoria == Categoria.IdCategoria).SingleOrDefault();
                    datoRow.Nombre = Categoria.Nombre;
                    if (Categoria.IdCategoriaPadre != 0 && Categoria.IdCategoriaPadre != null)
                        datoRow.Orden = getUltimoHijo(Categoria.IdCategoriaPadre.GetValueOrDefault());
                    else
                        datoRow.Orden = 1;

                    int pPadreAnterior = datoRow.IdCategoriaPadre.GetValueOrDefault();

                    datoRow.Estado = Categoria.Estado;
                    datoRow.IdCategoriaPadre = Categoria.IdCategoriaPadre;
                    datoRow.IdEmpresa = Categoria.IdEmpresa;
                    context.SaveChanges();

                    //Actualizamos padres
                    if(idPeriodo != 0)
                    {
                        //Actualizamos padre antiguo
                        if (pPadreAnterior != 0) context.SP_ActualizarPresupuestoPadre(pPadreAnterior, idPeriodo);
                        //Actualizamos padre nuevo
                        if (Categoria.IdCategoriaPadre.GetValueOrDefault() != 0) context.SP_ActualizarPresupuestoPadre(Categoria.IdCategoriaPadre, idPeriodo);
                    }
                    return true;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
예제 #4
0
 private static void PintarArbolPadre(CategoriaDTO obj, List<CategoriaDTO> lstCatMontos, EmpresaDTO objEmpresa, System.Data.DataTable dt)
 {
     System.Data.DataRow row = dt.NewRow();
     row["Nivel"] = obj.Nivel;
     row["Partida de Presupuesto"] = obj.Nombre;
     Decimal pMonto = lstCatMontos.SingleOrDefault(x => x.IdCategoria == obj.IdCategoria).Presupuesto.GetValueOrDefault();
     row["MONTO SIN IGV"] = pMonto.ToString("N2", CultureInfo.InvariantCulture);
     row["PRESUPUESTO SIN IGV"] = obj.Presupuesto.GetValueOrDefault().ToString("N2", CultureInfo.InvariantCulture);
     Decimal porcentaje = obj.Presupuesto.GetValueOrDefault() != 0 ? pMonto / obj.Presupuesto.GetValueOrDefault() : 0;
     row["EJECUCION DEL PRESUPUESTO"] = Math.Abs(porcentaje).ToString("P2", CultureInfo.InvariantCulture);
     dt.Rows.Add(row);
     foreach (var hijo in obj.Hijos)
     {
         PintarArbolPadre(hijo, lstCatMontos, objEmpresa, dt);
     }
 }
예제 #5
0
 public bool add(CategoriaDTO Categoria)
 {
     using (var context = getContext())
     {
         try
         {
             Categoria nuevo = new Categoria();
             nuevo.Nombre = Categoria.Nombre;
             if (Categoria.IdCategoriaPadre != 0 && Categoria.IdCategoriaPadre != null)
                 nuevo.Orden = getUltimoHijo(Categoria.IdCategoriaPadre.GetValueOrDefault());
             else
                 nuevo.Orden = 1;
             //nuevo.Orden = Categoria.Orden;
             nuevo.Estado = true;
             nuevo.IdCategoriaPadre = Categoria.IdCategoriaPadre;
             nuevo.IdEmpresa = Categoria.IdEmpresa;
             context.Categoria.Add(nuevo);
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }