<?php $fmt = static fn($v) => number_format((float)$v, 2, ',', ' ') . ' MAD'; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
  <div><h1 class="darlink-title mb-1">Cycle documentaire complet</h1><p class="text-muted mb-0">Devis → BL → Facture → Encaissement / Avoir</p></div>
  <a href="index.php?page=dashboard_commercial" class="btn btn-outline-secondary">Retour au pilotage</a>
</div>
<div class="row g-3 mb-4">
<?php foreach ([['Devis en attente',$cycle['devis_attente'],'devis'],['BL à facturer',$cycle['bl_a_facturer'],'bons_livraison'],['Factures à encaisser',$cycle['factures_a_encaisser'],'factures'],['Factures en retard',$cycle['factures_en_retard'],'factures']] as $k): ?>
<div class="col-md-3"><a class="text-decoration-none text-body" href="index.php?page=<?= $k[2] ?>"><div class="darlink-card p-3 h-100"><div class="text-muted small"><?= $k[0] ?></div><div class="h3 mb-0"><?= (int)$k[1] ?></div></div></a></div>
<?php endforeach; ?>
</div>
<div class="darlink-card p-4 mb-4"><div class="text-muted small">Reste total à encaisser</div><div class="h3 text-danger mb-0"><?= $fmt($cycle['reste_du']) ?></div></div>
<div class="darlink-card p-4"><h5>Documents récemment modifiés</h5><div class="table-responsive"><table class="table table-hover align-middle"><thead><tr><th>Type</th><th>Numéro</th><th>Dernière modification</th><th></th></tr></thead><tbody>
<?php foreach ($cycle['recent'] as $row): ?><tr><td><?= htmlspecialchars($row['type']) ?></td><td><strong><?= htmlspecialchars($row['numero']) ?></strong></td><td><?= htmlspecialchars($row['date_action']) ?></td><td class="text-end"><a class="btn btn-sm btn-outline-primary" href="index.php?page=<?= htmlspecialchars($row['page']) ?>&id=<?= (int)$row['id'] ?>">Ouvrir</a></td></tr><?php endforeach; ?>
</tbody></table></div></div>
