URL für Zeiterfassung

This commit is contained in:
Holger Trampe 2021-09-10 12:31:41 +02:00
parent c7daf964e5
commit f09f047f43
2 changed files with 74 additions and 1 deletions

View File

@ -29,5 +29,7 @@ urlpatterns = [
path('deletefile/<slug:fid>/<slug:secretkey>', views.deleteNCFile, name="api-deletencfile"),
path('tm/startday/<slug:uid>/<slug:secretkey>', views.startWorkDay, name="api-startday"),
path('tm/endday/<slug:uid>/<slug:secretkey>', views.endWorkDay, name="api-endday"),
path('tm/startbreak/<slug:uid>/<slug:secretkey>', views.startBreak, name="api-startbreak"),
path('tm/endbreak/<slug:uid>/<slug:secretkey>', views.endBreak, name="api-endbreak"),
path('tm/gettime/<slug:uid>/<slug:secretkey>', views.getTime, name="api-gettime"),
]

View File

@ -600,12 +600,40 @@ def getTime(request, uid, secretkey):
wd = Workday.objects.filter(user=user, agency=user.profile.agency, end=None, delflag = False)
workdaydata_workday = 0
workdaydata_starttime = 0
breakstatus = False
breaktimer = 0
breaksum = 0
if(len(wd) > 0):
wd_second = list(Workday.objects.filter(user=user, agency=user.profile.agency, end=None, delflag = False))[0]
workdaydata_workday = list(wd)[0].start
workdaydata_starttime = wd_second.start.strftime("%H:%M:%S")
return JsonResponse({'actualtime' : loadaccounttime(user)[0], 'workdaydata_workday' : workdaydata_workday, 'workdaydata_starttime' : workdaydata_starttime})
for b in wd_second.breaks.all():
if(b.end != None):
breaksum += (b.end - b.start).seconds
breaksum = breaksum*1000
# Check for Breaks
if(len(wd_second.breaks.all()) > 0):
# Check if all Breaks ended
wdbreak = wd_second.breaks.filter(end=None)
if(len(wdbreak) > 0):
breakstatus = True
# Break Found, return actual breakcounter
if(breakstatus):
wdbreak = wd_second.breaks.filter(end=None)
if(len(wdbreak) > 0):
now = timezone.now()
breakstart = list(wdbreak)[0].start
breaktimer = (now - breakstart).seconds * 1000
return JsonResponse({'actualtime' : loadaccounttime(user)[0], 'workdaydata_workday' : workdaydata_workday, 'workdaydata_starttime' : workdaydata_starttime, 'breakstatus' : breakstatus, 'breaktimer' : breaktimer, 'breaksum' : breaksum})
else:
return ({"status" : "FALSE"})
@ -641,6 +669,49 @@ def endWorkDay(request, uid, secretkey):
else:
return JsonResponse({"status" : "FALSE"})
# Start Break
@api_view(['GET'], )
def startBreak(request, uid, secretkey):
if request.method == "GET" and secretkey == '87zuhjk87GHJ546tzgvhas76aaskbdhr45edfVHAKia87s6gbAVGFGSR3451627gBHAKJBN':
user = User.objects.filter(username=uid).first()
wd = list(Workday.objects.filter(user=user, agency=user.profile.agency, end=None, delflag = False))[0]
newbreak = Breaks(workday=wd, user=user, agency=user.profile.agency, start=timezone.now())
newbreak.save()
wd.breaks.add(newbreak)
data = {
"success" : True,
"break_starttime" : newbreak.start,
}
return JsonResponse(data)
else:
return JsonResponse({"status" : "FALSE"})
# End Break
@api_view(['GET'], )
def endBreak(request, uid, secretkey):
if request.method == "GET" and secretkey == '87zuhjk87GHJ546tzgvhas76aaskbdhr45edfVHAKia87s6gbAVGFGSR3451627gBHAKJBN':
user = User.objects.filter(username=uid).first()
wd = list(Workday.objects.filter(user=user, agency=user.profile.agency, end=None, delflag = False))[0]
toendbreak = list(wd.breaks.filter(end=None))[0]
toendbreak.end = timezone.now()
toendbreak.save()
wd = list(Workday.objects.filter(user=user, agency=user.profile.agency, end=None, delflag = False))[0]
breaksum = 0
for b in wd.breaks.all():
if(b.end != None):
breaksum += (b.end - b.start).seconds
data = {
"success" : True,
"actualbreaktime" : breaksum*1000,
"wdtime" : wd.start
}
return JsonResponse(data)
else:
return JsonResponse({"status" : "FALSE"})