Ejemplo n.º 1
0
        public void AddDataForBasicSalary(string ProfileIDs, string BasicSalary, DateTime DateHire, Guid SalaryRankID,string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                string status = string.Empty;
                var repoBasicSalary = new CustomBaseRepository<Sal_BasicSalary>(unitOfWork);
                List<Guid> lstProfileIDs = ProfileIDs.Split(',').Select(x => Guid.Parse(x)).ToList();
                List<Sal_BasicSalary> lstBasicSalary = new List<Sal_BasicSalary>();
                //chua co cach giai quyet nen hard code lay mac dinh la VND
                var repoCurrency = new CustomBaseRepository<Cat_Currency>(unitOfWork);
                var currency = repoCurrency.FindBy(s => s.IsDelete == null && s.CurrencyName == "VND").FirstOrDefault();
                //var repoSalaryRank = new CustomBaseRepository<Cat_SalaryRank>(unitOfWork);
                //var repoSalaryClass = new CustomBaseRepository<Cat_SalaryClass>(unitOfWork);
                //var salaryRank = repoSalaryRank.FindBy(s => s.IsDelete == null && s.ID == SalaryRankID).FirstOrDefault();
                //var salaryClass = repoSalaryClass.FindBy(s => s.IsDelete == null && s.ID == salaryRank.SalaryClassID).FirstOrDefault();
                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();
               
                foreach (var item in lstProfileIDs)
                {
                    Sal_BasicSalary objBasicSalary = new Sal_BasicSalary();
                    objBasicSalary.ProfileID = item;
                    objBasicSalary.GrossAmount = BasicSalary;
                    objBasicSalary.Amount = BasicSalary.Encrypt(); 
                    objBasicSalary.DateOfEffect = DateHire;
                    objBasicSalary.RankRateID = SalaryRankID;
                    objBasicSalary.CurrencyID = currency.ID;
                    objBasicSalary.ClassRateID = salaryClassEntity == null ? Guid.Empty : salaryClassEntity.ID;
                    lstBasicSalary.Add(objBasicSalary);
                }

                repoBasicSalary.Add(lstBasicSalary);
                repoBasicSalary.SaveChanges();


            }
        }
Ejemplo n.º 2
0
        public void AddDataForBasicSalary(string ProfileIDs, string BasicSalary, DateTime DateHire, Guid SalaryRankID, string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var                    unitOfWork      = (IUnitOfWork)(new UnitOfWork(context));
                string                 status          = string.Empty;
                var                    repoBasicSalary = new CustomBaseRepository <Sal_BasicSalary>(unitOfWork);
                List <Guid>            lstProfileIDs   = ProfileIDs.Split(',').Select(x => Guid.Parse(x)).ToList();
                List <Sal_BasicSalary> lstBasicSalary  = new List <Sal_BasicSalary>();
                //chua co cach giai quyet nen hard code lay mac dinh la VND
                var repoCurrency = new CustomBaseRepository <Cat_Currency>(unitOfWork);
                var currency     = repoCurrency.FindBy(s => s.IsDelete == null && s.CurrencyName == "VND").FirstOrDefault();
                //var repoSalaryRank = new CustomBaseRepository<Cat_SalaryRank>(unitOfWork);
                //var repoSalaryClass = new CustomBaseRepository<Cat_SalaryClass>(unitOfWork);
                //var salaryRank = repoSalaryRank.FindBy(s => s.IsDelete == null && s.ID == SalaryRankID).FirstOrDefault();
                //var salaryClass = repoSalaryClass.FindBy(s => s.IsDelete == null && s.ID == salaryRank.SalaryClassID).FirstOrDefault();
                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();

                foreach (var item in lstProfileIDs)
                {
                    Sal_BasicSalary objBasicSalary = new Sal_BasicSalary();
                    objBasicSalary.ProfileID    = item;
                    objBasicSalary.GrossAmount  = BasicSalary;
                    objBasicSalary.Amount       = BasicSalary.Encrypt();
                    objBasicSalary.DateOfEffect = DateHire;
                    objBasicSalary.RankRateID   = SalaryRankID;
                    objBasicSalary.CurrencyID   = currency.ID;
                    objBasicSalary.ClassRateID  = salaryClassEntity == null ? Guid.Empty : salaryClassEntity.ID;
                    lstBasicSalary.Add(objBasicSalary);
                }

                repoBasicSalary.Add(lstBasicSalary);
                repoBasicSalary.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public List<Eva_PerformanceEntity> GetPerformanceGeneralList(List<Eva_PerformanceEntity> lstPerformce, string orgStructureID,string userLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                //DataTable table = CreateReportEvalutionSchema(_dateFrom, _dateTo);
                //if (_IsCreateTemplate)
                //    return table;
                string status = string.Empty;
                //DateTime _datetime = new DateTime(year, 01, 01);
                //Ngay goc
                //DateTime datetimeNode = _dateEnd.Value;
                List<object> paraEvalutionData = new List<object>();
                paraEvalutionData.AddRange(new object[17]);
                paraEvalutionData[0] = orgStructureID;
                //paraEvalutionData[1] = year;
                //paraEvalutionData[2] = _datetime;
                ////paraEvalutionData[3] = time;
                //paraEvalutionData[10] = _TimesGetDataID;

                //paraEvalutionData[11] = _JobTitleID;
                //paraEvalutionData[12] = _PositionID;
                //paraEvalutionData[13] = _WorkPlaceID;
                //paraEvalutionData[14] = _RankID;

                paraEvalutionData[15] = 1;
                paraEvalutionData[16] = int.MaxValue - 1;
                var evaServiceEvalutionData = new Eva_EvalutionDataServices();
                //chi danh gia nhung nv ngay vao lam <= ngay goc
                var lstEvalutionData = evaServiceEvalutionData.GetData<Eva_EvalutionDataEntity>(paraEvalutionData, ConstantSql.hrm_eva_getdata_EvalutionData, userLogin, ref status);
                Guid[] lstSalaryClassIDs = null;
                Guid[] lstProfielIds = null;
                if (lstEvalutionData != null)
                {
                    lstSalaryClassIDs = lstEvalutionData.Where(s => s.SalaryClassID != null).Select(s => s.SalaryClassID.Value).Distinct().ToArray();
                    lstEvalutionData = lstEvalutionData.Where(s => s.Year != null).ToList();
                }
                if(lstPerformce!=null)
                {
                    lstProfielIds = lstPerformce.Where(s => s.ProfileID != null).Select(s => s.ProfileID.Value).Distinct().ToArray();
                }
                #region luong co ban
                var lstBasicSalary = new List<Sal_BasicSalary>().Select(s => new { s.ProfileID, s.GrossAmount }).ToList();
                foreach (var lstProfile in lstProfielIds.Chunk(1000))
                {
                    lstBasicSalary.AddRange(unitOfWork.CreateQueryable<Sal_BasicSalary>(Guid.Empty, s => lstProfile.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.GrossAmount }).ToList());
                }
                List<object> paraSalaryRank = new List<object>();
                paraSalaryRank.AddRange(new object[4]);
                paraSalaryRank[2] = 1;
                paraSalaryRank[3] = int.MaxValue;
                var catServiceSalaryRank = new Cat_SalaryRankServices();
                var lstSalaryRank = catServiceSalaryRank.GetData<Cat_SalaryRankEntity>(paraSalaryRank, ConstantSql.hrm_cat_sp_get_SalaryRank, userLogin, ref status);
                if (lstSalaryRank != null && lstSalaryClassIDs != null)
                    lstSalaryRank = lstSalaryRank.Where(s => lstSalaryClassIDs.Contains(s.SalaryClassID.Value)).ToList();
                // s.DateOfEffect <= datetimeNode && 
                #endregion
             
                //DateTime dateFirstKi = _dateStart.Value;
                List<Eva_PerformanceEntity> lstPerformanceModel = new List<Eva_PerformanceEntity>();
                //lay all cau hinh 
                var lstAllSetting = unitOfWork.CreateQueryable<Sys_AllSetting>(Guid.Empty).Select(s => new { s.Name, s.Value1 }).ToList();
                foreach (var objPerformanceModel in lstPerformce)
                {
                    DateTime? _DateConfig=null;
                    DateTime? _dateFrom=null;
                    DateTime? _dateTo=null;
                    DateTime? datetimeNode=null;
                    DateTime? dateFirstKi=null;

                    //lay ket qua gan nhat danh gia cua nhan vien
                    if (objPerformanceModel.DateEffect != null)
                    {
                        if (lstEvalutionData != null)
                        {
                            var objEvalutionData = lstEvalutionData.Where(s => s.ProfileID == objPerformanceModel.ProfileID && objPerformanceModel.DateEffect.Value.Year == s.Year.Value.Year).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                            if (objEvalutionData != null && objEvalutionData.Year != null)
                            {
                                int? year;
                                year = objEvalutionData.Year.Value.Year;
                                //Get cau hinh ket thuc nam tai chinh
                                if (lstAllSetting.Count > 0)
                                {
                                    var tempDate = lstAllSetting.Where(s => s.Name == AppConfig.HRM_EVA_CONFIG_DAYENDYEARFINANCE.ToString()).Select(s => s.Value1).FirstOrDefault();
                                    DateTime tempDateConfig = DateTime.Now;
                                    DateTime.TryParse(tempDate, out tempDateConfig);
                                    _DateConfig = tempDateConfig;
                                }
                                if (_DateConfig != null)
                                {
                                    DateTime? _tempDate = _DateConfig.Value.AddDays(1);
                                    _dateFrom = new DateTime(year.Value, _tempDate.Value.Month, _tempDate.Value.Day);
                                    if (_dateFrom != null)
                                        dateFirstKi = _dateFrom;
                                    _DateConfig = new DateTime(DateTime.Now.Year, _DateConfig.Value.Month, _DateConfig.Value.Day);
                                    if (DateTime.Now.Date > _DateConfig)
                                    {
                                        _dateTo = new DateTime(year.Value + 1, _DateConfig.Value.Month, _DateConfig.Value.Day);
                                    }
                                    else
                                    {
                                        _dateTo = DateTime.Now.Date;
                                    }
                                }
                                if (_dateTo != null)
                                {
                                    datetimeNode = _dateTo;
                                    objPerformanceModel.ReportEvalutionDataNode = datetimeNode;
                                }

                                if (objEvalutionData.CostCentreCode != null)
                                    objPerformanceModel.GroupCode = objEvalutionData.CostCentreCode;
                                if (objEvalutionData.WorkPlaceCode != null)
                                    objPerformanceModel.LocationByGroupCode = objEvalutionData.WorkPlaceCode;

                                #region tham nien
                                if (objEvalutionData.DateOfBirth != null)
                                    objPerformanceModel.Age = DateTime.Today.Year - objEvalutionData.DateOfBirth.Value.Year;
                                if (objEvalutionData.DateHire != null)
                                {
                                    objPerformanceModel.Entering = objEvalutionData.DateHire;
                                    double dayServiceYear;
                                    dayServiceYear = datetimeNode.Value.Subtract(objEvalutionData.DateHire.Value).TotalDays;
                                    double _TotalYear = dayServiceYear / 360;
                                    double _tempYear = 0;
                                    if (_TotalYear > 0)
                                    {
                                        string[] parts = _TotalYear.ToString().Split('.');
                                        double _intMonth = double.Parse(parts[0]);
                                        if (parts.Length > 1)
                                        {
                                            double _modMonth = double.Parse("0." + parts[1]) * 12;
                                            if (_modMonth >= 10)
                                            {
                                                _tempYear = _intMonth + (_modMonth / 100);
                                            }
                                            else
                                            {
                                                _tempYear = _intMonth + (_modMonth / 10);
                                            }
                                        }
                                        objPerformanceModel.ServiceYear = String.Format("{0:0.0}", _tempYear); ;
                                    }
                                    if (objEvalutionData.DateHire.Value > dateFirstKi)
                                    {
                                        if (_TotalYear > 0)
                                            objPerformanceModel.ServiceYearKi = String.Format("{0:0.0}", _tempYear);
                                    }
                                    else
                                    {
                                        objPerformanceModel.ServiceYearKi = String.Format("{0:0.0}", 1.0);
                                    }
                                }
                                if(lstBasicSalary.Count>0)
                                {
                                    var objBasicSalary = lstBasicSalary.Where(s => s.ProfileID == objEvalutionData.ProfileID).FirstOrDefault();
                                    if (objBasicSalary != null)
                                        objPerformanceModel.BasicSalary = double.Parse(objBasicSalary.GrossAmount);
                                }
                                if (objEvalutionData.SalaryClassName != null)
                                    objPerformanceModel.Rank = objEvalutionData.SalaryClassName;
                                if (objEvalutionData.AbilityTitleVNI != null)
                                    objPerformanceModel.QualificationAbilitytitle = objEvalutionData.AbilityTitleVNI;
                                if (objEvalutionData.SalaryClassID != null)
                                {
                                    var objSalaryRank = lstSalaryRank.Where(s => s.SalaryClassID == objEvalutionData.SalaryClassID).FirstOrDefault();
                                    if (objSalaryRank != null)
                                        objPerformanceModel.RankZone = objSalaryRank.SalaryRankName;
                                }
                                objPerformanceModel.JobTitleName = objEvalutionData.JobTitleName;
                                double? totalUnusualAllowance = 0;
                                if (totalUnusualAllowance > 0)
                                    objPerformanceModel.TotalSalaryAllowance = totalUnusualAllowance;
                                if (objEvalutionData.Year != null)
                                    objPerformanceModel.Year = objEvalutionData.Year;
                                #region lan danh gia
                                if (objEvalutionData.TimeEvalutionData != null)
                                    objPerformanceModel.TimeEvalutionData = objEvalutionData.TimeEvalutionData;
                                if (objEvalutionData.TimeEvalutionDataCode != null)
                                    objPerformanceModel.TimeEvalutionDataCode = objEvalutionData.TimeEvalutionDataCode;
                                #endregion
                                #region C1->C32
                                if (objEvalutionData.C1 != null)
                                    objPerformanceModel.C1 = objEvalutionData.C1;
                                if (objEvalutionData.C2 != null)
                                    objPerformanceModel.C2 = objEvalutionData.C2;
                                if (objEvalutionData.C3 != null)
                                    objPerformanceModel.C3 = objEvalutionData.C3;
                                if (objEvalutionData.C4 != null)
                                    objPerformanceModel.C4 = objEvalutionData.C4;
                                if (objEvalutionData.C5 != null)
                                    objPerformanceModel.C5 = objEvalutionData.C5;
                                if (objEvalutionData.C6 != null)
                                    objPerformanceModel.C6 = objEvalutionData.C6;
                                if (objEvalutionData.C7 != null)
                                    objPerformanceModel.C7 = objEvalutionData.C7;
                                if (objEvalutionData.C8 != null)
                                    objPerformanceModel.C8 = objEvalutionData.C8;
                                if (objEvalutionData.C9 != null)
                                    objPerformanceModel.C9 = objEvalutionData.C9;
                                if (objEvalutionData.C10 != null)
                                    objPerformanceModel.C10 = objEvalutionData.C10;
                                if (objEvalutionData.C11 != null)
                                    objPerformanceModel.C11 = objEvalutionData.C11;
                                if (objEvalutionData.C12 != null)
                                    objPerformanceModel.C12 = objEvalutionData.C12;
                                if (objEvalutionData.C13 != null)
                                    objPerformanceModel.C13 = objEvalutionData.C13;
                                if (objEvalutionData.C14 != null)
                                    objPerformanceModel.C14 = objEvalutionData.C14;
                                if (objEvalutionData.C15 != null)
                                    objPerformanceModel.C15 = objEvalutionData.C15;
                                if (objEvalutionData.C16 != null)
                                    objPerformanceModel.C16 = objEvalutionData.C16;
                                if (objEvalutionData.C17 != null)
                                    objPerformanceModel.C17 = objEvalutionData.C17;
                                if (objEvalutionData.C18 != null)
                                    objPerformanceModel.C18 = objEvalutionData.C18;
                                if (objEvalutionData.C19 != null)
                                    objPerformanceModel.C19 = objEvalutionData.C19;
                                if (objEvalutionData.C20 != null)
                                    objPerformanceModel.C20 = objEvalutionData.C20;
                                if (objEvalutionData.C21 != null)
                                    objPerformanceModel.C21 = objEvalutionData.C21;
                                if (objEvalutionData.C22 != null)
                                    objPerformanceModel.C22 = objEvalutionData.C22;
                                if (objEvalutionData.C23 != null)
                                    objPerformanceModel.C23 = objEvalutionData.C23;
                                if (objEvalutionData.C24 != null)
                                    objPerformanceModel.C24 = objEvalutionData.C24;
                                if (objEvalutionData.C25 != null)
                                    objPerformanceModel.C25 = objEvalutionData.C25;
                                if (objEvalutionData.C26 != null)
                                    objPerformanceModel.C26 = objEvalutionData.C26;
                                if (objEvalutionData.C27 != null)
                                    objPerformanceModel.C27 = objEvalutionData.C27;
                                if (objEvalutionData.C28 != null)
                                    objPerformanceModel.C28 = objEvalutionData.C28;
                                if (objEvalutionData.C29 != null)
                                    objPerformanceModel.C29 = objEvalutionData.C29;
                                if (objEvalutionData.C30 != null)
                                    objPerformanceModel.C30 = objEvalutionData.C30;
                                if (objEvalutionData.C31 != null)
                                    objPerformanceModel.C31 = objEvalutionData.C31;
                                if (objEvalutionData.C32 != null)
                                    objPerformanceModel.C32 = objEvalutionData.C32;
                                #endregion
                                #endregion
                                #region thoi gian danh gia
                                if (_dateFrom != null)
                                    objPerformanceModel.DateStart = _dateFrom;
                                if (_dateTo != null)
                                    objPerformanceModel.DateEnd = _dateTo;
                            }
                        }
                                #endregion
                    }
                    lstPerformanceModel.Add(objPerformanceModel);
                }
                return lstPerformanceModel;
            }
        }
