68 lines
2.9 KiB
PHP
68 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* api/laporan_bantuan.php — Rekapitulasi penerima bantuan per jenis (KF-30).
|
|
* ?format=print (default) | json
|
|
*/
|
|
require_once __DIR__ . '/../config/db.php';
|
|
require_once __DIR__ . '/../config/auth_check.php';
|
|
requireAnyRole(['operator', 'pimpinan']);
|
|
$pdo = Database::getConnection();
|
|
$format = $_GET['format'] ?? 'print';
|
|
|
|
$rows = $pdo->query("
|
|
SELECT jb.kode, jb.nama AS jenis_nama, w.nama_kk, w.nik_kk,
|
|
bs.tgl_mulai, bs.tgl_berakhir, w.status_verifikasi,
|
|
(SELECT wl.nama FROM wilayah wl WHERE ST_Contains(wl.geom, w.geom) LIMIT 1) AS kelurahan
|
|
FROM bantuan_sosial bs
|
|
JOIN warga_miskin w ON w.id = bs.warga_id
|
|
JOIN jenis_bantuan jb ON jb.id = bs.jenis_bantuan_id
|
|
WHERE bs.is_aktif = 1
|
|
ORDER BY jb.id, w.nama_kk
|
|
")->fetchAll();
|
|
|
|
// kelompokkan per jenis
|
|
$grup = [];
|
|
foreach ($rows as $r) $grup[$r['kode'] . ' — ' . $r['jenis_nama']][] = $r;
|
|
|
|
if ($format === 'json') {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['status' => 'success', 'data' => ['total' => count($rows), 'jenis' => array_map('count', $grup)]]);
|
|
exit;
|
|
}
|
|
?>
|
|
<!DOCTYPE html><html lang="id"><head><meta charset="UTF-8">
|
|
<title>Rekap Penerima Bantuan</title>
|
|
<style>
|
|
body{font-family:Arial,sans-serif;margin:28px;color:#111;}
|
|
h2{margin:0 0 2px;} .sub{color:#666;font-size:0.85rem;margin-bottom:16px;}
|
|
h3{margin:18px 0 6px;background:#2563EB;color:#fff;padding:6px 10px;border-radius:6px;font-size:0.95rem;}
|
|
table{width:100%;border-collapse:collapse;font-size:0.78rem;margin-bottom:8px;}
|
|
th,td{border:1px solid #ccc;padding:5px 7px;text-align:left;} th{background:#f1f5f9;}
|
|
button{padding:8px 14px;background:#2563EB;color:#fff;border:none;border-radius:6px;cursor:pointer;margin-bottom:14px;}
|
|
@media print{button{display:none;}}
|
|
</style></head><body>
|
|
<button onclick="window.print()">🖨️ Cetak / Simpan PDF</button>
|
|
<h2>Rekapitulasi Penerima Bantuan Sosial</h2>
|
|
<div class="sub">WebGIS Pemetaan Kemiskinan · dicetak <?= date('d M Y H:i') ?> · total <?= count($rows) ?> penerima aktif</div>
|
|
<?php if (!$grup): ?><p>Belum ada penerima bantuan aktif.</p><?php endif; ?>
|
|
<?php foreach ($grup as $judul => $list): ?>
|
|
<h3><?= htmlspecialchars($judul) ?> (<?= count($list) ?>)</h3>
|
|
<table>
|
|
<thead><tr><th>#</th><th>Nama KK</th><th>NIK</th><th>Kelurahan</th><th>Mulai</th><th>Berakhir</th><th>Verifikasi</th></tr></thead>
|
|
<tbody>
|
|
<?php foreach ($list as $i => $r): ?>
|
|
<tr>
|
|
<td><?= $i+1 ?></td>
|
|
<td><?= htmlspecialchars($r['nama_kk']) ?></td>
|
|
<td><?= htmlspecialchars($r['nik_kk'] ?: '-') ?></td>
|
|
<td><?= htmlspecialchars($r['kelurahan'] ?: '-') ?></td>
|
|
<td><?= htmlspecialchars($r['tgl_mulai'] ?: '-') ?></td>
|
|
<td><?= htmlspecialchars($r['tgl_berakhir'] ?: '-') ?></td>
|
|
<td><?= htmlspecialchars($r['status_verifikasi']) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endforeach; ?>
|
|
</body></html>
|