/// <summary> /// Button Tính Phép Bệnh /// </summary> /// <param name="Year"></param> /// <param name="orgStructure"></param> /// <param name="LstProfileStatus"></param> /// <returns></returns> public bool ComputeAnnualSickLeaveDetail(int Year, string orgStructure, string LstProfileStatus, string UserLogin) { var result = false; using (var context = new VnrHrmDataContext()) { string status = string.Empty; var unitOfWork = (IUnitOfWork)new UnitOfWork(context); var repoAtt_AnnualLeaveDetail = new CustomBaseRepository<Att_AnnualLeaveDetail>(unitOfWork); var repoHre_Profile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var repoHre_HDTJob = new CustomBaseRepository<Hre_HDTJob>(unitOfWork); var repoCat_DayOff = new CustomBaseRepository<Cat_DayOff>(unitOfWork); var repoCat_LeaveDayType = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork); var repoAtt_LeaveDay = new CustomBaseRepository<Att_LeaveDay>(unitOfWork); var repoCat_JobTitle = new CustomBaseRepository<Cat_JobTitle>(unitOfWork); #region FilterInfo string E_SICK_LEAVE = AnnualLeaveDetailType.E_SICK_LEAVE.ToString(); Att_AnnualLeaveDetail AnnualLeaveDetailTop = repoAtt_AnnualLeaveDetail .FindBy(m => m.IsDelete == null && m.Type == E_SICK_LEAVE && m.Year == Year).FirstOrDefault(); DateTime beginyear = (AnnualLeaveDetailTop == null || AnnualLeaveDetailTop.MonthStart == null) ? new DateTime(Year, 1, 1) : AnnualLeaveDetailTop.MonthStart.Value; DateTime endYear = beginyear.AddYears(1).AddMinutes(-1); List<object> lstObj = new List<object>(); lstObj.Add(orgStructure); lstObj.Add(null); lstObj.Add(null); var lstProfileQuery = GetData<Hre_ProfileEntity>(lstObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList(); if (LstProfileStatus != null) { if (LstProfileStatus == StatusEmpLeaveDetail.E_NEWEMPINYEAR.ToString()) { lstProfileQuery = lstProfileQuery.Where(m => m.DateHire != null && m.DateHire >= beginyear && m.DateHire <= endYear).ToList(); } if (LstProfileStatus == StatusEmpLeaveDetail.E_RESIGNEMPINYEAR.ToString()) { lstProfileQuery = lstProfileQuery.Where(m => m.DateQuit != null && m.DateQuit >= beginyear && m.DateQuit <= endYear).ToList(); } if (LstProfileStatus == StatusEmpLeaveDetail.E_EMPOFHDT4.ToString()) { string Job4 = HDTJobType.E_Four.ToString(); List<Guid> lstprofileHDT4 = repoHre_HDTJob .FindBy(m => m.IsDelete == null && m.Type == Job4 && m.DateFrom <= endYear && m.DateTo >= beginyear && m.ProfileID != null) .Select(m => m.ProfileID.Value).ToList<Guid>(); lstProfileQuery = lstProfileQuery.Where(m => lstprofileHDT4.Contains(m.ID)).ToList(); } if (LstProfileStatus == StatusEmpLeaveDetail.E_EMPOFHDT5.ToString()) { string Job5 = HDTJobType.E_Five.ToString(); List<Guid> lstprofileHDT5 = repoHre_HDTJob .FindBy(m => m.IsDelete == null && m.Type == Job5 && m.DateFrom <= endYear && m.DateTo >= beginyear && m.ProfileID != null) .Select(m => m.ProfileID.Value).ToList<Guid>(); lstProfileQuery = lstProfileQuery.Where(m => lstprofileHDT5.Contains(m.ID)).ToList(); } } List<Guid> lstProfileID = lstProfileQuery.Select(m => m.ID).Distinct().ToList<Guid>(); #endregion #region get Data //string E_STANDARD_WORKDAY = AppConfig.E_STANDARD_WORKDAY.ToString(); //Sys_AppConfig appconfig = EntityService.CreateQueryable<Sys_AppConfig>(false, GuidContext, Guid.Empty, m => m.Info == E_STANDARD_WORKDAY).FirstOrDefault(); //if (appconfig == null || string.IsNullOrEmpty(appconfig.Value76) || string.IsNullOrEmpty(appconfig.Value77)) //{ // Common.MessageBoxs(Messages.Msg, Messages.PleaseConfigSickLeaveAtTotalConfig, MessageBox.Icon.WARNING, string.Empty); // return; //} string HRM_ATT_ANNUALSICKLEAVE_ = AppConfig.HRM_ATT_ANNUALSICKLEAVE_.ToString(); List<object> lstO = new List<object>(); lstO.Add(HRM_ATT_ANNUALSICKLEAVE_); lstO.Add(null); lstO.Add(null); var config = GetData<Sys_AllSettingEntity>(lstO, ConstantSql.hrm_sys_sp_get_AllSetting, UserLogin, ref status); var formular1 = config.Where(s => s.Name == AppConfig.HRM_ATT_ANNUALSICKLEAVE_FORMULARCONFIG.ToString()).FirstOrDefault(); var formular2 = config.Where(s => s.Name == AppConfig.HRM_ATT_ANNUALSICKLEAVE_FORMULARCOMPUTE.ToString()).FirstOrDefault(); if (config == null || string.IsNullOrEmpty(formular1.Value1) || string.IsNullOrEmpty(formular2.Value1)) { //Common.MessageBoxs(Messages.Msg, Messages.PleaseConfigAnnualLeaveAtTotalConfig, MessageBox.Icon.WARNING, string.Empty); return result; } string formularConfig = formular1.Value1; string formularCompute = formular2.Value1; ParamGetConfigANL configAnl = new ParamGetConfigANL(); (new Att_AttendanceServices()).GetConfigANL(formularConfig, out configAnl); int MonthBegin = 1; List<string> lstCodeLeaveTypeNonAnl = new List<string>(); if (configAnl != null && configAnl.monthBeginYear != null) { MonthBegin = configAnl.monthBeginYear; } if (configAnl != null && configAnl.lstCodeLeaveNonANL != null) { lstCodeLeaveTypeNonAnl = configAnl.lstCodeLeaveNonANL; } DateTime BeginYear = new DateTime(Year, MonthBegin, 1); DateTime EndYear = BeginYear.AddYears(1).AddMinutes(-1); string E_APPROVED = LeaveDayStatus.E_APPROVED.ToString(); List<DateTime> lstDayOff = repoCat_DayOff .FindBy(m => m.IsDelete == null && m.DateOff > BeginYear && m.DateOff <= EndYear) .Select(m => m.DateOff).Distinct().ToList<DateTime>(); List<Hre_ProfileEntity> lstprofile = lstProfileQuery .Where(m => m.DateQuit == null || (m.DateQuit != null && m.DateQuit > BeginYear)) .ToList<Hre_ProfileEntity>(); List<Guid> lstLeavedayTypeNonAnl = repoCat_LeaveDayType .FindBy(m => m.IsDelete == null && lstCodeLeaveTypeNonAnl.Contains(m.Code)).Select(m => m.ID).ToList<Guid>(); List<Att_LeaveDay> lstleavedayNonANl = repoAtt_LeaveDay .FindBy(m => m.IsDelete == null && m.Status == E_APPROVED && lstLeavedayTypeNonAnl.Contains(m.LeaveDayTypeID) && lstProfileID.Contains(m.ProfileID)).ToList<Att_LeaveDay>(); List<Att_LeaveDay> lstleavedayNonANlInYear = lstleavedayNonANl.Where(m => m.DateStart <= EndYear && m.DateEnd >= BeginYear).ToList<Att_LeaveDay>(); List<Hre_HDTJob> lstHDTJob = repoHre_HDTJob .FindBy(m => m.IsDelete == null && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)).ToList<Hre_HDTJob>(); List<Cat_JobTitle> lstJobtitle = repoCat_JobTitle.FindBy(s => s.IsDelete == null).ToList(); #endregion List<Att_AnnualLeaveDetail> lstAnnualDetail = new List<Att_AnnualLeaveDetail>(); foreach (var item in lstprofile) { List<Att_LeaveDay> lstLeavedayNonAnlByProfile = lstleavedayNonANl.Where(m => m.ProfileID == item.ID).ToList(); List<Att_LeaveDay> lstLeavedayNonAnlByProfileInYear = lstleavedayNonANlInYear.Where(m => m.ProfileID == item.ID).ToList(); List<Hre_HDTJob> lstHDTJobByProfile = lstHDTJob.Where(m => m.ProfileID == item.ID).ToList(); double AvailabelInYear = (new Att_AttendanceServices()).GetAnnualLeaveAvailableAllYear(Year, null, item.DateHire, item.DateEndProbation, item.DateQuit, formularConfig, formularCompute, lstLeavedayNonAnlByProfileInYear, lstJobtitle, lstDayOff, lstHDTJobByProfile, lstLeavedayNonAnlByProfile); Att_AnnualLeaveDetail annualProfile = new Att_AnnualLeaveDetail(); annualProfile.ID = Guid.NewGuid(); annualProfile.ProfileID = item.ID; annualProfile.MonthStart = BeginYear; annualProfile.MonthEnd = EndYear; annualProfile.Year = Year; annualProfile.Type = E_SICK_LEAVE; annualProfile.Month1 = AvailabelInYear; annualProfile.Month2 = AvailabelInYear; annualProfile.Month3 = AvailabelInYear; annualProfile.Month4 = AvailabelInYear; annualProfile.Month5 = AvailabelInYear; annualProfile.Month6 = AvailabelInYear; annualProfile.Month7 = AvailabelInYear; annualProfile.Month8 = AvailabelInYear; annualProfile.Month9 = AvailabelInYear; annualProfile.Month10 = AvailabelInYear; annualProfile.Month11 = AvailabelInYear; annualProfile.Month12 = AvailabelInYear; lstAnnualDetail.Add(annualProfile); } DataErrorCode DataErr = DataErrorCode.Unknown; if (lstAnnualDetail.Count > 0) { #region lấy dữ liệu dưới DB xóa đi List<Guid> lstProfileID_InDB = lstAnnualDetail.Where(m => m.ProfileID != null).Select(m => m.ProfileID.Value).ToList(); List<Att_AnnualLeaveDetail> lstAnnualLeaveDetail_InDB = repoAtt_AnnualLeaveDetail .FindBy(m => m.IsDelete == null && m.Year == Year && m.Type == E_SICK_LEAVE && m.ProfileID != null && lstProfileID_InDB.Contains(m.ProfileID.Value)).ToList<Att_AnnualLeaveDetail>(); foreach (var item in lstAnnualLeaveDetail_InDB) { item.IsDelete = true; } #endregion repoAtt_AnnualLeaveDetail.Add(lstAnnualDetail); try { repoAtt_AnnualLeaveDetail.SaveChanges(); } catch (Exception) { return false; } //EntityService.AddEntity<Att_AnnualLeaveDetail>(GuidContext, lstAnnualDetail.ToArray()); //DataErr = EntityService.SubmitChanges(GuidContext, LoginUserID); //if (DataErr == DataErrorCode.Success) //{ // Common.MessageBoxs(Messages.Msg, Messages.SaveSuccess, MessageBox.Icon.INFO, string.Empty); //} //else //{ // Common.MessageBoxs(Messages.Msg, Messages.SaveUnSuccess, MessageBox.Icon.INFO, string.Empty); //} } //else //{ // Common.MessageBoxs(Messages.Msg, Messages.NoDataToCompute, MessageBox.Icon.WARNING, string.Empty); //} result = true; } return result; }
public static void GetConfigANL(List<Sys_AllSetting> lstAllSeting, out ParamGetConfigANL paramConfig) { #region set default value paramConfig = new ParamGetConfigANL(); paramConfig.monthBeginYear = 1; paramConfig.dayBeginFullMonth = 1; paramConfig.seniorMonth = 12 * 5; paramConfig.dayPerMonth = 30; paramConfig.anlRoundUp = 0.5; paramConfig.typeProfileBegin = AnlProfileTypeBegin.E_DATE_HIRE.ToString(); paramConfig.maxInMonthToGetAct = 15; //Trươc ngày 15 thì tính cho tháng đó paramConfig.anlFullYear = (double)12 / (double)12; paramConfig.anlSeniorMoreThanNormal = (double)1 / (double)12; paramConfig.anlHDT4MoreThanNormal = (double)2 / (double)12; paramConfig.anlHDT5MoreThanNormal = (double)4 / (double)12; paramConfig.lstCodeLeaveNonANL = new List<string>(); paramConfig.monthInYearSenior = 0; paramConfig.monthRoundUp = 0; #endregion #region set value by Config // //AppConfig. - //AppConfig. - //AppConfig. - //AppConfig. - //AppConfig. - //AppConfig. - //AppConfig. - //AppConfig. - //AppConfig. - //AppConfig. - //AppConfig. - //AppConfig. if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_MONTHBEGINYEAR.ToString())) { int value = 0; int.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_MONTHBEGINYEAR.ToString()).FirstOrDefault().Value1, out value); value = value == 0 ? 1 : value; paramConfig.monthBeginYear = value; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_DAYBEGIN_FULLMONTH.ToString())) { int value = 0; int.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_DAYBEGIN_FULLMONTH.ToString()).FirstOrDefault().Value1, out value); value = value == 0 ? 1 : value; paramConfig.dayBeginFullMonth = value; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_SENIOR_MONTH.ToString())) { int value = 0; int.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_SENIOR_MONTH.ToString()).FirstOrDefault().Value1, out value); paramConfig.seniorMonth = value; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_DAY_PER_MONTH.ToString())) { int value = 0; int.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_DAY_PER_MONTH.ToString()).FirstOrDefault().Value1, out value); paramConfig.dayPerMonth = value; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_ROUND_UP.ToString())) { double value = 0; double.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_ROUND_UP.ToString()).FirstOrDefault().Value1, out value); paramConfig.anlRoundUp = value; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_TYPE_PROFILE_BEGIN.ToString())) { paramConfig.typeProfileBegin = lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_TYPE_PROFILE_BEGIN.ToString()).FirstOrDefault().Value1; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_DAY_MAX_IN_MONTH_GET_ACTUAL.ToString())) { int value = 0; int.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_DAY_MAX_IN_MONTH_GET_ACTUAL.ToString()).FirstOrDefault().Value1, out value); paramConfig.maxInMonthToGetAct = value; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_NORMAL_CAN_GET_FULLYEAR.ToString())) { double value = 0; double.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_NORMAL_CAN_GET_FULLYEAR.ToString()).FirstOrDefault().Value1, out value); paramConfig.anlFullYear = (double)value / (double)12; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_SENIOR_CAN_GET_EACH_LEVEL.ToString())) { double value = 0; double.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_SENIOR_CAN_GET_EACH_LEVEL.ToString()).FirstOrDefault().Value1, out value); paramConfig.anlSeniorMoreThanNormal = (double)value / (double)12; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_HDT4_CAN_GET_MORE_NORMAL.ToString())) { double value = 0; double.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_HDT4_CAN_GET_MORE_NORMAL.ToString()).FirstOrDefault().Value1, out value); paramConfig.anlHDT4MoreThanNormal = (double)value / (double)12; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_HDT5_CAN_GET_MORE_NORMAL.ToString())) { double value = 0; double.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_HDT5_CAN_GET_MORE_NORMAL.ToString()).FirstOrDefault().Value1, out value); paramConfig.anlHDT5MoreThanNormal = (double)value / (double)12; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_LEAVE_NON_ALN_CODES.ToString())) { string CodeLeaveNonANL = lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_LEAVE_NON_ALN_CODES.ToString()).FirstOrDefault().Value1; char[] ext = new char[] { ',' }; if (!string.IsNullOrEmpty(CodeLeaveNonANL)) { paramConfig.lstCodeLeaveNonANL = CodeLeaveNonANL.Split(ext, StringSplitOptions.RemoveEmptyEntries).ToList(); } } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_MONTH_INYEAR_TO_COMPUTE_SENIOR.ToString())) { int value = 0; int.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_MONTH_INYEAR_TO_COMPUTE_SENIOR.ToString()).FirstOrDefault().Value1, out value); paramConfig.monthInYearSenior = value; } if (lstAllSeting.Any(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_ROUND_UP.ToString())) { int value = 0; int.TryParse(lstAllSeting.Where(m => m.Name == AppConfig.HRM_ATT_CONFIG_ANL_ROUND_UP.ToString()).FirstOrDefault().Value1, out value); paramConfig.monthRoundUp = value; } #endregion }
/// <summary> /// Tính số ngày phép năm tích lũy được đến thời điểm currentMonth. /// </summary> /// <param name="currentMonth">Tháng đang xét</param> /// <param name="gradeCfg"></param> /// <param name="dateHire">Ngày vào làm của nhân viên.</param> /// <param name="dateEndProbation">Ngày kết thúc thử việc</param> /// <param name="dateQuit">Ngày nghỉ làm của nhân viên</param> /// <param name="monthStartAnnualLeave">Tháng bắt đầu tính phép năm.</param> /// <param name="initAnnualValue">Phép năm có sẵn từ trước</param> /// <param name="lstLeaveDay">DS nghỉ phép theo loại trong cấu hình từ đầu năm tới giờ</param> /// <returns></returns> public static Double GetAnnualLeaveReceive(int Year, DateTime currentMonth, Cat_GradeAttendance gradeCfg, DateTime? dateHire, DateTime? dateEndProbation, DateTime? dateQuit, int? monthStartAnnualLeave, double? initAnnualValue, Cat_Position pos, Hre_ProfileMultiField profile , List<Att_LeaveDayInfo> lstLeaveDay, List<Sys_AllSetting> lstAllSetting, List<Hre_HDTJob> lstHDTJob_ByProfile, List<DateTime> lstDayOff, List<Att_LeaveDayInfo> lstLeaveDayAllYear,string userLogin) { double result = 0; int Month = currentMonth.Month; Cat_JobTitle CatJobTitle = new Cat_JobTitle(); if (profile.JobTitleID != null && profile.JobTitleID != Guid.Empty) { CatJobTitle = lstCatJobTitle.Where(s => s.ID == profile.JobTitleID).FirstOrDefault(); } if (gradeCfg == null) { return result; } if (string.IsNullOrWhiteSpace(gradeCfg.FormulaAnnualLeave)) { throw new Exception("Formula Annual Leave not found."); } //Lấy khoảng thời gian của kỳ lương DateTime dtStart, dtEnd; Att_AttendanceServices.GetSalaryDateRange(gradeCfg, null, null, currentMonth, out dtStart, out dtEnd); double totalDayAnnualLeaveOnYear = gradeCfg.TotalDayAnnualLeaveOnYear.Get_Integer(); double seniority = GetAnnualBySeniority(currentMonth, dateHire, gradeCfg); string formulaAnnualLeave = gradeCfg.FormulaAnnualLeave; Formula formula = new Formula(formulaAnnualLeave); //đâsdasd #region abc #region Param lstHDTJob_ByProfile = lstHDTJob_ByProfile.Where(m => m.DateFrom != null && m.Type != null).OrderBy(m => m.DateFrom).ToList(); ParamGetConfigANL paramConfig = new ParamGetConfigANL(); //set du lieu GetConfigANL(lstAllSetting, out paramConfig); int monthBeginYear = paramConfig.monthBeginYear; //Tháng bắt đầu tính phép năm int dayBeginFullMonth = paramConfig.dayBeginFullMonth; //Ngày bắt đầu tính tròn ANL cho tháng int seniorMonth = paramConfig.seniorMonth; // Số tháng để có 1 level cho thâm niên int dayPerMonth = paramConfig.dayPerMonth; // Số ngày cho 1 tháng double anlRoundUp = paramConfig.anlRoundUp; //Số làm tròn Lên xuống string typeProfileBegin = paramConfig.typeProfileBegin; //Loại lấy theo DateHire hay DateQuit int maxInMonthToGetAct = paramConfig.maxInMonthToGetAct; //Ngày chuẩn để xét là DT4 và DT5 đc tính cho tháng àno double anlFullYear = paramConfig.anlFullYear; // Số ngày phép bình thường cho 1 năm (tính theo tháng) double anlSeniorMoreThanNormal = paramConfig.anlSeniorMoreThanNormal; // Số ngày phép Được cộng thêm do thâm niên so với bình thường (tính theo tháng) double anlHDT4MoreThanNormal = paramConfig.anlHDT4MoreThanNormal; // Số ngày phép được cộng thêm do HDT4 so với bình thường (tính theo tháng) double anlHDT5MoreThanNormal = paramConfig.anlHDT5MoreThanNormal; // Số ngày phép được cộng thêm do HDT5 so với bình thường (tính theo tháng) List<string> lstCodeLeaveNonANL = paramConfig.lstCodeLeaveNonANL; int monthInYearSenior = paramConfig.monthInYearSenior; int monthRoundUp = paramConfig.monthRoundUp; #endregion #region Data //gan du lieu can thiet DateTime BeginYear = new DateTime(Year, monthBeginYear, 1); DateTime EndYear = BeginYear.AddYears(1).AddMinutes(-1); DateTime? DateCheckByMonth = null; if (Month != null) { DateCheckByMonth = new DateTime(Year, Month, 1); if (Month < monthBeginYear) { DateCheckByMonth = new DateTime(Year + 1, Month, 1); } } DateTime? DateStartProfile = null; DateTime DateEndProfile = EndYear; if (typeProfileBegin == AnlProfileTypeBegin.E_DATE_ENDPROBATION.ToString()) { DateStartProfile = dateEndProbation; } else { DateStartProfile = dateHire; } if (DateStartProfile == null) return 0; if (dateQuit != null && dateQuit < EndYear) { DateEndProfile = dateQuit.Value.Date.AddDays(1).AddMinutes(-1); } if (DateStartProfile.Value.Day > dayBeginFullMonth) { DateTime beginMonthOfDateTime = new DateTime(DateStartProfile.Value.Year, DateStartProfile.Value.Month, dayBeginFullMonth); bool IsAdd1Month = false; for (DateTime dateCheck = beginMonthOfDateTime; dateCheck < DateStartProfile.Value.Date; dateCheck = dateCheck.AddDays(1)) { if (!lstDayOff.Any(m => m == dateCheck)) { IsAdd1Month = true; break; } } if (IsAdd1Month) { DateStartProfile = new DateTime(DateStartProfile.Value.AddMonths(1).Year, DateStartProfile.Value.AddMonths(1).Month, 1); } else { DateStartProfile = new DateTime(DateStartProfile.Value.Year, DateStartProfile.Value.Month, dayBeginFullMonth); } } DateTime DateStartInYear = BeginYear > DateStartProfile.Value ? BeginYear : DateStartProfile.Value; DateTime DateEndInYear = EndYear < DateEndProfile ? EndYear : DateEndProfile; List<HDTJobTypeRange> lstHDTJobContaint = new List<HDTJobTypeRange>(); foreach (var item in lstHDTJob_ByProfile) { HDTJobTypeRange hdtJob = new HDTJobTypeRange(); hdtJob.Type = item.Type; hdtJob.DateStart = item.DateFrom.Value; hdtJob.DateEnd = item.DateTo; lstHDTJobContaint.Add(hdtJob); } lstHDTJobContaint = lstHDTJobContaint.OrderByDescending(m => m.DateStart).ToList(); DateTime DateBeFore = DateTime.MaxValue; foreach (var item in lstHDTJobContaint) { if (item.DateEnd == null) { item.DateEnd = DateBeFore; } DateBeFore = item.DateStart; } #endregion //ANL_WORK_HDT4, //ANL_WORK_HDT5, if (DateCheckByMonth == null) { #region ANL and Leave if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ANL_NORMAL.ToString())) { double value = 0; double monthWorkingNormalInYear = 0; for (int i = 0; i < 12; i++) { if (DateStartInYear.AddMonths(i) < DateEndInYear) { monthWorkingNormalInYear++; } else { break; } } value = anlFullYear * monthWorkingNormalInYear; formula.Parameters.Add(Formula.FormulaConstant.ANL_NORMAL.ToString(), value); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ANL_SENIOR.ToString())) { double value = 0; int MonBegin = monthInYearSenior == 0 ? 1 : monthInYearSenior; //--DateStartProfile DateTime Monthyear = new DateTime(Year, MonBegin, 1); double dateLeave = lstLeaveDayAllYear.Where(m => m.TotalDuration != null).Sum(m => m.TotalDuration.Value); dateLeave += (lstLeaveDayAllYear.Where(m => m.TotalDuration == null).Sum(m => m.Duration) / 8); DateTime dateRoundProfileStart = DateStartProfile.Value.AddMonths(-monthRoundUp); double Days = (Monthyear - dateRoundProfileStart).TotalDays - dateLeave; double YearSenior = Math.Round(Days / 365, MidpointRounding.AwayFromZero); int level = (int)(YearSenior / (seniorMonth / 12)); value = level * anlSeniorMoreThanNormal * 12; formula.Parameters.Add(Formula.FormulaConstant.ANL_SENIOR.ToString(), value); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ANL_LEAVE_NON_HAVEANL.ToString())) { double value = 0; //Logic: Vướng cai đầu năm cuối năm nên phải cắt cái ngày đó ra cho chính xác double numLeave = 0; foreach (var item in lstLeaveDay) { if (item.DateStart < DateStartInYear && item.DateEnd > DateStartInYear) { DateTime FirstSunday = DateTime.MinValue; for (DateTime DateCheck = DateStartInYear; DateCheck < item.DateEnd; DateCheck = DateCheck.AddDays(1)) { if (DateCheck.DayOfWeek == DayOfWeek.Sunday) { FirstSunday = DateCheck; break; } } int sundayCount = 0; if (FirstSunday != DateTime.MinValue) { sundayCount = (int)((item.DateEnd - FirstSunday).TotalDays / 7) + 1; } int dayOffCount = lstDayOff.Select(m => m.Date >= DateStartInYear && m.Date < item.DateEnd).Count(); numLeave += (item.DateEnd - DateStartInYear).TotalDays - sundayCount - dayOffCount; } else if (item.DateStart < DateEndInYear && item.DateEnd > DateEndInYear) { DateTime FirstSunday = DateTime.MinValue; for (DateTime DateCheck = item.DateStart; DateCheck < DateEndInYear; DateCheck = DateCheck.AddDays(1)) { if (DateCheck.DayOfWeek == DayOfWeek.Sunday) { FirstSunday = DateCheck; break; } } int sundayCount = 0; if (FirstSunday != DateTime.MinValue) { sundayCount = (int)((DateEndInYear - FirstSunday).TotalDays / 7) + 1; } int dayOffCount = lstDayOff.Select(m => m.Date >= item.DateStart && m.Date < DateEndInYear).Count(); numLeave += (item.DateEnd - DateStartInYear).TotalDays - sundayCount - dayOffCount; } else { numLeave += item.LeaveDays ?? 0; } } value = ((int)(numLeave / dayPerMonth)) + ((numLeave % dayPerMonth) >= anlRoundUp ? 1 : 0); formula.Parameters.Add(Formula.FormulaConstant.ANL_LEAVE_NON_HAVEANL.ToString(), value); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ANL_WORK_HDT4.ToString())) { double value = 0; double monthCount = 0; double dayCount = 0; //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm string Lv4 = HDTJobType.E_Four.ToString(); List<HDTJobTypeRange> lstHDTJobContaintLV4 = lstHDTJobContaint.Where(m => m.Type == Lv4).ToList(); //Lấy ra 3 khoảng //Đầu Năm HDTJobTypeRange lstHDTJobContaintLV4_BeginYear = lstHDTJobContaintLV4.Where(m => m.DateStart < DateStartInYear && m.DateEnd != null && m.DateEnd.Value > DateStartInYear).FirstOrDefault(); //Trong Năm List<HDTJobTypeRange> lstHDTJobContaintLV4_InYear = lstHDTJobContaintLV4.Where(m => m.DateStart >= DateStartInYear && m.DateEnd != null && m.DateEnd.Value <= DateEndInYear).ToList(); //Cuối Năm HDTJobTypeRange lstHDTJobContaintLV4_EndYear = lstHDTJobContaintLV4.Where(m => m.DateStart < DateEndInYear && m.DateEnd != null && m.DateEnd.Value > DateEndInYear).FirstOrDefault(); bool isFullYear = false; if (lstHDTJobContaintLV4_BeginYear != null && !isFullYear) { if (lstHDTJobContaintLV4_BeginYear.DateEnd.Value > DateEndInYear) { dayCount = (DateEndInYear - DateStartInYear).TotalDays; isFullYear = true; } else { dayCount += (lstHDTJobContaintLV4_BeginYear.DateEnd.Value - DateStartInYear).TotalDays; } } if (lstHDTJobContaintLV4_EndYear != null && !isFullYear) { if (lstHDTJobContaintLV4_EndYear.DateStart < DateStartInYear) { dayCount = (DateEndInYear - DateStartInYear).TotalDays; isFullYear = true; } else { dayCount += (DateEndInYear - lstHDTJobContaintLV4_EndYear.DateStart).TotalDays; } } if (!isFullYear) { foreach (var item in lstHDTJobContaintLV4_InYear) { dayCount += (item.DateEnd.Value - item.DateStart).TotalDays; } } monthCount = ((int)(dayCount / dayPerMonth)) + (((dayCount % dayPerMonth) / dayPerMonth) >= anlRoundUp ? 1 : 0); value = monthCount * anlHDT4MoreThanNormal; formula.Parameters.Add(Formula.FormulaConstant.ANL_WORK_HDT4.ToString(), value); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ANL_WORK_HDT5.ToString())) { double value = 0; double monthCount = 0; double dayCount = 0; //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm string Lv5 = HDTJobType.E_Five.ToString(); List<HDTJobTypeRange> lstHDTJobContaintLV5 = lstHDTJobContaint.Where(m => m.Type == Lv5).ToList(); //Lấy ra 3 khoảng //Đầu Năm HDTJobTypeRange lstHDTJobContaintLV5_BeginYear = lstHDTJobContaintLV5.Where(m => m.DateStart < DateStartInYear && m.DateEnd != null && m.DateEnd.Value > DateStartInYear).FirstOrDefault(); //Trong Năm List<HDTJobTypeRange> lstHDTJobContaintLV5_InYear = lstHDTJobContaintLV5.Where(m => m.DateStart >= DateStartInYear && m.DateEnd != null && m.DateEnd.Value <= DateEndInYear).ToList(); //Cuối Năm HDTJobTypeRange lstHDTJobContaintLV5_EndYear = lstHDTJobContaintLV5.Where(m => m.DateStart < DateEndInYear && m.DateEnd != null && m.DateEnd.Value > DateEndInYear).FirstOrDefault(); bool isFullYear = false; if (lstHDTJobContaintLV5_BeginYear != null && !isFullYear) { if (lstHDTJobContaintLV5_BeginYear.DateEnd.Value > DateEndInYear) { dayCount = (DateEndInYear - DateStartInYear).TotalDays; isFullYear = true; } else { dayCount += (lstHDTJobContaintLV5_BeginYear.DateEnd.Value - DateStartInYear).TotalDays; } } if (lstHDTJobContaintLV5_EndYear != null && !isFullYear) { if (lstHDTJobContaintLV5_EndYear.DateStart < DateStartInYear) { dayCount = (DateEndInYear - DateStartInYear).TotalDays; isFullYear = true; } else { dayCount += (DateEndInYear - lstHDTJobContaintLV5_EndYear.DateStart).TotalDays; } } if (!isFullYear) { foreach (var item in lstHDTJobContaintLV5_InYear) { dayCount += (item.DateEnd.Value - item.DateStart).TotalDays; } } monthCount = ((int)(dayCount / dayPerMonth)) + (((dayCount % dayPerMonth) / dayPerMonth) >= anlRoundUp ? 1 : 0); value = monthCount * anlHDT5MoreThanNormal; formula.Parameters.Add(Formula.FormulaConstant.ANL_WORK_HDT5.ToString(), value); } #endregion } else { #region BHXH if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ANL_NORMAL.ToString())) { double value = 0; if (DateStartInYear <= DateCheckByMonth) { value = anlFullYear; } formula.Parameters.Add(Formula.FormulaConstant.ANL_NORMAL.ToString(), value); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ANL_SENIOR.ToString())) { double value = 0; int level = 0; DateTime DateSenior = DateTime.MinValue; for (int i = 0; i < 20; i++) { DateSenior = DateStartProfile.Value.AddMonths(seniorMonth); if (DateSenior <= DateCheckByMonth) { level++; continue; } else { break; } } value = (level * anlSeniorMoreThanNormal); formula.Parameters.Add(Formula.FormulaConstant.ANL_SENIOR.ToString(), value); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ANL_WORK_HDT4.ToString())) { double value = 0; double monthCount = 0; double dayCount = 0; //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm string Lv4 = HDTJobType.E_Four.ToString(); DateTime DateStartMonth = DateCheckByMonth.Value; DateTime DateEndMonth = DateStartMonth.AddMonths(1).AddMinutes(-1); List<HDTJobTypeRange> lstHDTJobContaintLV4 = lstHDTJobContaint.Where(m => m.Type == Lv4).ToList(); //Lấy ra 3 khoảng //Đầu Năm HDTJobTypeRange lstHDTJobContaintLV4_BeginMonth = lstHDTJobContaintLV4.Where(m => m.DateStart < DateStartMonth && m.DateEnd != null && m.DateEnd.Value > DateStartMonth).FirstOrDefault(); //Trong Năm List<HDTJobTypeRange> lstHDTJobContaintLV4_InMonth = lstHDTJobContaintLV4.Where(m => m.DateStart >= DateStartMonth && m.DateEnd != null && m.DateEnd.Value <= DateEndMonth).ToList(); //Cuối Năm HDTJobTypeRange lstHDTJobContaintLV4_EndMonth = lstHDTJobContaintLV4.Where(m => m.DateStart < DateEndMonth && m.DateEnd != null && m.DateEnd.Value > DateEndMonth).FirstOrDefault(); bool isFullMonth = false; if (lstHDTJobContaintLV4_BeginMonth != null && !isFullMonth) { if (lstHDTJobContaintLV4_BeginMonth.DateEnd.Value > DateEndMonth) { dayCount = (DateEndMonth - DateStartMonth).TotalDays; isFullMonth = true; } else { dayCount += (lstHDTJobContaintLV4_BeginMonth.DateEnd.Value - DateStartMonth).TotalDays; } } if (lstHDTJobContaintLV4_EndMonth != null && !isFullMonth) { if (lstHDTJobContaintLV4_EndMonth.DateStart < DateStartMonth) { dayCount = (DateEndMonth - DateStartMonth).TotalDays; isFullMonth = true; } else { dayCount += (DateEndMonth - lstHDTJobContaintLV4_EndMonth.DateStart).TotalDays; } } if (!isFullMonth) { foreach (var item in lstHDTJobContaintLV4_InMonth) { dayCount += (item.DateEnd.Value - item.DateStart).TotalDays; } } monthCount = ((dayCount % dayPerMonth) >= anlRoundUp ? 1 : 0); value = monthCount * anlHDT4MoreThanNormal; formula.Parameters.Add(Formula.FormulaConstant.ANL_WORK_HDT4.ToString(), value); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ANL_WORK_HDT5.ToString())) { double value = 0; double monthCount = 0; double dayCount = 0; //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm string Lv5 = HDTJobType.E_Five.ToString(); DateTime DateStartMonth = DateCheckByMonth.Value; DateTime DateEndMonth = DateStartMonth.AddMonths(1).AddMinutes(-1); List<HDTJobTypeRange> lstHDTJobContaintLV5 = lstHDTJobContaint.Where(m => m.Type == Lv5).ToList(); //Lấy ra 3 khoảng //Đầu Năm HDTJobTypeRange lstHDTJobContaintLV5_BeginMonth = lstHDTJobContaintLV5.Where(m => m.DateStart < DateStartMonth && m.DateEnd != null && m.DateEnd.Value > DateStartMonth).FirstOrDefault(); //Trong Năm List<HDTJobTypeRange> lstHDTJobContaintLV5_InMonth = lstHDTJobContaintLV5.Where(m => m.DateStart >= DateStartMonth && m.DateEnd != null && m.DateEnd.Value <= DateEndMonth).ToList(); //Cuối Năm HDTJobTypeRange lstHDTJobContaintLV5_EndMonth = lstHDTJobContaintLV5.Where(m => m.DateStart < DateEndMonth && m.DateEnd != null && m.DateEnd.Value > DateEndMonth).FirstOrDefault(); bool isFullMonth = false; if (lstHDTJobContaintLV5_BeginMonth != null && !isFullMonth) { if (lstHDTJobContaintLV5_BeginMonth.DateEnd.Value > DateEndMonth) { dayCount = (DateEndMonth - DateStartMonth).TotalDays; isFullMonth = true; } else { dayCount += (lstHDTJobContaintLV5_BeginMonth.DateEnd.Value - DateStartMonth).TotalDays; } } if (lstHDTJobContaintLV5_EndMonth != null && !isFullMonth) { if (lstHDTJobContaintLV5_EndMonth.DateStart < DateStartMonth) { dayCount = (DateEndMonth - DateStartMonth).TotalDays; isFullMonth = true; } else { dayCount += (DateEndMonth - lstHDTJobContaintLV5_EndMonth.DateStart).TotalDays; } } if (!isFullMonth) { foreach (var item in lstHDTJobContaintLV5_InMonth) { dayCount += (item.DateEnd.Value - item.DateStart).TotalDays; } } monthCount = ((dayCount % dayPerMonth) >= anlRoundUp ? 1 : 0); value = monthCount * anlHDT5MoreThanNormal; formula.Parameters.Add(Formula.FormulaConstant.ANL_WORK_HDT5.ToString(), value); } #endregion } #endregion double AnnualDays = 0; if (profile != null && CatJobTitle != null) { AnnualDays = CatJobTitle.AnnualDays ?? 0; } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.INS_PROBATION.ToString())) { DateTime midDate = new DateTime(currentMonth.Year, currentMonth.Month, 15); bool isProbation = dateEndProbation.HasValue && dateEndProbation.Value > midDate; formula.Parameters.Add(Formula.FormulaConstant.INS_PROBATION.ToString(), isProbation.ToString()); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.TOTAL.ToString())) { formula.Parameters.Add(Formula.FormulaConstant.TOTAL.ToString(), totalDayAnnualLeaveOnYear); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.CURRENTYEAR.ToString())) { formula.Parameters.Add(Formula.FormulaConstant.CURRENTYEAR.ToString(), currentMonth.Year); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.TOTAL_LEAVE_BY_TYPE_IN_MONTH.ToString())) { if (ProfileCurrentID != profile.ID || dtEnd.Month == 1) { _Num_TOTAL_LEAVE_BY_TYPE_IN_MONTH = 0; ProfileCurrentID = profile.ID; } DateTime DateBeginMonth = dtStart; DateTime DateEndMonth = dtEnd; string E_FULLSHIFT = LeaveDayDurationType.E_FULLSHIFT.ToString(); List<string> lstCodeLeave = lstCodeLeaveNonAnl; double Sum = 0; if (lstCodeLeave.Count > 0) { Guid guidNewRelease = Guid.NewGuid(); string status = string.Empty; BaseService baseService = new BaseService(); List<object> lst3ParamFT = new List<object>(); lst3ParamFT.Add(null); lst3ParamFT.Add(DateBeginMonth); lst3ParamFT.Add(DateEndMonth); var dataAtt_LeaveDay = baseService.GetData<Att_LeaveDay>(lst3ParamFT, ConstantSql.hrm_att_getdata_LeaveDay_Inner, userLogin, ref status).ToList(); var lstLeaveTotalDuration = dataAtt_LeaveDay.Where(m => m.ProfileID == profile.ID //&& m.DateStart <= DateEndMonth //&& m.DateEnd >= DateBeginMonth && m.DurationType == E_FULLSHIFT && m.TotalDuration != null && m.Cat_LeaveDayType != null && lstCodeLeave.Contains(m.Cat_LeaveDayType.Code)) .Select(m => m.TotalDuration); foreach (var item in lstLeaveTotalDuration) { if (item != null) { Sum += item.Value; } } if (Sum > 13) _Num_TOTAL_LEAVE_BY_TYPE_IN_MONTH = _Num_TOTAL_LEAVE_BY_TYPE_IN_MONTH + 1; //EntityService.Instance.ReleaseContext(guidNewRelease); } formula.Parameters.Add(Formula.FormulaConstant.TOTAL_LEAVE_BY_TYPE_IN_MONTH.ToString(), _Num_TOTAL_LEAVE_BY_TYPE_IN_MONTH); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.MONTHHIRE.ToString())) { double monthHire = dateHire == null ? 1 : dateHire.Value.Month; formula.Parameters.Add(Formula.FormulaConstant.MONTHHIRE.ToString(), monthHire); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.YEARHIRE.ToString())) { int yearHire = dateHire != null ? dateHire.Value.Year : 0; formula.Parameters.Add(Formula.FormulaConstant.YEARHIRE.ToString(), yearHire); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.ADDITIONAL_ANNUAL.ToString())) { initAnnualValue = initAnnualValue.HasValue ? initAnnualValue.Value : 0; formula.Parameters.Add(Formula.FormulaConstant.ADDITIONAL_ANNUAL.ToString(), initAnnualValue.Value); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.MONTHENDPRO.ToString())) { #region Tháng kết thúc thử việc if (dateEndProbation.HasValue) { DateTime fromDate = currentMonth.Date.AddDays(1 - currentMonth.Day); DateTime toDate = fromDate.Date.AddMonths(1).AddSeconds(-1); GetDuration(gradeCfg, currentMonth, out fromDate, out toDate); int monthstart = dateEndProbation.Value.Month; if (currentMonth.Year > dateEndProbation.Value.Year) { monthstart = monthStartAnnualLeave == null ? 1 : monthStartAnnualLeave.Value; } else if (currentMonth.Year == dateEndProbation.Value.Year) { monthstart = dateEndProbation.Value.Month; if (dateEndProbation.Value.Day > 15) { monthstart++; } //Tháng đang xét nhỏ hơn tháng vào cty if (currentMonth.Month < monthstart) { return 0; } } else if (currentMonth.Year < dateEndProbation.Value.Year) { return 0; } formula.Parameters.Add(Formula.FormulaConstant.MONTHENDPRO.ToString(), monthstart); } #endregion } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.MONTHSTART_PROB.FormulaToString())) { #region Tháng bắt đầu thử việc DateTime dateTemp = DateTime.Now; if (dateEndProbation.HasValue) { dateTemp = dateEndProbation.Value; } else if (dateHire.HasValue) { dateTemp = dateHire.Value; } int monthstart = dateTemp.Month; if (currentMonth.Year > dateTemp.Year) { monthstart = monthStartAnnualLeave == null ? 1 : monthStartAnnualLeave.Value; } else if (currentMonth.Year == dateTemp.Year) { monthstart = dateTemp.Month; if (dateTemp.Day > 15) { monthstart++; } //Trường hợp tháng vào cty nhỏn hơn tháng bắt đầu tính phép năm if (monthStartAnnualLeave != null && monthstart < monthStartAnnualLeave.Value) { monthstart = monthStartAnnualLeave.Value; } //Tháng đang xét nhỏ hơn tháng vào cty if (currentMonth.Month < monthstart) { return 0; } } else if (currentMonth.Year < dateTemp.Year) { return 0; } formula.Parameters.Add(Formula.FormulaConstant.MONTHSTART_PROB.ToString(), monthstart); #endregion } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.MONTHSTART2.FormulaToString())) { #region MONTHSTART2 if (!dateHire.HasValue) { return 0; } double monthstart = dateHire.Value.Month; if (currentMonth.Year > dateHire.Value.Year) { monthstart = monthStartAnnualLeave == null ? 1 : monthStartAnnualLeave.Value; } else if (currentMonth.Year == dateHire.Value.Year) { DateTime monthHirePro = dateHire.Value; DateTime fromDate = currentMonth.Date.AddDays(1 - currentMonth.Day); DateTime toDate = fromDate.Date.AddMonths(1).AddSeconds(-1); Att_AttendanceServices.GetMonthSalary(gradeCfg, dateHire.Value, out monthHirePro); Att_AttendanceLib.GetDuration(gradeCfg, monthHirePro, out fromDate, out toDate); Double countDay = toDate.Date.Subtract(dateHire.Value.Date).TotalDays; if (countDay <= 20 && countDay >= 10) { monthstart += 0.5; } else if (countDay < 10) { monthstart += 1; } //cung nam nhung thang dang xet nho hon thang vao cty if (currentMonth.Month < dateHire.Value.Month) { return 0; } } else if (currentMonth.Year < dateHire.Value.Year) { return 0; } formula.Parameters.Add(Formula.FormulaConstant.MONTHSTART2.ToString(), monthstart); #endregion } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.MONTHSTART.FormulaToString())) { #region MONTHSTART if (dateHire != null) { int monthstart = dateHire.Value.Month; if (currentMonth.Year > dateHire.Value.Year) { monthstart = monthStartAnnualLeave == null ? 1 : monthStartAnnualLeave.Value; } else if (currentMonth.Year == dateHire.Value.Year) { monthstart = dateHire.Value.Month; if (dateHire.Value.Day > 15) { monthstart++; } //cung nam nhung thang dang xet nho hon thang vao cty if (currentMonth.Month < monthstart) { return 0; } } else if (currentMonth.Year < dateHire.Value.Year) { return 0; } formula.Parameters.Add(Formula.FormulaConstant.MONTHSTART.ToString(), monthstart); } #endregion } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.TERMINATION.ToString())) { #region TERMINATION bool isTermination = dateQuit.HasValue && dateQuit.Value.Year == currentMonth.Year && dateQuit.Value.Month == currentMonth.Month; formula.Parameters.Add(Formula.FormulaConstant.TERMINATION.ToString(), isTermination); #endregion } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.MONTHEND.ToString())) { #region MONTHEND int monthEnd = 0; if (dateQuit.HasValue && dateQuit.Value.Year == currentMonth.Year) { if (dateQuit.Value.Day > 15) { monthEnd = dateQuit.Value.Month; } else { monthEnd = dateQuit.Value.Month - 1; } } formula.Parameters.Add(Formula.FormulaConstant.MONTHEND.ToString(), monthEnd); #endregion } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.CURRENTMONTH.ToString())) { #region CURRENTMONTH int month = 0; month = currentMonth.Month; if (dateQuit.HasValue && dateQuit.Value.Year == currentMonth.Year && dateQuit.Value.Month == currentMonth.Month) { if (dateQuit.Value.Day > 15) { month = currentMonth.Month; } else { month = currentMonth.Month - 1; } } formula.Parameters.Add(Formula.FormulaConstant.CURRENTMONTH.ToString(), month); #endregion } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.SENIOR_BONUS_LEAVE.ToString())) { formula.Parameters.Add(Formula.FormulaConstant.SENIOR_BONUS_LEAVE.ToString(), seniority); } if (formulaAnnualLeave.Contains(Formula.FormulaConstant.SENIOR_BONUS_LEAVE_FROM_.ToString())) { #region SENIOR_BONUS_LEAVE_FROM Double hourOnWorkDate = 8; if (gradeCfg.HourOnWorkDate.HasValue) { hourOnWorkDate = gradeCfg.HourOnWorkDate.Value; } int idx = formulaAnnualLeave.IndexOf(Formula.FormulaConstant.SENIOR_BONUS_LEAVE_FROM_.ToString()); while (idx != -1) { int idx2 = formulaAnnualLeave.IndexOf(@"]", idx) - 1; int lengh = Formula.FormulaConstant.SENIOR_BONUS_LEAVE_FROM_.ToString().Length; string monthYearString = formulaAnnualLeave.Substring(idx + lengh, idx2 - idx - lengh + 1); string year = monthYearString.Substring(4); string month = monthYearString.Substring(2, 2); string fullParamString = Formula.FormulaConstant.SENIOR_BONUS_LEAVE_FROM_.ToString() + monthYearString; if (!formula.Parameters.ContainsKey(fullParamString)) { DateTime monthYearEffect = new DateTime(int.Parse(year), int.Parse(month), 1); seniority = GetAnnualBySeniority(currentMonth, monthYearEffect, dateHire, gradeCfg); formula.Parameters.Add(fullParamString, seniority); } idx = formulaAnnualLeave.IndexOf(Formula.FormulaConstant.SENIOR_BONUS_LEAVE_FROM_.ToString(), idx2); } #endregion } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.MONTHENDPRO.ToString())) { #region MONTHENDPRO DateTime fromDate = new DateTime(currentMonth.Year, currentMonth.Month, 1); DateTime toDate = fromDate.AddMonths(1).AddMinutes(-1); Att_AttendanceServices.GetSalaryDateRange(gradeCfg, null, null, currentMonth, out fromDate, out toDate); int monthstart = 0; if (dateEndProbation != null) { monthstart = dateEndProbation.Value.Month; } if (dateEndProbation != null && currentMonth.Year > dateEndProbation.Value.Year) { monthstart = 1; monthstart = monthStartAnnualLeave ?? 1; } else if (dateEndProbation != null && currentMonth.Year == dateEndProbation.Value.Year) { if (dateEndProbation != null) { if (dateEndProbation.Value.Day > 15) monthstart = dateEndProbation.Value.Month; } monthstart++; // cung nam nhung thang dang xet nho hon thang vao cty if (currentMonth.Month < monthstart) return 0; } else if (dateEndProbation != null && currentMonth.Year < dateEndProbation.Value.Year) { return 0; } formula.Parameters.Add(Formula.FormulaConstant.MONTHENDPRO.ToString(), monthstart); #endregion } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.POSITION_CODE.ToString())) { string PositionCode = string.Empty; if (pos != null && pos.Code != null) { PositionCode = pos.Code; } formula.Parameters.Add(Formula.FormulaConstant.POSITION_CODE.ToString(), PositionCode); } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.CURRENTMONTH_INSALARY.ToString())) { int month = 0; month = currentMonth.Month; formula.Parameters.Add(Formula.FormulaConstant.CURRENTMONTH_INSALARY.ToString(), month); } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.IS_PROBATION.ToString())) { int flag = 0; if ((dateHire != null && dateHire >= dtStart && dateHire <= dtEnd) || (dateEndProbation != null && dateEndProbation >= dtStart && dateEndProbation <= dtEnd) || (dateHire != null && dateHire <= dtEnd && dateEndProbation != null && dateEndProbation >= dtStart)) { flag = 1; } formula.Parameters.Add(Formula.FormulaConstant.IS_PROBATION.ToString(), flag); } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.YEAR_OF_DATEHIRE.ToString())) { int year = 0; if (dateHire != null && dateHire >= dtStart && dateHire <= dtEnd) { year = dateHire.Value.Year; } formula.Parameters.Add(Formula.FormulaConstant.YEAR_OF_DATEHIRE.ToString(), year); } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.MONTH_OF_DATEHIRE.ToString())) { int month = 0; if (dateHire != null && dateHire >= dtStart && dateHire <= dtEnd) { month = dateHire.Value.Month; } formula.Parameters.Add(Formula.FormulaConstant.MONTH_OF_DATEHIRE.ToString(), month); } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.YEAR_OF_DATEENDPROBATION.ToString())) { int year = 0; if (dateEndProbation != null && dateEndProbation >= dtStart && dateEndProbation <= dtEnd) { year = dateEndProbation.Value.Year; } formula.Parameters.Add(Formula.FormulaConstant.YEAR_OF_DATEENDPROBATION.ToString(), year); } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.MONTH_OF_DATEENDPROBATION.ToString())) { int month = 0; if (dateEndProbation != null && dateEndProbation >= dtStart && dateEndProbation <= dtEnd) { month = dateEndProbation.Value.Month; } formula.Parameters.Add(Formula.FormulaConstant.MONTH_OF_DATEENDPROBATION.ToString(), month); } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.DAYOFDATEHIRE.ToString())) { int Day = 0; if (dateHire != null) Day = dateHire.Value.Day; formula.Parameters.Add(Formula.FormulaConstant.DAYOFDATEHIRE.ToString(), Day); } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.DAYOFDATEQUIT.ToString())) { int Day = 0; if (dateQuit != null) Day = dateQuit.Value.Day; formula.Parameters.Add(Formula.FormulaConstant.DAYOFDATEQUIT.ToString(), Day); } if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.JOBTITLE_ANNUAL.ToString())) { formula.Parameters.Add(Formula.FormulaConstant.JOBTITLE_ANNUAL.ToString(), AnnualDays); } //Lấy tháng của DateHire, lấy kỳ lương theo tháng đó (tháng của DateHire), sau đó xuất ra Năm của kỳ lương đó. //vd: DateHire là 26/08/2014 ==>kỳ lương T8 là 25/07/2014-24/08/2014, ktra DateHire có thuộc kỳ T8 ko, nếu ko thì ktra trong kỳ lương T9. if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.YEAR_OF_SALARY_IF_DATEHIRE_BELONG.ToString())) { int year = 0; DateTime dateStart, dateEnd; if (dateHire != null) { DateTime dtmonthCheck = new DateTime(dateHire.Value.Year, dateHire.Value.Month, 1); //Lấy khoảng thời gian của kỳ lương Att_AttendanceServices.GetSalaryDateRange(gradeCfg, null, null, dtmonthCheck, out dateStart, out dateEnd); if (dateHire >= dateStart && dateHire <= dateEnd) { year = dateEnd.Year; } else { DateTime dateStartAdd = dateStart.AddMonths(1); DateTime dateEndAdd = dateEnd.AddMonths(1); if (dateHire >= dateStartAdd && dateHire <= dateEndAdd) { year = dateEndAdd.Year; } } } formula.Parameters.Add(Formula.FormulaConstant.YEAR_OF_SALARY_IF_DATEHIRE_BELONG.ToString(), year); } //Lấy tháng của DateHire, lấy kỳ lương theo tháng đó (tháng của DateHire), sau đó xuất ra Tháng của kỳ lương đó. if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.MONTH_OF_SALARY_IF_DATEHIRE_BELONG.ToString())) { int month = 0; DateTime dateStart, dateEnd; if (dateHire != null) { DateTime dtmonthCheck = new DateTime(dateHire.Value.Year, dateHire.Value.Month, 1); //Lấy khoảng thời gian của kỳ lương Att_AttendanceServices.GetSalaryDateRange(gradeCfg, null, null, dtmonthCheck, out dateStart, out dateEnd); if (dateHire >= dateStart && dateHire <= dateEnd) { month = dateEnd.Month; } else { DateTime dateStartAdd = dateStart.AddMonths(1); DateTime dateEndAdd = dateEnd.AddMonths(1); if (dateHire >= dateStartAdd && dateHire <= dateEndAdd) { month = dateEndAdd.Month; } } } formula.Parameters.Add(Formula.FormulaConstant.MONTH_OF_SALARY_IF_DATEHIRE_BELONG.ToString(), month); } //XuChi..Phần tử lấy số ngày thâm niên (theo đk của Danieli) if (gradeCfg.FormulaAnnualLeave.Contains(Formula.FormulaConstant.THAMNIEN_DANIELI.ToString())) { int thamnien = 0; DateTime dayRule = new DateTime(2014, 10, 4); //Ngày quy định fixed của Danieli DateTime currentDay = DateTime.Now.Date; //Ngày hiện tại lúc kiểm tra if (dateHire != null) { DateTime dayHire = dateHire.Value.Date; //Nếu ngày vào làm vào sau ngày quy định (logic: thâm niên 5 năm thì cộng 1) if (dayHire >= dayRule) { while (dayHire.AddYears(5) <= currentDay) { dayHire = dayHire.AddYears(5); thamnien++; } } else //Nếu ngày vào làm trước ngày quy định { //logic 1: thâm niêm 3 năm thì cộng 1 while (dayHire.AddYears(3) <= dayRule) { dayHire = dayHire.AddYears(3); thamnien++; } //logic 2: sau logic 1, sẽ có ngày dayHire gần với ngày dayRule nhất, //khi đó dayHire sẽ đc so sánh với currentDay, sau đó tính thâm niên 5 năm thì cộng 1 while (dayHire.AddYears(5) <= currentDay) { dayHire = dayHire.AddYears(5); thamnien++; } } } formula.Parameters.Add(Formula.FormulaConstant.THAMNIEN_DANIELI.ToString(), thamnien); } result = Convert.ToDouble(formula.Evaluate()); if ((result - (int)result) > 0) { double dental = result - (int)result; result = dental >= 0.5 ? (int)result + 1 : (int)result; } return result; return result; }
public bool ComputeInsuranceLeaveDetail(int Year, string orgStructure, string LstProfileStatus,string UserLogin) { /* * -get leaveDetail : type , year * - get List Profile : * + Theo phong ban * + Theo trạng thai StatusEmpleaveDetail * */ var result = false; string status = string.Empty; using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_AnnualLeaveDetail = new CustomBaseRepository<Att_AnnualLeaveDetail>(unitOfWork); var repoHre_Profile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var repoHre_HDTJob = new CustomBaseRepository<Hre_HDTJob>(unitOfWork); var repoSys_AppConfig = new CustomBaseRepository<Sys_AppConfig>(unitOfWork); var repoCat_DayOff = new CustomBaseRepository<Cat_DayOff>(unitOfWork); var repoCat_LeaveDayType = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork); var repoAtt_LeaveDay = new CustomBaseRepository<Att_LeaveDay>(unitOfWork); var repoCat_JobTitle = new CustomBaseRepository<Cat_JobTitle>(unitOfWork); #region get Data string HRM_ATT_ANNUALINSURANCELEAVE_ = AppConfig.HRM_ATT_ANNUALINSURANCELEAVE_.ToString(); List<object> lstO = new List<object>(); lstO.Add(HRM_ATT_ANNUALINSURANCELEAVE_); lstO.Add(null); lstO.Add(null); var config = GetData<Sys_AllSettingEntity>(lstO, ConstantSql.hrm_sys_sp_get_AllSetting, UserLogin, ref status); var formular1 = config.Where(s => s.Name == AppConfig.HRM_ATT_ANNUALINSURANCELEAVE_FORMULARCONFIG.ToString()).FirstOrDefault(); var formular2 = config.Where(s => s.Name == AppConfig.HRM_ATT_ANNUALINSURANCELEAVE_FORMULARCOMPUTE.ToString()).FirstOrDefault(); if (config == null || string.IsNullOrEmpty(formular1.Value1) || string.IsNullOrEmpty(formular2.Value1)) { //Common.MessageBoxs(Messages.Msg, Messages.PleaseConfigAnnualLeaveAtTotalConfig, MessageBox.Icon.WARNING, string.Empty); return result; } List<object> lstPro = new List<object>(); lstPro.Add(orgStructure); lstPro.Add(null); lstPro.Add(null); var lstProfileQuery = GetData<Hre_ProfileEntity>(lstPro, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList(); string formularConfig = formular1.Value1; string formularCompute = formular2.Value1; ParamGetConfigANL configAnl = new ParamGetConfigANL(); (new Att_AttendanceServices()).GetConfigANL(formularConfig, out configAnl); int MonthBegin = 1; List<string> lstCodeLeaveTypeNonAnl = new List<string>(); if (configAnl != null && configAnl.monthBeginYear != null) { MonthBegin = configAnl.monthBeginYear; } if (configAnl != null && configAnl.lstCodeLeaveNonANL != null) { lstCodeLeaveTypeNonAnl = configAnl.lstCodeLeaveNonANL; } DateTime BeginYear = new DateTime(Year, MonthBegin, 1); DateTime EndYear = BeginYear.AddYears(1).AddMinutes(-1); string E_APPROVED = LeaveDayStatus.E_APPROVED.ToString(); List<DateTime> lstDayOff = repoCat_DayOff .FindBy(m => m.IsDelete == null && m.DateOff > BeginYear && m.DateOff <= EndYear) .Select(m => m.DateOff).Distinct().ToList<DateTime>(); List<Hre_ProfileEntity> lstprofile = lstProfileQuery .Where(m => m.DateQuit == null || (m.DateQuit != null && m.DateQuit > BeginYear)).ToList(); List<Guid> lstProfileID = lstprofile.Select(m => m.ID).ToList(); List<Guid> lstLeavedayTypeNonAnl = repoCat_LeaveDayType .FindBy(m => m.IsDelete == null && lstCodeLeaveTypeNonAnl.Contains(m.Code)).Select(m => m.ID).ToList<Guid>(); List<Att_LeaveDay> lstleavedayNonANl = repoAtt_LeaveDay .FindBy(m => m.IsDelete == null && m.Status == E_APPROVED && lstLeavedayTypeNonAnl.Contains(m.LeaveDayTypeID) && lstProfileID.Contains(m.ProfileID)).ToList<Att_LeaveDay>(); List<Att_LeaveDay> lstleavedayNonANlInYear = lstleavedayNonANl.Where(m => m.DateStart <= EndYear && m.DateEnd >= BeginYear).ToList<Att_LeaveDay>(); List<Hre_HDTJob> lstHDTJob = repoHre_HDTJob .FindBy(m => m.IsDelete == null && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)).ToList<Hre_HDTJob>(); List<Cat_JobTitle> lstJobtitle = repoCat_JobTitle.FindBy(s => s.IsDelete == null).ToList(); string E_INSURANCE_LEAVE = AnnualLeaveDetailType.E_INSURANCE_LEAVE.ToString(); #endregion List<Att_AnnualLeaveDetail> lstInsDetail = new List<Att_AnnualLeaveDetail>(); foreach (var item in lstprofile) { List<Att_LeaveDay> lstLeavedayNonAnlByProfile = lstleavedayNonANl.Where(m => m.ProfileID == item.ID).ToList(); List<Att_LeaveDay> lstLeavedayNonAnlByProfileInYear = lstleavedayNonANlInYear.Where(m => m.ProfileID == item.ID).ToList(); List<Hre_HDTJob> lstHDTJobByProfile = lstHDTJob.Where(m => m.ProfileID == item.ID).ToList(); Att_AnnualLeaveDetail annualProfile = new Att_AnnualLeaveDetail(); annualProfile.ID = Guid.NewGuid(); annualProfile.ProfileID = item.ID; annualProfile.MonthStart = BeginYear; annualProfile.MonthEnd = EndYear; annualProfile.Year = Year; annualProfile.Type = E_INSURANCE_LEAVE; for (DateTime Month = BeginYear; Month < EndYear; Month = Month.AddMonths(1)) { double AvailabelInYear = (new Att_AttendanceServices()).GetAnnualLeaveAvailableAllYear( Year, Month.Month, item.DateHire, item.DateEndProbation, item.DateQuit, formularConfig, formularCompute, lstLeavedayNonAnlByProfileInYear, lstJobtitle, lstDayOff, lstHDTJobByProfile, lstLeavedayNonAnlByProfile); if (Month.Month == 1) annualProfile.Month1 = AvailabelInYear; if (Month.Month == 2) annualProfile.Month2 = AvailabelInYear; if (Month.Month == 3) annualProfile.Month3 = AvailabelInYear; if (Month.Month == 4) annualProfile.Month4 = AvailabelInYear; if (Month.Month == 5) annualProfile.Month5 = AvailabelInYear; if (Month.Month == 6) annualProfile.Month6 = AvailabelInYear; if (Month.Month == 7) annualProfile.Month7 = AvailabelInYear; if (Month.Month == 8) annualProfile.Month8 = AvailabelInYear; if (Month.Month == 9) annualProfile.Month9 = AvailabelInYear; if (Month.Month == 10) annualProfile.Month10 = AvailabelInYear; if (Month.Month == 11) annualProfile.Month11 = AvailabelInYear; if (Month.Month == 12) annualProfile.Month12 = AvailabelInYear; } lstInsDetail.Add(annualProfile); } DataErrorCode DataErr = DataErrorCode.Unknown; if (lstInsDetail.Count > 0) { #region lấy dữ liệu dưới DB xóa đi List<Guid> lstProfileID_InDB = lstInsDetail.Where(m => m.ProfileID != null).Select(m => m.ProfileID.Value).ToList(); List<Att_AnnualLeaveDetail> lstAnnualLeaveDetail_InDB = repoAtt_AnnualLeaveDetail .FindBy(m => m.IsDelete == null && m.Type == E_INSURANCE_LEAVE && m.Year == Year && m.ProfileID != null && lstProfileID_InDB.Contains(m.ProfileID.Value)).ToList(); foreach (var item in lstAnnualLeaveDetail_InDB) { item.IsDelete = true; } #endregion repoAtt_AnnualLeaveDetail.Add(lstInsDetail); try { repoAtt_AnnualLeaveDetail.SaveChanges(); } catch (Exception) { return false; } //EntityService.AddEntity<Att_AnnualLeaveDetail>(GuidContext, lstInsDetail.ToArray()); //DataErr = EntityService.SubmitChanges(GuidContext, LoginUserID); //if (DataErr == DataErrorCode.Success) //{ // Common.MessageBoxs(Messages.Msg, Messages.SaveSuccess, MessageBox.Icon.INFO, string.Empty); //} //else //{ // Common.MessageBoxs(Messages.Msg, Messages.SaveUnSuccess, MessageBox.Icon.INFO, string.Empty); //} } //else //{ // Common.MessageBoxs(Messages.Msg, Messages.NoDataToCompute, MessageBox.Icon.WARNING, string.Empty); //} result = true; } return result; }
/// <summary> /// /// </summary> /// <param name="guidContext"></param> /// <param name="Year"></param> /// <param name="Month">nếu như null ->> Tính nguyên năm , nếu !Null -> tính cho từng tháng</param> /// <param name="dateHire"></param> /// <param name="dateEndProbation"></param> /// <param name="dateQuit"></param> /// <param name="fomularConfig"></param> /// <param name="formulaLeave"></param> /// <param name="lstLeaveDay"></param> /// <param name="lstJobtitle"></param> /// <param name="lstDayOff"></param> /// <param name="lstHDTJob_ByProfile"></param> /// <returns></returns> public Double GetAnnualLeaveAvailableAllYear(int Year, int? Month, DateTime? dateHire, DateTime? dateEndProbation, DateTime? dateQuit, string fomularConfig, string formulaLeave, List<Att_LeaveDay> lstLeaveDay, List<Cat_JobTitle> lstJobtitle, List<DateTime> lstDayOff, List<Hre_HDTJob> lstHDTJob_ByProfile, List<Att_LeaveDay> lstLeaveDayAllYear) { #region Param lstHDTJob_ByProfile = lstHDTJob_ByProfile.Where(m => m.DateFrom != null && m.Type != null).OrderBy(m => m.DateFrom).ToList(); ParamGetConfigANL paramConfig = new ParamGetConfigANL(); //set du lieu GetConfigANL(fomularConfig, out paramConfig); int monthBeginYear = paramConfig.monthBeginYear; //Tháng bắt đầu tính phép năm int dayBeginFullMonth = paramConfig.dayBeginFullMonth; //Ngày bắt đầu tính tròn ANL cho tháng int seniorMonth = paramConfig.seniorMonth; // Số tháng để có 1 level cho thâm niên int dayPerMonth = paramConfig.dayPerMonth; // Số ngày cho 1 tháng double anlRoundUp = paramConfig.anlRoundUp; //Số làm tròn Lên xuống string typeProfileBegin = paramConfig.typeProfileBegin; //Loại lấy theo DateHire hay DateQuit int maxInMonthToGetAct = paramConfig.maxInMonthToGetAct; //Ngày chuẩn để xét là DT4 và DT5 đc tính cho tháng àno double anlFullYear = paramConfig.anlFullYear; // Số ngày phép bình thường cho 1 năm (tính theo tháng) double anlSeniorMoreThanNormal = paramConfig.anlSeniorMoreThanNormal; // Số ngày phép Được cộng thêm do thâm niên so với bình thường (tính theo tháng) double anlHDT4MoreThanNormal = paramConfig.anlHDT4MoreThanNormal; // Số ngày phép được cộng thêm do HDT4 so với bình thường (tính theo tháng) double anlHDT5MoreThanNormal = paramConfig.anlHDT5MoreThanNormal; // Số ngày phép được cộng thêm do HDT5 so với bình thường (tính theo tháng) List<string> lstCodeLeaveNonANL = paramConfig.lstCodeLeaveNonANL; int monthInYearSenior = paramConfig.monthInYearSenior; int monthRoundUp = paramConfig.monthRoundUp; #endregion #region Data //gan du lieu can thiet DateTime BeginYear = new DateTime(Year, monthBeginYear, 1); DateTime EndYear = BeginYear.AddYears(1).AddMinutes(-1); DateTime? DateCheckByMonth = null; if (Month != null) { DateCheckByMonth = new DateTime(Year, Month.Value, 1); if (Month < monthBeginYear) { DateCheckByMonth = new DateTime(Year + 1, Month.Value, 1); } } DateTime? DateStartProfile = null; DateTime DateEndProfile = EndYear; if (typeProfileBegin == AnlProfileTypeBegin.E_DATE_ENDPROBATION.ToString()) { DateStartProfile = dateEndProbation; } else { DateStartProfile = dateHire; } if (DateStartProfile == null) return 0; if (dateQuit != null && dateQuit < EndYear) { DateEndProfile = dateQuit.Value.Date.AddDays(1).AddMinutes(-1); } if (DateStartProfile.Value.Day > dayBeginFullMonth) { DateStartProfile = new DateTime(DateStartProfile.Value.AddMonths(1).Year, DateStartProfile.Value.AddMonths(1).Month, 1); } DateTime DateStartInYear = BeginYear > DateStartProfile.Value ? BeginYear : DateStartProfile.Value; DateTime DateEndInYear = EndYear < DateEndProfile ? EndYear : DateEndProfile; List<HDTJobTypeRange> lstHDTJobContaint = new List<HDTJobTypeRange>(); foreach (var item in lstHDTJob_ByProfile) { HDTJobTypeRange hdtJob = new HDTJobTypeRange(); hdtJob.Type = item.Type; hdtJob.DateStart = item.DateFrom.Value; hdtJob.DateEnd = item.DateTo; lstHDTJobContaint.Add(hdtJob); } lstHDTJobContaint = lstHDTJobContaint.OrderByDescending(m => m.DateStart).ToList(); DateTime DateBeFore = DateTime.MaxValue; foreach (var item in lstHDTJobContaint) { if (item.DateEnd == null) { item.DateEnd = DateBeFore; } DateBeFore = item.DateStart; } #endregion //ANL_WORK_HDT4, //ANL_WORK_HDT5, Formula formula = new Formula(formulaLeave); if (DateCheckByMonth == null) { #region ANL and Leave if (formulaLeave.Contains(Formula.FormulaConstant.ANL_NORMAL.ToString())) { double value = 0; double monthWorkingNormalInYear = 0; for (int i = 0; i < 12; i++) { if (DateStartInYear.AddMonths(i) < DateEndInYear) { monthWorkingNormalInYear++; } else { break; } } value = anlFullYear * monthWorkingNormalInYear; formula.Parameters.Add(Formula.FormulaConstant.ANL_NORMAL.ToString(), value); } if (formulaLeave.Contains(Formula.FormulaConstant.ANL_SENIOR.ToString())) { double value = 0; int MonBegin = monthInYearSenior == 0 ? 1 : monthInYearSenior; //--DateStartProfile DateTime Monthyear = new DateTime(Year, MonBegin, 1); double dateLeave = lstLeaveDayAllYear.Where(m => m.LeaveDays != null).Sum(m => m.LeaveDays.Value); dateLeave += (lstLeaveDayAllYear.Where(m => m.LeaveHours == null).Sum(m => m.LeaveHours.Value) / 8); DateTime dateRoundProfileStart = DateStartProfile.Value.AddMonths(-monthRoundUp); double Days = (Monthyear - dateRoundProfileStart).TotalDays - dateLeave; int level = (int)(Days / (365 * (seniorMonth / 12))); value = level * anlSeniorMoreThanNormal * 12; formula.Parameters.Add(Formula.FormulaConstant.ANL_SENIOR.ToString(), value); } if (formulaLeave.Contains(Formula.FormulaConstant.ANL_LEAVE_NON_HAVEANL.ToString())) { double value = 0; //Logic: Vướng cai đầu năm cuối năm nên phải cắt cái ngày đó ra cho chính xác double numLeave = 0; foreach (var item in lstLeaveDay) { if (item.DateStart < DateStartInYear && item.DateEnd > DateStartInYear) { DateTime FirstSunday = DateTime.MinValue; for (DateTime DateCheck = DateStartInYear; DateCheck < item.DateEnd; DateCheck = DateCheck.AddDays(1)) { if (DateCheck.DayOfWeek == DayOfWeek.Sunday) { FirstSunday = DateCheck; break; } } int sundayCount = 0; if (FirstSunday != DateTime.MinValue) { sundayCount = (int)((item.DateEnd - FirstSunday).TotalDays / 7) + 1; } int dayOffCount = lstDayOff.Select(m => m.Date >= DateStartInYear && m.Date < item.DateEnd).Count(); numLeave += (item.DateEnd - DateStartInYear).TotalDays - sundayCount - dayOffCount; } else if (item.DateStart < DateEndInYear && item.DateEnd > DateEndInYear) { DateTime FirstSunday = DateTime.MinValue; for (DateTime DateCheck = item.DateStart; DateCheck < DateEndInYear; DateCheck = DateCheck.AddDays(1)) { if (DateCheck.DayOfWeek == DayOfWeek.Sunday) { FirstSunday = DateCheck; break; } } int sundayCount = 0; if (FirstSunday != DateTime.MinValue) { sundayCount = (int)((DateEndInYear - FirstSunday).TotalDays / 7) + 1; } int dayOffCount = lstDayOff.Select(m => m.Date >= item.DateStart && m.Date < DateEndInYear).Count(); numLeave += (item.DateEnd - DateStartInYear).TotalDays - sundayCount - dayOffCount; } else { numLeave += item.TotalDuration ?? 0; } } value = ((int)(numLeave / dayPerMonth)) + ((numLeave % dayPerMonth) >= anlRoundUp ? 1 : 0); formula.Parameters.Add(Formula.FormulaConstant.ANL_LEAVE_NON_HAVEANL.ToString(), value); } if (formulaLeave.Contains(Formula.FormulaConstant.ANL_WORK_HDT4.ToString())) { double value = 0; double monthCount = 0; double dayCount = 0; //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm string Lv4 = HDTJobType.E_Four.ToString(); List<HDTJobTypeRange> lstHDTJobContaintLV4 = lstHDTJobContaint.Where(m => m.Type == Lv4).ToList(); //Lấy ra 3 khoảng //Đầu Năm HDTJobTypeRange lstHDTJobContaintLV4_BeginYear = lstHDTJobContaintLV4.Where(m => m.DateStart < DateStartInYear && m.DateEnd != null && m.DateEnd.Value > DateStartInYear).FirstOrDefault(); //Trong Năm List<HDTJobTypeRange> lstHDTJobContaintLV4_InYear = lstHDTJobContaintLV4.Where(m => m.DateStart >= DateStartInYear && m.DateEnd != null && m.DateEnd.Value <= DateEndInYear).ToList(); //Cuối Năm HDTJobTypeRange lstHDTJobContaintLV4_EndYear = lstHDTJobContaintLV4.Where(m => m.DateStart < DateEndInYear && m.DateEnd != null && m.DateEnd.Value > DateEndInYear).FirstOrDefault(); bool isFullYear = false; if (lstHDTJobContaintLV4_BeginYear != null && !isFullYear) { if (lstHDTJobContaintLV4_BeginYear.DateEnd.Value > DateEndInYear) { dayCount = (DateEndInYear - DateStartInYear).TotalDays; isFullYear = true; } else { dayCount += (lstHDTJobContaintLV4_BeginYear.DateEnd.Value - DateStartInYear).TotalDays; } } if (lstHDTJobContaintLV4_EndYear != null && !isFullYear) { if (lstHDTJobContaintLV4_EndYear.DateStart < DateStartInYear) { dayCount = (DateEndInYear - DateStartInYear).TotalDays; isFullYear = true; } else { dayCount += (DateEndInYear - lstHDTJobContaintLV4_EndYear.DateStart).TotalDays; } } if (!isFullYear) { foreach (var item in lstHDTJobContaintLV4_InYear) { dayCount += (item.DateEnd.Value - item.DateStart).TotalDays; } } monthCount = ((int)(dayCount / dayPerMonth)) + ((dayCount % dayPerMonth) >= anlRoundUp ? 1 : 0); value = monthCount * anlHDT4MoreThanNormal; formula.Parameters.Add(Formula.FormulaConstant.ANL_WORK_HDT4.ToString(), value); } if (formulaLeave.Contains(Formula.FormulaConstant.ANL_WORK_HDT5.ToString())) { double value = 0; double monthCount = 0; double dayCount = 0; //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm string Lv5 = HDTJobType.E_Five.ToString(); List<HDTJobTypeRange> lstHDTJobContaintLV5 = lstHDTJobContaint.Where(m => m.Type == Lv5).ToList(); //Lấy ra 3 khoảng //Đầu Năm HDTJobTypeRange lstHDTJobContaintLV5_BeginYear = lstHDTJobContaintLV5.Where(m => m.DateStart < DateStartInYear && m.DateEnd != null && m.DateEnd.Value > DateStartInYear).FirstOrDefault(); //Trong Năm List<HDTJobTypeRange> lstHDTJobContaintLV5_InYear = lstHDTJobContaintLV5.Where(m => m.DateStart >= DateStartInYear && m.DateEnd != null && m.DateEnd.Value <= DateEndInYear).ToList(); //Cuối Năm HDTJobTypeRange lstHDTJobContaintLV5_EndYear = lstHDTJobContaintLV5.Where(m => m.DateStart < DateEndInYear && m.DateEnd != null && m.DateEnd.Value > DateEndInYear).FirstOrDefault(); bool isFullYear = false; if (lstHDTJobContaintLV5_BeginYear != null && !isFullYear) { if (lstHDTJobContaintLV5_BeginYear.DateEnd.Value > DateEndInYear) { dayCount = (DateEndInYear - DateStartInYear).TotalDays; isFullYear = true; } else { dayCount += (lstHDTJobContaintLV5_BeginYear.DateEnd.Value - DateStartInYear).TotalDays; } } if (lstHDTJobContaintLV5_EndYear != null && !isFullYear) { if (lstHDTJobContaintLV5_EndYear.DateStart < DateStartInYear) { dayCount = (DateEndInYear - DateStartInYear).TotalDays; isFullYear = true; } else { dayCount += (DateEndInYear - lstHDTJobContaintLV5_EndYear.DateStart).TotalDays; } } if (!isFullYear) { foreach (var item in lstHDTJobContaintLV5_InYear) { dayCount += (item.DateEnd.Value - item.DateStart).TotalDays; } } monthCount = ((int)(dayCount / dayPerMonth)) + ((dayCount % dayPerMonth) >= anlRoundUp ? 1 : 0); value = monthCount * anlHDT5MoreThanNormal; formula.Parameters.Add(Formula.FormulaConstant.ANL_WORK_HDT5.ToString(), value); } #endregion } else { #region BHXH if (formulaLeave.Contains(Formula.FormulaConstant.ANL_NORMAL.ToString())) { double value = 0; if (DateStartInYear <= DateCheckByMonth) { value = anlFullYear; } formula.Parameters.Add(Formula.FormulaConstant.ANL_NORMAL.ToString(), value); } if (formulaLeave.Contains(Formula.FormulaConstant.ANL_SENIOR.ToString())) { double value = 0; int level = 0; DateTime DateSenior = DateTime.MinValue; for (int i = 0; i < 20; i++) { DateSenior = DateStartProfile.Value.AddMonths(seniorMonth); if (DateSenior <= DateCheckByMonth) { level++; continue; } else { break; } } value = (level * anlSeniorMoreThanNormal); formula.Parameters.Add(Formula.FormulaConstant.ANL_SENIOR.ToString(), value); } if (formulaLeave.Contains(Formula.FormulaConstant.ANL_WORK_HDT4.ToString())) { double value = 0; double monthCount = 0; double dayCount = 0; //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm string Lv4 = HDTJobType.E_Four.ToString(); DateTime DateStartMonth = DateCheckByMonth.Value; DateTime DateEndMonth = DateStartMonth.AddMonths(1).AddMinutes(-1); List<HDTJobTypeRange> lstHDTJobContaintLV4 = lstHDTJobContaint.Where(m => m.Type == Lv4).ToList(); //Lấy ra 3 khoảng //Đầu Năm HDTJobTypeRange lstHDTJobContaintLV4_BeginMonth = lstHDTJobContaintLV4.Where(m => m.DateStart < DateStartMonth && m.DateEnd != null && m.DateEnd.Value > DateStartMonth).FirstOrDefault(); //Trong Năm List<HDTJobTypeRange> lstHDTJobContaintLV4_InMonth = lstHDTJobContaintLV4.Where(m => m.DateStart >= DateStartMonth && m.DateEnd != null && m.DateEnd.Value <= DateEndMonth).ToList(); //Cuối Năm HDTJobTypeRange lstHDTJobContaintLV4_EndMonth = lstHDTJobContaintLV4.Where(m => m.DateStart < DateEndMonth && m.DateEnd != null && m.DateEnd.Value > DateEndMonth).FirstOrDefault(); bool isFullMonth = false; if (lstHDTJobContaintLV4_BeginMonth != null && !isFullMonth) { if (lstHDTJobContaintLV4_BeginMonth.DateEnd.Value > DateEndMonth) { dayCount = (DateEndMonth - DateStartMonth).TotalDays; isFullMonth = true; } else { dayCount += (lstHDTJobContaintLV4_BeginMonth.DateEnd.Value - DateStartMonth).TotalDays; } } if (lstHDTJobContaintLV4_EndMonth != null && !isFullMonth) { if (lstHDTJobContaintLV4_EndMonth.DateStart < DateStartMonth) { dayCount = (DateEndMonth - DateStartMonth).TotalDays; isFullMonth = true; } else { dayCount += (DateEndMonth - lstHDTJobContaintLV4_EndMonth.DateStart).TotalDays; } } if (!isFullMonth) { foreach (var item in lstHDTJobContaintLV4_InMonth) { dayCount += (item.DateEnd.Value - item.DateStart).TotalDays; } } monthCount = ((dayCount % dayPerMonth) >= anlRoundUp ? 1 : 0); value = monthCount * anlHDT4MoreThanNormal; formula.Parameters.Add(Formula.FormulaConstant.ANL_WORK_HDT4.ToString(), value); } if (formulaLeave.Contains(Formula.FormulaConstant.ANL_WORK_HDT5.ToString())) { double value = 0; double monthCount = 0; double dayCount = 0; //thuat: 1. lây cái mới nhất so với ngày bắt đầu năm //Lấy cái moi nhất nhỏ hơn ngày bắt đầu năm string Lv5 = HDTJobType.E_Five.ToString(); DateTime DateStartMonth = DateCheckByMonth.Value; DateTime DateEndMonth = DateStartMonth.AddMonths(1).AddMinutes(-1); List<HDTJobTypeRange> lstHDTJobContaintLV5 = lstHDTJobContaint.Where(m => m.Type == Lv5).ToList(); //Lấy ra 3 khoảng //Đầu Năm HDTJobTypeRange lstHDTJobContaintLV5_BeginMonth = lstHDTJobContaintLV5.Where(m => m.DateStart < DateStartMonth && m.DateEnd != null && m.DateEnd.Value > DateStartMonth).FirstOrDefault(); //Trong Năm List<HDTJobTypeRange> lstHDTJobContaintLV5_InMonth = lstHDTJobContaintLV5.Where(m => m.DateStart >= DateStartMonth && m.DateEnd != null && m.DateEnd.Value <= DateEndMonth).ToList(); //Cuối Năm HDTJobTypeRange lstHDTJobContaintLV5_EndMonth = lstHDTJobContaintLV5.Where(m => m.DateStart < DateEndMonth && m.DateEnd != null && m.DateEnd.Value > DateEndMonth).FirstOrDefault(); bool isFullMonth = false; if (lstHDTJobContaintLV5_BeginMonth != null && !isFullMonth) { if (lstHDTJobContaintLV5_BeginMonth.DateEnd.Value > DateEndMonth) { dayCount = (DateEndMonth - DateStartMonth).TotalDays; isFullMonth = true; } else { dayCount += (lstHDTJobContaintLV5_BeginMonth.DateEnd.Value - DateStartMonth).TotalDays; } } if (lstHDTJobContaintLV5_EndMonth != null && !isFullMonth) { if (lstHDTJobContaintLV5_EndMonth.DateStart < DateStartMonth) { dayCount = (DateEndMonth - DateStartMonth).TotalDays; isFullMonth = true; } else { dayCount += (DateEndMonth - lstHDTJobContaintLV5_EndMonth.DateStart).TotalDays; } } if (!isFullMonth) { foreach (var item in lstHDTJobContaintLV5_InMonth) { dayCount += (item.DateEnd.Value - item.DateStart).TotalDays; } } monthCount = ((dayCount % dayPerMonth) >= anlRoundUp ? 1 : 0); value = monthCount * anlHDT5MoreThanNormal; formula.Parameters.Add(Formula.FormulaConstant.ANL_WORK_HDT5.ToString(), value); } #endregion } double result = Convert.ToDouble(formula.Evaluate()); if ((result - (int)result) > 0) { double dental = result - (int)result; result = dental >= 0.5 ? (int)result + 1 : (int)result; } return result; }
public void GetConfigANL(string fomularConfig, out ParamGetConfigANL paramConfig) { #region set default value paramConfig = new ParamGetConfigANL(); paramConfig.monthBeginYear = 1; paramConfig.dayBeginFullMonth = 1; paramConfig.seniorMonth = 12 * 5; paramConfig.dayPerMonth = 30; paramConfig.anlRoundUp = 0.5; paramConfig.typeProfileBegin = AnlProfileTypeBegin.E_DATE_HIRE.ToString(); paramConfig.maxInMonthToGetAct = 15; //Trươc ngày 15 thì tính cho tháng đó paramConfig.anlFullYear = (double)12 / (double)12; paramConfig.anlSeniorMoreThanNormal = (double)1 / (double)12; paramConfig.anlHDT4MoreThanNormal = (double)2 / (double)12; paramConfig.anlHDT5MoreThanNormal = (double)4 / (double)12; paramConfig.lstCodeLeaveNonANL = new List<string>(); paramConfig.monthInYearSenior = 0; paramConfig.monthRoundUp = 0; #endregion #region set value by Config List<string> lstConfig = fomularConfig.Split(';').ToList(); Dictionary<string, string> dicConfigANL = new Dictionary<string, string>(); foreach (var item in lstConfig) { string Val = string.Empty; Val = item.Replace("[", ""); Val = Val.Replace("]", ""); List<string> config = Val.Split(':').ToList(); if (config.Count > 1) { dicConfigANL.Add(config[0], config[1]); } } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_MONTHBEGINYEAR.ToString())) { int value = 0; int.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_MONTHBEGINYEAR.ToString()], out value); value = value == 0 ? 1 : value; paramConfig.monthBeginYear = value; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_DAYBEGIN_FULLMONTH.ToString())) { int value = 0; int.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_DAYBEGIN_FULLMONTH.ToString()], out value); value = value == 0 ? 1 : value; paramConfig.dayBeginFullMonth = value; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_SENIOR_MONTH.ToString())) { int value = 0; int.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_SENIOR_MONTH.ToString()], out value); paramConfig.seniorMonth = value; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_DAY_PER_MONTH.ToString())) { int value = 0; int.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_DAY_PER_MONTH.ToString()], out value); paramConfig.dayPerMonth = value; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_ROUND_UP.ToString())) { double value = 0; double.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_ROUND_UP.ToString()], out value); paramConfig.anlRoundUp = value; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_TYPE_PROFILE_BEGIN.ToString())) { paramConfig.typeProfileBegin = dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_TYPE_PROFILE_BEGIN.ToString()]; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_DAY_MAX_IN_MONTH_GET_ACTUAL.ToString())) { int value = 0; int.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_DAY_MAX_IN_MONTH_GET_ACTUAL.ToString()], out value); paramConfig.maxInMonthToGetAct = value; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_NORMAL_CAN_GET_FULLYEAR.ToString())) { double value = 0; double.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_NORMAL_CAN_GET_FULLYEAR.ToString()], out value); paramConfig.anlFullYear = (double)value / (double)12; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_SENIOR_CAN_GET_EACH_LEVEL.ToString())) { double value = 0; double.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_SENIOR_CAN_GET_EACH_LEVEL.ToString()], out value); paramConfig.anlSeniorMoreThanNormal = (double)value / (double)12; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_HDT4_CAN_GET_MORE_NORMAL.ToString())) { double value = 0; double.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_HDT4_CAN_GET_MORE_NORMAL.ToString()], out value); paramConfig.anlHDT4MoreThanNormal = (double)value / (double)12; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_ANL_HDT5_CAN_GET_MORE_NORMAL.ToString())) { double value = 0; double.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_ANL_HDT5_CAN_GET_MORE_NORMAL.ToString()], out value); paramConfig.anlHDT5MoreThanNormal = (double)value / (double)12; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_LEAVE_NON_ALN_CODES.ToString())) { string CodeLeaveNonANL = dicConfigANL[Formula.FormulaConstant.CONFIG_LEAVE_NON_ALN_CODES.ToString()]; char[] ext = new char[] { ',' }; paramConfig.lstCodeLeaveNonANL = CodeLeaveNonANL.Split(ext, StringSplitOptions.RemoveEmptyEntries).ToList(); } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_MONTH_INYEAR_TO_COMPUTE_SENIOR.ToString())) { string CodeLeaveNonANL = dicConfigANL[Formula.FormulaConstant.CONFIG_MONTH_INYEAR_TO_COMPUTE_SENIOR.ToString()]; int value = 0; int.TryParse(dicConfigANL[Formula.FormulaConstant.CONFIG_MONTH_INYEAR_TO_COMPUTE_SENIOR.ToString()], out value); paramConfig.monthInYearSenior = value; } if (dicConfigANL.ContainsKey(Formula.FormulaConstant.CONFIG_MONTH_ROUND_UP.ToString())) { string roundUp = dicConfigANL[Formula.FormulaConstant.CONFIG_MONTH_ROUND_UP.ToString()]; int value = 0; int.TryParse(roundUp, out value); paramConfig.monthRoundUp = value; } #endregion }