<div class="modal fade" id="facturerCommande<?= $c['id'] ?>" tabindex="-1">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">

      <div class="modal-header bg-success text-white">
        <h5>Facturation - <?= htmlspecialchars($c['numero']) ?></h5>
        <button class="btn-close" data-bs-dismiss="modal"></button>
      </div>

      <form method="POST" action="/eagle_client_istanbulcups/api/devis/facturer.php">

        <div class="modal-body">

          <input type="hidden" name="commande_id" value="<?= $c['id'] ?>">

          <table class="table table-bordered">
            <thead class="table-dark">
              <tr>
                <th>Produit</th>
                <th>Commandé</th>
                <th>Livré</th>
                <th>Déjà facturé</th>
                <th>Reste à facturer</th>
                <th>Facturer</th>
              </tr>
            </thead>

            <tbody>
            <?php foreach ($details as $d): 
              $reste = $d['quantite_livree'] - $d['quantite_facturee'];
            ?>
              <tr>
                <td><?= $d['produit'] ?></td>
                <td><?= $d['quantite'] ?></td>
                <td><?= $d['quantite_livree'] ?></td>
                <td><?= $d['quantite_facturee'] ?></td>
                <td><?= $reste ?></td>

                <td>
                  <input type="number"
                         name="factures[<?= $d['id'] ?>]"
                         class="form-control"
                         min="0"
                         max="<?= $reste ?>"
                         value="0">
                </td>
              </tr>
            <?php endforeach; ?>
            </tbody>
          </table>

        </div>

        <div class="modal-footer">
          <button class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
          <button class="btn btn-success">Créer facture</button>
        </div>

      </form>

    </div>
  </div>
</div>