{% extends "base.html" %} {% block title %}Inspection Schedules{% endblock %} {% block content %} {# Who may create/edit/delete a schedule — mirrors schedule_manager_required in routes/inspection_schedules.py. 'customer' is the Customer DIRECTOR, who plans work for their own facilities; a Customer Inspector ('external_inspector') performs schedules and is covered by is_inspector below. #} {% set can_manage_schedules = current_user.role in ['admin','director','project_manager','auditor','customer'] %}

Inspection Schedules

{% if can_manage_schedules %} New Schedule {% endif %}

{% if current_user.is_inspector %} Inspections scheduled for you. Auto schedules appear in your Inspections list on their own each period; Plan schedules wait for you to press Start. {% else %} Auto schedules automatically create an in-progress inspection for the assigned inspector each period. Plan schedules assign a due date and let the inspector press Start when they begin — with reminders the day before, on the day, and an alert to managers once overdue. {% endif %}

{# Pending / Completed tabs (phase51). The partition is on `active`, so it is exhaustive — no schedule can fall between the two tabs. #} {% if schedules %}
{% for s in schedules %} {% endfor %}
NameTemplateFacility / Area InspectorFrequencyModeNext Due EndsLast RunStatus
{{ s.name }} {% if s.is_follow_up %} {# phase48 — a schedule planned as the deferred twin of "Re-inspect Now". Starting it produces a linked re-inspection. #} Follow-up #{{ s.parent_inspection_id }} {% endif %} {{ s.template.name if s.template else '—' }} {{ s.facility.name if s.facility else '—' }} {% if s.area %}/ {{ s.area.name }}{% endif %} {{ s.inspector.display_name if s.inspector else '—' }} {{ s.recurrence_label }} {% if s.mode == 'plan' %} Plan {% else %} Auto {% endif %} {{ s.next_run_at.strftime('%Y-%m-%d %H:%M') if s.next_run_at else '—' }} {% if s.is_overdue(today) %} Overdue {% endif %} {% if s.frequency == 'once' %}— {% elif s.end_date %}{{ s.end_date.strftime('%Y-%m-%d') }} {% else %}No end{% endif %} {{ s.last_run_at.strftime('%Y-%m-%d %H:%M') if s.last_run_at else 'Never' }} {# "Ended" separates a schedule that reached its end date from one a manager switched off — both are inactive, for different reasons. #} {% if s.active %}Active {% elif s.is_expired %}Ended {% else %}Paused{% endif %} {# phase50 — receipt acknowledgement. Only meaningful for plan mode: an auto schedule materialises itself, so there is no request for anyone to receive. #} {% if s.mode == 'plan' and s.inspector_id %} {% if s.is_acknowledged %} Confirmed {% elif s.active %} Awaiting confirmation {% endif %} {% endif %} {# Assignee-only, like Start: a manager must not be able to confirm on someone's behalf, since the record means "this person saw it". #} {% if s.active and s.mode == 'plan' and not s.is_acknowledged and s.inspector_id == current_user.id %}
{% endif %} {# Start is for whoever must DO the work. A Customer Director can plan a schedule but never execute one — the route 403s them, so the button must not be offered either. #} {% if s.active and s.mode == 'plan' and current_user.role != 'customer' and (not current_user.is_inspector or s.inspector_id == current_user.id) %} Start {% endif %} {% if can_manage_schedules %}
{% endif %}
{% else %}
{% if tab == 'completed' %}

No completed schedules yet.

{% elif completed_count %} {# Nothing pending but there IS history — offer the other tab rather than inviting them to create a duplicate of something already closed. #}

Nothing pending — all schedules are complete.

View Completed ({{ completed_count }}) {% else %}

No inspection schedules configured yet.

{% if can_manage_schedules %} Create First Schedule {% endif %} {% endif %}
{% endif %} {% endblock %}