/// <summary> /// Lấy tất cả dữ liệu /// </summary> /// <returns></returns> public List<Cat_DayOffEntity> GetAll() { using (var context = new VnrHrmDataContext()) { List<Cat_DayOffEntity> lstSource = new List<Cat_DayOffEntity>(); IUnitOfWork unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); Cat_DayOffRepository repo = new Cat_DayOffRepository(unitOfWork); var data = repo.FindBy(s => s.IsDelete == null).ToList(); if (data.Count > 0) lstSource = data.Translate<Cat_DayOffEntity>(); return lstSource; } }
/// <summary> /// Lấy tất cả dữ liệu /// </summary> /// <returns></returns> public List <Cat_DayOffEntity> GetAll() { using (var context = new VnrHrmDataContext()) { List <Cat_DayOffEntity> lstSource = new List <Cat_DayOffEntity>(); IUnitOfWork unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); Cat_DayOffRepository repo = new Cat_DayOffRepository(unitOfWork); var data = repo.FindBy(s => s.IsDelete == null).ToList(); if (data.Count > 0) { lstSource = data.Translate <Cat_DayOffEntity>(); } return(lstSource); } }
public DataTable LoadDataAnalyzeOvertime_DataLimit(string strOrgStructure, DateTime DateStart, DateTime DateEnd, List<Hre_ProfileEntity> lstProfile, List<string> lstTypeData, Att_OvertimeInfoFillterAnalyze _OvertimeInfoFillterAnalyzeEntity, string userLogin) { DataTable table = GetSchemaExportExcel(); string status = string.Empty; DateStart = DateStart.Date; DateEnd = DateEnd.Date.AddDays(1).AddMilliseconds(-1); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_WorkDay = new Att_WorkDayRepository(unitOfWork); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var repoCat_ShiftItem = new Cat_ShiftItemRepository(unitOfWork); var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork); var repoCat_OvertimeType = new Cat_OvertimeTypeRepository(unitOfWork); var repoCat_OrgStructure = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork); var repoCat_OrgStructureType = new CustomBaseRepository<Cat_OrgStructureType>(unitOfWork); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); var orgs = repoCat_OrgStructure.FindBy(s => s.IsDelete == null && s.Code != null).ToList(); List<WorkdayCustom> lstWorkday = new List<WorkdayCustom>(); List<Guid> lstProfileId = lstProfile.Select(s => s.ID).ToList(); List<object> lst3ParamSE = new List<object>(); lst3ParamSE.Add(strOrgStructure); lst3ParamSE.Add(DateStart); lst3ParamSE.Add(DateEnd); if (lstProfile.Count > 0 && strOrgStructure == null) { var lstWD = repoAtt_WorkDay.FindBy(s => s.IsDelete == null && s.WorkDate >= DateStart && s.WorkDate <= DateEnd && lstProfileId.Contains(s.ProfileID)).ToList(); if (lstWD.Count > 0) { lstWorkday = lstWD.Translate<WorkdayCustom>(); } } else { lstWorkday = GetData<WorkdayCustom>(lst3ParamSE, ConstantSql.hrm_att_getdata_Workday, userLogin, ref status).ToList(); } //var lstWorkdayQuery = repoAtt_WorkDay.FindBy(m => m.IsDelete == null && m.WorkDate >= DateStart && m.WorkDate <= DateEnd); //if (lstProfileId.Count > 0) //{ // lstWorkdayQuery = lstWorkdayQuery.Where(m => lstProfileId.Contains(m.ProfileID)); //} //lstWorkday = lstWorkdayQuery.ToList().Translate<Att_WorkdayEntity>(); List<Cat_ShiftEntity> lstShift = repoCat_Shift .FindBy(s => s.IsDelete == null) .ToList() .Translate<Cat_ShiftEntity>(); List<Cat_ShiftItemEntity> lstShiftItem = repoCat_ShiftItem .FindBy(s => s.IsDelete == null) .ToList() .Translate<Cat_ShiftItemEntity>(); List<Cat_DayOffEntity> LstDayOff = repoCat_DayOff .FindBy(m => m.IsDelete == null && m.DateOff >= DateStart && m.DateOff < DateEnd) .ToList() .Translate<Cat_DayOffEntity>(); List<Cat_OvertimeTypeEntity> lstOvertimeType = repoCat_OvertimeType .FindBy(s => s.IsDelete == null).ToList() .Translate<Cat_OvertimeTypeEntity>(); string E_CANCEL = OverTimeStatus.E_CANCEL.ToString(); string E_REJECTED = OverTimeStatus.E_REJECTED.ToString(); DateTime beforeDateStart = DateStart.Date.AddDays(-1); DateTime afterDateEnd = DateEnd.Date.AddDays(2).AddMinutes(-1); // string E_HOLIDAY_HLD = HolidayType.E_HOLIDAY_HLD.ToString(); List<DateTime> lstHoliday = repoCat_DayOff .FindBy(s => s.IsDelete == null) .Select(m => m.DateOff).ToList<DateTime>(); //lstWorkday = filterData_NonAllowOT_inGrade(lstWorkday); List<Att_OvertimeEntity> lstOvertimeCal = AnalyzeOvertime(lstWorkday, lstShift, lstShiftItem, LstDayOff, lstOvertimeType, _OvertimeInfoFillterAnalyzeEntity, userLogin); if (lstOvertimeCal.Count == 0) { lstOvertimeCache = lstOvertimeCal; return table; } OvertimePermitEntity overtimePermit = getOvertimePermit(userLogin); FilterNonOvertimeByGradeConfig(lstOvertimeCal); SetNonOT(lstOvertimeCal); SetStatusOvertimeOnWorkday(lstOvertimeCal); FilterOvertimeByMaxHourPerDay(lstOvertimeCal, overtimePermit, _OvertimeInfoFillterAnalyzeEntity.MaximumOvertimeHour); RoundOT(lstOvertimeCal, userLogin); FillterAllowOvertime(context, lstOvertimeCal, overtimePermit, lstWorkday); RoundOT(lstOvertimeCal, userLogin); lstOvertimeCal = lstOvertimeCal.Where(m => m.RegisterHours != null && m.RegisterHours > 0).ToList(); SetStatusLeaveOnWorkday(lstOvertimeCal);//Set loại ngày nghỉ cho OT if (lstTypeData.Count > 0) { Expression<Func<Att_OvertimeEntity, bool>> predicate = VnResource.Helper.Linq.PredicateBuilder.False<Att_OvertimeEntity>(); if (lstTypeData.Any(m => m == ComputeLeavedayType.E_DATA_LEAVE.ToString())) { Expression<Func<Att_OvertimeEntity, bool>> predicate1 = m => m.udLeaveTypeCode != null || m.udLeaveTypeCode2 != null; predicate = predicate.Or(predicate1); //lstOvertimeCal = lstOvertimeCal.Where(m => (m.udLeaveTypeCode == null || m.udLeaveTypeCode == string.Empty) && (m.udLeaveTypeCode2 == null || m.udLeaveTypeCode2 == string.Empty)).ToList(); } if (lstTypeData.Any(m => m == ComputeLeavedayType.E_DATA_NON_LEAVE.ToString())) { Expression<Func<Att_OvertimeEntity, bool>> predicate2 = m => (m.udLeaveTypeCode == null || m.udLeaveTypeCode == string.Empty) && (m.udLeaveTypeCode2 == null || m.udLeaveTypeCode2 == string.Empty); predicate = predicate.Or(predicate2); //lstOvertimeCal = lstOvertimeCal.Where(m => m.udLeaveTypeCode != null || m.udLeaveTypeCode2 != null).ToList(); } if (lstTypeData.Any(m => m == ComputeOvertimeType.E_DATA_OT.ToString())) { Expression<Func<Att_OvertimeEntity, bool>> predicate2 = m => m.udOvertimeStatus != null; predicate = predicate.Or(predicate2); } if (lstTypeData.Any(m => m == ComputeOvertimeType.E_DATA_NON_OT.ToString())) { Expression<Func<Att_OvertimeEntity, bool>> predicate2 = m => m.udOvertimeStatus == null; predicate = predicate.Or(predicate2); } lstOvertimeCal = lstOvertimeCal.AsQueryable().Where(predicate).ToList(); } //lstOvertimeCal = lstOvertimeCal.OrderBy(m => m.WorkDate.Date).ThenBy(m => m.ProfileID).ToList(); //lstOvertimeCache = lstOvertimeCal; //BindToGrid(lstOvertimeCache); lstOvertimeCal = lstOvertimeCal .Where(m => m.udIsLimitHour == true || m.udIsLimitHourLv1 == true || m.udIsLimitHourLv2 == true) .OrderBy(m => m.WorkDate.Date) .ThenBy(m => m.ProfileID) .ToList(); //lstOvertimeCal.ForEach(s => s.IsValid = false); #region process return table foreach (var item in lstOvertimeCal) { DataRow row = table.NewRow(); Guid? orgId = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault().OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == orgId); 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_OvertimeEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty; row[Att_OvertimeEntity.FieldNames.OrgStructureCode] = orgOrg != null ? orgOrg.Code : string.Empty; row[Att_OvertimeEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty; row[Att_OvertimeEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty; row[Att_OvertimeEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Att_OvertimeEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Att_OvertimeEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Att_OvertimeEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Att_OvertimeEntity.FieldNames.WorkDate] = item.WorkDate; row[Att_OvertimeEntity.FieldNames.InTime] = item.InTime; row[Att_OvertimeEntity.FieldNames.OutTime] = item.OutTime; if (item.udIsLimitHour == null || item.udIsLimitHour == false) { row[Att_OvertimeEntity.FieldNames.Valid] = "Level1"; } else if (item.udIsLimitHourLv1 == null || item.udIsLimitHourLv1 == false) { row[Att_OvertimeEntity.FieldNames.Valid] = "Level2"; } else if (item.udIsLimitHourLv2 == null || item.udIsLimitHourLv2 == false) { row[Att_OvertimeEntity.FieldNames.Valid] = "Level3"; } else { row[Att_OvertimeEntity.FieldNames.Valid] = string.Empty; } if (item.OvertimeTypeID != Guid.Empty) { var OTType = lstOvertimeType.Where(s => s.ID == item.OvertimeTypeID).FirstOrDefault(); row[Att_OvertimeEntity.FieldNames.OvertimeTypeID] = item.OvertimeTypeID; row[Att_OvertimeEntity.FieldNames.OvertimeTypeName] = OTType.OvertimeTypeName; row[OTType.Code] = item.RegisterHours; row[OTType.Code + "Confirm"] = item.ApproveHours ?? 0.0; } if (item.ShiftID != Guid.Empty) { var _shift = lstShift.Where(s => s.ID == item.ShiftID).FirstOrDefault(); row[Att_OvertimeEntity.FieldNames.ShiftID] = item.ShiftID; row[Att_OvertimeEntity.FieldNames.ShiftName] = _shift.ShiftName; } if (item.ProfileID != Guid.Empty) { var temp = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault(); row[Att_OvertimeEntity.FieldNames.ProfileID] = item.ProfileID; row[Att_OvertimeEntity.FieldNames.ProfileName] = temp.ProfileName; row[Att_OvertimeEntity.FieldNames.CodeEmp] = temp.CodeEmp; //row[Att_ReportDetailOvertimeEntity.FieldNames.OrgStructureName] = temp.OrgStructureName; } row[Att_OvertimeEntity.FieldNames.TotalRow] = lstOvertimeCal.Count; row[Att_OvertimeEntity.FieldNames.DateExport] = DateTime.Now; row[Att_OvertimeEntity.FieldNames.AnalyseHour] = item.AnalyseHour; row[Att_OvertimeEntity.FieldNames.udHourByDate] = item.udHourByDate; row[Att_OvertimeEntity.FieldNames.udHourByWeek] = item.udHourByWeek; row[Att_OvertimeEntity.FieldNames.udHourByMonth] = item.udHourByMonth; row[Att_OvertimeEntity.FieldNames.udHourByYear] = item.udHourByYear; row[Att_OvertimeEntity.FieldNames.udLeaveTypeCode] = item.udLeaveTypeCode; row[Att_OvertimeEntity.FieldNames.udOvertimeStatus] = item.udOvertimeStatus; row[Att_OvertimeEntity.FieldNames.RegisterHours] = item.RegisterHours; row[Att_OvertimeEntity.FieldNames.ApproveHours] = item.RegisterHours; table.Rows.Add(row); } #endregion return table; } }
public void SetStatusLeaveOnWorkday(List<Att_WorkdayEntity> lstWorkday) { if (lstWorkday == null || lstWorkday.Count == 0) return; List<Guid> lstProfileId = lstWorkday.Select(m => m.ProfileID).ToList(); DateTime DateMin = lstWorkday.Min(m => m.WorkDate); DateTime DateMax = lstWorkday.Max(m => m.WorkDate); DateMax = DateMax.Date.AddDays(1).AddMinutes(-1); string E_CANCEL = AttendanceDataStatus.E_CANCEL.ToString(); string E_REJECTED = AttendanceDataStatus.E_REJECTED.ToString(); var lstLeaveDay = new List<Att_LeaveDay>().Select(m => new { m.ID, m.ProfileID, m.DateStart, m.DateEnd, m.LeaveHours, m.LeaveDayTypeID, m.Status }).ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork); var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); lstLeaveDay = repoAtt_Leaveday .FindBy(m => m.Status != E_CANCEL && m.Status != E_REJECTED && m.DateStart <= DateMax && m.DateEnd >= DateMin && lstProfileId.Contains(m.ProfileID) && m.IsDelete == null) .Select(m => new { m.ID, m.ProfileID, m.DateStart, m.DateEnd, m.LeaveHours, m.LeaveDayTypeID, m.Status }).ToList(); var lstLeaveType = repoCat_LeaveDayType.FindBy(s => s.IsDelete == null).Select(m => new { m.ID, m.Code, m.CodeStatistic }).ToList(); var lstDayOffHoliday = repoCat_DayOff.FindBy(m => m.DateOff != null && m.IsDelete == null).Select(m => new { m.DateOff, m.Type }).ToList(); foreach (var item in lstWorkday) { Guid profileId = item.ProfileID; DateTime workDate = item.WorkDate.Date; var Dayoff = lstDayOffHoliday.Where(m => m.DateOff == workDate).FirstOrDefault(); if (Dayoff != null) { string code = string.Empty; if (Dayoff.Type == HolidayType.E_HOLIDAY_HLD.ToString()) { code = "HLD"; } else if (Dayoff.Type == HolidayType.E_WEEKEND_HLD.ToString()) { code = "WH"; } else { code = "CH"; } var leavetype = lstLeaveType.Where(m => m.Code == code).FirstOrDefault(); if (leavetype == null) { continue; } string leavedayCode = !string.IsNullOrEmpty(leavetype.CodeStatistic) ? leavetype.CodeStatistic : leavetype.Code; item.udLeavedayCode1 = leavedayCode; continue; } var lstLeaveDayByProfile = lstLeaveDay.Where(m => m.ProfileID == profileId && m.DateStart.Date <= workDate && m.DateEnd.Date >= workDate).ToList(); int Num = 0; foreach (var leaveDay in lstLeaveDayByProfile) { Num++; if (Num == 3) break; if (leaveDay != null) { if (Num == 1) { var leavetype = lstLeaveType.Where(m => m.ID == leaveDay.LeaveDayTypeID).FirstOrDefault(); if (leavetype != null) { string leavedayCode = !string.IsNullOrEmpty(leavetype.CodeStatistic) ? leavetype.CodeStatistic : leavetype.Code; item.udLeavedayCode1 = leavedayCode; } item.udLeavedayStatus1 = leaveDay.Status; } else if (Num == 2) { var leavetype = lstLeaveType.Where(m => m.ID == leaveDay.LeaveDayTypeID).FirstOrDefault(); if (leavetype != null) { string leavedayCode = !string.IsNullOrEmpty(leavetype.CodeStatistic) ? leavetype.CodeStatistic : leavetype.Code; item.udLeavedayCode2 = leavedayCode; } item.udLeavedayStatus2 = leaveDay.Status; } } } } } return; }
/// <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; } }
public DataTable GetReportDetailedMonthlyStay(DateTime dateStart, DateTime dateEnd, List<Hre_ProfileEntity> profiles, string orgStructureID, bool isIncludeQuitEmp, Guid[] leaveDayTypeIDs, string codeEmp, bool isNotAllowZero, string userExport, bool IsCreateTemplate, string UserLogin) { using (var context = new VnrHrmDataContext()) { var baseservice = new BaseService(); string key = OverTimeStatus.E_APPROVED.ToString(); DataTable table = CreateReportDetailedMonthlyStaySchema(leaveDayTypeIDs, dateStart, dateEnd); if (IsCreateTemplate) { return table.ConfigTable(); } var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); var repoCat_LeaveDayTypeRepository = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork); var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var repoCat_GradeAtt = new Cat_GradeAttendanceRepository(unitOfWork); var repoHre_WorkHistory = new Hre_WorkHistoryRepository(unitOfWork); var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork); List<Guid> lstProfileIDs = profiles.Select(s => s.ID).ToList(); List<Att_LeaveDayEntity> leaveDays = new List<Att_LeaveDayEntity>(); List<Cat_LeaveDayType> leavedaytypes = new List<Cat_LeaveDayType>(); string status = string.Empty; List<object> para = new List<object>(); para.AddRange(new object[3]); para[0] = (object)orgStructureID; para[1] = dateStart; para[2] = dateEnd; if (lstProfileIDs != null && lstProfileIDs.Count > 0) { leaveDays = baseservice.GetData<Att_LeaveDayEntity>(para, ConstantSql.hrm_att_getdata_LeaveDay, UserLogin, ref status).Where(s => s.Status == key).ToList(); } else { return table.ConfigTable(); } //[Tho.Bui] Get LeavedayR=type if (leaveDays != null && leaveDays.Count > 0) { List<Guid> lstLDTinLD = leaveDays.Select(s => s.LeaveDayTypeID).Distinct().ToList(); leavedaytypes = repoCat_LeaveDayTypeRepository.FindBy(s => s.IsDelete == null && lstLDTinLD.Contains(s.ID)).ToList(); List<Guid> leavedayguid = leaveDays.Select(s => s.LeaveDayTypeID).ToList(); leavedaytypes = leavedaytypes.Where(s => leavedayguid.Contains(s.ID)).ToList(); } var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList(); var rosterStatus = RosterStatus.E_APPROVED.ToString(); var _rosters = new List<Att_Roster>(); foreach (var tempProfileIds in lstProfileIDs.Chunk(1000)) { _rosters.AddRange(unitOfWork.CreateQueryable<Att_Roster>(Guid.Empty, d => tempProfileIds.Contains(d.ProfileID) && d.Status == rosterStatus && d.DateStart <= dateEnd && d.DateEnd >= dateStart).ToList()); } var rosters = new List<Att_RosterEntity>(); if (_rosters.Count > 0) rosters = _rosters.Translate<Att_RosterEntity>(); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var leavedayTypes = repoCat_LeaveDayType.FindBy(s => s.Code != null && s.IsDelete == null).Select(s => new { s.Code, s.ID, s.PaidRate, s.LeaveDayTypeName }).ToList(); var leavdayPadidIDs = leavedayTypes.Where(s => s.PaidRate > 0).Select(s => s.ID).ToList(); List<Guid> guids = profiles.Select(s => s.ID).ToList(); leaveDays = leaveDays.Where(s => guids.Contains(s.ProfileID)).ToList(); if (leaveDayTypeIDs != null) { 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 > dateEnd).ToList(); } //var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList(); var shifts = unitOfWork.CreateQueryable<Cat_Shift>(Guid.Empty).ToList().Translate<Cat_ShiftEntity>(); List<string> codeRejects = new List<string>(); codeRejects.Add("SICK"); codeRejects.Add("SU"); codeRejects.Add("SD"); 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(); if (isNotAllowZero) { var profileIDs = leaveDays.Select(s => s.ProfileID).ToList(); profiles = profiles.Where(s => profileIDs.Contains(s.ID)).ToList(); } #region sai xong xóa string CodeEmpTest = string.Empty; if (CodeEmpTest != string.Empty) { char[] ext = new char[] { ';', ',' }; List<string> lstCodeEmpTest = CodeEmpTest.Split(ext, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); profiles = profiles.Where(m => lstCodeEmpTest.Contains(m.CodeEmp)).ToList(); } #endregion var leveDayIDs = leaveDays.Select(s => s.LeaveDayTypeID).ToList(); leavedayTypes = leavedayTypes.Where(s => leveDayIDs.Contains(s.ID)).ToList(); var holidayDates = repoCat_DayOff.FindBy(hol => hol.DateOff >= dateStart && hol.DateOff <= dateEnd).Select(s => s.DateOff).ToList(); holidayDates = holidayDates.Select(s => s.Date).ToList(); var lstRosterGroup = unitOfWork.CreateQueryable<Att_RosterGroup>(Guid.Empty, s => s.DateStart != null && s.DateStart >= dateStart && s.DateEnd != null && s.DateEnd <= dateEnd).ToList().Translate<Att_RosterGroupEntity>(); foreach (var profile in profiles) { var rosterProfiles = rosters.Where(s => s.ProfileID == profile.ID).ToList(); List<DateTime> workDayDates = new List<DateTime>(); foreach (var roster in rosterProfiles) { for (DateTime date = roster.DateStart; date <= roster.DateEnd; date = date.AddDays(1)) { workDayDates.Add(date.Date); } } workDayDates = workDayDates.Where(s => !holidayDates.Contains(s.Date)).ToList(); DataRow row = table.NewRow(); var leaveDay = leaveDays.FirstOrDefault(s => s.ProfileID == profile.ID); var LeaveDayType = leavedaytypes.FirstOrDefault(s => s.ID != Guid.Empty && leaveDay != null && s.ID == leaveDay.LeaveDayTypeID); row[Att_ReportDetailedMonthlyStayEntity.FieldNames.ProfileName] = profile.ProfileName; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.CodeEmp] = profile.CodeEmp; if (profile.E_COMPANY != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_COMPANY] = profile.E_COMPANY; if (profile.E_BRANCH != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_BRANCH] = profile.E_BRANCH; if (profile.E_UNIT != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_UNIT] = profile.E_UNIT; if (profile.E_DIVISION != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_DIVISION] = profile.E_DIVISION; if (profile.E_DEPARTMENT != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_DEPARTMENT] = profile.E_DEPARTMENT; if (profile.E_TEAM != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_TEAM] = profile.E_TEAM; if (profile.E_SECTION != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_SECTION] = profile.E_SECTION; if (profile.JobTitleName != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.JobTitleName] = profile.JobTitleName; if (profile.PositionName != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.PositionName] = profile.PositionName; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.DateFrom] = dateStart; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.DateTo] = dateEnd; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.UserExport] = userExport; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.DateExport] = DateTime.Today; var leadayProfiles = leaveDays.Where(s => s.ProfileID == profile.ID).ToList(); var ledayeTyepIDs = leadayProfiles.Select(s => s.LeaveDayTypeID).ToList(); double sumPaid = 0; foreach (var leadayType in leavedayTypes.Where(s => ledayeTyepIDs.Contains(s.ID)).ToList()) { double sum = 0; var leavdayProfiles = leadayProfiles.Where(s => s.LeaveDayTypeID == leadayType.ID).ToList(); foreach (var leavdayProfile in leavdayProfiles) { var DateEnd = leavdayProfile.DateEnd; if (DateEnd > dateEnd) { DateEnd = dateEnd; } for (DateTime date = leavdayProfile.DateStart; date <= DateEnd; date = date.AddDays(1)) { bool isWorkDay = workDayDates.Contains(date); if (!isWorkDay)// neu ngay do ko phai ngay di lam { if (leaveDayTypeRejectIDs.Contains(leavdayProfile.LeaveDayTypeID))// neu ngay do la ngay nghi dc xem la ko xem ca or ngay nghi { isWorkDay = true; } } if (isWorkDay) { if (leavdayProfile.Duration > 0) { //sum++; sum += leavdayProfile.Duration; } if (leavdayPadidIDs.Contains(leavdayProfile.LeaveDayTypeID)) { sumPaid += leadayType.PaidRate; //sumPaid++; } } } } row[leadayType.Code] = sum > 0 ? (object)sum : DBNull.Value; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.Paid] = sumPaid > 0 ? (object)sumPaid : DBNull.Value; } #region tinh so gio nghi tung ngay cua nhan vien var leavdayByProfile = leadayProfiles.Where(s => s.ProfileID == profile.ID).ToList(); Dictionary<DateTime, List<Guid?>> tempShiftByDate = new Dictionary<DateTime, List<Guid?>>(); tempShiftByDate = Att_AttendanceLib.GetDailyShifts(dateStart, dateEnd, profile.ID, rosterProfiles, lstRosterGroup); foreach (var leavdayProfile in leavdayByProfile) { for (DateTime date = dateStart; date < dateEnd; date = date.AddDays(1)) { bool isWorkDay = workDayDates.Contains(date); if (isWorkDay) { //lay ca lam viec cua nhan vien if (tempShiftByDate != null) { var lstShiftID = tempShiftByDate.Where(s => s.Key == date).SelectMany(s => s.Value).ToList(); if (lstShiftID.Count > 0) { var lstShiftProfileByDate = shifts.Where(s => s.WorkHours != null && lstShiftID.Contains(s.ID)).ToList(); double? _tempWorkHour = 0; _tempWorkHour = lstShiftProfileByDate.Sum(s => s.WorkHours); if (_tempWorkHour > 0) { row["Day" + date.Day.ToString()] = _tempWorkHour; } } } } } } #endregion table.Rows.Add(row); } var configs = new Dictionary<string, Dictionary<string, object>>(); var config = new Dictionary<string, object>(); var confighidden = new Dictionary<string, object>(); confighidden.Add("hidden", true); //var configdate = new Dictionary<string, object>(); //configdate.Add("format", "{0:dd/MM/yyyy}"); config.Add("width", 100); //config.Add("locked", true); if (!configs.ContainsKey("CodeEmp")) configs.Add("CodeEmp", config); if (!configs.ContainsKey("DepartmentCode")) configs.Add("DepartmentCode", config); if (!configs.ContainsKey("PositionName")) configs.Add("PositionName", config); if (!configs.ContainsKey("JobTitleName")) configs.Add("JobTitleName", config); if (!configs.ContainsKey("Paid")) configs.Add("Paid", config); if (!configs.ContainsKey("BranchCode")) configs.Add("BranchCode", config); if (!configs.ContainsKey("TeamCode")) configs.Add("TeamCode", config); if (!configs.ContainsKey("SectionCode")) configs.Add("SectionCode", config); if (!configs.ContainsKey("OrgName")) configs.Add("OrgName", config); if (!configs.ContainsKey("TeamName")) configs.Add("TeamName", config); if (!configs.ContainsKey("SectionName")) configs.Add("SectionName", config); if (!configs.ContainsKey("BranchName")) configs.Add("BranchName", config); if (!configs.ContainsKey("DateFrom")) configs.Add("DateFrom", confighidden); if (!configs.ContainsKey("DateTo")) configs.Add("DateTo", confighidden); if (!configs.ContainsKey("UserExport")) configs.Add("UserExport", confighidden); if (!configs.ContainsKey("DateExport")) configs.Add("DateExport", confighidden); foreach (var leavdayType in leavedayTypes) { if (!configs.ContainsKey(leavdayType.Code)) configs.Add(leavdayType.Code, config); } return table.ConfigTable(configs); } }