{# This is a Jinja template that is the page displayed when clicking the link on the sidebar. #} {% import "_envelope_query_table.html" as querytable with context %} {# Get view mode and currency #} {% set view = request.args.get('view', 'budget') %} {% set currency = request.args.get('currency') %} {% if currency == None %} {% set currency = extension.get_currencies()[0] %} {% endif %} {% if view == 'stats' %} {# ==================== STATS VIEW ==================== #} {% set overall = extension.generate_overall_stats(currency) %} {% set stats_table = extension.generate_stats_table(currency) %}

Budget

Stats

{% if extension.get_currencies() %} {% for c in extension.get_currencies() %} {% if not (currency == c) %}

Stats {{ c }}

{% endif %} {% endfor %} {% endif %}

Envelope Budget Statistics ({{ currency }})

Statistics calculated for {{ overall.total_periods }} periods up to current month.

Overall Summary
Total Periods Tracked
{{ overall.total_periods }}
Total Income
{{ "{:,.2f}".format(overall.total_income) }} {{ currency }}
Avg Monthly Income
{{ "{:,.2f}".format(overall.avg_income_per_month) }} {{ currency }}
Total Budgeted
{{ "{:,.2f}".format(overall.total_budgeted) }} {{ currency }}
Total Spent
{{ "{:,.2f}".format(overall.total_spent) }} {{ currency }}
{% set adherence_class = 'positive' if overall.overall_adherence_rate >= 80 else ('warning' if overall.overall_adherence_rate >= 60 else 'negative') %}
Overall Budget Adherence
{{ "{:.1f}".format(overall.overall_adherence_rate) }}%
{% if overall.envelopes_usually_under %}
Well-Managed Envelopes (>80% adherence)
{% endif %} {% if overall.envelopes_often_over %}
Needs Attention (<50% adherence)
{% endif %}
Detailed Envelope Statistics
{% if stats_table[1] %} {% for name, type in stats_table[0] %} {% endfor %} {% for row in stats_table[1] %} {% set adherence_str = row['Adherence %']|replace('%', '')|float %} {% set row_class = 'stats-excellent' if adherence_str >= 90 else ('stats-good' if adherence_str >= 70 else ('stats-warning' if adherence_str >= 50 else 'stats-poor')) %} {% for name, type in stats_table[0] %} {% endfor %} {% endfor %}
{{ name }}
{{ row[name] }}
{% else %}

No envelope data available for statistics.

{% endif %} {% else %} {# ==================== BUDGET VIEW (default) ==================== #} {% if extension.check_month_in_available_months(request.args.get('month'),currency) %} {% set month = request.args.get('month') %} {% endif %} {% if not month %} {# Default to current month if available, otherwise last available month #} {% set current_month = extension.get_current_month() %} {% set available_months = extension.get_budgets_months_available(currency) %} {% if current_month in available_months %} {% set month = current_month %} {% else %} {% set month = available_months[-1] %} {% endif %} {% endif %} {% if extension.get_currencies() %}
{% for c in extension.get_currencies() %}

{% if not (currency == c) %}Envelope Budget {{ c }}{% else %}Envelope Budget {{ c }}{% endif %}

{% endfor %}
{% endif %}

{{ title }}

{% for m in extension.get_budgets_months_available(currency) %}

{% if not (module == m) %}{{ m }}{% else %} {{ m }}{% endif %}

{% endfor %}

Stats

{{ month }}

{% set income_table = extension.generate_income_query_tables(month) %} {{ querytable.querytable(ledger, None, income_table[0], income_table[1]) }} {% set envelope_table = extension.generate_envelope_query_tables(month) %} {{ querytable.querytable(ledger, None, envelope_table[0], envelope_table[1]) }} {% endif %}