Example #1
0
        public AddSalaryComponentForEmployeeResponse AddSalaryComponentForEmployee(AddSalaryComponentForEmployeeRequest request)
        {
            AddSalaryComponentForEmployeeResponse response = new AddSalaryComponentForEmployeeResponse();

            EmployeeSalaryComponents empSalaryComponent = new EmployeeSalaryComponents()
            {
                EmployeeId = request.EmployeeId,
                SalaryComponentName = request.SalaryComponentName,
                IsExtra = request.IsExtra,
                SalaryPayFrequency = request.SalaryPayFerequency,
                Remark = request.Remark,
            };
            if(request.IsMainSalary)
            {
                EmployeeSalaryComponents currentEmpSalaryComponent = GetMainEmployeeSalaryComponent(request.EmployeeId);
                Employee employee = employeeRepository.GetById(request.EmployeeId);
                empSalaryComponent.StartApplyDate = request.ApplyDate;
                empSalaryComponent.EndApplyDate = DateTime.MaxValue;
                empSalaryComponent.IsMainSalary = true;
                empSalaryComponent.IsSalary = true;
                employee.Salary = request.Amount;
                if (currentEmpSalaryComponent != null)
                {
                    currentEmpSalaryComponent.IsMainSalary = false;
                    currentEmpSalaryComponent.EndApplyDate = request.ApplyDate.AddDays(-1);
                }
            }
            else{
                empSalaryComponent.StartApplyDate = request.ApplyDate;
                empSalaryComponent.EndApplyDate = request.EndApplyDate;
                empSalaryComponent.IsMainSalary = false;
                empSalaryComponent.IsSalary = false;
            }
            //
            if (!request.IsExtra && request.IsMainSalary)
                 empSalaryComponent.Amount = request.Amount  ;
            else if (!request.IsExtra)
                empSalaryComponent.Amount = 0 - request.Amount;
            else {
                empSalaryComponent.Amount = request.Amount;
            }
            //
            if (request.SalaryPayFerequency == Model.Enums.SalaryPayFerequency.OneTime)
                empSalaryComponent.EndApplyDate = new DateTime(request.ApplyDate.Year, request.ApplyDate.Month, DateTime.DaysInMonth(request.ApplyDate.Year, request.ApplyDate.Month));
            //
            try
            {
                empSalaryComponentRepository.Add(empSalaryComponent);
                SaveSalary();
                response.Status = true;
                response.Message = empSalaryComponent.Id.ToString();
            }
            catch (Exception ex)
            {
                response.Status = false;
                response.Message = ex.Message;
            }
            return response;
        }
Example #2
0
 public ActionResult AjaxAddEmployeeSalaryComponent(SalaryComponentAddFormView salaryComponentAddForm)
 {
     if (ModelState.IsValid)
     {
         AddSalaryComponentForEmployeeRequest request = new AddSalaryComponentForEmployeeRequest()
         {
             EmployeeId = salaryComponentAddForm.SalaryComponentEmployeeId,
             SalaryComponentName = salaryComponentAddForm.SalaryComponentName,
             Amount = salaryComponentAddForm.Amount,
             ApplyDate = salaryComponentAddForm.ApplyDate,
             EndApplyDate = salaryComponentAddForm.EndDate,
             IsExtra = salaryComponentAddForm.IsExtra,
             IsMainSalary = salaryComponentAddForm.IsMainSalary,
             SalaryPayFerequency = salaryComponentAddForm.SalaryPayFrequency,
             Remark = salaryComponentAddForm.SalaryComponentRemark
         };
         AddSalaryComponentForEmployeeResponse response = salaryService.AddSalaryComponentForEmployee(request);
         if (response.Status)
         {
             return Json(new { Status = "Success", Message = response.Message });
         }
         else
         {
             return Json(new { Status = "Fail", Message = response.Message });
         }
     }
     else {
         return Json(new { Status = "Fail", Message = "Kiểm tra dữ liệu nhập" });
     }
 }