diff --git a/definitions.py b/definitions.py index 7034256..a5c63cf 100644 --- a/definitions.py +++ b/definitions.py @@ -18,4 +18,17 @@ photofilename = "photo.jpg" # Status status_in = "eingestempelt" -status_out = "ausgestempelt" \ No newline at end of file +status_out = "ausgestempelt" + +# Abesenheiten + +absence_entries = {"U": { "name": "Urlaub", + "color": "green"}, + "K": { "name": "Krankheit", + "color": "red"}, + "KK": { "name": "Krankheit Kind", + "color": "orange"}, + "UU": { "name": "Urlaub aus Überstunden", + "color": "green"}, + "F": { "name": "Fortbildung", + "color": "black"}} diff --git a/users.py b/users.py index d534e34..976913a 100644 --- a/users.py +++ b/users.py @@ -171,11 +171,6 @@ class user: return(available_months) - - - - return available_months - def get_timestamps(self, year, month): try: with open(f"{self.userfolder}/{year}-{month}.txt", "r") as file: @@ -193,6 +188,33 @@ class user: def archive_hours(self, year, month): pass + def get_last_months_overtime(self, year, month): + try: + if int(month) == 1: + year = str(int(year) - 1) + month = str(12) + else: + month = str(int(month) - 1) + with open(f"{self.userfolder}/{year}-{month}.json", "r") as json_file: + json_data = json.load(json_file) + + if json_data["archived"] == 1: + overtime = int(json_data["overtime"]) + return overtime + else: + return 0 + except: + return 0 + + def get_absence(self, year, month): + try: + print(f"{self.userfolder}/{year}-{month}.json") + with open(f"{self.userfolder}/{year}-{month}.json", "r") as json_file: + json_data = json.load(json_file) + absence = json_data["absence"] + return absence + except: + return 0 # Benutzer auflisten def list_users(): diff --git a/users/testuser1/2025-3.json b/users/testuser1/2025-3.json index 7ac4a6f..8727377 100644 --- a/users/testuser1/2025-3.json +++ b/users/testuser1/2025-3.json @@ -1,4 +1,4 @@ { "archived": 1, - "total_hours": 28 + "overtime": 3950 } \ No newline at end of file diff --git a/users/testuser1/2025-4.json b/users/testuser1/2025-4.json index b7881be..ccd51db 100644 --- a/users/testuser1/2025-4.json +++ b/users/testuser1/2025-4.json @@ -1,4 +1,12 @@ { "archived": 0, - "total_hours": 0 + "total_hours": 0, + "absence": { + "1": "U", + "4": "U", + "7": "K", + "8": "UU", + "9": "KK", + "3": "K" + } } \ No newline at end of file diff --git a/users/testuser10/2025-4.json b/users/testuser10/2025-4.json index b7881be..48d10a6 100644 --- a/users/testuser10/2025-4.json +++ b/users/testuser10/2025-4.json @@ -1,4 +1,7 @@ { "archived": 0, - "total_hours": 0 + "total_hours": 0, + "absence": { + "1": "U" + } } \ No newline at end of file diff --git a/web_ui.py b/web_ui.py index b9324e5..cf1ceaf 100644 --- a/web_ui.py +++ b/web_ui.py @@ -96,6 +96,7 @@ def page_login(): @ui.page('/admin') def page_admin(): + ui.page_title(f"{app_title} {app_version}") data = load_adminsettings() active_login = cookie_hash(data["admin_user"], data["admin_password"]) try: @@ -191,6 +192,7 @@ def page_admin(): current_user = user(time_user.value) timestamps = current_user.get_timestamps(year=select_year.value, month=select_month.value) + user_absent = current_user.get_absence(year=select_year.value, month=select_month.value) # Dictionary für sortierte Timestamps timestamps_dict = { } # Dictionary mit zunächst leeren Tageinträgen befüllen @@ -213,6 +215,12 @@ def page_admin(): # Buchungen with ui.row(): + try: + for i in list(user_absent): + if int(i) == day: + ui.button(absence_entries[user_absent[i]]["name"]).props(f'color={absence_entries[user_absent[i]]["color"]}') + except: + pass if len(timestamps_dict[day]) > 0: timestamps_dict[day].sort() @@ -332,11 +340,19 @@ def page_admin(): ui.markdown(f"{current_user.workhours[entry][str(weekday_index)]} h") found_match = True - # Plus und Minuszeit für den Tag berechnen + # Saldo für den Tag berechnen if time.time() > day_in_list.timestamp(): time_duty = int(current_user.workhours[entry][str(weekday_index)]) * 3600 saldo = int(time_sum) - int(time_duty) + # Nach Abwesenheitseinträgen suchen + try: + for i in list(user_absent): + if int(i) == day: + saldo = 0 + except: + pass + general_saldo = general_saldo + saldo ui.markdown(convert_seconds_to_hours(saldo)) else: @@ -369,10 +385,20 @@ def page_admin(): ui.button("Abbrechen", on_click=add_dialog.close) add_dialog.open() ui.button("Eintrag hinzufügen", on_click=lambda day=day: add_entry(day)) - #4x leer und dann Gesamtsald + + #4x leer und dann Gesamtsaldo for i in range(4): ui.space() - ui.markdown(f"{convert_seconds_to_hours(general_saldo)}") + ui.markdown(f"{convert_seconds_to_hours(general_saldo)}") + for i in range(4): + ui.space() + ui.markdown("Stunden aus Vormonat") + last_months_overtime = current_user.get_last_months_overtime(select_year.value, select_month.value) + ui.markdown(f"{convert_seconds_to_hours(last_months_overtime)}") + for i in range(4): + ui.space() + ui.markdown("Gesamtsaldo") + ui.markdown(f"**{convert_seconds_to_hours(general_saldo + last_months_overtime)}**") table_grid.move(calendar_card) update_month_and_year()