Example #1
0
def SaveTempSch(userid, st, et, SchedulerShifts):
    from mysite.att.models.user_temp_sch import USER_TEMP_SCH
    from mysite.personnel.models.model_emp import Employee
    from mysite.iclock.sql import SaveTempSch_sql
    sql = SaveTempSch_sql(userid, st, et)
    customSql(sql)
    #print 'SchedulerShifts',SchedulerShifts
    for t in SchedulerShifts:
        if (t['TimeZone']['EndTime'] <
                st) or (t['TimeZone']['StartTime'] >=
                        (et + datetime.timedelta(days=1))):
            continue
        else:
            x = USER_TEMP_SCH()
            x.UserID = Employee.objects.get(pk=userid)
            x.ComeTime = t['TimeZone']['StartTime'].strftime(
                "%Y-%m-%d %H:%M:%S")
            x.LeaveTime = t['TimeZone']['EndTime'].strftime(
                "%Y-%m-%d %H:%M:%S")
            x.SchclassID = t['schClassID']
            x.OverTime = t['OverTime']
            x.save()
#                        sql=getSQL_insert(USER_TEMP_SCH._meta.db_table,userid=userid,comeTime=t['TimeZone']['StartTime'].strftime("%Y-%m-%d %H:%M:%S"),leavetime=t['TimeZone']['EndTime'].strftime("%Y-%m-%d %H:%M:%S"),
#                                      schclassid=t['schClassID'],overtime=t['OverTime'])
#
#                        customSql(sql)

    j = st

    while j <= et:
        m = 0
        for t in SchedulerShifts:
            m = 0
            if (j <= t['TimeZone']['StartTime']) and (j + datetime.timedelta(
                    days=1) > t['TimeZone']['StartTime']):
                m = 1
                break
        if m == 0:
            x = USER_TEMP_SCH()
            x.UserID = Employee.objects.get(pk=userid)
            x.ComeTime = (
                j + datetime.timedelta(hours=12)).strftime("%Y-%m-%d %H:%M:%S")
            x.LeaveTime = (
                j + datetime.timedelta(hours=12)).strftime("%Y-%m-%d %H:%M:%S")
            # x.SchclassID=t['schClassID']
            x.OverTime = 0
            x.save()
            #


#                        sql=getSQL_insert(USER_TEMP_SCH._meta.db_table,userid=userid,comeTime=(j+datetime.timedelta(hours=12)).strftime("%Y-%m-%d %H:%M:%S"),leavetime=(j+datetime.timedelta(hours=12)).strftime("%Y-%m-%d %H:%M:%S"),overtime=0)
#                        customSql(sql)

        j = j + datetime.timedelta(days=1)
    deleteCalcLog(UserID=userid)
Example #2
0
def SaveTempSch(userid,st,et,SchedulerShifts):
        from mysite.att.models.user_temp_sch import USER_TEMP_SCH
        from mysite.personnel.models.model_emp import Employee
        sql="delete from %s where userid=%s and leavetime>='%s' and cometime<'%s' and cometime>='%s'"%(USER_TEMP_SCH._meta.db_table,userid,st,et+datetime.timedelta(days=1),st)
        customSql(sql)
        #print 'SchedulerShifts',SchedulerShifts
        for t in SchedulerShifts:
                if (t['TimeZone']['EndTime']<st) or (t['TimeZone']['StartTime']>=(et+datetime.timedelta(days=1))):
                        continue
                else:
                    x=USER_TEMP_SCH()
                    x.UserID=Employee.objects.get(pk=userid)
                    x.ComeTime=t['TimeZone']['StartTime'].strftime("%Y-%m-%d %H:%M:%S")
                    x.LeaveTime=t['TimeZone']['EndTime'].strftime("%Y-%m-%d %H:%M:%S")
                    x.SchclassID=t['schClassID']
                    x.OverTime=t['OverTime']
                    x.save()
#                        sql=getSQL_insert(USER_TEMP_SCH._meta.db_table,userid=userid,comeTime=t['TimeZone']['StartTime'].strftime("%Y-%m-%d %H:%M:%S"),leavetime=t['TimeZone']['EndTime'].strftime("%Y-%m-%d %H:%M:%S"),
#                                      schclassid=t['schClassID'],overtime=t['OverTime'])
#                        
#                        customSql(sql)
        
        j=st
        
        while j<=et:
                m=0
                for t in SchedulerShifts:
                        m=0
                        if (j<=t['TimeZone']['StartTime']) and (j+datetime.timedelta(days=1)>t['TimeZone']['StartTime']):
                                m=1
                                break        
                if m==0:
                    x=USER_TEMP_SCH()
                    x.UserID=Employee.objects.get(pk=userid)
                    x.ComeTime=(j+datetime.timedelta(hours=12)).strftime("%Y-%m-%d %H:%M:%S")
                    x.LeaveTime=(j+datetime.timedelta(hours=12)).strftime("%Y-%m-%d %H:%M:%S")
                   # x.SchclassID=t['schClassID']
                    x.OverTime=0
                    x.save()
                    #
                    
