Files
2026-09-16 23:20:08 +07:00

133 lines
8.8 KiB
PHP

<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0 text-gray-800">พิจารณาอนุมัติ</h1>
</div>
<div class="card shadow border-0 rounded-4 mb-4">
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover align-middle" id="approvalsTable">
<thead class="table-light">
<tr>
<th>วันที่ขอ</th>
<th>เลขที่หนังสือ</th>
<th>เรื่อง</th>
<th>สถานที่</th>
<th>วันที่เดินทาง</th>
<th>สถานะ</th>
<th>จัดการ</th>
</tr>
</thead>
<tbody>
<?php if (!empty($approvals)): ?>
<?php foreach ($approvals as $row): ?>
<tr>
<td><?= date('d/m/Y', strtotime($row['created_at'])) ?></td>
<td><?= \App\Core\Security::escape($row['doc_number'] ?: '-') ?></td>
<td>
<strong><?= \App\Core\Security::escape($row['title']) ?></strong>
<div class="small text-muted text-truncate" style="max-width: 250px;">
<?= \App\Core\Security::escape($row['objective']) ?>
</div>
</td>
<td><?= \App\Core\Security::escape($row['location']) ?></td>
<td>
<?= date('d/m/Y', strtotime($row['start_date'])) ?>
- <?= date('d/m/Y', strtotime($row['end_date'])) ?>
</td>
<td>
<?php if ($row['req_status'] === 'Pending Cancel'): ?>
<span class="badge bg-danger"><i class="fa-solid fa-ban me-1"></i> ขอยกเลิก</span>
<?php elseif ($row['req_status'] === 'Pending Revise'): ?>
<span class="badge bg-warning text-dark"><i class="fa-solid fa-pen me-1"></i> ขอเปลี่ยนแปลง</span>
<?php else: ?>
<span class="badge bg-info text-dark"><i class="fa-solid fa-clock me-1"></i> รอพิจารณา</span>
<?php endif; ?>
</td>
<td>
<div class="btn-group btn-group-sm">
<button class="btn btn-outline-secondary" title="พิมพ์ได้เมื่ออนุมัติแล้วเท่านั้น" disabled>
<i class="fa-solid fa-print"></i>
</button>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#approveModal<?= $row['approval_id'] ?>">
พิจารณา
</button>
</div>
</td>
</tr>
<!-- Modal for each approval -->
<div class="modal fade" id="approveModal<?= $row['approval_id'] ?>" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form action="<?= BASE_URL ?>/trip/approvals/process" method="POST">
<input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
<input type="hidden" name="approval_id" value="<?= $row['approval_id'] ?>">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title">พิจารณาคำขอเดินทาง</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p><strong>เรื่อง:</strong> <?= \App\Core\Security::escape($row['title']) ?></p>
<p><strong>สถานที่:</strong> <?= \App\Core\Security::escape($row['location']) ?></p>
<p><strong>งบประมาณ:</strong> <?= number_format($row['budget'], 2) ?> บาท</p>
<?php if (!empty($row['doc_link'])): ?>
<p>
<a href="<?= \App\Core\Security::escape($row['doc_link']) ?>" target="_blank" class="btn btn-sm btn-outline-primary">
<i class="fa-solid fa-arrow-up-right-from-square me-1"></i> เปิดไฟล์เอกสาร
</a>
</p>
<?php endif; ?>
<?php if ($row['req_status'] === 'Pending Cancel'): ?>
<div class="alert alert-danger mt-3 mb-0">
<strong>เหตุผลที่ขอยกเลิก:</strong><br>
<?= nl2br(\App\Core\Security::escape($row['cancel_reason'])) ?>
</div>
<?php elseif ($row['req_status'] === 'Pending Revise'): ?>
<div class="alert alert-warning text-dark mt-3 mb-0">
<strong>รายละเอียดที่ขอเปลี่ยนแปลง:</strong><br>
<?= nl2br(\App\Core\Security::escape($row['revise_reason'])) ?>
</div>
<?php endif; ?>
<hr>
<div class="mb-3">
<label class="form-label">ความคิดเห็น (ถ้ามี)</label>
<textarea class="form-control" name="comments" rows="2" placeholder="ระบุเหตุผลการอนุมัติ/ไม่อนุมัติ"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="action" value="reject" class="btn btn-danger">ไม่อนุมัติ</button>
<button type="submit" name="action" value="approve" class="btn btn-success"><i class="fa-solid fa-check me-1"></i> อนุมัติ</button>
</div>
</form>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php
$extraScripts = '
<script>
$(document).ready(function() {
$("#approvalsTable").DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.13.6/i18n/th.json",
"emptyTable": "ไม่มีรายการรออนุมัติ"
},
"order": [[0, "desc"]],
"pageLength": 10
});
});
</script>
';
?>