private void MergeTASheet(Staff staff, List <AttendanceResult> timezones, TASheet sheet, DatetimeRange range) { List <AttendanceResult> items = new List <AttendanceResult>(); if (!range.Contain(sheet.StartDate) && !range.Contain(sheet.EndDate)) { return; } DateTime dt = sheet.StartDate; while (dt <= sheet.EndDate && range.Contain(dt)) { List <AttendanceResult> ots = CreateAttendanceResult(staff, dt, sheet); if (ots == null || ots.Count == 0) { break; } foreach (AttendanceResult ot in ots) { DatetimeRange drOT = new DatetimeRange(ot.NewStartTime, ot.NewEndTime); List <AttendanceResult> sts = timezones.Where(it => it.ShiftDate == ot.ShiftDate).ToList(); if (sts == null || sts.Count == 0) { items.Add(ot); } else { foreach (AttendanceResult st in sts) { DatetimeRange drSt = new DatetimeRange(st.NewStartTime, st.NewEndTime); if (!drSt.Contain(drOT)) //检查是否有全部重合的情况,如果与上班时间全部重合,则加班无效。 { if (drSt.Contain(drOT.Begin)) //如果加班的开始时间与普通上班时间有重叠,加班时间要截取掉重合部分,并且普通上班下班不用再打卡。 { st.LogWhenLeave = false; ot.NewStartTime = drSt.End; ot.ShiftTime = (new DatetimeRange(ot.NewStartTime, ot.NewEndTime)).TotalMinutes; ot.Present = (new DatetimeRange(ot.NewStartTime, ot.NewEndTime)).TotalMinutes; ot.LogWhenArrive = false; } if (drSt.Contain(drOT.End)) { ot.NewEndTime = drSt.Begin; ot.ShiftTime = (new DatetimeRange(ot.NewStartTime, ot.NewEndTime)).TotalMinutes; ot.Present = (new DatetimeRange(ot.NewStartTime, ot.NewEndTime)).TotalMinutes; ot.LogWhenLeave = false; st.LogWhenArrive = false; } items.Add(ot); } } } } dt = dt.AddDays(1); } if (items.Count > 0) { timezones.AddRange(items); } }
public static List <TASheet> UnGroup(TASheetGroup group) { List <TASheet> items = null; if (group.Staff != null && group.Staff.Count > 0) { items = new List <TASheet>(); foreach (Staff staff in group.Staff) { TASheet item = new TASheet() { SheetID = group.SheetID, SheetType = group.SheetType, CreateDate = group.CreateDate, StartDate = group.StartDate, EndDate = group.EndDate, Items = group.Items, CategoryID = group.Category, StaffID = staff.ID, StaffName = staff.Name, Header = group.Header, Manager = group.Manager, HR = group.HR, Memo = group.Memo, }; items.Add(item); } } return(items); }
public static List<TASheet> UnGroup(TASheetGroup group) { List<TASheet> items = null; if (group.Staff != null && group.Staff.Count > 0) { items = new List<TASheet>(); foreach (Staff staff in group.Staff) { TASheet item = new TASheet() { SheetID = group.SheetID, SheetType = group.SheetType, CreateDate = group.CreateDate, StartDate = group.StartDate, EndDate = group.EndDate, Items = group.Items, CategoryID = group.Category, StaffID = staff.ID, StaffName = staff.Name, Header = group.Header, Manager = group.Manager, HR = group.HR, Memo = group.Memo, }; items.Add(item); } } return items; }
private void ExcludeTASheet(List <AttendanceResult> timezones, TASheet sheet, DatetimeRange range) { List <AttendanceResult> items = new List <AttendanceResult>(); if (!range.Contain(sheet.StartDate) && !range.Contain(sheet.EndDate)) { return; } DateTime dt = sheet.StartDate; while (dt <= sheet.EndDate && range.Contain(dt)) { if (sheet.Items != null && sheet.Items.Count > 0) { foreach (TASheetItem item in sheet.Items) { DateTime dt1 = dt.AddHours(item.StartTime.Hour).AddMinutes(item.StartTime.Minute).AddSeconds(item.StartTime.Second); DateTime dt2 = dt.AddHours(item.EndTime.Hour).AddMinutes(item.EndTime.Minute).AddSeconds(item.EndTime.Second); if (item.NextDay) { dt2 = dt2.AddDays(1); } DatetimeRange dr = new DatetimeRange(dt1, dt2); List <AttendanceResult> sts = timezones.Where(it => it.ShiftDate == dt).ToList(); if (sts != null && sts.Count > 0) { foreach (AttendanceResult st in sts) { DatetimeRange drItem = new DatetimeRange(st.NewStartTime, st.NewEndTime); if (dr.Contain(drItem)) { if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu)) { st.Present = 0; } st.Category = sheet.CategoryID; st.LogWhenArrive = false; st.LogWhenLeave = false; AbsentItem ai = new AbsentItem() { ID = Guid.NewGuid(), Category = sheet.CategoryID, Duration = st.ShiftTime }; st.AbsentItems.Add(ai); } else if (drItem.Contain(dr)) { if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu)) { st.Present -= dr.TotalMinutes; } if (drItem.Begin == dr.Begin) { st.NewStartTime = dr.End; } if (drItem.End == dr.End) { st.NewEndTime = dr.Begin; } AbsentItem ai = new AbsentItem() { ID = Guid.NewGuid(), Category = sheet.CategoryID, Duration = dr.TotalMinutes }; st.AbsentItems.Add(ai); } else if (drItem.Contain(dr.Begin)) { DatetimeRange drTemp = new DatetimeRange(dr.Begin, drItem.End); if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu)) { st.Present -= drTemp.TotalMinutes; } st.NewEndTime = dr.Begin; AbsentItem ai = new AbsentItem() { ID = Guid.NewGuid(), Category = sheet.CategoryID, Duration = drTemp.TotalMinutes }; st.AbsentItems.Add(ai); } else if (drItem.Contain(dr.End)) { DatetimeRange drTemp = new DatetimeRange(drItem.Begin, dr.End); if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu)) { st.Present -= drTemp.TotalMinutes; } st.NewStartTime = dr.End; AbsentItem ai = new AbsentItem() { ID = Guid.NewGuid(), Category = sheet.CategoryID, Duration = drTemp.TotalMinutes }; st.AbsentItems.Add(ai); } } } } } dt = dt.AddDays(1); } if (items.Count > 0) { timezones.AddRange(items); } }
private List <AttendanceResult> CreateAttendanceResult(Staff staff, DateTime shiftDate, TASheet sheet) { List <AttendanceResult> items = new List <AttendanceResult>(); if (sheet.Items != null && sheet.Items.Count > 0) { foreach (TASheetItem item in sheet.Items) { DateTime dt1 = shiftDate.AddHours(item.StartTime.Hour).AddMinutes(item.StartTime.Minute).AddSeconds(item.StartTime.Second); DateTime dt2 = shiftDate.AddHours(item.EndTime.Hour).AddMinutes(item.EndTime.Minute).AddSeconds(item.EndTime.Second); if (dt1 > dt2) { dt2 = dt2.AddDays(1); //跨天 } AttendanceResult st = new AttendanceResult(); st.ID = Guid.NewGuid(); st.StaffID = staff.ID; st.StaffName = staff.Name; st.ShiftDate = shiftDate; st.Category = sheet.CategoryID; st.StartTime = dt1; st.NewStartTime = dt1; st.EndTime = dt2; st.NewEndTime = dt2; if (AttendanceRules.Current != null) { st.EarlyestTime = st.NewStartTime.AddMinutes(-(int)AttendanceRules.Current.BeforeOTStartTime); st.LatestTime = st.NewEndTime.AddMinutes((int)AttendanceRules.Current.AfterOTEndTime); } else { st.EarlyestTime = st.NewStartTime.AddMinutes(-30); st.LatestTime = st.NewEndTime.AddMinutes(30); } st.ShiftTime = item.Duration; st.Present = item.Duration; st.AbsentItems = new List <AbsentItem>(); st.LogWhenArrive = true; st.LogWhenLeave = true; st.EnableLate = true; st.EnableLeaveEarly = true; st.EnableAbsent = true; items.Add(st); } } return(items); }
private void ExcludeTASheet(List<AttendanceResult> timezones, TASheet sheet, DatetimeRange range) { List<AttendanceResult> items = new List<AttendanceResult>(); if (!range.Contain(sheet.StartDate) && !range.Contain(sheet.EndDate)) return; DateTime dt = sheet.StartDate; while (dt <= sheet.EndDate && range.Contain(dt)) { if (sheet.Items != null && sheet.Items.Count > 0) { foreach (TASheetItem item in sheet.Items) { DateTime dt1 = dt.AddHours(item.StartTime.Hour).AddMinutes(item.StartTime.Minute).AddSeconds(item.StartTime.Second); DateTime dt2 = dt.AddHours(item.EndTime.Hour).AddMinutes(item.EndTime.Minute).AddSeconds(item.EndTime.Second); if (item.NextDay) dt2 = dt2.AddDays(1); DatetimeRange dr = new DatetimeRange(dt1, dt2); List<AttendanceResult> sts = timezones.Where(it => it.ShiftDate == dt).ToList(); if (sts != null && sts.Count > 0) { foreach (AttendanceResult st in sts) { DatetimeRange drItem = new DatetimeRange(st.NewStartTime, st.NewEndTime); if (dr.Contain(drItem)) { if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu)) { st.Present = 0; } st.Category = sheet.CategoryID; st.LogWhenArrive = false; st.LogWhenLeave = false; AbsentItem ai = new AbsentItem() { ID=Guid.NewGuid (), Category = sheet.CategoryID, Duration = st.ShiftTime }; st.AbsentItems.Add(ai); } else if (drItem.Contain(dr)) { if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu)) { st.Present -= dr.TotalMinutes; } if (drItem.Begin == dr.Begin) st.NewStartTime = dr.End; if (drItem.End == dr.End) st.NewEndTime = dr.Begin; AbsentItem ai = new AbsentItem() { ID=Guid.NewGuid (), Category = sheet.CategoryID, Duration = dr.TotalMinutes }; st.AbsentItems.Add(ai); } else if (drItem.Contain(dr.Begin)) { DatetimeRange drTemp = new DatetimeRange(dr.Begin, drItem.End); if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu)) { st.Present -= drTemp.TotalMinutes; } st.NewEndTime = dr.Begin; AbsentItem ai = new AbsentItem() { ID=Guid.NewGuid (), Category = sheet.CategoryID, Duration = drTemp.TotalMinutes }; st.AbsentItems.Add(ai); } else if (drItem.Contain(dr.End)) { DatetimeRange drTemp = new DatetimeRange(drItem.Begin, dr.End); if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu)) { st.Present -= drTemp.TotalMinutes; } st.NewStartTime = dr.End; AbsentItem ai = new AbsentItem() { ID=Guid .NewGuid (), Category = sheet.CategoryID, Duration = drTemp.TotalMinutes }; st.AbsentItems.Add(ai); } } } } } dt = dt.AddDays(1); } if (items.Count > 0) timezones.AddRange(items); }
private List<AttendanceResult> CreateAttendanceResult(Staff staff, DateTime shiftDate, TASheet sheet) { List<AttendanceResult> items = new List<AttendanceResult>(); if (sheet.Items != null && sheet.Items.Count > 0) { foreach (TASheetItem item in sheet.Items) { DateTime dt1 = shiftDate.AddHours(item.StartTime.Hour).AddMinutes(item.StartTime.Minute).AddSeconds(item.StartTime.Second); DateTime dt2 = shiftDate.AddHours(item.EndTime.Hour).AddMinutes(item.EndTime.Minute).AddSeconds(item.EndTime.Second); if (dt1 > dt2) dt2 = dt2.AddDays(1); //跨天 AttendanceResult st = new AttendanceResult(); st.ID = Guid.NewGuid(); st.StaffID = staff.ID; st.StaffName = staff.Name; st.ShiftDate = shiftDate; st.Category = sheet.CategoryID; st.StartTime = dt1; st.NewStartTime = dt1; st.EndTime = dt2; st.NewEndTime = dt2; if (AttendanceRules.Current != null) { st.EarlyestTime = st.NewStartTime.AddMinutes(-(int)AttendanceRules.Current.BeforeOTStartTime); st.LatestTime = st.NewEndTime.AddMinutes((int)AttendanceRules.Current.AfterOTEndTime); } else { st.EarlyestTime = st.NewStartTime.AddMinutes(-30); st.LatestTime = st.NewEndTime.AddMinutes(30); } st.ShiftTime = item.Duration; st.Present = item.Duration; st.AbsentItems = new List<AbsentItem>(); st.LogWhenArrive = true; st.LogWhenLeave = true; st.EnableLate = true; st.EnableLeaveEarly = true; st.EnableAbsent = true; items.Add(st); } } return items; }
private void MergeTASheet(Staff staff, List<AttendanceResult> timezones, TASheet sheet, DatetimeRange range) { List<AttendanceResult> items = new List<AttendanceResult>(); if (!range.Contain(sheet.StartDate) && !range.Contain(sheet.EndDate)) return; DateTime dt = sheet.StartDate; while (dt <= sheet.EndDate && range.Contain(dt)) { List<AttendanceResult> ots = CreateAttendanceResult(staff, dt, sheet); if (ots == null || ots.Count == 0) break; foreach (AttendanceResult ot in ots) { DatetimeRange drOT = new DatetimeRange(ot.NewStartTime, ot.NewEndTime); List<AttendanceResult> sts = timezones.Where(it => it.ShiftDate == ot.ShiftDate).ToList(); if (sts == null || sts.Count == 0) { items.Add(ot); } else { foreach (AttendanceResult st in sts) { DatetimeRange drSt = new DatetimeRange(st.NewStartTime, st.NewEndTime); if (!drSt.Contain(drOT)) //检查是否有全部重合的情况,如果与上班时间全部重合,则加班无效。 { if (drSt.Contain(drOT.Begin)) //如果加班的开始时间与普通上班时间有重叠,加班时间要截取掉重合部分,并且普通上班下班不用再打卡。 { st.LogWhenLeave = false; ot.NewStartTime = drSt.End; ot.ShiftTime = (new DatetimeRange(ot.NewStartTime, ot.NewEndTime)).TotalMinutes; ot.Present = (new DatetimeRange(ot.NewStartTime, ot.NewEndTime)).TotalMinutes; ot.LogWhenArrive = false; } if (drSt.Contain(drOT.End)) { ot.NewEndTime = drSt.Begin; ot.ShiftTime = (new DatetimeRange(ot.NewStartTime, ot.NewEndTime)).TotalMinutes; ot.Present = (new DatetimeRange(ot.NewStartTime, ot.NewEndTime)).TotalMinutes; ot.LogWhenLeave = false; st.LogWhenArrive = false; } items.Add(ot); } } } } dt = dt.AddDays(1); } if (items.Count > 0) timezones.AddRange(items); }