Exemplo n.º 1
0
 protected bool ValidateModel(TimesheetYearListModel model)
 {
     DateTime today = DateTime.Today;
     if (!model.BeginDate.HasValue)
     {
         ModelState.Remove("BeginDate");
         model.BeginDate = model.EndDate.HasValue ?
             new DateTime(model.EndDate.Value.Year, model.EndDate.Value.Month, 1) :
             new DateTime(today.Year, today.Month, 1);
     }
     if (!model.EndDate.HasValue)
     {
         ModelState.Remove("EndDate");
         model.EndDate = new DateTime(model.BeginDate.Value.Year, model.BeginDate.Value.Month, 1).AddMonths(1).AddDays(-1);
     }
     if (model.BeginDate.Value > model.EndDate.Value)
         ModelState.AddModelError("BeginDate", "Дата в поле <Период с> не может быть больше даты в поле <по>.");
     return ModelState.IsValid;
 }
Exemplo n.º 2
0
 public ActionResult TimesheetYearList(TimesheetYearListModel model)
 {
     if(!ValidateModel(model))
     {
         model.DatesPeriod = string.Empty;
         model.CurrentPage = 0;
         model.NumberOfPages = 0;
         model.TimesheetDtos = new List<TimesheetDto>();
         return View(model);
     }
     EmployeeBl.GetTimesheetListModel(model);
     return View(model);
 }
Exemplo n.º 3
0
 public void GetTimesheetListModel(TimesheetYearListModel model)
 {
     SetYearTimesheetsInfo(model);
 }
Exemplo n.º 4
0
 public ActionResult TimesheetYearList(int managerId)
 {
     TimesheetYearListModel model = new TimesheetYearListModel
     {
         ManagerId = managerId,
     };
     EmployeeBl.SetupDepartment(model);
     SetInitialDates(model);
     EmployeeBl.GetTimesheetListModel(model);
     return View(model);
 }
