public List<Hre_ReportCodeNotInSystemEntity> GetReportCodeNotInSystem(DateTime? DateFrom, DateTime? DateTo) { List<Hre_ReportCodeNotInSystemEntity> lstReportCodeNotInSystem = new List<Hre_ReportCodeNotInSystemEntity>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Hre_ProfileRepository(unitOfWork); var codeAttendance = repo.FindBy(s => s.IsDelete == null).Select(m => m.CodeAttendance).Distinct().ToList(); var repoTAMScanLog = new Att_TAMScanLogRepository(unitOfWork); var lstCardHistory = repoTAMScanLog.FindBy(m => m.TimeLog >= DateFrom && m.TimeLog <= DateTo && !codeAttendance.Contains(m.CardCode)) .Select(m => new { m.CardCode, m.TimeLog, m.MachineNo, m.Type, m.SrcType, m.DateCreate, m.UserCreate }).ToList(); foreach (var CardHistory in lstCardHistory) { Hre_ReportCodeNotInSystemEntity codeNotInSystemEntity = new Hre_ReportCodeNotInSystemEntity(); codeNotInSystemEntity.Code = CardHistory.CardCode; codeNotInSystemEntity.Type = CardHistory.Type; codeNotInSystemEntity.Time = CardHistory.TimeLog; codeNotInSystemEntity.Machine = CardHistory.MachineNo; codeNotInSystemEntity.UserCreate = CardHistory.UserCreate; codeNotInSystemEntity.DateCreate = CardHistory.DateCreate; lstReportCodeNotInSystem.Add(codeNotInSystemEntity); } return lstReportCodeNotInSystem; } }
public List<Hre_ReportHDTJobEntity> GetReportHDTJob(DateTime? DateFrom, DateTime? DateTo, string lstOrgOrderNumber, string userLogin) { string status = string.Empty; List<Hre_ReportHDTJobEntity> lstReportHDTJobEntity = new List<Hre_ReportHDTJobEntity>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var hdtJobServices = new Hre_HDTJobServices(); List<object> listObjHDTJob = new List<object>(); listObjHDTJob.Add(lstOrgOrderNumber); listObjHDTJob.Add(DateFrom); listObjHDTJob.Add(DateTo); var lstHDTJob = hdtJobServices.GetData<Hre_HDTJobEntity>(listObjHDTJob, ConstantSql.hrm_hr_sp_get_RptHDTJob, userLogin, ref status).ToList(); if (lstHDTJob == null) { return lstReportHDTJobEntity; } var lstProfileByHDTJob = lstHDTJob.Select(s => s.ProfileID).ToList(); var repoProfile = new Hre_ProfileRepository(unitOfWork); var lstProfile = repoProfile.FindBy(s => lstProfileByHDTJob.Contains(s.ID)).ToList(); List<Guid> profileid = lstProfile.Select(m => m.ID).ToList(); var repoHDTJobType = new Cat_HDTJobTypeRepository(unitOfWork); var lstHDTJobType = repoHDTJobType.GetAll().ToList(); foreach (var ProfileID in profileid) { if (ProfileID == null) continue; var lstHDTJobbyProfile = lstHDTJob.Where(m => m.ProfileID == ProfileID).ToList(); foreach (var HDTJobbyProfile in lstHDTJobbyProfile) { Hre_ReportHDTJobEntity reportHDTJobEntity = new Hre_ReportHDTJobEntity(); var profile = lstProfile.Where(m => m.ID == ProfileID).Select(m => new { m.ProfileName, m.CodeEmp, m.PositionID, m.JobTitleID }).FirstOrDefault(); var HDTJobType = lstHDTJobType.Where(s => HDTJobbyProfile.HDTJobTypeID == s.ID).FirstOrDefault(); reportHDTJobEntity.ProfileName = profile.ProfileName; reportHDTJobEntity.CodeEmp = profile.CodeEmp; reportHDTJobEntity.HDTType = HDTJobType != null ? HDTJobType.HDTJobTypeName : null; reportHDTJobEntity.DateFrom = HDTJobbyProfile.DateFrom; reportHDTJobEntity.DateTo = HDTJobbyProfile.DateTo; lstReportHDTJobEntity.Add(reportHDTJobEntity); } } } return lstReportHDTJobEntity; }
public List<Hre_ReportProfileQuitEntity> GetReportProfileQuit(DateTime? DateFrom, DateTime? DateToSearch, List<Guid> lstProfileIDs) { List<Hre_ReportProfileQuitEntity> lstReportProfileQuit = new List<Hre_ReportProfileQuitEntity>(); DateTime DateTo = DateToSearch.Value.AddDays(1).AddMinutes(-1); if (lstProfileIDs == null) { return lstReportProfileQuit; } using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoorgs = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoorgs.FindBy(s => s.IsDelete == null && s.Code != null).ToList(); var repopostions = new Cat_PositionRepository(unitOfWork); var postions = repopostions.FindBy(s => s.IsDelete == null && s.PositionName != null).ToList(); var repojobtitles = new Cat_JobTitleRepository(unitOfWork); var jobtitles = repojobtitles.FindBy(s => s.IsDelete == null && s.JobTitleName != null).ToList(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); var reporesreason = new Cat_ResignReasonRepository(unitOfWork); var lstResReason = reporesreason.FindBy(s => s.IsDelete == null && s.ResignReasonName != null).ToList(); var repoprofiles = new Hre_ProfileRepository(unitOfWork); var profiles = repoprofiles.FindBy(s => s.IsDelete == null && s.DateQuit >= DateFrom && s.DateQuit <= DateTo && lstProfileIDs.Contains(s.ID)) .Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID, s.IDNo, s.CodeAttendance, s.DateEndProbation, s.ProbExtendDate, s.IDDateOfIssue, s.IDPlaceOfIssue, s.DateHire, s.WorkPlaceID, s.PAStreet, s.EmpTypeID, s.RequestDate, s.ResReasonID, s.Gender }).ToList(); foreach (var profile in profiles) { Hre_ReportProfileQuitEntity ReportProfileQuit = new Hre_ReportProfileQuitEntity(); Guid? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var jobtitlebypro = jobtitles.Where(s => s.ID == profile.JobTitleID).FirstOrDefault(); var positiobbypro = postions.Where(s => s.ID == profile.PositionID).FirstOrDefault(); var resReasonbypro = lstResReason.Where(s => s.ID == profile.ResReasonID).FirstOrDefault(); ReportProfileQuit.CodeEmp = profile.CodeEmp; ReportProfileQuit.ProfileName = profile.ProfileName; ReportProfileQuit.CodeOrg = org != null ? org.Code : null; ReportProfileQuit.OrgStructureName = org != null ? org.OrgStructureName : null; ReportProfileQuit.JobTitleName = jobtitlebypro != null ? jobtitlebypro.JobTitleName : null; ReportProfileQuit.PositionName = positiobbypro != null ? positiobbypro.PositionName : null; ReportProfileQuit.DateHire = profile.DateHire; ReportProfileQuit.RequestDate = profile.RequestDate; ReportProfileQuit.DateQuit = profile.DateQuit; ReportProfileQuit.ResignReasonName = resReasonbypro != null ? resReasonbypro.ResignReasonName : null; lstReportProfileQuit.Add(ReportProfileQuit); } return lstReportProfileQuit; } }
public List<Hre_ReportBirthdayEntity> GetReportBirthday(DateTime? DateFrom, DateTime? DateTo, List<Guid> lstProfileIDs) { List<Hre_ReportBirthdayEntity> lstReportBirthday = new List<Hre_ReportBirthdayEntity>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoProfile = new Hre_ProfileRepository(unitOfWork); var lstProfile = repoProfile.FindBy(s => s.DateOfBirth != null && s.IsDelete == null && s.DateOfBirth >= DateFrom && s.DateOfBirth <= DateTo && lstProfileIDs.Contains(s.ID)).ToList(); if (lstProfile == null) { return lstReportBirthday; } List<Guid> lstProfileIDsbyBirthday = lstProfile.Select(s => s.ID).ToList(); //var repoProfile = new Hre_ProfileRepository(unitOfWork); var lstAllprofile = repoProfile.FindBy(s => lstProfileIDsbyBirthday.Contains(s.ID)).Select(s => new { s.ID, s.ProfileName, s.CodeEmp, s.OrgStructureID, s.PositionID, s.JobTitleID, s.DateHire, s.DateOfBirth, s.PlaceOfBirth }).ToList(); var repoOrgStructure = new Cat_OrgStructureRepository(unitOfWork); var lstOrgStructure = repoOrgStructure.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.OrgStructureName }).ToList(); var repoPosition = new Cat_PositionRepository(unitOfWork); var lstPosition = repoPosition.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.PositionName }).ToList(); var repoJobtitle = new Cat_JobTitleRepository(unitOfWork); var lstJobtitle = repoJobtitle.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.JobTitleName }).ToList(); foreach (var ProfileBirthday in lstProfile) { Hre_ReportBirthdayEntity ReportBirthday = new Hre_ReportBirthdayEntity(); //var profileByContract = lstAllprofile.Where(s => contract.ProfileID == s.ID).FirstOrDefault(); //if (profileByContract == null) // continue; var orgByProfile = lstOrgStructure.Where(s => ProfileBirthday.OrgStructureID == s.ID).FirstOrDefault(); var positionByProfile = lstPosition.Where(s => ProfileBirthday.PositionID == s.ID).FirstOrDefault(); var jobtitleByProfile = lstJobtitle.Where(s => ProfileBirthday.JobTitleID == s.ID).FirstOrDefault(); ReportBirthday.CodeEmp = ProfileBirthday.CodeEmp; ReportBirthday.ProfileName = ProfileBirthday.ProfileName; ReportBirthday.ProfileID = ProfileBirthday.ID; ReportBirthday.OrgStructureName = orgByProfile != null ? orgByProfile.OrgStructureName : ""; ReportBirthday.JobTitleName = jobtitleByProfile != null ? jobtitleByProfile.JobTitleName : ""; ReportBirthday.PositionName = positionByProfile != null ? positionByProfile.PositionName : ""; ReportBirthday.DateTo = ProfileBirthday.DateTo; ReportBirthday.DateFrom = ProfileBirthday.DateFrom; ReportBirthday.DateHire = ProfileBirthday.DateHire; ReportBirthday.DateOfBirth = ProfileBirthday.DateOfBirth; ReportBirthday.PlaceOfBirth = ProfileBirthday.PlaceOfBirth; lstReportBirthday.Add(ReportBirthday); } return lstReportBirthday; } }
public DataTable ReportMultiSlideCard(List <int?> CarteringIDs, List <int?> CanteenIDS, List <int?> LineIDS, DateTime dateStart, DateTime dateEnd, List <int> lstProfileIds) { List <Can_ReportMultiSlideCardEntity> lstReportMultiSlideCard = new List <Can_ReportMultiSlideCardEntity>(); DataTable datatable = CreateReportMultiSlideCardSchema(dateStart, dateEnd); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var mealRecords = new List <Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList(); var repo = new Can_MealRecordRepository(unitOfWork); mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true) .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList(); var lstcateringids = mealRecords.Select(m => m.CateringID).ToList(); var lstcanteenids = mealRecords.Select(m => m.CanteenID).ToList(); var lstlineids = mealRecords.Select(m => m.LineID).ToList(); var workDays = new List <Att_WorkDay>().Select(s => new { s.ProfileID, s.WorkDate }).ToList(); var repoWorkDay = new Att_WorkDayRepository(unitOfWork); workDays = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd) .Select(s => new { s.ProfileID, s.WorkDate }).ToList(); var Cardcode = mealRecords.Select(s => s.CardCode).Distinct().ToList(); var repoProfile = new Hre_ProfileRepository(unitOfWork); var profiles = repoProfile.FindBy(m => Cardcode.Contains(m.CodeAttendance) && lstProfileIds.Contains(m.Id)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.CodeAttendance }).ToList(); var repoOrg = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoOrg.FindBy(m => m.Code != null).ToList(); var catering = new List <Can_Catering>().ToList(); var repocatering = new Can_CateringRepository(unitOfWork); if (CarteringIDs != null && CarteringIDs.Count > 0) { catering = repocatering.FindBy(m => CarteringIDs.Contains(m.Id)).ToList(); } else { catering = repocatering.GetAll().ToList(); } var canteen = new List <Can_Canteen>().ToList(); var repocanteen = new Can_CanteenRepository(unitOfWork); if (CanteenIDS != null && CanteenIDS.Count > 0) { canteen = repocanteen.FindBy(m => CanteenIDS.Contains(m.Id)).ToList(); } else { canteen = repocanteen.GetAll().ToList(); } var line = new List <Can_Line>().ToList(); var repoline = new Can_LineRepository(unitOfWork); if (LineIDS != null && LineIDS.Count > 0) { line = repoline.FindBy(m => LineIDS.Contains(m.Id)).ToList(); } else { line = repoline.GetAll().ToList(); } Can_ReportMultiSlideCardEntity ReportMultiSlideCardEntity = new Can_ReportMultiSlideCardEntity(); foreach (var profile in profiles) { DataRow row = datatable.NewRow(); var orgbyprofile = orgs.Where(m => m.Id == profile.OrgStructureID).FirstOrDefault(); var cateringbyprofile = catering.Where(m => lstcateringids.Contains(m.Id)).FirstOrDefault(); var lineprofile = line.Where(m => lstlineids.Contains(m.Id)).FirstOrDefault(); var canteenbyprofile = canteen.Where(m => lstcanteenids.Contains(m.Id)).FirstOrDefault(); row[Can_ReportMultiSlideCardEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Can_ReportMultiSlideCardEntity.FieldNames.ProfileName] = profile.ProfileName; row[Can_ReportMultiSlideCardEntity.FieldNames.OrgStructureName] = orgbyprofile.OrgStructureName; row[Can_ReportMultiSlideCardEntity.FieldNames.Cartering] = cateringbyprofile.CateringName; row[Can_ReportMultiSlideCardEntity.FieldNames.Canteen] = canteenbyprofile.CanteenName; row[Can_ReportMultiSlideCardEntity.FieldNames.Line] = lineprofile.LineName; var mealRecordProfiles = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).ToList(); var workDayProfiles = workDays.Where(s => s.ProfileID == profile.Id).ToList(); for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var meal = mealRecords.FirstOrDefault(s => s.CardCode == profile.CodeAttendance && s.TimeLog == date); if (meal != null) { row["Date" + date.Day] = (object)meal.TimeLog ?? DBNull.Value; //row["SumCardMore" + date.Day] = mealRecordProfiles.Count(s => s.TimeLog == date) - workDayProfiles.Count(s => s.WorkDate == date); } } datatable.Rows.Add(row); } } return(datatable); }
public List<Rec_CandidateEntity> FilterCandidate(DateTime dateFrom, DateTime dateTo, string jobVacancyIDs, string UserLogin, bool GetListFail = false, bool IsIncludeEvaCandidate = false) { List<Rec_CandidateEntity> lstCandidateResultPass = new List<Rec_CandidateEntity>(); List<Rec_CandidateEntity> lstCandidateResultFail = new List<Rec_CandidateEntity>(); using (var context = new VnrHrmDataContext()) { BaseService service = new BaseService(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoJobVacancy = new Rec_JobVacancyRepository(unitOfWork); var repoProfile = new Hre_ProfileRepository(unitOfWork); var repoJobCondition = new Rec_JobConditionRepository(unitOfWork); var repoCadidate = new Rec_CandidateRepository(unitOfWork); var repoRecruimentHistory = new Rec_RecruitmentHistoryRepository(unitOfWork); string status = string.Empty; #region Lấy tất cả nv var profileRepository = new Hre_ProfileRepository(unitOfWork); var lstProfile = new List<Hre_Profile>().Select(s => new { s.ID, s.IDNo, s.ProfileName, s.DateOfBirth }).ToList(); lstProfile.AddRange(profileRepository.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.IDNo, s.ProfileName, s.DateOfBirth }).ToList()); #endregion var lstJobCondition = repoJobCondition.FindBy(s => s.IsDelete == null).ToList(); List<object> lstpara = new List<object>(); lstpara.Add(dateFrom); lstpara.Add(dateTo); lstpara.Add(Common.DotNetToOracle(jobVacancyIDs)); var lstCandidate = service.GetData<Rec_CandidateEntity>(lstpara, ConstantSql.hrm_rec_sp_getdata_FilterCandidate, UserLogin, ref status); if (lstCandidate == null || lstCandidate.Count == 0) { return new List<Rec_CandidateEntity>(); } if (IsIncludeEvaCandidate == false) { lstCandidate = lstCandidate.Where(x => x.Status == null || x.Status == HRM.Infrastructure.Utilities.EnumDropDown.CandidateStatus.E_NEW.ToString()).ToList(); } if (lstCandidate == null || lstCandidate.Count == 0) { return new List<Rec_CandidateEntity>(); } var lstCandidateIds = lstCandidate.Select(s => s.ID).Distinct().ToList(); #region Lấy ds pv var interviewRepository = new Rec_InterviewRepository(unitOfWork); var lstInterview = new List<Rec_Interview>().Select(s => new { s.CandidateID, s.LevelInterview, s.Score1, s.Score2, s.Score3, s.DateUpdate }).ToList(); lstInterview.AddRange(interviewRepository.FindBy(s => s.IsDelete == null && lstCandidateIds.Contains(s.CandidateID.Value)).Select(s => new { s.CandidateID, s.LevelInterview, s.Score1, s.Score2, s.Score3, s.DateUpdate }).ToList()); #endregion var RecruitmentHistoryRepository = new Rec_RecruitmentHistoryRepository(unitOfWork); var lstrecruitmentHistory = RecruitmentHistoryRepository.FindBy(s => s.IsDelete == null && lstCandidateIds.Contains(s.CandidateID)).ToList(); List<object> lstparaEdu = new List<object>(); lstparaEdu.Add(null); lstparaEdu.Add(1); lstparaEdu.Add(int.MaxValue - 1); var lstEducationLevel = service.GetData<Cat_NameEntityEntity>(lstparaEdu, ConstantSql.hrm_cat_sp_get_EducationLevel, UserLogin,ref status).ToList(); List<object> lstparadiseelist = new List<object>(); lstparadiseelist.Add(null); lstparadiseelist.Add(EnumDropDown.EntityType.E_SICK_REC.ToString()); lstparadiseelist.Add(1); lstparadiseelist.Add(int.MaxValue - 1); var lstsick = service.GetData<Cat_NameEntityEntity>(lstparadiseelist, ConstantSql.hrm_cat_sp_get_LevelGeneral, UserLogin,ref status).ToList(); List<object> lstparaProvince = new List<object>(); lstparaProvince.Add(null); lstparaProvince.Add(null); lstparaProvince.Add(null); lstparaProvince.Add(null); lstparaProvince.Add(1); lstparaProvince.Add(int.MaxValue - 1); var lstProvince = service.GetData<Cat_ProvinceEntity>(lstparaProvince, ConstantSql.hrm_cat_sp_get_Province, UserLogin, ref status).ToList(); foreach (var item in lstCandidate) { string ReasonFailFilter = string.Empty; // nếu ko có điều kiện thì add vào ds fail if (string.IsNullOrEmpty(item.JobConditionIDs)) { lstCandidateResultPass.Add(item); continue; } if (item.IsFilterCV == null || item.IsFilterCV == false) { lstCandidateResultPass.Add(item); continue; } // nếu có thì bắt đầu lọc else { List<Guid> ids = new List<Guid>(); ids = item.JobConditionIDs .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => Guid.Parse(x)) .ToList(); var lstCondition = lstJobCondition.Where(x => ids.Contains(x.ID)).ToList(); int countCondition = lstCondition.Count; int countAgree = 0; foreach (var Condition in lstCondition) { #region Kiểm tra Tổng Điểm Phỏng Vấn if (Condition.ConditionName == ConditionName.E_INTERVIEW.ToString()) { double valueInterview1 = 0; try { valueInterview1 = double.Parse(Condition.Value1); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.Interview == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && valueInterview1 != 0 && item.Interview.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueInterview1 <= item.Interview) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueInterview1 >= item.Interview) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueInterview1 == item.Interview) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && valueInterview1 != 0 && item.Interview.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueInterview1 <= item.Interview) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueInterview1 >= item.Interview) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueInterview1 != item.Interview) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra Điểm Thi Viết if (Condition.ConditionName == ConditionName.E_WRITETEST.ToString()) { double valueWriteTest1 = 0; try { valueWriteTest1 = double.Parse(Condition.Value1); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.WriteTest == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && valueWriteTest1 != 0 && item.WriteTest.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueWriteTest1 <= item.WriteTest) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueWriteTest1 >= item.WriteTest) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueWriteTest1 == item.WriteTest) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && valueWriteTest1 != 0 && item.WriteTest.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueWriteTest1 <= item.WriteTest) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueWriteTest1 >= item.WriteTest) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueWriteTest1 != item.WriteTest) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra Tổng Sức Khỏe if (Condition.ConditionName == ConditionName.E_GENERALHEALTH.ToString()) { double valueHealth1 = 0; try { valueHealth1 = double.Parse(Condition.Value1); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.GenaralHealth == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && valueHealth1 != 0 && item.GenaralHealth.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueHealth1 <= item.GenaralHealth) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueHealth1 >= item.GenaralHealth) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueHealth1 == item.GenaralHealth) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && item.GenaralHealth.HasValue && valueHealth1 != 0) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueHealth1 <= item.GenaralHealth) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueHealth1 >= item.GenaralHealth) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueHealth1 != item.GenaralHealth) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra cao if (Condition.ConditionName == ConditionName.E_HEIGHT.ToString()) { double valueHeight1 = 0; try { valueHeight1 = double.Parse(Condition.Value1); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.Height == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && valueHeight1 != 0 && item.Height.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueHeight1 <= item.Height) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueHeight1 >= item.Height) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueHeight1 == item.Height) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && item.Height.HasValue && valueHeight1 != 0) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.Height <= valueHeight1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.Height >= valueHeight1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueHeight1 != item.Height) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra Cân Nặng if (Condition.ConditionName == ConditionName.E_WEIGHT.ToString()) { double valueWeight1 = 0; try { valueWeight1 = double.Parse(Condition.Value1); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.Weight == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && valueWeight1 != 0 && item.Weight.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.Weight == valueWeight1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.Weight >= valueWeight1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.Height <= valueWeight1) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && valueWeight1 != 0 && item.Weight.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.Weight != valueWeight1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.Weight <= valueWeight1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.Height >= valueWeight1) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm Tra Mắt #region Mắt Trái if (Condition.ConditionName == ConditionName.E_LEVELEYES.ToString()) { double valueEyes1 = 0; // double Eyes = 0; try { valueEyes1 = double.Parse(Condition.Value1); // Eyes = double.Parse(item.LevelEye); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (!item.LevelEye.HasValue) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && valueEyes1 != 0) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.LevelEye.Value == valueEyes1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.LevelEye.Value >= valueEyes1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.LevelEye.Value <= valueEyes1) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && valueEyes1 != 0) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.LevelEye.Value != valueEyes1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.LevelEye.Value <= valueEyes1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.LevelEye.Value >= valueEyes1) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Mắt Phải if (Condition.ConditionName == ConditionName.E_LEVERIGHTLEYES.ToString()) { double valueEyes1 = 0; // double Eyes = 0; try { valueEyes1 = double.Parse(Condition.Value1); // Eyes = double.Parse(item.LevelEye); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (!item.LevelEye.HasValue) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && valueEyes1 != 0) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.LevelEyeRight.Value == valueEyes1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.LevelEyeRight.Value >= valueEyes1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.LevelEyeRight.Value <= valueEyes1) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && valueEyes1 != 0) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.LevelEyeRight.Value != valueEyes1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.LevelEyeRight.Value <= valueEyes1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.LevelEyeRight.Value >= valueEyes1) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #endregion #region Kiểm tra Thời Gian Trượt Kỳ Trước if (Condition.ConditionName == ConditionName.E_DURATIONFAILPREVIOUS.ToString()) { if (lstrecruitmentHistory == null || lstrecruitmentHistory.Count == 0) { countAgree++; continue; } int valueDuration1 = int.Parse(Condition.Value1); // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString()) { var listCandidateHis = lstrecruitmentHistory.Where(x => x.CandidateID == item.ID && x.Status == HRM.Infrastructure.Utilities.EnumDropDown.CandidateStatus.E_FAIL.ToString()) .OrderByDescending(x => x.DateApply).ToList(); if (listCandidateHis == null || listCandidateHis.Count == 0) { countAgree++; continue; } if (listCandidateHis != null && listCandidateHis.Count != 0) { var CandidateHistory = listCandidateHis.FirstOrDefault(); double month = 0; if (CandidateHistory.DateApply != null && item.DateApply != null) { month = (new DateTime(item.DateApply.Value.Subtract(CandidateHistory.DateApply.Value).Ticks).Year - 1) > 0 ? (new DateTime(item.DateApply.Value.Subtract(CandidateHistory.DateApply.Value).Ticks).Year - 1) : (item.DateApply.Value.Subtract(CandidateHistory.DateApply.Value).TotalDays / (365.25 / 12)); } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && month == valueDuration1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && month > valueDuration1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && month < valueDuration1) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString()) { var listCandidateHis = lstrecruitmentHistory.Where(x => x.CandidateID == item.ID && x.Status == HRM.Infrastructure.Utilities.EnumDropDown.CandidateStatus.E_FAIL.ToString()) .OrderByDescending(x => x.DateApply).ToList(); if (listCandidateHis == null || listCandidateHis.Count == 0) { countAgree++; continue; } if (listCandidateHis != null && listCandidateHis.Count != 0) { var CandidateHistory = listCandidateHis.FirstOrDefault(); double month = 0; if (CandidateHistory.DateApply != null && item.DateApply != null) { month = (new DateTime(item.DateApply.Value.Subtract(CandidateHistory.DateApply.Value).Ticks).Year - 1) > 0 ? (new DateTime(item.DateApply.Value.Subtract(CandidateHistory.DateApply.Value).Ticks).Year - 1) : (item.DateApply.Value.Subtract(CandidateHistory.DateApply.Value).TotalDays / (365.25 / 12)); } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && month != valueDuration1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && month < valueDuration1) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && month > valueDuration1) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } } #endregion #region Kiểm tra Từ Tuổi if (Condition.ConditionName == ConditionName.E_AGE.ToString()) { // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.DateOfBirth == null) { countAgree++; continue; } //double AgeCadidate = DateTime.Now.Subtract(item.DateOfBirth).TotalDays / 365.242199; //AgeCadidate = Math.Round(AgeCadidate, 2); double? AgeCadidate = (new DateTime(DateTime.Now.Subtract(item.DateOfBirth).Ticks).Year - 1) > 0 ? (new DateTime(DateTime.Now.Subtract(item.DateOfBirth).Ticks).Year - 1) : (DateTime.Now.Subtract(item.DateOfBirth).TotalDays / 365.242199); double? valueAge = 0; try { valueAge = int.Parse(Condition.Value1); } catch { } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && AgeCadidate > 0) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && AgeCadidate >= valueAge) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && AgeCadidate <= valueAge) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && AgeCadidate == valueAge) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && AgeCadidate > 0) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && AgeCadidate <= valueAge) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && AgeCadidate >= valueAge) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && AgeCadidate != valueAge) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra Giới Tính if (Condition.ConditionName == ConditionName.E_GENDER.ToString()) { // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (string.IsNullOrEmpty(item.Gender)) { countAgree++; continue; } string valueGender = Condition.Value1; // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString()) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.Gender.Equals(valueGender)) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString()) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && !item.Gender.Equals(valueGender)) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm Tra Đã làm ở cty chưa if (Condition.ConditionName == ConditionName.E_ISTERMINATEINCOMPANY.ToString() && Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString()) { if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString()) { if (lstProfile != null && lstProfile.Count != 0) { // nếu có CMND thì ưu tiên kiểm tra trước if (!string.IsNullOrEmpty(item.IdentifyNumber)) { var Profile = lstProfile.FirstOrDefault(x => !string.IsNullOrEmpty(x.IDNo) && x.IDNo == item.IdentifyNumber); if (Profile == null) { countAgree++; continue; } } // nếu ko có CMND thì kiểm tra tên và ngày sinh else if (!string.IsNullOrEmpty(item.CandidateName) && item.DateOfBirth != null) { var Profile = lstProfile.FirstOrDefault(x => !string.IsNullOrEmpty(x.ProfileName) && x.DateOfBirth.HasValue && x.ProfileName == item.CandidateName && item.DateOfBirth == x.DateOfBirth.Value); if (Profile == null) { countAgree++; continue; } } else { ReasonFailFilter += Condition.ConditionName + ","; } } } else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString()) { if (lstProfile != null && lstProfile.Count != 0) { // nếu có CMND thì ưu tiên kiểm tra trước if (!string.IsNullOrEmpty(item.IdentifyNumber)) { var Profile = lstProfile.FirstOrDefault(x => !string.IsNullOrEmpty(x.IDNo) && x.IDNo == item.IdentifyNumber); if (Profile == null) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } // nếu ko có CMND thì kiểm tra tên và ngày sinh else if (!string.IsNullOrEmpty(item.CandidateName) && item.DateOfBirth != null) { var Profile = lstProfile.FirstOrDefault(x => !string.IsNullOrEmpty(x.ProfileName) && x.DateOfBirth.HasValue && x.ProfileName == item.CandidateName && item.DateOfBirth.Date == x.DateOfBirth.Value.Date); if (Profile == null) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } else { ReasonFailFilter += Condition.ConditionName + ","; } } } } #endregion #region Kiểm Tra Bệnh Loại Trừ if (Condition.ConditionName == ConditionName.E_DISEASEIDS.ToString()) { // nếu ko có bệnh thì qua if (string.IsNullOrEmpty(item.DiseaseListIDs)) { countAgree++; continue; } // nếu có chứa bệnh nào thì ko qua else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString()) { if (!string.IsNullOrEmpty(Condition.Value1)) { //lấy ds bệnh của đk tuyển var lstDiseaseCondition = Condition.Value1.Split(',').Select(x => x).ToList(); var lstsickbycondition = lstsick.Where(s => lstDiseaseCondition.Contains(Common.DotNetToOracle(s.ID.ToString()))).ToList(); // lấy ds mã bệnh của candidate - vì candidate lưu mã var lstDiseseCandidate = item.DiseaseListIDs.Split(',').ToList(); if (lstsickbycondition.Where(x => lstDiseseCandidate.Contains(x.Code)).Count() == 0) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } else if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString()) { if (!string.IsNullOrEmpty(Condition.Value1)) { //lấy ds bệnh của đk tuyển var lstDiseaseCondition = Condition.Value1.Split(',').Select(x => x).ToList(); var lstsickbycondition = lstsick.Where(s => lstDiseaseCondition.Contains(Common.DotNetToOracle(s.ID.ToString()))).ToList(); // lấy ds mã bệnh của candidate - vì candidate lưu mã var lstDiseseCandidate = item.DiseaseListIDs.Split(',').ToList(); if (lstsickbycondition.Where(x => lstDiseseCandidate.Contains(x.Code)).Count() != 0) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } } #endregion #region Kiểm tra điểm thi #region Điểm 1 if (Condition.ConditionName == ConditionName.E_SCORE1.ToString()) { if (lstInterview == null) { ReasonFailFilter += Condition.ConditionName + ","; continue; } var lstinterviewbyCandidate = lstInterview.Where(s => s.CandidateID == item.ID).ToList(); if (lstinterviewbyCandidate == null || (lstinterviewbyCandidate != null && lstinterviewbyCandidate.Count == 0)) { countAgree++; continue; } var interviewbyCan = lstinterviewbyCandidate.Where(s => s.LevelInterview == item.LevelInterview).OrderByDescending(s => s.DateUpdate).FirstOrDefault(); if (interviewbyCan == null) continue; double? valueScore1Condition = double.Parse(Condition.Value1); double? valueScore1 = interviewbyCan.Score1; // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString()) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueScore1 == valueScore1Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueScore1 > valueScore1Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueScore1 < valueScore1Condition) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString()) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueScore1 != valueScore1Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueScore1 < valueScore1Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueScore1 > valueScore1Condition) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Điểm 2 if (Condition.ConditionName == ConditionName.E_SCORE2.ToString()) { if (lstInterview == null) { ReasonFailFilter += Condition.ConditionName + ","; continue; } var lstinterviewbyCandidate = lstInterview.Where(s => s.CandidateID == item.ID).ToList(); if (lstinterviewbyCandidate == null || (lstinterviewbyCandidate != null && lstinterviewbyCandidate.Count == 0)) { countAgree++; continue; } var interviewbyCan = lstinterviewbyCandidate.Where(s => s.LevelInterview == item.LevelInterview).OrderByDescending(s => s.DateUpdate).FirstOrDefault(); if (interviewbyCan == null) continue; double? valueScore2Condition = double.Parse(Condition.Value1); double? valueScore2 = interviewbyCan.Score2; // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString()) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueScore2 == valueScore2Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueScore2 > valueScore2Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueScore2 < valueScore2Condition) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString()) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueScore2 != valueScore2Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueScore2 < valueScore2Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueScore2 > valueScore2Condition) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Điểm 3 if (Condition.ConditionName == ConditionName.E_SCORE3.ToString()) { if (lstInterview == null || lstInterview.Count == 0) { ReasonFailFilter += Condition.ConditionName + ","; continue; } var lstinterviewbyCandidate = lstInterview.Where(s => s.CandidateID == item.ID).ToList(); if (lstinterviewbyCandidate == null || (lstinterviewbyCandidate != null && lstinterviewbyCandidate.Count == 0)) { countAgree++; continue; } var interviewbyCan = lstinterviewbyCandidate.Where(s => s.LevelInterview == item.LevelInterview).OrderByDescending(s => s.DateUpdate).FirstOrDefault(); if (interviewbyCan == null) continue; double? valueScore3Condition = double.Parse(Condition.Value1); double? valueScore3 = interviewbyCan.Score3; // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString()) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueScore3 == valueScore3Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueScore3 > valueScore3Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueScore3 < valueScore3Condition) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString()) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && valueScore3 != valueScore3Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && valueScore3 < valueScore3Condition) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && valueScore3 > valueScore3Condition) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #endregion #region Kiểm tra Hệ Vận Động if (Condition.ConditionName == ConditionName.E_MUSCULOSKELETAL.ToString()) { double valuemusculoskeletal = 0; try { valuemusculoskeletal = double.Parse(Condition.Value1); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.Musculoskeletal == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && valuemusculoskeletal != 0 && item.Musculoskeletal.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.Musculoskeletal == valuemusculoskeletal) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.Musculoskeletal >= valuemusculoskeletal) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.Musculoskeletal <= valuemusculoskeletal) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && valuemusculoskeletal != 0 && item.Musculoskeletal.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.Musculoskeletal != valuemusculoskeletal) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.Musculoskeletal < valuemusculoskeletal) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.Musculoskeletal > valuemusculoskeletal) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra Huyết Áp if (Condition.ConditionName == ConditionName.E_BLOODPRESSURE.ToString()) { double bloodpressure = 0; try { bloodpressure = double.Parse(Condition.Value1); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.BloodPressure == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && bloodpressure != 0 && item.BloodPressure.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.BloodPressure == bloodpressure) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.BloodPressure >= bloodpressure) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.BloodPressure <= bloodpressure) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && bloodpressure != 0 && item.BloodPressure.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.BloodPressure != bloodpressure) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.BloodPressure < bloodpressure) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.BloodPressure > bloodpressure) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra Nhịp Tim if (Condition.ConditionName == ConditionName.E_HEARTBEAT.ToString()) { double heartbeat = 0; try { heartbeat = double.Parse(Condition.Value1); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.HeartBeat == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && heartbeat != 0 && item.HeartBeat.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.HeartBeat == heartbeat) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.HeartBeat >= heartbeat) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.HeartBeat <= heartbeat) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && heartbeat != 0 && item.HeartBeat.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && item.HeartBeat != heartbeat) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.HeartBeat < heartbeat) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.HeartBeat > heartbeat) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra Trình độ học vấn if (Condition.ConditionName == ConditionName.E_EDUCATIONLEVEL.ToString()) { if (item.EducationLevelID == null) { countAgree++; continue; } else { if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString()) { if (!string.IsNullOrEmpty(Condition.Value1)) { // Lấy list string mã trình độ học vấn var lstCodeEducationLevelOfCondition = Condition.Value1.Split(',').Select(x => x).ToList(); // lấy mã trình độ học vấn của Candidate var CodeEduOfCandidate = lstEducationLevel.Where(s => s.ID == item.EducationLevelID).Select(s => s.Code).FirstOrDefault(); if (lstCodeEducationLevelOfCondition.Contains(CodeEduOfCandidate)) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString()) { var lstEduCondition = Condition.Value1.Split(',').Select(x => x).ToList(); var CodeEduOfCandidate = lstEducationLevel.Where(s => s.ID == item.EducationLevelID).Select(s => s.Code).FirstOrDefault(); if (!lstEduCondition.Contains(CodeEduOfCandidate)) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } } #endregion #region Kiểm tra số năm kinh nghiệm if (Condition.ConditionName == ConditionName.E_YEAROFEXPERIENCE.ToString()) { double yearofexperienceFilter = 0; try { yearofexperienceFilter = double.Parse(Condition.Value1); } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.YearOfExperience == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && yearofexperienceFilter != 0 && item.YearOfExperience.HasValue) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && yearofexperienceFilter <= item.YearOfExperience) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && yearofexperienceFilter >= item.YearOfExperience) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && yearofexperienceFilter == item.YearOfExperience) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && item.YearOfExperience.HasValue && yearofexperienceFilter != 0) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_THAN.ToString() && item.YearOfExperience <= yearofexperienceFilter) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_LESS.ToString() && item.YearOfExperience >= yearofexperienceFilter) { countAgree++; continue; } if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && yearofexperienceFilter != item.YearOfExperience) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra tỉnh thường trú if (Condition.ConditionName == ConditionName.E_CANDIDATEP_PPROVINCE.ToString()) { if (item.PProvinceID == null) { countAgree++; continue; } else { if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString()) { if (!string.IsNullOrEmpty(Condition.Value1)) { // Lấy list string mã trình độ học vấn var lstCodeProvinceFilter = Condition.Value1.Split(',').Select(x => x).ToList(); // lấy mã trình độ học vấn của Candidate var codeProvinceCandidate = lstProvince.Where(s => s.ID == item.PProvinceID).Select(s => s.Code).FirstOrDefault(); if (lstCodeProvinceFilter.Contains(codeProvinceCandidate)) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString()) { var lstCodeProvinceFilter = Condition.Value1.Split(',').Select(x => x).ToList(); var codeProvinceCandidate = lstProvince.Where(s => s.ID == item.PProvinceID).Select(s => s.Code).FirstOrDefault(); if (!lstCodeProvinceFilter.Contains(codeProvinceCandidate)) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } } #endregion #region Kiểm tra chuyên ngành if (Condition.ConditionName == ConditionName.E_SPECIALISATION.ToString()) { string specialisationFilter = null; try { specialisationFilter = Condition.Value1; } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.Specialisation == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && specialisationFilter != null && item.Specialisation != null) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && specialisationFilter.ToLower() == item.Specialisation.ToLower()) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && specialisationFilter != null && item.Specialisation != null) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && specialisationFilter.ToLower() != item.Specialisation.ToLower()) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion #region Kiểm tra trường tốt nghiệp if (Condition.ConditionName == ConditionName.E_GRADUATESCHOOL.ToString()) { string schoolGraduateFilter = null; try { schoolGraduateFilter = Condition.Value1; } catch { } // nếu giá trị của ứng viên là null thì ko kiểm tra =>thỏa if (item.GraduateSchool == null) { countAgree++; continue; } // Điều kiện thỏa if (Condition.ConditionBrand == ConditionBrand.E_AGREEMENT.ToString() && schoolGraduateFilter != null && item.GraduateSchool != null) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && schoolGraduateFilter.ToLower() == item.GraduateSchool.ToLower()) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } //không thỏa else if (Condition.ConditionBrand == ConditionBrand.E_NOTAGREEMENT.ToString() && schoolGraduateFilter != null && item.GraduateSchool != null) { if (Condition.ValueType == HRM.Infrastructure.Utilities.ValueType.E_EQUAL.ToString() && schoolGraduateFilter.ToLower() != item.GraduateSchool.ToLower()) { countAgree++; continue; } else { ReasonFailFilter += Condition.ConditionName + ","; } } } #endregion } if (ReasonFailFilter != string.Empty) { ReasonFailFilter = ReasonFailFilter.Substring(0, ReasonFailFilter.Length - 1); item.ReasonFailFilter = ReasonFailFilter; } if (countAgree == countCondition) lstCandidateResultPass.Add(item); else lstCandidateResultFail.Add(item); } } // cap nhat status và history cho cadidate pass if (lstCandidateResultPass != null && lstCandidateResultPass.Count != 0) { var candidateservices = new Rec_CandidateServices(); var recruimenthistoryservices = new Rec_RecruitmentHistoryServices(); var ListIDsCadidate = lstCandidateResultPass.Select(x => x.ID).ToList(); var listCadidate = repoCadidate.FindBy(x => ListIDsCadidate.Contains(x.ID)).ToList(); //cập nhật status cho cadidate foreach (var item1 in listCadidate) { item1.Status = HRM.Infrastructure.Utilities.EnumDropDown.CandidateStatus.E_WAITINTERVIEW.ToString(); item1.PassFilterResume = true; if (lstrecruitmentHistory != null) { var listCandidateHis = lstrecruitmentHistory.Where(x => x.CandidateID == item1.ID).ToList(); if (listCandidateHis != null && listCandidateHis.Count != 0) { listCandidateHis = listCandidateHis.OrderByDescending(x => x.DateApply).ToList(); var objcandidatehis = listCandidateHis.FirstOrDefault(); objcandidatehis.PassFilterResume = true; objcandidatehis.Status = HRM.Infrastructure.Utilities.EnumDropDown.CandidateStatus.E_WAITINTERVIEW.ToString(); recruimenthistoryservices.Edit(objcandidatehis); } } candidateservices.Edit(item1); } repoRecruimentHistory.SaveChanges(); repoCadidate.SaveChanges(); } // cap nhat status và history cho cadidate fail if (lstCandidateResultFail != null && lstCandidateResultFail.Count != 0) { var candidateservices = new Rec_CandidateServices(); var recruimenthistoryservices = new Rec_RecruitmentHistoryServices(); var ListIDsCadidate = lstCandidateResultFail.Select(x => x.ID).ToList(); var listCadidate = repoCadidate.FindBy(x => ListIDsCadidate.Contains(x.ID)).ToList(); //cập nhật status cho cadidate foreach (var item1 in listCadidate) { //if() //item1.Status = HRM.Infrastructure.Utilities.EnumDropDown.CandidateStatus.E_FAIL.ToString(); var reasonbyCandidate = lstCandidateResultFail.Where(s => s.ID == item1.ID).FirstOrDefault(); item1.PassFilterResume = false; item1.Status = EnumDropDown.CandidateStatus.E_FAILFILTERRESUME.ToString(); item1.ReasonFailFilter = reasonbyCandidate != null ? reasonbyCandidate.ReasonFailFilter : null; if (lstrecruitmentHistory != null) { var listCandidateHis = lstrecruitmentHistory.Where(x => x.CandidateID == item1.ID).ToList(); if (listCandidateHis != null && listCandidateHis.Count != 0) { listCandidateHis = listCandidateHis.OrderByDescending(x => x.DateApply).ToList(); var objcandidatehis = listCandidateHis.FirstOrDefault(); objcandidatehis.PassFilterResume = false; objcandidatehis.Status = EnumDropDown.CandidateStatus.E_FAILFILTERRESUME.ToString(); recruimenthistoryservices.Edit(objcandidatehis); } } candidateservices.Edit(item1); } repoRecruimentHistory.SaveChanges(); repoCadidate.SaveChanges(); } } if (GetListFail) { return lstCandidateResultFail; } else { return lstCandidateResultPass; } }
/// <summary> /// [Tam.Le] - 20140726 - Lấy dữ liệu BC Trường Hợp Quẹt Thẻ Ở Hàng Ăn Không Tiêu Chuẩn /// </summary> /// <param name="CarteringIDs"></param> /// <param name="CanteenIDS"></param> /// <param name="LineIDS"></param> /// <param name="DateFrom"></param> /// <param name="DateTo"></param> /// <returns></returns> public List<Can_ReportCardNotStandEntity> ReportCardNotStand(List<int?> cateringIDs, List<int?> canteenIDs, List<int?> lineIDs, DateTime dateStart, DateTime dateEnd, List<int?> orgIDs) { DataTable datatable = CreateReportCardNotStandSchema(dateStart, dateEnd); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork); var mealRecords = repoCan_MealRecord.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd) .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount,s.MealAllowanceType }).ToList(); //var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList(); var codeAttendances = mealRecords.Select(s => s.CardCode).Distinct().ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => codeAttendances.Contains(s.CodeAttendance)) .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp,s.CodeAttendance }).ToList(); var repoCan_MealAllowanceTypeSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork); var mealAllowanceTypeSantandIDs = repoCan_MealAllowanceTypeSetting.FindBy(s => s.Standard == true) .Select(s => s.Id).ToList(); var repoCan_Line = new Can_LineRepository(unitOfWork); var lineHDTJobIDs = repoCan_Line.FindBy(s => s.LineHDTJOB != null) .Select(s => s.Id).ToList(); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); if (orgIDs != null) { profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); } //if (!isIncludeQuitEmp) //{ // profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList(); // profileIds = profiles.Select(s => s.ID).ToList(); // mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList(); //} if (canteenIDs != null) { mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList(); } if (cateringIDs != null) { mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList(); } if (lineIDs != null) { mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList(); } //for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) //{ // if (!table.Columns.Contains("Date" + date.Day)) // table.Columns.Add("Date" + date.Day, typeof(DateTime)); //} mealRecords = mealRecords.Where(s => s.MealAllowanceType != null && mealAllowanceTypeSantandIDs.Contains(s.MealAllowanceType) && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)).ToList(); profiles = profiles.Where(s => codeAttendances.Contains(s.CodeAttendance)).ToList(); var orgTypes = new List<Cat_OrgStructureType>(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); Can_ReportCardNotStandEntity reportCardNotStandEntity = null; List<Can_ReportCardNotStandEntity> lstreportCardNotStandEntity = new List<Can_ReportCardNotStandEntity>(); foreach (var profile in profiles) { reportCardNotStandEntity = new Can_ReportCardNotStandEntity(); int? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.Id == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); reportCardNotStandEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty; reportCardNotStandEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty; reportCardNotStandEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty; reportCardNotStandEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty; reportCardNotStandEntity.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; reportCardNotStandEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; reportCardNotStandEntity.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; reportCardNotStandEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty; reportCardNotStandEntity.CodeEmp = profile.CodeEmp; reportCardNotStandEntity.ProfileName = profile.ProfileName; //for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) //{ // var meal = mealRecords.FirstOrDefault(s => s.CardCode == profile.CodeAttendance && s.TimeLog == date); // if (meal != null) // { // //row["Date" + date.Day] = (object)meal.TimeLog ?? DBNull.Value; // } //} reportCardNotStandEntity.CountCard = mealRecords.Count(s => s.CardCode == profile.CodeAttendance); reportCardNotStandEntity.SumAmount = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).Sum(s => s.Amount); lstreportCardNotStandEntity.Add(reportCardNotStandEntity); } return lstreportCardNotStandEntity; } }
/// <summary> /// [Son.Vo] - 20140724 - BC Thanh Toán Trợ Cấp Ăn Ca Cho Nhân Viên /// </summary> /// <param name="CarteringIDs"></param> /// <param name="CanteenIDS"></param> /// <param name="LineIDS"></param> /// <param name="DateFrom"></param> /// <param name="DateTo"></param> /// <returns></returns> public List<Can_ReportAdjustmentMealAllowancePaymentEntity> ReportAdjustmentMealAllowancePayment(DateTime DateFrom, DateTime DateTo, List<int> lstProfileIDs) { #region GetData var lstMealRecord = new List<Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType, s.NoWorkDay }).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_MealRecordRepository(unitOfWork); lstMealRecord = repo.FindBy(m => m.TimeLog >= DateFrom || m.TimeLog <= DateTo && m.CardCode != null).Select( s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType, s.NoWorkDay }).ToList(); } var cardcode = lstMealRecord.Select(s => s.CardCode).Distinct().ToList(); var profiles = new List<Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Hre_ProfileRepository(unitOfWork); profiles = repo.FindBy(s => cardcode.Contains(s.CodeAttendance)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); } var mealAllowanceTypeSantandIDs = new List<Can_MealAllowanceTypeSetting>().Select(m=> m.Id).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_MealAllowanceTypeSettingRepository(unitOfWork); mealAllowanceTypeSantandIDs = repo.FindBy(s => s.Standard == true).Select(m=> m.Id).ToList(); } var lineHDTJobIDs = new List<Can_Line>().Select(m => m.Id).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_LineRepository(unitOfWork); lineHDTJobIDs = repo.FindBy(s => s.LineHDTJOB != null).Select(m => m.Id).ToList(); } var lines = new List<Can_Line>().ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_LineRepository(unitOfWork); lines = repo.GetAll().ToList(); } var lstOrgAll = new List<Cat_OrgStructure>().ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Cat_OrgStructureRepository(unitOfWork); lstOrgAll = repo.GetAll().ToList(); } #endregion List<Can_ReportAdjustmentMealAllowancePaymentEntity> lstReportAdjustmentMealAllowancePayment = new List<Can_ReportAdjustmentMealAllowancePaymentEntity>(); foreach (var profile in profiles) { Can_ReportAdjustmentMealAllowancePaymentEntity ReportAdjustmentMealAllowancePayment = new Can_ReportAdjustmentMealAllowancePaymentEntity(); var orgbyprofile = lstOrgAll.Where(m => m.Id == profile.OrgStructureID).Select(m => m.OrgStructureName).FirstOrDefault(); ReportAdjustmentMealAllowancePayment.CodeEmp = profile.CodeEmp; ReportAdjustmentMealAllowancePayment.ProfileName = profile.ProfileName; ReportAdjustmentMealAllowancePayment.OrgStructureName = orgbyprofile; var mealProfiles = lstMealRecord.Where(s => s.CardCode == profile.CodeAttendance).ToList(); if (mealProfiles.Count > 0) { var line = lines.FirstOrDefault(s => s.Id == mealProfiles[0].LineID); if (line != null) { ReportAdjustmentMealAllowancePayment.TotalAdditionalAmount = mealProfiles.Count * line.Amount; } ReportAdjustmentMealAllowancePayment.TotalMealTime = mealProfiles.Where(m => m.MealAllowanceType != null && mealAllowanceTypeSantandIDs.Contains(m.MealAllowanceType)).Count(); ReportAdjustmentMealAllowancePayment.TotalDeductionAmount = mealProfiles.Where(m => m.MealAllowanceType != null && mealAllowanceTypeSantandIDs.Contains(m.MealAllowanceType)).Sum(m => m.Amount.Value); var countCardMore1 = 0; double? AmountSubtractCardMore1 = 0; for (DateTime date = DateFrom; date <= DateTo; date = date.AddDays(1)) { if (mealProfiles.Count(s => s.TimeLog == date) > 1) { countCardMore1++; var meal = mealProfiles.FirstOrDefault(s => s.TimeLog == date); if (meal != null) { AmountSubtractCardMore1 += meal.Amount; } } } ReportAdjustmentMealAllowancePayment.TotalScanManyTime = countCardMore1; ReportAdjustmentMealAllowancePayment.TotalDeductionScanManyTime = AmountSubtractCardMore1.Value; ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatTime = mealProfiles.Count(s => s.NoWorkDay == true); ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatAmount = mealProfiles.Sum(s => s.Amount.Value); ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatAmount = mealProfiles.Sum(s => s.Amount.Value); } lstReportAdjustmentMealAllowancePayment.Add(ReportAdjustmentMealAllowancePayment); } return lstReportAdjustmentMealAllowancePayment; }
public DataTable ReportMealAllowanceOfEmployee(List<Guid?> lstMealAllowanceTypeSettingID, DateTime dateStart, DateTime dateEnd, List<Guid> lstProfileIds, List<Guid?> workPlaceIds, Boolean isCludeEmpQuit) { DataTable datatable = CreateReportMealAllowanceOfEmployeeSchema(); using (var context = new VnrHrmDataContext()) { //DateTime dateEnd = dateEnd.AddDays(1).AddMilliseconds(-1); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); string typeApprove = MealRecordMissingStatus.E_APPROVED.ToString(); string typeWaitApprove = MealRecordMissingStatus.E_WAIT_APPROVED.ToString(); var repoMealRecordMissing = new Can_MealRecordMissingRepository(unitOfWork); var lstMealRecordMiss = repoMealRecordMissing.FindBy(m => lstProfileIds.Contains(m.ProfileID.Value) && (m.Status == typeApprove || m.Status == typeWaitApprove) && m.WorkDate >= dateStart && m.WorkDate <= dateEnd).OrderBy(m => m.ProfileID).ThenBy(m => m.WorkDate).ToList(); var profileIDs = lstMealRecordMiss.Select(hre => hre.ProfileID.Value).Distinct().ToList(); var repoProfile = new Hre_ProfileRepository(unitOfWork); var profiles = repoProfile.FindBy(m => profileIDs.Contains(m.ID)).ToList(); //tất cả phòng ban và loại trợ cấp var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var lstOrgAll = repoCat_OrgStructure.FindBy(og => og.IsDelete == null).ToList(); var repoTypeMealAllSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork); var lstTypeMealAllSetting = repoTypeMealAllSetting.GetAll().ToList(); //ds Att_Workday và ca làm việc var repoAttWorkday = new Att_WorkDayRepository(unitOfWork); var workDays = repoAttWorkday.FindBy(wd => dateStart <= wd.WorkDate && wd.WorkDate <= dateEnd && profileIDs.Contains(wd.ProfileID)) .Select(wd => new { wd.ProfileID, wd.ShiftID, wd.WorkDate, wd.InTime1, wd.OutTime1, wd.ShiftActual, wd.ShiftApprove }).ToList(); var repoShift = new Cat_ShiftRepository(unitOfWork); var lstShiftAll = repoShift.GetAll().ToList(); if (lstProfileIds != null && lstProfileIds.Count >= 1) { profiles = profiles.Where(s => lstProfileIds.Contains(s.ID)).ToList(); } if (workPlaceIds != null && workPlaceIds[0] != null) { profiles = profiles.Where(s => workPlaceIds.Contains(s.WorkPlaceID)).ToList(); } if (isCludeEmpQuit != true) { profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList(); } lstProfileIds = profiles.Select(s => s.ID).ToList(); //ds ko quẹt thẻ theo loại trợ cấp if (lstMealAllowanceTypeSettingID[0] != Guid.Empty) { lstMealRecordMiss = lstMealRecordMiss.Where(m => m.MealAllowanceTypeSettingID != null && lstMealAllowanceTypeSettingID.Contains(m.MealAllowanceTypeSettingID.Value)).ToList(); } var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); foreach (var recordmiss in lstMealRecordMiss) { if (recordmiss == null) continue; var profile = profiles.FirstOrDefault(s => s.ID == recordmiss.ProfileID); if (profile == null) continue; DataRow row = datatable.NewRow(); var orgId = lstOrgAll.Where(s => s.ID == recordmiss.OrgStructureID).Select(og => og.ID).FirstOrDefault(); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, lstOrgAll, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, lstOrgAll, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, lstOrgAll, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, lstOrgAll, orgTypes); row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeDepartment] = orgOrg != null ? orgOrg.Code : string.Empty; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.ProfileName] = profile.ProfileName; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DateExport] = DateTime.Now; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DateFrom] = dateStart; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DateTo] = dateEnd; var mealAllowance = lstTypeMealAllSetting.FirstOrDefault(m => m.ID == recordmiss.MealAllowanceTypeSettingID); row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.MealAllowance] = mealAllowance != null ? mealAllowance.MealAllowanceTypeSettingName : string.Empty; var attworkday = workDays.FirstOrDefault(at => at.ProfileID == profile.ID && at.WorkDate == recordmiss.WorkDate); if (attworkday != null) { var shiftActual = lstShiftAll.FirstOrDefault(sf => sf.ID == attworkday.ShiftActual); row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.ShiftActual] = shiftActual != null ? shiftActual.ShiftName : string.Empty; var shiftApprove = lstShiftAll.FirstOrDefault(sf => sf.ID == attworkday.ShiftApprove); row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.ShiftApprove] = shiftApprove != null ? shiftApprove.ShiftName : string.Empty; } row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.Date] = recordmiss.WorkDate; row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.Status] = recordmiss.Status; datatable.Rows.Add(row); } } return datatable; }
public string SetBlackListProfile(string selectedIds) { using (var context = new VnrHrmDataContext()) { BaseService service = new BaseService(); string message = string.Empty; string status = string.Empty; var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoProfile = new Hre_ProfileRepository(unitOfWork); List<Guid> ProfileIds = selectedIds.Split(',').Select(x => Guid.Parse(x)).ToList(); var lstProfiles = repoProfile.FindBy(m => m.ID != null && ProfileIds.Contains(m.ID)).ToList(); foreach (var profile in lstProfiles) { profile.IsBlackList = true; } repoProfile.SaveChanges(); message = NotificationType.Success.ToString(); return message; } }
public DataTable ReportDetailCard(List<Guid?> cateringIDs, List<Guid?> canteenIDs, List<Guid?> lineIDs, DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs) { DataTable datatable = CreateReportDetailCardSchema(dateStart, dateEndSearch); using (var context = new VnrHrmDataContext()) { #region get data DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork); var mealRecords = repoCan_MealRecord.FindBy(s => s.ProfileID != null && s.WorkDay != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).Select(s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.WorkDay }).ToList(); if (mealRecords != null && mealRecords.Count < 1) { return datatable; } var profileIdsByMealRecord = mealRecords.Select(s => s.ProfileID).Distinct().ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => profileIdsByMealRecord.Contains(s.ID)).ToList(); var repoCan_Line = new Can_LineRepository(unitOfWork); var repoCan_Canteen = new Can_CanteenRepository(unitOfWork); var repoCan_Catering = new Can_CateringRepository(unitOfWork); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); var lstallLine = repoCan_Line.GetAll().ToList(); var lstallCatering = repoCan_Catering.GetAll().ToList(); var lstallCanteen = repoCan_Canteen.GetAll().ToList(); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); if (orgIDs != null && orgIDs[0] != null) { profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); } if (canteenIDs != null && canteenIDs[0] != null) { mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList(); } if (cateringIDs != null && cateringIDs[0] != null) { mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList(); } if (lineIDs != null && lineIDs[0] != null) { mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList(); } if (mealRecords == null && mealRecords.Count < 1) { return datatable; } #endregion foreach (var profile in profiles) { var mealRecordByProfile = mealRecords.Where(m => m.ProfileID != null && m.ProfileID.Value == profile.ID).ToList(); if (mealRecordByProfile == null && mealRecordByProfile.Count() == 0) continue; for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var lstMealByPro = mealRecords.Where(m => m.ProfileID == profile.ID && m.TimeLog != null && m.TimeLog.Value.Date == date.Date).ToList(); foreach (var MealByPro in lstMealByPro) { if (MealByPro != null) { DataRow row = datatable.NewRow(); var profilebymeal = repoHre_Profile.FindBy(m => m.ID == MealByPro.ProfileID).FirstOrDefault(); Guid? orgId = profilebymeal.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profilebymeal.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes); row[Can_ReportDetailCardEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Can_ReportDetailCardEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Can_ReportDetailCardEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Can_ReportDetailCardEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Can_ReportDetailCardEntity.FieldNames.CodeEmp] = profilebymeal.CodeEmp; row[Can_ReportDetailCardEntity.FieldNames.ProfileName] = profilebymeal.ProfileName; if (MealByPro.WorkDay != null) { row["Data" + date.Day] = MealByPro.WorkDay.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime); } var line = lstallLine.Where(m => MealByPro.LineID == m.ID).FirstOrDefault(); row[Can_ReportDetailCardEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty; var catering = lstallCatering.Where(m => MealByPro.CateringID == m.ID).FirstOrDefault(); row[Can_ReportDetailCardEntity.FieldNames.CateringName] = catering != null ? catering.CateringName : string.Empty; var canteen = lstallCanteen.Where(m => MealByPro.CanteenID == m.ID).FirstOrDefault(); row[Can_ReportDetailCardEntity.FieldNames.CanteenName] = canteen != null ? canteen.CanteenName : string.Empty; row[Can_ReportDetailCardEntity.FieldNames.DateFrom] = dateStart; row[Can_ReportDetailCardEntity.FieldNames.DateTo] = dateEnd; row[Can_ReportDetailCardEntity.FieldNames.DatePrint] = DateTime.Now; datatable.Rows.Add(row); } } } } return datatable; } }
public DataTable ReportMealTimeDetail(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs) { using (var context = new VnrHrmDataContext()) { DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1); DataTable datatable = CreateReportMealTimeDetailSchema(dateStart, dateEnd); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoMealRecord = new Can_MealRecordRepository(unitOfWork); var repoLine = new Can_LineRepository(unitOfWork); var lineHDTJobIDs = repoLine.FindBy(s => s.HDTJ != null).Select(s => s.ID).ToList(); var mealRecords = repoMealRecord.FindBy(s => s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value) && s.ProfileID != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).ToList(); if (mealRecords.Count < 1) { return datatable; } var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList(); var repoWorkDay = new Att_WorkDayRepository(unitOfWork); var workDayProfies = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd && profileIds.Contains(s.ProfileID)).ToList(); var repoProfile = new Hre_ProfileRepository(unitOfWork); var profiles = repoProfile.FindBy(s => profileIds.Contains(s.ID)).ToList(); var repoLeaveday = new Att_LeavedayRepository(unitOfWork); var leavedays = repoLeaveday.FindBy(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && profileIds.Contains(s.ProfileID)). Select(s => new { s.ProfileID, s.DateStart, s.DateEnd, s.LeaveDayTypeID }).ToList(); var repoleaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var leaveDayTypes = repoleaveDayType.GetAll().Select(s => new { s.ID, s.LeaveDayTypeName }).ToList(); List<Cat_OrgStructure> orgs = new List<Cat_OrgStructure>(); var repoOrg = new Cat_OrgStructureRepository(unitOfWork); orgs = repoOrg.FindBy(s => s.Code != null).ToList(); if (orgIDs != null && orgIDs.Count > 0) { profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); } if (CanteenIDS != null && CanteenIDS[0] != null) { mealRecords = mealRecords.Where(s => s.CanteenID != null && CanteenIDS.Contains(s.CanteenID.Value)).ToList(); } if (CarteringIDs != null && CarteringIDs[0] != null) { mealRecords = mealRecords.Where(s => s.CateringID != null && CarteringIDs.Contains(s.CateringID.Value)).ToList(); } if (LineIDS != null && LineIDS[0] != null) { mealRecords = mealRecords.Where(s => s.LineID != null && LineIDS.Contains(s.LineID.Value)).ToList(); } if (mealRecords.Count < 1) { return datatable; } profileIds = mealRecords.Select(s => s.ProfileID.Value).ToList(); profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList(); var orgTypes = new List<Cat_OrgStructureType>(); var repoorgType = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repoorgType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); var repoCanteen = new Can_CanteenRepository(unitOfWork); var repoCatering = new Can_CateringRepository(unitOfWork); var canteens = repoCanteen.GetAll().ToList(); var caterings = repoCatering.GetAll().ToList(); var lines = repoLine.GetAll().ToList(); #region Code Cũ //foreach (var profile in profiles) //{ // var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.Id).Select(s => s.WorkDate.Date).ToList(); // for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) // { // var record = mealRecords.FirstOrDefault(s => s.ProfileID == profile.Id && date == s.TimeLog.Date && !workdayProfileDates.Contains(date.Date)); // if (record != null) // { // DataRow row = datatable.NewRow(); // int? orgId = profile.OrgStructureID; // var org = orgs.FirstOrDefault(s => s.Id == profile.OrgStructureID); // var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); // var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); // var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); // var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); // row[Can_ReportMealTimeDetailEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; // row[Can_ReportMealTimeDetailEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; // row[Can_ReportMealTimeDetailEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; // row[Can_ReportMealTimeDetailEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; // row[Can_ReportMealTimeDetailEntity.FieldNames.CodeEmp] = profile.CodeEmp; // row[Can_ReportMealTimeDetailEntity.FieldNames.ProfileName] = profile.ProfileName; // var line = repoLine.FindBy(m => record.LineID == m.Id).FirstOrDefault(); // var canteen = repoCanteen.FindBy(m => record.CanteenID == m.Id).FirstOrDefault(); // var catering = repoCatering.FindBy(m => record.CateringID == m.Id).FirstOrDefault(); // row[Can_ReportMealTimeDetailEntity.FieldNames.CateringName] = catering != null ? catering.CateringName : null; // row[Can_ReportMealTimeDetailEntity.FieldNames.CanteenName] = canteen != null ? canteen.CanteenName : null; // row[Can_ReportMealTimeDetailEntity.FieldNames.LineName] = line != null ? line.LineName : null; // row[Can_ReportMealTimeDetailEntity.FieldNames.DateFrom] = dateStart; // row[Can_ReportMealTimeDetailEntity.FieldNames.DateTo] = dateEnd; // row[Can_ReportMealTimeDetailEntity.FieldNames.DatePrint] = DateTime.Now; // if (record.TimeLog != null) // { // row["Data" + date.Day] = record.TimeLog.ToString(ConstantFormat.HRM_Format_Grid_ShortTime); // } // datatable.Rows.Add(row); // } // } //} #endregion foreach (var profile in profiles) { var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID && (s.FirstInTime != null || s.LastOutTime != null)).Select(s => s.WorkDate.Date).ToList(); var mealRecordProfiles = mealRecords.Where(s => s.ProfileID == profile.ID).ToList(); for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var leaday = leavedays.FirstOrDefault(s => s.DateStart != null && s.DateEnd != null && s.ProfileID == profile.ID && s.DateStart.Date <= date.Date && date.Date <= s.DateEnd.Date); var record = mealRecordProfiles.FirstOrDefault(s => date.Date == s.WorkDay.Value.Date && (!workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null)); if (record != null) { DataRow row = datatable.NewRow(); Guid? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes); row[Can_ReportMealTimeDetailEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Can_ReportMealTimeDetailEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Can_ReportMealTimeDetailEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Can_ReportMealTimeDetailEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Can_ReportMealTimeDetailEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Can_ReportMealTimeDetailEntity.FieldNames.ProfileName] = profile.ProfileName; row[Can_ReportMealTimeDetailEntity.FieldNames.Date] = record.WorkDay; row[Can_ReportMealTimeDetailEntity.FieldNames.DateFrom] = dateStart; row[Can_ReportMealTimeDetailEntity.FieldNames.DateTo] = dateEnd; var cate = caterings.FirstOrDefault(s => s.ID == record.CateringID); var cateen = canteens.FirstOrDefault(s => s.ID == record.CanteenID); var line = lines.FirstOrDefault(s => s.ID == record.LineID); row[Can_ReportMealTimeDetailEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ; row[Can_ReportMealTimeDetailEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ; row[Can_ReportMealTimeDetailEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty; if (record.TimeLog != null) { row["Data" + record.WorkDay.Value.Day] = record.TimeLog == null ? null : (object)record.TimeLog.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime) ?? DBNull.Value; } row[Can_ReportMealTimeDetailEntity.FieldNames.DatePrint] = DateTime.Now; if (leaday != null) { var leadayType = leaveDayTypes.FirstOrDefault(s => s.ID == leaday.LeaveDayTypeID); row[Can_ReportMealTimeDetailEntity.FieldNames.LeaveDayTypeName] = leadayType != null ? leadayType.LeaveDayTypeName : string.Empty; } datatable.Rows.Add(row); } } } return datatable; } }
public DataTable ReportCardNotStand(List<Guid?> cateringIDs, List<Guid?> canteenIDs, List<Guid?> lineIDs, DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs) { DataTable datatable = CreateReportCardNotStandSchema(dateStart, dateEndSearch); using (var context = new VnrHrmDataContext()) { DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork); var mealRecords = repoCan_MealRecord.FindBy(s => s.ProfileID != null && s.WorkDay != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd) .Select(s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.WorkDay }).ToList(); if (mealRecords.Count < 1) { return datatable; } var Profileids = mealRecords.Select(s => s.ProfileID).ToList(); var repoProfile = new Hre_ProfileRepository(unitOfWork); var profiles = repoProfile.FindBy(s => Profileids.Contains(s.ID)).ToList(); var profileIdsByMealrecords = mealRecords.Where(m => m.ProfileID != null).Select(s => s.ProfileID.Value).ToList(); var amountByMealrecords = mealRecords.Select(m => m.Amount).Distinct().ToList(); var repoWorkDay = new Att_WorkDayRepository(unitOfWork); var workDayProfies = repoWorkDay.FindBy(s => s.ProfileID != null && s.WorkDate != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd && profileIdsByMealrecords.Contains(s.ProfileID)).ToList(); var repoAllowanceType = new Can_MealAllowanceTypeSettingRepository(unitOfWork); var mealAllowanceTypeStandard = repoAllowanceType.FindBy(s => s.Standard == true).FirstOrDefault(); var amountStandar = mealAllowanceTypeStandard != null ? mealAllowanceTypeStandard.Amount : null; var repoline = new Can_LineRepository(unitOfWork); var lineHDTJobIDs = repoline.FindBy(s => s.HDTJ != null).Select(s => s.ID).ToList(); var linIdNotAmoutStardands = repoline.FindBy(s => s.Amount != amountStandar).Select(s => s.ID).ToList(); var repoOrgs = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoOrgs.FindBy(s => s.Code != null).ToList(); if (orgIDs != null && orgIDs[0] != null) { profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); } if (canteenIDs != null && canteenIDs[0] != null) { mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList(); } if (cateringIDs != null && cateringIDs[0] != null) { mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList(); } if (lineIDs != null && lineIDs[0] != null) { mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList(); } if (linIdNotAmoutStardands.Count > 0) { mealRecords = mealRecords.Where(s => s.LineID != null && linIdNotAmoutStardands.Contains(s.LineID.Value)).ToList(); } if (lineHDTJobIDs.Count > 0) { mealRecords = mealRecords.Where(s => s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)).ToList(); } if (mealRecords.Count < 1) { return datatable; } var repocanteen = new Can_CanteenRepository(unitOfWork); var canteens = repocanteen.GetAll().ToList(); var repocatering = new Can_CateringRepository(unitOfWork); var caterings = repocatering.GetAll().ToList(); var lines = repoline.GetAll().ToList(); var orgTypes = new List<Cat_OrgStructureType>(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); var approve = LeaveDayStatus.E_APPROVED.ToString(); var repoleavedays = new Att_LeavedayRepository(unitOfWork); var leavedays = repoleavedays.FindBy(s => s.Status == approve && dateStart <= s.DateEnd && s.DateStart <= dateEnd && profileIdsByMealrecords.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList(); foreach (var profile in profiles) { var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList(); var dateLeveDays = new List<DateTime>(); for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var leaveDay = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd); if (leaveDay != null) { dateLeveDays.Add(date.Date); } } for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var leaveDay = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd); var meal = mealRecords.FirstOrDefault(s => s.ProfileID == profile.ID && s.TimeLog != null && s.WorkDay != null && s.TimeLog.Value.Date == date.Date && workdayProfileDates.Contains(s.WorkDay.Value.Date) && leaveDay == null); if (meal != null) { DataRow row = datatable.NewRow(); Guid? orgId = profile != null ? profile.OrgStructureID : null; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes); row[Can_ReportCardNotStandEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Can_ReportCardNotStandEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Can_ReportCardNotStandEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Can_ReportCardNotStandEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Can_ReportCardNotStandEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Can_ReportCardNotStandEntity.FieldNames.ProfileName] = profile.ProfileName; row[Can_ReportCardNotStandEntity.FieldNames.DateFrom] = dateStart; row[Can_ReportCardNotStandEntity.FieldNames.DateTo] = dateEnd; row[Can_ReportCardNotStandEntity.FieldNames.DatePrint] = DateTime.Now; var cate = caterings.FirstOrDefault(s => s.ID == meal.CateringID); var cateen = canteens.FirstOrDefault(s => s.ID == meal.CanteenID); var line = lines.FirstOrDefault(s => s.ID == meal.LineID); if (meal.WorkDay != null) { row["Data" + date.Day] = meal.WorkDay.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime); } row[Can_ReportCardNotStandEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ; row[Can_ReportCardNotStandEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ; row[Can_ReportCardNotStandEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty; var countcard = mealRecords.Count(s => s.WorkDay != null && s.ProfileID == profile.ID && workdayProfileDates.Contains(s.WorkDay.Value.Date) && !dateLeveDays.Contains(s.WorkDay.Value.Date)); if (countcard != null) { row[Can_ReportCardNotStandEntity.FieldNames.CountCard] = countcard; var SumAmount = mealRecords.Where(s => s.WorkDay != null && s.ProfileID == profile.ID && workdayProfileDates.Contains(s.WorkDay.Value.Date) && !dateLeveDays.Contains(s.WorkDay.Value.Date)).Sum(s => s.Amount) - countcard * amountStandar; row[Can_ReportCardNotStandEntity.FieldNames.SumAmount] = SumAmount; } datatable.Rows.Add(row); } } } return datatable; } }
public bool SaveSumryMealRecord(Guid CutOffDurationID, List<Guid> lstProfileIDs) { using (var context = new VnrHrmDataContext()) { try { #region GetData List<Can_ReportAdjustmentMealAllowancePaymentEntity> lstReportAdjustmentMealAllowancePayment = new List<Can_ReportAdjustmentMealAllowancePaymentEntity>(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoMealRecord = new Can_MealRecordRepository(unitOfWork); var cutoffdurationRepository = new Att_CutOffDurationRepository(unitOfWork); var Cutoffduration = cutoffdurationRepository.FindBy(m => m.ID == CutOffDurationID && m.IsDelete != true).FirstOrDefault(); DateTime DateFrom = new DateTime(); DateTime DateTo = new DateTime(); if (Cutoffduration != null) { DateFrom = Cutoffduration.DateStart; DateTo = Cutoffduration.DateEnd.AddDays(1).AddMilliseconds(-1); } var sumryMealRecordRepository = new Can_SumryMealRecordRepository(unitOfWork); var lstMealRecord = repoMealRecord.FindBy(m => m.WorkDay != null && m.WorkDay >= DateFrom && m.WorkDay <= DateTo && m.ProfileID != null) .Select(s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.NoWorkDay }).ToList(); if (lstMealRecord.Count < 0) { return true; } var status = StatusMealAllowanceToMoney.E_APPROVED.ToString(); #region Dư ko dùng //var repoAllowanceToMoney = new Can_MealAllowanceToMoneyRepository(unitOfWork); //var mealAllowncaToMoneyProfileIDs = repoAllowanceToMoney.FindBy(s => s.Status == status && s.ProfileID != null && DateFrom <= s.DateTo && s.DateFrom <= DateTo).ToList(); #endregion var lstProfileIdsByMeal = lstMealRecord.Select(s => s.ProfileID).Distinct().ToList(); var repoprofiles = new Hre_ProfileRepository(unitOfWork); var profiles = repoprofiles.FindBy(s => lstProfileIdsByMeal.Contains(s.ID)).Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); if (lstProfileIDs != null && lstProfileIDs.Count > 0) { profiles = profiles.Where(m => lstProfileIDs.Contains(m.ID)).ToList(); } var repomealAllowanceType = new Can_MealAllowanceTypeSettingRepository(unitOfWork); var mealAllowanceTypeSantandIDs = repomealAllowanceType.FindBy(s => s.Standard == true).Select(m => m.ID).ToList(); var mealAllowanceTypes = repomealAllowanceType.FindBy(s => s.IsDelete == null).ToList(); var amountStardand = repomealAllowanceType.FindBy(s => s.Standard == true && s.Amount != null).Select(s => s.Amount.Value).FirstOrDefault(); var repoLineHDTJob = new Can_LineRepository(unitOfWork); var lineHDTJobIDs = repoLineHDTJob.FindBy(s => s.HDTJ != null).Select(m => m.ID).ToList(); var repoHDTJob = new Hre_HDTJobRepository(unitOfWork); var profileHDTJs = repoHDTJob.FindBy(s => DateFrom <= s.DateTo && s.DateFrom <= DateTo) .Select(s => new { s.ProfileID, s.Type, s.DateFrom, s.DateTo }).ToList(); var profileHDTJIDs = profileHDTJs.Select(s => s.ProfileID).Distinct().ToList(); string approveKey = MealRecord_Status.E_APPROVED.ToString(); var repo_MealRecordMissing = new Can_MealRecordMissingRepository(unitOfWork); var mealRecordMissings = repo_MealRecordMissing.FindBy(s => s.Status == approveKey && DateFrom <= s.WorkDate && s.WorkDate <= DateTo) .Select(s => new { s.ProfileID, s.WorkDate, s.MealAllowanceTypeSettingID, s.TamScanReasonMissID, s.Amount }).ToList(); var repoWorkDay = new Att_WorkDayRepository(unitOfWork); var dateStart1 = DateFrom.AddDays(-1); var workDays = repoWorkDay.FindBy(s => dateStart1 <= s.WorkDate && s.WorkDate <= DateTo).Select(s => new { s.ProfileID, s.FirstInTime, s.LastOutTime, s.ShiftID, s.WorkDate }).ToList(); var workDayProfies = workDays.Where(s => s.FirstInTime != null || s.LastOutTime != null).ToList(); var repotamScan = new Cat_TAMScanReasonMissRepository(unitOfWork); var tamSans = repotamScan.GetAll().ToList(); var tamScanNotFullPayIDs = tamSans.Where(s => s.IsFullPay == null || s.IsFullPay == false).Select(s => s.ID).ToList(); var reposhift = new Cat_ShiftRepository(unitOfWork); var shifts = reposhift.GetAll().ToList(); var lines = new List<Can_Line>().ToList(); var repolines = new Can_LineRepository(unitOfWork); lines = repolines.GetAll().ToList(); var repoOrg = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoOrg.GetAll().ToList(); var orgTypes = new List<Cat_OrgStructureType>(); var repoorgType = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repoorgType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); #endregion foreach (var profile in profiles) { var mealProfiles = lstMealRecord.Where(s => s.ProfileID == profile.ID).ToList(); #region Dư ko dùng //var mealAllownProfiles = mealAllowncaToMoneyProfileIDs.Where(s => s.ProfileID == profile.ID).ToList(); //var mealNotStardands = lstMealRecord.Where(s => s.ProfileID == profile.ID && s.Amount > amountStardand).ToList(); #endregion Can_ReportAdjustmentMealAllowancePaymentEntity ReportAdjustmentMealAllowancePayment = new Can_ReportAdjustmentMealAllowancePaymentEntity(); Guid? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes); ReportAdjustmentMealAllowancePayment.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; ReportAdjustmentMealAllowancePayment.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; ReportAdjustmentMealAllowancePayment.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; ReportAdjustmentMealAllowancePayment.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty; ReportAdjustmentMealAllowancePayment.CodeEmp = profile.CodeEmp; ReportAdjustmentMealAllowancePayment.ProfileName = profile.ProfileName; ReportAdjustmentMealAllowancePayment.DateFrom = DateFrom; ReportAdjustmentMealAllowancePayment.DateTo = DateTo; ReportAdjustmentMealAllowancePayment.DatePrint = DateTime.Now; var countCard = 0; var sumCard = 0.0; int countCardMore1 = 0; var countNotWorkButHasEat = 0; var sumNotWorkButHasEat = 0.0; var countmealNotStardand = 0; var amountmealNotStardand = 0.0; var countHDTJ = 0; var amountHDTJ = 0.0; var countNotStandHDTJ = 0; var amountNotStandHDTJ = 0.0; int amount3OnMonth = 0; var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList(); for (DateTime date = DateFrom; date <= DateTo; date = date.AddDays(1)) { var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Date == date.Date); var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID); var missing = mealRecordMissings.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Value.Date == date.Date); if (missing != null) { if (missing.MealAllowanceTypeSettingID != null && missing.TamScanReasonMissID == null) { countCard++; sumCard += (double)(missing.Amount != null ? missing.Amount.Value : 0); } else if (missing.TamScanReasonMissID != null) { var tamscan = tamSans.FirstOrDefault(s => s.ID == missing.TamScanReasonMissID); if (tamscan != null) { if (tamscan.IsFullPay == true) { countCard++; sumCard += (double)amountStardand; } else { amount3OnMonth++; } } } } if (mealProfiles.Count(s => s.TimeLog != null && s.TimeLog.Value.Date == date.Date) > 1) { countCardMore1++; } var record = lstMealRecord.FirstOrDefault(s => s.TimeLog != null && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value) && s.ProfileID == profile.ID && date.Date == s.TimeLog.Value.Date && !workdayProfileDates.Contains(date.Date)); if (record != null) { countNotWorkButHasEat++; sumNotWorkButHasEat += (double)(record.Amount != null ? record.Amount.Value : 0); } var meal = lstMealRecord.FirstOrDefault(s => s.TimeLog != null && s.Amount > amountStardand && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value) && s.ProfileID == profile.ID && s.TimeLog.Value.Date == date.Date && workdayProfileDates.Contains(date.Date)); if (meal != null) { countmealNotStardand++; amountmealNotStardand += (double)(meal.Amount != null ? meal.Amount.Value : 0); } var mealHDT = lstMealRecord.FirstOrDefault(s => s.ProfileID == profile.ID && s.LineID != null && lineHDTJobIDs.Contains(s.LineID.Value) && s.TimeLog != null && s.TimeLog.Value.Date == date.Date && (!profileHDTJIDs.Contains(s.ProfileID.Value) || (profileHDTJIDs.Contains(s.ProfileID.Value) && !workdayProfileDates.Contains(date.Date)))); if (mealHDT != null) { countHDTJ++; amountHDTJ += (double)(mealHDT.Amount != null ? mealHDT.Amount.Value : 0); } var mealNotStandandHDT = lstMealRecord.FirstOrDefault(s => s.ProfileID != null && s.ProfileID == profile.ID && s.LineID != null && lineHDTJobIDs.Contains(s.LineID.Value) && s.TimeLog != null && s.TimeLog.Value.Date == date.Date && profileHDTJIDs.Contains(s.ProfileID.Value) && workdayProfileDates.Contains(date.Date)); if (mealNotStandandHDT != null && mealNotStandandHDT.LineID != null) { var line = lines.FirstOrDefault(s => s.ID == mealNotStandandHDT.LineID); var hdtjob = profileHDTJs.FirstOrDefault(s => s.Type != null && s.ProfileID == profile.ID && s.DateFrom.Value.Date <= date.Date && date.Date <= s.DateTo.Value.Date); if (line != null && line.HDTJ != null && hdtjob.Type != line.HDTJ) { var lineHDT = lines.FirstOrDefault(s => s.HDTJ == hdtjob.Type); if (lineHDT != null && lineHDT.Amount != null && lineHDT.Amount < line.Amount) { countNotStandHDTJ++; var lineAmount = line.Amount != null ? line.Amount.Value : 0; var lineAmountHDT = lineHDT.Amount != null ? lineHDT.Amount.Value : 0; amountNotStandHDTJ += (double)(lineAmount - lineAmountHDT); } } } double countMiss = mealRecordMissings.Count(s => s.ProfileID == profile.ID && s.TamScanReasonMissID != null && tamScanNotFullPayIDs.Contains(s.TamScanReasonMissID.Value)); countMiss = GetCountAmount((int)countMiss); if (countCard > 0) { ReportAdjustmentMealAllowancePayment.TotalMealAllowance = countCard + countMiss; } if (sumCard > 0) { ReportAdjustmentMealAllowancePayment.SumAmount = (double)(sumCard + countMiss * (double)amountStardand); } if (countmealNotStardand > 0) { ReportAdjustmentMealAllowancePayment.CountEatNotStandar = countmealNotStardand; ReportAdjustmentMealAllowancePayment.AmountEatNotStandar = amountmealNotStardand - (double)(amountStardand * countmealNotStardand); } if (countCardMore1 > 0) { ReportAdjustmentMealAllowancePayment.CountCardMore = countCardMore1; ReportAdjustmentMealAllowancePayment.SumCardMore = (double)Math.Round(countCardMore1 * amountStardand, 2); } if (countNotWorkButHasEat > 0) { ReportAdjustmentMealAllowancePayment.CountNotWorkHasEat = countNotWorkButHasEat; ReportAdjustmentMealAllowancePayment.AmountNotWorkHasEat = sumNotWorkButHasEat; } amount3OnMonth = amount3OnMonth - (int)GetCountAmount(amount3OnMonth); if (amount3OnMonth > 0) { ReportAdjustmentMealAllowancePayment.Amount3OnMonth = amount3OnMonth; } if (countHDTJ > 0) { ReportAdjustmentMealAllowancePayment.CountHDTJob = countHDTJ; ReportAdjustmentMealAllowancePayment.AmounSubtractHDTJob = amountHDTJ; } if (countNotStandHDTJ > 0) { ReportAdjustmentMealAllowancePayment.CountCardWorngStandar = countNotStandHDTJ; ReportAdjustmentMealAllowancePayment.AmountSubtractWorngStandar = amountNotStandHDTJ; } } Can_SumryMealRecord sumryMealRecordNew = new Can_SumryMealRecord(); sumryMealRecordNew.ProfileID = profile.ID; sumryMealRecordNew.DateFrom = Cutoffduration.DateStart; sumryMealRecordNew.DateTo = Cutoffduration.DateEnd; sumryMealRecordNew.TotalMealAllowance = ReportAdjustmentMealAllowancePayment.TotalMealAllowance; sumryMealRecordNew.SumAmount = ReportAdjustmentMealAllowancePayment.SumAmount; sumryMealRecordNew.CountEatNotStandar = ReportAdjustmentMealAllowancePayment.CountEatNotStandar; sumryMealRecordNew.AmountEatNotStandar = ReportAdjustmentMealAllowancePayment.AmountEatNotStandar; sumryMealRecordNew.CountCardMore = ReportAdjustmentMealAllowancePayment.CountCardMore; sumryMealRecordNew.SumAmountCardMore = ReportAdjustmentMealAllowancePayment.SumCardMore; sumryMealRecordNew.CountNotWorkHasEat = ReportAdjustmentMealAllowancePayment.CountNotWorkHasEat; sumryMealRecordNew.AmountNotWorkHasEat = ReportAdjustmentMealAllowancePayment.AmountNotWorkHasEat; sumryMealRecordNew.Amount3OnMonth = ReportAdjustmentMealAllowancePayment.Amount3OnMonth; sumryMealRecordNew.CountHDTJob = ReportAdjustmentMealAllowancePayment.CountHDTJob; sumryMealRecordNew.AmountHDTJob = ReportAdjustmentMealAllowancePayment.AmounSubtractHDTJob; sumryMealRecordNew.AmountNotWorkButHasHDT = ReportAdjustmentMealAllowancePayment.AmountNotWorkButHasHDT; sumryMealRecordNew.CountSubtractWorngStandarHDT = ReportAdjustmentMealAllowancePayment.CountSubtractWorngStandarHDT; sumryMealRecordNew.AmountSubtractWorngStandarHDT = ReportAdjustmentMealAllowancePayment.AmountSubtractWorngStandarHDT; sumryMealRecordRepository.Add(sumryMealRecordNew); lstReportAdjustmentMealAllowancePayment.Add(ReportAdjustmentMealAllowancePayment); if (profiles.IndexOf(profile) % 1000 == 0) { sumryMealRecordRepository.SaveChanges(); } } sumryMealRecordRepository.SaveChanges(); } catch (Exception) { return false; } } return true; }
public DataTable ReportHDTJobCardMore(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, DateTime dateStart, DateTime dateEnd, List<Guid> lstProfileIds, Boolean isCludeEmpQuit) { DataTable datatable = CreateReportHDTJobCardMoreSchema(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCan_Line = new Can_LineRepository(unitOfWork); var repo = new Can_MealRecordRepository(unitOfWork); var mealRecords = repo.FindBy(s => s.ProfileID != null && s.WorkDay != null && s.TimeLog != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).ToList(); if (mealRecords == null && mealRecords.Count < 1) { return datatable; } var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList(); var repoProfile = new Hre_ProfileRepository(unitOfWork); var profiles = repoProfile.FindBy(m => profileIds.Contains(m.ID)).ToList(); var repoCan_Location = new Can_LocationRepository(unitOfWork); var lstLocation = repoCan_Location.FindBy(s => s.IsDelete == null).ToList(); if (lstProfileIds != null && lstProfileIds.Count >= 1) { profiles = profiles.Where(s => lstProfileIds.Contains(s.ID)).ToList(); } if (isCludeEmpQuit != true) { profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList(); } profileIds = profiles.Select(s => s.ID).ToList(); mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList(); var lstcateringids = mealRecords.Select(m => m.CateringID).ToList(); var lstcanteenids = mealRecords.Select(m => m.CanteenID).ToList(); var Cardcode = mealRecords.Select(s => s.ProfileID).Distinct().ToList(); var repoOrg = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoOrg.FindBy(m => m.Code != null).ToList(); if (CarteringIDs != null && CarteringIDs[0] != null) { mealRecords = mealRecords.Where(m => m.CateringID != null && CarteringIDs.Contains(m.CateringID)).ToList(); } if (CanteenIDS != null && CanteenIDS[0] != null) { mealRecords = mealRecords.Where(m => m.CanteenID != null && CanteenIDS.Contains(m.CanteenID)).ToList(); } if (LineIDS != null && LineIDS[0] != null) { mealRecords = mealRecords.Where(m => m.LineID != null && LineIDS.Contains(m.LineID)).ToList(); } if (mealRecords == null && mealRecords.Count < 1) { return datatable; } var repoWorkLocation = new Cat_WorkPlaceRepository(unitOfWork); var lstWorkPlace = repoWorkLocation.GetAll().ToList(); var repocatering = new Can_CateringRepository(unitOfWork); var caterings = repocatering.GetAll().ToList(); var repocanteen = new Can_CanteenRepository(unitOfWork); var canteens = repocanteen.GetAll().ToList(); var repoline = new Can_LineRepository(unitOfWork); var lines = repoline.GetAll().ToList(); var orgTypes = new List<Cat_OrgStructureType>(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); var repoAttWorkday = new Att_WorkDayRepository(unitOfWork); var wordDayProfiles = repoAttWorkday.FindBy(wd => dateStart <= wd.WorkDate && wd.WorkDate <= dateEnd) .Select(wd => new { wd.ProfileID, wd.ShiftID, wd.WorkDate, wd.InTime1, wd.OutTime1 }).ToList(); var approve = LeaveDayStatus.E_APPROVED.ToString(); var repoAttLeaveday = new Att_LeavedayRepository(unitOfWork); var leavedays = repoAttLeaveday.FindBy(ld => ld.Status == approve && dateStart <= ld.DateEnd && ld.DateStart <= dateEnd && profileIds.Contains(ld.ProfileID)).Select(ld => new { ld.ProfileID, ld.DateStart, ld.DateEnd }).ToList(); var repoHDTjob = new Hre_HDTJobRepository(unitOfWork); var hdtJobs = repoHDTjob.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value) && dateStart <= s.DateTo && s.DateFrom <= dateEnd).Select(s => new { s.DateFrom, s.ProfileID, s.DateTo, s.Type }).ToList(); for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { if (!datatable.Columns.Contains("Data" + date.Day)) { datatable.Columns.Add("Data" + date.Day, typeof(double)); } } foreach (var profile in profiles) { List<DateTime> leaveDayDates = new List<DateTime>(); var leaveDayProfiles = leavedays.Where(s => s.ProfileID == profile.ID).ToList(); foreach (var leaveDayProfile in leaveDayProfiles) { for (DateTime date = leaveDayProfile.DateStart; date <= leaveDayProfile.DateEnd; date = date.AddDays(1)) { leaveDayDates.Add(date.Date); } } var workDayDates = wordDayProfiles.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList(); workDayDates = workDayDates.Where(s => !leaveDayDates.Contains(s.Date)).ToList(); var mealRecordProfiles = mealRecords.Where(s => s.ProfileID == profile.ID && workDayDates.Contains(s.WorkDay.Value.Date)).ToList(); if (mealRecordProfiles.Count > 0) { var dateend = mealRecordProfiles[mealRecordProfiles.Count - 1].WorkDay; for (DateTime date = mealRecordProfiles[0].WorkDay.Value; date <= dateend; date = date.AddDays(1)) { if (mealRecordProfiles.Count(s => s.WorkDay.Value.Date == date.Date) > 1) { var mealDoubles = mealRecordProfiles.Where(s => s.WorkDay.Value.Date == date.Date).ToList(); if (mealDoubles.Count > 1) { var hdtType = hdtJobs.FirstOrDefault(s => s.DateFrom <= date && date <= s.DateTo && s.ProfileID == profile.ID); foreach (var meal in mealDoubles) { DataRow row = datatable.NewRow(); var orgId = orgs.Where(og => og.ID == mealRecordProfiles[0].OrgStructureID).Select(og => og.ID).FirstOrDefault(); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes); row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty; row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeDepartment] = orgOrg != null ? orgOrg.Code : string.Empty; row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty; row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty; row[Can_ReportHDTJobCardMoreEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Can_ReportHDTJobCardMoreEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Can_ReportHDTJobCardMoreEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Can_ReportHDTJobCardMoreEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Can_ReportHDTJobCardMoreEntity.FieldNames.ProfileName] = profile.ProfileName; row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateFrom] = dateStart; row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateTo] = dateEnd; row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateExport] = DateTime.Now; if (meal.TimeLog != null) { row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateCard] = meal.WorkDay; row[Can_ReportHDTJobCardMoreEntity.FieldNames.Hour] = meal.TimeLog.Value.ToString("HH:mm:ss"); } var count1 = 0; for (DateTime date1 = dateStart; date1 <= dateEnd; date1 = date1.AddDays(1)) { int countDay = mealRecordProfiles.Count(s => s.WorkDay.Value.Date == date1.Date && !leaveDayDates.Contains(date1.Date)); if (countDay > 1) { count1 += countDay - 1; } } row[Can_ReportHDTJobCardMoreEntity.FieldNames.Total] = count1; row["Data" + date.Day] = mealDoubles.Sum(s => s.Amount); var cate = caterings.FirstOrDefault(s => s.ID == meal.CateringID); var cateen = canteens.FirstOrDefault(s => s.ID == meal.CanteenID); var line = lines.FirstOrDefault(s => s.ID == meal.LineID); row[Can_ReportHDTJobCardMoreEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ; row[Can_ReportHDTJobCardMoreEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ; row[Can_ReportHDTJobCardMoreEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty; if (hdtType != null) { var hdttype = lines.FirstOrDefault(s => s.HDTJ == hdtType.Type); if (hdttype != null) { row[Can_ReportHDTJobCardMoreEntity.FieldNames.PriceStardand] = (object)hdttype.Amount ?? DBNull.Value; } } datatable.Rows.Add(row); } } } } } } } return datatable; }
/// <summary> /// [Son.Vo] - 20140724 - BC Thanh Toán Trợ Cấp Ăn Ca Cho Nhân Viên /// </summary> /// <param name="CarteringIDs"></param> /// <param name="CanteenIDS"></param> /// <param name="LineIDS"></param> /// <param name="DateFrom"></param> /// <param name="DateTo"></param> /// <returns></returns> public List <Can_ReportAdjustmentMealAllowancePaymentEntity> ReportAdjustmentMealAllowancePayment(DateTime DateFrom, DateTime DateTo, List <int> lstProfileIDs) { #region GetData var lstMealRecord = new List <Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType, s.NoWorkDay }).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_MealRecordRepository(unitOfWork); lstMealRecord = repo.FindBy(m => m.TimeLog >= DateFrom || m.TimeLog <= DateTo && m.CardCode != null).Select( s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType, s.NoWorkDay }).ToList(); } var cardcode = lstMealRecord.Select(s => s.CardCode).Distinct().ToList(); var profiles = new List <Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Hre_ProfileRepository(unitOfWork); profiles = repo.FindBy(s => cardcode.Contains(s.CodeEmp)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); } var mealAllowanceTypeSantandIDs = new List <Can_MealAllowanceTypeSetting>().Select(m => m.Id).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_MealAllowanceTypeSettingRepository(unitOfWork); mealAllowanceTypeSantandIDs = repo.FindBy(s => s.Standard == true).Select(m => m.Id).ToList(); } var lineHDTJobIDs = new List <Can_Line>().Select(m => m.Id).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_LineRepository(unitOfWork); lineHDTJobIDs = repo.FindBy(s => s.LineHDTJOB != null).Select(m => m.Id).ToList(); } var lines = new List <Can_Line>().ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_LineRepository(unitOfWork); lines = repo.GetAll().ToList(); } var lstOrgAll = new List <Cat_OrgStructure>().ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Cat_OrgStructureRepository(unitOfWork); lstOrgAll = repo.GetAll().ToList(); } #endregion List <Can_ReportAdjustmentMealAllowancePaymentEntity> lstReportAdjustmentMealAllowancePayment = new List <Can_ReportAdjustmentMealAllowancePaymentEntity>(); foreach (var profile in profiles) { Can_ReportAdjustmentMealAllowancePaymentEntity ReportAdjustmentMealAllowancePayment = new Can_ReportAdjustmentMealAllowancePaymentEntity(); var orgbyprofile = lstOrgAll.Where(m => m.Id == profile.OrgStructureID).Select(m => m.OrgStructureName).FirstOrDefault(); ReportAdjustmentMealAllowancePayment.CodeEmp = profile.CodeEmp; ReportAdjustmentMealAllowancePayment.ProfileName = profile.ProfileName; ReportAdjustmentMealAllowancePayment.OrgStructureId = orgbyprofile; var mealProfiles = lstMealRecord.Where(s => s.CardCode == profile.CodeEmp).ToList(); if (mealProfiles.Count > 0) { var line = lines.FirstOrDefault(s => s.Id == mealProfiles[0].LineID); if (line != null) { ReportAdjustmentMealAllowancePayment.TotalAdditionalAmount = mealProfiles.Count * line.Amount; } ReportAdjustmentMealAllowancePayment.TotalMealTime = mealProfiles.Where(m => m.MealAllowanceType != null && mealAllowanceTypeSantandIDs.Contains(m.MealAllowanceType)).Count(); ReportAdjustmentMealAllowancePayment.TotalDeductionAmount = mealProfiles.Where(m => m.MealAllowanceType != null && mealAllowanceTypeSantandIDs.Contains(m.MealAllowanceType)).Sum(m => m.Amount.Value); var countCardMore1 = 0; double?AmountSubtractCardMore1 = 0; for (DateTime date = DateFrom; date <= DateTo; date = date.AddDays(1)) { if (mealProfiles.Count(s => s.TimeLog == date) > 1) { countCardMore1++; var meal = mealProfiles.FirstOrDefault(s => s.TimeLog == date); if (meal != null) { AmountSubtractCardMore1 += meal.Amount; } } } ReportAdjustmentMealAllowancePayment.TotalScanManyTime = countCardMore1; ReportAdjustmentMealAllowancePayment.TotalDeductionScanManyTime = AmountSubtractCardMore1.Value; ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatTime = mealProfiles.Count(s => s.NoWorkDay == true); ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatAmount = mealProfiles.Sum(s => s.Amount.Value); ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatAmount = mealProfiles.Sum(s => s.Amount.Value); } lstReportAdjustmentMealAllowancePayment.Add(ReportAdjustmentMealAllowancePayment); } return(lstReportAdjustmentMealAllowancePayment); }
public void SubmitStatus(List<Guid> selectedIds, string status, string userID, string userLogin) { using (var context = new VnrHrmDataContext()) { var baseServices = new BaseService(); string statuss = string.Empty; var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Hre_ProfileRepository(unitOfWork); var lstProfiles = repo.FindBy(m => m.ID != null && selectedIds.Contains(m.ID)).ToList(); Guid guidUserID = Guid.Empty; if (!string.IsNullOrEmpty(userID)) { try { Guid.TryParse(userID, out guidUserID); } catch (Exception) { } } foreach (var Profile in lstProfiles) { if (Profile.ContractTypeID != null) { var contractypebyProfile = baseServices.GetData<Cat_ContractTypeEntity>(Common.DotNetToOracle(Profile.ContractTypeID.ToString()), ConstantSql.hrm_cat_sp_get_ContractTypeById, userLogin, ref status).FirstOrDefault(); if (contractypebyProfile != null && (contractypebyProfile.Type == HRM.Infrastructure.Utilities.EnumDropDown.TypeContract.E_PROBATION.ToString() || contractypebyProfile.Type == HRM.Infrastructure.Utilities.EnumDropDown.TypeContract.E_APPRENTICESHIP.ToString()) ) { Profile.StatusSyn = ProfileStatusSyn.E_WAITING_APPROVE.ToString(); } else { Profile.StatusSyn = ProfileStatusSyn.E_HIRE.ToString(); } } else { Profile.StatusSyn = ProfileStatusSyn.E_HIRE.ToString(); } } unitOfWork.GenerateCode(guidUserID, "CodeEmp", lstProfiles.ToArray()); repo.SaveChanges(); } }
/// <summary> /// [Son.Vo] 05/06/2014 /// Phân Tích Nghỉ Phép Và Trễ Sớm /// </summary> /// <returns></returns> public List<Att_AnalysysLeaveAndLateEarlyEntity> AnalysisLeaveAndLate(DateTime DateS, DateTime DateE, List<Guid> lstProfileIDs) { using (var context = new VnrHrmDataContext()) { if (DateS == null || DateE == null) return null; DateTime DateStart = DateS; DateTime DateEnd = DateE; string E_LATE_EARLY = WorkdayType.E_LATE_EARLY.ToString(); var lstWorkday = new List<Att_WorkdayEntity>(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new CustomBaseRepository<Att_Workday>(unitOfWork); lstWorkday = repo .FindBy(m => m.IsDelete == null && ((m.Type == E_LATE_EARLY && m.LateEarlyDuration != null && m.LateEarlyDuration > 0) || m.InTime1 == null || m.OutTime1 == null) && m.WorkDate >= DateStart && m.WorkDate < DateEnd && lstProfileIDs.Contains(m.ProfileID)) .ToList() .Translate<Att_WorkdayEntity>(); SetStatusLeaveOnWorkday(lstWorkday); var profileIds = lstWorkday.Select(s => s.ProfileID).Distinct().ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => profileIds.Contains(s.ID)) .Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); List<Guid?> shiftids = lstWorkday.Select(m => m.ShiftID).ToList(); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var shifts = repoCat_Shift.FindBy(s => shiftids.Contains(s.ID)) .Select(s => new { s.ID, s.ShiftName }).ToList(); List<Att_AnalysysLeaveAndLateEarlyEntity> lstAnalysysLeaveAndLateEarly = new List<Att_AnalysysLeaveAndLateEarlyEntity>(); foreach (var item in profiles) { var lstWorkdayByProfile = lstWorkday.Where(m => m.ProfileID == item.ID).ToList(); foreach (var WorkdayByProfile in lstWorkdayByProfile) { Att_AnalysysLeaveAndLateEarlyEntity analysysLeaveAndLateEarly = new Att_AnalysysLeaveAndLateEarlyEntity(); var profileshifts = shifts.Where(m => m.ID == WorkdayByProfile.ShiftID).FirstOrDefault(); analysysLeaveAndLateEarly.ProfileName = item.ProfileName; analysysLeaveAndLateEarly.CodeEmp = item.CodeEmp; analysysLeaveAndLateEarly.WorkDate = WorkdayByProfile.WorkDate; if (profileshifts != null) { analysysLeaveAndLateEarly.ShiftName = profileshifts.ShiftName; } analysysLeaveAndLateEarly.InTime = WorkdayByProfile.FirstInTime; analysysLeaveAndLateEarly.OutTime = WorkdayByProfile.LastOutTime; analysysLeaveAndLateEarly.udLeavedayCode1 = WorkdayByProfile.udLeavedayCode1; analysysLeaveAndLateEarly.udLeavedayStatus1 = WorkdayByProfile.udLeavedayStatus1; analysysLeaveAndLateEarly.Late = WorkdayByProfile.LateDuration1; analysysLeaveAndLateEarly.Early = WorkdayByProfile.EarlyDuration1; analysysLeaveAndLateEarly.LateEarly = WorkdayByProfile.LateEarlyDuration; lstAnalysysLeaveAndLateEarly.Add(analysysLeaveAndLateEarly); } } return lstAnalysysLeaveAndLateEarly; } }
/// <summary> /// Lay du lieu bao cao tong hop nghi om /// </summary> /// <param name="dateYear"></param> /// <param name="lstProfileIDs"></param> /// <returns></returns> public List<Att_ReportSickLeaveEntity> GetReportSickLeave(DateTime dateYear, List<Guid> lstProfileIDs) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); int year = dateYear.Year; DateTime dateStart = new DateTime(year, 1, 1); DateTime dateEnd = new DateTime(year, 12, DateTime.DaysInMonth(year, 12)); string key = OverTimeStatus.E_APPROVED.ToString(); var repoCat_Leaveday = new Cat_LeaveDayTypeRepository(unitOfWork); var leavedayTypes = repoCat_Leaveday.FindBy(s => s.CodeStatistic == "P" || s.CodeStatistic == "SC").Select(s => new { s.ID, s.CodeStatistic, s.PaidRate }).Distinct().ToList(); var leadayTypeIDs = leavedayTypes.Select(s => s.ID).ToList(); var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork); var leaveDays = new List<Att_LeaveDay>().Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList(); if (lstProfileIDs != null && lstProfileIDs.Count > 0) { leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd && lstProfileIDs.Contains(s.ProfileID)) .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList(); } else { leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd) .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList(); } var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => profileIds.Contains(s.ID) && lstProfileIDs.Contains(s.ID)).Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID, }).ToList(); string E_ANNUAL_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString(); string E_SICK_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_SICK_LEAVE.ToString(); var repoAtt_AnnualLeaveDetail = new Att_AnnualLeaveDetailRepository(unitOfWork); var anualLeaves = repoAtt_AnnualLeaveDetail.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value) && (s.Type == E_ANNUAL_LEAVE || s.Type == E_SICK_LEAVE) && s.Year == year) .Select(s => new { s.ProfileID, s.Month3, s.Type }).ToList(); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); var repoCat_Position = new Cat_PositionRepository(unitOfWork); var positions = repoCat_Position.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList(); var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork); var jobtitles = repoCat_JobTitle.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList(); List<Att_ReportSickLeaveEntity> lstReportSickLeaveEntity = new List<Att_ReportSickLeaveEntity>(); Att_ReportSickLeaveEntity reportSickLeaveEntity = null; foreach (var profile in profiles) { reportSickLeaveEntity = new Att_ReportSickLeaveEntity(); Guid? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); reportSickLeaveEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty; reportSickLeaveEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty; reportSickLeaveEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty; reportSickLeaveEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty; var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); reportSickLeaveEntity.ProfileName = profile.ProfileName; reportSickLeaveEntity.CodeEmp = profile.CodeEmp; reportSickLeaveEntity.PositionName = positon != null ? positon.PositionName : string.Empty; reportSickLeaveEntity.JobtitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty; reportSickLeaveEntity.DateExport = DateTime.Now; var anual = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_ANNUAL_LEAVE); var anualSick = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_SICK_LEAVE); reportSickLeaveEntity.TotalP = anual != null ? anual.Month3 : 0; reportSickLeaveEntity.TotalSC = anualSick != null ? anualSick.Month3 : 0; //reportSickLeaveEntity.BugetYearP = anualSick != null ? anualSick.Month3 : 0; //reportSickLeaveEntity.BalanceSC = anualSick != null ? anualSick.Month3 : 0; for (int i = 1; i <= 12; i++) { dateStart = new DateTime(year, i, 1); dateEnd = new DateTime(year, i, DateTime.DaysInMonth(year, i)); reportSickLeaveEntity.DateFrom = dateStart; reportSickLeaveEntity.DateTo = dateEnd; foreach (var leaday in leavedayTypes) { Dictionary<string, double> leavedayKeyValue = new Dictionary<string, double>(); double leaveDayHours = leaveDays .Where(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && s.ProfileID == profile.ID && s.LeaveDayTypeID == leaday.ID) .Sum(s => s.LeaveHours.Value / 8); } } lstReportSickLeaveEntity.Add(reportSickLeaveEntity); } return lstReportSickLeaveEntity; } }
/// <summary> /// [Tam.Le] - 20140725 - Lấy dữ liệu BC Chi Tiết Nhân Viên Không Chấm Công Nhưng Có Ăn /// </summary> /// <param name="CarteringIDs"></param> /// <param name="CanteenIDS"></param> /// <param name="LineIDS"></param> /// <param name="DateFrom"></param> /// <param name="DateTo"></param> /// <returns></returns> public List<Can_ReportMealTimeDetailEntity> ReportMealTimeDetail(List<int?> CarteringIDs, List<int?> CanteenIDS, List<int?> LineIDS, DateTime dateStart, DateTime dateEnd, List<int?> orgIDs) { var mealRecords = new List<Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_MealRecordRepository(unitOfWork); if (LineIDS != null) { mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true) .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }) .ToList(); } else mealRecords = repo.GetAll().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList(); } var lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList(); var lstProfile = new List<Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Hre_ProfileRepository(unitOfWork); lstProfile = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance)) .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList(); } List<Cat_OrgStructure> orgs = new List<Cat_OrgStructure>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Cat_OrgStructureRepository(unitOfWork); orgs = repo.FindBy(s => s.Code != null).ToList(); } lstProfile = lstProfile.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); //if (!isIncludeQuitEmp) //{ // profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList(); // profileIds = profiles.Select(s => s.ID).ToList(); // mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList(); //} if (CanteenIDS != null) { mealRecords = mealRecords.Where(s => s.CanteenID != null && CanteenIDS.Contains(s.CanteenID.Value)).ToList(); } if (CarteringIDs != null) { mealRecords = mealRecords.Where(s => s.CateringID != null && CarteringIDs.Contains(s.CateringID.Value)).ToList(); } if (LineIDS != null) { mealRecords = mealRecords.Where(s => s.LineID != null && LineIDS.Contains(s.LineID.Value)).ToList(); } lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList(); List<Hre_Profile> profiles = new List<Hre_Profile>(); var lstProfileId = new List<int>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Hre_ProfileRepository(unitOfWork); profiles = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance)).ToList(); lstProfileId = profiles.Select(s => s.Id).ToList(); } var orgTypes = new List<Cat_OrgStructureType>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repo.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); } Can_ReportMealTimeDetailEntity reportMealTimeDetailEntity = null; List<Can_ReportMealTimeDetailEntity> lstreportMealTimeDetailEntity = new List<Can_ReportMealTimeDetailEntity>(); foreach (var mealRecord in mealRecords) { reportMealTimeDetailEntity = new Can_ReportMealTimeDetailEntity(); var profile = profiles.FirstOrDefault(s => s.CodeAttendance == mealRecord.CardCode); if (profile != null) { int? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.Id == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); reportMealTimeDetailEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty; reportMealTimeDetailEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty; reportMealTimeDetailEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty; reportMealTimeDetailEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty; reportMealTimeDetailEntity.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; reportMealTimeDetailEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; reportMealTimeDetailEntity.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; reportMealTimeDetailEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty; reportMealTimeDetailEntity.CodeEmp = profile.CodeEmp; reportMealTimeDetailEntity.ProfileName = profile.ProfileName; reportMealTimeDetailEntity.Date = mealRecord.TimeLog; } lstreportMealTimeDetailEntity.Add(reportMealTimeDetailEntity); } return lstreportMealTimeDetailEntity; }
/// <summary> /// [Kiet.Chung] 4/11/2014 /// BC In Out Đã Bị Điều Chỉnh /// </summary> public List<Att_ReportInOutAdjustmentEntity> GetReportInOutAdjustment(DateTime dateStart, DateTime dateEnd, String TAMScanReasonMissIDs, String OrgStructureIDs, String CodeEmp, String PayrollGroupIDs, string userPrint) { using (var context = new VnrHrmDataContext()) { var baseService = new BaseService(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var repoCat_TAMScanReasonMiss = new CustomBaseRepository<Cat_TAMScanReasonMiss>(unitOfWork); var repoCat_Shift = new CustomBaseRepository<Cat_Shift>(unitOfWork); List<Cat_OrgStructure> lstOrgAll = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); //var LstProfileQuery = repoHre_Profile.FindBy(s => s.IsDelete == null); //List<Guid> lstprofileIDs = LstProfileQuery.Select(m => m.ID).ToList<Guid>(); string E_APPROVED = WorkdayStatus.E_APPROVED.ToString(); var lstWorkdayQuery = repoAtt_Workday.FindBy(m => m.Status == E_APPROVED && m.WorkDate >= dateStart && m.WorkDate <= dateEnd && (m.InTime1 != m.InTimeRoot || m.OutTime1 != m.OutTimeRoot || (m.InTime1 != null && m.InTimeRoot == null) || (m.OutTime1 != null && m.OutTimeRoot == null))); //int? NumLimitContains = Common.NumLimitContains; //if (NumLimitContains == null || lstprofileIDs.Count < NumLimitContains.Value) //{ if (!string.IsNullOrEmpty(OrgStructureIDs)) { var lstOrderNumber = OrgStructureIDs.Split(',').Select(s => int.Parse(s)).Distinct().ToList(); List<Guid> lstOrgS = lstOrgAll.Where(s => lstOrderNumber.Contains(s.OrderNumber)).Select(s => s.ID).ToList(); lstWorkdayQuery = lstWorkdayQuery.Where(m => m.OrgStructureID != null && lstOrgS.Contains(m.OrgStructureID.Value)); } if (!string.IsNullOrEmpty(PayrollGroupIDs)) { var lstPayroll = PayrollGroupIDs.Split(',').Select(s => Guid.Parse(s)).ToList(); lstWorkdayQuery = lstWorkdayQuery.Where(m => m.Hre_Profile.PayrollGroupID != null && lstPayroll.Contains(m.Hre_Profile.PayrollGroupID.Value)); } if (!string.IsNullOrEmpty(CodeEmp)) { lstWorkdayQuery = lstWorkdayQuery.Where(s => s.Hre_Profile.CodeEmp.Contains(CodeEmp)); } //lstWorkdayQuery = lstWorkdayQuery.Where(m => lstprofileIDs.Contains(m.ProfileID)); List<Att_Workday> lstWorkday = lstWorkdayQuery.ToList<Att_Workday>(); if (!string.IsNullOrEmpty(TAMScanReasonMissIDs)) { var lstReasonMiss = TAMScanReasonMissIDs.Split(',').Select(s => Guid.Parse(s)).ToList(); lstWorkday = lstWorkday.Where(s => s.MissInOutReason.HasValue && lstReasonMiss.Contains(s.MissInOutReason.Value)).ToList(); } #region ConvertToExportData #endregion List<Att_ReportInOutAdjustmentEntity> dt = new List<Att_ReportInOutAdjustmentEntity>(); if (lstWorkday == null || lstWorkday.Count == 0) { return dt; } List<Guid> lstProfileId = lstWorkday.Select(m => m.ProfileID).Distinct().ToList(); var lstProfile = repoHre_Profile.FindBy(m => lstProfileId.Contains(m.ID)).Select(m => new { m.ID, m.ProfileName, m.CodeEmp, m.OrgStructureID, m.Cat_Position.Code, m.Cat_Position.PositionName }).ToList(); //string UserLogin = EntityService.CreateQueryable<Sys_UserInfo>(false, GuidContext, Guid.Empty, m => m.ID == LoginUserID).Select(m => m.UserLogin).FirstOrDefault(); var lstShift = repoCat_Shift.FindBy(s => s.Code != null).Select(m => new { m.ID, m.ShiftName, m.Code }).ToList(); List<Guid> lstOrgID = lstWorkday.Where(m => m.OrgStructureID != null).Select(m => m.OrgStructureID.Value).Distinct().ToList<Guid>(); Dictionary<Guid, OrgNameClass> DicOrgFull = (new Hre_ProfileServices()).GetOrgFullLink(lstOrgID, lstOrgAll); var lstReasonMissInout = repoCat_TAMScanReasonMiss.FindBy(s => s.Code != null).Select(m => new { m.ID, m.TAMScanReasonMissName }).ToList(); foreach (var item in lstWorkday) { Att_ReportInOutAdjustmentEntity dr = new Att_ReportInOutAdjustmentEntity(); var Profile = lstProfile.Where(m => m.ID == item.ProfileID).FirstOrDefault(); if (Profile != null) { dr.ProfileName = Profile.ProfileName; dr.CodeEmp = Profile.CodeEmp; if (item.OrgStructureID != null) { var Org = lstOrgAll.Where(m => m.ID == item.OrgStructureID).FirstOrDefault(); if (Org != null) { dr.ProfileOrgCode = Org.Code; dr.ProfileOrgName = Org.OrgStructureName; } if (DicOrgFull.ContainsKey(item.OrgStructureID.Value)) { OrgNameClass OrgName = DicOrgFull[item.OrgStructureID.Value]; if (OrgName != null) { dr.DepartmentCode = OrgName.DepartmentCode; dr.SectionCode = OrgName.SectionCode; dr.BrandCode = OrgName.BrandCode; dr.TeamCode = OrgName.TeamCode; dr.DepartmentName = OrgName.DepartmentName; dr.SectionName = OrgName.SectionName; dr.BrandName = OrgName.BrandName; dr.TeamName = OrgName.TeamName; } } } dr.PositionCode = Profile.Code; dr.PositionName = Profile.PositionName; } var shift = lstShift.Where(m => m.ID == item.ShiftID).FirstOrDefault(); if (shift != null) { dr.ShiftName = shift.ShiftName; } var shiftActual = lstShift.Where(m => m.ID == item.ShiftActual).FirstOrDefault(); if (shiftActual != null) { dr.ShiftNameActual = shiftActual.ShiftName; } if (item.WorkDate != null) { dr.WorkDate = item.WorkDate; } var shiftApprove = lstShift.Where(m => m.ID == item.ShiftApprove).FirstOrDefault(); if (shiftApprove != null) { dr.ShiftNameApprove = shiftApprove.ShiftName; } if (item.InTime1 != null) { dr.InTime1 = item.InTime1; } if (item.OutTime1 != null) { dr.OutTime1 = item.OutTime1; } dr.Type = item.Type; dr.SrcType = item.SrcType; dr.Status = item.Status; dr.Note = item.Note; if (item.LateDuration1 != null) { dr.LateDuration1 = item.LateDuration1; } if (item.EarlyDuration1 != null) { dr.EarlyDuration1 = item.EarlyDuration1; } if (item.LateEarlyDuration != null) { dr.LateEarlyDuration = item.LateEarlyDuration; } if (item.LateEarlyRoot != null) { dr.LateEarlyRoot = item.LateEarlyRoot; } if (item.MissInOutReason != null) { var reason = lstReasonMissInout.Where(m => m.ID == item.MissInOutReason.Value).FirstOrDefault(); if (reason != null) { dr.MissInOutReason = reason.TAMScanReasonMissName; } } dr.LateEarlyReason = item.LateEarlyReason; if (userPrint != null) { dr.UserExport = userPrint; } dr.DateExport = DateTime.Today; if (item.InTimeRoot != null) dr.InTimeRoot = item.InTimeRoot.Value; if (item.OutTimeRoot != null) dr.OutTimeRoot = item.OutTimeRoot.Value; if (item.LateEarlyDuration != null) { if (item.LateEarlyDuration.Value < 120) { dr.EarlyLateLess2h = "X"; } else { dr.EarlyLateOver2h = "X"; } } else { dr.EarlyLateLess2h = "X"; } dr.DateFrom = dateStart; dr.DateTo = dateEnd; dt.Add(dr); } return dt; //var lstWorkdayQuery = repoAtt_Workday.FindBy(x => x.Status == WorkdayStatus.E_APPROVED.ToString() && x.WorkDate >= DateFrom && x.WorkDate <= DateTo && // (x.InTime1 != x.InTimeRoot || x.OutTime1 != x.OutTimeRoot || (x.InTime1 != null && x.InTimeRoot == null) || (x.OutTime1 != null && x.OutTimeRoot == null))); //List<Guid> lstprofileIDs = new List<Guid>(); //if (!string.IsNullOrEmpty(OrgStructureIDs) || !string.IsNullOrEmpty(PayrollGroupIDs) || !string.IsNullOrEmpty(CodeEmp)) //{ // if (PayrollGroupIDs == null) // PayrollGroupIDs = ""; // var LstProfileQuery = repoHre_Profile.FindBy(x => x.PayrollGroupID.HasValue && PayrollGroupIDs.Contains(x.PayrollGroupID.Value.ToString())); // if (!string.IsNullOrEmpty(OrgStructureIDs)) // LstProfileQuery = repoHre_Profile.FindBy(x => x.OrgStructureID.HasValue && OrgStructureIDs.Contains(x.OrgStructureID.Value.ToString())); // if (!string.IsNullOrEmpty(CodeEmp)) // LstProfileQuery = repoHre_Profile.FindBy(x => x.CodeEmp == CodeEmp); // lstprofileIDs = LstProfileQuery.Select(m => m.ID).ToList<Guid>(); //} //if (lstWorkdayQuery != null && lstprofileIDs.Count > 0) // lstWorkdayQuery = repoAtt_Workday.FindBy(x => lstprofileIDs.Contains(x.ProfileID)); //List<Att_Workday> lstWorkday = lstWorkdayQuery.ToList(); ////if (lstWorkday == null) //// return null; ////return lstWorkday.Translate<Att_WorkdayEntity>(); //if (lstWorkday == null) // return null; //var profileIds = lstWorkday.Select(s => s.ProfileID).Distinct().ToList(); //string strIDs = string.Join(",", profileIds.ToArray()); //List<object> lstObj = new List<object>(); //lstObj.Add(strIDs); //string status = ""; //var lstProfile = baseService.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(String.Join(",", profileIds)), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status); //lstObj = new List<object>(4); //List<object> paracatshift = new List<object>(); //paracatshift.AddRange(new object[4]); //paracatshift[2] = 1; //paracatshift[3] = 10000000; ////var lstShift = baseService.GetData<Cat_ShiftEntity>(lstObj, ConstantSql.hrm_cat_sp_get_Shift, ref status); //var lstShift = baseService.GetData<Cat_ShiftEntity>(paracatshift, ConstantSql.hrm_cat_sp_get_Shift, ref status); //var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); //var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); //List<Att_ReportInOutAdjustmentEntity> lstResult = new List<Att_ReportInOutAdjustmentEntity>(); //var lstReasonMissInout = repoCat_TAMScanReasonMiss.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.TAMScanReasonMissName }).ToList(); //foreach (var item in lstWorkday) //{ // Att_ReportInOutAdjustmentEntity objResult = new Att_ReportInOutAdjustmentEntity(); // var Profile = lstProfile.Where(m => m.ID == item.ProfileID).FirstOrDefault(); // Guid? orgId = Profile.OrgStructureID; // var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); // var orgGroup = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes); // var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); // var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); // var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); // objResult.CodeEmp = Profile.CodeEmp; // objResult.ProfileName = Profile.ProfileName; // if (lstShift != null) // { // var shift = lstShift.Where(m => m.ID == item.ShiftID).FirstOrDefault(); // if (shift != null) // objResult.ShiftName = shift.ShiftName; // var shiftActual = lstShift.Where(m => m.ID == item.ShiftActual).FirstOrDefault(); // if (shiftActual != null) // objResult.ShiftNameActual = shiftActual.ShiftName; // if (item.WorkDate != null) // objResult.WorkDate = item.WorkDate; // var shiftApprove = lstShift.Where(m => m.ID == item.ShiftApprove).FirstOrDefault(); // if (shiftApprove != null) // objResult.ShiftNameApprove = shiftApprove.ShiftName; // } // if (item.InTime1 != null) // objResult.InTime1 = item.InTime1; // if (item.OutTime1 != null) // objResult.OutTime1 = item.OutTime1; // objResult.InTimeRoot = item.InTimeRoot; // objResult.OutTimeRoot = item.OutTimeRoot; // objResult.WorkDate = item.WorkDate; // objResult.Type = item.Type; // objResult.SrcType = item.SrcType; // objResult.Status = item.Status; // objResult.Note = item.Note; // objResult.LateDuration1 = item.LateDuration1; // objResult.EarlyDuration1 = item.EarlyDuration1; // objResult.LateEarlyDuration = item.LateEarlyDuration; // objResult.LateEarlyRoot = item.LateEarlyRoot; // objResult.LateEarlyReason = item.LateEarlyReason; // objResult.BrandCode = orgBranch != null ? orgBranch.Code : string.Empty; // objResult.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty; // objResult.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty; // objResult.SectionCode = orgSection != null ? orgSection.Code : string.Empty; // var Org = orgs.Where(d => d.ID == Profile.OrgStructureID).FirstOrDefault(); // if (Org != null) // { // objResult.ProfileOrgCode = Org.Code; // } // if (item.LateEarlyDuration != null) // { // if (item.LateEarlyDuration.Value < 2) // { // objResult.EarlyLateLess2h = "X"; // } // else // { // objResult.EarlyLateOver2h = "X"; // } // } // else // { // objResult.EarlyLateLess2h = "X"; // } // if (item.MissInOutReason != null) // { // var reason = lstReasonMissInout.Where(m => m.ID == item.MissInOutReason.Value).FirstOrDefault(); // if (reason != null) // { // objResult.MissInOutReason = reason.TAMScanReasonMissName; // } // } // objResult.DateFrom = DateFrom; // objResult.DateTo = DateTo; // objResult.DatePrint = DateTime.Today; // objResult.UserPrint = userPrint; // lstResult.Add(objResult); //} //return lstResult; } }
public DataTable ReportMultiSlideCard(List<int?> CarteringIDs, List<int?> CanteenIDS, List<int?> LineIDS, DateTime dateStart, DateTime dateEnd, List<int> lstProfileIds) { List<Can_ReportMultiSlideCardEntity> lstReportMultiSlideCard = new List<Can_ReportMultiSlideCardEntity>(); DataTable datatable = CreateReportMultiSlideCardSchema(dateStart, dateEnd); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var mealRecords = new List<Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList(); var repo = new Can_MealRecordRepository(unitOfWork); mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true) .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList(); var lstcateringids = mealRecords.Select(m =>m.CateringID).ToList(); var lstcanteenids = mealRecords.Select(m =>m.CanteenID).ToList(); var lstlineids = mealRecords.Select(m => m.LineID).ToList(); var workDays = new List<Att_WorkDay>().Select(s => new { s.ProfileID, s.WorkDate }).ToList(); var repoWorkDay = new Att_WorkDayRepository(unitOfWork); workDays = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd) .Select(s => new { s.ProfileID, s.WorkDate }).ToList(); var Cardcode = mealRecords.Select(s => s.CardCode).Distinct().ToList(); var repoProfile = new Hre_ProfileRepository(unitOfWork); var profiles = repoProfile.FindBy(m => Cardcode.Contains(m.CodeAttendance) && lstProfileIds.Contains(m.Id)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.CodeAttendance }).ToList(); var repoOrg = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoOrg.FindBy(m => m.Code != null).ToList(); var catering = new List<Can_Catering>().ToList(); var repocatering = new Can_CateringRepository(unitOfWork); if(CarteringIDs != null && CarteringIDs.Count >0) { catering = repocatering.FindBy(m => CarteringIDs.Contains(m.Id)).ToList(); } else catering = repocatering.GetAll().ToList(); var canteen = new List<Can_Canteen>().ToList(); var repocanteen = new Can_CanteenRepository(unitOfWork); if (CanteenIDS != null && CanteenIDS.Count > 0) { canteen = repocanteen.FindBy(m => CanteenIDS.Contains(m.Id)).ToList(); } else canteen = repocanteen.GetAll().ToList(); var line = new List<Can_Line>().ToList(); var repoline = new Can_LineRepository(unitOfWork); if (LineIDS != null && LineIDS.Count > 0) { line = repoline.FindBy(m => LineIDS.Contains(m.Id)).ToList(); } else line = repoline.GetAll().ToList(); Can_ReportMultiSlideCardEntity ReportMultiSlideCardEntity = new Can_ReportMultiSlideCardEntity(); foreach (var profile in profiles) { DataRow row = datatable.NewRow(); var orgbyprofile = orgs.Where(m => m.Id == profile.OrgStructureID).FirstOrDefault(); var cateringbyprofile = catering.Where(m => lstcateringids.Contains(m.Id)).FirstOrDefault(); var lineprofile = line.Where(m => lstlineids.Contains(m.Id)).FirstOrDefault(); var canteenbyprofile = canteen.Where(m => lstcanteenids.Contains(m.Id)).FirstOrDefault(); row[Can_ReportMultiSlideCardEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Can_ReportMultiSlideCardEntity.FieldNames.ProfileName] = profile.ProfileName; row[Can_ReportMultiSlideCardEntity.FieldNames.OrgStructureName] = orgbyprofile.OrgStructureName; row[Can_ReportMultiSlideCardEntity.FieldNames.Cartering] = cateringbyprofile.CateringName; row[Can_ReportMultiSlideCardEntity.FieldNames.Canteen] = canteenbyprofile.CanteenName; row[Can_ReportMultiSlideCardEntity.FieldNames.Line] = lineprofile.LineName; var mealRecordProfiles = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).ToList(); var workDayProfiles = workDays.Where(s => s.ProfileID == profile.Id).ToList(); for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var meal = mealRecords.FirstOrDefault(s => s.CardCode == profile.CodeAttendance && s.TimeLog == date); if (meal != null) { row["Date" + date.Day] = (object)meal.TimeLog ?? DBNull.Value; //row["SumCardMore" + date.Day] = mealRecordProfiles.Count(s => s.TimeLog == date) - workDayProfiles.Count(s => s.WorkDate == date); } } datatable.Rows.Add(row); } } return datatable; }
/// <summary> /// Lấy Dữ Liệu BC GetReportDetailForgetCard /// </summary> /// <returns></returns> public DataTable GetReportDetailForgetCard(DateTime? DateFrom, DateTime? DateTo, List<Guid> lstProfileIDs, List<Guid?> ShiftIDs, string userExport) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork); DataTable table = CreateReportDetailForgetCardSchema(); List<string> lstType = new List<string> { WorkdayType.E_MISS_IN.ToString(), WorkdayType.E_MISS_IN_OUT.ToString(), WorkdayType.E_MISS_OUT.ToString() }; var workDays = repoAtt_Workday.FindBy(s => DateFrom <= s.WorkDate && s.WorkDate <= DateTo && lstType.Contains(s.Type)) .Select(s => new { s.ProfileID, s.ShiftID, s.WorkDate, s.FirstInTime, s.LastOutTime, s.Type, s.InTime1, s.OutTime1 }).ToList(); if (lstProfileIDs != null) { workDays = workDays.Where(s => lstProfileIDs.Contains(s.ProfileID)).ToList(); } var profileIds = workDays.Select(s => s.ProfileID).Distinct().ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => (s.DateQuit == null || s.DateQuit > DateTo) && profileIds.Contains(s.ID)) .Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); var repoCat_Position = new Cat_PositionRepository(unitOfWork); var positions = repoCat_Position.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList(); var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork); var jobtitles = repoCat_JobTitle.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList(); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var shifts = repoCat_Shift.GetAll().ToList(); if (ShiftIDs[0] != null) { workDays = workDays.Where(s => s.ShiftID.HasValue && ShiftIDs.Contains(s.ShiftID.Value)).ToList(); } List<Guid> guids = profiles.Select(s => s.ID).ToList(); if (guids.Count > 0) { workDays = workDays.Where(s => guids.Contains(s.ProfileID)).ToList(); } foreach (var profile in profiles) { for (DateTime date = DateFrom.Value.Date; date <= DateTo; date = date.AddDays(1)) { var workDayProfiles = workDays.Where(s => s.WorkDate.Date == date && s.ProfileID == profile.ID).ToList(); if (workDayProfiles.Count > 0) { DataRow row = table.NewRow(); //var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); //var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); Guid? orgId = profile.OrgStructureID; var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); row[Att_ReportDetailForgetCardEntity.FieldNames.GroupCode] = orgBranch != null ? orgBranch.Code : string.Empty; row[Att_ReportDetailForgetCardEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.Code : string.Empty; row[Att_ReportDetailForgetCardEntity.FieldNames.Division] = orgTeam != null ? orgTeam.Code : string.Empty; row[Att_ReportDetailForgetCardEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty; row[Att_ReportDetailForgetCardEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Att_ReportDetailForgetCardEntity.FieldNames.ProfileName] = profile.ProfileName; row[Att_ReportDetailForgetCardEntity.FieldNames.DateFrom] = DateFrom; row[Att_ReportDetailForgetCardEntity.FieldNames.DateTo] = DateTo; row[Att_ReportDetailForgetCardEntity.FieldNames.DateExport] = DateTime.Today; row[Att_ReportDetailForgetCardEntity.FieldNames.UserExport] = userExport; var workDay1 = workDayProfiles.FirstOrDefault(); row[Att_ReportDetailForgetCardEntity.FieldNames.Date] = date; if (workDay1.ShiftID != null) { var shift = shifts.Where(m => m.ID == workDay1.ShiftID).FirstOrDefault(); row[Att_ReportDetailForgetCardEntity.FieldNames.ShiftName] = shift != null ? shift.ShiftName : string.Empty; } if (workDay1.Type == WorkdayType.E_MISS_IN.ToString()) { row[Att_ReportDetailForgetCardEntity.FieldNames.OutTime] = workDay1.LastOutTime != null ? workDay1.LastOutTime.Value : DateTime.MinValue; } else if (workDay1.Type == WorkdayType.E_MISS_OUT.ToString()) { row[Att_ReportDetailForgetCardEntity.FieldNames.InTime] = workDay1.FirstInTime != null ? workDay1.FirstInTime.Value : DateTime.MaxValue; } row[Att_ReportDetailForgetCardEntity.FieldNames.ScanType] = workDay1.Type; table.Rows.Add(row); } } } return table; } #region Code Cũ //#region logic hien tai ////1. Chi tinh dc workday thieu in thieu out hoac thieu in out ////2. khong tinh dc nhưng quẹt thẻ da them bang tay boi vi khi them bang tay thì workday da du inout hok len dc bc //#endregion //List<Att_ReportDetailForgetCardEntity> lstReportDetailForgetCardEntity = new List<Att_ReportDetailForgetCardEntity>(); //string E_MISS_IN = WorkdayType.E_MISS_IN.ToString(); //string E_MISS_OUT = WorkdayType.E_MISS_OUT.ToString(); //string E_MISS_IN_OUT = WorkdayType.E_MISS_IN_OUT.ToString(); //#region getData //var lstWorkday = new List<Att_Workday>().Select(m => new { m.ProfileID, m.WorkDate, m.ShiftID, m.Type, m.FirstInTime, m.LastOutTime }).ToList(); //using (var context = new VnrHrmDataContext()) //{ // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_WorkDayRepository(unitOfWork); // if (lstProfileIDs != null && lstProfileIDs.Count > 0) // { // lstWorkday = repo.FindBy(m => m.WorkDate >= DateFrom && m.WorkDate < DateTo // && m.ProfileID != null && lstProfileIDs.Contains(m.ProfileID) // && (m.Type == E_MISS_IN || m.Type == E_MISS_OUT || m.Type == E_MISS_IN_OUT)) // .Select(m => new { m.ProfileID, m.WorkDate, m.ShiftID, m.Type, m.FirstInTime, m.LastOutTime }).ToList(); // } // else // { // lstWorkday = repo.FindBy(m => (m.WorkDate >= DateFrom && m.WorkDate < DateTo) // && (m.Type == E_MISS_IN || m.Type == E_MISS_OUT || m.Type == E_MISS_IN_OUT)) // .Select(m => new { m.ProfileID, m.WorkDate, m.ShiftID, m.Type, m.FirstInTime, m.LastOutTime }).ToList(); // } //} //List<Guid> lstprofilebyworkday = lstWorkday.Select(m => m.ProfileID).ToList(); //var lstProfile = new List<Hre_Profile>().Select(m => new { m.ID, m.OrgStructureID, m.CodeEmp, m.ProfileName }); //using (var context = new VnrHrmDataContext()) //{ // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Hre_ProfileRepository(unitOfWork); // if (lstprofilebyworkday != null && lstprofilebyworkday.Count > 0) // { // lstProfile = repo.FindBy(m => lstprofilebyworkday.Contains(m.ID)).Select(m => new { m.ID, m.OrgStructureID, m.CodeEmp, m.ProfileName }).ToList(); // } //} //var lstShift = new List<Cat_Shift>().Select(m => new { m.ID, m.ShiftName, m.InTime, m.CoOut }).ToList(); //using (var context = new VnrHrmDataContext()) //{ // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Cat_ShiftRepository(unitOfWork); // lstShift = repo.GetAll().Select(m => new { m.ID, m.ShiftName, m.InTime, m.CoOut }).ToList(); //} //#endregion //#region get org nhieu cap //List<OrgTiny> lstOrgAll = new List<OrgTiny>(); //using (var context = new VnrHrmDataContext()) //{ // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repoOrg = new Cat_OrgStructureRepository(unitOfWork); // lstOrgAll = repoOrg.FindBy(s => s.IsDelete == null).Select(m => new OrgTiny { ID = m.ID, OrgCode = m.Code, OrgName = m.OrgStructureName, ParentID = m.ParentID, TypeID = m.TypeID }).ToList(); //} //List<Guid?> lstOrgIDs = lstProfile.Select(m => m.OrgStructureID).Distinct().ToList(); //Dictionary<Guid?, OrgLevelTypeName> OrgNameAllLevel = Cat_OrgStructureServices.GetFullLinkOrg(lstOrgIDs, lstOrgAll); //#endregion //foreach (var ProfileID in lstprofilebyworkday) //{ // if (ProfileID == null) // continue; // var lstWorkdayByProfile = lstWorkday.Where(m => m.ProfileID == ProfileID).ToList(); // foreach (var WorkdayByProfile in lstWorkdayByProfile) // { // if (WorkdayByProfile.WorkDate == null) // { // continue; // } // Att_ReportDetailForgetCardEntity ReportDetailForgetCardEntity = new Att_ReportDetailForgetCardEntity(); // var profileInfomation = lstProfile.Where(m => m.ID == ProfileID).FirstOrDefault(); // #region thông tin chung // ReportDetailForgetCardEntity.DateFrom = DateFrom; // ReportDetailForgetCardEntity.DateTo = DateTo; // #endregion // #region thông tin Profile // if (profileInfomation != null) // { // ReportDetailForgetCardEntity.ProfileName = profileInfomation.ProfileName; // ReportDetailForgetCardEntity.CodeEmp = profileInfomation.CodeEmp; // } // #endregion // #region thông tin Phòng ban // Guid? orgID = null; // if (profileInfomation != null) // { // orgID = profileInfomation.OrgStructureID; // } // if (orgID != null) // { // var orgByProfile = lstOrgAll.Where(m => m.ID == orgID).FirstOrDefault(); // if (orgByProfile != null) // { // ReportDetailForgetCardEntity.DepartmentName = orgByProfile.OrgName; // ReportDetailForgetCardEntity.Division = orgByProfile.OrgCode; // } // } // if (orgID != null && OrgNameAllLevel.ContainsKey(orgID)) // { // var OrgNameFull = OrgNameAllLevel[orgID]; // if (OrgNameFull != null) // { // ReportDetailForgetCardEntity.SectionCode = OrgNameFull.SectionCode; // ReportDetailForgetCardEntity.GroupCode = OrgNameFull.TeamCode; // } // } // #endregion // #region thông tin chấm công // ReportDetailForgetCardEntity.Date = WorkdayByProfile.WorkDate; // if (WorkdayByProfile.ShiftID != null) // { // var Shift = lstShift.Where(m => m.ID == WorkdayByProfile.ShiftID).FirstOrDefault(); // if (Shift != null) // { // ReportDetailForgetCardEntity.ShiftName = Shift.ShiftName; // } // } // #endregion // #region thoi gian vao ra // if (WorkdayByProfile.Type == E_MISS_IN) // { // ReportDetailForgetCardEntity.OutTime = WorkdayByProfile.LastOutTime; // } // else if (WorkdayByProfile.Type == E_MISS_OUT) // { // ReportDetailForgetCardEntity.InTime = WorkdayByProfile.FirstInTime; // } // ReportDetailForgetCardEntity.ScanType = WorkdayByProfile.Type; // #endregion // lstReportDetailForgetCardEntity.Add(ReportDetailForgetCardEntity); // } //} //return lstReportDetailForgetCardEntity; #endregion }
/// <summary> /// [Tam.Le] - 20140726 - Lấy dữ liệu BC Trường Hợp Quẹt Thẻ Ở Hàng Ăn Không Tiêu Chuẩn /// </summary> /// <param name="CarteringIDs"></param> /// <param name="CanteenIDS"></param> /// <param name="LineIDS"></param> /// <param name="DateFrom"></param> /// <param name="DateTo"></param> /// <returns></returns> public List <Can_ReportCardNotStandEntity> ReportCardNotStand(List <int?> cateringIDs, List <int?> canteenIDs, List <int?> lineIDs, DateTime dateStart, DateTime dateEnd, List <int?> orgIDs) { DataTable datatable = CreateReportCardNotStandSchema(dateStart, dateEnd); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork); var mealRecords = repoCan_MealRecord.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd) .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType }).ToList(); //var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList(); var codeAttendances = mealRecords.Select(s => s.CardCode).Distinct().ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => codeAttendances.Contains(s.CodeAttendance)) .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.CodeAttendance }).ToList(); var repoCan_MealAllowanceTypeSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork); var mealAllowanceTypeSantandIDs = repoCan_MealAllowanceTypeSetting.FindBy(s => s.Standard == true) .Select(s => s.Id).ToList(); var repoCan_Line = new Can_LineRepository(unitOfWork); var lineHDTJobIDs = repoCan_Line.FindBy(s => s.LineHDTJOB != null) .Select(s => s.Id).ToList(); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); if (orgIDs != null) { profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); } //if (!isIncludeQuitEmp) //{ // profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList(); // profileIds = profiles.Select(s => s.ID).ToList(); // mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList(); //} if (canteenIDs != null) { mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList(); } if (cateringIDs != null) { mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList(); } if (lineIDs != null) { mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList(); } //for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) //{ // if (!table.Columns.Contains("Date" + date.Day)) // table.Columns.Add("Date" + date.Day, typeof(DateTime)); //} mealRecords = mealRecords.Where(s => s.MealAllowanceType != null && mealAllowanceTypeSantandIDs.Contains(s.MealAllowanceType) && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)).ToList(); profiles = profiles.Where(s => codeAttendances.Contains(s.CodeAttendance)).ToList(); var orgTypes = new List <Cat_OrgStructureType>(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList <Cat_OrgStructureType>(); Can_ReportCardNotStandEntity reportCardNotStandEntity = null; List <Can_ReportCardNotStandEntity> lstreportCardNotStandEntity = new List <Can_ReportCardNotStandEntity>(); foreach (var profile in profiles) { reportCardNotStandEntity = new Can_ReportCardNotStandEntity(); int?orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.Id == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); reportCardNotStandEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty; reportCardNotStandEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty; reportCardNotStandEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty; reportCardNotStandEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty; reportCardNotStandEntity.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; reportCardNotStandEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; reportCardNotStandEntity.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; reportCardNotStandEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty; reportCardNotStandEntity.CodeEmp = profile.CodeEmp; reportCardNotStandEntity.ProfileName = profile.ProfileName; //for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) //{ // var meal = mealRecords.FirstOrDefault(s => s.CardCode == profile.CodeAttendance && s.TimeLog == date); // if (meal != null) // { // //row["Date" + date.Day] = (object)meal.TimeLog ?? DBNull.Value; // } //} reportCardNotStandEntity.CountCard = mealRecords.Count(s => s.CardCode == profile.CodeAttendance); reportCardNotStandEntity.SumAmount = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).Sum(s => s.Amount); lstreportCardNotStandEntity.Add(reportCardNotStandEntity); } return(lstreportCardNotStandEntity); } }
public List<Hre_Profile> GetWorkingProfile(DateTime from, DateTime to, bool isIncludeQuitEmp) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); string waitStatus = ProfileStatusSyn.E_WAITING.ToString(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); List<Hre_Profile> listProfile = repoHre_Profile.FindBy(pro => pro.StatusSyn != waitStatus).ToList(); if (!isIncludeQuitEmp) { listProfile = listProfile.Where(pro => (pro.DateQuit == null || pro.DateQuit.Value > from) && pro.DateHire <= to).ToList(); } return listProfile; } }
public List<Hre_ReportExpiryContractEntity> GetReportExpiryContract(DateTime? DateFrom, DateTime? DateTo, List<Guid> lstProfileIDs) { List<Hre_ReportExpiryContractEntity> lstReportExpiryContract = new List<Hre_ReportExpiryContractEntity>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoContract = new Hre_ContractRepository(unitOfWork); var lstContract = repoContract.FindBy(s => s.DateEnd != null && s.DateEnd >= DateFrom && s.DateEnd <= DateTo && lstProfileIDs.Contains(s.ProfileID)).ToList(); if (lstContract == null) { return lstReportExpiryContract; } List<Guid> lstProfileIDsbycontract = lstContract.Select(s => s.ProfileID).ToList(); var repoProfile = new Hre_ProfileRepository(unitOfWork); var lstAllprofile = repoProfile.FindBy(s => lstProfileIDsbycontract.Contains(s.ID)).Select(s => new { s.ID, s.ProfileName, s.CodeEmp, s.OrgStructureID, s.PositionID, s.JobTitleID }).ToList(); var repoOrgStructure = new Cat_OrgStructureRepository(unitOfWork); var lstOrgStructure = repoOrgStructure.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.OrgStructureName }).ToList(); var repoPosition = new Cat_PositionRepository(unitOfWork); var lstPosition = repoPosition.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.PositionName }).ToList(); var repoJobtitle = new Cat_JobTitleRepository(unitOfWork); var lstJobtitle = repoJobtitle.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.JobTitleName }).ToList(); var repoContractType = new Cat_ContractTypeRepository(unitOfWork); var lstContractType = repoContractType.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.ContractTypeName, s.ContractNextID }).ToList(); foreach (var contract in lstContract) { Hre_ReportExpiryContractEntity ReportExpiryContract = new Hre_ReportExpiryContractEntity(); var profileByContract = lstAllprofile.Where(s => contract.ProfileID == s.ID).FirstOrDefault(); if (profileByContract == null) continue; var orgByProfile = lstOrgStructure.Where(s => profileByContract.OrgStructureID == s.ID).FirstOrDefault(); var positionByProfile = lstPosition.Where(s => contract.PositionID == s.ID).FirstOrDefault(); var jobtitleByProfile = lstJobtitle.Where(s => contract.JobTitleID == s.ID).FirstOrDefault(); var contractTypeByContract = lstContractType.Where(s => s.ID == contract.ContractTypeID).FirstOrDefault(); ReportExpiryContract.CodeEmp = profileByContract.CodeEmp; ReportExpiryContract.ProfileName = profileByContract.ProfileName; ReportExpiryContract.OrgStructureName = orgByProfile != null ? orgByProfile.OrgStructureName : ""; ReportExpiryContract.JobTitleName = jobtitleByProfile != null ? jobtitleByProfile.JobTitleName : ""; ReportExpiryContract.PositionName = positionByProfile != null ? positionByProfile.PositionName : ""; ReportExpiryContract.ContractTypeName = contractTypeByContract != null ? contractTypeByContract.ContractTypeName : ""; ReportExpiryContract.DateSigned = contract.DateSigned; ReportExpiryContract.DateStart = contract.DateStart; ReportExpiryContract.DateEnd = contract.DateEnd; lstReportExpiryContract.Add(ReportExpiryContract); } return lstReportExpiryContract; } }
public DataTable GetReportDetailOvertime(string userExport, DateTime dateStart, DateTime dateEndSearch, string ProfileName, string CodeEmp, string OrgIDString, List<Guid?> lstovertimeTypeIds, bool noDisplay0Data, bool isIncludeQuitEmp) { DataTable table = CreateReportDetailOvertimeSchema(); DateTime dateEnd = dateEndSearch.AddDays(1).AddMinutes(-1); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_Overtime = new Att_OvertimeRepository(unitOfWork); string key = OverTimeStatus.E_APPROVED.ToString(); string E_CASHOUT = MethodOption.E_CASHOUT.ToString(); var overtimesQuery = unitOfWork.CreateQueryable<Att_Overtime>(s => s.IsDelete == null && (s.RegisterHours > 0 || s.ApproveHours > 0) && s.Status == key && dateStart <= s.WorkDate && s.WorkDate <= dateEnd && (s.MethodPayment == null || s.MethodPayment == E_CASHOUT)); if (!string.IsNullOrEmpty(OrgIDString)) { List<Guid> OrgIDs = new List<Guid>(); List<string> OrgIDsArr = OrgIDString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); foreach (var item in OrgIDsArr) { Guid OrgID = Guid.Empty; Guid.TryParse(item, out OrgID); if (OrgID != Guid.Empty) { OrgIDs.Add(OrgID); } } overtimesQuery = overtimesQuery.Where(m => m.OrgStructureID != null && OrgIDs.Contains(m.OrgStructureID.Value)); } if (!string.IsNullOrEmpty(ProfileName)) { List<string> lstProfileName = ProfileName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); if (lstProfileName.Count > 1) { overtimesQuery = overtimesQuery.Where(m => m.Hre_Profile != null && lstProfileName.Contains(m.Hre_Profile.ProfileName)); } else { overtimesQuery = overtimesQuery.Where(m => m.Hre_Profile != null && m.Hre_Profile.ProfileName != null && (m.Hre_Profile.ProfileName.Contains(ProfileName))); } } if (!string.IsNullOrEmpty(CodeEmp)) { List<string> lstCodeEmp = CodeEmp.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); if (lstCodeEmp.Count > 1) { overtimesQuery = overtimesQuery.Where(m => m.Hre_Profile != null && lstCodeEmp.Contains(m.Hre_Profile.CodeEmp)); } else { overtimesQuery = overtimesQuery.Where(m => m.Hre_Profile != null && m.Hre_Profile.CodeEmp != null && (m.Hre_Profile.CodeEmp.Contains(CodeEmp))); } } if (noDisplay0Data) { overtimesQuery = overtimesQuery.Where(s => s.ApproveHours > 0); } if (lstovertimeTypeIds != null && lstovertimeTypeIds[0] != null && lstovertimeTypeIds[0] != Guid.Empty) { overtimesQuery = overtimesQuery.Where(s => lstovertimeTypeIds.Contains(s.OvertimeTypeID)); } var overtimes = overtimesQuery.Select(s => new { s.ProfileID, s.WorkDate, s.OvertimeTypeID, s.ApproveHours, s.RegisterHours, s.AnalyseHour, s.ConfirmHours, s.OrgStructureID, s.ReasonOT }).ToList(); var profileIds = overtimes.Select(s => s.ProfileID).Distinct().ToList(); var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork); var workDays = repoAtt_Workday.FindBy(s => s.IsDelete == null & dateStart <= s.WorkDate && s.WorkDate <= dateEnd) .Select(s => new { s.ProfileID, s.ShiftID, s.InTime1, s.OutTime1, s.WorkDate }).ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => s.IsDelete == null && profileIds.Contains(s.ID)).Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.IsDelete == null && s.Code != null).ToList(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); var repoCat_Position = new Cat_PositionRepository(unitOfWork); var positions = repoCat_Position.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList(); var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork); var jobtitles = repoCat_JobTitle.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList(); var repoCat_OvertimeType = new Cat_OvertimeTypeRepository(unitOfWork); var overtimeTypes = repoCat_OvertimeType.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code }).ToList(); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList(); if (!isIncludeQuitEmp) { profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList(); } foreach (var profile in profiles) { for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var overtimeProfiles = overtimes.Where(s => s.WorkDate.Date == date.Date && s.ProfileID == profile.ID).ToList(); if (overtimeProfiles.Count == 0) continue; var lastOvertimeByProfile = overtimeProfiles.OrderByDescending(m => m.WorkDate).FirstOrDefault(); DataRow row = table.NewRow(); Guid? orgId = profile.OrgStructureID; if (lastOvertimeByProfile != null) orgId = lastOvertimeByProfile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); row[Att_ReportDetailOvertimeEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.CodeOrg] = orgOrg != null ? orgOrg.Code : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Att_ReportDetailOvertimeEntity.FieldNames.ProfileName] = profile.ProfileName; row[Att_ReportDetailOvertimeEntity.FieldNames.DateExport] = DateTime.Now; row[Att_ReportDetailOvertimeEntity.FieldNames.ReasonOT] = lastOvertimeByProfile.ReasonOT; var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate == date); var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID); row[Att_ReportDetailOvertimeEntity.FieldNames.CodePosition] = positon != null ? positon.Code : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.CodeJobtitle] = jobtitle != null ? jobtitle.Code : string.Empty; row[Att_ReportDetailOvertimeEntity.FieldNames.DateFrom] = dateStart; row[Att_ReportDetailOvertimeEntity.FieldNames.DateTo] = dateEnd; row[Att_ReportDetailOvertimeEntity.FieldNames.DateExport] = DateTime.Now; row[Att_ReportDetailOvertimeEntity.FieldNames.UserExport] = userExport; row[Att_ReportDetailOvertimeEntity.FieldNames.udSubmitApproveHour] = overtimeProfiles.Where(m => m.AnalyseHour != null).Sum(m => m.AnalyseHour); row[Att_ReportDetailOvertimeEntity.FieldNames.DateOvertime] = date; if (workDay != null && workDay.InTime1 != null) { //row[Att_ReportDetailOvertimeEntity.FieldNames.udInTime] = workDay.InTime1.Value.ToString("HH:mm:ss"); row[Att_ReportDetailOvertimeEntity.FieldNames.udInTime] = workDay.InTime1.Value; } if (workDay != null && workDay.OutTime1 != null) { //row[Att_ReportDetailOvertimeEntity.FieldNames.udOutTime] = workDay.OutTime1.Value.ToString("HH:mm:ss"); row[Att_ReportDetailOvertimeEntity.FieldNames.udOutTime] = workDay.OutTime1.Value; } if (shift != null) { row[Att_ReportDetailOvertimeEntity.FieldNames.ShiftName] = shift.ShiftName; } foreach (var item in overtimeTypes) { var sum = overtimeProfiles.Where(s => s.OvertimeTypeID == item.ID).Sum(s => s.RegisterHours); row[item.Code] = sum > 0 ? (object)sum : DBNull.Value; sum = overtimeProfiles.Where(s => s.OvertimeTypeID == item.ID && s.ApproveHours > 0).Sum(s => s.ApproveHours.Value); row[item.Code + "_Approve"] = sum > 0 ? (object)sum : DBNull.Value; sum = overtimeProfiles.Where(s => s.OvertimeTypeID == item.ID && s.ConfirmHours != null && s.ConfirmHours > 0).Sum(s => s.ConfirmHours); row[item.Code + "_Confirm"] = sum > 0 ? (object)sum : DBNull.Value; } table.Rows.Add(row); } } var configs = new Dictionary<string, Dictionary<string, object>>(); var config = new Dictionary<string, object>(); var configtime = new Dictionary<string, object>(); var configwidthCode = new Dictionary<string, object>(); var configwidthName = new Dictionary<string, object>(); var configwidthshift = new Dictionary<string, object>(); var configwidthudSubmitApproveHour = new Dictionary<string, object>(); configwidthCode.Add("width", 80); configs.Add("CodeBranch", configwidthCode); configs.Add("CodeOrg", configwidthCode); configs.Add("CodeTeam", configwidthCode); configs.Add("CodeSection", configwidthCode); configs.Add("CodeJobtitle", configwidthCode); configs.Add("CodePosition", configwidthCode); configwidthName.Add("width", 110); configs.Add("BranchName", configwidthName); configs.Add("OrgName", configwidthName); configs.Add("TeamName", configwidthName); configs.Add("SectionName", configwidthName); configwidthudSubmitApproveHour.Add("width", 120); configs.Add("udSubmitApproveHour", configwidthudSubmitApproveHour); configwidthshift.Add("width", 90); configs.Add("DateOvertime", configwidthshift); configs.Add("ShiftName", configwidthshift); config.Add("hidden", true); configs.Add("DateFrom", config); configs.Add("DateTo", config); configs.Add("UserExport", config); configs.Add("DateExport", config); configtime.Add("width", 80); configtime.Add("format", "{0:HH:mm:ss}"); configs.Add("udOutTime", configtime); configs.Add("udInTime", configtime); // return table.ConfigDatatable(); return table.ConfigTable(configs); } }
/// <summary> /// Lấy Dữ Liệu BC Chi Tiết Nghỉ Phép Ốm của nhân viên /// </summary> /// <returns></returns> /// public DataTable GetReportLeaveYear(int dateYear, List<Guid?> leaveDayTypeIDs, List<Guid> lstProfileIDs, string userExport, string codeEmp) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); int year = dateYear; DateTime dateStart = new DateTime(year, 1, 1); DateTime dateEnd = new DateTime(year, 12, DateTime.DaysInMonth(year, 12)); string key = OverTimeStatus.E_APPROVED.ToString(); var repoCat_Leaveday = new Cat_LeaveDayTypeRepository(unitOfWork); var leavedayTypes = repoCat_Leaveday.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PaidRate }).Distinct().ToList(); var leadayTypeIDs = leavedayTypes.Select(s => s.ID).ToList(); var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork); var leaveDays = new List<Att_LeaveDay>().Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd, s.LeaveDays }).ToList(); leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd) .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd, s.LeaveDays }).ToList(); leaveDays = leaveDays.Where(s => leaveDayTypeIDs.Contains(s.ProfileID)).ToList(); if (leaveDayTypeIDs[0] != null) { leaveDays = leaveDays.Where(s => leaveDayTypeIDs.Contains(s.LeaveDayTypeID)).ToList(); } var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList(); lstProfileIDs.AddRange(profileIds); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => profileIds.Contains(s.ID)).Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID, }).ToList(); profiles = profiles.Where(s => lstProfileIDs.Contains(s.ID)).ToList(); if (!string.IsNullOrEmpty(codeEmp)) { char[] ext = new char[] { ';', ',' }; List<string> codeEmpSeachs = codeEmp.Split(ext, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); if (codeEmpSeachs.Count == 1) { string codeEmpSearch = codeEmpSeachs[0]; profiles = profiles.Where(hr => hr.CodeEmp == codeEmpSearch).ToList(); } else { profiles = profiles.Where(hr => codeEmpSeachs.Contains(hr.CodeEmp)).ToList(); } } string E_ANNUAL_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString(); string E_SICK_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_SICK_LEAVE.ToString(); var repoAtt_AnnualLeaveDetail = new Att_AnnualLeaveDetailRepository(unitOfWork); var anualLeaves = repoAtt_AnnualLeaveDetail.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value) && (s.Type == E_ANNUAL_LEAVE || s.Type == E_SICK_LEAVE) && s.Year == year) .Select(s => new { s.ProfileID, s.Month3, s.Type }).ToList(); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); var repoCat_Position = new Cat_PositionRepository(unitOfWork); var positions = repoCat_Position.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList(); var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork); var jobtitles = repoCat_JobTitle.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList(); var repoAtt_Pregnancy = new Att_PregnancyRepository(unitOfWork); var pregnancys = repoAtt_Pregnancy.FindBy(s => s.DateStart != null && s.DateEnd != null && dateStart <= s.DateEnd && s.DateStart <= dateEnd && profileIds.Contains(s.ProfileID)) .Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList(); Dictionary<string, string> dicSchemma = new Dictionary<string, string>(); DataTable tb = GetSchema(dateStart, dateEnd, out dicSchemma); int stt = 0; foreach (var profile in profiles) { stt++; DataRow dr = tb.NewRow(); Guid? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); dr[Att_ReportSickLeaveEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty; dr[Att_ReportSickLeaveEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty; dr[Att_ReportSickLeaveEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty; dr[Att_ReportSickLeaveEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty; dr[Att_ReportSickLeaveEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; dr[Att_ReportSickLeaveEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; dr[Att_ReportSickLeaveEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); dr[Att_ReportSickLeaveEntity.FieldNames.CodeEmp] = profile.CodeEmp; dr[Att_ReportSickLeaveEntity.FieldNames.ProfileName] = profile.ProfileName; dr[Att_ReportSickLeaveEntity.FieldNames.CodePosition] = positon != null ? positon.Code : string.Empty; dr[Att_ReportSickLeaveEntity.FieldNames.CodeJobtitle] = jobtitle != null ? jobtitle.Code : string.Empty; var anual = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_ANNUAL_LEAVE); var anualSick = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_SICK_LEAVE); if (dicSchemma.ContainsKey(Att_ReportSickLeaveEntity.FieldNames.SumANL)) { dr[dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumANL]] = anual != null ? (object)anual.Month3 : DBNull.Value; string SttOfData = dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumANL].Substring(4, dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumANL].Length - 4); if (stt == 1) { dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = "Total P"; } else if (stt == 2) { dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = "Total SC"; } } if (dicSchemma.ContainsKey(Att_ReportSickLeaveEntity.FieldNames.SumSICK)) { dr[dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumSICK]] = anualSick != null ? (object)anualSick.Month3 : DBNull.Value; string SttOfData = dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumSICK].Substring(4, dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumSICK].Length - 4); if (stt == 1) { dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = "Total P"; } else if (stt == 2) { dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = "Total SC"; } } //var pregnancyProfiles = pregnancys.Where(s => s.ProfileID == profile.ID).ToList(); //for (DateTime DateCheck = dateStart; DateCheck <= dateEnd; DateCheck = DateCheck.AddMonths(1)) //{ // int dayPregancy = 0; // foreach (var pregnancyProfile in pregnancyProfiles) // { // for (DateTime date = pregnancyProfile.DateStart.Value; date < pregnancyProfile.DateEnd.Value; date = date.AddDays(1)) // { // dayPregancy += 1; // } // } // foreach (var leaday in leavedayTypes) // { // if (dicSchemma.ContainsKey(leaday.Code + DateCheck.Month)) // { // var sum = leaveDays.Where(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && s.ProfileID == profile.ID && s.LeaveDayTypeID == leaday.ID).Sum(s => s.TotalDuration); // dr[dicSchemma[leaday.CodeStatistic + DateCheck.Month]] = sum > 0 ? (object)(sum - dayPregancy) : DBNull.Value; // string SttOfData = dicSchemma[leaday.CodeStatistic + DateCheck.Month].Substring(4, dicSchemma[leaday.CodeStatistic + DateCheck.Month].Length - 4); // if (stt == 1) // { // dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = DateCheck.ToString("MMM-yyyy"); // } // else if (stt == 2) // { // dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = leaday.CodeStatistic; // } // } // } //} //dr[Att_ReportSickLeaveEntity.FieldNames.DateFrom] = dateStart; //dr[Att_ReportSickLeaveEntity.FieldNames.DateTo] = dateEnd; //tb.Rows.Add(dr); var pregnancyProfiles = pregnancys.Where(s => s.ProfileID == profile.ID).ToList(); for (DateTime DateCheck = dateStart; DateCheck <= dateEnd; DateCheck = DateCheck.AddMonths(1)) { int dayPregancy = 0; foreach (var pregnancyProfile in pregnancyProfiles) { for (DateTime date = pregnancyProfile.DateStart.Value; date < pregnancyProfile.DateEnd.Value; date = date.AddDays(1)) { dayPregancy += 1; } } foreach (var leaday in leavedayTypes) { if (dicSchemma.ContainsKey(leaday.Code + DateCheck.Month)) { var sum = leaveDays.Where(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && s.ProfileID == profile.ID && s.LeaveDayTypeID == leaday.ID).Sum(s => s.LeaveDays); dr[dicSchemma[leaday.Code + DateCheck.Month]] = sum > 0 ? (object)(sum - dayPregancy) : DBNull.Value; string SttOfData = dicSchemma[leaday.Code + DateCheck.Month].Substring(4, dicSchemma[leaday.Code + DateCheck.Month].Length - 4); if (stt == 1) { dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = DateCheck.ToString("MMM-yyyy"); } else if (stt == 2) { dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = leaday.Code; } } } } dr[Att_ReportSickLeaveEntity.FieldNames.DateFrom] = dateStart; dr[Att_ReportSickLeaveEntity.FieldNames.DateTo] = dateEnd; dr[Att_ReportSickLeaveEntity.FieldNames.UserExport] = userExport; dr[Att_ReportSickLeaveEntity.FieldNames.DateExport] = DateTime.Today; tb.Rows.Add(dr); } return tb; } }
public bool InsuranceReceiveSocialInsSelected(List<Guid> selectedIds) { var isSuccess = false; using (var context = new VnrHrmDataContext()) { var status = string.Empty; var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoHreProfile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHreProfile.FindBy(p => selectedIds.Contains(p.ID)).ToList(); var lstProfileModify = new List<Hre_Profile>(); foreach (var profile in profiles) { if (profile.IsSettlement.HasValue && profile.IsSettlement.Value == true) { profile.ReceiveSocialIns = true; lstProfileModify.Add(profile); } } if (lstProfileModify.Any()) { repoHreProfile.Edit(lstProfileModify); var resultStatus = repoHreProfile.SaveChanges(); if (resultStatus == DataErrorCode.Success) { isSuccess = true; } } } return isSuccess; }
public List<Hre_ReportEducationChartListEntity> GetReportEducationCharList(DateTime? DateFrom, DateTime? DateTo, List<Guid> lstProfileIDs, bool AppliedForThisPeriod) { List<Hre_ReportEducationChartListEntity> lstEducationChar = new List<Hre_ReportEducationChartListEntity>(); if (lstProfileIDs == null) { return lstEducationChar; } using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoOrgs = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoOrgs.FindBy(s => s.IsDelete == null && s.Code != null).ToList(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); var type = Education.E_EDUCATION_LEVEL.ToString(); var repoCat_NameEntity = new Cat_NameEntityRepository(unitOfWork); var lstNameEntity = repoCat_NameEntity.FindBy(s => s.NameEntityType == type && s.IsDelete == null).ToList(); var repoProfile = new Hre_ProfileRepository(unitOfWork); var lstProfile = repoProfile.FindBy(s => s.IsDelete == null).ToList(); if (AppliedForThisPeriod) { lstProfile = lstProfile.Where(s => s.DateHire <= DateTo && (s.DateQuit == null || (s.DateQuit >= DateFrom && s.DateQuit <= DateTo))).ToList(); } lstProfile = lstProfile.Where(s => s.DateHire <= DateTo && (s.DateQuit == null || s.DateQuit >= DateFrom) && lstProfileIDs.Contains(s.ID)).ToList(); foreach (var nameEntity in lstNameEntity) { Hre_ReportEducationChartListEntity EducationCharList = new Hre_ReportEducationChartListEntity(); int countprofile = lstProfile.Count(p => p.EducationLevelID == nameEntity.ID); if (countprofile == 0) continue; EducationCharList.EducationLevel = nameEntity.NameEntityName; EducationCharList.ProfileCount = countprofile; lstEducationChar.Add(EducationCharList); } return lstEducationChar; } }
public void AnalyzeCompensation(int Year, List <Guid> lstProfileIDTotal) { //Lấy cấu hình //lấy ngày nghỉ (Bù) //Lấy tăng ca (Bù) //Lấy Ca Làm Việc (Bù) //Hệ Số Tăng Ca (Loại Tăng Ca) foreach (var lstProfileID in lstProfileIDTotal.Chunk(500)) { using (var context = new VnrHrmDataContext()) { #region Khai báo var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); var repoAtt_Overtime = new Att_OvertimeRepository(unitOfWork); var repoAtt_CompensationConfig = new Att_CompensationConfigRepository(unitOfWork); var repoAtt_CompensationDetail = new Att_CompensationDetailRepository(unitOfWork); #endregion #region Lấy Dữ Liệu // var profileByCodeEmp = repoHre_Profile.FindBy(p => p.IsDelete == null && p.CodeEmp == codeEmp).FirstOrDefault(); var lstProfile = repoHre_Profile.FindBy(m => lstProfileID.Contains(m.ID)).Select(m => new { m.ID, m.DateHire }).ToList(); var lstCompensationConfig = repoAtt_CompensationConfig .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)) .Select(m => new CompensationConfigModel() { ID = m.ID, ProfileID = m.ProfileID, Year = m.Year, InitAvailable = m.InitAvailable, MonthBeginInYear = m.MonthBeginInYear, MonthResetInitAvailable = m.MonthResetInitAvailable, MonthStartProfile = m.MonthStartProfile }) .ToList(); int MonthBeginYear = 1; if (lstCompensationConfig != null && lstCompensationConfig.Count > 0) { MonthBeginYear = lstCompensationConfig.FirstOrDefault().MonthBeginInYear ?? 1; } DateTime BeginYear = new DateTime(Year, MonthBeginYear, 1); DateTime EndYear = BeginYear.AddYears(1).AddMinutes(-1); string E_APPROVED_Leave = LeaveDayStatus.E_APPROVED.ToString(); var lstLeaveDayCompensationTypeID = repoCat_LeaveDayType .FindBy(m => m.IsTimeOffInLieu == true) .Select(m => m.ID) .ToList(); var lstLeaveday = repoAtt_Leaveday .FindBy(m => m.Status == E_APPROVED_Leave && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstLeaveDayCompensationTypeID.Contains(m.LeaveDayTypeID) && lstProfileID.Contains(m.ProfileID)) .Select(m => new { m.ID, m.ProfileID, m.DateStart, m.DateEnd, m.LeaveHours, m.DurationType }) .ToList(); string E_TIMEOFF = MethodOption.E_TIMEOFF.ToString(); string E_APPROVED_Overtime = OverTimeStatus.E_APPROVED.ToString(); string E_CONFIRM_Overtime = OverTimeStatus.E_CONFIRM.ToString(); var lstOvertime = repoAtt_Overtime .FindBy(m => m.WorkDateRoot >= BeginYear && m.WorkDateRoot <= EndYear && m.MethodPayment == E_TIMEOFF && (m.Status == E_APPROVED_Overtime || m.Status == E_CONFIRM_Overtime) && lstProfileID.Contains(m.ProfileID)) .Select(m => new { m.ID, m.ProfileID, m.WorkDateRoot, m.ApproveHours, m.ConfirmHours, m.Status }).ToList(); string E_APPROVED_Roster = RosterStatus.E_APPROVED.ToString(); var lstRoster = repoAtt_Roster .FindBy(m => m.Status == E_APPROVED_Roster && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstProfileID.Contains(m.ProfileID)) .Select(m => new RosterModel { ID = m.ID, ProfileID = m.ProfileID, DateStart = m.DateStart, DateEnd = m.DateEnd, Type = m.Type, MonShiftID = m.MonShiftID, TueShiftID = m.TueShiftID, WedShiftID = m.WedShiftID, ThuShiftID = m.ThuShiftID, FriShiftID = m.FriShiftID, SatShiftID = m.SatShiftID, SunShiftID = m.SunShiftID }) .ToList(); var lstShift = repoCat_Shift.GetAll().Select(m => new { m.ID, m.WorkHours, m.StdWorkHours }).ToList(); List <Att_CompensationDetail> detailInDB = repoAtt_CompensationDetail .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)) .ToList(); List <Att_CompensationDetail> detailNew = new List <Att_CompensationDetail>(); foreach (var ProfileID in lstProfileID) { double TotalLeaveHourBeforeMonth = 0; double TotalOvertimeHourBeforeMonth = 0; var Profile = lstProfile.Where(m => m.ID == ProfileID).FirstOrDefault(); int MonthHire = 1; if (Profile.DateHire != null && Profile.DateHire >= BeginYear && Profile.DateHire <= EndYear) { if (Profile.DateHire.Value.Day >= 15) { MonthHire = Profile.DateHire.Value.AddMonths(1).Month; } else { MonthHire = Profile.DateHire.Value.Month; } } for (DateTime Month = BeginYear; Month < EndYear; Month = Month.AddMonths(1)) { if (MonthHire > Month.Month) { continue; } DateTime BeginMonth = Month; DateTime EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1); double TotalLeaveHourInMonth = 0; double TotalOvertimeHourInMonth = 0; #region Tăng Ca var lstOvertimeByProfileByMonth = lstOvertime.Where(m => m.ProfileID == ProfileID && m.WorkDateRoot >= BeginMonth && m.WorkDateRoot <= EndMonth).ToList(); TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_CONFIRM_Overtime).Sum(m => m.ConfirmHours); TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_APPROVED_Overtime).Sum(m => m.ApproveHours ?? 0); #endregion #region Ngày Nghỉ var lstLeavedayByProfileByMonth = lstLeaveday.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList(); var lstRosterByProfileByMonth = lstRoster.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList(); foreach (var Leaveday in lstLeavedayByProfileByMonth) { DateTime dateStart = Leaveday.DateStart < BeginMonth ? BeginMonth : Leaveday.DateStart; DateTime dateEnd = Leaveday.DateEnd > EndMonth ? EndMonth : Leaveday.DateEnd; for (DateTime dateCheck = dateStart; dateCheck <= dateEnd; dateCheck = dateCheck.AddDays(1)) { if (Leaveday.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()) // Trong Ca { TotalLeaveHourInMonth += Leaveday.LeaveHours ?? 0; } else //Toàn Ca { //Check xem có Ca làm việc không Guid?ShiftID = null; var E_TIME_OFF = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_TIME_OFF.ToString()).FirstOrDefault(); var E_CHANGE_SHIFT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_CHANGE_SHIFT.ToString()).FirstOrDefault(); var E_DEFAULT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_DEFAULT.ToString()).FirstOrDefault(); var E_ROSTERGROUP = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_ROSTERGROUP.ToString()).FirstOrDefault(); if (E_TIME_OFF != null) { } else if (E_CHANGE_SHIFT != null) { ShiftID = GetShiftRoster(dateCheck, E_CHANGE_SHIFT); } else if (E_DEFAULT != null) { ShiftID = GetShiftRoster(dateCheck, E_DEFAULT); } else if (E_ROSTERGROUP != null) { //Chưa hỗ trợ đăng ký ca theo nhóm } if (ShiftID != null) { var Shift = lstShift.Where(m => m.ID == ShiftID.Value).FirstOrDefault(); if (Shift != null) { TotalLeaveHourInMonth += Shift.StdWorkHours ?? (Shift.WorkHours ?? 0); } } } } } #endregion #region Gán Dữ Liệu CompensationConfigModel Config = lstCompensationConfig.Where(m => m.ProfileID == ProfileID).FirstOrDefault(); Att_CompensationDetail detail = detailInDB.Where(m => m.MonthYear == Month && m.ProfileID == ProfileID).FirstOrDefault(); if (detail == null) { detail = new Att_CompensationDetail(); detail.ID = Guid.NewGuid(); detailNew.Add(detail); } if (Config != null) { if (Config.MonthResetInitAvailable != null && Config.MonthResetInitAvailable.Value <= Month.Month) { } else { detail.InitAvailable = Config.InitAvailable; } detail.MonthBeginInYear = Config.MonthBeginInYear ?? 1; detail.MonthResetInitAvailable = Config.MonthResetInitAvailable; } detail.ProfileID = ProfileID; detail.Year = Year; detail.MonthYear = Month; detail.MonthStartProfile = MonthHire; detail.LeaveInMonth = TotalLeaveHourInMonth; detail.TotalLeaveBef = TotalLeaveHourBeforeMonth; detail.OvertimeInMonth = TotalOvertimeHourInMonth; detail.TotalOvertimeBef = TotalOvertimeHourBeforeMonth; detail.Remain = ((detail.InitAvailable ?? 0) + TotalOvertimeHourBeforeMonth + TotalOvertimeHourInMonth) - (TotalLeaveHourBeforeMonth + TotalLeaveHourInMonth); TotalOvertimeHourBeforeMonth += TotalOvertimeHourInMonth; TotalLeaveHourBeforeMonth += TotalLeaveHourInMonth; #endregion } } repoAtt_CompensationDetail.Add(detailNew); repoAtt_CompensationDetail.SaveChanges(); #endregion } } }
public void AnalyzeCompensation(int Year, List<Guid> lstProfileIDTotal) { //Lấy cấu hình //lấy ngày nghỉ (Bù) //Lấy tăng ca (Bù) //Lấy Ca Làm Việc (Bù) //Hệ Số Tăng Ca (Loại Tăng Ca) foreach (var lstProfileID in lstProfileIDTotal.Chunk(500)) { using (var context = new VnrHrmDataContext()) { #region Khai báo var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); var repoAtt_Overtime = new Att_OvertimeRepository(unitOfWork); var repoAtt_CompensationConfig = new Att_CompensationConfigRepository(unitOfWork); var repoAtt_CompensationDetail = new Att_CompensationDetailRepository(unitOfWork); #endregion #region Lấy Dữ Liệu // var profileByCodeEmp = repoHre_Profile.FindBy(p => p.IsDelete == null && p.CodeEmp == codeEmp).FirstOrDefault(); var lstProfile = repoHre_Profile.FindBy(m => lstProfileID.Contains(m.ID)).Select(m => new { m.ID, m.DateHire }).ToList(); var lstCompensationConfig = repoAtt_CompensationConfig .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)) .Select(m => new CompensationConfigModel() { ID = m.ID, ProfileID = m.ProfileID, Year = m.Year, InitAvailable = m.InitAvailable, MonthBeginInYear = m.MonthBeginInYear, MonthResetInitAvailable = m.MonthResetInitAvailable, MonthStartProfile = m.MonthStartProfile }) .ToList(); int MonthBeginYear = 1; if (lstCompensationConfig != null && lstCompensationConfig.Count>0) { MonthBeginYear = lstCompensationConfig.FirstOrDefault().MonthBeginInYear ?? 1; } DateTime BeginYear = new DateTime(Year, MonthBeginYear, 1); DateTime EndYear = BeginYear.AddYears(1).AddMinutes(-1); string E_APPROVED_Leave = LeaveDayStatus.E_APPROVED.ToString(); var lstLeaveDayCompensationTypeID = repoCat_LeaveDayType .FindBy(m => m.IsTimeOffInLieu == true) .Select(m => m.ID) .ToList(); var lstLeaveday = repoAtt_Leaveday .FindBy(m => m.Status == E_APPROVED_Leave && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstLeaveDayCompensationTypeID.Contains(m.LeaveDayTypeID) && lstProfileID.Contains(m.ProfileID)) .Select(m => new { m.ID, m.ProfileID, m.DateStart, m.DateEnd, m.LeaveHours, m.DurationType }) .ToList(); string E_TIMEOFF = MethodOption.E_TIMEOFF.ToString(); string E_APPROVED_Overtime = OverTimeStatus.E_APPROVED.ToString(); string E_CONFIRM_Overtime = OverTimeStatus.E_CONFIRM.ToString(); var lstOvertime = repoAtt_Overtime .FindBy(m => m.WorkDateRoot >= BeginYear && m.WorkDateRoot <= EndYear && m.MethodPayment == E_TIMEOFF && (m.Status == E_APPROVED_Overtime || m.Status == E_CONFIRM_Overtime) && lstProfileID.Contains(m.ProfileID)) .Select(m => new { m.ID, m.ProfileID, m.WorkDateRoot, m.ApproveHours, m.ConfirmHours, m.Status }).ToList(); string E_APPROVED_Roster = RosterStatus.E_APPROVED.ToString(); var lstRoster = repoAtt_Roster .FindBy(m => m.Status == E_APPROVED_Roster && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstProfileID.Contains(m.ProfileID)) .Select(m => new RosterModel { ID = m.ID, ProfileID = m.ProfileID, DateStart = m.DateStart, DateEnd = m.DateEnd, Type = m.Type, MonShiftID = m.MonShiftID, TueShiftID = m.TueShiftID, WedShiftID = m.WedShiftID, ThuShiftID = m.ThuShiftID, FriShiftID = m.FriShiftID, SatShiftID = m.SatShiftID, SunShiftID = m.SunShiftID }) .ToList(); var lstShift = repoCat_Shift.GetAll().Select(m => new { m.ID, m.WorkHours, m.StdWorkHours }).ToList(); List<Att_CompensationDetail> detailInDB = repoAtt_CompensationDetail .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)) .ToList(); List<Att_CompensationDetail> detailNew = new List<Att_CompensationDetail>(); foreach (var ProfileID in lstProfileID) { double TotalLeaveHourBeforeMonth = 0; double TotalOvertimeHourBeforeMonth = 0; var Profile = lstProfile.Where(m => m.ID == ProfileID).FirstOrDefault(); int MonthHire = 1; if (Profile.DateHire != null && Profile.DateHire >= BeginYear && Profile.DateHire <= EndYear) { if (Profile.DateHire.Value.Day >= 15) { MonthHire = Profile.DateHire.Value.AddMonths(1).Month; } else { MonthHire = Profile.DateHire.Value.Month; } } for (DateTime Month = BeginYear; Month < EndYear; Month = Month.AddMonths(1)) { if (MonthHire > Month.Month) continue; DateTime BeginMonth = Month; DateTime EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1); double TotalLeaveHourInMonth = 0; double TotalOvertimeHourInMonth = 0; #region Tăng Ca var lstOvertimeByProfileByMonth = lstOvertime.Where(m => m.ProfileID == ProfileID && m.WorkDateRoot >= BeginMonth && m.WorkDateRoot <= EndMonth).ToList(); TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_CONFIRM_Overtime).Sum(m => m.ConfirmHours); TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_APPROVED_Overtime).Sum(m => m.ApproveHours ?? 0); #endregion #region Ngày Nghỉ var lstLeavedayByProfileByMonth = lstLeaveday.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList(); var lstRosterByProfileByMonth = lstRoster.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList(); foreach (var Leaveday in lstLeavedayByProfileByMonth) { DateTime dateStart = Leaveday.DateStart < BeginMonth ? BeginMonth : Leaveday.DateStart; DateTime dateEnd = Leaveday.DateEnd > EndMonth ? EndMonth : Leaveday.DateEnd; for (DateTime dateCheck = dateStart; dateCheck <= dateEnd; dateCheck = dateCheck.AddDays(1)) { if (Leaveday.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()) // Trong Ca { TotalLeaveHourInMonth += Leaveday.LeaveHours ?? 0; } else //Toàn Ca { //Check xem có Ca làm việc không Guid? ShiftID = null; var E_TIME_OFF = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_TIME_OFF.ToString()).FirstOrDefault(); var E_CHANGE_SHIFT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_CHANGE_SHIFT.ToString()).FirstOrDefault(); var E_DEFAULT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_DEFAULT.ToString()).FirstOrDefault(); var E_ROSTERGROUP = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_ROSTERGROUP.ToString()).FirstOrDefault(); if (E_TIME_OFF != null) { } else if (E_CHANGE_SHIFT != null) { ShiftID = GetShiftRoster(dateCheck, E_CHANGE_SHIFT); } else if (E_DEFAULT != null) { ShiftID = GetShiftRoster(dateCheck, E_DEFAULT); } else if (E_ROSTERGROUP != null) { //Chưa hỗ trợ đăng ký ca theo nhóm } if (ShiftID != null) { var Shift = lstShift.Where(m => m.ID == ShiftID.Value).FirstOrDefault(); if (Shift != null) { TotalLeaveHourInMonth += Shift.StdWorkHours ?? (Shift.WorkHours ?? 0); } } } } } #endregion #region Gán Dữ Liệu CompensationConfigModel Config = lstCompensationConfig.Where(m => m.ProfileID == ProfileID).FirstOrDefault(); Att_CompensationDetail detail = detailInDB.Where(m => m.MonthYear == Month && m.ProfileID == ProfileID).FirstOrDefault(); if (detail == null) { detail = new Att_CompensationDetail(); detail.ID = Guid.NewGuid(); detailNew.Add(detail); } if (Config != null) { if (Config.MonthResetInitAvailable != null && Config.MonthResetInitAvailable.Value <= Month.Month) { } else { detail.InitAvailable = Config.InitAvailable; } detail.MonthBeginInYear = Config.MonthBeginInYear ?? 1; detail.MonthResetInitAvailable = Config.MonthResetInitAvailable; } detail.ProfileID = ProfileID; detail.Year = Year; detail.MonthYear = Month; detail.MonthStartProfile = MonthHire; detail.LeaveInMonth = TotalLeaveHourInMonth; detail.TotalLeaveBef = TotalLeaveHourBeforeMonth; detail.OvertimeInMonth = TotalOvertimeHourInMonth; detail.TotalOvertimeBef = TotalOvertimeHourBeforeMonth; detail.Remain = ((detail.InitAvailable ?? 0) + TotalOvertimeHourBeforeMonth + TotalOvertimeHourInMonth) - (TotalLeaveHourBeforeMonth + TotalLeaveHourInMonth); TotalOvertimeHourBeforeMonth += TotalOvertimeHourInMonth; TotalLeaveHourBeforeMonth += TotalLeaveHourInMonth; #endregion } } repoAtt_CompensationDetail.Add(detailNew); repoAtt_CompensationDetail.SaveChanges(); #endregion } } }
/// <summary> /// [Tam.Le] - 2014/08/08 /// Hàm xử lý load dữ liệu /// </summary> /// <param name="request"></param> /// <param name="otModel"></param> /// <returns></returns> public DataTable LoadData(DateTime dateStart, DateTime dateEnd, List<Guid> orgIDs, string ProfileName, string CodeEmp, Guid LeavedayType, out string ErrorMessages) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); ErrorMessages = string.Empty; //bool isIncludeQuitEmp = true; List<Guid> leavedayTypeIds = new List<Guid>(); if (LeavedayType != null) leavedayTypeIds.Add(LeavedayType); List<Guid> shiftIDs = new List<Guid>(); string E_WAIT_APPROVED = LeaveDayStatus.E_WAIT_APPROVED.ToString(); string E_SUBMIT = LeaveDayStatus.E_SUBMIT.ToString(); var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork); List<Att_LeaveDay> leaveDays = repoAtt_Leaveday.FindBy(s => s.LeaveDays > 0 && (s.Status == E_WAIT_APPROVED || s.Status == E_SUBMIT) && dateStart <= s.DateEnd && s.DateStart <= dateEnd).ToList<Att_LeaveDay>(); foreach (var item in leaveDays) { item.Status = E_WAIT_APPROVED; } var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList(); var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork); var workDays = repoAtt_Workday.FindBy(s => profileIds.Contains(s.ProfileID) && dateStart <= s.WorkDate && s.WorkDate <= dateEnd) .Select(s => new { s.ProfileID, s.ShiftID, s.WorkDate, s.InTime1, s.OutTime1 }).ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => profileIds.Contains(s.ID)) .Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); var repoCat_Position = new Cat_PositionRepository(unitOfWork); var positions = repoCat_Position.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code }).ToList(); var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork); var jobtitles = repoCat_JobTitle.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code }).ToList(); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var leavedayTypes = repoCat_LeaveDayType.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PaidRate }).Distinct().ToList(); var ledvedayPaidIds = leavedayTypes.Where(s => s.PaidRate > 0).Select(s => s.ID).ToList(); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var shifts = repoCat_Shift.GetAll().ToList(); if (orgIDs != null) { profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); } if (shiftIDs.Count > 0) { workDays = workDays.Where(s => s.ShiftID.HasValue && shiftIDs.Contains(s.ShiftID.Value)).ToList(); profileIds = workDays.Select(s => s.ProfileID).ToList(); profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList(); } if (leavedayTypeIds.Count > 0) { leaveDays = leaveDays.Where(s => leavedayTypeIds.Contains(s.LeaveDayTypeID)).ToList(); profileIds = leaveDays.Select(s => s.ProfileID).ToList(); profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList(); } //if (!isIncludeQuitEmp) //{ // profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateStart).ToList(); //} var startYear = new DateTime(dateStart.Year, 1, 1); var endYear = new DateTime(dateStart.Year, 12, DateTime.DaysInMonth(dateStart.Year, 12)); var rosterStatus = RosterStatus.E_APPROVED.ToString(); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); List<Att_Roster> listRoster = repoAtt_Roster.FindBy(d => d.Status == rosterStatus && profileIds.Contains(d.ProfileID) && d.DateStart <= dateEnd && d.DateEnd >= startYear).ToList<Att_Roster>(); var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork); List<Cat_DayOff> listHoliday = repoCat_DayOff.FindBy(hol => hol.DateOff >= startYear && hol.DateOff <= endYear).ToList<Cat_DayOff>(); var repoAtt_Grade = new Att_GradeRepository(unitOfWork); var listGrade = repoAtt_Grade.FindBy(d => d.MonthStart != null && d.MonthStart <= dateEnd && profileIds.Contains((Guid)d.ProfileID)).Select(d => new { d.ProfileID, d.MonthStart, d.GradeAttendanceID }).ToList(); List<Guid?> listGradeID = listGrade.Select(d => d.GradeAttendanceID).ToList(); var repoCat_Grade = new Cat_GradeAttendanceRepository(unitOfWork); List<Cat_GradeAttendance> listGradeCfg = repoCat_Grade.FindBy(d => listGradeID.Contains(d.ID)).ToList<Cat_GradeAttendance>(); List<Att_Roster> lstRosterTypeGroup = new List<Att_Roster>(); List<Att_RosterGroup> lstRosterGroup = new List<Att_RosterGroup>(); GetRosterGroup(profileIds, startYear, dateEnd, out lstRosterTypeGroup, out lstRosterGroup); var repoHre_WorkHistory = new Hre_WorkHistoryRepository(unitOfWork); List<Hre_WorkHistory> listWorkHistory = repoHre_WorkHistory.FindBy(d => profileIds.Contains(d.ProfileID) && d.DateEffective <= dateEnd).ToList<Hre_WorkHistory>(); var orgTypes = new List<Cat_OrgStructureType>(); var repoorgType = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repoorgType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); DataTable table = GetSchema(); List<string> codeRejects = new List<string>(); codeRejects.Add("SICK"); codeRejects.Add("SU"); codeRejects.Add("SD"); codeRejects.Add("D"); codeRejects.Add("D"); codeRejects.Add("DP"); codeRejects.Add("PSN"); codeRejects.Add("DSP"); codeRejects.Add("M"); List<Guid> leaveDayTypeRejectIDs = leavedayTypes.Where(s => codeRejects.Contains(s.Code)).Select(s => s.ID).ToList(); foreach (var profile in profiles) { var grade = listGrade.Where(d => d.ProfileID == profile.ID && d.MonthStart <= dateEnd).OrderByDescending(d => d.MonthStart).FirstOrDefault(); Cat_GradeAttendance gradeCfg = listGradeCfg.FirstOrDefault(d => grade != null && d.ID == grade.GradeAttendanceID); List<Hre_WorkHistory> listWorkHistoryByProfile = listWorkHistory.Where(d => d.ProfileID == profile.ID).ToList(); List<Att_Roster> listRosterByProfile = listRoster.Where(d => d.ProfileID == profile.ID && d.DateStart <= dateEnd && d.DateEnd >= dateStart).ToList(); var listRosterEntity = listRosterByProfile.Select(d => new Att_RosterEntity { ID = d.ID, ProfileID = d.ProfileID, RosterGroupName = d.RosterGroupName, Type = d.Type, Status = d.Status, DateEnd = d.DateEnd, DateStart = d.DateStart, MonShiftID = d.MonShiftID, TueShiftID = d.TueShiftID, WedShiftID = d.WedShiftID, ThuShiftID = d.ThuShiftID, FriShiftID = d.FriShiftID, SatShiftID = d.SatShiftID, SunShiftID = d.SunShiftID, MonShift2ID = d.MonShiftID, TueShift2ID = d.TueShift2ID, WedShift2ID = d.WedShift2ID, ThuShift2ID = d.ThuShift2ID, FriShift2ID = d.FriShift2ID, SatShift2ID = d.SatShift2ID, SunShift2ID = d.SunShift2ID }).ToList(); var listRosterGroupEntity = lstRosterGroup.Select(d => new Att_RosterGroupEntity { ID = d.ID, DateEnd = d.DateEnd, DateStart = d.DateStart, MonShiftID = d.MonShiftID, TueShiftID = d.TueShiftID, WedShiftID = d.WedShiftID, ThuShiftID = d.ThuShiftID, FriShiftID = d.FriShiftID, SatShiftID = d.SatShiftID, SunShiftID = d.SunShiftID, RosterGroupName = d.RosterGroupName }).ToList(); Dictionary<DateTime, Cat_Shift> listMonthShifts = Att_AttendanceLib.GetDailyShifts(profile.ID, dateStart, dateEnd, listRosterEntity, listRosterGroupEntity, shifts); for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var leavdayProfiles = leaveDays.Where(s => s.DateStart.Date <= date.Date && date.Date <= s.DateEnd.Date && s.ProfileID == profile.ID).ToList(); if (leavdayProfiles.Count > 0) { bool isWorkDay = gradeCfg != null && Att_WorkDayHelper.IsWorkDay(date, gradeCfg, listMonthShifts, listHoliday); var leaveday = leavdayProfiles.FirstOrDefault(s => ledvedayPaidIds.Contains(s.LeaveDayTypeID)); if (!isWorkDay)// neu ngay do ko phai ngay di lam { if (leaveday != null && leaveDayTypeRejectIDs.Contains(leaveday.LeaveDayTypeID) || listHoliday.Exists(s => s.DateOff == date))// neu ngay do la ngay nghi dc xem la ko xem ca or ngay nghi { isWorkDay = true; } } if (isWorkDay) { var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Date == date.Date); DataRow row = table.NewRow(); Guid? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); row[Att_LeaveDayEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.CodeOrg] = orgOrg != null ? orgOrg.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Att_LeaveDayEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Att_LeaveDayEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Att_LeaveDayEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); row[Att_LeaveDayEntity.FieldNames.ProfileName] = profile.ProfileName; row[Att_LeaveDayEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Att_LeaveDayEntity.FieldNames.CodePosition] = positon != null ? positon.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.CodeJobtitle] = jobtitle != null ? jobtitle.Code : string.Empty; var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID); row[Att_LeaveDayEntity.FieldNames.Date] = date; row[Att_LeaveDayEntity.FieldNames.DateFrom] = dateStart; row[Att_LeaveDayEntity.FieldNames.DateTo] = dateEnd; row[Att_LeaveDayEntity.FieldNames.DateExport] = DateTime.Now; //row[Att_LeavedayEntity.FieldNames.UserExport] = Session[SessionObjects.UserLogin]; if (leaveday != null && leaveday.LeaveDays > 0) { row["Paid"] = "X"; } if (workDay != null) { row[Att_LeaveDayEntity.FieldNames.Cat_Shift] = shift.ShiftName; row[Att_LeaveDayEntity.FieldNames.udInTime] = workDay.InTime1 != null ? workDay.InTime1.Value.ToString("HH:mm") : string.Empty; row[Att_LeaveDayEntity.FieldNames.udOutTime] = workDay.OutTime1 != null ? workDay.OutTime1.Value.ToString("HH:mm") : string.Empty; } foreach (var leaday in leavedayTypes) { var leaday1 = leavdayProfiles.FirstOrDefault(s => s.LeaveDayTypeID == leaday.ID); if (leaday1 != null && leaday1.LeaveDays > 0) { row[leaday.Code] = "X"; } } if (leaveday != null) { row[Att_LeaveDayEntity.FieldNames.Status] = leaveday.Status; } table.Rows.Add(row); } } } } //EntityService.SubmitChanges(GuidContext, LoginUserID.Value); context.SaveChanges(); return table; } }
/// <summary> /// [Tam.Le] - 20140725 - Lấy dữ liệu BC Chi Tiết Nhân Viên Không Chấm Công Nhưng Có Ăn /// </summary> /// <param name="CarteringIDs"></param> /// <param name="CanteenIDS"></param> /// <param name="LineIDS"></param> /// <param name="DateFrom"></param> /// <param name="DateTo"></param> /// <returns></returns> public List <Can_ReportMealTimeDetailEntity> ReportMealTimeDetail(List <int?> CarteringIDs, List <int?> CanteenIDS, List <int?> LineIDS, DateTime dateStart, DateTime dateEnd, List <int?> orgIDs) { var mealRecords = new List <Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Can_MealRecordRepository(unitOfWork); if (LineIDS != null) { mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true) .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }) .ToList(); } else { mealRecords = repo.GetAll().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList(); } } var lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList(); var lstProfile = new List <Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Hre_ProfileRepository(unitOfWork); lstProfile = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance)) .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList(); } List <Cat_OrgStructure> orgs = new List <Cat_OrgStructure>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Cat_OrgStructureRepository(unitOfWork); orgs = repo.FindBy(s => s.Code != null).ToList(); } lstProfile = lstProfile.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); //if (!isIncludeQuitEmp) //{ // profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList(); // profileIds = profiles.Select(s => s.ID).ToList(); // mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList(); //} if (CanteenIDS[0] != null) { mealRecords = mealRecords.Where(s => s.CanteenID != null && CanteenIDS.Contains(s.CanteenID.Value)).ToList(); } if (CarteringIDs[0] != null) { mealRecords = mealRecords.Where(s => s.CateringID != null && CarteringIDs.Contains(s.CateringID.Value)).ToList(); } if (LineIDS[0] != null) { mealRecords = mealRecords.Where(s => s.LineID != null && LineIDS.Contains(s.LineID.Value)).ToList(); } lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList(); List <Hre_Profile> profiles = new List <Hre_Profile>(); var lstProfileId = new List <int>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Hre_ProfileRepository(unitOfWork); profiles = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance)).ToList(); lstProfileId = profiles.Select(s => s.Id).ToList(); } var orgTypes = new List <Cat_OrgStructureType>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repo.FindBy(s => s.IsDelete == null).ToList <Cat_OrgStructureType>(); } Can_ReportMealTimeDetailEntity reportMealTimeDetailEntity = null; List <Can_ReportMealTimeDetailEntity> lstreportMealTimeDetailEntity = new List <Can_ReportMealTimeDetailEntity>(); foreach (var mealRecord in mealRecords) { var profile = profiles.FirstOrDefault(s => s.CodeAttendance == mealRecord.CardCode); if (profile != null) { int?orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.Id == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); reportMealTimeDetailEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty; reportMealTimeDetailEntity.OrgCode = orgOrg != null ? orgOrg.Code : string.Empty; reportMealTimeDetailEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty; reportMealTimeDetailEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty; reportMealTimeDetailEntity.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; reportMealTimeDetailEntity.OrgName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; reportMealTimeDetailEntity.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; reportMealTimeDetailEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty; reportMealTimeDetailEntity.CodeEmp = profile.CodeEmp; reportMealTimeDetailEntity.ProfileName = profile.ProfileName; reportMealTimeDetailEntity.Date = mealRecord.TimeLog; } lstreportMealTimeDetailEntity.Add(reportMealTimeDetailEntity); } return(lstreportMealTimeDetailEntity); }
public DataTable GetReportSumaryReturnMoneyEat(List<Guid?> cateringIDs, List<Guid?> canteenIDs, List<Guid?> lineIDs, List<Guid?> workPlaceIds, DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs, String codeEmp, Boolean IsIncludeQuitEmp) { DataTable datatable = CreateReportSumaryReturnMoneyEatSchema(); using (var context = new VnrHrmDataContext()) { DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork); var mealRecords = repoCan_MealRecord.FindBy(s => s.ProfileID != null && s.WorkDay != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).Select( s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.NoWorkDay, s.WorkDay }).ToList(); if (mealRecords == null && mealRecords.Count < 1) { return datatable; } var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList(); var repoWorkDay = new Att_WorkDayRepository(unitOfWork); var workDayProfies = repoWorkDay.FindBy(s => (s.FirstInTime != null || s.LastOutTime != null) && dateStart <= s.WorkDate && s.WorkDate <= dateEnd && profileIds.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.WorkDate }).ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(m => profileIds.Contains(m.ID)).ToList(); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); var repoHre_HDTJob = new Hre_HDTJobRepository(unitOfWork); var profileHDTJIDs = repoHre_HDTJob.FindBy(s => s.DateTo >= dateStart && s.DateFrom <= dateEnd).Select(s => s.ProfileID).ToList(); var repoCan_Line = new Can_LineRepository(unitOfWork); var lineHDTJIDs = repoCan_Line.FindBy(s => s.HDTJ != null).Select(s => s.ID).ToList(); var repoCan_MealAllowanceTypeSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork); var amountStardand = repoCan_MealAllowanceTypeSetting.FindBy(s => s.Standard == true && s.Amount != null).Select(s => s.Amount).FirstOrDefault(); var repoLeaveDay = new Att_LeavedayRepository(unitOfWork); var leavedays = repoLeaveDay.FindBy(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && profileIds.Contains(s.ProfileID)) .Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList(); if (orgIDs != null && orgIDs[0] != null) { profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); } if (workPlaceIds != null && workPlaceIds[0] != null) { profiles = profiles.Where(s => workPlaceIds.Contains(s.WorkPlaceID)).ToList(); } if (IsIncludeQuitEmp != true) { profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList(); //profileIds = profiles.Select(s => s.ID).ToList(); //mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList(); } if (!string.IsNullOrEmpty(codeEmp)) { char[] ext = new char[] { ';', ',' }; List<string> codeEmpSeachs = codeEmp.Split(ext, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); if (codeEmpSeachs.Count == 1) { string codeEmpSearch = codeEmpSeachs[0]; profiles = profiles.Where(hr => hr.CodeEmp == codeEmpSearch).ToList(); } else { profiles = profiles.Where(hr => codeEmpSeachs.Contains(hr.CodeEmp)).ToList(); } } profileIds = profiles.Select(s => s.ID).ToList(); mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList(); if (canteenIDs != null && canteenIDs[0] != null) { mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList(); } if (cateringIDs != null && cateringIDs[0] != null) { mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList(); } if (lineIDs != null && lineIDs[0] != null) { mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList(); } var codeAttendaceByProfile = profiles.Select(m => m.ID).ToList(); if (codeAttendaceByProfile != null && codeAttendaceByProfile.Count > 0) { mealRecords = mealRecords.Where(m => m.ProfileID != null && codeAttendaceByProfile.Contains(m.ProfileID.Value)).ToList(); } if (mealRecords == null && mealRecords.Count < 1) { return datatable; } profileIds = profiles.Select(s => s.ID).ToList(); mealRecords = mealRecords.Where(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value)).ToList(); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); var repoLine = new Can_LineRepository(unitOfWork); var lines = repoLine.FindBy(s => s.Amount != null && s.HDTJ == null && s.Amount != amountStardand).Select(s => new { s.Amount.Value, s.ID }).Distinct().ToList(); foreach (var profile in profiles) { var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList(); var mealProfiles = mealRecords.Where(s => s.ProfileID == profile.ID).ToList(); DataRow row = datatable.NewRow(); Guid? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes); row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.ProfileName] = profile.ProfileName; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DateFrom] = dateStart; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DateTo] = dateEnd; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DatePrint] = DateTime.Now; bool isAdd = false; var amounts = lines.Select(s => s.Value).Distinct().ToList(); foreach (var amount in amounts) { var countCareing = 0; double sumCareing = 0; var line1IDs = lines.Where(s => s.Value == amount).Select(s => s.ID).ToList(); for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var leaday = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd); countCareing += mealProfiles.Count(s => line1IDs.Contains(s.LineID.Value) && s.WorkDay.Value.Date == date.Date && (workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null)); var sumAmount = mealProfiles.Where(s => line1IDs.Contains(s.LineID.Value) && s.WorkDay.Value.Date == date.Date && (workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null)).Sum(s => s.Amount); if (sumAmount > 0) { sumCareing += (double)(sumAmount.Value - amountStardand.Value); } } if (countCareing > 0) { isAdd = true; row[amount.ToString()] = countCareing; row["Số Tiền " + amount] = sumCareing; } } var countSard = mealProfiles.Where(hr => hr.WorkDay != null).Count(hr => hr.Amount == amountStardand && workdayProfileDates.Contains(hr.WorkDay.Value.Date)); var countWorkDay = workDayProfies.Where(wd => wd.WorkDate != null).Count(wd => workdayProfileDates.Contains(wd.WorkDate.Date)); if (countSard > 0) row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountSandard] = countSard; if (countWorkDay > 0) row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountWorkDay] = countWorkDay; var countCardMore1 = 0; double sumAmountNotStardand = 0;// tong so tien quet the ko dat chuan double? sumAmountHDTJOB = 0;// tong so tien cua nhan vien ko phai HDTJOb ma an o cua an HDTJOB sumAmountHDTJOB = (double?)mealProfiles.Where(s => s.ProfileID == profile.ID && s.LineID != null && lineHDTJIDs.Contains(s.LineID.Value) && !profileHDTJIDs.Contains(s.ProfileID.Value)).Sum(s => s.Amount); double sumAmountNotWorkHasEat = 0;// tong so tien ko di lam ma co an var countNotWorkButHasEat = 0; for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var leaday = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd); if (mealProfiles.Count(s => s.WorkDay.Value.Date == date.Date) > 1) { countCardMore1++; } var amount = mealProfiles.FirstOrDefault(s => s.WorkDay.Value.Date == date.Date); if (amount != null) { sumAmountNotStardand += (double)(amount.Amount.Value - amountStardand.Value); } var meal = mealProfiles.FirstOrDefault(s => date.Date == s.WorkDay.Value.Date && (!workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null)); if (meal != null) { countNotWorkButHasEat++; sumAmountNotWorkHasEat += (double)meal.Amount.Value; } } if (countCardMore1 > 0) { row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountCardMore] = countCardMore1; isAdd = true; } var sumCardMore = countCardMore1 * amountStardand.Value; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumAmountCardMore] = sumCardMore; if (countNotWorkButHasEat > 0) { row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountNotWorkButHasEat] = countNotWorkButHasEat; row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumNotWorkButHasEat] = sumAmountNotWorkHasEat; isAdd = true; } var sum = Math.Round((sumAmountNotWorkHasEat + sumAmountNotStardand + (double)sumCardMore), 0); row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumAmountMustSubtract] = sum == 0 ? (object)DBNull.Value : sum; sum = Math.Round(sumAmountHDTJOB.Value, 0); if (sum > 0) { row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.MoneyMustSubtractHDT] = sum; isAdd = true; } sum = Math.Round((sumAmountNotWorkHasEat + sumAmountNotStardand + sumAmountHDTJOB.Value + (double)sumCardMore), 0); if (sum > 0) { row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumMoneyMustSubtract] = sum; isAdd = true; } if (isAdd) datatable.Rows.Add(row); } return datatable; } }