248 lines
11 KiB
PHP
248 lines
11 KiB
PHP
<?php
|
|
require_once 'koneksi.php';
|
|
cekLogin();
|
|
|
|
// Hanya pemerintah & admin yang bisa input bantuan
|
|
// Operator/relawan diarahkan ke konfirmasi-bantuan.php
|
|
if (in_array($role ?? $_SESSION['role'], ['pengurus','relawan'])) {
|
|
header('Location: konfirmasi-bantuan.php');
|
|
exit;
|
|
}
|
|
|
|
$page = 'bantuan';
|
|
$pageTitle = 'Bantuan Tersalur';
|
|
$pageSubtitle = 'Input & Rekap Penyaluran';
|
|
|
|
$cari = bersih($_GET['cari'] ?? '', $conn);
|
|
$filterJenis = bersih($_GET['jenis'] ?? '', $conn);
|
|
$where = "WHERE 1=1";
|
|
if ($cari) $where .= " AND (rm.nama_kepala_keluarga LIKE '%$cari%' OR bt.jenis_bantuan LIKE '%$cari%')";
|
|
if ($filterJenis) $where .= " AND bt.jenis_bantuan LIKE '%$filterJenis%'";
|
|
|
|
$data = $conn->query("
|
|
SELECT bt.*, rm.nama_kepala_keluarga, rm.kelurahan,
|
|
ri.nama_ibadah, b.nama_bencana, u.nama_lengkap AS petugas_user
|
|
FROM bantuan_tersalur bt
|
|
LEFT JOIN rumah_miskin rm ON bt.warga_id = rm.id
|
|
LEFT JOIN rumah_ibadah ri ON bt.ibadah_id = ri.id
|
|
LEFT JOIN bencana b ON bt.bencana_id = b.id
|
|
LEFT JOIN users u ON bt.disalurkan_oleh = u.id
|
|
$where
|
|
ORDER BY bt.created_at DESC
|
|
");
|
|
$total = $data->num_rows;
|
|
|
|
// Untuk dropdown pilih warga
|
|
$semuaKpm = $conn->query("SELECT id, nama_kepala_keluarga, kelurahan FROM rumah_miskin ORDER BY nama_kepala_keluarga ASC");
|
|
|
|
include 'includes/sidebar.php';
|
|
?>
|
|
|
|
<style>
|
|
.custom-header-wrapper {
|
|
display: flex !important;
|
|
justify-content: space-between !important;
|
|
align-items: center !important;
|
|
margin-bottom: 25px !important;
|
|
background: #ffffff !important;
|
|
padding: 20px 24px !important;
|
|
border-radius: 12px !important;
|
|
box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
|
|
}
|
|
@media (max-width: 768px) {
|
|
.custom-header-wrapper {
|
|
flex-direction: column !important;
|
|
align-items: flex-start !important;
|
|
gap: 15px !important;
|
|
}
|
|
}
|
|
</style>
|
|
|
|
<div class="custom-header-wrapper">
|
|
<div>
|
|
<h2 style="margin: 0; font-size: 24px; color: #1e293b; font-weight: 700; display: flex; align-items: center; gap: 10px;">
|
|
<span>🎁</span> Bantuan Tersalur
|
|
</h2>
|
|
<p style="margin: 4px 0 0 0; color: #64748b; font-size: 14px;">
|
|
Total <?= $total ?> transaksi logistik & bantuan sosial tercatat
|
|
</p>
|
|
</div>
|
|
<button class="btn btn-success" onclick="openModal('modalTambah')" style="display: flex; align-items: center; gap: 8px; padding: 10px 18px; font-weight: 600; border-radius: 8px; cursor: pointer;">
|
|
<i class="fa fa-plus"></i> Input Bantuan Baru
|
|
</button>
|
|
</div>
|
|
|
|
<div style="background:var(--blue-lt);border:1px solid #93c5fd;border-radius:var(--radius);padding:11px 16px;margin-bottom:18px;font-size:13px;color:var(--blue)">
|
|
<i class="fa fa-info-circle"></i>
|
|
Bantuan yang diinput di sini akan otomatis diteruskan ke halaman <strong>Konfirmasi Bantuan</strong> pada akun Relawan / Pengurus untuk diverifikasi penerimaannya di lapangan.
|
|
</div>
|
|
|
|
<div class="card" style="margin-bottom:16px">
|
|
<div style="padding:14px 18px">
|
|
<form method="GET" style="display:flex;gap:10px;align-items:flex-end;flex-wrap:wrap">
|
|
<div style="flex:2;min-width:180px">
|
|
<label style="font-size:11px;font-weight:600;color:var(--gray);display:block;margin-bottom:4px;text-transform:uppercase;letter-spacing:.5px">Cari</label>
|
|
<input class="form-control" name="cari" value="<?= htmlspecialchars($cari) ?>" placeholder="Nama penerima atau jenis bantuan...">
|
|
</div>
|
|
<div style="flex:1;min-width:130px">
|
|
<label style="font-size:11px;font-weight:600;color:var(--gray);display:block;margin-bottom:4px;text-transform:uppercase;letter-spacing:.5px">Jenis</label>
|
|
<input class="form-control" name="jenis" value="<?= htmlspecialchars($filterJenis) ?>" placeholder="Sembako, BPNT...">
|
|
</div>
|
|
<div style="display:flex;gap:6px">
|
|
<button type="submit" class="btn btn-primary">Filter</button>
|
|
<a href="bantuan.php" class="btn btn-ghost"><i class="fa fa-rotate-left"></i></a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3>Riwayat Distribusi Bantuan</h3>
|
|
<span class="badge badge-gray"><?= $total ?> data</span>
|
|
</div>
|
|
<div class="tbl-wrap">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Penerima</th>
|
|
<th>Jenis Bantuan</th>
|
|
<th>Jumlah</th>
|
|
<th>Tanggal</th>
|
|
<th>Petugas Lapangan</th>
|
|
<th>Status Konfirmasi</th>
|
|
<th>Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if ($total === 0): ?>
|
|
<tr><td colspan="8" style="text-align:center;padding:36px;color:var(--gray)">Belum ada data bantuan</td></tr>
|
|
<?php else: $no=1; while ($r = $data->fetch_assoc()):
|
|
$konfStatus = $r['status_konfirmasi'] ?? 'Menunggu';
|
|
$konfBadge = ['Menunggu'=>'badge-yellow','Dikonfirmasi'=>'badge-green','Ditolak'=>'badge-red'][$konfStatus] ?? 'badge-gray';
|
|
?>
|
|
<tr>
|
|
<td style="color:var(--gray);font-size:12px"><?= $no++ ?></td>
|
|
<td>
|
|
<div style="font-weight:600"><?= htmlspecialchars($r['nama_kepala_keluarga'] ?? '-') ?></div>
|
|
<div style="font-size:11px;color:var(--gray)"><?= htmlspecialchars($r['kelurahan'] ?? '') ?></div>
|
|
<?php if ($r['nama_bencana']): ?>
|
|
<span class="badge badge-red" style="font-size:9px;margin-top:2px"><?= htmlspecialchars($r['nama_bencana']) ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><span class="badge badge-blue"><?= htmlspecialchars($r['jenis_bantuan']) ?></span></td>
|
|
<td style="font-weight:600;font-size:13px"><?= htmlspecialchars($r['jumlah'] ?? '-') ?></td>
|
|
<td style="font-size:12px;color:var(--gray)"><?= date('d M Y', strtotime($r['tanggal'])) ?></td>
|
|
<td style="font-size:12px"><?= htmlspecialchars($r['petugas'] ?? $r['petugas_user'] ?? '-') ?></td>
|
|
<td><span class="badge <?= $konfBadge ?>"><?= $konfStatus ?></span></td>
|
|
<td>
|
|
<?php if ($_SESSION['role'] === 'admin'): ?>
|
|
<button class="btn btn-ghost btn-sm" onclick="hapusBantuan(<?= $r['id'] ?>)" style="color:var(--red)" title="Hapus Riwayat">
|
|
<i class="fa fa-trash" style="font-size:11px"></i>
|
|
</button>
|
|
<?php else: ?>
|
|
<span style="font-size:11px; color:#94a3b8">-</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endwhile; endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modal-overlay" id="modalTambah">
|
|
<div class="modal-box">
|
|
<div class="modal-head">
|
|
<h3><i class="fa fa-hand-holding-heart" style="color:#16a34a"></i> Catat Penyaluran Bantuan</h3>
|
|
<button class="btn-close" onclick="closeModal('modalTambah')">✕</button>
|
|
</div>
|
|
<form method="POST" action="proses.php">
|
|
<input type="hidden" name="aksi" value="simpan_bantuan">
|
|
<div class="modal-body">
|
|
<div class="form-group">
|
|
<label>Nama Penerima (KPM) *</label>
|
|
<select class="form-control" name="warga_id" required>
|
|
<option value="">-- Pilih KPM --</option>
|
|
<?php $semuaKpm->data_seek(0); while ($k = $semuaKpm->fetch_assoc()): ?>
|
|
<option value="<?= $k['id'] ?>">
|
|
<?= htmlspecialchars($k['nama_kepala_keluarga']) ?>
|
|
<?= $k['kelurahan'] ? '('.$k['kelurahan'].')' : '' ?>
|
|
</option>
|
|
<?php endwhile; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Jenis Bantuan *</label>
|
|
<input class="form-control" name="jenis_bantuan" required placeholder="cth: Sembako, BPNT, Zakat Mal...">
|
|
</div>
|
|
<div class="form-grid-2">
|
|
<div class="form-group">
|
|
<label>Jumlah / Nominal</label>
|
|
<input class="form-control" name="jumlah" placeholder="cth: 50kg beras / Rp500.000">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Tanggal Penyaluran *</label>
|
|
<input class="form-control" type="date" name="tanggal" required value="<?= date('Y-m-d') ?>">
|
|
</div>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Nama Petugas</label>
|
|
<input class="form-control" name="petugas" placeholder="Nama petugas / instansi penyalur">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Keterangan Tambahan</label>
|
|
<textarea class="form-control" name="keterangan" rows="2" placeholder="Catatan opsional..."></textarea>
|
|
</div>
|
|
<div style="background:#f0fdf4;border:1px solid #86efac;border-radius:var(--radius-sm);padding:9px 12px;font-size:12px;color:var(--green)">
|
|
Setelah disimpan, operator atau relawan di lapangan dapat melihat riwayat dan memvalidasi distribusi item fisik ini.
|
|
</div>
|
|
</div>
|
|
<div class="modal-foot">
|
|
<button type="button" class="btn btn-ghost" onclick="closeModal('modalTambah')">Batal</button>
|
|
<button type="submit" class="btn btn-success"><i class="fa fa-save"></i> Simpan Bantuan</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function openModal(id) {
|
|
const modal = document.getElementById(id);
|
|
if(modal) modal.style.display = 'flex';
|
|
}
|
|
|
|
function closeModal(id) {
|
|
const modal = document.getElementById(id);
|
|
if(modal) modal.style.display = 'none';
|
|
}
|
|
|
|
// Fungsi tombol hapus bantuan khusus administrator
|
|
function hapusBantuan(id) {
|
|
if (confirm('Apakah Anda yakin ingin menghapus data rekam jejak penyaluran bantuan ini?')) {
|
|
// Membuat form virtual di memori browser
|
|
const form = document.createElement('form');
|
|
form.method = 'POST';
|
|
form.action = 'proses.php';
|
|
|
|
form.innerHTML = `
|
|
<input type="hidden" name="aksi" value="hapus_bantuan">
|
|
<input type="hidden" name="id" value="${id}">
|
|
`;
|
|
document.body.appendChild(form);
|
|
form.submit();
|
|
}
|
|
}
|
|
|
|
// Menutup modal otomatis jika area luar modal diklik
|
|
window.onclick = function(event) {
|
|
if (event.target.classList.contains('modal-overlay')) {
|
|
closeModal(event.target.id);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<?php
|
|
include 'includes/footer.php';
|
|
?>
|