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; }
public List<Hre_ReportProfileProbationEntity> GetReportProfileProbation(DateTime? DateFrom, DateTime? DateToSearch, List<Guid> lstProfileIDs) { List<Hre_ReportProfileProbationEntity> lstReportProfileProbation = new List<Hre_ReportProfileProbationEntity>(); DateTime DateTo = DateToSearch.Value.AddDays(1).AddMinutes(-1); if (lstProfileIDs == null) { return lstReportProfileProbation; } 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 repoWorkPlace = new Cat_WorkPlaceRepository(unitOfWork); var workPlace = repoWorkPlace.FindBy(s => s.IsDelete == null && s.WorkPlaceName != null).ToList(); var repoprofiles = new Hre_ProfileRepository(unitOfWork); var profiles = repoprofiles.FindBy(s => s.IsDelete == null && s.DateEndProbation >= DateFrom && s.DateEndProbation <= 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.Gender }).ToList(); foreach (var profile in profiles) { Hre_ReportProfileProbationEntity ReportProfileProbation = new Hre_ReportProfileProbationEntity(); 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 workplacebypro = workPlace.Where(s => s.ID == profile.WorkPlaceID).FirstOrDefault(); ReportProfileProbation.CodeEmp = profile.CodeEmp; ReportProfileProbation.ProfileName = profile.ProfileName; ReportProfileProbation.CodeOrg = org != null ? org.Code : null; ReportProfileProbation.OrgStructureName = org != null ? org.OrgStructureName : null; ReportProfileProbation.JobTitleName = jobtitlebypro != null ? jobtitlebypro.JobTitleName : null; ReportProfileProbation.PositionName = positiobbypro != null ? positiobbypro.PositionName : null; ReportProfileProbation.DateHire = profile.DateHire; ReportProfileProbation.DateEndProbation = profile.DateEndProbation; ReportProfileProbation.ProbExtendDate = profile.ProbExtendDate; ReportProfileProbation.IDNo = profile.IDNo; ReportProfileProbation.IDDateOfIssue = profile.IDDateOfIssue; ReportProfileProbation.IDPlaceOfIssue = profile.IDPlaceOfIssue; ReportProfileProbation.WorkPlace = workplacebypro != null ? workplacebypro.WorkPlaceName : null; lstReportProfileProbation.Add(ReportProfileProbation); } return lstReportProfileProbation; } }
public DataTable ReportCardByLocation(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, DateTime dateStart, DateTime dateEndSearch, List<Guid> lstProfileIds, List<Guid?> workPlaceIds, List<Guid?> eatLocationIds, Boolean isCludeEmpQuit) { DataTable datatable = CreateReportCardByLocationSchema(dateStart, dateEndSearch); using (var context = new VnrHrmDataContext()) { DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1); 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 (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(); } 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(); } var repocanteen = new Can_CanteenRepository(unitOfWork); if (eatLocationIds != null && eatLocationIds[0] != null) { var lstcanteenbylocation = repocanteen.FindBy(c => c.IsDelete == null && c.LocationID != null && eatLocationIds.Contains(c.LocationID.Value)); var lstcanteenbylocationID = lstcanteenbylocation.Select(s => s.ID).ToList(); mealRecords = mealRecords.Where(s => s.CanteenID != null && lstcanteenbylocationID.Contains(s.CanteenID.Value)).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 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>(); foreach (var profile in profiles) { for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var meal = mealRecords.FirstOrDefault(s => s.TimeLog != null && s.ProfileID == profile.ID && s.TimeLog.Value.Date == date.Date); if (meal != null) { DataRow row = datatable.NewRow(); var cateen = canteens.FirstOrDefault(s => s.ID == meal.CanteenID); var cate = caterings.FirstOrDefault(s => s.ID == meal.CateringID); var line = lines.FirstOrDefault(s => s.ID == meal.LineID); 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_ReportCardByLocationEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.Code : string.Empty; row[Can_ReportCardByLocationEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.Code : string.Empty; row[Can_ReportCardByLocationEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.Code : string.Empty; row[Can_ReportCardByLocationEntity.FieldNames.SectionName] = orgSection != null ? orgSection.Code : string.Empty; row[Can_ReportCardByLocationEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Can_ReportCardByLocationEntity.FieldNames.ProfileName] = profile.ProfileName; row[Can_ReportCardByLocationEntity.FieldNames.DateFrom] = dateStart; row[Can_ReportCardByLocationEntity.FieldNames.DateTo] = dateEnd; row[Can_ReportCardByLocationEntity.FieldNames.DatePrint] = DateTime.Now; var location = cateen != null ? cateen.LocationID : null; row[Can_ReportCardByLocationEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; row[Can_ReportCardByLocationEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; row[Can_ReportCardByLocationEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty; if (lstWorkPlace != null && lstWorkPlace.Count > 0) { var workPlaceByPro = lstWorkPlace.Where(m => m.ID == profile.WorkPlaceID).FirstOrDefault(); row[Can_ReportCardByLocationEntity.FieldNames.WorkLocationCode] = workPlaceByPro != null ? workPlaceByPro.Code : string.Empty; row[Can_ReportCardByLocationEntity.FieldNames.WorkLocationHD] = workPlaceByPro != null ? workPlaceByPro.WorkPlaceName : string.Empty; } if (location != null && location != Guid.Empty) { var locationname = lstLocation.Where(s => s.ID == location).FirstOrDefault(); row[Can_ReportCardByLocationEntity.FieldNames.EatLoCationCode] = location != null ? locationname.LocationCode : string.Empty; row[Can_ReportCardByLocationEntity.FieldNames.EatLoCationHD] = location != null ? locationname.LocationName : string.Empty; } if (meal.WorkDay != null) { row["Data" + date.Day] = meal.WorkDay.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime); row[Can_ReportCardByLocationEntity.FieldNames.Quantity] = 1; } row[Can_ReportCardByLocationEntity.FieldNames.Amount] = (object)meal.Amount ?? DBNull.Value; row[Can_ReportCardByLocationEntity.FieldNames.Date] = meal.WorkDay; if (meal.TimeLog != null) { row[Can_ReportCardByLocationEntity.FieldNames.Hour] = meal.TimeLog.Value; } datatable.Rows.Add(row); } } } } return datatable; }