public void ComputeAllowance(DateTime payrollStartDate, DateTime payrollEndDate, IList <EmployeePayroll> payrollList) { if (_employeePayrollAllowanceService.proceedAllowance(payrollStartDate, payrollEndDate)) { // Get all active employees var employees = _employeeInfoService.GetAllWithAllowance(); int totalWorkHoursPerDay = Convert.ToInt32(_settingService.GetByKey(PAYROLL_TOTAL_HOURS)); var totalDays = Convert.ToInt32(_settingService.GetByKey(ALLOWANCE_TOTAL_DAYS)); foreach (EmployeeInfo employee in employees) { decimal totalAllowance = _employeePayrollAllowanceService .ComputeEmployeeAllowance(totalDays, totalWorkHoursPerDay, employee, payrollStartDate, payrollEndDate); //Update employee payroll EmployeePayroll employeePayroll = payrollList.OfType <EmployeePayroll>() .Where(p => p.EmployeeId == employee.EmployeeId).FirstOrDefault(); if (employeePayroll != null) { employeePayroll.TotalAllowance = totalAllowance; employeePayroll.TaxableIncome = decimal.Add(employeePayroll.TaxableIncome, totalAllowance); employeePayroll.TotalGross = decimal.Add(employeePayroll.TotalGross, totalAllowance); employeePayroll.TotalNet = employeePayroll.TotalGross; //TODO change this if allowance is already a list //Create allowance payroll item EmployeePayrollItem allowanceItem = new EmployeePayrollItem(); allowanceItem.EmployeeId = employeePayroll.EmployeeId; allowanceItem.PayrollId = employeePayroll.PayrollId; allowanceItem.PayrollDate = employeePayroll.PayrollDate; allowanceItem.Multiplier = 1; allowanceItem.RatePerHour = employee.Salary; allowanceItem.RateType = RateType.Allowance; allowanceItem.TotalAmount = employeePayroll.TotalAllowance; _employeePayrollItemService.Add(allowanceItem); _unitOfWork.Commit(); } } } }