{% extends "base.html" %}
{% block title %}{{ consumable.name }} — GMAO{% endblock %}
{% block content %}<div class="container-fluid"><h1 class="h4">{{ consumable.name }}</h1><p>Référence : {{ consumable.reference or '—' }} · Type : {{ consumable.consumable_type }} · Stock : {{ consumable.quantity }} · Minimum : {{ consumable.min_quantity }} · Cible : {{ consumable.target_quantity or '—' }} · À commander : {{ consumable.quantity_to_order }}</p><p>Commandé / à recevoir : <strong>{{ quantity_on_order }}</strong></p><p>Couverture estimée : {% if coverage.coverage_days is not none %}~{{ '%.0f'|format(coverage.coverage_days) }} jours{% else %}indisponible{% endif %} — {{ coverage.quality }} ({{ coverage.machines_with_history }}/{{ coverage.machines_total }} machines avec historique)</p><h2 class="h5">Compatible avec {{ compatible|length }} équipement(s)</h2><ul>{% for link in compatible %}<li>{{ link.equipment.name }}</li>{% else %}<li>Aucune machine.</li>{% endfor %}</ul><h2 class="h5">Commandes</h2><div class="table-responsive"><table class="table table-sm"><tr><th>Quantité</th><th>Reçue</th><th>À recevoir</th><th>État</th><th>Action</th></tr>{% for order in orders %}<tr><td>{{ order.quantity_ordered }}</td><td>{{ order.quantity_received }}</td><td>{{ order.remaining_quantity }}</td><td>{{ order.status }}</td><td>{% if order.remaining_quantity and order.status in ('ORDERED','PARTIALLY_RECEIVED') %}<form method="post" action="{{ url_for('c4.receive_order', order_id=order.id) }}" class="d-flex gap-2 mb-1"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input class="form-control form-control-sm" type="number" name="quantity" min="1" max="{{ order.remaining_quantity }}" value="{{ order.remaining_quantity }}"><button class="btn btn-sm btn-success">Réceptionner</button></form><form method="post" action="{{ url_for('c4.cancel_order', order_id=order.id) }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="reason" value="Annulation demandée"><button class="btn btn-sm btn-outline-danger">Annuler</button></form>{% endif %}</td></tr>{% else %}<tr><td colspan="5">Aucune commande.</td></tr>{% endfor %}</table></div><form method="post" action="{{ url_for('c4.order_consumable', consumable_id=consumable.id) }}" class="row g-2 mt-3"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="col-auto"><label class="form-label">Nouvelle commande</label><input class="form-control" type="number" name="quantity" min="1" value="{{ consumable.quantity_to_order or 1 }}"></div><div class="col-auto align-self-end"><button class="btn btn-primary">Commander</button></div></form><h2 class="h5 mt-4">Historique des sorties</h2><ul>{% for usage in usages %}<li>{{ usage.used_at }} — {{ usage.quantity_used }} — {{ usage.equipment.name if usage.equipment else '—' }}</li>{% else %}<li>Aucune sortie.</li>{% endfor %}</ul></div>{% endblock %}
