public object addUpTimeRule(WorkTimeRule data) { bool hasSame = Repository.chkSameWorkTime(data); bool isLegal = chkDataLegal(data); var result = 0; if (!isLegal) { return(cudAjaxResult(MessageCode.WorkDT_Illegal)); //該時間規則不合法 } data.lastOperaAccID = (int)loginID; if (data.ID == 0) { data.createTime = definePara.dtNow(); result = Repository.AddTimeRule(data); } else { data.updateTime = definePara.dtNow(); result = Repository.UpdateTimeRule(data); } if (hasSame && result == 1) { return(cudAjaxResult(MessageCode.Same_WorkDT)); //已有相同的上班與下班時間 } return(cudAjaxResult(result)); }
public dynamic addUpTimeRule(WorkTimeRule data) { bool hasSame = Repository.chkSameWorkTime(data); bool isLegal = chkDataLegal(data); if (!isLegal) { return("illegal"); } var result = 0; data.lastOperaAccID = (int)loginID; if (data.ID == 0) { data.createTime = definePara.dtNow(); result = Repository.AddTimeRule(data); } else { data.updateTime = definePara.dtNow(); result = Repository.UpdateTimeRule(data); } if (hasSame && result == 1) { return("same"); } return(result); }
public int AddTimeRule(WorkTimeRule newRule) { int count = 0; try{ _DbContext.worktimerules.Add(newRule); count = _DbContext.SaveChanges(); }catch (Exception e) { count = ((MySqlException)e.InnerException).Number; } if (count == 1) { var dic = new Dictionary <string, string> { }; var opLog = new OperateLog() { operateID = newRule.lastOperaAccID, active = "新增", category = "工作時間設定", createTime = definePara.dtNow() }; toNameFn.AddUpTimeRule_convertToDic(ref dic, newRule); opLog.content = toNameFn.AddUpTimeRule_convertToText(dic); saveOperateLog(opLog); //紀錄操作紀錄 } return(count); }
//in baseRepository /*public object GetAllTimeRule(){ * object result = null; * var query = (from a in _DbContext.worktimerules * orderby a.startTime * select new { * a.ID, a.name, a.startTime, a.endTime, a.restTime * }); * result = query.ToList(); * return result; * }*/ public bool chkSameWorkTime(WorkTimeRule newRule) { var query = _DbContext.worktimerules.FirstOrDefault( b => b.startTime == newRule.startTime && b.endTime == newRule.endTime); return((query == null || query.ID == newRule.ID)? false : true); }
private void calWorkTimeByID(PunchCardLog log, WorkTimeRule thisWorkTime) { var targetDate = log.logDate; var startDT = targetDate.AddDays(1 - targetDate.Day).Date; var endDT = startDT.AddMonths(1).AddDays(-1).Date; var thisMonthAllLog = Repository.GetPunchLogByDateByID(log.accountID, startDT, endDT); var otApplies = Repository.GetOvertimeApplyByDateByID(log.accountID, startDT, endDT); countWorkTime(thisMonthAllLog, otApplies, thisWorkTime, startDT); }
//正常打卡 public int punchCardProcess(PunchCardLog logData, WorkTimeRule thisWorkTime, int action, int employeeID) { WorkDateTime wt = workTimeProcess(thisWorkTime); //需new一個出來 用原本的logData會等於context,一旦修改logData之後query後的context也會是修改後的(雖然沒儲存所以資料庫沒變) PunchCardLog newLogData; int resultCount = 0; //0:操作異常 1:成功 if (logData == null) //今日皆未打卡 { newLogData = new PunchCardLog() { accountID = employeeID, departmentID = (int)loginDepartmentID, logDate = wt.sWorkDt.Date, lastOperaAccID = (int)loginID, onlineTime = definePara.dtNow(), createTime = definePara.dtNow() }; } else //今日有打過卡 or 電腦生成(跨日才有可能遇到) { newLogData = new PunchCardLog(); newLogData.ID = logData.ID; newLogData.accountID = logData.accountID; newLogData.departmentID = logData.departmentID; newLogData.logDate = logData.logDate; newLogData.onlineTime = logData.onlineTime; newLogData.offlineTime = logData.offlineTime; newLogData.punchStatus = logData.punchStatus; newLogData.createTime = logData.createTime; newLogData.lastOperaAccID = (int)loginID; newLogData.updateTime = definePara.dtNow(); if (newLogData.onlineTime.Year == 1 && newLogData.offlineTime.Year == 1) { newLogData.onlineTime = definePara.dtNow(); } else { newLogData.offlineTime = definePara.dtNow(); } } newLogData.punchStatus = getStatusCode(wt, newLogData); resultCount = newLogData.ID == 0? Repository.AddPunchCardLog(newLogData, true) : Repository.UpdatePunchCard(newLogData, true); if (resultCount == 1) //一定要新增log成功 不然會沒logID { if (newLogData.punchStatus > psCode.normal && newLogData.punchStatus != psCode.takeLeave) { Repository.AddPunchLogWarnAndMessage(newLogData); } else if (newLogData.punchStatus == psCode.normal) { Repository.delPunchLogWarnAndMessage(newLogData); } } return(resultCount); }
public int forceUpdatePunchCardLog(PunchCardLog updatePunchLog, string from) { if (updatePunchLog.ID == 0 || (updatePunchLog.onlineTime.Year == 1 && updatePunchLog.offlineTime.Year == 1)) { return(2); //此打卡紀錄不合法 } updatePunchLog.accountID = Repository.GetThisLogAccID(updatePunchLog.ID); WorkTimeRule thisWorkTime = Repository.GetThisWorkTime(updatePunchLog.accountID); return(punchCardFn.forcePunchLogProcess(updatePunchLog, thisWorkTime, "update", from)); }
public int forceAddPunchCardLog(PunchCardLog newPunchLog) { if (newPunchLog.accountID == 0 || (newPunchLog.onlineTime.Year == 1 && newPunchLog.offlineTime.Year == 1)) { return(2); //此打卡紀錄不合法 } WorkTimeRule thisWorkTime = Repository.GetThisWorkTime(newPunchLog.accountID); return(punchCardFn.forcePunchLogProcess(newPunchLog, thisWorkTime, "add")); }
public int addPunchCardLog(int action, int employeeID = 0) { if (employeeID == 0) { employeeID = (int)loginID; } WorkTimeRule thisWorkTime = Repository.GetThisWorkTime(employeeID); PunchCardLog logData = Repository.GetTodayPunchLog(employeeID, thisWorkTime); return(punchCardFn.punchCardProcess(logData, thisWorkTime, action, employeeID)); }
public void AddUpTimeRule_convertToDic(ref Dictionary <string, string> Dic, WorkTimeRule data) { data = (data == null? new WorkTimeRule() : data); Dic.Add("ruleName", data.name); Dic.Add("type", data.type == 1? "排休制":"固定制"); Dic.Add("sWorkTime", data.startTime.ToString(@"hh\:mm")); Dic.Add("eWorkTime", data.endTime.ToString(@"hh\:mm")); Dic.Add("sRestTime", data.sRestTime.ToString(@"hh\:mm")); Dic.Add("eRestTime", data.eRestTime.ToString(@"hh\:mm")); Dic.Add("elasticityMin", data.elasticityMin.ToString()); }
public bool chkDataLegal(WorkTimeRule data) { var wt = punchCardFn.workTimeProcess(data); var result = true; result = (wt.sWorkDt < wt.eWorkDt)? result : false; result = (wt.eWorkDt - wt.sWorkDt).TotalMinutes <= 720? result : false; //720mins = 12hours result = (wt.sRestDt > wt.sWorkDt && wt.sRestDt < wt.eWorkDt)? result : false; result = (wt.eRestDt > wt.sWorkDt && wt.eRestDt < wt.eWorkDt)? result : false; result = (wt.sRestDt <= wt.eRestDt)? result : false; return(result); }
private void punchCardProcess(int chkStatusDay) { List <PunchCardLog> warnLog = new List <PunchCardLog>(); warnLog = Repository.GetAllPunchLogWithWarn(chkStatusDay); foreach (PunchCardLog log in warnLog) { WorkTimeRule thisWorkTime = Repository.GetThisWorkTime(log.accountID); punchCardFn.processPunchlogWarn(log, thisWorkTime); //punchCardFn.processTakeLeaveWithLog(thisTakeLeave); } }
public PunchCardLog GetTodayPunchLog(int employeeID, WorkTimeRule thisWorkTime) { var wt = workTimeProcess(thisWorkTime); var query = (from a in _DbContext.punchcardlogs where a.accountID == employeeID && ( (a.onlineTime < wt.ePunchDT && a.onlineTime >= wt.sPunchDT) || (a.offlineTime <wt.ePunchDT && a.offlineTime> wt.sPunchDT) || (a.logDate.Date == wt.sWorkDt.Date && a.onlineTime.Year == 1 && a.offlineTime.Year == 1) ) select a).FirstOrDefault(); return(query); }
public void processPunchlogWarn(PunchCardLog log, WorkTimeRule thisWorkTime) //排程用 { WorkDateTime wt = workTimeProcess(thisWorkTime, log); if (definePara.dtNow() < wt.ePunchDT) { return; } log.punchStatus = getStatusCode(wt, log); log.lastOperaAccID = 0; Repository.UpdatePunchCard(log, true); if (log.punchStatus > 1 && log.punchStatus != psCode.takeLeave) { Repository.AddPunchLogWarnAndMessage(log); } }
public int UpdateTimeRule(WorkTimeRule updateData) { var oDic = new Dictionary <string, string> { }; var nDic = new Dictionary <string, string> { }; var opLog = new OperateLog() { operateID = updateData.lastOperaAccID, active = "更新", category = "工作時間設定", createTime = definePara.dtNow() }; int count = 0; try{ var context = _DbContext.worktimerules.FirstOrDefault(b => b.ID == updateData.ID); if (context != null) { toNameFn.AddUpTimeRule_convertToDic(ref oDic, context); context.name = updateData.name; context.type = updateData.type; context.startTime = updateData.startTime; context.endTime = updateData.endTime; context.sRestTime = updateData.sRestTime; context.eRestTime = updateData.eRestTime; context.elasticityMin = updateData.elasticityMin; context.lastOperaAccID = updateData.lastOperaAccID; context.updateTime = updateData.updateTime; count = _DbContext.SaveChanges(); if (count == 1) { toNameFn.AddUpTimeRule_convertToDic(ref nDic, context); opLog.content = toNameFn.AddUpTimeRule_convertToText(nDic, oDic); saveOperateLog(opLog); //紀錄操作紀錄 } } }catch (Exception e) { count = ((MySqlException)e.InnerException).Number; } return(count); }
private void calEmployeeWorkTime(int month) { var nMonth = (month > 12) || (month < 0)? 1 : month; var workEmployee = Repository.GetNeedPunchAcc("全體", 2, false); var dtNow = definePara.dtNow(); var startDT = dtNow.AddDays(1 - dtNow.Day).Date; var endDT = startDT.AddMonths(1).AddDays(-1).Date; var doCount = 1 + nMonth; for (var i = 0; i < doCount; i++) //計算這個月與上n個月 { foreach (var employee in workEmployee) { var thisMonthAllLog = Repository.GetPunchLogByDateByID(employee.ID, startDT, endDT); WorkTimeRule thisWorkTime = Repository.GetThisWorkTime(employee.ID); var otApplies = aRepository.GetOvertimeApplyByDateByID(employee.ID, startDT, endDT); punchCardFn.countWorkTime(thisMonthAllLog, otApplies, thisWorkTime, startDT); } startDT = startDT.AddMonths(-1).Date; endDT = startDT.AddMonths(1).AddDays(-1).Date; } }
//--------------------------------------------------------------------------------------- public object getTodayPunchStatus() //look my today PunchStatus { WorkTimeRule thisWorkTime = Repository.GetThisWorkTime((int)loginID); var dataLog = Repository.GetTodayPunchLog((int)loginID, thisWorkTime); if (dataLog == null) { dataLog = new PunchCardLog(); } dynamic onlineTime = dataLog.onlineTime; dynamic offlineTime = dataLog.offlineTime; if (onlineTime.Year == 1) { onlineTime = false; } if (offlineTime.Year == 1) { offlineTime = false; } return(new { onlineTime = onlineTime, offlineTime = offlineTime, }); }
//正常打卡 public int punchCardProcess(PunchCardNeedParam logParam, int action, int employeeID) { WorkTimeRule thisWorkTime = logParam.thisWorkTime; PunchCardLog logData = logParam.punchCardLog; WorkDateTime wt = logParam.workDateTime; //需new一個出來 用原本的logData會等於context,一旦修改logData之後query後的context也會是修改後的(雖然沒儲存所以資料庫沒變) PunchCardLog newLogData; DateTime dtNow = definePara.dtNow(); int resultCount = 0; //0:操作異常 1:成功 if (action == 1) //action = 1 提早打上班卡 { newLogData = new PunchCardLog() { ID = logData.ID, accountID = employeeID, departmentID = (int)loginDepartmentID, logDate = logData.logDate, lastOperaAccID = (int)loginID, onlineTime = dtNow, createTime = dtNow }; } else if (action == 0 && logData == null) //action = 0 正常打卡或打下班卡 // { newLogData = new PunchCardLog() { accountID = employeeID, departmentID = (int)loginDepartmentID, logDate = wt.sWorkDt.Date, lastOperaAccID = (int)loginID, createTime = dtNow }; if (dtNow >= wt.ePunchDT) //在模糊區段 打下班卡 { newLogData.offlineTime = dtNow; } else //非模糊區段 若上班卡沒打會先打上班卡 之後需要打一次下班卡 { newLogData.onlineTime = dtNow; } } else { newLogData = new PunchCardLog(); newLogData.ID = logData.ID; newLogData.accountID = logData.accountID; newLogData.departmentID = logData.departmentID; newLogData.logDate = logData.logDate; newLogData.onlineTime = logData.onlineTime; newLogData.offlineTime = logData.offlineTime; newLogData.punchStatus = logData.punchStatus; newLogData.createTime = logData.createTime; newLogData.lastOperaAccID = (int)loginID; newLogData.updateTime = dtNow; if (dtNow >= wt.ePunchDT || logData.onlineTime.Year > 1) { newLogData.offlineTime = dtNow; } else { newLogData.onlineTime = dtNow; } } logParam.punchCardLog = newLogData; logParam.workDateTime = workTimeProcess(thisWorkTime, newLogData); newLogData.punchStatus = getStatusCode(logParam); resultCount = newLogData.ID == 0? Repository.AddPunchCardLog(newLogData, true) : Repository.UpdatePunchCard(newLogData, true); if (resultCount == 1) //一定要新增log成功 不然會沒logID { if (newLogData.punchStatus > psCode.normal && newLogData.punchStatus != psCode.takeLeave) { Repository.AddPunchLogWarnAndMessage(newLogData); } else if (newLogData.punchStatus == psCode.normal) { Repository.delPunchLogWarnAndMessage(newLogData); } if (action == 1) //提早打上班卡 通知主管 { var accDetail = Repository.GetAccountDetail(newLogData.accountID); var userName = (string)accDetail.GetType().GetProperty("userName").GetValue(accDetail); //obj.GetType().GetProperty(key).GetValue(obj); Repository.systemSendMessage(userName, newLogData.accountID, "earlyPunch"); } } return(resultCount); }
public WorkDateTime workTimeProcess(WorkTimeRule thisWorkTime, PunchCardLog customLog = null) { return(Repository.workTimeProcess(thisWorkTime, customLog)); }
public List <LeaveOfficeApply> getThisAccLeaves(List <PunchCardLog> thisMonthAllLog, WorkTimeRule thisWorkTime, DateTime startDT) { if (thisMonthAllLog.Count == 0) { return(new List <LeaveOfficeApply>()); } var sDT = startDT; var eDT = startDT.AddMonths(1).AddDays(-1).Date; return(Repository.GetThisTakeLeave(thisMonthAllLog[0].accountID, sDT, eDT)); }
public void countWorkTime(List <PunchCardLog> thisMonthAllLog, List <OvertimeApply> otApplies, WorkTimeRule thisWorkTime, DateTime startDT) { var totalTimeMinute = 0.0; var totalOvertimeMinute = 0; var restTimeMinute = 0.0; var endStartWorkTimeMinute = 0.0; var noRestWorkTimeMinute = 0.0; var sWorkTime = thisWorkTime.startTime; //只取時間 var eWorkTime = thisWorkTime.endTime; var sRestTime = thisWorkTime.sRestTime; var eRestTime = thisWorkTime.eRestTime; var restlength = TimeSpan.Zero; var thisAccLeaves = getThisAccLeaves(thisMonthAllLog, thisWorkTime, startDT); if (eRestTime < sRestTime) { restlength = eRestTime.Add(new TimeSpan(24, 0, 0)) - sRestTime; } else { restlength = eRestTime - sRestTime; } restTimeMinute = restlength.TotalMinutes; var endStartLength = TimeSpan.Zero; if (eWorkTime < sWorkTime) { endStartLength = eWorkTime.Add(new TimeSpan(24, 0, 0)) - sWorkTime; } else { endStartLength = eWorkTime - sWorkTime; } endStartWorkTimeMinute = endStartLength.TotalMinutes; noRestWorkTimeMinute = (endStartWorkTimeMinute - restTimeMinute); foreach (var log in thisMonthAllLog) { if (log.onlineTime.Year == 1 || log.offlineTime.Year == 1 || log.onlineTime >= log.offlineTime) { continue; } WorkDateTime workTime = workTimeProcess(thisWorkTime, log); //計算工作時間 if (log.onlineTime <= workTime.sRestDt && log.offlineTime >= workTime.eRestDt) { totalTimeMinute += (int)((log.offlineTime - log.onlineTime).TotalMinutes) - restTimeMinute; } else if (log.onlineTime < workTime.sRestDt && log.offlineTime <= workTime.eRestDt) { if (log.offlineTime < workTime.sRestDt) { totalTimeMinute += (int)(log.offlineTime - log.onlineTime).TotalMinutes; } else { totalTimeMinute += (int)(workTime.sRestDt - log.onlineTime).TotalMinutes; } } else if (log.onlineTime >= workTime.sRestDt && log.offlineTime > workTime.eRestDt) { if (log.onlineTime > workTime.eRestDt) { totalTimeMinute += (int)(log.offlineTime - log.onlineTime).TotalMinutes; } else { totalTimeMinute += (int)(log.offlineTime - workTime.eRestDt).TotalMinutes; } } foreach (var leave in thisAccLeaves) //工作時間需會扣掉請假時間 { if (leave.startTime >= workTime.sWorkDt && leave.endTime <= workTime.eWorkDt && leave.unit == 3) //只處理單位為小時的請假 { if (leave.startTime > workTime.sWorkDt && leave.endTime < workTime.eWorkDt) { totalTimeMinute -= leave.unitVal * 60; } } } } foreach (var apply in otApplies) //計算加班 { totalOvertimeMinute += apply.timeLength; } if (thisMonthAllLog.Count > 0) { saveTotalTimeRecord(thisMonthAllLog[0].accountID, startDT, totalTimeMinute, totalOvertimeMinute); } }
public int forcePunchLogProcess(PunchCardLog processLog, WorkTimeRule thisWorkTime, string action, string from = "") { WorkDateTime wt = workTimeProcess(thisWorkTime, processLog); var et_big_st = thisWorkTime.endTime >= thisWorkTime.startTime? true: false; processLog.logDate = wt.sWorkDt.Date; processLog.lastOperaAccID = (int)loginID; if (action == "update") { processLog.updateTime = definePara.dtNow(); } else { processLog.createTime = definePara.dtNow(); } if (processLog.onlineTime.Year != 1) { if (processLog.onlineTime < wt.sPunchDT) //2300-0800 if write 0000-0800 { processLog.onlineTime = processLog.onlineTime.AddDays(1); } if (processLog.onlineTime >= wt.ePunchDT) //0000-0800 if write 2355-0800 { processLog.onlineTime = processLog.onlineTime.AddDays(-1); } } if (processLog.offlineTime.Year != 1) { if (processLog.offlineTime <= wt.sWorkDt) //2300-0800 if write 2300-0800 { processLog.offlineTime = processLog.offlineTime.AddDays(1); } } if (et_big_st && processLog.onlineTime.Year != 1 && processLog.offlineTime.Year != 1) { if (processLog.onlineTime >= processLog.offlineTime) { processLog.onlineTime = processLog.onlineTime.AddDays(-1); } } else if (!et_big_st && processLog.onlineTime.Year != 1 && processLog.offlineTime.Year != 1) { if (processLog.offlineTime <= processLog.onlineTime) { processLog.offlineTime = processLog.offlineTime.AddDays(1); } } processLog.punchStatus = getStatusCode(wt, processLog); int result = action == "update"? Repository.UpdatePunchCard(processLog, false) : Repository.AddPunchCardLog(processLog, false); if (result == 1) { if (processLog.punchStatus > psCode.normal && processLog.punchStatus != psCode.takeLeave) { Repository.AddPunchLogWarnAndMessage(processLog); } if (action == "update" && from == "applySign") { Repository.UpdatePunchLogWarn(processLog.ID); } } return(result); }
public WorkDateTime workTimeProcess(WorkTimeRule thisWorkTime, PunchCardLog customLog = null) { var wt = new WorkDateTime(); wt.sWorkDt = definePara.dtNow().Date; //online work dateTime wt.eWorkDt = definePara.dtNow().Date; //offline work dateTime wt.sPunchDT = definePara.dtNow().Date; //可打卡時間 wt.ePunchDT = definePara.dtNow().Date; // var sRest_start = new TimeSpan(0); var eRest_sRest = new TimeSpan(0); if (customLog != null) { if (customLog.logDate.Year != 1) { wt.sWorkDt = wt.eWorkDt = wt.sPunchDT = wt.ePunchDT = customLog.logDate.Date; } else if (customLog.onlineTime.Year != 1) { wt.sWorkDt = wt.eWorkDt = wt.sPunchDT = wt.ePunchDT = customLog.onlineTime.Date; } else if (customLog.offlineTime.Year != 1) { wt.sWorkDt = wt.eWorkDt = wt.sPunchDT = wt.ePunchDT = customLog.offlineTime.Date; } } if (thisWorkTime != null) { var eWork_sWork = thisWorkTime.endTime - thisWorkTime.startTime; eWork_sWork = eWork_sWork.TotalSeconds < 0? eWork_sWork.Add(new TimeSpan(1, 0, 0, 0)) : eWork_sWork; wt.addEtHour = (int)(24 * 60 + wt.lessStHour - eWork_sWork.TotalMinutes); //單位改為分鐘 sRest_start = thisWorkTime.sRestTime - thisWorkTime.startTime; sRest_start = sRest_start.TotalSeconds < 0? sRest_start.Add(new TimeSpan(1, 0, 0, 0)) : sRest_start; eRest_sRest = thisWorkTime.eRestTime - thisWorkTime.sRestTime; eRest_sRest = eRest_sRest.TotalSeconds < 0? eRest_sRest.Add(new TimeSpan(1, 0, 0, 0)) : eRest_sRest; wt.type = thisWorkTime.type; wt.workAllTime = false; wt.sWorkDt = wt.sWorkDt + thisWorkTime.startTime; wt.eWorkDt = wt.eWorkDt + thisWorkTime.endTime; wt.eWorkDt = wt.eWorkDt <= wt.sWorkDt ? wt.eWorkDt.AddDays(1) : wt.eWorkDt; wt.sPunchDT = wt.sWorkDt.AddMinutes(wt.lessStHour); wt.ePunchDT = wt.eWorkDt.AddMinutes(wt.addEtHour); wt.elasticityMin = thisWorkTime.elasticityMin; if (customLog == null) { if (definePara.dtNow() >= wt.ePunchDT) { wt.sPunchDT = wt.sPunchDT.AddDays(1); wt.ePunchDT = wt.ePunchDT.AddDays(1); wt.sWorkDt = wt.sPunchDT.AddMinutes((wt.lessStHour * -1)); wt.eWorkDt = wt.ePunchDT.AddMinutes((wt.addEtHour * -1)); } else if (definePara.dtNow() < wt.sPunchDT) { wt.sPunchDT = wt.sPunchDT.AddDays(-1); wt.ePunchDT = wt.ePunchDT.AddDays(-1); wt.sWorkDt = wt.sPunchDT.AddMinutes((wt.lessStHour * -1)); wt.eWorkDt = wt.ePunchDT.AddMinutes((wt.addEtHour * -1)); } } } else { wt.workAllTime = true; wt.eWorkDt = wt.eWorkDt.AddDays(1); wt.ePunchDT = wt.ePunchDT.AddDays(1); } wt.sRestDt = wt.sWorkDt.AddMinutes(sRest_start.TotalMinutes); wt.eRestDt = wt.sRestDt.AddMinutes(eRest_sRest.TotalMinutes); return(wt); }
public WorkDateTime workTimeProcess(WorkTimeRule thisWorkTime, PunchCardLog customLog = null) { var wt = new WorkDateTime(); var dtNow = definePara.dtNow(); wt.sWorkDt = dtNow.Date; //online work dateTime wt.eWorkDt = dtNow.Date; //offline work dateTime var eWork_sWork = new TimeSpan(0); var sRest_start = new TimeSpan(0); var eRest_sRest = new TimeSpan(0); if (customLog != null) { if (customLog.logDate.Year != 1) { wt.sWorkDt = wt.eWorkDt = customLog.logDate.Date; } else if (customLog.onlineTime.Year != 1) { wt.sWorkDt = wt.eWorkDt = customLog.onlineTime.Date; } else if (customLog.offlineTime.Year != 1) { wt.sWorkDt = wt.eWorkDt = customLog.offlineTime.Date; } } if (thisWorkTime != null) { eWork_sWork = thisWorkTime.endTime - thisWorkTime.startTime; eWork_sWork = eWork_sWork.TotalSeconds < 0? eWork_sWork.Add(new TimeSpan(1, 0, 0, 0)) : eWork_sWork; // wt.addEtHour = (int)(24*60 + wt.lessStHour - eWork_sWork.TotalMinutes); //單位改為分鐘 sRest_start = thisWorkTime.sRestTime - thisWorkTime.startTime; sRest_start = sRest_start.TotalSeconds < 0? sRest_start.Add(new TimeSpan(1, 0, 0, 0)) : sRest_start; eRest_sRest = thisWorkTime.eRestTime - thisWorkTime.sRestTime; eRest_sRest = eRest_sRest.TotalSeconds < 0? eRest_sRest.Add(new TimeSpan(1, 0, 0, 0)) : eRest_sRest; wt.type = thisWorkTime.type; wt.workAllTime = false; wt.sWorkDt = wt.sWorkDt + thisWorkTime.startTime; wt.eWorkDt = wt.eWorkDt + thisWorkTime.endTime; wt.eWorkDt = wt.eWorkDt <= wt.sWorkDt ? wt.eWorkDt.AddDays(1) : wt.eWorkDt; wt.sPunchDT = wt.sWorkDt.AddMinutes(wt.lessStHour); wt.ePunchDT = wt.eWorkDt.AddMinutes(wt.addEtHour); wt.elasticityMin = thisWorkTime.elasticityMin; if (customLog == null) { if (dtNow < wt.sPunchDT && dtNow < wt.ePunchDT.AddDays(-1)) //2300-0800 0830打卡 { wt.sWorkDt = wt.sWorkDt.AddDays(-1); wt.eWorkDt = wt.eWorkDt.AddDays(-1); wt.sPunchDT = wt.sWorkDt.AddMinutes(wt.lessStHour); wt.ePunchDT = wt.eWorkDt.AddMinutes(wt.addEtHour); } else if (dtNow < wt.sPunchDT && dtNow >= wt.ePunchDT.AddDays(-1)) { //ambiguous //目前工作日判斷,把位於模糊區域的時間,以某工作日的加班來處理 wt.sWorkDt = wt.sWorkDt.AddDays(-1); wt.eWorkDt = wt.eWorkDt.AddDays(-1); wt.sPunchDT = wt.sWorkDt.AddMinutes(wt.lessStHour); wt.ePunchDT = wt.eWorkDt.AddMinutes(wt.addEtHour); } else if (dtNow >= wt.ePunchDT && dtNow >= wt.sPunchDT.AddDays(1)) //0000-0800 2330打卡 { wt.sWorkDt = wt.sWorkDt.AddDays(1); wt.eWorkDt = wt.eWorkDt.AddDays(1); wt.sPunchDT = wt.sWorkDt.AddMinutes(wt.lessStHour); wt.ePunchDT = wt.eWorkDt.AddMinutes(wt.addEtHour); } else if (dtNow >= wt.ePunchDT && dtNow < wt.sPunchDT.AddDays(1)) { //ambiguous //目前工作日判斷,把位於模糊區域的時間,以某工作日的加班來處理 //不處理 } } } else { wt.workAllTime = true; wt.sPunchDT = wt.sWorkDt; wt.eWorkDt = wt.sWorkDt.AddDays(1); wt.ePunchDT = wt.eWorkDt; } wt.sRestDt = wt.sWorkDt.AddMinutes(sRest_start.TotalMinutes); wt.eRestDt = wt.sRestDt.AddMinutes(eRest_sRest.TotalMinutes); return(wt); }
public bool chkApplyOvertimeData(OvertimeApply data) { var result = true; var punchLog = _DbContext.punchcardlogs.FirstOrDefault(b => b.accountID == data.accountID && b.logDate == data.workDate); if (punchLog == null) { result = false; } else { result = punchLog.onlineTime.Year > 1 && punchLog.offlineTime.Year > 1? result : false; } //計算加班長度 WorkTimeRule thisWorkTime = pRepository.GetThisWorkTime(data.accountID); PunchCardLog tmpLog = new PunchCardLog() { logDate = data.workDate }; WorkDateTime workTime = punchCardFn.workTimeProcess(thisWorkTime, tmpLog); var sRestTime = thisWorkTime.sRestTime; var eRestTime = thisWorkTime.eRestTime; var restTimeMinute = 0; var restlength = TimeSpan.Zero; if (eRestTime < sRestTime) { restlength = eRestTime.Add(new TimeSpan(24, 0, 0)) - sRestTime; } else { restlength = eRestTime - sRestTime; } restTimeMinute = (int)restlength.TotalMinutes; var st = data.startDateTime; var et = data.endDateTime; var overLength = 0; //加班長度 if (st <= workTime.sRestDt && et >= workTime.eRestDt) { overLength = (int)((et - st).TotalMinutes) - restTimeMinute; } else if (st < workTime.sRestDt && et <= workTime.eRestDt) { if (et < workTime.sRestDt) { overLength = (int)(et - st).TotalMinutes; } else { overLength = (int)(workTime.sRestDt - st).TotalMinutes; } } else if (st >= workTime.sRestDt && et > workTime.eRestDt) { if (st > workTime.eRestDt) { overLength = (int)(et - st).TotalMinutes; } else { overLength = (int)(et - workTime.eRestDt).TotalMinutes; } } overLength = (overLength / 30) * 30; //以半小時的倍數為準 result = overLength >= 30? result : false; data.timeLength = overLength; return(result); }