public Cat_OvertimeType getOTType(DateTime dateWorkDate, bool isNightShift, Hre_Profile profile, List <Cat_DayOff> list_dayOff, List <Att_RosterGroup> lstRosterGroup, List <Att_Roster> lstRosterTypeGroup) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_LeaveDay = new CustomBaseRepository <Att_LeaveDay>(unitOfWork); var repoCat_OvertimeType = new CustomBaseRepository <Cat_OvertimeType>(unitOfWork); Cat_OvertimeType otType = null; try { dateWorkDate = dateWorkDate.Date; //LamLe : Them chuc nang neu tang ca vao ngay nghi thi chon loai tang ca phu thuoc vao cau hinh Tang ca trong ngay nghi. List <Att_LeaveDay> lstLeave = repoAtt_LeaveDay .FindBy(lv => lv.IsDelete == null && lv.DateStart <= dateWorkDate && lv.DateEnd >= dateWorkDate && lv.ProfileID == profile.ID) .ToList(); if (lstLeave.Count > 0) { Att_LeaveDay leave = lstLeave[0]; if (leave != null && leave.Cat_LeaveDayType != null && leave.Cat_LeaveDayType.Cat_OvertimeType != null) { otType = leave.Cat_LeaveDayType.Cat_OvertimeType; return(otType); } } Att_Grade grade = Att_GradeServices.GetGrade(profile, dateWorkDate); if (grade == null) { string status = OverTimeType.E_WORKDAY.ToString(); otType = repoCat_OvertimeType.FindBy(dayoff => dayoff.IsDelete == null && dayoff.Code == status).FirstOrDefault(); return(otType); } list_dayOff = list_dayOff.Where(df => df.DateOff.Date == dateWorkDate.Date).ToList(); Cat_GradeCfg gradecfg = grade.Cat_GradeCfg; //Check overtime holiday //List<Cat_DayOff> list_dayOff = EntityService.Instance.GetEntityList<Cat_DayOff>(GuidContext, _userId, dayoff => dayoff.DateOff == dateWorkDate); if (list_dayOff.Count > 0) { //Cat_GradeCfg.FieldNames.Cat_OvertimeType1 bool isDayOffHollyDay = false; foreach (var item in list_dayOff) { if (item.DateOff.Date == dateWorkDate.Date && item.Type == HolidayType.E_HOLIDAY_HLD.ToString()) { isDayOffHollyDay = true; } } //Ca dem ngay le if (isDayOffHollyDay && isNightShift) { otType = gradecfg.Cat_OvertimeType5; } //Ca dem ngay nghi cuoi tuan else if (!isDayOffHollyDay && isNightShift) { otType = gradecfg.Cat_OvertimeType4; } ////Ca ngay ngay le else if (isDayOffHollyDay && !isNightShift) { otType = gradecfg.Cat_OvertimeType2; } ////Ca ngay ngay nghi cuoi tuan else { otType = gradecfg.Cat_OvertimeType1; } } else { Hashtable hsRoster = Att_RosterServices.GetRosterTable(false, profile, dateWorkDate, dateWorkDate, lstRosterGroup, lstRosterTypeGroup); bool isWorkday = Att_AttendanceServices.IsWorkDay(grade.Cat_GradeAttendance, hsRoster, list_dayOff, dateWorkDate); if (isWorkday) { if (isNightShift) { otType = gradecfg.Cat_OvertimeType3; } else { otType = gradecfg.Cat_OvertimeType; } //if (gradecfg.Cat_OvertimeType == null) //{ // string workday = OverTimeType.E_WORKDAY.ToString(); // otType = EntityService.Instance.GetEntity<Cat_OvertimeType>(GuidContext, _userId, dayoff => dayoff.Code == workday); //} //else // otType = gradecfg.Cat_OvertimeType; } else { if (isNightShift) { otType = gradecfg.Cat_OvertimeType4; } else { otType = gradecfg.Cat_OvertimeType1; } //if (gradecfg.Cat_OvertimeType1 == null) //{ // string workday = OverTimeType.E_WORKDAY.ToString(); // otType = EntityService.Instance.GetEntity<Cat_OvertimeType>(GuidContext, _userId, dayoff => dayoff.Code == workday); //} //else // otType = gradecfg.Cat_OvertimeType1; } } } catch (Exception ex) { } return(otType); } }
/// <summary> /// Edit comment Trung.le 20120529 /// Them thuoc tinh Khong cat Overtime qua ngày E_STANDARD_WORKDAY - Value37 Trung.le 20120529 /// </summary> /// <param name="overtime"></param> /// <param name="lstDayOff"></param> /// <param name="_LstPregnancy"></param> /// <param name="GuidContext"></param> /// <param name="_userId"></param> /// <param name="isByShift">Lấy theo ca làm việc của từng người</param> /// <returns></returns> public List <Att_OvertimeEntity> AnalysisOvertime(Att_OvertimeEntity overtime, List <Cat_DayOff> lstDayOff, List <Att_Pregnancy> _LstPregnancy, bool isByShift, bool isAllowCutBreakHour, string UserLogin) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCat_Shift = new CustomBaseRepository <Cat_Shift>(unitOfWork); Cat_Shift ShiftOfOT = repoCat_Shift.FindBy(s => s.ID == overtime.ShiftID).FirstOrDefault(); string status = string.Empty; Att_OvertimeEntity baseOT = null; if (overtime != null) { //overtime.SerialCode = overtime.Workdate.ToString("ddMMyyyy"); } List <Att_OvertimeEntity> listOvertimeInsert = new List <Att_OvertimeEntity>(); Hre_Profile profile = new Hre_Profile(); profile.ID = overtime.ProfileID; DateTime _workDate = overtime.WorkDate; DateTime dateWorkDate = _workDate; string key = "HRM_ATT_OT"; List <object> lstSysOT = new List <object>(); lstSysOT.Add(key); lstSysOT.Add(null); lstSysOT.Add(null); var config = GetData <Sys_AllSettingEntity>(lstSysOT, ConstantSql.hrm_sys_sp_get_AllSetting, UserLogin, ref status); if (config == null) { return(listOvertimeInsert); } var NoCutOvertimePassDay = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_NOCUTOVERTIMEPASSDAY.ToString()).FirstOrDefault(); var ByPeriodOfTime = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_BYPERIODOFTIME.ToString()).FirstOrDefault(); var nightShiftFrom = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_NIGHTSHIFTFROM.ToString()).FirstOrDefault(); var nightShiftTo = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_NIGHTSHIFTTO.ToString()).FirstOrDefault(); bool isNocutOvertimePassDay = Convert.ToBoolean(NoCutOvertimePassDay.Value1);//Không cắt Overtime qua ngày List <Hre_Profile> lstProfile = new List <Hre_Profile>() { profile }; List <Guid> lstProfileIDs = lstProfile.Select(m => m.ID).ToList(); List <Att_Roster> lstRosterTypeGroup = new List <Att_Roster>(); List <Att_RosterGroup> lstRosterGroup = new List <Att_RosterGroup>(); Att_RosterServices.GetRosterGroup(lstProfileIDs, _workDate.Date, _workDate.Date, out lstRosterTypeGroup, out lstRosterGroup); string registryCode = "OT_" + overtime.CodeEmp + "_" + overtime.WorkDate.ToString("ddMMyyyyHHmmss"); double basicHours = overtime.RegisterHours; double durationHours = overtime.RegisterHours; //overtime.BasicHours = basicHours; //overtime.RegisterCode = registryCode; bool isWorkDay = true; DateTime dateWorkDateEnd = dateWorkDate.AddHours(durationHours); Att_Grade grade = Att_GradeServices.GetGrade(profile, _workDate.Date); Cat_GradeAttendance gradeCfg = grade == null ? null : grade.Cat_GradeAttendance; if (gradeCfg == null) { return(listOvertimeInsert); } Hashtable htable = null; htable = Att_RosterServices.GetRosterTable(false, profile, _workDate.Date, _workDate.Date, lstRosterGroup, lstRosterTypeGroup); isWorkDay = Att_AttendanceServices.IsWorkDay(gradeCfg, htable, lstDayOff, _workDate.Date); if (isByShift)//Lấy theo ca làm việc của từng người { #region Lấy theo ca làm việc của từng người Cat_Shift ship = Att_AttendanceServices.GetShift(gradeCfg, htable, _workDate.Date); if (ship != null) { if (isWorkDay) { if (overtime.DurationType == EnumDropDown.OvertimeDurationType.E_OT_LATE.ToString() && ship != null) { DateTime timeOut = ship.InTime.AddHours(ship.CoOut); dateWorkDate = _workDate.Date.AddHours(timeOut.Hour).AddMinutes(timeOut.Minute); dateWorkDateEnd = dateWorkDate.AddHours(durationHours); } else if (overtime.DurationType == EnumDropDown.OvertimeDurationType.E_OT_EARLY.ToString() && ship != null) { DateTime timeIn = ship.InTime; dateWorkDate = _workDate.Date.AddHours(timeIn.Hour).AddMinutes(timeIn.Minute); dateWorkDateEnd = dateWorkDate; dateWorkDate = dateWorkDate.AddHours(-durationHours); } } else { DateTime timeIn = ship.InTime; dateWorkDate = _workDate.Date.AddHours(timeIn.Hour).AddMinutes(timeIn.Minute); } } else { dateWorkDate = dateWorkDate.Date; dateWorkDateEnd = dateWorkDate.AddHours(durationHours); } ShiftOfOT = ship; htable = Att_RosterServices.GetRosterTable(false, profile, dateWorkDate, dateWorkDate.AddHours(durationHours), lstRosterGroup, lstRosterTypeGroup); isWorkDay = Att_AttendanceServices.IsWorkDay(gradeCfg, htable, lstDayOff, dateWorkDate.AddHours(durationHours)); #endregion } //Kiem tra xem co trong thoi gian nghi thai san khong? if (isWorkDay && overtime.DurationType == EnumDropDown.OvertimeDurationType.E_OT_LATE.ToString() && _LstPregnancy != null && _LstPregnancy.Exists(pc => pc.ProfileID == profile.ID && pc.DateEnd >= dateWorkDate && pc.DateStart <= dateWorkDateEnd)) { dateWorkDate = dateWorkDate.AddHours(-1); dateWorkDateEnd = dateWorkDate.AddHours(durationHours); } overtime.WorkDate = dateWorkDate; string strHoursNightFrom = string.Empty; string strHoursNightTo = string.Empty; if (!Att_AttendanceServices.IsNightShiftByConfig(ByPeriodOfTime) && ShiftOfOT != null && ShiftOfOT.NightTimeStart != null && ShiftOfOT.NightTimeEnd != null) { strHoursNightFrom = ShiftOfOT.NightTimeStart.Value.ToString("HH:mm:ss"); strHoursNightTo = ShiftOfOT.NightTimeEnd.Value.ToString("HH:mm:ss"); } else { strHoursNightFrom = string.IsNullOrEmpty(nightShiftFrom.Value1) == true ? "21:00:00" : nightShiftFrom.Value1 + ":00"; strHoursNightTo = string.IsNullOrEmpty(nightShiftTo.Value1) == true ? "05:00:00" : nightShiftTo.Value1 + ":00"; } DateTime dateNightFrom = Common.ConvertStringToDateTime(dateWorkDate.Date.ToString("MM/dd/yyyy") + " " + strHoursNightFrom, CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern); DateTime dateNightTo = Common.ConvertStringToDateTime(dateWorkDate.Date.AddDays(1).ToString("MM/dd/yyyy") + " " + strHoursNightTo, CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern); OvertimeInfo overtimeInfo = new OvertimeInfo(true); overtimeInfo.DateFrom = dateWorkDate; overtimeInfo.TotalHours = overtime.RegisterHours; overtimeInfo.DayShiftPoints = new DateTime[] { dateNightTo }; if (isNocutOvertimePassDay) { overtimeInfo.NightShiftPoints = new DateTime[] { dateNightFrom }; } else { //truong hop cat khi qua ngay hom sau overtimeInfo.NightShiftPoints = new DateTime[] { dateNightFrom, dateNightFrom.Date }; } if (ShiftOfOT != null && isAllowCutBreakHour) { Cat_Shift shift = ShiftOfOT; DateTime coBreakOut = shift.InTime.AddHours(shift.CoBreakIn); if (shift.CoBreakOut - shift.CoBreakIn > 0) { overtimeInfo.BreaktPoints.Add(coBreakOut, shift.CoBreakOut - shift.CoBreakIn); } } Hre_Profile temp = new Hre_Profile(); temp.ID = overtime.ProfileID; overtimeInfo.Hre_Profile = temp; overtimeInfo.ListDayOff = lstDayOff; listOvertimeInsert = AnalysisOvertime(overtime, overtimeInfo); return(listOvertimeInsert); } }