Browse Source

Add v0.1.2 money formatting cleanup

main
def 2 weeks ago
parent
commit
c31a493145
  1. 2
      VERSION
  2. 19
      backend/app.py
  3. 2
      templates/dashboard.html
  4. 6
      templates/invoices/list.html
  5. 4
      templates/payments/list.html
  6. 2
      templates/services/list.html

2
VERSION

@ -1 +1 @@
0.1.1
0.1.2

19
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()

2
templates/dashboard.html

@ -24,7 +24,7 @@
<td>{{ total_clients }}</td>
<td>{{ active_services }}</td>
<td>{{ outstanding_invoices }}</td>
<td>{{ revenue_received }}</td>
<td>{{ revenue_received|money('CAD') }}</td>
</tr>
</table>

6
templates/invoices/list.html

@ -31,9 +31,9 @@
<td>{{ i.invoice_number }}</td>
<td>{{ i.client_code }} - {{ i.company_name }}</td>
<td>{{ i.currency_code }}</td>
<td>{{ i.total_amount }}</td>
<td>{{ i.amount_paid }}</td>
<td>{{ i.total_amount - i.amount_paid }}</td>
<td>{{ i.total_amount|money(i.currency_code) }}</td>
<td>{{ i.amount_paid|money(i.currency_code) }}</td>
<td>{{ (i.total_amount - i.amount_paid)|money(i.currency_code) }}</td>
<td>{{ i.status }}</td>
<td>{{ i.issued_at|localtime }}</td>
<td>{{ i.due_at|localtime }}</td>

4
templates/payments/list.html

@ -30,8 +30,8 @@
<td>{{ p.client_code }} - {{ p.company_name }}</td>
<td>{{ p.payment_method }}</td>
<td>{{ p.payment_currency }}</td>
<td>{{ p.payment_amount }}</td>
<td>{{ p.cad_value_at_payment }}</td>
<td>{{ p.payment_amount|money(p.payment_currency) }}</td>
<td>{{ p.cad_value_at_payment|money('CAD') }}</td>
<td>{{ p.reference }}</td>
<td>{{ p.received_at|localtime }}</td>
</tr>

2
templates/services/list.html

@ -33,7 +33,7 @@
<td>{{ s.service_type }}</td>
<td>{{ s.billing_cycle }}</td>
<td>{{ s.currency_code }}</td>
<td>{{ s.recurring_amount }}</td>
<td>{{ s.recurring_amount|money(s.currency_code) }}</td>
<td>{{ s.status }}</td>
<td>{{ s.start_date }}</td>
</tr>

Loading…
Cancel
Save