///// <summary> ///// Lấy danh sách tất cả tăng ca ///// </summary> ///// <returns></returns> //public IQueryable<Att_AttendanceTableEntity> GetAttendanceTable(ListQueryModel model) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // IAtt_AttendanceTableRepository repo = new Att_AttendanceTableRepository(unitOfWork); // return repo.GetAttendanceTable(); // } //} ///// <summary> ///// Lấy toàn bộ data ///// </summary> ///// <returns></returns> //public IQueryable<Att_AttendanceTable> Get() //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // IAtt_AttendanceTableRepository repo = new Att_AttendanceTableRepository(unitOfWork); // return repo.GetAll().Where(i => i.IsDelete == null); // } //} ///// <summary> ///// Lấy dữ liệu theo Id ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //public Att_AttendanceTable Get(int id) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // IAtt_AttendanceTableRepository repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetById(id); // if (data.IsDelete == true) data = null; // return data; // } //} ///// <summary> ///// Lấy dữ liệu theo Id ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //public Att_AttendanceTable GetByProfileId(int ProfileId) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // IAtt_AttendanceTableRepository repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetAttendanceTableByProfileId(ProfileId); // return data; // } //} //public List<Att_AttendanceTableEntity> GetAttendanceTableByIds(string selectedIds) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // return repo.GetAttendanceTableByIds(selectedIds); // } //} ///// <summary> ///// Thêm mới một record ///// </summary> ///// <param name="cat"></param> ///// <returns></returns> //public bool Add(Att_AttendanceTable model) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // try // { // repo.Add(model); // repo.SaveChanges(); // return true; // } // catch // { // return false; // } // } //} ///// <summary> ///// Edit một record ///// </summary> ///// <param name="cat"></param> ///// <returns></returns> //public bool Edit(Att_AttendanceTable model) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // try // { // repo.Edit(model); // repo.SaveChanges(); // return true; // } // catch // { // return false; // } // } //} ///// <summary> ///// Remove 1 record là chuyển trạng thái IsDelete=true ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //public bool Remove(int id) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetById(id); // try // { // repo.Remove(data); // repo.SaveChanges(); // return true; // } // catch // { // return false; // } // } //} ///// <summary> ///// Delete 1 record là xóa luôn record khỏi database ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //public bool Delete(int id) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetById(id); // try // { // repo.Delete(data); // repo.SaveChanges(); // return true; // } // catch // { // return false; // } // } //} ///// <summary> ///// Lấy dữ liệu AttendanceTable theo Id ///// </summary> ///// <param name="overtimeId"></param> ///// <returns></returns> //public Att_AttendanceTable GetAttendanceTableById(int attendanceTableId) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetAttendanceTableById(attendanceTableId); // if (data.IsDelete == true) // { // data = null; // } // return data; // } //} #endregion public Att_AttendanceTable GetAttTableByCutOffAndProfileId(Guid profileId, Guid cutOffId, string UserLogin) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Att_AttendanceTableRepository(unitOfWork); string status = string.Empty; List <object> lstObject = new List <object>(); lstObject.Add(profileId); lstObject.Add(cutOffId); var data = repo.GetData(lstObject, ConstantSql.att_get_AttTable_CfId_PfId, UserLogin, ref status).FirstOrDefault(); return(data); } }
public DataTable GetReportGeneralMonthlyAttendance(DateTime? dateStart, DateTime DateTo, string strOrgStructure, List<Hre_ProfileEntity> profiles, Guid[] shiftIDs, Guid[] payrollIDs, string employeeStatus, string groupByType, bool ExcludeIfWorkingDayIsZero, bool isShowOTHourRow, string userExport, string UserLogin) { using (var context = new VnrHrmDataContext()) { var basesevise = new BaseService(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoProfile = new Hre_ProfileRepository(unitOfWork); var repoAtt_Att_LeaveDay = new CustomBaseRepository<Att_LeaveDay>(unitOfWork); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var repoCat_Position = new Cat_PositionRepository(unitOfWork); var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var repoCat_OvertimeType = new Cat_OvertimeTypeRepository(unitOfWork); var repoWorkDay = new Att_WorkDayRepository(unitOfWork); var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork); var repoAtt_AttendencaTable = new Att_AttendanceTableRepository(unitOfWork); var repoAtt_AttendanceItem = new Att_AttendanceTableItemRepository(unitOfWork); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var repoAtt_CutOffDuration = new Att_CutOffDurationRepository(unitOfWork); // var monthDuration = dateStart.ToString(); DataTable table = CreateReportGeneralMonthlyAttendanceSchema(UserLogin); dateStart = new DateTime(dateStart.Value.Year, dateStart.Value.Month, 1); // Guid? durationID = monthDuration != null ? (Guid?)(object)monthDuration : null; DateTime monthEnd = new DateTime(dateStart.Value.Year, dateStart.Value.Month, DateTime.DaysInMonth(dateStart.Value.Year, dateStart.Value.Month)); // profiles = profiles.Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID, s.PayrollGroupID }).ToList(); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); var positions = repoCat_Position.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList(); var jobtitles = repoCat_JobTitle.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList(); 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 overtimTypes = repoCat_OvertimeType.FindBy(s => s.Code != null && s.IsDelete == null).Select(s => new { s.ID, s.Code, s.OvertimeTypeName }).ToList(); List<Guid> profileIds = profiles.Select(s => s.ID).ToList(); DateTime dateFrom = dateStart.Value.Date.AddDays(1 - dateStart.Value.Day); DateTime dateTo = dateFrom.Date.AddDays(1 - dateFrom.Day).AddMonths(1).AddSeconds(-1); string status = string.Empty; List<object> para = new List<object>(); para.AddRange(new object[3]); para[0] = strOrgStructure; para[1] = dateFrom; para[2] = dateTo; var workDays = basesevise.GetData<Att_WorkdayEntity>(para, ConstantSql.hrm_att_getdata_Workday, UserLogin, ref status).ToList(); string groupBy = groupByType != null ? groupByType.ToString() : string.Empty; #region DataInfo List<object> paratables = new List<object>(); paratables.AddRange(new object[7]); paratables[3] = dateFrom; paratables[4] = dateTo; paratables[5] = 1; paratables[6] = Int32.MaxValue - 1; var tableQueryable = basesevise.GetData<Att_AttendanceTableEntity>(paratables, ConstantSql.hrm_att_sp_get_AttendanceTable, UserLogin, ref status).ToList(); List<object> paratable = new List<object>(); paratable.AddRange(new object[4]); paratable[0] = dateFrom; paratable[1] = dateTo; paratable[2] = 1; paratable[3] = Int32.MaxValue - 1; var itemQueryable = basesevise.GetData<Att_AttendanceTableItemEntity>(paratable, ConstantSql.hrm_att_sp_getdata_AttendanceTableItem, UserLogin, ref status).ToList(); #region durationID //if (durationID != null && durationID != Guid.Empty) //{ // var cutOffDuration = repoAtt_CutOffDuration.FindBy( // d => d.ID == durationID).Select(d => new { d.DateStart, d.DateEnd }).FirstOrDefault(); // if (cutOffDuration != null) // { // dateFrom = cutOffDuration.DateStart; // dateTo = cutOffDuration.DateEnd; // } // tableQueryable = tableQueryable.Where(d => d.CutOffDurationID == durationID).ToList(); //} //else //{ // tableQueryable = tableQueryable.Where(d => d.MonthYear == dateFrom).ToList(); // } #endregion tableQueryable = tableQueryable.Where(d => d.MonthYear == dateFrom).ToList(); #endregion if (payrollIDs != null) { profiles = profiles.Where(s => s.PayrollGroupID != null && payrollIDs.Contains(s.PayrollGroupID.Value)).ToList(); } if (employeeStatus != null) { if (employeeStatus == StatusEmployee.E_WORKING.ToString()) { profiles = profiles.Where(pro => (pro.DateQuit == null || pro.DateQuit >= dateTo) && pro.DateHire < dateFrom).ToList(); } else if (employeeStatus == StatusEmployee.E_NEWEMPLOYEE.ToString()) { profiles = profiles.Where(pro => pro.DateHire <= dateTo && pro.DateHire >= dateFrom).ToList(); } else if (employeeStatus == StatusEmployee.E_STOPWORKING.ToString()) { profiles = profiles.Where(pro => pro.DateQuit != null && pro.DateQuit.Value <= dateTo && pro.DateQuit.Value >= dateFrom).ToList(); } else if (employeeStatus == StatusEmployee.E_WORKINGANDNEW.ToString()) { profiles = profiles.Where(pro => pro.DateQuit == null || pro.DateQuit >= dateTo).ToList(); } } profileIds = profiles.Select(d => d.ID).ToList<Guid>(); tableQueryable = tableQueryable.Where(d => profileIds.Contains(d.ProfileID)).ToList(); var listAttendanceTable = tableQueryable .Select(d => new { d.ID, d.ProfileID, d.AnlDayAvailable, d.StdWorkDayCount, d.RealWorkDayCount, d.LateEarlyDeductionHours, d.PaidWorkDayCount, d.AnlDayTaken, d.Overtime1Hours, d.Overtime2Hours, d.Overtime3Hours, d.Overtime4Hours, d.Overtime5Hours, d.Overtime6Hours, d.Overtime1Type, d.Overtime2Type, d.Overtime3Type, d.Overtime4Type, d.Overtime5Type, d.Overtime6Type, d.LeaveDay1Hours, d.LeaveDay2Hours, d.LeaveDay3Hours, d.LeaveDay4Hours, d.NightShiftHours, d.LeaveDay1Type, d.LeaveDay2Type, d.LeaveDay3Type, d.LeaveDay4Type, }).ToList(); profileIds = listAttendanceTable.Select(s => s.ProfileID).ToList(); List<Guid> listAttendanceTableID = listAttendanceTable.Select(d => d.ID).ToList(); profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList(); var listProfileInfo = profiles.Select(d => new { d.ID, d.CodeEmp, d.ProfileName, d.DateHire, d.DateQuit, d.LaborType, d.WorkingPlace, d.OrgStructureID, d.WorkPlaceName, d.PositionName, d.JobTitleName, d.EmployeeTypeName, d.OrgStructureName, }).ToList(); itemQueryable = itemQueryable.Where(d => listAttendanceTableID.Contains(d.AttendanceTableID) && d.WorkDate >= dateFrom && d.WorkDate <= dateTo).ToList(); var listAttendanceTableItem = itemQueryable.Select(d => new { d.AttendanceTableID, d.WorkDate, d.OvertimeHours, d.ExtraOvertimeHours, d.ExtraOvertimeHours2, d.ExtraOvertimeHours3, d.WorkPaidHours, d.NightShiftHours, d.ShiftID, d.WorkHourFirstHaftShift, d.WorkHourLastHaftShift, d.LeaveTypeID, d.AvailableHours, }).ToList(); var listLeaveDay = repoAtt_Att_LeaveDay.FindBy(d => profileIds.Contains(d.ProfileID) && dateFrom <= d.DateStart && d.DateEnd <= dateTo).Select(d => new { d.ProfileID, d.Comment }).ToList(); var listGrade = repoAtt_Grade.FindBy(d => profileIds.Contains(d.ProfileID.Value) && d.IsDelete == null).OrderByDescending(d => d.MonthStart).Select(d => new { d.ProfileID, d.MonthStart, d.Cat_GradeAttendance.HourOnWorkDate }).ToList(); var lstShift = repoCat_Shift.FindBy(s => s.IsDelete == null).Select(d => new { d.ID, d.IsDoubleShift, d.Code, d.FirstShiftID, d.LastShiftID }).ToList(); DataTable table_lstResult = new DataTable(); #region bang 7 dung store ben sql table_lstResult.Columns.Add("ProfileID"); for (int i = 1; i <= 31; i++) { table_lstResult.Columns.Add("Data" + i); } //lay du lieu bang cat_shift // var lst_CatShift = repoCat_Shift.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.IsDoubleShift, s.Code, s.FirstShiftID, s.LastShiftID }).ToList(); var lst_CatShift = lstShift.ToList(); //var lstAttendanceTable = repoAtt_AttendencaTable.FindBy(s => s.IsDelete == null && s.MonthYear == dateFrom && profileIds.Contains(s.ProfileID)).Select(s => new { s.ID, s.ProfileID }).ToList(); var lstAttendanceTable = listAttendanceTable.ToList(); var lstAttendanceTableID = lstAttendanceTable.Select(s => s.ID).Distinct().ToList(); //var lstAttendanceTableItem = repoAtt_AttendanceItem.FindBy(s => s.IsDelete == null && lstAttendanceTableID.Contains(s.AttendanceTableID)) // .Select(s => new {s.ID,s.AttendanceTableID,s.LeaveTypeID,s.WorkPaidHours,s.AvailableHours,s.ShiftID,s.WorkHourFirstHaftShift,s.WorkHourLastHaftShift,s.WorkDate }).ToList(); var lstAttendanceTableItem = listAttendanceTableItem.ToList(); int countId = lstAttendanceTableID.Count; // DataRow rowlstResult = table_lstResult.NewRow(); var lstCat_LeaDayType = repoCat_LeaveDayType.FindBy(s => s.IsDelete == null).ToList(); //while(countId >0) //{ for (int i = countId; i > 0; i--) { // } var AttendanceID = lstAttendanceTable.Select(s => s.ID).FirstOrDefault(); var ProfileID = lstAttendanceTable.Select(s => s.ProfileID).FirstOrDefault(); lstAttendanceTable = lstAttendanceTable.Where(s => s.ID != AttendanceID).ToList(); DataRow rowlstResult = table_lstResult.NewRow(); rowlstResult["ProfileID"] = ProfileID; //int Numday = 1; //while(Numday <=31) //{ for (int Numday = 1; Numday <= 31; Numday++) { // } var tab_AttendanceTableItem = lstAttendanceTableItem.Where(s => s.AttendanceTableID == AttendanceID && s.WorkDate.Day == Numday) .Select(s => new { s.LeaveTypeID, s.WorkPaidHours, s.AvailableHours, s.ShiftID, s.WorkHourFirstHaftShift, s.WorkHourLastHaftShift }).ToList(); var leaveTypeID = tab_AttendanceTableItem.Select(s => s.LeaveTypeID).FirstOrDefault(); double workPaidHour = tab_AttendanceTableItem.Select(s => s.WorkPaidHours).FirstOrDefault(); double available = tab_AttendanceTableItem.Select(s => s.AvailableHours).FirstOrDefault(); available = 8; var shiftID = tab_AttendanceTableItem.Select(s => s.ShiftID).FirstOrDefault(); var isDoubleShift = lst_CatShift.Where(s => s.ID == shiftID).Select(s => s.IsDoubleShift).FirstOrDefault(); double? workHourFirstHaftShift = tab_AttendanceTableItem.Select(s => s.WorkHourFirstHaftShift).FirstOrDefault(); double? workHourLastHaftShift = tab_AttendanceTableItem.Select(s => s.WorkHourLastHaftShift).FirstOrDefault(); string result = string.Empty; if (leaveTypeID != null) { result = lstCat_LeaDayType.Where(s => s.ID == leaveTypeID).Select(s => s.CodeStatistic).ToString(); } else { if (isDoubleShift == true) { if (available == workHourFirstHaftShift) { var firstShiftID = lst_CatShift.Where(s => s.ID == shiftID).Select(s => s.FirstShiftID).FirstOrDefault(); result = lst_CatShift.Where(s => s.ID == firstShiftID).Select(s => s.Code).FirstOrDefault(); } else { result = workHourFirstHaftShift.ToString(); } if (available == workHourLastHaftShift) { var lastShiftID = lst_CatShift.Where(s => s.ID == shiftID).Select(s => s.LastShiftID).FirstOrDefault(); result = result + "-" + lst_CatShift.Where(s => s.ID == lastShiftID).Select(s => s.Code).FirstOrDefault(); } else { result = result + "-" + workHourLastHaftShift.ToString(); } } else { if (available == workPaidHour) { result = lst_CatShift.Where(s => s.ID == shiftID).Select(s => s.Code).FirstOrDefault(); } else { result = workPaidHour.ToString(); } } } rowlstResult["Data" + Numday] = result; //Numday++; } table_lstResult.Rows.Add(rowlstResult); //countId--; } #endregion DateTime DateMin = DateTime.MinValue; DateTime DateMax = DateTime.MinValue; DateTime? DateS = tableQueryable.Select(m => m.DateStart).FirstOrDefault(); DateTime? DateE = tableQueryable.Select(m => m.DateEnd).FirstOrDefault(); if (DateS != null) DateMin = DateS.Value; if (DateE != null) DateMax = DateE.Value; foreach (var profile in profiles) { DataRow row = table.NewRow(); var attendanceTable = listAttendanceTable.Where(s => s.ProfileID == profile.ID).FirstOrDefault(); 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); var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.ProfileName] = profile.ProfileName; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty; //row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.CodeOrg] = orgOrg != null ? orgOrg.Code : string.Empty; // row[Att_ReportMonthlyTimeSheetEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.PositionName] = positon != null ? positon.PositionName : string.Empty; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.JobTitleName] = jobtitle != null ? jobtitle.JobTitleName : string.Empty; if (profile.DateHire != null) { row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.DateHire] = profile.DateHire.Value; } if (profile.DateQuit != null) { row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.DateQuit] = profile.DateQuit.Value; } row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.UserExport] = userExport; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.DateExport] = DateTime.Today; var gradeByProfile = listGrade.Where(d => d.ProfileID == attendanceTable.ProfileID).OrderByDescending(d => d.MonthStart).FirstOrDefault(); var listAttendanceTableItemByTable = listAttendanceTableItem.Where(d => d.AttendanceTableID == attendanceTable.ID).ToList(); var listLeaveDayByProfile = listLeaveDay.Where(d => d.ProfileID == attendanceTable.ProfileID).ToList(); double hourOnWorkDate = gradeByProfile != null ? double.Parse(gradeByProfile.HourOnWorkDate.ToString()) : 1; #region Att_AttendanceTable row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.PaidWorkDayCount] = attendanceTable.PaidWorkDayCount; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.LateEarlyDeductionHours] = attendanceTable.LateEarlyDeductionHours; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.LateEarlyDeductionDays] = attendanceTable.LateEarlyDeductionHours / hourOnWorkDate; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.NightShiftHours] = attendanceTable.NightShiftHours; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.AnlDayAvailable] = attendanceTable.AnlDayAvailable; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.StandardWorkDays] = attendanceTable.StdWorkDayCount; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.RealWorkingDays] = attendanceTable.RealWorkDayCount; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.StandardWorkDaysFormula] = attendanceTable.RealWorkDayCount; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.DateFrom] = DateMin; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.DateTo] = DateMax; if (attendanceTable.AnlDayTaken > 0) { row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.ANL] = attendanceTable.AnlDayTaken; } #endregion #region table_lstResult Att_AttendanceTableItem_Symbol var dtRow = table_lstResult.Rows.OfType<DataRow>().Where(d => d["ProfileID"].GetString() == profile.ID.ToString()).FirstOrDefault(); if (dtRow != null) { for (DateTime dateCheck = DateMin; dateCheck < DateMax; dateCheck = dateCheck.AddDays(1)) { string Result = string.Empty; switch (dateCheck.Day) { case 1: Result = dtRow["Data1"].ToString(); break; case 2: Result = dtRow["Data2"].ToString(); break; case 3: Result = dtRow["Data3"].ToString(); break; case 4: Result = dtRow["Data4"].ToString(); break; case 5: Result = dtRow["Data5"].ToString(); break; case 6: Result = dtRow["Data6"].ToString(); break; case 7: Result = dtRow["Data7"].ToString(); break; case 8: Result = dtRow["Data8"].ToString(); break; case 9: Result = dtRow["Data9"].ToString(); break; case 10: Result = dtRow["Data10"].ToString(); break; case 11: Result = dtRow["Data11"].ToString(); break; case 12: Result = dtRow["Data12"].ToString(); break; case 13: Result = dtRow["Data13"].ToString(); break; case 14: Result = dtRow["Data14"].ToString(); break; case 15: Result = dtRow["Data15"].ToString(); break; case 16: Result = dtRow["Data16"].ToString(); break; case 17: Result = dtRow["Data17"].ToString(); break; case 18: Result = dtRow["Data18"].ToString(); break; case 19: Result = dtRow["Data19"].ToString(); break; case 20: Result = dtRow["Data20"].ToString(); break; case 21: Result = dtRow["Data21"].ToString(); break; case 22: Result = dtRow["Data22"].ToString(); break; case 23: Result = dtRow["Data23"].ToString(); break; case 24: Result = dtRow["Data24"].ToString(); break; case 25: Result = dtRow["Data25"].ToString(); break; case 26: Result = dtRow["Data26"].ToString(); break; case 27: Result = dtRow["Data27"].ToString(); break; case 28: Result = dtRow["Data28"].ToString(); break; case 29: Result = dtRow["Data29"].ToString(); break; case 30: Result = dtRow["Data30"].ToString(); break; case 31: Result = dtRow["Data31"].ToString(); break; } //row["Data" + dateCheck.Day] = Result; string day = dateCheck.Day.ToString(); row[day] = Result; } } #endregion #region att_AttendanceTableItem int WorkPaidHourOver8 = 0; int NightShiftOver6 = 0; double WorkPaidHours = 0; foreach (var attendanceTableItem in listAttendanceTableItemByTable) { var shift = lstShift.Where(m => m.ID == attendanceTableItem.ShiftID).FirstOrDefault(); if (shift != null && shift.IsDoubleShift == true) { if (attendanceTableItem.WorkHourFirstHaftShift >= 8) { WorkPaidHourOver8++; } if (attendanceTableItem.WorkHourLastHaftShift >= 8) { WorkPaidHourOver8++; } } else if (attendanceTableItem.WorkPaidHours >= 8) { WorkPaidHourOver8++; } if (attendanceTableItem.NightShiftHours >= 6) { NightShiftOver6++; } WorkPaidHours += attendanceTableItem.WorkPaidHours; } row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.WorkPaidHourOver8] = WorkPaidHourOver8; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.NightHourOver6] = NightShiftOver6; row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.WorkPaidHours] = WorkPaidHours; #endregion #region LeaveDayComment string leaveDayComment = string.Empty; foreach (var leaveDay in listLeaveDayByProfile) { if (!string.IsNullOrWhiteSpace(leaveDayComment)) { leaveDayComment += ", "; } leaveDayComment += leaveDay.Comment; } row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.Comment] = leaveDayComment; #endregion #region LeaveDay1Hours // string LeaveDayTypeCode1 = string.Empty; var LeaveDayTypeCode1 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay1Type).Select(s => s.Code).FirstOrDefault(); string leaveDayTypeCode = LeaveDayTypeCode1; var LeaveDayTypeCodeStatistic1 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay1Type).Select(s => s.CodeStatistic).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(LeaveDayTypeCodeStatistic1)) { leaveDayTypeCode = LeaveDayTypeCodeStatistic1; } leaveDayTypeCode = leaveDayTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(leaveDayTypeCode)) { if (table.Columns.Contains(leaveDayTypeCode)) { row[leaveDayTypeCode] = attendanceTable.LeaveDay1Hours / hourOnWorkDate; } if (table.Columns.Contains("h" + leaveDayTypeCode)) { row["h" + leaveDayTypeCode] = attendanceTable.LeaveDay1Hours; } } #endregion #region LeaveDay2Hours leaveDayTypeCode = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay2Type).Select(s => s.Code).FirstOrDefault(); var LeaveDayTypeCodeStatistic2 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay2Type).Select(s => s.CodeStatistic).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(LeaveDayTypeCodeStatistic2)) { leaveDayTypeCode = LeaveDayTypeCodeStatistic2; } leaveDayTypeCode = leaveDayTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(leaveDayTypeCode)) { if (table.Columns.Contains(leaveDayTypeCode)) { row[leaveDayTypeCode] = attendanceTable.LeaveDay2Hours / hourOnWorkDate; } if (table.Columns.Contains("h" + leaveDayTypeCode)) { row["h" + leaveDayTypeCode] = attendanceTable.LeaveDay2Hours; } } #endregion #region LeaveDay3Hours leaveDayTypeCode = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay3Type).Select(s => s.Code).FirstOrDefault(); var LeaveDayTypeCodeStatistic3 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay3Type).Select(s => s.CodeStatistic).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(LeaveDayTypeCodeStatistic3)) { leaveDayTypeCode = LeaveDayTypeCodeStatistic3; } leaveDayTypeCode = leaveDayTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(leaveDayTypeCode)) { if (table.Columns.Contains(leaveDayTypeCode)) { row[leaveDayTypeCode] = attendanceTable.LeaveDay3Hours / hourOnWorkDate; } if (table.Columns.Contains("h" + leaveDayTypeCode)) { row["h" + leaveDayTypeCode] = attendanceTable.LeaveDay3Hours; } } #endregion #region LeaveDay4Hours leaveDayTypeCode = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay4Type).Select(s => s.Code).FirstOrDefault(); var LeaveDayTypeCodeStatistic4 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay4Type).Select(s => s.CodeStatistic).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(LeaveDayTypeCodeStatistic4)) { leaveDayTypeCode = LeaveDayTypeCodeStatistic4; } leaveDayTypeCode = leaveDayTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(leaveDayTypeCode)) { if (table.Columns.Contains(leaveDayTypeCode)) { row[leaveDayTypeCode] = attendanceTable.LeaveDay4Hours / hourOnWorkDate; } if (table.Columns.Contains("h" + leaveDayTypeCode)) { row["h" + leaveDayTypeCode] = attendanceTable.LeaveDay4Hours; } } #endregion #region Cat_Overtime var OvertimeTypeCode1 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime1Type).Select(s => s.Code).FirstOrDefault(); string overtimeTypeCode = OvertimeTypeCode1; overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(overtimeTypeCode)) { if (table.Columns.Contains(overtimeTypeCode)) { row[overtimeTypeCode] = attendanceTable.Overtime1Hours; } } var OvertimeTypeCode2 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime2Type).Select(s => s.Code).FirstOrDefault(); overtimeTypeCode = OvertimeTypeCode2; overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(overtimeTypeCode)) { if (table.Columns.Contains(overtimeTypeCode)) { row[overtimeTypeCode] = attendanceTable.Overtime2Hours; } } var OvertimeTypeCode3 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime3Type).Select(s => s.Code).FirstOrDefault(); overtimeTypeCode = OvertimeTypeCode3; overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(overtimeTypeCode)) { if (table.Columns.Contains(overtimeTypeCode)) { row[overtimeTypeCode] = attendanceTable.Overtime3Hours; } } var OvertimeTypeCode4 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime4Type).Select(s => s.Code).FirstOrDefault(); overtimeTypeCode = OvertimeTypeCode4; overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(overtimeTypeCode)) { if (table.Columns.Contains(overtimeTypeCode)) { row[overtimeTypeCode] = attendanceTable.Overtime4Hours; } } var OvertimeTypeCode5 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime5Type).Select(s => s.Code).FirstOrDefault(); overtimeTypeCode = OvertimeTypeCode5; overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(overtimeTypeCode)) { if (table.Columns.Contains(overtimeTypeCode)) { row[overtimeTypeCode] = attendanceTable.Overtime5Hours; } } var OvertimeTypeCode6 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime6Type).Select(s => s.Code).FirstOrDefault(); overtimeTypeCode = OvertimeTypeCode6; overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_'); if (!string.IsNullOrWhiteSpace(overtimeTypeCode)) { if (table.Columns.Contains(overtimeTypeCode)) { row[overtimeTypeCode] = attendanceTable.Overtime6Hours; } } #endregion table.Rows.Add(row); #region second Row (OT HOUR) if (isShowOTHourRow) { DataRow dr_OT_Hour = table.NewRow(); foreach (var attendanceTableItem in listAttendanceTableItemByTable) { int date = attendanceTableItem.WorkDate.Day; double totalHourOT = attendanceTableItem.OvertimeHours; totalHourOT += attendanceTableItem.ExtraOvertimeHours; totalHourOT += attendanceTableItem.ExtraOvertimeHours2; totalHourOT += attendanceTableItem.ExtraOvertimeHours3; dr_OT_Hour[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.Data + date] = totalHourOT; } table.Rows.Add(dr_OT_Hour); } #endregion } #region Code cu #endregion var configs = new Dictionary<string, Dictionary<string, object>>(); var config = new Dictionary<string, object>(); var configdouble = new Dictionary<string, object>(); var config90 = new Dictionary<string, object>(); var config95 = new Dictionary<string, object>(); var config110 = new Dictionary<string, object>(); var config81 = new Dictionary<string, object>(); config81.Add("width", 81); for (int i = 1; i <= 31; i++) { if (!configs.ContainsKey("_" + i.ToString())) configs.Add("_" + i.ToString(), config81); } config95.Add("width", 95); if (!configs.ContainsKey("DateQuit")) configs.Add("DateQuit", config95); config90.Add("width", 90); if (!configs.ContainsKey("DateHire")) configs.Add("DateHire", config90); if (!configs.ContainsKey("CodeEmp")) configs.Add("CodeEmp", config90); if (!configs.ContainsKey("DepartmentCode")) configs.Add("DepartmentCode", config90); if (!configs.ContainsKey("BranchCode")) configs.Add("BranchCode", config90); if (!configs.ContainsKey("TeamCode")) configs.Add("TeamCode", config90); if (!configs.ContainsKey("SectionCode")) configs.Add("SectionCode", config90); config110.Add("width", 110); if (!configs.ContainsKey("BranchName")) configs.Add("BranchName", config110); if (!configs.ContainsKey("TeamName")) configs.Add("TeamName", config110); if (!configs.ContainsKey("SectionName")) configs.Add("SectionName", config110); if (!configs.ContainsKey("PositionName")) configs.Add("PositionName", config110); if (!configs.ContainsKey("JobTitleName")) configs.Add("JobTitleName", config110); config.Add("hidden", true); if (!configs.ContainsKey("DateFrom")) configs.Add("DateFrom", config); if (!configs.ContainsKey("DateTo")) configs.Add("DateTo", config); if (!configs.ContainsKey("UserExport")) configs.Add("UserExport", config); if (!configs.ContainsKey("DateExport")) configs.Add("DateExport", config); configdouble.Add("format", "{0:n2}"); if (!configs.ContainsKey("RealWorkingDays")) configs.Add("RealWorkingDays", configdouble); if (!configs.ContainsKey("StandardWorkDaysFormula")) configs.Add("StandardWorkDaysFormula", configdouble); return table.ConfigTable(configs); } }
///// <summary> ///// Lấy danh sách tất cả tăng ca ///// </summary> ///// <returns></returns> //public IQueryable<Att_AttendanceTableEntity> GetAttendanceTable(ListQueryModel model) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // IAtt_AttendanceTableRepository repo = new Att_AttendanceTableRepository(unitOfWork); // return repo.GetAttendanceTable(); // } //} ///// <summary> ///// Lấy toàn bộ data ///// </summary> ///// <returns></returns> //public IQueryable<Att_AttendanceTable> Get() //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // IAtt_AttendanceTableRepository repo = new Att_AttendanceTableRepository(unitOfWork); // return repo.GetAll().Where(i => i.IsDelete == null); // } //} ///// <summary> ///// Lấy dữ liệu theo Id ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //public Att_AttendanceTable Get(int id) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // IAtt_AttendanceTableRepository repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetById(id); // if (data.IsDelete == true) data = null; // return data; // } //} ///// <summary> ///// Lấy dữ liệu theo Id ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //public Att_AttendanceTable GetByProfileId(int ProfileId) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // IAtt_AttendanceTableRepository repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetAttendanceTableByProfileId(ProfileId); // return data; // } //} //public List<Att_AttendanceTableEntity> GetAttendanceTableByIds(string selectedIds) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // return repo.GetAttendanceTableByIds(selectedIds); // } //} ///// <summary> ///// Thêm mới một record ///// </summary> ///// <param name="cat"></param> ///// <returns></returns> //public bool Add(Att_AttendanceTable model) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // try // { // repo.Add(model); // repo.SaveChanges(); // return true; // } // catch // { // return false; // } // } //} ///// <summary> ///// Edit một record ///// </summary> ///// <param name="cat"></param> ///// <returns></returns> //public bool Edit(Att_AttendanceTable model) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // try // { // repo.Edit(model); // repo.SaveChanges(); // return true; // } // catch // { // return false; // } // } //} ///// <summary> ///// Remove 1 record là chuyển trạng thái IsDelete=true ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //public bool Remove(int id) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetById(id); // try // { // repo.Remove(data); // repo.SaveChanges(); // return true; // } // catch // { // return false; // } // } //} ///// <summary> ///// Delete 1 record là xóa luôn record khỏi database ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //public bool Delete(int id) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetById(id); // try // { // repo.Delete(data); // repo.SaveChanges(); // return true; // } // catch // { // return false; // } // } //} ///// <summary> ///// Lấy dữ liệu AttendanceTable theo Id ///// </summary> ///// <param name="overtimeId"></param> ///// <returns></returns> //public Att_AttendanceTable GetAttendanceTableById(int attendanceTableId) //{ // using (var context = new VnrHrmDataContext()) // { // var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); // var repo = new Att_AttendanceTableRepository(unitOfWork); // var data = repo.GetAttendanceTableById(attendanceTableId); // if (data.IsDelete == true) // { // data = null; // } // return data; // } //} #endregion public Att_AttendanceTable GetAttTableByCutOffAndProfileId(Guid profileId, Guid cutOffId, string UserLogin) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Att_AttendanceTableRepository(unitOfWork); string status = string.Empty; List<object> lstObject = new List<object>(); lstObject.Add(profileId); lstObject.Add(cutOffId); var data = repo.GetData(lstObject, ConstantSql.att_get_AttTable_CfId_PfId, UserLogin, ref status).FirstOrDefault(); return data; } }
public DataTable GetReportMonthlyTimeSheet(DateTime? dateStart, DateTime DateTo, string strOrgStructure, List<Hre_ProfileEntity> profiles, Guid[] shiftIDs, Guid[] payrollIDs, bool isIncludeQuitEmp, bool isNotAllowZero, Guid exportid, string UserLogin) { using (var context = new VnrHrmDataContext()) { DataTable table = CreateReportMonthlyTimeSheetSchema(UserLogin); dateStart = new DateTime(dateStart.Value.Year, dateStart.Value.Month, 1); DateTime monthEnd = new DateTime(dateStart.Value.Year, dateStart.Value.Month, DateTime.DaysInMonth(dateStart.Value.Year, dateStart.Value.Month)); monthEnd = monthEnd.AddDays(1).AddMilliseconds(-1); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoProfile = new Hre_ProfileRepository(unitOfWork); 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_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 repoCat_OvertimeType = new Cat_OvertimeTypeRepository(unitOfWork); var overtimTypes = repoCat_OvertimeType.FindBy(s => s.Code != null && s.IsDelete == null).Select(s => new { s.ID, s.Code, s.OvertimeTypeName }).ToList(); var codeCenters = unitOfWork.CreateQueryable<Cat_CostCentre>(Guid.Empty, s => s.Code != null).Select(s => new { s.ID, s.Code }).ToList(); List<Guid> profileIds = profiles.Select(s => s.ID).ToList(); string status = string.Empty; List<object> para_reportWorDay = new List<object>(); para_reportWorDay.AddRange(new object[2]); para_reportWorDay[0] = dateStart; para_reportWorDay[0] = monthEnd; var repoWorkDay = new Att_WorkDayServices(); List<Att_WorkdayEntity> workDays = repoWorkDay.GetData<Att_WorkdayEntity>(para_reportWorDay, ConstantSql.hrm_att_sp_getdata_reportWorDay, UserLogin, ref status).ToList(); workDays = workDays.Where(s => profileIds.Contains(s.ProfileID)).ToList(); if (payrollIDs != null) { profiles = profiles.Where(s => s.PayrollGroupID != null && payrollIDs.Contains(s.PayrollGroupID.Value)).ToList(); } if (shiftIDs != null) { 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 (!isIncludeQuitEmp) { profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateStart).ToList(); } profileIds = profiles.Select(s => s.ID).ToList(); var repoAtt_AttendencaTable = new Att_AttendanceTableRepository(unitOfWork); List<object> para = new List<object>(); para.AddRange(new object[7]); para[3] = dateStart; para[4] = monthEnd; para[5] = 1; para[6] = int.MaxValue; var attService = new Att_AttendanceServices(); List<Att_AttendanceTableEntity> lstAttendanceTable = attService.GetData<Att_AttendanceTableEntity>(para, ConstantSql.hrm_att_sp_get_attdancetable, UserLogin, ref status).ToList(); var attendanceTables = lstAttendanceTable.Where(s => profileIds.Contains(s.ProfileID)).ToList(); profileIds = attendanceTables.Select(s => s.ProfileID).ToList(); profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList(); foreach (var profile in profiles) { var attendanceTableProfile = attendanceTables.FirstOrDefault(s => s.ProfileID == profile.ID); if (attendanceTableProfile == null) { continue; } 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); var cost = codeCenters.FirstOrDefault(s => s.ID == profile.CostCentreID); var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); row[Att_ReportMonthlyTimeSheetEntity.FieldNames.ProfileName] = profile.ProfileName; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.CodeOrg] = orgOrg != null ? orgOrg.Code : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.PositionName] = positon != null ? positon.PositionName : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.JobTitleName] = jobtitle != null ? jobtitle.JobTitleName : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.CodeCenter] = cost != null ? cost.Code : string.Empty; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.StdWorkDayCount] = attendanceTableProfile.StdWorkDayCount > 0 ? (object)attendanceTableProfile.StdWorkDayCount : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.RealWorkDayCount] = attendanceTableProfile.RealWorkDayCount > 0 ? (object)attendanceTableProfile.RealWorkDayCount : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.PaidWorkDayCount] = attendanceTableProfile.PaidWorkDayCount > 0 ? (object)attendanceTableProfile.PaidWorkDayCount : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.AnlDayAvailable] = attendanceTableProfile.AnlDayAvailable > 0 ? (object)attendanceTableProfile.AnlDayAvailable : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.NightShiftHours] = attendanceTableProfile.NightShiftHours > 0 ? (object)attendanceTableProfile.NightShiftHours : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.LateEarlyDeductionHours] = attendanceTableProfile.LateEarlyDeductionHours > 0 ? (object)attendanceTableProfile.LateEarlyDeductionHours : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.AnlDayTaken] = attendanceTableProfile.AnlDayTaken > 0 ? (object)attendanceTableProfile.AnlDayTaken : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.Note] = attendanceTableProfile.Note != null ? attendanceTableProfile.Note : string.Empty; #region Export theo cot dong if (exportid != Guid.Empty) { var leaday = leavedayTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.LeaveDay1Type); if (leaday != null && !string.IsNullOrEmpty(leaday.Code) && table.Columns.Contains(leaday.Code)) { row[leaday.Code] = attendanceTableProfile.LeaveDay1Hours > 0 ? (object)attendanceTableProfile.LeaveDay1Hours : DBNull.Value; } leaday = leavedayTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.LeaveDay2Type); if (leaday != null) { row[leaday.Code] = attendanceTableProfile.LeaveDay2Hours > 0 ? (object)attendanceTableProfile.LeaveDay2Hours : DBNull.Value; } leaday = leavedayTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.LeaveDay3Type); if (leaday != null) { row[leaday.Code] = attendanceTableProfile.LeaveDay3Hours > 0 ? (object)attendanceTableProfile.LeaveDay3Hours : DBNull.Value; } leaday = leavedayTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.LeaveDay4Type); if (leaday != null) { row[leaday.Code] = attendanceTableProfile.LeaveDay4Hours > 0 ? (object)attendanceTableProfile.LeaveDay4Hours : DBNull.Value; } var overtimeType = overtimTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.Overtime1Type); if (overtimeType != null) { // row[overtimeType.Code] = attendanceTableProfile.Overtime1Hours > 0 ? (object)attendanceTableProfile.Overtime1Hours : DBNull.Value; row[overtimeType.OvertimeTypeName] = attendanceTableProfile.Overtime1Hours > 0 ? (object)attendanceTableProfile.Overtime1Hours : DBNull.Value; } overtimeType = overtimTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.Overtime2Type); if (overtimeType != null) { // row[overtimeType.Code] = attendanceTableProfile.Overtime2Hours > 0 ? (object)attendanceTableProfile.Overtime2Hours : DBNull.Value; row[overtimeType.OvertimeTypeName] = attendanceTableProfile.Overtime2Hours > 0 ? (object)attendanceTableProfile.Overtime2Hours : DBNull.Value; } overtimeType = overtimTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.Overtime3Type); if (overtimeType != null) { //row[overtimeType.Code] = attendanceTableProfile.Overtime3Hours > 0 ? (object)attendanceTableProfile.Overtime3Hours : DBNull.Value; row[overtimeType.OvertimeTypeName] = attendanceTableProfile.Overtime3Hours > 0 ? (object)attendanceTableProfile.Overtime3Hours : DBNull.Value; } overtimeType = overtimTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.Overtime4Type); if (overtimeType != null) { //row[overtimeType.Code] = attendanceTableProfile.Overtime4Hours > 0 ? (object)attendanceTableProfile.Overtime4Hours : DBNull.Value; row[overtimeType.OvertimeTypeName] = attendanceTableProfile.Overtime4Hours > 0 ? (object)attendanceTableProfile.Overtime4Hours : DBNull.Value; } overtimeType = overtimTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.Overtime5Type); if (overtimeType != null) { //row[overtimeType.Code] = attendanceTableProfile.Overtime5Hours > 0 ? (object)attendanceTableProfile.Overtime5Hours : DBNull.Value; row[overtimeType.OvertimeTypeName] = attendanceTableProfile.Overtime5Hours > 0 ? (object)attendanceTableProfile.Overtime5Hours : DBNull.Value; } overtimeType = overtimTypes.FirstOrDefault(s => s.ID == attendanceTableProfile.Overtime6Type); if (overtimeType != null) { //row[overtimeType.Code] = attendanceTableProfile.Overtime6Hours > 0 ? (object)attendanceTableProfile.Overtime6Hours : DBNull.Value; row[overtimeType.OvertimeTypeName] = attendanceTableProfile.Overtime6Hours > 0 ? (object)attendanceTableProfile.Overtime6Hours : DBNull.Value; } row[Att_ReportMonthlyTimeSheetEntity.FieldNames.CountLateEarly] = (object)attendanceTableProfile.CardMissingCount ?? DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.CountLateLess2H] = (object)attendanceTableProfile.LateEarlyLeastCount ?? DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.CountLateMore2H] = (object)attendanceTableProfile.LateEarlyGreaterCount ?? DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.UsableLeave] = attendanceTableProfile.TotalAnlDayAvailable > 0 ? (object)attendanceTableProfile.TotalAnlDayAvailable : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.SickLeave] = attendanceTableProfile.TotalSickDayAvailable > 0 ? (object)attendanceTableProfile.TotalSickDayAvailable : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.CurrentMonth] = attendanceTableProfile.AnlDayTaken > 0 ? (object)attendanceTableProfile.AnlDayTaken : DBNull.Value; //row["SickCurrentMonth"] = attendanceTableProfile.SickDayTaken > 0 ? (object)attendanceTableProfile.SickDayTaken : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.SickCurrentMonth] = attendanceTableProfile.SickDayTaken > 0 ? (object)attendanceTableProfile.SickDayTaken : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.YearToDate] = attendanceTableProfile.AnlDayAdjacent > 0 ? (object)attendanceTableProfile.AnlDayAdjacent : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.SickYearToDate] = attendanceTableProfile.SickDayAdjacent > 0 ? (object)attendanceTableProfile.SickDayAdjacent : DBNull.Value; row[Att_ReportMonthlyTimeSheetEntity.FieldNames.SumMuteLateEarly] = (object)attendanceTableProfile.LateEarlyTotal ?? DBNull.Value; } #endregion table.Rows.Add(row); } if (exportid != Guid.Empty) { return table.ConfigDatatable(); } return table; } }