<?php
require_once __DIR__ . '/config/config.php';

$id = $_GET['id'] ?? 0;

$stmt = $conn->prepare("
    SELECT 
        p.*,
        s.nama_sekolah,
        s.npsn,
        s.kecamatan,
        s.kepala_sekolah,
        s.nip_kepsek,
        s.bendahara,
        s.nip_bendahara
    FROM penganggaran p
    LEFT JOIN sekolah s ON p.npsn = s.npsn
    WHERE p.id_anggaran = ?
");
$stmt->bind_param("i", $id);
$stmt->execute();
$d = $stmt->get_result()->fetch_assoc();

if(!$d) die("Data tidak ditemukan");

// HITUNG
$total = $d['total'];
$tahap = $total / 2;
function tgl_indo($tanggal){
    $bulan = [
        1=>'Januari','Februari','Maret','April','Mei','Juni',
        'Juli','Agustus','September','Oktober','November','Desember'
    ];
    $split = explode('-', $tanggal);
    return $split[2].' '.$bulan[(int)$split[1]].' '.$split[0];
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cetak Penganggaran</title>

<style>
body{
    font-family: Arial;
    font-size: 12px;
}

.container{
    width: 700px;
    margin: auto;
}

.judul{
    text-align:center;
    font-weight:bold;
    margin-bottom:20px;
}

table{
    width:100%;
    border-collapse: collapse;
}

td, th{
    border:1px solid #000;
    padding:6px;
}

.no-border td{
    border:none;
    padding:3px;
}

.ttd{
    margin-top:50px;
    width:100%;
}

.ttd td{
    border:none;
    text-align:center;
}
</style>
</head>

<body onload="window.print()">

<div class="container">

<div class="judul">
RINCIAN ANGGARAN BELANJA BOS TAHUN <?= $d['tahun'] ?>
</div>

<table class="no-border">
<tr><td width="200">NAMA LEMBAGA</td><td>: <?= $d['nama_sekolah'] ?></td></tr>
<tr><td>NPSN</td><td>: <?= $d['npsn'] ?></td></tr>
<tr><td>KECAMATAN</td><td>: <?= $d['kecamatan'] ?? '-' ?></td></tr>
<tr><td>PAGU 1 TAHUN</td><td>: <?= number_format($total,0,',','.') ?></td></tr>
<tr><td>PENERIMAAN TAHAP 1</td><td>: <?= number_format($tahap,0,',','.') ?></td></tr>
<tr><td>PENERIMAAN TAHAP 2</td><td>: <?= number_format($tahap,0,',','.') ?></td></tr>
</table>

<br>

<b>BOS REGULER</b>

<table>
<tr>
    <th width="40">No</th>
    <th>Uraian</th>
    <th width="150">Jumlah</th>
</tr>

<tr>
    <td align="center">1</td>
    <td>BARJAS</td>
    <td align="right"><?= number_format($d['barjas'],0,',','.') ?></td>
</tr>

<tr>
    <td align="center">2</td>
    <td>BELANJA PEGAWAI</td>
    <td align="right"><?= number_format($d['habis_pakai'],0,',','.') ?></td>
</tr>

<tr>
    <td align="center">3</td>
    <td>BM MESIN</td>
    <td align="right"><?= number_format($d['modal_mesin'],0,',','.') ?></td>
</tr>

<tr>
    <td align="center">4</td>
    <td>BM ASET LAINNYA</td>
    <td align="right"><?= number_format($d['modal_lainnya'],0,',','.') ?></td>
</tr>

<tr>
    <td></td>
    <td><b>Jumlah</b></td>
    <td align="right"><b><?= number_format($total,0,',','.') ?></b></td>
</tr>
</table>

<table class="ttd">
<tr>
    <td>
        Mengetahui,<br>
        Kepala Sekolah
        <br><br><br><br>

        <b><?= strtoupper($d['kepala_sekolah'] ?? '-') ?></b><br>
        NIP. <?= $d['nip_kepsek'] ?? '-' ?>
    </td>

    <td>
        <?= $d['kecamatan'] ?? '-' ?>, <?= tgl_indo(date('Y-m-d')) ?><br>
        Bendahara Sekolah
        <br><br><br><br>

        <b><?= strtoupper($d['bendahara'] ?? '-') ?></b><br>
        NIP. <?= $d['nip_bendahara'] ?? '-' ?>
    </td>
</tr>
</table>

</div>

</body>
</html>