Exemplo n.º 1
0
        protected virtual IEnumerable <AttendanceViewModel> GetAttendance(string startDate, string endDate, int employeeId)
        {
            //do not display the edit link if attendance date < last payroll date
            var nextPayrollDate = _employeePayrollRepository.GetNextPayrollStartDate(); //this is actually the last payroll date
            var lastPayrollDate = nextPayrollDate ?? DateTime.MinValue;
            var sDate           = startDate.ToDateTime();
            var eDate           = endDate.ToDateTime();

            var holidays = _holidayRepository.Find(x => x.IsActive && x.Date >= sDate && x.Date <= eDate).ToList();

            Func <IEnumerable <EmployeeHours>, bool> isNotEmpty = x => x != null && x.Any(y => y != null);
            Func <DateTime, bool> isHoliday        = x => holidays.Any(y => y.Date == x.Date);
            Func <DateTime, bool> isRegularHoliday = x =>
            {
                var holiday = holidays.FirstOrDefault(y => y.Date == x.Date);
                return(holiday != null ? holiday.IsRegularHoliday : false);
            };

            var result    = _attendanceService.GetAttendanceAndHoursByDate(sDate, eDate, employeeId).ToList();
            var viewModel = result.MapCollection <AttendanceDao, AttendanceViewModel>((s, d) =>
            {
                d.Editable          = s.ClockIn > lastPayrollDate;
                d.RegularHours      = isNotEmpty(s.EmployeeHours) ? s.EmployeeHours.Where(x => x.Type == RateType.Regular).Sum(x => x.Hours) : 0;
                d.Overtime          = isNotEmpty(s.EmployeeHours) ? s.EmployeeHours.Where(x => x.Type == RateType.OverTime).Sum(x => x.Hours) : 0;
                d.NightDifferential = isNotEmpty(s.EmployeeHours) ? s.EmployeeHours.Where(x => x.Type == RateType.NightDifferential).Sum(x => x.Hours) : 0;
                d.IsHoliday         = isHoliday(s.ClockIn);
                d.IsRegularHoliday  = isRegularHoliday(s.ClockIn);
                d.Breakdown         = s.EmployeeHours.Where(x => x != null).ToList().GroupBy(x => x.Date).Select(x => new AttendanceBreakdownViewModel
                {
                    Date = x.Key,
                    NightDifferential = isNotEmpty(x) ? x.Where(y => y.Type == RateType.NightDifferential).Sum(y => y.Hours) : 0,
                    Overtime          = isNotEmpty(x) ?  x.Where(y => y.Type == RateType.OverTime).Sum(y => y.Hours) : 0,
                    RegularHours      = isNotEmpty(x) ? x.Where(y => y.Type == RateType.Regular).Sum(y => y.Hours) : 0,
                    IsHoliday         = isHoliday(x.Key),
                    IsRegularHoliday  = isRegularHoliday(x.Key)
                });
            });

            return(viewModel);
        }
Exemplo n.º 2
0
 //
 // GET: /Holiday/Edit/5
 public ActionResult Edit(int id)
 {
     var holiday = _holidayRepository.Find(id);
     return View(AutoMapper.Mapper.Map<Holiday, HolidayModel>(holiday));
 }