Ejemplo n.º 4
0
        public DataTable GetReportEvalutionData(int year, Guid? _TimesGetDataID, string orgStructureID, bool _IsCreateTemplate, DateTime? _dateStart,
            DateTime? _dateEnd, DateTime? _dateFrom, DateTime? _dateTo, Guid? _JobTitleID, Guid? _PositionID, Guid? _WorkPlaceID, Guid? _RankID,string userLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                DataTable table = CreateReportEvalutionSchema(_dateFrom, _dateTo, userLogin);
                if (_IsCreateTemplate)
                    return table;
                string status = string.Empty;
                List<Eva_EvalutionDataEntity> lstEvalutionDataEntity = new List<Eva_EvalutionDataEntity>();
                DateTime _datetime = new DateTime(year, 01, 01);
                //Ngay goc
                DateTime datetimeNode = _dateEnd.Value;
                List<object> paraEvalutionData = new List<object>();
                paraEvalutionData.AddRange(new object[17]);
                paraEvalutionData[0] = orgStructureID;
                paraEvalutionData[1] = year;
                paraEvalutionData[2] = _datetime;
                //paraEvalutionData[3] = time;
                paraEvalutionData[10] = _TimesGetDataID;

                paraEvalutionData[11] = _JobTitleID;
                paraEvalutionData[12] = _PositionID;
                paraEvalutionData[13] = _WorkPlaceID;
                paraEvalutionData[14] = _RankID;

                paraEvalutionData[15] = 1;
                paraEvalutionData[16] = int.MaxValue - 1;
                var evaServiceEvalutionData = new Eva_EvalutionDataServices();
                //chi danh gia nhung nv ngay vao lam <= ngay goc
                var lstEvalutionData = evaServiceEvalutionData.GetData<Eva_EvalutionDataEntity>(paraEvalutionData, ConstantSql.hrm_eva_getdata_EvalutionData, userLogin, ref status);
                Guid[] lstSalaryClassIDs = null;
                Guid[] lstProfielIds = null;
                if (lstEvalutionData != null)
                {
                    lstSalaryClassIDs = lstEvalutionData.Where(s => s.SalaryClassID != null).Select(s => s.SalaryClassID.Value).Distinct().ToArray();
                    lstProfielIds = lstEvalutionData.Where(s => s.ProfileID != null).Select(s => s.ProfileID.Value).Distinct().ToArray();
                }
                #region luong co ban
                List<object> paraBasicSalary = new List<object>();
                paraBasicSalary.AddRange(new object[10]);
                DateTime _dateMin = DateTime.MinValue;

                paraBasicSalary[2] = orgStructureID;
                paraBasicSalary[3] = _dateMin;
                paraBasicSalary[4] = datetimeNode;
                paraBasicSalary[5] = _dateMin;
                paraBasicSalary[6] = datetimeNode;
                paraBasicSalary[8] = 1;
                paraBasicSalary[9] = int.MaxValue - 1;
                var salServiceBasicSalary = new Sal_BasicSalaryServices();
                var lstBasicSalary = salServiceBasicSalary.GetData<Sal_BasicSalaryEntity>(paraBasicSalary, ConstantSql.hrm_sal_sp_get_BasicPayroll, userLogin, ref status);
                if (lstBasicSalary != null && lstProfielIds != null)
                    lstBasicSalary = lstBasicSalary.Where(s => lstProfielIds.Contains(s.ProfileID)).ToList();
                List<object> paraSalaryRank = new List<object>();
                paraSalaryRank.AddRange(new object[4]);
                paraSalaryRank[2] = 1;
                paraSalaryRank[3] = int.MaxValue;
                var catServiceSalaryRank = new Cat_SalaryRankServices();
                var lstSalaryRank = catServiceSalaryRank.GetData<Cat_SalaryRankEntity>(paraSalaryRank, ConstantSql.hrm_cat_sp_get_SalaryRank, userLogin, ref status);
                if (lstSalaryRank != null && lstSalaryClassIDs != null)
                    lstSalaryRank = lstSalaryRank.Where(s => s.DateOfEffect <= datetimeNode && lstSalaryClassIDs.Contains(s.SalaryClassID.Value)).ToList();
                #endregion
                #region phu cap
                List<object> paraUnusualAllowance = new List<object>();
                paraUnusualAllowance.AddRange(new object[9]);

                paraBasicSalary[3] = _dateMin;
                paraBasicSalary[4] = datetimeNode;
                paraUnusualAllowance[7] = 1;
                paraUnusualAllowance[8] = int.MaxValue - 1;
                var salServiceUnusualAllowance = new Sal_UnusualAllowanceServices();
                var lstUnusualAllowance = salServiceUnusualAllowance.GetData<Sal_UnusualAllowanceEntity>(paraUnusualAllowance, ConstantSql.hrm_sal_sp_get_UnusualED, userLogin, ref status);
                List<Guid> lstUnusualAllowanceIDs = null;
                if (lstUnusualAllowance != null)
                {
                    //lstUnusualAllowance = lstUnusualAllowance.Where(s => s.MonthEnd <= datetimeNode || (s.MonthStart <= datetimeNode && s.MonthEnd == null)).ToList();
                    lstUnusualAllowanceIDs = lstUnusualAllowance.Where(s => s.UnusualEDTypeID != null).Select(s => s.UnusualEDTypeID.Value).Distinct().ToList();
                }

                #endregion
                #region loai phu cap
                List<object> paraUnusualAllowanceCfg = new List<object>();
                paraUnusualAllowanceCfg.AddRange(new object[6]);
                paraUnusualAllowanceCfg[4] = 1;
                paraUnusualAllowanceCfg[5] = int.MaxValue - 1;
                var catServiceUnusualAllowanceCfg = new Cat_UnusualAllowanceCfgServices();
                var lstUnusualAllowanceCfg = catServiceUnusualAllowanceCfg.GetData<Cat_UnusualAllowanceCfgEntity>(paraUnusualAllowanceCfg, ConstantSql.hrm_cat_sp_get_UnusualAllowanceCfg, userLogin, ref status);
                if (lstUnusualAllowanceCfg != null && lstUnusualAllowanceIDs != null)
                    lstUnusualAllowanceCfg = lstUnusualAllowanceCfg.Where(s => lstUnusualAllowanceIDs.Contains(s.ID)).ToList();
                #endregion
                #region lay lich su danh gia
                List<Eva_PerformanceEntity> lstPerformance = null;
                int _yearFrom = DateTime.MinValue.Year;
                int _yearTo = DateTime.MinValue.Year;
                if (_dateFrom != null && _dateTo != null)
                {
                    _yearFrom = _dateFrom.Value.Year;
                    _yearTo = _dateTo.Value.Year;
                    var evaServicePerformance = new Eva_PerformanceServices();
                    List<object> paraPerformance = new List<object>();
                    paraPerformance.AddRange(new object[20]);
                    paraPerformance[2] = orgStructureID;
                    paraPerformance[18] = 1;
                    paraPerformance[19] = int.MaxValue - 1;
                    lstPerformance = evaServicePerformance.GetData<Eva_PerformanceEntity>(paraPerformance, ConstantSql.hrm_eva_sp_get_PerformanceGeneral, userLogin, ref status);
                    if (lstPerformance != null)
                        lstPerformance = lstPerformance.Where(s => s.YearEvaluation != null).ToList();
                    if (lstPerformance.Count != 0)
                        lstPerformance = lstPerformance.Where(s => s.YearEvaluation.Value.Year >= _yearFrom && s.YearEvaluation.Value.Year <= _yearTo).ToList();
                }
                #endregion
                DateTime dateFirstKi = _dateStart.Value;
                foreach (var item in lstEvalutionData)
                {
                    DataRow row = table.NewRow();
                    #region thong tin nhan vien
                    row[Eva_ReportEvalutionDataEntity.FieldNames.CodeEmp] = item.CodeEmp;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.ProfileName] = item.ProfileName;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.E_DEPARTMENT] = item.E_DEPARTMENT;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.E_DIVISION] = item.E_DIVISION;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.E_SECTION] = item.E_SECTION;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.E_TEAM] = item.E_TEAM;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.E_UNIT] = item.E_UNIT;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.GroupCode] = item.CostCentreCode;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.LocationByGroupCode] = item.WorkPlaceCode;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.ReportEvalutionDataNode] = datetimeNode;
                    #endregion
                    #region tham nien
                    if (item.DateOfBirth != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.Age] = DateTime.Today.Year - item.DateOfBirth.Value.Year;
                    if (item.DateHire != null)
                    {
                        row[Eva_ReportEvalutionDataEntity.FieldNames.Entering] = item.DateHire;
                        double dayServiceYear;
                        dayServiceYear = datetimeNode.Subtract(item.DateHire.Value).TotalDays;
                        double _TotalYear = dayServiceYear / 360;
                        double _tempYear = 0;
                        if (_TotalYear > 0)
                        {
                            string[] parts = _TotalYear.ToString().Split('.');
                            double _intMonth = double.Parse(parts[0]);
                            if (parts.Length > 1)
                            {
                                double _modMonth = double.Parse("0." + parts[1]) * 12;
                                if (_modMonth >= 10)
                                {
                                    _tempYear = _intMonth + (_modMonth / 100);
                                }
                                else
                                {
                                    _tempYear = _intMonth + (_modMonth / 10);
                                }
                            }
                            row[Eva_ReportEvalutionDataEntity.FieldNames.ServiceYear] = String.Format("{0:0.0}", _tempYear); ;
                        }
                        if (item.DateHire.Value > dateFirstKi)
                        {
                            if (_TotalYear > 0)
                                row[Eva_ReportEvalutionDataEntity.FieldNames.ServiceYearKi] = String.Format("{0:0.0}", _tempYear);
                        }
                        else
                        {
                            row[Eva_ReportEvalutionDataEntity.FieldNames.ServiceYearKi] = 1.0;
                        }
                    }
                    #endregion

                    var objBasicSalary = lstBasicSalary.Where(s => s.ProfileID == item.ProfileID).FirstOrDefault();
                    if (objBasicSalary != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.BasicSalary] = double.Parse(objBasicSalary.GrossAmount);
                    row[Eva_ReportEvalutionDataEntity.FieldNames.Rank] = item.SalaryClassName;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.QualificationAbilitytitle] = item.AbilityTitleVNI;
                    if (item.SalaryClassID != null)
                    {
                        var objSalaryRank = lstSalaryRank.Where(s => s.SalaryClassID == item.SalaryClassID).FirstOrDefault();
                        if (objSalaryRank != null)
                            row[Eva_ReportEvalutionDataEntity.FieldNames.RankZone] = objSalaryRank.SalaryRankName;
                    }
                    row[Eva_ReportEvalutionDataEntity.FieldNames.JobTitle] = item.JobTitleName;
                    Guid[] lstUnusualAllowanceProfileCfgIds = null;
                    if (lstUnusualAllowance != null)
                    {
                        lstUnusualAllowance = lstUnusualAllowance.Where(s => s.ProfileID == item.ProfileID && s.UnusualEDTypeID != null).ToList();
                        lstUnusualAllowanceProfileCfgIds = lstUnusualAllowance.Select(s => s.UnusualEDTypeID.Value).ToArray();
                    }
                    if (lstUnusualAllowanceCfg != null && lstUnusualAllowanceProfileCfgIds != null)
                        lstUnusualAllowanceCfg = lstUnusualAllowanceCfg.Where(s => lstUnusualAllowanceProfileCfgIds.Contains(s.ID)).ToList();
                    double? totalUnusualAllowance = 0;
                    if (lstUnusualAllowanceCfg != null)
                    {
                        foreach (var itemUnusualAllowanceCfg in lstUnusualAllowanceCfg)
                        {
                            var objUnusualAllowance = lstUnusualAllowance.Where(s => s.UnusualEDTypeID == itemUnusualAllowanceCfg.ID).OrderByDescending(s => s.MonthEnd).FirstOrDefault();
                            if (objUnusualAllowance != null)
                            {
                                row[itemUnusualAllowanceCfg.Code] = objUnusualAllowance.Amount;
                                totalUnusualAllowance += objUnusualAllowance.Amount;
                            }
                        }
                    }
                    #region lich su danh gia
                    if (_dateFrom != null && _dateTo != null && lstPerformance != null)
                    {
                        _yearFrom = _dateFrom.Value.Year;
                        _yearTo = _dateTo.Value.Year;
                        var lstPerformanceProfile = lstPerformance.Where(s => s.ProfileID == item.ProfileID).OrderByDescending(s => s.YearEvaluation).ToList();
                        if (lstPerformanceProfile.Count != 0)
                        {
                            while (_yearTo >= _yearFrom)
                            {
                                var objPerformanceFirst = lstPerformanceProfile.Where(s => s.YearEvaluation.Value.Year == _yearTo).OrderByDescending(s => s.YearEvaluation).FirstOrDefault();
                                _yearTo -= 1;
                                var objPerformance = lstPerformanceProfile.Where(s => s.YearEvaluation.Value.Year == _yearTo).OrderByDescending(s => s.YearEvaluation).FirstOrDefault();
                                int _yeartemp = _yearTo + 1;
                                if (objPerformanceFirst != null && objPerformanceFirst.Level1Name != null)
                                {
                                    if (objPerformanceFirst.RankID != null && objPerformance != null && objPerformance.Level1Name != null && objPerformance.RankID != null)
                                    {
                                        if (objPerformanceFirst.RankID != objPerformance.RankID)
                                        {
                                            row["Year" + _yeartemp] = "(" + objPerformanceFirst.Level1Name + ")";
                                            row["Year" + _yearTo] = "(" + objPerformance.Level1Name + ")";
                                            _yearTo -= 1;
                                            while (_yearTo >= _yearFrom)
                                            {
                                                var objPerformanceYear = lstPerformanceProfile.Where(s => s.YearEvaluation.Value.Year == _yearTo).OrderByDescending(s => s.YearEvaluation).FirstOrDefault();
                                                if (objPerformanceYear != null && objPerformanceYear.Level1Name != null)
                                                    row["Year" + _yearTo] = "(" + objPerformanceYear.Level1Name + ")";
                                                _yearTo -= 1;
                                            }
                                        }
                                        else
                                        {
                                            row["Year" + _yeartemp] = objPerformanceFirst.Level1Name;
                                        }
                                    }
                                    else
                                    {
                                        row["Year" + _yeartemp] = objPerformanceFirst.Level1Name;
                                    }
                                }
                            }
                        }
                        row[Eva_ReportEvalutionDataEntity.FieldNames.HistoryDateFrom] = _dateFrom.Value.ToShortDateString();
                    }
                    #endregion
                    if (totalUnusualAllowance > 0)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.TotalSalaryAllowance] = totalUnusualAllowance;
                    if (item.Year != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.Year] = item.Year;
                    //if (item.Time !=null)
                    //    row[Eva_ReportEvalutionDataEntity.FieldNames.Time] = item.Time;
                    #region lan danh gia
                    if (item.TimeEvalutionData != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.TimeEvalutionData] = item.TimeEvalutionData;
                    if (item.TimeEvalutionDataCode != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.TimeEvalutionDataCode] = item.TimeEvalutionDataCode;

                    #endregion


                    #region C1->C32
                    if (item.C1 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C1] = item.C1;
                    if (item.C2 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C2] = item.C2;
                    if (item.C3 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C3] = item.C3;
                    if (item.C4 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C4] = item.C4;
                    if (item.C5 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C5] = item.C5;
                    if (item.C6 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C6] = item.C6;
                    if (item.C7 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C7] = item.C7;
                    if (item.C8 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C8] = item.C8;
                    if (item.C9 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C9] = item.C9;
                    if (item.C10 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C10] = item.C10;
                    if (item.C11 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C11] = item.C11;
                    if (item.C12 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C12] = item.C12;
                    if (item.C13 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C13] = item.C13;
                    if (item.C14 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C14] = item.C14;
                    if (item.C15 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C15] = item.C15;
                    if (item.C16 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C16] = item.C16;
                    if (item.C17 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C17] = item.C17;
                    if (item.C18 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C18] = item.C18;
                    if (item.C19 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C19] = item.C19;
                    if (item.C20 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C20] = item.C20;
                    if (item.C21 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C21] = item.C21;
                    if (item.C22 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C22] = item.C22;
                    if (item.C23 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C23] = item.C23;
                    if (item.C24 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C24] = item.C24;
                    if (item.C25 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C25] = item.C25;
                    if (item.C26 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C26] = item.C26;
                    if (item.C27 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C27] = item.C27;
                    if (item.C28 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C28] = item.C28;
                    if (item.C29 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C29] = item.C29;
                    if (item.C30 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C30] = item.C30;
                    if (item.C31 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C31] = item.C31;
                    if (item.C32 != null)
                        row[Eva_ReportEvalutionDataEntity.FieldNames.C32] = item.C32;
                    #endregion
                    #region Bo sung
                    //int _tempC1 = 0;
                    //int _TempC2 = 0;
                    //int _tempC3 = 0;
                    //int _tempC4 = 0;
                    //int _tempC5 = 0;
                    //int _tempC6 = 0;
                    //int _tempC7 = 0;
                    //int _tempC8 = 0;
                    //int _tempC9 = 0;
                    //#region TotalC1C2
                    //if (item.C1 != null)
                    //    _tempC1 = item.C1.Value;
                    //if (item.C2 != null)
                    //    _TempC2 = item.C2.Value;
                    //if (item.C1 != null || item.C2 != null)
                    //    row[Eva_ReportEvalutionDataEntity.FieldNames.TotalC1C2] = _tempC1 + _TempC2;
                    //#endregion
                    //#region TotalC3C4C5C6C7
                    //if (item.C3 != null)
                    //    _tempC3 = item.C3.Value;
                    //if (item.C4 != null)
                    //    _tempC4 = item.C4.Value;
                    //if (item.C5 != null)
                    //    _tempC5 = item.C5.Value;
                    //if (item.C6 != null)
                    //    _tempC6 = item.C6.Value;
                    //if (item.C7 != null)
                    //    _tempC7 = item.C7.Value;
                    //if (item.C3 != null || item.C4 != null || item.C5 != null || item.C6 != null || item.C7 != null)
                    //    row[Eva_ReportEvalutionDataEntity.FieldNames.TotalC3C4C5C6C7] = _tempC3 + _tempC4 + _tempC5 + _tempC6 + _tempC7;
                    //#endregion
                    //#region TotalC1C2C3C4C5C6C7
                    //if (item.C1 != null || item.C2 != null || item.C3 != null || item.C4 != null || item.C5 != null || item.C6 != null || item.C7 != null)
                    //    row[Eva_ReportEvalutionDataEntity.FieldNames.TotalC1C2C3C4C5C6C7] = _tempC1 + _TempC2 + _tempC3 + _tempC4 + _tempC5 + _tempC6 + _tempC7;
                    //#endregion
                    //#region  TotalC8C9
                    //if (item.C8 != null)
                    //    _tempC8 = item.C8.Value;
                    //if (item.C9 != null)
                    //    _tempC9 = item.C9.Value;
                    //if (item.C8 != null || item.C9 != null)
                    //    row[Eva_ReportEvalutionDataEntity.FieldNames.TotalC8C9] = _tempC8 + _tempC9;
                    //#endregion                    
                    #endregion
                    #region thoi gian danh gia
                    row[Eva_ReportEvalutionDataEntity.FieldNames.DateStart] = _dateStart;
                    row[Eva_ReportEvalutionDataEntity.FieldNames.DateEnd] = _dateEnd;
                    #endregion
                    table.Rows.Add(row);
                }
                return table.ConfigTable();
                //    #endregion
            }
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        public ActionResult GetDataBySalaryRankID(string rankID)
        {

            string status = string.Empty;
            ActionService service = new ActionService(UserLogin);
            var salaryRankService = new Cat_SalaryRankServices();
            var result = service.GetByIdUseStore<Cat_SalaryRankEntity>(Common.ConvertToGuid(rankID), ConstantSql.hrm_cat_sp_get_SalaryRankById, ref status);
            var model = result.CopyData<Cat_SalaryRankModel>();

            return Json(model, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 7
0
        public ActionResult GetDataByContractID(string contractID, string contractTypeID)
        {

            string status = string.Empty;

            if (contractID == null)
            {
                return null;
            }
            var actionService = new ActionService(UserLogin);

            var salaryRankServices = new Cat_SalaryRankServices();
            var lstObjSalaryRank = new List<object>();
            lstObjSalaryRank.Add(null);
            lstObjSalaryRank.Add(1);
            lstObjSalaryRank.Add(int.MaxValue - 1);

            var contractTypeServices = new Cat_ContractTypeServices();
            var lstContractType = actionService.GetData<Cat_ContractTypeEntity>(Common.ConvertToGuid(contractTypeID), ConstantSql.hrm_cat_sp_get_ContractTypeById, ref status).FirstOrDefault();

            var lstSalaryRank = actionService.GetData<Cat_SalaryRankEntity>(lstObjSalaryRank, ConstantSql.hrm_cat_sp_get_SalaryRank, ref status).ToList();

            var result = actionService.GetData<Hre_ContractEntity>(Common.ConvertToGuid(contractID), ConstantSql.hrm_hr_sp_get_ContractById, ref status).FirstOrDefault();
            if (result != null)
            {
                if (result.ContractEvaType == EnumDropDown.ContractEvaType.E_EXPIRED_APPRENTICE.ToString())
                {
                    int month = 0;
                    if (lstContractType.ValueTime != null)
                    {
                        month = (int)lstContractType.ValueTime.Value;
                        if (lstContractType.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                        {
                            month = month * 12;
                        }
                        lstContractType.DateStart = result.DateEnd.Value.AddDays(1);
                    }
                    //chưa tìm dc cách xử lý nên hard code 
                    var lstSalaryRankNew = lstSalaryRank.Where(s => s.SalaryRankName == "R0V08").FirstOrDefault();
                    var contractModel = new Hre_ContractModel
                    {
                        //   ContractNo = getContractNo(result, result.DateSigned),
                        ProfileID = result.ProfileID,
                        DateStart = result.DateEnd.Value.AddDays(1),
                        DateSigned = result.DateEnd.Value.AddDays(1),
                        DateEnd = lstContractType.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

                    };
                    return Json(contractModel, JsonRequestBehavior.AllowGet);
                }

                if (result.ContractEvaType == EnumDropDown.ContractEvaType.E_ANNUAL_EVALUATION.ToString())
                {
                    var contractModel = new Hre_ContractModel
                    {
                        //  ContractNo = getContractNo(result, result.DateSigned),
                        ProfileID = result.ProfileID,
                        DateStart = new DateTime(DateTime.Now.Year, 06, 01),
                    };
                    return Json(contractModel, JsonRequestBehavior.AllowGet);
                }
            }

            return null;
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public ActionResult ActionApplyCandidateGeneral(string selectedIds)
        {
            string message = NotificationType.Success.ToString();
            var actionService = new ActionService(UserLogin);
            string status = string.Empty;
            var lstCandidateGeneral = actionService.GetData<Hre_CandidateGeneralEntity>(Common.DotNetToOracle(selectedIds), ConstantSql.hrm_hr_sp_get_GeneralCandidateByIds, ref status);
            var salaryRankServices = new Cat_SalaryRankServices();
            var salaryClassServices = new Cat_SalaryClassServices();
            var profileServices = new Hre_ProfileServices();
            var contracttypeServices = new Cat_ContractTypeServices();
            var workHistoryServices = new Hre_WorkHistoryServices();
            var rankEntity = new Cat_SalaryRankEntity();
            var salaryClass = new Cat_SalaryClassEntity();
            var contractypeentity = new Cat_ContractTypeEntity();
            ActionService service = new ActionService(UserLogin);
            var salgradeServices = new Sal_GradeServices();
            var attgradeservive = new Att_GradeServices();

            foreach (var CandidateGeneral in lstCandidateGeneral)
            {
                #region Code Cũ
                //var datecontract = DateTime.Now;
                //if (CandidateGeneral.EnteringDate != null)
                //{
                //    datecontract = CandidateGeneral.EnteringDate.Value;
                //}
                //if (CandidateGeneral.RankRateID != Guid.Empty)
                //{
                //    rankEntity = service.GetByIdUseStore<Cat_SalaryRankEntity>(CandidateGeneral.RankRateID.Value,
                //                        ConstantSql.hrm_cat_sp_get_SalaryRankById, ref status);
                //}
                //if(CandidateGeneral.ContractTypeID != Guid.Empty)
                //{
                //    contractypeentity = service.GetByIdUseStore<Cat_ContractTypeEntity>(CandidateGeneral.ContractTypeID.Value, ConstantSql.hrm_cat_sp_get_ContractTypeById, ref status);
                //}

                //var profileEntity = profileServices.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(CandidateGeneral.ProfileID.ToString()),
                //        ConstantSql.hrm_hr_sp_get_ProfileById, ref status).FirstOrDefault();

                //if (contractypeentity != null && contractypeentity.ValueTime != null)
                //{
                //    if (contractypeentity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_MONTH.ToString())
                //    {
                //        datecontract = datecontract.AddMonths(int.Parse(contractypeentity.ValueTime.Value.ToString()));
                //    }
                //    else if (contractypeentity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                //    {
                //        datecontract = datecontract.AddYears(int.Parse(contractypeentity.ValueTime.Value.ToString()));
                //    }
                //}

                //if(profileEntity != null)
                //{
                //    profileEntity.OrgStructureID = CandidateGeneral.OrgStructureID;
                //    profileEntity.SalaryClassID = CandidateGeneral.SalaryClassID;
                //    profileEntity.DateHire = CandidateGeneral.EnteringDate;
                //    profileEntity.DateEndProbation = datecontract;
                //    profileEntity.WorkPlaceID = CandidateGeneral.WorkPlaceID;
                //}

                // var workplaceServices = new Cat_WorkPlaceServices();
                // Cat_WorkPlaceEntity workplace = null;
                //if(CandidateGeneral.WorkPlaceID != Guid.Empty)
                //{
                //workplace = workplaceServices.GetData<Cat_WorkPlaceEntity>(Common.DotNetToOracle(CandidateGeneral.WorkPlaceID.ToString()), ConstantSql.hrm_cat_sp_get_WorkPlaceById, ref status).FirstOrDefault();
                //}

                //var WorkHistoryEntity = new Hre_WorkHistoryEntity();
                //    WorkHistoryEntity.ProfileID = CandidateGeneral.ProfileID.Value;
                //    WorkHistoryEntity.DateEffective = CandidateGeneral.EnteringDate != null ? CandidateGeneral.EnteringDate.Value ? DateTime.Now;
                //    WorkHistoryEntity.SalaryClassID = CandidateGeneral.SalaryClassID;
                //    WorkHistoryEntity.OrganizationStructureID = CandidateGeneral.OrgStructureID;
                //    WorkHistoryEntity.WorkLocation = workplace != null ? workplace.WorkPlaceName : null;
                //    workHistoryServices.Add(WorkHistoryEntity);
                //} 
                #endregion

                var datecontract = DateTime.Now;
                if (CandidateGeneral.ContractTypeID != Guid.Empty)
                {
                    contractypeentity = actionService.GetData<Cat_ContractTypeEntity>(Common.DotNetToOracle(CandidateGeneral.ContractTypeID.ToString()),
                        ConstantSql.hrm_cat_sp_get_ContractTypeById, ref status).FirstOrDefault();
                }

                if (contractypeentity != null && contractypeentity.ValueTime != null)
                {
                    if (contractypeentity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_MONTH.ToString())
                    {
                        datecontract = datecontract.AddMonths(int.Parse(contractypeentity.ValueTime.Value.ToString()));
                    }
                    else if (contractypeentity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                    {
                        datecontract = datecontract.AddYears(int.Parse(contractypeentity.ValueTime.Value.ToString()));
                    }
                }
                profileServices.UpdateSalaryClassNameForProfile(null, CandidateGeneral.ProfileID.ToString(), datecontract, CandidateGeneral.EnteringDate.Value,
                    CandidateGeneral.OrgStructureID.Value, CandidateGeneral.RankRateID.Value, CandidateGeneral.WorkPlaceID.Value, CandidateGeneral.ContractTypeID.Value,
                    CandidateGeneral.BasicSalary.ToString(), UserLogin);
                //  profileServices.AddDataForContract(CandidateGeneral.BasicSalary.ToString(), CandidateGeneral.ProfileID.ToString(), CandidateGeneral.ContractTypeID.Value, CandidateGeneral.EnteringDate.Value, CandidateGeneral.RankRateID.Value);
                salgradeServices.AddDataForGrade(CandidateGeneral.ProfileID.ToString(), CandidateGeneral.GradePayrollID.Value, CandidateGeneral.EnteringDate.Value);
                attgradeservive.AddDataForGrade(CandidateGeneral.ProfileID.ToString(), CandidateGeneral.GradeAttendanceID.Value, CandidateGeneral.EnteringDate.Value);
            }
            return Json(message, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 11
0
        public DataTable GetReportTraineeJoinCourse(Guid[] rankIds, string[] courseIds, string orderNumber, bool IsCreateTemplate, DateTime? dateSeniory, string UserLogin)
        {

            DataTable table = CreateReportTraineeJoinCourseSchema();
            if (IsCreateTemplate)
            {
                return table;
            }
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;

                var dateCheck = DateTime.Now;
                //var dateSeniotyConfig = "31/03/N";
                // var strDateSeniorty = dateSeniotyConfig.Split('/');
                var dateCheckConfig = DateTime.Now;

                //if (dateCheckConfig.Day <= int.Parse(strDateSeniorty[0]) && dateCheckConfig.Month <= int.Parse(strDateSeniorty[1]))
                //{
                //    dateCheckConfig = new DateTime(dateCheckConfig.Year - 1, dateCheckConfig.Month, dateCheckConfig.Day);
                //}
                if (dateSeniory != null)
                {
                    dateCheckConfig = dateSeniory.Value;
                }

                var profileServices = new Hre_ProfileServices();
                var objProfile = new List<object>();
                objProfile.AddRange(new object[17]);
                objProfile[2] = orderNumber;
                objProfile[15] = 1;
                objProfile[16] = int.MaxValue - 1;
                //objProfile.Add(orderNumber);
                //objProfile.Add(null);
                //objProfile.Add(null);
                var lstProfile = profileServices.GetData<Hre_ProfileEntity>(objProfile, ConstantSql.hrm_hr_sp_get_ProfileAll, UserLogin, ref status).Where(s => s.DateQuit == null).ToList();
                //var lstProfile = profileServices.GetData<Hre_ProfileEntity>(objProfile, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, ref status).ToList();
                var lstProfileID = lstProfile.Select(s => s.ID).ToList();

                var orgsService = new Cat_OrgStructureServices();
                var objOrg = new List<object>();
                objOrg.AddRange(new object[5]);
                objOrg[3] = 1;
                objOrg[4] = int.MaxValue - 1;
                var lstallorgs = orgsService.GetData<Cat_OrgStructureEntity>(objOrg, ConstantSql.hrm_cat_sp_get_OrgStructure, UserLogin, ref status).ToList();

                var courseServices = new Tra_CourseServices();
                var objCourse = new List<object>();
                objCourse.AddRange(new object[11]);
                objCourse[9] = 1;
                objCourse[10] = int.MaxValue - 1;
                var lstCourse = courseServices.GetData<Tra_CourseEntity>(objCourse, ConstantSql.hrm_tra_sp_get_Course, UserLogin, ref status).ToList();
                if (courseIds != null)
                {
                    lstCourse = lstCourse.Where(s => courseIds.Contains(s.Code)).ToList();
                }

                var jobTitleServices = new Cat_JobTitleServices();
                var objJobtitle = new List<object>();
                objJobtitle.Add(null);
                objJobtitle.Add(null);
                objJobtitle.Add(null);
                objJobtitle.Add(1);
                objJobtitle.Add(int.MaxValue - 1);
                var lstJobtitle = jobTitleServices.GetData<Cat_JobTitleEntity>(objJobtitle, ConstantSql.hrm_cat_sp_get_JobTitle, UserLogin, ref status).ToList();

                var classServices = new Tra_ClassServices();
                var objClass = new List<object>();
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(1);
                objClass.Add(int.MaxValue - 1);
                var lstClass = classServices.GetData<Tra_ClassEntity>(objClass, ConstantSql.hrm_tra_sp_get_Class, UserLogin, ref status).ToList();

                var salaryClassServices = new Cat_SalaryClassServices();
                var objSalaryClass = new List<object>();
                objSalaryClass.Add(null);
                objSalaryClass.Add(1);
                objSalaryClass.Add(int.MaxValue - 1);
                var lstSalaryClass = salaryClassServices.GetData<Cat_SalaryClassEntity>(objSalaryClass, ConstantSql.hrm_cat_sp_get_SalaryClass, UserLogin, ref status).ToList();
                if (rankIds != null)
                {
                    lstSalaryClass = lstSalaryClass.Where(s => rankIds.Contains(s.ID)).ToList();
                }

                var rankServices = new Cat_SalaryRankServices();
                var objRank = new List<object>();
                objRank.Add(null);
                objRank.Add(null);
                objRank.Add(1);
                objRank.Add(int.MaxValue - 1);
                var lstRank = rankServices.GetData<Cat_SalaryRankEntity>(objRank, ConstantSql.hrm_cat_sp_get_SalaryRank, UserLogin, ref status).ToList();

                var traineeServices = new Tra_TraineeServices();
                var objTrainee = new List<object>();
                objTrainee.AddRange(new object[15]);
                objTrainee[13] = 1;
                objTrainee[14] = int.MaxValue - 1;
                var lstTrainee = rankServices.GetData<Tra_TraineeEntity>(objTrainee, ConstantSql.hrm_tra_sp_get_Trainee, UserLogin, ref status).ToList();

                var workingHistoryServices = new Hre_WorkHistoryServices();
                var objWorking = new List<object>();
                objWorking.AddRange(new object[17]);
                objWorking[15] = 1;
                objWorking[16] = int.MaxValue - 1;
                var lstWorking = workingHistoryServices.GetData<Hre_WorkHistoryEntity>(objWorking, ConstantSql.hrm_hr_sp_get_WorkHistory, UserLogin, ref status).ToList();


                var stopWorkingServices = new Hre_StopWorkingServices();
                var objStopWorking = new List<object>();
                objStopWorking.AddRange(new object[17]);
                objStopWorking[15] = 1;
                objStopWorking[16] = int.MaxValue - 1;
                var lstStopWorking = stopWorkingServices.GetData<Hre_StopWorkingEntity>(objStopWorking, ConstantSql.hrm_hr_sp_get_StopWorking, UserLogin, ref status).ToList();

                var traineeCertificateServices = new Tra_TraineeCertificateServices();
                var objTraineeCertificate = new List<object>();
                objTraineeCertificate.Add(1);
                objTraineeCertificate.Add(int.MaxValue - 1);
                var lstTraineeCertificate = traineeCertificateServices.GetData<Tra_TraineeCertificateEntity>(objTraineeCertificate, ConstantSql.hrm_tra_sp_get_TraineeCertificate, UserLogin, ref status).ToList();
                var lstTraineeIDFromTraineeCertificate = lstTraineeCertificate.Select(s => s.TraineeID).ToList();

                var requirmentDetailServices = new Tra_RequirementTrainDetailServices();
                var objRequirementDetail = new List<object>();
                objRequirementDetail.Add(null);
                objRequirementDetail.Add(1);
                objRequirementDetail.Add(int.MaxValue - 1);
                var lstRequirementDetail = requirmentDetailServices.GetData<Tra_RequirementTrainDetailEntity>(objRequirementDetail, ConstantSql.hrm_tra_sp_get_RequirementDetail, UserLogin, ref status).ToList();

                //if(lstTrainee != null)
                //{
                //    lstTrainee = lstTrainee.Where(s => lstProfileID.Contains(s.ProfileID)).ToList();
                //}

                if (lstTraineeCertificate != null)
                {
                    lstTrainee = lstTrainee.Where(s => !lstTraineeIDFromTraineeCertificate.Contains(s.ID)).ToList();
                }

                foreach (var item in lstCourse)
                {
                    string[] arrCourse = new string[1];
                    if (!string.IsNullOrEmpty(item.CourseListID))
                    {
                        arrCourse = item.CourseListID.Split(',').ToArray();
                    }

                    string[] arrJobtitle = new string[1];
                    int[] arrOrg = new int[1];
                    if (!string.IsNullOrEmpty(item.JobTitleListCode1))
                    {
                        arrJobtitle = item.JobTitleListCode1.Split(',').ToArray();
                    }
                    if (!string.IsNullOrEmpty(item.OrgListCode1))
                    {
                        arrOrg = item.OrgListCode1.Split(',').Select(s => int.Parse(s)).ToArray();
                    }

                    var lstJobtitleByJobtitleCode = lstJobtitle.Where(s => arrJobtitle.Contains(s.Code)).Select(s => s.ID).ToList();
                    var lstOrgByOrderNumber = lstallorgs.Where(s => arrOrg.Contains(s.OrderNumber)).Select(s => s.ID).ToList();
                    string[] _ranklistID = new string[1];
                    if (!string.IsNullOrEmpty(item.RankListID))
                    {
                        _ranklistID = item.RankListID.Split(',').ToArray();
                    }

                    // var lstClassByCourseID = lstClass.Where(s => s.CourseID == item.ID && arrCourse.Contains(s.CourseID)).ToList();
                    var salaryClassEntity = lstSalaryClass.Where(s => _ranklistID.Contains(s.Code)).ToList();
                    var lstSalaryClassID = salaryClassEntity.Select(s => s.ID).ToList();

                    var lstTraineePassedCourse = new List<Tra_TraineeEntity>();
                    // var lstTraineeForProfile = lstProfile.Where(s => s.CodeEmp == "M26423");
                    if (arrCourse[0] != null)
                    {
                        lstTraineePassedCourse = lstTrainee.Where(s => arrCourse.Contains(s.CourseCode) && s.Status == EnumDropDown.TraineeStatus.E_PASSED.ToString()).ToList();
                        int soLuongKhoaTienQUyet = arrCourse.Count();
                        var lstCheckTraineePassedCourse = lstTraineePassedCourse.GroupBy(m => m.ProfileID).Where(m => m.Count() >= soLuongKhoaTienQUyet).ToList();
                        var lstProfileIDPassedCourse = lstCheckTraineePassedCourse.Select(s => s.Key).Distinct().ToList();
                        lstProfile = lstProfile.Where(s => lstProfileIDPassedCourse.Contains(s.ID)).ToList();
                    }

                    foreach (var profileEntity in lstProfile)
                    {
                        var traineePassCourse = lstTrainee.Where(s => s.CourseID == item.ID && profileEntity.ID == s.ProfileID && s.Status == EnumDropDown.TraineeStatus.E_PASSED.ToString()).FirstOrDefault();
                        if (traineePassCourse != null)
                        {
                            continue;
                        }
                        Guid? orgId = profileEntity.OrgStructureID;
                        //    var org = lstOrg.FirstOrDefault(s => s.ID == profileEntity.OrgStructureID);
                        //   var orgOrg = LibraryService.GetNearestParentEntity(orgId, OrgUnit.E_DEPARTMENT, lstOrg, lstOrgType);
                        DataRow dr = table.NewRow();
                        bool flag = false;
                        var lstTraineeByProfileID = lstTrainee.Where(s => s.ProfileID == profileEntity.ID && arrCourse.Contains(s.CourseCode)).ToList();
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.ID] = profileEntity.ID != null ? profileEntity.ID : Guid.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.CodeEmp] = profileEntity.CodeEmp != null ? profileEntity.CodeEmp : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.TraineeName] = profileEntity.ProfileName != null ? profileEntity.ProfileName : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.IDNo] = profileEntity.IDNo != null ? profileEntity.IDNo : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.OrgStructureName] = profileEntity.OrgStructureName != null ? profileEntity.OrgStructureName : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_UNIT] = profileEntity.E_UNIT != null ? profileEntity.E_UNIT : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_DIVISION] = profileEntity.E_DIVISION != null ? profileEntity.E_DIVISION : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_DEPARTMENT] = profileEntity.E_DEPARTMENT != null ? profileEntity.E_DEPARTMENT : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_SECTION] = profileEntity.E_SECTION != null ? profileEntity.E_SECTION : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_TEAM] = profileEntity.E_TEAM != null ? profileEntity.E_TEAM : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.JobTitleName] = profileEntity.JobTitleName != null ? profileEntity.JobTitleName : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.PositionName] = profileEntity.PositionName != null ? profileEntity.PositionName : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.CourseName] = item.CourseName != null ? item.CourseName : string.Empty;

                        //var profileEntity = lstProfile.Where(s => s.ID == trainee.ProfileID && s.SalaryClassID != null).FirstOrDefault();
                        var stopWorkingEntity = lstStopWorking.Where(s => s.ProfileID.Value == profileEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                        //var workingEntity = new Hre_WorkHistoryEntity();
                        var lstWorkingByProfileID = lstWorking.Where(s => s.ProfileID == profileEntity.ID && lstSalaryClassID.Contains(s.SalaryClassID == null ? Guid.Empty : s.SalaryClassID.Value)).ToList();
                        if (lstJobtitleByJobtitleCode.Count > 0)
                        {
                            lstWorkingByProfileID = lstWorkingByProfileID.Where(s => lstJobtitleByJobtitleCode.Contains(s.JobTitleID != null ? s.JobTitleID.Value : Guid.Empty)).ToList();

                        }
                        if (lstOrgByOrderNumber.Count > 0)
                        {
                            lstWorkingByProfileID = lstWorkingByProfileID.Where(s => lstOrgByOrderNumber.Contains(s.OrganizationStructureID != null ? s.OrganizationStructureID.Value : Guid.Empty)).ToList();
                        }
                        var workingEntity = lstWorkingByProfileID.OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                        var dateSuspend = new TimeSpan();
                        var dateSeniority = new TimeSpan();
                        double dateResult = 0;
                        double monthSeniority = 0;
                        if (profileEntity.DateHire == null)
                        {
                            continue;
                        }
                        dateSeniority = dateCheckConfig.Subtract(profileEntity.DateHire.Value);

                        if (stopWorkingEntity != null && stopWorkingEntity.DateStop != null && stopWorkingEntity.DateComeBack != null)
                        {
                            dateSuspend = stopWorkingEntity.DateComeBack.Value.Subtract(stopWorkingEntity.DateStop.Value);
                            dateResult = dateSeniority.Subtract(dateSuspend).TotalDays / 30;
                            monthSeniority = Math.Floor(dateResult);
                        }

                        dateSeniority = dateCheckConfig.Subtract(profileEntity.DateHire.Value);
                        monthSeniority = Math.Floor(dateSeniority.TotalDays / 30);

                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.Seniority] = monthSeniority;


                        #region KT điều kiện seniority và maxSeniority != null
                        if (item.Seniority != null && item.MaxSeniority != null)
                        {
                            if (monthSeniority >= item.Seniority && item.MaxSeniority >= monthSeniority)
                            {

                                if (salaryClassEntity != null)
                                {
                                    if (workingEntity != null)
                                    {
                                        // if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                                        // {
                                        var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                                        var monthRank = Math.Floor(dateCheckRank);
                                        if (item.TimeOnCurrentRank != null)
                                        {
                                            if (monthRank < item.TimeOnCurrentRank)
                                            {
                                                flag = true;
                                                // table.Rows.Add(dr);
                                            }
                                        }

                                        //}

                                    }
                                }

                            }
                            else
                            {
                                flag = true;
                            }
                        }
                        #endregion

                        #region KT điều kiện seniority != null && maxSeniority == null
                        if (item.Seniority != null && item.MaxSeniority == null)
                        {
                            if (monthSeniority >= item.Seniority)
                            {
                                if (salaryClassEntity != null)
                                {
                                    if (workingEntity != null)
                                    {
                                        //  if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                                        // {
                                        var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                                        var monthRank = Math.Floor(dateCheckRank);
                                        if (item.TimeOnCurrentRank != null)
                                        {
                                            if (monthRank < item.TimeOnCurrentRank)
                                            {
                                                flag = true;
                                                //  table.Rows.Add(dr);
                                            }
                                        }
                                        // }
                                    }
                                }
                            }
                            else
                            {
                                flag = true;
                            }
                        }
                        #endregion

                        #region KT điều kiện seniority == && maxSeniority != null
                        if (item.MaxSeniority != null && item.Seniority == null)
                        {
                            if (monthSeniority <= item.MaxSeniority)
                            {
                                if (salaryClassEntity != null)
                                {
                                    if (workingEntity != null)
                                    {
                                        // if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                                        // {
                                        var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                                        var monthRank = Math.Floor(dateCheckRank);
                                        if (item.TimeOnCurrentRank != null)
                                        {
                                            if (item.TimeOnCurrentRank != null)
                                            {
                                                if (monthRank < item.TimeOnCurrentRank)
                                                {
                                                    flag = true;
                                                    // table.Rows.Add(dr);
                                                }
                                            }

                                        }

                                        //}

                                    }
                                }
                            }
                            else
                            {
                                flag = true;
                            }

                        }
                        #endregion

                        //#region kiem tra dk Seniority == null và MaxSeniority == null
                        //if (item.Seniority == null && item.MaxSeniority == null)
                        //{
                        //    if (salaryClassEntity != null)
                        //    {
                        //        if (workingEntity != null)
                        //        {
                        //           // if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                        //           // {
                        //                var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                        //                var monthRank = Math.Floor(dateCheckRank);
                        //                if (item.TimeOnCurrentRank != null)
                        //                {
                        //                    if (item.TimeOnCurrentRank != null)
                        //                    {
                        //                        if (monthRank < item.TimeOnCurrentRank)
                        //                        {
                        //                            flag = true;
                        //                          //  table.Rows.Add(dr);
                        //                        }
                        //                    }

                        //                }
                        //            //}

                        //        }
                        //    }
                        //}
                        //#endregion


                        if (lstTraineeByProfileID.Count > 0)
                        {
                            foreach (var traineeEntity in lstTraineeByProfileID)
                            {
                                // dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.Note] = traineeEntity.TeacherComment != null ? traineeEntity.TeacherComment : string.Empty;
                                double monthCourse = Math.Floor(dateCheck.Subtract(traineeEntity.EndDate.Value).TotalDays / 30);
                                var traineeInRequirementDetail = lstRequirementDetail.Where(s => s.CourseID == traineeEntity.ID && traineeEntity.ID == s.ProfileID && s.YearAnalyze != null && s.YearAnalyze.Value.Year == dateCheckConfig.Year).ToList();

                                if (traineeInRequirementDetail.Count >= 1)
                                {
                                    flag = true;
                                    continue;
                                }
                                if (traineeEntity.EndDate == null)
                                {
                                    flag = true;
                                    continue;
                                }

                                if (item.DurationMinCourse != null)
                                {
                                    if (monthCourse < item.DurationMinCourse)
                                    {
                                        flag = true;
                                        continue;
                                    }

                                }
                            }
                        }
                        else
                        {
                            var traineeInRequirementDetail = lstRequirementDetail.Where(s => s.CourseID == item.ID && profileEntity.ID == s.ProfileID && s.YearAnalyze != null && s.YearAnalyze.Value.Year == dateCheckConfig.Year).ToList();
                            if (traineeInRequirementDetail.Count >= 1)
                            {
                                flag = true;
                                continue;
                            }

                        }


                        if (flag == false)
                        {
                            if (salaryClassEntity != null)
                            {
                                if (workingEntity != null)
                                {
                                    // if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                                    // {
                                    var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                                    var monthRank = Math.Floor(dateCheckRank);
                                    if (item.TimeOnCurrentRank != null)
                                    {
                                        if (item.TimeOnCurrentRank != null)
                                        {
                                            if (monthRank >= item.TimeOnCurrentRank)
                                            {
                                                flag = true;
                                                table.Rows.Add(dr);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        table.Rows.Add(dr);
                                    }
                                    // }
                                }
                            }
                        }
                    }
                }
            }

            return table;
        }
Ejemplo n.º 12
0
        public DataTable ReportUnusualPay(DateTime monthYear, List<Guid> listProfileIDs, Guid? payrollGroupID, Boolean isIncludeQuitEmp, string codeEmp, string orderNumber, string UserLogin)
        {
            try
            {
                using (var context = new VnrHrmDataContext())
                {


                    #region " Load dữ liệu"
                    string status = string.Empty;
                    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));

                    //kỳ lương (hiện tại mặc định đầu tháng -> cuối tháng)
                    DateTime from = new DateTime(monthYear.Year, monthYear.Month, 1);
                    DateTime to = new DateTime(monthYear.Year, monthYear.Month, DateTime.DaysInMonth(monthYear.Year, monthYear.Month));

                    //Ds tất cả phòng ban
                    var orgServices = new Cat_OrgStructureServices();
                    var lstObjOrg = new List<object>();
                    //  var reposOrgStructure = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork);
                    var listOrgAll = orgServices.GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, UserLogin, ref status).ToList();

                    var lstObjOrgNumber = new List<object>();
                    lstObjOrgNumber.Add(orderNumber);
                    var lstOrgID = orgServices.GetData<Cat_OrgStructureEntity>(lstObjOrgNumber, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, UserLogin, ref status).Select(s => s.ID).ToList();


                    //Ds cửa Hàng
                    var shopServices = new Cat_ShopServices();
                    var lstObjShop = new List<object>();
                    lstObjShop.Add(null);
                    lstObjShop.Add(null);
                    lstObjShop.Add(null);
                    lstObjShop.Add(1);
                    lstObjShop.Add(int.MaxValue - 1);
                    var lstShop = shopServices.GetData<Cat_ShopEntity>(lstObjShop, ConstantSql.hrm_cat_sp_get_Shop, UserLogin, ref status).ToList();

                    //Ds tất cả loại PB
                    var orgTypeServices = new Cat_OrgStructureTypeServices();
                    var lstObjOrgType = new List<object>();
                    lstObjOrgType.Add(string.Empty);
                    lstObjOrgType.Add(string.Empty);
                    lstObjOrgType.Add(1);
                    lstObjOrgType.Add(int.MaxValue - 1);
                    //    var reposOrgStructureType = new CustomBaseRepository<Cat_OrgStructureType>(unitOfWork);
                    var listOrgType = orgTypeServices.GetData<Cat_OrgStructureType>(lstObjOrgType, ConstantSql.hrm_cat_sp_get_OrgStructureType, UserLogin, ref status).ToList();

                    //Ds nhân viên
                    var reposProfile = new CustomBaseRepository<Hre_Profile>(unitOfWork);
                    var profileServices = new Hre_ProfileServices();
                    var lstObjProfile = new List<object>();
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(string.Empty);
                    lstObjProfile.Add(1);
                    lstObjProfile.Add(int.MaxValue - 1);

                    //lọc theo phòng ban
                    //var listProfile = reposProfile.GetAll().Where(hr => hr.IsDelete == null
                    // && hr.OrgStructureID.HasValue
                    // && listOrgIDs.Contains(hr.OrgStructureID.Value)).ToList();
                    var listProfile = reposProfile.GetAll().Where(s => s.IsDelete != true).ToList();
                    if (listProfileIDs != null)
                    {
                        listProfile = listProfile.Where(s => listProfileIDs.Contains(s.ID)).ToList();
                    }


                    //lọc theo nhóm lương
                    // listProfile = listProfile.Where(hr => hr.PayrollGroupID.HasValue && listPrGroupIDs.Contains(hr.PayrollGroupID.Value)).ToList();
                    List<Guid> listProfileID = listProfile.Select(s => s.ID).Distinct().ToList();

                    //lọc nhân viên nghỉ việc
                    if (!isIncludeQuitEmp)
                    {
                        listProfile = listProfile.Where(pro => pro.DateHire <= to && (pro.DateQuit == null || pro.DateQuit.Value > from)).ToList();
                    }
                    if (payrollGroupID != null && payrollGroupID != Guid.Empty)
                    {
                        listProfile = listProfile.Where(s => s.PayrollGroupID == payrollGroupID).ToList();
                    }

                    //lọc theo tên nhân viên
                    if (!string.IsNullOrEmpty(codeEmp))
                    {
                        listProfile = listProfile.Where(s => s.CodeEmp == codeEmp).ToList();
                    }

                    //ds chế độ lương
                    var saleGradeServices = new Sal_GradeServices();
                    var lstObjSalGrade = new List<object>();
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(1);
                    lstObjSalGrade.Add(int.MaxValue - 1);

                    var reposSalGrade = new CustomBaseRepository<Sal_Grade>(unitOfWork);
                    var lstGradeAll = reposSalGrade.GetAll().Where(s => s.IsDelete != true).ToList();
                    // var lstGradeAll = saleGradeServices.GetData<Sal_Grade>(lstObjSalGrade, ConstantSql.hrm_sal_sp_get_Sal_Grade, UserLogin,ref status).ToList();
                    //ds thông tin lương

                    var salInfoServices = new Sal_SalaryInformationServices();
                    var lstObjSalInfo = new List<object>();
                    lstObjSalInfo.Add(string.Empty);
                    lstObjSalInfo.Add(string.Empty);
                    lstObjSalInfo.Add(string.Empty);
                    lstObjSalInfo.Add(string.Empty);
                    lstObjSalInfo.Add(string.Empty);
                    lstObjSalInfo.Add(string.Empty);
                    lstObjSalInfo.Add(1);
                    lstObjSalInfo.Add(int.MaxValue - 1);

                    var salInfoServices1 = new Sal_SalaryInformationServices();
                    var lstSalaryInformation = salInfoServices.GetData<Sal_SalaryInformationEntity>(lstObjSalInfo, ConstantSql.hrm_sal_sp_get_Sal_SalaryInformation, UserLogin, ref status).OrderByDescending(sal => sal.DateUpdate).ToList().Translate<Sal_SalaryInformation>();

                    //var reposSalaryInformation = new CustomBaseRepository<Sal_SalaryInformation>(unitOfWork);
                    //var lstSalaryInformation = salInfoServices.GetData<Sal_SalaryInformation>(lstObjSalInfo, ConstantSql.hrm_sal_sp_get_Sal_SalaryInformation,UserLogin,ref status).OrderByDescending(sal => sal.DateUpdate).ToList();
                    //       var lstSalaryInformation = new Sal_SalaryInformation();

                    //ds hợp đồng
                    var contractServices = new Hre_ContractServices();
                    var lstObjContract = new List<object>();
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(string.Empty);
                    lstObjContract.Add(1);
                    lstObjContract.Add(int.MaxValue - 1);
                    var reposHreContract = new CustomBaseRepository<Hre_Contract>(unitOfWork);
                    //  var lstHreContractAll = contractServices.GetData<Hre_ContractEntity>(lstObjContract, ConstantSql.hrm_hr_sp_get_Contract, UserLogin,ref status).ToList().Translate<Hre_Contract>();
                    var lstHreContractAll = reposHreContract.GetAll().Where(s => s.IsDelete != true).ToList();

                    //ds mức lươn64864866498*-*/-*/7896543564555555978g
                    var salaryRankServices = new Cat_SalaryRankServices();
                    var lstObjSalaryRank = new List<object>();
                    lstObjSalaryRank.Add(string.Empty);
                    lstObjSalaryRank.Add(null);
                    lstObjSalaryRank.Add(1);
                    lstObjSalaryRank.Add(int.MaxValue - 1);
                    var reposSalaryRank = new CustomBaseRepository<Cat_SalaryRank>(unitOfWork);
                    var lstSalaryRankAll = salaryRankServices.GetData<Cat_SalaryRankEntity>(lstObjSalaryRank, ConstantSql.hrm_cat_sp_get_SalaryRank, UserLogin, ref status).ToList().Translate<Cat_SalaryRank>();

                    var revenueProfileServices = new Sal_RevenueForProfileServices();
                    var lstObjRevenueForProfile = new List<object>();
                    lstObjRevenueForProfile.Add(null);
                    lstObjRevenueForProfile.Add(1);
                    lstObjRevenueForProfile.Add(int.MaxValue - 1);
                    var lstRevenueForProfile = revenueProfileServices.GetData<Sal_RevenueForProfileEntity>(lstObjRevenueForProfile, ConstantSql.hrm_sal_sp_get_RevenueForProfile, UserLogin, ref status).ToList();

                    //Ds phần tử lương
                    var elementServices = new Cat_ElementServices();
                    var methodPayroll = MethodPayroll.E_ADNVANCE_PAYMENT.ToString();
                    var lstObjElement = new List<object>();
                    lstObjElement.Add("");
                    lstObjElement.Add("");
                    lstObjElement.Add("");
                    lstObjElement.Add(1);
                    lstObjElement.Add(int.MaxValue - 1);
                    var reposPayrollElement = new CustomBaseRepository<Cat_Element>(unitOfWork);
                    //var reposPayrollElement = new CustomBaseRepository<Cat_ElementMultiEntity>(unitOfWork);
                    // var listPayrollElement = elementServices.GetData<Cat_ElementMultiEntity>(lstObjElement, ConstantSql.hrm_cat_sp_get_Element,UserLogin,ref status).ToList();
                    var listPayrollElement = reposPayrollElement.GetAll().Where(s => s.MethodPayroll == methodPayroll && s.IsDelete != true).ToList();


                    // ds Bảng Ứng Lương
                    var repoUnusualPay = new CustomBaseRepository<Sal_UnusualPay>(unitOfWork);
                    var lstUnusualPay = repoUnusualPay.GetAll().Where(s => s.IsDelete != true && s.MonthYear == monthYear && listProfileID.Contains(s.ProfileID)).ToList();
                    List<Guid> lstUnusualPayIDs = lstUnusualPay.Select(s => s.ID).ToList();

                    //Ds Bảng Ứng Lương Chi Tiết
                    var repoUnusualPayItem = new CustomBaseRepository<Sal_UnusualPayItem>(unitOfWork);
                    var lstUnusualPayItem = repoUnusualPayItem.GetAll().Where(s => s.IsDelete != true && lstUnusualPayIDs.Contains(s.UnusualPayID)).ToList();

                    //      //ds bảng lương
                    //      var payrollTableServices = new Sal_PayrollTableServices();
                    //      var lstObjPayrollTable = new List<object>();
                    //      lstObjPayrollTable.Add(string.Empty);
                    //      lstObjPayrollTable.Add(string.Empty);
                    //      lstObjPayrollTable.Add(1);
                    //      lstObjPayrollTable.Add(int.MaxValue -1);
                    //      var reposSalPayrollTb = new CustomBaseRepository<Sal_PayrollTable>(unitOfWork);
                    ////      var lstSalPayrollTb = payrollTableServices.GetData<Sal_PayrollTableEntity>(lstObjPayrollTable, ConstantSql.hrm_sal_sp_get_PayrollTable, UserLogin,ref status).Where(pr => pr.IsDelete == null && pr.MonthYear == monthYear && listProfileID.Contains(pr.ProfileID)).ToList();
                    //      var lstSalPayrollTb = reposSalPayrollTb.GetAll().Where(pr => pr.IsDelete == null && pr.MonthYear == monthYear && listProfileID.Contains(pr.ProfileID)).ToList();
                    //      List<Guid> listSalPayrollIDs = lstSalPayrollTb.Select(p => p.ID).ToList();
                    //      //order theo pb
                    //      lstSalPayrollTb = lstSalPayrollTb.OrderBy(m => m.Hre_Profile.Cat_OrgStructure.OrderOrg != null ? m.Hre_Profile.Cat_OrgStructure.OrderOrg.Value : 0).ToList();

                    // //ds bảng lương chi tiết
                    // var payrollTableItemServices = new Sal_PayrollTableItemServices();
                    // var lstObjPayrollTableItem = new List<object>();
                    // lstObjPayrollTableItem.Add(string.Empty);
                    // lstObjPayrollTableItem.Add(string.Empty);
                    // lstObjPayrollTableItem.Add(1);
                    // lstObjPayrollTableItem.Add(int.MaxValue -1);
                    // var reposSalPayrollTbItem = new CustomBaseRepository<Sal_PayrollTableItem>(unitOfWork);
                    //// var lstSalPayrollTbItem = payrollTableItemServices.GetData<Sal_PayrollTableItem>(lstObjPayrollTableItem, ConstantSql.hrm_sal_sp_get_PayrollTableItem, UserLogin,ref status).Where(it => it.IsDelete == null && listSalPayrollIDs.Contains(it.PayrollTableID)).ToList();
                    // var lstSalPayrollTbItem = reposSalPayrollTbItem.GetAll().Where(it => it.IsDelete == null && listSalPayrollIDs.Contains(it.PayrollTableID)).ToList();

                    //Tạo cột dữ liệu cho table
                    DataTable tblData = GetSchemaReportUnusualPay();
                    #endregion
                    #region " Không có dữ liệu Sal_PayrollTable"
                    if (lstUnusualPay == null || lstUnusualPay.Count <= 0)
                    {
                        foreach (Hre_Profile profile in listProfile)
                        {
                            DataRow dr = tblData.NewRow();
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.MonthYear] = monthYear;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CodeAttendance] = profile.CodeAttendance;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.ProfileName] = profile.ProfileName;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.LaborType] = profile.LaborType;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.EmployeeType] = profile.Cat_EmployeeType != null ? profile.Cat_EmployeeType.EmployeeTypeName : string.Empty;

                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Supervisor] = profile.Supervisor != null ? profile.Supervisor : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.HighSupervisor] = profile.HighSupervisor != null ? profile.HighSupervisor : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.WorkPlace] = profile.Cat_WorkPlace != null ? profile.Cat_WorkPlace.WorkPlaceName : string.Empty;
                            //   dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.WorkingPlace] = profile.WorkingPlace != null ? profile.WorkingPlace : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TaxCode] = profile.CodeTax != null ? profile.CodeTax : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.IDNo] = profile.IDNo != null ? profile.IDNo : string.Empty;

                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenter] = profile.Cat_CostCentre != null ? profile.Cat_CostCentre.CostCentreName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenterCode] = profile.Cat_CostCentre != null ? profile.Cat_CostCentre.Code : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PositionName] = profile.Cat_Position != null ? profile.Cat_Position.PositionName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.JobtitleName] = profile.Cat_JobTitle != null ? profile.Cat_JobTitle.JobTitleName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Email] = profile.Email != null ? profile.Email : string.Empty;
                            if (profile.DateHire != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateHire] = profile.DateHire.Value;
                            if (profile.DateQuit != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateQuit] = profile.DateQuit;
                            if (profile.DateEndProbation != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateEndProbation] = profile.DateEndProbation.Value;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SocialInsNo] = profile.SocialInsNo != null ? profile.SocialInsNo : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PayrollGroup] = profile.Cat_PayrollGroup != null ? profile.Cat_PayrollGroup.PayrollGroupName : string.Empty;

                            if (profile.OrgStructureID != null)
                            {
                                var orgName = GetParentOrg(listOrgAll, listOrgType, profile.OrgStructureID);
                                if (orgName.Count < 3)
                                {
                                    orgName.Insert(0, string.Empty);
                                    if (orgName.Count < 3)
                                    {
                                        orgName.Insert(0, string.Empty);
                                    }
                                }
                                dr[Hre_ReportHCSalesEntity.FieldNames.Channel] = orgName[2];
                                dr[Hre_ReportHCSalesEntity.FieldNames.Region] = orgName[1];
                                dr[Hre_ReportHCSalesEntity.FieldNames.Area] = orgName[0];

                                //var orgBranch = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_BRANCH, listOrgAll, listOrgType);
                                //var orgOrg = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_DEPARTMENT, listOrgAll, listOrgType);
                                //var orgTeam = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_TEAM, listOrgAll, listOrgType);
                                //var orgSection = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_SECTION, listOrgAll, listOrgType);
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            }

                            Hre_Contract hrcontract = lstHreContractAll.Where(hr => hr.ProfileID == profile.ID && hr.IsDelete == null).FirstOrDefault();
                            if (hrcontract != null && hrcontract.RankRateID != null)
                            {
                                Cat_SalaryRank salrank = lstSalaryRankAll.Where(rk => rk.ID == hrcontract.RankRateID.Value && rk.IsDelete == null).FirstOrDefault();
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SalaryRankName] = salrank != null ? salrank.SalaryRankName : string.Empty;
                            }

                            #region Insurance, Bank
                            var salaryInformationList = lstSalaryInformation.Where(sal => sal.ProfileID == profile.ID).ToList();
                            if (salaryInformationList.Count > 0)
                            {
                                Sal_SalaryInformation bankSalary = salaryInformationList[0];
                                string accountTemp = string.Empty;
                                string accountNo = string.Empty;
                                string accountNo2 = string.Empty;
                                string bankNameTemp = string.Empty;
                                string bankCode = string.Empty;

                                accountTemp = bankSalary.AccountNo == null ? string.Empty : bankSalary.AccountNo;
                                accountNo = bankSalary.AccountNo == null ? string.Empty : bankSalary.AccountNo;
                                accountNo2 = bankSalary.AccountNo2 == null ? string.Empty : bankSalary.AccountNo2;
                                bankNameTemp = bankSalary.Cat_Bank == null ? string.Empty : bankSalary.Cat_Bank.BankName;
                                bankCode = bankSalary.Cat_Bank == null ? string.Empty : bankSalary.Cat_Bank.BankCode;

                                if (!string.IsNullOrEmpty(accountTemp))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankAccountNo] = accountTemp.Trim();
                                if (!string.IsNullOrEmpty(accountNo))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.AccountNo] = accountNo.Trim();
                                if (!string.IsNullOrEmpty(accountNo2))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.AccountNo2] = accountNo2.Trim();
                                if (!string.IsNullOrEmpty(bankCode))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankCode] = bankCode.Trim();
                                if (!string.IsNullOrEmpty(bankNameTemp))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankName] = bankNameTemp.Trim();
                            }
                            #endregion

                            tblData.Rows.Add(dr);
                        }
                    }
                    #endregion
                    #region " Có dữ liệu tính lương Sal_PayrollTable"
                    else
                    {
                        foreach (Sal_UnusualPay payroll in lstUnusualPay)
                        {
                            Hre_Profile profile = listProfile.Where(s => s.ID == payroll.ProfileID).FirstOrDefault();
                            // var lstRevenueByProfileId = lstRevenueForProfile.Where(s => s.ProfileID == payroll.ProfileID).FirstOrDefault();
                            //  var lstRankByProfileId = lstShop.Where(s => s.ID == profile.ShopID).FirstOrDefault();
                            List<Sal_UnusualPayItem> listItem = lstUnusualPayItem.Where(pi => pi.UnusualPayID == payroll.ID).ToList();
                            if (profile == null)
                                continue;

                            DataRow dr = tblData.NewRow();
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.MonthYear] = monthYear;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CodeAttendance] = profile.CodeAttendance;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.ProfileName] = profile.ProfileName;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.LaborType] = profile.LaborType;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.EmployeeType] = profile.Cat_EmployeeType != null ? profile.Cat_EmployeeType.EmployeeTypeName : string.Empty;

                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Supervisor] = profile.Supervisor != null ? profile.Supervisor : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.HighSupervisor] = profile.HighSupervisor != null ? profile.HighSupervisor : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.WorkPlace] = profile.Cat_WorkPlace != null ? profile.Cat_WorkPlace.WorkPlaceName : string.Empty;
                            //  dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.WorkingPlace] = profile.WorkingPlace != null ? profile.WorkingPlace : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TaxCode] = profile.CodeTax != null ? profile.CodeTax : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.IDNo] = profile.IDNo != null ? profile.IDNo : string.Empty;

                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenter] = profile.Cat_CostCentre != null ? profile.Cat_CostCentre.CostCentreName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenterCode] = profile.Cat_CostCentre != null ? profile.Cat_CostCentre.Code : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PositionName] = profile.Cat_Position != null ? profile.Cat_Position.PositionName : string.Empty;
                            dr["PositionCode"] = profile.Cat_Position != null ? profile.Cat_Position.Code : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.JobtitleName] = profile.Cat_JobTitle != null ? profile.Cat_JobTitle.JobTitleName : string.Empty;
                            dr["JobtitleCode"] = profile.Cat_JobTitle != null ? profile.Cat_JobTitle.Code : string.Empty;
                            //      dr["Rank"] = lstRankByProfileId != null ? lstRankByProfileId.Rank : string.Empty;
                            //   dr["Target"] = lstRevenueByProfileId != null ? lstRevenueByProfileId.Target : 0;
                            //     dr["Actual"] = lstRevenueByProfileId != null ? lstRevenueByProfileId.Actual : 0;

                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Email] = profile.Email != null ? profile.Email : string.Empty;
                            if (profile.DateHire != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateHire] = profile.DateHire.Value;
                            if (profile.DateQuit != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateQuit] = profile.DateQuit;
                            if (profile.DateEndProbation != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateEndProbation] = profile.DateEndProbation.Value;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SocialInsNo] = profile.SocialInsNo != null ? profile.SocialInsNo : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PayrollGroup] = profile.Cat_PayrollGroup != null ? profile.Cat_PayrollGroup.PayrollGroupName : string.Empty;

                            if (profile.OrgStructureID != null)
                            {

                                var orgName = GetParentOrgNameForShiseido(listOrgAll, listOrgType, profile.OrgStructureID);
                                if (orgName.Count < 5)
                                {
                                    orgName.Insert(0, string.Empty);
                                    if (orgName.Count < 5)
                                    {
                                        orgName.Insert(0, string.Empty);
                                    }
                                    if (orgName.Count < 5)
                                    {
                                        orgName.Insert(0, string.Empty);
                                    }
                                    if (orgName.Count < 5)
                                    {
                                        orgName.Insert(0, string.Empty);
                                    }
                                    if (orgName.Count < 5)
                                    {
                                        orgName.Insert(0, string.Empty);
                                    }

                                }

                                dr["Công Ty"] = orgName[4];
                                dr["Chi Nhánh"] = orgName[3];
                                dr[Hre_ReportHCSalesEntity.FieldNames.Channel] = orgName[2];
                                dr[Hre_ReportHCSalesEntity.FieldNames.Region] = orgName[1];
                                dr[Hre_ReportHCSalesEntity.FieldNames.Area] = orgName[0];

                                var orgCode = GetParentOrgCodeForShiseido(listOrgAll, listOrgType, profile.OrgStructureID);
                                if (orgCode.Count < 5)
                                {
                                    orgCode.Insert(0, string.Empty);
                                    if (orgCode.Count < 5)
                                    {
                                        orgCode.Insert(0, string.Empty);
                                    }
                                    if (orgCode.Count < 5)
                                    {
                                        orgCode.Insert(0, string.Empty);
                                    }
                                    if (orgCode.Count < 5)
                                    {
                                        orgCode.Insert(0, string.Empty);
                                    }
                                    if (orgCode.Count < 5)
                                    {
                                        orgCode.Insert(0, string.Empty);
                                    }
                                }
                                dr["Mã Công Ty"] = orgCode[4];
                                dr["Mã Chi Nhánh"] = orgCode[3];
                                dr["Mã Channel"] = orgCode[2];
                                dr["Mã Region"] = orgCode[1];
                                dr["Mã Area"] = orgCode[0];

                                //var orgBranch = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_BRANCH, listOrgAll, listOrgType);
                                //var orgOrg = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_DEPARTMENT, listOrgAll, listOrgType);
                                //var orgTeam = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_TEAM, listOrgAll, listOrgType);
                                //var orgSection = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_SECTION, listOrgAll, listOrgType);
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            }

                            Hre_Contract hrcontract = lstHreContractAll.Where(hr => hr.ProfileID == profile.ID && hr.IsDelete == null).FirstOrDefault();
                            if (hrcontract != null && hrcontract.RankRateID != null)
                            {
                                Cat_SalaryRank salrank = lstSalaryRankAll.Where(rk => rk.ID == hrcontract.RankRateID.Value && rk.IsDelete == null).FirstOrDefault();
                                if (salrank != null)
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SalaryRankName] = salrank.SalaryRankName;
                            }

                            #region Insurance, Bank
                            List<Sal_SalaryInformation> salaryInformationList = lstSalaryInformation.Where(sal => sal.ProfileID == profile.ID).ToList();
                            if (salaryInformationList.Count > 0)
                            {
                                Sal_SalaryInformation bankSalary = salaryInformationList[0];
                                string accountTemp = string.Empty;
                                string accountNo = string.Empty;
                                string accountNo2 = string.Empty;
                                string bankNameTemp = string.Empty;
                                string bankCode = string.Empty;

                                accountTemp = bankSalary.AccountNo == null ? string.Empty : bankSalary.AccountNo;
                                accountNo = bankSalary.AccountNo == null ? string.Empty : bankSalary.AccountNo;
                                accountNo2 = bankSalary.AccountNo2 == null ? string.Empty : bankSalary.AccountNo2;
                                bankNameTemp = bankSalary.Cat_Bank == null ? string.Empty : bankSalary.Cat_Bank.BankName;
                                bankCode = bankSalary.Cat_Bank == null ? string.Empty : bankSalary.Cat_Bank.BankCode;

                                if (!string.IsNullOrEmpty(accountTemp))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankAccountNo] = accountTemp.Trim();
                                if (!string.IsNullOrEmpty(accountNo))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.AccountNo] = accountNo.Trim();
                                if (!string.IsNullOrEmpty(accountNo2))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.AccountNo2] = accountNo2.Trim();
                                if (!string.IsNullOrEmpty(bankCode))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankCode] = bankCode.Trim();
                                if (!string.IsNullOrEmpty(bankNameTemp))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankName] = bankNameTemp.Trim();
                            }
                            #endregion

                            #region sal grade
                            //   Sal_Grade grade = lstGradeAll.Where(gr => gr.IsDelete == null && gr.ProfileID == profile.ID
                            //                                           && gr.MonthStart < to).OrderByDescending(gr => gr.MonthStart).FirstOrDefault();
                            // if (grade != null)
                            //  {
                            // Cat_GradePayroll gradepayroll = grade.Cat_GradePayroll1;
                            // if (gradepayroll != null && gradepayroll.IsFormulaSalary == true)
                            //   {
                            try
                            {
                                var lstSalPrItem = lstUnusualPayItem.Where(sal => sal.UnusualPayID == payroll.ID).ToList();
                                //  var lstelement = listPayrollElement.Where(pr => pr.GradePayrollID == gradepayroll.ID).ToList();
                                if (listPayrollElement != null && listPayrollElement.Count > 0)
                                {
                                    foreach (Cat_Element payrollElement in listPayrollElement)
                                    {
                                        if (payrollElement != null && !String.IsNullOrEmpty(payrollElement.ElementCode))
                                        {
                                            //Add phần tử vào cột dữ liệu nếu chưa có
                                            if (!tblData.Columns.Contains(payrollElement.ElementCode))
                                            {
                                                tblData.Columns.Add(payrollElement.ElementCode, typeof(Double));
                                            }
                                            //Lấy value của phần tử 
                                            if (tblData.Columns.Contains(payrollElement.ElementCode))
                                            {
                                                Sal_UnusualPayItem item = lstSalPrItem.Where(it => it.Element == payrollElement.ElementCode).FirstOrDefault();
                                                Double value = 0;
                                                if (item != null)
                                                {
                                                    //if (item.ValueType == typeof(Double).Name)
                                                    //  {
                                                    Double.TryParse(item.Amount.ToString(), out value);
                                                    // }
                                                }
                                                dr[payrollElement.ElementCode] = value;
                                            }
                                        }
                                    }
                                }
                            }
                            catch { }
                            // }
                            // }
                            #endregion

                            tblData.Rows.Add(dr);
                        }
                    }
                    #endregion
                    return tblData.ConfigTable(true);
                }
            }
            catch (Exception ex)
            {
                return new DataTable();
            }
        }
Ejemplo n.º 13
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);
                    }


                }

            }
        }
Ejemplo n.º 14
0
        public void AddDataForContract(string BasicSalary, string ProfileIDs, Guid ContractTypeID, DateTime DateHire, Guid SalaryRankID, string userLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var repoContract = new Hre_ContractRepository(unitOfWork);
                List<Hre_ContractEntity> lstContract = new List<Hre_ContractEntity>();
                var contractServices = new Hre_ContractServices();
                List<Guid> lstProfileIDs = ProfileIDs.Split(',').Select(x => Guid.Parse(x)).ToList();
                var repoSalaryRank = new CustomBaseRepository<Cat_SalaryRank>(unitOfWork);
                var repoSalaryClass = new CustomBaseRepository<Cat_SalaryClass>(unitOfWork);
                // var salaryRank = repoSalaryRank.FindBy(s => s.IsDelete == null && s.ID == SalaryRankID).FirstOrDefault();
                //  var salaryClass = repoSalaryClass.FindBy(s => s.IsDelete == null && s.ID == salaryRank.SalaryClassID).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 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 contractType = lstContractType.Where(s => s.ID == ContractTypeID).FirstOrDefault();
                foreach (var item in lstProfileIDs)
                {
                    //model.ProfileID = profile.ID;
                    var objContract = new List<object>();
                    objContract.Add(item);
                    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;
                    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);
                    lstContract.Add(Contract);
                }

                contractServices.Add(lstContract);
                repoContract.SaveChanges();
            }
        }