{% extends "base.html" %} {% from "_macros.html" import state_badge, pay_badge, icon with context %} {% block title %}{{ t('Dashboard') }}{% endblock %} {% macro delta(cur, prev, up_is_good=True) -%} {%- if prev -%} {%- set pct = (cur - prev) / (prev if prev > 0 else -prev) * 100 -%} {%- set good = (pct >= 0) == up_is_good -%} {{ '▲' if pct >= 0 else '▼' }} {{ '%.1f'|format(pct|abs) }}%{{ t('vs last year') }} {%- else -%}{{ t('Year to date') }}{%- endif -%} {%- endmacro %} {% block content %} {% if empty %}
{{ t('You do not have access to any branch. Ask an administrator.') }}
{% else %}

{{ t(greeting) }}{{ '،' if rtl else ',' }} {{ (user.full_name or user.username).split(' ')[0] if lang == 'en' else (user.full_name or user.username) }}

{% if branches|length > 1 %}{{ branches|length }} {{ t('branches') }} · {{ t('Consolidated') }}{% else %}{{ nm(branches[0]) }}{% endif %} {{ t('Fiscal year from') }} {{ fys }}·{{ t('Amounts in') }} {{ currency }}
{% if can_write %}
{% if has('sales') %}{{ icon('file') }}{{ t('Quotation') }}{% endif %} {% if has('procurement') %}{{ icon('clipboard') }}{{ t('Material Request') }}{% endif %} {{ icon('file-in') }}{{ t('Vendor Bill') }} {{ icon('book') }}{{ t('Journal Entry') }} {{ icon('receipt') }}{{ t('Customer Invoice') }}
{% endif %}
{% if error %}
{{ icon('alert') }}{{ error }}
{% endif %} {% set revs = [] %}{% for m in months %}{% set _ = revs.append(series[m][0]) %}{% endfor %} {% set smax = [revs|max, 1]|max %}
{{ t('Revenue (YTD)') }}{{ icon('trend') }}
{{ totals.revenue|money(currency) }}{{ currency }}
{{ delta(totals.revenue, last_year.revenue) }}
{{ t('Expenses (YTD)') }}{{ icon('wallet') }}
{{ totals.expenses|money(currency) }}{{ currency }}
{{ delta(totals.expenses, last_year.expenses, False) }}
{{ t('Net Profit (YTD)') }}{{ icon('chart') }}
{{ totals.profit|money(currency) }}{{ currency }}
{% if totals.revenue %}{{ '%.1f'|format(totals.profit / totals.revenue * 100) }}%{{ t('net margin') }}{% else %}{{ t('Year to date') }}{% endif %}
{{ t('Bank and Cash') }}{{ icon('bank') }}
{{ totals.cash|money(currency) }}{{ currency }}
{{ cash_accounts }} {{ t('bank and cash accounts') }}
{{ icon('receipt') }}
{{ t('Receivables') }}
{{ totals.receivable|money(currency) }}
{{ open_inv_n }} {{ t('open invoices') }}
{{ icon('file-in') }}
{{ t('Payables') }}
{{ totals.payable|money(currency) }}
{{ open_bills_n }} {{ t('open bills') }}
{{ icon('alert') }}
{{ t('Overdue receivables') }}
{{ overdue_amt|money(currency) }}
{{ overdue_n }} {{ t('invoices') }}
{{ t('Follow up') }} →

{{ t('Revenue vs Expenses') }}

{{ t('Revenue') }}{{ t('Expenses') }}
{% for v in scale %}
{% set u = v / 1000 %}{{ ('%gM'|format((u / 1000000)|round(1))) if u >= 1000000 else ('%gk'|format((u / 1000)|round(1))) if u >= 1000 else '%g'|format(u|round(0)) }}
{% endfor %}
{% for m in months %}{% set v = series[m] %}
{{ m[5:] }}/{{ m[2:4] }}
{% endfor %}

{{ t('Needs your attention') }}

{% if actions %}{{ actions|length }}{% endif %}
{% if actions %}
{% for label, n, href in actions %}{% set ic = action_icons.get(label, ('alert', 'indigo')) %} {{ icon(ic[0]) }}{{ t(label) }}{{ n }}› {% endfor %}
{% else %}
{{ icon('check') }}
{{ t('All caught up') }}
{{ t('Nothing is waiting for you.') }}
{% endif %} {% if drafts %}
{{ drafts }} {{ t('draft documents waiting to be posted') }}
{% endif %}
{% if branches|length > 1 %}

{{ t('Branch performance') }} ({{ currency }})

{{ t('Consolidated reports') }} →
{% set tones = ['indigo', 'green', 'amber', 'blue', 'red'] %} {% for b in branches %}{% set s = stats[b.id] %} {% endfor %}
{{ t('Branch') }}{{ t('Revenue (YTD)') }}{{ t('Net Profit (YTD)') }}{{ t('Share of revenue') }}{{ t('Receivables') }}
{{ b.code }}
{{ nm(b) }}{{ b.currency }}{% if b.currency != currency %} → {{ currency }}{% endif %}
{{ s.revenue|money(currency) }} {{ s.profit|money(currency) }}
{{ s.receivable|money(currency) }}
{{ t('Total') }}{{ totals.revenue|money(currency) }}{{ totals.profit|money(currency) }}{{ totals.receivable|money(currency) }}
{% if translated %}
{{ t('Foreign-currency branches are translated at today\'s closing rate. Inter-branch balances are not eliminated here; see the consolidated reports.') }}
{% endif %}
{% else %}

{{ t('Position') }}

{{ t('Bank and Cash') }}{{ totals.cash|money(currency) }}
{{ t('Receivables') }}{{ totals.receivable|money(currency) }}
{{ t('Payables') }}{{ totals.payable|money(currency) }}
{{ t('Net Profit (YTD)') }}{{ totals.profit|money(currency) }}
{% endif %}

{{ t('Recent invoices') }}

{{ t('View all') }} →
{% set tones = ['blue', 'green', 'amber', 'indigo', 'red'] %} {% for i in recent %}{% set pname = nm({'name_en': i.pname_en, 'name_ar': i.pname_ar}) %} {% else %}{% endfor %}
{{ (pname[:2] if lang == 'en' else pname[:1])|upper }}
{{ i.number or t('Draft') }}{{ pname }}
{% if i.overdue %}{{ t('Overdue') }}{% elif i.pay %}{{ pay_badge(i.pay) }}{% else %}{{ state_badge(i.state) }}{% endif %} {{ i.amount_total|money }}
{{ t('Nothing yet.') }}
{% endif %} {% endblock %} {% block scripts %} {% endblock %}