Exemplo n.º 5
0
        protected void SetYearTimesheetsInfo(TimesheetYearListModel model)
        {
            IUser user = AuthenticationService.CurrentUser;

            Log.Debug("Before GetRequestsForMonth");
            DateTime beginDate = model.BeginDate.Value;
            DateTime endDate = model.EndDate.Value;
            IList<DayRequestsDto> dayDtoList = GetDayDtoList(beginDate,endDate);
            model.DatesPeriod = string.Format("Период: {0} - {1}", beginDate.ToString("dd MMMM yyyy"), endDate.ToString("dd MMMM yyyy"));
            IList<IdNameDtoWithDates> uDtoList =
                UserDao.GetUsersForManagerWithDatePaged(user.Id, user.UserRole,beginDate, endDate, model.DepartmentId, model.UserName);
            Log.Debug("After GetUsersForManagerWithDatePaged");
            int userCount = uDtoList.Count;
            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.TimesheetDtos = new List<TimesheetDto>();
                //model.IsSaveVisible = false;
                return;
            }
            List<int> usIds = uDtoList.Select(x => x.Id).ToList();
            IList<WorkingCalendar> workDays = WorkingCalendarDao.GetEntitiesBetweenDates(beginDate, endDate);
            //IList<TerraGraphicDbDto> tgList = TerraGraphicDao.LoadDtoForIdsList(usIds,beginDate,endDate);

            IList<DayRequestsDto> dtos = TimesheetDao.GetRequestsForYear
                (beginDate, endDate, user.Id, user.UserRole, dayDtoList, uDtoList, workDays,/*tgList*/new List<TerraGraphicDbDto>());
            Log.Debug("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("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();
            allUserIds = userNameDtoList.ToList().ConvertAll(x => x.Id).ToList();
            Log.Debug("After create ordered user dto list ");
            List<TimesheetDto> list = new List<TimesheetDto>();
            IList<WorkingGraphic> wgList = WorkingGraphicDao.LoadForIdsList(allUserIds,beginDate, endDate);
            IList<WorkingGraphicTypeDto> wgtList = WorkingGraphicTypeDao.GetWorkingGraphicTypeDtoForUsers(allUserIds);
            foreach (int userId in allUserIds)
            {
                TimesheetDto dto = new TimesheetDto();
                List<RequestDto> userDtoList = new List<RequestDto>();
                List<TimesheetDayDto> userDayList = new List<TimesheetDayDto>();
                IdNameDtoWithDates uDto = uDtoList.Where(x => x.Id == userId).FirstOrDefault();

                float wgHoursSum = 0;
                DateTime beginUserDate = beginDate;
                DateTime endUserDate = endDate;
                foreach (var dayRequestsDto in dtos)
                {
                    List<RequestDto> userList = dayRequestsDto.Requests.Where(x => x.UserId == userId).ToList();
                    float? wgHours;
                    WorkingGraphic graphicEntity = wgList.Where(x => x.UserId == userId &&
                                                               x.Day == dayRequestsDto.Day).FirstOrDefault();
                    wgHours = graphicEntity == null ?
                        GetDefaultGraphicsForUser(wgtList, workDays, userId, dayRequestsDto.Day)
                        : graphicEntity.Hours;
                    wgHoursSum += wgHours.HasValue ? wgHours.Value : 0;
                    userDtoList.AddRange(userList);
                    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;
                }
                if ((user.UserRole & UserRole.Employee) != UserRole.Employee && uDto != null)
                {
                    int? workdaysSum = workDays.Where(x => x.Date >= beginUserDate && x.Date <= endUserDate).Sum(x => x.IsWorkingHours);
                    int daySum = workDays.Where(x => x.Date >= beginUserDate && x.Date <= endUserDate && x.IsWorkingHours.HasValue).Count();
                    userDayList.Add(new TimesheetDayDto
                    {
                        Number = 0,
                        isStatRecord = true,
                        isHoliday = false,
                        Status = daySum.ToString(),
                        Hours = workdaysSum.Value.ToString(),
                        StatCode = "Б",
                    });

                    //List<WorkingDaysConstant> wdk = WorkingDaysConstantDao.LoadDataForDates(beginDate,endDate);
                    //if (wdk == null || wdk.Count == 0)
                    //    userDayList.Add(new TimesheetDayDto
                    //    {
                    //        Number = 0,
                    //        isStatRecord = true,
                    //        isHoliday = false,
                    //        Status = string.Empty,
                    //        Hours = string.Empty,
                    //        StatCode = "Б",
                    //    });
                    //else
                    //    userDayList.Add(new TimesheetDayDto
                    //    {
                    //        Number = 0,
                    //        isStatRecord = true,
                    //        isHoliday = false,
                    //        Status = wdk.Sum(x => x.Days).ToString(),
                    //        Hours = wdk.Sum(x => x.Hours).ToString(),
                    //        StatCode = "Б",
                    //    });
                    int sumDays = 0;
                    decimal sum = 0;
                    string graphic = null;
                    for (int i = 0; i < 5; i++)
                    {

                        if (i == 0)
                        {
                            graphic = (int)wgHoursSum == wgHoursSum
                               ? ((int)wgHoursSum).ToString()
                               : wgHoursSum.ToString("0.0");
                        }
                        sum += uDto.userStats[i];
                        sumDays += uDto.userStatsDays[i];
                        userDayList.Add(new TimesheetDayDto
                        {
                            Number = 0,
                            isHoliday = false,
                            isStatRecord = true,
                            Status = uDto.userStatsDays[i].ToString(),
                            Hours = uDto.userStats[i].ToString(),
                            StatCode = GetStatCodeName(i),
                            Graphic = i == 0 ? graphic : null,
                        });
                    }
                    userDayList.Add(new TimesheetDayDto
                    {
                        Number = 0,
                        isHoliday = false,
                        isStatRecord = true,
                        Status = sumDays.ToString(),
                        Hours = sum.ToString(),
                        StatCode = "Всего",
                        Graphic = graphic,
                    });
                }
                dto.UserNameAndCode = userDtoList.First().UserName;
                dto.UserId = userId;
                dto.Days = userDayList;
                dto.IsHoursVisible = (user.UserRole & UserRole.Employee) != UserRole.Employee;
                dto.IsGraphicVisible = (user.UserRole & UserRole.Employee) != UserRole.Employee;
                dto.IsGraphicEditable = false;
                list.Add(dto);
            }
            Log.Debug("After foreach");
            model.TimesheetDtos = list;
        }