[], 'jiwa'=>0];
foreach ($allKemiskinan as $kk) {
$kkCoverage[$kk['id']] = [];
foreach ($allMasjid as $m) {
$dist = haversine($kk['lat'], $kk['lng'], $m['lat'], $m['lng']);
if ($dist <= (int)$m['radius_m']) {
$kkCoverage[$kk['id']][] = $m;
$masjidCoverage[$m['id']]['kk'][] = $kk;
$masjidCoverage[$m['id']]['jiwa'] += (int)$kk['jumlah_kk'];
}
}
}
$totalKK = count($allKemiskinan);
$totalJiwa = array_sum(array_column($allKemiskinan, 'jumlah_kk'));
$countT = 0; $jiwaT = 0;
foreach ($allKemiskinan as $kk) {
if (count($kkCoverage[$kk['id']]) > 0) { $countT++; $jiwaT += (int)$kk['jumlah_kk']; }
}
$countTT = $totalKK - $countT; $jiwaTT = $totalJiwa - $jiwaT;
$pct = $totalKK > 0 ? number_format($countT / $totalKK * 100, 1) : '0.0';
$pctTT = $totalKK > 0 ? number_format($countTT / $totalKK * 100, 1) : '0.0';
$bulan = ['','Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember'];
$tgl = date('j') . ' ' . $bulan[(int)date('n')] . ' ' . date('Y');
$rowsMasjid = '';
foreach ($allMasjid as $i => $m) {
$cov = $masjidCoverage[$m['id']];
$bg = ($i % 2 === 0) ? '#ffffff' : '#f9fafb';
$rowsMasjid .= "
| " . ($i+1) . " |
{$m['nama_masjid']} |
{$m['radius_m']} |
" . count($cov['kk']) . " |
{$cov['jiwa']} |
";
}
if (!$rowsMasjid) $rowsMasjid = "| Belum ada data masjid. |
";
$rowsKK = '';
foreach ($allKemiskinan as $i => $kk) {
$covers = $kkCoverage[$kk['id']];
$covered = count($covers) > 0;
$minDist = '-';
if (count($allMasjid) > 0) {
$dists = array_map(fn($m) => haversine($kk['lat'], $kk['lng'], $m['lat'], $m['lng']), $allMasjid);
$minDist = min($dists);
}
$statusTxt = $covered ? 'Terjangkau' : 'Tidak Terjangkau';
$masjidNames = $covered ? implode(', ', array_column($covers, 'nama_masjid')) : '-';
$bg = ($i % 2 === 0) ? '#ffffff' : '#f9fafb';
$pkhTxt = $kk['pkh'] ? '✓' : '-';
$bpntTxt = $kk['bpnt'] ? '✓' : '-';
$bltTxt = $kk['blt'] ? '✓' : '-';
$rowsKK .= "
| " . ($i+1) . " |
{$kk['nama_kk']} |
{$kk['jumlah_kk']} |
{$kk['alamat']} |
{$pkhTxt} |
{$bpntTxt} |
{$bltTxt} |
{$statusTxt} |
{$masjidNames} |
{$minDist} |
";
}
if (!$rowsKK) $rowsKK = "| Belum ada data kemiskinan. |
";
$html = <<
body { font-family: sans-serif; font-size: 11px; color: #222; }
h1 { font-size: 15px; text-align: center; margin-bottom: 2px; color: #1e3a5f; }
.subtitle { text-align: center; font-size: 10px; color: #555; margin-bottom: 14px; }
.section { font-size: 12px; font-weight: bold; color: #1e3a5f; border-bottom: 2px solid #1e3a5f; padding-bottom: 3px; margin: 12px 0 7px; }
table { width: 100%; border-collapse: collapse; font-size: 10px; }
th { background: #1e3a5f; color: white; padding: 5px; text-align: center; }
td { padding: 4px 5px; border-bottom: 1px solid #e5e7eb; vertical-align: top; }
.sg { width: 100%; border-collapse: collapse; margin-bottom: 4px; }
.sc { width: 25%; padding: 7px; text-align: center; border: 1px solid #ddd; }
.sn { font-size: 20px; font-weight: bold; }
.sl { font-size: 9px; color: #666; margin-top: 1px; }
.g { color: #1a7a3e; } .r { color: #c0392b; }
Laporan Analisis Kemiskinan & Jangkauan Masjid
Sistem WebGIS SIG B — Universitas Tanjungpura | Dicetak: {$tgl}
Ringkasan Statistik
{$totalKK} Total KK Miskin |
{$totalJiwa} Total Jiwa |
{$countT} ({$pct}%) KK Terjangkau • {$jiwaT} jiwa |
{$countTT} ({$pctTT}%) KK Tidak Terjangkau • {$jiwaTT} jiwa |
Statistik per Masjid
| No | Nama Masjid | Radius (m) | KK Terjangkau | Jiwa Terjangkau |
{$rowsMasjid}
Daftar KK Miskin & Status Jangkauan
| No | Nama KK | Jiwa |
Alamat | PKH | BPNT | BLT |
Status | Dijangkau Masjid | Jarak Terdekat (m) |
{$rowsKK}
HTML;
try {
$mpdf = new \Mpdf\Mpdf(['mode'=>'utf-8','format'=>'A4-L','margin_top'=>14,'margin_bottom'=>14,'margin_left'=>12,'margin_right'=>12]);
$mpdf->SetTitle('Laporan Kemiskinan & Jangkauan Masjid');
$mpdf->WriteHTML($html);
$mpdf->Output('laporan_kemiskinan_' . date('Y-m-d') . '.pdf', 'D');
} catch (\Mpdf\MpdfException $e) {
http_response_code(500);
echo 'Gagal membuat PDF: ' . htmlspecialchars($e->getMessage()) . '
';
}