Inventory by Barcode Controller Documentation
File: /controllers/inventorybybarcodeController.php
Purpose: Barcode-based inventory counting and management system
Last Updated: December 20, 2024
Total Functions: 4+
Lines of Code: ~254
---
๐ Overview
The Inventory by Barcode Controller provides a streamlined interface for inventory management using barcode scanning. It offers:
- โข Multi-store barcode inventory processing
- โข Products without inventory tracking
- โข Simplified inventory entry workflow
- โข Real-time inventory updates
- โข Store-based inventory management
- โข Progress tracking for inventory completion
Primary Functions
- โ Barcode-based inventory interface
- โ Multi-store inventory selection
- โ Real-time inventory processing
- โ Products without inventory reports
- โ Simplified quantity adjustment
- โ Store progress tracking
Related Controllers
- โข inventoryController.php - Full inventory management
- โข inventoryexpirationController.php - Product expiration tracking
- โข storedetailController.php - Store quantity management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **storedetail** | Store inventory quantities | storedetailid, productid, storeid, productquantity, userid, storedetaildate | |
| **storereport** | Inventory movement history | storereportid, productid, storeid, productbefore, productafter, productquantity, storereporttype, tablename, userid, storereportdate |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **store** | Store locations | storeId, storeName, conditions | |
| **product** | Product master data | productId, productName, productCatId | |
| **productcat** | Product categories | productCatId, productCatName | |
| **programsettings** | System configuration | programsettingsid, setting values | |
| **youtubelink** | Tutorial links | youtubelinkid, title, url |
๐ Key Functions
1. Default Action - Store Selection Interface
Location: Line 70
Purpose: Display store selection interface for barcode inventory
Process Flow:
1. Load YouTube tutorial links
2. Load program settings
3. Load available stores using getStores()
4. Display via invoicesearningsreportview/byparcode.html template
Template Variables:
- โข
Programsettingdata- System configuration - โข
storesData- Available stores for selection - โข
youtubes- Tutorial links
---
2. start Action - Initialize Barcode Inventory
Location: Line 88
Purpose: Start barcode inventory process for selected stores
Function Flow:
1. Process store selection from $_POST['storeId']
2. Handle "all stores" or specific store selection
3. Build query string for store filtering
4. Load selected stores data
5. Prepare JSON data for front-end processing
6. Display inventory interface
Store Selection Logic:
$choosenStores = filter_input(INPUT_POST, 'storeId', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
if (in_array("all", $choosenStores)) {
$ids = 'all';
$queryString = " where conditions = 0 order by storeId asc ";
} else {
$ids = '';
foreach ($choosenStores as $value) {
$ids .= $value . ",";
}
$ids = rtrim($ids, ',');
$queryString = " where conditions = 0 and storeId in($ids) order by storeId asc ";
}
Template Variables:
- โข
stores- Selected store objects - โข
stores_json- JSON encoded stores for JavaScript - โข
storesCount- Number of selected stores - โข
ids- Store IDs string
---
3. doinventory Action - Process Barcode Inventory
Location: Line 107
Purpose: Process inventory adjustments from barcode scanning
Function Flow:
1. Call add() function to process adjustments
2. Handle success/error scenarios
3. Redirect back to barcode controller
4. Display completion message
Error Handling:
- โข Try-catch wrapper for inventory processing
- โข User-friendly error messages in Arabic
- โข Automatic redirection to starting page
---
4. add() - Core Inventory Processing
Location: Line 194
Purpose: Process individual inventory items from barcode input
Function Signature:
function add()
Process Flow:
1. Get iteration count from $_POST['hidden_itr']
2. Get store ID from $_POST['ids']
3. For each inventory item:
- Extract new quantity ($_POST['pronum' . $i])
- Get product ID ($_POST['productid' . $i])
- Get store detail ID and old quantity
- Calculate quantity difference
- Update store quantities
- Generate store reports
Quantity Change Detection:
if ($oldQty > $newQty) {
$status = "ุจุงูููุต"; // Decrease
$actualQty = $oldQty - $newQty;
$type = 1;
} else if ($oldQty < $newQty) {
$status = "ุจุงูุฒูุงุฏุฉ"; // Increase
$actualQty = $newQty - $oldQty;
$type = 0;
} else {
$status = "ูู
ูุชุบูุฑ"; // No change
$actualQty = $newQty;
$type = 0;
}
Store Report Generation:
$storeReport->processname = "ุชู
ุฅุนุงุฏุฉ ุฌุฑุฏ ุงูู
ูุชุฌ ุจุงูุจุงุฑููุฏ ุจุงูููู
ุฉ ุงูุญุงููุฉ " . $status;
$storeReport->productafter = $newQty;
$storeReport->productbefore = $oldQty;
$storeReport->productid = $productId;
$storeReport->productquantity = $actualQty;
$storeReport->storeid = $storeid;
$storeReport->tablename = "inventoryController.php"; // Links to main inventory
---
5. productwithoutInventory Action - Uninventoried Products Report
Location: Line 123
Purpose: Generate report of products that haven't been inventoried
Function Flow:
1. Load all stores for selection
2. Process search parameters (date range, stores)
3. Build complex query to find products without inventory records
4. Display products missing from inventory process
Search Parameters:
- โข
from/to- Date range for inventory records - โข
storeId- Store filter (array or "all")
Query Logic:
$queryStringJoin = ' and storereport.tablename = "inventoryController.php" ';
$queryString = " where storereport.storereportid is NULL ";
$noInventory = $storeDetailExt->queryProductsNotInInventoryNoServiceFatma($queryStringJoin, $queryString);
Data Processing:
- โข Groups products by product ID
- โข Stores quantities per store in
storeNamearray property - โข Creates comprehensive view of uninventoried items
---
6. getStores() - Store Loading Helper
Location: Line 187
Purpose: Load active stores for selection
Returns: Array of store objects with conditions = 0
---
๐ Workflows
Workflow 1: Barcode Inventory Process
---
Workflow 2: Products Without Inventory Report
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default action | Store selection interface | |
| `do=start` | Store initialization | Start inventory for selected stores | |
| `do=doinventory` | `add()` | Process barcode inventory adjustments | |
| `do=productwithoutInventory` | Report generation | Show uninventoried products |
Start Inventory (do=start):
- โข
storeId[]- Array of store IDs or "all"
Process Inventory (do=doinventory):
- โข
hidden_itr- Number of items being processed - โข
ids- Store ID being processed - โข
pronum{N}- New quantity for item N - โข
productid{N}- Product ID for item N - โข
detailid{N}_{storeId}- Store detail ID - โข
storeQty{N}_{storeId}- Previous quantity
Products Without Inventory (do=productwithoutInventory):
- โข
from/to- Date range (optional) - โข
storeId[]- Store filter array (optional)
---
๐งฎ Calculation Methods
Quantity Adjustment Calculation
// Same logic as main inventory controller
if ($oldQty > $newQty) {
$actualQty = $oldQty - $newQty; // Shortage
$type = 1; // Decrease
} else if ($oldQty < $newQty) {
$actualQty = $newQty - $oldQty; // Overage
$type = 0; // Increase
}
Progress Tracking
- โข Tracks number of stores processed
- โข Counts products inventoried per store
- โข Provides completion percentage
---
๐ Security & Permissions
Authentication Required
- โข All actions require valid session
- โข User authentication via
../public/authentication.php
Input Validation
- โข Store ID array validation and sanitization
- โข Numeric quantity validation
- โข Product existence verification
Data Protection
- โข No daily entries generated (simplified process)
- โข Links all reports to main inventory controller
- โข Maintains audit trail through store reports
---
๐ Performance Considerations
Optimization Features
1. Simplified Processing: No daily entry generation for faster processing
2. Batch Operations: Processes multiple items in single transaction
3. JSON Data: Pre-loads store data for client-side processing
4. Minimal Queries: Efficient update patterns
Scalability
- โข Suitable for high-volume barcode scanning
- โข Handles multiple stores efficiently
- โข Optimized for mobile devices
---
๐ Common Issues & Troubleshooting
1. Store Selection Issues
Issue: "All stores" selection not working
Cause: Array processing of mixed values
Debug:
// Check POST data structure
var_dump($_POST['storeId']);
// Verify store filtering
$stores = $storeEX->queryAllQueryStringSimple($queryString);
echo count($stores) . " stores found";
2. Barcode Processing Errors
Issue: Product quantities not updating
Cause: Missing store detail records or invalid product IDs
Fix:
-- Check store detail existence
SELECT * FROM storedetail
WHERE productid = [PRODUCTID] AND storeid = [STOREID];
-- Verify product exists
SELECT productId, productName FROM product WHERE productId = [PRODUCTID];
3. Progress Tracking Issues
Issue: Progress not updating correctly
Cause: JavaScript/AJAX communication problems
Debug:
- โข Check browser console for JavaScript errors
- โข Verify AJAX endpoints responding correctly
- โข Test with simple products first
4. Products Without Inventory Query Performance
Issue: Report takes too long to generate
Cause: Complex LEFT JOIN on large datasets
Optimization:
-- Add indexes for better performance
CREATE INDEX idx_storereport_product_table ON storereport(productid, tablename);
CREATE INDEX idx_storedetail_product_store ON storedetail(productid, storeid);
---
๐งช Testing Scenarios
Test Case 1: Multi-Store Barcode Inventory
1. Select multiple stores for inventory
2. Start barcode inventory process
3. Scan products and enter quantities
4. Verify updates across selected stores
5. Check store reports generated correctly
Test Case 2: All Stores Inventory
1. Select "all stores" option
2. Verify all active stores included
3. Process inventory for multiple stores
4. Check data consistency across stores
Test Case 3: Products Without Inventory Report
1. Set date range for inventory records
2. Select specific stores
3. Generate uninventoried products report
4. Verify products with no inventory records shown
5. Check store-specific quantity display
Test Case 4: Error Handling
1. Enter invalid product ID
2. Try negative quantities
3. Test with missing store details
4. Verify error messages and recovery
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข inventoryController.md - Full inventory management
- โข inventoryexpirationController.md - Expiration tracking
- โข storedetailController.md - Store management
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur