{% extends "base.html" %} {% from '_upsell.html' import crown_badge, max_badge, beta_pill %} {% block title %}{{ _("Customers") }}{% endblock %} {% block content %}
{# ── Header row ── #}

people {{ _("Customers") }}

{% trans %}manual sync — use API sync or CSV import{% endtrans %}
{% trans count=total_count %}{{ count }} customer{% pluralize %}{{ count }} customers{% endtrans %}
{% include '_csv_import.html' %} {# ── Filters ── #}
{# Preserve sort + pill values as hidden inputs (updated by JS) #} {% if filters.search or filters.country or filters.bc or filters.ctype or filters.online or filters.module %} {{ _("Clear") }} {% endif %}
{# ── Online / Module pill filters ── #}
{{ _("Online:") }} {% set online_opts = [('', _('All')), ('yes', _('Online')), ('no', _('Offline')), ('unchecked', _('Unchecked'))] %} {% for val, label in online_opts %} {% endfor %}
{{ _("Module:") }} {% set module_opts = [('', _('All')), ('yes', _('Found')), ('no', _('Not found')), ('unchecked', _('Unchecked'))] %} {% for val, label in module_opts %} {% endfor %}
{# ── Summary strip (live-updated during checks) ── #}
{% trans count=total_count %}Showing {{ count }} customer{% pluralize %}Showing {{ count }} customers{% endtrans %} {% if check_summary %} | task_alt {{ check_summary.checked | default(0) }} {{ _("checked") }} · {{ check_summary.online | default(0) }} {{ _("online") }} · {{ check_summary.offline | default(0) }} {{ _("offline") }} · extension {{ check_summary.module_found | default(0) }} {{ _("modules") }} · schedule {{ check_summary.unchecked | default(0) }} {{ _("queued") }} {% endif %}
{# ── Inline website-check progress banner (hidden until check runs) ── #} {# ── Sort tabs ── #}
{% set sort_options = [ ('activity_desc', _('Recent Activity')), ('revenue_desc', _('Top Revenue')), ('orders_desc', _('Most Orders')), ('tickets_desc', _('Most Tickets')), ('name_asc', _('Name A-Z')), ] %} {% for val, label in sort_options %} {{ label }} {% endfor %}
{# ── Customers table ── #} {% if customers %}
{% set base_url = url_for('customers_list', search=filters.search, country=filters.country, ctype=filters.ctype, bc=filters.bc, online=filters.online, module=filters.module, page=1) %} {% macro sort_th(label, key, align='left') %} {% set cur = filters.sort or 'activity_desc' %} {% set is_active = cur.startswith(key) %} {% set next_sort = key + '_asc' if cur == key + '_desc' else key + '_desc' %} {% set arrow = '' %} {% if cur == key + '_desc' %}{% set arrow = ' ▼' %}{% elif cur == key + '_asc' %}{% set arrow = ' ▲' %}{% endif %} {% endmacro %} {{ sort_th(_('Customer'), 'name') }} {{ sort_th(_('Website'), 'website') }} {{ sort_th(_('Country'), 'country') }} {{ sort_th(_('Revenue'), 'revenue', 'right') }} {{ sort_th(_('Orders'), 'orders', 'center') }} {{ sort_th(_('Products'), 'products', 'center') }} {{ sort_th(_('Tickets'), 'tickets', 'center') }} {{ sort_th(_('Last Activity'), 'activity') }} {% for c in customers %} {# Customer name #} {# Website URL #} {# Online status #} {# Module found #} {# Country #} {# Revenue #} {# Orders #} {# Products #} {# Tickets #} {# BC badge #} {# Last Activity #} {% endfor %}
{{ label }}{{ arrow | safe }} {{ _("Online") }} {{ _("Module") }}{{ _("BC") }}
{{ c.display_name }} {% if c.website %} {% set ws_href = c.website if c.website.startswith('http') else 'https://' + c.website %} {{ c.website | truncate(30) }} {% else %} -- {% endif %} {% set ss = site_status.get(c.customer_hash) %} {% if ss and ss.is_online == true %} {% set tip = _('Online') %} {% if ss.error_message %}{% set tip = _('Online') ~ ' (' ~ ss.http_status ~ ' — ' ~ ss.error_message ~ ')' %} {% elif ss.http_status %}{% set tip = _('Online') ~ ' (' ~ ss.http_status ~ ', ' ~ (ss.response_time_ms or '?') ~ 'ms)' %}{% endif %} {% elif ss and ss.is_online == false %} {% set tip = _('Offline') %} {% if ss.error_message %}{% set tip = _('Offline') ~ ' — ' ~ ss.error_message %}{% endif %} {% else %}--{% endif %} {% set ss = site_status.get(c.customer_hash) %} {% if ss and ss.modules_found_slugs %}
{% for slug in ss.modules_found_slugs %} {% if slug in ss.get('purchased_slugs', []) %} {{ slug }} {% else %} {{ slug }} {% endif %} {% endfor %}
{% elif ss and ss.module_found == false %}{{ _("No") }} {% else %}--{% endif %}
{{ c.country_code or '--' }} €{{ c.total_revenue }} {{ c.total_orders }} {{ c.total_products }} {{ c.total_threads }} {% if c.has_bc %} {{ _("BC") }} {% else %} -- {% endif %} {{ c.last_activity|localdt('%Y-%m-%d') if c.last_activity else '--' }}
{# ── Pagination ── #} {% if total_pages > 1 %}

{% trans %}Page {{ page }} of {{ total_pages }}{% endtrans %}

{% if page > 1 %} chevron_left {% endif %} {% for p in range(1, total_pages + 1) %} {% if p == page %} {{ p }} {% elif p == 1 or p == total_pages or (p >= page - 2 and p <= page + 2) %} {{ p }} {% elif p == 2 or p == total_pages - 1 %} {% endif %} {% endfor %} {% if page < total_pages %} chevron_right {% endif %}
{% endif %} {% else %} {# ── Empty state ── #}
people

{{ _("No customers found.") }}

{{ _("Try adjusting your filters or sync orders first.") }}

{% endif %}
{% endblock %}