#                        sql=getSQL_insert(USER_TEMP_SCH._meta.db_table,userid=userid,comeTime=(j+datetime.timedelta(hours=12)).strftime("%Y-%m-%d %H:%M:%S"),leavetime=(j+datetime.timedelta(hours=12)).strftime("%Y-%m-%d %H:%M:%S"),overtime=0)
#                        customSql(sql)
                        
                j=j+datetime.timedelta(days=1)
        deleteCalcLog(UserID=userid)
Example #3
0
        def action(self, UserID, StartDate, EndDate, WorkType):
            from mysite.personnel.models.model_emp import Employee
            from mysite.att.models.schclass import SchClass
            from mysite.att.models.user_temp_sch import USER_TEMP_SCH
            import datetime
            from mysite.personnel.models import Department
            if self.request:

                #addTemparyShifts(self.request)
                st = self.request.POST.get('StartDate', "")
                et = self.request.POST.get('EndDate', "")
                start = st.replace("/", "-")
                endt = et.replace("/", "-")
                chklbSchClass = self.request.POST.getlist("sTimeTbl")
                chklbDates = self.request.POST.getlist("sDates")
                OverTime = self.request.POST.get('OverTime', '')
                users = UserID

                flag = self.request.POST.get('Flag', '1')
                #print 'flag:%s'%flag
                is_OT = self.request.POST.get('is_OT', '')
                is_OT = (str(is_OT) == 'on')

                #                #获取用户
                #                if len(UserIDs)>0:
                #                    users=Employee.objects.filter(id__in=UserIDs)
                #                else:
                #                    if dept_all:
                #                       users=Employee.objects.filter(DeptID__in=deptIDs)
                #                    else:
                #                        users=[]

                if not users:
                    raise Exception(_(u'请选择人员'))
                if len(users) > 1000:
                    raise Exception(_(u'人员选择过多,最大支持1000人同时新增记录!'))
                if not chklbDates:
                    raise Exception(_(u'请选择日期'))
                if not chklbSchClass:
                    raise Exception(_(u'请选择时段'))
                #获取时间段
                schs = SchClass.objects.filter(pk__in=chklbSchClass)
                #                for sch in schs:
                #                    st=datetime.strptime(start+' '+ sch.StartTime.strftime('%H:%M:%S'),"%Y-%m-%d %H:%M:%S")
                #                    et=datetime.strptime(endt+' '+ sch.EndTime.strftime('%H:%M:%S'),"%Y-%m-%d %H:%M:%S")
                #
                #                    for u in users:
                #
                #                        sql="delete from %s where UserID=%s and SchClassID=%s and ComeTime>='%s' and LeaveTime<='%s'"%( USER_TEMP_SCH._meta.db_table,
                #                                                                      u.pk,sch.pk,st.strftime("%Y-%m-%d %H:%M:%S"),et.strftime("%Y-%m-%d %H:%M:%S"))
                #                        print "sql:%s"%sql
                #                        customSql(sql)
                #
                #循环保存临时排班
                for day in chklbDates:
                    day = day.replace("/", "-")

                    for sch in schs:

                        #格式化时间
                        st = datetime.datetime.strptime(
                            day + ' ' + sch.StartTime.strftime('%H:%M:%S'),
                            '%Y-%m-%d %H:%M:%S')
                        et = datetime.datetime.strptime(
                            day + ' ' + sch.EndTime.strftime('%H:%M:%S'),
                            '%Y-%m-%d %H:%M:%S')

                        if et < st:  #判断时间段是否跨天
                            et = et + datetime.timedelta(days=1)

                        #清除已经排过的临时排班
                        #USER_TEMP_SCH.objects.filter(UserID__in=users,SchclassID__exact=sch.pk,ComeTime__exact=st,LeaveTime__exact=et).delete()

                        #保存
                        for u in users:
                            USER_TEMP_SCH.objects.filter(
                                UserID__exact=u,
                                SchclassID__exact=sch.pk,
                                ComeTime__exact=st,
                                LeaveTime__exact=et).delete()
                            t = USER_TEMP_SCH()
                            t.UserID = u
                            t.ComeTime = st
                            t.LeaveTime = et
                            t.WorkType = WorkType
                            t.Flag = flag
                            if is_OT:
                                t.OverTime = OverTime
                            t.SchclassID = sch.pk
                            t.save()
