Zeiterfassung

This commit is contained in:
Holger Trampe 2020-07-20 23:59:14 +02:00
parent b63c458df4
commit 5a015fe583
4 changed files with 411 additions and 191 deletions

View File

@ -3,67 +3,51 @@
{% load counter_tag %}
{% if request.user.profile.agency.module_timemanagement %}
<div class="content-section col-12">
<h3>Zeiterfassung&nbsp;<small><i data-toggle="tooltip" data-placement="top" title="Bearbeiten Sie hier Ihre Zeiterfassung." class="far fa-question-circle"></i></small></h3>
<h3>Zeiterfassung&nbsp;<small><i data-toggle="tooltip" data-placement="top" title="Bearbeiten Sie hier Ihre Zeiterfassung." class="far fa-question-circle"></i></small>
<button type="button" class="btn btn-primary btn-sm" style="position: relative; float: right !important;" onclick=""><i class="fas fa-plus"></i>&nbsp;Arbeitstag</button>
</h3>
<hr>
<div class="table-responsive ">
<table class="table table-hover" id="table_timemanagement" >
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Start</th>
<th scope="col">Ende</th>
<th scope="col">Arbeitszeit</th>
<th scope="col">Pausen</th>
<th scope="col">Gesamtzeit</th>
<th scope="col">Gleitzeit</th>
<th scope="col">&nbsp;</th>
</tr>
</thead>
<tbody id="table_contacts" >
{% for workday in workdays %}
<tr id="wd_{{workday.pk}}">
<td>
{{forloop.counter}}
</td>
<td>
{{workday.start|date:"d.m.y H:i"}}
</td>
<td>
{{workday.end|date:"d.m.y H:i"}}
</td>
<td>
{% getsumworkdayexcludebreak workday as sumworkday %}
{{ sumworkday }}
</td>
<td>
{% getsumbreak workday as sumbreakofday %}
{{sumbreakofday}} min. ({{workday.breaks.all|length}})
</td>
<td>
{% getsumworkday workday as sumwd %}
{{sumwd}}
</td>
<td>
{% gettimeoveralldiff workday user as erg%}
{% if erg.1 == 0 %}
<span style="color: green">+{{erg.0}}</span>
{% elif erg.1 == 1 %}
<span>{{erg.0}}</span>
{% else %}
<span style="color: red">-{{erg.0}}</span>
{% endif %}
</td>
<td>
<button class="btn btn-secondary btn-sm ml-2" onclick="window.location.href='{% url 'tm-update' workday.pk %}'"><small><i class="fas fa-pen"></i></small></button>
<button class="btn btn-secondary btn-sm " onclick="javascript:$('#confirm-delete_{{workday.pk}}').modal('toggle')"><small><i class="fas fa-trash"></i></small></button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- TODO: Hier noch Jahr speichern und Monat usw. -->
<div class="btn-group" role="group" aria-label="" style="min-width: 100% !important">
<button type="button" class="btn btn-primary mr-1" onclick="{% url 'tm-management' prev_month 2020 %}" ><i class="fas fa-arrow-circle-left"></i></button>
<button type="button" class="btn btn-primary mr-1" style="min-width: 150px !important;" onclick="">{{active_month}}</button>
<button type="button" class="btn btn-primary mr-1" onclick="{% url 'tm-management' next_month 2020 %}"><i class="fas fa-arrow-circle-right"></i></button>
</div>
<hr>
{% for workday in workdays %}
{% if workday.start.weekday == 0 %}
{{workday.start|date:"W"}}. Woche
<hr>
{% endif %}
<div class="card col-2">
<div class="card-body">
<h5 class="card-title">{{workday.start|date:"l"}}, {{workday.start|date:"d.m"}}</h5>
Von {{workday.start|date:"H:i"}} bis {{workday.end|date:"H:i"}}<br />
<small>
{% getsumworkdayexcludebreak workday as sumworkday %}
Arbeitszeit: {{ sumworkday }}<br />
{% getsumbreak workday as sumbreakofday %}
Pausen: {{sumbreakofday}} min. ({{workday.breaks.all|length}})
{% getsumworkday workday as sumwd %}
Gesamtzeit: {{sumwd}}<br />
Gleitzeit:
{% gettimeoveralldiff workday user as erg%}
{% if erg.1 == 0 %}
<span style="color: green">+{{erg.0}}</span>
{% elif erg.1 == 1 %}
<span>{{erg.0}}</span>
{% else %}
<span style="color: red">-{{erg.0}}</span>
{% endif %}
</small>
</div>
</div>
{% endfor %}
{% if user.usertime.usetime_start == None %}
<div class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" id="missingdatainfo">
<div class="modal-dialog" role="document">
@ -79,7 +63,7 @@
<br />
<small>Dies können nur Mitarbeiter eintragen, die das Recht haben, Mitarbeiter zu verwalten.</small>
</div>
<div class="modal-footer">
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Schließen</button>
</div>
</div>
@ -108,32 +92,33 @@
<div class="modal-body">
Es wurden keine Arbeitstage bis zum Beginn der Zeiterfassung am {{user.usertime.usetime_start|date:"d.m.Y"}} gefunden. Sollen diese Tage mit der Regelarbeitszeit aufgefüllt werden, welche bei den Vertragsdaten hinterlegt wurde?
</div>
<div class="modal-footer">
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="javascript:loadInitiDays()">Ja</button>
<button type="button" class="btn btn" data-dismiss="modal">Nein</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#initialload").modal("toggle");
//$("#initialload").modal("toggle");
});
function loadInitiDays(){
$.ajax(
{
type: "GET",
url: "{% url 'tm-ajax' %}",
data:{
action : "initial_load",
action : "initial_load",
},
success: function( data )
{
success: function( data )
{
location.href = location.href;
}
});
});
}
</script>
@ -152,7 +137,7 @@
<div class="modal-footer">
<button class="btn btn-primary" id="dodel_{{workday.pk}}" >Löschen</button>
<button type="button" class="btn" data-dismiss="modal">Abbrechen</button>
</div>
</div>
</div>
@ -168,12 +153,12 @@
action : "remove_workday",
workday: {{workday.pk}},
},
success: function( data )
{
success: function( data )
{
$("#wd_{{workday.pk}}").remove();
$("#confirm-delete_{{workday.pk}}").modal("toggle");
}
});
});
});
</script>
{% endfor %}
@ -186,7 +171,7 @@
</style>
<script>
$(document).ready(function(){
$('#table_timemanagement').DataTable({
"language": {
"search" : "Suche",
@ -206,7 +191,7 @@ $(document).ready(function(){
}
});
});
</script>
{% else %}
<h3>Das Modul Abwesenheits- und Zeiterfassung wurde in ihrer Agentur deaktiviert oder die Zeiterfassung wurde im Modul deaktiviert.</h3>

View File

@ -0,0 +1,214 @@
{% extends "users/base.html" %}
{% block content %}
{% load counter_tag %}
{% if request.user.profile.agency.module_timemanagement %}
<div class="content-section col-12">
<h3>Zeiterfassung&nbsp;<small><i data-toggle="tooltip" data-placement="top" title="Bearbeiten Sie hier Ihre Zeiterfassung." class="far fa-question-circle"></i></small></h3>
<hr>
<div class="table-responsive ">
<table class="table table-hover" id="table_timemanagement" >
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Start</th>
<th scope="col">Ende</th>
<th scope="col">Arbeitszeit</th>
<th scope="col">Pausen</th>
<th scope="col">Gesamtzeit</th>
<th scope="col">Gleitzeit</th>
<th scope="col">&nbsp;</th>
</tr>
</thead>
<tbody id="table_contacts" >
{% for workday in workdays %}
<tr id="wd_{{workday.pk}}">
<td>
{{forloop.counter}}
</td>
<td>
{{workday.start|date:"d.m.y H:i"}}
</td>
<td>
{{workday.end|date:"d.m.y H:i"}}
</td>
<td>
{% getsumworkdayexcludebreak workday as sumworkday %}
{{ sumworkday }}
</td>
<td>
{% getsumbreak workday as sumbreakofday %}
{{sumbreakofday}} min. ({{workday.breaks.all|length}})
</td>
<td>
{% getsumworkday workday as sumwd %}
{{sumwd}}
</td>
<td>
{% gettimeoveralldiff workday user as erg%}
{% if erg.1 == 0 %}
<span style="color: green">+{{erg.0}}</span>
{% elif erg.1 == 1 %}
<span>{{erg.0}}</span>
{% else %}
<span style="color: red">-{{erg.0}}</span>
{% endif %}
</td>
<td>
<button class="btn btn-secondary btn-sm ml-2" onclick="window.location.href='{% url 'tm-update' workday.pk %}'"><small><i class="fas fa-pen"></i></small></button>
<button class="btn btn-secondary btn-sm " onclick="javascript:$('#confirm-delete_{{workday.pk}}').modal('toggle')"><small><i class="fas fa-trash"></i></small></button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if user.usertime.usetime_start == None %}
<div class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" id="missingdatainfo">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Fehlende Informationen</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Achtung! Es wurde kein Datum gefunden, ab wann die Zeiterfassung beginnen soll. Bitte tragen Sie dies in Ihrem Mitarbeiterkonto unter Einstellungen, Mitarbeiter, Ihre Vertragsdaten nach.
<br />
<small>Dies können nur Mitarbeiter eintragen, die das Recht haben, Mitarbeiter zu verwalten.</small>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Schließen</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#missingdatainfo").modal("toggle");
})
$('#missingdatainfo').on('hidden.bs.modal', function (e) {
location.href = "{% url 'dasettings' %}";
})
</script>
{% elif workdays|length == 0 %}
<div class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" id="initialload">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Arbeitstage auffüllen</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Es wurden keine Arbeitstage bis zum Beginn der Zeiterfassung am {{user.usertime.usetime_start|date:"d.m.Y"}} gefunden. Sollen diese Tage mit der Regelarbeitszeit aufgefüllt werden, welche bei den Vertragsdaten hinterlegt wurde?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="javascript:loadInitiDays()">Ja</button>
<button type="button" class="btn btn" data-dismiss="modal">Nein</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#initialload").modal("toggle");
});
function loadInitiDays(){
$.ajax(
{
type: "GET",
url: "{% url 'tm-ajax' %}",
data:{
action : "initial_load",
},
success: function( data )
{
location.href = location.href;
}
});
}
</script>
{% endif %}
{% for workday in workdays %}
<div class="modal fade" id="confirm-delete_{{workday.pk}}" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Arbeitstag löschen</h5>
</div>
<div class="modal-body">
Möchten Sie wirklich den Arbeitstag am {{workday.start|date:"d.m"}} löschen?
</div>
<div class="modal-footer">
<button class="btn btn-primary" id="dodel_{{workday.pk}}" >Löschen</button>
<button type="button" class="btn" data-dismiss="modal">Abbrechen</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$("#dodel_{{workday.pk}}").click(function(){
$.ajax(
{
type: "GET",
url: "{% url 'tm-ajax' %}",
data:{
action : "remove_workday",
workday: {{workday.pk}},
},
success: function( data )
{
$("#wd_{{workday.pk}}").remove();
$("#confirm-delete_{{workday.pk}}").modal("toggle");
}
});
});
</script>
{% endfor %}
<style>
/* DATATABLES */
.paginate_button {
padding: 0px !important;
border: 0px !important;
}
</style>
<script>
$(document).ready(function(){
$('#table_timemanagement').DataTable({
"language": {
"search" : "Suche",
"info": "Zeige _START_ bis _END_ von _TOTAL_ Einträgen",
"lengthMenu": "Zeige _MENU_ Einträge",
"zeroRecords": "Nichts gefunden",
"infoEmpty": "Keine Einträge",
"paginate": {
"first": "Erste",
"last": "Letzte",
"next": "Nächste",
"previous": "Zurück"
},
},
"buttons" : {
"className" : "btn-danger"
}
});
});
</script>
{% else %}
<h3>Das Modul Abwesenheits- und Zeiterfassung wurde in ihrer Agentur deaktiviert oder die Zeiterfassung wurde im Modul deaktiviert.</h3>
{% endif %}
{% endblock content %}

View File

@ -7,6 +7,7 @@ Permissions definiert in models.py bei USERS und dann hier vor die View geschrie
urlpatterns = [
path('', TimeManagement, name='tm-management'),
path('<int:activemonth>/<int:activeyear>', TimeManagement, name='tm-management'),
path('update/<int:pk>', TimeUpdate, name='tm-update'),
path('update/<int:pk>/addbreak/', AddBreak, name='add-break'),
path('abs/', AbsenceManagmenet, name='tma-management'),

View File

@ -18,22 +18,23 @@ from users.models import UserTime
from datetime import timedelta
from django.db.models.signals import post_save
from users.signals import save_newabsence
import locale
# Load freedays
def loadingFreeDays(plz):
# Getting land
file_path = os.path.join(settings.STATIC_ROOT, 'users/extra/plz_short.csv')
land = False
with open(file_path, 'rt') as csvfile:
with open(file_path, 'rt') as csvfile:
filecsv = csv.reader(csvfile, delimiter=';')
for row in filecsv:
if row[1] == plz:
land = row[6]
break;
if(land != False):
# CALCULATE FREEDAYS AS JSON
year = today = date.today().year
@ -69,19 +70,19 @@ def AbsenceUpdate(request, pk):
"timeinfo_nextyear" : timeinfo_nextyear,
"start" : absence.start.strftime("%d.%m.%Y"),
"end" : absence.end.strftime("%d.%m.%Y"),
}
}
return render(request, 'timemanagement/tm_ab_update.html', context)
elif request.method == "POST":
elif request.method == "POST":
absence = Absence.objects.get(pk=pk)
formtocheck = UpdateAbsence(request.POST, instance=request.user)
if(formtocheck.is_valid()):
formtocheck = UpdateAbsence(request.POST, instance=request.user)
if(formtocheck.is_valid()):
abinfo = list(UserYearAbsenceInfo.objects.filter(user=absence.user, year=absence.start.year))[0]
abinfo_lastyear = ""
abinfo_nextyear = ""
is_lastyear = False
abinfo_lastyear = list(UserYearAbsenceInfo.objects.filter(user=absence.user, year=absence.start.year-1))
if(len(abinfo_lastyear) > 0):
is_lastyear = True
@ -109,7 +110,7 @@ def AbsenceUpdate(request, pk):
rep = None
if(formtocheck.cleaned_data["representator"] != None):
rep = User.objects.get(pk=formtocheck.cleaned_data["representator"].pk)
rep = User.objects.get(pk=formtocheck.cleaned_data["representator"].pk)
absence.representator = rep
absence.info = formtocheck.cleaned_data["info"]
@ -117,13 +118,13 @@ def AbsenceUpdate(request, pk):
absence.holidays_rest = 0.0
absence.holidays_normal_next = 0.0
absence.holidays_rest_next = 0.0
absence.save()
messages.success(request, f'Abwesenheit aktualisiert!')
absence.save()
messages.success(request, f'Abwesenheit aktualisiert!')
else:
messages.success(request, f'Fehler bei Abwesenheitsaktualisierung!')
messages.success(request, f'Fehler bei Abwesenheitsaktualisierung!')
context = {
"active_link" : "abscence",
}
"active_link" : "abscence",
}
return redirect("tma-management")
@login_required
@ -133,14 +134,14 @@ def AbsenceManagmenet(request, activemonth=False, activeyear=False):
if(request.method == "POST"):
'''
Nachdem eine neue Abwesenheit gespeichert wurde, geht es zur normalen Seite zurück, jedoch mit den Daten des
Nachdem eine neue Abwesenheit gespeichert wurde, geht es zur normalen Seite zurück, jedoch mit den Daten des
aktuell angezeigten Monate/Jahr
'''
'''
if(request.POST.get("form_type") == "absenceform"):
formtocheck = AddAbsence(request.POST, instance=request.user)
if(formtocheck.is_valid()):
formtocheck = AddAbsence(request.POST, instance=request.user)
if(formtocheck.is_valid()):
try:
workinguser = UserFullName.objects.get(pk=formtocheck.cleaned_data["userid"])
@ -160,15 +161,15 @@ def AbsenceManagmenet(request, activemonth=False, activeyear=False):
rep = None
if(formtocheck.cleaned_data["representator"] != None):
rep = User.objects.get(pk=formtocheck.cleaned_data["representator"].pk)
rep = User.objects.get(pk=formtocheck.cleaned_data["representator"].pk)
#newab = Absence(agency=request.user.profile.agency, user=workinguser, start=formtocheck.cleaned_data["start"],end=formtocheck.cleaned_data["end"], representator=rep, confirm_status=confirmstat, info=formtocheck.cleaned_data["info"], reason=formtocheck.cleaned_data["reason"], start_ishalf=formtocheck.cleaned_data["start_ishalf"], end_ishalf=formtocheck.cleaned_data["end_ishalf"]).save()
newab = Absence(agency=request.user.profile.agency, user=workinguser, start=formtocheck.cleaned_data["start"],end=formtocheck.cleaned_data["end"], representator=rep, confirm_status=confirmstat, info=formtocheck.cleaned_data["info"], reason=formtocheck.cleaned_data["reason"], startday_info=formtocheck.cleaned_data["startday_info"], endday_info=formtocheck.cleaned_data["endday_info"]).save()
# USER NOT FOUND
except:
messages.success(request, f'Fehler bei Benutzerzuweisung!')
return redirect('tma-management', formtocheck.cleaned_data['activemonth'], formtocheck.cleaned_data['activeyear'])
return redirect('tma-management', formtocheck.cleaned_data['activemonth'], formtocheck.cleaned_data['activeyear'])
else:
messages.success(request, f'Fehler beim eintragen der neuen Abwesenheit!')
@ -184,7 +185,7 @@ def AbsenceManagmenet(request, activemonth=False, activeyear=False):
activemonth = int(activemonth)
#Active month
activemonth=date.today().month
if(activemonth == 1):
prevmonth = 12
else:
@ -195,7 +196,7 @@ def AbsenceManagmenet(request, activemonth=False, activeyear=False):
else:
nextmonth = activemonth + 1
else:
if(activemonth == 1):
prevmonth = 12
else:
@ -221,13 +222,13 @@ def AbsenceManagmenet(request, activemonth=False, activeyear=False):
prevyear = activeyear - 1
else:
prevyear = activeyear
missinguserdata = []
#CHECK, ob alle nötigen Infos zur Urlaubsberechnung vorliegen
for user in User.objects.filter(profile__agency=request.user.profile.agency):
tempTime = UserTime.objects.get(user=user)
if(tempTime.startdate == None):
if(tempTime.startdate == None):
missinguserdata.append(user)
kontingent = 0
@ -244,13 +245,13 @@ def AbsenceManagmenet(request, activemonth=False, activeyear=False):
# ABSENCE AUFLISTUNG NACH GRUND
allreasons = AbsenceReason.objects.filter(agency=request.user.profile.agency).order_by("name")
final_reasons = []
final_reasons = []
for ar in allreasons:
tempabsece = Absence.objects.filter(reason=ar, user=request.user, start__year=activeyear, confirm_status=0)
temp_sum = 0.0
for t in tempabsece:
temp_sum += calculatingHolidaysByAbsence(request, t)
final_reasons.append([ar, temp_sum])
temp_sum += calculatingHolidaysByAbsence(request, t)
final_reasons.append([ar, temp_sum])
context = {
"active_link" : "abscence",
@ -270,22 +271,44 @@ def AbsenceManagmenet(request, activemonth=False, activeyear=False):
"today" : date.today(),
"abscenceform" : AddAbsence(instance=request.user),
"userown" : Absence.objects.filter(agency=request.user.profile.agency, user=request.user).order_by("-start")
}
}
if(request.user.has_perm("users.absencemanager")):
context.update({
"needtoconfirm" : Absence.objects.filter(agency=request.user.profile.agency, confirm_status=1).order_by("-start"),
"allabsences" : Absence.objects.filter(agency=request.user.profile.agency).order_by("-start")
"allabsences" : Absence.objects.filter(agency=request.user.profile.agency).order_by("-start")
})
return render(request, 'timemanagement/tm_ab_management.html', context)
@login_required
def TimeManagement(request):
def TimeManagement(request, activemonth=False, activeyear=False):
# TODO: Abwesenheiten mit berücksichtigen!
locale.setlocale(locale.LC_TIME, 'de_DE.UTF-8')
# TODO: Hier noch umbauen, dass das Datum beim Wechsel mit auf diesen Monat gesetzt wird
# TODO: Jahr fehlt auch noch :)
if(activemonth == False):
today = datetime.datetime.today()
active_month = str(today.strftime("%B"))
else:
today = datetime.datetime(2020, activemonth, 1)
active_month = activemonth
active_month = str(today.strftime("%B"))
next_month = today.month + 1
if(next_month == 13):
next_month = 1
prev_month = today.month - 1
if(prev_month == 0):
prev_month = 12
context = {
"next_month" : next_month,
"prev_month" : prev_month,
"active_month" : active_month,
"active_link" : "timemanagement",
"workdays" : Workday.objects.filter(agency=request.user.profile.agency, user=request.user).order_by("-start").exclude(end=None)
}
@ -295,17 +318,17 @@ def TimeManagement(request):
def TimeUpdate(request, pk):
if(request.method == "POST"):
form = UpdateWorkdayForm(request.POST, instance=request.user)
workday = Workday.objects.get(pk=pk)
workday = Workday.objects.get(pk=pk)
start = datetime.datetime(int(workday.start.year), int(workday.start.month), int(workday.start.day), int(((str(form["start"].value()).split(":"))[0])), int(((str(form["start"].value()).split(":"))[1])))
end = datetime.datetime(int(workday.end.year), int(workday.end.month), int(workday.end.day), int(((str(form["end"].value()).split(":"))[0])), int(((str(form["end"].value()).split(":"))[1])))
start = datetime.datetime(int(workday.start.year), int(workday.start.month), int(workday.start.day), int(((str(form["start"].value()).split(":"))[0])), int(((str(form["start"].value()).split(":"))[1])))
end = datetime.datetime(int(workday.end.year), int(workday.end.month), int(workday.end.day), int(((str(form["end"].value()).split(":"))[0])), int(((str(form["end"].value()).split(":"))[1])))
workday.start = start
workday.end = end
workday.target = form["target"].value()
workday.save()
messages.success(request, f'Arbeitstag aktualisiert')
messages.success(request, f'Arbeitstag aktualisiert')
return redirect('tm-management')
else:
@ -319,18 +342,18 @@ def TimeUpdate(request, pk):
@login_required
def AddBreak(request, pk):
if(request.method == "POST"):
workday = Workday.objects.get(pk=pk)
form = AddBreakForm(request.POST, instance=request.user)
start = datetime.datetime(int(workday.start.year), int(workday.start.month), int(workday.start.day), int(((str(form["start"].value()).split(":"))[0])), int(((str(form["start"].value()).split(":"))[1])))
workday = Workday.objects.get(pk=pk)
form = AddBreakForm(request.POST, instance=request.user)
start = datetime.datetime(int(workday.start.year), int(workday.start.month), int(workday.start.day), int(((str(form["start"].value()).split(":"))[0])), int(((str(form["start"].value()).split(":"))[1])))
end = datetime.datetime(int(workday.end.year), int(workday.end.month), int(workday.end.day), int(((str(form["end"].value()).split(":"))[0])), int(((str(form["end"].value()).split(":"))[1])))
newbreak = Breaks.objects.create(workday=workday, user=request.user, agency=request.user.profile.agency, start=start, end=end)
workday.breaks.add(newbreak)
workday.save()
messages.success(request, f'Pause hinzugefügt')
messages.success(request, f'Pause hinzugefügt')
return redirect('tm-update', pk=pk)
else:
context = {
@ -346,7 +369,7 @@ def TimeAjax(request):
if request.method == "GET":
# START WORKDAY
if request.GET["action"] == "start_day":
today = date.today()
targettime = 0.0
if(today.isoweekday() == 1):
@ -357,12 +380,12 @@ def TimeAjax(request):
targettime = request.user.usertime.wd_we
elif(today.isoweekday() == 4):
targettime = request.user.usertime.wd_th
elif(today.isoweekday() == 5):
elif(today.isoweekday() == 5):
targettime = request.user.usertime.wd_fr
elif(today.isoweekday() == 6):
elif(today.isoweekday() == 6):
targettime = request.user.usertime.wd_sa
elif(today.isoweekday() == 7):
targettime = request.user.usertime.wd_so
elif(today.isoweekday() == 7):
targettime = request.user.usertime.wd_so
wd = Workday(user=request.user, agency=request.user.profile.agency, start=timezone.now(), target=targettime)
wd.save()
@ -390,23 +413,23 @@ def TimeAjax(request):
data = {
"success" : True,
"wd_endtime" : wd.end.strftime("%H:%M:%S"),
"actualbreaktime" : breaksum*1000
"wd_endtime" : wd.end.strftime("%H:%M:%S"),
"actualbreaktime" : breaksum*1000
}
# START A BREAK
elif request.GET["action"] == "start_break":
wd = list(Workday.objects.filter(user=request.user, agency=request.user.profile.agency, end=None))[0]
wd = list(Workday.objects.filter(user=request.user, agency=request.user.profile.agency, end=None))[0]
newbreak = Breaks(workday=wd, user=request.user, agency=request.user.profile.agency, start=timezone.now())
newbreak.save()
wd.breaks.add(newbreak)
data = {
"success" : True,
"break_starttime" : newbreak.start,
"break_starttime" : newbreak.start,
}
# END BREAK
elif request.GET["action"] == "end_break":
wd = list(Workday.objects.filter(user=request.user, agency=request.user.profile.agency, end=None))[0]
toendbreak = list(wd.breaks.filter(end=None))[0]
wd = list(Workday.objects.filter(user=request.user, agency=request.user.profile.agency, end=None))[0]
toendbreak = list(wd.breaks.filter(end=None))[0]
toendbreak.end = timezone.now()
toendbreak.save()
@ -418,7 +441,7 @@ def TimeAjax(request):
data = {
"success" : True,
"actualbreaktime" : breaksum*1000
"actualbreaktime" : breaksum*1000
}
# REMOVE WORKDAY
elif request.GET["action"] == "remove_workday":
@ -426,7 +449,7 @@ def TimeAjax(request):
if(wd.user == request.user and wd.agency == request.user.profile.agency):
wd.delete()
data = {
"success" : True
"success" : True
}
else:
data = { "success" : False}
@ -436,7 +459,7 @@ def TimeAjax(request):
if(breakwd.user == request.user and breakwd.agency == request.user.profile.agency):
breakwd.delete()
data = {
"success" : True
"success" : True
}
else:
data = { "success" : False}
@ -445,14 +468,14 @@ def TimeAjax(request):
allfreedays = FreeDays.objects.filter(agency=request.user.profile.agency, day__gt=request.user.usertime.usetime_start, day__lt=date.today())
weekdays = [6,7]
for dt in daterange(request.user.usertime.usetime_start, date.today()):
if dt.isoweekday() not in weekdays:
in_freedays = False
for freeday in allfreedays.all():
if(dt == freeday.day):
in_freedays = True
in_freedays = True
break;
if(not in_freedays):
@ -541,7 +564,7 @@ def TimeAjax(request):
activemonth = int(activemonth)
#Active month
activemonth=date.today().month
if(activemonth == 1):
prevmonth = 12
else:
@ -552,7 +575,7 @@ def TimeAjax(request):
else:
nextmonth = activemonth + 1
else:
if(activemonth == 1):
prevmonth = 12
else:
@ -583,7 +606,7 @@ def TimeAjax(request):
for user in User.objects.filter(profile__agency=request.user.profile.agency):
tempTime = UserTime.objects.get(user=user)
if(tempTime.startdate == None):
if(tempTime.startdate == None):
missinguserdata.append(user)
context = {
@ -598,9 +621,9 @@ def TimeAjax(request):
"nextyear" : nextyear,
"prevyear" : prevyear,
"today" : date.today(),
}
}
return render(request, "timemanagement/rendered_table.html", context)
# Prüfung, ob eine Vertretung nötig ist oder nicht
elif request.GET["action"] == "checkrequired":
reason = AbsenceReason.objects.get(pk=request.GET["rid"])
@ -608,24 +631,24 @@ def TimeAjax(request):
data = {
"success" : True,
"isreq" : reason.need_rep,
"isholiday" : reason.is_holiday
"isholiday" : reason.is_holiday
}
else:
data = {
"success" : False
"success" : False
}
# DELETE ABSENCE
elif request.GET["action"] == "remove_absence":
elif request.GET["action"] == "remove_absence":
absence = Absence.objects.get(pk=request.GET["ab"])
if(request.user.has_perm("users.absencemanager") and absence.agency == request.user.profile.agency):
absence.delete()
data = {
"success" : True
}
# GET FORM FOR CONFIRM ABSENCE
}
# GET FORM FOR CONFIRM ABSENCE
elif request.GET["action"] == "getrenderedform":
absence = Absence.objects.get(pk=request.GET["abscenceid"])
timeinfo_thisyear = list(UserYearAbsenceInfo.objects.filter(year=absence.start.year, user=absence.user))[0]
try:
@ -642,7 +665,7 @@ def TimeAjax(request):
other_absences_string = []
for a in other_absences:
other_absences_string.append(a.user.first_name + " " + a.user.last_name + " - Vom " + a.start.strftime("%d.%m.%Y") + " bis " + a.end.strftime("%d.%m.%Y"))
context = {
"confirmform" : ConfirmAbsenceForm(instance=request.user),
@ -652,7 +675,7 @@ def TimeAjax(request):
"timeinfo_nextyear" : timeinfo_nextyear
}
return render(request, "timemanagement/rendered_confirmform.html", context)
return render(request, "timemanagement/rendered_confirmform.html", context)
elif request.GET["action"] == "confirmornotabscence":
absence = Absence.objects.get(pk=request.GET["absencetowork"])
new_stat = request.GET["newconfstat"]
@ -689,26 +712,26 @@ def TimeAjax(request):
post_save.connect(save_newabsence, sender=Absence)
messages.success(request, f'Abwesenheit gespeichert!')
else:
messages.success(request, f'Das dürfen Sie nicht!')
messages.success(request, f'Das dürfen Sie nicht!')
data = {
"success" : True,
"activemonth" : request.GET["activemonth"],
"activemonth" : request.GET["activemonth"],
"activeyear" : request.GET["activeyear"]
}
}
# Berechnung starten, da Urlaub vorhanden ist
elif request.GET["action"] == "getrestholidays":
elif request.GET["action"] == "getrestholidays":
user = User.objects.get(pk=request.GET["userid"])
usertimedata = UserTime.objects.get(user=user)
today = date.today()
usertimedata = UserTime.objects.get(user=user)
today = date.today()
if(user.profile.agency == request.user.profile.agency):
start_day = request.GET["startdate"].split("__")
start_day_obj = datetime.date(int(start_day[0]), int(start_day[1]), int(start_day[2]))
end_day = request.GET["enddate"].split("__")
end_day_obj = datetime.date(int(end_day[0]), int(end_day[1]), int(end_day[2]))
try:
holidayloose_date = datetime.date(start_day_obj.year, int(usertimedata.loose_holidedate.split(".")[1]), int(usertimedata.loose_holidedate.split(".")[0]))
except:
@ -725,7 +748,7 @@ def TimeAjax(request):
end_half = True
choosenyear = int(start_day[0])
yeardata = list(UserYearAbsenceInfo.objects.filter(user=user, agency=user.profile.agency, year=choosenyear))[0]
holiday_thisyear = 0
@ -737,21 +760,21 @@ def TimeAjax(request):
need_days_this = 0
try:
holiday_nextyear = list(UserYearAbsenceInfo.objects.filter(user=user, agency=user.profile.agency,
year=choosenyear+1))[0].days - list(UserYearAbsenceInfo.objects.filter(user=user, agency=user.profile.agency,
holiday_nextyear = list(UserYearAbsenceInfo.objects.filter(user=user, agency=user.profile.agency,
year=choosenyear+1))[0].days - list(UserYearAbsenceInfo.objects.filter(user=user, agency=user.profile.agency,
year=choosenyear+1))[0].days_inuse
holiday_nextyear_rest = list(UserYearAbsenceInfo.objects.filter(user=user, agency=user.profile.agency,
holiday_nextyear_rest = list(UserYearAbsenceInfo.objects.filter(user=user, agency=user.profile.agency,
year=choosenyear+1))[0].restdays
except:
holiday_nextyear = yeardata.days
holiday_nextyear = yeardata.days
# Urlaub innerhalb eines Jahres inkl. Prüfung auf Resturlaubsanspruch
if(end_day_obj.year == start_day_obj.year):
# Startt des Urlaubs NACH Verfallsdatum - nur aktuelles JAhr und die Zahl interessiert
if(start_day_obj > holidayloose_date):
if(start_day_obj > holidayloose_date):
need_days = (calculateHolidays(request, start_day_obj, end_day_obj, start_half, end_half, user))*(-1)
holiday_thisyear = yeardata.days - yeardata.days_inuse - need_days
else:
else:
need_days = (calculateHolidays(request, start_day_obj, end_day_obj, start_half, end_half, user))*(-1)
# Kein Resturlaub
if(yeardata.restdays == 0.0):
@ -763,9 +786,9 @@ def TimeAjax(request):
temp_holiday = holiday_lastyear - need_days
if(temp_holiday < 0):
holiday_lastyear = 0
holiday_thisyear = yeardata.days - yeardata.days_inuse + temp_holiday
holiday_thisyear = yeardata.days - yeardata.days_inuse + temp_holiday
else:
holiday_lastyear = yeardata.restdays - need_days
holiday_lastyear = yeardata.restdays - need_days
# Urlaub geht über das nächstes Jahr hinweg
else:
two_years = True
@ -773,9 +796,9 @@ def TimeAjax(request):
date_splitter = datetime.date(end_day_obj.year, 1, 1)
need_days_this = (calculateHolidays(request, start_day_obj, date_splitter, start_half, False), user)*(-1)
need_days_next = (calculateHolidays(request, date_splitter, end_day_obj, False, end_half, user))*(-1)
need_days = (calculateHolidays(request, start_day_obj, date_splitter, start_half, False, user))*(-1) + (calculateHolidays(request, date_splitter, end_day_obj, False, end_half))*(-1)
holiday_thisyear = yeardata.days - yeardata.days_inuse - need_days_this
days_nextyear_normal = 0
@ -789,14 +812,14 @@ def TimeAjax(request):
if(temprest >= 0):
holiday_nextyear_rest = temprest
days_nextyear_normal = 0
days_nextyear_rest = need_days_next
days_nextyear_rest = need_days_next
# Rest reicht nicht
else:
holiday_nextyear_rest = 0
holiday_nextyear += temprest
days_nextyear_rest = need_days_next + temprest
days_nextyear_normal = temprest * -1
# POrüfen, ob es in diesem Zeitraum noch andere Abwesenheiten gibt
other_absences = Absence.objects.filter(start__lte=start_day_obj, end__gte=end_day_obj, agency=request.user.profile.agency, confirm_status=0).exclude(user=user)
@ -807,9 +830,9 @@ def TimeAjax(request):
other_absences_string += a.user.first_name + " " + a.user.last_name + " - Vom " + a.start.strftime("%d.%m.%Y") + " bis " + a.end.strftime("%d.%m.%Y") + "<br />"
# Prüfen, ob der Nutzer selbst schon Abwesenheiten in diesem Zeitraum hat
userown_absences = Absence.objects.filter(start__lte=start_day_obj, end__gte=end_day_obj, agency=request.user.profile.agency, user=user, confirm_status=0)
userown_absences_string = False
if (len(userown_absences) > 0):
userown_absences_string = ""
@ -827,16 +850,16 @@ def TimeAjax(request):
"need_days_this" : need_days_this,
"other_absences" : other_absences_string,
"userown_absences" : userown_absences_string
}
}
# REQUEST USER NO RIGHTS
else:
data = {
"success" : False
"success" : False
}
# GET REQUEST ACTION UNKNOWN
else:
data = {
"success" : False
"success" : False
}
return JsonResponse(data)
@ -856,7 +879,7 @@ def calculateHolidays(request, start, end, start_half, end_half, user):
if(start_half):
return restdays - 0.5
else:
return restdays - 1
return restdays - 1
else:
if(end < start):
return False
@ -870,13 +893,13 @@ def calculateHolidays(request, start, end, start_half, end_half, user):
weekdays = []
freedaycounter = 0
for dt in daterange(start, end):
if dt.isoweekday() not in weekdays:
counter += 1
counter += 1
for freeday in allfreedays.all():
if(dt == freeday.day):
if(dt == freeday.day):
freedaycounter += 1
# Prüfung, ob der Mitarbeiter an diesem Tag überhaupt arbeitet. Wenn nicht, wird der Freedaycounter einfach erhöht
if(dt.isoweekday() == 1):
if user.usertime.wd_mo == 0.0:
@ -890,13 +913,13 @@ def calculateHolidays(request, start, end, start_half, end_half, user):
elif(dt.isoweekday() == 4):
if user.usertime.wd_th == 0.0:
freedaycounter += 1
elif(dt.isoweekday() == 5):
elif(dt.isoweekday() == 5):
if user.usertime.wd_fr == 0.0:
freedaycounter += 1
elif(dt.isoweekday() == 6):
elif(dt.isoweekday() == 6):
if user.usertime.wd_sa == 0.0:
freedaycounter += 1
elif(dt.isoweekday() == 7):
elif(dt.isoweekday() == 7):
if user.usertime.wd_so == 0.0:
freedaycounter += 1
@ -927,9 +950,9 @@ def calculatingHolidaysByAbsence(request, absence):
weekdays = []
freedaycounter = 0
for dt in daterange(absence.start, absence.end):
if dt.isoweekday() not in weekdays:
finalholidayinabsence += 1
finalholidayinabsence += 1
# Prüfung, ob freie Tage vorhanden sind
for freeday in allfreedays.all():
# FREEDAY FOUND
@ -949,13 +972,13 @@ def calculatingHolidaysByAbsence(request, absence):
elif(dt.isoweekday() == 4):
if absence.user.usertime.wd_th == 0.0:
freedaycounter += 1
elif(dt.isoweekday() == 5):
elif(dt.isoweekday() == 5):
if absence.user.usertime.wd_fr == 0.0:
freedaycounter += 1
elif(dt.isoweekday() == 6):
elif(dt.isoweekday() == 6):
if absence.user.usertime.wd_sa == 0.0:
freedaycounter += 1
elif(dt.isoweekday() == 7):
elif(dt.isoweekday() == 7):
if absence.user.usertime.wd_so == 0.0:
freedaycounter += 1
@ -965,6 +988,3 @@ def calculatingHolidaysByAbsence(request, absence):
def daterange(date1, date2):
for n in range(int ((date2 - date1).days)+1):
yield date1 + timedelta(n)