public ActionResult Export(ReportGenerationViewModel RGViewModel, string command) { bool result = false; ReportGenerationManager RGManager = new ReportGenerationManager(); result = RGManager.ManageReport(RGViewModel, command); return(RedirectToAction("Index")); }
// GET: Reports public async Task <IActionResult> Index() { ReportGenerationViewModel generationViewModel = new ReportGenerationViewModel(); generationViewModel.Reports = await GetReports(); _reportVM.Reports = generationViewModel.Reports; return(View(GetIndexReportViewModel(generationViewModel))); }
public async Task <IActionResult> OnCallIndia() { ReportGenerationViewModel generationViewModel = new ReportGenerationViewModel(); generationViewModel.Reports = await GetReports(); int escalateId = _context.onCallEscalates.SingleOrDefault(e => e.OnCallEscalateName.ToLower().Contains("india")).OnCallEscalateId; generationViewModel.Reports.RemoveAll(e => e.onCallEscalateId != escalateId); _reportVM.Reports = generationViewModel.Reports; return(View("Index", GetIndexReportViewModel(generationViewModel))); }
/// <summary> /// Triggers the unit report creation. /// </summary> public IEnumerable <IResult> GenerateUnitReports() { var dialog = new ReportGenerationViewModel(Dossier.RootUnit); DialogResult result = ShowDialog(dialog); List <UnitDecorator> units = dialog.MarkedUnits.ToList(); if (result != DialogResult.Ok || units.Count == 0) { yield break; } bool modelChanged = false; using (this._busyWatcher.GetTicket()) { yield return (new AsyncResult( () => Parallel.ForEach( units.Where( unit => !unit.Reports.SourceCollection.Cast <ReportDecorator>() .Any(report => report.ScenarioName == SelectedReport.ScenarioName)), unit => { Execute.OnUIThread(unit.AddNewReport); ((ReportDecorator)unit.Reports.CurrentItem).ScenarioName = SelectedReport.ScenarioName; modelChanged = true; }), null, exception => ShowError(exception, Resources.UnableToGenerateReports))); if (modelChanged) { OnModelChanged(); } } }
public ActionResult Filter(ReportGenerationViewModel model) { var where = GetWhere(model); if (User.IsInRole(Constants.ADMIN)) { model.Reports = _context.Report.Where(where) .Include(r => r.Category).Include(r => r.Shift).Include(r => r.Type).Include(r => r.User).Include(r => r.onCallEscalate).ToList(); } else if (User.IsInRole(Constants.TL)) { model.Reports = _context.Report.Where(where) .Include(r => r.Category).Include(r => r.Shift).Include(r => r.Type).Include(r => r.User).Include(r => r.onCallEscalate).ToList(); } else if (User.IsInRole(Constants.USER)) { model.Reports = _context.Report.Where(where) .Include(r => r.Category).Include(r => r.Shift).Include(r => r.Type).Include(r => r.User).Include(r => r.onCallEscalate).ToList(); } _reportVM = model; return(View("Index", GetIndexReportViewModel(model))); }
public bool ManageReport(ReportGenerationViewModel RGViewModel, string command) { using (CFMMCDEntities db = new CFMMCDEntities()) { List <CSHMIMP0> MIMRow = new List <CSHMIMP0>(); List <INVRIRP0> RECRow = new List <INVRIRP0>(); List <INVRIMP0> RIMRow = new List <INVRIMP0>(); List <Store_Profile> SPRow = new List <Store_Profile>(); if (RGViewModel.ItemToExport.Equals("Store")) { SPRow = db.Store_Profile.Where(o => o.STORE_NO.ToString().Equals(RGViewModel.Store)).ToList(); } else { if (RGViewModel.MenuItem) { MIMRow = db.CSHMIMP0.ToList(); if (RGViewModel.DateFrom != null && !RGViewModel.DateFrom.Equals("")) { MIMRow = MIMRow.Where(o => o.MIMDAT >= DateTime.Parse(RGViewModel.DateFrom)).ToList(); } if (RGViewModel.DateTo != null && !RGViewModel.DateTo.Equals("")) { MIMRow = MIMRow.Where(o => o.MIMDAT <= DateTime.Parse(RGViewModel.DateTo)).ToList(); } } if (RGViewModel.RawItem) { RIMRow = db.INVRIMP0.ToList(); if (!RGViewModel.FRESH_OR_FROZEN.Equals("0")) { RIMRow = RIMRow.Where(o => o.Store_Attrib.Equals(RGViewModel.FRESH_OR_FROZEN)).ToList(); } else if (!RGViewModel.PAPER_OR_PLASTIC.Equals("0")) { RIMRow = RIMRow.Where(o => o.Store_Attrib.Equals(RGViewModel.PAPER_OR_PLASTIC)).ToList(); } else if (!RGViewModel.SOFT_SERVE_OR_VANILLA_POWDER_MIX.Equals("0")) { RIMRow = RIMRow.Where(o => o.Store_Attrib.Equals(RGViewModel.SOFT_SERVE_OR_VANILLA_POWDER_MIX)).ToList(); } else if (!RGViewModel.SIMPLOT_OR_MCCAIN.Equals("0")) { RIMRow = RIMRow.Where(o => o.Store_Attrib.Equals(RGViewModel.SIMPLOT_OR_MCCAIN)).ToList(); } else if (!RGViewModel.MCCORMICK_OR_GSF.Equals("0")) { RIMRow = RIMRow.Where(o => o.Store_Attrib.Equals(RGViewModel.MCCORMICK_OR_GSF)).ToList(); } else if (!RGViewModel.FRESHB_OR_FROZENB.Equals("0")) { RIMRow = RIMRow.Where(o => o.Store_Attrib.Equals(RGViewModel.FRESHB_OR_FROZENB)).ToList(); } if (RGViewModel.DateFrom != null && !RGViewModel.DateFrom.Equals("")) { RIMRow = RIMRow.Where(o => o.RIMDAT >= DateTime.Parse(RGViewModel.DateFrom)).ToList(); } if (RGViewModel.DateTo != null && !RGViewModel.DateTo.Equals("")) { RIMRow = RIMRow.Where(o => o.RIMDAT <= DateTime.Parse(RGViewModel.DateTo)).ToList(); } } if (RGViewModel.Recipe) { RECRow = db.INVRIRP0.ToList(); if (RGViewModel.DateFrom != null && !RGViewModel.DateFrom.Equals("")) { RECRow = RECRow.Where(o => o.RIRDAT >= DateTime.Parse(RGViewModel.DateFrom)).ToList(); } if (RGViewModel.DateTo != null && !RGViewModel.DateTo.Equals("")) { RECRow = RECRow.Where(o => o.RIRDAT <= DateTime.Parse(RGViewModel.DateTo)).ToList(); } } } if ((MIMRow == null || MIMRow.Count() <= 0) && (RECRow == null || RECRow.Count() <= 0) && (RIMRow == null || RIMRow.Count() <= 0) && (SPRow == null || SPRow.Count() <= 0)) { return(false); } if (command.Equals("toPDF")) { ExportToPDF(MIMRow, RECRow, RIMRow, SPRow); } else if (command.Equals("toExcel")) { ExportToExcel(MIMRow, RECRow, RIMRow, SPRow); } return(true); } }
private ReportGenerationViewModel GetIndexReportViewModel(ReportGenerationViewModel report) { var user = userManager.GetUserAsync(HttpContext.User).Result; report.Shifts = _context.Shift.Where(e => e.IsActive).Select(e => new SelectListItem { Text = e.ShiftName, Value = e.ShiftId.ToString(), Selected = e.ShiftId.ToString() == report.ShiftID ? true : false }).ToList(); report.Types = _context.Type.Where(e => e.IsActive).Select(e => new SelectListItem { Text = e.TypeName, Value = e.TypeId.ToString(), Selected = e.TypeId.ToString() == report.TypeID ? true : false }).ToList(); report.Categories = _context.Category.Where(e => e.IsActive).Select(e => new SelectListItem { Text = e.CategoryName, Value = e.CategoryId.ToString(), Selected = e.CategoryId.ToString() == report.CategoryID ? true : false }).ToList(); if (User.IsInRole(Constants.ADMIN)) { report.Users = userManager.Users.Select(e => new SelectListItem { Text = e.Name, Value = e.Id, Selected = e.Id == report.UserID ? true : false }).ToList(); } else if (User.IsInRole(Constants.TL)) { report.Users = userManager.Users.Where(e => e.CategoryId == user.CategoryId).Select(e => new SelectListItem { Text = e.Name, Value = e.Id, Selected = e.Id == report.UserID ? true : false }).ToList(); } else { report.Users = new List <SelectListItem>(); } report.OnCallEscalaties = _context.onCallEscalates.Select(e => new SelectListItem { Text = e.OnCallEscalateName, Value = e.OnCallEscalateId.ToString(), Selected = e.OnCallEscalateId.ToString() == report.OnCallEscalateID ? true : false }).ToList(); report.Categories.Add(new SelectListItem { Text = "Select Department", Value = string.Empty, Selected = string.IsNullOrEmpty(report?.CategoryID) ? true : false }); report.Types.Add(new SelectListItem { Text = "Select Ticket Type", Value = string.Empty, Selected = string.IsNullOrEmpty(report?.TypeID) ? true : false }); report.Shifts.Add(new SelectListItem { Text = "Select Shift", Value = string.Empty, Selected = string.IsNullOrEmpty(report?.ShiftID) ? true : false }); report.OnCallEscalaties.Add(new SelectListItem { Text = "Select OnCall", Value = string.Empty, Selected = string.IsNullOrEmpty(report?.OnCallEscalateID) ? true : false }); report.Users.Add(new SelectListItem { Text = "Select User", Value = string.Empty, Selected = string.IsNullOrEmpty(report?.UserID) ? true : false }); return(report); }
private Expression <Func <Models.Report, bool> > GetWhere(ReportGenerationViewModel model) { Expression <Func <Models.Report, bool> > where = c => true; var user = userManager.GetUserAsync(HttpContext.User).Result; if (model.StartTime != null) { var prefix = where.Compile(); where = c => prefix(c) && c.StartTime >= model.StartTime; } else { var prefix = where.Compile(); where = c => prefix(c) && c.StartTime > DateTime.Today.AddMonths(-1); } if (model.EndTime != null) { var prefix = where.Compile(); where = c => prefix(c) && c.StartTime <= model.EndTime; } if (!string.IsNullOrEmpty(model.CategoryID) || User.IsInRole(Constants.TL)) { var prefix = where.Compile(); if (User.IsInRole(Constants.TL)) { where = c => prefix(c) && c.CategoryID == user.CategoryId; } else if (!string.IsNullOrEmpty(model.CategoryID)) { where = c => prefix(c) && c.CategoryID.ToString() == model.CategoryID; } } if (!string.IsNullOrEmpty(model.ShiftID)) { var prefix = where.Compile(); where = c => prefix(c) && c.ShiftID.ToString() == model.ShiftID; } if (!string.IsNullOrEmpty(model.OnCallEscalateID)) { var prefix = where.Compile(); where = c => prefix(c) && c.onCallEscalateId.ToString() == model.OnCallEscalateID; } if (!string.IsNullOrEmpty(model.TypeID)) { var prefix = where.Compile(); where = c => prefix(c) && c.TypeID.ToString() == model.TypeID; } if (!string.IsNullOrEmpty(model.UserID) || User.IsInRole(Constants.USER)) { if (User.IsInRole(Constants.USER)) { var prefix = where.Compile(); where = c => prefix(c) && c.UserID.ToString() == user.Id; } else if (!string.IsNullOrEmpty(model.UserID)) { var prefix = where.Compile(); where = c => prefix(c) && c.UserID.ToString() == model.UserID; } } return(where); }
/// <summary> /// Triggers the unit report creation. /// </summary> public IEnumerable<IResult> GenerateUnitReports() { var dialog = new ReportGenerationViewModel(Dossier.RootUnit); DialogResult result = ShowDialog(dialog); List<UnitDecorator> units = dialog.MarkedUnits.ToList(); if (result != DialogResult.Ok || units.Count == 0) { yield break; } bool modelChanged = false; using (this._busyWatcher.GetTicket()) { yield return new AsyncResult( () => Parallel.ForEach( units.Where( unit => !unit.Reports.SourceCollection.Cast<ReportDecorator>() .Any(report => report.ScenarioName == SelectedReport.ScenarioName)), unit => { Execute.OnUIThread(unit.AddNewReport); ((ReportDecorator)unit.Reports.CurrentItem).ScenarioName = SelectedReport.ScenarioName; modelChanged = true; }), null, exception => ShowError(exception, Resources.UnableToGenerateReports)); if (modelChanged) { OnModelChanged(); } } }