{% extends "base.html" %} {% block title %}Dashboard{% endblock %} {% block content %} {# Handler ("Handled by") breakdown chips for an issue KPI card. `base` is a dict of extra issues.index query params identifying the card's scope. #} {% macro handler_chips(bd, base) %}
Handled by: {% if bd.internal > 0 %} Janitorial {{ bd.internal }}{% endif %} {% if bd.facility > 0 %} Facility {{ bd.facility }}{% endif %} {% if bd.vendor > 0 %} Vendor {{ bd.vendor }}{% endif %}
{% endmacro %}

Welcome, {{ current_user.display_name }}!

{{ current_user.role.replace('_',' ')|title }}
{# ── Scheduled inspections: upcoming / overdue (phase36) ─────────────────── #} {% if current_user.role != 'customer' and (sched_upcoming or sched_overdue_count) %}
Scheduled Inspections View all
{% if sched_overdue_count %}
{{ sched_overdue_count }} scheduled inspection{{ 's' if sched_overdue_count != 1 }} {{ 'are' if sched_overdue_count != 1 else 'is' }} overdue.
{% endif %} {% if sched_upcoming %}
{% for s in sched_upcoming %} {% endfor %}
FacilityTemplateInspectorDue
{{ s.facility.name if s.facility else '—' }} {{ s.template.name if s.template else '—' }} {{ s.inspector.display_name if s.inspector else '—' }} {{ s.next_due_date.strftime('%b %d') }} {% if current_user.role in ['admin','director','project_manager'] or (current_user.role == 'inspector' and s.inspector_id == current_user.id) %} Start {% endif %}
{% else %}

No inspections due in the next 7 days.

{% endif %}
{% endif %} {# ── Inspections section ─────────────────────────────────────────────────── #}
Inspections
Today's Inspections
{{ today_inspections }}
All inspections started today
Submitted Today
{{ completed_today }}
Fully completed & submitted today
{% if current_user.role != 'customer' %}
Stale In-Progress
{{ stale_in_progress }}
Started >24 h ago, not yet submitted
Pending Follow-ups
{{ pending_followups }}
Flagged for a follow-up re-inspection
{% endif %}
{# ── Issues section ──────────────────────────────────────────────────────── #}
Issues
{# Open issues split into three cards by who handles them. #}
Open · Janitorial
{{ handler_breakdown.internal }}
Open issues handled by our crew
Open · Facility Staff
{{ handler_breakdown.facility }}
Open issues the facility staff handle
Open · Vendor
{{ handler_breakdown.vendor }}
Open issues an outside vendor handles
Issues Opened Today
{{ issues_opened_today }}
{% if issues_opened_today > 0 %} {{ handler_chips(opened_today_handler, {'date_from': today_str, 'date_to': today_str}) }} {% else %}
New issues reported today
{% endif %}
Resolved Today
{{ resolved_today }}
Issues closed and resolved today
{% if current_user.role != 'customer' %}
Pending Verification
{{ pending_verification }}
Resolved but awaiting supervisor sign-off
Unassigned Open
{{ unassigned_open }}
{% if unassigned_open > 0 %} {{ handler_chips(unassigned_handler, {'status': 'open', 'unassigned': '1'}) }} {% else %}
Open issues with no one assigned
{% endif %}
{% endif %}
{# ── SLA Summary ─────────────────────────────────────────────────────────── #} {% if sla_breached > 0 or sla_at_risk > 0 %}
{% if sla_breached > 0 %}
SLA Breached
{{ sla_breached }}
{% endif %} {% if sla_at_risk > 0 %}
SLA At Risk
{{ sla_at_risk }}
{% endif %}
{% endif %} {# ── Recent activity ─────────────────────────────────────────────────────── #}
Recent Activity
{% if recent_inspections %}
{% if current_user.role != 'inspector' %}{% endif %} {% for insp in recent_inspections %} {% if current_user.role != 'inspector' %}{% endif %} {% endfor %}
Date Facility AreaInspectorScore Status
{{ insp.inspection_date.strftime('%Y-%m-%d %H:%M') }} {{ insp.facility.name }} {{ insp.area.name if insp.area else '—' }}{{ insp.inspector.display_name }} {% if insp.overall_score %} {{ insp.overall_score }}% {% else %} {% endif %} {{ 'Submitted' if insp.status == 'completed' else insp.status|title }}
{% else %}
No recent inspections.
{% endif %}
{# ── Inspector activity today (admin / director / PM) ───────────────────── #} {% if inspector_activity %}
Inspector Activity Today View all
{% for row in inspector_activity %} {% endfor %}
Inspector Submitted Today
{{ row.name }} {% if row.count > 0 %} {{ row.count }} {% else %} {% endif %}
{% set max_count = inspector_activity | map(attribute='count') | max %} {% set pct = (row.count / max_count * 100) | int if max_count > 0 else 0 %}
{% endif %} {# ── My open issues (inspector widget) ──────────────────────────────────── #} {% if my_issues %}
My Open Issues View all
{% for issue in my_issues %} {% set sla = sla_status(issue) %} {% endfor %}
ID Severity Facility / Description Status SLA
#{{ issue.id }} {{ issue.severity|title }}
{{ issue.resolved_facility.name if issue.resolved_facility else '—' }}
{{ issue.description[:60] }}{% if issue.description|length > 60 %}…{% endif %}
{{ issue.status|replace('_',' ')|title }} {% if sla == 'breached' %} Breached {% elif sla == 'at_risk' %} {{ sla_hours_remaining(issue)|abs|round(1) }}h left {% else %} OK {% endif %}
{% endif %} {# ── Customer portal: scoped facilities panel ───────────────────────────── #} {% if current_user.role == 'customer' %}
Your Facilities {% if customer_facilities %} {{ customer_facilities|length }} {% endif %}
{% if customer_facilities %}
{% if customer_facilities|length > 6 %}
{% endif %}
{% for f in customer_facilities %}
{{ f.name }}
{{ f.address or '—' }}
{{ f.project.name if f.project else '—' }}
{% endfor %}
{% if customer_facilities|length > 9 %}
{% endif %}
{% else %}
No facilities have been assigned to your account yet. Please contact your administrator.
{% endif %}
{% endif %} {% endblock %}