Absent Report Controller Documentation
File: /controllers/absentReportController.php
Purpose: Generates employee attendance and absence tracking reports
Last Updated: December 20, 2024
Total Functions: 0 (Main logic inline)
Lines of Code: ~147
---
๐ Overview
The Absent Report Controller is a simple yet essential reporting module that tracks employee attendance and absence patterns. It provides:
- โข Employee daily attendance tracking
- โข Absence pattern analysis
- โข Date range filtering for attendance reports
- โข Branch-based employee filtering
- โข Real-time attendance status display
- โข Employee selection and filtering capabilities
- โข Timezone-aware reporting
- โข Integration with employee management system
Primary Functions
- โ Display employee attendance reports
- โ Track absence patterns by date range
- โ Filter employees by branch assignment
- โ Support date range selection for analysis
- โ Provide employee selection dropdowns
- โ Handle timezone adjustments for reports
- โ Generate attendance summaries
- โ Show current day attendance status
Related Controllers
- โข employeeController.php - Employee management
- โข userController.php - User management
- โข branchController.php - Branch management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns |
|---|---|---|
| **employee** | Employee master data | employeeId, employeename, branchid, employeeDate, status |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **programsettings** | System configuration | programsettingsid, settingkey, settingvalue, reportsPlusHours | |
| **youtubelink** | Tutorial links | youtubelinkid, title, url | |
| **branch** | Branch information | branchid, branchname |
๐ Key Functions
1. Default Action - Current Day Attendance
Location: Line 51-86
Purpose: Display today's employee attendance status with default filtering
Process Flow:
1. Check branch permission restrictions
2. Load all employees for current branch
3. Set default date range to today
4. Apply timezone adjustments if configured
5. Load today's attendance data
6. Display via absentReportview/show.html template
Branch Filtering:
$queryString = '';
if ($_SESSION['branchId'] > 0)
$queryString = ' AND branchid = ' . $_SESSION['branchId'];
$allemployee = $employeeEX->queryAllSimple($queryString);
Timezone Handling:
$Programsetting = $ProgramsettingDAO->load(1);
if (isset($Programsetting->reportsPlusHours) && !empty($Programsetting->reportsPlusHours)) {
$reportsPlusHours = $Programsetting->reportsPlusHours + 24;
$endDate = date('Y-m-d', strtotime('+' . $reportsPlusHours . ' hour', strtotime($endDate)));
$startDate = date('Y-m-d', strtotime('+' . $Programsetting->reportsPlusHours . ' hour', strtotime($startDate)));
}
---
2. show Action - Custom Date Range Report
Location: Line 87-137
Purpose: Generate attendance report for specified date range and employee
Function Signature:
// Triggered when: do=show
$startDate = $_REQUEST['from'];
$endDate = $_REQUEST['to'];
$employeeId = $_REQUEST['chooseEmp'];
Process Flow:
1. Load employee dropdown data with branch filtering
2. Parse date range and employee selection parameters
3. Apply timezone adjustments to date range
4. Build query string with date and employee filters
5. Execute attendance query with filters
6. Display filtered results via template
Query Building:
if (!empty($startDate) && !empty($endDate)) {
$queryString .= ' AND employeeDate >= "' . $startDate . '" AND employeeDate <= "' . $endDate . '" ';
}
if (!empty($employeeId)) {
$queryString .= ' AND employee.employeeId =' . $employeeId;
}
if ($_SESSION['branchId'] > 0)
$queryString .= ' AND branchid = ' . $_SESSION['branchId'];
Features:
- โข Custom date range selection
- โข Individual employee filtering
- โข Branch-based access control
- โข Timezone-aware date processing
---
๐ Workflows
Workflow 1: Daily Attendance Check
---
Workflow 2: Custom Date Range Analysis
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default action | Today's attendance report | |
| `do=show` | Custom filtering | Date range and employee filtered report | |
| `do=sucess` | Template only | Success message display | |
| `do=error` | Template only | Error message display |
Default Report (no do parameter):
- โข No parameters required
- โข Uses today's date automatically
- โข Applies user's branch restrictions
Custom Report (do=show):
- โข
from- Start date (optional, YYYY-MM-DD) - โข
to- End date (optional, YYYY-MM-DD) - โข
chooseEmp- Employee ID filter (optional)
---
๐งฎ Calculation Methods
Date Range Processing
// Default to today if no dates provided
$startDate = date('Y-m-d');
$endDate = date('Y-m-d');
// Timezone adjustment
if (isset($Programsetting->reportsPlusHours) && !empty($Programsetting->reportsPlusHours)) {
$reportsPlusHours = $Programsetting->reportsPlusHours + 24;
$endDate = date('Y-m-d', strtotime('+' . $reportsPlusHours . ' hour', strtotime($endDate)));
$startDate = date('Y-m-d', strtotime('+' . $Programsetting->reportsPlusHours . ' hour', strtotime($startDate)));
} else {
$endDate = $endDate . ' 23:59:59';
$startDate = $startDate . " 00:00:00";
}
Branch Filtering
$queryString = '';
if ($_SESSION['branchId'] > 0) {
$queryString = ' AND branchid = ' . $_SESSION['branchId'];
}
Query String Construction
if (!empty($startDate) && !empty($endDate)) {
$queryString .= ' AND employeeDate >= "' . $startDate . '" AND employeeDate <= "' . $endDate . '" ';
}
if (!empty($employeeId)) {
$queryString .= ' AND employee.employeeId =' . $employeeId;
}
---
๐ Security & Permissions
Branch-Based Access Control
// Users can only see employees from their assigned branch
if ($_SESSION['branchId'] > 0) {
$queryString .= ' AND branchid = ' . $_SESSION['branchId'];
}
Permission Model:
- โข Users assigned to specific branches can only see those employees
- โข Users with
branchId = 0orNULLcan see all employees - โข Branch restrictions apply to both employee lists and attendance data
Session Management
- โข Uses standard ERP session authentication
- โข Validates session before allowing access to reports
- โข Branch permissions enforced through session variables
Input Validation
- โข Date format validation for start/end dates
- โข Employee ID validation and type casting
- โข Branch ID validation through session system
- โข SQL injection prevention through DAO layer
---
๐ Performance Considerations
Database Optimization Tips
1. Required Indexes:
- employee(branchid, employeeDate)
- employee(employeeId, employeeDate)
- employee(branchid, employeeId)
2. Query Optimization:
- Use of date range indexes for efficient filtering
- Branch filtering reduces dataset size
- Simple queries minimize complexity
3. Memory Management:
- Small dataset typically due to daily focus
- Branch filtering limits result size
- Minimal data processing required
Known Performance Issues
-- Avoid functions in WHERE clauses for large datasets
-- BAD: WHERE DATE(employeeDate) = '2024-12-20'
-- GOOD: WHERE employeeDate >= '2024-12-20 00:00:00' AND employeeDate <= '2024-12-20 23:59:59'
---
๐ Common Issues & Troubleshooting
1. Missing Employee Data
Issue: Some employees don't appear in attendance reports
Cause: Branch filtering or inactive employee status
Debug:
-- Check branch assignments
SELECT employeeId, employeename, branchid FROM employee WHERE branchid = [USER_BRANCH];
-- Check employee status
SELECT COUNT(*) FROM employee WHERE status = 0; -- Inactive employees
2. Date Range Issues
Issue: No data appears for valid date ranges
Cause: Timezone configuration or date format problems
Debug:
// Check timezone settings
$Programsetting = $ProgramsettingDAO->load(1);
echo "Report Plus Hours: " . $Programsetting->reportsPlusHours;
// Verify date format
echo "Start Date: " . $startDate . "<br>";
echo "End Date: " . $endDate . "<br>";
3. Branch Permission Issues
Issue: Users see employees from wrong branches
Cause: Incorrect branch assignment in session
Fix:
// Verify session branch assignment
if (!isset($_SESSION['branchId']) || $_SESSION['branchId'] <= 0) {
// Handle missing or invalid branch assignment
echo "Warning: No branch assigned to user";
}
4. Empty Dropdown Lists
Issue: Employee selection dropdown appears empty
Cause: Overly restrictive branch filtering
Debug:
-- Check if branch has any employees
SELECT COUNT(*) FROM employee WHERE branchid = [BRANCH_ID];
-- Check employee status in branch
SELECT status, COUNT(*) FROM employee WHERE branchid = [BRANCH_ID] GROUP BY status;
---
๐งช Testing Scenarios
Test Case 1: Daily Attendance Report
1. Login as user assigned to specific branch
2. Access absent report controller without parameters
3. Verify only employees from user's branch appear
4. Check that today's date is used automatically
5. Confirm attendance data loads correctly
Test Case 2: Date Range Filtering
1. Select custom date range (e.g., last week)
2. Choose specific employee from dropdown
3. Submit report and verify data filtering
4. Test edge cases (same start/end date, future dates)
5. Confirm timezone adjustments work correctly
Test Case 3: Branch Permissions
1. Create test employees in different branches
2. Login as user assigned to Branch A
3. Verify only Branch A employees appear in reports
4. Test with user having no branch assignment
5. Confirm cross-branch access is properly restricted
Debug Mode Enable
// Add at top of controller for debugging
echo "Session Branch ID: " . $_SESSION['branchId'] . "<br>";
echo "Query String: " . $queryString . "<br>";
echo "Start Date: " . $startDate . " End Date: " . $endDate . "<br>";
// Debug employee loading
echo "Employees loaded: " . count($allemployee) . "<br>";
echo "Attendance records: " . count($employes) . "<br>";
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข employeeController.php - Employee management
- โข userController.php - User management
- โข branchController.php - Branch management
- โข Database Schema Documentation - Table relationships
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When attendance tracking requirements change