53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
// ========================================
|
|
// FILE: php/ambil_detail.php
|
|
// Mengambil detail lengkap data masyarakat + bantuan + BPJS
|
|
// ========================================
|
|
|
|
include 'koneksi.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
|
|
|
$id = intval($_GET['id'] ?? 0);
|
|
|
|
if ($id == 0) {
|
|
sendJSON('error', 'ID tidak ditemukan');
|
|
}
|
|
|
|
// AMBIL DATA MASYARAKAT
|
|
$query_masyarakat = "SELECT * FROM masyarakat_miskin WHERE id = $id";
|
|
$result_masyarakat = $conn->query($query_masyarakat);
|
|
|
|
if ($result_masyarakat->num_rows === 0) {
|
|
sendJSON('error', 'Data masyarakat tidak ditemukan');
|
|
}
|
|
|
|
$masyarakat = $result_masyarakat->fetch_assoc();
|
|
|
|
// AMBIL DATA BANTUAN
|
|
$query_bantuan = "SELECT * FROM bantuan_riwayat WHERE id_masyarakat = $id ORDER BY tanggal_bantuan DESC";
|
|
$result_bantuan = $conn->query($query_bantuan);
|
|
$bantuan_list = [];
|
|
while ($row = $result_bantuan->fetch_assoc()) {
|
|
$bantuan_list[] = $row;
|
|
}
|
|
|
|
// AMBIL DATA BPJS
|
|
$query_bpjs = "SELECT * FROM bpjs_record WHERE id_masyarakat = $id";
|
|
$result_bpjs = $conn->query($query_bpjs);
|
|
$bpjs = null;
|
|
if ($result_bpjs->num_rows > 0) {
|
|
$bpjs = $result_bpjs->fetch_assoc();
|
|
}
|
|
|
|
$data = [
|
|
'masyarakat' => $masyarakat,
|
|
'bantuan' => $bantuan_list,
|
|
'bpjs' => $bpjs
|
|
];
|
|
|
|
sendJSON('success', 'Detail data berhasil diambil', $data);
|
|
}
|
|
|
|
?>
|