{% extends "base.html" %}{% block title %}Prévention — GMAO{% endblock %}{% block content %}
<div class="d-flex justify-content-between"><div><h1 class="h3"><i class="bi bi-shield-check"></i> Assistant de prévention</h1><p class="text-muted">Agents, temps dédié, DUERP, habilitations et plan d’actions.</p><a class="btn btn-sm btn-outline-success" href="{{ url_for('prevention.export_duerp') }}"><i class="bi bi-download"></i> Exporter le DUERP</a></div><div class="text-end"><strong>{{ (minutes / 60)|round(1) }} h / {{ (target / 60)|round(1) }} h</strong><div class="progress" style="width:220px"><div class="progress-bar" style="width:{{ [100, minutes * 100 / target]|min if target else 0 }}%">Objectif 10 % du temps réellement disponible</div></div><small class="text-muted">Base : {{ (available_minutes / 60)|round(1) }} h cette semaine</small></div></div>
<div class="row g-3">
<div class="col-lg-6"><div class="card"><div class="card-header">Temps de prévention</div><div class="card-body"><form method="post" action="{{ url_for('prevention.add_time') }}" class="row g-2"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="col-4"><input type="date" name="work_date" class="form-control" required></div><div class="col-3"><input type="number" min="1" name="duration_minutes" class="form-control" placeholder="Minutes" required></div><div class="col"><input name="activity" class="form-control" placeholder="Activité" required></div><div class="col-auto"><button class="btn btn-primary">Ajouter</button></div></form><table class="table table-sm mt-3"><tbody>{% for x in logs %}<tr><td>{{ x.work_date|date_fmt }}</td><td>{{ x.activity }}</td><td>{{ x.duration_minutes }} min</td></tr>{% endfor %}</tbody></table></div></div></div>
<div class="col-lg-6"><div class="card"><div class="card-header">Agents et habilitations ({{ staff|length }})</div><div class="card-body"><form method="post" action="{{ url_for('prevention.add_staff') }}" class="row g-2 mb-3"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="col"><input name="first_name" class="form-control" placeholder="Prénom" required></div><div class="col"><input name="last_name" class="form-control" placeholder="Nom" required></div><div class="col"><input name="function" class="form-control" placeholder="Fonction"></div><div class="col-auto"><button class="btn btn-primary">Ajouter</button></div></form><form method="post" action="{{ url_for('prevention.add_authorization') }}" class="row g-2"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="col"><select name="staff_id" class="form-select" required><option value="">Agent…</option>{% for x in staff %}<option value="{{ x.id }}">{{ x.full_name }}</option>{% endfor %}</select></div><div class="col"><input name="name" class="form-control" placeholder="Habilitation / formation" required></div><div class="col"><input type="date" name="expires_on" class="form-control"></div><div class="col-auto"><button class="btn btn-outline-primary">Ajouter</button></div></form></div></div></div>
<div class="col-lg-6"><div class="card"><div class="card-header">DUERP — risques</div><div class="card-body"><form method="post" action="{{ url_for('prevention.add_risk') }}" class="row g-2"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="col-5"><input name="work_unit" class="form-control" placeholder="Unité de travail" required></div><div class="col-7"><input name="hazard" class="form-control" placeholder="Danger / situation" required></div><div class="col-3"><input type="number" min="1" max="4" name="severity" class="form-control" placeholder="Gravité"></div><div class="col-3"><input type="number" min="1" max="4" name="probability" class="form-control" placeholder="Probabilité"></div><div class="col"><input name="control_measures" class="form-control" placeholder="Mesures existantes"></div><div class="col-auto"><button class="btn btn-primary">Ajouter</button></div></form><table class="table table-sm mt-3"><tbody>{% for x in risks %}<tr><td>{{ x.work_unit }}</td><td>{{ x.hazard }}</td><td><span class="badge text-bg-{{ 'danger' if x.score >= 9 else 'warning' if x.score >= 4 else 'success' }}">{{ x.score }}</span></td></tr>{% endfor %}</tbody></table></div></div></div>
<div class="col-lg-6"><div class="card"><div class="card-header">Plan d’actions</div><div class="card-body"><form method="post" action="{{ url_for('prevention.add_action') }}" class="row g-2"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="col"><input name="title" class="form-control" placeholder="Action" required></div><div class="col-3"><input name="owner" class="form-control" placeholder="Pilote"></div><div class="col-3"><input type="date" name="due_date" class="form-control"></div><div class="col-auto"><button class="btn btn-primary">Ajouter</button></div></form><table class="table table-sm mt-3"><tbody>{% for x in actions %}<tr><td>{{ x.title }}</td><td>{{ x.owner or '—' }}</td><td>{{ x.due_date|date_fmt }}</td><td><form method="post" action="{{ url_for('prevention.update_action_status', id=x.id) }}" class="d-flex gap-1"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><select name="status" class="form-select form-select-sm"><option value="a_faire" {% if x.status == 'a_faire' %}selected{% endif %}>À faire</option><option value="validee" {% if x.status == 'validee' %}selected{% endif %}>Validée</option><option value="planifiee" {% if x.status == 'planifiee' %}selected{% endif %}>Planifiée</option><option value="en_cours" {% if x.status == 'en_cours' %}selected{% endif %}>En cours</option><option value="verifiee" {% if x.status == 'verifiee' %}selected{% endif %}>Vérifiée</option><option value="cloturee" {% if x.status == 'cloturee' %}selected{% endif %}>Clôturée</option><option value="refusee" {% if x.status == 'refusee' %}selected{% endif %}>Refusée</option></select><button class="btn btn-sm btn-outline-secondary">OK</button></form></td></tr>{% endfor %}</tbody></table></div></div></div>
<div class="col-12"><div class="card"><div class="card-header">Registre sécurité / incidents / exercices</div><div class="card-body"><form method="post" action="{{ url_for('prevention.add_register') }}" class="row g-2"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="col-2"><input type="date" name="entry_date" class="form-control" required></div><div class="col-2"><select name="entry_type" class="form-select"><option>observation</option><option>incident</option><option>presque_accident</option><option>exercice</option><option>verification</option></select></div><div class="col"><input name="title" class="form-control" placeholder="Objet" required></div><div class="col"><input name="location" class="form-control" placeholder="Lieu"></div><div class="col-auto"><button class="btn btn-primary">Ajouter</button></div></form><table class="table table-sm mt-3"><tbody>{% for x in entries %}<tr><td>{{ x.entry_date|date_fmt }}</td><td>{{ x.entry_type }}</td><td>{{ x.title }}</td><td>{{ x.location }}</td></tr>{% endfor %}</tbody></table></div></div></div>
</div>{% endblock %}
