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

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Core Execution Tables

Table NamePurposeKey Columns
**executors**Execution assignmentsid, executorsclientid, executorssellid, executorsuserids, executorsdate, userid, del
**executorsusers**Individual user assignmentsid, executorsid, executorsuserid, today, del
### Financial Analysis Tables

Table NamePurposeKey Columns
**sellbill**Sales bill master datasellbillid, sellbillclientid, sellbillaftertotalbill, sellbilldate, datestarting, conditions
**expenses**Execution-related costsid, sellbillid, expensesValue, expensesdate, conditions
**clientdebtchange**Payment trackingid, billid, clientdebtchangeamount, tablename, debtchangedate
### User Management Tables

Table NamePurposeKey Columns
**user**System usersuserid, employeename, conditions
### Reference Tables

Table NamePurposeKey Columns
**client**Customer informationclientid, 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:

---

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:

---

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:

---

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"];

2. User Collection Performance

$userCollections = $clientdebtchangeamount;

3. User Cost Efficiency

$userExecutionCosts = $row["expensesValue"];

4. User Outstanding Management

$userOutstanding = $salesAmount - $clientPayments;

5. User Gross Profit Generation

$userGrossProfit = $salesAmount - $executionCosts;

6. User Net Profit Realization

$userNetProfit = $clientPayments - $executionCosts;

---

๐Ÿ”„ User Performance Analysis Workflow

Workflow 1: Individual User Performance Assessment

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Assess User Performance
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Define Analysis Parameters
- Set evaluation period (date range)
- Select specific user (if individual assessment)
- Choose client focus (optional)
- Define performance criteria
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Load User Execution Data
- Query executions assigned to user
- Include sales bills and client information
- Load execution costs and payment data
- Apply period and entity filters
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Calculate User Performance KPIs
FOR EACH User Execution:
โ”‚
โ†’ Sales Volume: Total sales value
โ†’ Collection Rate: Payments/Sales ratio
โ†’ Cost Efficiency: Costs/Sales ratio
โ†’ Outstanding Ratio: Outstanding/Sales
โ†’ Gross Margin: Gross profit percentage
โ”‚ โ””โ”€โ†’ Net Margin: Net profit percentage โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Generate User Performance Report
- Display individual execution performance
- Calculate aggregated user metrics
- Compare with benchmarks/targets
- Provide actionable insights
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

Workflow 2: User Performance Benchmarking

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Benchmark User Performance
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Collect User Performance Data
- Load all user execution assignments
- Calculate individual user KPIs
- Aggregate performance by user
- Apply consistent measurement period
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Calculate Benchmark Metrics
- Average sales volume per user
- Average collection rate across users
- Average cost efficiency per user
- Average profit margins by user
- Identify top and bottom performers
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Performance Comparison Analysis
- Rank users by each KPI
- Identify performance gaps
- Analyze best practices from top performers
- Identify improvement opportunities
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Generate Actionable Insights
- Performance improvement recommendations
- Training needs identification
- Resource allocation optimization
- Performance target setting
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescriptionAjax
(empty)Default displayShow user performance report interfaceNo
`do=select2client``select2client()`Ajax client search for user contextYes
`do=select2sellbill``select2sellbill()`Ajax sales bill search for usersYes
`do=showajax``showajax()`DataTables user performance data providerYes
### Required Parameters by Action

Client Search (do=select2client):

Sales Bill Search (do=select2sellbill):

User Performance Report (do=showajax):

---

๐Ÿ“Š 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

---

๐Ÿ”’ 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:

---

๐Ÿงช 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

2. Intended Usage

3. Reporting Context

4. Analysis Perspective

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur