public int GenerateEmployeeHours(DateTime fromDate, DateTime toDate) { //Get all active employee with the same frequency var employees = _employeeInfoService.GetAllActive(); //Delete existing entries with the same date //var employeeHoursList = this.GetByDateRange(fromDate, toDate); //_employeeHoursRepository.DeleteAll(employeeHoursList); //_unitOfWork.Commit(); foreach (var employee in employees) { employeeWorkSchedule = _employeeWorkScheduleService.GetByEmployeeId(employee.EmployeeId); //Will not compute if work schedule is null if (employeeWorkSchedule != null) { foreach (DateTime d in DatetimeExtension.EachDay(fromDate, toDate)) { ComputeEmployeeHours(d, employee.EmployeeId); } } } _unitOfWork.Commit(); return(0); }
public int GenerateEmployeeHours(DateTime fromDate, DateTime toDate) { //Get all active employee with the same frequency var employees = _employeeInfoService.GetAllActive(); //Delete existing entries with the same date var employeeHoursList = this.GetByDateRange(fromDate, toDate); _employeeHoursRepository.DeleteAll(employeeHoursList); _unitOfWork.Commit(); foreach (var employee in employees) { employeeWorkSchedule = _employeeWorkScheduleService.GetByEmployeeId(employee.EmployeeId); //Will not compute if work schedule is null if (employeeWorkSchedule != null) { foreach (DateTime d in DatetimeExtension.EachDay(fromDate, toDate)) { day = d; //Get all employee attendance within date range // Will not include attendance without clockout IList <Attendance> attendanceList = _attendanceService .GetAttendanceForProcessing(employee.EmployeeId, day); ComputeEmployeeHours(attendanceList, day); } } } _unitOfWork.Commit(); return(0); }
public EmployeeWorkSchedule Add(int workScheduleId, int employeeId) { var employeeWorkSchedule = new EmployeeWorkSchedule { EmployeeId = employeeId, WorkScheduleId = workScheduleId }; return(_employeeWorkScheduleRepository.Add(employeeWorkSchedule)); }
public int GenerateEmployeeHours(DateTime fromDate, DateTime toDate, int employeeId) { employeeWorkSchedule = _employeeWorkScheduleService.GetByEmployeeId(employeeId); //Will not compute if work schedule is null if (employeeWorkSchedule != null) { foreach (DateTime d in DatetimeExtension.EachDay(fromDate, toDate)) { ComputeEmployeeHours(d, employeeId); } } _unitOfWork.Commit(); return(0); }
public void ComputeEmployeeHours(DateTime day, int employeeId) { if (employeeWorkSchedule == null) { employeeWorkSchedule = _employeeWorkScheduleService.GetByEmployeeId(employeeId); } if (employeeWorkSchedule == null) { throw new Exception("Employee does not have work schedule"); } this.day = day; //Get all employee attendance within date range // Will not include attendance without clockout var attendanceList = _attendanceService.GetAttendanceForProcessing(employeeId, day); ComputeEmployeeHours(attendanceList, day); }
//[TestMethod] public void GenerateEmployeeDailySalaryByDateRangeHolidayNoWork2() { //Arrange Initialize(); DeleteData(); var employee = new Employee { EmployeeCode = "11001", FirstName = "Jona", LastName = "Pereira", MiddleName = "Aprecio", BirthDate = DateTime.Parse("02/02/1991"), Gender = 1, IsActive = true }; var employee2 = new Employee { EmployeeCode = "11002", FirstName = "Cornelio", LastName = "Cawicaan", MiddleName = "Bue", BirthDate = DateTime.Parse("10/30/1989"), Gender = 2, IsActive = true }; var employeeInfo = new EmployeeInfo { Employee = employee, Salary = 5000, SalaryFrequency = FrequencyType.Weekly }; var employeeInfo2 = new EmployeeInfo { Employee = employee2, Salary = 8000, SalaryFrequency = FrequencyType.Weekly }; _employeeInfoRepository.Add(employeeInfo); _employeeInfoRepository.Add(employeeInfo2); var workSchedule = new WorkSchedule { TimeStart = new TimeSpan(0, 7, 0, 0), TimeEnd = new TimeSpan(0, 16, 0, 0), WeekStart = 1, WeekEnd = 6 }; var employeeWorkSchedule = new EmployeeWorkSchedule { WorkSchedule = workSchedule, EmployeeId = 1 }; var employeeWorkSchedule2 = new EmployeeWorkSchedule { WorkSchedule = workSchedule, EmployeeId = 2 }; _employeeWorkScheduleRepository.Add(employeeWorkSchedule); _employeeWorkScheduleRepository.Add(employeeWorkSchedule2); _unitOfWork.Commit(); //Test var dateFrom = DateTime.Parse("01/01/2015"); var dateTo = DateTime.Parse("01/02/2016"); _employeeDailyPayrollService.GenerateEmployeeDailySalaryByDateRange(dateFrom, dateTo); //Results Verification var results = _employeeDailyPayrollService.GetByDateRange(dateFrom, dateTo); Assert.IsNotNull(results); Assert.AreEqual(2, results.Count); Assert.AreEqual(1, results[0].EmployeeId); Assert.AreEqual(null, results[0].TotalEmployeeHoursId); Assert.AreEqual((decimal)1000, results[0].TotalPay); Assert.AreEqual(DateTime.Parse("01/01/2016"), results[0].Date); Assert.AreEqual(2, results[1].EmployeeId); Assert.AreEqual(null, results[1].TotalEmployeeHoursId); Assert.AreEqual((decimal)1600, results[1].TotalPay); Assert.AreEqual(DateTime.Parse("01/01/2016"), results[1].Date); }
//[TestMethod] public void GenerateEmployeeDailySalaryByDateRangeHoliday() { //Arrange Initialize(); DeleteData(); var employee = new Employee { EmployeeCode = "11001", FirstName = "Jona", LastName = "Pereira", MiddleName = "Aprecio", BirthDate = DateTime.Parse("02/02/1991"), Gender = 1, IsActive = true }; var employee2 = new Employee { EmployeeCode = "11002", FirstName = "Cornelio", LastName = "Cawicaan", MiddleName = "Bue", BirthDate = DateTime.Parse("10/30/1989"), Gender = 2, IsActive = true }; var employeeInfo = new EmployeeInfo { Employee = employee, Salary = 5000, SalaryFrequency = FrequencyType.Weekly }; var employeeInfo2 = new EmployeeInfo { Employee = employee2, Salary = 8000, SalaryFrequency = FrequencyType.Weekly }; _employeeInfoRepository.Add(employeeInfo); _employeeInfoRepository.Add(employeeInfo2); var workSchedule = new WorkSchedule { TimeStart = new TimeSpan(0, 7, 0, 0), TimeEnd = new TimeSpan(0, 16, 0, 0), WeekStart = 1, WeekEnd = 5 }; var employeeWorkSchedule = new EmployeeWorkSchedule { WorkSchedule = workSchedule, EmployeeId = 1 }; var employeeWorkSchedule2 = new EmployeeWorkSchedule { WorkSchedule = workSchedule, EmployeeId = 2 }; _employeeWorkScheduleRepository.Add(employeeWorkSchedule); _employeeWorkScheduleRepository.Add(employeeWorkSchedule2); //Total EmployeeHours var totalEmployeeHours1 = new TotalEmployeeHours { Date = DateTime.Parse("01/01/2016"), EmployeeId = 1, Hours = 8, TotalEmployeeHoursId = 1, Type = RateType.Regular }; var totalEmployeeHours2 = new TotalEmployeeHours { Date = DateTime.Parse("01/01/2016"), EmployeeId = 1, Hours = 4.5, TotalEmployeeHoursId = 2, Type = RateType.OverTime }; var totalEmployeeHours3 = new TotalEmployeeHours { Date = DateTime.Parse("01/01/2016"), EmployeeId = 1, Hours = 2.5, TotalEmployeeHoursId = 3, Type = RateType.NightDifferential }; var totalEmployeeHours4 = new TotalEmployeeHours { Date = DateTime.Parse("01/02/2016"), EmployeeId = 2, Hours = 4, TotalEmployeeHoursId = 4, Type = RateType.Regular }; var totalEmployeeHours5 = new TotalEmployeeHours { Date = DateTime.Parse("01/02/2016"), EmployeeId = 2, Hours = 3.25, TotalEmployeeHoursId = 5, Type = RateType.OverTime }; var totalEmployeeHours6 = new TotalEmployeeHours { Date = DateTime.Parse("01/02/2016"), EmployeeId = 2, Hours = 0.25, TotalEmployeeHoursId = 6, Type = RateType.NightDifferential }; _totalEmployeeHoursRepository.Add(totalEmployeeHours1); _totalEmployeeHoursRepository.Add(totalEmployeeHours2); _totalEmployeeHoursRepository.Add(totalEmployeeHours3); _totalEmployeeHoursRepository.Add(totalEmployeeHours4); _totalEmployeeHoursRepository.Add(totalEmployeeHours5); _totalEmployeeHoursRepository.Add(totalEmployeeHours6); _unitOfWork.Commit(); //Test var dateFrom = DateTime.Parse("01/01/2016"); var dateTo = DateTime.Parse("01/02/2016"); _employeeDailyPayrollService.GenerateEmployeeDailySalaryByDateRange(dateFrom, dateTo); //Results Verification var results = _employeeDailyPayrollService.GetByDateRange(dateFrom, dateTo); Assert.IsNotNull(results); Assert.AreEqual(7, results.Count); Assert.AreEqual(1, results[0].EmployeeId); Assert.AreEqual(1, results[0].TotalEmployeeHoursId); Assert.AreEqual((decimal)2000, results[0].TotalPay); Assert.AreEqual(DateTime.Parse("01/01/2016"), results[0].Date); Assert.AreEqual(1, results[1].EmployeeId); Assert.AreEqual(2, results[1].TotalEmployeeHoursId); Assert.AreEqual((decimal)1462.5, results[1].TotalPay); Assert.AreEqual(DateTime.Parse("01/01/2016"), results[1].Date); Assert.AreEqual(1, results[2].EmployeeId); Assert.AreEqual(3, results[2].TotalEmployeeHoursId); Assert.AreEqual((decimal)4, results[2].TotalPay); Assert.AreEqual(DateTime.Parse("01/01/2016"), results[2].Date); Assert.AreEqual(2, results[3].EmployeeId); Assert.AreEqual(4, results[3].TotalEmployeeHoursId); Assert.AreEqual((decimal)1200, results[3].TotalPay); Assert.AreEqual(DateTime.Parse("01/02/2016"), results[3].Date); Assert.AreEqual(2, results[6].EmployeeId); Assert.AreEqual(null, results[6].TotalEmployeeHoursId); Assert.AreEqual((decimal)1600, results[6].TotalPay); Assert.AreEqual(DateTime.Parse("01/01/2016"), results[6].Date); Assert.AreEqual(2, results[4].EmployeeId); Assert.AreEqual(5, results[4].TotalEmployeeHoursId); Assert.AreEqual((decimal)1267.5, results[4].TotalPay); Assert.AreEqual(DateTime.Parse("01/02/2016"), results[4].Date); Assert.AreEqual(2, results[5].EmployeeId); Assert.AreEqual(6, results[5].TotalEmployeeHoursId); Assert.AreEqual((decimal)0.3, results[5].TotalPay); Assert.AreEqual(DateTime.Parse("01/02/2016"), results[5].Date); }