<?php
session_start();
require_once '../config/database.php';
$id_siswa = $_SESSION['id_user'];

$stmt = $pdo->prepare("SELECT * FROM transaksi WHERE id_siswa = ? AND status = 'valid' ORDER BY tanggal_transaksi DESC");
$stmt->execute([$id_siswa]);
$rows = $stmt->fetchAll();
?>
<div class="table-responsive">
    <table class="table table-sm table-hover mb-0" style="font-size: 0.85rem;">
        <thead class="table-light">
            <tr>
                <th>Tgl</th>
                <th>Keterangan</th>
                <th class="text-end">Jumlah</th>
            </tr>
        </thead>
        <tbody>
            <?php if(!$rows): ?>
                <tr><td colspan="3" class="text-center py-3">Belum ada transaksi valid.</td></tr>
            <?php endif; ?>
            <?php foreach($rows as $row): ?>
            <tr>
                <td><?= date('d/m', strtotime($row['tanggal_transaksi'])) ?></td>
                <td>
                    <span class="fw-bold"><?= ucfirst($row['jenis_transaksi']) ?></span><br>
                    <small class="text-muted"><?= htmlspecialchars($row['keterangan']) ?></small>
                </td>
                <td class="text-end <?= in_array($row['jenis_transaksi'], ['setoran','transfer_masuk']) ? 'text-success' : 'text-danger' ?>">
                    <?= number_format($row['jumlah'], 0, ',', '.') ?>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>