Salary Report Controller Documentation
File: /controllers/salaryReportController.php
Purpose: Manages salary calculations, payroll reports, and salary payment processing
Last Updated: December 19, 2024
Total Functions: 10
Lines of Code: ~975
---
๐ Overview
The Salary Report Controller is the core component for managing payroll operations in the ERP system. It handles:
- โข Monthly salary calculations and reports
- โข Employee salary entitlements and deductions
- โข Payroll payment processing and receipts
- โข Salary history tracking and management
- โข Integration with accounting system for payroll entries
- โข Cost center allocation for salary expenses
- โข Multi-branch payroll support
- โข Advanced salary calculations with bonuses, deductions, and previous balances
Primary Functions
- โ Generate monthly salary reports
- โ Calculate employee net pay with all components
- โ Process salary payments and receipts
- โ Track salary history and changes
- โ Generate payroll accounting entries
- โ Handle salary advances and deductions
- โ Print salary slips and reports
- โ Support multi-branch payroll
- โ Cost center allocation for payroll
- โ Excel export capabilities
Related Controllers
- โข employeeController.php - Employee management
- โข EmployeeAttendanceController.php - Attendance tracking
- โข employeePersonalController.php - Employee loans and advances
- โข dailyentry.php - Accounting entries
- โข saveController.php - Cash/bank management
- โข accountstree.php - Chart of accounts
- โข costcenterController.php - Cost center management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `salaryreport` | Monthly salary reports | `salaryreportid`, `employeeid`, `salarymonth`, `salaryreportnet` | |
| `employeepersonnel` | Employee transactions/deductions | `employeeid`, `employeepersonneltype`, `employeepersonnelvalue` | |
| `employee` | Employee master data | `employeeId`, `employeeName`, `employeeSalary`, `treeId2` | |
| `save` | Cash/bank accounts for payment | `saveid`, `savename`, `savevalue` | |
| `savedaily` | Daily cash movements | `saveid`, `savedailychangeamount`, `savedailychangetype` |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `dailyentry` | Payroll accounting entries | `dailyentryid`, `entryComment`, `thedate` | |
| `dailyentrycreditor` | Credit side of entries | `dailyentryid`, `accountstreeid`, `value` | |
| `dailyentrydebtor` | Debit side of entries | `dailyentryid`, `accountstreeid`, `value` | |
| `accountstree` | Chart of accounts | `id`, `customName`, `parentId` | |
| `costcenter` | Cost center allocation | `costcenterid`, `costcentername` | |
| `costcenterdetail` | Cost center details | `costcenterid`, `accountstreeid`, `value` |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `programsettings` | System configuration | `settingName`, `settingValue` | |
| `user` | User preferences for saves | `userid`, `saveids`, `searchinonesave` | |
| `branch` | Branch-based payroll | `branchId`, `branchName` |
๐ง Key Functions
Main Controller Actions
Default Action (Salary Report View)
if (!isset($_GET['do'])) // Line 168
- โข Purpose: Display monthly salary calculation report
- โข Parameters:
- from (POST): Salary month (YYYY-MM format)
- โข Process Flow:
Show Finalized Salaries
elseif ($do == "show") // Line 260
- โข Purpose: Display employees who received their salaries
- โข Function Call:
show() - โข Template:
salaryReportview/showfinsh.html
Edit Print Receipt
elseif ($do == "editprint") // Line 267
- โข Purpose: Edit and print salary receipt
- โข Function Call:
editprint() - โข Template:
salaryReportview/editprint.html
Process Receipt Payment
elseif ($do == "Receipt") // Line 274
- โข Purpose: Process salary payment receipt
- โข Function Call:
Receipt() - โข Support: CURL requests and normal requests
- โข Returns: 1 on success, -1 on error
Core Business Functions
show() Function
function show() // Line 506
- โข Purpose: Retrieve and display finalized salary payments
- โข Process Flow:
Receipt() Function
function Receipt() // Line 584
- โข Purpose: Process employee salary payment with full accounting integration
- โข Parameters (from $_POST):
- empIds[]: Array of employee IDs
- amounts[]: Corresponding payment amounts
- salarymonthdate: Payment month
- saveid: Payment account ID
- costcenterid: Cost center for allocation
- note: Payment note/reference
- โข Process Flow:
- โข Code Example:
// Create salary record
$Salaryreport->employeeid = $empId;
$Salaryreport->salaryreportnet = $amount;
$Salaryreport->salarymonth = $salarymonthdate;
$Salaryreport->sysdate = date("Y-m-d H:i:s");
$Salaryreport->conditions = 0;
$Salaryreport->userid = $_SESSION['userid'];
// Update cash account
$saveValueBefore = getSaveValueBefore($saveid);
$saveValueAfter = $saveValueBefore - $amount;
updateSave($saveid, $saveValueAfter);
// Create daily entry
insertSavedaily($saveValueBefore, $amount, 2, $saveid,
"ุงุณุชูุงู
ู
ุฑุชุจ $employeeName", $salaryId, $saveValueAfter, "salaryreport");
delete() Function
function delete() // Line 827
- โข Purpose: Cancel salary payment and reverse transactions
- โข Parameters:
- id (GET): Salary report ID to delete
- โข Process Flow:
Salary Entitlement Entry
elseif ($do == "salaryEntitlementEntry-notFinised") // Line 306
- โข Purpose: Create accounting entries for salary entitlements (accruals)
- โข Process Flow:
Utility Functions
getSaveValueBefore($saveid)
function getSaveValueBefore($saveid) // Line 877
- โข Purpose: Get current balance of cash/bank account
- โข Return: Current account balance (float)
updateSave($saveid, $savevalueafter)
function updateSave($saveid, $savevalueafter) // Line 925
- โข Purpose: Update cash/bank account balance
- โข Parameters: Account ID and new balance
insertSavedaily()
function insertSavedaily($savedailysavebefore, $savedailychangeamount, $savedailychangetype,
$saveid, $processname, $savedailymodelid, $savedailysaveafter, $tablename) // Line 941
- โข Purpose: Record cash movement transaction
- โข Parameters: Before/after balances, change amount, process details
---
๐ Business Logic Flow
Monthly Salary Calculation Workflow
Salary Payment Processing
Salary Component Calculations
---
โ ๏ธ Common Issues
Known Bugs & Limitations
1. Transaction Safety
- Issue: Some operations lack proper transaction wrapping
- Location: Various functions
- Impact: Data inconsistency if operations fail mid-process
- Solution: Add transaction management to all multi-table operations
2. Duplicate Object Creation
- Issue: Same objects created multiple times
- Location: Lines 54-57, 123-125 (Savedaily objects)
- Impact: Memory waste and confusion
- Solution: Remove duplicate object creation
3. Array Index Safety
- Issue: Direct array access without isset() checks
- Location: Receipt() function processing $_POST arrays
- Impact: PHP warnings for missing indices
- Solution: Add proper array validation
4. Date Format Validation
- Issue: No validation for date format inputs
- Location: Month parameter processing
- Impact: SQL errors or incorrect calculations
- Solution: Add date format validation
PHP 8.2 Compatibility
1. Object Initialization
- All stdClass objects properly initialized before property assignment
- No "attempt to assign property on null" errors
2. Type Casting
- Proper float casting for salary calculations
- Safe array handling for employee data
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core operations - โข
../public/config.php- Database configuration - โข
../public/include_dao.php- DAO includes - โข
dailyentryfun.php- Daily entry functions
Required DAOs
- โข
EmployeepersonnelDAO- Employee transactions - โข
SalaryreportDAO- Salary report operations - โข
SaveDAO- Cash/bank account management - โข
SavedailyDAO- Daily cash movements - โข
EmployeeDAO- Employee data access - โข
CostcenterDAO- Cost center management - โข
DailyentryDAO- Accounting entries - โข
ProgramsettingsDAO- System settings
Related Controllers
- โข Must coordinate with employee management for data consistency
- โข Integrates with daily entry system for accounting
- โข Works with save management for payment processing
- โข Connects to cost center allocation system
Template Files
- โข
salaryReportview/show.html- Monthly salary report - โข
salaryReportview/showfinsh.html- Finalized payments - โข
salaryReportview/editprint.html- Edit/print receipts - โข
succes.html- Success message - โข
error.html- Error message
Key Payroll Features
- โข Multi-Component Calculation: Base salary + allowances + bonuses - deductions
- โข Previous Balance Integration: Carries forward negative balances from previous months
- โข Full Accounting Integration: Automatic journal entries for all transactions
- โข Cost Center Allocation: Department-wise expense allocation
- โข Branch Support: Multi-branch payroll processing
- โข Transaction Safety: Database transaction support for data integrity
- โข Flexible Payment Methods: Multiple cash/bank account support
- โข Audit Trail: Complete history of all salary transactions
- โข Real-time Balance Updates: Immediate cash account balance updates