๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

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:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey 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`
### Related Tables (References)

Table NamePurposeKey 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`
### Reference Tables (Lookups)

Table NamePurposeKey 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

- date (POST): Target date for attendance (defaults to today)

โ”Œโ”€ Initialize Date โ”€โ”€โ”€โ”€โ”
Default to today if
no date provided
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Apply Branch Filter โ”
Filter employees by
user's branch
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Load All Employees โ”€โ”
queryAllemployeeby
condation(0)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ For Each Employee โ”€โ”€โ”
โ€ข Load attendance
โ€ข Load daily history
โ€ข Prepare time data
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Display Dashboard โ”€โ”€โ”
employee_attendance_
view/add.html
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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

- empid (int): Employee ID

- date (string): Attendance date

- value (string): Time value (HH:MM format)

- type (string): "attend" or "depart"

โ”Œโ”€ Validate Input โ”€โ”€โ”€โ”€โ”€โ”
โ€ข Employee ID valid
โ€ข Date format valid
โ€ข Time format valid
โ€ข Type is valid
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Initialize Day โ”€โ”€โ”€โ”€โ”€โ”
If first attendance
of day, create day
record via
beginDayAttendance()
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Check Entry Limit โ”€โ”€โ”
If < 2 attendance
records exist,
create new raw
attendance record
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Update Daily Summaryโ”
โ€ข Load existing
history record
โ€ข Update attend/
depart time
โ€ข Save changes
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Return Status โ”€โ”€โ”€โ”€โ”€โ”€โ”
Echo 1 on success
Echo -1 on error
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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

โ”Œโ”€ START: Daily Attendance โ”€โ”
โ–ผ
โ”Œโ”€ Select Date โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
Default to current date
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ–ผ
โ”Œโ”€ Load Employee List โ”€โ”€โ”€โ” โ”‚
โ€ข Active employees
โ€ข Branch filtered
โ€ข Not deleted
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ–ผ
โ”Œโ”€ For Each Employee โ”€โ”€โ”€โ”€โ” โ”‚
โ€ข Load daily schedule
โ€ข Check existing
attendance
โ€ข Load history data
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ–ผ
โ”Œโ”€ Display Dashboard โ”€โ”€โ”€โ”€โ” โ”‚
โ€ข Employee list
โ€ข Time input fields
โ€ข Current status
โ€ข Action buttons
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ–ผ
โ”Œโ”€ User Time Entry โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ€ข Select employee
โ€ข Enter time
โ€ข Choose attend/depart
โ€ข Submit via AJAX
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ–ผ
โ”Œโ”€ Process Entry โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ€ข Validate data
โ€ข Create/update recordsโ”‚
โ€ข Update status
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ–ผ
โ”Œโ”€ END: Save Success โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Time Entry Processing

โ”Œโ”€ Receive Time Entry โ”€โ”€โ”€โ”
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Initialize Day โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Create day record if
first entry of the day
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Check Entry Limit โ”€โ”€โ”€โ”€โ”
Max 2 raw attendance
records per employee
per day
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Create Raw Record โ”€โ”€โ”€โ”€โ”
employeeattendance
table with timestamp
and employee details
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Update Daily Summary โ”€โ”
โ€ข attendanceTime
โ€ข departureTime
โ€ข Clear absence flags
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Return Response โ”€โ”€โ”€โ”€โ”€โ”€โ”
AJAX response:
1 = Success
-1 = Error
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Attendance Data Structure

โ”Œโ”€ Raw Records โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ€ข First punch (IN)
โ€ข Second punch (OUT)
โ€ข Timestamp exact
โ€ข Source device info
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Daily Summary โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Table: employeeclosed...
โ€ข Start time (HH:MM)
โ€ข End time (HH:MM)
โ€ข Absence flags
โ€ข Permission flags
โ€ข Daily totals
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Schedule Template โ”€โ”€โ”€โ”€โ”€โ”€โ”
Table: employeeattend...
systemweek
โ€ข Expected start time
โ€ข Expected end time
โ€ข Day of week
โ€ข Work day flag
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

โš ๏ธ 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

Required DAOs

Related Controllers

Template Files

Key Attendance Features

โ†‘