ReportClientAndSupplier Documentation
Report Client And Supplier Controller Documentation
File: /controllers/reportClientAndSupplier.php
Purpose: Unified reporting for both customer and supplier debt transactions and history
Last Updated: December 21, 2024
Total Functions: 4
Lines of Code: ~741
---
๐ Overview
The Report Client And Supplier Controller provides comprehensive reporting capabilities for both customer and supplier accounts in a unified interface. It handles:
- โข Individual client debt transaction reports
- โข Individual supplier debt transaction reports
- โข Transaction history with source document linking
- โข Running balance calculations for both clients and suppliers
- โข Date range filtering and sorting options
- โข Payment tracking and debt change analysis
- โข Combined client/supplier selection in single interface
Primary Functions
- โ Generate client debt transaction reports
- โ Generate supplier debt transaction reports
- โ Track transaction history with document links
- โ Calculate running balances and debt changes
- โ Date range filtering and sorting
- โ Payment and debt analysis
- โ Source document linking and navigation
Related Controllers
- โข clientReportsController.php - Dedicated client reports
- โข supplierReportsController.php - Dedicated supplier reports
- โข sellbillController.php - Sales transactions
- โข buyBillController.php - Purchase transactions
- โข clientPayedDeptController.php - Customer payments
- โข supplierPayedDeptController.php - Supplier payments
---
๐๏ธ Database Tables
Client Transaction Tables
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **client** | Customer master data | clientid, clientname, clientdebt | |
| **clientdebtchange** | Client debt transaction log | clientdebtchangeid, clientid, clientdebtchangeamount, clientdebtchangetype, clientdebtchangedate, tablename, clientdebtchangemodelid |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **supplier** | Supplier master data | supplierid, suppliername, supplierdebt | |
| **supplierdebtchange** | Supplier debt transaction log | supplierdebtchangeid, supplierid, supplierdebtchangeamount, supplierdebtchangetype, supplierdebtchangedate, tablename, supplierdebtchangemodelid |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **sellbill** | Sales bills | sellbillid, sellbillclientid, sellbilltotalbill, sellbillaftertotalbill | |
| **returnsellbill** | Sales return bills | returnsellbillid, returnsellbillclientid, returnsellbilltotalbill, returnsellbillaftertotalbill | |
| **sellbillandrutern** | Combined sell & return | sellbillid, sellbillclientid, sellbillaftertotalbill |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **buybill** | Purchase bills | buybillid, buybillsupplierid, buybillaftertotalbill | |
| **returnbuybill** | Purchase return bills | returnbuybillid, returnbuybillsupplierid, returnbuybillaftertotalbill | |
| **buyandruternbill** | Combined buy & return | buyandruternbillid, buybillsupplierid, buybillaftertotalbill |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **checkdeposit** | Check deposits | checkdepositid, clientid, bankname, accountname | |
| **checkwithdrawal** | Check withdrawals | checkwithdrawalid, supplierid, bankname, accountname | |
| **bills** | Service bills | billid, clientid, finalnetbillvalue | |
| **youtubelink** | Tutorial videos | youtubelinkid, title, url |
๐ Key Functions
1. Default Action - Combined Client/Supplier Report
Location: Line 249 (empty($do) or $do == "show")
Purpose: Main report interface handling both client and supplier debt reports
Function Signature:
// URL parameters: clientid, supplierid, from, to, order
$clientid = $_REQUEST['clientid'];
$supplierid = $_REQUEST['supplierid'];
$startDate = $_REQUEST['from'];
$endDate = $_REQUEST['to'];
$order = (int)$_REQUEST['order'];
Process Flow:
1. Include authentication check
2. Load client and supplier dropdown data
3. Process client report if client ID provided:
- Load client information
- Call clientShow() function
- Build message with client name
4. Process supplier report if supplier ID provided:
- Load supplier information
- Call supplierShow() function
- Build message with supplier name
5. Load YouTube tutorial links
6. Display combined report via template
Template Variables:
- โข
$clientData- Client dropdown options - โข
$supplierData- Supplier dropdown options - โข
$shownData- Client transaction data (if client selected) - โข
$shownData2- Supplier transaction data (if supplier selected) - โข
$message- Report header with selected entity and date range - โข
$youtubes- Tutorial video links
---
2. clientShow() - Client Transaction Report
Location: Line 312
Purpose: Generate detailed client debt transaction report with document linking
Function Signature:
function clientShow($clientid, $startDate, $endDate, $order)
Process Flow:
1. Build dynamic query string with filters:
- Client ID filter
- Date range filter (if provided)
- User permission restrictions
2. Execute query with sorting options:
- $order = 1: Sort by date descending
- Default: Sort by ID descending
3. Process each transaction record:
- Calculate running total based on transaction type
- Generate links to source documents
- Load related data (bill amounts, bank info, etc.)
4. Handle "bure" (net) view processing if requested
5. Assign data to Smarty template
Transaction Type Handling:
foreach ($shownData as $data) {
if ($data->clientdebtchangetype == 0) {
$total = $total + $data->clientdebtchangeamount; // Debt increase
} else {
$total = $total - $data->clientdebtchangeamount; // Payment/decrease
}
// Generate document links based on tablename
if ($data->tablename == "sellbillController.php") {
$data->link = "sellbillController.php?do=showDetail&sellbillid=" . $data->clientdebtchangemodelid;
// Load bill totals...
}
// ... additional transaction types
}
Document Link Generation:
- โข
sellbillController.php- Sales bills - โข
returnsellbillController.php- Sales returns - โข
depositcheckController.php- Check deposits with bank details - โข
clientPayedDeptController.php- Customer payments - โข
billreceiptController.php- Bill receipts - โข
premiumController.php- Premium transactions
---
3. supplierShow() - Supplier Transaction Report
Location: Line 538
Purpose: Generate detailed supplier debt transaction report with document linking
Function Signature:
function supplierShow($supplierid, $startDate, $endDate, $order)
Process Flow:
1. Build query string similar to client report
2. Query supplier debt change table with filters
3. Process each transaction:
- Load related document data
- Generate appropriate links
- Calculate totals and amounts
4. Handle "bure" view processing for net display
5. Assign to $shownData2 template variable
Supplier Transaction Types:
- โข
buyBillController.php- Purchase bills - โข
returnBuyBillController.php- Purchase returns - โข
buyAndReturnBillController.php- Combined purchase bills - โข
checkwithdrawalController.php- Check withdrawals with bank details - โข
supplierPayedDeptController.php- Supplier payments - โข
kempialaController.php- Promissory notes
Unique Supplier Features:
// Load bank information for check withdrawals
if ($data->tablename == "checkwithdrawalController.php") {
$checkdata = $checkWithdrawalExtDAO->queryByIdExt($id);
$data->bankname = $checkdata->bankname;
$data->accountname = $checkdata->accountname;
}
---
4. getClientData() - Client Dropdown Data
Location: Line 298
Purpose: Load client data for report selection
Function Signature:
function getClientData()
Returns: Array of client objects with extended information using queryAllsup()
---
5. getSupplierData() - Supplier Dropdown Data
Location: Line 305
Purpose: Load supplier data for report selection
Function Signature:
function getSupplierData()
Returns: Array of all supplier objects using queryAll()
---
๐ Workflows
Workflow 1: Combined Client/Supplier Report Generation
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description |
|---|---|---|
| No `do` parameter or `do=show` | Default action | Main combined client/supplier report |
Combined Report:
- โข
clientid- Client ID for client report (optional) - โข
supplierid- Supplier ID for supplier report (optional) - โข
from- Start date filter (YYYY-MM-DD, optional) - โข
to- End date filter (YYYY-MM-DD, optional) - โข
order- Sort order (1=date desc, default=ID desc, optional)
Example URLs:
reportClientAndSupplier.php?clientid=123&from=2024-01-01&to=2024-01-31&order=1
reportClientAndSupplier.php?supplierid=456&from=2024-01-01&to=2024-01-31
reportClientAndSupplier.php?clientid=123&supplierid=456&from=2024-01-01&to=2024-01-31
---
๐งฎ Calculation Methods
Running Balance Calculation (Client)
foreach ($shownData as $data) {
if ($data->clientdebtchangetype == 0) {
$total = $total + $data->clientdebtchangeamount; // Debt increase
} else {
$total = $total - $data->clientdebtchangeamount; // Payment/decrease
}
}
Query String Building
$queryString = ' WHERE';
if (isset($clientid) && $clientid != '-1') {
$queryString .= ' clientdebtchange.clientid =' . $clientid . ' AND';
}
if (!empty($startDate) && !empty($endDate)) {
$queryString .= ' clientdebtchange.clientdebtchangedate >= "' . $startDate . '" AND clientdebtchange.clientdebtchangedate <= "' . $endDate . '" AND';
}
// Clean up trailing AND/WHERE
$arr = explode(' ', $queryString);
$lastWord = end($arr);
if ($lastWord == 'AND') {
array_pop($arr);
$queryString = implode(' ', $arr);
} else if ($lastWord == 'WHERE') {
$queryString = ' ';
}
Net View Processing (Bure View)
if ($bure == "1") {
foreach ($shownData as $datax) {
$finalstring = $datax->finalstring;
$type = $datax->clientdebtchangetype;
if ($type == 1) { // Payment
$otherfinal = substr_replace($finalstring, '0', -1);
// Find and hide offsetting entries
foreach ($shownData as $xx) {
if ($xx->finalstring == $otherfinal) {
$xx->clientdebtchangeid = -1;
$datax->clientdebtchangeid = -1;
}
}
}
}
}
---
๐ Security & Permissions
Authentication
include_once("../public/authentication.php");
- โข Requires user authentication before accessing reports
- โข No specific permission levels for clients vs suppliers
Input Sanitization
- โข Parameters used directly in SQL queries
- โข Should implement proper sanitization and validation
- โข Integer casting used for order parameter:
(int)$_REQUEST['order']
Recommended Security Improvements
// Sanitize IDs
$clientid = filter_input(INPUT_REQUEST, 'clientid', FILTER_VALIDATE_INT);
$supplierid = filter_input(INPUT_REQUEST, 'supplierid', FILTER_VALIDATE_INT);
// Validate dates
if (!empty($startDate) && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $startDate)) {
$startDate = '';
}
---
๐ Performance Considerations
Database Optimization
1. Indexes Required:
- clientdebtchange(clientid, clientdebtchangedate)
- supplierdebtchange(supplierid, supplierdebtchangedate)
- sellbill(sellbillid) for document linking
- buybill(buybillid) for document linking
2. Query Performance:
- Date range queries can be expensive without proper indexing
- Document linking requires additional queries for each transaction
- Running balance calculation done in PHP rather than SQL
Performance Notes
- โข Multiple individual queries for loading related document data
- โข Could benefit from JOIN queries to reduce database round trips
- โข No pagination for large transaction histories
---
๐ Common Issues & Troubleshooting
1. Missing Document Links
Issue: Transaction shows "#" instead of proper link
Cause: clientdebtchangemodelid = -1 or unrecognized tablename
Debug:
-- Check for invalid model IDs
SELECT tablename, COUNT(*)
FROM clientdebtchange
WHERE clientdebtchangemodelid = -1
GROUP BY tablename;
-- Check for unrecognized table names
SELECT DISTINCT tablename
FROM clientdebtchange
WHERE tablename NOT IN ('sellbillController.php', 'clientPayedDeptController.php', ...);
2. Incorrect Running Balances
Issue: Balance calculations don't match expected values
Cause: Missing transactions or incorrect transaction types
Debug:
-- Verify transaction types
SELECT clientdebtchangetype, COUNT(*)
FROM clientdebtchange
WHERE clientid = [ID]
GROUP BY clientdebtchangetype;
-- Check for orphaned transactions
SELECT * FROM clientdebtchange
WHERE clientdebtchangemodelid NOT IN (
SELECT sellbillid FROM sellbill
) AND tablename = 'sellbillController.php';
3. Date Range Issues
Issue: No results for valid date ranges
Cause: Date format mismatch or timezone problems
Fix: Ensure consistent date formatting and add time components:
if (!empty($startDate)) $startDate .= " 00:00:00";
if (!empty($endDate)) $endDate .= " 23:59:59";
---
๐งช Testing Scenarios
Test Case 1: Client Report Generation
1. Select client with known transactions
2. Set date range covering transactions
3. Verify transaction list and running balance
4. Test document links functionality
5. Verify net view (bure) calculations
Test Case 2: Supplier Report Generation
1. Select supplier with purchase history
2. Apply date filters
3. Verify supplier-specific transaction types
4. Test check withdrawal bank information display
5. Verify payment tracking accuracy
Test Case 3: Combined Client/Supplier Report
1. Select both client and supplier
2. Verify both reports display simultaneously
3. Test with overlapping date ranges
4. Verify proper data separation
5. Test message generation with both entities
Test Case 4: Sorting and Filtering
1. Test different sort orders (date vs ID)
2. Apply various date range combinations
3. Test edge cases (same start/end date)
4. Verify filter reset functionality
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข clientReportsController.md - Detailed client reporting
- โข sellbillController.php - Sales transaction creation
- โข buyBillController.php - Purchase transaction creation
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur