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:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

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

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

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

โ”Œโ”€ Load Data โ”€โ”
โ€ข Week days
โ€ข Countries
โ€ข Religions
โ€ข Groups
โ€ข Branches
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Assign to Template โ”€โ”
employeeview/add.html
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Show Employee List

elseif ($_GET['do'] == "show") // Line 167

- txtSearch (string): Employee name search

- Branch filtering from session

โ”Œโ”€ Check Search โ”€โ”
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Apply Filters โ”€โ”
โ€ข Name search
โ€ข Branch filter
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Query Database โ”€โ”
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Edit Employee

elseif ($_GET['do'] == "edit") // Line 217

- id (int): Employee ID to edit

โ”Œโ”€ Load Employee โ”€โ”
employeeDAO->
load($id)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Branch Security โ”€โ”
Check branchId
permissions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Load Attendance โ”€โ”
Schedule & Groups
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Business Functions

add() Function

function add() // Line 289

- 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

โ”Œโ”€ Validate Input โ”€โ”
โ€ข File uploads
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Upload Documents โ”€โ”
โ€ข Contract
โ€ข Personal photo
โ€ข ID cards
โ€ข Certificates
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Calculate Costs โ”€โ”
minuteLateCost =
(salary+allow)/
(days*hours*60)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Create Accounting โ”€โ”
โ€ข Advance account
โ€ข Employee account
addTreeElement()
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Save Employee โ”€โ”
employeeDAO->
insert()
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Setup Schedule โ”€โ”
system setup
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

// 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

- Salary change history tracking via savesalaryChangeRecord()

- Document update with old file cleanup

- Attendance schedule updates

- Accounting tree updates

โ”Œโ”€ Load Current โ”€โ”
Employee data
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Track Changes โ”€โ”
Record()
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Update Files โ”€โ”
โ€ข Replace docs
โ€ข Delete old
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Update Database โ”€โ”
employeeDAO->
update()
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Update Accounting โ”€โ”
Tree element names
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

delete() Function

function delete() // Line 915

- id (GET): Employee ID

- conditions (GET): Delete status

โ”Œโ”€ Mark Deleted โ”€โ”
conditions = 1
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Update Record โ”€โ”
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Remove Accounting โ”€โ”
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

savesalaryChangeRecord() Function

function savesalaryChangeRecord($employeeId, $oldSalary, $newSalary, $changeReason = '') // Line 941

- $employeeId (int): Employee identifier

- $oldSalary (float): Previous salary amount

- $newSalary (float): New salary amount

- $changeReason (string): Optional reason for change

โ”Œโ”€ Compare Values โ”€โ”
old == new?
return if same
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Create Record โ”€โ”
โ€ข Type 15
โ€ข Done = 0
โ€ข Current month
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Save to Personnel โ”€โ”
employeepersonnel
table
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐Ÿ”„ Business Logic Flow

Employee Creation Workflow

โ”Œโ”€ START: Add Employee โ”€โ”
โ–ผ
โ”Œโ”€ Validate Required โ”€โ” โ”‚
โ€ข Name
โ€ข Branch
โ€ข Basic info
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ–ผ
โ”Œโ”€ Process Documents โ”€โ”โ”‚
โ€ข Contract
โ€ข ID cards
โ€ข Certificates
โ€ข Photos
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Calculate Rates โ”€โ” โ”‚
โ€ข Minute cost
โ€ข Absence cost
โ€ข Based on salary
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ–ผ
โ”Œโ”€ Setup Accounting โ”€โ”โ”‚
โ€ข Advance account
โ€ข Employee ledger
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Configure Schedule โ”โ”‚
โ€ข 7-day setup
โ€ข Attendance times
โ€ข Departure times
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Save Employee โ”€โ”€โ”€โ”€โ”โ”‚
Database insert
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ END: Return ID โ”€โ”€โ”€โ”˜

Salary Change Tracking

โ”Œโ”€ Salary Update โ”€โ”
โ–ผ
โ”Œโ”€ Compare Values โ”โ”‚
old != new?
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Create History โ”โ”‚
โ€ข Old amount
โ€ข New amount
โ€ข Change date
โ€ข User ID
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Save Record โ”€โ”€โ”โ”‚
Type 15
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Update Employee โ”˜
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

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

Required DAOs

Related Controllers

Template Files

Key HR Features