diff --git a/db/migrations/20260306_002_surat_keluar_log.sql b/db/migrations/20260306_002_surat_keluar_log.sql new file mode 100644 index 0000000..e564571 --- /dev/null +++ b/db/migrations/20260306_002_surat_keluar_log.sql @@ -0,0 +1,14 @@ +-- Add status transition audit trail +CREATE TABLE IF NOT EXISTS surat_keluar_log ( + id INT AUTO_INCREMENT PRIMARY KEY, + surat_keluar_id INT NOT NULL, + old_status VARCHAR(20), + new_status VARCHAR(20), + user_id INT, + note TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (surat_keluar_id) REFERENCES surat_keluar(id) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Ensure enum has proper values if we needed to update (already has draft, review, approved, kirim) +-- Since they exist, we just add the logging table. diff --git a/surat_keluar.php b/surat_keluar.php index 3290df1..9dc6b94 100644 --- a/surat_keluar.php +++ b/surat_keluar.php @@ -78,6 +78,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $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)); @@ -103,7 +106,7 @@ render_header('Surat Keluar', 'keluar');