Employeedailyreport Documentation
Employee Daily Report Controller Documentation
File: /controllers/employeedailyreport.php
Purpose: Generate comprehensive daily attendance reports for employees with filtering and analytics
Last Updated: December 20, 2024
Total Functions: 3+
Lines of Code: ~148
---
๐ Overview
The Employee Daily Report Controller provides specialized reporting capabilities for employee attendance monitoring and daily workforce analytics. It handles:
- โข Individual employee attendance reports
- โข Date range filtering for attendance data
- โข Employee selection and filtering
- โข Absence tracking and reporting
- โข Branch-based employee filtering
- โข Multi-criteria attendance analytics
- โข Integration with attendance systems
- โข Report customization with time zones
Primary Functions
- โ Generate daily employee attendance reports
- โ Filter employees by date ranges
- โ Track employee absence patterns
- โ Support branch-based filtering
- โ Handle time zone adjustments
- โ Provide absence status filtering
- โ Integration with employee management
- โ YouTube tutorial integration
Related Controllers
- โข employeeController.php - Employee management
- โข employeeAttendance.php - Attendance tracking
- โข employeeendday.php - End of day processing
- โข employeereport.php - General employee reports
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **employee** | Employee master data | employeeId, employeeName, employeeDate, branchid, conditions | |
| **employeeattendance** | Attendance records | employeeId, employeeDate, attendanceTime, departureTime |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **programsettings** | System configuration | programsettingsid, reportsPlusHours, settingkey, settingvalue | |
| **youtubelink** | Tutorial links | youtubelinkid, title, url |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **branch** | Branch information | branchid, branchname, branchstatus |
๐ Key Functions
1. Default Action (empty $do) - Initial Report Display
Location: Line 51-86
Purpose: Display default employee daily report with current day data
Function Signature:
// Triggered when: no action specified
// Access: Requires authentication
Process Flow:
1. Apply authentication check
2. Filter employees by branch (if branch-specific user)
3. Set default date range (current day)
4. Apply time zone adjustments from program settings
5. Query employee attendance data for the day
6. Load YouTube tutorial links
7. Display via employeedailyreportview/show.html
Time Zone Handling:
$Programsetting = $ProgramsettingDAO->load(1);
if (isset($Programsetting->reportsPlusHours) && !empty($Programsetting->reportsPlusHours)) {
$reportsPlusHours = $Programsetting->reportsPlusHours + 24;
$endDate = date('Y-m-d', strtotime('+' . $reportsPlusHours . ' hour +0 minutes', strtotime($endDate)));
$startDate = date('Y-m-d', strtotime('+' . $Programsetting->reportsPlusHours . ' hour +0 minutes', strtotime($startDate)));
} else {
$endDate = $endDate . ' 23:59:59';
$startDate = $startDate . " 00:00:00";
}
Features:
- โข Automatic current day selection
- โข Branch-based employee filtering
- โข Time zone adjustment support
- โข Integration with program settings
---
2. show() - Custom Date Range Report
Location: Line 87-141
Purpose: Generate employee attendance report for specific date range and employee
Function Signature:
// Triggered when: do=show
$startDate = $_REQUEST['from'];
$endDate = $_REQUEST['to'];
$employeeId = $_REQUEST['chooseEmp'];
$isAbsent = $_REQUEST['isAbsent'];
Process Flow:
1. Load all employees for dropdown (branch-filtered)
2. Parse input parameters for date range and employee selection
3. Apply time zone adjustments (with bug fix needed - see Issues section)
4. Build query string with filters:
- Date range filter
- Employee ID filter
- Branch filter
5. Execute query with absence status filter
6. Display results with same template
Parameter Handling:
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'];
Absence Filtering:
- โข $isAbsent = 0: Show present employees
- โข $isAbsent = 1: Show absent employees
- โข Default: Show all employees
---
3. queryAllByIdAndDate() - Extended Query Function
Location: Line 134 (called from EmployeeMySqlExtDAO)
Purpose: Execute complex attendance queries with multiple filters
Function Call:
$employes = $employeeEX->queryAllByIdAndDate($queryString, $isAbsent);
Features:
- โข Supports complex WHERE clauses
- โข Absence status filtering
- โข Branch-based restrictions
- โข Date range filtering
- โข Employee-specific filtering
---
๐ Workflows
Workflow 1: Default Daily Report Generation
---
Workflow 2: Custom Date Range Report
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| (empty) | Default action | Current day attendance report | |
| `do=show` | show() | Custom date range and employee filter | |
| `do=sucess` | Success page | Display success message | |
| `do=error` | Error page | Display error message |
Default Report (no parameters):
- โข Uses current date automatically
- โข Shows all employees (branch-filtered)
- โข Uses default time zone settings
Custom Report (do=show):
- โข
from- Start date (YYYY-MM-DD) - โข
to- End date (YYYY-MM-DD) - โข
chooseEmp- Employee ID (optional) - โข
isAbsent- Absence filter (0=present, 1=absent, null=all)
---
๐ Security & Permissions
Authentication Requirements
include_once("../public/authentication.php");
- โข All actions require valid user session
- โข Authentication check on every function call
- โข Session-based user identification
Branch-Level Access Control
if ($_SESSION['branchId'] > 0)
$queryString = ' AND branchid = ' . $_SESSION['branchId'];
Access Levels:
- โข Branch Manager: Can see all employees in their branch only
- โข Super Admin: Can see employees across all branches
- โข Regular User: Subject to branch restrictions
Input Sanitization
- โข All
$_REQUESTparameters filtered through framework - โข Numeric IDs validated and cast to integers
- โข Date strings validated before SQL inclusion
- โข SQL injection prevented by DAO layer
---
๐ Common Issues & Troubleshooting
1. Time Zone Variable Bug
Issue: Line 109 references undefined $Programsettingdata
Location: Line 109-112
Problem Code:
if (isset($Programsettingdata->reportsPlusHours) && !empty($Programsettingdata->reportsPlusHours)) {
Fix:
if (isset($Programsetting->reportsPlusHours) && !empty($Programsetting->reportsPlusHours)) {
2. Duplicate Query Execution
Issue: Lines 132 and 134 execute similar queries
Problem: Inefficient database calls
Fix: Remove redundant query on line 132:
// Remove this line:
// $employes = $employeeEX->queryAllString($startDate, $endDate);
// Keep only this line:
$employes = $employeeEX->queryAllByIdAndDate($queryString,$isAbsent);
3. Missing Employee Data
Issue: Reports show no employees when branch filtering is too restrictive
Debug Steps:
1. Check $_SESSION['branchId'] value
2. Verify employee.branchid assignments in database
3. Test query without branch filter
4. Date Format Issues
Issue: Time zone adjustments fail with invalid date formats
Solution:
// Validate date format before processing
if (!empty($startDate) && strtotime($startDate) !== false) {
// Safe to process
}
---
๐ Performance Considerations
Database Optimization
1. Required Indexes:
- employee(branchid, employeeDate)
- employee(employeeId, employeeDate)
- employeeattendance(employeeId, employeeDate)
2. Query Optimization:
- Use specific date ranges to limit result sets
- Apply branch filtering early in queries
- Consider pagination for large employee counts
Memory Usage
- โข Large date ranges can return thousands of records
- โข Consider implementing pagination for reports > 100 employees
- โข Cache employee dropdown data for repeated usage
---
๐งช Testing Scenarios
Test Case 1: Default Daily Report
1. Access controller without parameters
2. Verify current date is used
3. Check that branch filtering is applied
4. Confirm employee list is populated
5. Validate time zone adjustments
Test Case 2: Date Range Filtering
1. Specify custom from/to dates
2. Test with various date formats
3. Verify time zone handling
4. Check edge cases (same day, future dates)
5. Test with empty date ranges
Test Case 3: Employee Specific Report
1. Select specific employee from dropdown
2. Verify attendance data is employee-specific
3. Test with employees from different branches
4. Check absence status filtering
Test Case 4: Branch Restrictions
1. Login as branch-restricted user
2. Verify only branch employees appear
3. Test as super admin (all branches)
4. Check query string construction
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข employeeController.md - Employee management
- โข employeeAttendance.md - Attendance tracking
- โข Database Schema Documentation - Table relationships
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur