Automatische Neuberechnung fertig
This commit is contained in:
parent
3556dd8c1a
commit
a20c9210ee
|
|
@ -31,4 +31,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#text_recalc").html("Es wurden {{ab_counter}} Abwesenheiten anhand der neuen Infos neu berechnet. Aktuelle Werte für Resturlaubsdaten aus Vorjahren wurden bereits verrechnet und können daher von Werten in der Tabelle abweichen. Diese werden in der Regel automatisch verarbeitet. {{tomanyinfo}}");
|
||||||
|
</script>
|
||||||
|
|
@ -395,7 +395,10 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
Urlaubstage werden neu berechnet. Bitte warten und nicht das Fenster aktualisieren!
|
<span id="text_recalc">Urlaubstage werden neu berechnet. Bitte warten und nicht das Fenster aktualisieren!</span>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" id="closeCalcButton" class="btn btn-primary" data-dismiss="modal" style="display: hide;">Schließen</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -441,12 +444,14 @@ function saveUpdateTableHolidays(){
|
||||||
userid: {{vieweduser}}
|
userid: {{vieweduser}}
|
||||||
},
|
},
|
||||||
beforeSend: function(){
|
beforeSend: function(){
|
||||||
|
$("#text_recalc").html("Urlaubstage werden neu berechnet. Bitte warten und nicht das Fenster aktualisieren!")
|
||||||
|
$("#closeCalcButton").hide();
|
||||||
$("#calculatingAbsences").modal("show");
|
$("#calculatingAbsences").modal("show");
|
||||||
},
|
},
|
||||||
success: function( data )
|
success: function( data )
|
||||||
{
|
{
|
||||||
|
$("#text_recalc").html("Es wurden "+data["ab_counter"]+" Abwesenheiten anhand der neuen Infos neu berechnet. ")
|
||||||
$("#calculatingAbsences").modal("hide");
|
$("#closeCalcButton").show();
|
||||||
$("#year_overview").html(data);
|
$("#year_overview").html(data);
|
||||||
$("#changeHolidayDataSave").hide();
|
$("#changeHolidayDataSave").hide();
|
||||||
$("#changeHolidayData").show();
|
$("#changeHolidayData").show();
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ import io as BytesIO
|
||||||
import base64
|
import base64
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
from users.signals import save_newabsence
|
||||||
|
|
||||||
def randomString(stringLength=10):
|
def randomString(stringLength=10):
|
||||||
"""Generate a random string of fixed length """
|
"""Generate a random string of fixed length """
|
||||||
letters = string.ascii_lowercase
|
letters = string.ascii_lowercase
|
||||||
|
|
@ -982,6 +985,18 @@ def SettingsAjaxRouter(request):
|
||||||
# GET ELEMENTS
|
# GET ELEMENTS
|
||||||
newHolidayData = request.GET["new_data_info"].split("___")
|
newHolidayData = request.GET["new_data_info"].split("___")
|
||||||
# EVERY ELEMENT GET ID AND SAVE NEW DAY-INFO
|
# 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:
|
for ele in newHolidayData:
|
||||||
ele_elements = ele.split("__")
|
ele_elements = ele.split("__")
|
||||||
|
|
||||||
|
|
@ -991,20 +1006,33 @@ def SettingsAjaxRouter(request):
|
||||||
temp_year = UserYearAbsenceInfo.objects.get(pk=ele_id, agency=request.user.profile.agency)
|
temp_year = UserYearAbsenceInfo.objects.get(pk=ele_id, agency=request.user.profile.agency)
|
||||||
if(ele_type == "nor"):
|
if(ele_type == "nor"):
|
||||||
temp_year.days = ele_elements[1]
|
temp_year.days = ele_elements[1]
|
||||||
|
|
||||||
elif(ele_type == "rest"):
|
elif(ele_type == "rest"):
|
||||||
temp_year.restdays = ele_elements[1]
|
temp_year.restdays = ele_elements[1]
|
||||||
|
|
||||||
|
temp_year.days_inuse = 0
|
||||||
temp_year.save()
|
temp_year.save()
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"user_years" : UserYearAbsenceInfo.objects.filter(user=User.objects.get(pk=request.GET["userid"])),
|
"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)
|
absences = Absence.objects.filter(user=user_to_recalculate)
|
||||||
|
ab_counter = 0
|
||||||
|
|
||||||
|
# RECALCULATE ALL ABSENCES
|
||||||
for ab in 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)
|
return render(request, 'dasettings/data_absence_yeardata.html', context)
|
||||||
# RESET TIMEMANAGEMENT
|
# RESET TIMEMANAGEMENT
|
||||||
elif request.method == "GET" and request.GET['action'] == "del_tmdata" :
|
elif request.method == "GET" and request.GET['action'] == "del_tmdata" :
|
||||||
|
|
@ -1040,6 +1068,76 @@ def SettingsAjaxRouter(request):
|
||||||
|
|
||||||
|
|
||||||
''' BERECHNUNG URLAUBSTAGE USW. '''
|
''' 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 '''
|
''' AB HIER WIEDER RAUSNEHMEN '''
|
||||||
def getFinalHolidayData(abscence):
|
def getFinalHolidayData(abscence):
|
||||||
|
|
@ -1072,6 +1170,8 @@ def getFinalHolidayData(abscence):
|
||||||
holiday_lastyear = yeardata.restdays
|
holiday_lastyear = yeardata.restdays
|
||||||
holiday_nextyear = 0
|
holiday_nextyear = 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,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
{% loadmonthwork next_month user as monthwork %}
|
{% loadmonthwork next_month user as monthwork %}
|
||||||
|
|
||||||
|
|
||||||
Arbeitszeit im Monat: {{monthwork}}<br />
|
Gesamtarbeitszeit dieser Monat: {{monthwork}} Stunden<br />
|
||||||
{% loadaccounttime user as actualaccounttime %}
|
{% loadaccounttime user as actualaccounttime %}
|
||||||
Gleitzeitkonto:
|
Gleitzeitkonto:
|
||||||
{% if actualaccounttime.1 == 0 %}
|
{% if actualaccounttime.1 == 0 %}
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,7 @@
|
||||||
|
|
||||||
<span style="float: right !important; text-align: right; min-width: 82%; margin-bottom: -20px; margin-top: -10px; ">
|
<span style="float: right !important; text-align: right; min-width: 82%; margin-bottom: -20px; margin-top: -10px; ">
|
||||||
{% loadmonthwork next_month user as monthwork %}
|
{% loadmonthwork next_month user as monthwork %}
|
||||||
|
Gesamtarbeitszeit dieser Monat: {{monthwork}} Stunden<br />
|
||||||
|
|
||||||
Arbeitszeit im Monat: {{monthwork}}<br />
|
|
||||||
{% loadaccounttime user as actualaccounttime %}
|
{% loadaccounttime user as actualaccounttime %}
|
||||||
Gleitzeitkonto:
|
Gleitzeitkonto:
|
||||||
{% if actualaccounttime.1 == 0 %}
|
{% if actualaccounttime.1 == 0 %}
|
||||||
|
|
@ -22,9 +20,7 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<b><span style="color: red">-{{actualaccounttime.0}} Stunden</span></b>
|
<b><span style="color: red">-{{actualaccounttime.0}} Stunden</span></b>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div class="table-responsive ">
|
<div class="table-responsive ">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue