public OvertimePermitEntity GetOTPermit(string userLogin)
 {
     string HRM_ATT_OT_OTPERMIT_ = AppConfig.HRM_ATT_OT_OTPERMIT_.ToString();
     string status = string.Empty;
     List<object> lstO = new List<object>();
     lstO.Add(HRM_ATT_OT_OTPERMIT_);
     lstO.Add(null);
     lstO.Add(null);
     var config = GetData<Sys_AllSetting>(lstO, ConstantSql.hrm_sys_sp_get_AllSetting, userLogin, ref status);
     OvertimePermitEntity result = new OvertimePermitEntity();
     if (config != null)
     {
         var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByDay = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV1.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByDay_Lev1 = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV2.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByDay_Lev2 = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByWeek = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV1.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByWeek_Lev1 = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV2.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByWeek_Lev2 = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByMonth = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV1.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByMonth_Lev1 = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV2.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByMonth_Lev2 = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByYear = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV1.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByYear_Lev1 = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV2.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitHour_ByYear_Lev2 = double.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitColor = objConfig.Value1;
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV1.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitColor_Lev1 = objConfig.Value1;
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV2.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.limitColor_Lev2 = objConfig.Value1;
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.IsAllowOverLimit_Normal = bool.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV1.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.IsAllowOverLimit_Normal_Lev1 = bool.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV2.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.IsAllowOverLimit_Normal_Lev2 = bool.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.IsAllowOverLimit_AllowOver = bool.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV1.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.IsAllowOverLimit_AllowOver_Lev1 = bool.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV2.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.IsAllowOverLimit_AllowOver_Lev2 = bool.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWSPLIT.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.IsAllowSplit = bool.Parse(objConfig.Value1);
         objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_ISALLOWCUT.ToString()).FirstOrDefault();
         if (objConfig != null && !string.IsNullOrEmpty(objConfig.Value1))
             result.IsAllowCut = bool.Parse(objConfig.Value1);
     }
     
     return result;
 }
