๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

Employee Personal AJAX Controller Documentation

File: /controllers/employeePersonalajex.php

Purpose: AJAX endpoint for employee personal financial operations including salary calculations and departmental debt management

Last Updated: December 20, 2024

Total Functions: 3+

Lines of Code: ~188

---

๐Ÿ“‹ Overview

The Employee Personal AJAX Controller is a lightweight API endpoint that provides real-time employee financial data and calculations for other controllers and AJAX requests. It serves:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Read Operations)

Table NamePurposeKey Columns
**employee**Employee master data with financial infoemployeeId, employeeName, employeeSalary, employeeBouns, empdept, Reward, Discount, Withdraw, Absence, Repayment, permission, allLeave
**employeepersonnel**Employee financial transactionsid, empName, empValue, type, employeepersonneldate
**employeeclosedayhistory**Daily attendance trackingid, employeeid, day, isAbsent, del
### Financial Calculation Fields

Field NamePurposeType
**employeeSalary**Base monthly salaryDecimal
**employeeBouns**Regular bonusesDecimal
**empdept**Employee debt balanceDecimal
**Reward**Rewards and incentivesDecimal
**Discount**Penalties and discountsDecimal
**Withdraw**Cash withdrawals/advancesDecimal
**Absence**Absence penalty totalsDecimal
**Repayment**Debt repaymentsDecimal
**permission**Permission-based deductionsDecimal
**allLeave**Leave-related deductionsDecimal
### Reference Tables

Table NamePurposeKey Columns
**save**Cash registers and safessaveid, savename, savevalue
**salaryreport**Salary calculation summariesid, employeeId, month, year
---

๐Ÿ”‘ Key Functions

1. getdeptbefor() - Retrieve Employee Debt

Location: Line 104

Purpose: Get current departmental debt amount for specific employee

Function Signature:

// Triggered when: do=getdeptbefor
$id = $_GET["id"];  // Employee ID

Process Flow:

1. Get employee ID from request parameter

2. Load employee record using DAO

3. Return departmental debt amount

4. Simple text response (not JSON)

Implementation:

$id = $_GET["id"];
$myempdata = $empDao->load($id);
echo $myempdata->empdept;

Features:

---

2. absentEmploye() - List Absent Employees

Location: Line 113

Purpose: Return list of employees who were absent on a specific date

Function Signature:

// Triggered when: do=absentEmploye
$id = filter_input(INPUT_POST, 'id');  // Date string

Process Flow:

1. Receive date from POST parameter

2. Query employees absent on that date

3. Format results as JSON array

4. Return employee list for processing

Implementation:

$id = filter_input(INPUT_POST, 'id');
$employes = $empEX->queryAllFromdayhistoty($id);
echo json_encode($employes);

Features:

---

3. getNetSalary() - Comprehensive Salary Calculation

Location: Line 122

Purpose: Calculate net salary with comprehensive breakdown of all financial components

Function Signature:

// Triggered when: do=getNetSalary  
$id = $_GET["id"];  // Employee ID

Process Flow:

1. Employee Data Loading: Load complete employee financial record

2. Null Validation: Set null values to 0 for calculations

3. Component Assembly: Build all salary components

4. Net Calculation: Apply formula for final net salary

5. Response Formatting: Return net salary and current debt

Comprehensive Null Handling:

if ($allsalarys->employeeBouns == null || $allsalarys->employeeBouns == "") {
    $allsalarys->employeeBouns = 0;
}
if ($allsalarys->empdept == null || $allsalarys->empdept == "" || $allsalarys->empdept == 0) {
    $allsalarys->empdept = 0;
}
// ... continues for all financial fields

Salary Calculation Formula:

$total = (($allsalarys->employeeBouns) + ($allsalarys->Reward) + ($allsalarys->employeeSalary)) -
         (($allsalarys->Discount) + ($allsalarys->Withdraw) + ($allsalarys->Absence) + 
          ($allsalarys->Repayment) + ($allsalarys->permission) + ($allsalarys->allLeave));

$currentDebt = ($allsalarys->empdept) - ($allsalarys->Repayment);
echo $total . "*" . $currentDebt;  // Returns "netSalary*currentDebt"

Financial Components:

- Base salary (employeeSalary)

- Regular bonuses (employeeBouns)

- Rewards and incentives (Reward)

- Penalties and discounts (Discount)

- Cash withdrawals (Withdraw)

- Absence penalties (Absence)

- Debt repayments (Repayment)

- Permission-based deductions (permission)

- Leave-related deductions (allLeave)

- Current debt = Original debt - Repayments

- Net salary excludes debt balance

- Both values returned for frontend processing

---

๐Ÿ”„ Workflows

