Modul Rasio Keuangan 00 8
HTML; } function foot_ui() { echo '
'; } /* ===== Routing ===== */ $action = $_GET['action'] ?? 'list'; /* ===== Daftar Field Rasio Keuangan 00 8 ===== */ $fields = [ 'sandi_pos', 'nilai_rasio', 'keterangan', 'prosen_rasio', 'flag_detail', 'urut', 'id' ]; /* ===== Delete ===== */ if ($action === 'delete') { $id = (int)($_GET['id'] ?? 0); if ($id > 0) { @pg_query_params($dbconn, "DELETE FROM public.tbl_rasiokeuangan_00_8 WHERE id=$1", [$id]); } header("Location: ?"); exit; } /* ===== Save (Create/Update) ===== */ if ($action === 'save' && $_SERVER['REQUEST_METHOD'] === 'POST') { $id = (int)($_POST['id'] ?? 0); $p = []; foreach ($fields as $f) { $p[$f] = isset($_POST[$f]) ? trim((string)$_POST[$f]) : null; } // Handle tipe data khusus foreach (['nilai_rasio','prosen_rasio','urut'] as $nf) { $p[$nf] = ($p[$nf] === '' ? null : $p[$nf]); } if ($id > 0) { // UPDATE $set = []; foreach ($fields as $i => $f) { $set[] = "$f=$".($i+1); } $sql = "UPDATE public.tbl_rasiokeuangan_00_8 SET " . implode(', ', $set) . " WHERE id=$" . (count($fields)+1); $params = array_merge(array_values($p), [$id]); } else { // INSERT $cols = implode(', ', $fields); $vals = []; for ($i=1; $i<=count($fields); $i++) $vals[] = '$'.$i; $sql = "INSERT INTO public.tbl_rasiokeuangan_00_8($cols) VALUES (" . implode(', ', $vals) . ")"; $params = array_values($p); } $ok = @pg_query_params($dbconn, $sql, $params); if ($ok) { header('Location: ?'); exit; } head_ui('Error'); echo '
Gagal simpan: ' . h(pg_last_error($dbconn)) . '

Kembali
'; foot_ui(); exit; } /* ===== Form ===== */ if ($action === 'form') { $id = (int)($_GET['id'] ?? 0); $editing = $id > 0; $defaults = []; foreach ($fields as $f) $defaults[$f] = ''; $data = $defaults; if ($editing) { $res = pg_query_params($dbconn, "SELECT * FROM public.tbl_rasiokeuangan_00_8 WHERE id=$1", [$id]); if ($row = pg_fetch_assoc($res)) { $data = array_merge($data, $row); } } head_ui(($editing ? 'Ubah' : 'Tambah') . ' Data'); echo '

' . ($editing ? 'Ubah' : 'Tambah') . ' Data Rasio Keuangan

'; echo '
'; if ($editing) echo ''; foreach ($fields as $f) { $label = strtoupper(str_replace('_', ' ', $f)); $type = (in_array($f, ['nilai_rasio','prosen_rasio','urut']) ? 'number' : 'text'); $step = ($type === 'number') ? ' step="any"' : ''; echo ''; } echo '
' . '' . 'Batal
'; foot_ui(); exit; } /* ===== List (default) ===== */ $q = trim($_GET['q'] ?? ''); $page = max(1, (int)($_GET['page'] ?? 1)); $perpage = (int)($_GET['perpage'] ?? 25); if (!in_array($perpage, [10, 25, 50, 100], true)) { $perpage = 25; } $offset = ($page - 1) * $perpage; $where = ''; $params = []; if ($q !== '') { $where = "WHERE (sandi_pos ILIKE $1 OR keterangan ILIKE $1)"; $params[] = "%{$q}%"; } $resCount = $where ? pg_query_params($dbconn, "SELECT COUNT(*) FROM public.tbl_rasiokeuangan_00_8 {$where}", $params) : pg_query($dbconn, "SELECT COUNT(*) FROM public.tbl_rasiokeuangan_00_8"); $total = (int)pg_fetch_result($resCount, 0, 0); $total_pages = max(1, (int)ceil($total / $perpage)); $sql = " SELECT id, sandi_pos, nilai_rasio, keterangan, prosen_rasio, flag_detail, urut FROM public.tbl_rasiokeuangan_00_8 " . ($where ?: '') . " ORDER BY id ASC LIMIT $perpage OFFSET $offset "; $res = $where ? pg_query_params($dbconn, $sql, $params) : pg_query($dbconn, $sql); head_ui('Daftar Rasio Keuangan 00 8'); ?>
Reset
Total: data
Aksi ID Sandi Pos Nilai Rasio Keterangan Prosen Rasio Flag Detail Urut
Ubah Hapus
$q, 'perpage' => $perpage]); if ($page > 1) echo '« Prev'; echo 'Hal ' . h($page) . ' / ' . h($total_pages) . ''; if ($page < $total_pages) echo 'Next »'; ?>