beginTransaction(); $stmt = $pdo->prepare("SELECT MAX(urut) as max_urut FROM surat_keluar WHERE kode_surat = ? AND bulan = ? AND tahun = ?"); $stmt->execute([$kode, $bulan, $tahun]); $maxUrut = (int)($stmt->fetch()['max_urut'] ?? 0); $nextUrut = $maxUrut + 1; $nomor = format_nomor($kode, $nextUrut, $bulan, $tahun); $insert = $pdo->prepare("INSERT INTO surat_keluar (nomor_surat, kode_surat, urut, bulan, tahun, tanggal_surat, tujuan, perihal, departemen_pengirim, status, file_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $insert->execute([ $nomor, $kode, $nextUrut, $bulan, $tahun, $tanggal, $tujuan, $perihal, $departemen, $status, $filePath ]); $suratId = $pdo->lastInsertId(); $pdo->prepare("INSERT INTO surat_keluar_log (surat_keluar_id, new_status, note) VALUES (?, ?, ?)") ->execute([$suratId, $status, 'Surat dibuat.']); $pdo->commit(); header('Location: /surat_keluar.php?success=1&nomor=' . urlencode($nomor)); exit; } } $search = trim($_GET['q'] ?? ''); $where = ''; $params = []; if ($search !== '') { $where = "WHERE nomor_surat LIKE ? OR perihal LIKE ? OR tujuan LIKE ? OR departemen_pengirim LIKE ?"; $like = '%' . $search . '%'; $params = [$like, $like, $like, $like]; } $stmt = $pdo->prepare("SELECT id, nomor_surat, tanggal_surat, tujuan, perihal, departemen_pengirim, status FROM surat_keluar $where ORDER BY tanggal_surat DESC, id DESC LIMIT 50"); $stmt->execute($params); $rows = $stmt->fetchAll(); render_header('Surat Keluar', 'keluar'); ?>
| Tanggal | Nomor | Tujuan | Perihal | Status |
|---|---|---|---|---|
| = h($row['tanggal_surat']) ?> | = h($row['nomor_surat']) ?> | = h($row['tujuan']) ?> | = h($row['perihal']) ?> | = h($row['status']) ?> |