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 @@