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

<head>
    <meta charset="UTF-8">
    <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;
        }

        .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: 6px;
            font-size: 13px;
        }

        .table-print th {
            background-color: #f2f2f2 !important;
            text-align: center;
        }
        .text-right { text-align: right; }
        .text-center { text-align: center; }
    </style>
</head>

<body>

    <div class="kop-surat">
        <h2 class="mb-0"><b>KELOMPOK TANI SARI RASA</b></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 class="mb-1"><b>LAPORAN REALISASI PENEBUSAN PUPUK BERSUBSIDI</b></h4>
        <h5><b>(STANDAR e-RDKK)</b></h5>
        <p class="text-uppercase font-weight-bold mt-2" style="letter-spacing: 1px;"><?= $periodeText ?></p>
    </div>

    <table class="table table-print w-100">
        <thead>
            <tr>
                <th width="5%">No</th>
                <th width="15%">No. Invoice</th>
                <th width="15%">Waktu Tebus</th>
                <th width="15%">NIK Petani</th>
                <th>Nama Petani</th>
                <th width="15%">Jenis Pupuk</th>
                <th width="12%">Jumlah (Kg)</th>
            </tr>
        </thead>
        <tbody>
            <?php 
            $no = 1;
            $total_kg = 0;
            foreach ($alokasi as $a):
                $total_kg += $a['jumlah_beli'];
            ?>
                <tr>
                    <td class="text-center"><?= $no++ ?></td>
                    <td class="text-center"><b><?= $a['no_invoice'] ?></b></td>
                    <td class="text-center"><?= date('d-m-Y H:i', strtotime($a['tanggal_transaksi'])) ?></td>
                    <td><?= $a['nik'] ?></td>
                    <td><?= $a['nama_petani'] ?></td>
                    <td class="text-center"><span class="badge badge-light border border-dark"><?= $a['nama_pupuk'] ?></span></td>
                    <td class="text-right"><?= number_format($a['jumlah_beli'], 1, ',', '.') ?> Kg</td>
                </tr>
            <?php endforeach; ?>
            
            <?php if(empty($alokasi)): ?>
                <tr>
                    <td colspan="7" class="text-center text-muted py-4">Tidak ada rekaman transaksi penebusan pupuk pada periode ini.</td>
                </tr>
            <?php else: ?>
                <tr style="background-color: #f2f2f2 !important; font-weight: bold;">
                    <td colspan="6" class="text-center">TOTAL PUPUK DISALURKAN</td>
                    <td class="text-right"><?= number_format($total_kg, 1, ',', '.') ?> Kg</td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>

    <div class="row mt-5">
        <div class="col-7"></div>
        <div class="col-5 text-center">
            <p>Sari Rasa, <?= date('d F Y') ?><br><b>Ketua Kelompok Tani,</b></p>
            <br><br><br>
            <p><u><b>Bpk. Suwito</b></u></p>
        </div>
    </div>

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

</html>