/// <summary> /// Calculate the employee's bonus based on proportion of the employee's salary on the total wage budget of the company /// </summary> /// <param name="employee"></param> /// <param name="bonusPool"></param> /// <returns></returns> public int CalculateBonus(HrEmployee employee, int bonusPool) { //get the total salary budget for the company int totalSalary = GetTotalSalaryOfAllCompanyPersonnel(); return(CalculateBonus(employee.Salary, bonusPool, totalSalary)); }
public ActionResult Calculate(BonusPoolCalculatorModel model) { int selectedEmployeeId = model.SelectedEmployeeId; int totalBonusPool = model.BonusPoolAmount; //load the details of the selected employee using the ID HrEmployee hrEmployee = getEmployeeProfile(selectedEmployeeId); int employeeSalary = hrEmployee.Salary; //get the total salary budget for the company int totalSalary = getEmployeeTotalSalary(); //calculate the bonus allocation for the employee int bonusAllocation = getBonusAllocation(employeeSalary, totalSalary, totalBonusPool); BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel(); result.hrEmployee = hrEmployee; result.bonusPoolAllocation = bonusAllocation; return(View(result)); }
public async Task GetBonusPoolCalculationResultAsync_EmployeeIdNotInRepository_ThrowsException() { //Arrange var employeeOne = new HrEmployee { ID = 1, Full_Name = "Employee One", Salary = 7000 }; var employeeTwo = new HrEmployee { ID = 1, Full_Name = "Employee Two", Salary = 3000 }; _employeeRepositoryMock.Setup(er => er.GetEmployeesAsync()).ReturnsAsync(new List <HrEmployee>() { employeeOne, employeeTwo }); //Act Func <Task <BonusPoolCalculatorResultModel> > getBonusCalculationResultFunc = async() => await _bonusPoolService.GetBonusPoolCalculationResultAsync(3, 3000); //Assert await getBonusCalculationResultFunc.Should().ThrowAsync <Exception>(); }
public HrEmployeeVM MapTo(HrEmployee model) { return(new HrEmployeeVM { Id = model.Id, FullName = model.FullName, Code_1C = model.Code_1C, ID_1C = model.ID_1C, DateOfBirth = model.DateOfBirth, PlaceOfBirth = model.PlaceOfBirth, Gender = model.Gender, Address = model.Address, EmailLogin = model.EmailLogin, EntryDate = model.EntryDate, LeaveDate = model.LeaveDate, PositionId = model.PositionId, DepartmentId = model.DepartmentId, PositionStartDate = model.PositionStartDate, IsActive = model.IsActive, PassportNo = model.PassportNo, PassportIssueDate = model.PassportIssueDate, PassportIssuePlace = model.PassportIssuePlace, FullNameGenitive = model.FullNameGenitive }); }
public async Task <IActionResult> updateProfile([FromBody] HrEmployee hrEmployee) { _context.Update(hrEmployee); await _context.SaveChangesAsync(); return(Ok(hrEmployee)); }
public async Task GetBonusPoolCalculationResultAsync_ReturnsBonusPoolCalcualteResultForEmployee() { //Arrange var employeeOne = new HrEmployee { ID = 1, Full_Name = "Employee One", Salary = 7000 }; var employeeTwo = new HrEmployee { ID = 1, Full_Name = "Employee Two", Salary = 3000 }; _employeeRepositoryMock.Setup(er => er.GetEmployeesAsync()).ReturnsAsync(new List <HrEmployee>() { employeeOne, employeeTwo }); //Act var result = await _bonusPoolService.GetBonusPoolCalculationResultAsync(employeeOne.ID, 3000); //Assert result.Employee.ID.Should().Be(employeeOne.ID); result.Employee.FullName.Should().Be(employeeOne.Full_Name); result.bonusPoolAllocation.Should().Be(2100); }
public async Task GetBonusPool_ReturnsBonusPoolWithAllEmployees() { //Arrange var employeeOne = new HrEmployee { ID = 1, Full_Name = "Employee One" }; var employeeTwo = new HrEmployee { ID = 1, Full_Name = "Employee Two" }; _employeeRepositoryMock.Setup(er => er.GetEmployeesAsync()).ReturnsAsync(new List <HrEmployee>() { employeeOne, employeeTwo }); //Act var result = await _bonusPoolService.GetBonusPoolAsync(); //Assert result.Employees[0].FullName.Should().Be(employeeOne.Full_Name); result.Employees[0].ID.Should().Be(employeeOne.ID); result.Employees[1].FullName.Should().Be(employeeTwo.Full_Name); result.Employees[1].ID.Should().Be(employeeTwo.ID); }
public HrEmployeeEntity(HrEmployee HrEmployee) { this.Id = HrEmployee.Id; this.CompanyId = HrEmployee.CompanyId; this.Display = HrEmployee.Display; this.Name = HrEmployee.Name; this.Cx = HrEmployee.Cx; }
public HrEmployeeEntity Update(UserEntity UserEntity, Guid Id, HrEmployeeEntity HrEmployeeEntity) { HrEmployee HrEmployee = IMSContext.HrEmployees.Where(h => h.Id == Id).FirstOrDefault(); HrEmployeeEntity.ToModel(HrEmployee); IMSContext.SaveChanges(); return(HrEmployeeEntity); }
public void EmployeeProfileShouldGenerate() { //BonusPoolController samp = new BonusPoolController(); HrEmployee newSample = samp.getEmployeeProfile(5); Assert.NotNull(newSample); }
// GET: BonusPool public ActionResult Input() { var viewModel = new BonusCalculatorInput { AllEmployees = HrEmployee.GetEmployeeList() }; return(View(viewModel)); }
public HrEmployeeEntity(HrEmployee HrEmployee) { this.Id = HrEmployee.Id; this.Username = HrEmployee.IdNavigation.Username; this.CompanyId = HrEmployee.CompanyId; this.Display = HrEmployee.Display; this.Name = HrEmployee.Name; //this.Cx = HrEmployee.Cx; }
public HrEmployeeEntity Get(UserEntity UserEntity, Guid Id) { HrEmployee HrEmployee = IMSContext.HrEmployees.Where(h => h.Id == Id).FirstOrDefault(); if (HrEmployee == null) { throw new BadRequestException("Hremplopyee không tồn tại!"); } return(new HrEmployeeEntity(HrEmployee)); }
/// <summary> /// Calculate the employee's bonus based on the employee's department allocation percentage /// </summary> /// <param name="employee"></param> /// <param name="bonusPool"></param> /// <returns></returns> public int CalculateBonusBasedOnDepartmentAllocation(HrEmployee employee, int bonusPool) { // calculate bonus allocation for department var bonusAllocationPercForDept = _departmentRepository.Get(employee.HrDepartmentId).BonusPoolAllocationPerc; // Compute the sum of all salaries paid to personnel in this department int totalDepartmentSalary = GetTotalSalaryOfAllPersonnelInDepartment(employee.HrDepartmentId); return(CalculateBonusBasedOnDepartmentAllocation(employee.Salary, bonusPool, employee.HrDepartmentId, bonusAllocationPercForDept)); }
public int BonusAllocationCalculation(HrEmployee hrEmployee, Payroll payroll, BonusPool bonusPool) { Allocation EmployeeAllocation = new Allocation(); EmployeeAllocation.PercentAllocation = BonusAllocationPercentageCalculation(hrEmployee, payroll); int result = (int)(EmployeeAllocation.PercentAllocation * bonusPool.BonusPoolAmount); return(result); }
public void CalculateBonusPoolForEmployee_Successful_When_It_Has_Correct_Input() { var bonusPoolAmount = 50; var employee = new HrEmployee { ID = 3, FistName = "John", SecondName = "Smith", DateOfBirth = Convert.ToDateTime("1985-09-05"), HrDepartmentId = 1, JobTitle = "Accountant", Salary = 60000, Full_Name = " John Smith" }; List <HrEmployee> employees = new List <HrEmployee>() { new HrEmployee { ID = 3, FistName = "John", SecondName = "Smith", DateOfBirth = Convert.ToDateTime("1985-09-05"), HrDepartmentId = 1, JobTitle = "Accountant", Salary = 60000, Full_Name = " John Smith" }, new HrEmployee { ID = 2, FistName = "Janet", SecondName = "Jones", DateOfBirth = Convert.ToDateTime("1975-09-05"), HrDepartmentId = 2, JobTitle = "HR Director", Salary = 90000, Full_Name = "Janet Jones" } }; var employeeRepository = new Mock <IHrEmployeeRepository>(); employeeRepository.Setup(x => x.GetById(employee.ID)) .Returns(employee); employeeRepository.Setup(x => x.Read()) .Returns(employees); var service = new BonusPoolCalculationService(employeeRepository.Object); var actual = service.CalculateBonusPoolForEmployee(employee.ID, bonusPoolAmount); Assert.AreEqual(20, actual); }
public bool Delete(UserEntity UserEntity, Guid Id) { HrEmployee HrEmployee = IMSContext.HrEmployees.Where(h => h.Id == Id).FirstOrDefault(); if (HrEmployee == null) { throw new BadRequestException("HrEmployee không tồn tại"); } IMSContext.HrEmployees.Remove(HrEmployee); IMSContext.SaveChanges(); return(true); }
public HrEmployeeEntity Create(UserEntity UserEntity, HrEmployeeEntity HrEmployeeEntity) { HrEmployee HrEmployee = HrEmployeeEntity.ToModel(); User User = new User() { Id = HrEmployee.Id, Username = HrEmployee.Name, Password = "******" }; IMSContext.Users.Add(User); IMSContext.HrEmployees.Add(HrEmployee); IMSContext.SaveChanges(); return(HrEmployeeEntity); }
public void BonusAllocationPercentageCalculation_CalculateBonusAllocationPercentage_ReturnBonusAllocationPercentage() { var allocation = new Allocation(); var employee = new HrEmployee(); var payroll = new Payroll(); employee.Salary = 20000; payroll.TotalCostToCompany = 1000000; var result = (decimal)allocation.BonusAllocationPercentageCalculation(employee, payroll); Assert.AreEqual(result, (decimal)0.02); }
public HrEmployee ToModel(HrEmployee HrEmployee = null) { if (HrEmployee == null) { HrEmployee = new HrEmployee(); this.Id = Guid.NewGuid(); } HrEmployee.Id = this.Id; HrEmployee.CompanyId = this.CompanyId; HrEmployee.Display = this.Display; HrEmployee.Name = this.Name; return(HrEmployee); }
public void CalculateBonusPercentageOfEmployeeSalary_When_TotalSalary_Is_Null_Throws_Exception() { var employeeRepository = new Mock <IHrEmployeeRepository>(); var employee = new HrEmployee { ID = 3, FistName = "John", SecondName = "Smith", DateOfBirth = Convert.ToDateTime("1985-09-05"), HrDepartmentId = 1, JobTitle = "Accountant", Salary = 35000, Full_Name = " John Smith" }; List <HrEmployee> employees = new List <HrEmployee>() { new HrEmployee { ID = 3, FistName = "John", SecondName = "Smith", DateOfBirth = Convert.ToDateTime("1985-09-05"), HrDepartmentId = 1, JobTitle = "Accountant", Salary = 0, Full_Name = " John Smith" }, new HrEmployee { ID = 2, FistName = "Janet", SecondName = "Jones", DateOfBirth = Convert.ToDateTime("1975-09-05"), HrDepartmentId = 2, JobTitle = "HR Director", Salary = 0, Full_Name = "Janet Jones" } }; employeeRepository.Setup(x => x.GetById(employee.ID)) .Returns(employee); employeeRepository.Setup(x => x.Read()) .Returns(employees); var service = new BonusPoolCalculationService(employeeRepository.Object); service.CalculateBonusPercentageOfEmployeeSalary(employee.ID); }
public HrEmployeeEntity Create(UserEntity UserEntity, HrEmployeeEntity HrEmployeeEntity) { HrEmployee HrEmployee = HrEmployeeEntity.ToModel(); User user = new User(); user.Id = HrEmployee.Id; user.Username = HrEmployeeEntity.Username; user.Password = "******"; IMSContext.Users.Add(user); IMSContext.HrEmployees.Add(HrEmployee); IMSContext.SaveChanges(); return(Get(UserEntity, HrEmployee.Id)); }
public void BonusAllocationCalculation_CalculateBonusAllocation_ReturnBonusAllocation() { var allocation = new Allocation(); var employee = new HrEmployee(); var payroll = new Payroll(); var bonusPool = new BonusPool(); employee.Salary = 50000; payroll.TotalCostToCompany = 1000000; bonusPool.BonusPoolAmount = 1000; var result = allocation.BonusAllocationCalculation(employee, payroll, bonusPool); Assert.AreEqual(result, 50); }
public void PayrollCostTocompany_CalculatePayrollCostTocompany_ReturnPayrollCostTocompany() { var payroll = new Payroll(); List <HrEmployee> Employees = new List <HrEmployee>(); var Employee1 = new HrEmployee(); Employee1.Salary = 500000; Employees.Add(Employee1); var Employee2 = new HrEmployee(); Employee2.Salary = 250000; Employees.Add(Employee2); var result = (int)payroll.PayrollCostTocompany(Employees); Assert.AreEqual(result, 750000); }
public void Test_CalculateSalaryBudget_ListHrEmployees_ShouldReturnTotal() { var employee1 = new HrEmployee { Salary = 50000 }; var employee2 = new HrEmployee { Salary = 60000 }; var employee3 = new HrEmployee { Salary = 70000 }; var employees = new List <HrEmployee> { employee1, employee2, employee3 }; var result = TestCalculateSalaryBudget(employees); result.Should().Be(180000); }
//to follow DRY - sapated into submethod private HrEmployeeDocumentListVM PrepareVM(HrEmployee employee, bool isHr) { return(new HrEmployeeDocumentListVM() { IsHrUser = isHr, EmployeeId = employee.Id, EmployeeName = employee.FullName, HrEmployeeDocuments = _hrEmployeeDocumentService .GetByEmployeeQueryable(employee.Id) .Select(d => new HrEmployeeDocumentVM { Id = d.Id, FileName = d.FileName, Title = d.Title }).ToList(), CompletedRuCv = employee.ComplietedRuCv, CompletedUzCv = employee.ComplietedUzCv }); }
public ActionResult Calculate(BonusPoolCalculatorModel model) { int selectedEmployeeId = model.SelectedEmployeeId; int totalBonusPool = model.BonusPoolAmount; //load the details of the selected employee using the ID HrEmployee hrEmployee = _hrRepository.GetHrEmployee(selectedEmployeeId); int employeeSalary = _bonusCalculator.GetSalary(hrEmployee); IEnumerable <HrEmployee> allEmployees = _hrRepository.GetHrEmployees(); //get the total salary budget for the company int totalSalary = _bonusCalculator.GetTotalSalary(allEmployees); int bonusAllocation = _bonusCalculator.Calculate(employeeSalary, totalSalary, totalBonusPool); var result = ToBonusPoolCalculatorResultModel(hrEmployee, bonusAllocation); return(View(result)); }
public ActionResult Calculate(BonusPoolCalculatorModel model) { int selectedEmployeeId = model.SelectedEmployeeId; int totalBonusPool = model.BonusPoolAmount; HrEmployee hrEmployee = (HrEmployee)db.HrEmployees.FirstOrDefault(item => item.ID == selectedEmployeeId); Payroll payroll = new Payroll(); payroll.AllEmployees = getEmployees(); payroll.TotalCostToCompany = payroll.PayrollCostTocompany(payroll.AllEmployees); BonusPool bonusPool = new BonusPool(); bonusPool.BonusPoolAmount = totalBonusPool; BonusPoolCalculatorResultModel result = new BonusPoolCalculatorResultModel(); Allocation allocation = new Allocation(); result.hrEmployee = hrEmployee; result.bonusPoolAllocation = allocation.BonusAllocationCalculation(hrEmployee, payroll, bonusPool); return(View(result)); }
public async Task <IActionResult> RegisterUser([FromBody] HrEmployee hrEmployee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { MD5 md5Hash = MD5.Create(); hrEmployee.SEmpPassword = Auth.GetMd5Hash(md5Hash, hrEmployee.SEmpPassword); hrEmployee.UpdateAt = DateTime.Today; _context.HrEmployee.Add(hrEmployee); await _context.SaveChangesAsync(); return(Ok(hrEmployee)); } catch (Exception ex) { return(Ok(ex)); } }
public IEnumerable <HrEmployee> GetHrEmployees() { List <HrEmployee> hrEmployees = new List <HrEmployee>(); var connectionString = @"Server=localhost\SQLEXPRESS;Database=SynetecMvcDb;Trusted_Connection=True;"; SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM [dbo].[HrEmployee]"; DataTable dt = new DataTable(); dt.Load(cmd.ExecuteReader()); foreach (DataRow row in dt.Rows) { var hrEmployee = new HrEmployee(); hrEmployee.ID = Convert.ToInt32(row[0]); hrEmployee.FistName = Convert.ToString(row[1]); hrEmployee.SecondName = Convert.ToString(row[2]); hrEmployee.DateOfBirth = Convert.ToDateTime(row[3]); hrEmployee.HrDepartmentId = Convert.ToInt32(row[4]); hrEmployee.JobTitle = Convert.ToString(row[5]); hrEmployee.Salary = Convert.ToInt32(row[6]); hrEmployee.Full_Name = Convert.ToString(row[7]); hrEmployees.Add(hrEmployee); } conn.Close(); return(hrEmployees); }