Пример #1
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);
                    }


                }

            }
        }
Пример #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;
        }