Employee Attendance Controller Documentation
File: /controllers/EmployeeAttendanceController.php
Purpose: Manages daily employee attendance tracking and time recording
Last Updated: December 19, 2024
Total Functions: 0 (Controller actions only)
Lines of Code: ~202
---
๐ Overview
The Employee Attendance Controller handles daily attendance operations for tracking employee check-ins and check-outs. It provides:
- โข Daily attendance time recording (arrival/departure)
- โข Real-time attendance monitoring dashboard
- โข Employee attendance history management
- โข Integration with attendance calculation systems
- โข Branch-based attendance filtering
- โข Manual time entry and corrections
- โข Attendance system initialization for new periods
- โข AJAX-based time entry for seamless user experience
Primary Functions
- โ Display daily attendance dashboard
- โ Record employee arrival times
- โ Record employee departure times
- โ View employee attendance history
- โ Filter attendance by date and branch
- โ Manual time entry and corrections
- โ Initialize attendance for new periods
- โ Real-time attendance updates via AJAX
- โ Integration with fingerprint/RFID systems
- โ Support for YouTube training links
Related Controllers
- โข employeeController.php - Employee management
- โข salaryReportController.php - Salary calculations based on attendance
- โข employeePersonalController.php - Employee loans and advances
- โข employeeAttendance.php - Extended attendance features
- โข EmployeeAttendanceExcelController.php - Excel import/export
- โข employeeendday.php - End-of-day processing
- โข absentReportController.php - Absence reporting
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `employeeattendance` | Raw attendance records | `empid`, `sysdate`, `fingerid`, `rfid`, `accessType` | |
| `employeeclosedayhistory` | Daily attendance summary | `employeeid`, `day`, `attendanceTime`, `departureTime`, `isAbsent` | |
| `employee` | Employee master data | `employeeId`, `employeeName`, `branchid`, `conditions` |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `employeeattendancesystemweek` | Weekly schedule templates | `employee_id`, `attendancedaynum`, `attendancetime`, `departuretime` | |
| `employeeattendancesystem` | Attendance system definitions | `id`, `systemName`, `description` | |
| `branch` | Branch information for filtering | `branchId`, `branchName` | |
| `user` | User information for audit | `userid`, `username` |
| Table Name | Purpose | Key Columns |
|---|---|---|
| `youtubelink` | Training video links | `id`, `title`, `url`, `description` |
๐ง Key Functions
Main Controller Actions
Default Action (Show Attendance Dashboard)
if (empty($do) || $do == "show") // Line 84
- โข Purpose: Display daily attendance dashboard with all employees
- โข Parameters:
- date (POST): Target date for attendance (defaults to today)
- โข Process Flow:
- โข Employee Data Processing:
foreach ($employees as $emp) {
if ($emp->employeeId > 0) {
// Build query for specific employee and date
$queryString = " and empid = $emp->employeeId ";
if ($date != '') {
$queryString .= " and date(employeeattendance.sysdate) = '" . $date . "' ";
}
// Load raw attendance records
$employeeAttendanceData = $employeeAttendanceEX->queryByQueryString($queryString);
// Load daily summary
$employeeClosedHistoryData = $employeeCloseDayHistoryEX
->getEmployeeHistoryByQueryString(" and employeeid = " . $emp->employeeId .
" and date(day) = '" . $date . "'");
// Attach data to employee object
$emp->attendanceData = $employeeClosedHistoryData;
}
}
Add Time Entry (AJAX)
elseif ($do == "addTime") // Line 139
- โข Purpose: Process attendance time entry via AJAX
- โข Parameters (from $_POST):
- empid (int): Employee ID
- date (string): Attendance date
- value (string): Time value (HH:MM format)
- type (string): "attend" or "depart"
- โข Process Flow:
- โข Code Example:
try {
$empid = (int) filter_input(INPUT_POST, 'empid');
$day = filter_input(INPUT_POST, 'date');
$time = filter_input(INPUT_POST, 'value');
$type = filter_input(INPUT_POST, 'type');
// Ensure day attendance record exists
if ((int) $employeeCloseDayHistoryEX->dayAttendanceCount($day) == 0) {
$employeeCloseDayHistoryEX->beginDayAttendance($day, date('Y-m-d H:i:s'), $_SESSION['userid']);
}
// Check if we can add more attendance records (limit of 2)
$employeeAttendanceData = $employeeAttendanceEX->queryByQueryString(
" and empid = " . $empid . " and date(sysdate) = '" . $day . "'"
);
if (count($employeeAttendanceData) < 2) {
// Create new raw attendance record
$employeeAttendance->empid = $empid;
$employeeAttendance->sysdate = date_format(date_create($day . ' ' . $time), 'Y-m-d H:i:s');
$employeeAttendance->userid = $_SESSION['userid'];
$id = $employeeAttendanceDAO->insert($employeeAttendance);
}
// Update daily summary record
$row = $employeeCloseDayHistoryEX->getEmployeeHistoryByQueryString(
" and employeeid=$empid and day='" . $day . "' and del = 0"
);
if (count($row) > 0) {
$employeeCloseDayHistory = $row[0];
if ($type == "attend") {
$employeeCloseDayHistory->attendanceTime = $time;
} else {
$employeeCloseDayHistory->departureTime = $time;
}
$employeeCloseDayHistory->isAbsent = 0;
$employeeCloseDayHistoryDAO->update($employeeCloseDayHistory);
}
echo 1; // Success
} catch (Exception $e) {
echo -1; // Error
}
---
๐ Business Logic Flow
Daily Attendance Workflow
Time Entry Processing
Attendance Data Structure
---
โ ๏ธ Common Issues
Known Bugs & Limitations
1. Time Format Validation
- Issue: No client-side validation for time format
- Location: AJAX time entry
- Impact: Invalid time entries may cause database errors
- Solution: Add time format validation before processing
2. Attendance Limit Logic
- Issue: Hard-coded limit of 2 attendance records per day
- Location: Line 154 (count check)
- Impact: Cannot handle multiple in/out entries for breaks
- Solution: Make attendance entry limit configurable
3. Error Handling
- Issue: Generic error responses without specific error messages
- Location: AJAX response handling
- Impact: Difficult to diagnose attendance entry issues
- Solution: Return specific error codes and messages
4. Date Validation
- Issue: No validation for future dates or invalid date formats
- Location: Date parameter processing
- Impact: May allow invalid attendance entries
- Solution: Add proper date validation
PHP 8.2 Compatibility
1. Object Initialization
- All objects properly initialized before use
- No "attempt to assign property on null" errors
2. Array Access Safety
- Safe array handling for attendance data processing
- Proper count() usage with array checks
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core operations (conditionally loaded) - โข
../public/config.php- Database configuration - โข
../public/include_dao.php- DAO includes - โข
../library/uploadImages.php- File handling utilities - โข
../library/num_to_ar.php- Number to Arabic conversion - โข
../library/Classes/PHPExcel/IOFactory.php- Excel operations - โข
dailyentryfun.php- Daily entry functions
Required DAOs
- โข
EmployeeattendanceDAO- Raw attendance records - โข
EmployeeclosedayhistoryDAO- Daily attendance summaries - โข
EmployeeDAO- Employee master data - โข
EmployeeMySqlExtDAO- Extended employee queries - โข
YoutubeLinkDAO- Training video management - โข
UserDAO- User information for audit trail
Related Controllers
- โข Must coordinate with employee management system
- โข Integrates with payroll calculations for attendance-based pay
- โข Works with absence tracking and reporting systems
- โข Connects to fingerprint/RFID attendance devices
Template Files
- โข
employee_attendance_view/add.html- Main attendance dashboard - โข
succes.html- Success message - โข
error.html- Error message - โข
header.html- Page header (conditionally loaded) - โข
footer.html- Page footer
Key Attendance Features
- โข Real-time Dashboard: Live view of all employee attendance status
- โข AJAX Time Entry: Seamless time recording without page refresh
- โข Branch Filtering: Multi-branch organization support with proper access control
- โข Dual Recording: Both raw punch records and daily summaries for flexibility
- โข Schedule Integration: Links to employee weekly attendance schedules
- โข Device Support: Ready for integration with fingerprint and RFID devices
- โข Training Integration: YouTube video links for attendance system training
- โข Audit Trail: Complete tracking of who recorded what and when
- โข Error Recovery: Handles day initialization and duplicate entry scenarios
- โข Time Correction: Manual time entry and correction capabilities