<!DOCTYPE html>
<html lang="id">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $title ?></title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
    <style>
        body {
            font-family: 'Times New Roman', Times, serif;
            color: black;
            background-color: white;
            padding: 20px;
        }

        .kop-surat {
            text-align: center;
            margin-bottom: 20px;
        }

        .kop-surat h2 {
            margin: 0;
            font-weight: bold;
            font-size: 24px;
        }

        .kop-surat h5 {
            margin: 5px 0;
            font-size: 18px;
        }

        .kop-surat p {
            margin: 0;
            font-size: 14px;
        }

        .garis-kop {
            border-top: 3px solid black;
            margin-top: 15px;
            margin-bottom: 2px;
        }

        .garis-kop-bawah {
            border-top: 1px solid black;
            margin-top: 0px;
            margin-bottom: 20px;
        }

        .table-print th,
        .table-print td {
            border: 1px solid black !important;
            padding: 8px;
        }

        .table-print th {
            text-align: center;
            background-color: #f8f9fa !important;
        }

        .text-right {
            text-align: right;
        }

        .text-center {
            text-align: center;
        }
    </style>
</head>

<body>

    <div class="kop-surat">
        <h2>KELOMPOK TANI SARI RASA</h2>
        <h5>Desa Trahean, Kecamatan Teweh Seletan, Kabupaten Barito Utara</h5>
        <p>Sekretariat: Jl. Pertanian No. 12 | Email: sarirasa@kelompoktani.id | Telp: 0812-3456-7890</p>
    </div>
    <hr class="garis-kop">
    <hr class="garis-kop-bawah">

    <div class="text-center mb-4">
        <h4 style="text-decoration: underline; font-weight: bold;">LAPORAN BUKU KAS KEUANGAN</h4>
        <p>Periode Tahun: <?= date('Y') ?></p>
    </div>

    <table class="table table-print w-100">
        <thead>
            <tr>
                <th width="10%">Tanggal</th>
                <th width="35%">Uraian / Keterangan</th>
                <th width="15%">Pemasukan</th>
                <th width="15%">Pengeluaran</th>
                <th width="20%">Saldo Akhir</th>
            </tr>
        </thead>
        <tbody>
            <?php if (empty($kas)): ?>
                <tr>
                    <td colspan="5" class="text-center">Belum ada transaksi keuangan.</td>
                </tr>
            <?php else: ?>
                <?php foreach ($kas as $k): ?>
                    <tr>
                        <td class="text-center"><?= date('d/m/Y', strtotime($k['tanggal'])) ?></td>
                        <td>
                            <?= $k['keterangan'] ?>
                            <?php if (!empty($k['nama_petani'])): ?>
                                <br><small style="color: #059669;">Petani: <b><?= $k['nama_petani'] ?></b></small>
                            <?php endif; ?>
                        </td>
                        <td class="text-right"><?= $k['jenis'] == 'masuk' ? 'Rp ' . number_format($k['nominal'], 0, ',', '.') : '-' ?></td>
                        <td class="text-right"><?= $k['jenis'] == 'keluar' ? 'Rp ' . number_format($k['nominal'], 0, ',', '.') : '-' ?></td>
                        <td class="text-right font-weight-bold">Rp <?= number_format($k['saldo_akhir'], 0, ',', '.') ?></td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>

    <div class="row mt-5 pt-4">
        <div class="col-6 text-center">
            <p>Mengetahui,<br><b>Ketua Kelompok Tani</b></p>
            <br><br><br><br>
            <p class="mb-0"><u><b>Bpk. Suwito</b></u></p>
            <p>-</p>
        </div>
        <div class="col-6 text-center">
            <p>Sari Rasa, <?= date('d F Y') ?><br><b>Bendahara / Admin</b></p>
            <br><br><br><br>
            <p class="mb-0"><u><b><?= session()->get('nama_lengkap') ?></b></u></p>
        </div>
    </div>

    <script>
        window.onload = function() {
            window.print();
        }
    </script>
</body>

</html>