public PartialViewResult Table(int month, int year, int departmentId, string userName,int? currentPage) { GraphicsListModel model = new GraphicsListModel { CurrentPage = currentPage.HasValue?currentPage.Value:0, DepartmentId = departmentId, Month = month, UserName = userName, Year = year, }; EmployeeBl.GetGraphicsListModel(model); return PartialView("Table", model); }
public ActionResult IndexPrint(int month, int year, int departmentId, string userName, int? currentPage) { GraphicsListModel model = new GraphicsListModel { Month=month, Year=year, DepartmentId=departmentId, UserName=userName, CurrentPage=currentPage.HasValue?currentPage.Value:0 }; model.ForPrint = false; ViewBag.HideLayout = true; return Index(model); }
public ActionResult Index(GraphicsListModel model) { if (model.ForPrint) { return GetPrintForm("Graphics", "IndexPrint", model.ToParamsString(), false); } EmployeeBl.SetupDepartment(model); EmployeeBl.GetGraphicsListModel(model); return View("Index",model); }
public ActionResult Index(/*int managerId,*/ int? month, int? year) { if (!month.HasValue) month = DateTime.Today.Month; if (!year.HasValue) year = DateTime.Today.Year; GraphicsListModel model = new GraphicsListModel { //ManagerId = managerId, Month = month.Value, Year = year.Value, }; EmployeeBl.SetupDepartment(model); EmployeeBl.GetGraphicsListModel(model); return View(model); }
public void SetGraphicsInfo(GraphicsListModel model) { IUser user = AuthenticationService.CurrentUser; Log.Debug("SetGraphicsInfo:Before GetRequestsForMonth"); IList<DayRequestsDto> dayDtoList = GetDayDtoList(model.Month, model.Year); IList<IdNameDtoWithDates> uDtoList = UserDao.GetUsersForManagerWithDatePagedForGraphics_NEW(user.Id, user.UserRole, dayDtoList.First().Day, dayDtoList.Last().Day , model.DepartmentId, model.UserName); Log.Debug("SetGraphicsInfo:After GetUsersForManagerWithDatePaged"); int userCount = uDtoList.Count; //model.TotalRecordsCount = userCount; int numberOfPages = Convert.ToInt32(Math.Ceiling((double)userCount / TimesheetPageSize)); int currentPage = model.CurrentPage; if (currentPage > numberOfPages) currentPage = numberOfPages; if (currentPage == 0) currentPage = 1; uDtoList = uDtoList .Skip((currentPage - 1) * TimesheetPageSize) .Take(TimesheetPageSize).ToList(); model.CurrentPage = currentPage; model.NumberOfPages = numberOfPages; if (userCount == 0) { model.Dtos = new List<TerraGraphicDto>(); return; } IList<WorkingCalendar> workDays = WorkingCalendarDao.GetEntitiesBetweenDates(model.Month, model.Year); IList<DayRequestsDto> dtos = TimesheetDao.GetRequestsForMonth (model.Month, model.Year, user.Id, user.UserRole, dayDtoList, uDtoList, workDays ,new List<TerraGraphicDbDto>(),false); Log.Debug("SetGraphicsInfo:After GetRequestsForMonth"); List<int> allUserIds = new List<int>(); allUserIds = dtos.Aggregate(allUserIds, (current, dayRequestsDto) => current.Union(dayRequestsDto.Requests.Select(x => x.UserId).Distinct().ToList()) .ToList()); Log.Debug("SetGraphicsInfo:After aggregate"); /*List<IdNameDto> userNameDtoList = new List<IdNameDto>(); foreach (int userId in allUserIds) { foreach (var dayRequestsDto in dtos) { RequestDto dto = dayRequestsDto.Requests.Where(y => y.UserId == userId).FirstOrDefault(); if (dto != null) { userNameDtoList.Add(new IdNameDto { Id = userId, Name = dto.UserName }); break; } } }*/ //userNameDtoList = userNameDtoList.OrderBy(x => x.Name).ToList(); IList<User> users = UserDao.LoadForIdsList(allUserIds); allUserIds = users.ToList().ConvertAll(x => x.Id).ToList(); Log.Debug("SetGraphicsInfo:After create ordered user dto list "); List<TerraGraphicDto> list = new List<TerraGraphicDto>(); IList<TerraGraphicDbDto> tgList = TerraGraphicDao.LoadDtoForIdsList(allUserIds,model.Month, model.Year); foreach (int userId in allUserIds) { TerraGraphicDto dto = new TerraGraphicDto(); List<TerraGraphicDayDto> userDayList = new List<TerraGraphicDayDto>(); DateTime beginUserDate = dayDtoList.First().Day; DateTime endUserDate = dayDtoList.Last().Day; foreach (var dayRequestsDto in dtos) { List<RequestDto> userList = dayRequestsDto.Requests.Where(x => x.UserId == userId).ToList(); decimal? hours = new decimal?(); TerraGraphicDbDto graphicEntity = tgList.Where(x => x.UserId == userId && x.Day == dayRequestsDto.Day).FirstOrDefault(); if(graphicEntity != null) hours = graphicEntity.Hours; /*string status = userList.Aggregate(string.Empty, (curr, requestDto) => curr + requestDto.TimesheetCode + "/");*/ /*if (graphicEntity == null) { RequestDto rDto = userList.Where(x => x.TimesheetHours.HasValue).FirstOrDefault(); if (rDto != null) hours = rDto.TimesheetHours.Value; } else hours = graphicEntity.Hours;*/ RequestDto employmentDay = userList.Where(x => x.IsEmploymentDay).FirstOrDefault(); if (employmentDay != null && employmentDay.BeginDate > beginUserDate) beginUserDate = employmentDay.BeginDate; RequestDto dismissalDay = userList.Where(x => x.IsDismissalDay).FirstOrDefault(); if (dismissalDay != null && dismissalDay.EndDate < endUserDate) endUserDate = dismissalDay.EndDate; bool? isCredit = new bool?(); if (graphicEntity != null) isCredit = graphicEntity.IsCreditAvailable; bool? isFactCredit = new bool?(); if (graphicEntity != null) isFactCredit = graphicEntity.IsFactCreditAvailable; userDayList.Add(new TerraGraphicDayDto { Number = dayRequestsDto.Day.Day, Day = dayRequestsDto.Day.ToString("dd.MM.yyyy"), isHoliday = CoreUtils.IsDayHoliday(workDays, dayRequestsDto.Day), Hours = hours, Id = graphicEntity == null ? 0 : graphicEntity.Id, IsCredits = isCredit.HasValue?isCredit.Value?"Да":"Нет":string.Empty, IsFactCredits = isFactCredit.HasValue ? isFactCredit.Value ? "Да" : "Нет" : string.Empty, TerraPointId = graphicEntity == null || !graphicEntity.PointId.HasValue ? 0 : graphicEntity.PointId, TerraPointName = graphicEntity == null || !graphicEntity.PointId.HasValue ? string.Empty : (string.IsNullOrEmpty(graphicEntity.PointName) ? "!" : graphicEntity.PointName), TerraPointTitle = graphicEntity == null ? string.Empty:graphicEntity.PointTitle, IsEditable = (user.UserRole & UserRole.Manager) == UserRole.Manager, FactHours = dayRequestsDto.Day.Date > DateTime.Today || graphicEntity == null ? null : graphicEntity.FactHours, FactPointTitle = dayRequestsDto.Day.Date > DateTime.Today || graphicEntity == null || !graphicEntity.FactPointId.HasValue ? string.Empty : graphicEntity.FactPointTitle, FactPointName = dayRequestsDto.Day.Date > DateTime.Today || graphicEntity == null || !graphicEntity.FactPointId.HasValue ? string.Empty : (string.IsNullOrEmpty(graphicEntity.FactPointName) ? "!" : graphicEntity.FactPointName), //TabelStatus = status.Substring(0, status.Length - 1), }); } userDayList.Insert(0,new TerraGraphicDayDto { Number = 0, isStatRecord = true, isHoliday = false, StatCode = string.Empty, IsCredits = "Кредиты", IsFactCredits = "Кредиты факт", TerraPointName = "Точка план", FactPointName = "Точка факт", //TabelStatus = "Табель", }); decimal? planHours = userDayList.Sum(x => x.Hours); decimal? factHours = userDayList.Sum(x => x.FactHours); int? workdaysSum = workDays.Where(x => x.Date >= beginUserDate && x.Date <= endUserDate).Sum(x => x.IsWorkingHours); userDayList.Add(new TerraGraphicDayDto { Number = 0, isStatRecord = true, isHoliday = false, Hours = workdaysSum, StatCode = "Б", }); userDayList.Add(new TerraGraphicDayDto { Number = 0, isStatRecord = true, isHoliday = false, Hours = planHours, StatCode = "План", FactHours = factHours, }); User usr = users.Where(x => x.Id == userId).FirstOrDefault(); if (usr == null) throw new ArgumentException(string.Format("Не найден пользователь с id {0}", userId)); dto.MonthAndYear = GetMonthName(model.Month) + " " + model.Year; dto.UserNameAndCode = usr.Name; dto.UserId = userId; dto.Days = userDayList; dto.Postion = string.IsNullOrEmpty(usr.Position.Name) ? string.Empty : usr.Position.Name.Trim(); dto.Rate = usr.Rate.HasValue ? usr.Rate.Value.ToString() : string.Empty; list.Add(dto); } Log.Debug("SetGraphicsInfo:After foreach"); model.Dtos = list; }
public void GetGraphicsListModel(GraphicsListModel model) { SetListboxes(model); SetGraphicsInfo(model); UserRole role = CurrentUser.UserRole; model.IsSetShortNamesAvailable = ((role & UserRole.Manager) > 0) || (role & UserRole.OutsourcingManager) > 0 || (role & UserRole.Estimator) >0 ; model.IsShortNamesEditable = ((role & UserRole.Manager) > 0); }