1 Commits
0.24 ... 0.25

Author SHA1 Message Date
b2aaca5df9 feat: Add /sync-bank endpoint to trigger bank sync and inference from web UI
Some checks failed
Deploy to K8s / deploy (push) Failing after 6s
Build and Push / build (push) Successful in 6s
Adds a new GET /sync-bank route that runs sync_to_sheets (2026) + infer_payments + flush_cache,
capturing all output and displaying it on a styled results page. Adds "Tools: [Sync Bank Data]"
nav link to all templates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 17:24:41 +01:00
9 changed files with 294 additions and 43 deletions

105
app.py
View File

@@ -24,6 +24,8 @@ from config import (
from attendance import get_members_with_fees, get_junior_members_with_fees, ADULT_MERGED_MONTHS, JUNIOR_MERGED_MONTHS from attendance import get_members_with_fees, get_junior_members_with_fees, ADULT_MERGED_MONTHS, JUNIOR_MERGED_MONTHS
from match_payments import reconcile, fetch_sheet_data, fetch_exceptions, normalize from match_payments import reconcile, fetch_sheet_data, fetch_exceptions, normalize
from cache_utils import get_sheet_modified_time, read_cache, write_cache, _LAST_CHECKED, flush_cache from cache_utils import get_sheet_modified_time, read_cache, write_cache, _LAST_CHECKED, flush_cache
from sync_fio_to_sheets import sync_to_sheets
from infer_payments import infer_payments
def get_cached_data(cache_key, sheet_id, fetch_func, *args, serialize=None, deserialize=None, **kwargs): def get_cached_data(cache_key, sheet_id, fetch_func, *args, serialize=None, deserialize=None, **kwargs):
mod_time = get_sheet_modified_time(cache_key) mod_time = get_sheet_modified_time(cache_key)
@@ -120,6 +122,35 @@ def flush_cache_endpoint():
deleted = flush_cache() deleted = flush_cache()
return jsonify({"status": "ok", "deleted_files": deleted}) return jsonify({"status": "ok", "deleted_files": deleted})
@app.route("/sync-bank")
def sync_bank():
import contextlib
output = io.StringIO()
success = True
try:
with contextlib.redirect_stdout(output), contextlib.redirect_stderr(output):
# sync_to_sheets: equivalent of make sync-2026
output.write("=== Syncing Fio transactions (2026) ===\n")
sync_to_sheets(
spreadsheet_id=PAYMENTS_SHEET_ID,
credentials_path=CREDENTIALS_PATH,
date_from_str="2026-01-01",
date_to_str="2026-12-31",
sort_by_date=True,
)
output.write("\n=== Inferring payment details ===\n")
infer_payments(PAYMENTS_SHEET_ID, CREDENTIALS_PATH)
output.write("\n=== Flushing cache ===\n")
deleted = flush_cache()
output.write(f"Deleted {deleted} cache files.\n")
output.write("\n=== Done ===\n")
except Exception as e:
import traceback
output.write(f"\n!!! Error: {e}\n")
output.write(traceback.format_exc())
success = False
return render_template("sync.html", output=output.getvalue(), success=success)
@app.route("/version") @app.route("/version")
def version(): def version():
return BUILD_META return BUILD_META
@@ -300,8 +331,9 @@ def adults_view():
formatted_results = [] formatted_results = []
for name in adult_names: for name in adult_names:
data = result["members"][name] data = result["members"][name]
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": ""} row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": "", "raw_unpaid_periods": ""}
unpaid_months = [] unpaid_months = []
raw_unpaid_months = []
for m in sorted_months: for m in sorted_months:
mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "attendance_count": 0, "paid": 0, "exception": None}) mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "attendance_count": 0, "paid": 0, "exception": None})
expected = mdata.get("expected", 0) expected = mdata.get("expected", 0)
@@ -309,12 +341,12 @@ def adults_view():
count = mdata.get("attendance_count", 0) count = mdata.get("attendance_count", 0)
paid = int(mdata.get("paid", 0)) paid = int(mdata.get("paid", 0))
exception_info = mdata.get("exception", None) exception_info = mdata.get("exception", None)
monthly_totals[m]["expected"] += expected monthly_totals[m]["expected"] += expected
monthly_totals[m]["paid"] += paid monthly_totals[m]["paid"] += paid
override_amount = exception_info["amount"] if exception_info else None override_amount = exception_info["amount"] if exception_info else None
if override_amount is not None and override_amount != original_expected: if override_amount is not None and override_amount != original_expected:
is_overridden = True is_overridden = True
fee_display = f"{override_amount} ({original_expected}) CZK ({count})" if count > 0 else f"{override_amount} ({original_expected}) CZK" fee_display = f"{override_amount} ({original_expected}) CZK ({count})" if count > 0 else f"{override_amount} ({original_expected}) CZK"
@@ -325,7 +357,7 @@ def adults_view():
status = "empty" status = "empty"
cell_text = "-" cell_text = "-"
amount_to_pay = 0 amount_to_pay = 0
if expected > 0: if expected > 0:
amount_to_pay = max(0, expected - paid) amount_to_pay = max(0, expected - paid)
if paid >= expected: if paid >= expected:
@@ -335,32 +367,36 @@ def adults_view():
status = "partial" status = "partial"
cell_text = f"{paid}/{fee_display}" cell_text = f"{paid}/{fee_display}"
unpaid_months.append(month_labels[m]) unpaid_months.append(month_labels[m])
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
else: else:
status = "unpaid" status = "unpaid"
cell_text = f"0/{fee_display}" cell_text = f"0/{fee_display}"
unpaid_months.append(month_labels[m]) unpaid_months.append(month_labels[m])
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
elif paid > 0: elif paid > 0:
status = "surplus" status = "surplus"
cell_text = f"PAID {paid}" cell_text = f"PAID {paid}"
else: else:
cell_text = "-" cell_text = "-"
amount_to_pay = 0 amount_to_pay = 0
if expected > 0 or paid > 0: if expected > 0 or paid > 0:
tooltip = f"Received: {paid}, Expected: {expected}" tooltip = f"Received: {paid}, Expected: {expected}"
else: else:
tooltip = "" tooltip = ""
row["months"].append({ row["months"].append({
"text": cell_text, "text": cell_text,
"overridden": is_overridden, "overridden": is_overridden,
"status": status, "status": status,
"amount": amount_to_pay, "amount": amount_to_pay,
"month": month_labels[m], "month": month_labels[m],
"raw_month": m,
"tooltip": tooltip "tooltip": tooltip
}) })
row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "") row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "")
row["raw_unpaid_periods"] = "+".join(raw_unpaid_months)
row["balance"] = data["total_balance"] row["balance"] = data["total_balance"]
formatted_results.append(row) formatted_results.append(row)
@@ -439,17 +475,18 @@ def reconcile_view():
formatted_results = [] formatted_results = []
for name in adult_names: for name in adult_names:
data = result["members"][name] data = result["members"][name]
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": ""} row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": "", "raw_unpaid_periods": ""}
unpaid_months = [] unpaid_months = []
raw_unpaid_months = []
for m in sorted_months: for m in sorted_months:
mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "paid": 0}) mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "paid": 0})
expected = mdata["expected"] expected = mdata["expected"]
paid = int(mdata["paid"]) paid = int(mdata["paid"])
status = "empty" status = "empty"
cell_text = "-" cell_text = "-"
amount_to_pay = 0 amount_to_pay = 0
if expected > 0: if expected > 0:
if paid >= expected: if paid >= expected:
status = "ok" status = "ok"
@@ -459,23 +496,27 @@ def reconcile_view():
cell_text = f"{paid}/{expected}" cell_text = f"{paid}/{expected}"
amount_to_pay = expected - paid amount_to_pay = expected - paid
unpaid_months.append(month_labels[m]) unpaid_months.append(month_labels[m])
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
else: else:
status = "unpaid" status = "unpaid"
cell_text = f"UNPAID {expected}" cell_text = f"UNPAID {expected}"
amount_to_pay = expected amount_to_pay = expected
unpaid_months.append(month_labels[m]) unpaid_months.append(month_labels[m])
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
elif paid > 0: elif paid > 0:
status = "surplus" status = "surplus"
cell_text = f"PAID {paid}" cell_text = f"PAID {paid}"
row["months"].append({ row["months"].append({
"text": cell_text, "text": cell_text,
"status": status, "status": status,
"amount": amount_to_pay, "amount": amount_to_pay,
"month": month_labels[m] "month": month_labels[m],
"raw_month": m
}) })
row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "") row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "")
row["raw_unpaid_periods"] = "+".join(raw_unpaid_months)
row["balance"] = data["total_balance"] # Updated to use total_balance row["balance"] = data["total_balance"] # Updated to use total_balance
formatted_results.append(row) formatted_results.append(row)
@@ -552,8 +593,9 @@ def juniors_view():
formatted_results = [] formatted_results = []
for name in junior_names: for name in junior_names:
data = result["members"][name] data = result["members"][name]
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": ""} row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": "", "raw_unpaid_periods": ""}
unpaid_months = [] unpaid_months = []
raw_unpaid_months = []
for m in sorted_months: for m in sorted_months:
mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "attendance_count": 0, "paid": 0, "exception": None}) mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "attendance_count": 0, "paid": 0, "exception": None})
expected = mdata.get("expected", 0) expected = mdata.get("expected", 0)
@@ -561,11 +603,11 @@ def juniors_view():
count = mdata.get("attendance_count", 0) count = mdata.get("attendance_count", 0)
paid = int(mdata.get("paid", 0)) paid = int(mdata.get("paid", 0))
exception_info = mdata.get("exception", None) exception_info = mdata.get("exception", None)
if expected != "?" and isinstance(expected, int): if expected != "?" and isinstance(expected, int):
monthly_totals[m]["expected"] += expected monthly_totals[m]["expected"] += expected
monthly_totals[m]["paid"] += paid monthly_totals[m]["paid"] += paid
orig_fee_data = junior_members_dict.get(name, {}).get(m) orig_fee_data = junior_members_dict.get(name, {}).get(m)
adult_count = 0 adult_count = 0
junior_count = 0 junior_count = 0
@@ -581,9 +623,9 @@ def juniors_view():
breakdown = f":{adult_count}A" breakdown = f":{adult_count}A"
count_str = f" ({count}{breakdown})" if count > 0 else "" count_str = f" ({count}{breakdown})" if count > 0 else ""
override_amount = exception_info["amount"] if exception_info else None override_amount = exception_info["amount"] if exception_info else None
if override_amount is not None and override_amount != original_expected: if override_amount is not None and override_amount != original_expected:
is_overridden = True is_overridden = True
fee_display = f"{override_amount} ({original_expected}) CZK{count_str}" fee_display = f"{override_amount} ({original_expected}) CZK{count_str}"
@@ -594,7 +636,7 @@ def juniors_view():
status = "empty" status = "empty"
cell_text = "-" cell_text = "-"
amount_to_pay = 0 amount_to_pay = 0
if expected == "?" or (isinstance(expected, int) and expected > 0): if expected == "?" or (isinstance(expected, int) and expected > 0):
if expected == "?": if expected == "?":
status = "empty" status = "empty"
@@ -607,30 +649,34 @@ def juniors_view():
cell_text = f"{paid}/{fee_display}" cell_text = f"{paid}/{fee_display}"
amount_to_pay = expected - paid amount_to_pay = expected - paid
unpaid_months.append(month_labels[m]) unpaid_months.append(month_labels[m])
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
else: else:
status = "unpaid" status = "unpaid"
cell_text = f"0/{fee_display}" cell_text = f"0/{fee_display}"
amount_to_pay = expected amount_to_pay = expected
unpaid_months.append(month_labels[m]) unpaid_months.append(month_labels[m])
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
elif paid > 0: elif paid > 0:
status = "surplus" status = "surplus"
cell_text = f"PAID {paid}" cell_text = f"PAID {paid}"
if (isinstance(expected, int) and expected > 0) or paid > 0: if (isinstance(expected, int) and expected > 0) or paid > 0:
tooltip = f"Received: {paid}, Expected: {expected}" tooltip = f"Received: {paid}, Expected: {expected}"
else: else:
tooltip = "" tooltip = ""
row["months"].append({ row["months"].append({
"text": cell_text, "text": cell_text,
"overridden": is_overridden, "overridden": is_overridden,
"status": status, "status": status,
"amount": amount_to_pay, "amount": amount_to_pay,
"month": month_labels[m], "month": month_labels[m],
"raw_month": m,
"tooltip": tooltip "tooltip": tooltip
}) })
row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "") row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "")
row["raw_unpaid_periods"] = "+".join(raw_unpaid_months)
row["balance"] = data["total_balance"] row["balance"] = data["total_balance"]
formatted_results.append(row) formatted_results.append(row)
@@ -726,8 +772,9 @@ def reconcile_juniors_view():
formatted_results = [] formatted_results = []
for name in junior_names: for name in junior_names:
data = result["members"][name] data = result["members"][name]
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": ""} row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": "", "raw_unpaid_periods": ""}
unpaid_months = [] unpaid_months = []
raw_unpaid_months = []
for m in sorted_months: for m in sorted_months:
mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "paid": 0}) mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "paid": 0})
expected = mdata["expected"] expected = mdata["expected"]
@@ -766,23 +813,27 @@ def reconcile_juniors_view():
cell_text = f"{paid}/{expected}" cell_text = f"{paid}/{expected}"
amount_to_pay = expected - paid amount_to_pay = expected - paid
unpaid_months.append(month_labels[m]) unpaid_months.append(month_labels[m])
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
else: else:
status = "unpaid" status = "unpaid"
cell_text = f"UNPAID {expected}" cell_text = f"UNPAID {expected}"
amount_to_pay = expected amount_to_pay = expected
unpaid_months.append(month_labels[m]) unpaid_months.append(month_labels[m])
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
elif paid > 0: elif paid > 0:
status = "surplus" status = "surplus"
cell_text = f"PAID {paid}" cell_text = f"PAID {paid}"
row["months"].append({ row["months"].append({
"text": cell_text, "text": cell_text,
"status": status, "status": status,
"amount": amount_to_pay, "amount": amount_to_pay,
"month": month_labels[m] "month": month_labels[m],
"raw_month": m
}) })
row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "") row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "")
row["raw_unpaid_periods"] = "+".join(raw_unpaid_months)
row["balance"] = data["total_balance"] row["balance"] = data["total_balance"]
formatted_results.append(row) formatted_results.append(row)

View File

@@ -464,6 +464,10 @@
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a> <a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
<a href="/payments">[Payments Ledger]</a> <a href="/payments">[Payments Ledger]</a>
</div> </div>
<div class="nav-archived">
<span style="color: #666; margin-right: 5px;">Tools:</span>
<a href="/sync-bank">[Sync Bank Data]</a>
</div>
</div> </div>
<h1>Adults Dashboard</h1> <h1>Adults Dashboard</h1>
@@ -503,7 +507,7 @@
{{ cell.text }} {{ cell.text }}
{% if cell.status == 'unpaid' or cell.status == 'partial' %} {% if cell.status == 'unpaid' or cell.status == 'partial' %}
<button class="pay-btn" <button class="pay-btn"
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}')">Pay</button> onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}', '{{ cell.raw_month }}')">Pay</button>
{% endif %} {% endif %}
</td> </td>
{% endfor %} {% endfor %}
@@ -511,7 +515,7 @@
{{ "%+d"|format(row.balance) if row.balance != 0 else "0" }} {{ "%+d"|format(row.balance) if row.balance != 0 else "0" }}
{% if row.balance < 0 %} {% if row.balance < 0 %}
<button class="pay-btn" <button class="pay-btn"
onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}')">Pay All</button> onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}', '{{ row.raw_unpaid_periods|e }}')">Pay All</button>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
@@ -857,9 +861,13 @@
showMemberDetails(nextName); showMemberDetails(nextName);
} }
} }
function showPayQR(name, amount, month) { function showPayQR(name, amount, month, rawMonth) {
const account = "{{ bank_account }}"; const account = "{{ bank_account }}";
const message = `${name} / ${month}`; // Convert YYYY-MM to MM/YYYY for infer_payments.py compatibility
const numericMonth = rawMonth.includes('+')
? rawMonth.split('+').map(p => p.replace(/(\d{4})-(\d{2})/, '$2/$1')).join('+')
: rawMonth.replace(/(\d{4})-(\d{2})/, '$2/$1');
const message = `${name} / ${numericMonth}`;
const qrTitle = document.getElementById('qrTitle'); const qrTitle = document.getElementById('qrTitle');
const qrImg = document.getElementById('qrImg'); const qrImg = document.getElementById('qrImg');
const qrAccount = document.getElementById('qrAccount'); const qrAccount = document.getElementById('qrAccount');

View File

@@ -192,6 +192,10 @@
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a> <a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
<a href="/payments">[Payments Ledger]</a> <a href="/payments">[Payments Ledger]</a>
</div> </div>
<div class="nav-archived">
<span style="color: #666; margin-right: 5px;">Tools:</span>
<a href="/sync-bank">[Sync Bank Data]</a>
</div>
</div> </div>
<h1>FUJ Junior Fees Dashboard</h1> <h1>FUJ Junior Fees Dashboard</h1>

View File

@@ -207,6 +207,10 @@
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a> <a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
<a href="/payments">[Payments Ledger]</a> <a href="/payments">[Payments Ledger]</a>
</div> </div>
<div class="nav-archived">
<span style="color: #666; margin-right: 5px;">Tools:</span>
<a href="/sync-bank">[Sync Bank Data]</a>
</div>
</div> </div>
<h1>FUJ Fees Dashboard</h1> <h1>FUJ Fees Dashboard</h1>

View File

@@ -464,6 +464,10 @@
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a> <a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
<a href="/payments">[Payments Ledger]</a> <a href="/payments">[Payments Ledger]</a>
</div> </div>
<div class="nav-archived">
<span style="color: #666; margin-right: 5px;">Tools:</span>
<a href="/sync-bank">[Sync Bank Data]</a>
</div>
</div> </div>
<h1>Juniors Dashboard</h1> <h1>Juniors Dashboard</h1>
@@ -503,7 +507,7 @@
{{ cell.text }} {{ cell.text }}
{% if cell.status == 'unpaid' or cell.status == 'partial' %} {% if cell.status == 'unpaid' or cell.status == 'partial' %}
<button class="pay-btn" <button class="pay-btn"
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}')">Pay</button> onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}', '{{ cell.raw_month }}')">Pay</button>
{% endif %} {% endif %}
</td> </td>
{% endfor %} {% endfor %}
@@ -511,7 +515,7 @@
{{ "%+d"|format(row.balance) if row.balance != 0 else "0" }} {{ "%+d"|format(row.balance) if row.balance != 0 else "0" }}
{% if row.balance < 0 %} {% if row.balance < 0 %}
<button class="pay-btn" <button class="pay-btn"
onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}')">Pay All</button> onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}', '{{ row.raw_unpaid_periods|e }}')">Pay All</button>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
@@ -838,9 +842,13 @@
showMemberDetails(nextName); showMemberDetails(nextName);
} }
} }
function showPayQR(name, amount, month) { function showPayQR(name, amount, month, rawMonth) {
const account = "{{ bank_account }}"; const account = "{{ bank_account }}";
const message = `${name} / ${month}`; // Convert YYYY-MM to MM/YYYY for infer_payments.py compatibility
const numericMonth = rawMonth.includes('+')
? rawMonth.split('+').map(p => p.replace(/(\d{4})-(\d{2})/, '$2/$1')).join('+')
: rawMonth.replace(/(\d{4})-(\d{2})/, '$2/$1');
const message = `${name} / ${numericMonth}`;
const qrTitle = document.getElementById('qrTitle'); const qrTitle = document.getElementById('qrTitle');
const qrImg = document.getElementById('qrImg'); const qrImg = document.getElementById('qrImg');
const qrAccount = document.getElementById('qrAccount'); const qrAccount = document.getElementById('qrAccount');

View File

@@ -196,6 +196,10 @@
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a> <a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
<a href="/payments" class="active">[Payments Ledger]</a> <a href="/payments" class="active">[Payments Ledger]</a>
</div> </div>
<div class="nav-archived">
<span style="color: #666; margin-right: 5px;">Tools:</span>
<a href="/sync-bank">[Sync Bank Data]</a>
</div>
</div> </div>
<h1>Payments Ledger</h1> <h1>Payments Ledger</h1>

View File

@@ -460,6 +460,10 @@
<a href="/reconcile-juniors" class="active">[Junior Payment Reconciliation]</a> <a href="/reconcile-juniors" class="active">[Junior Payment Reconciliation]</a>
<a href="/payments">[Payments Ledger]</a> <a href="/payments">[Payments Ledger]</a>
</div> </div>
<div class="nav-archived">
<span style="color: #666; margin-right: 5px;">Tools:</span>
<a href="/sync-bank">[Sync Bank Data]</a>
</div>
</div> </div>
<h1>Junior Payment Reconciliation</h1> <h1>Junior Payment Reconciliation</h1>
@@ -499,7 +503,7 @@
{{ cell.text }} {{ cell.text }}
{% if cell.status == 'unpaid' or cell.status == 'partial' %} {% if cell.status == 'unpaid' or cell.status == 'partial' %}
<button class="pay-btn" <button class="pay-btn"
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}')">Pay</button> onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}', '{{ cell.raw_month }}')">Pay</button>
{% endif %} {% endif %}
</td> </td>
{% endfor %} {% endfor %}
@@ -507,7 +511,7 @@
{{ "%+d"|format(row.balance) if row.balance != 0 else "0" }} {{ "%+d"|format(row.balance) if row.balance != 0 else "0" }}
{% if row.balance < 0 %} {% if row.balance < 0 %}
<button class="pay-btn" <button class="pay-btn"
onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}')">Pay All</button> onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}', '{{ row.raw_unpaid_periods|e }}')">Pay All</button>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
@@ -841,9 +845,13 @@
showMemberDetails(nextName); showMemberDetails(nextName);
} }
} }
function showPayQR(name, amount, month) { function showPayQR(name, amount, month, rawMonth) {
const account = "{{ bank_account }}"; const account = "{{ bank_account }}";
const message = `${name} / ${month}`; // Convert YYYY-MM to MM/YYYY for infer_payments.py compatibility
const numericMonth = rawMonth.includes('+')
? rawMonth.split('+').map(p => p.replace(/(\d{4})-(\d{2})/, '$2/$1')).join('+')
: rawMonth.replace(/(\d{4})-(\d{2})/, '$2/$1');
const message = `${name} / ${numericMonth}`;
const qrTitle = document.getElementById('qrTitle'); const qrTitle = document.getElementById('qrTitle');
const qrImg = document.getElementById('qrImg'); const qrImg = document.getElementById('qrImg');
const qrAccount = document.getElementById('qrAccount'); const qrAccount = document.getElementById('qrAccount');

View File

@@ -460,6 +460,10 @@
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a> <a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
<a href="/payments">[Payments Ledger]</a> <a href="/payments">[Payments Ledger]</a>
</div> </div>
<div class="nav-archived">
<span style="color: #666; margin-right: 5px;">Tools:</span>
<a href="/sync-bank">[Sync Bank Data]</a>
</div>
</div> </div>
<h1>Payment Reconciliation</h1> <h1>Payment Reconciliation</h1>
@@ -499,7 +503,7 @@
{{ cell.text }} {{ cell.text }}
{% if cell.status == 'unpaid' or cell.status == 'partial' %} {% if cell.status == 'unpaid' or cell.status == 'partial' %}
<button class="pay-btn" <button class="pay-btn"
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}')">Pay</button> onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}', '{{ cell.raw_month }}')">Pay</button>
{% endif %} {% endif %}
</td> </td>
{% endfor %} {% endfor %}
@@ -507,7 +511,7 @@
{{ "%+d"|format(row.balance) if row.balance != 0 else "0" }} {{ "%+d"|format(row.balance) if row.balance != 0 else "0" }}
{% if row.balance < 0 %} {% if row.balance < 0 %}
<button class="pay-btn" <button class="pay-btn"
onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}')">Pay All</button> onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}', '{{ row.raw_unpaid_periods|e }}')">Pay All</button>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
@@ -841,9 +845,13 @@
showMemberDetails(nextName); showMemberDetails(nextName);
} }
} }
function showPayQR(name, amount, month) { function showPayQR(name, amount, month, rawMonth) {
const account = "{{ bank_account }}"; const account = "{{ bank_account }}";
const message = `${name} / ${month}`; // Convert YYYY-MM to MM/YYYY for infer_payments.py compatibility
const numericMonth = rawMonth.includes('+')
? rawMonth.split('+').map(p => p.replace(/(\d{4})-(\d{2})/, '$2/$1')).join('+')
: rawMonth.replace(/(\d{4})-(\d{2})/, '$2/$1');
const message = `${name} / ${numericMonth}`;
const qrTitle = document.getElementById('qrTitle'); const qrTitle = document.getElementById('qrTitle');
const qrImg = document.getElementById('qrImg'); const qrImg = document.getElementById('qrImg');
const qrAccount = document.getElementById('qrAccount'); const qrAccount = document.getElementById('qrAccount');

156
templates/sync.html Normal file
View File

@@ -0,0 +1,156 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FUJ - Sync Bank Data</title>
<style>
body {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
background-color: #0c0c0c;
color: #cccccc;
padding: 10px;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
font-size: 11px;
line-height: 1.2;
}
h1 {
color: #00ff00;
font-family: inherit;
margin-top: 10px;
margin-bottom: 20px;
text-transform: uppercase;
letter-spacing: 1px;
font-size: 14px;
}
.nav {
margin-bottom: 20px;
font-size: 12px;
color: #555;
display: flex;
flex-direction: column;
gap: 10px;
align-items: center;
}
.nav > div {
display: flex;
gap: 15px;
align-items: center;
}
.nav a {
color: #00ff00;
text-decoration: none;
padding: 2px 8px;
border: 1px solid #333;
}
.nav a.active {
color: #000;
background-color: #00ff00;
border-color: #00ff00;
}
.nav a:hover {
color: #fff;
border-color: #555;
}
.nav-archived a {
font-size: 10px;
color: #666;
border-color: #222;
}
.nav-archived a.active {
color: #ccc;
background-color: #333;
border-color: #555;
}
.nav-archived a:hover {
color: #999;
border-color: #444;
}
.output-container {
background-color: #111;
border: 1px solid #333;
padding: 15px;
width: 100%;
max-width: 1200px;
margin-bottom: 30px;
overflow-x: auto;
}
.output-container pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
color: {% if success %}#cccccc{% else %}#ff6666{% endif %};
}
.status {
margin-bottom: 15px;
font-size: 12px;
}
.status-ok { color: #00ff00; }
.status-error { color: #ff6666; }
.footer {
text-align: center;
color: #333;
margin-top: 20px;
font-size: 10px;
}
</style>
</head>
<body>
<div class="nav">
<div>
<a href="/adults">[Adults]</a>
<a href="/juniors">[Juniors]</a>
</div>
<div class="nav-archived">
<span style="color: #666; margin-right: 5px;">Archived:</span>
<a href="/fees">[Adult - Attendance/Fees]</a>
<a href="/fees-juniors">[Junior Attendance/Fees]</a>
<a href="/reconcile">[Adult Payment Reconciliation]</a>
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
<a href="/payments">[Payments Ledger]</a>
</div>
<div class="nav-archived">
<span style="color: #666; margin-right: 5px;">Tools:</span>
<a href="/sync-bank" class="active">[Sync Bank Data]</a>
</div>
</div>
<h1>Sync Bank Data</h1>
<div class="status">
{% if success %}
<span class="status-ok">Sync completed successfully.</span>
{% else %}
<span class="status-error">Sync failed - see output below.</span>
{% endif %}
</div>
<div class="output-container">
<pre>{{ output }}</pre>
</div>
<div class="footer">
{{ build_meta.tag }} | {{ build_meta.commit }} | {{ build_meta.build_date }}
</div>
</body>
</html>