ليس لديك صلاحية للوصول إلى هذه الصفحة."; require_once 'includes/footer.php'; exit; } $date = $_GET['date'] ?? date('Y-m-d'); $error = ''; $success = ''; // Handle Attendance Submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_attendance'])) { if (!canAdd('hr_attendance') && !canEdit('hr_attendance')) { $error = "لا تملك صلاحية التعديل."; } else { $emp_id = $_POST['employee_id']; $att_date = $_POST['date']; $status = $_POST['status']; $check_in = !empty($_POST['check_in']) ? $_POST['check_in'] : null; $check_out = !empty($_POST['check_out']) ? $_POST['check_out'] : null; $notes = $_POST['notes']; try { // Check if exists $stmt = db()->prepare("SELECT id FROM hr_attendance WHERE employee_id = ? AND date = ?"); $stmt->execute([$emp_id, $att_date]); $exists = $stmt->fetch(); if ($exists) { $stmt = db()->prepare("UPDATE hr_attendance SET status = ?, check_in = ?, check_out = ?, notes = ? WHERE id = ?"); $stmt->execute([$status, $check_in, $check_out, $notes, $exists['id']]); $success = "تم تحديث الحضور بنجاح."; } else { $stmt = db()->prepare("INSERT INTO hr_attendance (employee_id, date, status, check_in, check_out, notes) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$emp_id, $att_date, $status, $check_in, $check_out, $notes]); $success = "تم تسجيل الحضور بنجاح."; } } catch (PDOException $e) { $error = "خطأ: " . $e->getMessage(); } } } // Fetch Employees and their attendance for the selected date $sql = "SELECT e.id, e.first_name, e.last_name, e.job_title, a.id as att_id, a.status, a.check_in, a.check_out, a.notes FROM hr_employees e LEFT JOIN hr_attendance a ON e.id = a.employee_id AND a.date = ? WHERE e.status = 'active' ORDER BY e.first_name"; $stmt = db()->prepare($sql); $stmt->execute([$date]); $records = $stmt->fetchAll(); ?>
| الموظف | الوظيفة | الحالة | وقت الحضور | وقت الانصراف | ملاحظات | إجراء |
|---|---|---|---|---|---|---|
| = htmlspecialchars($row['first_name'] . ' ' . $row['last_name']) ?> | = htmlspecialchars($row['job_title']) ?> | 'success', 'absent' => 'danger', 'late' => 'warning', 'excused' => 'info', 'holiday' => 'primary', default => 'secondary' }; $status_text = match($row['status']) { 'present' => 'حاضر', 'absent' => 'غائب', 'late' => 'تأخير', 'excused' => 'مأذون', 'holiday' => 'عطلة', default => $row['status'] }; ?> = $status_text ?> غير مسجل | = $row['check_in'] ? date('h:i A', strtotime($row['check_in'])) : '-' ?> | = $row['check_out'] ? date('h:i A', strtotime($row['check_out'])) : '-' ?> | = htmlspecialchars($row['notes'] ?? '') ?> |