Zusätzliche Übersichtsansicht im Adminbereich

Genehmigungsfunktion für Urlaube mit automatischer Eintragung
This commit is contained in:
Alexander Malzkuhn 2025-05-28 12:32:48 +02:00
parent 57eec6d4f1
commit a12bd1e15a
5 changed files with 634 additions and 522 deletions

File diff suppressed because it is too large Load Diff

View File

@ -525,7 +525,7 @@ def json_info(api_key: str):
data["time"]["overall"] = time_saldo data["time"]["overall"] = time_saldo
data["vacation"] = { } data["vacation"] = { }
data["vacation"]["claim"] = current_user.get_vacation_claim(now_dt.year, now_dt.month, now_dt.day) data["vacation"]["claim"] = current_user.get_vacation_claim(now_dt.year, now_dt.month, now_dt.day)
data["vacation"]["used"] = current_user.count_vacation_days(now_dt.year) data["vacation"]["used"] = current_user.count_absence_days("U", now_dt.year)
data["vacation"]["remaining"] = data["vacation"]["claim"] - data["vacation"]["used"] data["vacation"]["remaining"] = data["vacation"]["claim"] - data["vacation"]["used"]
return data return data
break break

View File

@ -262,9 +262,10 @@ def homepage():
va_table = ui.table(columns=va_columns, rows=va_rows, selection="single", row_key="index").classes('w-full') va_table = ui.table(columns=va_columns, rows=va_rows, selection="single", row_key="index").classes('w-full')
def retract_va(): def retract_va():
try: try:
current_user.revoke_vacation_application(va_table.selected[0]["index"]) retract_result = current_user.revoke_vacation_application(va_table.selected[0]["index"])
open_vacation_applications.refresh() open_vacation_applications.refresh()
ui.notify("Urlaubsantrag zurückgezogen") if retract_result == 0:
ui.notify("Urlaubsantrag zurückgezogen")
except IndexError: except IndexError:
ui.notify("Kein Urlaubsanstrag ausgewählt") ui.notify("Kein Urlaubsanstrag ausgewählt")
ui.button("Zurückziehen", on_click=retract_va).tooltip("Hiermit wird der oben gewählte Urlaubsantrag zurückgezogen.").classes('w-full') ui.button("Zurückziehen", on_click=retract_va).tooltip("Hiermit wird der oben gewählte Urlaubsantrag zurückgezogen.").classes('w-full')

View File

@ -5,6 +5,8 @@ import hashlib
import os import os
from calendar import monthrange from calendar import monthrange
from stat import S_IREAD, S_IWUSR from stat import S_IREAD, S_IWUSR
from nicegui import ui
import datetime import datetime
import time import time
import json import json
@ -61,7 +63,6 @@ class user:
with open(filename, 'a') as file: with open(filename, 'a') as file:
# Schreibe den Timestamp in die Datei und füge einen Zeilenumbruch hinzu # Schreibe den Timestamp in die Datei und füge einen Zeilenumbruch hinzu
file.write(f"{timestamp}\n") file.write(f"{timestamp}\n")
file.close()
except FileNotFoundError: except FileNotFoundError:
# Fehlende Verzeichnisse anlegen # Fehlende Verzeichnisse anlegen
folder_path = os.path.dirname(filename) folder_path = os.path.dirname(filename)
@ -263,7 +264,7 @@ class user:
filename_txt = os.path.join(self.userfolder, f"{year}-{month}.txt") filename_txt = os.path.join(self.userfolder, f"{year}-{month}.txt")
os.chmod(filename_txt, S_IREAD) os.chmod(filename_txt, S_IREAD)
def get_last_months_overtime(self, year, month): def get_last_months_overtime(self, year=datetime.datetime.now().year, month=datetime.datetime.now().month):
try: try:
if int(month) == 1: if int(month) == 1:
year = str(int(year) - 1) year = str(int(year) - 1)
@ -387,7 +388,7 @@ class user:
hours_to_work = -1 hours_to_work = -1
return hours_to_work return hours_to_work
def get_vacation_claim(self, year, month, day): def get_vacation_claim(self, year=datetime.datetime.now().year, month=datetime.datetime.now().month, day=datetime.datetime.now().day):
workhour_entries = list(self.workhours) workhour_entries = list(self.workhours)
workhour_entries.sort() workhour_entries.sort()
day_to_check = datetime.datetime(int(year), int(month), int(day)) day_to_check = datetime.datetime(int(year), int(month), int(day))
@ -405,18 +406,18 @@ class user:
return int(claim) return int(claim)
def count_vacation_days(self, year): def count_absence_days(self, absence_code: str, year=datetime.datetime.now().year):
vacation_used = 0 absence_days = 0
for month in range(0, 13): for month in range(0, 13):
try: try:
absence_dict = self.get_absence(year, month) absence_dict = self.get_absence(year, month)
for entry, absence_type in absence_dict.items(): for entry, absence_type in absence_dict.items():
if absence_type == "U": if absence_type == absence_code:
vacation_used += 1 absence_days += 1
except: except:
pass pass
return vacation_used return absence_days
def delete_photo(self): def delete_photo(self):
os.remove(self.photofile) os.remove(self.photofile)
@ -477,14 +478,19 @@ class user:
application_file = os.path.join(self.userfolder, va_file) application_file = os.path.join(self.userfolder, va_file)
with open(application_file, 'r') as json_file: with open(application_file, 'r') as json_file:
applications = json.load(json_file) applications = json.load(json_file)
del(applications[index]) try:
new_applications = { } del(applications[index])
new_index = 0 new_applications = { }
for index, dates in applications.items(): new_index = 0
new_applications[new_index] = dates for index, dates in applications.items():
new_index += 1 new_applications[new_index] = dates
with open(application_file, 'w') as json_file: new_index += 1
json_file.write(json.dumps(new_applications, indent=4)) with open(application_file, 'w') as json_file:
json_file.write(json.dumps(new_applications, indent=4))
return 0
except KeyError:
ui.notify("Urlaubsantrag wurde schon bearbeitet")
return -1
# Benutzer auflisten # Benutzer auflisten
def list_users(): def list_users():

View File

@ -71,6 +71,7 @@
"2030-10-03": "Tag der deutschen Einheit", "2030-10-03": "Tag der deutschen Einheit",
"2030-10-30": "Reformationstag", "2030-10-30": "Reformationstag",
"2030-12-25": "1. Weihnachtsfeiertag", "2030-12-25": "1. Weihnachtsfeiertag",
"2030-12-26": "2. Weihnachtsfeiertag" "2030-12-26": "2. Weihnachtsfeiertag",
"2025-06-11": "Testeintrag"
} }
} }