| Server IP : 104.21.80.248 / Your IP : 172.71.28.155 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : E:/Inetpub/www/supply_system/requisitions/ |
Upload File : |
<?php
include_once __DIR__ . '/../config.php';
include_once __DIR__ . '/../functions.php';
include_once __DIR__ . '/../includes/auth_check.php';
// requireRole(['department']);
$page_title = "รายการคำขอเบิกของฉัน";
$user_id = getUserData('user_id');
// --- Fetch Requisitions for the current user ---
$requisitions = [];
$sql = "SELECT r.id, r.requisition_no, r.request_date, r.status, d.dept_name, r.total_value
FROM requisitions r
JOIN departments d ON r.department_id = d.id
WHERE r.requested_by = $user_id
ORDER BY r.request_date DESC, r.id DESC";
$result = mysqli_query($conn, $sql);
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
$requisitions[] = $row;
}
mysqli_free_result($result);
} else {
echo "Error fetching requisitions: " . mysqli_error($conn);
}
mysqli_close($conn);
// --- Include Header and Sidebar ---
include_once __DIR__ . '/../includes/header.php';
include_once __DIR__ . '/../includes/sidebar_dept.php';
?>
<div class="container-fluid">
<h1 class="mt-4"><?php echo $page_title; ?></h1>
<?php if (isset($_SESSION['message'])): ?>
<div class="alert alert-<?php echo $_SESSION['message_type']; ?> alert-dismissible fade show" role="alert">
<?php echo $_SESSION['message']; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php unset($_SESSION['message'], $_SESSION['message_type']); ?>
<?php endif; ?>
<div class="card mb-4">
<div class="card-header">
<i class="bi bi-list-task me-1"></i>
รายการคำขอเบิกที่สร้าง
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover table-sm"> <thead class="table-dark">
<tr>
<th>#</th>
<th>เลขที่คำขอ</th>
<th>วันที่ขอ</th>
<th>กลุ่มงาน</th>
<th>สถานะ</th>
<th class="text-end">มูลค่ารวม (ถ้ามี)</th>
<th>ดำเนินการ</th>
</tr>
</thead>
<tbody>
<?php if (!empty($requisitions)): ?>
<?php $counter = 1; ?>
<?php foreach ($requisitions as $req):
$can_delete = ($req['status'] == 'pending' || $req['status'] == 'head_rejected'); // Check if deletable
?>
<tr>
<td><?php echo $counter++; ?></td>
<td><?php echo htmlspecialchars($req['requisition_no']); ?></td>
<td><?php echo formatThaiDate($req['request_date'], false); ?></td>
<td><?php echo htmlspecialchars($req['dept_name']); ?></td>
<td>
<?php
$status_badge = 'secondary';
$status_text = $req['status'];
switch ($req['status']) {
case 'pending': $status_badge = 'warning text-dark'; $status_text = 'รอ ผอ. กลุ่มรับทราบ'; break;
case 'head_approved': $status_badge = 'info text-dark'; $status_text = 'รอฝ่ายพัสดุอนุมัติ'; break;
case 'approved': $status_badge = 'success'; $status_text = 'อนุมัติแล้ว'; break;
case 'rejected': $status_badge = 'danger'; $status_text = 'ไม่อนุมัติ (พัสดุ)'; break;
case 'head_rejected': $status_badge = 'danger'; $status_text = 'ไม่อนุมัติ (ผอ. กลุ่ม)'; break;
}
?>
<span class="badge bg-<?php echo $status_badge; ?>"><?php echo $status_text; ?></span>
</td>
<td class="text-end">
<?php echo ($req['status'] == 'approved') ? number_format($req['total_value'], 2) : '-'; ?>
</td>
<td>
<a href="view.php?id=<?php echo $req['id']; ?>" class="btn btn-sm btn-info" title="ดูรายละเอียด">
<i class="bi bi-search"></i>
</a>
<?php if ($can_delete): ?>
<a href="action_requisition_delete.php?id=<?php echo $req['id']; ?>"
class="btn btn-sm btn-danger"
title="ลบคำขอ"
onclick="return confirm('ต้องการลบคำขอเบิก <?php echo htmlspecialchars($req['requisition_no']); ?> ใช่หรือไม่?');">
<i class="bi bi-trash-fill"></i>
</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="7" class="text-center">คุณยังไม่ได้สร้างคำขอเบิก</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
// --- Include Footer ---
include_once __DIR__ . '/../includes/footer.php';
?>