Example #4
0
         def action(self,UserID,StartDate,EndDate,WorkType):
            from mysite.att.models.schclass import SchClass
            from mysite.att.models.user_temp_sch import USER_TEMP_SCH
            import datetime
            from mysite.personnel.models import Department
            if self.request:
                
                st=self.request.POST.get('StartDate',"")
                et=self.request.POST.get('EndDate',"")
                start=st.replace("/","-")
                endt=et.replace("/","-")
                chklbSchClass=self.request.POST.getlist("sTimeTbl")
                chklbDates=self.request.POST.getlist("sDates")
                OverTime=self.request.POST.get('OverTime','')
                deptIDs=self.request.POST.getlist('deptIDs')
                UserIDs=self.request.POST.getlist('UserID')  
                dept_all=self.request.POST.get('dept_all','')    
                flag=self.request.POST.get('Flag','1')    
                is_OT=self.request.POST.get('is_OT','')
                is_OT=(str(is_OT)=='on')
                
                if len(UserIDs)>0:
                    users=Employee.objects.filter(id__in=UserIDs)
                else:
                    if dept_all:
                       users=Employee.objects.filter(DeptID__in=deptIDs)
                    else:
                        users=[]
                    
                if not users:
                    raise Exception(_(u'请选择人员'))
                if not chklbDates:
                    raise Exception(_(u'请选择日期'))
                if not chklbSchClass:
                    raise Exception(_(u'请选择时段'))
                #获取时间段
                schs=SchClass.objects.filter(pk__in=chklbSchClass)
                #循环保存临时排班
                for day in chklbDates:
                    day=day.replace("/","-")
                    
                    for sch in schs:

                        #格式化时间
                        st=datetime.datetime.strptime(day+' '+sch.StartTime.strftime('%H:%M:%S'),'%Y-%m-%d %H:%M:%S')
                        et=datetime.datetime.strptime(day+' '+sch.EndTime.strftime('%H:%M:%S'),'%Y-%m-%d %H:%M:%S')
                        
                        if et<st:           #判断时间段是否跨天
                            et=et+datetime.timedelta(days=1)
                        
                        
                        #保存
                        for u in users:    
                            USER_TEMP_SCH.objects.filter(UserID__exact=u,SchclassID__exact=sch.pk,ComeTime__exact=st,LeaveTime__exact=et).delete()
                            t=USER_TEMP_SCH()
                            t.UserID=u
                            t.ComeTime=st
                            t.LeaveTime=et
                            t.WorkType=WorkType
                            t.Flag=flag
                            if is_OT:
                                t.OverTime=OverTime                            
                            t.SchclassID=sch.pk
                            t.save()
Example #5
0
        def action(self, UserID, StartDate, EndDate, WorkType):
            from mysite.att.models.schclass import SchClass
            from mysite.att.models.user_temp_sch import USER_TEMP_SCH
            import datetime
            from mysite.personnel.models import Department
            if self.request:

                st = self.request.POST.get('StartDate', "")
                et = self.request.POST.get('EndDate', "")
                start = st.replace("/", "-")
                endt = et.replace("/", "-")
                chklbSchClass = self.request.POST.getlist("sTimeTbl")
                chklbDates = self.request.POST.getlist("sDates")
                OverTime = self.request.POST.get('OverTime', '')
                deptIDs = self.request.POST.getlist('deptIDs')
                UserIDs = self.request.POST.getlist('UserID')
                dept_all = self.request.POST.get('dept_all', '')
                flag = self.request.POST.get('Flag', '1')
                is_OT = self.request.POST.get('is_OT', '')
                is_OT = (str(is_OT) == 'on')

                if len(UserIDs) > 0:
                    users = Employee.objects.filter(id__in=UserIDs)
                else:
                    if dept_all:
                        users = Employee.objects.filter(DeptID__in=deptIDs)
                    else:
                        users = []

                if not users:
                    raise Exception(_(u'请选择人员'))
                if not chklbDates:
                    raise Exception(_(u'请选择日期'))
                if not chklbSchClass:
                    raise Exception(_(u'请选择时段'))
                #获取时间段
                schs = SchClass.objects.filter(pk__in=chklbSchClass)
                #循环保存临时排班
                for day in chklbDates:
                    day = day.replace("/", "-")

                    for sch in schs:

                        #格式化时间
                        st = datetime.datetime.strptime(
                            day + ' ' + sch.StartTime.strftime('%H:%M:%S'),
                            '%Y-%m-%d %H:%M:%S')
                        et = datetime.datetime.strptime(
                            day + ' ' + sch.EndTime.strftime('%H:%M:%S'),
                            '%Y-%m-%d %H:%M:%S')

                        if et < st:  #判断时间段是否跨天
                            et = et + datetime.timedelta(days=1)

                        #保存
                        for u in users:
                            USER_TEMP_SCH.objects.filter(
                                UserID__exact=u,
                                SchclassID__exact=sch.pk,
                                ComeTime__exact=st,
                                LeaveTime__exact=et).delete()
                            t = USER_TEMP_SCH()
                            t.UserID = u
                            t.ComeTime = st
                            t.LeaveTime = et
                            t.WorkType = WorkType
                            t.Flag = flag
                            if is_OT:
                                t.OverTime = OverTime
                            t.SchclassID = sch.pk
                            t.save()