Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
@@ -0,0 +1,299 @@
<?php
require_once 'includes/db.php';
require_once 'includes/auth.php';
requireLogin();
// Fetch summary counts
$readyCount = 0;
$limitedCount = 0;
$notReadyCount = 0;
$uncheckedCount = 0;
try {
$stmt = $pdo->query("SELECT overall_status, COUNT(*) as count FROM ambulances GROUP BY overall_status");
if ($stmt) {
$counts = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($counts as $row) {
if ($row['overall_status'] === 'พร้อมปฏิบัติการ') $readyCount = $row['count'];
if ($row['overall_status'] === 'พร้อมใช้งานแบบมีข้อจำกัด') $limitedCount = $row['count'];
if ($row['overall_status'] === 'ไม่พร้อมปฏิบัติการ') $notReadyCount = $row['count'];
if ($row['overall_status'] === 'ยังไม่ได้ตรวจ') $uncheckedCount = $row['count'];
}
}
} catch (Exception $e) {}
// Fetch ambulances list
$ambulances = [];
try {
$query = "
SELECT
a.id, a.plate_no, a.type, a.latest_check_date, a.latest_check_time,
a.latest_check_by, a.overall_status, a.issues_count,
u.name as unit_name
FROM ambulances a
LEFT JOIN units u ON a.unit_id = u.id
ORDER BY a.id ASC
";
$stmt = $pdo->query($query);
if ($stmt) $ambulances = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {}
// Fetch Critical Issues
$criticalAmbulances = [];
try {
$query = "
SELECT
a.id, a.plate_no, u.name as unit_name, a.latest_check_by, a.issues_count
FROM ambulances a
LEFT JOIN units u ON a.unit_id = u.id
WHERE a.overall_status = 'ไม่พร้อมปฏิบัติการ' OR a.issues_count > 0
";
$stmt = $pdo->query($query);
if ($stmt) $criticalAmbulances = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {}
// Fetch Expiring Inventory
$expiringItems = [];
try {
$query = "
SELECT
i.item_name, i.expire_date,
a.id as ambulance_id, a.plate_no
FROM ambulance_inventory i
JOIN ambulances a ON i.ambulance_id = a.id
ORDER BY i.expire_date ASC
";
$stmt = $pdo->query($query);
if ($stmt) $expiringItems = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {}
function getDaysUntil($dateStr) {
$now = new DateTime();
$target = new DateTime($dateStr);
$diff = $now->diff($target);
$days = (int)$diff->format('%R%a');
return $days;
}
?>
<?php require_once 'includes/header.php'; ?>
<div class="space-y-6 animate-fadeIn pb-10">
<!-- Top Navigation Tabs -->
<div class="flex flex-wrap items-center gap-2">
<button class="bg-indigo-600 text-white flex items-center justify-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold shadow-sm cursor-default">
<i data-lucide="layout-dashboard" class="w-4 h-4"></i> แดชบอร์ดรถพยาบาล
</button>
<button onclick="Swal.fire('Coming Soon', 'ระบบแบบฟอร์มกำลังพัฒนา', 'info')" class="bg-white text-slate-600 border border-slate-200 hover:bg-slate-50 flex items-center justify-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all cursor-pointer">
<i data-lucide="plus-circle" class="w-4 h-4 text-slate-400"></i> แบบฟอร์มตรวจความพร้อมรถ
</button>
<button onclick="Swal.fire('Coming Soon', 'ระบบรายการซ่อมบำรุงกำลังพัฒนา', 'info')" class="bg-white text-slate-600 border border-slate-200 hover:bg-slate-50 flex items-center justify-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all cursor-pointer">
<i data-lucide="triangle-alert" class="w-4 h-4 text-slate-400"></i> รายการซ่อมบำรุง (2)
</button>
</div>
<!-- 4 Summary Cards -->
<div class="grid grid-cols-2 lg:grid-cols-4 gap-4">
<div class="bg-white p-4 rounded-2xl shadow-sm border border-slate-100 flex items-center gap-3">
<div class="p-3 bg-emerald-50 text-emerald-600 rounded-xl">
<i data-lucide="shield-check" class="w-6 h-6"></i>
</div>
<div>
<div class="text-xs text-slate-400 font-bold">พร้อมปฏิบัติการ</div>
<div class="text-xl md:text-2xl font-black text-slate-800"><?php echo $readyCount; ?> <span class="text-sm font-bold text-slate-500">คัน</span></div>
</div>
</div>
<div class="bg-white p-4 rounded-2xl shadow-sm border border-slate-100 flex items-center gap-3">
<div class="p-3 bg-amber-50 text-amber-600 rounded-xl">
<i data-lucide="triangle-alert" class="w-6 h-6"></i>
</div>
<div>
<div class="text-xs text-slate-400 font-bold font-sans">พร้อมใช้มีข้อจำกัด</div>
<div class="text-xl md:text-2xl font-black text-slate-800"><?php echo $limitedCount; ?> <span class="text-sm font-bold text-slate-500">คัน</span></div>
</div>
</div>
<div class="bg-white p-4 rounded-2xl shadow-sm border border-slate-100 flex items-center gap-3">
<div class="p-3 bg-red-50 text-red-600 rounded-xl">
<i data-lucide="x-circle" class="w-6 h-6"></i>
</div>
<div>
<div class="text-xs text-slate-400 font-bold">ไม่พร้อมใช้</div>
<div class="text-xl md:text-2xl font-black text-slate-800"><?php echo $notReadyCount; ?> <span class="text-sm font-bold text-slate-500">คัน</span></div>
</div>
</div>
<div class="bg-white p-4 rounded-2xl shadow-sm border border-slate-100 flex items-center gap-3">
<div class="p-3 bg-slate-50 text-slate-400 rounded-xl">
<i data-lucide="clock" class="w-6 h-6"></i>
</div>
<div>
<div class="text-xs text-slate-400 font-bold">ยังไม่ได้ตรวจประจำเวร</div>
<div class="text-xl md:text-2xl font-black text-slate-800"><?php echo $uncheckedCount; ?> <span class="text-sm font-bold text-slate-500">คัน</span></div>
</div>
</div>
</div>
<!-- Main Table -->
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 overflow-hidden">
<div class="p-4 md:p-5 border-b border-slate-100 bg-slate-50 flex items-center justify-between">
<div>
<h3 class="text-base font-bold text-slate-800">สถานะความพร้อมรถพยาบาลปัจจุบัน</h3>
<p class="text-xs text-slate-500 mt-0.5">แสดงข้อมูลจากการประเมินครั้งล่าสุดของแต่ละคันในระบบ</p>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full text-left border-collapse text-xs md:text-sm">
<thead>
<tr class="bg-slate-100/50 text-slate-600 font-bold border-b border-slate-100">
<th class="py-3 px-4">รหัส / ทะเบียนรถ</th>
<th class="py-3 px-3">หน่วยงานผู้ควบคุม</th>
<th class="py-3 px-3 text-center">ประเภทรถ</th>
<th class="py-3 px-3">เวลาที่ตรวจล่าสุด</th>
<th class="py-3 px-3">ผู้ตรวจสภาพ</th>
<th class="py-3 px-3 text-center">สถานะความพร้อม</th>
<th class="py-3 px-3 text-center">รายงานปัญหา</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 text-slate-700 font-medium">
<?php if (empty($ambulances)): ?>
<tr><td colspan="7" class="text-center py-6 text-slate-400 font-bold">ไม่มีข้อมูลรถพยาบาล</td></tr>
<?php else: ?>
<?php foreach ($ambulances as $amb):
// Determine type badge
$typeClass = $amb['type'] === 'ALS' ? 'bg-red-100 text-red-800 border border-red-200' : 'bg-blue-100 text-blue-800 border border-blue-200';
// Determine status badge
$statusClass = 'bg-slate-100 text-slate-500 border-slate-200';
$statusIcon = 'w-3 h-3 bg-slate-400 rounded-full';
if ($amb['overall_status'] === 'พร้อมปฏิบัติการ') {
$statusClass = 'bg-emerald-50 text-emerald-700 border-emerald-200';
$statusIcon = 'w-1.5 h-1.5 bg-emerald-500 rounded-full';
} elseif ($amb['overall_status'] === 'พร้อมใช้งานแบบมีข้อจำกัด') {
$statusClass = 'bg-amber-50 text-amber-700 border-amber-200';
$statusIcon = 'w-1.5 h-1.5 bg-amber-500 rounded-full';
} elseif ($amb['overall_status'] === 'ไม่พร้อมปฏิบัติการ') {
$statusClass = 'bg-rose-50 text-rose-700 border-rose-200';
$statusIcon = 'w-1.5 h-1.5 bg-rose-500 rounded-full';
}
?>
<tr class="hover:bg-slate-50/50 transition-colors">
<td class="py-3.5 px-4">
<div class="flex items-center gap-2">
<i data-lucide="truck" class="w-4 h-4 text-slate-400"></i>
<div>
<div class="font-bold text-slate-800"><?php echo htmlspecialchars($amb['id']); ?></div>
<div class="text-[10px] text-slate-400 font-mono font-semibold"><?php echo htmlspecialchars($amb['plate_no']); ?></div>
</div>
</div>
</td>
<td class="py-3.5 px-3">
<span class="bg-slate-100 px-2.5 py-1 rounded-lg text-slate-600 font-semibold"><?php echo htmlspecialchars($amb['unit_name'] ?? 'ไม่ระบุ'); ?></span>
</td>
<td class="py-3.5 px-3 text-center">
<span class="px-2 py-0.5 rounded text-[10px] font-bold <?php echo $typeClass; ?>"><?php echo htmlspecialchars($amb['type']); ?></span>
</td>
<td class="py-3.5 px-3 font-mono text-slate-500 text-xs">
<?php if ($amb['latest_check_date']): ?>
<?php echo htmlspecialchars($amb['latest_check_date']); ?> | <?php echo htmlspecialchars(substr($amb['latest_check_time'], 0, 5)); ?> น.
<?php else: ?>
ยังไม่ได้ตรวจ
<?php endif; ?>
</td>
<td class="py-3.5 px-3 text-slate-600 truncate max-w-[130px]">
<?php echo htmlspecialchars($amb['latest_check_by'] ?? '-'); ?>
</td>
<td class="py-3.5 px-3 text-center">
<span class="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold border shadow-sm <?php echo $statusClass; ?>">
<span class="<?php echo $statusIcon; ?>"></span>
<?php echo htmlspecialchars($amb['overall_status']); ?>
</span>
</td>
<td class="py-3.5 px-3 text-center">
<?php if ($amb['issues_count'] > 0): ?>
<span class="bg-rose-100 text-rose-700 font-black text-xs px-2.5 py-1 rounded-full border border-rose-200 animate-pulse">
⚠️ พบจุดชำรุด <?php echo $amb['issues_count']; ?> แห่ง
</span>
<?php else: ?>
<span class="text-slate-400 text-xs font-semibold">ปกติ</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<!-- Bottom Alerts -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Left: Critical Issues -->
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 p-5 space-y-4">
<div class="flex items-center justify-between border-b border-slate-50 pb-2">
<h4 class="font-bold text-slate-800 flex items-center gap-2">
<i data-lucide="triangle-alert" class="w-4 h-4 text-rose-600"></i> แจ้งเตือนรถพยาบาลวิกฤต/ฉุกเฉิน
</h4>
<span class="text-[10px] bg-red-50 text-red-600 font-bold px-2 py-0.5 rounded-full border border-red-200">ต้องการแก้ไขด่วน</span>
</div>
<div class="space-y-2.5">
<?php if (empty($criticalAmbulances)): ?>
<div class="text-center py-6 text-slate-400 text-xs font-medium">✨ ระบบไม่พบปัญหาเร่งด่วนในรถกู้ชีพพยาบาลทุกคัน</div>
<?php else: ?>
<?php foreach ($criticalAmbulances as $cAmb): ?>
<div class="flex items-center justify-between bg-red-50/30 p-3 rounded-xl border border-red-100">
<div>
<div class="text-xs font-bold text-slate-800"><?php echo htmlspecialchars($cAmb['id']); ?> (<?php echo htmlspecialchars($cAmb['plate_no']); ?>)</div>
<div class="text-[10px] text-slate-500 mt-1">ค่ายดูแล: <?php echo htmlspecialchars($cAmb['unit_name']); ?> | ตรวจโดย: <?php echo htmlspecialchars($cAmb['latest_check_by']); ?></div>
</div>
<div class="text-right">
<span class="bg-red-100 text-red-800 text-[10px] font-black px-2 py-1 rounded border border-red-200 uppercase tracking-wide">ไม่พร้อมใช้ (<?php echo $cAmb['issues_count']; ?> ปัญหา)</span>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<!-- Right: Expiring Inventory -->
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 p-5 space-y-4">
<div class="flex items-center justify-between border-b border-slate-50 pb-2">
<h4 class="font-bold text-slate-800 flex items-center gap-2">
<i data-lucide="package" class="w-4 h-4 text-amber-600"></i> ยา/เวชภัณฑ์ใกล้หมดอายุ
</h4>
<span class="text-[10px] bg-amber-50 text-amber-700 font-bold px-2 py-0.5 rounded-full border border-amber-200">ตรวจสอบดวงชะตาเวชภัณฑ์</span>
</div>
<div class="space-y-2.5">
<?php if (empty($expiringItems)): ?>
<div class="text-center py-6 text-slate-400 text-xs font-medium">ไม่มียา/เวชภัณฑ์ใกล้หมดอายุ</div>
<?php else: ?>
<?php foreach ($expiringItems as $item):
$days = getDaysUntil($item['expire_date']);
$isExpired = $days <= 30; // Just an example threshold
$textClass = $isExpired ? 'text-amber-700' : 'text-slate-500';
$statusText = $isExpired ? "หมดอายุ {$days} วันข้างหน้า" : "เหลือ {$days} วัน";
?>
<div class="flex items-center justify-between bg-amber-50/40 p-3 rounded-xl border border-amber-100">
<div>
<div class="text-xs font-bold text-slate-800"><?php echo htmlspecialchars($item['item_name']); ?></div>
<div class="text-[10px] text-slate-400 mt-1">รถ: <?php echo htmlspecialchars($item['ambulance_id']); ?> | ทะเบียน: <?php echo htmlspecialchars($item['plate_no']); ?></div>
</div>
<div class="text-right">
<span class="text-xs font-extrabold <?php echo $textClass; ?>"><?php echo $statusText; ?></span>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<script>
lucide.createIcons();
</script>
<?php require_once 'includes/footer.php'; ?>