Esempio n. 1
0
        public string UpdateWorkingPosition(string selectedIds, string userLogin)
        {
            string      message             = string.Empty;
            string      status              = string.Empty;
            var         profileServices     = new Hre_ProfileServices();
            var         workhistoryServices = new Hre_WorkHistoryServices();
            List <Guid> lstIds              = selectedIds.Split(',').Select(x => Guid.Parse(x)).ToList();
            //   var lstSuspenses = repo.FindBy(m => m.ID != null && lstIds.Contains(m.ID)).ToList();
            var services = new BaseService();
            var lstObj   = new List <object>();

            lstObj.AddRange(new object[14]);
            lstObj[12] = 1;
            lstObj[13] = int.MaxValue - 1;
            var lstComback = services.GetData <Hre_StopWorkingEntity>(lstObj, ConstantSql.hrm_hr_sp_get_RegisterComback, userLogin, ref status).ToList().Translate <Hre_StopWorking>();

            lstComback = lstComback.Where(s => lstIds.Contains(s.ID)).ToList();
            Hre_WorkHistoryEntity workHistoryEntity;

            foreach (var item in lstComback)
            {
                var profile = profileServices.GetData <Hre_ProfileEntity>(Common.DotNetToOracle(item.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, userLogin, ref status).FirstOrDefault();
                profile.DateOfEffect = item.DateComeBack;
                string supervisor = null;
                if (profile.SupervisorID != null)
                {
                    var supervisorbyProfile = profileServices.GetData <Hre_ProfileEntity>(Common.DotNetToOracle(profile.SupervisorID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, userLogin, ref status).FirstOrDefault();
                    if (supervisorbyProfile != null)
                    {
                        supervisor = supervisorbyProfile.ProfileName;
                    }
                }
                workHistoryEntity                         = new Hre_WorkHistoryEntity();
                workHistoryEntity.ProfileID               = item.ProfileID.Value;
                workHistoryEntity.DateEffective           = item.DateComeBack != null ? item.DateComeBack.Value : DateTime.Now;
                workHistoryEntity.OrganizationStructureID = profile.OrgStructureID;
                workHistoryEntity.JobTitleID              = profile.JobTitleID;
                workHistoryEntity.PositionID              = profile.PositionID;
                workHistoryEntity.Supervisor              = supervisor;
                profileServices.Edit(profile);
                workhistoryServices.Add(workHistoryEntity);
            }
            message = NotificationType.Success.ToString();
            return(message);
        }
Esempio n. 2
0
        public Hre_ProfileModel Post([Bind] Hre_ProfileModel model)
        {
            string status = string.Empty;

            if (model != null)
            {
                ActionService service     = new ActionService(UserLogin);
                BaseService   BaseService = new BaseService();

                if (!string.IsNullOrWhiteSpace(model.CodeAttendance))
                {
                    model.CodeAttendance = model.CodeAttendance.TrimAll();
                }

                #region Validate

                string message = string.Empty;

                var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_ProfileModel>(model, "Hre_Profile", ref message);
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return(model);
                }
                if (model.DateOfEffectOld != null)
                {
                    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_ProfileModel>(model, "Hre_ProfileCheckDateOfEffect", ref message);
                    if (!checkValidate)
                    {
                        model.ActionStatus = message;
                        return(model);
                    }
                }
                #endregion

                #region Xử lý cập nhật AbilityTitle khi chọn rank

                if (model.SalaryClassID != null)
                {
                    var abilityTitleBySalaryClass = BaseService.GetData <Cat_AbilityTileEntity>(Common.DotNetToOracle(model.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault();
                    if (abilityTitleBySalaryClass != null)
                    {
                        model.AbilityTileID = abilityTitleBySalaryClass.ID;
                    }
                }

                #endregion

                #region Xử Lý Lưu field DateOfBirth
                var dateOfBirth = string.Empty;
                if (model.DayOfBirth == 00 && model.MonthOfBirth == 00)
                {
                    model.ActionStatus = "ErrorDateOfBirth";
                    return(model);
                }
                if (model.DayOfBirth == null && model.MonthOfBirth == null && model.YearOfBirth == null)
                {
                    dateOfBirth = string.Empty;
                }
                else
                {
                    if (model.DayOfBirth == null)
                    {
                        model.DayOfBirth = DateTime.Now.Day;
                    }
                    if (model.MonthOfBirth == null)
                    {
                        model.MonthOfBirth = DateTime.Now.Month;
                    }
                    if (model.YearOfBirth == null)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                }


                if (model.DayOfBirth >= 0 || model.MonthOfBirth >= 0 || model.YearOfBirth >= 0)
                {
                    if (model.DayOfBirth == 30 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                    if (model.DayOfBirth == 31 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                    if (model.DayOfBirth > 31 || model.MonthOfBirth > 12)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                    dateOfBirth = model.MonthOfBirth + "/" + model.DayOfBirth + "/" + model.YearOfBirth;
                }

                model.DateOfBirth = string.IsNullOrEmpty(dateOfBirth) ? (DateTime?)null : DateTime.Parse(dateOfBirth);
                #endregion
                Hre_ProfileModel HreProfile = new Hre_ProfileModel();
                if (model.ID != Guid.Empty)
                {
                    HreProfile = GetById(model.ID);
                }
                if (HreProfile != null && (model.ID == HreProfile.ID) && model.ActionStatus != "1")
                {
                    string[] listFieldName = new[] { "JobTitleID", "PositionID", "EmpTypeID", "DateOfEffect", "CostCentreID", "OrgStructureID", "WorkPlaceID", "SupervisorID" };
                    foreach (var item in listFieldName)
                    {
                        var value1 = model.GetPropertyValue(item);
                        var value2 = HreProfile.GetPropertyValue(item);
                        if ((value1 != null && value2 != null) && (value1.ToString() != value2.ToString()))
                        {
                            model.SetPropertyValue(Constant.ActionStatus, NotificationType.Change.ToString());
                            return(model);
                        }
                    }
                    if (HreProfile.ProfileName != model.ProfileName)
                    {
                        if (model.ProfileName.Contains(' '))
                        {
                            model.FirstName  = model.ProfileName.Substring(model.ProfileName.LastIndexOf(' ') + 1);
                            model.NameFamily = model.ProfileName.Substring(0, model.ProfileName.LastIndexOf(' '));
                        }
                        else
                        {
                            model.FirstName = model.ProfileName;
                        }
                    }
                }
                if (model.ActionStatus == "1" || model.ActionStatus == "Success" || string.IsNullOrEmpty(model.ActionStatus))
                {
                    var serviceAddress = new Hre_AddressServices();
                    var serviceProfile = new Hre_ProfileServices();
                    var profileEntity  = new Hre_ProfileEntity();
                    if (model.ID != Guid.Empty)
                    {
                        profileEntity = serviceProfile.GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();
                    }

                    #region Xử lý lưu CardCode
                    Hre_CardHistoryServices cardservices        = new Hre_CardHistoryServices();
                    Hre_WorkHistoryServices workHistoryservices = new Hre_WorkHistoryServices();

                    if (profileEntity != null && model.CodeAttendance != null && model.DateApplyAttendanceCode != null && (model.CodeAttendance != profileEntity.CodeAttendance ||
                                                                                                                           model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        // Chỉ thay đổi mã chấm công
                        if (model.DateApplyAttendanceCode == profileEntity.DateApplyAttendanceCode && model.CodeAttendance != profileEntity.CodeAttendance)
                        {
                            Hre_CardHistoryEntity history = cardservices.GetData <Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.CardCode = model.CodeAttendance;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history            = new Hre_CardHistoryEntity();
                                history.ProfileID  = model.ID;
                                history.CardCode   = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                        // Chỉ thay đổi Ngày áp dụng mã chấm công

                        else if (model.CodeAttendance == profileEntity.CodeAttendance && model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode)
                        {
                            if (model.DateApplyAttendanceCode < profileEntity.DateApplyAttendanceCode)
                            {
                                model.StatusVerify = "Invalid";
                                return(model);
                            }
                            Hre_CardHistoryEntity history = cardservices.GetData <Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history            = new Hre_CardHistoryEntity();
                                history.ProfileID  = model.ID;
                                history.CardCode   = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                    }
                    // Tạo mới NV hoặc thay đổi cả 2( mã chấm công + ngày hiệu lực)
                    Hre_CardHistoryEntity cardhistory = null;
                    if (model != null && model.ID == Guid.Empty || (model != null && profileEntity != null && model.CodeAttendance != profileEntity.CodeAttendance &&
                                                                    model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        cardhistory            = new Hre_CardHistoryEntity();
                        cardhistory.ProfileID  = model.ID;
                        cardhistory.CardCode   = model.CodeAttendance;
                        cardhistory.DateEffect = model.DateApplyAttendanceCode;
                    }
                    #endregion

                    #region Xử lý lưu quá trình công tác
                    Hre_WorkHistoryEntity workHistory = null;
                    if (model != null && (model.JobTitleID != profileEntity.JobTitleID || model.PositionID != profileEntity.PositionID || model.EmpTypeID != profileEntity.EmpTypeID ||
                                          (model.DateOfEffect != null && profileEntity.DateOfEffect != null &&
                                           model.DateOfEffect.Value.ToString() != profileEntity.DateOfEffect.Value.ToString()) ||
                                          model.CostCentreID != profileEntity.CostCentreID || model.SupervisorID != profileEntity.SupervisorID ||
                                          model.OrgStructureID != profileEntity.OrgStructureID || model.WorkPlaceID != profileEntity.WorkPlaceID))
                    {
                        workHistory = new Hre_WorkHistoryEntity();
                        var orgService       = new Cat_OrgStructureServices();
                        var jobtitleService  = new Cat_JobTitleServices();
                        var postitionService = new Cat_PositionServices();
                        var workPlaceService = new Cat_WorkPlaceServices();

                        workHistory.CostCentreID            = model.CostCentreID;
                        workHistory.OrganizationStructureID = model.OrgStructureID;
                        workHistory.PositionID    = model.PositionID;
                        workHistory.JobTitleID    = model.JobTitleID;
                        workHistory.SalaryClassID = model.SalaryClassID;
                        workHistory.CostSourceID  = model.CostSourceID;
                        workHistory.AbilityTileID = model.AbilityTileID;
                        if (profileEntity != null)
                        {
                            var orgStructureOld = new Cat_OrgStructureEntity();
                            if (profileEntity.OrgStructureID != null && profileEntity.OrgStructureID != Guid.Empty)
                            {
                                orgStructureOld = orgService.GetData <Cat_OrgStructureEntity>(profileEntity.OrgStructureID, ConstantSql.hrm_cat_sp_get_OrgStructureById, UserLogin, ref status).FirstOrDefault();
                            }
                            var jobtitleOld = new Cat_JobTitleEntity();
                            if (profileEntity.JobTitleID != null && profileEntity.JobTitleID != Guid.Empty)
                            {
                                jobtitleOld = jobtitleService.GetData <Cat_JobTitleEntity>(profileEntity.JobTitleID, ConstantSql.hrm_cat_sp_get_HDTJobTypeById, UserLogin, ref status).FirstOrDefault();
                            }
                            var postitionOld = new Cat_PositionEntity();
                            if (profileEntity.PositionID != null && profileEntity.PositionID != Guid.Empty)
                            {
                                postitionOld = postitionService.GetData <Cat_PositionEntity>(profileEntity.PositionID, ConstantSql.hrm_cat_sp_get_PositionById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlace = new Cat_WorkPlaceEntity();
                            if (model.WorkPlaceID != null && model.WorkPlaceID != Guid.Empty)
                            {
                                workPlace = workPlaceService.GetData <Cat_WorkPlaceEntity>(model.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlaceOld = new Cat_WorkPlaceEntity();
                            if (profileEntity.WorkPlaceID != null && profileEntity.WorkPlaceID != Guid.Empty)
                            {
                                workPlaceOld = workPlaceService.GetData <Cat_WorkPlaceEntity>(profileEntity.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            workHistory.OrgOld          = orgStructureOld != null ? orgStructureOld.OrgStructureName : "";
                            workHistory.JobTitleOld     = jobtitleOld != null ? jobtitleOld.JobTitleName : "";
                            workHistory.PositionOld     = postitionOld != null ? postitionOld.PositionName : "";
                            workHistory.WorkLocation    = workPlace != null ? workPlace.WorkPlaceName : "";
                            workHistory.WorkLocationOld = workPlaceOld != null ? workPlaceOld.WorkPlaceName : "";
                        }
                        if (workHistory.ID == Guid.Empty)
                        {
                            if (model.DateOfEffect != null)
                            {
                                workHistory.DateEffective = model.DateOfEffect.Value;
                            }
                            else
                            {
                                workHistory.DateEffective = DateTime.Now;
                            }
                        }

                        if (model.DateQuit != null && (profileEntity == null || profileEntity.DateQuit != model.DateQuit))
                        {
                            workHistory.DateEffective = model.DateQuit.Value;
                        }
                    }

                    #region Ngày hiệu lực phải <= ngày hiện tại thì mới cập nhật lại quá trình công tác
                    if (model.DateOfEffect > DateTime.Now && profileEntity != null && profileEntity.DateOfEffect != null)
                    {
                        model.DateOfEffect     = profileEntity.DateOfEffect;
                        model.OrgStructureID   = profileEntity.OrgStructureID;
                        model.ShopID           = profileEntity.ShopID;
                        model.JobTitleID       = profileEntity.JobTitleID;
                        model.PositionID       = profileEntity.PositionID;
                        model.SupervisorID     = profileEntity.SupervisorID;
                        model.HighSupervisorID = profileEntity.HighSupervisorID;
                        model.IsHeadDept       = profileEntity.IsHeadDept;
                        model.EmpTypeID        = profileEntity.EmpTypeID;
                        model.LaborType        = profileEntity.LaborType;
                        model.SikillLevel      = profileEntity.SikillLevel;
                        model.PayrollGroupID   = profileEntity.PayrollGroupID;
                        model.SalaryClassID    = profileEntity.SalaryClassID;
                        model.CostCentreID     = profileEntity.CostCentreID;
                        model.LocationCode     = profileEntity.LocationCode;
                        model.WorkPlaceID      = profileEntity.WorkPlaceID;
                    }
                    #endregion

                    #endregion

                    var profileModel = service.UpdateOrCreate <Hre_ProfileEntity, Hre_ProfileModel>(model);

                    if (cardhistory != null && profileModel != null)
                    {
                        cardhistory.ProfileID = profileModel.ID;
                        cardservices.Add(cardhistory);
                    }

                    if (workHistory != null && profileModel != null)
                    {
                        workHistory.EmployeeTypeID = profileModel.EmpTypeID;
                        workHistory.ProfileID      = profileModel.ID;
                        workHistoryservices.Add(workHistory);
                    }
                }
            }

            //Xóa cache lưu lại của cây phòng ban
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeView");
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeViewSumProfile");

            return(model);
        }
Esempio n. 3
0
 public string UpdateWorkingPosition(string selectedIds, string userLogin)
 {
     string message = string.Empty;
     string status = string.Empty;
     var profileServices = new Hre_ProfileServices();
     var workhistoryServices = new Hre_WorkHistoryServices();
     List<Guid> lstIds = selectedIds.Split(',').Select(x => Guid.Parse(x)).ToList();
     //   var lstSuspenses = repo.FindBy(m => m.ID != null && lstIds.Contains(m.ID)).ToList();
     var services = new BaseService();
     var lstObj = new List<object>();
     lstObj.AddRange(new object[14]);
     lstObj[12] = 1;
     lstObj[13] = int.MaxValue - 1;
     var lstComback = services.GetData<Hre_StopWorkingEntity>(lstObj, ConstantSql.hrm_hr_sp_get_RegisterComback, userLogin, ref status).ToList().Translate<Hre_StopWorking>();
     lstComback = lstComback.Where(s => lstIds.Contains(s.ID)).ToList();
     Hre_WorkHistoryEntity workHistoryEntity;
     foreach (var item in lstComback)
     {
         var profile = profileServices.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(item.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, userLogin, ref status).FirstOrDefault();
         profile.DateOfEffect = item.DateComeBack;
         string supervisor = null;
         if (profile.SupervisorID != null)
         {
             var supervisorbyProfile = profileServices.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(profile.SupervisorID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, userLogin, ref status).FirstOrDefault();
             if (supervisorbyProfile != null)
             {
                 supervisor = supervisorbyProfile.ProfileName;
             }
         }
         workHistoryEntity = new Hre_WorkHistoryEntity();
         workHistoryEntity.ProfileID = item.ProfileID.Value;
         workHistoryEntity.DateEffective = item.DateComeBack != null ? item.DateComeBack.Value : DateTime.Now;
         workHistoryEntity.OrganizationStructureID = profile.OrgStructureID;
         workHistoryEntity.JobTitleID = profile.JobTitleID;
         workHistoryEntity.PositionID = profile.PositionID;
         workHistoryEntity.Supervisor = supervisor;
         profileServices.Edit(profile);
         workhistoryServices.Add(workHistoryEntity);
     }
     message = NotificationType.Success.ToString();
     return message;
 }
Esempio n. 4
0
        public ActionResult SaveContractAndSaslary(DateTime? dateStart, DateTime? dateEnd, string orgStructureID, string contractTypeID, string RankDetailForNextContract, List<Guid> selectedIds, string statusContract, bool IsEvaluation)
        {
            var hrService = new Hre_ProfileServices();
            string message = string.Empty;
            var actionService = new ActionService(UserLogin);
            string status = string.Empty;
            var lstObjProfile = new List<object>();
            lstObjProfile.AddRange(new object[16]);
            lstObjProfile[14] = 1;
            lstObjProfile[15] = int.MaxValue - 1;
            var lstProfile = actionService.GetData<Hre_ProfileEntity>(lstObjProfile, ConstantSql.hrm_hr_sp_get_Profile, ref status).ToList();

            var salaryRankServices = new Cat_SalaryRankServices();
            var lstObjSalaryRank = new List<object>();
            lstObjSalaryRank.Add(null);
            lstObjSalaryRank.Add(null);
            lstObjSalaryRank.Add(1);
            lstObjSalaryRank.Add(int.MaxValue - 1);
            var lstSalaryRank = actionService.GetData<Cat_SalaryRankEntity>(lstObjSalaryRank, ConstantSql.hrm_cat_sp_get_SalaryRank, ref status).ToList();
            var contractServices = new Hre_ContractServices();
            var lisobjContract = new List<object>();
            string strIDs = string.Empty;
            foreach (var item in selectedIds)
            {
                strIDs += Common.DotNetToOracle(item.ToString()) + ",";
            }
            if (strIDs.IndexOf(",") > 0)
                strIDs = strIDs.Substring(0, strIDs.Length - 1);
            lisobjContract.Add(strIDs);
            var lstContractByProfileID = actionService.GetData<Hre_ContractEntity>(lisobjContract, ConstantSql.hrm_hr_sp_get_ContractsByListId, ref status).ToList();
            var workhistoryService = new Hre_WorkHistoryServices();
            var lstObjWorkhistory = new List<object>();
            lstObjWorkhistory.AddRange(new object[17]);
            lstObjWorkhistory[15] = 1;
            lstObjWorkhistory[16] = int.MaxValue - 1;
            var lstWorkhistory = actionService.GetData<Hre_WorkHistoryEntity>(lstObjWorkhistory, ConstantSql.hrm_hr_sp_get_WorkHistory, ref status).ToList();

            var basicSalaryService = new Sal_BasicSalaryServices();

            var attGradeService = new Att_GradeServices();
            var lstObjAttGrade = new List<object>();
            lstObjAttGrade.AddRange(new object[6]);
            lstObjAttGrade[4] = 1;
            lstObjAttGrade[5] = int.MaxValue - 1;
            var lstAttGrade = actionService.GetData<Att_GradeEntity>(lstObjAttGrade, ConstantSql.hrm_att_sp_get_Att_Grade, ref status).ToList();

            var gradeService = new Sal_GradeServices();
            var lstObjSalGrade = new List<object>();
            lstObjSalGrade.AddRange(new object[7]);
            lstObjSalGrade[5] = 1;
            lstObjSalGrade[6] = int.MaxValue - 1;
            var lstSalGrade = actionService.GetData<Sal_GradeEntity>(lstObjSalGrade, ConstantSql.hrm_sal_sp_get_Sal_Grade, ref status).ToList();

            var gradePayrollService = new Cat_GradePayrollServices();
            var lstObjGradePayroll = new List<object>();
            lstObjGradePayroll.Add(null);
            lstObjGradePayroll.Add(null);
            lstObjGradePayroll.Add(1);
            lstObjGradePayroll.Add(int.MaxValue - 1);
            var lstGradePayroll = actionService.GetData<Cat_GradePayrollEntity>(lstObjGradePayroll, ConstantSql.hrm_cat_sp_get_GradePayroll, ref status).ToList();

            var gradeAttService = new Cat_GradeAttendanceServices();
            var lstObjGradeAtt = new List<object>();
            lstObjGradeAtt.AddRange(new object[10]);
            lstObjGradeAtt[8] = 1;
            lstObjGradeAtt[9] = int.MaxValue - 1;
            var lstGradeAtt = actionService.GetData<Cat_GradeAttendanceEntity>(lstObjGradeAtt, ConstantSql.hrm_cat_sp_get_Cat_GradeAttendance, ref status).ToList();

            var currencyServices = new Cat_CurrencyServices();
            var lstObjCurrency = new List<object>();
            lstObjCurrency.Add(null);
            lstObjCurrency.Add(null);
            lstObjCurrency.Add(1);
            lstObjCurrency.Add(int.MaxValue - 1);
            var lstCurrency = actionService.GetData<Cat_CurrencyEntity>(lstObjCurrency, ConstantSql.hrm_cat_sp_get_Currency, ref status).ToList();
            var lstCurrencyNew = lstCurrency.Where(s => s.CurrencyName == "VND").FirstOrDefault();

            var contractTypeService = new Cat_ContractTypeServices();
            var lstObjContractType = new List<object>();
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(1);
            lstObjContractType.Add(int.MaxValue - 1);
            var lstContractType = actionService.GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status).ToList();

            var insuranceConfigServices = new Cat_InsuranceConfigServices();
            var objInsuranceConfig = new List<object>();
            objInsuranceConfig.Add(1);
            objInsuranceConfig.Add(int.MaxValue - 1);
            var lstInsuranceConfig = actionService.GetData<Cat_InsuranceConfigEntity>(objInsuranceConfig, ConstantSql.hrm_cat_sp_get_InsuranceConfig, ref status).ToList();

            var insuranceServices = new Sal_InsuranceSalaryServices();
            var objInsurance = new List<object>();
            objInsurance.AddRange(new object[9]);
            objInsurance[7] = 1;
            objInsurance[8] = int.MaxValue - 1;
            var lstInsurance = actionService.GetData<Sal_InsuranceSalaryEntity>(objInsurance, ConstantSql.hrm_sal_sp_get_InsuranceSalary, ref status).ToList();

            foreach (var item in lstContractByProfileID)
            {
                var contractTypeEntity = new Cat_ContractTypeEntity();
                var objContract = new List<object>();
                objContract.Add(item.ProfileID);
                var lstContractIdByProfileID = actionService.GetData<Hre_ContractEntity>(objContract, ConstantSql.hrm_hr_sp_get_ContractsByProfileId, ref status);
                var listIdContract = string.Empty;
                if (lstContractIdByProfileID != null)
                {
                    listIdContract = string.Join(",", lstContractIdByProfileID.Select(d => d.ContractTypeID));
                }

                var profile = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault();

                if (item.NextContractTypeID != null)
                {
                    contractTypeEntity = lstContractType.Where(s => item.NextContractTypeID.Value == s.ID).FirstOrDefault();
                }
                else
                {
                    message = ConstantMessages.WarningContractHaveNotNextContract.ToString().TranslateString();
                    return Json(message, JsonRequestBehavior.AllowGet);
                    // contractTypeEntity = lstContractType.Where(s => Guid.Parse(Common.DotNetToOracle(item.ContractNextID.ToString())) == s.ID).FirstOrDefault();
                }


                var workingHistoryEntity = lstWorkhistory.Where(s => s.ProfileID == item.ProfileID).FirstOrDefault();
                var objSalGrade = new List<object>();
                objSalGrade.Add(item.ProfileID);
                objSalGrade.Add(null);
                objSalGrade.Add(1);
                objSalGrade.Add(int.MaxValue - 1);
                var salGradeByProfileIDEntity = actionService.GetData<Sal_GradeEntity>(objSalGrade, ConstantSql.hrm_sal_sp_get_GradeAndAllownaceByProId, ref status).FirstOrDefault();
                var objAttGrade = new List<object>();
                objAttGrade.Add(item.ProfileID);
                objAttGrade.Add(null);
                objAttGrade.Add(1);
                objAttGrade.Add(int.MaxValue - 1);
                var attGradeByProfileIDEntity = actionService.GetData<Att_GradeEntity>(objAttGrade, ConstantSql.hrm_att_sp_get_GradeAttendanceByProIdCutID, ref status).FirstOrDefault();

                if (contractTypeEntity == null)
                {
                    continue;
                }

                if (item.ContractResult == EnumDropDown.ResultContract.PASS.ToString())
                {
                    if (item.ContractEvaType == EnumDropDown.ContractEvaType.E_EXPIRED_APPRENTICE.ToString())
                    {

                        //chưa tìm dc cách xử lý nên hard code 
                        var lstSalaryRankNew = new Cat_SalaryRankEntity();
                        // var lstSalaryRankNew = lstSalaryRank.Where(s => item.RankDetailForNextContract != null && s.ID == item.RankDetailForNextContract.Value).FirstOrDefault();
                        if (item.RankDetailForNextContract != null)
                        {
                            lstSalaryRankNew = lstSalaryRank.Where(s => item.RankDetailForNextContract != null && s.ID == item.RankDetailForNextContract.Value).FirstOrDefault();
                        }
                        else
                        {
                            lstSalaryRankNew = lstSalaryRank.Where(s => item.RankRateID != null && s.ID == item.RankRateID.Value).FirstOrDefault();
                        }

                        #region Xử lý Hre_Contract
                        if (item.TypeOfPass == EnumDropDown.TypeOfPass.E_SIGNED_NEXTCONTRACT.ToString())
                        {
                            int month = 0;
                            if (contractTypeEntity != null && contractTypeEntity.ValueTime != null)
                            {
                                month = (int)contractTypeEntity.ValueTime.Value;
                                if (contractTypeEntity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                                {
                                    month = month * 12;
                                }
                                contractTypeEntity.DateStart = item.DateEnd.Value.AddDays(1);

                                //chưa tìm dc cách xử lý nên hard code 
                                //  var nextContractTypeID = Common.ConvertToGuid(contractTypeEntity.ContractNextID).ToString();
                                var contractEntity = new Hre_ContractEntity
                                {
                                    //   ContractNo = getContractNo(item, item.DateSigned),
                                    ProfileID = item.ProfileID,
                                    ProfileName = item.ProfileName,
                                    DateStart = item.DateEnd.Value.AddDays(1),
                                    DateSigned = item.DateEnd.Value.AddDays(1),
                                    JobTitleID = item.JobTitleID,
                                    PositionID = item.PositionID,
                                    DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                    Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                    RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                                    ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                    ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                    SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                    ContractTypeID = contractTypeEntity.ID
                                };

                                if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                                {
                                    contractEntity = SetNewDateEndContract(contractEntity);
                                }

                                if (item.DateEndNextContract != null)
                                {
                                    contractEntity.DateEnd = item.DateEndNextContract.Value;
                                }
                                if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                                {
                                    return Json(contractEntity, JsonRequestBehavior.AllowGet);
                                }
                                message = contractServices.Add(contractEntity);
                            }
                            else
                            {
                                contractTypeEntity.DateStart = item.DateEnd.Value.AddDays(1);

                                //chưa tìm dc cách xử lý nên hard code 
                                //  var nextContractTypeID = Common.ConvertToGuid(contractTypeEntity.ContractNextID).ToString();
                                var contractEntity = new Hre_ContractEntity
                                {
                                    //  ContractNo = getContractNo(item, item.DateSigned),
                                    ProfileID = item.ProfileID,
                                    ProfileName = item.ProfileName,
                                    DateStart = item.DateEnd.Value.AddDays(1),
                                    DateSigned = item.DateEnd.Value.AddDays(1),
                                    JobTitleID = item.JobTitleID,
                                    PositionID = item.PositionID,
                                    //   DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                    Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                    RankRateID = lstSalaryRankNew == null ? item.RankRateID : lstSalaryRankNew.ID,
                                    ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                    ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                    SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                    ContractTypeID = contractTypeEntity.ID
                                };

                                if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                                {
                                    contractEntity = SetNewDateEndContract(contractEntity);
                                }
                                if (item.DateEndNextContract != null)
                                {
                                    contractEntity.DateEnd = item.DateEndNextContract.Value;
                                }
                                if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                                {
                                    return Json(contractEntity, JsonRequestBehavior.AllowGet);
                                }
                                message = contractServices.Add(contractEntity);
                            }
                        }

                        #endregion

                        #region Xử Lý Sal_BasicSalary
                        var salaryEntity = new Sal_BasicSalaryEntity
                        {
                            ProfileID = item.ProfileID,
                            ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                            GrossAmount = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryStandard.ToString(),
                            DateOfEffect = item.DateEnd.Value.AddDays(1),
                            CurrencyID = lstCurrencyNew.ID,
                            Note = item.Remark


                        };
                        message = basicSalaryService.Add(salaryEntity);

                        #endregion

                        #region Xử Lý Hre_Profile
                        var profileEntity = profile.CopyData<Hre_ProfileEntity>();
                        profileEntity.SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID;

                        hrService.Edit(profileEntity);

                        if (workingHistoryEntity != null)
                        {
                            if (workingHistoryEntity.SalaryClassID != lstSalaryRankNew.SalaryClassID)
                            {
                                var workhistoryEntity = new Hre_WorkHistoryEntity
                                {
                                    ProfileID = item.ProfileID,
                                    SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                    DateEffective = item.DateEnd.Value.AddDays(1)
                                };
                                message = workhistoryService.Add(workhistoryEntity);
                            }

                        }
                        else
                        {
                            var workhistoryEntity = new Hre_WorkHistoryEntity
                            {
                                ProfileID = item.ProfileID,
                                SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                DateEffective = item.DateEnd.Value.AddDays(1)
                            };
                            message = workhistoryService.Add(workhistoryEntity);
                        }

                        #endregion

                        #region Sal_Grade
                        var lstGradeByProfileID = lstSalGrade.Where(s => item.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                        var lstGradePayrollByProfileID = lstGradePayroll.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                        if (salGradeByProfileIDEntity != null)
                        {
                            if (salGradeByProfileIDEntity.GradePayrollID != lstGradePayrollByProfileID.ID)
                            {
                                var gradeEntity = new Sal_GradeEntity
                                {
                                    //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                    ProfileID = item.ProfileID,
                                    GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                    MonthStart = item.DateEnd.Value.AddDays(1)
                                };
                                message = gradeService.Add(gradeEntity);
                            }

                        }
                        else
                        {
                            var gradeEntity = new Sal_GradeEntity
                            {
                                //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                ProfileID = item.ProfileID,
                                GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                MonthStart = item.DateEnd.Value.AddDays(1)
                            };
                            message = gradeService.Add(gradeEntity);
                        }

                        #endregion

                        #region Att_Grade
                        var lstAttGradeByProfileID = lstAttGrade.Where(s => item.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                        var lstGradeAttByProfileID = lstGradeAtt.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                        if (attGradeByProfileIDEntity != null)
                        {
                            if (attGradeByProfileIDEntity.GradeAttendanceID != lstGradeAttByProfileID.ID)
                            {
                                var gradeAttEntity = new Att_GradeEntity
                                {
                                    // ID = lstGradeAttByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                    ProfileID = item.ProfileID,
                                    GradeAttendanceID = lstAttGradeByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                    MonthStart = item.DateEnd.Value.AddDays(1)
                                };
                                message = attGradeService.Add(gradeAttEntity);
                            }
                        }
                        else
                        {
                            var gradeAttEntity = new Att_GradeEntity
                            {
                                // ID = lstGradeAttByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                ProfileID = item.ProfileID,
                                GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                MonthStart = item.DateEnd.Value.AddDays(1)
                            };
                            message = attGradeService.Add(gradeAttEntity);
                        }


                        #endregion

                        #region Xử Lý Lương BHXH
                        if (contractTypeEntity.NoneTypeInsuarance == true)
                        {
                            var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == item.ProfileID && s.DateEffect == item.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                            var insuranceEntity = new Sal_InsuranceSalaryEntity
                            {
                                ProfileID = item.ProfileID,
                                InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                DateEffect = item.DateEnd.Value.AddDays(1),
                                IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                                IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                                IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                                CurrencyID = lstCurrencyNew.ID
                            };
                            if (insuranceEntityByProfileID != null)
                            {
                                insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                insuranceEntityByProfileID.IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance;
                                insuranceEntityByProfileID.IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance;
                                insuranceEntityByProfileID.IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance;
                                message = insuranceServices.Edit(insuranceEntityByProfileID);
                            }
                            else
                            {
                                message = insuranceServices.Add(insuranceEntity);
                            }


                        }

                        if (contractTypeEntity.NoneTypeInsuarance == false)
                        {

                            var insuranceConfigEntity = lstInsuranceConfig.Where(s => s.ContractTypeID != null && s.ContractTypeID.Value == contractTypeEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                            if (insuranceConfigEntity != null)
                            {
                                var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == item.ProfileID && s.DateEffect == item.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                                var insuranceEntity = new Sal_InsuranceSalaryEntity
                                {
                                    ProfileID = item.ProfileID,
                                    InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                    DateEffect = item.DateEnd.Value.AddDays(1),
                                    IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial,
                                    IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy,
                                    IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth,
                                    CurrencyID = lstCurrencyNew.ID
                                };

                                if (insuranceEntityByProfileID != null)
                                {
                                    insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                    insuranceEntityByProfileID.IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial;
                                    insuranceEntityByProfileID.IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy;
                                    insuranceEntityByProfileID.IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth;
                                    message = insuranceServices.Edit(insuranceEntityByProfileID);
                                }
                                else
                                {
                                    message = insuranceServices.Add(insuranceEntity);
                                }

                            }
                        }
                        #endregion

                        //  return Json(message, JsonRequestBehavior.AllowGet);
                    }

                    if (item.ContractEvaType == EnumDropDown.ContractEvaType.E_ANNUAL_EVALUATION.ToString() && item.ContractResult == EnumDropDown.ResultContract.PASS.ToString())
                    {

                        var lstSalaryRankNew = new Cat_SalaryRankEntity();
                        // var lstSalaryRankNew = lstSalaryRank.Where(s => item.RankDetailForNextContract != null && s.ID == item.RankDetailForNextContract.Value).FirstOrDefault();
                        if (item.RankDetailForNextContract != null)
                        {
                            lstSalaryRankNew = lstSalaryRank.Where(s => item.RankDetailForNextContract != null && s.ID == item.RankDetailForNextContract.Value).FirstOrDefault();
                        }
                        else
                        {
                            lstSalaryRankNew = lstSalaryRank.Where(s => item.RankRateID != null && s.ID == item.RankRateID.Value).FirstOrDefault();
                        }

                        #region Xử lý Hre_Contract
                        int month = 0;
                        if (contractTypeEntity != null && contractTypeEntity.ValueTime != null)
                        {
                            month = (int)contractTypeEntity.ValueTime.Value;
                            if (contractTypeEntity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                            {
                                month = month * 12;
                            }
                            contractTypeEntity.DateStart = item.DateEnd.Value.AddDays(1);

                            //chưa tìm dc cách xử lý nên hard code 

                            var contractEntity = new Hre_ContractEntity
                            {
                                // ContractNo = getContractNo(item, item.DateSigned),
                                ProfileID = item.ProfileID,
                                ProfileName = item.ProfileName,
                                DateStart = new DateTime(DateTime.Now.Year, 6, 1),
                                DateSigned = new DateTime(DateTime.Now.Year, 6, 1),
                                JobTitleID = item.JobTitleID,
                                PositionID = item.PositionID,
                                DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                                ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                ContractTypeID = contractTypeEntity.ID
                            };

                            if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                            {
                                contractEntity = SetNewDateEndContract(contractEntity);
                            }
                            if (item.DateEndNextContract != null)
                            {
                                contractEntity.DateEnd = item.DateEndNextContract.Value;
                            }
                            if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                            {
                                return Json(contractEntity, JsonRequestBehavior.AllowGet);
                            }
                            message = contractServices.Add(contractEntity);
                        }
                        else
                        {
                            contractTypeEntity.DateStart = item.DateEnd.Value.AddDays(1);

                            //chưa tìm dc cách xử lý nên hard code 

                            var contractEntity = new Hre_ContractEntity
                            {
                                // ContractNo = getContractNo(item, item.DateSigned),
                                ProfileID = item.ProfileID,
                                ProfileName = item.ProfileName,
                                DateStart = new DateTime(DateTime.Now.Year, 6, 1),
                                DateSigned = new DateTime(DateTime.Now.Year, 6, 1),
                                JobTitleID = item.JobTitleID,
                                PositionID = item.PositionID,
                                // DateEnd = null,
                                Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                                ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                ContractTypeID = contractTypeEntity.ID
                            };

                            if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                            {
                                contractEntity = SetNewDateEndContract(contractEntity);
                            }

                            if (item.DateEndNextContract != null)
                            {
                                contractEntity.DateEnd = item.DateEndNextContract.Value;
                            }
                            if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                            {

                                return Json(contractEntity, JsonRequestBehavior.AllowGet);
                            }
                            message = contractServices.Add(contractEntity);
                        }
                        #endregion

                        #region Xử Lý Sal_BasicSalary
                        var salaryEntity = new Sal_BasicSalaryEntity
                        {
                            ProfileID = item.ProfileID,
                            ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                            GrossAmount = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryStandard.ToString(),
                            DateOfEffect = new DateTime(DateTime.Now.Year, 6, 1),
                            CurrencyID = lstCurrencyNew.ID,
                            Note = item.Remark

                        };
                        message = basicSalaryService.Add(salaryEntity);

                        #endregion

                        #region Xử Lý Hre_Profile
                        var profileEntity = profile.CopyData<Hre_ProfileEntity>();
                        profileEntity.SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID;
                        message = hrService.Edit(profileEntity);

                        if (workingHistoryEntity != null)
                        {
                            if (workingHistoryEntity.SalaryClassID != lstSalaryRankNew.SalaryClassID)
                            {
                                var workhistoryEntity = new Hre_WorkHistoryEntity
                                {
                                    ProfileID = item.ProfileID,
                                    SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                    DateEffective = new DateTime(DateTime.Now.Year, 6, 1)
                                };
                                message = workhistoryService.Add(workhistoryEntity);
                            }

                        }
                        else
                        {
                            var workhistoryEntity = new Hre_WorkHistoryEntity
                            {
                                ProfileID = item.ProfileID,
                                SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                DateEffective = new DateTime(DateTime.Now.Year, 6, 1)
                            };
                            message = workhistoryService.Add(workhistoryEntity);
                        }
                        #endregion

                        #region Sal_Grade
                        var lstGradeByProfileID = lstSalGrade.Where(s => item.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                        var lstGradePayrollByProfileID = lstGradePayroll.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                        if (salGradeByProfileIDEntity != null)
                        {
                            if (salGradeByProfileIDEntity.GradePayrollID != lstGradePayrollByProfileID.ID)
                            {
                                var gradeEntity = new Sal_GradeEntity
                                {
                                    //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                    ProfileID = item.ProfileID,
                                    GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                    MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                                };
                                message = gradeService.Add(gradeEntity);
                            }
                        }
                        else
                        {
                            var gradeEntity = new Sal_GradeEntity
                            {
                                //  ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                ProfileID = item.ProfileID,
                                GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                            };
                            message = gradeService.Add(gradeEntity);
                        }


                        #endregion

                        #region Att_Grade
                        var lstAttGradeByProfileID = lstAttGrade.Where(s => item.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                        var lstGradeAttByProfileID = lstGradeAtt.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                        if (attGradeByProfileIDEntity != null)
                        {
                            if (attGradeByProfileIDEntity.GradeAttendanceID != lstGradeAttByProfileID.ID)
                            {
                                var gradeAttEntity = new Att_GradeEntity
                                {
                                    //ID = lstAttGradeByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                    ProfileID = item.ProfileID,
                                    GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                    MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                                };
                                message = attGradeService.Add(gradeAttEntity);
                            }
                        }
                        else
                        {
                            var gradeAttEntity = new Att_GradeEntity
                            {
                                //ID = lstAttGradeByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                ProfileID = item.ProfileID,
                                GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                            };
                            message = attGradeService.Add(gradeAttEntity);
                        }


                        #endregion

                        #region Xử Lý Lương BHXH
                        if (contractTypeEntity.NoneTypeInsuarance == true)
                        {
                            var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == item.ProfileID && s.DateEffect == item.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                            var insuranceEntity = new Sal_InsuranceSalaryEntity
                            {
                                ProfileID = item.ProfileID,
                                InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                DateEffect = item.DateEnd.Value.AddDays(1),
                                IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                                IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                                IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                                CurrencyID = lstCurrencyNew.ID
                            };

                            if (insuranceEntityByProfileID != null)
                            {
                                insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                insuranceEntityByProfileID.IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance;
                                insuranceEntityByProfileID.IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance;
                                insuranceEntityByProfileID.IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance;
                                message = insuranceServices.Edit(insuranceEntityByProfileID);
                            }
                            else
                            {
                                message = insuranceServices.Add(insuranceEntity);
                            }
                        }
                        if (contractTypeEntity.NoneTypeInsuarance == false)
                        {
                            var insuranceConfigEntity = lstInsuranceConfig.Where(s => s.ContractTypeID != null && s.ContractTypeID.Value == contractTypeEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                            if (insuranceConfigEntity != null)
                            {
                                var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == item.ProfileID && s.DateEffect == item.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                                var insuranceEntity = new Sal_InsuranceSalaryEntity
                                {
                                    ProfileID = item.ProfileID,
                                    InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                    DateEffect = item.DateEnd.Value.AddDays(1),
                                    IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial,
                                    IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy,
                                    IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth,
                                    CurrencyID = lstCurrencyNew.ID
                                };
                                if (insuranceEntityByProfileID != null)
                                {
                                    insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                    insuranceEntityByProfileID.IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial;
                                    insuranceEntityByProfileID.IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy;
                                    insuranceEntityByProfileID.IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth;
                                    message = insuranceServices.Edit(insuranceEntityByProfileID);
                                }
                                else
                                {
                                    message = insuranceServices.Add(insuranceEntity);
                                }
                            }
                        }
                        #endregion

                    }
                }
            }
            return Json(message, JsonRequestBehavior.AllowGet);
            //   return null;
        }
Esempio n. 5
0
 public ActionResult GetTopWorkHistoryByProfileID(Guid profileID)
 {
     string status = string.Empty;
     var actionServices = new ActionService(UserLogin);
     var result = actionServices.GetData<Hre_WorkHistoryEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_hr_sp_get_WorkHistoryByProfileId, ref status).ToList();
     Hre_WorkHistoryEntity objWorkHistory = new Hre_WorkHistoryEntity();
     if (result.Count > 0)
     {
         objWorkHistory = result.OrderByDescending(s => s.DateEffective).FirstOrDefault();
         return Json(objWorkHistory);
     }
     else
     {
         return null;
     }
 }
Esempio n. 6
0
        public string SaveContractAndNextSalaryApprovedEvaluation(Hre_ContractEntity contract)
        {

            if (contract.DateEndNextContract == null)
            {
                return string.Empty;
            }

            // Lấy biến Dateend này gắn cho quá trình công tác khi cập nhật quá trinh công tác ở dưới
            DateTime? dateEnd = contract.DateEnd;

            string message = string.Empty;
            var actionService = new ActionService(UserLogin);
            string status = string.Empty;

            var profile = actionService.GetData<Hre_ProfileEntity>(contract.ProfileID, ConstantSql.hrm_hr_sp_get_ProfileById, ref status).FirstOrDefault();
            var hrService = new Hre_ProfileServices();
            var salaryRankServices = new Cat_SalaryRankServices();
            var lstObjSalaryRank = new List<object>();
            lstObjSalaryRank.Add(null);
            lstObjSalaryRank.Add(null);
            lstObjSalaryRank.Add(1);
            lstObjSalaryRank.Add(int.MaxValue - 1);
            var lstSalaryRank = actionService.GetData<Cat_SalaryRankEntity>(lstObjSalaryRank, ConstantSql.hrm_cat_sp_get_SalaryRank, ref status).ToList();

            var contractServices = new Hre_ContractServices();

            var workhistoryService = new Hre_WorkHistoryServices();
            var lstObjWorkhistory = new List<object>();
            lstObjWorkhistory.AddRange(new object[17]);
            lstObjWorkhistory[15] = 1;
            lstObjWorkhistory[16] = int.MaxValue - 1;
            var lstWorkhistory = actionService.GetData<Hre_WorkHistoryEntity>(lstObjWorkhistory, ConstantSql.hrm_hr_sp_get_WorkHistory, ref status).ToList();

            var basicSalaryService = new Sal_BasicSalaryServices();

            var attGradeService = new Att_GradeServices();
            var lstObjAttGrade = new List<object>();
            lstObjAttGrade.AddRange(new object[6]);
            lstObjAttGrade[4] = 1;
            lstObjAttGrade[5] = int.MaxValue - 1;
            var lstAttGrade = actionService.GetData<Att_GradeEntity>(lstObjAttGrade, ConstantSql.hrm_att_sp_get_Att_Grade, ref status).ToList();

            var gradeService = new Sal_GradeServices();
            var lstObjSalGrade = new List<object>();
            lstObjSalGrade.AddRange(new object[7]);
            lstObjSalGrade[5] = 1;
            lstObjSalGrade[6] = int.MaxValue - 1;
            var lstSalGrade = actionService.GetData<Sal_GradeEntity>(lstObjSalGrade, ConstantSql.hrm_sal_sp_get_Sal_Grade, ref status).ToList();

            var gradePayrollService = new Cat_GradePayrollServices();
            var lstObjGradePayroll = new List<object>();
            lstObjGradePayroll.Add(null);
            lstObjGradePayroll.Add(null);
            lstObjGradePayroll.Add(1);
            lstObjGradePayroll.Add(int.MaxValue - 1);
            var lstGradePayroll = actionService.GetData<Cat_GradePayrollEntity>(lstObjGradePayroll, ConstantSql.hrm_cat_sp_get_GradePayroll, ref status).ToList();

            var gradeAttService = new Cat_GradeAttendanceServices();
            var lstObjGradeAtt = new List<object>();
            lstObjGradeAtt.AddRange(new object[10]);
            lstObjGradeAtt[8] = 1;
            lstObjGradeAtt[9] = int.MaxValue - 1;
            var lstGradeAtt = actionService.GetData<Cat_GradeAttendanceEntity>(lstObjGradeAtt, ConstantSql.hrm_cat_sp_get_Cat_GradeAttendance, ref status).ToList();

            var currencyServices = new Cat_CurrencyServices();
            var lstObjCurrency = new List<object>();
            lstObjCurrency.Add(null);
            lstObjCurrency.Add(null);
            lstObjCurrency.Add(1);
            lstObjCurrency.Add(int.MaxValue - 1);
            var lstCurrency = actionService.GetData<Cat_CurrencyEntity>(lstObjCurrency, ConstantSql.hrm_cat_sp_get_Currency, ref status).ToList();
            var lstCurrencyNew = lstCurrency.Where(s => s.CurrencyName == "VND").FirstOrDefault();

            var contractTypeService = new Cat_ContractTypeServices();
            var lstObjContractType = new List<object>();
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(1);
            lstObjContractType.Add(int.MaxValue - 1);
            var lstContractType = actionService.GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status).ToList();

            var insuranceConfigServices = new Cat_InsuranceConfigServices();
            var objInsuranceConfig = new List<object>();
            objInsuranceConfig.Add(1);
            objInsuranceConfig.Add(int.MaxValue - 1);
            var lstInsuranceConfig = actionService.GetData<Cat_InsuranceConfigEntity>(objInsuranceConfig, ConstantSql.hrm_cat_sp_get_InsuranceConfig, ref status).ToList();

            var insuranceServices = new Sal_InsuranceSalaryServices();
            var objInsurance = new List<object>();
            objInsurance.AddRange(new object[9]);
            objInsurance[7] = 1;
            objInsurance[8] = int.MaxValue - 1;
            var lstInsurance = actionService.GetData<Sal_InsuranceSalaryEntity>(objInsurance, ConstantSql.hrm_sal_sp_get_InsuranceSalary, ref status).ToList();


            var contractTypeEntity = new Cat_ContractTypeEntity();
            var objContract = new List<object>();
            objContract.Add(contract.ProfileID);
            var lstContractIdByProfileID = actionService.GetData<Hre_ContractEntity>(objContract, ConstantSql.hrm_hr_sp_get_ContractsByProfileId, ref status);
            var listIdContract = string.Empty;
            if (lstContractIdByProfileID != null)
            {
                listIdContract = string.Join(",", lstContractIdByProfileID.Select(d => d.ContractTypeID));
            }

            if (contract.NextContractTypeID != null)
            {
                contractTypeEntity = lstContractType.Where(s => contract.NextContractTypeID.Value == s.ID).FirstOrDefault();
            }
            else
            {
                message = ConstantMessages.WarningContractHaveNotNextContract.ToString().TranslateString();
                return message;
            }


            if (contractTypeEntity != null)
            {
                if (contractTypeEntity.Type == EnumDropDown.TypeContract.E_NODURATION.ToString())
                {
                    return string.Empty;
                }
            }

            var workingHistoryEntity = lstWorkhistory.Where(s => s.ProfileID == contract.ProfileID).FirstOrDefault();
            var objSalGrade = new List<object>();
            objSalGrade.Add(contract.ProfileID);
            objSalGrade.Add(null);
            objSalGrade.Add(1);
            objSalGrade.Add(int.MaxValue - 1);
            var salGradeByProfileIDEntity = actionService.GetData<Sal_GradeEntity>(objSalGrade, ConstantSql.hrm_sal_sp_get_GradeAndAllownaceByProId, ref status).FirstOrDefault();
            var objAttGrade = new List<object>();
            objAttGrade.Add(contract.ProfileID);
            objAttGrade.Add(null);
            objAttGrade.Add(1);
            objAttGrade.Add(int.MaxValue - 1);
            var attGradeByProfileIDEntity = actionService.GetData<Att_GradeEntity>(objAttGrade, ConstantSql.hrm_att_sp_get_GradeAttendanceByProIdCutID, ref status).FirstOrDefault();

            if (contractTypeEntity == null)
            {
                return string.Empty;
            }

            var contracttypeByContract = lstContractType.Where(s => s.ID == contract.ContractTypeID).FirstOrDefault();

            if (contract.ContractResult == EnumDropDown.ResultContract.PASS.ToString())
            {
                if (contract.ContractEvaType == EnumDropDown.ContractEvaType.E_EXPIRED_APPRENTICE.ToString())
                {

                    //chưa tìm dc cách xử lý nên hard code 
                    var lstSalaryRankNew = new Cat_SalaryRankEntity();
                    if (contract.RankDetailForNextContract != null)
                    {
                        lstSalaryRankNew = lstSalaryRank.Where(s => contract.RankDetailForNextContract != null && s.ID == contract.RankDetailForNextContract.Value).FirstOrDefault();
                    }
                    else
                    {
                        lstSalaryRankNew = lstSalaryRank.Where(s => contract.RankRateID != null && s.ID == contract.RankRateID.Value).FirstOrDefault();
                    }

                    #region Xử lý Hre_Contract
                    if (contract.TypeOfPass == EnumDropDown.TypeOfPass.E_SIGNED_NEXTCONTRACT.ToString())
                    {
                        int month = 0;
                        if (contractTypeEntity != null && contractTypeEntity.ValueTime != null)
                        {
                            month = (int)contractTypeEntity.ValueTime.Value;
                            if (contractTypeEntity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                            {
                                month = month * 12;
                            }
                            contractTypeEntity.DateStart = contract.DateEnd.Value.AddDays(1);

                            //chưa tìm dc cách xử lý nên hard code 
                            //  var nextContractTypeID = Common.ConvertToGuid(contractTypeEntity.ContractNextID).ToString();
                            var contractEntity = new Hre_ContractEntity
                            {
                                //   ContractNo = getContractNo(item, item.DateSigned),
                                ProfileID = contract.ProfileID,
                                ProfileName = contract.ProfileName,
                                DateStart = contract.DateEnd.Value.AddDays(1),
                                DateSigned = contract.DateEnd.Value.AddDays(1),
                                JobTitleID = contract.JobTitleID,
                                PositionID = contract.PositionID,
                                DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                                ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                ContractTypeID = contractTypeEntity.ID,
                                DateEndNextContract = contract.DateEndNextContract,
                            };
                            if (contract.DateEndNextContract != null)
                            {
                                contractEntity.DateEnd = contract.DateEndNextContract.Value;
                            }
                            contractEntity = SetNewCodeContract(contractEntity, listIdContract);

                            #region Nếu là loại hđ xác định thời hạn thì update lại cột TimesContract theo task 0049731
                            if (contracttypeByContract != null && contracttypeByContract.Type == HRM.Infrastructure.Utilities.EnumDropDown.TypeContract.E_DURATION.ToString())
                            {
                                try
                                {
                                    string times = contractEntity.ContractNo.Substring(contractEntity.ContractNo.Length - 1, 1);
                                    int Year = int.Parse(times);
                                    contractEntity.TimesContract = Year;
                                }
                                catch
                                {
                                }
                            }
                            #endregion
                            contractEntity.Status = "E_APPROVED";
                            contractEntity.StatusEvaluation = "E_APPROVED";
                            contractEntity.DateExtend = contract.DateEnd;
                            if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                            {
                                return string.Empty;
                            }
                            message = contractServices.Add(contractEntity);
                        }
                        else
                        {
                            contractTypeEntity.DateStart = contract.DateEnd.Value.AddDays(1);

                            //chưa tìm dc cách xử lý nên hard code 
                            //  var nextContractTypeID = Common.ConvertToGuid(contractTypeEntity.ContractNextID).ToString();
                            var contractEntity = new Hre_ContractEntity
                            {
                                //  ContractNo = getContractNo(item, item.DateSigned),
                                ProfileID = contract.ProfileID,
                                ProfileName = contract.ProfileName,
                                DateStart = contract.DateEnd.Value.AddDays(1),
                                DateSigned = contract.DateEnd.Value.AddDays(1),
                                JobTitleID = contract.JobTitleID,
                                PositionID = contract.PositionID,
                                //   DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                RankRateID = lstSalaryRankNew == null ? contract.RankRateID : lstSalaryRankNew.ID,
                                ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                ContractTypeID = contractTypeEntity.ID
                            };

                            //if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                            //{
                            //    contractEntity = SetNewDateEndContract(contractEntity);
                            //}
                            if (contract.DateEndNextContract != null)
                            {
                                contractEntity.DateEnd = contract.DateEndNextContract.Value;
                            }
                            contractEntity.DateExtend = contract.DateEnd;
                            contractEntity.StatusEvaluation = "E_APPROVED";

                            if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                            {
                                return string.Empty;
                            }

                            message = contractServices.Add(contractEntity);
                        }
                    }

                    //Edit lai StatusEvaluation 
                    contract.StatusEvaluation = "E_APPROVED";
                    message = contractServices.Edit(contract);

                    #endregion

                    #region Xử Lý Sal_BasicSalary
                    var salaryEntity = new Sal_BasicSalaryEntity
                    {
                        ProfileID = contract.ProfileID,
                        ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                        RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                        GrossAmount = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryStandard.ToString(),
                        DateOfEffect = contract.DateSigned != null ? contract.DateSigned.Value : DateTime.Now,
                        CurrencyID = lstCurrencyNew.ID,
                        Note = contract.Remark,
                        Status = "E_APPROVED"
                    };
                    message = basicSalaryService.Add(salaryEntity);

                    #endregion

                    #region Xử Lý Hre_Profile
                    var profileEntity = profile.CopyData<Hre_ProfileEntity>();
                    Guid? _AbilityTileID = null;
                    profileEntity.SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID;
                    if (profileEntity.SalaryClassID != null)
                    {
                        var abilityTitleBySalaryClass = hrService.GetData<Cat_AbilityTileEntity>(Common.DotNetToOracle(profileEntity.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault();
                        if (abilityTitleBySalaryClass != null)
                        {
                            _AbilityTileID = abilityTitleBySalaryClass.ID;
                            profileEntity.AbilityTileID = _AbilityTileID;
                        }
                    }

                    hrService.Edit(profileEntity);

                    if (workingHistoryEntity != null)
                    {
                        if (workingHistoryEntity.SalaryClassID != lstSalaryRankNew.SalaryClassID)
                        {
                            var workhistoryEntity = new Hre_WorkHistoryEntity
                            {
                                ProfileID = contract.ProfileID,
                                SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                DateEffective = dateEnd != null ? dateEnd.Value.AddDays(1) : DateTime.Now,
                                AbilityTileID = _AbilityTileID,
                                Status = "E_APPROVED"

                            };
                            message = workhistoryService.Add(workhistoryEntity);
                        }


                    }
                    else
                    {
                        var workhistoryEntity = new Hre_WorkHistoryEntity
                        {
                            ProfileID = contract.ProfileID,
                            SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            DateEffective = dateEnd != null ? dateEnd.Value.AddDays(1) : DateTime.Now,
                            Status = "E_APPROVED",

                        };
                        message = workhistoryService.Add(workhistoryEntity);
                    }

                    #endregion

                    #region Sal_Grade
                    var lstGradeByProfileID = lstSalGrade.Where(s => contract.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                    var lstGradePayrollByProfileID = lstGradePayroll.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                    if (salGradeByProfileIDEntity != null)
                    {
                        if (salGradeByProfileIDEntity.GradePayrollID != lstGradePayrollByProfileID.ID)
                        {
                            var gradeEntity = new Sal_GradeEntity
                            {
                                //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                ProfileID = contract.ProfileID,
                                GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                MonthStart = contract.DateSigned.Value,
                            };
                            message = gradeService.Add(gradeEntity);
                        }

                    }
                    else
                    {
                        var gradeEntity = new Sal_GradeEntity
                        {
                            //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                            ProfileID = contract.ProfileID,
                            GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                            MonthStart = contract.DateSigned.Value,
                        };
                        message = gradeService.Add(gradeEntity);
                    }

                    #endregion

                    #region Att_Grade
                    var lstAttGradeByProfileID = lstAttGrade.Where(s => contract.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                    var lstGradeAttByProfileID = lstGradeAtt.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                    if (attGradeByProfileIDEntity != null)
                    {
                        if (attGradeByProfileIDEntity.GradeAttendanceID != lstGradeAttByProfileID.ID)
                        {
                            var gradeAttEntity = new Att_GradeEntity
                            {
                                // ID = lstGradeAttByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                ProfileID = contract.ProfileID,
                                GradeAttendanceID = lstAttGradeByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                MonthStart = contract.DateSigned.Value,
                            };
                            message = attGradeService.Add(gradeAttEntity);
                        }
                    }
                    else
                    {
                        var gradeAttEntity = new Att_GradeEntity
                        {
                            // ID = lstGradeAttByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                            ProfileID = contract.ProfileID,
                            GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                            MonthStart = contract.DateSigned.Value,
                        };
                        message = attGradeService.Add(gradeAttEntity);
                    }


                    #endregion

                    #region Xử Lý Lương BHXH
                    if (contractTypeEntity.NoneTypeInsuarance == true)
                    {
                        var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == contract.ProfileID && s.DateEffect == contract.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                        var insuranceEntity = new Sal_InsuranceSalaryEntity
                        {
                            ProfileID = contract.ProfileID,
                            InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                            DateEffect = contract.DateSigned != null ? contract.DateSigned.Value : DateTime.Now,
                            IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                            IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                            IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                            CurrencyID = lstCurrencyNew.ID
                        };
                        if (insuranceEntityByProfileID != null)
                        {
                            insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                            insuranceEntityByProfileID.IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance;
                            insuranceEntityByProfileID.IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance;
                            insuranceEntityByProfileID.IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance;
                            message = insuranceServices.Edit(insuranceEntityByProfileID);
                        }
                        else
                        {
                            message = insuranceServices.Add(insuranceEntity);
                        }


                    }

                    if (contractTypeEntity.NoneTypeInsuarance == false)
                    {

                        var insuranceConfigEntity = lstInsuranceConfig.Where(s => s.ContractTypeID != null && s.ContractTypeID.Value == contractTypeEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                        if (insuranceConfigEntity != null)
                        {
                            var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == contract.ProfileID && s.DateEffect == contract.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                            var insuranceEntity = new Sal_InsuranceSalaryEntity
                            {
                                ProfileID = contract.ProfileID,
                                InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                DateEffect = contract.DateSigned != null ? contract.DateSigned.Value : DateTime.Now,
                                IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial,
                                IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy,
                                IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth,
                                CurrencyID = lstCurrencyNew.ID
                            };

                            if (insuranceEntityByProfileID != null)
                            {
                                insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                insuranceEntityByProfileID.IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial;
                                insuranceEntityByProfileID.IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy;
                                insuranceEntityByProfileID.IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth;
                                message = insuranceServices.Edit(insuranceEntityByProfileID);
                            }
                            else
                            {
                                message = insuranceServices.Add(insuranceEntity);
                            }

                        }
                    }
                    #endregion
                }

                if (contract.ContractEvaType == EnumDropDown.ContractEvaType.E_ANNUAL_EVALUATION.ToString() && contract.ContractResult == EnumDropDown.ResultContract.PASS.ToString())
                {
                    var lstSalaryRankNew = new Cat_SalaryRankEntity();
                    if (contract.RankDetailForNextContract != null)
                    {
                        lstSalaryRankNew = lstSalaryRank.Where(s => contract.RankDetailForNextContract != null && s.ID == contract.RankDetailForNextContract.Value).FirstOrDefault();
                    }
                    else
                    {
                        lstSalaryRankNew = lstSalaryRank.Where(s => contract.RankRateID != null && s.ID == contract.RankRateID.Value).FirstOrDefault();
                    }

                    #region Xử lý Hre_Contract
                    int month = 0;
                    if (contractTypeEntity != null && contractTypeEntity.ValueTime != null)
                    {
                        month = (int)contractTypeEntity.ValueTime.Value;
                        if (contractTypeEntity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                        {
                            month = month * 12;
                        }
                        contractTypeEntity.DateStart = contract.DateEnd.Value.AddDays(1);

                        //chưa tìm dc cách xử lý nên hard code 

                        var contractEntity = new Hre_ContractEntity
                        {
                            // ContractNo = getContractNo(item, item.DateSigned),
                            ProfileID = contract.ProfileID,
                            ProfileName = contract.ProfileName,
                            DateStart = new DateTime(DateTime.Now.Year, 6, 1),
                            DateSigned = new DateTime(DateTime.Now.Year, 6, 1),
                            JobTitleID = contract.JobTitleID,
                            PositionID = contract.PositionID,
                            DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                            Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                            RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                            ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                            SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                            ContractTypeID = contractTypeEntity.ID
                        };

                        //if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                        //{
                        //    contractEntity = SetNewDateEndContract(contractEntity);
                        //}
                        if (contract.DateEndNextContract != null)
                        {
                            contractEntity.DateEnd = contract.DateEndNextContract.Value;
                        }
                        contractEntity = SetNewCodeContract(contractEntity, listIdContract);

                        #region Nếu là loại hđ xác định thời hạn thì update lại cột TimesContract theo task 0049731
                        if (contracttypeByContract != null && contracttypeByContract.Type == HRM.Infrastructure.Utilities.EnumDropDown.TypeContract.E_DURATION.ToString())
                        {
                            try
                            {
                                string times = contractEntity.ContractNo.Substring(contractEntity.ContractNo.Length - 1, 1);
                                int Year = int.Parse(times);
                                contractEntity.TimesContract = Year;
                            }
                            catch
                            {
                            }
                        }
                        #endregion

                        contractEntity.Status = "E_APPROVED";
                        contractEntity.DateExtend = contract.DateEnd;
                        contractEntity.StatusEvaluation = "E_APPROVED";

                        if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                        {
                            return string.Empty;
                        }
                        message = contractServices.Add(contractEntity);
                    }
                    else
                    {
                        contractTypeEntity.DateStart = contract.DateEnd.Value.AddDays(1);

                        //chưa tìm dc cách xử lý nên hard code 

                        var contractEntity = new Hre_ContractEntity
                        {
                            // ContractNo = getContractNo(item, item.DateSigned),
                            ProfileID = contract.ProfileID,
                            ProfileName = contract.ProfileName,
                            DateStart = new DateTime(DateTime.Now.Year, 6, 1),
                            DateSigned = new DateTime(DateTime.Now.Year, 6, 1),
                            JobTitleID = contract.JobTitleID,
                            PositionID = contract.PositionID,
                            // DateEnd = null,
                            Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                            RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                            ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                            SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                            ContractTypeID = contractTypeEntity.ID
                        };

                        //if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                        //{
                        //    contractEntity = SetNewDateEndContract(contractEntity);
                        //}

                        if (contract.DateEndNextContract != null)
                        {
                            contractEntity.DateEnd = contract.DateEndNextContract.Value;
                        }
                        contractEntity.DateExtend = contract.DateEnd;
                        contractEntity.StatusEvaluation = "E_APPROVED";
                        if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                        {

                            return string.Empty;
                        }
                        message = contractServices.Add(contractEntity);
                    }
                    //Edit lai StatusEvaluation 
                    contract.StatusEvaluation = "E_APPROVED";
                    message = contractServices.Edit(contract);

                    #endregion

                    #region Xử Lý Sal_BasicSalary
                    var salaryEntity = new Sal_BasicSalaryEntity
                    {
                        ProfileID = contract.ProfileID,
                        ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                        RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                        GrossAmount = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryStandard.ToString(),
                        DateOfEffect = new DateTime(DateTime.Now.Year, 6, 1),
                        CurrencyID = lstCurrencyNew.ID,
                        Note = contract.Remark,
                        Status = "E_APPROVED"

                    };
                    message = basicSalaryService.Add(salaryEntity);

                    #endregion

                    #region Xử Lý Hre_Profile
                    var profileEntity = profile.CopyData<Hre_ProfileEntity>();
                    profileEntity.SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID;
                    Guid? _AbilityTileID = null;
                    if (profileEntity.SalaryClassID != null)
                    {
                        var abilityTitleBySalaryClass = actionService.GetData<Cat_AbilityTileEntity>(Common.DotNetToOracle(profileEntity.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, ref status).FirstOrDefault();
                        if (abilityTitleBySalaryClass != null)
                        {
                            _AbilityTileID = abilityTitleBySalaryClass.ID;
                            profileEntity.AbilityTileID = _AbilityTileID;
                        }
                    }
                    message = hrService.Edit(profileEntity);
                    if (workingHistoryEntity != null)
                    {
                        if (workingHistoryEntity.SalaryClassID != lstSalaryRankNew.SalaryClassID)
                        {
                            var workhistoryEntity = new Hre_WorkHistoryEntity
                            {
                                ProfileID = contract.ProfileID,
                                SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                DateEffective = dateEnd != null ? dateEnd.Value.AddDays(1) : DateTime.Now,
                                AbilityTileID = _AbilityTileID,
                                Status = "E_APPROVED"
                            };
                            message = workhistoryService.Add(workhistoryEntity);
                        }
                    }
                    else
                    {
                        var workhistoryEntity = new Hre_WorkHistoryEntity
                        {
                            ProfileID = contract.ProfileID,
                            SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            DateEffective = dateEnd != null ? dateEnd.Value.AddDays(1) : DateTime.Now,
                            Status = "E_APPROVED"

                        };
                        message = workhistoryService.Add(workhistoryEntity);
                    }
                    #endregion

                    #region Sal_Grade
                    var lstGradeByProfileID = lstSalGrade.Where(s => contract.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                    var lstGradePayrollByProfileID = lstGradePayroll.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                    if (salGradeByProfileIDEntity != null)
                    {
                        if (salGradeByProfileIDEntity.GradePayrollID != lstGradePayrollByProfileID.ID)
                        {
                            var gradeEntity = new Sal_GradeEntity
                            {
                                //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                ProfileID = contract.ProfileID,
                                GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                MonthStart = new DateTime(DateTime.Now.Year, 6, 1),

                            };
                            message = gradeService.Add(gradeEntity);
                        }
                    }
                    else
                    {
                        var gradeEntity = new Sal_GradeEntity
                        {
                            //  ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                            ProfileID = contract.ProfileID,
                            GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                            MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                        };
                        message = gradeService.Add(gradeEntity);
                    }


                    #endregion

                    #region Att_Grade
                    var lstAttGradeByProfileID = lstAttGrade.Where(s => contract.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                    var lstGradeAttByProfileID = lstGradeAtt.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                    if (attGradeByProfileIDEntity != null)
                    {
                        if (attGradeByProfileIDEntity.GradeAttendanceID != lstGradeAttByProfileID.ID)
                        {
                            var gradeAttEntity = new Att_GradeEntity
                            {
                                //ID = lstAttGradeByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                ProfileID = contract.ProfileID,
                                GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                            };
                            message = attGradeService.Add(gradeAttEntity);
                        }
                    }
                    else
                    {
                        var gradeAttEntity = new Att_GradeEntity
                        {
                            //ID = lstAttGradeByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                            ProfileID = contract.ProfileID,
                            GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                            MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                        };
                        message = attGradeService.Add(gradeAttEntity);
                    }


                    #endregion

                    #region Xử Lý Lương BHXH
                    if (contractTypeEntity.NoneTypeInsuarance == true)
                    {
                        var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == contract.ProfileID && s.DateEffect == contract.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                        var insuranceEntity = new Sal_InsuranceSalaryEntity
                        {
                            ProfileID = contract.ProfileID,
                            InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                            DateEffect = contract.DateEnd.Value.AddDays(1),
                            IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                            IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                            IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                            CurrencyID = lstCurrencyNew.ID,

                        };

                        if (insuranceEntityByProfileID != null)
                        {
                            insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                            insuranceEntityByProfileID.IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance;
                            insuranceEntityByProfileID.IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance;
                            insuranceEntityByProfileID.IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance;
                            message = insuranceServices.Edit(insuranceEntityByProfileID);
                        }
                        else
                        {
                            message = insuranceServices.Add(insuranceEntity);
                        }
                    }
                    if (contractTypeEntity.NoneTypeInsuarance == false)
                    {
                        var insuranceConfigEntity = lstInsuranceConfig.Where(s => s.ContractTypeID != null && s.ContractTypeID.Value == contractTypeEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                        if (insuranceConfigEntity != null)
                        {
                            var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == contract.ProfileID && s.DateEffect == contract.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                            var insuranceEntity = new Sal_InsuranceSalaryEntity
                            {
                                ProfileID = contract.ProfileID,
                                InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                DateEffect = contract.DateEnd.Value.AddDays(1),
                                IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial,
                                IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy,
                                IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth,
                                CurrencyID = lstCurrencyNew.ID
                            };
                            if (insuranceEntityByProfileID != null)
                            {
                                insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                insuranceEntityByProfileID.IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial;
                                insuranceEntityByProfileID.IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy;
                                insuranceEntityByProfileID.IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth;
                                message = insuranceServices.Edit(insuranceEntityByProfileID);
                            }
                            else
                            {
                                message = insuranceServices.Add(insuranceEntity);
                            }
                        }
                    }
                    #endregion

                }
            }

            return message;
            //   return null;
        }
Esempio n. 7
0
        public ActionResult UpdateDataForProfileWaiting(string SalaryClassName, string ProfileIDs, DateTime? DateEndProbation,
            DateTime DateHire, Guid OrgStructureID, Guid? SalaryRankID, Guid? WorkPlaceID, Guid ContractTypeID, string BasicSalary,
            Guid? GradePayrollID, Guid? GradeAttendanceID,

            Guid? jobTitleID, Guid? positionID, Guid? allowanceID1, Guid? allowanceID2, Guid? allowanceID3, Guid? allowanceID4, Guid? allowanceID5,
            double? allowance1, double? allowance2, double? allowance3, double? allowance4, double? allowance5, Guid? currencyID, double? insuranceSalary, string codeEmp)
        {
            var profileSevices = new Hre_ProfileServices();
            string message = string.Empty;
            string status = string.Empty;
            var actionService = new ActionService(UserLogin);
            var workingHistoryServices = new Hre_WorkHistoryServices();
            var basicSalaryServices = new Sal_BasicSalaryServices();
            var insServices = new Sal_InsuranceSalaryServices();
            var attGradeServices = new Att_GradeServices();
            var salGradeServices = new Sal_GradeServices();
            var contractServices = new Hre_ContractServices();
            var contractTypeServices = new Cat_ContractTypeServices();
            var currencyServices = new Cat_CurrencyServices();
            var settingServices = new Sys_AllSettingServices();

            var lstProfiles = actionService.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status);

            var candidateServices = new Hre_CandidateGeneralServices();
            var lstCandidateGeneral = actionService.GetData<Hre_CandidateGeneralEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_hr_sp_get_CandidateGeneralByProfileIDs, ref status).ToList();

            var salaryRankServices = new Cat_SalaryRankServices();
            var lstObjRank = new List<object>();
            lstObjRank.Add(null);
            lstObjRank.Add(null);
            lstObjRank.Add(1);
            lstObjRank.Add(int.MaxValue - 1);
            var lstRank = actionService.GetData<Cat_SalaryRankEntity>(lstObjRank, ConstantSql.hrm_cat_sp_get_SalaryRank, ref status).ToList();
            var rankEntity = lstRank.Where(s => s.ID == SalaryRankID).FirstOrDefault();

            Cat_SalaryClassEntity salaryClassEntity = null;
            if (rankEntity != null)
            {
                var salaryClassServices = new Cat_SalaryClassServices();
                var lstObjClass = new List<object>();
                lstObjClass.Add(null);
                lstObjClass.Add(1);
                lstObjClass.Add(int.MaxValue - 1);
                var salaryClass = actionService.GetData<Cat_SalaryClassEntity>(lstObjClass, ConstantSql.hrm_cat_sp_get_SalaryClass, ref status).ToList();
                salaryClassEntity = salaryClass.Where(s => rankEntity.SalaryClassID == s.ID).FirstOrDefault();
            }

            var lstObjContractType = new List<object>();
            lstObjContractType.AddRange(new object[6]);
            lstObjContractType[4] = 1;
            lstObjContractType[5] = int.MaxValue - 1;
            var lstContractType = actionService.GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status).ToList();

            var lstProfile = new List<Hre_ProfileEntity>();
            var workplaceServices = new Cat_WorkPlaceServices();
            var workplace = actionService.GetData<Cat_WorkPlaceEntity>(Common.DotNetToOracle(WorkPlaceID.ToString()), ConstantSql.hrm_cat_sp_get_WorkPlaceById, ref status).FirstOrDefault();

            var lstAttGrade = actionService.GetData<Att_GradeEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_sal_sp_get_Att_GradeByProfileIds, ref status).ToList();

            var lstSalGrade = actionService.GetData<Sal_GradeEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_sal_sp_get_Sal_GradeByProfileIds, ref status).ToList();

            var lstBasicSalary = actionService.GetData<Sal_BasicSalaryEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_sal_sp_get_BasicSalaryByProfileIds, ref status).ToList();

            var lstInsuranceSalary = actionService.GetData<Sal_InsuranceSalaryEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_sal_sp_get_InsuranceSalaryByProfileIds, ref status).ToList();

            var lstWorkingHistory = actionService.GetData<Hre_WorkHistoryEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_hr_sp_get_WorkHistoryByProfileIds, ref status).ToList();

            foreach (var item in lstProfiles)
            {
                var candidateGeneralByProfile = lstCandidateGeneral.Where(s => s.ProfileID.Value == item.ID).FirstOrDefault();

                var objContract = new List<object>();
                var lstContractByProfileID = actionService.GetData<Hre_ContractEntity>(Common.DotNetToOracle(item.ID.ToString()), ConstantSql.hrm_hr_sp_get_ContractsByProfileId, ref status);
                var listIdContract = string.Empty;
                if (lstContractByProfileID != null)
                {
                    listIdContract = string.Join(",", lstContractByProfileID.Select(d => d.ContractTypeID));
                }
                var contractType = lstContractType.Where(s => s.ID == ContractTypeID).FirstOrDefault();
                DateTime dateEnd = DateHire;
                if (contractType != null)
                {
                    if (contractType.ValueTime != null)
                    {
                        if (contractType.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_MONTH.ToString())
                        {
                            dateEnd = DateHire.AddMonths(int.Parse(contractType.ValueTime.Value.ToString()));
                        }
                        else if (contractType.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                        {
                            dateEnd = DateHire.AddYears(int.Parse(contractType.ValueTime.Value.ToString()));
                        }
                    }
                }
                double Salary = 0;
                if (!string.IsNullOrEmpty(BasicSalary))
                    Salary = double.Parse(BasicSalary);
                if (candidateGeneralByProfile == null)
                {
                    #region Add CandidateGeneral
                    Hre_CandidateGeneralEntity candidateGeneral = new Hre_CandidateGeneralEntity();
                    candidateGeneral.ProfileID = item.ID;
                    candidateGeneral.BasicSalary = Salary;
                    candidateGeneral.RankRateID = SalaryRankID;
                    if (salaryClassEntity != null)
                    {
                        candidateGeneral.SalaryClassID = salaryClassEntity.ID;
                    }
                    candidateGeneral.ContractTypeID = ContractTypeID;
                    candidateGeneral.EnteringDate = DateHire;
                    candidateGeneral.OrgStructureID = OrgStructureID;
                    candidateGeneral.GradeAttendanceID = GradeAttendanceID;
                    candidateGeneral.GradePayrollID = GradePayrollID;
                    candidateGeneral.WorkPlaceID = WorkPlaceID;
                    candidateGeneral.JobTitleID = jobTitleID;
                    candidateGeneral.PositionID = positionID;
                    candidateGeneral.AllowanceID1 = allowanceID1;
                    candidateGeneral.AllowanceID2 = allowanceID2;
                    candidateGeneral.AllowanceID3 = allowanceID3;
                    candidateGeneral.AllowanceID4 = allowanceID4;
                    candidateGeneral.AllowanceID5 = allowanceID5;
                    candidateGeneral.Allowance1 = allowance1;
                    candidateGeneral.Allowance2 = allowance2;
                    candidateGeneral.Allowance3 = allowance3;
                    candidateGeneral.Allowance4 = allowance4;
                    candidateGeneral.Allowance5 = allowance5;
                    candidateGeneral.CurrencyID = currencyID;
                    candidateGeneral.CodeEmp = codeEmp;
                    message = candidateServices.Add(candidateGeneral);

                    #endregion

                    #region Add Contract
                    //Add new contract

                    Hre_ContractEntity Contract = new Hre_ContractEntity();
                    Contract.ProfileID = item.ID;
                    Contract.Salary = Salary;
                    Contract.ContractTypeID = ContractTypeID;
                    Contract.DateStart = DateHire;
                    Contract.DateSigned = DateHire;
                    Contract.RankRateID = SalaryRankID;
                    if (salaryClassEntity != null)
                    {
                        Contract.ClassRateID = salaryClassEntity.ID;
                    }

                    Contract.InsuranceAmount = insuranceSalary;
                    Contract.AllowanceID1 = allowanceID1;
                    Contract.AllowanceID2 = allowanceID2;
                    Contract.AllowanceID3 = allowanceID3;
                    Contract.AllowanceID4 = allowanceID4;
                    Contract.Allowance1 = allowance1;
                    Contract.Allowance2 = allowance2;
                    Contract.Allowance3 = allowance3;
                    Contract.Allowance4 = allowance4;
                    Contract.Allowance = allowance5;

                    Contract.CurenncyID = currencyID;
                    Contract.CurenncyID1 = currencyID;
                    Contract.CurenncyID2 = currencyID;
                    Contract.CurenncyID3 = currencyID;
                    Contract.CurenncyIDSalary = currencyID;
                    Contract.CurenncyID4 = currencyID;
                    Contract.CurenncyID5 = currencyID;
                    Contract.Status = HRM.Infrastructure.Utilities.EnumDropDown.Status.E_WAITING.ToString();
                    Contract.JobTitleID = jobTitleID;
                    Contract.PositionID = positionID;

                    if (!string.IsNullOrEmpty(contractType.Formula))
                    {
                        Contract = SetNewDateEndContract(Contract);
                    }
                    Contract.DateExtend = Contract.DateEnd;
                    //   Contract = SetNewCodeContract(Contract, listIdContract);
                    message = contractServices.Add(Contract);
                    #endregion

                    #region Edit Profile
                    //Edit Profile
                    item.OrgStructureID = OrgStructureID;
                    if (salaryClassEntity != null)
                    {
                        item.SalaryClassID = salaryClassEntity.ID;
                    }
                    item.DateOfEffect = DateHire;
                    item.DateHire = DateHire;
                    item.DateEndProbation = Contract.DateEnd.Value;
                    item.WorkPlaceID = WorkPlaceID;
                    item.ContractTypeID = ContractTypeID;
                    item.CodeEmp = codeEmp;
                    item.StatusSyn = ProfileStatusSyn.E_WAITING.ToString();

                    message = profileSevices.Edit(item);
                    #endregion

                    #region Add Sal_Insurance
                    // Add Insurance
                    if (contractType != null && contractType.NoneTypeInsuarance == true)
                    {
                        var insuranceEntity = new Sal_InsuranceSalaryEntity
                        {
                            ProfileID = item.ID,
                            InsuranceAmount = insuranceSalary,
                            DateEffect = DateHire,
                            IsSocialIns = contractType.IsSocialInsurance == null ? null : contractType.IsSocialInsurance,
                            IsUnimploymentIns = contractType.IsUnEmployInsurance == null ? null : contractType.IsUnEmployInsurance,
                            IsMedicalIns = contractType.IsHealthInsurance == null ? null : contractType.IsHealthInsurance,
                            CurrencyID = currencyID
                        };
                        message = insServices.Add(insuranceEntity);
                    }
                    #endregion

                    #region Add Sal_BasicSalary
                    Sal_BasicSalaryEntity basicSalaryEntity = new Sal_BasicSalaryEntity();
                    basicSalaryEntity.ProfileID = item.ID;
                    basicSalaryEntity.GrossAmount = BasicSalary;
                    basicSalaryEntity.Amount = BasicSalary.Encrypt();
                    basicSalaryEntity.DateOfEffect = DateHire;
                    basicSalaryEntity.RankRateID = SalaryRankID;
                    basicSalaryEntity.CurrencyID = currencyID.Value;
                    if (salaryClassEntity != null)
                    {
                        basicSalaryEntity.ClassRateID = salaryClassEntity.ID;
                    }

                    basicSalaryEntity.AllowanceType1ID = allowanceID1;
                    basicSalaryEntity.AllowanceType2ID = allowanceID2;
                    basicSalaryEntity.AllowanceType3ID = allowanceID3;
                    basicSalaryEntity.AllowanceType4ID = allowanceID4;
                    basicSalaryEntity.AllowanceTypeID5 = allowanceID5;

                    basicSalaryEntity.AllowanceAmount1 = allowance1;
                    basicSalaryEntity.AllowanceAmount2 = allowance2;
                    basicSalaryEntity.AllowanceAmount3 = allowance3;
                    basicSalaryEntity.AllowanceAmount4 = allowance4;
                    basicSalaryEntity.AllowanceAmount5 = allowance5;

                    basicSalaryEntity.CurrencyID5 = currencyID;
                    basicSalaryEntity.CurrencyID2 = currencyID;
                    basicSalaryEntity.CurrencyID3 = currencyID;
                    basicSalaryEntity.CurrencyID4 = currencyID;
                    if (insuranceSalary != null)
                    {
                        basicSalaryEntity.InsuranceAmount = insuranceSalary.Value;
                    }

                    message = basicSalaryServices.Add(basicSalaryEntity);
                    #endregion

                    #region Add WorkHistory
                    Hre_WorkHistoryEntity workHistory = new Hre_WorkHistoryEntity();
                    workHistory.ProfileID = item.ID;
                    workHistory.DateEffective = DateHire;
                    if (salaryClassEntity != null)
                    {
                        workHistory.SalaryClassID = salaryClassEntity.ID;
                    }
                    workHistory.OrganizationStructureID = OrgStructureID;
                    workHistory.WorkLocation = workplace != null ? workplace.WorkPlaceName : null;
                    workHistory.JobTitleID = jobTitleID;
                    workHistory.PositionID = positionID;

                    message = workingHistoryServices.Add(workHistory);
                    #endregion

                    #region Add Att_Grade
                    Att_GradeEntity attGradeEntity = new Att_GradeEntity();
                    attGradeEntity.ProfileID = item.ID;
                    attGradeEntity.GradeAttendanceID = GradeAttendanceID;
                    attGradeEntity.MonthStart = DateHire;
                    message = attGradeServices.Add(attGradeEntity);
                    #endregion

                    #region Add Sal_Grade
                    Sal_GradeEntity salGradeEntity = new Sal_GradeEntity();
                    salGradeEntity.ProfileID = item.ID;
                    salGradeEntity.GradePayrollID = GradePayrollID;
                    salGradeEntity.MonthStart = DateHire;
                    message = salGradeServices.Add(salGradeEntity);
                    #endregion

                }
                else
                {
                    #region Edit CandidateGeneral

                    candidateGeneralByProfile.ProfileID = item.ID;
                    candidateGeneralByProfile.BasicSalary = Salary;
                    candidateGeneralByProfile.RankRateID = SalaryRankID;
                    if (salaryClassEntity != null)
                    {
                        candidateGeneralByProfile.SalaryClassID = salaryClassEntity.ID;
                    }
                    candidateGeneralByProfile.ContractTypeID = ContractTypeID;
                    candidateGeneralByProfile.EnteringDate = DateHire;
                    candidateGeneralByProfile.OrgStructureID = OrgStructureID;
                    candidateGeneralByProfile.GradeAttendanceID = GradeAttendanceID;
                    candidateGeneralByProfile.GradePayrollID = GradePayrollID;
                    candidateGeneralByProfile.WorkPlaceID = WorkPlaceID;
                    candidateGeneralByProfile.JobTitleID = jobTitleID;
                    candidateGeneralByProfile.PositionID = positionID;
                    candidateGeneralByProfile.AllowanceID1 = allowanceID1;
                    candidateGeneralByProfile.AllowanceID2 = allowanceID2;
                    candidateGeneralByProfile.AllowanceID3 = allowanceID3;
                    candidateGeneralByProfile.AllowanceID4 = allowanceID4;
                    candidateGeneralByProfile.AllowanceID5 = allowanceID5;
                    candidateGeneralByProfile.Allowance1 = allowance1;
                    candidateGeneralByProfile.Allowance2 = allowance2;
                    candidateGeneralByProfile.Allowance3 = allowance3;
                    candidateGeneralByProfile.Allowance4 = allowance4;
                    candidateGeneralByProfile.Allowance5 = allowance5;
                    candidateGeneralByProfile.CurrencyID = currencyID;
                    candidateGeneralByProfile.CodeEmp = codeEmp;
                    message = candidateServices.Edit(candidateGeneralByProfile);

                    #endregion

                    #region Edit Contract
                    if (lstContractByProfileID != null)
                    {
                        var contractEntityByProfileID = lstContractByProfileID.FirstOrDefault();
                        if (contractEntityByProfileID != null)
                        {
                            contractEntityByProfileID.Salary = Salary;
                            contractEntityByProfileID.ContractTypeID = ContractTypeID;
                            contractEntityByProfileID.DateStart = DateHire;
                            contractEntityByProfileID.DateSigned = DateHire;
                            contractEntityByProfileID.DateEnd = dateEnd;
                            contractEntityByProfileID.RankRateID = SalaryRankID;
                            if (salaryClassEntity != null)
                            {
                                contractEntityByProfileID.ClassRateID = salaryClassEntity.ID;
                            }

                            contractEntityByProfileID.InsuranceAmount = insuranceSalary;
                            contractEntityByProfileID.AllowanceID1 = allowanceID1;
                            contractEntityByProfileID.AllowanceID2 = allowanceID2;
                            contractEntityByProfileID.AllowanceID3 = allowanceID3;
                            contractEntityByProfileID.AllowanceID4 = allowanceID4;
                            contractEntityByProfileID.Allowance1 = allowance1;
                            contractEntityByProfileID.Allowance2 = allowance2;
                            contractEntityByProfileID.Allowance3 = allowance3;
                            contractEntityByProfileID.Allowance4 = allowance4;
                            contractEntityByProfileID.Allowance = allowance5;
                            contractEntityByProfileID.CurenncyID = currencyID;
                            contractEntityByProfileID.CurenncyID1 = currencyID;
                            contractEntityByProfileID.CurenncyID2 = currencyID;
                            contractEntityByProfileID.CurenncyID3 = currencyID;
                            contractEntityByProfileID.CurenncyIDSalary = currencyID;
                            contractEntityByProfileID.CurenncyID4 = currencyID;
                            contractEntityByProfileID.CurenncyID5 = currencyID;
                            contractEntityByProfileID.Status = HRM.Infrastructure.Utilities.EnumDropDown.Status.E_WAITING.ToString();
                            contractEntityByProfileID.JobTitleID = jobTitleID;
                            contractEntityByProfileID.PositionID = positionID;
                            if (!string.IsNullOrEmpty(contractType.Formula))
                            {
                                contractEntityByProfileID = SetNewDateEndContract(contractEntityByProfileID);
                            }
                            if (contractEntityByProfileID.DateExtend == null)
                            {
                                contractEntityByProfileID.DateExtend = dateEnd;
                            }
                            message = contractServices.Edit(contractEntityByProfileID);
                            if (contractEntityByProfileID.DateEnd != null)
                            {
                                item.DateEndProbation = contractEntityByProfileID.DateEnd.Value;
                            }
                        }
                    }

                    #endregion

                    #region Edit Profile
                    //Edit Profile
                    item.OrgStructureID = OrgStructureID;
                    if (salaryClassEntity != null)
                    {
                        item.SalaryClassID = salaryClassEntity.ID;
                    }
                    item.DateOfEffect = DateHire;
                    item.DateHire = DateHire;
                    item.WorkPlaceID = WorkPlaceID;
                    item.ContractTypeID = ContractTypeID;
                    item.StatusSyn = ProfileStatusSyn.E_WAITING.ToString();
                    item.CodeEmp = codeEmp;
                    message = profileSevices.Edit(item);
                    #endregion

                    #region Edit Sal_Insurance
                    var insSalaryEntityByProfileID = lstInsuranceSalary.Where(s => s.ProfileID == item.ID).OrderBy(s => s.DateUpdate).FirstOrDefault();
                    if (insSalaryEntityByProfileID != null)
                    {
                        if (contractType != null && contractType.NoneTypeInsuarance == true)
                        {
                            insSalaryEntityByProfileID.InsuranceAmount = insuranceSalary;
                            insSalaryEntityByProfileID.DateEffect = DateHire;
                            insSalaryEntityByProfileID.IsSocialIns = contractType.IsSocialInsurance == null ? null : contractType.IsSocialInsurance;
                            insSalaryEntityByProfileID.IsUnimploymentIns = contractType.IsUnEmployInsurance == null ? null : contractType.IsUnEmployInsurance;
                            insSalaryEntityByProfileID.IsMedicalIns = contractType.IsHealthInsurance == null ? null : contractType.IsHealthInsurance;
                            insSalaryEntityByProfileID.CurrencyID = currencyID;

                            message = insServices.Edit(insSalaryEntityByProfileID);
                        }
                    }
                    #endregion

                    #region Edit Sal_BasicSalary
                    var basicSalaryEntityByProfileID = lstBasicSalary.Where(s => s.ProfileID == item.ID).FirstOrDefault();
                    if (basicSalaryEntityByProfileID != null)
                    {
                        basicSalaryEntityByProfileID.GrossAmount = BasicSalary;
                        basicSalaryEntityByProfileID.Amount = BasicSalary.Encrypt();
                        basicSalaryEntityByProfileID.DateOfEffect = DateHire;
                        basicSalaryEntityByProfileID.RankRateID = SalaryRankID;
                        if (salaryClassEntity != null)
                        {
                            basicSalaryEntityByProfileID.ClassRateID = salaryClassEntity.ID;
                        }
                        basicSalaryEntityByProfileID.CurrencyID = currencyID.Value;
                        basicSalaryEntityByProfileID.AllowanceType1ID = allowanceID1;
                        basicSalaryEntityByProfileID.AllowanceType2ID = allowanceID2;
                        basicSalaryEntityByProfileID.AllowanceType3ID = allowanceID3;
                        basicSalaryEntityByProfileID.AllowanceType4ID = allowanceID4;
                        basicSalaryEntityByProfileID.AllowanceTypeID5 = allowanceID5;
                        basicSalaryEntityByProfileID.AllowanceAmount1 = allowance1;
                        basicSalaryEntityByProfileID.AllowanceAmount2 = allowance2;
                        basicSalaryEntityByProfileID.AllowanceAmount3 = allowance3;
                        basicSalaryEntityByProfileID.AllowanceAmount4 = allowance4;
                        basicSalaryEntityByProfileID.AllowanceAmount5 = allowance5;
                        basicSalaryEntityByProfileID.CurrencyID5 = currencyID;
                        basicSalaryEntityByProfileID.CurrencyID2 = currencyID;
                        basicSalaryEntityByProfileID.CurrencyID3 = currencyID;
                        basicSalaryEntityByProfileID.CurrencyID4 = currencyID;
                        if (insuranceSalary != null)
                        {
                            basicSalaryEntityByProfileID.InsuranceAmount = insuranceSalary.Value;
                        }
                        message = basicSalaryServices.Edit(basicSalaryEntityByProfileID);
                    }
                    #endregion

                    #region Edit WorkingHistory
                    var workingByProfileID = lstWorkingHistory.Where(s => s.ProfileID == item.ID).FirstOrDefault();
                    if (workingByProfileID != null)
                    {
                        workingByProfileID.DateEffective = DateHire;
                        if (salaryClassEntity != null)
                        {
                            workingByProfileID.SalaryClassID = salaryClassEntity.ID;
                        }
                        workingByProfileID.OrganizationStructureID = OrgStructureID;
                        workingByProfileID.WorkLocation = workplace != null ? workplace.WorkPlaceName : null;
                        workingByProfileID.JobTitleID = jobTitleID;
                        workingByProfileID.PositionID = positionID;
                        message = workingHistoryServices.Edit(workingByProfileID);
                    }
                    #endregion

                    #region Edit Att_Grade
                    var attGradeEntityByProfileID = lstAttGrade.Where(s => s.ProfileID == item.ID).FirstOrDefault();
                    if (attGradeEntityByProfileID != null)
                    {
                        attGradeEntityByProfileID.GradeAttendanceID = GradeAttendanceID;
                        attGradeEntityByProfileID.MonthStart = DateHire;
                        message = attGradeServices.Edit(attGradeEntityByProfileID);
                    }
                    #endregion

                    #region Edit Sal_Grade
                    var salGradeEntityByProfileID = lstSalGrade.Where(s => s.ProfileID == item.ID).FirstOrDefault();
                    if (salGradeEntityByProfileID != null)
                    {
                        salGradeEntityByProfileID.GradePayrollID = GradePayrollID;
                        salGradeEntityByProfileID.MonthStart = DateHire;
                        message = salGradeServices.Edit(salGradeEntityByProfileID);
                    }
                    #endregion
                }
            }


            return Json(message, JsonRequestBehavior.AllowGet);
        }
Esempio n. 8
0
        public string ApplyPerformance(Guid? profileID, Guid? rankdetailID, DateTime? dateEffect,string userLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                string result = ConstantMessages.Succeed;
                var profileservices = new Hre_ProfileServices();
                BaseService service = new BaseService();
                string message = string.Empty;
                string status = string.Empty;
                var contractservices = new Hre_ContractServices();
                var basicSalaryServices = new Sal_BasicSalaryServices();
                var InsuranceSalaryServices = new Sal_InsuranceSalaryServices();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCandidate = new Rec_CandidateRepository(unitOfWork);
                var repoHistory = new Rec_RecruitmentHistoryRepository(unitOfWork);
                var profile = service.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, userLogin, ref status).FirstOrDefault();
                var salaryRank = service.GetData<Cat_SalaryRankEntity>(Common.DotNetToOracle(rankdetailID.ToString()), ConstantSql.hrm_cat_sp_get_SalaryRankById, userLogin, ref status).FirstOrDefault();

                Guid? _AbilitiTitleID = null;
                if (salaryRank != null && salaryRank.SalaryClassID != null)
                {
                    var abilityTitleBySalaryClass = service.GetData<Cat_AbilityTileEntity>(Common.DotNetToOracle(salaryRank.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, userLogin, ref status).FirstOrDefault();
                    if (abilityTitleBySalaryClass != null)
                    {
                        _AbilitiTitleID = abilityTitleBySalaryClass.ID;
                    }
                }

                // theo task 0049950 - không làm gì liên quan đến hđ hết.
                //var contractybyProfile = service.GetData<Hre_ContractEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_hr_sp_get_ContractsByProfileId, userLogin, ref status)
                //    .OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                ////if (contractybyProfile == null)
                ////{
                ////    result = ConstantDisplay.HRM_Common_ProfileNotHaveContract.ToString();
                ////    return result;
                ////}
                ////if (contractybyProfile != null && contractybyProfile.ContractNextID == null)
                ////{
                ////    result = ConstantDisplay.HRM_Common_ProfileNotHaveNextContract.ToString();
                ////    return result;
                ////}
                //if (contractybyProfile != null && contractybyProfile.ContractNextID != null)
                //{
                    //var contractype = service.GetData<Cat_ContractTypeEntity>(Guid.Parse(Common.DotNetToOracle(contractybyProfile.ContractNextID.ToString())), ConstantSql.hrm_cat_sp_get_ContractTypeById, userLogin, ref status).FirstOrDefault();
                    //if (contractype == null)
                    //{
                    //    result = ConstantDisplay.HRM_Common_ProfileNotHaveNextContract.ToString();
                    //    return result;
                    //}
                    //Hre_ContractEntity contract = new Hre_ContractEntity();
                    //contract.ProfileID = profile.ID;
                    //contract.DateStart = dateEffect.Value;
                    //contract.DateSigned = dateEffect;
                    //contract.RankRateID = rankdetailID;
                    //contract.ClassRateID = salaryRank != null ? salaryRank.SalaryClassID : null;
                    //contract.Salary = salaryRank != null ? salaryRank.SalaryStandard : null;
                    //contract.ContractTypeID = contractype.ID;
                    //if (!string.IsNullOrEmpty(contractype.Formula))
                    //{
                    //    contract = SetNewDateEndContract(contract,userLogin);
                    //}

                    //if (contractybyProfile.DateEndNextContract != null)
                    //{
                    //    contractybyProfile.DateEnd = contractybyProfile.DateEndNextContract.Value;
                    //}
                    //contractservices.Add(contract);

                    // Thêm mới lương cơ bản + lương BHXH
                    string defaultcur = null;
                    string ConfigHre = AppConfig.HRM_HRE_CONFIG.ToString();
                    List<object> lstOb = new List<object>();
                    lstOb.Add(ConfigHre);
                    lstOb.Add(null);
                    lstOb.Add(null);
                    var config = GetData<Sys_AllSettingEntity>(lstOb, ConstantSql.hrm_sys_sp_get_AllSetting, userLogin, ref status);
                    string valueConfig = AppConfig.HRM_HRE_CONFIG_DEFAULTCURRENCY.ToString();
                    if (config != null)
                    {
                        defaultcur = config.Where(s => s.Name == valueConfig).Select(s => s.Value1).FirstOrDefault().ToString();
                        List<object> listObjCurrency = new List<object>();
                        listObjCurrency.Add(null);
                        listObjCurrency.Add(defaultcur);
                        listObjCurrency.Add(1);
                        listObjCurrency.Add(Int32.MaxValue - 1);
                        var lstCurrency = service.GetData<Cat_CurrencyEntity>(listObjCurrency, ConstantSql.hrm_cat_sp_get_Currency, userLogin, ref status).FirstOrDefault();

                        var basicsalarybyprofile = service.GetData<Sal_BasicSalaryEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_sal_sp_get_BasicSalaryByProfileIds, userLogin, ref status)
                            .OrderByDescending(s => s.DateOfEffect).FirstOrDefault();
                        var insuransalarybyprofile = service.GetData<Sal_InsuranceSalaryEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_sal_sp_get_InsuranceSalaryByProfileIds, userLogin, ref status)
                     .OrderByDescending(s => s.DateEffect).FirstOrDefault();

                        if (basicsalarybyprofile != null && salaryRank != null && basicsalarybyprofile.RankRateID != rankdetailID && salaryRank.SalaryClassID == basicsalarybyprofile.ClassRateID)
                        {
                            Sal_BasicSalaryEntity basicSalary = new Sal_BasicSalaryEntity();
                            basicSalary.ProfileID = profile.ID;
                            basicSalary.GrossAmount = (salaryRank != null && salaryRank.SalaryStandard != null) ? salaryRank.SalaryStandard.Value.ToString() : null;
                            basicSalary.Amount = basicSalary.GrossAmount != null ? basicSalary.GrossAmount.Encrypt() : "";
                            basicSalary.InsuranceAmount = (salaryRank != null && salaryRank.SalaryStandard != null) ? salaryRank.SalaryStandard.Value : 0;
                            basicSalary.DateOfEffect = dateEffect.Value;
                            basicSalary.CurrencyID = lstCurrency.ID;
                            basicSalary.Status = EnumDropDown.Sal_BasicSalaryStatus.E_WATTING_APPROVED.ToString();
                            basicSalary.AmountTotal = salaryRank != null ? salaryRank.SalaryStandard : null;
                            basicSalary.ClassRateID = salaryRank.SalaryClassID;
                            basicSalary.RankRateID = salaryRank.ID;
                            basicSalaryServices.Add(basicSalary);

                            if(insuransalarybyprofile != null)
                            {
                                Sal_InsuranceSalaryEntity insuranceSalary = new Sal_InsuranceSalaryEntity();
                                insuranceSalary.ProfileID = profile.ID;
                                insuranceSalary.InsuranceAmount = salaryRank != null ? salaryRank.SalaryStandard : null;
                                insuranceSalary.DateEffect = dateEffect;
                                insuranceSalary.CurrencyID = lstCurrency.ID;
                                insuranceSalary.IsSocialIns = insuransalarybyprofile.IsSocialIns;
                                insuranceSalary.IsMedicalIns = insuransalarybyprofile.IsMedicalIns;
                                insuranceSalary.IsUnimploymentIns = insuransalarybyprofile.IsUnimploymentIns;
                                InsuranceSalaryServices.Add(insuranceSalary);
                            }
                          
                        }
                        else
                        {
                            profile.SalaryClassID = salaryRank == null ? Guid.Empty : salaryRank.SalaryClassID;
                            profile.AbilityTileID = _AbilitiTitleID;
                            profile.DateOfEffect = dateEffect;
                            service.Edit(profile);

                            var workHistoryEntity = service.GetData<Hre_WorkHistoryEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_hr_sp_get_WorkHistoryByProfileId, userLogin, ref status)
                                .OrderByDescending(s => s.DateEffective).FirstOrDefault();


                            if (workHistoryEntity == null || workHistoryEntity.DateEffective != dateEffect)
                            {
                                var workHistory = new Hre_WorkHistoryEntity();
                                workHistory.ProfileID = profile.ID;
                                workHistory.SalaryClassID = salaryRank != null ? salaryRank.SalaryClassID : null;
                                workHistory.DateEffective = dateEffect != null ? dateEffect.Value : DateTime.Now;
                                workHistory.AbilityTileID = _AbilitiTitleID;
                                service.Add(workHistory);
                            }
                            else
                            {
                                workHistoryEntity.SalaryClassID = salaryRank != null ? salaryRank.SalaryClassID : null;
                                workHistoryEntity.DateEffective = dateEffect != null ? dateEffect.Value : DateTime.Now;
                                workHistoryEntity.AbilityTileID = _AbilitiTitleID;
                                service.Edit(workHistoryEntity);
                            }

                            Sal_BasicSalaryEntity basicSalary = new Sal_BasicSalaryEntity();
                            basicSalary.ProfileID = profile.ID;
                            basicSalary.GrossAmount = (salaryRank != null && salaryRank.SalaryStandard != null) ? salaryRank.SalaryStandard.Value.ToString() : null;
                            basicSalary.Amount = basicSalary.GrossAmount != null ? basicSalary.GrossAmount.Encrypt() : "";
                            basicSalary.InsuranceAmount = (salaryRank != null && salaryRank.SalaryStandard != null) ? salaryRank.SalaryStandard.Value : 0;
                            basicSalary.AmountTotal = salaryRank != null ? salaryRank.SalaryStandard : null;
                            basicSalary.DateOfEffect = dateEffect.Value;
                            basicSalary.CurrencyID = lstCurrency.ID;
                            basicSalary.Status = EnumDropDown.Sal_BasicSalaryStatus.E_WATTING_APPROVED.ToString();
                            basicSalaryServices.Add(basicSalary);

                            if (insuransalarybyprofile != null)
                            {
                                Sal_InsuranceSalaryEntity insuranceSalary = new Sal_InsuranceSalaryEntity();
                                insuranceSalary.ProfileID = profile.ID;
                                insuranceSalary.InsuranceAmount = salaryRank != null ? salaryRank.SalaryStandard : null;
                                insuranceSalary.DateEffect = dateEffect;
                                insuranceSalary.CurrencyID = lstCurrency.ID;
                                insuranceSalary.IsSocialIns = insuransalarybyprofile.IsSocialIns;
                                insuranceSalary.IsMedicalIns = insuransalarybyprofile.IsMedicalIns;
                                insuranceSalary.IsUnimploymentIns = insuransalarybyprofile.IsUnimploymentIns;
                                InsuranceSalaryServices.Add(insuranceSalary);
                            }
                        }
                }
                return result;
            }
        }
Esempio n. 9
0
        public Double GetAnnualLeaveAvailableAllYear(int Year, int Month, DateTime?dateHire,
                                                     DateTime?dateEndProbation, DateTime?dateQuit, string fomularConfig, List <Att_LeaveDayEntity> lstLeaveDay_ByType_ByProfile, List <DateTime> lstDayOff, Guid?HDTJob4, Guid?HDTJob5, List <Hre_WorkHistoryEntity> lstWorkingHistory_ByProfile)
        {
            #region Param
            int    monthBeginYear          = 0;            //Tháng bắt đầu tính phép năm
            int    dayBeginFullMonth       = 0;            //Ngày bắt đầu tính tròn ANL cho tháng
            int    seniorMonth             = 0;            // Số tháng để có 1 level cho thâm niên
            int    dayPerMonth             = 0;            // Số ngày cho 1 tháng
            double anlRoundUp              = 0;            //Số làm tròn Lên xuống
            string typeProfileBegin        = string.Empty; //Loại lấy theo DateHire hay DateQuit
            int    maxInMonthToGetAct      = 0;            //Ngày chuẩn để xét là DT4 và DT5 đc tính cho tháng àno
            double anlFullYear             = 0;            // Số ngày phép bình thường cho 1 năm (tính theo tháng)
            double anlSeniorMoreThanNormal = 0;            // Số ngày phép Được cộng thêm do thâm niên so với bình thường (tính theo tháng)
            double anlHDT4MoreThanNormal   = 0;            // Số ngày phép được cộng thêm do HDT4 so với bình thường (tính theo tháng)
            double anlHDT5MoreThanNormal   = 0;            // Số ngày phép được cộng thêm do HDT5 so với bình thường (tính theo tháng)
            //set du lieu
            GetConfigANL(fomularConfig, out monthBeginYear, out dayBeginFullMonth, out seniorMonth,
                         out dayPerMonth, out anlRoundUp, out typeProfileBegin, out maxInMonthToGetAct,
                         out anlFullYear, out anlSeniorMoreThanNormal, out anlHDT4MoreThanNormal, out anlHDT5MoreThanNormal);
            #endregion

            #region Data
            //gan du lieu can thiet

            DateTime BeginYear        = new DateTime(Year, monthBeginYear, 1);
            DateTime EndYear          = BeginYear.AddYears(1).AddMinutes(-1);
            DateTime?DateStartProfile = null;
            DateTime DateEndProfile   = EndYear;

            if (typeProfileBegin == AnlProfileTypeBegin.E_DATE_ENDPROBATION.ToString())
            {
                DateStartProfile = dateEndProbation;
            }
            else
            {
                DateStartProfile = dateHire;
            }
            if (DateStartProfile == null)
            {
                return(0);
            }
            if (dateQuit != null && dateQuit < EndYear)
            {
                DateEndProfile = dateQuit.Value.Date.AddDays(1).AddMinutes(-1);
            }
            if (DateStartProfile.Value.Day > dayBeginFullMonth)
            {
                DateStartProfile = new DateTime(DateStartProfile.Value.AddMonths(1).Year, DateStartProfile.Value.AddMonths(1).Month, 1);
            }
            DateTime DateStartInYear = BeginYear > DateStartProfile.Value ? BeginYear : DateStartProfile.Value;
            DateTime DateEndInYear   = EndYear < DateEndProfile ? EndYear : DateEndProfile;
            #endregion
            string formulaAnnualLeave = string.Empty; // lấy tư trong cong thức tính phép năm
            List <ElementFormula> listElementFormular = new List <ElementFormula>();
            if (formulaAnnualLeave.Contains(FormulaAnual.ANL_NORMAL.ToString()))
            {
                double value = 0;
                double monthWorkingNormalInYear = 0;
                for (int i = 0; i < 12; i++)
                {
                    if (DateStartInYear.AddMonths(i) < DateEndInYear)
                    {
                        monthWorkingNormalInYear++;
                    }
                    else
                    {
                        break;
                    }
                }
                value = anlFullYear * monthWorkingNormalInYear;
                ElementFormula ElementFormula = new ElementFormula(FormulaAnual.ANL_NORMAL.ToString(), value, 0);
                listElementFormular.Add(ElementFormula);
            }
            if (formulaAnnualLeave.Contains(FormulaAnual.ANL_SENIOR.ToString()))
            {
                double   value       = 0;
                int      level1      = 0;
                int      level2      = 0;
                int      MonthLevel1 = 0;
                int      MonthLevel2 = 0;
                DateTime DateSenior  = DateTime.MinValue;
                for (int i = 0; i < 20; i++)
                {
                    DateSenior = DateStartProfile.Value.AddMonths(seniorMonth);
                    if (DateSenior < DateStartInYear)
                    {
                        level1++;
                        continue;
                    }
                    else if (DateSenior >= DateStartInYear && DateSenior < DateEndInYear)
                    {
                        for (int y = 0; y < 12; y++)
                        {
                            if (DateStartInYear.AddMonths(y) < DateSenior)
                            {
                                MonthLevel1++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        level2      = level1 + 1;
                        MonthLevel2 = 12 - MonthLevel1;
                    }
                    else
                    {
                        break;
                    }
                }
                value = (level1 * MonthLevel1 * anlSeniorMoreThanNormal) + (level2 * MonthLevel2 * anlSeniorMoreThanNormal);
                ElementFormula ElementFormula = new ElementFormula(FormulaAnual.ANL_SENIOR.ToString(), value, 1);
                listElementFormular.Add(ElementFormula);
            }
            if (formulaAnnualLeave.Contains(FormulaAnual.ANL_LEAVE_NON_HAVEANL.ToString()))
            {
                double value = 0;
                //Logic: Vướng cai đầu năm cuối năm nên phải cắt cái ngày đó ra cho chính xác
                double numLeave = 0;
                foreach (var item in lstLeaveDay_ByType_ByProfile)
                {
                    if (item.DateStart < DateStartInYear && item.DateEnd > DateStartInYear)
                    {
                        DateTime FirstSunday = DateTime.MinValue;
                        for (DateTime DateCheck = DateStartInYear; DateCheck < item.DateEnd; DateCheck = DateCheck.AddDays(1))
                        {
                            if (DateCheck.DayOfWeek == DayOfWeek.Sunday)
                            {
                                FirstSunday = DateCheck;
                                break;
                            }
                        }
                        int sundayCount = 0;
                        if (FirstSunday != DateTime.MinValue)
                        {
                            sundayCount = (int)((item.DateEnd - FirstSunday).TotalDays / 7) + 1;
                        }
                        int dayOffCount = lstDayOff.Select(m => m.Date >= DateStartInYear && m.Date < item.DateEnd).Count();
                        numLeave += (item.DateEnd - DateStartInYear).TotalDays - sundayCount - dayOffCount;
                    }
                    else if (item.DateStart < DateEndInYear && item.DateEnd > DateEndInYear)
                    {
                        DateTime FirstSunday = DateTime.MinValue;
                        for (DateTime DateCheck = item.DateStart; DateCheck < DateEndInYear; DateCheck = DateCheck.AddDays(1))
                        {
                            if (DateCheck.DayOfWeek == DayOfWeek.Sunday)
                            {
                                FirstSunday = DateCheck;
                                break;
                            }
                        }
                        int sundayCount = 0;
                        if (FirstSunday != DateTime.MinValue)
                        {
                            sundayCount = (int)((DateEndInYear - FirstSunday).TotalDays / 7) + 1;
                        }
                        int dayOffCount = lstDayOff.Select(m => m.Date >= item.DateStart && m.Date < DateEndInYear).Count();
                        numLeave += (item.DateEnd - DateStartInYear).TotalDays - sundayCount - dayOffCount;
                    }
                    else
                    {
                        numLeave += item.LeaveDays ?? 0;
                    }
                }
                value = ((int)(numLeave / dayPerMonth)) + ((numLeave % dayPerMonth) >= anlRoundUp ? 1 : 0);
                ElementFormula ElementFormula = new ElementFormula(FormulaAnual.ANL_LEAVE_NON_HAVEANL.ToString(), value, 2);
                listElementFormular.Add(ElementFormula);
            }
            if (formulaAnnualLeave.Contains(FormulaAnual.ANL_WORK_HDT4.ToString()))
            {
                double value      = 0;
                double monthCount = 0;
                double dayCount   = 0;
                //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm
                //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm
                Hre_WorkHistoryEntity workHistoryNewest_beforeBeginYear = lstWorkingHistory_ByProfile.Where(m => m.DateEffective < DateStartInYear && m.JobTitleID == HDTJob4).OrderByDescending(m => m.DateEffective).FirstOrDefault();
                if (workHistoryNewest_beforeBeginYear == null || workHistoryNewest_beforeBeginYear.JobTitleID != HDTJob4)
                {
                    Hre_WorkHistoryEntity workHistoryAfterYear = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > DateStartInYear && m.DateEffective < DateEndInYear && m.JobTitleID == HDTJob4).OrderBy(m => m.DateEffective).FirstOrDefault();
                    if (workHistoryAfterYear != null)
                    {
                        DateTime dateStartJob = workHistoryAfterYear.DateEffective;
                        for (int i = 0; i < 20; i++)
                        {
                            Hre_WorkHistoryEntity workHistoryNextStep = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > dateStartJob && m.JobTitleID != HDTJob4).OrderBy(m => m.DateEffective).FirstOrDefault();
                            DateTime dateEndJob = DateTime.MaxValue;
                            if (workHistoryNextStep != null)
                            {
                                dateEndJob = workHistoryNextStep.DateEffective;
                            }
                            if (dateEndJob > DateEndInYear)
                            {
                                dateEndJob = DateEndInYear;
                            }
                            dayCount = (dateEndJob - DateStartInYear).TotalDays;

                            //Kiếm cặp tiếp theo
                            Hre_WorkHistoryEntity workHistoryNextStep2 = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > dateEndJob && m.JobTitleID == HDTJob4).OrderBy(m => m.DateEffective).FirstOrDefault();
                            if (workHistoryNextStep2 == null || workHistoryNextStep2.DateEffective > DateEndInYear)
                            {
                                break;
                            }
                            else
                            {
                                dateStartJob = workHistoryNextStep2.DateEffective;
                            }
                        }
                    }
                }
                else
                {
                    Hre_WorkHistoryEntity workHistoryNewest_beforeEndYear = lstWorkingHistory_ByProfile.Where(m => m.DateEffective < DateEndInYear && m.JobTitleID == HDTJob4).OrderByDescending(m => m.DateEffective).FirstOrDefault();
                    if (workHistoryNewest_beforeBeginYear.ID == workHistoryNewest_beforeEndYear.ID)
                    {
                        //nếu như làm HDT Nguyên năm
                        dayCount = (DateEndInYear - DateStartInYear).TotalDays;
                    }
                    else
                    {
                        //Lấy từng cặp trong khảong thời gian cho so voi ngày dateStartInyear và ngày dateEndInyear
                        DateTime dateStartJob = workHistoryNewest_beforeBeginYear.DateEffective;
                        for (int i = 0; i < 20; i++)
                        {
                            //Lấy ra cái mới nhất so với ngày hiện tại đang check
                            Hre_WorkHistoryEntity workHistoryNextStep = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > dateStartJob && m.JobTitleID != HDTJob4).OrderBy(m => m.DateEffective).FirstOrDefault();
                            DateTime dateEndJob = DateTime.MaxValue;
                            if (workHistoryNextStep != null)
                            {
                                dateEndJob = workHistoryNextStep.DateEffective;
                            }
                            if (dateEndJob > DateEndInYear)
                            {
                                dateEndJob = DateEndInYear;
                            }
                            dayCount = (dateEndJob - DateStartInYear).TotalDays;

                            //Kiếm cặp tiếp theo
                            Hre_WorkHistoryEntity workHistoryNextStep2 = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > dateEndJob && m.JobTitleID == HDTJob4).OrderBy(m => m.DateEffective).FirstOrDefault();
                            if (workHistoryNextStep2 == null || workHistoryNextStep2.DateEffective > DateEndInYear)
                            {
                                break;
                            }
                            else
                            {
                                dateStartJob = workHistoryNextStep2.DateEffective;
                            }
                        }
                    }
                }

                monthCount = ((int)(dayCount / dayPerMonth)) + ((dayCount % dayPerMonth) >= anlRoundUp ? 1 : 0);
                value      = monthCount * anlHDT4MoreThanNormal;
                ElementFormula ElementFormula = new ElementFormula(FormulaAnual.ANL_WORK_HDT4.ToString(), value, 3);
                listElementFormular.Add(ElementFormula);
            }

            if (formulaAnnualLeave.Contains(FormulaAnual.ANL_WORK_HDT5.ToString()))
            {
                double value      = 0;
                double monthCount = 0;
                double dayCount   = 0;
                //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm
                //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm
                Hre_WorkHistoryEntity workHistoryNewest_beforeBeginYear = lstWorkingHistory_ByProfile.Where(m => m.DateEffective < DateStartInYear && m.JobTitleID == HDTJob5).OrderByDescending(m => m.DateEffective).FirstOrDefault();
                if (workHistoryNewest_beforeBeginYear == null || workHistoryNewest_beforeBeginYear.JobTitleID != HDTJob5)
                {
                    Hre_WorkHistoryEntity workHistoryAfterYear = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > DateStartInYear && m.DateEffective < DateEndInYear && m.JobTitleID == HDTJob5).OrderBy(m => m.DateEffective).FirstOrDefault();
                    if (workHistoryAfterYear != null)
                    {
                        DateTime dateStartJob = workHistoryAfterYear.DateEffective;
                        for (int i = 0; i < 20; i++)
                        {
                            Hre_WorkHistoryEntity workHistoryNextStep = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > dateStartJob && m.JobTitleID != HDTJob5).OrderBy(m => m.DateEffective).FirstOrDefault();
                            DateTime dateEndJob = DateTime.MaxValue;
                            if (workHistoryNextStep != null)
                            {
                                dateEndJob = workHistoryNextStep.DateEffective;
                            }
                            if (dateEndJob > DateEndInYear)
                            {
                                dateEndJob = DateEndInYear;
                            }
                            dayCount = (dateEndJob - DateStartInYear).TotalDays;

                            //Kiếm cặp tiếp theo
                            Hre_WorkHistoryEntity workHistoryNextStep2 = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > dateEndJob && m.JobTitleID == HDTJob5).OrderBy(m => m.DateEffective).FirstOrDefault();
                            if (workHistoryNextStep2 == null || workHistoryNextStep2.DateEffective > DateEndInYear)
                            {
                                break;
                            }
                            else
                            {
                                dateStartJob = workHistoryNextStep2.DateEffective;
                            }
                        }
                    }
                }
                else
                {
                    Hre_WorkHistoryEntity workHistoryNewest_beforeEndYear = lstWorkingHistory_ByProfile.Where(m => m.DateEffective < DateEndInYear && m.JobTitleID == HDTJob5).OrderByDescending(m => m.DateEffective).FirstOrDefault();
                    if (workHistoryNewest_beforeBeginYear.ID == workHistoryNewest_beforeEndYear.ID)
                    {
                        //nếu như làm HDT Nguyên năm
                        dayCount = (DateEndInYear - DateStartInYear).TotalDays;
                    }
                    else
                    {
                        //Lấy từng cặp trong khảong thời gian cho so voi ngày dateStartInyear và ngày dateEndInyear
                        DateTime dateStartJob = workHistoryNewest_beforeBeginYear.DateEffective;
                        for (int i = 0; i < 20; i++)
                        {
                            //Lấy ra cái mới nhất so với ngày hiện tại đang check
                            Hre_WorkHistoryEntity workHistoryNextStep = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > dateStartJob && m.JobTitleID != HDTJob5).OrderBy(m => m.DateEffective).FirstOrDefault();
                            DateTime dateEndJob = DateTime.MaxValue;
                            if (workHistoryNextStep != null)
                            {
                                dateEndJob = workHistoryNextStep.DateEffective;
                            }
                            if (dateEndJob > DateEndInYear)
                            {
                                dateEndJob = DateEndInYear;
                            }
                            dayCount = (dateEndJob - DateStartInYear).TotalDays;

                            //Kiếm cặp tiếp theo
                            Hre_WorkHistoryEntity workHistoryNextStep2 = lstWorkingHistory_ByProfile.Where(m => m.DateEffective > dateEndJob && m.JobTitleID == HDTJob5).OrderBy(m => m.DateEffective).FirstOrDefault();
                            if (workHistoryNextStep2 == null || workHistoryNextStep2.DateEffective > DateEndInYear)
                            {
                                break;
                            }
                            else
                            {
                                dateStartJob = workHistoryNextStep2.DateEffective;
                            }
                        }
                    }
                }

                monthCount = ((int)(dayCount / dayPerMonth)) + ((dayCount % dayPerMonth) >= anlRoundUp ? 1 : 0);
                value      = monthCount * anlHDT5MoreThanNormal;
                ElementFormula ElementFormula = new ElementFormula(FormulaAnual.ANL_WORK_HDT5.ToString(), value, 4);
                listElementFormular.Add(ElementFormula);
            }

            double result = (double)FormulaHelper.ParseFormula(formulaAnnualLeave, listElementFormular).Value;
            return(result);
        }
Esempio n. 10
0
        public void UpdateSalaryClassNameForProfile(string SalaryClassName, string ProfileIDs, DateTime DateEndProbation, DateTime DateHire, Guid OrgStructureID, Guid SalaryRankID, Guid WorkPlaceID, Guid ContractTypeID, string BasicSalary, string userLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                string status = string.Empty;
                var repo = new Hre_ProfileRepository(unitOfWork);
                var profileSevices = new Hre_ProfileServices();
                var repoWorkHistory = new CustomBaseRepository<Hre_WorkHistory>(unitOfWork);
                var workingHistoryServices = new Hre_WorkHistoryServices();
                // var insuranceServices = new Sal_InsuranceSalaryServices();
                var ObjProfile = new List<object>();
                ObjProfile.AddRange(new object[17]);
                ObjProfile[15] = 1;
                ObjProfile[16] = int.MaxValue - 1;


                List<Guid> lstProfileIDs = ProfileIDs.Split(',').Select(x => Guid.Parse(x)).ToList();
                var lstProfiles = profileSevices.GetData<Hre_ProfileEntity>(ObjProfile, ConstantSql.hrm_hr_sp_get_ProfileAll, userLogin, ref status).Where(s => lstProfileIDs.Contains(s.ID)).ToList();
                var contractServices = new Hre_ContractServices();
                var repoContract = new Hre_ContractRepository(unitOfWork);
                List<Hre_ContractEntity> lstContract = new List<Hre_ContractEntity>();

                var salaryRankServices = new Cat_SalaryRankServices();
                var lstObjRank = new List<object>();
                lstObjRank.Add(null);
                lstObjRank.Add(null);
                lstObjRank.Add(1);
                lstObjRank.Add(int.MaxValue - 1);
                var lstRank = salaryRankServices.GetData<Cat_SalaryRankEntity>(lstObjRank, ConstantSql.hrm_cat_sp_get_SalaryRank, userLogin, ref status).ToList().Translate<Cat_SalaryRank>();
                var rankEntity = lstRank.Where(s => s.ID == SalaryRankID).FirstOrDefault();

                var salaryClassServices = new Cat_SalaryClassServices();
                var lstObjClass = new List<object>();
                lstObjClass.Add(null);
                lstObjClass.Add(1);
                lstObjClass.Add(int.MaxValue - 1);
                var salaryClass = salaryClassServices.GetData<Cat_SalaryClassEntity>(lstObjClass, ConstantSql.hrm_cat_sp_get_SalaryClass, userLogin, ref status).ToList().Translate<Cat_SalaryClass>();
                var salaryClassEntity = salaryClass.Where(s => rankEntity.SalaryClassID == s.ID).FirstOrDefault();

                var lstObjContractType = new List<object>();
                lstObjContractType.AddRange(new object[6]);
                lstObjContractType[4] = 1;
                lstObjContractType[5] = int.MaxValue - 1;
                var lstContractType = GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, userLogin, ref status).ToList();

                var candidateServices = new Hre_CandidateGeneralServices();
                var objCan = new List<object>();
                objCan.AddRange(new object[14]);
                objCan[12] = 1;
                objCan[13] = int.MaxValue - 1;
                var lstCan = candidateServices.GetData<Hre_CandidateGeneralEntity>(objCan, ConstantSql.hrm_hr_sp_get_CandidateGeneral, userLogin, ref status).ToList();

                var lstProfile = new List<Hre_ProfileEntity>();
                var workplaceServices = new Cat_WorkPlaceServices();
                var workplace = workplaceServices.GetData<Cat_WorkPlaceEntity>(Common.DotNetToOracle(WorkPlaceID.ToString()), ConstantSql.hrm_cat_sp_get_WorkPlaceById, userLogin, ref status).FirstOrDefault();

                foreach (var item in lstProfiles)
                {
                    var canEntity = lstCan.Where(s => s.ProfileID.Value == item.ID).FirstOrDefault();
                    if (canEntity == null)
                    {
                        //Add new contract
                        var objContract = new List<object>();
                        objContract.Add(item.ID);
                        var lstContractByProfileID = contractServices.GetData<Hre_ContractEntity>(objContract, ConstantSql.hrm_hr_sp_get_ContractsByProfileId, userLogin, ref status);
                        var listIdContract = string.Empty;
                        if (lstContractByProfileID != null)
                        {
                            listIdContract = string.Join(",", lstContractByProfileID.Select(d => d.ContractTypeID));
                        }
                        var contractType = lstContractType.Where(s => s.ID == ContractTypeID).FirstOrDefault();
                        DateTime dateEnd = DateHire;
                        if (contractType != null)
                        {
                            if (contractType.ValueTime != null)
                            {
                                //month = (int)contractType.ValueTime.Value;
                                //if (contractType.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                                //{
                                //    month = month * 12;
                                //}
                                if (contractType.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_MONTH.ToString())
                                {
                                    dateEnd = DateHire.AddMonths(int.Parse(contractType.ValueTime.Value.ToString()));
                                }
                                else if (contractType.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                                {
                                    dateEnd = DateHire.AddYears(int.Parse(contractType.ValueTime.Value.ToString()));
                                }
                            }
                        }
                        double Salary = 0;
                        if (!string.IsNullOrEmpty(BasicSalary))
                            Salary = double.Parse(BasicSalary);
                        Hre_ContractEntity Contract = new Hre_ContractEntity();
                        Contract.ProfileID = item.ID;
                        Contract.Salary = Salary;
                        Contract.ContractTypeID = ContractTypeID;
                        Contract.DateStart = DateHire;
                        Contract.DateSigned = DateHire;
                        Contract.DateEnd = dateEnd;

                        Contract.RankRateID = SalaryRankID;
                        Contract.ClassRateID = salaryClassEntity.ID;
                        if (!string.IsNullOrEmpty(contractType.Formula))
                        {
                            Contract = SetNewDateEndContract(Contract, userLogin);
                        }
                        Contract = SetNewCodeContract(Contract, listIdContract, userLogin);
                        contractServices.Add(Contract);


                        //Edit Profile
                        item.OrgStructureID = OrgStructureID;
                        item.SalaryClassID = salaryClassEntity == null ? Guid.Empty : salaryClassEntity.ID;
                        item.DateOfEffect = DateHire;
                        item.DateHire = DateHire;
                        item.DateEndProbation = Contract.DateEnd.Value;
                        item.WorkPlaceID = WorkPlaceID;
                        item.ContractTypeID = ContractTypeID;

                        profileSevices.Edit(item);

                        //// Add Insurance
                        //if (contractType != null && contractType.NoneTypeInsuarance == true)
                        //{
                        //    var insuranceEntity = new Sal_InsuranceSalaryEntity
                        //    {
                        //        ProfileID = item.ID,
                        //        InsuranceAmount = model.InsuranceAmount,
                        //        DateEffect = DateHire,
                        //        IsSocialIns = contractType.IsSocialInsurance == null ? null : contractType.IsSocialInsurance,
                        //        IsUnimploymentIns = contractType.IsUnEmployInsurance == null ? null : contractType.IsUnEmployInsurance,
                        //        IsMedicalIns = contractType.IsHealthInsurance == null ? null : contractType.IsHealthInsurance,
                        //        CurrencyID = model.CurenncyID1
                        //    };
                        //    insuranceServices.Add(insuranceEntity);
                        //}

                        Hre_WorkHistoryEntity workHistory = new Hre_WorkHistoryEntity();
                        workHistory.ProfileID = item.ID;
                        workHistory.DateEffective = DateHire;
                        workHistory.SalaryClassID = salaryClassEntity == null ? Guid.Empty : salaryClassEntity.ID;
                        workHistory.OrganizationStructureID = OrgStructureID;
                        workHistory.WorkLocation = workplace != null ? workplace.WorkPlaceName : null;

                        workingHistoryServices.Add(workHistory);
                    }


                }

            }
        }
Esempio n. 11
0
        public Hre_ProfileModel Post([Bind]Hre_ProfileModel model)
        {
            string status = string.Empty;
            if (model != null)
            {
                ActionService service = new ActionService(UserLogin);
                BaseService BaseService = new BaseService();

                if (!string.IsNullOrWhiteSpace(model.CodeAttendance))
                {
                    model.CodeAttendance = model.CodeAttendance.TrimAll();
                }

                #region Validate

                string message = string.Empty;

                var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ProfileModel>(model, "Hre_Profile", ref message);
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return model;
                }
                if (model.DateOfEffectOld != null)
                {
                    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ProfileModel>(model, "Hre_ProfileCheckDateOfEffect", ref message);
                    if (!checkValidate)
                    {
                        model.ActionStatus = message;
                        return model;
                    }
                }
                #endregion

                #region Xử lý cập nhật AbilityTitle khi chọn rank

                if (model.SalaryClassID != null)
                {
                    var abilityTitleBySalaryClass = BaseService.GetData<Cat_AbilityTileEntity>(Common.DotNetToOracle(model.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault();
                    if (abilityTitleBySalaryClass != null)
                    {
                        model.AbilityTileID = abilityTitleBySalaryClass.ID;
                    }
                }

                #endregion

                #region Xử Lý Lưu field DateOfBirth
                var dateOfBirth = string.Empty;
                if (model.DayOfBirth == 00 && model.MonthOfBirth == 00)
                {
                    model.ActionStatus = "ErrorDateOfBirth";
                    return model;
                }
                if (model.DayOfBirth == null && model.MonthOfBirth == null && model.YearOfBirth == null)
                {
                    dateOfBirth = string.Empty;

                }
                else
                {
                    if (model.DayOfBirth == null)
                    {
                        model.DayOfBirth = DateTime.Now.Day;
                    }
                    if (model.MonthOfBirth == null)
                    {
                        model.MonthOfBirth = DateTime.Now.Month;
                    }
                    if (model.YearOfBirth == null)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return model;
                    }
                }


                if (model.DayOfBirth >= 0 || model.MonthOfBirth >= 0 || model.YearOfBirth >= 0)
                {
                    if (model.DayOfBirth == 30 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return model;
                    }
                    if (model.DayOfBirth == 31 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return model;
                    }
                    if (model.DayOfBirth > 31 || model.MonthOfBirth > 12)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return model;
                    }
                    dateOfBirth = model.MonthOfBirth + "/" + model.DayOfBirth + "/" + model.YearOfBirth;

                }

                model.DateOfBirth = string.IsNullOrEmpty(dateOfBirth) ? (DateTime?)null : DateTime.Parse(dateOfBirth);
                #endregion
                Hre_ProfileModel HreProfile = new Hre_ProfileModel();
                if (model.ID != Guid.Empty)
                {
                    HreProfile = GetById(model.ID);
                }
                if (HreProfile != null && (model.ID == HreProfile.ID) && model.ActionStatus != "1")
                {
                    string[] listFieldName = new[] { "JobTitleID", "PositionID", "EmpTypeID", "DateOfEffect", "CostCentreID", "OrgStructureID", "WorkPlaceID", "SupervisorID" };
                    foreach (var item in listFieldName)
                    {
                        var value1 = model.GetPropertyValue(item);
                        var value2 = HreProfile.GetPropertyValue(item);
                        if ((value1 != null && value2 != null) && (value1.ToString() != value2.ToString()))
                        {
                            model.SetPropertyValue(Constant.ActionStatus, NotificationType.Change.ToString());
                            return model;
                        }
                    }
                    if (HreProfile.ProfileName != model.ProfileName)
                    {
                        if (model.ProfileName.Contains(' '))
                        {
                            model.FirstName = model.ProfileName.Substring(model.ProfileName.LastIndexOf(' ') + 1);
                            model.NameFamily = model.ProfileName.Substring(0, model.ProfileName.LastIndexOf(' '));
                        }
                        else
                        {
                            model.FirstName = model.ProfileName;
                        }
                    }
                }
                if (model.ActionStatus == "1" || model.ActionStatus == "Success" || string.IsNullOrEmpty(model.ActionStatus))
                {

                    var serviceAddress = new Hre_AddressServices();
                    var serviceProfile = new Hre_ProfileServices();
                    var profileEntity = new Hre_ProfileEntity();
                    if (model.ID != Guid.Empty)
                    {
                        profileEntity = serviceProfile.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();
                    }

                    #region Xử lý lưu CardCode
                    Hre_CardHistoryServices cardservices = new Hre_CardHistoryServices();
                    Hre_WorkHistoryServices workHistoryservices = new Hre_WorkHistoryServices();

                    if (profileEntity != null && model.CodeAttendance != null && model.DateApplyAttendanceCode != null && (model.CodeAttendance != profileEntity.CodeAttendance
                    || model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        // Chỉ thay đổi mã chấm công
                        if (model.DateApplyAttendanceCode == profileEntity.DateApplyAttendanceCode && model.CodeAttendance != profileEntity.CodeAttendance)
                        {
                            Hre_CardHistoryEntity history = cardservices.GetData<Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.CardCode = model.CodeAttendance;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history = new Hre_CardHistoryEntity();
                                history.ProfileID = model.ID;
                                history.CardCode = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                        // Chỉ thay đổi Ngày áp dụng mã chấm công

                        else if (model.CodeAttendance == profileEntity.CodeAttendance && model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode)
                        {
                            if (model.DateApplyAttendanceCode < profileEntity.DateApplyAttendanceCode)
                            {
                                model.StatusVerify = "Invalid";
                                return model;
                            }
                            Hre_CardHistoryEntity history = cardservices.GetData<Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history = new Hre_CardHistoryEntity();
                                history.ProfileID = model.ID;
                                history.CardCode = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                    }
                    // Tạo mới NV hoặc thay đổi cả 2( mã chấm công + ngày hiệu lực)
                    Hre_CardHistoryEntity cardhistory = null;
                    if (model != null && model.ID == Guid.Empty || (model != null && profileEntity != null && model.CodeAttendance != profileEntity.CodeAttendance
                                && model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        cardhistory = new Hre_CardHistoryEntity();
                        cardhistory.ProfileID = model.ID;
                        cardhistory.CardCode = model.CodeAttendance;
                        cardhistory.DateEffect = model.DateApplyAttendanceCode;
                    }
                    #endregion

                    #region Xử lý lưu quá trình công tác
                    Hre_WorkHistoryEntity workHistory = null;
                    if (model != null && (model.JobTitleID != profileEntity.JobTitleID || model.PositionID != profileEntity.PositionID || model.EmpTypeID != profileEntity.EmpTypeID ||
                        (model.DateOfEffect != null && profileEntity.DateOfEffect != null &&
                        model.DateOfEffect.Value.ToString() != profileEntity.DateOfEffect.Value.ToString())
                        || model.CostCentreID != profileEntity.CostCentreID || model.SupervisorID != profileEntity.SupervisorID
                        || model.OrgStructureID != profileEntity.OrgStructureID || model.WorkPlaceID != profileEntity.WorkPlaceID))
                    {

                        workHistory = new Hre_WorkHistoryEntity();
                        var orgService = new Cat_OrgStructureServices();
                        var jobtitleService = new Cat_JobTitleServices();
                        var postitionService = new Cat_PositionServices();
                        var workPlaceService = new Cat_WorkPlaceServices();

                        workHistory.CostCentreID = model.CostCentreID;
                        workHistory.OrganizationStructureID = model.OrgStructureID;
                        workHistory.PositionID = model.PositionID;
                        workHistory.JobTitleID = model.JobTitleID;
                        workHistory.SalaryClassID = model.SalaryClassID;
                        workHistory.CostSourceID = model.CostSourceID;
                        workHistory.AbilityTileID = model.AbilityTileID;
                        if (profileEntity != null)
                        {
                            var orgStructureOld = new Cat_OrgStructureEntity();
                            if (profileEntity.OrgStructureID != null && profileEntity.OrgStructureID != Guid.Empty)
                            {
                                orgStructureOld = orgService.GetData<Cat_OrgStructureEntity>(profileEntity.OrgStructureID, ConstantSql.hrm_cat_sp_get_OrgStructureById, UserLogin, ref status).FirstOrDefault();
                            }
                            var jobtitleOld = new Cat_JobTitleEntity();
                            if (profileEntity.JobTitleID != null && profileEntity.JobTitleID != Guid.Empty)
                            {
                                jobtitleOld = jobtitleService.GetData<Cat_JobTitleEntity>(profileEntity.JobTitleID, ConstantSql.hrm_cat_sp_get_HDTJobTypeById, UserLogin, ref status).FirstOrDefault();
                            }
                            var postitionOld = new Cat_PositionEntity();
                            if (profileEntity.PositionID != null && profileEntity.PositionID != Guid.Empty)
                            {
                                postitionOld = postitionService.GetData<Cat_PositionEntity>(profileEntity.PositionID, ConstantSql.hrm_cat_sp_get_PositionById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlace = new Cat_WorkPlaceEntity();
                            if (model.WorkPlaceID != null && model.WorkPlaceID != Guid.Empty)
                            {
                                workPlace = workPlaceService.GetData<Cat_WorkPlaceEntity>(model.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlaceOld = new Cat_WorkPlaceEntity();
                            if (profileEntity.WorkPlaceID != null && profileEntity.WorkPlaceID != Guid.Empty)
                            {
                                workPlaceOld = workPlaceService.GetData<Cat_WorkPlaceEntity>(profileEntity.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            workHistory.OrgOld = orgStructureOld != null ? orgStructureOld.OrgStructureName : "";
                            workHistory.JobTitleOld = jobtitleOld != null ? jobtitleOld.JobTitleName : "";
                            workHistory.PositionOld = postitionOld != null ? postitionOld.PositionName : "";
                            workHistory.WorkLocation = workPlace != null ? workPlace.WorkPlaceName : "";
                            workHistory.WorkLocationOld = workPlaceOld != null ? workPlaceOld.WorkPlaceName : "";
                        }
                        if (workHistory.ID == Guid.Empty)
                        {
                            if (model.DateOfEffect != null)
                            {
                                workHistory.DateEffective = model.DateOfEffect.Value;
                            }
                            else
                            {
                                workHistory.DateEffective = DateTime.Now;
                            }
                        }

                        if (model.DateQuit != null && (profileEntity == null || profileEntity.DateQuit != model.DateQuit))
                        {
                            workHistory.DateEffective = model.DateQuit.Value;
                        }
                    }

                    #region Ngày hiệu lực phải <= ngày hiện tại thì mới cập nhật lại quá trình công tác
                    if (model.DateOfEffect > DateTime.Now && profileEntity != null && profileEntity.DateOfEffect != null)
                    {
                        model.DateOfEffect = profileEntity.DateOfEffect;
                        model.OrgStructureID = profileEntity.OrgStructureID;
                        model.ShopID = profileEntity.ShopID;
                        model.JobTitleID = profileEntity.JobTitleID;
                        model.PositionID = profileEntity.PositionID;
                        model.SupervisorID = profileEntity.SupervisorID;
                        model.HighSupervisorID = profileEntity.HighSupervisorID;
                        model.IsHeadDept = profileEntity.IsHeadDept;
                        model.EmpTypeID = profileEntity.EmpTypeID;
                        model.LaborType = profileEntity.LaborType;
                        model.SikillLevel = profileEntity.SikillLevel;
                        model.PayrollGroupID = profileEntity.PayrollGroupID;
                        model.SalaryClassID = profileEntity.SalaryClassID;
                        model.CostCentreID = profileEntity.CostCentreID;
                        model.LocationCode = profileEntity.LocationCode;
                        model.WorkPlaceID = profileEntity.WorkPlaceID;
                    }
                    #endregion

                    #endregion

                    var profileModel = service.UpdateOrCreate<Hre_ProfileEntity, Hre_ProfileModel>(model);

                    if (cardhistory != null && profileModel != null)
                    {
                        cardhistory.ProfileID = profileModel.ID;
                        cardservices.Add(cardhistory);
                    }

                    if (workHistory != null && profileModel != null)
                    {
                        workHistory.EmployeeTypeID = profileModel.EmpTypeID;
                        workHistory.ProfileID = profileModel.ID;
                        workHistoryservices.Add(workHistory);
                    }
                }
            }

            //Xóa cache lưu lại của cây phòng ban
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeView");
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeViewSumProfile");

            return model;
        }