104 lines
3.7 KiB
PHP
104 lines
3.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/includes/db_init.php';
|
|
require_once __DIR__ . '/includes/layout.php';
|
|
require_once __DIR__ . '/includes/helpers.php';
|
|
|
|
ensure_tables();
|
|
$pdo = db();
|
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_status'])) {
|
|
$newStatus = $_POST['status'];
|
|
$note = trim($_POST['note'] ?? '');
|
|
|
|
$pdo->beginTransaction();
|
|
$stmt = $pdo->prepare("SELECT status FROM surat_keluar WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$oldStatus = $stmt->fetchColumn();
|
|
|
|
$stmt = $pdo->prepare("UPDATE surat_keluar SET status = ? WHERE id = ?");
|
|
$stmt->execute([$newStatus, $id]);
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO surat_keluar_log (surat_keluar_id, old_status, new_status, note) VALUES (?, ?, ?, ?)");
|
|
$stmt->execute([$id, $oldStatus, $newStatus, $note]);
|
|
$pdo->commit();
|
|
|
|
header('Location: /surat_keluar_view.php?id=' . $id . '&success=1');
|
|
exit;
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM surat_keluar WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$row = $stmt->fetch();
|
|
|
|
$logs = $pdo->prepare("SELECT * FROM surat_keluar_log WHERE surat_keluar_id = ? ORDER BY created_at DESC");
|
|
$logs->execute([$id]);
|
|
$logs = $logs->fetchAll();
|
|
|
|
render_header('Detail Surat Keluar', 'keluar');
|
|
?>
|
|
|
|
<div class="row g-3">
|
|
<div class="col-lg-8">
|
|
<div class="card mb-3">
|
|
<div class="card-header">Detail Surat Keluar</div>
|
|
<div class="card-body">
|
|
<?php if (!$row): ?>
|
|
<div class="empty-state">Data surat keluar tidak ditemukan.</div>
|
|
<?php else: ?>
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<div class="text-muted small">Nomor Surat</div>
|
|
<div class="fw-semibold"><?= h($row['nomor_surat']) ?></div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="text-muted small">Status</div>
|
|
<span class="<?= h(status_badge($row['status'], 'keluar')) ?>"><?= h($row['status']) ?></span>
|
|
</div>
|
|
<div class="col-12">
|
|
<div class="text-muted small">Perihal</div>
|
|
<div class="fw-semibold"><?= h($row['perihal']) ?></div>
|
|
</div>
|
|
<!-- ... -->
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">Riwayat Status</div>
|
|
<div class="card-body">
|
|
<ul class="list-group list-group-flush">
|
|
<?php foreach($logs as $log): ?>
|
|
<li class="list-group-item">
|
|
<small class="text-muted"><?= h($log['created_at']) ?></small><br>
|
|
Status: <strong><?= h($log['old_status'] ?? 'N/A') ?></strong> -> <strong><?= h($log['new_status']) ?></strong>
|
|
<?php if($log['note']): ?> <br><em><?= h($log['note']) ?></em> <?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-4">
|
|
<div class="card mb-3">
|
|
<div class="card-header">Update Status</div>
|
|
<div class="card-body">
|
|
<form method="post">
|
|
<select name="status" class="form-select mb-2">
|
|
<?php foreach (['draft' => 'Draft', 'review' => 'Review', 'approved' => 'Approved', 'kirim' => 'Kirim'] as $val => $label): ?>
|
|
<option value="<?= h($val) ?>" <?= ($row['status'] === $val ? 'selected' : '') ?>><?= h($label) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<textarea name="note" class="form-control mb-2" placeholder="Catatan"></textarea>
|
|
<button type="submit" name="update_status" class="btn btn-primary w-100">Simpan Status</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php render_footer(); ?>
|