|
|
|
@ -3,6 +3,7 @@ from db import get_db_connection |
|
|
|
from utils import generate_client_code, generate_service_code |
|
|
|
from utils import generate_client_code, generate_service_code |
|
|
|
from datetime import datetime, timezone |
|
|
|
from datetime import datetime, timezone |
|
|
|
from zoneinfo import ZoneInfo |
|
|
|
from zoneinfo import ZoneInfo |
|
|
|
|
|
|
|
from decimal import Decimal, InvalidOperation |
|
|
|
|
|
|
|
|
|
|
|
app = Flask( |
|
|
|
app = Flask( |
|
|
|
__name__, |
|
|
|
__name__, |
|
|
|
@ -24,6 +25,20 @@ def fmt_local(dt_value): |
|
|
|
dt_value = dt_value.replace(tzinfo=timezone.utc) |
|
|
|
dt_value = dt_value.replace(tzinfo=timezone.utc) |
|
|
|
return dt_value.astimezone(LOCAL_TZ).strftime("%Y-%m-%d %I:%M:%S %p") |
|
|
|
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(): |
|
|
|
def refresh_overdue_invoices(): |
|
|
|
conn = get_db_connection() |
|
|
|
conn = get_db_connection() |
|
|
|
cursor = conn.cursor() |
|
|
|
cursor = conn.cursor() |
|
|
|
@ -41,6 +56,10 @@ def refresh_overdue_invoices(): |
|
|
|
def localtime_filter(value): |
|
|
|
def localtime_filter(value): |
|
|
|
return fmt_local(value) |
|
|
|
return fmt_local(value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.template_filter("money") |
|
|
|
|
|
|
|
def money_filter(value, currency_code="CAD"): |
|
|
|
|
|
|
|
return fmt_money(value, currency_code) |
|
|
|
|
|
|
|
|
|
|
|
@app.route("/") |
|
|
|
@app.route("/") |
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
refresh_overdue_invoices() |
|
|
|
refresh_overdue_invoices() |
|
|
|
|