public LAScopeViewModel() { rbu = string.Empty; smo = string.Empty; BUList = new List <SelectListItem>(); SMOList = new List <SelectListItem>(); MasterDataBLL = new LARCA2.Business.Services.MasterDataBLL(); BUList.Add(new SelectListItem { Text = "Select RBU", Value = "0", Selected = true }); SMOList.Add(new SelectListItem { Text = "Select SMO", Value = "0", Selected = true }); foreach (LARCA2.Data.DatabaseModels.LARCA20_MasterData md in MasterDataBLL.Todos().Where(x => x.Data == "BU" && x.deleted != true).ToList()) { if (md.DataFin.Length > 0) { if (!BUList.Exists(m => m.Text == md.DataFin.ToString())) { BUList.Add(new SelectListItem { Text = md.DataFin, Value = md.DataFin }); } } } foreach (LARCA2.Data.DatabaseModels.LARCA20_MasterData md in MasterDataBLL.Todos().Where(x => x.Data == "SMO" && x.deleted != true).ToList()) { if (!SMOList.Exists(m => m.Text == md.DataFin.ToString()) && md.DataFin != "VENEZUELA") { SMOList.Add(new SelectListItem { Text = md.DataFin, Value = md.DataFin }); } } SMOList.Add(new SelectListItem { Text = "LA", Value = "1" }); var user = (LARCA20_Users)HttpContext.Current.Session["Usuario"]; if (user == null) { user = new UsuariosBLL().Traer(2); } Permisos = new LARCA2.Business.Services.UserOwnerBLL().TraerPorIdUsuario(user.Id); }
public ActionResult Index() { var model = new Larca2.Views.ViewModels.SMOScopeViewModel(); /*try * { * ViewData["MasterRows"] = new SMOScopeBLL().Todos().ToList(); * } * catch * { * ViewData["MasterRows"] = new List<LARCA20_SmoScope>(); * }*/ //Declaro BLLs e inicializo viewModel Larca2.Views.ViewModels.SMOScopeViewModel viewModel = new Larca2.Views.ViewModels.SMOScopeViewModel(); LARCA2.Business.Services.UsuariosBLL repoUsuarios = new LARCA2.Business.Services.UsuariosBLL(); LARCA2.Business.Services.UserOwnerBLL uobll = new LARCA2.Business.Services.UserOwnerBLL(); LARCA2.Business.Services.SMOScopeBLL ssbll = new LARCA2.Business.Services.SMOScopeBLL(); //Reviso el usuario logueado, sino como prueba traigo al de ID 2 LARCA2.Data.DatabaseModels.LARCA20_Users user = (LARCA2.Data.DatabaseModels.LARCA20_Users)Session["Usuario"]; if (user == null) { user = repoUsuarios.Traer(2); } //determino el rol del usuario para entender qué filtros y funcionalidades disponer LARCA2.Business.Services.RolesBLL robll = new LARCA2.Business.Services.RolesBLL(); LARCA2.Business.Services.UsuariosRolesBLL urbll = new LARCA2.Business.Services.UsuariosRolesBLL(); viewModel.userRole = robll.Traer(urbll.Traer(user.Id).RefIdRoles).Description; viewModel.idRole = robll.Traer(urbll.Traer(user.Id).RefIdRoles).Id; //Obtengo los registros de User Owner con IdUser igual al del usuario logueado List <LARCA2.Data.DatabaseModels.LARCA20_User_Owner> luo = uobll.TraerPorIdUsuario(user.Id); // Quito de la lista de SMO y BU de los filtros aquellos no contemplados por un registro existente de UserOwner para el usuario logueado // viewModel.SMOList = viewModel.SMOList.Where(x => luo.Exists(y => y.IdSmo.ToString() == x.Value) || x.Value == "0").ToList(); // viewModel.BUList = viewModel.BUList.Where(x => luo.Exists(y => y.IdBU.ToString() == x.Value) || x.Value == "0").ToList(); //Filtro los registros de la tabla SmoScope en función del rol y los permisos para cada uno //Aquellos cuyos RefIdSMO, RefIdBU, y RefIdOwner coinciden con los de un registro de la tabla UserOwner para el usuario logueado, permanecen //Con que algunos de los campos en cuestion difiera, el registro de SmoScope ya no será mostrado. if (viewModel.idRole != 1 && viewModel.idRole != 3) { List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope> smoscopeact; viewModel.RegistrosSMO = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>(); foreach (LARCA2.Data.DatabaseModels.LARCA20_User_Owner actualLuo in luo) { smoscopeact = ssbll.FiltrarPending(actualLuo.IdBU.ToString(), actualLuo.IdSmo.ToString(), viewModel.idRole.ToString()).Where(x => x.RefIdOwner == actualLuo.IdOwner).ToList(); if (smoscopeact != null) { viewModel.RegistrosSMO.AddRange(smoscopeact); } } } else { viewModel.RegistrosSMO = ssbll.FiltrarPending("0", "0", viewModel.idRole.ToString()).ToList(); } viewModel.RegistrosSMO = viewModel.RegistrosSMO.Distinct().ToList(); /* * * viewModel.SMOList = viewModel.SMOList.Where(x => viewModel.RegistrosSMO.Exists(y => y.RefIdSMO.ToString() == x.Value) || x.Value == "0").ToList(); * viewModel.BUList = viewModel.BUList.Where(x => viewModel.RegistrosSMO.Exists(y => y.RefIdBU.ToString() == x.Value) || x.Value == "0").ToList(); * * * //LARCA2.Business.Services.MasterDataBLL mdlll = new LARCA2.Business.Services.MasterDataBLL(); * //List<LARCA2.Data.DatabaseModels.LARCA20_MasterData> allmaster = mdlll.Todos().Exists(z => viewModel.SMOList.Where(x => x.Text == z.DataIni).ToList()); * // Quito de la lista de SMO y BU de los filtros aquellos no contemplados por un registro existente de SmoScope valido en termino de fecha pero llevaria mas horas * //viewModel.SMOList = viewModel.SMOList.Where(x => viewModel.RegistrosSMO.Exists(y => y.RefIdSMO.ToString() == x.Value) || x.Value == "0").ToList(); * //viewModel.BUList = viewModel.BUList.Where(x => viewModel.RegistrosSMO.Exists(y => y.RefIdBU.ToString() == x.Value) || x.Value == "0").ToList(); * * if (viewModel.RegistrosSMO.Where(x => x.date.Value.Month == (DateTime.Now.Month - 1)).Count() > 0) * viewModel.dropdownMeses.Add(new SelectListItem { Text = "Previous Month", Value = "1", Selected = false }); * * viewModel.RegistrosSMO = viewModel.RegistrosSMO.Where(x => x.date.Value.Month == DateTime.Now.Month).ToList(); * * viewModel.RegistrosSMO = viewModel.RegistrosSMO.Distinct().ToList(); * * //traigo aquellos de los cuales el user es el responsable * ResponsablesBLL respBLL = new ResponsablesBLL(); * int idResp = respBLL.TraerPorNombreDeUsuario(user.user_name).Id; * viewModel.RegistrosSMO = viewModel.RegistrosSMO.Where(x => x.RefIdResponsable != null && x.RefIdResponsable.Value == idResp).ToList(); * * * //Copio la lista a los editables para poder modificar los datos necesarios. * viewModel.EditablesSMO = viewModel.RegistrosSMO; * * * LARCA2.Business.Services.ApplicationDataBLL adb = new LARCA2.Business.Services.ApplicationDataBLL(); * int valMax = adb.Todos()[0].Toplvl4; * viewModel.maxClones = new List<int>(); * for (int i = 0; i < viewModel.EditablesSMO.Count; i++) * { viewModel.maxClones.Add(valMax); } * * ResponsablesBLL repoResponsables = new ResponsablesBLL(); * viewModel.responsibles = new List<string>(); * foreach (LARCA2.Data.DatabaseModels.LARCA20_SmoScope itemstr in viewModel.EditablesSMO) * * * viewModel.responsibles.Add((itemstr.RefIdResponsable == null ? "" : repoResponsables.TraerSuNombreDeUsuario(itemstr.RefIdResponsable.Value))); * * */ ViewData["MasterRows"] = viewModel.RegistrosSMO; return(View(model)); }
public ActionResult Export() { var model = new Larca2.Views.ViewModels.SMOScopeViewModel(); /*try * { * ViewData["MasterRows"] = new SMOScopeBLL().Todos().ToList(); * } * catch * { * ViewData["MasterRows"] = new List<LARCA20_SmoScope>(); * }*/ //Declaro BLLs e inicializo viewModel Larca2.Views.ViewModels.SMOScopeViewModel viewModel = new Larca2.Views.ViewModels.SMOScopeViewModel(); LARCA2.Business.Services.UsuariosBLL repoUsuarios = new LARCA2.Business.Services.UsuariosBLL(); LARCA2.Business.Services.UserOwnerBLL uobll = new LARCA2.Business.Services.UserOwnerBLL(); LARCA2.Business.Services.SMOScopeBLL ssbll = new LARCA2.Business.Services.SMOScopeBLL(); //Reviso el usuario logueado, sino como prueba traigo al de ID 2 LARCA2.Data.DatabaseModels.LARCA20_Users user = (LARCA2.Data.DatabaseModels.LARCA20_Users)Session["Usuario"]; if (user == null) { user = repoUsuarios.Traer(2); } //determino el rol del usuario para entender qué filtros y funcionalidades disponer LARCA2.Business.Services.RolesBLL robll = new LARCA2.Business.Services.RolesBLL(); LARCA2.Business.Services.UsuariosRolesBLL urbll = new LARCA2.Business.Services.UsuariosRolesBLL(); viewModel.userRole = robll.Traer(urbll.Traer(user.Id).RefIdRoles).Description; viewModel.idRole = robll.Traer(urbll.Traer(user.Id).RefIdRoles).Id; //Obtengo los registros de User Owner con IdUser igual al del usuario logueado List <LARCA2.Data.DatabaseModels.LARCA20_User_Owner> luo = uobll.TraerPorIdUsuario(user.Id); // Quito de la lista de SMO y BU de los filtros aquellos no contemplados por un registro existente de UserOwner para el usuario logueado // viewModel.SMOList = viewModel.SMOList.Where(x => luo.Exists(y => y.IdSmo.ToString() == x.Value) || x.Value == "0").ToList(); // viewModel.BUList = viewModel.BUList.Where(x => luo.Exists(y => y.IdBU.ToString() == x.Value) || x.Value == "0").ToList(); //Filtro los registros de la tabla SmoScope en función del rol y los permisos para cada uno //Aquellos cuyos RefIdSMO, RefIdBU, y RefIdOwner coinciden con los de un registro de la tabla UserOwner para el usuario logueado, permanecen //Con que algunos de los campos en cuestion difiera, el registro de SmoScope ya no será mostrado. if (viewModel.idRole != 1 && viewModel.idRole != 3) { List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope> smoscopeact; viewModel.RegistrosSMO = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>(); foreach (LARCA2.Data.DatabaseModels.LARCA20_User_Owner actualLuo in luo) { smoscopeact = ssbll.Filtrar(actualLuo.IdBU.ToString(), actualLuo.IdSmo.ToString(), viewModel.idRole.ToString()).Where(x => x.RefIdOwner == actualLuo.IdOwner).ToList(); if (smoscopeact != null) { viewModel.RegistrosSMO.AddRange(smoscopeact); } } } else { viewModel.RegistrosSMO = ssbll.Filtrar("0", "0", viewModel.idRole.ToString()).ToList(); } viewModel.RegistrosSMO = viewModel.RegistrosSMO.Distinct().ToList(); var masterData = viewModel.RegistrosSMO.ToList(); //var masterData = new SMOScopeBLL().Todos().ToList(); var file = new ExcelCore().GenerarExcelPendingAnalysis("LARCA Pending Analysis", masterData); DownloadFile(file); return(Content("<script language='javascript' type='text/javascript'>alert('Exported!');document.location = 'Index';</script>")); }
private string CheckProblem(string problem, string action_plan, long?bu, long?smo, long?owner, bool?partial, bool?top) { /* * if (problem != null && action_plan != null && action_plan != "" && problem != "") * { * return problem; * } * else * { * * * if (partial == true) * { * return "Cut under analysis due to its appearance outside of scope (between Monday and Tuesday), analysis due next week"; * } * * else * { * * * if (top == true){ * var user = new UserOwnerBLL().UserPermisoCheck(bu, smo, owner); * if (user.Id > 0) * { * return "Analysis pending by " + user.user_name; * } * else * { * return "Analysis pending by user"; * } * } * else * { * return "Cut under analysis due to its appearance outside of scope (between Monday and Tuesday), analysis due next week"; * } * } * } * */ if (problem != null && action_plan != null && action_plan != "" && problem != "") { return(problem); } if (partial == true) { return("Cut under analysis due to its appearance outside of scope (between Monday and Tuesday), analysis due next week"); } if (top == true) { var user = new UserOwnerBLL().UserPermisoCheck(bu, smo, owner); if (user.Id > 0) { return("Analysis pending by " + user.user_name); } else { return("Analysis pending by user"); } } else { /* if (partial == true) * { * return "Cut under analysis due to its appearance outside of scope (between Monday and Tuesday), analysis due next week"; * } * * var user = new UserOwnerBLL().UserPermisoCheck(bu, smo, owner); * if (user.Id > 0) * { * return "Analysis pending by " + user.user_name; * } * else * { * return "Analysis pending by user"; * } */ return("Cut under analysis due to its appearance outside of scope (between Monday and Tuesday), analysis due next week"); } }
public List <ReportRow> LARCANews(string smoFin, string buFin, string regionId) { var permisos = new List <LARCA20_UsersRoles>(); var lista = new List <ReportRow>(); var toplvl2 = new ApplicationDataBLL().TraerTopLvl2(); var lista22 = new LARCA2.Data.Services.UserOwnerDAL(); var permisostodos = lista22.Todos(); if (smoFin.Length > 0) { var items = SmoScopeDAL.Todos().Where(s => s.MasterSMO.DataFin == smoFin && s.clone != true && s.historic != true).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]); int cant = 0; foreach (var item in items) //.Take(toplvl2)) { cant++; var volumenSmo = Convert.ToDecimal(SmoDetailDAL.Todos().Where(s => s.MasterSMODetail.DataFin == smoFin && s.historic == false).Sum(s => s.Volumen)); var volumen = SmoDetailDAL.Todos().Where(s => s.MasterSMODetail.DataFin == smoFin && s.historic == false && s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[0] + "." + s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[1] == item.Key).Sum(s => s.Volumen); var row = new ReportRow(); row.SMO = item.ToList()[0].MasterSMO.DataFin; row.RBU = "TOTAL"; row.CUT = new RCClassificationBLL().Traer(item.Key).Description; row.Details = new List <ReportRow>(); row.VOLUME = (Math.Round(decimal.Parse(volumen.ToString()), 2)).ToString(); row.PROBLEM = "View Details Below"; row.GAP = Math.Round(volumen * 100 / volumenSmo, 2).ToString() + " %"; var toplvl3 = new ApplicationDataBLL().TraerTopLvl3(); decimal vol = 0; int i = 1; foreach (var subitem in item.ToList().OrderByDescending(s => s.Volumen).Take(toplvl3)) //.Take(toplvl3)) { var detailRow = new ReportRow { SMO = subitem.MasterSMO.DataFin, RBU = subitem.MasterBU.DataFin, CUT = subitem.MasterLvl.Description, VOLUME = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString(), PROBLEM = CheckProblem(subitem.Problem, subitem.ActionPlan, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner, subitem.partial, subitem.top_news), WHY1 = subitem.Why1, WHY2 = subitem.Why2, WHY3 = subitem.Why3, ACTIONPLAN = subitem.ActionPlan, LEVEL4 = "", RESPONSIBLE = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Responsable_user.user_name : string.Empty, GAP = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %" }; try { detailRow.LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty; } catch (Exception) { detailRow.LEVEL4 = ""; } var user = new UserOwnerBLL().UserPermisoCheck(subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner); if (user.Id > 0) { detailRow.GAPANALYSIS = user.user_name; } else { detailRow.GAPANALYSIS = ""; } ////// Boolean paso = false; if (i == 1) { i++; vol = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)); row.Details.Add(detailRow); paso = true; } else { if (vol * 100 / volumen <= 80) { i++; vol += (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)); row.Details.Add(detailRow); paso = true; } } if (paso) { // Chequeo de clones var clones = new SMOScopeBLL().Todos().Where(s => s.RefIdSMO == subitem.RefIdSMO && s.RefIdBU == subitem.RefIdBU && s.RefIdOwner == subitem.RefIdOwner && s.RefIdRC == subitem.RefIdRC && s.SmoScopeID != subitem.SmoScopeID && s.clone == true && s.historic == false); if (clones.Count() > 0) { foreach (var clon in clones) { var detail = new ReportRow { SMO = string.Empty, RBU = string.Empty, CUT = string.Empty, VOLUME = string.Empty, PROBLEM = clon.Problem, WHY1 = clon.Why1, WHY2 = clon.Why2, WHY3 = clon.Why3, ACTIONPLAN = clon.ActionPlan, RESPONSIBLE = clon.ResponsableSmo != null ? clon.ResponsableSmo.Responsable_user.user_name : string.Empty, //LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty, LEVEL4 = "", GAP = string.Empty }; try { detail.LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty; } catch (Exception) { detail.LEVEL4 = ""; } user = new UserOwnerBLL().UserPermisoCheck(clon.RefIdBU, clon.RefIdSMO, clon.RefIdOwner); if (user.Id > 0) { detail.GAPANALYSIS = user.user_name; } else { detail.GAPANALYSIS = ""; } row.Details.Add(detail); } } } } lista.Add(row); } } else if (buFin.Length > 0) { var items = SmoScopeDAL.Todos().Where(s => s.MasterBU.DataFin == buFin && s.historic == false && s.clone != true).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]); int cant = 0; foreach (var item in items) //.Take(toplvl2)) { cant++; var volumenBU = Convert.ToDecimal(SmoDetailDAL.Todos().Where(s => s.MasterBUDetail.DataFin == buFin && s.historic == false).Sum(s => s.Volumen)); var volumen = SmoDetailDAL.Todos().Where(s => s.MasterBUDetail.DataFin == buFin && s.historic == false && s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[0] + "." + s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[1] == item.Key).Sum(s => s.Volumen); var row = new ReportRow(); row.SMO = "TOTAL"; row.RBU = item.ToList()[0].MasterBU.DataFin; row.CUT = new RCClassificationBLL().Traer(item.Key).Description; row.Details = new List <ReportRow>(); row.VOLUME = (Math.Round(decimal.Parse(volumen.ToString()), 2)).ToString(); row.PROBLEM = "View Details Below"; row.GAP = Math.Round(volumen * 100 / volumenBU, 2).ToString() + " %"; decimal vol = 0; int i = 1; var toplvl3 = new ApplicationDataBLL().TraerTopLvl3(); foreach (var subitem in item.ToList().OrderByDescending(s => s.Volumen).Take(toplvl3)) { string SMOt = subitem.MasterSMO.DataFin; string RBUt = subitem.MasterBU.DataFin; string CUTt = subitem.MasterLvl.Description; string VOLUMEt = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString(); string PROBLEMt = CheckProblem(subitem.Problem, subitem.ActionPlan, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner, subitem.partial, subitem.top_news); string WHY1t = subitem.Why1; string WHY2t = subitem.Why2; string WHY3t = subitem.Why3; string ACTIONPLANt = subitem.ActionPlan; string RESPONSIBLEt = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Responsable_user.user_name : string.Empty; string LEVEL4t = ""; string GAPANALYSIS; try { LEVEL4t = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty; } catch (Exception) { LEVEL4t = ""; } var user = new UserOwnerBLL().UserPermisoCheck(subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner); if (user.Id > 0) { GAPANALYSIS = user.user_name; } else { GAPANALYSIS = ""; } string GAPt = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %"; var detailRow = new ReportRow { SMO = SMOt, RBU = RBUt, CUT = CUTt, VOLUME = VOLUMEt, PROBLEM = PROBLEMt, WHY1 = WHY1t, WHY2 = WHY2t, WHY3 = WHY3t, ACTIONPLAN = ACTIONPLANt, RESPONSIBLE = RESPONSIBLEt, LEVEL4 = LEVEL4t, GAP = GAPt, GAPANALYSIS = GAPANALYSIS /* * SMO = subitem.MasterSMO.DataFin, * RBU = subitem.MasterBU.DataFin, * CUT = subitem.MasterLvl.Description, * VOLUME = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString(), * PROBLEM = CheckProblem(subitem.Problem, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner), * WHY1 = subitem.Why1, * WHY2 = subitem.Why2, * WHY3 = subitem.Why3, * ACTIONPLAN = subitem.ActionPlan, * RESPONSIBLE = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Name.ToString() : string.Empty, * LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty, * GAP = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %" */ }; Boolean paso = false; if (i == 1) { i++; vol = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)); row.Details.Add(detailRow); paso = true; } else { if (vol * 100 / volumen <= 80) { i++; vol += (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)); row.Details.Add(detailRow); paso = true; } } if (paso) { // Chequeo de clones var clones = new SMOScopeBLL().Todos().Where(s => s.RefIdSMO == subitem.RefIdSMO && s.RefIdBU == subitem.RefIdBU && s.RefIdOwner == subitem.RefIdOwner && s.RefIdRC == subitem.RefIdRC && s.SmoScopeID != subitem.SmoScopeID && s.clone == true && s.historic == false); if (clones.Count() > 0) { foreach (var clon in clones) { var detail = new ReportRow { SMO = string.Empty, RBU = string.Empty, CUT = string.Empty, VOLUME = string.Empty, PROBLEM = clon.Problem, WHY1 = clon.Why1, WHY2 = clon.Why2, WHY3 = clon.Why3, ACTIONPLAN = clon.ActionPlan, RESPONSIBLE = clon.ResponsableSmo != null ? clon.ResponsableSmo.Responsable_user.user_name : string.Empty, //LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty, LEVEL4 = "", GAP = string.Empty }; try { detail.LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty; } catch (Exception) { detail.LEVEL4 = ""; } user = new UserOwnerBLL().UserPermisoCheck(clon.RefIdBU, clon.RefIdSMO, clon.RefIdOwner); if (user.Id > 0) { detail.GAPANALYSIS = user.user_name; } else { detail.GAPANALYSIS = ""; } row.Details.Add(detail); } } } } lista.Add(row); } } else { if (regionId == "1") { var items = SmoScopeDAL.Todos().Where(p => p.clone != true && p.historic == false).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]); int cant = 0; foreach (var item in items) //.Take(toplvl2)) { cant++; var volumenTotal = Convert.ToDecimal(SmoDetailDAL.Todos().Where(s => s.historic == false).Sum(s => s.Volumen)); var volumen = SmoDetailDAL.Todos().Where(s => s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[0] + "." + s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[1] == item.Key && s.historic == false).Sum(s => s.Volumen); var row = new ReportRow(); row.SMO = "TOTAL"; row.RBU = "TOTAL"; row.CUT = new RCClassificationBLL().Traer(item.Key).Description; row.Details = new List <ReportRow>(); row.VOLUME = (Math.Round(decimal.Parse(volumen.ToString()), 2)).ToString(); row.PROBLEM = "View Details Below"; row.GAP = Math.Round(volumen * 100 / volumenTotal, 2).ToString() + " %"; decimal vol = 0; int i = 1; var toplvl3 = new ApplicationDataBLL().TraerTopLvl3(); foreach (var subitem in item.ToList().OrderByDescending(s => s.Volumen).Take(toplvl3)) { var detailRow = new ReportRow { SMO = subitem.MasterSMO.DataFin, RBU = subitem.MasterBU.DataFin, CUT = subitem.MasterLvl.Description, VOLUME = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString(), PROBLEM = CheckProblem(subitem.Problem, subitem.ActionPlan, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner, subitem.partial, subitem.top_news), WHY1 = subitem.Why1, WHY2 = subitem.Why2, WHY3 = subitem.Why3, ACTIONPLAN = subitem.ActionPlan, RESPONSIBLE = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Responsable_user.user_name : string.Empty, //LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty, LEVEL4 = "", GAP = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %" }; try { detailRow.LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty; } catch (Exception) { detailRow.LEVEL4 = ""; } var user = new UserOwnerBLL().UserPermisoCheck(subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner); if (user.Id > 0) { detailRow.GAPANALYSIS = user.user_name; } else { detailRow.GAPANALYSIS = ""; } Boolean paso = false; if (i == 1) { i++; vol = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)); row.Details.Add(detailRow); paso = true; } else { if (vol * 100 / volumen <= 80) { i++; vol += (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)); row.Details.Add(detailRow); paso = true; } } if (paso) { // Chequeo de clones var clones = new SMOScopeBLL().Todos().Where(s => s.RefIdSMO == subitem.RefIdSMO && s.RefIdBU == subitem.RefIdBU && s.RefIdOwner == subitem.RefIdOwner && s.RefIdRC == subitem.RefIdRC && s.SmoScopeID != subitem.SmoScopeID && s.clone == true && s.historic == false); if (clones.Count() > 0) { foreach (var clon in clones) { var detail = new ReportRow { SMO = string.Empty, RBU = string.Empty, CUT = string.Empty, VOLUME = string.Empty, PROBLEM = clon.Problem, WHY1 = clon.Why1, WHY2 = clon.Why2, WHY3 = clon.Why3, ACTIONPLAN = clon.ActionPlan, RESPONSIBLE = clon.ResponsableSmo != null ? clon.ResponsableSmo.Responsable_user.user_name : string.Empty, //LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty, LEVEL4 = "", GAP = string.Empty }; try { detail.LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty; } catch (Exception) { detail.LEVEL4 = ""; } user = new UserOwnerBLL().UserPermisoCheck(clon.RefIdBU, clon.RefIdSMO, clon.RefIdOwner); if (user.Id > 0) { detail.GAPANALYSIS = user.user_name; } else { detail.GAPANALYSIS = ""; } row.Details.Add(detail); } } } } lista.Add(row); } } else if (regionId == "2") { var items = SmoScopeDAL.TodosConExclusiones().Where(p => p.clone != true && p.historic == false).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]); int cant = 0; foreach (var item in items) //.Take(toplvl2)) { cant++; var volumenTotal = Convert.ToDecimal(SmoDetailDAL.Todos().Where(s => s.historic == false).Sum(s => s.Volumen)); var volumen = SmoDetailDAL.Todos().Where(s => s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[0] + "." + s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[1] == item.Key && s.historic == false).Sum(s => s.Volumen); var row = new ReportRow(); row.SMO = "TOTAL"; row.RBU = "TOTAL"; row.CUT = new RCClassificationBLL().Traer(item.Key).Description; row.Details = new List <ReportRow>(); row.VOLUME = (Math.Round(decimal.Parse(volumen.ToString()), 2)).ToString(); row.PROBLEM = "View Details Below"; row.GAP = Math.Round(volumen * 100 / volumenTotal, 2).ToString() + " %"; decimal vol = 0; int i = 1; var toplvl3 = new ApplicationDataBLL().TraerTopLvl3(); foreach (var subitem in item.ToList().OrderByDescending(s => s.Volumen).Take(toplvl3)) { var detailRow = new ReportRow { SMO = subitem.MasterSMO.DataFin, RBU = subitem.MasterBU.DataFin, CUT = subitem.MasterLvl.Description, VOLUME = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString(), PROBLEM = CheckProblem(subitem.Problem, subitem.ActionPlan, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner, subitem.partial, subitem.top_news), WHY1 = subitem.Why1, WHY2 = subitem.Why2, WHY3 = subitem.Why3, ACTIONPLAN = subitem.ActionPlan, RESPONSIBLE = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Responsable_user.user_name : string.Empty, //LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty, LEVEL4 = "", GAP = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %" }; try { detailRow.LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty; } catch (Exception) { detailRow.LEVEL4 = ""; } var user = new UserOwnerBLL().UserPermisoCheck(subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner); if (user.Id > 0) { detailRow.GAPANALYSIS = user.user_name; } else { detailRow.GAPANALYSIS = ""; } Boolean paso = false; if (i == 1) { i++; vol = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)); row.Details.Add(detailRow); paso = true; } else { if (vol * 100 / volumen <= 80) { i++; vol += (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)); row.Details.Add(detailRow); paso = true; } } if (paso) { // Chequeo de clones var clones = new SMOScopeBLL().Todos().Where(s => s.RefIdSMO == subitem.RefIdSMO && s.RefIdBU == subitem.RefIdBU && s.RefIdOwner == subitem.RefIdOwner && s.RefIdRC == subitem.RefIdRC && s.SmoScopeID != subitem.SmoScopeID && s.clone == true && s.historic == false); if (clones.Count() > 0) { foreach (var clon in clones) { var detail = new ReportRow { SMO = string.Empty, RBU = string.Empty, CUT = string.Empty, VOLUME = string.Empty, PROBLEM = clon.Problem, WHY1 = clon.Why1, WHY2 = clon.Why2, WHY3 = clon.Why3, ACTIONPLAN = clon.ActionPlan, RESPONSIBLE = clon.ResponsableSmo != null ? clon.ResponsableSmo.Responsable_user.user_name : string.Empty, //LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty, LEVEL4 = "", GAP = string.Empty }; try { detail.LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty; } catch (Exception) { detail.LEVEL4 = ""; } user = new UserOwnerBLL().UserPermisoCheck(clon.RefIdBU, clon.RefIdSMO, clon.RefIdOwner); if (user.Id > 0) { detail.GAPANALYSIS = user.user_name; } else { detail.GAPANALYSIS = ""; } row.Details.Add(detail); } } } } lista.Add(row); } } } return(lista.OrderByDescending(i => Convert.ToDecimal(i.VOLUME)).Take(toplvl2).ToList()); }