Workflow 1: Real-time Debt Checking

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Check Employee Debt
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Receive AJAX Request
- GET parameter with employee ID
- Called from frontend forms/interfaces
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Load Employee Record
- Direct DAO lookup by employee ID
- Access departmental debt field
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Return Debt Amount
- Plain text response for quick integration
- Used by forms to display current debt
- Enables real-time debt validation
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

Workflow 2: Comprehensive Salary Calculation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Calculate Net Salary
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Load Complete Employee Financial Data
- Get employee ID from request
- Load all financial fields from employee table
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Validate and Normalize Data
- Check each financial field for null/empty values
- Set null values to 0 for safe calculations
- Prepare all components for mathematical operations
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Calculate Income Components
- Base Salary: employeeSalary
- Regular Bonuses: employeeBouns
- Rewards: Reward
- Total Income = Salary + Bonuses + Rewards
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Calculate Deduction Components
- Penalties: Discount
- Withdrawals: Withdraw
- Absences: Absence
- Repayments: Repayment
- Permission Deductions: permission
- Leave Deductions: allLeave
- Total Deductions = Sum of all deduction types
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Calculate Final Amounts
- Net Salary = Total Income - Total Deductions
- Current Debt = Original Debt - Repayments
- Format: "netSalary*currentDebt"
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
6Return Calculated Results
- Send formatted string response
- Frontend parses for display/processing
- Used for payroll and financial planning
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=getdeptbefor`Debt lookupGet employee departmental debt amount
`do=absentEmploye`Absent listGet employees absent on specific date
`do=getNetSalary`Salary calculationCalculate comprehensive net salary
### Required Parameters by Action

Get Debt (do=getdeptbefor):

Absent Employees (do=absentEmploye):

Net Salary (do=getNetSalary):

---

๐Ÿงฎ Calculation Methods

Debt Amount Retrieval

$myempdata = $empDao->load($id);
echo $myempdata->empdept;  // Direct field access

Net Salary Formula

// Income components
$income = $employeeSalary + $employeeBouns + $Reward;

// Deduction components  
$deductions = $Discount + $Withdraw + $Absence + $Repayment + $permission + $allLeave;

// Final calculation
$netSalary = $income - $deductions;
$currentDebt = $empdept - $Repayment;

// Response format
echo $netSalary . "*" . $currentDebt;

Null Value Normalization

$value = ($field == null || $field == "" || $field == 0) ? 0 : $field;

---

๐Ÿ”’ Security & Permissions

Session Management

Input Validation

Data Access

---

๐Ÿ“Š Performance Considerations

Database Optimization

1. Single Queries: Each function performs one targeted query

2. Direct Loads: Uses DAO load() method for ID-based access

3. No Joins: Simple table access without complex joins

Response Efficiency

1. Lightweight Responses: Plain text or minimal JSON

2. No Template Processing: Direct echo responses

3. Fast Calculations: In-memory mathematical operations

Known Performance Issues

---

๐Ÿ› Common Issues & Troubleshooting

1. Empty/Null Salary Components

Issue: Calculation returns NaN or incorrect values

Cause: Database fields containing NULL or empty strings

Solution: Comprehensive null checking implemented:

if ($allsalarys->employeeBouns == null || $allsalarys->employeeBouns == "") {
    $allsalarys->employeeBouns = 0;
}

2. Session Not Available

Issue: Session data not accessible to AJAX calls

Cause: Session not properly started or expired

Debug:

session_start();
if (!isset($_SESSION['userid'])) {
    echo "Session expired";
    exit;
}

3. Employee Not Found

Issue: DAO load returns null/empty object

Cause: Invalid employee ID or deleted employee

Protection:

$myempdata = $empDao->load($id);
if (!$myempdata) {
    echo "0";  // Return safe default
    exit;
}

4. Calculation Overflow

Issue: Very large salary amounts cause calculation errors

Solution: Use appropriate data types and validation:

$total = (float) $income - (float) $deductions;

---

๐Ÿงช Testing Scenarios

Test Case 1: Debt Amount Retrieval

1. Create employee with known debt amount
2. Call getdeptbefor with employee ID
3. Verify returned value matches database
4. Test with employee ID = 0 (invalid)
5. Test with non-existent employee ID

Test Case 2: Absent Employee Listing

1. Create test employees with attendance records
2. Mark some as absent for specific date
3. Call absentEmploye with test date
4. Verify JSON response contains correct employees
5. Test with date having no absences
6. Test with invalid date format

Test Case 3: Net Salary Calculation

1. Create employee with all salary components populated
2. Test calculation with positive values
3. Test with null/empty fields
4. Test with negative values (debt scenarios)
5. Verify response format (netSalary*currentDebt)
6. Test edge cases (very large numbers)

Test Case 4: Session and Security

1. Test calls without valid session
2. Verify session data access
3. Test with expired sessions
4. Check SQL injection protection
5. Validate input parameter handling

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur

โ†‘