Projectsaccountreport Documentation
Project Accounting Summary Report Controller Documentation
File: /controllers/projectsaccountreport.php
Purpose: Generate comprehensive accounting analysis by expense type with date filtering for project financial management
Last Updated: 2024-12-20
---
๐ Overview
Primary Functions
- โ Expense type consolidation and analysis
- โ Date-range filtering for financial periods
- โ Multi-source expense aggregation
- โ Supervision fee tracking by expense category
- โ Project accounting audit and control
Related Controllers
- โข projectReportController.php - Basic financial reports
- โข projectoperationController.php - Material operations
- โข expenseexchangeController.php - Additional expenses
---
๐๏ธ Database Tables
Primary Tables
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| project | Project master | id, clientid, costcenterid, supervision_amount | |
| clientdebtchange | Client payments | clientid, clientdebtchangedate, clientdebtchangeamount | |
| income | Project income | costcenterid, incomeDate, incomeValue | |
| projectexchmaterialdetail | Material issues by expense type | expensestypeid, totalbuyprice, finalsupervision | |
| projectexchmaterialdetailreturn | Material returns by expense type | expensestypeid, totalbuyprice, finalsupervision | |
| expenseexchange | Additional project expenses | projectid, expensetype, thevalue, finalsupervision | |
| expensestype | Expense categories | expensestypeid, expensestypename |
๐ง Key Functions
1. Date-Filtered Financial Analysis
Purpose: Generate accounting report with flexible date filtering
Date Filter Construction:
if ($start_date != '') {
$clientdebtchangeQuery .=' and clientdebtchange.clientdebtchangedate >= "' . $start_date . ' 00-00-00" ';
$expenseexchangeQuery .=' and expenseexchange.expensedate >= "' . $start_date . '" ';
$projectexchmaterialchangeQuery .=' and projectexchmaterial.projdate >= "' . $start_date . '" ';
$projectexchmaterialreturnQuery .=' and projectexchmaterialreturn.projdate >= "' . $start_date . '" ';
$incomeQuery .=' and income.incomeDate >= "' . $start_date . '" ';
}
if ($end_date != '') {
$clientdebtchangeQuery .=' and clientdebtchange.clientdebtchangedate <= "' . $end_date . ' 23-59-55" ';
$expenseexchangeQuery .=' and expenseexchange.expensedate <= "' . $end_date . '" ';
$projectexchmaterialchangeQuery .=' and projectexchmaterial.projdate <= "' . $end_date . '" ';
$projectexchmaterialreturnQuery .=' and projectexchmaterialreturn.projdate <= "' . $end_date . '" ';
$incomeQuery .=' and income.incomeDate <= "' . $end_date . '" ';
}
2. Expense Type Consolidation Engine
Purpose: Aggregate expenses from multiple sources by expense type
Material Issues by Expense Type:
$projectexchmaterialdetails = R::getAll("select *, sum(totalbuyprice) as totals, sum(finalsupervision) as finalsupervisions from projectexchmaterialdetail JOIN projectexchmaterial
ON projectexchmaterialdetail.projectexchid = projectexchmaterial.id WHERE projectexchmaterial.projectid = ? $projectexchmaterialchangeQuery group by projectexchmaterialdetail.expensestypeid ",[$project->id]);
foreach ($projectexchmaterialdetails as $projectexchmaterialdetail) {
$expensestypeids .= ',' . $projectexchmaterialdetail['expensestypeid'];
$expensestypedata = R::getRow('SELECT expensestype.* FROM `expensestype` WHERE expensestypeid = ? ',[$projectexchmaterialdetail['expensestypeid']]);
// Get additional expenses for same type
$expenseexchange = R::getROW("select sum(thevalue) as totals, sum(finalsupervision) as finalsupervisions from expenseexchange where del = 0 and projectid = ? and expensetype = ? $expenseexchangeQuery ",[$project->id, $projectexchmaterialdetail['expensestypeid']]);
// Get returns for same type
$projectexchmaterialdetailreturn = R::getROW("select *, sum(totalbuyprice) as totals, sum(finalsupervision) as finalsupervisions from projectexchmaterialdetailreturn JOIN projectexchmaterialreturn
ON projectexchmaterialdetailreturn.projectexchid = projectexchmaterialreturn.id WHERE projectexchmaterial.projectid = ? and projectexchmaterialdetailreturn.expensestypeid = ? $projectexchmaterialreturnQuery ",[$project->id, $projectexchmaterialdetail['expensestypeid']]);
// Calculate net totals
$totals = $expenseexchange['totals'] + $projectexchmaterialdetail['totals'] - $projectexchmaterialdetailreturn['totals'];
$finalsupervisions = $expenseexchange['finalsupervisions'] + $projectexchmaterialdetail['finalsupervisions'] - $projectexchmaterialdetailreturn['finalsupervisions'];
$expensestype = [
'expensestypeid' => $expensestypedata['expensestypeid'],
'expensestypename' => $expensestypedata['expensestypename'],
'totals' => $totals,
'finalsupervisions' => $finalsupervisions,
];
$allexpensestype[] = $expensestype;
$alltotals += $totals;
$alltotalvalues += $finalsupervisions;
}
3. Revenue Stream Analysis
Client Payments:
$clientdebtchanges = R::getAll("SELECT clientdebtchange.* FROM `clientdebtchange` WHERE clientid = ? and paySerialNo > 0 and del = 0 $clientdebtchangeQuery ",[$project->clientid]);
Project Income:
$incomes = R::getAll("SELECT income.* FROM `income` WHERE costcenterid = ? and conditions = 0 $incomeQuery ",[$project->costcenterid]);
4. Expense Source Integration
Three-Way Expense Consolidation:
1. Material Issues: From projectexchmaterialdetail
2. Material Returns: From projectexchmaterialdetailreturn (subtracted)
3. Additional Expenses: From expenseexchange
Handle Return-Only Expense Types:
$projectexchmaterialdetailreturns = R::getAll("select *, sum(totalbuyprice) as totals, sum(finalsupervision) as finalsupervisions from projectexchmaterialdetailreturn JOIN projectexchmaterialreturn
ON projectexchmaterialdetailreturn.projectexchid = projectexchmaterialreturn.id WHERE projectexchmaterialreturn.projectid = ? and projectexchmaterialdetailreturn.expensestypeid not in ($expensestypeids) $projectexchmaterialreturnQuery group by projectexchmaterialdetailreturn.expensestypeid ",[$project->id]);
Handle Expense-Exchange-Only Types:
$expenseexchanges = R::getAll("select *, sum(thevalue) as totals, sum(finalsupervision) as finalsupervisions from expenseexchange where del = 0 and projectid = ? and expensetype not in ($expensestypeids) $expenseexchangeQuery group by expenseexchange.expensetype ",[$project->id]);
---
๐ Report Structure
Expense Type Summary
Expense Type | Material Costs | Additional Expenses | Material Returns | Net Cost | Supervision Fees | Total
-------------|----------------|---------------------|------------------|----------|------------------|-------
Labor | 50,000 | 10,000 | 2,000 | 58,000 | 5,800 | 63,800
Materials | 75,000 | 5,000 | 3,000 | 77,000 | 7,700 | 84,700
Equipment | 25,000 | 15,000 | 1,000 | 39,000 | 3,900 | 42,900
Financial Summaries
- โข Total Project Costs: Sum across all expense types
- โข Total Supervision Fees: Percentage-based or fixed amounts
- โข Client Payments: Detailed payment history
- โข Project Income: Additional income streams
---
๐ฏ URL Routes & Actions
| Action (`?do=`) | Method | Description | View Template |
|---|---|---|---|
| (empty) | GET/POST | Generate accounting report with filters | show.html |
โ ๏ธ Known Issues & Fixes
Issue 1: Date Filter Logic Error (Line 26, 36)
Problem: Income date filter uses wrong variable name
Cause: Copy-paste error in query construction
Fix: Correct variable name in income queries
File: Lines 26, 36
Issue 2: Complex Query Performance
Problem: Multiple aggregation queries with JOINs may be slow
Cause: Non-optimized query structure
Fix: Consider materialized views or query optimization
File: Throughout aggregation logic
Issue 3: Missing NULL Handling
Problem: SUM() results may be NULL causing calculation errors
Cause: No NULL value handling in aggregations
Fix: Use COALESCE() or IFNULL() in SQL queries
File: All SUM() operations
---
๐ Business Rules
Date Range Logic
- โข Start date: Include from 00:00:00
- โข End date: Include until 23:59:55
- โข All date filters are optional
- โข Default: No date restrictions
Expense Type Consolidation Rules
1. Material Issues: Add to expense type total
2. Material Returns: Subtract from expense type total
3. Additional Expenses: Add to expense type total
4. Supervision Fees: Calculated separately per type
Supervision Fee Handling
- โข Project-level: Fixed amount from
project.supervision_amount - โข Type-level: Percentage-based from each transaction
- โข Display logic varies by project setup
---
๐ Notes
Important Features
- โข Multi-Source Integration: Combines three expense data sources
- โข Date Range Flexibility: Filter by any date range
- โข Expense Type Grouping: Consolidated view by category
- โข Supervision Tracking: Detailed fee analysis
- โข Audit Trail: Complete transaction history
Use Cases
- โข Period-End Reporting: Monthly/quarterly financial analysis
- โข Cost Center Analysis: Track expenses by category
- โข Budget Monitoring: Compare actual vs planned costs
- โข Client Billing: Detailed cost breakdown for invoicing
- โข Project Audit: Financial compliance and verification
Performance Considerations
- โข Complex aggregations may timeout on large projects
- โข Consider pagination for projects with many transactions
- โข Index optimization recommended for date range queries
---