private int CalculateWorkHoursInMonth(UserData user, int fullWorkHours) { int result = fullWorkHours; bool recalculateForStartDate = user.StartDate.HasValue && user.StartDate.Value.Year == _year && user.StartDate.Value.Month == _month && user.StartDate.Value.Day > 1; bool recalculateForTerminationDate = user.TerminationDate.HasValue && user.TerminationDate.Value.Year == _year && user.TerminationDate.Value.Month == _month; if (recalculateForStartDate || recalculateForTerminationDate) { DateTime startDate = recalculateForStartDate ? user.StartDate.Value : new DateTime(_year, _month, 1); DateTime terminationDate = recalculateForTerminationDate ? user.TerminationDate.Value : new DateTime(_year, _month, 1).AddMonths(1).AddDays(-1); MonthWorkHoursReporter userMonthWorkHoursReporter = new MonthWorkHoursReporter( _workHoursReporter, startDate, terminationDate); result = userMonthWorkHoursReporter.Report(); } return(result); }
protected override List <FoodStampData> CalculateReportData() { Logger.Info("Calculating food stamp data"); var entitledUsers = _usersActiveInMonthReporter.Report() .Where(x => x.GetContractType() == ContractType.Employee); var monthWorkDays = _monthWorkHoursReporter.Report() / 8; var absences = _absenceReporter.Report() .Where(x => x.Date.Month == _previousMonth && x.Date.Year == _previousYear) .ToList(); var result = entitledUsers.Select(x => { var absencesForAdjustment = absences.Count(a => a.UserName == x.Login && a.Hours >= HoursForAbsenceAdjustment); return(new FoodStampData { Month = _month, Year = _year, FirstName = x.FirstName, LastName = x.LastName, FoodStampCountEntitlement = monthWorkDays, AdjustmentForAbsences = absencesForAdjustment }); }); return(result.ToList()); }
protected override List <Overtime> CalculateReportData() { var users = _usersActiveInMonthReporter.Report(); var attendances = _attendanceReporter.Report(); var timeTrackingUsers = users.Where(x => x.IsTracking.HasValue && x.IsTracking.Value); var workHours = _workHoursReporter.Report(); Logger.Info("Calculating overtimes for {0} users", users.Count); var overtimes = attendances .Where(x => x.Date.Month == _month && x.Date.Year == _year) .GroupBy(x => x.User) .Join(timeTrackingUsers, gu => gu.Key, u => u.Login, (gu, u) => new Overtime { Login = gu.Key, HoursWorked = gu.Sum(x => x.HoursWorked), ContractType = u.ContractType, FirstName = u.FirstName, LastName = u.LastName, CostCenter = u.CostCenter, Month = _month, Year = _year, Absences = gu.Sum(x => x.AbsenceTotal), WorkHoursInMonth = CalculateWorkHoursInMonth(u, workHours) }) .ToList(); return(overtimes); }