diff --git a/VERSION b/VERSION index 17e51c3..d917d3e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.1 +0.1.2 diff --git a/backend/app.py b/backend/app.py index 048bd9b..dbd4773 100644 --- a/backend/app.py +++ b/backend/app.py @@ -3,6 +3,7 @@ from db import get_db_connection from utils import generate_client_code, generate_service_code from datetime import datetime, timezone from zoneinfo import ZoneInfo +from decimal import Decimal, InvalidOperation app = Flask( __name__, @@ -24,6 +25,20 @@ def fmt_local(dt_value): dt_value = dt_value.replace(tzinfo=timezone.utc) return dt_value.astimezone(LOCAL_TZ).strftime("%Y-%m-%d %I:%M:%S %p") +def to_decimal(value): + if value is None or value == "": + return Decimal("0") + try: + return Decimal(str(value)) + except (InvalidOperation, ValueError): + return Decimal("0") + +def fmt_money(value, currency_code="CAD"): + amount = to_decimal(value) + if currency_code == "CAD": + return f"{amount:.2f}" + return f"{amount:.8f}" + def refresh_overdue_invoices(): conn = get_db_connection() cursor = conn.cursor() @@ -41,6 +56,10 @@ def refresh_overdue_invoices(): def localtime_filter(value): return fmt_local(value) +@app.template_filter("money") +def money_filter(value, currency_code="CAD"): + return fmt_money(value, currency_code) + @app.route("/") def index(): refresh_overdue_invoices() diff --git a/templates/dashboard.html b/templates/dashboard.html index e2b60ef..301868c 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -24,7 +24,7 @@ {{ total_clients }} {{ active_services }} {{ outstanding_invoices }} - {{ revenue_received }} + {{ revenue_received|money('CAD') }} diff --git a/templates/invoices/list.html b/templates/invoices/list.html index a4ad047..fd4f420 100644 --- a/templates/invoices/list.html +++ b/templates/invoices/list.html @@ -31,9 +31,9 @@ {{ i.invoice_number }} {{ i.client_code }} - {{ i.company_name }} {{ i.currency_code }} -{{ i.total_amount }} -{{ i.amount_paid }} -{{ i.total_amount - i.amount_paid }} +{{ i.total_amount|money(i.currency_code) }} +{{ i.amount_paid|money(i.currency_code) }} +{{ (i.total_amount - i.amount_paid)|money(i.currency_code) }} {{ i.status }} {{ i.issued_at|localtime }} {{ i.due_at|localtime }} diff --git a/templates/payments/list.html b/templates/payments/list.html index 7ade56e..e49c74f 100644 --- a/templates/payments/list.html +++ b/templates/payments/list.html @@ -30,8 +30,8 @@ {{ p.client_code }} - {{ p.company_name }} {{ p.payment_method }} {{ p.payment_currency }} - {{ p.payment_amount }} - {{ p.cad_value_at_payment }} + {{ p.payment_amount|money(p.payment_currency) }} + {{ p.cad_value_at_payment|money('CAD') }} {{ p.reference }} {{ p.received_at|localtime }} diff --git a/templates/services/list.html b/templates/services/list.html index 614cf84..f56c940 100644 --- a/templates/services/list.html +++ b/templates/services/list.html @@ -33,7 +33,7 @@ {{ s.service_type }} {{ s.billing_cycle }} {{ s.currency_code }} - {{ s.recurring_amount }} + {{ s.recurring_amount|money(s.currency_code) }} {{ s.status }} {{ s.start_date }}