コード例 #1
0
        /// <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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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>();
        }
コード例 #4
0
 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
     });
 }
コード例 #5
0
        public async Task <IActionResult> updateProfile([FromBody] HrEmployee hrEmployee)
        {
            _context.Update(hrEmployee);
            await _context.SaveChangesAsync();

            return(Ok(hrEmployee));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 public HrEmployeeEntity(HrEmployee HrEmployee)
 {
     this.Id        = HrEmployee.Id;
     this.CompanyId = HrEmployee.CompanyId;
     this.Display   = HrEmployee.Display;
     this.Name      = HrEmployee.Name;
     this.Cx        = HrEmployee.Cx;
 }
コード例 #9
0
ファイル: HremployeeService.cs プロジェクト: linhlpv/IMS
        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);
        }
コード例 #10
0
        public void EmployeeProfileShouldGenerate()
        {
            //BonusPoolController samp = new BonusPoolController();

            HrEmployee newSample = samp.getEmployeeProfile(5);


            Assert.NotNull(newSample);
        }
コード例 #11
0
        // GET: BonusPool
        public ActionResult Input()
        {
            var viewModel = new BonusCalculatorInput
            {
                AllEmployees = HrEmployee.GetEmployeeList()
            };

            return(View(viewModel));
        }
コード例 #12
0
 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;
 }
コード例 #13
0
ファイル: HremployeeService.cs プロジェクト: linhlpv/IMS
        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));
        }
コード例 #14
0
        /// <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));
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
ファイル: HremployeeService.cs プロジェクト: linhlpv/IMS
        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);
        }
コード例 #18
0
ファイル: HremployeeService.cs プロジェクト: linhlpv/IMS
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
 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);
 }
コード例 #21
0
        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);
        }
コード例 #22
0
        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));
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
 //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
     });
 }
コード例 #27
0
        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));
        }
コード例 #28
0
        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));
        }
コード例 #29
0
        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));
            }
        }
コード例 #30
0
        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);
        }