Files
LT_Janitorial_Quality_Control/app/templates/customers/index.html
T
2026-04-25 12:41:24 -04:00

153 lines
6.2 KiB
HTML

{% extends "base.html" %}
{% block title %}Customer Management{% endblock %}
{% block content %}
<div class="row mb-4 align-items-center">
<div class="col">
<h2><i class="bi bi-person-badge"></i> Customer Management</h2>
<p class="text-muted mb-0">Manage portal access for all customer accounts.</p>
</div>
<div class="col-auto d-flex gap-2">
<a href="{{ url_for('customers.bulk_import') }}" class="btn btn-outline-success">
<i class="bi bi-upload"></i> Import CSV
</a>
<a href="{{ url_for('customers.create') }}" class="btn btn-primary">
<i class="bi bi-person-plus"></i> New Customer
</a>
</div>
</div>
{% if customers %}
{% if expired_invitations %}
<div class="alert alert-warning d-flex align-items-start gap-3 mb-3" role="alert">
<i class="bi bi-exclamation-triangle-fill fs-5 mt-1 flex-shrink-0"></i>
<div>
<strong>{{ expired_invitations|length }} invitation{{ 's' if expired_invitations|length != 1 else '' }} expired</strong>
— the following customer{{ 's' if expired_invitations|length != 1 else '' }} never completed account setup
and {{ 'their' if expired_invitations|length != 1 else 'their' }} link has expired:
<ul class="mb-2 mt-1">
{% for c in expired_invitations %}
<li>
<strong>{{ c.display_name }}</strong> ({{ c.email }}) —
expired {{ c.set_password_token_expires.strftime('%Y-%m-%d %H:%M') }}
&nbsp;
<form method="POST" action="{{ url_for('customers.resend_invite', customer_id=c.id) }}"
class="d-inline">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="btn btn-sm btn-warning py-0 px-2"
style="font-size:.75rem;">
<i class="bi bi-send me-1"></i>Resend
</button>
</form>
</li>
{% endfor %}
</ul>
<span class="text-muted small">Resend a fresh 72-hour invitation link or delete the account if it is no longer needed.</span>
</div>
</div>
{% endif %}
<div class="card shadow-sm">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead class="table-light">
<tr>
<th>Username</th>
<th>Full Name</th>
<th>Email</th>
<th>Status</th>
<th>Assigned Contracts</th>
<th>Accessible Facilities</th>
<th>Created</th>
<th width="160"></th>
</tr>
</thead>
<tbody>
{% for customer in customers %}
{% set assignments = assignment_map[customer.id] %}
{% set facility_ids = scope_map[customer.id] %}
<tr class="{{ 'table-secondary text-muted' if not customer.active else '' }}">
<td>
<strong>
<a href="{{ url_for('customers.manage', customer_id=customer.id) }}"
class="text-decoration-none">
{{ customer.username }}
</a>
</strong>
</td>
<td>{{ customer.full_name or '—' }}</td>
<td class="small text-muted">{{ customer.email }}</td>
<td>
{% if customer.active %}
<span class="badge bg-success">Active</span>
{% else %}
<span class="badge bg-secondary">Disabled</span>
{% endif %}
</td>
<td>
{% if assignments %}
{% set project_names = assignments | map(attribute='project') | map(attribute='name') | unique | list %}
{% for pname in project_names %}
<span class="badge bg-primary me-1">{{ pname }}</span>
{% endfor %}
{% else %}
<span class="text-muted small">— None —</span>
{% endif %}
</td>
<td>
{% if facility_ids %}
<span class="badge bg-info text-dark">{{ facility_ids|length }} facilit{{ 'y' if facility_ids|length == 1 else 'ies' }}</span>
{% else %}
<span class="text-muted small">— None —</span>
{% endif %}
</td>
<td class="small text-muted">{{ customer.created_at.strftime('%Y-%m-%d') }}</td>
<td class="text-end">
<a href="{{ url_for('customers.manage', customer_id=customer.id) }}"
class="btn btn-sm btn-outline-primary" title="Manage">
<i class="bi bi-gear"></i>
</a>
<a href="{{ url_for('customers.edit', customer_id=customer.id) }}"
class="btn btn-sm btn-outline-secondary" title="Edit">
<i class="bi bi-pencil"></i>
</a>
<form method="POST"
action="{{ url_for('customers.toggle_active', customer_id=customer.id) }}"
class="d-inline">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit"
class="btn btn-sm {{ 'btn-outline-warning' if customer.active else 'btn-outline-success' }}"
title="{{ 'Disable' if customer.active else 'Enable' }}"
onclick="return confirm('{{ 'Disable' if customer.active else 'Enable' }} {{ customer.username }}?')">
<i class="bi bi-{{ 'person-slash' if customer.active else 'person-check' }}"></i>
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{# ── Summary footer ── #}
<div class="mt-3 text-muted small">
{{ customers|length }} customer account{{ 's' if customers|length != 1 else '' }} total
· {{ customers|selectattr('active')|list|length }} active
</div>
{% else %}
<div class="card shadow-sm">
<div class="card-body text-center py-5 text-muted">
<i class="bi bi-person-badge fs-1 d-block mb-3 opacity-25"></i>
<p class="mb-3">No customer accounts have been created yet.</p>
<a href="{{ url_for('customers.create') }}" class="btn btn-primary">
<i class="bi bi-person-plus"></i> Create First Customer
</a>
</div>
</div>
{% endif %}
{% endblock %}