public EmployeeTimeModel GetEmployeeMonthReport(Employee employee, int year, int month) { //TOTAL HOURS IN DASHBOARD - MONTHLY THEORETICAL WORKING HOURS EmployeeTimeModel employeeReport = new EmployeeTimeModel(_dayTypes); employeeReport.Employee = employee.Master(); List <DayModel> calendar = GetEmployeeMonth(employee, year, month); //this is to shorten down the Dictionary name Dictionary <string, decimal> hours = employeeReport.HourTypes; foreach (DayModel day in calendar) { if (day.DayType.Name == "Empty") { hours["Missing entries"] += 8; } if (_dayTypes.FirstOrDefault(x => x == day.DayType.Name) != null) { /*The Get method in the generic Repository throws an exception if the entity isn't found, * so it is necessary to try to get the daytype from the database.*/ hours[day.DayType.Name] += day.TotalHours; employeeReport.TotalHours += day.TotalHours; //Is it better for this to be in a separate method, considering the application performance? if (day.IsWorkday()) { employeeReport.AddOvertime(day); } /*if the total recorded hours for a Workday are less than 8, the difference is added to the missing entries*/ /*If tasks are added to weekend day, the day is saved as a workday. In that case, it is not necessary to add * the difference to the missing entries*/ if (day.TotalHours < 8 && !day.IsWeekend()) //is this necessary? SHOULD WE DELETE IT? { hours["Missing entries"] += 8 - day.TotalHours; } //Any additional day types to be added as paid time off? Other (Id = 7)? if (!day.IsWorkday()) { employeeReport.PaidTimeOff += day.TotalHours; } } } //hours["Missing entries"] = calendar.FindAll(x => x.DayType.Name == "Empty").Count() * 8; //Missing entries are included in the Total hours sum employeeReport.TotalHours += hours["Missing entries"]; return(employeeReport); }
public static void AddOvertime(this EmployeeTimeModel employeeTime, DayModel day) { //Overtime isn't included in the TotalHours calculation if (day.TotalHours > 8) { employeeTime.Overtime += day.TotalHours - 8; employeeTime.TotalHours -= day.TotalHours - 8; } //Any weekend working hours will be added to overtime. Any weekend day that has tasks (working hours), is set to DayType "Workday" if (day.IsWeekend()) { employeeTime.Overtime += day.TotalHours; employeeTime.TotalHours -= day.TotalHours; } }
public async Task <TeamTimeModel> GeTeamReport(int teamId, int year, int month) { Team team = await _unit.Teams.Get(teamId); TeamTimeModel result = new TeamTimeModel { Team = team.Master() }; List <int> members = team.Members.Select(m => m.Employee.Id).ToList(); foreach (int empId in members) { EmployeeTimeModel e = await GetEmployeeReport(empId, year, month); if (e.TotalHours != 0) { result.Employees.Add(e); } } return(result); }
public async Task <EmployeeTimeModel> GetEmployeeReport(int empId, int year, int month) { Employee emp = await _unit.People.Get(empId); EmployeeTimeModel result = new EmployeeTimeModel { Employee = emp.Master() }; List <Day> list = emp.Calendar.Where(c => c.Date.Month == month && c.Date.Year == year).ToList(); var query = list.GroupBy(c => c.DayType.ToString()).Select(d => new { type = d.Key, hours = d.Sum(h => h.TotalHours) }); foreach (var d in query) { result.HourTypes[d.type] = d.hours; } result.TotalHours = list.Sum(h => h.TotalHours); result.PTOHours = list.Where(d => d.DayType != DayType.Workday).Sum(h => h.TotalHours); result.Overtime = list.Where(d => d.Date.Weekend()).Sum(h => h.TotalHours) + list.Where(d => !d.Date.Weekend() && d.TotalHours > 8).Sum(h => (h.TotalHours - 8)); return(result); }
/*This method is for manual creation of the assertion employee time models. * The calculated hours assigned were calculated using queries in PostgreSQL*/ private List <EmployeeTimeModel> CreateEmployeeTimeModels() { List <EmployeeTimeModel> employeeTimes = new List <EmployeeTimeModel>(); List <string> dayTypes = unit.DayTypes.Get().Select(x => x.Name).ToList(); // //ASSERT EMPLOYEE NR. 1 - id nr 2 - William Brown // int firstEmployeeId = 2; //This test employee has only 12 work hours in the test database EmployeeTimeModel firstEmployee = new EmployeeTimeModel(dayTypes); firstEmployee.Employee = unit.Employees.Get(firstEmployeeId).Master(); //SetHourTypes(firstEmployee.HourTypes); firstEmployee.HourTypes["Workday"] = 120; firstEmployee.HourTypes["Holiday"] = 16; firstEmployee.HourTypes["Vacation"] = 40; //6 actual weekend days in the calendar = 48 hours /*There are in fact 22 day entries in the Calendar table, plus the 8 weekend days for january 2018 which aren't saved in the database, * should make a total of 30 days entered. This should mean that there is 1 missing entry (31 total days for january). * But, 2 of those 8 weekend days are entered as holidays, which ARE saved in the database. * This means that there are actually 3 missing entries = 24 hours*/ //Technically, holidays/vacations aren't paid if they happen to be on a weekend, and thus should not be saved! firstEmployee.HourTypes["Missing entries"] = 24; firstEmployee.TotalHours = 200; //Total hours + Weekends for the month = 248 firstEmployee.PaidTimeOff = firstEmployee.HourTypes["Holiday"] + firstEmployee.HourTypes["Vacation"]; employeeTimes.Add(firstEmployee); // //ASSERT EMPLOYEE NR. 2 - Id nr 41 - Laura Parker // int secondEmployeeId = 41; EmployeeTimeModel secondEmployee = new EmployeeTimeModel(dayTypes); secondEmployee.Employee = unit.Employees.Get(secondEmployeeId).Master(); //SetHourTypes(secondEmployee.HourTypes); secondEmployee.HourTypes["Workday"] = 215; secondEmployee.HourTypes["Holiday"] = 0; secondEmployee.HourTypes["Vacation"] = 0; //4 actual weekend days in the calendar = 32 hours /*There are in fact 22 day entries in the Calendar table, plus the 8 weekend days for january 2018 which aren't saved in the database, * should make a total of 30 days entered. This should mean that there is 1 missing entry (31 total days for january). * But, 2 of those 8 weekend days are entered as holidays, which ARE saved in the database. * This means that there are actually 3 missing entries = 24 hours*/ //Technically, holidays/vacations aren't paid if they happen to be on a weekend, and thus should not be saved! secondEmployee.HourTypes["Missing entries"] = 0; secondEmployee.TotalHours = 215; //Total hours + Weekends for the month = 247 secondEmployee.Overtime = 24 + 15; //Weekend hours = 15 secondEmployee.PaidTimeOff = secondEmployee.HourTypes["Holiday"] + secondEmployee.HourTypes["Vacation"]; employeeTimes.Add(secondEmployee); return(employeeTimes); }