diff --git a/users/testuser1/2025-4.txt b/users/testuser1/2025-4.txt index 454cd73..aef4b0f 100644 --- a/users/testuser1/2025-4.txt +++ b/users/testuser1/2025-4.txt @@ -34,3 +34,4 @@ 1745391058 1745391059 1743660240 +1743685200 diff --git a/users/testuser1/settings.json b/users/testuser1/settings.json index 248c322..4f9e3b6 100644 --- a/users/testuser1/settings.json +++ b/users/testuser1/settings.json @@ -4,13 +4,13 @@ "password": "123456789", "workhours": { "2024-04-01": { - "1": "11", - "2": "12", - "3": "13", - "4": "14", - "5": "15", - "6": "16", - "7": "17", + "1": "8", + "2": "8", + "3": "8", + "4": "8", + "5": "8", + "6": "0", + "7": "0", "vacation": "35" }, "2025-05-13": { diff --git a/users/testuser3/settings.json b/users/testuser3/settings.json index 47c60e7..827a4fb 100644 --- a/users/testuser3/settings.json +++ b/users/testuser3/settings.json @@ -4,23 +4,23 @@ "password": "123456789", "workhours": { "2024-04-01": { - "0": "0", - "1": "8", + "1": "0", "2": "8", "3": "8", "4": "8", "5": "8", - "6": "0", + "6": "8", + "7": "0", "vacation": "30" }, "2024-04-07": { - "0": "0", - "1": "6", + "1": "0", "2": "6", "3": "6", - "4": "8", - "5": "6", - "6": "0", + "4": "6", + "5": "8", + "6": "6", + "7": "0", "vacation": "28" } } diff --git a/users/testuser5/settings.json b/users/testuser5/settings.json index 1935ee2..aeec70b 100644 --- a/users/testuser5/settings.json +++ b/users/testuser5/settings.json @@ -4,33 +4,33 @@ "password": "123456789", "workhours": { "2025-04-01": { - "0": "0", - "1": "8", + "1": "0", "2": "8", "3": "8", "4": "8", "5": "8", - "6": "0", + "6": "8", + "7": "0", "vacation": "30" }, "2025-04-07": { - "0": "5", - "1": "6", + "1": "5", "2": "6", "3": "6", - "4": "8", - "5": "6", - "6": "0", + "4": "6", + "5": "8", + "6": "6", + "7": "0", "vacation": "28" }, "2025-03-16": { - "0": 0, "1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0, + "7": 0, "vacation": 0 } } diff --git a/web_ui.py b/web_ui.py index cf7efa7..f5ef720 100644 --- a/web_ui.py +++ b/web_ui.py @@ -34,12 +34,17 @@ def load_adminsettings(): return(-1) def convert_seconds_to_hours(seconds): + if seconds < 0: + sign = "-" + seconds = seconds * (-1) + else: + sign = "" hours = seconds // 3600 remaining_seconds = seconds - hours * 3600 minutes = remaining_seconds // 60 remaining_seconds = remaining_seconds - minutes * 60 - if remaining_seconds > 0: - minutes += 1 + if remaining_seconds > 0 and sign != "-": + minutes = minutes + 1 if hours < 10: hours = "0" + str(hours) else: @@ -48,7 +53,12 @@ def convert_seconds_to_hours(seconds): minutes = "0" + str(minutes) else: minutes = str(minutes) - return(f"{hours}:{minutes}") + + if sign == "-": + return(f"-{hours}:{minutes}") + else: + return(f"{hours}:{minutes}") + @ui.page('/login') def page_login(): @@ -80,7 +90,6 @@ def page_login(): ui.button(text="Login", on_click=lambda: login()) - @ui.page('/admin') def page_admin(): data = load_adminsettings() @@ -112,19 +121,6 @@ def page_admin(): with ui.tab_panel(time_overview): ui.markdown("##Übersichten") - # Basisstruktur - with ui.card(): - with ui.row(): - - - userlist = list_users() - ui.markdown("Benutzer:") - time_user = ui.select(options=userlist) - time_user.value = userlist[0] - def update_user(): - pass - ui.button("Aktualisieren", on_click=update_user) - # Tabelle konstruieren with ui.card(): @@ -141,6 +137,11 @@ def page_admin(): select_month.set_options(available_months_dict) select_month.value = list(available_months)[0] + userlist = list_users() + ui.markdown("Benutzer:") + time_user = ui.select(options=userlist) + + time_user.value = userlist[0] current_year = datetime.datetime.now().year current_month = datetime.datetime.now().month @@ -181,6 +182,8 @@ def page_admin(): current_user = user(time_user.value) timestamps = current_user.get_timestamps(year=select_year.value, month=select_month.value) + general_saldo = 0 + for day in range(1, monthrange(int(select_year.value), int(select_month.value))[1] + 1): day_in_list = datetime.datetime(int(select_year.value), int(select_month.value), day) @@ -272,23 +275,33 @@ def page_admin(): timestamps_of_this_day.append(i) timestamps_of_this_day.sort() + time_sum = 0 if len(timestamps_of_this_day) > 1: - time_sum = 0 + + if len(timestamps_of_this_day) % 2 == 0: for i in range(0, len(timestamps_of_this_day), 2): time_delta = int(timestamps_of_this_day[i+1]) - int(timestamps_of_this_day[i]) - time_sum += time_delta + time_sum = time_sum + time_delta else: for i in range(0, len(timestamps_of_this_day) - 1, 2): time_delta = int(timestamps_of_this_day[i+1]) - int(timestamps_of_this_day[i]) - time_sum += time_delta + time_sum = time_sum + time_delta ui.markdown(convert_seconds_to_hours(time_sum)) else: ui.markdown("Kein") - # ui.markdown("Ist") - ui.markdown("+/-") + # Plus und Minuszeit 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) + general_saldo = general_saldo + saldo + ui.markdown(convert_seconds_to_hours(saldo)) + else: + ui.markdown("-") + def add_entry(day): with ui.dialog() as add_dialog, ui.card(): @@ -315,6 +328,10 @@ 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 + for i in range(4): + ui.space() + ui.markdown(f"{convert_seconds_to_hours(general_saldo)}") table_grid.move(calendar_card) update_month_and_year()