Beispiel #2
0
        private void FillAllowOTValidate(List<Att_OvertimeEntity> lstOvertime, OvertimePermitEntity OtPermit)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Overtime = new CustomBaseRepository<Att_Overtime>(unitOfWork);
                var repoCat_Shift = new CustomBaseRepository<Cat_Shift>(unitOfWork);
                var repoCat_DayOff = new CustomBaseRepository<Cat_DayOff>(unitOfWork);

                if (lstOvertime.Count == 0)
                {
                    return;
                }
                if (OtPermit == null || (OtPermit.limitHour_ByDay == null
                                        && OtPermit.limitHour_ByDay_Lev1 == null
                                        && OtPermit.limitHour_ByDay_Lev2 == null
                                        && OtPermit.limitHour_ByWeek == null
                                        && OtPermit.limitHour_ByWeek_Lev1 == null
                                        && OtPermit.limitHour_ByWeek_Lev2 == null
                                        && OtPermit.limitHour_ByMonth == null
                                        && OtPermit.limitHour_ByMonth_Lev1 == null
                                        && OtPermit.limitHour_ByMonth_Lev2 == null
                                        && OtPermit.limitHour_ByYear == null
                                        && OtPermit.limitHour_ByYear_Lev1 == null
                                        && OtPermit.limitHour_ByYear_Lev2 == null)
                    )
                {
                    return;
                }
                #region getData
                DateTime DateMinInlstOvertime = lstOvertime.Min(m => m.WorkDate);
                DateTime DateMaxInlstOvertime = lstOvertime.Max(m => m.WorkDate);
                List<Guid> lstProfileID = lstOvertime.Select(m => m.ProfileID).Distinct().ToList();

                //Lấy ngày Đầu Năm, Đầu Tuần ->> Ngày nào nhỏ nhất thì lấy theo Ngày đó làm mốc
                DateTime DateMin = DateTime.MinValue;
                DateTime DateBeginYear = new DateTime(DateMinInlstOvertime.Year, 1, 1);
                DateTime DateBeginMonth = new DateTime(DateMinInlstOvertime.Year, DateMinInlstOvertime.Month, 1);
                DateTime DateBeginWeek = DateTime.MinValue;
                DateTime DateEndWeek = DateTime.MinValue;
                Common.GetStartEndWeek(DateMinInlstOvertime.Date, out DateBeginWeek, out DateEndWeek);
                DateMin = DateBeginYear < DateBeginWeek ? DateBeginYear : DateBeginWeek;
                DateTime DateMax = DateMaxInlstOvertime.AddYears(1);

                //string E_SUBMIT = OverTimeStatus.E_SUBMIT.ToString();
                //string E_SUBMIT_TEMP = OverTimeStatus.E_SUBMIT_TEMP.ToString();
                //string E_FIRST_APPROVED = OverTimeStatus.E_FIRST_APPROVED.ToString();
                //string E_WAIT_APPROVED = OverTimeStatus.E_WAIT_APPROVED.ToString();
                string E_APPROVED = OverTimeStatus.E_APPROVED.ToString();
                //string E_CONFIRM = OverTimeStatus.E_CONFIRM.ToString();
                string E_CASHOUT = MethodOption.E_CASHOUT.ToString();

                List<Guid> lstOvertimeAlreadyID = lstOvertime.Where(m => m.udAlreadyOvertimeID != null).Select(m => m.udAlreadyOvertimeID ?? Guid.Empty).Distinct().ToList();


                //var lstOvertimeInDb = repoAtt_Overtime.FindBy(m => m.IsDelete == null && m.WorkDate >= DateMin && m.WorkDate < DateMax && lstProfileID.Contains(m.ProfileID)
                //    && (m.MethodPayment == null || (m.MethodPayment != null && m.MethodPayment == E_CASHOUT))
                //&& m.Status == E_APPROVED)
                //    .Select(m => new { m.Status, m.ProfileID, m.WorkDate, m.RegisterHours, m.ApproveHours, m.ConfirmHours });
                var lstOvertimeInDb = new List<Att_Overtime>().Select(m => new { m.Status, m.ProfileID, m.WorkDate, m.RegisterHours, m.ApproveHours, m.ConfirmHours });
                if (lstProfileID.Count < 2000)
                {
                    lstOvertimeInDb = repoAtt_Overtime.FindBy(m => m.IsDelete == null && m.WorkDate >= DateMin && m.WorkDate < DateMax && lstProfileID.Contains(m.ProfileID)
                           && (m.MethodPayment == null || (m.MethodPayment != null && m.MethodPayment == E_CASHOUT))
                       && m.Status == E_APPROVED)
                       .Select(m => new { m.Status, m.ProfileID, m.WorkDate, m.RegisterHours, m.ApproveHours, m.ConfirmHours }).ToList();
                }
                else
                {
                    lstOvertimeInDb = repoAtt_Overtime.FindBy(m => m.IsDelete == null && m.WorkDate >= DateMin && m.WorkDate < DateMax
                           && (m.MethodPayment == null || (m.MethodPayment != null && m.MethodPayment == E_CASHOUT))
                       && m.Status == E_APPROVED)
                       .Select(m => new { m.Status, m.ProfileID, m.WorkDate, m.RegisterHours, m.ApproveHours, m.ConfirmHours }).ToList();
                }

                var lstShift = repoCat_Shift.GetAll().Select(m => new { m.ID, m.InTime, m.CoBreakOut, m.CoBreakIn, m.CoOut });

                string E_HOLIDAY_HLD = HolidayType.E_HOLIDAY_HLD.ToString();
                List<DateTime> lstHoliday = repoCat_DayOff.FindBy(m => m.Type == E_HOLIDAY_HLD).Select(m => m.DateOff).ToList<DateTime>();
                #endregion

                #region processing

                lstOvertime = lstOvertime.OrderBy(m => m.WorkDateRoot).ThenBy(m => m.WorkDate).ToList();
                foreach (var ProfileID in lstProfileID)
                {
                    Double RegisterPlus_Year_Validate = 0;
                    Double RegisterPlus_Month_Validate = 0;
                    Double RegisterPlus_Week_Validate = 0;

                    DateTime BeginYear = DateTime.MinValue;
                    DateTime EndYear = DateTime.MinValue;
                    DateTime BeginMonth = DateTime.MinValue;
                    DateTime EndMonth = DateTime.MinValue;
                    DateTime BeginWeek = DateTime.MinValue;
                    DateTime EndWeek = DateTime.MinValue;
                    DateTime BeginDate = DateTime.MinValue;
                    DateTime EndDate = DateTime.MinValue;

                    bool isResetYear = false;
                    bool isResetMonth = false;
                    bool isResetWeek = false;

                    List<Att_OvertimeEntity> lstOvertime_ByProfile = lstOvertime.Where(m => m.ProfileID == ProfileID).ToList();
                    var lstOvertime_ByProfile_DB = lstOvertimeInDb.Where(m => m.ProfileID == ProfileID).ToList();

                    foreach (var OT in lstOvertime_ByProfile)
                    {
                        DateTime workday = OT.WorkDateRoot ?? OT.WorkDate;
                        #region ResetPlus
                        //reset year
                        if (workday.Date > EndYear)
                        {
                            BeginYear = new DateTime(workday.Year, 1, 1);
                            EndYear = BeginYear.AddYears(1).AddMinutes(-1);
                            if (string.IsNullOrEmpty(OT.udOvertimeStatus))
                                RegisterPlus_Year_Validate = OT.RegisterHours;
                            isResetYear = true;
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(OT.udOvertimeStatus))
                                RegisterPlus_Year_Validate += OT.RegisterHours;
                            isResetYear = false;
                        }
                        //Reset Month
                        if (workday.Date > EndMonth)
                        {
                            BeginMonth = new DateTime(workday.Year, workday.Month, 1);
                            EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1);
                            if (string.IsNullOrEmpty(OT.udOvertimeStatus))
                                RegisterPlus_Month_Validate = OT.RegisterHours;
                            isResetMonth = true;
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(OT.udOvertimeStatus))
                                RegisterPlus_Month_Validate += OT.RegisterHours;
                            isResetMonth = false;
                        }
                        //Reset Week
                        if (workday.Date > EndWeek)
                        {
                            Common.GetStartEndWeek(workday.Date, out BeginWeek, out EndWeek);
                            if (string.IsNullOrEmpty(OT.udOvertimeStatus))
                                RegisterPlus_Week_Validate = OT.RegisterHours;
                            isResetWeek = true;
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(OT.udOvertimeStatus))
                                RegisterPlus_Week_Validate += OT.RegisterHours;
                            isResetWeek = false;
                        }
                        //Reset Day
                        #endregion
                        #region getDataExactHour
                        if (isResetYear)
                        {
                            RegisterPlus_Year_Validate += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginYear && m.WorkDate < EndYear && m.Status == E_APPROVED && m.ApproveHours != null).Sum(m => m.ApproveHours.Value);
                        }
                        if (isResetMonth)
                        {
                            RegisterPlus_Month_Validate += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginMonth && m.WorkDate < EndMonth && m.Status == E_APPROVED && m.ApproveHours != null).Sum(m => m.ApproveHours.Value);
                        }
                        if (isResetWeek)
                        {
                            RegisterPlus_Week_Validate += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginWeek && m.WorkDate < EndWeek && m.Status == E_APPROVED && m.ApproveHours != null).Sum(m => m.ApproveHours.Value);
                        }

                        #endregion
                        //Cập nhật lại cho OT voi nhung trang thai can thiet
                        CalOverAllowOT(OT, RegisterPlus_Week_Validate, RegisterPlus_Month_Validate, RegisterPlus_Year_Validate, OtPermit);

                    }
                }
                //unitOfWork.SaveChanges();
                #endregion
            }
        }
        public string SaveOvertimePermitConfig(OvertimePermitEntity entity, string userLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoSys_AllSetting = new CustomBaseRepository<Sys_AllSetting>(unitOfWork);
                Sys_AllSetting sys = new Sys_AllSetting();

                string HRM_ATT_OT_OTPERMIT_ = AppConfig.HRM_ATT_OT_OTPERMIT_.ToString();
                string status = string.Empty;
                List<object> lstO = new List<object>();
                lstO.Add(HRM_ATT_OT_OTPERMIT_);
                lstO.Add(null);
                lstO.Add(null);

                var config = GetData<Sys_AllSetting>(lstO, ConstantSql.hrm_sys_sp_get_AllSetting, userLogin, ref status);
                if (config != null)
                {
                    if (entity.limitHour_ByDay.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByDay.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByDay.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY.ToString();
                            objConfig.Value1 = entity.limitHour_ByDay.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByDay_Lev1.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV1.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByDay_Lev1.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByDay_Lev1.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV1.ToString();
                            objConfig.Value1 = entity.limitHour_ByDay_Lev1.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByDay_Lev2.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV2.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByDay_Lev2.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByDay_Lev2.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV2.ToString();
                            objConfig.Value1 = entity.limitHour_ByDay_Lev2.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByWeek.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByWeek.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByWeek.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK.ToString();
                            objConfig.Value1 = entity.limitHour_ByWeek.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByWeek_Lev1.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV1.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByWeek_Lev1.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByWeek_Lev1.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV1.ToString();
                            objConfig.Value1 = entity.limitHour_ByWeek_Lev1.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByWeek_Lev2.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV2.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByWeek_Lev2.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByWeek_Lev2.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV2.ToString();
                            objConfig.Value1 = entity.limitHour_ByWeek_Lev2.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByMonth.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByMonth.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByMonth.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH.ToString();
                            objConfig.Value1 = entity.limitHour_ByMonth.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByMonth_Lev1.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV1.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByMonth_Lev1.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByMonth_Lev1.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV1.ToString();
                            objConfig.Value1 = entity.limitHour_ByMonth_Lev1.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByMonth_Lev2.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV2.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByMonth_Lev2.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByMonth_Lev2.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV2.ToString();
                            objConfig.Value1 = entity.limitHour_ByMonth_Lev2.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByYear.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByYear.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByYear.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR.ToString();
                            objConfig.Value1 = entity.limitHour_ByYear.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByYear_Lev1.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV1.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByYear_Lev1.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByYear_Lev1.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV1.ToString();
                            objConfig.Value1 = entity.limitHour_ByYear_Lev1.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.limitHour_ByYear_Lev2.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV2.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitHour_ByYear_Lev2.Value.ToString())
                            {
                                objConfig.Value1 = entity.limitHour_ByYear_Lev2.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV2.ToString();
                            objConfig.Value1 = entity.limitHour_ByYear_Lev2.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (!string.IsNullOrEmpty(entity.limitColor))
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitColor)
                            {
                                objConfig.Value1 = entity.limitColor;
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR.ToString();
                            objConfig.Value1 = entity.limitColor;
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (!string.IsNullOrEmpty(entity.limitColor_Lev1))
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV1.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitColor_Lev1)
                            {
                                objConfig.Value1 = entity.limitColor_Lev1;
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV1.ToString();
                            objConfig.Value1 = entity.limitColor_Lev1;
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (!string.IsNullOrEmpty(entity.limitColor_Lev2))
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV2.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.limitColor_Lev2)
                            {
                                objConfig.Value1 = entity.limitColor_Lev2;
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV2.ToString();
                            objConfig.Value1 = entity.limitColor_Lev2;
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.IsAllowOverLimit_Normal.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.IsAllowOverLimit_Normal.Value.ToString())
                            {
                                objConfig.Value1 = entity.IsAllowOverLimit_Normal.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL.ToString();
                            objConfig.Value1 = entity.IsAllowOverLimit_Normal.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.IsAllowOverLimit_Normal_Lev1.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV1.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.IsAllowOverLimit_Normal_Lev1.Value.ToString())
                            {
                                objConfig.Value1 = entity.IsAllowOverLimit_Normal_Lev1.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV1.ToString();
                            objConfig.Value1 = entity.IsAllowOverLimit_Normal_Lev1.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.IsAllowOverLimit_Normal_Lev2.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV2.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.IsAllowOverLimit_Normal_Lev2.Value.ToString())
                            {
                                objConfig.Value1 = entity.IsAllowOverLimit_Normal_Lev2.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV2.ToString();
                            objConfig.Value1 = entity.IsAllowOverLimit_Normal_Lev2.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.IsAllowOverLimit_AllowOver.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.IsAllowOverLimit_AllowOver.Value.ToString())
                            {
                                objConfig.Value1 = entity.IsAllowOverLimit_AllowOver.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER.ToString();
                            objConfig.Value1 = entity.IsAllowOverLimit_AllowOver.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.IsAllowOverLimit_AllowOver_Lev1.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV1.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.IsAllowOverLimit_AllowOver_Lev1.Value.ToString())
                            {
                                objConfig.Value1 = entity.IsAllowOverLimit_AllowOver_Lev1.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV1.ToString();
                            objConfig.Value1 = entity.IsAllowOverLimit_AllowOver_Lev1.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.IsAllowOverLimit_AllowOver_Lev2.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV2.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.IsAllowOverLimit_AllowOver_Lev2.Value.ToString())
                            {
                                objConfig.Value1 = entity.IsAllowOverLimit_AllowOver_Lev2.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV2.ToString();
                            objConfig.Value1 = entity.IsAllowOverLimit_AllowOver_Lev2.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                    if (entity.IsAllowSplit.HasValue)
                    {
                        var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWSPLIT.ToString()).FirstOrDefault();
                        if (objConfig != null)
                        {
                            if (objConfig.Value1 != entity.IsAllowSplit.Value.ToString())
                            {
                                objConfig.Value1 = entity.IsAllowSplit.Value.ToString();
                                repoSys_AllSetting.Edit(objConfig);
                            }
                        }
                        else
                        {
                            objConfig.ID = Guid.NewGuid();
                            objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWSPLIT.ToString();
                            objConfig.Value1 = entity.IsAllowSplit.Value.ToString();
                            repoSys_AllSetting.Add(objConfig);
                        }
                    }
                }
                

                repoSys_AllSetting.SaveChanges();
                return "0";
            }
        }
