Пример #1
0
        public CreateExperienceForEmployeeResponse CreateNewExperienceForEmployee(CreateExperienceForEmployeeRequest requets)
        {
            CreateExperienceForEmployeeResponse response = new CreateExperienceForEmployeeResponse();

            Employee employeeUpdated = requets.Employee;
            if (employeeUpdated.CompanyId == requets.NewCompanyId &&
                employeeUpdated.PositionId == requets.NewPositionId &&
                employeeUpdated.Departement == requets.NewDepartement)
            {
                response.Status = false;
                response.Message = "Không thay đổi";
            }
            else
            {
                // create new exp
                Experience experience = new Experience() {
                    OldCompanyName = employeeUpdated.Company.CompanyName,
                    OldPositionName = employeeUpdated.Position.PositionName,
                    OldDepartement = employeeUpdated.Departement,
                    PositionId = employeeUpdated.PositionId,
                    OldJoinedDate = employeeUpdated.JoinedDate,
                    TransferDate = requets.TransferDate,
                    ExperienceYears = employeeUpdated.WorkingTimeSpan,
                    OldSalary = employeeUpdated.Salary,
                    OldInsurance = employeeUpdated.MadatoryInsurance,
                    Reason = requets.Reason,
                    AttachFile = requets.AttachFile,
                    EmployeeId = employeeUpdated.Id,
                    CompanyId = employeeUpdated.CompanyId,
                };
                // Make all insurance is history
                IEnumerable<Insurance> insuranceList = insuranceRepository.GetMany(ins => ins.EmployeeId == employeeUpdated.Id);
                foreach (Insurance ins in insuranceList)
                {
                    ins.IsHistory = true;
                    ins.HistoryCompanyName = employeeUpdated.Company.CompanyName;
                    ins.HistoryPositionName = employeeUpdated.Position.PositionName;
                }
                // update new employee infor
                employeeUpdated.JoinedDate = requets.TransferDate;
                employeeUpdated.CompanyId = requets.NewCompanyId;
                employeeUpdated.PositionId = requets.NewPositionId;
                employeeUpdated.Salary = requets.NewSalary;
                employeeUpdated.Departement = requets.NewDepartement;
                employeeUpdated.Status = Model.Enums.EmployeeStatus.Transfer;
                //
                if (employeeUpdated.GetMainSalaryComponent() != null)
                {
                    employeeUpdated.GetMainSalaryComponent().StartApplyDate = requets.TransferDate;
                    employeeUpdated.GetMainSalaryComponent().Amount = requets.NewSalary;
                }
                else
                {
                    EmployeeSalaryComponents empSalaryComponet = new EmployeeSalaryComponents()
                    {
                        SalaryComponentName = "Lương cơ bản",
                        IsSalary = true,
                        IsExtra = true,
                        IsMainSalary = true,
                        StartApplyDate = requets.TransferDate,
                        SalaryPayFrequency = SalaryPayFerequency.Monthly,
                        EndApplyDate = DateTime.MaxValue,
                        Amount = requets.NewSalary,
                        EmployeeId = employeeUpdated.Id,
                    };
                    employeeUpdated.EmployeeSalaryComponents.Add(empSalaryComponet);
                }
                // Check if have tranfer insurance
                if (requets.IsInsuranceTransfer)
                {
                    double postionInsuranceRate = positionRepository.GetById(requets.NewPositionId).InsuranceRate;
                    double companyInsuranceRate = companyRepository.GetById(requets.NewCompanyId).CompanyInsuranceRatePercent;
                    double labratorInsuranceRate = companyRepository.GetById(requets.NewCompanyId).LabaratorInsuranceRatePercent;
                    string insuranceNo = string.Format("BH/{0}/T/{1}", employeeUpdated.EmployeeCode,requets.InsuranceApplyDate.ToShortDateString());
                    Insurance ins;
                    if (requets.InsuranceTransferAmount != 0)
                    {
                        ins = new Insurance()
                        {
                            DateOfIssue = requets.InsuranceApplyDate,
                            Amount = requets.InsuranceTransferAmount,
                            Values = requets.InsuranceTransferAmount * labratorInsuranceRate,
                            CompanyValue = companyInsuranceRate * requets.InsuranceTransferAmount,
                            CompanyRatePercent = companyInsuranceRate,
                            LabaratorRatePercent = labratorInsuranceRate,
                            IsMandatory = true,
                            IsHistory = false,
                            EmployeeId = employeeUpdated.Id,
                            InsuranceNo = insuranceNo
                        };
                    }
                    else {
                        ins = new Insurance()
                        {
                            DateOfIssue = requets.InsuranceApplyDate,
                            Amount = employeeUpdated.Position.InsuranceRate,
                            CompanyRatePercent = companyInsuranceRate,
                            LabaratorRatePercent = labratorInsuranceRate,
                            Values = postionInsuranceRate * labratorInsuranceRate,
                            CompanyValue = companyInsuranceRate * postionInsuranceRate,
                            IsMandatory = true,
                            IsHistory = false,
                            EmployeeId = employeeUpdated.Id,
                            InsuranceNo = insuranceNo
                        };
                    }
                    insuranceRepository.Add(ins);
                }

                try
                {
                    employeeRepository.Update(employeeUpdated);
                    experienceRepository.Add(experience);
                    SaveExperience();
                    response.Status = true;
                    response.Message = experience.Id.ToString();
                }
                catch (Exception ex)
                {
                    response.Status = false;
                    response.Message = "System error";
                }
            }
            return response;
        }
Пример #2
0
        public ActionResult EmployeeTransferAdd(EmployeeTransferFormModel item)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Employee employee = employeeService.GetEmployee(item.EmployeeId);
                    CreateExperienceForEmployeeRequest request = new CreateExperienceForEmployeeRequest() {
                        Employee = employee,
                        NewCompanyId = item.NewCompanyId,
                        NewPositionId = item.NewPositionId,
                        NewDepartement = item.NewDepartement,
                        NewSalary = item.NewSalary,
                        TransferDate = item.TransferDate,
                        Reason = item.Reason,
                        AttachFile = item.FileAttach,
                        IsInsuranceTransfer = item.IsInsuranceTransfer,
                        InsuranceTransferAmount = item.InsuranceAmount,
                        InsuranceApplyDate = item.InsuranceApplyDate,

                    };
                    CreateExperienceForEmployeeResponse response = experienceService.CreateNewExperienceForEmployee(request);
                    if (response.Status == true)
                    {
                        return Json(new { status = "OK", message = response.Message });
                    }
                    else {
                        return Json(new { status = "Fail", message = response.Message });
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                    return Json(new { status = "Errors", message = e.Message });
                }
            }
            else
            {
                return Json(new { status = "NotValid", message = "yyy" });
            }
        }