diff --git a/app/routes/accounts.py b/app/routes/accounts.py index 49da1ba..05ab627 100644 --- a/app/routes/accounts.py +++ b/app/routes/accounts.py @@ -44,15 +44,30 @@ class AccountForm(FlaskForm): submit = SubmitField('Save') +BANK_TYPES = {'checking', 'savings', 'cash', 'investment', 'crypto', 'other'} + + @accounts_bp.route('/') @login_required def index(): - accounts = Account.query.filter_by(is_active=True).order_by(Account.name).all() - # Recalc balances on page load - for a in accounts: + tab = request.args.get('tab', 'bank') + if tab not in ('bank', 'credit'): + tab = 'bank' + + all_accounts = Account.query.filter_by(is_active=True).order_by(Account.name).all() + for a in all_accounts: calc_balance(a.id) - accounts = Account.query.filter_by(is_active=True).order_by(Account.name).all() - return render_template('accounts/index.html', accounts=accounts) + all_accounts = Account.query.filter_by(is_active=True).order_by(Account.name).all() + + bank_accounts = [a for a in all_accounts if a.account_type in BANK_TYPES] + credit_accounts = [a for a in all_accounts if a.account_type == 'credit_card'] + accounts = credit_accounts if tab == 'credit' else bank_accounts + + return render_template('accounts/index.html', + accounts=accounts, + tab=tab, + bank_count=len(bank_accounts), + credit_count=len(credit_accounts)) @accounts_bp.route('/new', methods=['GET', 'POST']) diff --git a/app/templates/accounts/index.html b/app/templates/accounts/index.html index 28d478a..55ef789 100644 --- a/app/templates/accounts/index.html +++ b/app/templates/accounts/index.html @@ -7,12 +7,27 @@ {% endblock %} {% block content %} + + +
+ + Bank Accounts + {{ bank_count }} + + + Credit Cards + {{ credit_count }} + +
+ {% if accounts %}
{% for acct in accounts %}
-
+
@@ -36,19 +51,54 @@
+ {% if acct.notes %} -
{{ acct.notes }}
+
{{ acct.notes }}
+ {% endif %} + + {% if tab == 'credit' %} + + {% else %} + {% endif %}
{% endfor %}
+ {% else %}
- -
No accounts yet
-

Add your bank accounts, cash, and credit cards.

- Add Account + {% if tab == 'credit' %} + +
No credit cards yet
+

Add a credit card account to track charges and payments.

+ {% else %} + +
No bank accounts yet
+

Add your checking, savings, or cash accounts.

+ {% endif %} + + New Account +
{% endif %} + {% endblock %}