public Guid GetCutOffDurationDefault() { var guid = Guid.Empty; using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Att_CutOffDurationRepository(unitOfWork); guid = repo.FindBy(m => (!m.IsDelete.HasValue || m.IsDelete != true) && m.MonthYear.Month == DateTime.Now.Month && m.MonthYear.Year == DateTime.Now.Year).Select(d=>d.ID).FirstOrDefault(); } return guid; }
public Guid GetCutOffDurationDefault() { var guid = Guid.Empty; using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Att_CutOffDurationRepository(unitOfWork); guid = repo.FindBy(m => (!m.IsDelete.HasValue || m.IsDelete != true) && m.MonthYear.Month == DateTime.Now.Month && m.MonthYear.Year == DateTime.Now.Year).Select(d => d.ID).FirstOrDefault(); } return(guid); }
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); } }
public bool SaveSumryMealRecord(Guid CutOffDurationID, List<Guid> lstProfileIDs) { using (var context = new VnrHrmDataContext()) { try { #region GetData List<Can_ReportAdjustmentMealAllowancePaymentEntity> lstReportAdjustmentMealAllowancePayment = new List<Can_ReportAdjustmentMealAllowancePaymentEntity>(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoMealRecord = new Can_MealRecordRepository(unitOfWork); var cutoffdurationRepository = new Att_CutOffDurationRepository(unitOfWork); var Cutoffduration = cutoffdurationRepository.FindBy(m => m.ID == CutOffDurationID && m.IsDelete != true).FirstOrDefault(); DateTime DateFrom = new DateTime(); DateTime DateTo = new DateTime(); if (Cutoffduration != null) { DateFrom = Cutoffduration.DateStart; DateTo = Cutoffduration.DateEnd.AddDays(1).AddMilliseconds(-1); } var sumryMealRecordRepository = new Can_SumryMealRecordRepository(unitOfWork); var lstMealRecord = repoMealRecord.FindBy(m => m.WorkDay != null && m.WorkDay >= DateFrom && m.WorkDay <= DateTo && m.ProfileID != null) .Select(s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.NoWorkDay }).ToList(); if (lstMealRecord.Count < 0) { return true; } var status = StatusMealAllowanceToMoney.E_APPROVED.ToString(); #region Dư ko dùng //var repoAllowanceToMoney = new Can_MealAllowanceToMoneyRepository(unitOfWork); //var mealAllowncaToMoneyProfileIDs = repoAllowanceToMoney.FindBy(s => s.Status == status && s.ProfileID != null && DateFrom <= s.DateTo && s.DateFrom <= DateTo).ToList(); #endregion var lstProfileIdsByMeal = lstMealRecord.Select(s => s.ProfileID).Distinct().ToList(); var repoprofiles = new Hre_ProfileRepository(unitOfWork); var profiles = repoprofiles.FindBy(s => lstProfileIdsByMeal.Contains(s.ID)).Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); if (lstProfileIDs != null && lstProfileIDs.Count > 0) { profiles = profiles.Where(m => lstProfileIDs.Contains(m.ID)).ToList(); } var repomealAllowanceType = new Can_MealAllowanceTypeSettingRepository(unitOfWork); var mealAllowanceTypeSantandIDs = repomealAllowanceType.FindBy(s => s.Standard == true).Select(m => m.ID).ToList(); var mealAllowanceTypes = repomealAllowanceType.FindBy(s => s.IsDelete == null).ToList(); var amountStardand = repomealAllowanceType.FindBy(s => s.Standard == true && s.Amount != null).Select(s => s.Amount.Value).FirstOrDefault(); var repoLineHDTJob = new Can_LineRepository(unitOfWork); var lineHDTJobIDs = repoLineHDTJob.FindBy(s => s.HDTJ != null).Select(m => m.ID).ToList(); var repoHDTJob = new Hre_HDTJobRepository(unitOfWork); var profileHDTJs = repoHDTJob.FindBy(s => DateFrom <= s.DateTo && s.DateFrom <= DateTo) .Select(s => new { s.ProfileID, s.Type, s.DateFrom, s.DateTo }).ToList(); var profileHDTJIDs = profileHDTJs.Select(s => s.ProfileID).Distinct().ToList(); string approveKey = MealRecord_Status.E_APPROVED.ToString(); var repo_MealRecordMissing = new Can_MealRecordMissingRepository(unitOfWork); var mealRecordMissings = repo_MealRecordMissing.FindBy(s => s.Status == approveKey && DateFrom <= s.WorkDate && s.WorkDate <= DateTo) .Select(s => new { s.ProfileID, s.WorkDate, s.MealAllowanceTypeSettingID, s.TamScanReasonMissID, s.Amount }).ToList(); var repoWorkDay = new Att_WorkDayRepository(unitOfWork); var dateStart1 = DateFrom.AddDays(-1); var workDays = repoWorkDay.FindBy(s => dateStart1 <= s.WorkDate && s.WorkDate <= DateTo).Select(s => new { s.ProfileID, s.FirstInTime, s.LastOutTime, s.ShiftID, s.WorkDate }).ToList(); var workDayProfies = workDays.Where(s => s.FirstInTime != null || s.LastOutTime != null).ToList(); var repotamScan = new Cat_TAMScanReasonMissRepository(unitOfWork); var tamSans = repotamScan.GetAll().ToList(); var tamScanNotFullPayIDs = tamSans.Where(s => s.IsFullPay == null || s.IsFullPay == false).Select(s => s.ID).ToList(); var reposhift = new Cat_ShiftRepository(unitOfWork); var shifts = reposhift.GetAll().ToList(); var lines = new List<Can_Line>().ToList(); var repolines = new Can_LineRepository(unitOfWork); lines = repolines.GetAll().ToList(); var repoOrg = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoOrg.GetAll().ToList(); var orgTypes = new List<Cat_OrgStructureType>(); var repoorgType = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repoorgType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); #endregion foreach (var profile in profiles) { var mealProfiles = lstMealRecord.Where(s => s.ProfileID == profile.ID).ToList(); #region Dư ko dùng //var mealAllownProfiles = mealAllowncaToMoneyProfileIDs.Where(s => s.ProfileID == profile.ID).ToList(); //var mealNotStardands = lstMealRecord.Where(s => s.ProfileID == profile.ID && s.Amount > amountStardand).ToList(); #endregion Can_ReportAdjustmentMealAllowancePaymentEntity ReportAdjustmentMealAllowancePayment = new Can_ReportAdjustmentMealAllowancePaymentEntity(); Guid? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes); ReportAdjustmentMealAllowancePayment.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; ReportAdjustmentMealAllowancePayment.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; ReportAdjustmentMealAllowancePayment.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; ReportAdjustmentMealAllowancePayment.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty; ReportAdjustmentMealAllowancePayment.CodeEmp = profile.CodeEmp; ReportAdjustmentMealAllowancePayment.ProfileName = profile.ProfileName; ReportAdjustmentMealAllowancePayment.DateFrom = DateFrom; ReportAdjustmentMealAllowancePayment.DateTo = DateTo; ReportAdjustmentMealAllowancePayment.DatePrint = DateTime.Now; var countCard = 0; var sumCard = 0.0; int countCardMore1 = 0; var countNotWorkButHasEat = 0; var sumNotWorkButHasEat = 0.0; var countmealNotStardand = 0; var amountmealNotStardand = 0.0; var countHDTJ = 0; var amountHDTJ = 0.0; var countNotStandHDTJ = 0; var amountNotStandHDTJ = 0.0; int amount3OnMonth = 0; var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList(); for (DateTime date = DateFrom; date <= DateTo; date = date.AddDays(1)) { var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Date == date.Date); var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID); var missing = mealRecordMissings.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Value.Date == date.Date); if (missing != null) { if (missing.MealAllowanceTypeSettingID != null && missing.TamScanReasonMissID == null) { countCard++; sumCard += (double)(missing.Amount != null ? missing.Amount.Value : 0); } else if (missing.TamScanReasonMissID != null) { var tamscan = tamSans.FirstOrDefault(s => s.ID == missing.TamScanReasonMissID); if (tamscan != null) { if (tamscan.IsFullPay == true) { countCard++; sumCard += (double)amountStardand; } else { amount3OnMonth++; } } } } if (mealProfiles.Count(s => s.TimeLog != null && s.TimeLog.Value.Date == date.Date) > 1) { countCardMore1++; } var record = lstMealRecord.FirstOrDefault(s => s.TimeLog != null && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value) && s.ProfileID == profile.ID && date.Date == s.TimeLog.Value.Date && !workdayProfileDates.Contains(date.Date)); if (record != null) { countNotWorkButHasEat++; sumNotWorkButHasEat += (double)(record.Amount != null ? record.Amount.Value : 0); } var meal = lstMealRecord.FirstOrDefault(s => s.TimeLog != null && s.Amount > amountStardand && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value) && s.ProfileID == profile.ID && s.TimeLog.Value.Date == date.Date && workdayProfileDates.Contains(date.Date)); if (meal != null) { countmealNotStardand++; amountmealNotStardand += (double)(meal.Amount != null ? meal.Amount.Value : 0); } var mealHDT = lstMealRecord.FirstOrDefault(s => s.ProfileID == profile.ID && s.LineID != null && lineHDTJobIDs.Contains(s.LineID.Value) && s.TimeLog != null && s.TimeLog.Value.Date == date.Date && (!profileHDTJIDs.Contains(s.ProfileID.Value) || (profileHDTJIDs.Contains(s.ProfileID.Value) && !workdayProfileDates.Contains(date.Date)))); if (mealHDT != null) { countHDTJ++; amountHDTJ += (double)(mealHDT.Amount != null ? mealHDT.Amount.Value : 0); } var mealNotStandandHDT = lstMealRecord.FirstOrDefault(s => s.ProfileID != null && s.ProfileID == profile.ID && s.LineID != null && lineHDTJobIDs.Contains(s.LineID.Value) && s.TimeLog != null && s.TimeLog.Value.Date == date.Date && profileHDTJIDs.Contains(s.ProfileID.Value) && workdayProfileDates.Contains(date.Date)); if (mealNotStandandHDT != null && mealNotStandandHDT.LineID != null) { var line = lines.FirstOrDefault(s => s.ID == mealNotStandandHDT.LineID); var hdtjob = profileHDTJs.FirstOrDefault(s => s.Type != null && s.ProfileID == profile.ID && s.DateFrom.Value.Date <= date.Date && date.Date <= s.DateTo.Value.Date); if (line != null && line.HDTJ != null && hdtjob.Type != line.HDTJ) { var lineHDT = lines.FirstOrDefault(s => s.HDTJ == hdtjob.Type); if (lineHDT != null && lineHDT.Amount != null && lineHDT.Amount < line.Amount) { countNotStandHDTJ++; var lineAmount = line.Amount != null ? line.Amount.Value : 0; var lineAmountHDT = lineHDT.Amount != null ? lineHDT.Amount.Value : 0; amountNotStandHDTJ += (double)(lineAmount - lineAmountHDT); } } } double countMiss = mealRecordMissings.Count(s => s.ProfileID == profile.ID && s.TamScanReasonMissID != null && tamScanNotFullPayIDs.Contains(s.TamScanReasonMissID.Value)); countMiss = GetCountAmount((int)countMiss); if (countCard > 0) { ReportAdjustmentMealAllowancePayment.TotalMealAllowance = countCard + countMiss; } if (sumCard > 0) { ReportAdjustmentMealAllowancePayment.SumAmount = (double)(sumCard + countMiss * (double)amountStardand); } if (countmealNotStardand > 0) { ReportAdjustmentMealAllowancePayment.CountEatNotStandar = countmealNotStardand; ReportAdjustmentMealAllowancePayment.AmountEatNotStandar = amountmealNotStardand - (double)(amountStardand * countmealNotStardand); } if (countCardMore1 > 0) { ReportAdjustmentMealAllowancePayment.CountCardMore = countCardMore1; ReportAdjustmentMealAllowancePayment.SumCardMore = (double)Math.Round(countCardMore1 * amountStardand, 2); } if (countNotWorkButHasEat > 0) { ReportAdjustmentMealAllowancePayment.CountNotWorkHasEat = countNotWorkButHasEat; ReportAdjustmentMealAllowancePayment.AmountNotWorkHasEat = sumNotWorkButHasEat; } amount3OnMonth = amount3OnMonth - (int)GetCountAmount(amount3OnMonth); if (amount3OnMonth > 0) { ReportAdjustmentMealAllowancePayment.Amount3OnMonth = amount3OnMonth; } if (countHDTJ > 0) { ReportAdjustmentMealAllowancePayment.CountHDTJob = countHDTJ; ReportAdjustmentMealAllowancePayment.AmounSubtractHDTJob = amountHDTJ; } if (countNotStandHDTJ > 0) { ReportAdjustmentMealAllowancePayment.CountCardWorngStandar = countNotStandHDTJ; ReportAdjustmentMealAllowancePayment.AmountSubtractWorngStandar = amountNotStandHDTJ; } } Can_SumryMealRecord sumryMealRecordNew = new Can_SumryMealRecord(); sumryMealRecordNew.ProfileID = profile.ID; sumryMealRecordNew.DateFrom = Cutoffduration.DateStart; sumryMealRecordNew.DateTo = Cutoffduration.DateEnd; sumryMealRecordNew.TotalMealAllowance = ReportAdjustmentMealAllowancePayment.TotalMealAllowance; sumryMealRecordNew.SumAmount = ReportAdjustmentMealAllowancePayment.SumAmount; sumryMealRecordNew.CountEatNotStandar = ReportAdjustmentMealAllowancePayment.CountEatNotStandar; sumryMealRecordNew.AmountEatNotStandar = ReportAdjustmentMealAllowancePayment.AmountEatNotStandar; sumryMealRecordNew.CountCardMore = ReportAdjustmentMealAllowancePayment.CountCardMore; sumryMealRecordNew.SumAmountCardMore = ReportAdjustmentMealAllowancePayment.SumCardMore; sumryMealRecordNew.CountNotWorkHasEat = ReportAdjustmentMealAllowancePayment.CountNotWorkHasEat; sumryMealRecordNew.AmountNotWorkHasEat = ReportAdjustmentMealAllowancePayment.AmountNotWorkHasEat; sumryMealRecordNew.Amount3OnMonth = ReportAdjustmentMealAllowancePayment.Amount3OnMonth; sumryMealRecordNew.CountHDTJob = ReportAdjustmentMealAllowancePayment.CountHDTJob; sumryMealRecordNew.AmountHDTJob = ReportAdjustmentMealAllowancePayment.AmounSubtractHDTJob; sumryMealRecordNew.AmountNotWorkButHasHDT = ReportAdjustmentMealAllowancePayment.AmountNotWorkButHasHDT; sumryMealRecordNew.CountSubtractWorngStandarHDT = ReportAdjustmentMealAllowancePayment.CountSubtractWorngStandarHDT; sumryMealRecordNew.AmountSubtractWorngStandarHDT = ReportAdjustmentMealAllowancePayment.AmountSubtractWorngStandarHDT; sumryMealRecordRepository.Add(sumryMealRecordNew); lstReportAdjustmentMealAllowancePayment.Add(ReportAdjustmentMealAllowancePayment); if (profiles.IndexOf(profile) % 1000 == 0) { sumryMealRecordRepository.SaveChanges(); } } sumryMealRecordRepository.SaveChanges(); } catch (Exception) { return false; } } return true; }