fix layout + collect/writeoff debts
This commit is contained in:
8 files changed
+263
-35
No files matched your search
@@ -438,6 +438,74 @@ def admin_write_off_front() -> str:
|
||||
return redirect(url_for("admin_dashboard"))
|
||||
|
||||
|
||||
@app.post("/admin/collect-front")
|
||||
def admin_collect_front() -> str:
|
||||
if not is_admin():
|
||||
flash("Admin login required.", "error")
|
||||
return redirect(url_for("admin_login"))
|
||||
|
||||
debt_key = request.form.get("debt_key", "").strip()
|
||||
note = request.form.get("note", "").strip()
|
||||
amount_raw = request.form.get("amount", "0").strip()
|
||||
|
||||
try:
|
||||
amount_cents = int(round(float(amount_raw) * 100))
|
||||
except ValueError:
|
||||
flash("Amount must be a number.", "error")
|
||||
return redirect(url_for("admin_dashboard"))
|
||||
|
||||
if amount_cents <= 0:
|
||||
flash("Collected amount must be greater than zero.", "error")
|
||||
return redirect(url_for("admin_dashboard"))
|
||||
|
||||
try:
|
||||
session_id, player_name = debt_key.split("||", 1)
|
||||
except ValueError:
|
||||
flash("Select a valid player debt.", "error")
|
||||
return redirect(url_for("admin_dashboard"))
|
||||
|
||||
events = load_events(DATA_PATH)
|
||||
sessions = build_session_summaries(events)
|
||||
target = next(
|
||||
(session for session in sessions if session.session_id == session_id),
|
||||
None,
|
||||
)
|
||||
|
||||
if target is None:
|
||||
flash("Session not found.", "error")
|
||||
return redirect(url_for("admin_dashboard"))
|
||||
|
||||
entry = next(
|
||||
(entry for entry in target.entries if entry.player_name == player_name),
|
||||
None,
|
||||
)
|
||||
|
||||
if entry is None or entry.player_owes_cents <= 0:
|
||||
flash("That player does not have an outstanding front debt.", "error")
|
||||
return redirect(url_for("admin_dashboard"))
|
||||
|
||||
if amount_cents > entry.player_owes_cents:
|
||||
flash(
|
||||
f"Collection cannot exceed {cents_to_dollars(entry.player_owes_cents)}.",
|
||||
"error",
|
||||
)
|
||||
return redirect(url_for("admin_dashboard"))
|
||||
|
||||
append_event(
|
||||
DATA_PATH,
|
||||
session_id=target.session_id,
|
||||
session_date=target.session_date,
|
||||
player_name=entry.player_name,
|
||||
event_type="front_collected",
|
||||
amount_cents=amount_cents,
|
||||
note=note or "Front debt collected.",
|
||||
actor=app.config["ADMIN_USERNAME"],
|
||||
)
|
||||
|
||||
flash("Front debt collected.", "success")
|
||||
return redirect(url_for("admin_dashboard"))
|
||||
|
||||
|
||||
@app.post("/admin/open-session")
|
||||
def admin_open_session() -> str:
|
||||
if not is_admin():
|
||||
@@ -537,6 +605,9 @@ def admin_dashboard():
|
||||
"players_owe_cents": sum(
|
||||
session.total_player_owes_cents for session in sessions
|
||||
),
|
||||
"collected_cents": sum(
|
||||
session.total_front_collected_cents for session in sessions
|
||||
),
|
||||
"written_off_cents": sum(
|
||||
session.total_front_writeoff_cents for session in sessions
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user