Fehlerbehebung Sollstunden, Übersicht Fehltage

This commit is contained in:
Alexander Malzkuhn 2025-04-28 16:39:08 +02:00
parent 005d5be686
commit 4c7e8dfadc
3 changed files with 38 additions and 7 deletions

View File

@ -243,6 +243,7 @@ Dies kann nicht rückgägig gemacht werden!''')
ui.button(datetime.datetime.fromtimestamp(int(timestamps_dict[day][i])).strftime('%H:%M'), on_click=lambda t_stamp=timestamps_dict[day][i], day=day: edit_entry(t_stamp, day)) ui.button(datetime.datetime.fromtimestamp(int(timestamps_dict[day][i])).strftime('%H:%M'), on_click=lambda t_stamp=timestamps_dict[day][i], day=day: edit_entry(t_stamp, day))
# Arbeitszeit Ist bestimmen # Arbeitszeit Ist bestimmen
timestamps_of_this_day = [] timestamps_of_this_day = []
# Suche mir alle timestamps für diesen Tag # Suche mir alle timestamps für diesen Tag
@ -254,6 +255,7 @@ Dies kann nicht rückgägig gemacht werden!''')
timestamps_of_this_day.append(i) timestamps_of_this_day.append(i)
timestamps_of_this_day.sort() timestamps_of_this_day.sort()
time_sum = 0 time_sum = 0
if len(timestamps_of_this_day) > 1: if len(timestamps_of_this_day) > 1:

37
api.py
View File

@ -12,13 +12,14 @@ import calendar
# Überblicksseite zum Ausdrucken oder als PDF speichern # Überblicksseite zum Ausdrucken oder als PDF speichern
@ui.page('/api/overview/month/{username}-{year}-{month}') @ui.page('/api/overview/month/{username}/{year}-{month}')
def page(username: str, year: int, month: int): def page(username: str, year: int, month: int):
try: try:
current_user = user(username) current_user = user(username)
ui.page_title(f"Bericht für {current_user.fullname} für {calendar.month_name[month]} {year}") ui.page_title(f"Bericht für {current_user.fullname} für {calendar.month_name[month]} {year}")
ui.label(datetime.now().strftime('%d.%m.%Y')).classes('absolute top-5 right-5') ui.label(datetime.now().strftime('%d.%m.%Y')).classes('absolute top-5 right-5')
ui.space()
ui.markdown(f'#Bericht für {current_user.fullname} für {calendar.month_name[month]} {year}') ui.markdown(f'#Bericht für {current_user.fullname} für {calendar.month_name[month]} {year}')
columns = [ columns = [
@ -147,12 +148,12 @@ def page(username: str, year: int, month: int):
rows.append({'date': current_day_date, 'bookings': booking_text, 'is_time': is_time, 'target_time': target_time, 'total': total}) rows.append({'date': current_day_date, 'bookings': booking_text, 'is_time': is_time, 'target_time': target_time, 'total': total})
overview_table = ui.table(columns=columns, rows=rows).classes('w-120') overview_table = ui.table(columns=columns, rows=rows, row_key='date').classes('w-full')
# Zeilenumbruch umsetzen # Zeilenumbruch umsetzen
overview_table.add_slot('body-cell', r''' overview_table.add_slot('body-cell', r'''
<td :props="props" :style="{'white-space':'pre-line'}">{{ props.value }}</td> <td :props="props" :style="{'white-space':'pre-line'}">{{ props.value }}</td>
''') ''')
# Überstundenzusammenfassung # Überstundenzusammenfassung
with ui.grid(columns=2).classes('w-full gap-0'): with ui.grid(columns=2).classes('w-full gap-0'):
@ -165,6 +166,36 @@ def page(username: str, year: int, month: int):
overtime_overall = last_months_overtime + general_saldo overtime_overall = last_months_overtime + general_saldo
ui.markdown(f"**{convert_seconds_to_hours(overtime_overall)} h**") ui.markdown(f"**{convert_seconds_to_hours(overtime_overall)} h**")
absences_this_month = current_user.get_absence(year, month)
absence_dict = { }
for abbr in list(absence_entries):
absence_dict[abbr] = 0
for key, value in absences_this_month.items():
if value in list(absence_dict):
absence_dict[value] += 1
total_absence_days = 0
for key, value in absence_dict.items():
total_absence_days += absence_dict[key]
if total_absence_days > 0:
ui.markdown("###Abwesenheitstage diesen Monat:")
a_columns = [
{'name': 'type', 'label': 'Typ', 'field': 'type', 'required': True, 'align': 'left'},
{'name': 'sum', 'label': 'Tage', 'field': 'sum', 'required': True, 'align': 'left'},
]
a_row = [ ]
for key,value in absence_dict.items():
if value > 0:
a_row.append({'type': absence_entries[key]['name'], 'sum': value})
absence_table = ui.table(columns=a_columns, rows=a_row)
except Exception as e: except Exception as e:
print(str(type(e).__name__) + " " + str(e)) print(str(type(e).__name__) + " " + str(e))
if type(e) == UnboundLocalError: if type(e) == UnboundLocalError:

View File

@ -156,7 +156,6 @@ class user:
years.append(year) years.append(year)
years.sort() years.sort()
print(years)
return years return years
def get_months(self, year): def get_months(self, year):
@ -183,7 +182,7 @@ class user:
elif int(year) < year_now: elif int(year) < year_now:
for i in range(1, 13): for i in range(1, 13):
available_months.append(i) available_months.append(i)
print(available_months)
for file in os.listdir(self.userfolder): for file in os.listdir(self.userfolder):
if re.match(r"\d{4}-\d{1,2}\.json", file): if re.match(r"\d{4}-\d{1,2}\.json", file):
@ -254,8 +253,6 @@ class user:
except: except:
json_data.update({ "absence": { str(int(day)): absence_type}}) json_data.update({ "absence": { str(int(day)): absence_type}})
json_dict = json.dumps(json_data, indent=4) json_dict = json.dumps(json_data, indent=4)
print(json_dict)
print(f"{self.userfolder}/{year}-{month}.json")
with open(f"{self.userfolder}/{int(year)}-{int(month)}.json", "w") as json_file: with open(f"{self.userfolder}/{int(year)}-{int(month)}.json", "w") as json_file:
json_file.write(json_dict) json_file.write(json_dict)
@ -285,6 +282,7 @@ class user:
if int(weekday) == 0: if int(weekday) == 0:
weekday = str(7) weekday = str(7)
hours_to_work = self.workhours[entry][weekday] hours_to_work = self.workhours[entry][weekday]
break
else: else:
# Wenn vor Einstellungsdatum -1 ausgeben # Wenn vor Einstellungsdatum -1 ausgeben
hours_to_work = -1 hours_to_work = -1