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 %} {% load counter_tag %}
{% if request.user.profile.agency.module_timemanagement %} {% if request.user.profile.agency.module_timemanagement %}
<div class="content-section col-12"> <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> <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 %} <!-- TODO: Hier noch Jahr speichern und Monat usw. -->
</tbody> <div class="btn-group" role="group" aria-label="" style="min-width: 100% !important">
</table> <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>
</div> <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 %} {% if user.usertime.usetime_start == None %}
<div class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" id="missingdatainfo"> <div class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" id="missingdatainfo">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
@ -79,7 +63,7 @@
<br /> <br />
<small>Dies können nur Mitarbeiter eintragen, die das Recht haben, Mitarbeiter zu verwalten.</small> <small>Dies können nur Mitarbeiter eintragen, die das Recht haben, Mitarbeiter zu verwalten.</small>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Schließen</button> <button type="button" class="btn btn-primary" data-dismiss="modal">Schließen</button>
</div> </div>
</div> </div>
@ -108,32 +92,33 @@
<div class="modal-body"> <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? 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>
<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-primary" onclick="javascript:loadInitiDays()">Ja</button>
<button type="button" class="btn btn" data-dismiss="modal">Nein</button> <button type="button" class="btn btn" data-dismiss="modal">Nein</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){
$("#initialload").modal("toggle"); //$("#initialload").modal("toggle");
}); });
function loadInitiDays(){ function loadInitiDays(){
$.ajax( $.ajax(
{ {
type: "GET", type: "GET",
url: "{% url 'tm-ajax' %}", url: "{% url 'tm-ajax' %}",
data:{ data:{
action : "initial_load", action : "initial_load",
}, },
success: function( data ) success: function( data )
{ {
location.href = location.href; location.href = location.href;
} }
}); });
} }
</script> </script>
@ -152,7 +137,7 @@
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-primary" id="dodel_{{workday.pk}}" >Löschen</button> <button class="btn btn-primary" id="dodel_{{workday.pk}}" >Löschen</button>
<button type="button" class="btn" data-dismiss="modal">Abbrechen</button> <button type="button" class="btn" data-dismiss="modal">Abbrechen</button>
</div> </div>
</div> </div>
</div> </div>
@ -168,12 +153,12 @@
action : "remove_workday", action : "remove_workday",
workday: {{workday.pk}}, workday: {{workday.pk}},
}, },
success: function( data ) success: function( data )
{ {
$("#wd_{{workday.pk}}").remove(); $("#wd_{{workday.pk}}").remove();
$("#confirm-delete_{{workday.pk}}").modal("toggle"); $("#confirm-delete_{{workday.pk}}").modal("toggle");
} }
}); });
}); });
</script> </script>
{% endfor %} {% endfor %}
@ -186,7 +171,7 @@
</style> </style>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
$('#table_timemanagement').DataTable({ $('#table_timemanagement').DataTable({
"language": { "language": {
"search" : "Suche", "search" : "Suche",
@ -206,7 +191,7 @@ $(document).ready(function(){
} }
}); });
}); });
</script> </script>
{% else %} {% else %}
<h3>Das Modul Abwesenheits- und Zeiterfassung wurde in ihrer Agentur deaktiviert oder die Zeiterfassung wurde im Modul deaktiviert.</h3> <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 = [ urlpatterns = [
path('', TimeManagement, name='tm-management'), 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>', TimeUpdate, name='tm-update'),
path('update/<int:pk>/addbreak/', AddBreak, name='add-break'), path('update/<int:pk>/addbreak/', AddBreak, name='add-break'),
path('abs/', AbsenceManagmenet, name='tma-management'), path('abs/', AbsenceManagmenet, name='tma-management'),

View File

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