ProjectReport Documentation
Project Financial Reports Controller Documentation
File: /controllers/projectReportController.php
Purpose: Generate comprehensive financial analysis and profitability reports for projects
Last Updated: 2024-12-20
---
๐ Overview
Primary Functions
- โ Project profitability analysis
- โ Revenue vs expenses calculation
- โ Client payment tracking
- โ Material cost analysis
- โ Supplier payment analysis
- โ Profit/loss determination
Related Controllers
- โข projectController.php - Project master data
- โข projectoperationController.php - Material costs
- โข clientPayedDeptController.php - Client payments
---
๐๏ธ Database Tables
Primary Tables
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| project | Project master data | id, name, clientid, costcenterid | |
| clientdebtchange | Client payment history | clientid, clientdebtchangeamount, clientdebtchangetype | |
| income | Project income | costcenterid, incomeValue | |
| projectexchmaterial | Material issued | projectid, totalbuyprice | |
| projectexchmaterialreturn | Material returned | projectid, totalbuyprice | |
| expenses | Project expenses | costcenterid, expensesValue |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| client | Customer data | Foreign Key: project.clientid | |
| costcenter | Cost centers | Foreign Key: project.costcenterid | |
| supplier | Supplier data | Referenced in payments | |
| expenseexchange | Additional expenses | projectid reference |
๐ง Key Functions
1. search() - Financial Analysis Engine
Purpose: Calculate complete project financial position
Called By: POST action to ?do=search
Parameters:
- โข
$projectId(int) - Project to analyze
Returns: Displays financial analysis report
Database Operations:
- โข SELECT from
project- Project details - โข SELECT from
income- All project income - โข SELECT from
clientdebtchange- Client payment history - โข SELECT from
projectexchmaterial- Material costs - โข SELECT from
projectexchmaterialreturn- Material returns - โข SELECT from
expenses- Project expenses - โข SELECT from
supplierdebtchange- Supplier payments - โข SELECT from
expenseexchange- Additional expenses
Business Logic:
1. Income Calculation:
foreach ($allincomeData as $income) {
$incomeData += $income->incomeValue;
}
```
2. **Client Payments Calculation**:
```php
foreach ($allclientDeptChangeDAO as $clientDeptChangeDAO) {
if($clientDeptChangeDAO->clientdebtchangetype == 0){
$clientPaid += $clientDeptChangeDAO->clientdebtchangeamount;
}else{
$clientPaid -= $clientDeptChangeDAO->clientdebtchangeamount;
}
}
```
3. **Material Cost Calculation**:
```php
$supplies = $totalallMaterial - $totalallMaterialReturn;
```
4. **Total Expenses**:
```php
$proMasrofat = $supplies + $masroofat + $supplierdebtchangeamountto;
```
5. **Profit/Loss Analysis**:
```php
$clientPaids = $clientPaid + $incomeData;
$operation = $clientPaids - abs($proMasrofat);
if ($operation < 0) {
$operation = abs($operation);
$txt = 'ุตุงูู ุงูุฎุณุงุฑุฉ'; // Net Loss
} else {
$txt = 'ุตุงูู ุงูุฑุจุญ'; // Net Profit
}
```
**Example Output**:
Project: Building Construction
Client Payments: 100,000
Income: 5,000
Material Costs: 60,000
Expenses: 20,000
Supplier Payments: 15,000
Total Revenue: 105,000
Total Costs: 95,000
Net Profit: 10,000
---
## ๐ Main Workflows
### Workflow 1: Project Financial Analysis
1. User selects project
โ
2. Load project master data
โ
3. Calculate income streams
โ
4. Calculate client payments
โ
5. Calculate material costs
โ
6. Calculate all expenses
โ
7. Compute profit/loss
โ
8. Display financial report
**Files Involved**:
- View: `/views/default/projectview/report.html`
- Model: `/models/dto/Project.class.php`
- DAO: Multiple DAO classes for financial data
### Workflow 2: Financial Data Aggregation
1. Income Aggregation
โโโ Direct Income (income table)
โโโ Client Payments (clientdebtchange)
2. Cost Aggregation
โโโ Material Costs (projectexchmaterial)
โโโ Direct Expenses (expenses)
โโโ Supplier Payments (supplierdebtchange)
โโโ Additional Expenses (expenseexchange)
3. Net Position Calculation
โโโ Revenue - Costs = Profit/Loss
---
## ๐ File Dependencies
### Includes
php
include("../public/impOpreation.php");
include_once("../public/config.php");
include("../public/include_dao.php");
include_once("dailyentryfun.php");
### Required Models
- Project, Client, Clientdebtchange, Costcenter, Accountstree
- Expenseexchange, Projectexchmaterial, Projectexchmaterialreturn
- Income, Incometype, Supplier, Supplierdebtchange, YoutubeLink
### Related Views
- `/views/default/projectview/report.html` - Financial report display
---
## ๐ฏ URL Routes & Actions
| Action (`?do=`) | Method | Description | View Template |
|-----------------|--------|-------------|---------------|
| (empty) | GET | Display project selection | report.html |
| search | POST | Generate financial analysis | report.html |
| sucess | GET | Success message | succes.html |
| error | GET | Error message | error.html |
---
## โ ๏ธ Known Issues & Fixes
### Issue 1: Missing Project Validation (Line 205)
**Problem**: No validation if project ID is valid before processing
**Cause**: Missing input validation
**Fix**: Add project existence check
**File**: Line 205-207
### Issue 2: Complex Financial Logic
**Problem**: Complex financial calculations in single function
**Cause**: Monolithic function design
**Fix**: Break into smaller calculation functions
**File**: Lines 210-298
### Issue 3: Hardcoded Values
**Problem**: Hardcoded account IDs (e.g., accountstreeid = 16)
**Cause**: Configuration not externalized
**Fix**: Move to configuration file
**File**: Line 750
---
## ๐ Permissions & Security
### Required Permissions
- Project reporting access
- Financial data viewing
### Security Checks
php
include_once("../public/authentication.php");
### Input Validation
- Project ID filtered with `filter_input()`
- Redirect if invalid project selected
---
## ๐ Financial Calculations
### Revenue Components
1. **Client Payments**: Direct payments from clients
2. **Project Income**: Additional income streams
3. **Total Revenue** = Client Payments + Project Income
### Cost Components
1. **Material Costs**: Net material issued (issued - returned)
2. **Direct Expenses**: Operating expenses
3. **Supplier Payments**: Payments to suppliers
4. **Additional Expenses**: Miscellaneous project costs
5. **Total Costs** = Materials + Expenses + Supplier Payments + Additional
### Profitability Analysis
Net Position = Total Revenue - Total Costs
If Net Position > 0: Net Profit
If Net Position < 0: Net Loss
```
---
๐ Notes
Important Considerations
- โข Financial calculations consider material returns
- โข Client payment types affect calculation (add/subtract)
- โข Supplier payments are tracked by cost center
- โข All amounts are absolute values for display
Future Improvements
- โป๏ธ Add budget vs actual comparison
- โป๏ธ Implement trend analysis
- โป๏ธ Add export functionality
- โป๏ธ Create visual charts
- โป๏ธ Add project comparison
Performance Considerations
- โข Multiple database queries per report
- โข Consider caching for large projects
- โข Optimize with materialized views
---
๐ Related Documentation
- โข Project Master
- โข Project Operations
- โข Daily Entry Functions
- โข Financial Reports