Inventory Expiration Controller Documentation
File: /controllers/inventoryexpirationController.php
Purpose: Serial number and expiration date management for inventory items
Last Updated: December 20, 2024
Total Functions: 8+
Lines of Code: ~444
---
๐ Overview
The Inventory Expiration Controller manages product serial numbers, expiration dates, and detailed product tracking. It provides:
- โข Serial number generation and management
- โข Product expiration date tracking
- โข Size/color variant serial tracking
- โข Car chassis and motor number tracking
- โข AJAX-based real-time updates
- โข Batch serial number processing
Primary Functions
- โ Serial number generation and assignment
- โ Product expiration date management
- โ Size/color variant tracking
- โ Car-specific data (chassis, motor, color)
- โ AJAX real-time updates
- โ Batch processing capabilities
- โ Automatic serial generation
Related Controllers
- โข inventoryController.php - Main inventory management
- โข inventorybybarcodeController.php - Barcode inventory
- โข productController.php - Product management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns |
|---|---|---|
| **productserial** | Product serial numbers and expiration | productserailid, productid, serialnumber, startdate, enddate, storeid, sizeid, colorid, quantity, type, chassisNo, motorNo, theColor |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **product** | Product master data | productId, productName, productCatId | |
| **productcat** | Product categories | productCatId, productCatName | |
| **store** | Store locations | storeId, storeName | |
| **storedetail** | Store inventory quantities | storedetailid, productid, storeid, productquantity | |
| **programsettings** | System configuration | programsettingsid, settings |
๐ Key Functions
1. show() / Default Action - Serial Entry Interface
Location: Line 155
Purpose: Display serial number and expiration management interface
Features:
- โข Store-specific access control based on
$_SESSION['searchinonestore'] - โข Category hierarchy loading
- โข Store selection and filtering
- โข Template variable assignment
2. add() - Batch Serial Processing
Location: Line 285
Purpose: Process multiple product serial entries with expiration dates
Process Flow:
1. Process deletion list for removed serials
2. Loop through products and serial quantities
3. Generate or validate serial numbers
4. Insert/update serial records with dates and quantities
5. Handle car-specific data (chassis, motor, color)
Serial Generation Logic:
if (empty($serialnumber)) {
$serialnumber = getserail(6, $productid);
}
3. addAjax() - AJAX Serial Processing
Location: Line 348
Purpose: Real-time AJAX processing for single product serial updates
Returns: JSON response with status and generated serial IDs
echo json_encode(array('status' => 1, 'result' => $returnArr));
4. getserail() - Serial Number Generator
Location: Line 413
Purpose: Generate unique 6-digit serial numbers with collision detection
Function Signature:
function getserail($length = 6, $productid)
Algorithm:
1. Generate random 6-digit number
2. Check against existing serials in database
3. Check against session array to avoid duplicates in same session
4. Recursively generate new number if collision detected
5. Store in session array to prevent duplicates
---
๐ Workflows
Workflow 1: Product Serial Management
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) or `do=show` | Default action | Serial entry interface | |
| `do=add` | `add()` | Process batch serial entries | |
| `do=addAjax` | `addAjax()` | AJAX serial processing |
Batch Entry (do=add):
- โข
itr- Number of products being processed - โข
delIds- Comma-separated list of serials to delete - โข
productid{N}- Product ID for item N - โข
sizeid{N}- Size variant ID - โข
colorid{N}- Color variant ID - โข
totalproduct{N}- Total quantity for product N - โข
storeid{N}- Store location - โข
serialnumber{X}_{N}- Serial number for unit X of product N - โข
stratdate{X}_{N}- Start date - โข
enddate{X}_{N}- Expiration date - โข
quantity{X}_{N}- Quantity per serial - โข
chassisNo{X}_{N}- Chassis number (cars) - โข
motorNo{X}_{N}- Motor number (cars) - โข
theColor{X}_{N}- Car color
---
๐งฎ Calculation Methods
Serial Number Generation
$characters = '0123456789';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
Collision Detection
$data = $ProductserialEX->queryAllbyserial($randomString);
if (count($data) > 0 || @in_array($randomString, $serialArray)) {
getserail(6, $productid); // Recursive generation
}
---
๐ Security & Permissions
Store Access Control
if ($_SESSION['searchinonestore'] == 0) {
// Multi-store access
if ($_SESSION['storeids'] == 0) {
$stores = $myStoreEx->queryByConditions();
} else {
$stores = $myStoreEx->queryByConditions(' and store.storeId in (' . $_SESSION['storeids'] . ')');
}
} else {
// Single store access
$storedef = $myStoreEx->queryByConditionsOne(' and store.storeId = '.$_SESSION['storeid'].' ');
}
Input Validation
- โข Serial number uniqueness validation
- โข Date format validation
- โข Numeric quantity validation
- โข Product and store existence checks
---
๐ Performance Considerations
Optimization Features
1. AJAX Updates: Real-time processing without page reloads
2. Session Caching: Serial number collision prevention
3. Batch Processing: Multiple items in single transaction
4. Conditional Loading: Store-specific data loading
Potential Issues
- โข Large batch processing may timeout
- โข Serial generation recursion could impact performance
- โข Session array memory usage for large batches
---
๐ Common Issues & Troubleshooting
1. Serial Number Collisions
Issue: Duplicate serial numbers generated
Cause: High concurrent usage or session data loss
Fix: Implement database-level unique constraints
ALTER TABLE productserial ADD UNIQUE KEY unique_serial (serialnumber);
2. Date Validation Errors
Issue: Invalid date formats causing insertion failures
Cause: Client-side date format inconsistencies
Fix: Server-side date validation and formatting
$startdate = date('Y-m-d', strtotime($stratdate));
$enddate = date('Y-m-d', strtotime($enddate));
3. AJAX Response Issues
Issue: AJAX calls not returning proper responses
Cause: PHP errors or incorrect header settings
Debug:
// Add error reporting for AJAX
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: application/json');
---
๐ Related Documentation
- โข inventoryController.md - Main inventory management
- โข productController.md - Product management
- โข storedetailController.md - Store quantities
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur