<?= $this->extend('layout/main') ?>
<?= $this->section('content') ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h5 class="m-0">Historique des Paiements</h5>
</div>

<div class="table-card">
    <table class="table table-hover" id="paymentsTable">
        <thead>
            <tr>
                <th>Date</th>
                <th>Facture</th>
                <th>Client</th>
                <th class="text-end">Montant</th>
                <th>Mode</th>
                <th>Reference</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($payments as $p): ?>
                <tr>
                    <td><?= date('d/m/Y', strtotime($p['payment_date'])) ?></td>
                    <td><a href="/invoices/view/<?= $p['invoice_id'] ?>" class="fw-bold text-decoration-none"><?= $p['invoice_number'] ?></a></td>
                    <td><?= $p['company_name'] ?></td>
                    <td class="text-end fw-bold text-success"><?= number_format($p['amount'], 2, ',', ' ') ?> TND</td>
                    <td><span class="badge bg-info"><?= ucfirst($p['payment_method']) ?></span></td>
                    <td><?= $p['reference'] ?: '-' ?></td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <?= $pager->links() ?>
</div>

<?= $this->endSection() ?>

<?= $this->section('scripts') ?>
<script>
$(document).ready(function() {
    $('#paymentsTable').DataTable({
        paging: false,
        info: false,
        searching: false,
        order: [[0, 'desc']],
        language: { url: '//cdn.datatables.net/plug-ins/1.13.7/i18n/fr-FR.json' }
    });
});
</script>
<?= $this->endSection() ?>
