From 2146fa6bad73003fc920720e6cc473c4d7292d81 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Mon, 15 Jun 2026 19:08:07 -0400 Subject: [PATCH] Add paid hours to reports --- app.py | 24 +++++++++++++----------- templates/index.html | 8 ++++++-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app.py b/app.py index 6cd0635..9c526fe 100644 --- a/app.py +++ b/app.py @@ -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", diff --git a/templates/index.html b/templates/index.html index e04fc01..9527c31 100644 --- a/templates/index.html +++ b/templates/index.html @@ -38,12 +38,14 @@ User Total Hours Worked + Paid Hours {% for report in all_user_reports %} {{ report.name }} - {{ report.hours }} + {{ report.total_hours }} + {{ report.paid_hours }} {% endfor %} @@ -166,10 +168,12 @@ Total Hours Worked + Paid Hours - {{ report_hours }} + {{ report_hours.total_hours }} + {{ report_hours.paid_hours }}