<?php
$types = $conn->query("
    SELECT id, libelle
    FROM types_caisse
    ORDER BY libelle
")->fetchAll(PDO::FETCH_ASSOC);
?>

<form method="POST" action="/eagle_client_istanbulcups/api/caisses/add_type_to_caisse.php">
<div class="modal fade" id="addType" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">

      <div class="modal-header bg-primary text-white">
        <h5>Affecter un type de caisse</h5>
        <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
      </div>

      <div class="modal-body">
        <input type="hidden" name="caisse_id" value="<?= $caisse_id ?>">

        <div class="mb-3">
          <label class="form-label">Type de caisse</label>
          <select name="type_caisse_id" class="form-select" required>
            <option value="">-- Choisir --</option>
            <?php foreach ($types as $t): ?>
              <option value="<?= $t['id'] ?>">
                <?= htmlspecialchars($t['libelle']) ?>
              </option>
            <?php endforeach; ?>
          </select>
        </div>

        <div class="mb-3">
          <label class="form-label">Solde initial</label>
          <input type="number" step="0.01" name="solde_initial" class="form-control" value="0">
        </div>
      </div>

      <div class="modal-footer">
        <button class="btn btn-success">
          <i class="fa fa-plus"></i> Affecter
        </button>
      </div>

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