Add paid hours to reports
This commit is contained in:
24
app.py
24
app.py
@@ -77,27 +77,28 @@ def generate_report(user_id, begin_date, end_date):
|
|||||||
begin_dt = parse_iso_datetime(begin_date)
|
begin_dt = parse_iso_datetime(begin_date)
|
||||||
end_dt = parse_iso_datetime(end_date)
|
end_dt = parse_iso_datetime(end_date)
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT entrytype, ts
|
SELECT entrytype, ts, paid
|
||||||
FROM entries
|
FROM entries
|
||||||
WHERE user_id = ?
|
WHERE user_id = ?
|
||||||
|
AND ts BETWEEN ? AND ?
|
||||||
ORDER BY ts ASC
|
ORDER BY ts ASC
|
||||||
""", (user_id,))
|
""", (user_id, begin_dt, end_dt))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
total_seconds = 0
|
total_seconds = 0
|
||||||
clock_in_time = None
|
paid_seconds = 0
|
||||||
for row in rows:
|
for row in rows:
|
||||||
timestamp = parse_iso_datetime(row["ts"])
|
timestamp = parse_iso_datetime(row["ts"])
|
||||||
if timestamp < begin_dt or timestamp > end_dt:
|
if timestamp < begin_dt or timestamp > end_dt:
|
||||||
continue
|
continue
|
||||||
if row["entrytype"] == "in":
|
delta = row["ts"] - timestamp
|
||||||
clock_in_time = timestamp
|
if row["paid"]:
|
||||||
elif row["entrytype"] == "out" and clock_in_time is not None:
|
paid_seconds += delta.total_seconds()
|
||||||
delta = timestamp - clock_in_time
|
else:
|
||||||
total_seconds += delta.total_seconds()
|
total_seconds += delta.total_seconds()
|
||||||
clock_in_time = None
|
|
||||||
total_hours = total_seconds / 3600.0
|
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"])
|
@app.route("/", methods=["GET", "POST"])
|
||||||
def index():
|
def index():
|
||||||
@@ -168,7 +169,7 @@ def index():
|
|||||||
default_end = parse_iso_datetime(end_date)
|
default_end = parse_iso_datetime(end_date)
|
||||||
else:
|
else:
|
||||||
for user in users:
|
for user in users:
|
||||||
hours = generate_report(
|
total_hours, paid_hours = generate_report(
|
||||||
user["id"],
|
user["id"],
|
||||||
default_begin.isoformat(),
|
default_begin.isoformat(),
|
||||||
default_end.isoformat()
|
default_end.isoformat()
|
||||||
@@ -176,7 +177,8 @@ def index():
|
|||||||
all_user_reports.append({
|
all_user_reports.append({
|
||||||
"id": user["id"],
|
"id": user["id"],
|
||||||
"name": user["name"],
|
"name": user["name"],
|
||||||
"hours": hours
|
"total_hours": total_hours,
|
||||||
|
"paid_hours": paid_hours
|
||||||
})
|
})
|
||||||
return render_template(
|
return render_template(
|
||||||
"index.html",
|
"index.html",
|
||||||
|
|||||||
@@ -38,12 +38,14 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>User</th>
|
<th>User</th>
|
||||||
<th>Total Hours Worked</th>
|
<th>Total Hours Worked</th>
|
||||||
|
<th>Paid Hours</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{% for report in all_user_reports %}
|
{% for report in all_user_reports %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ report.name }}</td>
|
<td>{{ report.name }}</td>
|
||||||
<td>{{ report.hours }}</td>
|
<td>{{ report.total_hours }}</td>
|
||||||
|
<td>{{ report.paid_hours }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
@@ -166,10 +168,12 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>Total Hours Worked</th>
|
<th>Total Hours Worked</th>
|
||||||
|
<th>Paid Hours</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ report_hours }}</td>
|
<td>{{ report_hours.total_hours }}</td>
|
||||||
|
<td>{{ report_hours.paid_hours }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user