Beispiel #4
0
        /// <summary>
        /// Hàm Lọc ra những OT đã bị vi phạm
        /// </summary>
        /// <param name="lstOverTimeNotAllow">Danh Sách Overtime Đã bị vượt trần dựa vào type limit thuộc Year và ở mức 1 và mức 2</param>
        /// <param name="lstAllowLimitOvertime">Danh Sách Profile Đc phép vượt trần ở mức độ nào đã được lọc theo ds Profile Của lstOvertime</param>
        /// <returns>Cho phép vượt ở DS OT vượt phép năm level 1
        /// Có thể chặn những người 
        /// </returns>
        private List<Att_OvertimeEntity> ValidateLimitOTByYear(List<Att_OvertimeEntity> lstOverTime, List<Att_AllowLimitOvertime> lstAllowLimitOvertime, OvertimePermitEntity OtPermit)
        {
            FillAllowOTValidate(lstOverTime, OtPermit);

            string E_YEAR = OverTimeOverLimitType.E_YEAR.ToString();
            string E_YEAR_LV1 = OverTimeOverLimitType.E_YEAR_LV1.ToString();
            string E_YEAR_LV2 = OverTimeOverLimitType.E_YEAR_LV2.ToString();
            List<Att_OvertimeEntity> lstOverTimeOver = lstOverTime.Where(m => m.udIsLimitHourLv2_Validate == true || m.udIsLimitHourLv1_Validate == true || m.udIsLimitHour_Validate == true).ToList();
            List<Att_OvertimeEntity> lstOverTimeLimit = new List<Att_OvertimeEntity>();

            if (OtPermit.IsAllowOverLimit_Normal != true
                && OtPermit.IsAllowOverLimit_Normal_Lev1 != true
                && OtPermit.IsAllowOverLimit_Normal_Lev2 != true
                && OtPermit.IsAllowOverLimit_AllowOver != true
                && OtPermit.IsAllowOverLimit_AllowOver_Lev1 != true
                && OtPermit.IsAllowOverLimit_AllowOver_Lev2 != true)
            {
                lstOverTimeLimit = lstOverTimeOver.ToList();
                return lstOverTimeLimit;
            }
            else
            {

                if (OtPermit.IsAllowOverLimit_Normal == true || OtPermit.IsAllowOverLimit_AllowOver == true)
                {
                    List<Att_OvertimeEntity> lstOverTimeNotAllow_Lev0 = lstOverTimeOver.Where(m => m.udIsLimitHour_Validate == true).ToList();
                    foreach (var overtime in lstOverTimeNotAllow_Lev0)
                    {
                        DateTime Workday = overtime.WorkDate;
                        Guid ProfileID = overtime.ProfileID;
                        bool PersonHaveAllowOver = lstAllowLimitOvertime.Any(m => m.ProfileID == ProfileID && m.DateStart <= Workday && m.DateEnd >= Workday);
                        //PersonHaveAllowOver = true; Nhân viên này có trong ds đc phép vượt
                        //PersonHaveAllowOver = true; Nhân viên này không có trong ds đc phép vượt
                        if (OtPermit.IsAllowOverLimit_Normal == true && !PersonHaveAllowOver)
                        {
                            lstOverTimeLimit.Add(overtime);
                        }
                        else if (OtPermit.IsAllowOverLimit_AllowOver == true && PersonHaveAllowOver)
                        {
                            lstOverTimeLimit.Add(overtime);
                        }
                    }
                }
                if (OtPermit.IsAllowOverLimit_Normal_Lev1 == true || OtPermit.IsAllowOverLimit_AllowOver_Lev1 == true)
                {
                    List<Att_OvertimeEntity> lstOverTimeNotAllow_Lev1 = lstOverTimeOver.Where(m => m.udIsLimitHourLv1_Validate == true).ToList();
                    foreach (var overtime in lstOverTimeNotAllow_Lev1)
                    {
                        DateTime Workday = overtime.WorkDate;
                        Guid ProfileID = overtime.ProfileID;
                        bool PersonHaveAllowOver = lstAllowLimitOvertime.Any(m => m.ProfileID == ProfileID && m.DateStart <= Workday && m.DateEnd >= Workday);
                        if (OtPermit.IsAllowOverLimit_Normal_Lev1 == true && !PersonHaveAllowOver)
                        {
                            lstOverTimeLimit.Add(overtime);
                        }
                        else if (OtPermit.IsAllowOverLimit_AllowOver_Lev1 == true && PersonHaveAllowOver)
                        {
                            lstOverTimeLimit.Add(overtime);
                        }
                    }
                }
                if (OtPermit.IsAllowOverLimit_Normal_Lev2 == true || OtPermit.IsAllowOverLimit_AllowOver_Lev2 == true)
                {
                    List<Att_OvertimeEntity> lstOverTimeNotAllow_Lev2 = lstOverTimeOver.Where(m => m.udIsLimitHourLv2_Validate == true).ToList();
                    foreach (var overtime in lstOverTimeNotAllow_Lev2)
                    {
                        DateTime Workday = overtime.WorkDate;
                        Guid ProfileID = overtime.ProfileID;
                        bool PersonHaveAllowOver = lstAllowLimitOvertime.Any(m => m.ProfileID == ProfileID && m.DateStart <= Workday && m.DateEnd >= Workday);
                        if (OtPermit.IsAllowOverLimit_Normal_Lev2 == true && !PersonHaveAllowOver)
                        {
                            lstOverTimeLimit.Add(overtime);
                        }
                        else if (OtPermit.IsAllowOverLimit_AllowOver_Lev2 == true && PersonHaveAllowOver)
                        {
                            lstOverTimeLimit.Add(overtime);
                        }
                    }
                }
            }
            if (lstOverTimeLimit.Count > 0)
            {
                lstOverTimeLimit = lstOverTimeLimit.Distinct().ToList();
            }
            return lstOverTimeLimit;
        }
