{% extends "base.html" %} {% block title %}{{ customer.username }} — Customer Portal{% endblock %} {% block content %}

{{ customer.display_name }} {{ customer.role_label }} {% if not customer.active %} Disabled {% else %} Active {% endif %}

{{ customer.email }}{% if customer.full_name %} · @{{ customer.username }}{% endif %}

Edit Account {# ── Switch role (admin only) ── #} {% if current_user.role == 'admin' %} {% set to_label = 'Customer Director' if customer.is_inspector else 'Customer Inspector' %}
{% endif %}
All Customers
{# ── Left column: account info + scoped facilities ── #}
Account Details
Full Name
{{ customer.full_name or '—' }}
Role
{{ customer.role_label }}
{% if customer.is_inspector %} Performs inspections and manages issues on their assigned contracts. {% else %} Portal access to their facilities' inspections, issues and reports. {% endif %}
Username
{{ customer.username }}
Email
{{ customer.email }}
Status
{{ 'Active' if customer.active else 'Disabled' }}
Password
{% if customer.password_set %} Set {% else %} Pending setup {% endif %}
Created
{{ customer.created_at.strftime('%Y-%m-%d') }}
Assignments
{{ assigned_pids|length if customer.is_inspector else assignments|length }}
Facilities
{{ facilities|length }}
{% if not customer.password_set %}
{% endif %}
{# ── Scoped facilities ── #}
Accessible Facilities
{% if facilities %}
    {% for f in facilities %}
  • {{ f.name }} {% if f.project %} {{ f.project.name }} {% endif %}
  • {% endfor %}
{% else %}
No facilities accessible yet — add an assignment below.
{% endif %}
{# ── Right column: assignments ── #}
{% if customer.is_inspector %} {# ══ Customer Inspector — whole contracts, no facility-level narrowing ══ Scoped by InspectorAssignment, the same rows an internal inspector uses. Posts the COMPLETE checked set; unchecked contracts are removed. ══ #}
Contract Assignments {{ assigned_pids|length }} assigned

A Customer Inspector sees only the contracts ticked here — with none ticked they see nothing at all. Inspectors are assigned whole contracts; there is no per-facility option for this role.

{% if projects %}
{% for p in projects %} {% endfor %}
{% else %}

No active contracts exist yet.

{% endif %}
{% else %} {# ══ Customer Director — contract or single-facility assignments ══ #} {# ── Current assignments table ── #}
Contract Assignments
{% if assignments %}
{% for a in assignments %} {% endfor %}
Contract Facility Scope Assigned
{{ a.project.name }} {% if a.facility %} {{ a.facility.name }} {% else %} All facilities {% endif %} {{ a.created_at.strftime('%Y-%m-%d') }}
{% else %}
No assignments yet.
{% endif %}
{# ── Add assignment form ── #}
Add Assignment
Leave blank to grant access to all facilities in the contract.
{% endif %} {# ── Per-account notification matrix ───────────────────────────────── Overrides the global Notification Matrix for THIS account only. "Inherit" is the default and means "follow the global column", so it keeps tracking future changes there — it is not a snapshot. #}
Notifications for this account

Each customer's enrollment form says which notifications their people want, so these can differ per person. Inherit follows the global Notification Matrix for {{ customer.role_label }}s — including any later change to it. Choose On or Off only where this account should differ.

{% for row in matrix_rows %} {% endfor %}
Event Inherit On Off
{{ row.label }} {% if row.override is not none %} custom {% endif %}
{{ 'on' if row.global else 'off' }}
{% endblock %} {% block extra_js %} {% endblock %}