All Premium Report Controller Documentation
File: /controllers/allpremiumReportController.php
Purpose: Generates comprehensive reports for client premium/installment payments and tracking
Last Updated: December 20, 2024
Total Functions: 3
Lines of Code: ~228
---
๐ Overview
The All Premium Report Controller is a specialized reporting module that manages and tracks client premium payments and installments. It provides:
- โข Client premium payment history reports
- โข Area-based premium analysis
- โข Client type-based premium filtering
- โข Date range filtering for premium tracking
- โข Individual vs grouped premium reporting
- โข Premium payment status tracking
- โข Multi-criteria premium analysis
- โข Client premium balance reporting
Primary Functions
- โ Generate client premium payment reports
- โ Filter premiums by client area
- โ Filter premiums by client type
- โ Apply date range filtering to premium tracking
- โ Display individual vs summary premium reports
- โ Track premium payment schedules
- โ Calculate premium balances and totals
- โ Support checkbox-based reporting options
Related Controllers
- โข clientController.php - Client management
- โข premiumController.php - Premium/installment operations
- โข clientReportsController.php - Customer reports
- โข clientAreaController.php - Client area management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **premium** | Premium/installment records | premiumid, client_id, premiumamount, date, status, duedate | |
| **premiumclient** | Client-premium relationships | premiumclientid, client_id, premiumid, amount, status |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **client** | Customer master data | clientid, clientname, clientareaid, typeclientid | |
| **clientarea** | Client area/region data | id, name, description | |
| **typeclient** | Client type classifications | typeclientid, typeName, description | |
| **programsettings** | System configuration | programsettingsid, reportsPlusHours | |
| **youtubelink** | Tutorial links | youtubelinkid, title, url |
๐ Key Functions
1. show() / Default Action - Premium Reports Interface
Location: Line 91-198
Purpose: Main interface for generating premium reports with multi-criteria filtering
Function Signature:
// Triggered when: do=show or empty $do
$startDate = $_REQUEST['from'];
$endDate = $_REQUEST['to'];
$clientId = $_REQUEST['clientId'];
$areaId = $_REQUEST['areaId'];
$typeclientId = $_REQUEST['typeclientId'];
$check = (int)filter_input(INPUT_POST, "check");
Process Flow:
1. Load dropdown data for filtering (clients, areas, types)
2. Parse search parameters with validation
3. Build dynamic query string based on filters
4. Apply timezone adjustments to date ranges
5. Execute appropriate premium query based on check option
6. Display via allpremiumReportview/showNew.html template
Filter Processing:
// Client filter
if ($clientId != '' && $clientId != '-1') {
$clientData = $clientDAO->load($clientId);
$message .= "ุงูุนู
ูู :" . $clientData->clientname;
$queryString .= ' premiumclient.client_id = ' . $clientId . ' AND';
}
// Area filter
if ($areaId != '' && $areaId != '-1') {
$ClientareaData = $ClientareaDAO->load($areaId);
$message .= "/ ุงูู
ูุทูู: " . $ClientareaData->name;
$queryString .= ' client.clientareaid = ' . $areaId . ' AND';
}
// Client type filter
if ($typeclientId != '' && $typeclientId != '-1') {
$TypeClientData = $TypeClientDAO->load($typeclientId);
$message .= "/ ููุน ุงูุนู
ูู: " . $TypeClientData->typeName;
$queryString .= ' client.typeclientid in ("",' . $typeclientId . ') AND';
}
Date Range Handling:
if ($startDate != '' && $endDate != '') {
$Programsetting = $ProgramsettingDAO->load(1);
if (isset($Programsetting->reportsPlusHours) && !empty($Programsetting->reportsPlusHours)) {
$reportsPlusHours = $Programsetting->reportsPlusHours + 24;
$endDate = date('Y-m-d', strtotime('+' . $reportsPlusHours . ' hour', strtotime($endDate)));
$startDate = date('Y-m-d', strtotime('+' . $Programsetting->reportsPlusHours . ' hour', strtotime($startDate)));
} else {
$endDate = $endDate . ' 23:59:59';
$startDate = $startDate . " 00:00:00";
}
$queryString .= ' premium.date >= "' . $startDate . '" AND premium.date <= "' . $endDate . '" AND';
}
Report Type Selection:
if (!$check && $check != 1) {
// Standard premium report
$allData = $premiumExt->getAllpremium($queryString);
} else {
// Premium by client ID report
$allData = $premiumExt->getpremiumbyclientid($queryString);
}
---
2. getClients() - Client Data Loader
Location: Line 206-210
Purpose: Load all active clients for dropdown selection
Function Signature:
function getClients()
Process Flow:
1. Query client table for active records (condition = 0)
2. Return array of client objects for dropdown population
Query:
$clientsData = $clientDAO->queryByCondition(0);
---
3. getClientarea() - Client Area Data Loader
Location: Line 212-216
Purpose: Load all client areas for area-based filtering
Function Signature:
function getClientarea()
Process Flow:
1. Query clientarea table for all records
2. Return array of area objects for dropdown population
Query:
$ClientareaData = $ClientareaDAO->queryAll();
---
4. getTypeclient() - Client Type Data Loader
Location: Line 218-222
Purpose: Load all client types for type-based filtering
Function Signature:
function getTypeclient()
Process Flow:
1. Query client type table for all superior types
2. Return array of type objects for dropdown population
Query:
$TypeClientData = $TypeClientEX->queryAllsup();
---
๐ Workflows
Workflow 1: Premium Report Generation
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description |
|---|---|---|
| `do=` (empty) or `do=show` | Main logic | Premium report interface |
Premium Report (do=show):
- โข
clientId- Client filter (optional, -1 for all) - โข
areaId- Area filter (optional, -1 for all) - โข
typeclientId- Client type filter (optional, -1 for all) - โข
from- Start date (optional, YYYY-MM-DD) - โข
to- End date (optional, YYYY-MM-DD) - โข
check- Report type checkbox (0=standard, 1=grouped by client)
---
๐งฎ Calculation Methods
Query String Construction
$queryString = ' WHERE';
// Add filters dynamically
if ($filter_condition) {
$queryString .= ' table.column = value AND';
}
// Clean up trailing operators
$arr = explode(' ', $queryString);
$lastWord = end($arr);
if ($lastWord == 'AND') {
array_pop($arr);
$queryString = implode(' ', $arr);
} else if ($lastWord == 'WHERE') {
array_pop($arr);
$queryString = ' ';
}
Date Range Processing
// Default date handling
if (empty($startDate) && empty($endDate)) {
$startDate = date('Y-m-d');
$endDate = date('Y-m-d');
}
// Timezone adjustment
if (isset($Programsetting->reportsPlusHours)) {
$reportsPlusHours = $Programsetting->reportsPlusHours + 24;
$endDate = date('Y-m-d', strtotime('+' . $reportsPlusHours . ' hour', strtotime($endDate)));
$startDate = date('Y-m-d', strtotime('+' . $Programsetting->reportsPlusHours . ' hour', strtotime($startDate)));
} else {
$endDate = $endDate . ' 23:59:59';
$startDate = $startDate . " 00:00:00";
}
Filter Message Generation
$message = '';
if ($clientId != '-1') {
$clientData = $clientDAO->load($clientId);
$message .= "ุงูุนู
ูู :" . $clientData->clientname;
}
if ($areaId != '-1') {
$message .= "/ ุงูู
ูุทูู: " . $areaData->name;
}
if ($typeclientId != '-1') {
$message .= "/ ููุน ุงูุนู
ูู: " . $typeData->typeName;
}
if ($startDate && $endDate) {
$message .= "<br> ู
ู ุชุงุฑูุฎ: " . $startDate . " ุฅูู ุชุงุฑูุฎ: " . $endDate;
}
---
๐ Security & Permissions
Input Validation
- โข All
$_REQUESTparameters filtered through framework - โข Client/area/type ID validation and type casting
- โข Date format validation
- โข Checkbox value validation with
filter_input() - โข SQL injection prevention through DAO layer
Access Control
- โข Uses standard ERP session authentication
- โข Respects user permissions from authentication.php
- โข No additional access restrictions beyond standard login
- โข Standard session-based security model
Data Filtering
// Safe parameter binding through DAO layer
$queryString .= ' premium.date >= "' . $startDate . '" AND premium.date <= "' . $endDate . '" AND';
// Validated ID filtering
$queryString .= ' premiumclient.client_id = ' . (int)$clientId . ' AND';
// Safe string filtering for types
$queryString .= ' client.typeclientid in ("",' . (int)$typeclientId . ') AND';
---
๐ Performance Considerations
Database Optimization Tips
1. Required Indexes:
- premium(client_id, date)
- premiumclient(client_id)
- client(clientareaid, typeclientid)
2. Query Optimization:
- Use of date range indexes for efficient filtering
- Client ID filtering reduces result sets
- Proper use of DAO layer for query optimization
3. Memory Management:
- Moderate dataset size due to premium-specific focus
- Efficient dropdown loading
- Minimal data processing overhead
Potential Performance Issues
-- Avoid date functions in WHERE clauses
-- BAD: WHERE YEAR(premium.date) = 2024
-- GOOD: WHERE premium.date >= '2024-01-01' AND premium.date <= '2024-12-31'
---
๐ Common Issues & Troubleshooting
1. No Data Returned
Issue: Reports show empty results despite valid data
Cause: Overly restrictive filters or date range issues
Debug:
-- Check basic premium data
SELECT COUNT(*) FROM premium WHERE date >= '2024-01-01';
-- Verify client relationships
SELECT COUNT(*) FROM premiumclient pc
JOIN client c ON pc.client_id = c.clientid
WHERE c.clientareaid = [AREA_ID];
2. Date Range Problems
Issue: Date filtering not working correctly
Cause: Timezone settings or date format issues
Fix:
// Debug timezone settings
$Programsetting = $ProgramsettingDAO->load(1);
echo "Report Plus Hours: " . $Programsetting->reportsPlusHours;
// Verify date format
echo "Start: " . $startDate . " End: " . $endDate;
3. Filter Dropdown Issues
Issue: Client/area/type dropdowns appear empty
Cause: Missing data or incorrect query conditions
Debug:
-- Check client data availability
SELECT COUNT(*) FROM client WHERE condition = 0;
-- Check area data
SELECT COUNT(*) FROM clientarea;
-- Check type data
SELECT COUNT(*) FROM typeclient;
4. Query String Building Errors
Issue: Malformed SQL queries or trailing operators
Cause: Improper query string cleanup
Fix:
// Debug query string construction
echo "Query String: " . $queryString . "<br>";
// Verify cleanup logic
$arr = explode(' ', $queryString);
echo "Last word: " . end($arr) . "<br>";
---
๐งช Testing Scenarios
Test Case 1: Basic Premium Report
1. Access premium report without any filters
2. Verify all premium records display
3. Check that dropdown filters load correctly
4. Confirm default date handling works
5. Test report generation performance
Test Case 2: Multi-Filter Testing
1. Select specific client, area, and date range
2. Apply filters and generate report
3. Verify only matching records appear
4. Test filter message accuracy
5. Check that filter combinations work correctly
Test Case 3: Report Type Selection
1. Test standard report (check = 0)
2. Test client-grouped report (check = 1)
3. Compare output differences
4. Verify appropriate query functions are called
5. Check data format consistency
Debug Mode Enable
// Add at top of show() function for debugging
echo "Client ID: " . $clientId . "<br>";
echo "Area ID: " . $areaId . "<br>";
echo "Type ID: " . $typeclientId . "<br>";
echo "Date Range: " . $startDate . " to " . $endDate . "<br>";
echo "Check Value: " . $check . "<br>";
echo "Final Query String: " . $queryString . "<br>";
// Debug data loading
echo "Premium Records Found: " . count($allData) . "<br>";
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข clientController.php - Client management
- โข premiumController.php - Premium operations
- โข clientReportsController.md - Customer reports
- โข Database Schema Documentation - Table relationships
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When premium tracking requirements change