Beispiel #5
0
 /// <summary>
 /// Hàm Phân tích OT voi những vi pham vượt trần
 /// </summary>
 /// <param name="Overtime">OT</param>
 /// <param name="dateHour">Giờ từ bắt đầu ngày đến kết thúc (đã có giơ OT hiện tại trong đó)</param>
 /// <param name="weekHour">Giờ từ bắt đầu tuần đến kết thúc  (đã có giơ OT hiện tại trong đó) </param>
 /// <param name="monthHour">Giờ từ bắt đầu tháng đến kết thúc  (đã có giơ OT hiện tại trong đó)</param>
 /// <param name="yearHour">Giờ từ bắt đầu năm đến kết thúc  (đã có giơ OT hiện tại trong đó)</param>
 /// <param name="OtPermit">Những thông số vượt trần</param>
 private void CalOverAllowOT(Att_OvertimeEntity Overtime, Double weekHour, double monthHour, double yearHour, OvertimePermitEntity OtPermit)
 {
     //Theo thu tu Uu tien tu tren xuong duoi
     string Status = OverTimeOverLimitType.E_NONE.ToString();
     #region du lieu thong thuong
     if (OtPermit.limitHour_ByYear_Lev2 != null && yearHour > OtPermit.limitHour_ByYear_Lev2.Value)
     {
         Status = OverTimeOverLimitType.E_YEAR_LV2.ToString();
         Overtime.udIsLimitHourLv2_Validate = true;
     }
     else if (OtPermit.limitHour_ByMonth_Lev2 != null && monthHour > OtPermit.limitHour_ByMonth_Lev2.Value)
     {
         Status = OverTimeOverLimitType.E_MONTH_LV2.ToString();
         Overtime.udIsLimitHourLv2_Validate = true;
     }
     else if (OtPermit.limitHour_ByWeek_Lev2 != null && weekHour > OtPermit.limitHour_ByWeek_Lev2.Value)
     {
         Status = OverTimeOverLimitType.E_WEEK_LV2.ToString();
         Overtime.udIsLimitHourLv2_Validate = true;
     }
     else if (OtPermit.limitHour_ByDay_Lev2 != null && Overtime.udHourByDate > OtPermit.limitHour_ByDay_Lev2.Value)
     {
         Status = OverTimeOverLimitType.E_DAY_LV2.ToString();
         Overtime.udIsLimitHourLv2_Validate = true;
     }
     else if (OtPermit.limitHour_ByYear_Lev1 != null && yearHour > OtPermit.limitHour_ByYear_Lev1.Value)
     {
         Status = OverTimeOverLimitType.E_YEAR_LV1.ToString();
         Overtime.udIsLimitHourLv1_Validate = true;
     }
     else if (OtPermit.limitHour_ByMonth_Lev1 != null && monthHour > OtPermit.limitHour_ByMonth_Lev1.Value)
     {
         Status = OverTimeOverLimitType.E_MONTH_LV1.ToString();
         Overtime.udIsLimitHourLv1_Validate = true;
     }
     else if (OtPermit.limitHour_ByWeek_Lev1 != null && weekHour > OtPermit.limitHour_ByWeek_Lev1.Value)
     {
         Status = OverTimeOverLimitType.E_WEEK_LV1.ToString();
         Overtime.udIsLimitHourLv1_Validate = true;
     }
     else if (OtPermit.limitHour_ByDay_Lev1 != null && Overtime.udHourByDate > OtPermit.limitHour_ByDay_Lev1.Value)
     {
         Status = OverTimeOverLimitType.E_DAY_LV1.ToString();
         Overtime.udIsLimitHourLv1_Validate = true;
     }
     else if (OtPermit.limitHour_ByYear != null && yearHour > OtPermit.limitHour_ByYear.Value)
     {
         Status = OverTimeOverLimitType.E_YEAR.ToString();
         Overtime.udIsLimitHour_Validate = true;
     }
     else if (OtPermit.limitHour_ByMonth != null && monthHour > OtPermit.limitHour_ByMonth.Value)
     {
         Status = OverTimeOverLimitType.E_MONTH.ToString();
         Overtime.udIsLimitHour_Validate = true;
     }
     else if (OtPermit.limitHour_ByWeek != null && weekHour > OtPermit.limitHour_ByWeek.Value)
     {
         Status = OverTimeOverLimitType.E_WEEK.ToString();
         Overtime.udIsLimitHour_Validate = true;
     }
     else if (OtPermit.limitHour_ByDay != null && Overtime.udHourByDate > OtPermit.limitHour_ByDay.Value)
     {
         Status = OverTimeOverLimitType.E_DAY.ToString();
         Overtime.udIsLimitHour_Validate = true;
     }
     #endregion
     Overtime.udLimitHourType_Validate = Status;
 }
Beispiel #6
0
        private void FilterOvertimeByMaxHourPerDay(List<Att_OvertimeEntity> lstOvertimeCal, OvertimePermitEntity overtimePermit, double HourMax)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCat_OvertimeType = new CustomBaseRepository<Cat_OvertimeType>(unitOfWork);

                if (lstOvertimeCal.Count == 0)
                    return;

                if (overtimePermit.IsAllowSplit == true && HourMax > 0)
                {
                    List<Guid> lstProfileID = lstOvertimeCal.Select(m => m.ProfileID).Distinct().ToList();
                    DateTime dateMin = lstOvertimeCal.Min(m => m.WorkDate).Date;
                    DateTime dateMax = lstOvertimeCal.Max(m => m.WorkDate).Date;

                    var lstOvertimeType = repoCat_OvertimeType.FindBy(s => s.IsDelete == null).Select(m => new { m.ID, m.Rate }).ToList();
                    foreach (var item in lstOvertimeCal)
                    {
                        var overtimeType = lstOvertimeType.Where(m => m.ID == item.OvertimeTypeID).FirstOrDefault();
                        if (overtimeType != null && overtimeType.Rate != null)
                        {
                            item.udRateOvertimeType = overtimeType.Rate;
                        }
                        else
                        {
                            item.udRateOvertimeType = 0;
                        }

                    }


                    foreach (var profileID in lstProfileID)
                    {
                        bool IsBeginWeek = false;
                        bool IsBeginMonth = false;
                        bool IsBeginYear = false;

                        double deltaWeek = 0;
                        double deltaMonth = 0;
                        double deltaYear = 0;
                        double deltaDay = 0;

                        for (DateTime dx = dateMin; dx <= dateMax; dx = dx.AddDays(1))
                        {
                            if (dx.DayOfWeek == DayOfWeek.Monday)
                                IsBeginWeek = true;
                            else IsBeginWeek = false;
                            if (dx.Day == 1)
                                IsBeginMonth = true;
                            else IsBeginMonth = false;
                            if (dx.Day == 1 && dx.Month == 1)
                                IsBeginYear = true;
                            else IsBeginYear = false;

                            if (IsBeginWeek)
                                deltaWeek = 0;
                            if (IsBeginMonth)
                                deltaMonth = 0;
                            if (IsBeginYear)
                                deltaYear = 0;
                            var lstOvertimeCal_ByProfile_ByDay = lstOvertimeCal.Where(m => m.WorkDate.Date == dx && m.ProfileID == profileID && m.IsNonOvertime == null).ToList();
                            //foreach (var OTModify in lstOvertimeCal_ByProfile_ByDay)
                            //{
                            //    if (!IsBeginWeek)
                            //    {
                            //        OTModify.udHourByWeek_Validate = OTModify.udHourByWeek_Validate - deltaWeek;
                            //    }
                            //    if (!IsBeginMonth)
                            //    {
                            //        OTModify.udHourByMonth_Validate = OTModify.udHourByMonth_Validate - deltaMonth;
                            //    }
                            //    if (!IsBeginYear)
                            //    {
                            //        OTModify.udHourByYear_Validate = OTModify.udHourByYear_Validate - deltaYear;
                            //    }
                            //}
                            var OtTopInday = lstOvertimeCal_ByProfile_ByDay.OrderByDescending(m => m.udHourByDate).FirstOrDefault();
                            if (OtTopInday != null && OtTopInday.udHourByDate != null && OtTopInday.udHourByDate.Value > HourMax)
                            {
                                deltaDay = OtTopInday.udHourByDate.Value - HourMax;
                                deltaWeek += deltaDay;
                                deltaMonth += deltaDay;
                                deltaYear += deltaDay;
                                var lstOvertimeByProfileOrderByRate = lstOvertimeCal_ByProfile_ByDay.OrderBy(m => m.udRateOvertimeType).ToList();

                                double deltaAgain = 0;
                                deltaAgain = deltaDay;
                                foreach (var item in lstOvertimeByProfileOrderByRate)
                                {
                                    if (deltaAgain > item.RegisterHours)
                                    {
                                        deltaAgain = deltaAgain - item.RegisterHours;
                                        item.RegisterHours = 0;
                                        item.AnalyseHour = 0;
                                    }
                                    else
                                    {
                                        item.RegisterHours = item.RegisterHours - deltaAgain;
                                        item.AnalyseHour = item.AnalyseHour - deltaAgain;
                                    }
                                    item.udHourByDate = item.udHourByDate - deltaDay;
                                    //item.udHourByWeek_Validate = item.udHourByWeek_Validate - deltaDay;
                                    //item.udHourByMonth_Validate = item.udHourByMonth_Validate - deltaDay;
                                    //item.udHourByYear_Validate = item.udHourByYear_Validate - deltaDay;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        private void FillterAllowOvertime(VnrHrmDataContext context, List<Att_OvertimeEntity> lstOvertime, OvertimePermitEntity OtPermit, List<WorkdayCustom> lstWorkday)
        {
            if (lstOvertime.Count == 0)
            {
                return;
            }
            if (OtPermit == null || (OtPermit.limitHour_ByDay == null
                                    && OtPermit.limitHour_ByDay_Lev1 == null
                                    && OtPermit.limitHour_ByDay_Lev2 == null
                                    && OtPermit.limitHour_ByWeek == null
                                    && OtPermit.limitHour_ByWeek_Lev1 == null
                                    && OtPermit.limitHour_ByWeek_Lev2 == null
                                    && OtPermit.limitHour_ByMonth == null
                                    && OtPermit.limitHour_ByMonth_Lev1 == null
                                    && OtPermit.limitHour_ByMonth_Lev2 == null
                                    && OtPermit.limitHour_ByYear == null
                                    && OtPermit.limitHour_ByYear_Lev1 == null
                                    && OtPermit.limitHour_ByYear_Lev2 == null)
                )
            {
                return;
            }
            var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
            var repoAtt_Overtime = new CustomBaseRepository<Att_Overtime>(unitOfWork);
            var repoCat_Shift = new CustomBaseRepository<Cat_Shift>(unitOfWork);
            var repoCat_DayOff = new CustomBaseRepository<Cat_DayOff>(unitOfWork);

            #region getData
            DateTime DateMinInlstOvertime = lstOvertime.Min(m => m.WorkDate);
            DateTime DateMaxInlstOvertime = lstOvertime.Max(m => m.WorkDate);
            List<Guid> lstProfileID = lstOvertime.Select(m => m.ProfileID).Distinct().ToList();

            //Lấy ngày Đầu Năm, Đầu Tuần ->> Ngày nào nhỏ nhất thì lấy theo Ngày đó làm mốc
            DateTime DateMin = DateTime.MinValue;
            DateTime DateBeginYear = new DateTime(DateMinInlstOvertime.Year, 1, 1);
            DateTime DateBeginMonth = new DateTime(DateMinInlstOvertime.Year, DateMinInlstOvertime.Month, 1);
            DateTime DateBeginWeek = DateTime.MinValue;
            DateTime DateEndWeek = DateTime.MinValue;
            Common.GetStartEndWeek(DateMinInlstOvertime.Date, out DateBeginWeek, out DateEndWeek);
            DateMin = DateBeginYear < DateBeginWeek ? DateBeginYear : DateBeginWeek;
            DateTime DateMax = DateMaxInlstOvertime.AddYears(1);

            string E_CANCEL = OverTimeStatus.E_CANCEL.ToString();
            string E_APPROVED = OverTimeStatus.E_APPROVED.ToString();
            string E_CONFIRM = OverTimeStatus.E_CONFIRM.ToString();
            string E_FIRST_APPROVED = OverTimeStatus.E_FIRST_APPROVED.ToString();
            string E_REJECTED = OverTimeStatus.E_REJECTED.ToString();
            string E_SUBMIT = OverTimeStatus.E_SUBMIT.ToString();
            string E_SUBMIT_TEMP = OverTimeStatus.E_SUBMIT_TEMP.ToString();
            string E_TEMP = OverTimeStatus.E_TEMP.ToString();
            string E_WAIT_APPROVED = OverTimeStatus.E_WAIT_APPROVED.ToString();

            string E_CASHOUT = MethodOption.E_CASHOUT.ToString();

            List<Guid> lstOvertimeAlreadyID = lstOvertime.Where(m => m.udAlreadyOvertimeID != null).Select(m => m.udAlreadyOvertimeID ?? Guid.Empty).Distinct().ToList();

            var lstOvertimeInDb = repoAtt_Overtime
                .FindBy(m => m.IsDelete == null
                    && m.WorkDate >= DateMin && m.WorkDate < DateMax && lstProfileID.Contains(m.ProfileID)
                    && (m.MethodPayment == null || (m.MethodPayment != null && m.MethodPayment == E_CASHOUT))
                    && m.IsNonOvertime == null
                    && !lstOvertimeAlreadyID.Contains(m.ID)
                    && m.Status != E_CANCEL && m.Status != E_REJECTED)
                .Select(m => new { m.Status, m.ProfileID, m.WorkDate, m.RegisterHours, m.ApproveHours, m.ConfirmHours })
                .ToList();

            var lstShift = repoCat_Shift
                .FindBy(m => m.IsDelete == null)
                .Select(m => new { m.ID, m.InTime, m.CoBreakOut, m.CoBreakIn, m.CoOut })
                .ToList();

            string E_HOLIDAY_HLD = HolidayType.E_HOLIDAY_HLD.ToString();
            List<DateTime> lstHoliday = repoCat_DayOff
                .FindBy(m => m.IsDelete == null && m.Type == E_HOLIDAY_HLD)
                .Select(m => m.DateOff)
                .ToList<DateTime>();

            #endregion

            #region processing

            lstOvertime = lstOvertime.OrderBy(m => m.WorkDateRoot).ThenBy(m => m.WorkDate).ToList();
            foreach (var ProfileID in lstProfileID)
            {
                Double RegisterPlus_Year = 0;
                Double RegisterPlus_Month = 0;
                Double RegisterPlus_Week = 0;
                Double WorkHour_Day = 0;

                DateTime BeginYear = DateTime.MinValue;
                DateTime EndYear = DateTime.MinValue;
                DateTime BeginMonth = DateTime.MinValue;
                DateTime EndMonth = DateTime.MinValue;
                DateTime BeginWeek = DateTime.MinValue;
                DateTime EndWeek = DateTime.MinValue;
                DateTime BeginDate = DateTime.MinValue;
                DateTime EndDate = DateTime.MinValue;

                bool isResetYear = false;
                bool isResetMonth = false;
                // bool isResetWeek = false;
                bool isResetDate = false;

                List<Att_OvertimeEntity> lstOvertime_ByProfile = lstOvertime.Where(m => m.ProfileID == ProfileID).ToList();
                var lstOvertime_ByProfile_DB = lstOvertimeInDb.Where(m => m.ProfileID == ProfileID).ToList();


                foreach (var OT in lstOvertime_ByProfile)
                {
                    DateTime workday = OT.WorkDateRoot ?? OT.WorkDate;
                    #region ResetPlus
                    //reset year
                    if (workday.Date > EndYear)
                    {
                        BeginYear = new DateTime(workday.Year, 1, 1);
                        EndYear = BeginYear.AddYears(1).AddMinutes(-1);
                        if (OT.IsNonOvertime != true)
                            RegisterPlus_Year = OT.RegisterHours;
                        isResetYear = true;
                    }
                    else
                    {
                        if (OT.IsNonOvertime != true)
                            RegisterPlus_Year += OT.RegisterHours;
                        isResetYear = false;
                    }
                    //Reset Month
                    if (workday.Date > EndMonth)
                    {
                        BeginMonth = new DateTime(workday.Year, workday.Month, 1);
                        EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1);
                        if (OT.IsNonOvertime != true)
                            RegisterPlus_Month = OT.RegisterHours;
                        isResetMonth = true;
                    }
                    else
                    {
                        if (OT.IsNonOvertime != true)
                            RegisterPlus_Month += OT.RegisterHours;
                        isResetMonth = false;
                    }
                    ////Reset Week
                    //if (workday.Date > EndWeek)
                    //{
                    //    Common.GetStartEndWeek(workday.Date, out BeginWeek, out EndWeek);
                    //    if (string.IsNullOrEmpty(OT.udOvertimeStatus) && OT.IsNonOvertime != true)
                    //        RegisterPlus_Week = OT.RegisterHours;
                    //    isResetWeek = true;
                    //}
                    //else
                    //{
                    //    if (string.IsNullOrEmpty(OT.udOvertimeStatus) && OT.IsNonOvertime != true)
                    //        RegisterPlus_Week += OT.RegisterHours;
                    //    isResetWeek = false;
                    //}
                    //Reset Day
                    if (workday.Date > BeginDate)
                    {
                        BeginDate = workday.Date;
                        EndDate = BeginDate.AddDays(1).AddMinutes(-1);

                        if (OT.OutTime != null && OT.InTime != null)
                        {
                            // WorkHour_Day = OT.RegisterHours;
                            WorkHour_Day = (OT.OutTime.Value - OT.InTime.Value).TotalMinutes / 60;
                            var shift = lstShift.Where(m => m.ID == OT.ShiftID).FirstOrDefault();
                            if (shift != null && OT.InTime != null && OT.OutTime != null && !lstWorkday.Any(m => m.ProfileID == ProfileID && m.WorkDate == workday && lstHoliday.Contains(m.WorkDate)))
                            {
                                DateTime BeginShift = workday.Date.AddHours(shift.InTime.Hour).AddMinutes(shift.InTime.Minute);
                                DateTime EndShift = BeginShift.AddHours(shift.CoOut);
                                DateTime BeginCoBreakIn = BeginShift.AddHours(shift.CoBreakIn);
                                DateTime EndCoBreakOut = BeginShift.AddHours(shift.CoBreakOut);
                                //Giao nữa ca đầu
                                WorkHour_Day = 0;
                                if (OT.udWorkdayNonShift == null || OT.udWorkdayNonShift == false)
                                {
                                    if (OT.InTime.Value < BeginCoBreakIn && OT.OutTime.Value > BeginShift)
                                    {
                                        DateTime Begin = OT.InTime.Value > BeginShift ? OT.InTime.Value : BeginShift;
                                        DateTime End = OT.OutTime.Value > BeginCoBreakIn ? BeginCoBreakIn : OT.OutTime.Value;
                                        WorkHour_Day += (End - Begin).TotalHours;
                                    }
                                    //Giao nữa ca sau
                                    if (OT.InTime < EndShift && OT.OutTime > EndCoBreakOut)
                                    {
                                        DateTime Begin = OT.InTime.Value > EndCoBreakOut ? OT.InTime.Value : EndCoBreakOut;
                                        DateTime End = OT.OutTime.Value > EndShift ? EndShift : OT.OutTime.Value;
                                        WorkHour_Day += (End - Begin).TotalHours;
                                    }
                                }
                                if (OT.IsNonOvertime != true)
                                    WorkHour_Day += OT.RegisterHours;
                            }
                            else
                            {
                                if (OT.IsNonOvertime != true)
                                    WorkHour_Day += OT.RegisterHours;
                            }

                        }
                        isResetDate = true;
                    }
                    else
                    {
                        if (OT.IsNonOvertime != true)
                            WorkHour_Day += OT.RegisterHours;
                        isResetDate = false;

                    }
                    #endregion
                    #region getDataExactHour
                    //1. Có 3 loại : register, Approve, Confirm
                    //2. Có 4 dạng la: Year, Month, Week, Day
                    //3. các khoảng thời gian đã được xác định phía trên.
                    //4. Cộng khoảng thời gian trên kia lại và truyền vào hàm
                    if (isResetYear)
                    {
                        RegisterPlus_Year += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginYear && m.WorkDate < EndYear && (m.Status == E_SUBMIT || m.Status == E_SUBMIT_TEMP || m.Status == E_FIRST_APPROVED || m.Status == E_WAIT_APPROVED)).Sum(m => m.RegisterHours);
                        RegisterPlus_Year += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginYear && m.WorkDate.Date <= workday && m.Status == E_APPROVED && m.ApproveHours != null).Sum(m => m.ApproveHours.Value);
                        RegisterPlus_Year += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginYear && m.WorkDate < EndYear && m.Status == E_CONFIRM).Sum(m => m.ConfirmHours);
                    }
                    if (isResetMonth)
                    {
                        RegisterPlus_Month += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginMonth && m.WorkDate < EndMonth && (m.Status == E_SUBMIT || m.Status == E_SUBMIT_TEMP || m.Status == E_FIRST_APPROVED || m.Status == E_WAIT_APPROVED)).Sum(m => m.RegisterHours);
                        RegisterPlus_Month += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginMonth && m.WorkDate.Date <= workday && m.Status == E_APPROVED && m.ApproveHours != null).Sum(m => m.ApproveHours.Value);
                        RegisterPlus_Month += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginMonth && m.WorkDate < EndMonth && m.Status == E_CONFIRM).Sum(m => m.ConfirmHours);
                    }
                    //if (isResetWeek)
                    //{
                    //    RegisterPlus_Week += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginWeek && m.WorkDate < EndWeek && (m.Status == E_SUBMIT || m.Status == E_SUBMIT_TEMP || m.Status == E_FIRST_APPROVED || m.Status == E_WAIT_APPROVED)).Sum(m => m.RegisterHours);
                    //    RegisterPlus_Week = lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginWeek && m.WorkDate.Date <= workday && m.Status == E_APPROVED && m.ApproveHours != null).Sum(m => m.ApproveHours.Value);
                    //    RegisterPlus_Week += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginWeek && m.WorkDate < EndWeek && m.Status == E_CONFIRM).Sum(m => m.ConfirmHours);
                    //}
                    if (isResetDate)
                    {
                        WorkHour_Day += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginDate && m.WorkDate < EndDate && (m.Status == E_SUBMIT || m.Status == E_SUBMIT_TEMP || m.Status == E_FIRST_APPROVED || m.Status == E_WAIT_APPROVED)).Sum(m => m.RegisterHours);
                        WorkHour_Day += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginDate && m.WorkDate.Date <= EndDate && m.Status == E_APPROVED && m.ApproveHours != null).Sum(m => m.ApproveHours.Value);
                        WorkHour_Day += lstOvertime_ByProfile_DB.Where(m => m.WorkDate > BeginDate && m.WorkDate < EndDate && m.Status == E_CONFIRM).Sum(m => m.ConfirmHours);
                    }
                    #endregion
                    //Cập nhật lại cho OT voi nhung trang thai can thiet
                    CalOverAllowOT(OT, WorkHour_Day, RegisterPlus_Week, RegisterPlus_Month, RegisterPlus_Year, OtPermit);

                }
                DateTime DateMinCal = lstOvertime_ByProfile.Min(m => m.WorkDate);
                DateTime DateMaxCal = lstOvertime_ByProfile.Max(m => m.WorkDate);
                DateMinCal = DateMinCal.Date;
                DateMaxCal = DateMaxCal.Date.AddDays(1).AddMinutes(-1);
                for (DateTime DateOfOT = DateMinCal; DateOfOT <= DateMaxCal; DateOfOT = DateOfOT.AddDays(1))
                {
                    var lstOvertime_ByProfile_ByDate = lstOvertime_ByProfile.Where(m => m.WorkDateRoot == DateOfOT).ToList();
                    if (lstOvertime_ByProfile_ByDate.Count > 0)
                    {
                        double NumMax = lstOvertime_ByProfile_ByDate.Max(m => m.udHourByDate ?? 0);
                        foreach (var item in lstOvertime_ByProfile_ByDate)
                        {
                            item.udHourByDate = NumMax;
                        }
                    }
                }
            }
            #endregion


        }
