๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

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:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**mcheck**Product inspection recordsourSerial, conditions, branchId
**mproducthistory**Product repair history/stagesourSerial, status, stageFrom, stageTitle, sysDate
**mcomreceiptdetail**Problem and comment trackingourSerial, problem, comment
### Reference Tables

Table NamePurposeKey Columns
**supplier**Supplier informationsupplierid, 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:

Template Variables:

---

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:

---

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:

---

๐Ÿ”„ Workflows

Workflow 1: Product Inspection Display

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Load Inspection Report
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Query Products Under Inspection
- Filter by current branch
- Get all mcheck records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Enhance Each Product Record
FOR EACH product in checkData:
โ”‚
โ†’ Get Latest Status from Product History
โ”‚ โ”‚ โ””โ”€ Query by ourSerial with max date โ”‚
โ”‚
โ†’ Get Problem and Comment Details
โ”‚ โ”‚ โ””โ”€ Query commercial receipt details โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Assign enhanced data to product record โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Load Reference Data
- Load all suppliers for dropdown/reference
- Set current date
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Prepare Template Display
- Assign all data to Smarty template
- Set maintenance module headers
- Configure footer scripts and validation
- Display via checkReport.html template
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty) or `do=all`Default displayShow all products under inspection
### Session Requirements

---

๐Ÿ” 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

---

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

Data Isolation

---

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

---

๐Ÿ› 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

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When maintenance workflow changes occur

โ†‘