EmployeePersonal Documentation

Employee Personal Controller Documentation

File: /controllers/employeePersonalController.php

Purpose: Manages employee financial transactions, loans, advances, deductions, and rewards

Last Updated: December 19, 2024

Total Functions: 13

Lines of Code: ~1285

---

๐Ÿ“‹ Overview

The Employee Personal Controller is the core component for managing all employee financial transactions beyond basic salary. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
`employeepersonnel`Employee financial transactions`employeeid`, `employeepersonneltype`, `employeepersonnelvalue`, `empdeptbefor`, `empdeptafter`
`employee`Employee debt tracking`employeeId`, `empdept`, `employeeName`
`save`Cash accounts for payments`saveid`, `savename`, `savevalue`, `treeId`
`savedaily`Daily cash movements`saveid`, `savedailychangeamount`, `savedailychangetype`
`salaryreport`Salary payment records`employeeid`, `salarymonth`, `salaryreportnet`
### Related Tables (References)

Table NamePurposeKey Columns
`dailyentry`Accounting journal entries`dailyentryid`, `entryComment`, `thedate`
`dailyentrycreditor`Credit side of entries`dailyentryid`, `accountstreeid`, `value`
`dailyentrydebtor`Debit side of entries`dailyentryid`, `accountstreeid`, `value`
`costcenter`Cost center allocation`costcenterid`, `costcentername`
`costcenterdetail`Cost center transaction details`costcenterid`, `modelid`, `costamount`
`bankaccount`Bank account information`bankaccountid`, `treeId`, `accountname`
### Reference Tables (Lookups)

Table NamePurposeKey Columns
`programsettings`System configuration`settingName`, `settingValue`
`bank`Bank master data`bankid`, `bankname`
`user`User information for audit`userid`, `username`, `saveids`
`branch`Branch filtering`branchId`, `branchName`
---

๐Ÿ”ง Key Functions

Transaction Type Constants

// Employee Personnel Transaction Types
const TRANSACTION_TYPES = [
    1 => 'Bonus/Reward',           // ู…ูƒุงูุฃุฉ
    2 => 'Deduction/Fine',         // ุฎุตู…/ุบุฑุงู…ุฉ  
    3 => 'Withdrawal',             // ุณุญุจ
    4 => 'Advance/Loan',           // ุณู„ูุฉ
    5 => 'Absence Deduction',      // ุฎุตู… ุบูŠุงุจ
    6 => 'Loan Repayment',         // ุณุฏุงุฏ ุณู„ูุฉ
    7 => 'Permission Deduction',   // ุฎุตู… ุฅุฐู†
    8 => 'Debt Adjustment',        // ุชุนุฏูŠู„ ุฑุตูŠุฏ
    9 => 'Late Penalty',           // ุฎุตู… ุชุฃุฎูŠุฑ
    10 => 'Salary Receipt',        // ู‚ุจุถ ุฑุงุชุจ
    11 => 'Extra Allowance',       // ุจุฏู„ ุฅุถุงููŠ
    12 => 'Overtime',              // ุฅุถุงููŠ
    13 => 'Holiday Work',          // ุนู…ู„ ุนุทู„ุฉ
    14 => 'Leave Deduction',       // ุฎุตู… ุฅุฌุงุฒุฉ
    15 => 'Salary Change Record'   // ุชุณุฌูŠู„ ุชุบูŠูŠุฑ ุฑุงุชุจ
];

Main Controller Actions

Default Action (Transaction Entry Form)

if (!isset($_GET['do'])) // Line 179

โ”Œโ”€ Load Form Data โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ€ข Cost centers
โ€ข Cash accounts
โ€ข Bank accounts
โ€ข Active employees
โ€ข Current date/time
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Apply Branch Filter โ”€โ”
Filter employees by
user's branch access
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Display Form โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
employeePersonalview/
add.html
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Add Transaction

elseif ($do == "add") // Line 203

- type: Transaction type (1-15)

- empName: Employee ID

- empValue: Transaction amount

- paymethod: Payment method (0=cash, 1=bank)

- employeepersonneldate: Transaction date

- desc: Transaction description

- saveid: Cash account ID (if cash payment)

- bankid, bankaccountid, checkNo: Bank details (if bank payment)

- Costcenterid: Cost center for allocation

- netSalary: Employee's current net salary

โ”Œโ”€ Determine Transaction โ”€โ”
Type and validation
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Check Net Salary โ”€โ”€โ”€โ”€โ”€โ”
validate against
available net salary
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Split Transaction โ”€โ”€โ”€โ”€โ”
If amount > net salary:
โ€ข Current month part
โ€ข Next month part
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Process Payment โ”€โ”€โ”€โ”€โ”€โ”€โ”
Call add() function
with transaction data
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Generate Receipt โ”€โ”€โ”€โ”€โ”€โ”
Optional print receipt
or redirect to success
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Business Functions

add() Function

function add($employeepersonnelvalue, $saveInNextMonth = 0, $paymethod = 0, 
    $employeepersonneltype = 0, $deviceid = '01', $employeeid, 
    $employeepersonneldate, $userid = 0, $saveid = 0) // Line 826

- $employeepersonnelvalue: Transaction amount

- $saveInNextMonth: Flag for next month processing

- $paymethod: Payment method (0=cash, 1=bank)

- $employeepersonneltype: Transaction type

- $deviceid: Device/source identifier

- $employeeid: Employee ID

- $employeepersonneldate: Transaction date

- $userid: User performing transaction

- $saveid: Cash/bank account ID

