/// <summary> /// chuyển thành trạng thái Cho Duyet /// </summary> /// <returns></returns> public void SubmitRoster(List<Guid> ids) { var lstWorkday = new List<Att_RosterEntity>(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new Att_RosterRepository(unitOfWork); lstWorkday = repo.FindBy(m => ids.Contains(m.ID)).ToList().Translate<Att_RosterEntity>(); foreach (var workday in lstWorkday) { workday.Status = AttendanceDataStatus.E_SUBMIT.ToString(); repo.SaveChanges(); } } }
public void AnalyzeCompensation(int Year, List<Guid> lstProfileIDTotal) { //Lấy cấu hình //lấy ngày nghỉ (Bù) //Lấy tăng ca (Bù) //Lấy Ca Làm Việc (Bù) //Hệ Số Tăng Ca (Loại Tăng Ca) foreach (var lstProfileID in lstProfileIDTotal.Chunk(500)) { using (var context = new VnrHrmDataContext()) { #region Khai báo var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); var repoAtt_Overtime = new Att_OvertimeRepository(unitOfWork); var repoAtt_CompensationConfig = new Att_CompensationConfigRepository(unitOfWork); var repoAtt_CompensationDetail = new Att_CompensationDetailRepository(unitOfWork); #endregion #region Lấy Dữ Liệu // var profileByCodeEmp = repoHre_Profile.FindBy(p => p.IsDelete == null && p.CodeEmp == codeEmp).FirstOrDefault(); var lstProfile = repoHre_Profile.FindBy(m => lstProfileID.Contains(m.ID)).Select(m => new { m.ID, m.DateHire }).ToList(); var lstCompensationConfig = repoAtt_CompensationConfig .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)) .Select(m => new CompensationConfigModel() { ID = m.ID, ProfileID = m.ProfileID, Year = m.Year, InitAvailable = m.InitAvailable, MonthBeginInYear = m.MonthBeginInYear, MonthResetInitAvailable = m.MonthResetInitAvailable, MonthStartProfile = m.MonthStartProfile }) .ToList(); int MonthBeginYear = 1; if (lstCompensationConfig != null && lstCompensationConfig.Count>0) { MonthBeginYear = lstCompensationConfig.FirstOrDefault().MonthBeginInYear ?? 1; } DateTime BeginYear = new DateTime(Year, MonthBeginYear, 1); DateTime EndYear = BeginYear.AddYears(1).AddMinutes(-1); string E_APPROVED_Leave = LeaveDayStatus.E_APPROVED.ToString(); var lstLeaveDayCompensationTypeID = repoCat_LeaveDayType .FindBy(m => m.IsTimeOffInLieu == true) .Select(m => m.ID) .ToList(); var lstLeaveday = repoAtt_Leaveday .FindBy(m => m.Status == E_APPROVED_Leave && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstLeaveDayCompensationTypeID.Contains(m.LeaveDayTypeID) && lstProfileID.Contains(m.ProfileID)) .Select(m => new { m.ID, m.ProfileID, m.DateStart, m.DateEnd, m.LeaveHours, m.DurationType }) .ToList(); string E_TIMEOFF = MethodOption.E_TIMEOFF.ToString(); string E_APPROVED_Overtime = OverTimeStatus.E_APPROVED.ToString(); string E_CONFIRM_Overtime = OverTimeStatus.E_CONFIRM.ToString(); var lstOvertime = repoAtt_Overtime .FindBy(m => m.WorkDateRoot >= BeginYear && m.WorkDateRoot <= EndYear && m.MethodPayment == E_TIMEOFF && (m.Status == E_APPROVED_Overtime || m.Status == E_CONFIRM_Overtime) && lstProfileID.Contains(m.ProfileID)) .Select(m => new { m.ID, m.ProfileID, m.WorkDateRoot, m.ApproveHours, m.ConfirmHours, m.Status }).ToList(); string E_APPROVED_Roster = RosterStatus.E_APPROVED.ToString(); var lstRoster = repoAtt_Roster .FindBy(m => m.Status == E_APPROVED_Roster && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstProfileID.Contains(m.ProfileID)) .Select(m => new RosterModel { ID = m.ID, ProfileID = m.ProfileID, DateStart = m.DateStart, DateEnd = m.DateEnd, Type = m.Type, MonShiftID = m.MonShiftID, TueShiftID = m.TueShiftID, WedShiftID = m.WedShiftID, ThuShiftID = m.ThuShiftID, FriShiftID = m.FriShiftID, SatShiftID = m.SatShiftID, SunShiftID = m.SunShiftID }) .ToList(); var lstShift = repoCat_Shift.GetAll().Select(m => new { m.ID, m.WorkHours, m.StdWorkHours }).ToList(); List<Att_CompensationDetail> detailInDB = repoAtt_CompensationDetail .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)) .ToList(); List<Att_CompensationDetail> detailNew = new List<Att_CompensationDetail>(); foreach (var ProfileID in lstProfileID) { double TotalLeaveHourBeforeMonth = 0; double TotalOvertimeHourBeforeMonth = 0; var Profile = lstProfile.Where(m => m.ID == ProfileID).FirstOrDefault(); int MonthHire = 1; if (Profile.DateHire != null && Profile.DateHire >= BeginYear && Profile.DateHire <= EndYear) { if (Profile.DateHire.Value.Day >= 15) { MonthHire = Profile.DateHire.Value.AddMonths(1).Month; } else { MonthHire = Profile.DateHire.Value.Month; } } for (DateTime Month = BeginYear; Month < EndYear; Month = Month.AddMonths(1)) { if (MonthHire > Month.Month) continue; DateTime BeginMonth = Month; DateTime EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1); double TotalLeaveHourInMonth = 0; double TotalOvertimeHourInMonth = 0; #region Tăng Ca var lstOvertimeByProfileByMonth = lstOvertime.Where(m => m.ProfileID == ProfileID && m.WorkDateRoot >= BeginMonth && m.WorkDateRoot <= EndMonth).ToList(); TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_CONFIRM_Overtime).Sum(m => m.ConfirmHours); TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_APPROVED_Overtime).Sum(m => m.ApproveHours ?? 0); #endregion #region Ngày Nghỉ var lstLeavedayByProfileByMonth = lstLeaveday.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList(); var lstRosterByProfileByMonth = lstRoster.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList(); foreach (var Leaveday in lstLeavedayByProfileByMonth) { DateTime dateStart = Leaveday.DateStart < BeginMonth ? BeginMonth : Leaveday.DateStart; DateTime dateEnd = Leaveday.DateEnd > EndMonth ? EndMonth : Leaveday.DateEnd; for (DateTime dateCheck = dateStart; dateCheck <= dateEnd; dateCheck = dateCheck.AddDays(1)) { if (Leaveday.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()) // Trong Ca { TotalLeaveHourInMonth += Leaveday.LeaveHours ?? 0; } else //Toàn Ca { //Check xem có Ca làm việc không Guid? ShiftID = null; var E_TIME_OFF = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_TIME_OFF.ToString()).FirstOrDefault(); var E_CHANGE_SHIFT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_CHANGE_SHIFT.ToString()).FirstOrDefault(); var E_DEFAULT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_DEFAULT.ToString()).FirstOrDefault(); var E_ROSTERGROUP = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_ROSTERGROUP.ToString()).FirstOrDefault(); if (E_TIME_OFF != null) { } else if (E_CHANGE_SHIFT != null) { ShiftID = GetShiftRoster(dateCheck, E_CHANGE_SHIFT); } else if (E_DEFAULT != null) { ShiftID = GetShiftRoster(dateCheck, E_DEFAULT); } else if (E_ROSTERGROUP != null) { //Chưa hỗ trợ đăng ký ca theo nhóm } if (ShiftID != null) { var Shift = lstShift.Where(m => m.ID == ShiftID.Value).FirstOrDefault(); if (Shift != null) { TotalLeaveHourInMonth += Shift.StdWorkHours ?? (Shift.WorkHours ?? 0); } } } } } #endregion #region Gán Dữ Liệu CompensationConfigModel Config = lstCompensationConfig.Where(m => m.ProfileID == ProfileID).FirstOrDefault(); Att_CompensationDetail detail = detailInDB.Where(m => m.MonthYear == Month && m.ProfileID == ProfileID).FirstOrDefault(); if (detail == null) { detail = new Att_CompensationDetail(); detail.ID = Guid.NewGuid(); detailNew.Add(detail); } if (Config != null) { if (Config.MonthResetInitAvailable != null && Config.MonthResetInitAvailable.Value <= Month.Month) { } else { detail.InitAvailable = Config.InitAvailable; } detail.MonthBeginInYear = Config.MonthBeginInYear ?? 1; detail.MonthResetInitAvailable = Config.MonthResetInitAvailable; } detail.ProfileID = ProfileID; detail.Year = Year; detail.MonthYear = Month; detail.MonthStartProfile = MonthHire; detail.LeaveInMonth = TotalLeaveHourInMonth; detail.TotalLeaveBef = TotalLeaveHourBeforeMonth; detail.OvertimeInMonth = TotalOvertimeHourInMonth; detail.TotalOvertimeBef = TotalOvertimeHourBeforeMonth; detail.Remain = ((detail.InitAvailable ?? 0) + TotalOvertimeHourBeforeMonth + TotalOvertimeHourInMonth) - (TotalLeaveHourBeforeMonth + TotalLeaveHourInMonth); TotalOvertimeHourBeforeMonth += TotalOvertimeHourInMonth; TotalLeaveHourBeforeMonth += TotalLeaveHourInMonth; #endregion } } repoAtt_CompensationDetail.Add(detailNew); repoAtt_CompensationDetail.SaveChanges(); #endregion } } }
public static void GetRosterGroup(List<Guid> lstProfileID, DateTime? DateFrom, DateTime? DateTo, out List<Att_Roster> lstRosterTypeGroup, out List<Att_RosterGroup> lstRosterGroup) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); lstRosterGroup = new List<Att_RosterGroup>(); lstRosterTypeGroup = new List<Att_Roster>(); string E_APPROVED = RosterStatus.E_APPROVED.ToString(); string E_ROSTERGROUP = RosterType.E_ROSTERGROUP.ToString(); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); var repoAtt_RosterGroup = new Att_RosterGroupRepository(unitOfWork); if (DateFrom == null || DateTo == null) { lstRosterTypeGroup = repoAtt_Roster.FindBy(m => lstProfileID.Contains(m.ProfileID) && m.Status == E_APPROVED && m.Type == E_ROSTERGROUP).ToList<Att_Roster>(); lstRosterGroup = repoAtt_RosterGroup.FindBy(m => m.DateStart != null && m.DateEnd != null).ToList<Att_RosterGroup>(); } else { lstRosterTypeGroup = repoAtt_Roster.FindBy(m => lstProfileID.Contains(m.ProfileID) && m.Status == E_APPROVED && m.Type == E_ROSTERGROUP && m.DateStart <= DateTo).ToList<Att_Roster>(); lstRosterGroup = repoAtt_RosterGroup.FindBy(m => m.DateStart != null && m.DateEnd != null && m.DateStart <= DateTo && m.DateEnd >= DateFrom).ToList<Att_RosterGroup>(); } } }
/// <summary> /// [Tam.Le] - 2014/08/08 /// Hàm xử lý load dữ liệu /// </summary> /// <param name="request"></param> /// <param name="otModel"></param> /// <returns></returns> public DataTable LoadData(DateTime dateStart, DateTime dateEnd, List<Guid> orgIDs, string ProfileName, string CodeEmp, Guid LeavedayType, out string ErrorMessages) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); ErrorMessages = string.Empty; //bool isIncludeQuitEmp = true; List<Guid> leavedayTypeIds = new List<Guid>(); if (LeavedayType != null) leavedayTypeIds.Add(LeavedayType); List<Guid> shiftIDs = new List<Guid>(); string E_WAIT_APPROVED = LeaveDayStatus.E_WAIT_APPROVED.ToString(); string E_SUBMIT = LeaveDayStatus.E_SUBMIT.ToString(); var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork); List<Att_LeaveDay> leaveDays = repoAtt_Leaveday.FindBy(s => s.LeaveDays > 0 && (s.Status == E_WAIT_APPROVED || s.Status == E_SUBMIT) && dateStart <= s.DateEnd && s.DateStart <= dateEnd).ToList<Att_LeaveDay>(); foreach (var item in leaveDays) { item.Status = E_WAIT_APPROVED; } var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList(); var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork); var workDays = repoAtt_Workday.FindBy(s => profileIds.Contains(s.ProfileID) && dateStart <= s.WorkDate && s.WorkDate <= dateEnd) .Select(s => new { s.ProfileID, s.ShiftID, s.WorkDate, s.InTime1, s.OutTime1 }).ToList(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = repoHre_Profile.FindBy(s => profileIds.Contains(s.ID)) .Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList(); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList(); var repoCat_Position = new Cat_PositionRepository(unitOfWork); var positions = repoCat_Position.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code }).ToList(); var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork); var jobtitles = repoCat_JobTitle.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code }).ToList(); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var leavedayTypes = repoCat_LeaveDayType.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PaidRate }).Distinct().ToList(); var ledvedayPaidIds = leavedayTypes.Where(s => s.PaidRate > 0).Select(s => s.ID).ToList(); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var shifts = repoCat_Shift.GetAll().ToList(); if (orgIDs != null) { profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList(); } if (shiftIDs.Count > 0) { workDays = workDays.Where(s => s.ShiftID.HasValue && shiftIDs.Contains(s.ShiftID.Value)).ToList(); profileIds = workDays.Select(s => s.ProfileID).ToList(); profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList(); } if (leavedayTypeIds.Count > 0) { leaveDays = leaveDays.Where(s => leavedayTypeIds.Contains(s.LeaveDayTypeID)).ToList(); profileIds = leaveDays.Select(s => s.ProfileID).ToList(); profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList(); } //if (!isIncludeQuitEmp) //{ // profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateStart).ToList(); //} var startYear = new DateTime(dateStart.Year, 1, 1); var endYear = new DateTime(dateStart.Year, 12, DateTime.DaysInMonth(dateStart.Year, 12)); var rosterStatus = RosterStatus.E_APPROVED.ToString(); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); List<Att_Roster> listRoster = repoAtt_Roster.FindBy(d => d.Status == rosterStatus && profileIds.Contains(d.ProfileID) && d.DateStart <= dateEnd && d.DateEnd >= startYear).ToList<Att_Roster>(); var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork); List<Cat_DayOff> listHoliday = repoCat_DayOff.FindBy(hol => hol.DateOff >= startYear && hol.DateOff <= endYear).ToList<Cat_DayOff>(); var repoAtt_Grade = new Att_GradeRepository(unitOfWork); var listGrade = repoAtt_Grade.FindBy(d => d.MonthStart != null && d.MonthStart <= dateEnd && profileIds.Contains((Guid)d.ProfileID)).Select(d => new { d.ProfileID, d.MonthStart, d.GradeAttendanceID }).ToList(); List<Guid?> listGradeID = listGrade.Select(d => d.GradeAttendanceID).ToList(); var repoCat_Grade = new Cat_GradeAttendanceRepository(unitOfWork); List<Cat_GradeAttendance> listGradeCfg = repoCat_Grade.FindBy(d => listGradeID.Contains(d.ID)).ToList<Cat_GradeAttendance>(); List<Att_Roster> lstRosterTypeGroup = new List<Att_Roster>(); List<Att_RosterGroup> lstRosterGroup = new List<Att_RosterGroup>(); GetRosterGroup(profileIds, startYear, dateEnd, out lstRosterTypeGroup, out lstRosterGroup); var repoHre_WorkHistory = new Hre_WorkHistoryRepository(unitOfWork); List<Hre_WorkHistory> listWorkHistory = repoHre_WorkHistory.FindBy(d => profileIds.Contains(d.ProfileID) && d.DateEffective <= dateEnd).ToList<Hre_WorkHistory>(); var orgTypes = new List<Cat_OrgStructureType>(); var repoorgType = new Cat_OrgStructureTypeRepository(unitOfWork); orgTypes = repoorgType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>(); DataTable table = GetSchema(); List<string> codeRejects = new List<string>(); codeRejects.Add("SICK"); codeRejects.Add("SU"); codeRejects.Add("SD"); codeRejects.Add("D"); codeRejects.Add("D"); codeRejects.Add("DP"); codeRejects.Add("PSN"); codeRejects.Add("DSP"); codeRejects.Add("M"); List<Guid> leaveDayTypeRejectIDs = leavedayTypes.Where(s => codeRejects.Contains(s.Code)).Select(s => s.ID).ToList(); foreach (var profile in profiles) { var grade = listGrade.Where(d => d.ProfileID == profile.ID && d.MonthStart <= dateEnd).OrderByDescending(d => d.MonthStart).FirstOrDefault(); Cat_GradeAttendance gradeCfg = listGradeCfg.FirstOrDefault(d => grade != null && d.ID == grade.GradeAttendanceID); List<Hre_WorkHistory> listWorkHistoryByProfile = listWorkHistory.Where(d => d.ProfileID == profile.ID).ToList(); List<Att_Roster> listRosterByProfile = listRoster.Where(d => d.ProfileID == profile.ID && d.DateStart <= dateEnd && d.DateEnd >= dateStart).ToList(); var listRosterEntity = listRosterByProfile.Select(d => new Att_RosterEntity { ID = d.ID, ProfileID = d.ProfileID, RosterGroupName = d.RosterGroupName, Type = d.Type, Status = d.Status, DateEnd = d.DateEnd, DateStart = d.DateStart, MonShiftID = d.MonShiftID, TueShiftID = d.TueShiftID, WedShiftID = d.WedShiftID, ThuShiftID = d.ThuShiftID, FriShiftID = d.FriShiftID, SatShiftID = d.SatShiftID, SunShiftID = d.SunShiftID, MonShift2ID = d.MonShiftID, TueShift2ID = d.TueShift2ID, WedShift2ID = d.WedShift2ID, ThuShift2ID = d.ThuShift2ID, FriShift2ID = d.FriShift2ID, SatShift2ID = d.SatShift2ID, SunShift2ID = d.SunShift2ID }).ToList(); var listRosterGroupEntity = lstRosterGroup.Select(d => new Att_RosterGroupEntity { ID = d.ID, DateEnd = d.DateEnd, DateStart = d.DateStart, MonShiftID = d.MonShiftID, TueShiftID = d.TueShiftID, WedShiftID = d.WedShiftID, ThuShiftID = d.ThuShiftID, FriShiftID = d.FriShiftID, SatShiftID = d.SatShiftID, SunShiftID = d.SunShiftID, RosterGroupName = d.RosterGroupName }).ToList(); Dictionary<DateTime, Cat_Shift> listMonthShifts = Att_AttendanceLib.GetDailyShifts(profile.ID, dateStart, dateEnd, listRosterEntity, listRosterGroupEntity, shifts); for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1)) { var leavdayProfiles = leaveDays.Where(s => s.DateStart.Date <= date.Date && date.Date <= s.DateEnd.Date && s.ProfileID == profile.ID).ToList(); if (leavdayProfiles.Count > 0) { bool isWorkDay = gradeCfg != null && Att_WorkDayHelper.IsWorkDay(date, gradeCfg, listMonthShifts, listHoliday); var leaveday = leavdayProfiles.FirstOrDefault(s => ledvedayPaidIds.Contains(s.LeaveDayTypeID)); if (!isWorkDay)// neu ngay do ko phai ngay di lam { if (leaveday != null && leaveDayTypeRejectIDs.Contains(leaveday.LeaveDayTypeID) || listHoliday.Exists(s => s.DateOff == date))// neu ngay do la ngay nghi dc xem la ko xem ca or ngay nghi { isWorkDay = true; } } if (isWorkDay) { var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Date == date.Date); DataRow row = table.NewRow(); Guid? orgId = profile.OrgStructureID; var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID); var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); row[Att_LeaveDayEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.CodeOrg] = orgOrg != null ? orgOrg.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty; row[Att_LeaveDayEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty; row[Att_LeaveDayEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty; row[Att_LeaveDayEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty; var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); row[Att_LeaveDayEntity.FieldNames.ProfileName] = profile.ProfileName; row[Att_LeaveDayEntity.FieldNames.CodeEmp] = profile.CodeEmp; row[Att_LeaveDayEntity.FieldNames.CodePosition] = positon != null ? positon.Code : string.Empty; row[Att_LeaveDayEntity.FieldNames.CodeJobtitle] = jobtitle != null ? jobtitle.Code : string.Empty; var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID); row[Att_LeaveDayEntity.FieldNames.Date] = date; row[Att_LeaveDayEntity.FieldNames.DateFrom] = dateStart; row[Att_LeaveDayEntity.FieldNames.DateTo] = dateEnd; row[Att_LeaveDayEntity.FieldNames.DateExport] = DateTime.Now; //row[Att_LeavedayEntity.FieldNames.UserExport] = Session[SessionObjects.UserLogin]; if (leaveday != null && leaveday.LeaveDays > 0) { row["Paid"] = "X"; } if (workDay != null) { row[Att_LeaveDayEntity.FieldNames.Cat_Shift] = shift.ShiftName; row[Att_LeaveDayEntity.FieldNames.udInTime] = workDay.InTime1 != null ? workDay.InTime1.Value.ToString("HH:mm") : string.Empty; row[Att_LeaveDayEntity.FieldNames.udOutTime] = workDay.OutTime1 != null ? workDay.OutTime1.Value.ToString("HH:mm") : string.Empty; } foreach (var leaday in leavedayTypes) { var leaday1 = leavdayProfiles.FirstOrDefault(s => s.LeaveDayTypeID == leaday.ID); if (leaday1 != null && leaday1.LeaveDays > 0) { row[leaday.Code] = "X"; } } if (leaveday != null) { row[Att_LeaveDayEntity.FieldNames.Status] = leaveday.Status; } table.Rows.Add(row); } } } } //EntityService.SubmitChanges(GuidContext, LoginUserID.Value); context.SaveChanges(); return table; } }
public string ValidateLeaveDayTimeOff(List<Guid> lstProfileId, List<Att_LeaveDay> listleaveDayInsert) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_TimeOffInLieu = new Att_TimeOffInLieuRepository(unitOfWork); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); var repoAtt_RosterGroup = new Att_RosterGroupRepository(unitOfWork); var repoHre_WorkHistory = new Hre_WorkHistoryRepository(unitOfWork); var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork); var repoAtt_TimeOffInLieuMonth = new CustomBaseRepository<Att_TimeOffInLieuMonth>(unitOfWork); var repoCat_GradeAttendance = new CustomBaseRepository<Cat_GradeAttendance>(unitOfWork); var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork); var repoHre_Profile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList(); string ErrorResult = string.Empty; Guid GuidContext = Guid.NewGuid(); DateTime dateMin = listleaveDayInsert.Min(m => m.DateStart); DateTime Datemax = listleaveDayInsert.Min(m => m.DateEnd); DateTime BeginMonthOfMin = new DateTime(dateMin.Year, dateMin.Month, 1); DateTime EndMonthOfMax = new DateTime(Datemax.Year, Datemax.Month, 1); EndMonthOfMax = EndMonthOfMax.AddMonths(1).AddMinutes(-1); DateTime Month4Ago = BeginMonthOfMin.AddMonths(-4); List<Att_TimeOffInLieu> lstTimeOffInLieu = repoAtt_TimeOffInLieu.FindBy(m => m.Date >= Month4Ago && m.Date < EndMonthOfMax && lstProfileId.Contains(m.ProfileID)).ToList<Att_TimeOffInLieu>(); List<Att_TimeOffInLieuMonth> lstTimeOffInLieu_Month = repoAtt_TimeOffInLieuMonth.FindBy(m => m.Month >= Month4Ago && m.Month < EndMonthOfMax && lstProfileId.Contains(m.ProfileID)).ToList<Att_TimeOffInLieuMonth>(); List<Cat_GradeAttendance> lstGradeCfg = repoCat_GradeAttendance.GetAll().ToList<Cat_GradeAttendance>(); var lstGrade = repoAtt_Grade.FindBy(m => lstProfileId.Contains((Guid)m.ProfileID) && m.MonthStart <= dateMin).Select(m => new { m.ProfileID, m.MonthStart, m.GradeAttendanceID }).OrderByDescending(m => m.MonthStart); string E_APPROVED_Roster = RosterStatus.E_APPROVED.ToString(); List<Att_Roster> lstRoster = repoAtt_Roster.FindBy(m => m.Status == E_APPROVED_Roster && m.DateEnd >= dateMin && m.DateStart <= Datemax && lstProfileId.Contains(m.ProfileID)).ToList<Att_Roster>(); List<Att_RosterGroup> lstRosterGroup = repoAtt_RosterGroup.FindBy(m => m.DateEnd >= dateMin && m.DateStart <= Datemax).ToList<Att_RosterGroup>(); string E_ROSTERGROUP = RosterType.E_ROSTERGROUP.ToString(); List<Att_Roster> lstRosterTypeGroup = lstRoster.Where(m => m.Type == E_ROSTERGROUP).ToList(); List<Hre_WorkHistory> lstWorkHistory = repoHre_WorkHistory.FindBy(m => lstProfileId.Contains(m.ProfileID)).ToList<Hre_WorkHistory>(); List<DateTime> lstDayOff = repoCat_DayOff.GetAll().Select(m => m.DateOff).ToList<DateTime>(); //Tạo ra một list giả dữ liệu List<LeaveDayValidate> lstLeaveDayValidate = new List<LeaveDayValidate>(); List<LeaveDayValidate> lstLeaveDayValidate1 = new List<LeaveDayValidate>(); foreach (var item in listleaveDayInsert) { LeaveDayValidate LeaveDayValid = new LeaveDayValidate(); LeaveDayValid.ProfileID = item.ProfileID; LeaveDayValid.DateStart = item.DateStart; LeaveDayValid.DateEnd = item.DateEnd; LeaveDayValid.Duration = item.LeaveHours.Value; LeaveDayValid.TotalDuration = item.LeaveDays ?? 1; lstLeaveDayValidate1.Add(LeaveDayValid); } foreach (var item in lstLeaveDayValidate1) { if (item.DateEnd.Date > item.DateStart.Date) { Dictionary<DateTime, DateTime> dicTime = new Dictionary<DateTime, DateTime>(); DateTime DateMinBeginMonth = new DateTime(item.DateStart.Year, item.DateStart.Month, 1); DateTime DateMaxBeginMonth = new DateTime(item.DateEnd.Year, item.DateEnd.Month, 1); if (DateMinBeginMonth < DateMaxBeginMonth) { Guid GradeID = Guid.Empty; var gradeByProfile = lstGrade.Where(m => m.ProfileID == item.ProfileID).FirstOrDefault(); if (gradeByProfile != null) { GradeID = (Guid)gradeByProfile.GradeAttendanceID; } Cat_GradeAttendance gradeCfg = lstGradeCfg.Where(m => m.ID == GradeID).FirstOrDefault(); if (gradeCfg == null) continue; List<Att_Roster> listRosterByProfile = lstRoster.Where(m => m.ProfileID == item.ProfileID).ToList(); List<Hre_WorkHistory> listWorkHistoryByProfile = lstWorkHistory.Where(m => m.ProfileID == item.ProfileID).ToList(); List<Att_Roster> lstRosterTypeGroupByProfile = lstRosterTypeGroup.Where(m => m.ProfileID == item.ProfileID).ToList(); var listRosterEntity = listRosterByProfile.Select(d => new Att_RosterEntity { ID = d.ID, ProfileID = d.ProfileID, RosterGroupName = d.RosterGroupName, Type = d.Type, Status = d.Status, DateEnd = d.DateEnd, DateStart = d.DateStart, MonShiftID = d.MonShiftID, TueShiftID = d.TueShiftID, WedShiftID = d.WedShiftID, ThuShiftID = d.ThuShiftID, FriShiftID = d.FriShiftID, SatShiftID = d.SatShiftID, SunShiftID = d.SunShiftID, MonShift2ID = d.MonShiftID, TueShift2ID = d.TueShift2ID, WedShift2ID = d.WedShift2ID, ThuShift2ID = d.ThuShift2ID, FriShift2ID = d.FriShift2ID, SatShift2ID = d.SatShift2ID, SunShift2ID = d.SunShift2ID }).ToList(); var listRosterGroupEntity = lstRosterGroup.Select(d => new Att_RosterGroupEntity { ID = d.ID, DateEnd = d.DateEnd, DateStart = d.DateStart, MonShiftID = d.MonShiftID, TueShiftID = d.TueShiftID, WedShiftID = d.WedShiftID, ThuShiftID = d.ThuShiftID, FriShiftID = d.FriShiftID, SatShiftID = d.SatShiftID, SunShiftID = d.SunShiftID, RosterGroupName = d.RosterGroupName }).ToList(); Dictionary<DateTime, Cat_Shift> dailyShifts = Att_AttendanceLib.GetDailyShifts(item.ProfileID, item.DateStart, item.DateEnd, listRosterEntity, listRosterGroupEntity, shifts); for (DateTime DateCheck = DateMinBeginMonth; DateCheck <= DateMaxBeginMonth; DateCheck = DateCheck.AddMonths(1)) { DateTime beginMonth = DateCheck; DateTime endMonth = beginMonth.AddMonths(1).AddMinutes(-1); if (DateCheck == DateMinBeginMonth) { dicTime.Add(item.DateStart, endMonth); } else if (DateCheck == DateMaxBeginMonth) { dicTime.Add(beginMonth, item.DateEnd); } else { dicTime.Add(beginMonth, endMonth); } } foreach (var dicTimeKey in dicTime.Keys) { DateTime DateS = dicTimeKey; DateTime DateE = dicTime[dicTimeKey]; double TotalDuration = 0; for (DateTime dateC = DateS; dateC <= DateE; dateC = dateC.AddDays(1)) { if (!lstDayOff.Contains(dateC) && dailyShifts.ContainsKey(dateC)) { if (dailyShifts[dateC] != null) { TotalDuration++; } } } LeaveDayValidate LeaveDayValid = new LeaveDayValidate(); LeaveDayValid.ProfileID = item.ProfileID; LeaveDayValid.DateStart = DateS; LeaveDayValid.DateEnd = DateE; LeaveDayValid.Duration = item.Duration; LeaveDayValid.TotalDuration = TotalDuration; lstLeaveDayValidate1.Add(LeaveDayValid); } } else { lstLeaveDayValidate.Add(item); } } else { lstLeaveDayValidate.Add(item); } } List<Guid> LstProfileIDs_Error_MissImport = new List<Guid>(); List<Guid> LstProfileIDs_Error_NotValid = new List<Guid>(); foreach (var item in lstLeaveDayValidate) { DateTime monthYear = new DateTime(item.DateStart.Year, item.DateStart.Month, 1); List<Att_TimeOffInLieu> lstTimeOffInlieu_ByProfile = lstTimeOffInLieu.Where(m => m.ProfileID == item.ProfileID).ToList(); List<Att_TimeOffInLieuMonth> lstTimeOffInlieuMonth_ByProfile = lstTimeOffInLieu_Month.Where(m => m.ProfileID == item.ProfileID).ToList(); double? NumAvailable = CalculateTotalHourTimeOff(item.ProfileID, lstTimeOffInlieu_ByProfile, lstTimeOffInlieuMonth_ByProfile, monthYear, 1); if (NumAvailable == null) { LstProfileIDs_Error_MissImport.Add(item.ProfileID); } else if ((item.Duration * item.TotalDuration) > NumAvailable.Value) { LstProfileIDs_Error_NotValid.Add(item.ProfileID); } } if (LstProfileIDs_Error_MissImport.Count > 0) { var profile = repoHre_Profile.FindBy(m => LstProfileIDs_Error_MissImport.Contains(m.ID)).Select(m => new { m.CodeEmp, m.ProfileName }); foreach (var item in profile) { ErrorResult += item.ProfileName + "[" + item.CodeEmp + "]; "; } if (ErrorResult.Length > 0) { ErrorResult = ErrorResult.Substring(0, ErrorResult.Length - 2); } ErrorResult = ConstantMessages.EmpDoNotConfigTimeOffBegin.TranslateString(); //ErrorResult = "EmpDoNotConfigTimeOffBegin"; } else if (LstProfileIDs_Error_NotValid.Count > 0) { var profile = repoHre_Profile.FindBy(m => LstProfileIDs_Error_NotValid.Contains(m.ID)).Select(m => new { m.CodeEmp, m.ProfileName }); foreach (var item in profile) { ErrorResult += item.ProfileName + "[" + item.CodeEmp + "]; "; } if (ErrorResult.Length > 0) { ErrorResult = ErrorResult.Substring(0, ErrorResult.Length - 2); } ErrorResult = ConstantMessages.DataNotEnoughToMakeLeave.TranslateString(); //ErrorResult = "EmpDoNotEnoughTimeOff"; } return ErrorResult; } }
public void AnalyzeCompensation(int Year, List <Guid> lstProfileIDTotal) { //Lấy cấu hình //lấy ngày nghỉ (Bù) //Lấy tăng ca (Bù) //Lấy Ca Làm Việc (Bù) //Hệ Số Tăng Ca (Loại Tăng Ca) foreach (var lstProfileID in lstProfileIDTotal.Chunk(500)) { using (var context = new VnrHrmDataContext()) { #region Khai báo var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); var repoAtt_Overtime = new Att_OvertimeRepository(unitOfWork); var repoAtt_CompensationConfig = new Att_CompensationConfigRepository(unitOfWork); var repoAtt_CompensationDetail = new Att_CompensationDetailRepository(unitOfWork); #endregion #region Lấy Dữ Liệu // var profileByCodeEmp = repoHre_Profile.FindBy(p => p.IsDelete == null && p.CodeEmp == codeEmp).FirstOrDefault(); var lstProfile = repoHre_Profile.FindBy(m => lstProfileID.Contains(m.ID)).Select(m => new { m.ID, m.DateHire }).ToList(); var lstCompensationConfig = repoAtt_CompensationConfig .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)) .Select(m => new CompensationConfigModel() { ID = m.ID, ProfileID = m.ProfileID, Year = m.Year, InitAvailable = m.InitAvailable, MonthBeginInYear = m.MonthBeginInYear, MonthResetInitAvailable = m.MonthResetInitAvailable, MonthStartProfile = m.MonthStartProfile }) .ToList(); int MonthBeginYear = 1; if (lstCompensationConfig != null && lstCompensationConfig.Count > 0) { MonthBeginYear = lstCompensationConfig.FirstOrDefault().MonthBeginInYear ?? 1; } DateTime BeginYear = new DateTime(Year, MonthBeginYear, 1); DateTime EndYear = BeginYear.AddYears(1).AddMinutes(-1); string E_APPROVED_Leave = LeaveDayStatus.E_APPROVED.ToString(); var lstLeaveDayCompensationTypeID = repoCat_LeaveDayType .FindBy(m => m.IsTimeOffInLieu == true) .Select(m => m.ID) .ToList(); var lstLeaveday = repoAtt_Leaveday .FindBy(m => m.Status == E_APPROVED_Leave && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstLeaveDayCompensationTypeID.Contains(m.LeaveDayTypeID) && lstProfileID.Contains(m.ProfileID)) .Select(m => new { m.ID, m.ProfileID, m.DateStart, m.DateEnd, m.LeaveHours, m.DurationType }) .ToList(); string E_TIMEOFF = MethodOption.E_TIMEOFF.ToString(); string E_APPROVED_Overtime = OverTimeStatus.E_APPROVED.ToString(); string E_CONFIRM_Overtime = OverTimeStatus.E_CONFIRM.ToString(); var lstOvertime = repoAtt_Overtime .FindBy(m => m.WorkDateRoot >= BeginYear && m.WorkDateRoot <= EndYear && m.MethodPayment == E_TIMEOFF && (m.Status == E_APPROVED_Overtime || m.Status == E_CONFIRM_Overtime) && lstProfileID.Contains(m.ProfileID)) .Select(m => new { m.ID, m.ProfileID, m.WorkDateRoot, m.ApproveHours, m.ConfirmHours, m.Status }).ToList(); string E_APPROVED_Roster = RosterStatus.E_APPROVED.ToString(); var lstRoster = repoAtt_Roster .FindBy(m => m.Status == E_APPROVED_Roster && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstProfileID.Contains(m.ProfileID)) .Select(m => new RosterModel { ID = m.ID, ProfileID = m.ProfileID, DateStart = m.DateStart, DateEnd = m.DateEnd, Type = m.Type, MonShiftID = m.MonShiftID, TueShiftID = m.TueShiftID, WedShiftID = m.WedShiftID, ThuShiftID = m.ThuShiftID, FriShiftID = m.FriShiftID, SatShiftID = m.SatShiftID, SunShiftID = m.SunShiftID }) .ToList(); var lstShift = repoCat_Shift.GetAll().Select(m => new { m.ID, m.WorkHours, m.StdWorkHours }).ToList(); List <Att_CompensationDetail> detailInDB = repoAtt_CompensationDetail .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)) .ToList(); List <Att_CompensationDetail> detailNew = new List <Att_CompensationDetail>(); foreach (var ProfileID in lstProfileID) { double TotalLeaveHourBeforeMonth = 0; double TotalOvertimeHourBeforeMonth = 0; var Profile = lstProfile.Where(m => m.ID == ProfileID).FirstOrDefault(); int MonthHire = 1; if (Profile.DateHire != null && Profile.DateHire >= BeginYear && Profile.DateHire <= EndYear) { if (Profile.DateHire.Value.Day >= 15) { MonthHire = Profile.DateHire.Value.AddMonths(1).Month; } else { MonthHire = Profile.DateHire.Value.Month; } } for (DateTime Month = BeginYear; Month < EndYear; Month = Month.AddMonths(1)) { if (MonthHire > Month.Month) { continue; } DateTime BeginMonth = Month; DateTime EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1); double TotalLeaveHourInMonth = 0; double TotalOvertimeHourInMonth = 0; #region Tăng Ca var lstOvertimeByProfileByMonth = lstOvertime.Where(m => m.ProfileID == ProfileID && m.WorkDateRoot >= BeginMonth && m.WorkDateRoot <= EndMonth).ToList(); TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_CONFIRM_Overtime).Sum(m => m.ConfirmHours); TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_APPROVED_Overtime).Sum(m => m.ApproveHours ?? 0); #endregion #region Ngày Nghỉ var lstLeavedayByProfileByMonth = lstLeaveday.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList(); var lstRosterByProfileByMonth = lstRoster.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList(); foreach (var Leaveday in lstLeavedayByProfileByMonth) { DateTime dateStart = Leaveday.DateStart < BeginMonth ? BeginMonth : Leaveday.DateStart; DateTime dateEnd = Leaveday.DateEnd > EndMonth ? EndMonth : Leaveday.DateEnd; for (DateTime dateCheck = dateStart; dateCheck <= dateEnd; dateCheck = dateCheck.AddDays(1)) { if (Leaveday.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()) // Trong Ca { TotalLeaveHourInMonth += Leaveday.LeaveHours ?? 0; } else //Toàn Ca { //Check xem có Ca làm việc không Guid?ShiftID = null; var E_TIME_OFF = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_TIME_OFF.ToString()).FirstOrDefault(); var E_CHANGE_SHIFT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_CHANGE_SHIFT.ToString()).FirstOrDefault(); var E_DEFAULT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_DEFAULT.ToString()).FirstOrDefault(); var E_ROSTERGROUP = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_ROSTERGROUP.ToString()).FirstOrDefault(); if (E_TIME_OFF != null) { } else if (E_CHANGE_SHIFT != null) { ShiftID = GetShiftRoster(dateCheck, E_CHANGE_SHIFT); } else if (E_DEFAULT != null) { ShiftID = GetShiftRoster(dateCheck, E_DEFAULT); } else if (E_ROSTERGROUP != null) { //Chưa hỗ trợ đăng ký ca theo nhóm } if (ShiftID != null) { var Shift = lstShift.Where(m => m.ID == ShiftID.Value).FirstOrDefault(); if (Shift != null) { TotalLeaveHourInMonth += Shift.StdWorkHours ?? (Shift.WorkHours ?? 0); } } } } } #endregion #region Gán Dữ Liệu CompensationConfigModel Config = lstCompensationConfig.Where(m => m.ProfileID == ProfileID).FirstOrDefault(); Att_CompensationDetail detail = detailInDB.Where(m => m.MonthYear == Month && m.ProfileID == ProfileID).FirstOrDefault(); if (detail == null) { detail = new Att_CompensationDetail(); detail.ID = Guid.NewGuid(); detailNew.Add(detail); } if (Config != null) { if (Config.MonthResetInitAvailable != null && Config.MonthResetInitAvailable.Value <= Month.Month) { } else { detail.InitAvailable = Config.InitAvailable; } detail.MonthBeginInYear = Config.MonthBeginInYear ?? 1; detail.MonthResetInitAvailable = Config.MonthResetInitAvailable; } detail.ProfileID = ProfileID; detail.Year = Year; detail.MonthYear = Month; detail.MonthStartProfile = MonthHire; detail.LeaveInMonth = TotalLeaveHourInMonth; detail.TotalLeaveBef = TotalLeaveHourBeforeMonth; detail.OvertimeInMonth = TotalOvertimeHourInMonth; detail.TotalOvertimeBef = TotalOvertimeHourBeforeMonth; detail.Remain = ((detail.InitAvailable ?? 0) + TotalOvertimeHourBeforeMonth + TotalOvertimeHourInMonth) - (TotalLeaveHourBeforeMonth + TotalLeaveHourInMonth); TotalOvertimeHourBeforeMonth += TotalOvertimeHourInMonth; TotalLeaveHourBeforeMonth += TotalLeaveHourInMonth; #endregion } } repoAtt_CompensationDetail.Add(detailNew); repoAtt_CompensationDetail.SaveChanges(); #endregion } } }
/// <summary> /// Hàm tính ra số ngày không làm HDTJob /// </summary> /// <param name="lstProfile">Ds Nhân Viên</param> /// <param name="LeaveDayTypeCode">các mã ngày nghỉ không tính HDJob </param> /// <param name="MonthCheck">tháng kiểm tra</param> public static void GetHDTJobDayByProfile(List<Hre_ProfileEntity> lstProfile, string LeaveDayTypeCode, DateTime MonthCheck) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoHre_HDTJob = new Hre_HDTJobRepository(unitOfWork); var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); DateTime DateStart = new DateTime(MonthCheck.Year, MonthCheck.Month, 1); DateTime DateEnd = DateStart.AddMonths(1).AddSeconds(-1); List<string> lstLeaveTypeCode = LeaveDayTypeCode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); //=======Get DB string E_APPROVE = HDTJobStatus.E_APPROVE.ToString(); string E_Four = EnumDropDown.HDTJobType.E_TYPE4.ToString(); string E_Five = EnumDropDown.HDTJobType.E_TYPE5.ToString(); var lstHDTJob = repoHre_HDTJob.FindBy(m => m.IsDelete == null && m.Status == E_APPROVE && m.DateFrom <= DateEnd && m.DateTo >= DateStart).Select(m => new { m.ProfileID, m.DateFrom, m.DateTo, m.Type }).ToList(); string E_APPROVED = LeaveDayStatus.E_APPROVED.ToString(); //=======Get DB var lstLeaveDayHaveCode = repoAtt_LeaveDay.FindBy(m => m.IsDelete == null && m.Status == E_APPROVE && m.DateStart <= DateEnd && m.DateEnd >= DateStart && m.LeaveDayTypeID != null && lstLeaveTypeCode.Contains(m.Cat_LeaveDayType.Code)).Select(m => new { m.ProfileID, m.DateStart, m.DateEnd }).ToList(); //=======Get DB var lstRoster = repoAtt_Roster.FindBy(m => m.IsDelete == null && m.Status == E_APPROVED && m.DateStart <= DateEnd && m.DateEnd >= DateStart).Select(m => new { m.ProfileID, m.DateStart, m.DateEnd, m.MonShiftID, m.TueShiftID, m.WedShiftID, m.ThuShiftID, m.FriShiftID, m.SatShiftID, m.SunShiftID }); foreach (var profile in lstProfile) { var lstHDTJobByProfile = lstHDTJob.Where(m => m.ProfileID == profile.ID).ToList(); var lstLeaveDayHaveCodeByProfile = lstLeaveDayHaveCode.Where(m => m.ProfileID == profile.ID).ToList(); var lstRosterByProfile = lstRoster.Where(m => m.ProfileID == profile.ID).ToList(); int Numday_Non_HDTJob = 0; int Numday_HDTJob_4 = 0; int Numday_HDTJob_5 = 0; bool isHaveHDTJob = lstHDTJob.Any(m => m.ProfileID == profile.ID); if (isHaveHDTJob) { for (DateTime dateCheck = DateStart; dateCheck <= DateEnd; dateCheck = dateCheck.AddDays(1)) { bool isHaveRoster = false; switch (dateCheck.DayOfWeek) { case DayOfWeek.Monday: if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.MonShiftID != null)) { isHaveRoster = true; } break; case DayOfWeek.Tuesday: if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.TueShiftID != null)) { isHaveRoster = true; } break; case DayOfWeek.Wednesday: if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.WedShiftID != null)) { isHaveRoster = true; } break; case DayOfWeek.Thursday: if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.ThuShiftID != null)) { isHaveRoster = true; } break; case DayOfWeek.Friday: if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.FriShiftID != null)) { isHaveRoster = true; } break; case DayOfWeek.Saturday: if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.SatShiftID != null)) { isHaveRoster = true; } break; case DayOfWeek.Sunday: if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.SunShiftID != null)) { isHaveRoster = true; } break; } if (isHaveRoster) { //thỏa 2 điều kiên 1: nam ngoài cung hdt job Hoặc là có ngày nghỉ trong loại kia if (lstLeaveDayHaveCodeByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck) || !lstHDTJobByProfile.Any(m => m.DateFrom <= dateCheck && m.DateTo >= dateCheck)) { Numday_Non_HDTJob++; } if (lstHDTJobByProfile.Any(m => m.Type == E_Four && m.DateFrom <= dateCheck && m.DateTo >= dateCheck)) { Numday_HDTJob_4++; } if (lstHDTJobByProfile.Any(m => m.Type == E_Five && m.DateFrom <= dateCheck && m.DateTo >= dateCheck)) { Numday_HDTJob_5++; } } } profile.NumdayNonHDTJob = Numday_Non_HDTJob; profile.NumdayHDTJobTypeIV = Numday_HDTJob_4; profile.NumdayHDTJobTypeV = Numday_HDTJob_5; } else { profile.NumdayNonHDTJob = int.MaxValue; profile.NumdayHDTJobTypeIV = 0; profile.NumdayHDTJobTypeV = 0; } } }//close using }
public DataTable GetReportDetailedMonthlyStay(DateTime dateStart, DateTime dateEnd, List<Hre_ProfileEntity> profiles, string orgStructureID, bool isIncludeQuitEmp, Guid[] leaveDayTypeIDs, string codeEmp, bool isNotAllowZero, string userExport, bool IsCreateTemplate, string UserLogin) { using (var context = new VnrHrmDataContext()) { var baseservice = new BaseService(); string key = OverTimeStatus.E_APPROVED.ToString(); DataTable table = CreateReportDetailedMonthlyStaySchema(leaveDayTypeIDs, dateStart, dateEnd); if (IsCreateTemplate) { return table.ConfigTable(); } var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); var repoCat_LeaveDayTypeRepository = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork); var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork); var repoCat_Shift = new Cat_ShiftRepository(unitOfWork); var repoCat_GradeAtt = new Cat_GradeAttendanceRepository(unitOfWork); var repoHre_WorkHistory = new Hre_WorkHistoryRepository(unitOfWork); var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork); List<Guid> lstProfileIDs = profiles.Select(s => s.ID).ToList(); List<Att_LeaveDayEntity> leaveDays = new List<Att_LeaveDayEntity>(); List<Cat_LeaveDayType> leavedaytypes = new List<Cat_LeaveDayType>(); string status = string.Empty; List<object> para = new List<object>(); para.AddRange(new object[3]); para[0] = (object)orgStructureID; para[1] = dateStart; para[2] = dateEnd; if (lstProfileIDs != null && lstProfileIDs.Count > 0) { leaveDays = baseservice.GetData<Att_LeaveDayEntity>(para, ConstantSql.hrm_att_getdata_LeaveDay, UserLogin, ref status).Where(s => s.Status == key).ToList(); } else { return table.ConfigTable(); } //[Tho.Bui] Get LeavedayR=type if (leaveDays != null && leaveDays.Count > 0) { List<Guid> lstLDTinLD = leaveDays.Select(s => s.LeaveDayTypeID).Distinct().ToList(); leavedaytypes = repoCat_LeaveDayTypeRepository.FindBy(s => s.IsDelete == null && lstLDTinLD.Contains(s.ID)).ToList(); List<Guid> leavedayguid = leaveDays.Select(s => s.LeaveDayTypeID).ToList(); leavedaytypes = leavedaytypes.Where(s => leavedayguid.Contains(s.ID)).ToList(); } var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList(); var rosterStatus = RosterStatus.E_APPROVED.ToString(); var _rosters = new List<Att_Roster>(); foreach (var tempProfileIds in lstProfileIDs.Chunk(1000)) { _rosters.AddRange(unitOfWork.CreateQueryable<Att_Roster>(Guid.Empty, d => tempProfileIds.Contains(d.ProfileID) && d.Status == rosterStatus && d.DateStart <= dateEnd && d.DateEnd >= dateStart).ToList()); } var rosters = new List<Att_RosterEntity>(); if (_rosters.Count > 0) rosters = _rosters.Translate<Att_RosterEntity>(); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var leavedayTypes = repoCat_LeaveDayType.FindBy(s => s.Code != null && s.IsDelete == null).Select(s => new { s.Code, s.ID, s.PaidRate, s.LeaveDayTypeName }).ToList(); var leavdayPadidIDs = leavedayTypes.Where(s => s.PaidRate > 0).Select(s => s.ID).ToList(); List<Guid> guids = profiles.Select(s => s.ID).ToList(); leaveDays = leaveDays.Where(s => guids.Contains(s.ProfileID)).ToList(); if (leaveDayTypeIDs != null) { leaveDays = leaveDays.Where(s => leaveDayTypeIDs.Contains(s.LeaveDayTypeID)).ToList(); profileIds = leaveDays.Select(s => s.ProfileID).ToList(); profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList(); } if (!isIncludeQuitEmp) { profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList(); } //var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList(); var shifts = unitOfWork.CreateQueryable<Cat_Shift>(Guid.Empty).ToList().Translate<Cat_ShiftEntity>(); List<string> codeRejects = new List<string>(); codeRejects.Add("SICK"); codeRejects.Add("SU"); codeRejects.Add("SD"); codeRejects.Add("D"); codeRejects.Add("DP"); codeRejects.Add("PSN"); codeRejects.Add("DSP"); codeRejects.Add("M"); List<Guid> leaveDayTypeRejectIDs = leavedayTypes.Where(s => codeRejects.Contains(s.Code)).Select(s => s.ID).ToList(); if (isNotAllowZero) { var profileIDs = leaveDays.Select(s => s.ProfileID).ToList(); profiles = profiles.Where(s => profileIDs.Contains(s.ID)).ToList(); } #region sai xong xóa string CodeEmpTest = string.Empty; if (CodeEmpTest != string.Empty) { char[] ext = new char[] { ';', ',' }; List<string> lstCodeEmpTest = CodeEmpTest.Split(ext, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); profiles = profiles.Where(m => lstCodeEmpTest.Contains(m.CodeEmp)).ToList(); } #endregion var leveDayIDs = leaveDays.Select(s => s.LeaveDayTypeID).ToList(); leavedayTypes = leavedayTypes.Where(s => leveDayIDs.Contains(s.ID)).ToList(); var holidayDates = repoCat_DayOff.FindBy(hol => hol.DateOff >= dateStart && hol.DateOff <= dateEnd).Select(s => s.DateOff).ToList(); holidayDates = holidayDates.Select(s => s.Date).ToList(); var lstRosterGroup = unitOfWork.CreateQueryable<Att_RosterGroup>(Guid.Empty, s => s.DateStart != null && s.DateStart >= dateStart && s.DateEnd != null && s.DateEnd <= dateEnd).ToList().Translate<Att_RosterGroupEntity>(); foreach (var profile in profiles) { var rosterProfiles = rosters.Where(s => s.ProfileID == profile.ID).ToList(); List<DateTime> workDayDates = new List<DateTime>(); foreach (var roster in rosterProfiles) { for (DateTime date = roster.DateStart; date <= roster.DateEnd; date = date.AddDays(1)) { workDayDates.Add(date.Date); } } workDayDates = workDayDates.Where(s => !holidayDates.Contains(s.Date)).ToList(); DataRow row = table.NewRow(); var leaveDay = leaveDays.FirstOrDefault(s => s.ProfileID == profile.ID); var LeaveDayType = leavedaytypes.FirstOrDefault(s => s.ID != Guid.Empty && leaveDay != null && s.ID == leaveDay.LeaveDayTypeID); row[Att_ReportDetailedMonthlyStayEntity.FieldNames.ProfileName] = profile.ProfileName; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.CodeEmp] = profile.CodeEmp; if (profile.E_COMPANY != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_COMPANY] = profile.E_COMPANY; if (profile.E_BRANCH != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_BRANCH] = profile.E_BRANCH; if (profile.E_UNIT != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_UNIT] = profile.E_UNIT; if (profile.E_DIVISION != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_DIVISION] = profile.E_DIVISION; if (profile.E_DEPARTMENT != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_DEPARTMENT] = profile.E_DEPARTMENT; if (profile.E_TEAM != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_TEAM] = profile.E_TEAM; if (profile.E_SECTION != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_SECTION] = profile.E_SECTION; if (profile.JobTitleName != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.JobTitleName] = profile.JobTitleName; if (profile.PositionName != null) row[Att_ReportDetailedMonthlyStayEntity.FieldNames.PositionName] = profile.PositionName; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.DateFrom] = dateStart; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.DateTo] = dateEnd; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.UserExport] = userExport; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.DateExport] = DateTime.Today; var leadayProfiles = leaveDays.Where(s => s.ProfileID == profile.ID).ToList(); var ledayeTyepIDs = leadayProfiles.Select(s => s.LeaveDayTypeID).ToList(); double sumPaid = 0; foreach (var leadayType in leavedayTypes.Where(s => ledayeTyepIDs.Contains(s.ID)).ToList()) { double sum = 0; var leavdayProfiles = leadayProfiles.Where(s => s.LeaveDayTypeID == leadayType.ID).ToList(); foreach (var leavdayProfile in leavdayProfiles) { var DateEnd = leavdayProfile.DateEnd; if (DateEnd > dateEnd) { DateEnd = dateEnd; } for (DateTime date = leavdayProfile.DateStart; date <= DateEnd; date = date.AddDays(1)) { bool isWorkDay = workDayDates.Contains(date); if (!isWorkDay)// neu ngay do ko phai ngay di lam { if (leaveDayTypeRejectIDs.Contains(leavdayProfile.LeaveDayTypeID))// neu ngay do la ngay nghi dc xem la ko xem ca or ngay nghi { isWorkDay = true; } } if (isWorkDay) { if (leavdayProfile.Duration > 0) { //sum++; sum += leavdayProfile.Duration; } if (leavdayPadidIDs.Contains(leavdayProfile.LeaveDayTypeID)) { sumPaid += leadayType.PaidRate; //sumPaid++; } } } } row[leadayType.Code] = sum > 0 ? (object)sum : DBNull.Value; row[Att_ReportDetailedMonthlyStayEntity.FieldNames.Paid] = sumPaid > 0 ? (object)sumPaid : DBNull.Value; } #region tinh so gio nghi tung ngay cua nhan vien var leavdayByProfile = leadayProfiles.Where(s => s.ProfileID == profile.ID).ToList(); Dictionary<DateTime, List<Guid?>> tempShiftByDate = new Dictionary<DateTime, List<Guid?>>(); tempShiftByDate = Att_AttendanceLib.GetDailyShifts(dateStart, dateEnd, profile.ID, rosterProfiles, lstRosterGroup); foreach (var leavdayProfile in leavdayByProfile) { for (DateTime date = dateStart; date < dateEnd; date = date.AddDays(1)) { bool isWorkDay = workDayDates.Contains(date); if (isWorkDay) { //lay ca lam viec cua nhan vien if (tempShiftByDate != null) { var lstShiftID = tempShiftByDate.Where(s => s.Key == date).SelectMany(s => s.Value).ToList(); if (lstShiftID.Count > 0) { var lstShiftProfileByDate = shifts.Where(s => s.WorkHours != null && lstShiftID.Contains(s.ID)).ToList(); double? _tempWorkHour = 0; _tempWorkHour = lstShiftProfileByDate.Sum(s => s.WorkHours); if (_tempWorkHour > 0) { row["Day" + date.Day.ToString()] = _tempWorkHour; } } } } } } #endregion table.Rows.Add(row); } var configs = new Dictionary<string, Dictionary<string, object>>(); var config = new Dictionary<string, object>(); var confighidden = new Dictionary<string, object>(); confighidden.Add("hidden", true); //var configdate = new Dictionary<string, object>(); //configdate.Add("format", "{0:dd/MM/yyyy}"); config.Add("width", 100); //config.Add("locked", true); if (!configs.ContainsKey("CodeEmp")) configs.Add("CodeEmp", config); if (!configs.ContainsKey("DepartmentCode")) configs.Add("DepartmentCode", config); if (!configs.ContainsKey("PositionName")) configs.Add("PositionName", config); if (!configs.ContainsKey("JobTitleName")) configs.Add("JobTitleName", config); if (!configs.ContainsKey("Paid")) configs.Add("Paid", config); if (!configs.ContainsKey("BranchCode")) configs.Add("BranchCode", config); if (!configs.ContainsKey("TeamCode")) configs.Add("TeamCode", config); if (!configs.ContainsKey("SectionCode")) configs.Add("SectionCode", config); if (!configs.ContainsKey("OrgName")) configs.Add("OrgName", config); if (!configs.ContainsKey("TeamName")) configs.Add("TeamName", config); if (!configs.ContainsKey("SectionName")) configs.Add("SectionName", config); if (!configs.ContainsKey("BranchName")) configs.Add("BranchName", config); if (!configs.ContainsKey("DateFrom")) configs.Add("DateFrom", confighidden); if (!configs.ContainsKey("DateTo")) configs.Add("DateTo", confighidden); if (!configs.ContainsKey("UserExport")) configs.Add("UserExport", confighidden); if (!configs.ContainsKey("DateExport")) configs.Add("DateExport", confighidden); foreach (var leavdayType in leavedayTypes) { if (!configs.ContainsKey(leavdayType.Code)) configs.Add(leavdayType.Code, config); } return table.ConfigTable(configs); } }
public List<Att_ProfileEntity> CheckRoster(DateTime? DateStart, DateTime? DateEnd, List<Hre_ProfileEntity> lstProfileIDsModel, bool isNotRoster, bool isDuplicateRoster, bool? isConstantRoster) { // List<Att_ProfileEntity> reportData = new List<Att_ProfileEntity>(); List<Guid> lstProfileIDs = lstProfileIDsModel.Select(s => s.ID).ToList(); string status = string.Empty; List<Att_ProfileEntity> reportData = new List<Att_ProfileEntity>(); var _baseService = new BaseService(); if (DateStart > DateEnd) { return reportData; } using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork); var repoCat_Position = new Cat_PositionRepository(unitOfWork); var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var repoLeaveDay = new Att_LeavedayRepository(unitOfWork); List<Att_RosterEntity> listWRt = new List<Att_RosterEntity>(); string E_CANCEL = RosterStatus.E_CANCEL.ToString(); string E_REJECTED = RosterStatus.E_REJECTED.ToString(); var repoRoster = new Att_RosterRepository(unitOfWork); var lstRoster = repoRoster.FindBy(s => s.IsDelete == null && s.DateStart <= DateEnd && s.DateEnd >= DateStart && s.Status != E_CANCEL && s.Status != E_REJECTED).ToList(); //var lstRoster = GetData<Att_RosterEntity>(lstObj, ConstantSql.hrm_att_sp_get_Roster,ref status).Where( // s => s.StatusRoster != E_CANCEL && s.StatusRoster != E_REJECTED // ).ToList(); var profileIds = lstRoster.Where(s => lstProfileIDs.Contains(s.ProfileID)).Select(s => s.ProfileID).Distinct().ToList(); string key = ProfileStatusSyn.E_WAITING.ToString(); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var profiles = lstProfileIDsModel.Where(s => s.IsDelete == null && s.StatusSyn != key && (s.DateQuit == null || s.DateQuit > DateStart)) .Select(s => new { s.ID, s.DateQuit, s.OrgStructureName, s.E_UNIT, s.E_DIVISION, s.E_DEPARTMENT, s.E_TEAM, s.E_SECTION, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID, s.Email, s.CodeAttendance, s.Gender, s.BusinessPhone, s.DateEndProbation, s.DateHire }).ToList(); if (lstProfileIDs.Count != 0 && lstProfileIDs[0] != Guid.Empty) { profiles = profiles.Where(s => lstProfileIDs.Contains(s.ID)).ToList(); } var orgs = repoCat_OrgStructure.FindBy(s => s.Code != 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 orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); string E_CANCEL_LEAVE = LeaveDayStatus.E_CANCEL.ToString(); string E_REJECTED_LEAVE = LeaveDayStatus.E_REJECTED.ToString(); var lstLeaveDay = repoLeaveDay.FindBy(s => s.IsDelete == null && s.DateStart <= DateEnd && s.DateEnd >= DateStart && s.Status != E_CANCEL_LEAVE && s.Status != E_REJECTED_LEAVE).ToList(); //var lstLeaveDay = GetData<Att_LeaveDayEntity>(lstObj1, ConstantSql.hrm_att_sp_get_Leaveday, ref status).Where( // s => s.StatusLeaveDay != E_CANCEL_LEAVE && s.StatusLeaveDay != E_REJECTED_LEAVE).ToList(); //List<Guid> guids = EntityService.GetEntityList<Att_Roster>(false, EntityService.GuidMainContext, Guid.Empty, s => s.DateStart <= DateEnd && s.DateEnd >= DateStart).Select(s => s.ProfileID).Distinct().ToList(); List<Guid> guids = lstRoster.Select(s => s.ProfileID).Distinct().ToList(); // var listProfile = GetProfilesWorking(OrgStructureID, DateStart); if (isNotRoster == true) { //List<Hre_Profile> profiles = listProfile.Where(s => !guids.Contains(s.ID)).ToList(); if (isConstantRoster == true) { foreach (var profile in profiles) { for (DateTime dateCheck = DateStart.Value; dateCheck <= DateEnd.Value; dateCheck = dateCheck.AddDays(1)) { List<Guid> ListProfileRosterIds = lstRoster.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck).Select(m => m.ProfileID).Distinct().ToList(); List<Guid> ListProfileLeaveIds = lstLeaveDay.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck).Select(m => m.ProfileID).Distinct().ToList(); var profileNotIn = profiles.Where(m => !ListProfileRosterIds.Contains(m.ID) && !ListProfileLeaveIds.Contains(m.ID)).ToList(); //reportData.AddRange(profileNotIn.Translate<Att_ProfileEntity>()); //foreach (var profileNotRoster in profileNotIn) //{ if (profileNotIn != null && profileNotIn.Count > 0) { Att_ProfileEntity profileResult = new Att_ProfileEntity(); //Guid? orgId = profile.OrgStructureID; //var orgModel = orgs.Where(s => s.ID == orgId).FirstOrDefault(); //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); profileResult.E_UNIT = profile.E_UNIT; profileResult.E_DIVISION = profile.E_DIVISION; profileResult.E_DEPARTMENT = profile.E_DEPARTMENT; profileResult.E_TEAM = profile.E_TEAM; profileResult.E_SECTION = profile.E_SECTION; var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); profileResult.ID = profile.ID; profileResult.CodeEmp = profile.CodeEmp; profileResult.ProfileName = profile.ProfileName; profileResult.CodeAttendance = profile.CodeAttendance; profileResult.DateHire = profile.DateHire; profileResult.PositionName = positon != null ? positon.PositionName : string.Empty; profileResult.JobTitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty; profileResult.Email = profile.Email; profileResult.DateEndProbation = profile.DateEndProbation; profileResult.DateQuit = profile.DateQuit; if (profile.Gender == "E_FEMALE") profileResult.Gender = "Nam"; if (profile.Gender == "E_MALE") profileResult.Gender = "Nữ"; reportData.Add(profileResult); } //} //profileResult.AddRange(profileNotIn); } } reportData = reportData.Distinct().ToList(); return reportData; } else { var rs = profiles.Where(s => !guids.Contains(s.ID)).ToList().Translate<Att_ProfileEntity>(); foreach (var profile in rs) { Att_ProfileEntity profileResult = new Att_ProfileEntity(); //Guid? orgId = profile.OrgStructureID; //var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes); //var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); //var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes); //var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); profileResult.E_UNIT = profile.E_UNIT; profileResult.E_DIVISION = profile.E_DIVISION; profileResult.E_DEPARTMENT = profile.E_DEPARTMENT; profileResult.E_TEAM = profile.E_TEAM; profileResult.E_SECTION = profile.E_SECTION; var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID); var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID); profileResult.ID = profile.ID; profileResult.CodeEmp = profile.CodeEmp; profileResult.ProfileName = profile.ProfileName; profileResult.CodeAttendance = profile.CodeAttendance; profileResult.DateHire = profile.DateHire; profileResult.PositionName = positon != null ? positon.PositionName : string.Empty; profileResult.JobTitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty; profileResult.Email = profile.Email; profileResult.DateEndProbation = profile.DateEndProbation; profileResult.DateQuit = profile.DateQuit; if (profile.Gender == "E_FEMALE") profileResult.Gender = "Nam"; if (profile.Gender == "E_MALE") profileResult.Gender = "Nữ"; reportData.Add(profileResult); } return reportData; } reportData = profiles.Distinct().ToList().Translate<Att_ProfileEntity>(); } // danh sach trung ca // else if (isDuplicateRoster == true) // { // var rosters = GetData<Att_RosterEntity>(lstObj, ConstantSql.hrm_att_sp_get_Roster, ref status).ToList(); // foreach (var pf in listProfile) // { // // lay ca cua nhan vien // var listWRosterPr = rosters.Where(rt => rt.ProfileID == pf.ID).ToList(); // if (listWRosterPr.Count > 0) // for (DateTime dx = DateStart.Value.Date; dx <= DateEnd; dx = dx.AddDays(1)) // { // var listWRoster = listWRosterPr.Where(s => s.ProfileID == pf.ID // && s.DateStart <= dx // && dx <= s.DateEnd // && s.Type == RosterType.E_DEFAULT.ToString() // && s.Status != RosterStatus.E_REJECTED.ToString() // && s.Status != RosterStatus.E_CANCEL.ToString() // && s.IsDelete == null).ToList(); // if (listWRoster.Count >= 2) // listWRt.AddRange(listWRoster); // } // } // var result = listWRt.OrderBy(s => s.CodeEmp).ToList(); // // return result; // } //} return reportData; } }
/// <summary> Hàm tính toán và save lại bảo hiểm của từng người theo tháng </summary> /// <param name="orgs"></param> /// <param name="monthCheck">Vd: 01/12/2014</param> /// <param name="periodInsurance">Loại tạm thời , Loại Chính Thức</param> public void AnalyzeAndSaveInsuranceByMonth(string orgs, DateTime monthCheck, string periodInsurance, string codeEmp, List<Guid> socialInsPlaceIDs,string userLogin) { /* * Goal(tính toán và save lại bảo hiểm của từng NV theo tháng và phòng ban (Tạo mới hoặc update Ins_ProfileInsuranceMonthly)) * Steps : * - Step1 : Lấy DS NV theo phòng ban và theo tháng được chọn * - Step2 : xử lý tính ra tháng bắt đầu join đóng BHXH,BHYT,BHTN * - Step3 : Set giá trị cho IsLeaveNonWorkday trong profile (cho nghỉ >=14 ngày) * - Step4 : kiểm tra xem có đóng BHXH,BHYT,BHTN * - Step5 : Tính lương và mức đóng của BHXH,BHYT,BHTN * - Step6 : Tạo mới hoặc cập nhật dữ liệu vào bảng Ins_ProfileInsuranceMonthly */ //ngày 1 tháng N var beginMonth = new DateTime(monthCheck.Year, monthCheck.Month, 1); //ngày 31 tháng N DateTime endMonth = beginMonth.AddMonths(1).AddMinutes(-1); var step = 200; monthCheck = new DateTime(monthCheck.Year, monthCheck.Month, 1); var lstProfile = new List<Hre_ProfileEntity>(); using (var context = new VnrHrmDataContext()) { #region Khai báo var status = string.Empty; var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoInsMonthly = new Ins_ProfileInsuranceMonthlyRepository(unitOfWork); var repoSalInsuranceSalary = new Sal_InsuranceSalaryRepository(unitOfWork); var repoAtt_WorkDay = new Att_WorkDayRepository(unitOfWork); var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork); var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork); var repoAtt_Roster = new Att_RosterRepository(unitOfWork); var repoHre_Profile = new Hre_ProfileRepository(unitOfWork); var repoIns_InsuranceRecord = new Ins_InsuranceRecordRepository(unitOfWork); var profileIDByCodeEmp = Guid.Empty; #endregion #region phân tích theo mã NV (từ đk tìm kiếm) if (!string.IsNullOrEmpty(codeEmp)) { var profileByCodeEmp = unitOfWork.CreateQueryable<Hre_Profile>(Guid.Empty, p => p.IsDelete == null && p.CodeEmp == codeEmp).FirstOrDefault(); if (profileByCodeEmp != null) { profileIDByCodeEmp = profileByCodeEmp.ID; } else { return; } } #endregion //lay ds ngay nghi var dayOffMonthChecks = unitOfWork.CreateQueryable<Cat_DayOff>(Guid.Empty, m => m.DateOff.Year == monthCheck.Year && m.DateOff.Month == monthCheck.Month).ToList(); #region lay hop dong theo phòng ban //List<object> contractPara = new List<object>(); //contractPara.AddRange(new object[16]); //contractPara[0] = null; //contractPara[1] = null; //contractPara[2] = orgs; //contractPara[3] = null; //contractPara[4] = null; //contractPara[5] = null; //contractPara[6] = null; //contractPara[7] = null; //contractPara[8] = null; //contractPara[9] = null; //contractPara[10] = null; //contractPara[11] = null; //contractPara[12] = null; //contractPara[13] = null; //contractPara[14] = 1; //contractPara[15] = int.MaxValue; //if (profileIDByCodeEmp != Guid.Empty) //{ // contractPara[1] = codeEmp; // contractPara[2] = null; //} //var contracts = GetData<Hre_ContractEntity>(contractPara, ConstantSql.hrm_hr_sp_get_Contract, ref status).Translate<Hre_Contract>().ToList(); var contracts = new List<Hre_Contract>(); #endregion #region Get Profiles by orgs var listObj = new List<object> { orgs, string.Empty, string.Empty }; if (profileIDByCodeEmp != Guid.Empty) { listObj[0] = null; listObj[2] = codeEmp; } if (!string.IsNullOrEmpty(codeEmp)) { lstProfile = unitOfWork.CreateQueryable<Hre_Profile>(Guid.Empty, m => m.CodeEmp == codeEmp).ToList().Translate<Hre_ProfileEntity>(); } else if (orgs != null) { var lstOrderNumberORG = orgs.Split(',').Select(s => int.Parse(s)).Distinct().ToList(); var orgObj = unitOfWork.CreateQueryable<Cat_OrgStructure>(Guid.Empty).Select(p => p.ID).ToList(); var orgStructureIDs = unitOfWork.CreateQueryable<Cat_OrgStructure>(Guid.Empty, m => lstOrderNumberORG.Contains(m.OrderNumber)).Select(m => m.ID).ToList(); lstProfile = new List<Hre_ProfileEntity>(); foreach (var orgIds in orgStructureIDs.Chunk(step)) { var profileByOrgs = unitOfWork.CreateQueryable<Hre_Profile>(Guid.Empty, m => m.OrgStructureID.HasValue && orgIds.Contains(m.OrgStructureID.Value)).ToList().Translate<Hre_ProfileEntity>(); lstProfile.AddRange(profileByOrgs); } } #endregion if (socialInsPlaceIDs != null) { socialInsPlaceIDs = socialInsPlaceIDs.Where(p => p != null && p != Guid.Empty).ToList(); if (socialInsPlaceIDs != null && socialInsPlaceIDs.Any()) { lstProfile = lstProfile.Where(p => socialInsPlaceIDs != null && socialInsPlaceIDs.Count > 0 && socialInsPlaceIDs.Contains(p.SocialInsPlaceID ?? Guid.Empty)).ToList(); } } #region lay ds inusuranceSalary by profile list //ds profileId theo phong ban List<Guid> lstProfileIDs = lstProfile.Select(m => m.ID).ToList(); var lstInsuranceSalaryByProfile = new List<Sal_InsuranceSalary>(); foreach (var profileIds in lstProfileIDs.Chunk(step)) { var lstInsuranceSalaryByProfileTemp = unitOfWork.CreateQueryable<Sal_InsuranceSalary>(Guid.Empty, m => m.InsuranceAmount != null && m.ProfileID != null && m.DateEffect <= endMonth && profileIds.Contains(m.ProfileID.Value)).ToList(); lstInsuranceSalaryByProfile.AddRange(lstInsuranceSalaryByProfileTemp); var contractTemp = unitOfWork.CreateQueryable<Hre_Contract>(Guid.Empty, m => profileIds.Contains(m.ProfileID)).ToList(); contracts.AddRange(contractTemp); } if (lstInsuranceSalaryByProfile.Any()) { lstProfileIDs = lstInsuranceSalaryByProfile.Select(p => p.ProfileID ?? Guid.Empty).ToList(); lstProfile = lstProfile.Where(p => lstProfileIDs.Contains(p.ID)).ToList(); } #endregion #region ds NV đóng Bảo Hiểm theo phòng ban và tháng (Ins_ProfileInsuranceMonthly) var listInsMonthlyObj = new List<object> { orgs, monthCheck, null, 1, int.MaxValue - 1 }; if (Common.UseDataBaseName == DATABASETYPE.SQLSERVER.ToString()) { listInsMonthlyObj.Add("id"); } var lstProfileInsuranceMonthlyInDb = GetData<Ins_ProfileInsuranceMonthlyEntity>(listInsMonthlyObj, ConstantSql.hrm_ins_sp_get_ProfileInsMonthly,userLogin, ref status).Translate<Ins_ProfileInsuranceMonthly>(); // lstProfileInsuranceMonthlyInDb = lstProfileInsuranceMonthlyInDb.Where(m => m.PaybackID == null ).ToList(); #endregion #region Tháng bắt đầu tham gia bảo hiểm SetMonthJoinInsuranceByProfile(lstProfile, lstInsuranceSalaryByProfile, endMonth); #endregion #region Kiem tra co dong bao hiem ko? //Kiểm tra xem co đóng BHXH,BHYT,BHTN SetIsHaveInsurnceByProfileByMonth(lstProfile, monthCheck, contracts,userLogin); if (lstProfile.Any()) { lstProfileIDs = lstProfile.Select(p => p.ID).ToList(); } #endregion #region Nghỉ 14 ngày List<Hre_ProfileEntity> lstProfileEntities = new List<Hre_ProfileEntity>(); List<string> lstLeaveInsuranceType = String.Join(",", leaveDayInsuranceTypes).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (HasLeaveGreater14day) { string E_APPROVE = HDTJobStatus.E_APPROVE.ToString(); var lstProfilesIdChunks = lstProfileIDs; var leaveDayTypeIDs = unitOfWork.CreateQueryable<Cat_LeaveDayType>(Guid.Empty, m => m.PaidRate == 0 || lstLeaveInsuranceType.Contains(m.InsuranceType)).Select(m => m.ID).ToList(); foreach (var profileIDs in lstProfilesIdChunks.Chunk(step)) { var lstProfileEntitiesTemp = lstProfile.Where(p => profileIDs.Contains(p.ID)).ToList(); #region workday từ 1->31 tháng N theo các NV (không có quẹt thẻ) var lstWorkday = unitOfWork.CreateQueryable<Att_Workday>(Guid.Empty, m => m.InTime1 == null && m.OutTime1 == null && m.WorkDate >= beginMonth && m.WorkDate <= endMonth && profileIDs.Contains(m.ProfileID)).Select(m => new CustomWorkDayEntity() { ProfileID = m.ProfileID, InTime1 = m.InTime1, OutTime1 = m.OutTime1, WorkDate = m.WorkDate }).ToList(); #endregion #region Leaveday (ngày nghỉ trong khoảng 1->31 tháng N) theo NV string app = LeaveDayStatus.E_APPROVED.ToString(); var lstLeaveDay = unitOfWork.CreateQueryable<Att_LeaveDay>(Guid.Empty, m => m.Status == app && m.DateStart <= endMonth && m.DateEnd >= beginMonth && profileIDs.Contains(m.ProfileID)) .Select(m => new CustomLeavedayEntity() { ProfileID = m.ProfileID, DateStart = m.DateStart, DateEnd = m.DateEnd, LeaveDayTypeID = m.LeaveDayTypeID }).ToList(); #endregion //paidrate = 0 :ko tra luong var lstLeavedayTypeRateZero = unitOfWork.CreateQueryable<Cat_LeaveDayType>(Guid.Empty, p => p.PaidRate == 0).ToList(); #region lấy ds chứng từ bảo hiểm var insRecords = unitOfWork.CreateQueryable<Ins_InsuranceRecord>(Guid.Empty, m => m.DateStart != null && m.DateEnd != null && m.DateStart <= endMonth && m.DateEnd >= beginMonth && profileIDs.Contains(m.ProfileID)) .Select(m => new CustomInsuranceRecordEntity() { ProfileID = m.ProfileID, DateStart = m.DateStart.Value, DateEnd = m.DateEnd.Value, InsuranceType = m.InsuranceType }).ToList(); #endregion var approved = RosterStatus.E_APPROVED.ToString(); var rosters = unitOfWork.CreateQueryable<Att_Roster>(Guid.Empty, p => p.Status == approved && (p.DateStart <= endMonth && p.DateEnd >= beginMonth) && profileIDs.Contains(p.ProfileID)) .Select(m => new CustomRosterEntity() { ProfileID = m.ProfileID, DateStart = m.DateStart, DateEnd = m.DateEnd, MonShiftID = m.MonShiftID, TueShiftID = m.TueShiftID, WedShiftID = m.WedShiftID, ThuShiftID = m.ThuShiftID, FriShiftID = m.FriShiftID, SatShiftID = m.SatShiftID, SunShiftID = m.SunShift2ID }) .ToList(); //kt co nghỉ hơn 14 ngay ko? SetLeaveNonWorkdayByProfile(lstProfileEntitiesTemp, beginMonth, endMonth, lstWorkday, lstLeaveDay, lstLeavedayTypeRateZero, insRecords, rosters, dayOffMonthChecks); //Hàm do Triet.Mai Hỗ trợ. tính ra số ngày không làm HDTJOb // "SC, SU, SM, SD, DP, D, M, AL, TSC,TAS" lstLeaveDay = lstLeaveDay.Where(m => m.LeaveDayTypeID != null && leaveDayTypeIDs.Contains(m.LeaveDayTypeID.Value)).ToList(); var lstHDTJob = unitOfWork.CreateQueryable<Hre_HDTJob>(Guid.Empty, m => m.Status == E_APPROVE && m.DateFrom <= endMonth && m.DateTo >= beginMonth && m.ProfileID.HasValue && profileIDs.Contains(m.ProfileID.Value)).ToList(); GetHDTJobDayByProfile(lstProfileEntitiesTemp, leaveDayTypeIDs, monthCheck, rosters, lstLeaveDay, lstHDTJob); lstProfileEntities.AddRange(lstProfileEntitiesTemp); } } lstProfile = lstProfileEntities; #endregion #region tính lương , mức đóng BHXH,BHYT,BHTN SetMoneyInsuranceByProfileByMonth(lstProfile, lstInsuranceSalaryByProfile, endMonth, orgs, contracts,userLogin); #endregion #region Save Change var lstProfileInsuranceMonthlyAddNew = new List<Ins_ProfileInsuranceMonthly>(); var lstProfileInsuranceMonthlyModify = new List<Ins_ProfileInsuranceMonthly>(); foreach (var profile in lstProfile) { if (lstProfileInsuranceMonthlyInDb.Where(m => m.ProfileID == profile.ID && m.PaybackID != null).FirstOrDefault() != null) { continue; } Ins_ProfileInsuranceMonthly insuranceByProfile = lstProfileInsuranceMonthlyInDb .FirstOrDefault(m => m.ProfileID == profile.ID && m.PaybackID == null); if (insuranceByProfile != null) //Update cái dữ liệu cũ { insuranceByProfile.WorkPlaceID = profile.WorkPlaceID; insuranceByProfile.SocialInsPlaceID = profile.SocialInsPlaceID; insuranceByProfile.IsSocialInsurance = profile.IsHaveInsSocial; insuranceByProfile.IsHealthInsurance = profile.IsHaveInsHealth; insuranceByProfile.IsUnEmpInsurance = profile.IsHaveInsUnEmp; insuranceByProfile.IsPregnant = profile.IsPregnant; insuranceByProfile.MoneySocialInsurance = profile.MoneyInsuranceSocial; insuranceByProfile.MoneyHealthInsurance = profile.MoneyInsuranceHealth; insuranceByProfile.MoneyUnEmpInsurance = profile.MoneyInsuranceUnEmp; insuranceByProfile.SalaryInsurance = profile.MoneyInsuranceTotal; insuranceByProfile.SalaryHealthInsurance = profile.MoneyInsuranceHealthTotal; insuranceByProfile.SalaryUnEmpInsurance = profile.MoneyInsuranceUnEmpTotal; insuranceByProfile.IsDecreaseWorkingDays = profile.IsDecreaseWorkingDays; insuranceByProfile.JobName = profile.JobName; insuranceByProfile.AmountHDTIns = profile.AmountHDTIns; insuranceByProfile.HDTGroupCode = profile.HDTJobGroupCode; insuranceByProfile.TypeGetData = periodInsurance; #region Tung.Ly set các tỉ lệ và mức đóng insuranceByProfile.Allowance1 = profile.Allowance1; insuranceByProfile.Allowance2 = profile.Allowance2; insuranceByProfile.Allowance3 = profile.Allowance3; insuranceByProfile.Allowance4 = profile.Allowance4; insuranceByProfile.AmountChargeIns = profile.AmountChargeIns; insuranceByProfile.SocialInsComRate = profile.SocialInsComRate; insuranceByProfile.SocialInsComAmount = profile.SocialInsComAmount; insuranceByProfile.SocialInsEmpRate = profile.SocialInsEmpRate; insuranceByProfile.SocialInsEmpAmount = profile.SocialInsEmpAmount; insuranceByProfile.HealthInsComRate = profile.HealthInsComRate; insuranceByProfile.HealthInsComAmount = profile.HealthInsComAmount; insuranceByProfile.HealthInsEmpRate = profile.HealthInsEmpRate; insuranceByProfile.HealthInsEmpAmount = profile.HealthInsEmpAmount; insuranceByProfile.UnemployComRate = profile.UnemployComRate; insuranceByProfile.UnemployComAmount = profile.UnemployComAmount; insuranceByProfile.UnemployEmpRate = profile.UnemployEmpRate; insuranceByProfile.UnemployEmpAmount = profile.UnemployEmpAmount; insuranceByProfile.IsPayback = false; insuranceByProfile.MonthYearEffect = monthCheck; #endregion lstProfileInsuranceMonthlyModify.Add(insuranceByProfile);//add vao list (Modify) } else //Tạo mới { var newInsurance = new Ins_ProfileInsuranceMonthly { ProfileID = profile.ID, WorkPlaceID = profile.WorkPlaceID, SocialInsPlaceID = profile.SocialInsPlaceID, IsSocialInsurance = profile.IsHaveInsSocial, IsHealthInsurance = profile.IsHaveInsHealth, IsUnEmpInsurance = profile.IsHaveInsUnEmp, IsPregnant = profile.IsPregnant, MoneySocialInsurance = profile.MoneyInsuranceSocial, MoneyHealthInsurance = profile.MoneyInsuranceHealth, MoneyUnEmpInsurance = profile.MoneyInsuranceUnEmp, IsDecreaseWorkingDays = profile.IsDecreaseWorkingDays, SalaryInsurance = profile.MoneyInsuranceTotal, AmountHDTIns = profile.AmountHDTIns, HDTGroupCode = profile.HDTJobGroupCode, SalaryHealthInsurance = profile.MoneyInsuranceHealthTotal, SalaryUnEmpInsurance = profile.MoneyInsuranceUnEmpTotal, TypeGetData = periodInsurance, MonthYear = monthCheck, IsPayback = false, MonthYearEffect = monthCheck, #region Tung.Ly set các tỉ lệ và mức đóng Allowance1 = profile.Allowance1, Allowance2 = profile.Allowance2, Allowance3 = profile.Allowance3, Allowance4 = profile.Allowance4, AmountChargeIns = profile.AmountChargeIns, SocialInsComRate = profile.SocialInsComRate, SocialInsComAmount = profile.SocialInsComAmount, SocialInsEmpRate = profile.SocialInsEmpRate, SocialInsEmpAmount = profile.SocialInsEmpAmount, HealthInsComRate = profile.HealthInsComRate, HealthInsComAmount = profile.HealthInsComAmount, HealthInsEmpRate = profile.HealthInsEmpRate, HealthInsEmpAmount = profile.HealthInsEmpAmount, UnemployComRate = profile.UnemployComRate, UnemployComAmount = profile.UnemployComAmount, UnemployEmpRate = profile.UnemployEmpRate, UnemployEmpAmount = profile.UnemployEmpAmount, JobName = profile.JobName, #endregion }; lstProfileInsuranceMonthlyAddNew.Add(newInsurance);//add new } } if (lstProfileInsuranceMonthlyAddNew.Any()) { repoInsMonthly.Add(lstProfileInsuranceMonthlyAddNew); } if (lstProfileInsuranceMonthlyModify.Any()) { repoInsMonthly.Edit(lstProfileInsuranceMonthlyModify); } repoInsMonthly.SaveChanges(); #endregion } }