| Server IP : 172.67.187.206 / Your IP : 162.159.115.42 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 : /Inetpub/www/supply_system/reports/ |
Upload File : |
<?php
include_once __DIR__ . '/../config.php';
include_once __DIR__ . '/../functions.php';
include_once __DIR__ . '/../includes/auth_check.php';
// requireRole(['admin', 'supply_manager']);
$page_title = "รายงานพัสดุใกล้หมด / ต่ำกว่าจุดสั่งซื้อ";
// --- Fetch Low Stock Items ---
$low_stock_items = [];
$sql = "SELECT s.id, s.supply_code, s.supply_name, c.category_name, s.unit, s.quantity_in_stock, s.min_stock_level
FROM supplies s
JOIN categories c ON s.category_id = c.id
WHERE s.status = 'active' AND s.quantity_in_stock <= s.min_stock_level AND s.min_stock_level > 0
ORDER BY s.supply_code ASC";
$result = mysqli_query($conn, $sql);
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
$low_stock_items[] = $row;
}
mysqli_free_result($result);
} else {
echo "Error fetching low stock data: " . mysqli_error($conn);
}
mysqli_close($conn);
// --- Include Header and Sidebar ---
include_once __DIR__ . '/../includes/header.php';
include_once __DIR__ . '/../includes/sidebar_supply.php';
?>
<div class="container-fluid">
<div class="d-flex justify-content-between align-items-center mb-4 mt-4">
<div>
<h1 class="mb-0"><?php echo $page_title; ?></h1>
<p class="text-muted mb-0">รายการพัสดุที่จำนวนคงคลังปัจจุบัน เท่ากับ หรือ น้อยกว่า จุดสั่งซื้อขั้นต่ำ</p>
</div>
<div>
<button type="button" class="btn btn-success" id="exportBtn">
<i class="bi bi-file-earmark-excel-fill"></i> ส่งออกเป็น Excel
</button>
</div>
</div>
<div class="card mb-4">
<div class="card-header text-white bg-danger">
<i class="bi bi-exclamation-triangle-fill me-1"></i>
รายการพัสดุที่ต้องพิจารณาสั่งซื้อเพิ่ม (<?php echo count($low_stock_items); ?> รายการ)
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover table-sm" id="lowStockTable"> <thead class="table-dark">
<tr>
<th>#</th>
<th>รหัส</th>
<th>ชื่อพัสดุ</th>
<th>หมวดหมู่</th>
<th>หน่วยนับ</th>
<th class="text-end">คงคลังปัจจุบัน</th>
<th class="text-end">จุดสั่งซื้อ</th>
<th class="text-end">ต่ำกว่าจุดสั่งซื้อ</th>
<th>ดำเนินการ</th>
</tr>
</thead>
<tbody>
<?php if (!empty($low_stock_items)): ?>
<?php $counter = 1; ?>
<?php foreach ($low_stock_items as $item): ?>
<tr class="table-warning">
<td><?php echo $counter++; ?></td>
<td><?php echo htmlspecialchars($item['supply_code']); ?></td>
<td><?php echo htmlspecialchars($item['supply_name']); ?></td>
<td><?php echo htmlspecialchars($item['category_name']); ?></td>
<td><?php echo htmlspecialchars($item['unit']); ?></td>
<td class="text-end fw-bold text-danger"><?php echo number_format($item['quantity_in_stock']); ?></td>
<td class="text-end"><?php echo number_format($item['min_stock_level']); ?></td>
<td class="text-end fw-bold text-danger">
<?php echo number_format($item['min_stock_level'] - $item['quantity_in_stock']); ?>
</td>
<td>
<a href="../supplies/supply_view.php?id=<?php echo $item['id']; ?>" class="btn btn-sm btn-info" title="ดูรายละเอียด Batch">
<i class="bi bi-search"></i>
</a>
<a href="../supplies/batch_add.php?supply_id=<?php echo $item['id']; ?>" class="btn btn-sm btn-success" title="เพิ่มสต็อก">
<i class="bi bi-plus-circle"></i>
</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="9" class="text-center">ไม่พบพัสดุที่ต่ำกว่าจุดสั่งซื้อ</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
// --- Include Footer ---
include_once __DIR__ . '/../includes/footer.php';
?>
<script>
document.getElementById('exportBtn').addEventListener('click', function() {
// Since this report doesn't have filters yet, we directly call the export script
window.location.href = 'export_low_stock.php'; // The script that will generate the Excel
});
</script>