diff --git a/dasettings/templates/dasettings/data_absence_yeardata.html b/dasettings/templates/dasettings/data_absence_yeardata.html
index 89c9605..57a0f39 100644
--- a/dasettings/templates/dasettings/data_absence_yeardata.html
+++ b/dasettings/templates/dasettings/data_absence_yeardata.html
@@ -31,4 +31,7 @@
{% endfor %}
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/dasettings/templates/dasettings/user_usprof.html b/dasettings/templates/dasettings/user_usprof.html
index 2bc3663..4468ce6 100644
--- a/dasettings/templates/dasettings/user_usprof.html
+++ b/dasettings/templates/dasettings/user_usprof.html
@@ -395,7 +395,10 @@
- Urlaubstage werden neu berechnet. Bitte warten und nicht das Fenster aktualisieren!
+ Urlaubstage werden neu berechnet. Bitte warten und nicht das Fenster aktualisieren!
+
+
@@ -441,12 +444,14 @@ function saveUpdateTableHolidays(){
userid: {{vieweduser}}
},
beforeSend: function(){
+ $("#text_recalc").html("Urlaubstage werden neu berechnet. Bitte warten und nicht das Fenster aktualisieren!")
+ $("#closeCalcButton").hide();
$("#calculatingAbsences").modal("show");
},
success: function( data )
{
-
- $("#calculatingAbsences").modal("hide");
+ $("#text_recalc").html("Es wurden "+data["ab_counter"]+" Abwesenheiten anhand der neuen Infos neu berechnet. ")
+ $("#closeCalcButton").show();
$("#year_overview").html(data);
$("#changeHolidayDataSave").hide();
$("#changeHolidayData").show();
diff --git a/dasettings/views.py b/dasettings/views.py
index d83f5b9..5f7fa45 100644
--- a/dasettings/views.py
+++ b/dasettings/views.py
@@ -43,6 +43,9 @@ import io as BytesIO
import base64
from django.http import HttpResponse
+from django.db.models.signals import post_save
+from users.signals import save_newabsence
+
def randomString(stringLength=10):
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
@@ -982,6 +985,18 @@ def SettingsAjaxRouter(request):
# GET ELEMENTS
newHolidayData = request.GET["new_data_info"].split("___")
# EVERY ELEMENT GET ID AND SAVE NEW DAY-INFO
+ user_to_recalculate = User.objects.get(pk=request.GET["userid"])
+ # DELETE ALL USED DAYS
+ absences = Absence.objects.filter(user=user_to_recalculate)
+ post_save.disconnect(save_newabsence, sender=Absence)
+
+ for ab in absences:
+ ab.holidays_normal = 0.0
+ ab.holidays_rest = 0.0
+ ab.holidays_normal_next = 0.0
+ ab.holidays_rest_next = 0.0
+ ab.save()
+
for ele in newHolidayData:
ele_elements = ele.split("__")
@@ -991,20 +1006,33 @@ def SettingsAjaxRouter(request):
temp_year = UserYearAbsenceInfo.objects.get(pk=ele_id, agency=request.user.profile.agency)
if(ele_type == "nor"):
temp_year.days = ele_elements[1]
+
elif(ele_type == "rest"):
temp_year.restdays = ele_elements[1]
+
+ temp_year.days_inuse = 0
temp_year.save()
+
context = {
"user_years" : UserYearAbsenceInfo.objects.filter(user=User.objects.get(pk=request.GET["userid"])),
}
- user_to_recalculate = User.objects.get(pk=request.GET["userid"])
-
+
absences = Absence.objects.filter(user=user_to_recalculate)
-
+ ab_counter = 0
+
+ # RECALCULATE ALL ABSENCES
for ab in absences:
- getFinalHolidayData(ab)
+ calculateNewAbsenceDate(ab)
+ ab_counter += 1
+ post_save.connect(save_newabsence, sender=Absence)
+ tomany = ""
+ # After Absence checking
+ for year in UserYearAbsenceInfo.objects.filter(user=User.objects.get(pk=request.GET["userid"])):
+ if year.days_inuse > year.days+year.restdays:
+ tomany = "Es sind mehr Abwesenheiten eingetragen als verfügbar. Bitte prüfen Sie die Abwesenheiten des Mitarbeiters."
+ context.update({"ab_counter" : ab_counter, "tomanyinfo" : tomany})
return render(request, 'dasettings/data_absence_yeardata.html', context)
# RESET TIMEMANAGEMENT
elif request.method == "GET" and request.GET['action'] == "del_tmdata" :
@@ -1040,6 +1068,76 @@ def SettingsAjaxRouter(request):
''' BERECHNUNG URLAUBSTAGE USW. '''
+def calculateNewAbsenceDate(instance):
+
+ newdata = getFinalHolidayData(instance)
+
+ abinfo = list(UserYearAbsenceInfo.objects.filter(user=instance.user, year=instance.start.year))[0]
+ abinfo_lastyear = ""
+ abinfo_nextyear = ""
+
+ is_lastyear = False
+
+ abinfo_lastyear = list(UserYearAbsenceInfo.objects.filter(user=instance.user, year=instance.start.year-1))
+ if(len(abinfo_lastyear) > 0):
+ is_lastyear = True
+ abinfo_lastyear = abinfo_lastyear[0]
+
+ is_nextyear = False
+ abinfo_nextyear = list(UserYearAbsenceInfo.objects.filter(user=instance.user, year=instance.start.year+1))
+ if(len(abinfo_nextyear) > 0):
+ is_nextyear = True
+ abinfo_nextyear = abinfo_nextyear[0]
+
+ multiple_info_needays = False
+ if(hasattr(newdata[3], "__len__")):
+ multiple_info_needays = True
+
+ # Gleiches Jahr MIT Rest
+ if(multiple_info_needays and newdata[3][2] == False):
+ # Rest ist positiv, daher bleibt rest übrig, rest wird in absence gespeichert und vom rest des Jahres-Restes abgezogen
+ # Rest ist positiv, damit bleibt Rest übrig
+ if(newdata[3][0] > 0):
+ instance.holidays_rest = abinfo.restdays - newdata[3][0]
+ instance.save()
+ abinfo.restdays = newdata[3][0]
+ abinfo.save()
+ # Rest ist negativ
+ elif(newdata[3][0] < 0):
+ instance.holidays_rest = (abinfo.restdays - newdata[3][0]) - newdata[3][0]*(-1)
+ instance.holidays_normal = newdata[3][0]*(-1)
+ instance.save()
+ abinfo.restdays = 0
+ abinfo.days_inuse = abinfo.days_inuse + newdata[3][0]*(-1)
+ abinfo.save()
+ # Rest ist Urlaubsdauer
+ else:
+ instance.holidays_rest = abinfo.restdays
+ instance.save()
+ #abinfo.days_inuse = abinfo.days_inuse + abinfo.restdays
+ abinfo.restdays = 0
+ abinfo.save()
+ # Gleiches Jahr ohne Rest
+ elif(not multiple_info_needays):
+ abinfo.days_inuse = abinfo.days_inuse + newdata[3]
+ abinfo.save()
+ instance.holidays_normal = newdata[3]
+ instance.save()
+ # Mehrere Jahre
+ elif(multiple_info_needays and newdata[3][2] == True):
+
+ abinfo.days_inuse = abinfo.days_inuse + newdata[3][0]
+ abinfo.save()
+ abinfo_nextyear.days_inuse = abinfo_nextyear.days_inuse + newdata[3][1]
+ abinfo_nextyear.restdays = abinfo_nextyear.restdays - newdata[3][3]
+ abinfo_nextyear.save()
+
+ # Hier werden alle benötigten Tage von Vor- und Nächstem Jahr gespeichert
+ instance.holidays_normal = newdata[3][0]
+ instance.holidays_rest = 0
+ instance.holidays_normal_next = newdata[3][1]
+ instance.holidays_rest_next = newdata[3][3]
+ instance.save()
''' AB HIER WIEDER RAUSNEHMEN '''
def getFinalHolidayData(abscence):
@@ -1072,6 +1170,8 @@ def getFinalHolidayData(abscence):
holiday_lastyear = yeardata.restdays
holiday_nextyear = 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,
diff --git a/dump.rdb b/dump.rdb
index 723ed73..983a30d 100644
Binary files a/dump.rdb and b/dump.rdb differ
diff --git a/timemanagement/templates/timemanagement/timemanagement_singleview.html b/timemanagement/templates/timemanagement/timemanagement_singleview.html
index bcf8a41..54e4dff 100644
--- a/timemanagement/templates/timemanagement/timemanagement_singleview.html
+++ b/timemanagement/templates/timemanagement/timemanagement_singleview.html
@@ -10,7 +10,7 @@
{% loadmonthwork next_month user as monthwork %}
- Arbeitszeit im Monat: {{monthwork}}
+ Gesamtarbeitszeit dieser Monat: {{monthwork}} Stunden
{% loadaccounttime user as actualaccounttime %}
Gleitzeitkonto:
{% if actualaccounttime.1 == 0 %}
diff --git a/timemanagement/templates/timemanagement/timemanagement_teamview_single.html b/timemanagement/templates/timemanagement/timemanagement_teamview_single.html
index c3f6124..74e1249 100644
--- a/timemanagement/templates/timemanagement/timemanagement_teamview_single.html
+++ b/timemanagement/templates/timemanagement/timemanagement_teamview_single.html
@@ -12,9 +12,7 @@
{% loadmonthwork next_month user as monthwork %}
-
-
- Arbeitszeit im Monat: {{monthwork}}
+ Gesamtarbeitszeit dieser Monat: {{monthwork}} Stunden
{% loadaccounttime user as actualaccounttime %}
Gleitzeitkonto:
{% if actualaccounttime.1 == 0 %}
@@ -22,9 +20,7 @@
{% else %}
-{{actualaccounttime.0}} Stunden
{% endif %}
-
-
-
+