コード例 #1
0
ファイル: EmployeeController.cs プロジェクト: andreyu/Reports
        public FileResult TimesheetListExcel(TimesheetListModel model)
        {
            EmployeeBl.GetTimesheetListModel(model);
            string result = "";
            bool RowFirst = true;
            foreach (var dto in model.TimesheetDtos)
            {
                string row1 = "<tr><td>ФИО сотрудника</td><td>Календарные дни месяца</td>";
                string row2 = "<tr><td>" + dto.UserNameAndCode + "</td><td>Рабочие дни</td>";
                string row3 = "<tr><td>" + dto.UserNameAndCode + "</td><td>Рабочие часы</td>";
                string row4 = "<tr><td>" + dto.UserNameAndCode + "</td><td>Фактические часы</td>";
                foreach (var day in dto.Days)
                {
                    row1 += "<td>" + (day.isStatRecord ? day.StatCode : day.Number.ToString()) + "</td>";
                    row2 += "<td>" + day.Status + "</td>";
                    row3 += "<td>" + day.Hours + "</td>";
                    row4 += "<td>" + day.Graphic + "</td>";

                }
                row1 += "</tr>";
                row2 += "</tr>";
                row3 += "</tr>";
                row4 += "</tr>";
                result += RowFirst? row1:"" + row2 + row3 + row4;
                RowFirst = false;
            }
            result += "";
            return base.Excel(result);
            //if(!ValidateModel(model))
            //{
            //    EmployeeBl.GetTimesheetListModel(model);
            //    return View(model);
            //}
            //CorrectHours(model);
            ////EmployeeBl.SetTimesheetsHours(model);
            //return View(model);
        }
コード例 #2
0
ファイル: EmployeeController.cs プロジェクト: andreyu/Reports
 /*protected void CorrectHours(TimesheetListModel model)
 {
     float hours = model.Hours;
     hours = (float)Math.Round(hours * 100) / 100;
     if (hours != model.Hours)
     {
         model.Hours = hours;
         if (ModelState.ContainsKey("Hours"))
             ModelState.Remove("Hours");
     }
 }*/
 protected bool ValidateModel(TimesheetListModel model)
 {
     if(!ValidateTimeSheets(model.TimesheetDtos))
         ModelState.AddModelError(string.Empty, "Указаны недопустимые значения рабочего времени.Значения должны быть от 0 до 24 или пустыми.");
     return ModelState.IsValid;
 }
コード例 #3
0
ファイル: EmployeeController.cs プロジェクト: andreyu/Reports
        public ActionResult TimesheetList(TimesheetListModel model)
        {
            if(model.IsSaveNeed)
            {
                if(!ValidateModel(model))
                {
                    EmployeeBl.SetListboxes(model);
                    return View(model);
                }

                model.IsSaveNeed = false;
                EmployeeBl.SaveGraphicsRecord(model);
            }
            EmployeeBl.GetTimesheetListModel(model);
            return View(model);
            //if(!ValidateModel(model))
            //{
            //    EmployeeBl.GetTimesheetListModel(model);
            //    return View(model);
            //}
            //CorrectHours(model);
            ////EmployeeBl.SetTimesheetsHours(model);
            //return View(model);
        }
コード例 #4
0
ファイル: EmployeeController.cs プロジェクト: andreyu/Reports
 public ActionResult TimesheetList(int managerId, int? month, int? year)
 {
     if (!month.HasValue)
         month = DateTime.Today.Month;
     if(!year.HasValue)
         year = DateTime.Today.Year;
     TimesheetListModel model = new TimesheetListModel
         {
             ManagerId = managerId,
             Month = month.Value,
             Year = year.Value,
             //DepartmentId = departmentId.HasValue? departmentId.Value:0,
             //DepartmentName = departmentName,
             //CurrentPage = currentPage.HasValue?currentPage.Value:0,
             //UserName = userName,
             //IsEditable = false,
         };
     EmployeeBl.SetupDepartment(model);
     EmployeeBl.GetTimesheetListModel(model);
     return View(model);
 }
コード例 #5
0
ファイル: EmployeeBl.cs プロジェクト: andreyu/Reports
 public void SaveGraphicsRecord(TimesheetListModel model)
 {
     Log.Debug("Before save WorkingGraphic records.");
     List<int> userIds = model.TimesheetDtos.ToList().ConvertAll(x => x.UserId);
     IList<WorkingGraphic> list = WorkingGraphicDao.LoadForIdsList(userIds,
                                                   model.Month, model.Year);
     foreach (TimesheetDto dto in model.TimesheetDtos)
     {
         foreach (TimesheetDayDto day in dto.Days)
         {
             if (day.isStatRecord)
                 continue;
             float? graphicHours = null;
             if (!string.IsNullOrEmpty(day.Graphic))
             {
                 double value;
                 if (double.TryParse(day.Graphic, out value))
                     graphicHours = (float) value;
                 else
                     Log.WarnFormat("Cannot parse day.Graphic {0}", day.Graphic);
             }
             WorkingGraphic entity;
             if(day.Id == 0)
             {
                 entity = new WorkingGraphic
                 {
                     Day = new DateTime(model.Year, model.Month, day.Number),
                     Hours = graphicHours,
                     UserId = dto.UserId,
                 };
             }
             else
             {
                 entity = list.Where(x => x.Id == day.Id).FirstOrDefault();
                 if(entity == null)
                     throw new ArgumentException(string.Format("Не могу найти запись о рабочем графике с Id {0}",day.Id));
                 entity.Hours = graphicHours;
             }
             WorkingGraphicDao.Save(entity);
         }
         WorkingGraphicDao.Flush();
     }
     Log.Debug("After save WorkingGraphic records.");
 }
