public string getNombreCategoria(int id) { if(id != 0) { CategoriaBL oBL = new CategoriaBL(); return oBL.getCategoria(id).Nombre; } return "Sin Categoría"; }
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); }
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"); }
public ActionResult Categorias() { if (!this.currentUser()) { return RedirectToAction("Ingresar"); } if (!isAdministrator()) { return RedirectToAction("Index"); } ViewBag.Title = "Partidas de Presupuesto"; MenuNavBarSelected(8, 0); EmpresaBL empBL = new EmpresaBL(); UsuarioDTO miUsuario = getCurrentUser(); EmpresaDTO empresa = empBL.getEmpresa(miUsuario.IdEmpresa); ViewBag.IdPeriodo = empresa.IdPeriodo.GetValueOrDefault(); ViewBag.SimboloMoneda = empresa.SimboloMoneda; CategoriaBL objBL = new CategoriaBL(); ViewBag.Periodos = objBL.GetPeriodosEnEmpresaViewBag(miUsuario.IdEmpresa); List<CategoriaDTO> listaCategorias = new List<CategoriaDTO>(); if (empresa.IdEmpresa > 0 && empresa.IdPeriodo > 0) { //listaCategorias = objBL.getCategoriasPorPeriodo_ArbolEnEmpresa(empresa.IdEmpresa, (int)empresa.IdPeriodo); listaCategorias = objBL.getCategoriasTreeEnEmpresa(empresa.IdEmpresa); } return View(listaCategorias); }
public ActionResult GenerarRep_AvanceDePresupuesto(DateTime FechaInicio, DateTime FechaFin, int periodo) { if (FechaInicio == null || FechaFin == null) { return RedirectToAction("ReportesPresupuestos", new { message = 1 }); } EmpresaDTO objEmpresa = (new EmpresaBL()).getEmpresa(getCurrentUser().IdEmpresa); PeriodoDTO objPeriodo = (new PeriodoBL()).getPeriodoEnEmpresa(objEmpresa.IdEmpresa, periodo); ReportesBL repBL = new ReportesBL(); List<CategoriaDTO> lstCatsMontos = repBL.AvanceDePresupuesto(objEmpresa.IdEmpresa, FechaInicio, FechaFin); //Sumatoria de Presupuestos de Padres y armado de Arbol List<CategoriaDTO> lstCats = repBL.getCategoriasTreeEnEmpresa(lstCatsMontos, objEmpresa.IdEmpresa); //Arbol de presupuestos CategoriaBL catBL = new CategoriaBL(); //List<CategoriaDTO> arbolPresupuestos = repBL.getCategoriasPresupuestosTreeEnEmpresa(objEmpresa.IdEmpresa, 0); List<CategoriaDTO> arbolPresupuestos = repBL.getCategoriasPresupuestosTree_PorPeriodo_EnEmpresa(objEmpresa.IdEmpresa, 0, periodo); if (lstCats == null) return RedirectToAction("ReportesPresupuestos", new { message = 2 }); System.Data.DataTable dt = new System.Data.DataTable(); dt.Clear(); dt.Columns.Add("Nivel"); dt.Columns.Add("Partida de Presupuesto"); dt.Columns.Add("MONTO SIN IGV"); dt.Columns.Add("PRESUPUESTO SIN IGV"); dt.Columns.Add("EJECUCION DEL PRESUPUESTO"); //Suma de Padres de Nivel 0 //Decimal SumaPadres0 = lstCatsMontos.Where(x => x.IdCategoriaPadre == null).Sum(x => x.Presupuesto.GetValueOrDefault()); //Decimal SumaPresupuesto = arbolPresupuestos.Sum(x => x.Presupuesto.GetValueOrDefault()); /*System.Data.DataRow auxRow = dt.NewRow(); auxRow[0] = ""; auxRow[1] = ""; auxRow[2] = SumaPadres0.ToString("N2", CultureInfo.InvariantCulture); auxRow[3] = SumaPresupuesto.ToString("N2", CultureInfo.InvariantCulture); auxRow[4] = (SumaPresupuesto == 0) ? "0.00%" : (SumaPresupuesto / SumaPresupuesto).ToString("P2", CultureInfo.InvariantCulture); dt.Rows.Add(auxRow);*/ foreach (var obj in arbolPresupuestos) { PintarArbolPadre(obj, lstCatsMontos, objEmpresa, dt); } GridView gv = new GridView(); gv.DataSource = dt; gv.AllowPaging = false; gv.DataBind(); if (dt.Rows.Count > 0) { PintarCabeceraTabla(gv); //PintarIntercaladoCategorias(gv); AddSuperHeader(gv, "Ejecucion de Presupuesto - Empresa:" + objEmpresa.Nombre); //Cabecera principal //AddWhiteHeader(gv, 1, ""); AddWhiteHeader(gv, 1, "FECHAS: " + FechaInicio.ToShortDateString() + " - " + FechaFin.ToShortDateString()); AddWhiteHeader(gv, 2, "PERIODO: " + objPeriodo.Nombre + " (" + objPeriodo.FechaInicio.ToShortDateString() + " - " + objPeriodo.FechaFin.ToShortDateString() + ")"); AddWhiteHeader(gv, 3, "MONEDA: (" + objEmpresa.SimboloMoneda + ")"); PintarCategorias(gv); Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment; filename=" + "EjecucionDePresupuesto_" + objEmpresa.Nombre + "_" + DateTime.Now.ToString("dd-MM-yyyy") + ".xls"); Response.ContentType = "application/ms-excel"; Response.Charset = ""; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gv.RenderControl(htw); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); htw.Close(); sw.Close(); } return RedirectToAction("ReportesPresupuestos", new { message = 2 }); }
public List<Select2DTO> CategoriasBucle(int idEmpresa, int idPeriodo, int? id = null, IList<CategoriaDTO> lista = null) { var listaCat = lista; if (id == null && lista == null) { CategoriaBL objBL = new CategoriaBL(); listaCat = objBL.getCategoriasTreeEnEmpresa(getCurrentUser().IdEmpresa); //listaCat = objBL.getCategoriasPorPeriodo_ArbolEnEmpresa(idEmpresa, idPeriodo); } List<Select2DTO> selectTree = new List<Select2DTO>(); foreach (var item in listaCat) { if (item.Estado) { Select2DTO selectItem = new Select2DTO(); selectItem.id = item.IdCategoria; selectItem.text = item.Nombre; if (item.Hijos != null && item.Hijos.Count > 0) { selectItem.children = CategoriasBucle(idEmpresa, idPeriodo, item.IdCategoria, item.Hijos); } selectTree.Add(selectItem); } } return selectTree; }
public JsonResult ActualizarPresupuesto(int idCategoria, Decimal Monto) { if (!this.currentUser() || !isAdministrator()) { return Json(false, JsonRequestBehavior.AllowGet); } CategoriaBL objBL = new CategoriaBL(); EmpresaBL empBL = new EmpresaBL(); int pPeriodo = empBL.getEmpresa(getCurrentUser().IdEmpresa).IdPeriodo.GetValueOrDefault(); if (pPeriodo == 0) { return Json(false, JsonRequestBehavior.AllowGet); } CategoriaPorPeriodoDTO dto = new CategoriaPorPeriodoDTO() { IdCategoria = idCategoria, IdPeriodo = pPeriodo, Monto = Monto }; objBL.updatePresupuesto(dto); return Json(true, JsonRequestBehavior.AllowGet); }
public JsonResult CategoriasJson() { EmpresaDTO empresa = (new EmpresaBL()).getEmpresa(getCurrentUser().IdEmpresa); CategoriaBL objBL = new CategoriaBL(); var listaCat = CategoriasBucle(empresa.IdEmpresa, (int)empresa.IdPeriodo, null, null); return Json(new { listaCat }, JsonRequestBehavior.AllowGet); }