Executorsuserreport Documentation
Executors User Report Controller Documentation
File: /controllers/executorsuserreport.php
Purpose: User-specific financial analysis and profitability reporting for sales bill execution assignments
Last Updated: December 20, 2024
Total Functions: 4+
Lines of Code: ~164
---
๐ Overview
The Executors User Report Controller provides user-specific financial analysis for sales bill execution assignments. It's nearly identical to the executorsreport.php but focuses on individual user performance analysis, enabling management to track the financial performance of specific users or teams in executing sales orders.
Key Capabilities
- โข User-centric profitability analysis for executed sales bills
- โข Individual user performance tracking and KPI analysis
- โข Integration of sales amounts, client payments, and execution costs per user
- โข Multi-dimensional financial calculations focused on user performance
- โข Date range filtering for user performance analysis
- โข Client and sales bill filtering for targeted user reporting
- โข Ajax-powered DataTables integration for user-specific reporting
Primary Functions
- โ Calculate user-specific gross profit (Sales Amount - Execution Costs)
- โ Track user performance in client payment collection
- โ Calculate user-specific net profit (Client Payments - Execution Costs)
- โ Provide individual user financial analysis for executions
- โ Support user performance benchmarking
- โ Ajax search for clients and sales bills (user context)
- โ DataTables integration for user performance reporting
Related Controllers
- โข executors.php - Execution assignment management
- โข executorsreport.php - General execution reporting
- โข userController.php - User management
- โข sellbillController.php - Sales bill operations
---
๐๏ธ Database Tables
Core Execution Tables
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **executors** | Execution assignments | id, executorsclientid, executorssellid, executorsuserids, executorsdate, userid, del | |
| **executorsusers** | Individual user assignments | id, executorsid, executorsuserid, today, del |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **sellbill** | Sales bill master data | sellbillid, sellbillclientid, sellbillaftertotalbill, sellbilldate, datestarting, conditions | |
| **expenses** | Execution-related costs | id, sellbillid, expensesValue, expensesdate, conditions | |
| **clientdebtchange** | Payment tracking | id, billid, clientdebtchangeamount, tablename, debtchangedate |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **user** | System users | userid, employeename, conditions |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **client** | Customer information | clientid, clientname, conditions |
๐ Key Functions
1. Default Display - User Report Interface
Location: Line 8-12
Purpose: Display the user-specific executors financial report interface
Implementation:
if (empty($do)) {
$smarty->display("header.html");
$smarty->display("executorsuserreport/show.html");
$smarty->display("footer.html");
}
Features:
- โข User-focused report interface
- โข Filter controls for user performance analysis
- โข Date range and entity filtering
- โข Export capabilities for user metrics
---
2. select2client() - Client Search for User Context
Location: Line 21-37
Purpose: Provide Ajax-powered client search for user-specific report filtering
Function Signature:
function select2client()
// POST Parameter: searchTerm - Client name search
Implementation:
$name = $_POST['searchTerm'];
$productsData = R::getAll("SELECT clientid, clientname as name
FROM client
WHERE conditions = 0 and clientname LIKE '%" . $name . "%' limit 50");
foreach ($productsData as $pro) {
$row_array['id'] = $pro['clientid'];
$row_array['text'] = $pro['name'];
array_push($return_arr, $row_array);
}
echo json_encode($return_arr);
Features:
- โข Real-time client search for user analysis
- โข Select2 dropdown integration
- โข Performance-optimized result limiting
- โข Active client filtering
---
3. select2sellbill() - Sales Bill Search with User Context
Location: Line 41-57
Purpose: Search sales bills for user-specific execution analysis
Function Signature:
function select2sellbill()
// POST Parameters: searchTerm, clientid
Implementation:
$name = $_POST['searchTerm'];
$clientid = $_POST['clientid'];
$productsData = R::getAll("SELECT sellbillid, CONCAT(sellbillid,'/',datestarting) as texts
FROM sellbill
WHERE conditions = 0 and CONCAT(sellbillid,'/',datestarting) LIKE '%" . $name . "%'
and sellbill.sellbillclientid = $clientid limit 50");
foreach ($productsData as $pro) {
$row_array['id'] = $pro['sellbillid'];
$row_array['text'] = $pro['texts'];
array_push($return_arr, $row_array);
}
Features:
- โข Client-filtered bill search for user context
- โข Bill ID and date display
- โข User-specific execution context
- โข Integration with user performance analysis
---
4. showajax() - User Performance Financial Report
Location: Line 61-157
Purpose: Generate detailed user-specific financial analysis for execution assignments
Function Signature:
function showajax()
// POST Parameters: fromdate, todate, data1 (client), data2 (sellbill), DataTables parameters
Filter Building:
$searchQuery = " ";
if($data1 != ''){
$searchQuery .= " and executors.executorsclientid = ".$data1. " ";
}
if($data2 != ''){
$searchQuery .= " and executors.executorssellid = ".$data2. " ";
}
if($start_date != '' && $end_date != ''){
$searchQuery .='and sellbill.datestarting >= "' . $start_date . '" and sellbill.datestarting <= "' . $end_date . '" ';
}
Main Query:
$rResult = R::getAll('SELECT executors.* ,clientname, expensesValue, sellbillaftertotalbill, sellbilldate, datestarting
FROM `executors`
LEFT JOIN sellbill ON executors.executorssellid = sellbill.sellbillid
LEFT JOIN client ON executors.executorsclientid = client.clientid
LEFT JOIN expenses ON expenses.sellbillid = sellbill.sellbillid
WHERE 1 '.$searchQuery.' ');
User Performance Calculations:
foreach ($rResult as $row) {
// 1. Get client payments for this bill
$clientdebtchangeamount = R::getCell('SELECT sum(clientdebtchangeamount) as clientdebtchangeamount
FROM clientdebtchange
WHERE billid = '. $row["executorssellid"]. '
and tablename = "clientPayedDeptSellBillsController.php"');
// 2. User performance metrics
$sub_array[] = $row["id"]; // Execution ID
$sub_array[] = $row["clientname"]; // Client Name
$sub_array[] = $row["executorssellid"]; // Sales Bill ID
$sub_array[] = $row["sellbilldate"]; // Bill Date
$sub_array[] = $row["sellbillaftertotalbill"]; // Sales Amount
$sub_array[] = $clientdebtchangeamount; // Client Payments (user collection performance)
$sub_array[] = $row["expensesValue"]; // Execution Costs (user cost efficiency)
$sub_array[] = $row["sellbillaftertotalbill"] - $clientdebtchangeamount; // Outstanding Amount
$sub_array[] = $row["sellbillaftertotalbill"] - $row["expensesValue"]; // Gross Profit
$sub_array[] = $clientdebtchangeamount - $row["expensesValue"]; // Net Profit
}
---
๐งฎ User Performance Metrics
1. User Sales Performance
$userSalesAmount = $row["sellbillaftertotalbill"];
- โข Total sales value executed by user
- โข Measures user sales effectiveness
2. User Collection Performance
$userCollections = $clientdebtchangeamount;
- โข Payments collected by user or their team
- โข Tracks user effectiveness in payment collection
3. User Cost Efficiency
$userExecutionCosts = $row["expensesValue"];
- โข Costs incurred in user's execution assignments
- โข Measures user cost management skills
4. User Outstanding Management
$userOutstanding = $salesAmount - $clientPayments;
- โข Uncollected amounts under user responsibility
- โข Indicates user's credit management effectiveness
5. User Gross Profit Generation
$userGrossProfit = $salesAmount - $executionCosts;
- โข Profit generated before collection issues
- โข Measures user execution efficiency
6. User Net Profit Realization
$userNetProfit = $clientPayments - $executionCosts;
- โข Actual profit realized by user performance
- โข Key indicator of user financial contribution
---
๐ User Performance Analysis Workflow
Workflow 1: Individual User Performance Assessment
---
Workflow 2: User Performance Benchmarking
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | Ajax | |
|---|---|---|---|---|
| (empty) | Default display | Show user performance report interface | No | |
| `do=select2client` | `select2client()` | Ajax client search for user context | Yes | |
| `do=select2sellbill` | `select2sellbill()` | Ajax sales bill search for users | Yes | |
| `do=showajax` | `showajax()` | DataTables user performance data provider | Yes |
Client Search (do=select2client):
- โข
searchTerm- Client name search string
Sales Bill Search (do=select2sellbill):
- โข
searchTerm- Bill search string - โข
clientid- Client filter for user context
User Performance Report (do=showajax):
- โข Standard DataTables parameters (draw, start, length, search, order)
- โข
fromdate- User performance analysis period start - โข
todate- User performance analysis period end - โข
data1- Client filter for user analysis - โข
data2- Sales bill filter for user focus
---
๐ User Performance KPIs
Individual User Metrics
1. Sales Volume: Total sales value executed by user
2. Collection Efficiency: Percentage of sales amount collected
3. Cost Control: Execution costs as percentage of sales
4. Outstanding Management: Uncollected amounts ratio
5. Gross Profit Generation: Profit before collection issues
6. Net Profit Realization: Actual realized profit
Comparative User Analytics
// User Performance Ranking Calculations
$userSalesTotal = array_sum($userSalesData);
$userCollectionRate = ($userCollections / $userSalesTotal) * 100;
$userCostEfficiency = ($userCosts / $userSalesTotal) * 100;
$userProfitMargin = (($userCollections - $userCosts) / $userCollections) * 100;
// Benchmarking Metrics
$avgSalesPerUser = $totalSales / $activeUsers;
$avgCollectionRate = $totalCollections / $totalSales * 100;
$avgCostRate = $totalCosts / $totalSales * 100;
// Performance Variance
$userPerformanceScore = (
($userCollectionRate / $avgCollectionRate) +
($avgCostRate / $userCostEfficiency) +
($userSalesTotal / $avgSalesPerUser)
) / 3;
User Performance Categories
- โข Top Performers: Above average in sales, collection, and cost control
- โข Sales Leaders: High sales volume but may need collection improvement
- โข Efficiency Experts: Best cost control and collection rates
- โข Development Needed: Below average in multiple metrics
- โข Balanced Performers: Consistent average performance across metrics
---
๐ Security & Permissions
User-Specific Access Control
// Potential user filtering (if implemented)
if ($_SESSION['role'] == 'user') {
$searchQuery .= ' AND executors.userid = ' . $_SESSION['userid'];
}
Input Validation
$searchTerm = $_POST['searchTerm'];
$clientid = $_POST['clientid'];
$start_date = $_POST['fromdate'];
$end_date = $_POST['todate'];
Security Features:
- โข Session-based access control
- โข RedBean ORM SQL injection protection
- โข Input parameter validation
- โข User context preservation
- โข Read-only operations (no data modification)
---
๐งช Testing Scenarios
Test Case 1: User Performance Calculation
1. Create execution assignments for specific user
2. Add known sales amounts, costs, and payments
3. Verify user performance metrics calculated correctly
4. Check collection rate = payments / sales * 100
5. Validate cost efficiency = costs / sales * 100
6. Confirm profit calculations accurate
Test Case 2: User Comparison Analysis
1. Create executions for multiple users
2. Generate performance report for all users
3. Verify relative performance calculations
4. Check user ranking accuracy
5. Validate benchmark calculations
Test Case 3: Date Range Performance
1. Generate user performance report for specific period
2. Test with different date ranges
3. Verify date filtering affects only relevant executions
4. Check period-based performance trends
5. Validate cumulative metrics
Test Case 4: User-Specific Filtering
1. Test client search in user context
2. Test sales bill search for user assignments
3. Verify filtering maintains user focus
4. Check DataTables search functionality
5. Validate export capabilities for user data
---
๐ Differences from executorsreport.php
While the code is nearly identical to executorsreport.php, the key differences are:
1. Template Focus
- โข Uses
executorsuserreport/show.htmlinstead ofexecutorsreport/show.html - โข Template likely includes user-specific UI elements
- โข May include user comparison features
2. Intended Usage
- โข executorsreport.php: General financial analysis of all executions
- โข executorsuserreport.php: User-centric performance analysis
3. Reporting Context
- โข General report focuses on overall profitability
- โข User report focuses on individual performance metrics
4. Analysis Perspective
- โข General: "How profitable are our executions?"
- โข User: "How well are our users performing in executions?"
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข executors.md - Execution assignment management
- โข executorsreport.md - General execution reporting
- โข userController.md - User management
- โข sellbillController.md - Sales bill operations
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur