Employee Documentation
Employee Controller Documentation
File: /controllers/employeeController.php
Purpose: Manages employee records, personal data, attendance systems, and employee lifecycle
Last Updated: December 19, 2024
Total Functions: 4
Lines of Code: ~986
---
๐ Overview
The Employee Controller is the core component for managing employee-related operations in the ERP system. It handles:
- โข Creating and editing employee profiles
- โข Managing employee personal information and documents
- โข Setting up employee attendance systems and schedules
- โข Tracking salary changes and employment history
- โข Handling employee groups and subgroups
- โข Managing employee documents and file uploads
- โข Calculating salary-related metrics (minute costs, absence costs)
- โข Branch-based employee access control
Primary Functions
- โ Create new employee profiles
- โ Edit existing employee data
- โ Delete employee records
- โ View employee listings with search
- โ Upload employee documents (contracts, ID cards, etc.)
- โ Set up weekly attendance schedules
- โ Calculate salary breakdowns and costs
- โ Track salary change history
- โ Manage employee groups and subgroups
- โ Branch-based employee filtering
Related Controllers
- โข salaryReportController.php - Salary calculations and reports
- โข EmployeeAttendanceController.php - Daily attendance tracking
- โข employeePersonalController.php - Employee loans and advances
- โข clientController.php - Customer management
- โข supplierController.php - Supplier management
- โข dailyentry.php - Accounting entries
- โข accountstree.php - Chart of accounts
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `employee` | Main employee records | `employeeId`, `employeeName`, `employeeSalary`, `branchid` | |
| `employeegroup` | Employee group categorization | `id`, `groupName`, `employeeattendancesystemid` | |
| `employeesubgroup` | Employee sub-categorization | `id`, `subgroupName`, `employeegroupid` | |
| `employeepersonnel` | Employee transactions/history | `employeeid`, `employeepersonneltype`, `employeepersonnelvalue` | |
| `employeeattendancesystemweek` | Weekly attendance schedule | `employee_id`, `attendancedaynum`, `attendancetime` |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `accountstree` | Employee accounting entries | `id`, `customName`, `parentId` | |
| `user` | System users linked to employees | `userid`, `username` | |
| `country` | Employee nationality | `id`, `countryName` | |
| `religions` | Employee religion | `id`, `religionName` | |
| `branch` | Employee branch assignment | `branchId`, `branchName` |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `employeeattendancesystem` | Attendance system templates | `id`, `systemName` | |
| `programsettings` | System configuration | `settingName`, `settingValue` |
๐ง Key Functions
Main Controller Actions
Default Action (Show Add Form)
if (!isset($_GET['do'])) // Line 121
- โข Purpose: Display employee add form with necessary data
- โข Parameters: None (GET request)
- โข Process Flow:
Show Employee List
elseif ($_GET['do'] == "show") // Line 167
- โข Purpose: Display filtered list of employees
- โข Parameters:
- txtSearch (string): Employee name search
- Branch filtering from session
- โข Process Flow:
Edit Employee
elseif ($_GET['do'] == "edit") // Line 217
- โข Purpose: Load employee data for editing
- โข Parameters:
- id (int): Employee ID to edit
- โข Security: Branch access validation
- โข Process Flow:
Core Business Functions
add() Function
function add() // Line 289
- โข Purpose: Create new employee with full data processing
- โข Parameters (from $_POST):
- empName: Employee name (required)
- empSalary: Base salary amount
- empBouns: Bonus amount
- houseAllowance: Housing allowance
- transportationAllowance: Transport allowance
- noOfWorkDaysPerMonth: Working days per month
- noOfWorkHoursDaysPerDay: Working hours per day
- socialInsurance: Social insurance percentage
- workTax: Work tax percentage
- branchid: Branch assignment
- Multiple file uploads for documents
- Attendance schedule for 7 days
- โข Return: Employee ID (int)
- โข Process Flow:
- โข Code Example:
// Salary cost calculations
$bast = $employee->employeeSalary + $employee->houseAllowance + $employee->transportationAllowance;
$makam = $employee->noOfWorkDaysPerMonth * $employee->noOfWorkHoursDaysPerDay * 60;
if ($makam != 0) {
$employee->minuteLateCost = round(($bast / $makam), 3);
}
// Create accounting entries
$treeId1 = addTreeElement("ุณููุฉ $employee->employeeName", 63, 1, 0, 1);
$treeId2 = addTreeElement($employee->employeeName, 97, 1, 0, 1);
update() Function
function update() // Line 576
- โข Purpose: Update existing employee with change tracking
- โข Parameters: Similar to add() plus
employeeId - โข Key Features:
- Salary change history tracking via savesalaryChangeRecord()
- Document update with old file cleanup
- Attendance schedule updates
- Accounting tree updates
- โข Process Flow:
delete() Function
function delete() // Line 915
- โข Purpose: Soft delete employee (mark as deleted)
- โข Parameters:
- id (GET): Employee ID
- conditions (GET): Delete status
- โข Process Flow:
savesalaryChangeRecord() Function
function savesalaryChangeRecord($employeeId, $oldSalary, $newSalary, $changeReason = '') // Line 941
- โข Purpose: Track salary changes for audit purposes
- โข Parameters:
- $employeeId (int): Employee identifier
- $oldSalary (float): Previous salary amount
- $newSalary (float): New salary amount
- $changeReason (string): Optional reason for change
- โข Process Flow:
---
๐ Business Logic Flow
Employee Creation Workflow
Salary Change Tracking
Cost Calculation Logic
Total Compensation = Base Salary + House Allowance + Transportation Allowance
Minute Late Cost = Total Compensation / (Work Days ร Work Hours ร 60 minutes)
Day Absence Cost = Total Compensation / (Work Days ร Absence Days Factor)
---
โ ๏ธ Common Issues
Known Bugs & Limitations
1. File Upload Issues
- Issue: Unlink operations may fail if files don't exist
- Location: Lines 640-727 in update()
- Impact: PHP warnings when updating documents
- Solution: Add file_exists() checks before unlink()
2. Duplicate Code
- Issue: Army photo upload duplicated
- Location: Lines 694-696 in update()
- Impact: Redundant processing
- Solution: Remove duplicate block
3. Missing Validation
- Issue: No validation for required fields in frontend
- Impact: Database errors if critical fields are empty
- Solution: Add proper validation before processing
4. Branch Security
- Issue: Branch filtering can be bypassed in some queries
- Location: Various query functions
- Impact: Users might see employees from other branches
- Solution: Ensure consistent branch filtering
PHP 8.2 Compatibility
1. Object Initialization
- All objects properly initialized before property assignment
- No "attempt to assign property on null" errors
2. Type Safety
- Proper float casting for numeric fields
- Safe array handling for POST data
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core operations - โข
../public/config.php- Database configuration - โข
../public/include_dao.php- DAO includes - โข
../library/uploadImages.php- File upload handling - โข
dailyentryfun.php- Daily entry functions
Required DAOs
- โข
EmployeeDAO- Main employee operations - โข
EmployeeMySqlExtDAO- Extended employee queries - โข
EmployeegroupDAO- Employee group management - โข
EmployeesubgroupDAO- Sub-group management - โข
EmployeepersonnelDAO- Employee history/transactions - โข
UserDAO- User management - โข
CountryDAO- Country lookup - โข
ReligionsMySqlDAO- Religion lookup - โข
YoutubeLinkDAO- Training video links
Related Controllers
- โข Must work in coordination with attendance systems
- โข Integrates with payroll processing
- โข Links to accounting system through tree elements
- โข Connects to branch-based security system
Template Files
- โข
employeeview/add.html- Add employee form - โข
employeeview/edit.html- Edit employee form - โข
employeeview/show.html- Employee listing - โข
succes.html- Success message - โข
error.html- Error message
Key HR Features
- โข Salary Management: Base salary, allowances, bonuses tracking
- โข Document Management: 15+ document types (contract, ID, passport, etc.)
- โข Attendance Integration: 7-day schedule setup with flexible timing
- โข Cost Calculations: Automatic minute and day absence cost computation
- โข Change Tracking: Complete salary change audit trail
- โข Branch Security: Multi-branch organization support
- โข Group Management: Hierarchical employee categorization