コード例 #6
0
ファイル: EmployeeBl.cs プロジェクト: andreyu/Reports
 public void GetTimesheetListModel(TimesheetListModel model)
 {
     SetListboxes(model);
     SetTimesheetsInfo(model);
 }
コード例 #7
0
ファイル: EmployeeBl.cs プロジェクト: andreyu/Reports
        protected void SetTimesheetsInfo(TimesheetListModel model)
        {
            IUser user = AuthenticationService.CurrentUser;
            Log.Debug("Before GetRequestsForMonth");

            IList<DayRequestsDto> dayDtoList = GetDayDtoList(model.Month, model.Year);
            IList<IdNameDtoWithDates> uDtoList =
                UserDao.GetUsersForManagerWithDatePaged(user.Id, user.UserRole,
                        dayDtoList.First().Day, dayDtoList.Last().Day
                        ,model.DepartmentId,model.UserName);
            Log.Debug("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.TimesheetDtos = new List<TimesheetDto>();
                model.IsSaveVisible = false;
                return;
            }
            List<int> usIds = uDtoList.Select(x => x.Id).ToList();
            IList<WorkingCalendar> workDays = WorkingCalendarDao.GetEntitiesBetweenDates(model.Month, model.Year);
            //IList<TerraGraphicDbDto> tgList = TerraGraphicDao.LoadDtoForIdsList(usIds, model.Month, model.Year);
            IList<DayRequestsDto> dtos = TimesheetDao.GetRequestsForMonth
                (model.Month, model.Year, user.Id, user.UserRole,dayDtoList,uDtoList,workDays,
                /*tgList*/new List<TerraGraphicDbDto>(), true);
            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>();
            //List<int> userIds = userNameDtoList.ConvertAll(x => x.Id);
            IList<WorkingGraphic> wgList = WorkingGraphicDao.LoadForIdsList(allUserIds,
                                                                            model.Month, model.Year);
            IList<WorkingGraphicTypeDto>  wgtList = WorkingGraphicTypeDao.GetWorkingGraphicTypeDtoForUsers(allUserIds);

            foreach (int userId in allUserIds)
            {
                //dtos.Where(x => x.Requests.Where(y => y.UserId == userId))
                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 = dayDtoList.First().Day;
                DateTime endUserDate = dayDtoList.Last().Day;
                foreach (var dayRequestsDto in dtos)
                {
                    List<RequestDto> userList = dayRequestsDto.Requests.Where(x => x.UserId == userId).ToList();
                    string status = userList.Aggregate(string.Empty,
                                                       (curr, requestDto) => curr + requestDto.TimesheetCode + "/");
                    string hours = userList.Aggregate(string.Empty,
                                                      (curr, requestDto) =>
                                                      curr +
                                                      (requestDto.TimesheetHours.HasValue
                                                           ? requestDto.TimesheetHours.Value.ToString()
                                                           : " ") + "/");
                    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;
                    string graphic = string.Empty;
                    if(wgHours.HasValue)
                    {
                         graphic = (int)wgHours.Value == wgHours.Value
                                ? ((int)wgHours.Value).ToString()
                                : wgHours.Value.ToString("0.0");
                    }
                    userDayList.Add(new TimesheetDayDto
                                                 {
                                                     Number = dayRequestsDto.Day.Day,
                                                     isHoliday = CoreUtils.IsDayHoliday(workDays,dayRequestsDto.Day),
                                                     Status = status.Substring(0,status.Length -1),
                                                     Hours = hours.Substring(0, hours.Length - 1),
                                                     Graphic = graphic,
                                                     Id = graphicEntity == null?0:graphicEntity.Id,
                                                 });
                    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 = "Б",
                    });
                    //WorkingDaysConstant wdk = WorkingDaysConstantDao.LoadDataForMonth(model.Month, model.Year);
                    //if (wdk == null)
                    //    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.Days.ToString(),
                    //        Hours = wdk.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.MonthAndYear = GetMonthName(model.Month) + " " + model.Year;
                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 = (user.UserRole & UserRole.Manager) == UserRole.Manager;
                list.Add(dto);
            }
            Log.Debug("After foreach");
            model.TimesheetDtos = list;
            model.IsSaveVisible = list.Count > 0 && (user.UserRole & UserRole.Manager) == UserRole.Manager;
        }