<?php
session_start();
require_once '../koneksi.php';
require_once '../auth.php';
require_once '../vendor/autoload.php'; // Sesuaikan path autoload dompdf Anda

use Dompdf\Dompdf;

$id_siswa = $_GET['id_siswa'];
$siswa = mysqli_fetch_assoc(mysqli_query($koneksi, "SELECT nama FROM master_siswa WHERE id_siswa = '$id_siswa'"));
$riwayat = mysqli_query($koneksi, "SELECT * FROM riwayat_tabungan WHERE id_siswa = '$id_siswa' ORDER BY tanggal ASC");

// Mulai membuat HTML untuk PDF
$html = "<h3>Laporan Transaksi Tabungan</h3>";
$html .= "<p>Nama Siswa: " . htmlspecialchars($siswa['nama']) . "</p>";
$html .= "<table border='1' cellpadding='5' style='width:100%; border-collapse:collapse;'>
            <tr><th>Tanggal</th><th>Jenis</th><th>Jumlah</th><th>Keterangan</th></tr>";

while($row = mysqli_fetch_assoc($riwayat)) {
    $html .= "<tr>
                <td>" . date('d-m-Y', strtotime($row['tanggal'])) . "</td>
                <td>" . $row['jenis'] . "</td>
                <td>Rp " . number_format($row['jumlah'], 0, ',', '.') . "</td>
                <td>" . $row['keterangan'] . "</td>
              </tr>";
}
$html .= "</table>";

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("Laporan_Tabungan_" . $siswa['nama'] . ".pdf");
?>