{#- The monthly budget panel on the Usage page. Built-in Jinja only. budget_panel(status, can_edit=False, notice='', error='') status usage_budget.budget_status(...), or None when no budget is set can_edit used only when status is None; otherwise status.can_edit notice, error from usage_budget.budget_messages(request.query_params); a notice code ('saved', 'cleared') is shown as its text. -#} {% macro _money(value) -%}{{ '${:,.2f}'.format(value) }}{%- endmacro %} {% macro _budget_form(monthly_usd='', alert_percent=80) -%}
{%- endmacro %} {% macro budget_panel(status, can_edit=False, notice='', error='') -%} {% set editable = status.can_edit if status else can_edit %} {% set notice = {'saved': 'Budget saved.', 'cleared': 'Budget removed.'}.get(notice, notice) %}

{{ 'This month' if status else 'Monthly budget' }}

{% if status %}Known spend since {{ status.month_start.strftime('%b') }} {{ status.month_start.day }}, UTC. The Overview flags it at {{ status.alert_percent }}% of the budget.{% elif editable %}Set a monthly budget to get an alert before spend runs over.{% else %}No monthly budget is set.{% endif %}

{% if notice %}

{{ notice }}

{% endif %} {% if error %}{% endif %} {% if status and status.state == 'unknown' %}

Spend can't be read right now, so the budget can't be checked. Try again in a few minutes.

{% elif status %} {% set shown = status.percent|round(0, 'floor')|int %}

{{ _money(status.spend) }} of {{ _money(status.budget) }} {{ shown }}%{% if status.state == 'over' %} ยท over budget{% endif %}

{% if status.projected is not none %}On pace for {{ _money(status.projected) }} by month end{% else %}A month-end projection shows after the first day{% endif %} {{ '{:,}'.format(status.calls) }} call{{ 's' if status.calls != 1 else '' }} this month

{% if status.unpriced_calls %}

{% if status.unpriced_calls == 1 %}1 call has no price and isn't counted.{% else %}{{ '{:,}'.format(status.unpriced_calls) }} calls have no price and aren't counted.{% endif %} Set prices

{% endif %} {% endif %} {% if status and editable %}
Edit budget {{ _budget_form(status.budget, status.alert_percent) }}
{% elif editable %}{{ _budget_form() }}{% endif %}
{%- endmacro %}