โ”Œโ”€ Setup Transaction โ”€โ”€โ”€โ”€โ”
โ€ข Create personnel rec
โ€ข Set basic details
โ€ข Determine payment
method details
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Update Employee Debt โ”€โ”
For debt-affecting
transaction types:
โ€ข Advances (type 4)
โ€ข Repayments (type 6)
โ€ข Debt adjustments
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Process Payment โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ€ข Update cash/bank
account balances
โ€ข Create daily cash
movement records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Cost Center Allocationโ”
If cost center
specified, create
allocation record
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Generate Accounting โ”€โ”€โ”
Create daily entry
with appropriate
debits and credits
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

// Advance/Loan (Type 4)
if ($employeepersonneltype == 4) {
    $empdeptafter = $empdept + $employeepersonnelvalue;
}
// Loan Repayment (Type 6) 
elseif ($employeepersonneltype == 6) {
    $empdeptafter = $empdept - $employeepersonnelvalue;
}
// Debt Adjustment (Type 8)
elseif ($employeepersonneltype == 8) {
    $empdeptafter = $employeepersonnelvalue; // Set absolute value
}

show() Function

function show() // Line 458

- Date range filtering

- Employee-specific filtering

- Transaction type filtering

- Branch-based security

- Pagination support

delete() Function

function delete() // Line 742

โ”Œโ”€ Load Transaction โ”€โ”€โ”€โ”€โ”€โ”
Get original personnel
record details
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Reverse Debt Impact โ”€โ”€โ”
Update employee debt
to pre-transaction
amount
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Reverse Payment โ”€โ”€โ”€โ”€โ”€โ”€โ”
Add/subtract amount
back to cash/bank
account
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Reverse Accounting โ”€โ”€โ”€โ”
Cancel daily entry
and related records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€ Mark as Deleted โ”€โ”€โ”€โ”€โ”€โ”€โ”
Set conditions = 1
(soft delete)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

curlAddSalary() Function

function curlAddSalary($empid, $salarymonthdate, $Costcenterid) // Line 1261

getEmployeeNetSalary() Function

function getEmployeeNetSalary($id) // Line 1135

Net Salary = Base Salary + Bonuses + Allowances 
           - (Existing Advances + Deductions + Taxes)
           - Already Withdrawn This Month

Utility Functions

Cash Management Functions

function getSaveValueBefore($saveid)           // Get current balance
function updateSave($saveid, $savevalueafter)  // Update account balance
function insertSavedaily(...)                 // Record cash movement

doEmployeePersonalDailyEntry() Function

function doEmployeePersonalDailyEntry($EmployeepersonnelId) // Line 1194

Advance (Type 4):
Dr: Employee Advance Account
Cr: Cash/Bank Account

Repayment (Type 6):  
Dr: Cash/Bank Account
Cr: Employee Advance Account

Bonus (Type 1):
Dr: Employee Account
Cr: Cash/Bank Account

Deduction (Type 2):
Dr: Cash/Bank Account  
Cr: Employee Account

---

๐Ÿ”„ Business Logic Flow

Employee Advance Processing Workflow

โ”Œโ”€ START: Employee Advance โ”€โ”
โ–ผ
โ”Œโ”€ Employee Requests โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
Advance amount
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Check Net Salary โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
Available balance for
advance (current month)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Split if Necessary โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
If amount > net salary:
โ€ข Part from current month
โ€ข Part from next month
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Update Employee Debt โ”€โ”€โ”€โ”€โ”โ”‚
empdept += advance_amount
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Process Payment โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
โ€ข Deduct from cash/bank
โ€ข Create payment record
โ€ข Generate receipt
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Create Accounting โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
Dr: Employee Advance A/c
Cr: Cash/Bank Account
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Cost Center Allocation โ”€โ”€โ”โ”‚
If specified, allocate
to department/project
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ END: Advance Processed โ”€โ”€โ”€โ”˜

Loan Repayment Processing

โ”Œโ”€ START: Loan Repayment โ”€โ”€โ”€โ”
โ–ผ
โ”Œโ”€ Employee Payment โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
Repayment amount
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Validate Amount โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
Check against outstanding
loan balance
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Receive Payment โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
โ€ข Record transaction
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Update Employee Debt โ”€โ”€โ”€โ”€โ”โ”‚
empdept -= repayment_amt
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ Create Accounting โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
Dr: Cash/Bank Account
Cr: Employee Advance A/c
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ–ผ
โ”Œโ”€ END: Repayment Complete โ”€โ”˜

Multi-Month Advance Logic

โ”Œโ”€ Month 1 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Amount: $600
Source: Current
Net Salary
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€ Month 2 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Amount: $400
Source: Next
Month Salary
Flag: saveInNext
Month = 1
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

โš ๏ธ Common Issues

Known Bugs & Limitations

1. Salary Validation Logic

- Issue: Complex validation logic for advance amounts vs net salary

- Location: Lines 233-241

- Impact: May allow advances exceeding available salary in some cases

- Solution: Implement more robust salary validation

2. Transaction Splitting

- Issue: Multi-month transaction splitting may cause confusion

- Location: add() function processing

- Impact: Employees may not understand why advance is split

- Solution: Add clear communication about split transactions

3. Debt Calculation Race Conditions

- Issue: Multiple concurrent transactions may cause debt calculation errors

- Location: Employee debt update operations

- Impact: Incorrect debt balances

- Solution: Implement transaction locking or atomic operations

4. Payment Method Validation

- Issue: Insufficient validation for bank account details

- Location: Bank payment processing

- Impact: Invalid bank transactions may be recorded

- Solution: Add comprehensive bank account validation

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 financial calculations

- Safe array handling for transaction data

---

๐Ÿ”— Dependencies

Required Files

Required DAOs

Related Controllers

Template Files

Key Financial Features