From de948156b964cfe0b0ab9e9514dbd7967e51d3c9 Mon Sep 17 00:00:00 2001 From: NguyenND Date: Tue, 2 Jun 2026 16:20:36 -0400 Subject: [PATCH] 06/02 Optimize app --- app/routes/accounts.py | 31 +++++++ app/templates/accounts/index.html | 10 +-- app/templates/accounts/payments.html | 111 ++++++++++++++++++++++++++ app/templates/base.html | 16 +++- app/templates/dashboard/index.html | 12 +-- app/templates/investments/index.html | 4 +- app/templates/transactions/index.html | 14 ++-- 7 files changed, 175 insertions(+), 23 deletions(-) create mode 100644 app/templates/accounts/payments.html diff --git a/app/routes/accounts.py b/app/routes/accounts.py index 26fc7f2..d204c6d 100644 --- a/app/routes/accounts.py +++ b/app/routes/accounts.py @@ -157,6 +157,37 @@ def delete(id): return redirect(url_for('accounts.index')) +@accounts_bp.route('//payments') +@login_required +def payments(id): + account = db.get_or_404(Account, id) + page = request.args.get('page', 1, type=int) + + pagination = Transaction.query.filter( + Transaction.transaction_type == 'transfer', + Transaction.to_account_id == account.id, + ).order_by(Transaction.date.desc(), Transaction.id.desc()).paginate( + page=page, per_page=30, error_out=False + ) + + # Running total paid this month + today = date.today() + paid_this_month = db.session.query( + func.coalesce(func.sum(Transaction.amount), 0) + ).filter( + Transaction.transaction_type == 'transfer', + Transaction.to_account_id == account.id, + extract('year', Transaction.date) == today.year, + extract('month', Transaction.date) == today.month, + ).scalar() + + return render_template('accounts/payments.html', + account=account, + pagination=pagination, + payments=pagination.items, + paid_this_month=float(paid_this_month)) + + @accounts_bp.route('//adjust', methods=['GET', 'POST']) @login_required def adjust_balance(id): diff --git a/app/templates/accounts/index.html b/app/templates/accounts/index.html index a3802c3..85812ef 100644 --- a/app/templates/accounts/index.html +++ b/app/templates/accounts/index.html @@ -90,16 +90,16 @@ {% else %}
diff --git a/app/templates/accounts/payments.html b/app/templates/accounts/payments.html new file mode 100644 index 0000000..4ce04da --- /dev/null +++ b/app/templates/accounts/payments.html @@ -0,0 +1,111 @@ +{% extends "base.html" %} +{% block title %}Payments — {{ account.name }}{% endblock %} +{% block page_title %}Card Payments{% endblock %} + +{% block topbar_actions %} + + Pay Card + +{% endblock %} + +{% block content %} + + +
+
+
+
+ +
+
+
{{ account.name }}
+
Payment History
+
+
+
+
+
Paid This Month
+
+{{ paid_this_month | currency }}
+
+
+ {% set owed = [0, -account.balance] | max %} +
Still Owed
+
+ {% if owed > 0 %}-{% endif %}{{ owed | currency }} +
+
+
+
+
+ + + + +{% if payments %} +
+ + + + + + + + + + + {% for txn in payments %} + + + + + + + {% endfor %} + +
DateDescriptionFrom AccountAmount Paid
+ {{ txn.date.strftime('%b %d, %Y') }} + +
{{ txn.description }}
+ {% if txn.notes %}
{{ txn.notes | truncate(60) }}
{% endif %} +
+ {{ txn.account.name if txn.account else '—' }} + + +{{ txn.amount | currency }} +
+ + {% if pagination.pages > 1 %} +
+ {{ ((pagination.page-1)*30)+1 }}–{{ [pagination.page*30, pagination.total]|min }} of {{ pagination.total }} +
+ {% if pagination.has_prev %} + ← Prev + {% endif %} + {% if pagination.has_next %} + Next → + {% endif %} +
+
+ {% endif %} +
+ +{% else %} +
+ +

No payments recorded yet

+

Use "Pay Card" to record a payment from your checking or savings account.

+ + Record First Payment + +
+{% endif %} + +{% endblock %} diff --git a/app/templates/base.html b/app/templates/base.html index 40ee54e..c3aa547 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -165,12 +165,22 @@ .pcard { padding: 14px; } .stat-card { padding: 14px 16px; } .stat-card .stat-value { font-size: 20px; } - /* Tables: scroll horizontally on small screens. - Targets both manual .table-wrap and the common .pcard.p-0 pattern. */ + /* Tables: scroll horizontally on small screens */ .table-wrap, .pcard.p-0 { overflow-x: auto; -webkit-overflow-scrolling: touch; } - .pfm-table { min-width: 560px; } + .pfm-table { min-width: 580px; } /* Hide low-priority columns */ .d-mob-none { display: none !important; } + /* Topbar title: truncate so action buttons always fit */ + .tb-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; } + /* Flash: stretch full width */ + .flash-wrap { left: 8px; right: 8px; max-width: none; } + } + /* Extra-small screens: hide button label text, keep icons */ + @media (max-width: 575px) { + #main { padding: 10px; } + .pcard { padding: 12px; } + .btn-label { display: none; } + .tb-right .btn { padding-left: 8px; padding-right: 8px; } } .sb-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1039; } .sb-overlay.on { display: block; } diff --git a/app/templates/dashboard/index.html b/app/templates/dashboard/index.html index 4ac5edf..e1db06d 100644 --- a/app/templates/dashboard/index.html +++ b/app/templates/dashboard/index.html @@ -11,21 +11,21 @@ {% block topbar_actions %}
- This Month - Last Month - + This Month + Last Month +
{% endblock %} {% block content %} -
+
{{ period_label }}
{{ date_from.strftime('%b %d') }} – {{ date_to.strftime('%b %d, %Y') }}
diff --git a/app/templates/investments/index.html b/app/templates/investments/index.html index b28e918..96ddd5e 100644 --- a/app/templates/investments/index.html +++ b/app/templates/investments/index.html @@ -152,7 +152,7 @@ Asset Price - 1D Chg + 1D Chg Value P&L @@ -184,7 +184,7 @@ {% endif %} - + {% if inv.ticker %} {% else %} diff --git a/app/templates/transactions/index.html b/app/templates/transactions/index.html index 2fb536d..8257c59 100644 --- a/app/templates/transactions/index.html +++ b/app/templates/transactions/index.html @@ -3,9 +3,9 @@ {% block page_title %}Transactions{% endblock %} {% block topbar_actions %} -Income -Expense -Transfer +Income +Expense +Transfer {% endblock %} {% block content %} @@ -68,8 +68,8 @@ Date Description - Category - Account + Category + Account Amount Actions @@ -82,14 +82,14 @@
{{ txn.description }}
{% if txn.notes %}
{{ txn.notes | truncate(60) }}
{% endif %} - + {% if txn.category %} {{ txn.category.name }} {% else %}{% endif %} - {{ txn.account.name if txn.account else '—' }} + {{ txn.account.name if txn.account else '—' }} {% if txn.transaction_type=='income' %}+{% else %}-{% endif %}{{ txn.amount | currency }}