Ejemplo n.º 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;
        }
Ejemplo n.º 2
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;
        }