<?php
require_once '../init.php';

$payments = $subscription->getUserPayments($_SESSION['user_id'], 50);

$pageTitle = 'Pembayaran - KasirMurah.biz.id';
?>
<?php include '../layout/header.php'; ?>
    <?php include '../layout/navbar.php'; ?>
    
    <div class="container mt-4">
        <h1>Riwayat Pembayaran</h1>
        
        <div class="card mt-4">
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead class="table-light">
                            <tr>
                                <th>Invoice</th>
                                <th>Jumlah</th>
                                <th>Tanggal</th>
                                <th>Jatuh Tempo</th>
                                <th>Status</th>
                                <th>Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($payments as $payment): ?>
                            <tr>
                                <td><?php echo $payment['invoice_number']; ?></td>
                                <td><?php echo Helper::formatCurrency($payment['amount']); ?></td>
                                <td><?php echo Helper::formatDate($payment['created_at']); ?></td>
                                <td><?php echo Helper::formatDate($payment['due_date']); ?></td>
                                <td><?php echo Helper::getStatusBadge($payment['status']); ?></td>
                                <td>
                                    <a href="payment-detail.php?payment_id=<?php echo $payment['id']; ?>" class="btn btn-sm btn-info">Detail</a>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
                
                <?php if (empty($payments)): ?>
                <div class="alert alert-info">Belum ada pembayaran</div>
                <?php endif; ?>
            </div>
        </div>
    </div>
    
    <?php include '../layout/footer.php'; ?>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
