Add paid hours to reports

This commit is contained in:
2026-06-15 19:08:07 -04:00
parent 3defdc3aab
commit 2146fa6bad
2 changed files with 19 additions and 13 deletions

24
app.py
View File

@@ -77,27 +77,28 @@ def generate_report(user_id, begin_date, end_date):
begin_dt = parse_iso_datetime(begin_date)
end_dt = parse_iso_datetime(end_date)
cursor.execute("""
SELECT entrytype, ts
SELECT entrytype, ts, paid
FROM entries
WHERE user_id = ?
AND ts BETWEEN ? AND ?
ORDER BY ts ASC
""", (user_id,))
""", (user_id, begin_dt, end_dt))
rows = cursor.fetchall()
conn.close()
total_seconds = 0
clock_in_time = None
paid_seconds = 0
for row in rows:
timestamp = parse_iso_datetime(row["ts"])
if timestamp < begin_dt or timestamp > end_dt:
continue
if row["entrytype"] == "in":
clock_in_time = timestamp
elif row["entrytype"] == "out" and clock_in_time is not None:
delta = timestamp - clock_in_time
delta = row["ts"] - timestamp
if row["paid"]:
paid_seconds += delta.total_seconds()
else:
total_seconds += delta.total_seconds()
clock_in_time = None
total_hours = total_seconds / 3600.0
return round(total_hours, 2)
paid_hours = paid_seconds / 3600.0
return round(total_hours, 2), round(paid_hours, 2)
@app.route("/", methods=["GET", "POST"])
def index():
@@ -168,7 +169,7 @@ def index():
default_end = parse_iso_datetime(end_date)
else:
for user in users:
hours = generate_report(
total_hours, paid_hours = generate_report(
user["id"],
default_begin.isoformat(),
default_end.isoformat()
@@ -176,7 +177,8 @@ def index():
all_user_reports.append({
"id": user["id"],
"name": user["name"],
"hours": hours
"total_hours": total_hours,
"paid_hours": paid_hours
})
return render_template(
"index.html",