Storeinquiriesreport Documentation
Store Inquiries Report Controller Documentation
File: /controllers/storeinquiriesreportController.php
Purpose: Generates inventory inquiry reports with product details, pricing, and discounts
Last Updated: December 21, 2024
Total Functions: 1
Lines of Code: ~180
---
๐ Overview
The Store Inquiries Report Controller is a simple reporting module that provides detailed product information across multiple stores with discount calculations. It handles:
- โข Product search by ID or barcode
- โข Store-based product inquiries
- โข Discount application (fixed amount or percentage)
- โข Product pricing retrieval (all, half, unit prices)
- โข Cross-store product availability checking
- โข Multi-format discount calculations
Primary Functions
- โ Search products by ID or barcode
- โ Apply discount calculations
- โ Display product details with pricing
- โ Handle size/color product variations
- โ Store-based product filtering
- โ Real-time price adjustments
Related Controllers
- โข storedetailController.php - Store detail management
- โข productController.php - Product management
- โข storereportController.php - Store reports
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **storedetail** | Product quantities in stores | storedetailid, productid, storeid, productquantity | |
| **product** | Product master data | productId, productName, productSellAllPrice, productSellHalfPrice, productSellUnitPrice | |
| **store** | Store master data | storeId, storeName |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **programsettings** | System configuration | programsettingsid, settingkey, settingvalue | |
| **youtubelink** | Tutorial links | youtubelinkid, title, url |
๐ Key Functions
1. showAll() - Product Search and Display
Location: Line 124
Purpose: Search for products by ID or barcode, apply discounts, and display detailed product information
Function Signature:
function showAll()
Process Flow:
1. Parse input parameters:
- productId - Product ID for search
- productparcode - Product barcode for search
- selldiscount - Flag to apply discounts
2. Handle size/color product variants:
- Extract product ID, size ID, and color ID from complex IDs
- Format: {productId}hasSizeColor-{sizeId}-{colorId}
3. Build query string based on search criteria
4. Execute product search via queryAllByProudctnameandParcode()
5. Apply discount calculations if requested:
- Fixed amount discount: Direct subtraction
- Percentage discount: Calculate percentage and subtract
6. Round percentage discounts to 2 decimal places
7. Return processed product data
Key Variables:
- โข
$productId- Primary product identifier - โข
$productparcode- Product barcode identifier - โข
$selldiscount- Discount application flag - โข
$queryString- Dynamic SQL WHERE clause - โข
$sizeId,$colorId- Product variant identifiers
Discount Calculation Logic:
if ($selldiscount == 1 && $item->selldiscount > 0) {
if ($all->discounttype == 0) { // Fixed amount discount
$item->productSellAllPrice -= $item->selldiscount;
$item->productSellHalfPrice -= $item->selldiscount;
$item->productSellUnitPrice -= $item->selldiscount;
} elseif ($item->discounttype == 1) { // Percentage discount
$item->productSellAllPrice -= $item->productSellAllPrice * ($item->selldiscount / 100);
$item->productSellHalfPrice -= $item->productSellHalfPrice * ($item->selldiscount / 100);
$item->productSellUnitPrice -= $item->productSellUnitPrice * ($item->selldiscount / 100);
// Round to 2 decimal places
$item->productSellAllPrice = round($item->productSellAllPrice, 2);
$item->productSellHalfPrice = round($item->productSellHalfPrice, 2);
$item->productSellUnitPrice = round($item->productSellUnitPrice, 2);
}
}
---
๐ Workflows
Workflow 1: Product Search and Price Calculation
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default action | Display search form | |
| `do=showAll` | `showAll()` | Execute product search and display results |
Default Action (do= empty):
- โข
productId- Product ID for search (optional) - โข
parcode- Product barcode for search (optional) - โข
selldiscount- Apply discounts flag (optional)
Product Search (do=showAll):
- โข
productId- Product ID for search (required if no barcode) - โข
parcode- Product barcode for search (required if no product ID) - โข
selldiscount- Apply discounts flag (0 or 1)
Special Parameter Handling
- โข Size/Color Products: Use format
{productId}hasSizeColor-{sizeId}-{colorId} - โข Empty Search: Returns empty result set if both productId and barcode are empty
- โข Discount Flag: Only applies if
selldiscount=1AND product has discount > 0
---
๐งฎ Calculation Methods
Discount Calculations
Fixed Amount Discount:
if ($item->discounttype == 0) {
$newPrice = $originalPrice - $discountAmount;
}
Percentage Discount:
if ($item->discounttype == 1) {
$discountAmount = $originalPrice * ($discountPercentage / 100);
$newPrice = $originalPrice - $discountAmount;
$newPrice = round($newPrice, 2); // Round to 2 decimal places
}
Size/Color Product Parsing
if (strpos($productId, "hasSizeColor") !== false) {
$productIdComplex = explode('-', str_replace("hasSizeColor", "", $productId));
$productId = $productIdComplex[0]; // Main product ID
$sizeId = $productIdComplex[1]; // Size variant ID
$colorId = $productIdComplex[2]; // Color variant ID
}
---
๐ Security & Permissions
Input Sanitization
- โข All
$_REQUESTparameters are filtered through the framework - โข Product IDs cast to appropriate types before database queries
- โข SQL injection prevented by DAO layer parameterized queries
Authentication
- โข Uses standard authentication via
../public/authentication.php - โข Session-based user validation
Data Access Control
- โข No user-specific restrictions implemented
- โข All authenticated users can access product inquiry data
---
๐ Performance Considerations
Database Optimization Tips
1. Indexes Required:
- product(productId) - Primary key (already exists)
- storedetail(productid, storeid) - Composite for joins
- product(productName) - For name-based searches
2. Query Optimization:
- Uses efficient DAO layer with prepared statements
- Single query retrieves all needed product/store data
- Minimal database round trips
Known Performance Issues
- โข No pagination implemented - large product sets may cause memory issues
- โข Discount calculations performed in PHP rather than database
- โข No caching of frequently accessed product data
---
๐ Common Issues & Troubleshooting
1. No Results Returned
Issue: Search returns empty result set
Cause: Both productId and barcode parameters are empty
Debug:
// Check query string construction
if (empty($productId) && empty($productparcode)) {
$queryString .= "product.productId = ''"; // Returns no results
}
2. Discount Not Applied
Issue: Expected discount calculations not showing
Cause: selldiscount flag not set or product has no discount value
Fix:
// Ensure conditions are met
if ($selldiscount == 1 && $item->selldiscount > 0) {
// Discount will be applied
}
3. Size/Color Products Not Found
Issue: Complex product IDs not parsing correctly
Cause: Incorrect format or missing size/color data
Debug:
// Verify format: "123hasSizeColor-5-7"
if (strpos($productId, "hasSizeColor") !== false) {
// Should extract: productId=123, sizeId=5, colorId=7
}
---
๐งช Testing Scenarios
Test Case 1: Basic Product Search
1. Use valid product ID
2. Set selldiscount=0
3. Verify product details returned
4. Check all price fields populated
Test Case 2: Discount Application
1. Use product with configured discount
2. Set selldiscount=1
3. Test both fixed amount and percentage discounts
4. Verify price calculations are correct
5. Check rounding for percentage discounts
Test Case 3: Size/Color Product Search
1. Use complex ID format: "123hasSizeColor-5-7"
2. Verify parsing extracts correct IDs
3. Check query finds specific variant
4. Validate result contains size/color data
Test Case 4: Barcode Search
1. Use product barcode instead of ID
2. Verify search finds correct product
3. Check all functionality works same as ID search
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข storedetailController.php - Store inventory management
- โข productController.php - Product management
- โข Database Schema Documentation - Table relationships
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur