query("SELECT COUNT(*) FROM incidents"); if ($stmt) { $totalCases = $stmt->fetchColumn(); } $stmt = $pdo->prepare("SELECT COUNT(*) FROM incidents WHERE channel LIKE :channel"); if ($stmt) { $stmt->execute(['channel' => '%First Call%']); $totalFirstCalls = $stmt->fetchColumn(); } $stmt = $pdo->prepare("SELECT COUNT(*) FROM incidents WHERE status = :status"); if ($stmt) { $stmt->execute(['status' => 'ปิดเคส']); $totalCompleted = $stmt->fetchColumn(); } $totalPending = max(0, $totalCases - $totalCompleted); } catch (Exception $e) { // Silently handle if incidents table doesn't exist yet } // Fetch Call Channels $channelsQuery = " SELECT CASE WHEN channel LIKE '%First Call%' THEN 'First Call (เบอร์ 1669 หลัก)' WHEN channel LIKE '%Second Call%' THEN 'Second Call (สายซ้อนประสาน)' WHEN channel LIKE '%วิทยุ%' THEN 'วิทยุสื่อสาร ว.6' ELSE 'หมายเลขอื่น / ช่องทางอื่น ๆ' END as channel_group, COUNT(*) as count FROM incidents GROUP BY channel_group "; $channelsResult = []; try { $stmt = $pdo->query($channelsQuery); if ($stmt) { $channelsResult = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); } } catch (Exception $e) {} // Fallback values if empty $channels = [ 'First Call (เบอร์ 1669 หลัก)' => $channelsResult['First Call (เบอร์ 1669 หลัก)'] ?? 0, 'Second Call (สายซ้อนประสาน)' => $channelsResult['Second Call (สายซ้อนประสาน)'] ?? 0, 'วิทยุสื่อสาร ว.6' => $channelsResult['วิทยุสื่อสาร ว.6'] ?? 0, 'หมายเลขอื่น / ช่องทางอื่น ๆ' => $channelsResult['หมายเลขอื่น / ช่องทางอื่น ๆ'] ?? 0, ]; // Fetch Phone Triage $triageQuery = " SELECT CASE WHEN phone_triage LIKE '%แดง%' THEN '🔴 สีแดง - วิกฤตสูงสุด' WHEN phone_triage LIKE '%เหลือง%' THEN '🟡 สีเหลือง - เร่งด่วน' WHEN phone_triage LIKE '%เขียว%' THEN '🟢 สีเขียว - เจ็บป่วยทั่วไป' WHEN phone_triage LIKE '%ขาว%' THEN '⚪ สีขาว - ตรวจสุขภาพนัดส่งต่อ' ELSE 'ไม่ระบุ' END as triage_group, COUNT(*) as count FROM incidents WHERE phone_triage IS NOT NULL AND phone_triage != '' GROUP BY triage_group "; $triageResult = []; try { $stmt = $pdo->query($triageQuery); if ($stmt) { $triageResult = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); } } catch (Exception $e) {} $triage = [ '🔴 สีแดง - วิกฤตสูงสุด' => $triageResult['🔴 สีแดง - วิกฤตสูงสุด'] ?? 0, '🟡 สีเหลือง - เร่งด่วน' => $triageResult['🟡 สีเหลือง - เร่งด่วน'] ?? 0, '🟢 สีเขียว - เจ็บป่วยทั่วไป' => $triageResult['🟢 สีเขียว - เจ็บป่วยทั่วไป'] ?? 0, '⚪ สีขาว - ตรวจสุขภาพนัดส่งต่อ' => $triageResult['⚪ สีขาว - ตรวจสุขภาพนัดส่งต่อ'] ?? 0, ]; // Fetch Dispatcher Productivity $productivity = []; try { $usersQuery = "SELECT id, username, full_name as name, role FROM users WHERE is_active = 1"; $stmt = $pdo->query($usersQuery); if ($stmt) { $users = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($users as $user) { // Calls & Cases Created $stmt = $pdo->prepare("SELECT COUNT(*) FROM incidents WHERE created_by = :user_id"); $createdCount = 0; if ($stmt) { $stmt->execute(['user_id' => $user['id']]); $createdCount = $stmt->fetchColumn(); } // Assigned Cases (where they are completed_by) $stmt = $pdo->prepare("SELECT COUNT(*) FROM incidents WHERE completed_by = :name OR completed_by = :username"); $assignedCount = 0; if ($stmt) { $stmt->execute(['name' => $user['name'], 'username' => $user['username']]); $assignedCount = $stmt->fetchColumn(); } // Completed Cases $stmt = $pdo->prepare("SELECT COUNT(*) FROM incidents WHERE (completed_by = :name OR completed_by = :username) AND status = 'ปิดเคส'"); $resolvedCount = 0; if ($stmt) { $stmt->execute(['name' => $user['name'], 'username' => $user['username']]); $resolvedCount = $stmt->fetchColumn(); } $productivity[] = [ 'fullName' => $user['name'], 'role' => $user['role'], 'createdCalls' => $createdCount, 'createdCases' => $createdCount, 'assignedCases' => $assignedCount, 'resolvedCases' => $resolvedCount, ]; } } } catch (Exception $e) {} ?>
คำนวณสถิติสรุปงานแยกรายเจ้าหน้าที่โดยอัตโนมัติอ้างอิงตาม username บันทึกข้อมูลจริงในข่าย
| ชื่อเจ้าหน้าที่กู้ชีพกู้ภัย | สิทธิ์ในระบบ | รับสายโทรศัพท์ (สาย) | สร้างเคสใหม่ (เคส) | รับมอบ Complete (เคส) | เคสที่ปิดแล้ว (เคส) |
|---|---|---|---|---|---|
| เคสสำเร็จ |