Add comments field

This commit is contained in:
2026-06-16 09:09:05 -04:00
parent 36f6d5135f
commit b2f84a27cd
2 changed files with 36 additions and 12 deletions

35
app.py
View File

@@ -34,6 +34,7 @@ def initialize_database():
entrytype TEXT NOT NULL CHECK(entrytype IN ('in', 'out')), entrytype TEXT NOT NULL CHECK(entrytype IN ('in', 'out')),
ts TEXT NOT NULL, ts TEXT NOT NULL,
paid BOOLEAN NOT NULL DEFAULT FALSE, paid BOOLEAN NOT NULL DEFAULT FALSE,
comments TEXT,
FOREIGN KEY(user_id) REFERENCES users(id) FOREIGN KEY(user_id) REFERENCES users(id)
) )
""") """)
@@ -57,17 +58,23 @@ def parse_iso_datetime(value):
def utc_now(): def utc_now():
return datetime.now(timezone.utc) return datetime.now(timezone.utc)
def create_entry(user_id, entry_type, client_timestamp=None): def create_entry(user_id, entry_type, client_timestamp=None, comments=None):
conn = get_db_connection() conn = get_db_connection()
cursor = conn.cursor() cursor = conn.cursor()
if client_timestamp: if client_timestamp:
timestamp = parse_iso_datetime(client_timestamp) timestamp = parse_iso_datetime(client_timestamp)
else: else:
timestamp = utc_now() timestamp = utc_now()
cursor.execute(""" if comments:
INSERT INTO entries (user_id, entrytype, ts, paid) cursor.execute("""
VALUES (?, ?, ?, ?) INSERT INTO entries (user_id, entrytype, ts, paid, comments)
""", (user_id, entry_type, timestamp.isoformat(), False)) VALUES (?, ?, ?, ?, ?)
""", (user_id, entrytype, timestamp.isoformat(), False, comments))
else:
cursor.execute("""
INSERT INTO entries (user_id, entrytype, ts, paid)
VALUES (?, ?, ?, ?)
""", (user_id, entrytype, timestamp.isoformat(), False))
conn.commit() conn.commit()
conn.close() conn.close()
@@ -77,7 +84,7 @@ 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, paid SELECT entrytype, ts, paid, comments
FROM entries FROM entries
WHERE user_id = ? WHERE user_id = ?
AND ts BETWEEN ? AND ? AND ts BETWEEN ? AND ?
@@ -145,17 +152,20 @@ def index():
selected_user_id = request.form.get("user_id") selected_user_id = request.form.get("user_id")
action = request.form.get("action") action = request.form.get("action")
client_timestamp = request.form.get("client_timestamp") client_timestamp = request.form.get("client_timestamp")
comments = request.form.get("comments")
if action == "clock_in": if action == "clock_in":
create_entry( create_entry(
selected_user_id, selected_user_id,
"in", "in",
client_timestamp client_timestamp,
comments
) )
elif action == "clock_out": elif action == "clock_out":
create_entry( create_entry(
selected_user_id, selected_user_id,
"out", "out",
client_timestamp client_timestamp,
comments
) )
elif action == "pay": elif action == "pay":
# Update the paid column for all entries for the selected user to True # Update the paid column for all entries for the selected user to True
@@ -211,7 +221,7 @@ def api_get_users():
def api_get_entries(): def api_get_entries():
conn = get_db_connection() conn = get_db_connection()
entries = conn.execute(""" entries = conn.execute("""
SELECT id, user_id, entrytype, ts, paid SELECT id, user_id, entrytype, ts, paid, comments
FROM entries FROM entries
ORDER BY ts DESC ORDER BY ts DESC
""").fetchall() """).fetchall()
@@ -225,15 +235,17 @@ def api_create_entry():
entry_type = data.get("entrytype") entry_type = data.get("entrytype")
client_timestamp = data.get("timestamp") client_timestamp = data.get("timestamp")
paid = data.get("paid", False) paid = data.get("paid", False)
comments = data.get("comments", "")
if entry_type not in ("in", "out", "pay"): if entry_type not in ("in", "out", "pay"):
return jsonify({ return jsonify({
"error": "Invalid entrytype" "error": "Invalid entrytype"
}), 400 }), 400
create_entry( create_entry(
user_id, user_id,
entry_type, entrytype,
client_timestamp, client_timestamp,
paid paid,
comments
) )
return jsonify({ return jsonify({
"status": "success" "status": "success"
@@ -246,4 +258,3 @@ if __name__ == "__main__":
port=5000, port=5000,
debug=False debug=False
) )

View File

@@ -149,6 +149,19 @@
</td> </td>
</tr> </tr>
<tr>
<td>Comments</td>
<td>
<input
type="text"
name="comments"
id="comments"
value=""
>
</td>
</tr>
<tr> <tr>
<td>Report</td> <td>Report</td>