{{ report.frequency|title }} Report — {{ report.name }}
{{ start.strftime('%b %d, %Y') }} — {{ end.strftime('%b %d, %Y') }}{% if facility %} · {{ facility.name }}{% endif %}

{% if report.report_type in ('summary','facility') %}
SUMMARY
-------
Inspections:  {{ total_inspections }}
Completed:    {{ completed }}
Open Issues:  {{ open_issues }}
Avg Score:    {{ '%.1f'|format(avg_score) ~ '%' if avg_score else '—' }}

{% if facility_scores %}
FACILITY SCORES
---------------
{% for row in facility_scores %}
  {{ row.name }}: {{ '%.1f'|format(row.avg) }}% ({{ row.count }} inspection{{ 's' if row.count != 1 else '' }})
{% endfor %}
{% endif %}

{% if critical_issues %}
OPEN CRITICAL / HIGH ISSUES
----------------------------
{% for i in critical_issues %}
  {% set rf = i.resolved_facility %}#{{ i.id }} [{{ i.severity|title }}] {{ rf.name if rf else '—' }} — {{ i.description[:80] }}
  Link: {{ base_url }}/issues/{{ i.id }}
{% endfor %}
{% endif %}

{% elif report.report_type == 'issues' %}
OPEN ISSUES ({{ issues|length }}) — Breached: {{ sla_breached }}  At Risk: {{ sla_at_risk }}
{% if issues %}
{% for facility_name, fac_issues in issues_by_facility %}

  {{ facility_name }} ({{ fac_issues|length }} issue{{ 's' if fac_issues|length != 1 else '' }})
  {% for i, sla in fac_issues %}  #{{ i.id }} [{{ i.severity|title }}] [SLA: {{ 'Breached' if sla == 'breached' else 'At Risk' if sla == 'at_risk' else 'OK' }}] {{ i.area.name if i.area else '—' }}
    Status: {{ i.status|replace('_',' ')|title }} | {{ i.description[:70] }}
    Link: {{ base_url }}/issues/{{ i.id }}
  {% endfor %}
{% endfor %}
{% else %}
  No open issues.
{% endif %}
{% endif %}

--
Janitorial QC System — automated scheduled report.
View dashboard: {{ base_url }}/reports
