{% extends "base.html" %}
{% block title %}{{ contract.name }} — GMAO{% endblock %}
{% block content %}
<div class="container-fluid">
  <div class="d-flex justify-content-between"><h1 class="h4">{{ contract.name }}</h1><span class="badge text-bg-secondary">{{ contract.status }}</span></div>
  <p>{{ contract.supplier.name }} · {{ contract.start_date }} → {{ contract.end_date }} · période quota à partir du {{ contract.quota_start_date or contract.start_date }} · anniversaire {{ '%02d/%02d'|format(contract.anniversary_day, contract.anniversary_month) }}</p>
  <form method="post" action="{{ url_for('c4.close_contract', contract_id=contract.id) }}" class="mb-3"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><button class="btn btn-outline-danger btn-sm">Clore le contrat</button></form>
  {% for period in periods %}{% set u=usage[period.id] %}{% set p=projections[period.id] %}
  <section class="card mb-3"><div class="card-header">Période {{ period.start_date }} → {{ period.end_date }}</div><div class="card-body"><div class="row"><div class="col-md-6"><strong>N&B</strong><br>{{ '%.0f'|format(u.bw) }}{% if period.quota_bw is not none %} / {{ period.quota_bw }}{% else %} — sans quota{% endif %}<small class="d-block">Projection : {{ '%.0f'|format(p.projection.bw) if p.projection.bw is not none else 'indisponible' }}</small></div><div class="col-md-6"><strong>Couleur</strong><br>{{ '%.0f'|format(u.color) }}{% if period.quota_color is not none %} / {{ period.quota_color }}{% else %} — sans quota{% endif %}<small class="d-block">Projection : {{ '%.0f'|format(p.projection.color) if p.projection.color is not none else 'indisponible' }}</small></div></div><small>Machines prises en compte : {{ u.machines }} · qualité : {{ u.quality }}{% if p.confidence == 'LOW' %} · projection à faible confiance{% endif %}</small></div></section>
  {% endfor %}
  <h2 class="h5">Machines rattachées</h2><ul>{% for a in contract.assignments %}<li><a href="{{ url_for('c4.equipment_detail', equipment_id=a.equipment_id) }}">{{ a.equipment.name }}</a> — {{ a.entry_date }}{% if a.exit_date %} → {{ a.exit_date }}{% endif %}</li>{% else %}<li>Aucune machine.</li>{% endfor %}</ul>
</div>
{% endblock %}
