Income Documentation

Income Controller Documentation

File: /controllers/incomeController.php

Purpose: Manages income transactions, income types, and revenue tracking with cost center integration

Last Updated: December 19, 2024

Total Functions: 18

Lines of Code: 1,538

---

๐Ÿ“‹ Overview

The Income Controller manages all income and revenue transactions in the ERP system. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
`income`Main income recordsincomeid, incomeamount, incomedate, incometypeid, clientid, saveid, incomeDescription, projectid
`incometype`Income categorizationincometypeid, incometypename, incometypeparent, conditions
`costcenterdetail`Cost allocationcostcenterdetailid, costcenterid, incomeamount, incomeid, incomedate
### Financial Integration Tables

Table NamePurposeKey Columns
`save`Cash accountssaveid, savename, savecurrentvalue, savecurrentvalueInMainCurrency
`savedaily`Daily cash movementssavedailyid, saveid, savedailyamount, savedailydate, savedailydescription
`clientdebtchange`Client balance changesclientdebtchangeid, clientid, clientdebtchangeamount, clientdebtchangedate
### Reference Tables

Table NamePurposeKey Columns
`client`Customer informationclientid, clientname, clientphone, clientdebt
`costcenter`Cost center mastercostcenterid, costcentername, costcenterdescription
`programsettings`System configurationid, currency_settings, decimal_places
`usergroup`User permissionsusergroupid, usergroupname, permissions
---

๐Ÿ”ง Key Functions

Core CRUD Operations

add() (Lines 571-785)

Purpose: Creates new income transaction with cost center allocation

Parameters:

Process Flow:

โ”Œโ”€ Validate Input โ”€โ”€โ”€โ”
Amount, Date, Type
Insert main record
Save daily entry
Cost center detail
Debt adjustment
โ””โ”€ Complete โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

delete($incomeId) (Lines 998-1091)

Purpose: Deletes income transaction and reverses all related entries

Parameters: $incomeId - Income transaction ID

Reversal Process:

โ”Œโ”€ Load Income โ”€โ”€โ”€โ”€โ”€โ”€โ”
Get original data
Subtract from cash
Update debt balance
Remove allocations
โ””โ”€ Delete Income โ”€โ”€โ”€โ”˜

update() (Lines 1327-1355)

Purpose: Updates existing income transaction

Process: Deletes old transaction and creates new one with updated data

Query and Reporting Functions

showWithDate($from, $to, $projectid, $clientid, $saveid) (Lines 847-891)

Purpose: Retrieves income transactions by date range with optional filters

Parameters: Date range and optional filter criteria

Returns: Filtered income transaction list

showWithOneDate($condition, $date, $incomeTypeId, $clientid, $saveid) (Lines 892-930)

Purpose: Gets income transactions for specific date with conditions

Parameters: Date and filter conditions

Returns: Single-date income transactions

showWithDateAndType($from, $to, $incomeTypeId) (Lines 966-997)

Purpose: Filters income by date range and income type

Parameters: Date range and income type

Returns: Type-filtered income transactions

showwithsearch() (Lines 786-820)

Purpose: Provides search interface for income transactions

Features: Supports multiple search criteria and filters

Financial Integration Functions

getSaveValue($saveid) (Lines 1452-1466)

Purpose: Retrieves current cash account balance

Parameters: $saveid - Save account ID (optional)

Returns: Current balance or total of all accounts

getSaveValueAndPlus($savevaluechanged, $saveid) (Lines 1467-1486)

Purpose: Increases cash account balance

Parameters: Amount to add and save account ID

Process: Updates save balance and records daily transaction

getSaveValueAndMins($savevaluechanged, $saveid) (Lines 1487-1510)

Purpose: Decreases cash account balance

Parameters: Amount to subtract and save account ID

Process: Updates save balance and records daily transaction

Specialized Functions

getClients() (Lines 564-570)

Purpose: Loads active clients for dropdown selection

Returns: Array of client data

IncomeType() (Lines 545-555)

Purpose: Loads income type hierarchy for categorization

Returns: Tree structure of income types

tempdelete($incomeId) (Lines 1186-1270)

Purpose: Temporary deletion without permanent removal

Use case: For draft or pending income transactions

returndelete($incomeId) (Lines 1271-1326)

Purpose: Handles return-based income deletions

Use case: For refund or correction scenarios

---

๐Ÿ”„ Business Logic Flow

Income Transaction Creation

User Input โ†’ Validation โ†’ Income Record Creation
     โ†“
Cash Account Update โ†’ Daily Transaction Log โ†’ Cost Center Allocation
     โ†“
Client Debt Adjustment โ†’ Financial Report Update โ†’ Completion

Income Categories and Cost Centers

Income Entry โ†’ Type Selection โ†’ Cost Center Allocation
     โ†“
Amount Distribution โ†’ Project Assignment โ†’ Financial Posting

Cash Flow Integration

Income Transaction โ†’ Save Account Selection โ†’ Balance Update
     โ†“
Daily Entry Creation โ†’ Audit Trail โ†’ Report Generation

---

โš ๏ธ Common Issues

Data Integrity Issues

1. Double posting: No locking mechanism to prevent duplicate transactions

2. Reverse calculations: Complex reversal logic may cause balance discrepancies

3. Cost center allocation: Total allocation validation needed

Performance Considerations

1. Complex queries: Multiple table joins for reporting

2. Date range searches: Large ranges may impact performance

3. Real-time balance updates: No caching of frequently accessed balances

Business Logic Warnings

1. Currency conversion: Multi-currency support may have rate conversion issues

2. Client debt tracking: Automatic debt adjustments need validation

3. Permission control: Access control implementation varies by function

---

๐Ÿ”— Dependencies

Required Files

Database Dependencies

External Dependencies

Financial Dependencies

---

Income Management Notes: