Beispiel #1
0
        public void refreshOvertimeRest(OvertimeApply data, int status)     //0:none / 1:add / 2:less
        {
            if (status == 0)
            {
                return;
            }
            var timeLength = data.timeLength;
            var context    = _DbContext.overTimeRest.FirstOrDefault(b => b.accountID == data.accountID);

            if (context == null)
            {
                context = new OverTimeRest {
                    accountID  = data.accountID, lastOperaAccID = data.lastOperaAccID,
                    createTime = definePara.dtNow(), updateTime = definePara.dtNow()
                };
                context.canRestTime = status == 1? timeLength : 0;
                _DbContext.overTimeRest.Add(context);
            }
            else
            {
                context.lastOperaAccID = data.lastOperaAccID;
                context.updateTime     = definePara.dtNow();
                if (status == 1)
                {
                    context.canRestTime += timeLength;
                }
                else if (status == 2)
                {
                    context.canRestTime -= timeLength;
                    context.canRestTime  = context.canRestTime < 0? 0 : context.canRestTime;
                }
            }
            _DbContext.SaveChanges();
        }
Beispiel #2
0
        public void refreshEmployeeOvertimeRest(LeaveOfficeApply context, int status)
        {
            var applyHours       = getApplyHours(context);
            var tmpOvertimeApply = new OvertimeApply {
                accountID      = context.accountID,
                timeLength     = Convert.ToInt32(applyHours * 60),
                lastOperaAccID = context.lastOperaAccID,
            };

            refreshOvertimeRest(tmpOvertimeApply, status);
        }
 public void IsAgreeOvertime_convertToDic(ref Dictionary <string, string> Dic, OvertimeApply apply)
 {
     if (apply == null)
     {
         apply = new OvertimeApply();
     }
     Dic.Add("applyDate", apply.createTime.ToString("yyyy-MM-dd HH:mm"));
     Dic.Add("workDate", apply.workDate.ToString("yyyy-MM-dd"));
     Dic.Add("timeLength", apply.timeLength.ToString());
     Dic.Add("applyStatus", apply.applyStatus == 0? "待審核" : apply.applyStatus == 1? "通過" : "未通過");
 }
        public object addUpApplyOvertime(OvertimeApply data)
        {
            var result = 0;

            if (data.ID == 0)
            {
                data.accountID = data.lastOperaAccID = (int)loginID;
                if (!Repository.chkApplyOvertimeData(data))
                {
                    return(cudAjaxResult(MessageCode.ApplyOverTime_Illegal));
                }
                result = Repository.CreateApplyOvertime(data, loginName);
            }
            return(cudAjaxResult(result));
        }
        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? true : false;
            }
            return(result);
        }
        public dynamic addUpApplyOvertime(OvertimeApply data)
        {
            int result = 0;

            if (data.ID == 0)
            {
                data.accountID = data.lastOperaAccID = (int)loginID;
                if (!Repository.chkApplyOvertimeData(data))
                {
                    return("data_illegal");
                }
                result = Repository.CreateApplyOvertime(data, loginName);
            }
            return(result);
        }
 public int CreateApplyOvertime(OvertimeApply newApply, String loginName)
 {
     using (var trans = _DbContext.Database.BeginTransaction()){
         var count = 0;
         try
         {
             newApply.createTime = newApply.updateTime = definePara.dtNow();
             _DbContext.overtimeApply.Add(newApply);
             count = _DbContext.SaveChanges();
             if (count == 1)
             {
                 systemSendMessage(loginName, newApply.accountID, "overtime");
             }
             trans.Commit();
         }
         catch (Exception ex) {
             count = catchErrorProcess(ex, count);
         }
         return(count);
     }
 }
        public void refreshEmployeeOvertime(OvertimeApply context)
        {
            var accID      = context.accountID;
            var targetDate = context.workDate;
            var sDate      = targetDate.AddDays(1 - targetDate.Day).Date;
            var eDate      = sDate.AddMonths(1).AddDays(-1).Date;

            var otApplies = _DbContext.overtimeApply.Where(
                b => b.accountID == accID && b.applyStatus == 1 &&
                b.workDate >= sDate && b.workDate <= eDate)
                            .OrderBy(b => b.workDate).ToList();

            var totalOvertimeMinute = 0;

            foreach (var apply in otApplies)                //計算加班
            {
                totalOvertimeMinute += apply.timeLength;
            }
            var workTimeTotal = _DbContext.worktimetotals.FirstOrDefault(
                b => b.accountID == accID &&  b.dateMonth == sDate);

            if (workTimeTotal == null)
            {
                var timeRecord = new workTimeTotal();
                timeRecord.accountID     = accID;
                timeRecord.dateMonth     = sDate;
                timeRecord.totalOvertime = totalOvertimeMinute;
                timeRecord.createTime    = definePara.dtNow();
                _DbContext.worktimetotals.Add(timeRecord);
                _DbContext.SaveChanges();
            }
            else
            {
                workTimeTotal.totalOvertime = totalOvertimeMinute;
                workTimeTotal.updateTime    = definePara.dtNow();
                _DbContext.SaveChanges();
            }
        }
        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);
        }