Check Report Controller Documentation
File: /controllers/checkReportController.php
Purpose: Maintenance module for managing product inspection status and repair reports
Last Updated: December 20, 2024
Total Functions: 3 (basic CRUD operations)
Lines of Code: ~98
---
๐ Overview
The Check Report Controller is a specialized maintenance management module that provides comprehensive tracking of products under inspection and repair. It handles:
- โข Display of products currently under inspection
- โข Product status tracking throughout repair stages
- โข Problem identification and commenting system
- โข Integration with maintenance workflow
- โข Serial number-based product tracking
- โข Supplier and history data correlation
Primary Functions
- โ Display products under inspection
- โ Track repair stage progression
- โ Show problem descriptions and comments
- โ Link product history and status
- โ Integrate with supplier information
- โ Provide maintenance overview
Related Controllers
- โข MProducthistory - Product repair history
- โข MComreceiptdetail - Commercial receipt details
- โข Supplier - Supplier management
- โข MCheck - Check/inspection records
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **mcheck** | Product inspection records | ourSerial, conditions, branchId | |
| **mproducthistory** | Product repair history/stages | ourSerial, status, stageFrom, stageTitle, sysDate | |
| **mcomreceiptdetail** | Problem and comment tracking | ourSerial, problem, comment |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **supplier** | Supplier information | supplierid, suppliername |
๐ Key Functions
1. Default Action (show) - Display Products Under Inspection
Location: Lines 53-90
Purpose: Main display function showing all products currently under inspection for the current branch
Function Signature:
// Triggered when: empty($do) OR $do == "all"
// Uses: $_SESSION['branchId'] for branch filtering
Process Flow:
1. Query all check records for current branch
2. For each product:
- Get latest status from product history
- Retrieve problem and comment data
- Combine all information for display
3. Load supplier data for reference
4. Set today's date
5. Display via maintenance template
Key Operations:
- โข
$mCheckEX->queryByBranchEX($_SESSION['branchId'])- Get branch products - โข
$mProductHistoryEX->GetStatusOfSerialWithMaxDate($row->ourSerial)- Latest status - โข
$MComreceiptDetailEX->getProblemAndcommentByOurserialEX($row->ourSerial)- Problem data
Template Variables:
- โข
$checkData- Main product inspection data - โข
$suppliers- All supplier information - โข
$today- Current date
---
2. Data Enhancement Process - Product Status Correlation
Location: Lines 56-69
Purpose: Enhance each product record with status, stage, and problem information
Process Flow:
foreach($checkData as $row) {
// Get latest product history status
$data = $mProductHistoryEX->GetStatusOfSerialWithMaxDate($row->ourSerial);
$row->productHistoryStatus = $data->status;
$row->stageFrom = $data->stageFrom;
$row->m_stageTitle = $data->stageTitle;
// Get problem and comment details
$mydata = $MComreceiptDetailEX->getProblemAndcommentByOurserialEX($row->ourSerial);
$row->problem = $mydata->problem;
$row->comment = $mydata->comment;
}
Data Enhancement:
- โข productHistoryStatus: Current repair status
- โข stageFrom: Source stage of product
- โข m_stageTitle: Current stage description
- โข problem: Identified problem description
- โข comment: Additional comments/notes
---
3. Template Assignment - Data Preparation for Display
Location: Lines 71-89
Purpose: Prepare all data for template rendering with maintenance headers
Template Setup:
$smarty->assign("checkData", $checkData);
$smarty->assign("suppliers", $suppliers);
$smarty->assign("today", $today);
// Maintenance module headers
$smarty->assign("title1", 'ุงูุตูุงูุฉ'); // Maintenance
$smarty->assign("title2", 'ุฅุฏุงุฑุฉ ุงููุญุต'); // Inspection Management
$smarty->assign("title3", 'ุนุฑุถ ุงูู
ูุชุฌุงุช ุชุญุช ุงููุญุต'); // Show Products Under Inspection
Footer Configuration:
- โข
$customValidation = 1- Enable custom validation - โข
$customCheckReport = 1- Enable check report scripts - โข
$GeneralSearch = 1- Enable general search functionality
---
๐ Workflows
Workflow 1: Product Inspection Display
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description |
|---|---|---|
| `do=` (empty) or `do=all` | Default display | Show all products under inspection |
- โข
$_SESSION['branchId']- Current branch ID for filtering - โข
$_SESSION['userid']- User identification (implied)
---
๐ Data Correlation Logic
Serial Number Tracking
The controller uses ourSerial as the primary key to correlate data across multiple tables:
// Primary product check record
$checkData = $mCheckEX->queryByBranchEX($_SESSION['branchId']);
// For each product, get related data by serial
foreach($checkData as $row) {
// Latest repair status and stage
$historyData = $mProductHistoryEX->GetStatusOfSerialWithMaxDate($row->ourSerial);
// Problem description and comments
$problemData = $MComreceiptDetailEX->getProblemAndcommentByOurserialEX($row->ourSerial);
}
Status Tracking Fields
- โข status: Current repair/inspection status
- โข stageFrom: Origin stage of the product
- โข stageTitle: Human-readable stage description
- โข problem: Identified problem description
- โข comment: Additional technician comments
---
๐งฎ Business Logic
Branch-Based Filtering
All inspection data is filtered by the current user's branch:
$checkData = $mCheckEX->queryByBranchEX($_SESSION['branchId']);
Latest Status Determination
The system gets the most recent product history record for status determination:
$data = $mProductHistoryEX->GetStatusOfSerialWithMaxDate($row->ourSerial);
This ensures that only the current, most up-to-date status information is displayed.
---
๐ Security & Permissions
Session-Based Access
- โข Uses
$_SESSION['branchId']for branch-specific data access - โข Implicit user authentication through session management
Data Isolation
- โข Branch-level data isolation prevents cross-branch data access
- โข Each branch sees only their own inspection records
---
๐ Performance Considerations
Optimization Opportunities
1. N+1 Query Problem: The current implementation makes individual queries for each product's status and problems
2. Potential Solution: Implement batch queries or JOIN operations to reduce database calls
3. Index Requirements: Ensure indexes exist on:
- mcheck(branchId)
- mproducthistory(ourSerial, sysDate)
- mcomreceiptdetail(ourSerial)
Current Performance Impact
For each product under inspection, the system makes:
- โข 1 query for product history status
- โข 1 query for problem/comment data
- โข Total: 2 ร N queries (where N = number of products)
---
๐ Common Issues & Troubleshooting
1. Missing Product Status
Issue: Product shows without status information
Cause: No records in mproducthistory table for the serial
Debug:
SELECT * FROM mproducthistory WHERE ourSerial = '[SERIAL]' ORDER BY sysDate DESC;
2. Empty Problem/Comment Data
Issue: Products show without problem descriptions
Cause: No corresponding records in mcomreceiptdetail
Debug:
SELECT * FROM mcomreceiptdetail WHERE ourSerial = '[SERIAL]';
3. Branch Filtering Issues
Issue: Wrong products displayed for branch
Cause: Incorrect $_SESSION['branchId'] or missing branch data
Fix:
// Verify session data
echo "Current Branch: " . $_SESSION['branchId'];
---
๐งช Testing Scenarios
Test Case 1: Basic Inspection Display
1. Login with branch-specific user
2. Navigate to check report controller
3. Verify products displayed are branch-specific
4. Check that status and problem data appear correctly
Test Case 2: Data Correlation Accuracy
1. Create test product with known serial
2. Add history and problem records
3. Verify all related data displays correctly
4. Check that latest status is shown
Test Case 3: Empty Data Handling
1. Test with products having no history
2. Test with products having no problems
3. Verify graceful handling of missing data
4. Check that display remains functional
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข Maintenance Module Documentation - Overall maintenance workflow
- โข Product History Tracking - Repair stage management
- โข Serial Number Management - Product identification system
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When maintenance workflow changes occur