From 8f69023ffdb4730587687a34c064bf5584734c1a Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Thu, 28 Aug 2025 21:19:58 +1000 Subject: [PATCH] format totals per year and based on dates/END_YEAR --- main.py | 5 +++-- templates/bills.html | 28 +++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index f4d5596..92a283a 100644 --- a/main.py +++ b/main.py @@ -6,8 +6,9 @@ from db import get_bill_data, new_bill, update_bill_data, delete_bill from db import get_bill_ui, save_ui from db import get_bill_types, insert_bill_type, update_bill_type, delete_bill_type, use_growth from bills import process_bill_data +from defines import END_YEAR from collections import defaultdict, Counter -from datetime import datetime +from datetime import datetime, date import csv import io from disp import FP_VAR @@ -148,7 +149,7 @@ def DisplayBillData(): bill_ui = get_bill_ui() process_bill_data(bill_data, bill_types, bill_freqs) bill_data = get_bill_data() - return render_template('bills.html', bill_data=bill_data, bill_types=bill_types, bill_freqs=bill_freqs, bill_ui=bill_ui ) + return render_template('bills.html', bill_data=bill_data, bill_types=bill_types, bill_freqs=bill_freqs, bill_ui=bill_ui, this_year=datetime.today().year, END_YEAR=END_YEAR ) @app.route('/newbilltype', methods=['POST']) def InsertBillType(): diff --git a/templates/bills.html b/templates/bills.html index eceb695..ae83579 100644 --- a/templates/bills.html +++ b/templates/bills.html @@ -86,20 +86,22 @@ {% endfor %} - {% set total=namespace( sum=0 ) %} - {% for bd in bill_data %} - {% if '2025' in bd['bill_date'] %} - {% set total.sum = total.sum + bd['amount'] %} - {% endif %} + {% for yr in range( this_year, END_YEAR) %} + {% set total=namespace( sum=0 ) %} + {% for bd in bill_data %} + {% if yr|string in bd['bill_date'] %} + {% set total.sum = total.sum + bd['amount'] %} + {% endif %} + {% endfor %} +
+
+ Total bills in {{yr}} +
+
+ ${{'%.2f'|format(total.sum)}} +
+
{% endfor %} -
-
- Total bills in 2025: -
-
- ${{total.sum}} -
-