public static Att_TimeOffInLieu AddTimeOffInLieu(Att_LeaveDay leaveDay) { Att_TimeOffInLieu timeOffInLieu = null; if (leaveDay.ID != Guid.Empty) { Hre_Profile profile = leaveDay.Hre_Profile; timeOffInLieu = new Att_TimeOffInLieu(); //double HourOnWorkDate = 8; //Sal_Grade grade = GradeDAO.GetGrade(profile, leaveDay.DateStart, context, userid); //if (grade != null) //{ // Cat_GradeCfg gradecfg = grade.Cat_GradeCfg; // HourOnWorkDate = gradecfg.HourOnWorkDate == null ? 8 : gradecfg.HourOnWorkDate.Value; //} double ApproveHour; if (leaveDay.DurationType == LeaveDayDurationType.E_FULLSHIFT.ToString()) { ApproveHour = leaveDay.LeaveDays.Value * leaveDay.LeaveHours.Value; } else { ApproveHour = leaveDay.LeaveHours.Value; } double HourTimeOffInLieu = ApproveHour; double accumulateLeaves = Att_LeavedayServices.getAccumulateLeaves(profile.ID); double RemainLeaves = accumulateLeaves - HourTimeOffInLieu; timeOffInLieu.AccumulateLeaves = accumulateLeaves; timeOffInLieu.UnusualLeaves = 0; timeOffInLieu.TakenLeaves = HourTimeOffInLieu; timeOffInLieu.RemainLeaves = RemainLeaves; timeOffInLieu.Date = leaveDay.DateStart; if (leaveDay.DateApprove != null) timeOffInLieu.DateApprove = leaveDay.DateApprove.Value; // so gio quy ra tien = 0 timeOffInLieu.ConvertedCashHours = 0; timeOffInLieu.Att_LeaveDay = leaveDay; timeOffInLieu.Hre_Profile = profile; //timeOffInLieu.DateCreate = DateTime.Now; } return timeOffInLieu; }
private string SaveLeaveDay(List<Att_Overtime> lstAttOvertimeInput, DateTime? date1, DateTime? date2) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_Workday = new CustomBaseRepository<Att_Workday>(unitOfWork); var repoCat_LeaveDayType = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork); var repoCat_Shift = new CustomBaseRepository<Cat_Shift>(unitOfWork); var repoAtt_LeaveDay = new CustomBaseRepository<Att_LeaveDay>(unitOfWork); var repoAtt_TimeOffInLieu = new CustomBaseRepository<Att_TimeOffInLieu>(unitOfWork); string E_TIMEOFF = MethodOption.E_TIMEOFF.ToString(); List<Att_Overtime> lstAttOvertime = lstAttOvertimeInput.Where(m => m.MethodPayment == E_TIMEOFF && m.WorkDateRoot != null).ToList(); //string validate string Validate = validateSaveLeaveDay(lstAttOvertime, date1, date2); if (Validate != string.Empty) { return Validate; } List<Guid> lstProfileIDs = lstAttOvertime.Select(m => m.ProfileID).Distinct().ToList(); var LstWorkday1 = new List<Att_Workday>().Select(m => new { m.ProfileID, m.WorkDate, m.ShiftApprove, m.ShiftID }); var LstWorkday2 = new List<Att_Workday>().Select(m => new { m.ProfileID, m.WorkDate, m.ShiftApprove, m.ShiftID }); if (date1 != null) { LstWorkday1 = repoAtt_Workday.FindBy(m => m.WorkDate == date1.Value && lstProfileIDs.Contains(m.ProfileID)) .Select(m => new { m.ProfileID, m.WorkDate, m.ShiftApprove, m.ShiftID }); } if (date2 != null) { LstWorkday2 = repoAtt_Workday.FindBy(m => m.WorkDate == date2.Value && lstProfileIDs.Contains(m.ProfileID)) .Select(m => new { m.ProfileID, m.WorkDate, m.ShiftApprove, m.ShiftID }); } List<Att_LeaveDay> lstLeaveDayInsert = new List<Att_LeaveDay>(); Guid OvertimeTypeTimeOffID = repoCat_LeaveDayType.FindBy(m => m.IsTimeOffInLieu == true).Select(m => m.ID).FirstOrDefault(); if (OvertimeTypeTimeOffID == null || OvertimeTypeTimeOffID == Guid.Empty) return string.Empty; var lstShift = repoCat_Shift.GetAll().Select(m => new { m.ID, m.WorkHours }); foreach (var item in lstAttOvertime) { if (date1 != null) { Att_LeaveDay leaveDay = new Att_LeaveDay(); leaveDay.ID = Guid.Empty; leaveDay.ProfileID = item.ProfileID; leaveDay.LeaveDayTypeID = OvertimeTypeTimeOffID; leaveDay.DateStart = date1.Value; leaveDay.DateEnd = date1.Value; leaveDay.TotalDuration = 1; leaveDay.LeaveDays = 1; leaveDay.Att_Overtime = item; if (item.Status == OverTimeStatus.E_WAIT_APPROVED.ToString()) leaveDay.Status = LeaveDayStatus.E_WAIT_APPROVED.ToString(); else if (item.Status == OverTimeStatus.E_APPROVED.ToString()) { leaveDay.Status = LeaveDayStatus.E_APPROVED.ToString(); } else if (item.Status == OverTimeStatus.E_CONFIRM.ToString()) { leaveDay.Status = LeaveDayStatus.E_APPROVED.ToString(); } else { leaveDay.Status = LeaveDayStatus.E_SUBMIT.ToString(); } var workday = LstWorkday1.Where(m => m.ProfileID == item.ProfileID && m.WorkDate == date1.Value).FirstOrDefault(); if (workday != null) { Guid? ShiftID = workday.ShiftApprove ?? workday.ShiftID; if (ShiftID != null) { var shift = lstShift.Where(m => m.ID == ShiftID).FirstOrDefault(); if (shift != null) { leaveDay.LeaveHours = shift.WorkHours ?? 0; } } } if (leaveDay.LeaveHours == null || leaveDay.LeaveHours == 0) { leaveDay.LeaveHours = 8; } lstLeaveDayInsert.Add(leaveDay); } if (date2 != null) { Att_LeaveDay leaveDay = new Att_LeaveDay(); leaveDay.ID = Guid.Empty; leaveDay.ProfileID = item.ProfileID; leaveDay.LeaveDayTypeID = OvertimeTypeTimeOffID; leaveDay.DateStart = date2.Value; leaveDay.DateEnd = date2.Value; leaveDay.TotalDuration = 1; leaveDay.LeaveDays = 1; leaveDay.Att_Overtime = item; if (item.Status == OverTimeStatus.E_WAIT_APPROVED.ToString()) leaveDay.Status = LeaveDayStatus.E_WAIT_APPROVED.ToString(); else if (item.Status == OverTimeStatus.E_APPROVED.ToString()) { leaveDay.Status = LeaveDayStatus.E_APPROVED.ToString(); } else if (item.Status == OverTimeStatus.E_CONFIRM.ToString()) { leaveDay.Status = LeaveDayStatus.E_APPROVED.ToString(); } else { leaveDay.Status = LeaveDayStatus.E_SUBMIT.ToString(); } var workday = LstWorkday2.Where(m => m.ProfileID == item.ProfileID && m.WorkDate == date2.Value).FirstOrDefault(); if (workday != null) { Guid? ShiftID = workday.ShiftApprove ?? workday.ShiftID; if (ShiftID != null) { var shift = lstShift.Where(m => m.ID == ShiftID).FirstOrDefault(); if (shift != null) { leaveDay.LeaveHours = shift.WorkHours ?? 0; } } } if (leaveDay.LeaveHours == null || leaveDay.LeaveHours == 0) { leaveDay.LeaveHours = 8; } lstLeaveDayInsert.Add(leaveDay); } } if (lstLeaveDayInsert.Count > 0) { repoAtt_LeaveDay.Add(lstLeaveDayInsert); //EntityService.AddEntity<Att_LeaveDay>(GuidContext, lstLeaveDayInsert.ToArray()); } List<Att_TimeOffInLieu> lstTimeoffInlieu = new List<Att_TimeOffInLieu>(); foreach (var item in lstLeaveDayInsert) { if (item.Status == LeaveDayStatus.E_APPROVED.ToString()) { Att_TimeOffInLieu timeOffLieu = AddTimeOffInLieu(item); if (timeOffLieu != null) lstTimeoffInlieu.Add(timeOffLieu); } } if (lstTimeoffInlieu.Count > 0) { repoAtt_TimeOffInLieu.Add(lstTimeoffInlieu); //EntityService.AddEntity<Att_TimeOffInLieu>(GuidContext, lstTimeoffInlieu.ToArray()); } return string.Empty; } }
public String SaveLeaveDataItem(Guid workDayID, Guid LeaveTypeID, Guid? userApprove, string comment, bool IsAllowModify) { var message = ""; using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_LeaveDay = new CustomBaseRepository<Att_LeaveDay>(unitOfWork); var repoCat_LeaveDayType = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork); var repoCat_Shift = new CustomBaseRepository<Cat_Shift>(unitOfWork); var repoAtt_Workday = new CustomBaseRepository<Att_Workday>(unitOfWork); var repoSys_AllSeting = new CustomBaseRepository<Sys_AllSetting>(unitOfWork); var repoHre_Profile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork); var repoCat_GradeAttendance = new CustomBaseRepository<Cat_GradeAttendance>(unitOfWork); var repoHre_WorkHistory = new CustomBaseRepository<Hre_WorkHistory>(unitOfWork); var repoCat_DayOff = new CustomBaseRepository<Cat_DayOff>(unitOfWork); var repoAtt_Roster = new CustomBaseRepository<Att_Roster>(unitOfWork); var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList(); Att_WorkdayEntity WorkDayInDB = repoAtt_Workday.FindBy(m => m.ID == workDayID).FirstOrDefault().CopyData<Att_WorkdayEntity>(); if (WorkDayInDB == null || LeaveTypeID == Guid.Empty) { //return WorkDayInDB.CopyData<Att_WorkdayEntity>(); message = ConstantMessages.PlsSelectLeaveType.TranslateString(); return message; } #region [Hien.Nguyen] - Nếu ngày đó đã có loại ngày nghỉ này rồi thì out function var tmp = repoAtt_LeaveDay.FindBy(m => m.IsDelete == null && m.ProfileID == WorkDayInDB.ProfileID && m.LeaveDayTypeID == LeaveTypeID && m.DateStart <= WorkDayInDB.WorkDate && m.DateEnd >= WorkDayInDB.WorkDate).FirstOrDefault(); if (tmp != null) { message = "Đã Có Ngày Nghỉ"; return message; //return WorkDayInDB.CopyData<Att_WorkdayEntity>(); } #endregion Cat_Shift shift = repoCat_Shift.FindBy(m => m.ID == WorkDayInDB.ShiftID).FirstOrDefault(); if (shift == null) { //return WorkDayInDB.CopyData<Att_WorkdayEntity>(); message = ConstantMessages.Error.TranslateString(); return message; } var leaveType = repoCat_LeaveDayType.FindBy(m => m.ID == LeaveTypeID).Select(m => new { m.Code, m.CodeStatistic }).FirstOrDefault(); var leaveTypeCode = string.Empty; if (leaveType != null) { leaveTypeCode = leaveType.CodeStatistic ?? leaveType.Code; } DateTime workday = WorkDayInDB.WorkDate; DateTime beginDate = workday.Date; DateTime endDate = beginDate.AddDays(1).AddMinutes(-1); DateTime beginShift = workday.AddHours(shift.InTime.Hour).AddMinutes(shift.InTime.Minute); DateTime endShift = beginShift.AddHours(shift.CoOut); List<Att_LeaveDay> lstLeaveDayInDbUpdate = repoAtt_LeaveDay.FindBy(m => m.DateStart <= endDate && m.DateEnd >= beginDate && m.ProfileID == WorkDayInDB.ProfileID).ToList<Att_LeaveDay>(); List<Att_LeaveDay> lstLeaveDayInsert = new List<Att_LeaveDay>(); if (WorkDayInDB.InTime1 == null || WorkDayInDB.OutTime1 == null) //Thiếu 1 trong 2 la tao nghi full ca { if (IsAllowModify && lstLeaveDayInDbUpdate.Count > 0 && !lstLeaveDayInDbUpdate.Any(m => m.Status == LeaveDayStatus.E_APPROVED.ToString())) { lstLeaveDayInDbUpdate.ForEach(m => m.LeaveDayTypeID = LeaveTypeID); } else { Att_LeaveDay LeavedayInsert = new Att_LeaveDay(); LeavedayInsert.ID = Guid.NewGuid(); LeavedayInsert.ProfileID = WorkDayInDB.ProfileID; LeavedayInsert.TotalDuration = 1; LeavedayInsert.LeaveDays = 1; LeavedayInsert.Duration = shift.WorkHours ?? 8; LeavedayInsert.LeaveHours = shift.WorkHours ?? 8; LeavedayInsert.DurationType = LeaveDayDurationType.E_FULLSHIFT.ToString(); LeavedayInsert.DateStart = workday; LeavedayInsert.DateEnd = workday; LeavedayInsert.LeaveDayTypeID = LeaveTypeID; LeavedayInsert.Status = LeaveDayStatus.E_SUBMIT.ToString(); lstLeaveDayInsert.Add(LeavedayInsert); } } else // thuộc loại trễ sớm { if (IsAllowModify && lstLeaveDayInDbUpdate.Count > 0 && !lstLeaveDayInDbUpdate.Any(m => m.Status == LeaveDayStatus.E_APPROVED.ToString())) { lstLeaveDayInDbUpdate.ForEach(m => m.LeaveDayTypeID = LeaveTypeID); } else { if (WorkDayInDB.LateDuration1 != null && WorkDayInDB.LateDuration1 > 0) //đi trễ { double HourLeave = (int)(WorkDayInDB.LateDuration1 ?? 0) / 60; if (((WorkDayInDB.LateDuration1 ?? 0) % 60) > 0) HourLeave = HourLeave + 1; //di trễ thì loại của no la nua ca dau Att_LeaveDay LeavedayInsert = new Att_LeaveDay(); LeavedayInsert.ID = Guid.NewGuid(); LeavedayInsert.ProfileID = WorkDayInDB.ProfileID; LeavedayInsert.TotalDuration = 1; LeavedayInsert.LeaveDays = 1; LeavedayInsert.Duration = HourLeave; LeavedayInsert.LeaveHours = HourLeave; LeavedayInsert.DurationType = LeaveDayDurationType.E_FIRSTHALFSHIFT.ToString(); LeavedayInsert.DateStart = beginShift; LeavedayInsert.DateEnd = beginShift.AddHours(HourLeave); LeavedayInsert.LeaveDayTypeID = LeaveTypeID; LeavedayInsert.Status = LeaveDayStatus.E_SUBMIT.ToString(); lstLeaveDayInsert.Add(LeavedayInsert); } else if (WorkDayInDB.EarlyDuration1 != null && WorkDayInDB.EarlyDuration1 > 0) //Về sớm { //về sơm thi loại cua no la nua ca sau double HourLeave = (int)(WorkDayInDB.EarlyDuration1 ?? 0) / 60; if (((WorkDayInDB.EarlyDuration1 ?? 0) % 60) > 0) HourLeave = HourLeave + 1; //di trễ thì loại của no la nua ca sai Att_LeaveDay LeavedayInsert = new Att_LeaveDay(); LeavedayInsert.ID = Guid.NewGuid(); LeavedayInsert.ProfileID = WorkDayInDB.ProfileID; LeavedayInsert.TotalDuration = 1; LeavedayInsert.LeaveDays = 1; LeavedayInsert.Duration = HourLeave; LeavedayInsert.LeaveHours = HourLeave; LeavedayInsert.DurationType = LeaveDayDurationType.E_FIRSTHALFSHIFT.ToString(); LeavedayInsert.DateStart = endShift.AddHours(-HourLeave); LeavedayInsert.DateEnd = endShift; LeavedayInsert.LeaveDayTypeID = LeaveTypeID; LeavedayInsert.Status = LeaveDayStatus.E_SUBMIT.ToString(); lstLeaveDayInsert.Add(LeavedayInsert); } } } foreach (var item in lstLeaveDayInsert) { if (userApprove != null) { item.UserApproveID = userApprove.Value; } item.Comment = comment; } #region Triet.Mai Validate Nghỉ Bù if (lstLeaveDayInsert.Count > 0) { List<Guid> LeaveTypeDayOffID = repoCat_LeaveDayType.FindBy(m => m.IsTimeOffInLieu == true).Select(m => m.ID).ToList<Guid>(); if (lstLeaveDayInsert.FirstOrDefault().Status != OverTimeStatus.E_CANCEL.ToString() && LeaveTypeDayOffID.Any(m => m == lstLeaveDayInsert.FirstOrDefault().LeaveDayTypeID)) { message = ValidateLeaveDayTimeOff(lstLeaveDayInsert.Select(m => m.ProfileID).Distinct().ToList(), lstLeaveDayInsert); if (message != string.Empty) { //ErrorMessages = Error; return message; } } } #endregion #region triet.mai validate vấn đề ngày nghỉ dành cho nhân viên thực tập string HRM_ATT_STAFF_PROBATION = AppConfig.HRM_ATT_STAFF_PROBATION.ToString(); Sys_AllSetting config = repoSys_AllSeting.FindBy(m => m.Name == HRM_ATT_STAFF_PROBATION).FirstOrDefault(); string validateEmpProbation = ValidateLeaveTypeByNewEmployee(config, lstLeaveDayInsert); if (validateEmpProbation != string.Empty) { //ErrorMessages = validateEmpProbation; return null; } #endregion //Cap nhat leavedayID cho workday o day if (lstLeaveDayInsert.Count > 0) { if (lstLeaveDayInsert.Count > 1) { WorkDayInDB.LeaveDayID1 = lstLeaveDayInsert[0].ID; WorkDayInDB.LeaveDayID2 = lstLeaveDayInsert[1].ID; WorkDayInDB.udLeavedayCode1 = leaveTypeCode; WorkDayInDB.udLeavedayCode2 = leaveTypeCode; WorkDayInDB.udLeavedayStatus1 = lstLeaveDayInsert.FirstOrDefault().Status; WorkDayInDB.udLeavedayStatus2 = lstLeaveDayInsert.FirstOrDefault().Status; } else { WorkDayInDB.LeaveDayID1 = lstLeaveDayInsert[0].ID; WorkDayInDB.udLeavedayCode1 = leaveTypeCode; WorkDayInDB.udLeavedayStatus1 = lstLeaveDayInsert.FirstOrDefault().Status; } } else if (lstLeaveDayInDbUpdate.Count > 0) { if (lstLeaveDayInDbUpdate.Count >= 2) { WorkDayInDB.udLeavedayCode1 = leaveTypeCode; WorkDayInDB.udLeavedayCode2 = leaveTypeCode; WorkDayInDB.udLeavedayStatus1 = lstLeaveDayInDbUpdate.FirstOrDefault().Status; WorkDayInDB.udLeavedayStatus2 = lstLeaveDayInDbUpdate.FirstOrDefault().Status; } else { WorkDayInDB.udLeavedayCode1 = leaveTypeCode; WorkDayInDB.udLeavedayStatus1 = lstLeaveDayInDbUpdate.FirstOrDefault().Status; WorkDayInDB.udLeavedayStatus2 = lstLeaveDayInDbUpdate.FirstOrDefault().Status; } } #region triet.mai cap nhat leaveDays va leaveHours List<Cat_LeaveDayType> lstLeaveDayType = repoCat_LeaveDayType.GetAll().ToList<Cat_LeaveDayType>(); List<Guid> lstProfileID1 = lstLeaveDayInsert.Select(m => m.ProfileID).Distinct().ToList<Guid>(); List<Hre_Profile> lstProfile = repoHre_Profile.FindBy(m => lstProfileID1.Contains(m.ID)).ToList<Hre_Profile>(); DateTime dateMin1 = lstLeaveDayInsert.Min(m => m.DateStart).Date; DateTime dateMax1 = lstLeaveDayInsert.Max(m => m.DateEnd); List<Att_Roster> lstRosterTypeGroup = new List<Att_Roster>(); List<Att_RosterGroup> lstRosterGroup = new List<Att_RosterGroup>(); var lstGrade = repoAtt_Grade.FindBy(m => lstProfileID1.Contains((Guid)m.ProfileID)) .Select(m => new { m.ID, m.ProfileID, m.MonthStart, m.GradeAttendanceID }) .OrderByDescending(m => m.MonthStart) .ToList(); List<Cat_GradeAttendance> lstGradeCfg = repoCat_GradeAttendance.GetAll().ToList<Cat_GradeAttendance>(); List<Hre_WorkHistory> listWorkHistory = repoHre_WorkHistory.FindBy(m => m.DateEffective <= dateMax1 && lstProfileID1.Contains(m.ProfileID)).OrderByDescending(m => m.DateEffective).ToList<Hre_WorkHistory>(); GetRosterGroup(lstProfileID1, dateMin1, dateMax1, out lstRosterTypeGroup, out lstRosterGroup); List<Cat_DayOff> lstHoliday = repoCat_DayOff.GetAll().ToList(); string E_APPROVED1 = RosterStatus.E_APPROVED.ToString(); string E_ROSTERGROUP = RosterType.E_ROSTERGROUP.ToString(); List<Att_Roster> lstRoster = repoAtt_Roster.FindBy(m => m.Status == E_APPROVED1 && m.DateStart <= dateMax1 && m.DateEnd >= dateMin1 && lstProfileID1.Contains(m.ProfileID)).ToList<Att_Roster>(); List<DateTime> lstHolidayType = lstHoliday.Select(m => m.DateOff).ToList<DateTime>(); //LeaveDayDAO ldDao = new LeaveDayDAO(); foreach (var item in lstLeaveDayInsert) { if (item.DurationType != null && item.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()) continue; Cat_LeaveDayType leaveDayType = lstLeaveDayType.Where(m => m.ID == item.LeaveDayTypeID).FirstOrDefault(); if (leaveDayType == null) continue; Hre_Profile profileInLeave = lstProfile.Where(m => m.ID == item.ProfileID).FirstOrDefault(); if (profileInLeave == null) continue; DateTime dateFrom = item.DateStart; DateTime dateTo = item.DateEnd; dateTo = dateTo.AddDays(1).AddMinutes(-1); Guid GradeCfgID = lstGrade.Where(m => m.ProfileID.Value == profileInLeave.ID && m.MonthStart <= dateTo).Select(m => m.GradeAttendanceID.Value).FirstOrDefault(); Cat_GradeAttendance gradeCfg = lstGradeCfg.Where(m => m.ID == GradeCfgID).FirstOrDefault(); List<Att_Roster> lstRosterByProfile = lstRoster.Where(m => m.ProfileID == profileInLeave.ID).ToList(); List<Hre_WorkHistory> listWorkHistoryByProfile = listWorkHistory.Where(m => m.ProfileID == profileInLeave.ID && m.DateEffective < dateTo).ToList(); List<Att_Roster> lstRosterByProfileTypeGroup = lstRosterByProfile.Where(m => m.Type == E_ROSTERGROUP).ToList(); AnalyseTotalLeaveDaysAndHours(item, leaveDayType, profileInLeave, gradeCfg, lstRosterByProfile, lstRosterGroup, listWorkHistoryByProfile, lstHoliday, shifts); } #endregion //var listWorkDay=repoAtt_Workday.GetAll().ToList(); //Att_Workday workdayOld = listWorkDay.Where(m => m.ProfileID == WorkDayInDB.ProfileID && m.WorkDate == WorkDayInDB.WorkDate).FirstOrDefault(); //if (workdayOld != null) //{ // int index = listWorkDay.IndexOf(workdayOld); // listWorkDay.Remove(workdayOld); // listWorkDay.Insert(index, WorkDayInDB.CopyData<Att_Workday>()); //} repoAtt_LeaveDay.Add(lstLeaveDayInsert); unitOfWork.SaveChanges(); //EntityService.AddEntity<Att_LeaveDay>(GuidContext, lstLeaveDayInsert.ToArray()); //message = "Susscess"; return message; //return WorkDayInDB; } }
public void AnalyseTotalLeaveDaysAndHours(Att_LeaveDay LeaveDay, Cat_LeaveDayType LeaveDayType, Hre_Profile profile, Cat_GradeAttendance gradeCfg, List<Att_Roster> lstRoster, List<Att_RosterGroup> lstRosterGroup, List<Hre_WorkHistory> listWorkHistory, List<Cat_DayOff> lstHoliday, List<Cat_Shift> lstShift) { if (LeaveDay.DurationType == null) return; #region data string LeaveDayTypeCode = string.Empty; if (LeaveDayType != null) LeaveDayTypeCode = LeaveDayType.Code; if (gradeCfg == null) return; DateTime dateFrom = LeaveDay.DateStart.Date; DateTime dateTo = LeaveDay.DateEnd; dateTo = dateTo.AddDays(1).AddMinutes(-1); string E_ROSTERGROUP = RosterType.E_ROSTERGROUP.ToString(); List<Att_Roster> lstRosterByProfile = lstRoster.Where(m => m.ProfileID == profile.ID && m.DateStart <= dateTo && m.DateEnd >= dateFrom).ToList(); List<Att_Roster> lstRosterByProfileTypeGroup = lstRosterByProfile.Where(m => m.Type == E_ROSTERGROUP).ToList(); List<Hre_WorkHistory> listWorkHistoryByProfile = listWorkHistory.Where(m => m.ProfileID == profile.ID && m.DateEffective < dateTo).ToList(); var listRosterEntity = lstRosterByProfile.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, dateFrom, dateTo, listRosterEntity, listRosterGroupEntity, lstShift); double leaveDays = 0; double leaveHours = 0; #endregion if (LeaveDay.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()) { DateTime dateLeave = LeaveDay.DateStart.Date; //Check co ca ko if (gradeCfg != null && Att_WorkDayHelper.IsWorkDay(dateLeave, gradeCfg, listMonthShifts, lstHoliday)) { if (listMonthShifts.ContainsKey(dateLeave) && listMonthShifts[dateLeave] != null && listMonthShifts[dateLeave].WorkHours != null && listMonthShifts[dateLeave].WorkHours != 0) { Cat_Shift Shift = listMonthShifts[dateLeave]; //Có ca thi lây giờ nghỉ giua ca để mà tính thời gian thực nghỉ //Nếu như trừ thời gian nghỉ ra khỏi giờ nghi trưa mà lơn hơn workhour của ca thì lấy max la workhour của ca DateTime ShiftBreakIn = dateLeave.Add(Shift.InTime.TimeOfDay).AddHours(Shift.CoBreakIn); DateTime ShiftBreakOut = dateLeave.Add(Shift.InTime.TimeOfDay).AddHours(Shift.CoBreakOut); if (LeaveDay.DateStart < ShiftBreakOut && LeaveDay.DateEnd > ShiftBreakIn) { //neu co long nhau if (ShiftBreakIn > LeaveDay.DateStart) leaveHours = (ShiftBreakIn - LeaveDay.DateStart).TotalHours; if (LeaveDay.DateEnd > ShiftBreakOut) leaveHours += (LeaveDay.DateEnd - ShiftBreakOut).TotalHours; leaveDays = leaveHours / Shift.WorkHours ?? 8; } else { leaveHours = (LeaveDay.DateEnd - LeaveDay.DateStart).TotalHours; leaveDays = leaveHours / Shift.WorkHours ?? 8; //neu ko long nhau } } else //Ko có ca làm việc { //Nếu ko có ca thì lấy giờ out trừ giờ in leaveHours = (LeaveDay.DateEnd - LeaveDay.DateStart).TotalHours; leaveDays = leaveHours / 8; } } } else //Loại FullShift { if (LeaveDay.DurationType == null) { LeaveDay.DurationType = LeaveDayDurationType.E_FULLSHIFT.ToString(); } if (profile == null) return; bool isSetFullLeaveDay = false; if (!string.IsNullOrEmpty(LeaveDayTypeCode) && (LeaveDayTypeCode == "SICK" || LeaveDayTypeCode == "PRG" || LeaveDayTypeCode == "SU" || LeaveDayTypeCode == "SD" || LeaveDayTypeCode == "D" || LeaveDayTypeCode == "DP" || LeaveDayTypeCode == "PSN" || LeaveDayTypeCode == "M" || LeaveDayTypeCode == "DSP")) { for (DateTime idx = dateFrom; idx <= dateTo; idx = idx.AddDays(1)) { if (!lstHoliday.Any(m => m.DateOff == idx)) { leaveDays += 1; Cat_Shift ShiftByDay = null; if (listMonthShifts.ContainsKey(idx)) { ShiftByDay = listMonthShifts[idx]; } if (ShiftByDay != null) { leaveHours += ShiftByDay.WorkHours ?? 8; } else { leaveHours += 8; } } isSetFullLeaveDay = true; } } if (isSetFullLeaveDay == false) { for (DateTime idx = dateFrom; idx <= dateTo; idx = idx.AddDays(1)) { if (gradeCfg != null && Att_WorkDayHelper.IsWorkDay(idx, gradeCfg, listMonthShifts, lstHoliday)) { leaveDays += 1; Cat_Shift ShiftByDay = null; if (listMonthShifts.ContainsKey(idx)) { ShiftByDay = listMonthShifts[idx]; } if (ShiftByDay != null) { leaveHours += ShiftByDay.WorkHours ?? 8; } } } } } if (LeaveDay.LeaveDays == null || LeaveDay.LeaveDays != leaveDays) { LeaveDay.LeaveDays = leaveDays; } if (LeaveDay.LeaveHours == null || LeaveDay.LeaveHours != leaveHours) { LeaveDay.LeaveHours = leaveHours; } }
public string SaveLeaveDay(Att_Workday Workday, string LeaveTypeCode, string UserLogin) { if (Workday == null) return string.Empty; using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCat_Shift = new CustomBaseRepository<Cat_Shift>(unitOfWork); var repoCat_LeaveDayType = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork); var repoAtt_LeaveDay = new CustomBaseRepository<Att_LeaveDay>(unitOfWork); var repoHre_Profile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork); var repoCat_GradeAttendance = new CustomBaseRepository<Cat_GradeAttendance>(unitOfWork); var repoHre_WorkHistory = new CustomBaseRepository<Hre_WorkHistory>(unitOfWork); var repoAtt_Roster = new CustomBaseRepository<Att_Roster>(unitOfWork); var repoAtt_RosterGroup = new CustomBaseRepository<Att_RosterGroup>(unitOfWork); var repoCat_DayOff = new CustomBaseRepository<Cat_DayOff>(unitOfWork); var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList(); Att_LeavedayServices leavedayServices = new Att_LeavedayServices(); LeaveTypeCode = LeaveTypeCode.Replace("...", string.Empty); Guid? ShiftID = Workday.ShiftApprove ?? Workday.ShiftID; double DurationHour = 8; var shift = repoCat_Shift.FindBy(m => m.ID == ShiftID).FirstOrDefault(); //Cat_Shift shift = EntityService.CreateQueryable<Cat_Shift>(false, GuidContext, Guid.Empty, m => m.ID == ShiftID).FirstOrDefault(); if (shift != null) DurationHour = shift.WorkHours ?? 8; var leaveType = new List<Cat_LeaveDayType>().Select(m => new { m.ID, m.Code, m.CodeStatistic }).FirstOrDefault(); if (!string.IsNullOrEmpty(LeaveTypeCode)) { leaveType = repoCat_LeaveDayType.FindBy(m => m.Code == LeaveTypeCode).Select(m => new { m.ID, m.Code, m.CodeStatistic }).FirstOrDefault(); //leaveType = EntityService.CreateQueryable<Cat_LeaveDayType>(false, GuidContext, Guid.Empty, m => m.CodeStatistic == LeaveTypeCode).Select(m => new { m.ID, m.Code, m.CodeStatistic }).FirstOrDefault(); } DateTime workday = Workday.WorkDate; DateTime beginDate = workday.Date; DateTime endDate = beginDate.AddDays(1).AddMinutes(-1); DateTime beginShift = workday.AddHours(shift.InTime.Hour).AddMinutes(shift.InTime.Minute); DateTime endShift = beginShift.AddHours(shift.CoOut); string E_APPROVED = LeaveDayStatus.E_APPROVED.ToString(); string E_REJECTED = LeaveDayStatus.E_REJECTED.ToString(); List<Att_LeaveDay> lstLeaveDayInDbUpdate = repoAtt_LeaveDay.FindBy(m => m.DateStart <= endDate && m.DateEnd >= beginDate && m.ProfileID == Workday.ProfileID && m.Status != E_REJECTED).ToList<Att_LeaveDay>(); List<Att_LeaveDay> lstLeaveDayInsert = new List<Att_LeaveDay>(); if (lstLeaveDayInDbUpdate.Count > 0) { if (!lstLeaveDayInDbUpdate.Any(m => m.Status == LeaveDayStatus.E_APPROVED.ToString())) { if (leaveType != null) { lstLeaveDayInDbUpdate.ForEach(m => m.LeaveDayTypeID = leaveType.ID); } else { lstLeaveDayInDbUpdate.ForEach(m => m.IsDelete = true); } } else lstLeaveDayInDbUpdate = new List<Att_LeaveDay>(); } else { if (leaveType != null) { Att_LeaveDay LeavedayInsert = new Att_LeaveDay(); LeavedayInsert.ID = Guid.Empty; LeavedayInsert.ProfileID = Workday.ProfileID; LeavedayInsert.TotalDuration = 1; LeavedayInsert.LeaveDays = 1; LeavedayInsert.Duration = shift.WorkHours ?? 8; LeavedayInsert.LeaveHours = shift.WorkHours ?? 8; LeavedayInsert.DurationType = LeaveDayDurationType.E_FULLSHIFT.ToString(); LeavedayInsert.DateStart = workday; LeavedayInsert.DateEnd = workday; LeavedayInsert.LeaveDayTypeID = leaveType.ID; LeavedayInsert.Status = LeaveDayStatus.E_SUBMIT.ToString(); lstLeaveDayInsert.Add(LeavedayInsert); } } //Cap nhat leavedayID cho workday o day if (lstLeaveDayInsert.Count > 0) { if (lstLeaveDayInsert.Count > 1) { Workday.LeaveDayID1 = lstLeaveDayInsert[0].ID; Workday.LeaveDayID2 = lstLeaveDayInsert[1].ID; //Workday.udLeavedayCode1 = LeaveTypeCode; //Workday.udLeavedayCode2 = LeaveTypeCode; //Workday.udLeavedayStatus1 = lstLeaveDayInsert.FirstOrDefault().Status.TranslateString(); //Workday.udLeavedayStatus2 = lstLeaveDayInsert.FirstOrDefault().Status.TranslateString(); } else { Workday.LeaveDayID1 = lstLeaveDayInsert[0].ID; //Workday.udLeavedayCode1 = LeaveTypeCode; //Workday.udLeavedayStatus1 = lstLeaveDayInsert.FirstOrDefault().Status.TranslateString(); } } //else if (lstLeaveDayInDbUpdate.Count > 0) //{ // if (lstLeaveDayInDbUpdate.Count >= 2) // { // Workday.udLeavedayCode1 = LeaveTypeCode; // Workday.udLeavedayCode2 = LeaveTypeCode; // Workday.udLeavedayStatus1 = lstLeaveDayInDbUpdate.FirstOrDefault().Status.TranslateString(); // Workday.udLeavedayStatus2 = lstLeaveDayInDbUpdate.FirstOrDefault().Status.TranslateString(); // } // else // { // Workday.udLeavedayCode1 = LeaveTypeCode; // Workday.udLeavedayStatus1 = lstLeaveDayInDbUpdate.FirstOrDefault().Status.TranslateString(); // Workday.udLeavedayStatus2 = lstLeaveDayInDbUpdate.FirstOrDefault().Status.TranslateString(); // } //} #region Triet.Mai Validate Nghỉ Bù if (lstLeaveDayInsert.Count > 0) { List<Guid> LeaveTypeDayOffID = repoCat_LeaveDayType.FindBy(m => m.IsTimeOffInLieu == true).Select(m => m.ID).ToList<Guid>(); //List<Guid> LeaveTypeDayOffID = EntityService.CreateQueryable<Cat_LeaveDayType>(false, GuidContext, Guid.Empty, m => m.IsTimeOffInLieu == true).Select(m => m.ID).ToList<Guid>(); if (lstLeaveDayInsert.FirstOrDefault().Status != OverTimeStatus.E_CANCEL.ToString() && LeaveTypeDayOffID.Any(m => m == lstLeaveDayInsert.FirstOrDefault().LeaveDayTypeID)) { string Error = leavedayServices.ValidateLeaveDayTimeOff(lstLeaveDayInsert.Select(m => m.ProfileID).Distinct().ToList(), lstLeaveDayInsert); if (Error != string.Empty) { return Error; } } } #endregion #region triet.mai validate vấn đề ngày nghỉ dành cho nhân viên thực tập string E_STANDARD_WORKDAY = AppConfig.E_STANDARD_WORKDAY.ToString(); string status = string.Empty; List<object> lstO = new List<object>(); lstO.Add(E_STANDARD_WORKDAY); lstO.Add(null); lstO.Add(null); Sys_AllSetting config = GetData<Sys_AllSetting>(lstO, ConstantSql.hrm_sys_sp_get_AllSetting, UserLogin, ref status).FirstOrDefault(); //Sys_AppConfig config = EntityService.GetEntity<Sys_AppConfig>(false, GuidContext, Guid.Empty, m => m.Info == E_STANDARD_WORKDAY); string validateEmpProbation = leavedayServices.ValidateLeaveTypeByNewEmployee(config, lstLeaveDayInsert); if (validateEmpProbation != string.Empty) { return validateEmpProbation; } #endregion #region triet.mai cap nhat leaveDays va leaveHours lstLeaveDayInsert.AddRange(lstLeaveDayInDbUpdate); if (lstLeaveDayInsert.Count > 0) { List<Cat_LeaveDayType> lstLeaveDayType = repoCat_LeaveDayType.FindBy(m => m.IsDelete == null).ToList<Cat_LeaveDayType>(); //List<Cat_LeaveDayType> lstLeaveDayType = EntityService.CreateQueryable<Cat_LeaveDayType>(false, GuidContext, Guid.Empty).ToList<Cat_LeaveDayType>(); List<Guid> lstProfileID1 = lstLeaveDayInsert.Select(m => m.ProfileID).Distinct().ToList<Guid>(); List<Hre_Profile> lstProfile = repoHre_Profile.FindBy(m => lstProfileID1.Contains(m.ID)).ToList<Hre_Profile>(); //List<Hre_Profile> lstProfile = EntityService.CreateQueryable<Hre_Profile>(false, GuidContext, Guid.Empty, m => lstProfileID1.Contains(m.ID)).ToList<Hre_Profile>(); DateTime dateMin1 = lstLeaveDayInsert.Min(m => m.DateStart).Date; DateTime dateMax1 = lstLeaveDayInsert.Max(m => m.DateEnd); List<Att_Roster> lstRosterTypeGroup = new List<Att_Roster>(); List<Att_RosterGroup> lstRosterGroup = new List<Att_RosterGroup>(); var lstGrade = repoAtt_Grade.FindBy(m => lstProfileID1.Contains(m.ProfileID.Value)) .Select(m => new { m.ID, m.ProfileID, m.MonthStart, m.GradeAttendanceID }) .OrderByDescending(m => m.MonthStart).ToList(); //var lstGrade = EntityService.CreateQueryable<Sal_Grade>(false, GuidContext, Guid.Empty, m => lstProfileID1.Contains(m.ProfileID)) // .Select(m => new { m.ID, m.ProfileID, m.MonthStart, m.GradeID }) // .OrderByDescending(m => m.MonthStart) // .Execute(); List<Cat_GradeAttendance> lstGradeAttendance = repoCat_GradeAttendance.FindBy(m => m.IsDelete == null).ToList(); //List<Cat_GradeCfg> lstGradeCfg = EntityService.CreateQueryable<Cat_GradeCfg>(false, GuidContext, Guid.Empty).ToList<Cat_GradeCfg>(); List<Hre_WorkHistory> listWorkHistory = repoHre_WorkHistory.FindBy(m => m.DateEffective <= dateMax1 && lstProfileID1.Contains(m.ProfileID)).OrderByDescending(m => m.DateEffective).ToList<Hre_WorkHistory>(); //List<Hre_WorkHistory> listWorkHistory = EntityService.CreateQueryable<Hre_WorkHistory>(false, GuidContext, Guid.Empty, m => m.DateEffective <= dateMax1 && lstProfileID1.Contains(m.ProfileID)).OrderByDescending(m => m.DateEffective).ToList<Hre_WorkHistory>(); E_APPROVED = RosterStatus.E_APPROVED.ToString(); string E_ROSTERGROUP = RosterType.E_ROSTERGROUP.ToString(); if (dateMin1 == null || dateMax1 == null) { lstRosterTypeGroup = repoAtt_Roster.FindBy(m => lstProfileID1.Contains(m.ProfileID) && m.Status == E_APPROVED && m.Type == E_ROSTERGROUP).ToList<Att_Roster>(); //lstRosterTypeGroup = EntityService.Instance.CreateQueryable<Att_Roster>(false, guidContext, Guid.Empty, 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>(); //lstRosterGroup = EntityService.Instance.CreateQueryable<Att_RosterGroup>(false, guidContext, Guid.Empty, m => m.DateStart != null && m.DateEnd != null).ToList<Att_RosterGroup>(); } else { lstRosterTypeGroup = repoAtt_Roster.FindBy(m => lstProfileID1.Contains(m.ProfileID) && m.Status == E_APPROVED && m.Type == E_ROSTERGROUP && m.DateStart <= dateMax1).ToList<Att_Roster>(); //lstRosterTypeGroup = EntityService.Instance.CreateQueryable<Att_Roster>(false, guidContext, Guid.Empty, 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 <= dateMax1 && m.DateEnd >= dateMin1).ToList<Att_RosterGroup>(); //lstRosterGroup = EntityService.Instance.CreateQueryable<Att_RosterGroup>(false, guidContext, Guid.Empty, m => m.DateStart != null && m.DateEnd != null && m.DateStart <= DateTo && m.DateEnd >= DateFrom).ToList<Att_RosterGroup>(); } //RosterDAO.GetRosterGroup(GuidContext, lstProfileID1, dateMin1, dateMax1, out lstRosterTypeGroup, out lstRosterGroup); List<Cat_DayOff> lstHoliday = repoCat_DayOff.FindBy(m => m.IsDelete == null).ToList<Cat_DayOff>(); //List<Cat_DayOff> lstHoliday = EntityService.CreateQueryable<Cat_DayOff>(false, GuidContext, Guid.Empty).ToList<Cat_DayOff>(); string E_APPROVED1 = RosterStatus.E_APPROVED.ToString(); E_ROSTERGROUP = RosterType.E_ROSTERGROUP.ToString(); List<Att_Roster> lstRoster = repoAtt_Roster.FindBy(m => m.Status == E_APPROVED1 && m.DateStart <= dateMax1 && m.DateEnd >= dateMin1 && lstProfileID1.Contains(m.ProfileID)).ToList<Att_Roster>(); //List<Att_Roster> lstRoster = EntityService.CreateQueryable<Att_Roster>(false, GuidContext, Guid.Empty, m => m.Status == E_APPROVED1 && m.DateStart <= dateMax1 && m.DateEnd >= dateMin1 && lstProfileID1.Contains(m.ProfileID)).ToList<Att_Roster>(); List<DateTime> lstHolidayType = lstHoliday.Select(m => m.DateOff).ToList<DateTime>(); //LeaveDayDAO ldDao = new LeaveDayDAO(); foreach (var item in lstLeaveDayInsert) { if (item.DurationType != null && item.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()) continue; Cat_LeaveDayType leaveDayType = lstLeaveDayType.Where(m => m.ID == item.LeaveDayTypeID).FirstOrDefault(); if (leaveDayType == null) continue; Hre_Profile profileInLeave = lstProfile.Where(m => m.ID == item.ProfileID).FirstOrDefault(); if (profileInLeave == null) continue; DateTime dateFrom = item.DateStart; DateTime dateTo = item.DateEnd; dateTo = dateTo.AddDays(1).AddMinutes(-1); Guid GradeAttendanceID = lstGrade.Where(m => m.ProfileID == profileInLeave.ID && m.MonthStart <= dateMax1 && m.GradeAttendanceID.HasValue).Select(m => m.GradeAttendanceID.Value).FirstOrDefault(); Cat_GradeAttendance gradeAttendance = lstGradeAttendance.Where(m => m.ID == GradeAttendanceID).FirstOrDefault(); List<Att_Roster> lstRosterByProfile = lstRoster.Where(m => m.ProfileID == profileInLeave.ID).ToList(); List<Hre_WorkHistory> listWorkHistoryByProfile = listWorkHistory.Where(m => m.ProfileID == profileInLeave.ID && m.DateEffective < dateTo).ToList(); List<Att_Roster> lstRosterByProfileTypeGroup = lstRosterByProfile.Where(m => m.Type == E_ROSTERGROUP).ToList(); leavedayServices.AnalyseTotalLeaveDaysAndHours(item, leaveDayType, profileInLeave, gradeAttendance, lstRosterByProfile, lstRosterGroup, listWorkHistoryByProfile, lstHoliday, shifts); if (item.ID == Guid.Empty) { item.ID = Guid.NewGuid(); repoAtt_LeaveDay.Add(item); } else repoAtt_LeaveDay.Edit(item); } } #endregion //repoAtt_LeaveDay.Add(lstLeaveDayInsert); repoAtt_LeaveDay.SaveChanges(); //EntityService.AddEntity<Att_LeaveDay>(GuidContext, lstLeaveDayInsert.ToArray()); return string.Empty; } }
/// <summary> /// Hàm tính ra số phép Còn lại của tháng hiện tại và cuối năm ps: chưa trừ ra cái leaveday đang check /// </summary> /// <param name="leaveDay"></param> /// <param name="lstLeaveDayType"></param> /// <param name="RemainInEndMonth"></param> /// <param name="RemainInEndYear"></param> public void GetRemainLeaveDay(Att_LeaveDay leaveDay, List<Cat_LeaveDayType> lstLeaveDayType, out double RemainInEndMonth, out double RemainInEndYear) { RemainInEndMonth = 0; RemainInEndYear = 0; var LeaveDayType = lstLeaveDayType.Where(m => m.ID == leaveDay.LeaveDayTypeID).FirstOrDefault(); if (LeaveDayType == null) return; if (LeaveDayType.IsAnnualLeave) { List<Att_RemainLeaveEntity> lstRemainLeaveEntity = GetRemainLeave_Annual(leaveDay.DateEnd, new List<Guid>() { leaveDay.ProfileID }); if (lstRemainLeaveEntity != null && lstRemainLeaveEntity.Count > 0) { Att_RemainLeaveEntity RemainLeave = lstRemainLeaveEntity.FirstOrDefault(); if (RemainLeave != null) { RemainInEndMonth = RemainLeave.RemainEndMonth ?? 0; RemainInEndYear = RemainLeave.RemainEndYear ?? 0; } } } else if (LeaveDayType.IsTimeOffInLieu != null && LeaveDayType.IsTimeOffInLieu == true) { List<Att_RemainLeaveEntity> lstRemainLeaveEntity = GetRemainLeave_TimeOffInLieu(leaveDay.DateEnd, new List<Guid>() { leaveDay.ProfileID }); if (lstRemainLeaveEntity != null && lstRemainLeaveEntity.Count > 0) { Att_RemainLeaveEntity RemainLeave = lstRemainLeaveEntity.FirstOrDefault(); if (RemainLeave != null) { RemainInEndMonth = RemainLeave.RemainEndMonth ?? 0; RemainInEndYear = RemainLeave.RemainEndYear ?? 0; } } } }