Beispiel #8
0
        //private List<Att_WorkdayEntity> filterData_NonAllowOT_inGrade(List<Att_WorkdayEntity> lstWorkday)
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork);
        //        var repoCat_GradeCfg = new CustomBaseRepository<Cat_GradeAttendance>(unitOfWork);

        //        List<Att_WorkdayEntity> lstResult = new List<Att_WorkdayEntity>();
        //        List<Guid> lstProfileID = lstWorkday.Select(m => m.ProfileID).Distinct().ToList();
        //        var lstSalGrade = repoAtt_Grade
        //            .FindBy( m => m.IsDelete == null && lstProfileID.Contains(m.ProfileID.Value))
        //            .Select(m => new { m.ID, m.ProfileID, m.MonthStart, m.GradeAttendanceID })
        //            .ToList();
        //        var lstGradeConfg = repoCat_GradeCfg
        //            .FindBy(s => s.IsDelete == null)
        //            .Select(m => new { m.ID, m.IsReceiveOvertimeBonus })
        //            .ToList();

        //        foreach (var item in lstWorkday)
        //        {
        //            Guid gradeID = lstSalGrade
        //                .Where(m => m.ProfileID == item.ProfileID && m.MonthStart <= item.WorkDate).OrderByDescending(m => m.MonthStart)
        //                .Select(m => m.GradeAttendanceID.Value)
        //                .FirstOrDefault();

        //            if (gradeID != null && gradeID != Guid.Empty)
        //            {
        //                var gradeConfig = lstGradeConfg.Where(m => m.ID == gradeID).FirstOrDefault();
        //                if (gradeConfig != null && (gradeConfig.IsReceiveOvertimeBonus == true))
        //                {
        //                    lstResult.Add(item);
        //                }
        //            }

        //        }
        //        return lstResult;
        //    }
        //}

        #region Analyze Overtime

        // Kiem tra gioi han, rang buoc OT
        public static OvertimePermitEntity getOvertimePermit(string userLogin)
        {
            BaseService _baseService = new BaseService();
            string HRM_ATT_OT_OTPERMIT_ = AppConfig.HRM_ATT_OT_OTPERMIT_.ToString();
            string status = string.Empty;
            List<object> lstO = new List<object>();
            lstO.Add(HRM_ATT_OT_OTPERMIT_);
            lstO.Add(null);
            lstO.Add(null);

            var config = _baseService.GetData<Sys_AllSettingEntity>(lstO, ConstantSql.hrm_sys_sp_get_AllSetting, userLogin, ref status);

            var configlimitHour_ByDay = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY.ToString()).FirstOrDefault();
            var configlimitHour_ByWeek = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK.ToString()).FirstOrDefault();
            var configlimitHour_ByMonth = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH.ToString()).FirstOrDefault();
            var configlimitHour_ByYear = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR.ToString()).FirstOrDefault();
            var configlimitColor = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR.ToString()).FirstOrDefault();

            var configlimitHour_ByDay_Lev1 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV1.ToString()).FirstOrDefault();
            var configlimitHour_ByWeek_Lev1 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV1.ToString()).FirstOrDefault();
            var configlimitHour_ByMonth_Lev1 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV1.ToString()).FirstOrDefault();
            var configlimitHour_ByYear_Lev1 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV1.ToString()).FirstOrDefault();
            var configlimitColor_Lev1 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV1.ToString()).FirstOrDefault();

            var configlimitHour_ByDay_Lev2 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV2.ToString()).FirstOrDefault();
            var configlimitHour_ByWeek_Lev2 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV2.ToString()).FirstOrDefault();
            var configlimitHour_ByMonth_Lev2 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV2.ToString()).FirstOrDefault();
            var configlimitHour_ByYear_Lev2 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV2.ToString()).FirstOrDefault();
            var configlimitColor_Lev2 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV2.ToString()).FirstOrDefault();

            var configIsAllowOverLimit_Normal = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL.ToString()).FirstOrDefault();
            var configIsAllowOverLimit_Normal_Lev1 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV1.ToString()).FirstOrDefault();
            var configIsAllowOverLimit_Normal_Lev2 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV2.ToString()).FirstOrDefault();
            var configIsAllowOverLimit_AllowOver = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER.ToString()).FirstOrDefault();
            var configIsAllowOverLimit_AllowOver_Lev1 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV1.ToString()).FirstOrDefault();
            var configIsAllowOverLimit_AllowOver_Lev2 = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV2.ToString()).FirstOrDefault();
            var configIsAllowSplit = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWSPLIT.ToString()).FirstOrDefault();

            OvertimePermitEntity result = new OvertimePermitEntity();

            if (config != null)
            {
                if (configlimitHour_ByDay != null)
                {
                    if (configlimitHour_ByDay.Value1 == null)
                    {
                        result.limitHour_ByDay = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByDay.Value1, out limitHour);
                        result.limitHour_ByDay = limitHour;
                    }
                }
                if (configlimitHour_ByWeek != null)
                {
                    if (configlimitHour_ByWeek.Value1 == null)
                    {
                        result.limitHour_ByWeek = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByWeek.Value1, out limitHour);
                        result.limitHour_ByWeek = limitHour;
                    }
                }
                if (configlimitHour_ByMonth != null)
                {
                    if (configlimitHour_ByMonth.Value1 == null)
                    {
                        result.limitHour_ByMonth = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByMonth.Value1, out limitHour);
                        result.limitHour_ByMonth = limitHour;
                    }
                }
                if (configlimitHour_ByYear != null)
                {
                    if (configlimitHour_ByYear.Value1 == null)
                    {
                        result.limitHour_ByYear = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByYear.Value1, out limitHour);
                        result.limitHour_ByYear = limitHour;
                    }
                }
                if (configlimitColor != null)
                {
                    result.limitColor = configlimitColor.Value1;
                }

                if (configlimitHour_ByDay_Lev1 != null)
                {
                    if (configlimitHour_ByDay_Lev1.Value1 == null)
                    {
                        result.limitHour_ByDay_Lev1 = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByDay_Lev1.Value1, out limitHour);
                        result.limitHour_ByDay_Lev1 = limitHour;
                    }
                }
                if (configlimitHour_ByWeek_Lev1 != null)
                {
                    if (configlimitHour_ByWeek_Lev1.Value1 == null)
                    {
                        result.limitHour_ByWeek_Lev1 = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByWeek_Lev1.Value1, out limitHour);
                        result.limitHour_ByWeek_Lev1 = limitHour;
                    }
                }
                if (configlimitHour_ByMonth_Lev1 != null)
                {
                    if (configlimitHour_ByMonth_Lev1.Value1 == null)
                    {
                        result.limitHour_ByMonth_Lev1 = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByMonth_Lev1.Value1, out limitHour);
                        result.limitHour_ByMonth_Lev1 = limitHour;
                    }
                }
                if (configlimitHour_ByYear_Lev1 != null)
                {
                    if (configlimitHour_ByYear_Lev1.Value1 == null)
                    {
                        result.limitHour_ByYear_Lev1 = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByYear_Lev1.Value1, out limitHour);
                        result.limitHour_ByYear_Lev1 = limitHour;
                    }
                }
                if (configlimitColor_Lev1 != null)
                {
                    result.limitColor_Lev1 = configlimitColor_Lev1.Value1;
                }

                if (configlimitHour_ByDay_Lev2 != null)
                {
                    if (configlimitHour_ByDay_Lev2.Value1 == null)
                    {
                        result.limitHour_ByDay_Lev2 = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByDay_Lev2.Value1, out limitHour);
                        result.limitHour_ByDay_Lev2 = limitHour;
                    }
                }
                if (configlimitHour_ByWeek_Lev2 != null)
                {
                    if (configlimitHour_ByWeek_Lev2.Value1 == null)
                    {
                        result.limitHour_ByWeek_Lev2 = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByWeek_Lev2.Value1, out limitHour);
                        result.limitHour_ByWeek_Lev2 = limitHour;
                    }
                }
                if (configlimitHour_ByMonth_Lev2 != null)
                {
                    if (configlimitHour_ByMonth_Lev2.Value1 == null)
                    {
                        result.limitHour_ByMonth_Lev2 = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByMonth_Lev2.Value1, out limitHour);
                        result.limitHour_ByMonth_Lev2 = limitHour;
                    }
                }
                if (configlimitHour_ByYear_Lev2 != null)
                {
                    if (configlimitHour_ByYear_Lev2.Value1 == null)
                    {
                        result.limitHour_ByYear_Lev2 = null;
                    }
                    else
                    {
                        double limitHour = 0;
                        double.TryParse(configlimitHour_ByYear_Lev2.Value1, out limitHour);
                        result.limitHour_ByYear_Lev2 = limitHour;
                    }
                }
                if (configlimitColor_Lev2 != null)
                {
                    result.limitColor_Lev2 = configlimitColor_Lev2.Value1;
                }

                if (configIsAllowOverLimit_Normal != null && configIsAllowOverLimit_Normal.Value1 == bool.TrueString)
                {
                    result.IsAllowOverLimit_Normal = true;
                }
                if (configIsAllowOverLimit_Normal_Lev1 != null && configIsAllowOverLimit_Normal_Lev1.Value1 == bool.TrueString)
                {
                    result.IsAllowOverLimit_Normal_Lev1 = true;
                }
                if (configIsAllowOverLimit_Normal_Lev2 != null && configIsAllowOverLimit_Normal_Lev2.Value1 == bool.TrueString)
                {
                    result.IsAllowOverLimit_Normal_Lev2 = true;
                }
                if (configIsAllowOverLimit_AllowOver != null && configIsAllowOverLimit_AllowOver.Value1 == bool.TrueString)
                {
                    result.IsAllowOverLimit_AllowOver = true;
                }
                if (configIsAllowOverLimit_AllowOver_Lev1 != null && configIsAllowOverLimit_AllowOver_Lev1.Value1 == bool.TrueString)
                {
                    result.IsAllowOverLimit_AllowOver_Lev1 = true;
                }
                if (configIsAllowOverLimit_AllowOver_Lev2 != null && configIsAllowOverLimit_AllowOver_Lev2.Value1 == bool.TrueString)
                {
                    result.IsAllowOverLimit_AllowOver_Lev2 = true;
                }
                if (configIsAllowSplit != null && configIsAllowSplit.Value1 == bool.TrueString)
                {
                    result.IsAllowSplit = true;
                }

            }
            return result;

        }