๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

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:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**productserial**Product serial numbers and expirationproductserailid, productid, serialnumber, startdate, enddate, storeid, sizeid, colorid, quantity, type, chassisNo, motorNo, theColor
### Reference Tables

Table NamePurposeKey Columns
**product**Product master dataproductId, productName, productCatId
**productcat**Product categoriesproductCatId, productCatName
**store**Store locationsstoreId, storeName
**storedetail**Store inventory quantitiesstoredetailid, productid, storeid, productquantity
**programsettings**System configurationprogramsettingsid, settings
---

๐Ÿ”‘ Key Functions

1. show() / Default Action - Serial Entry Interface

Location: Line 155

Purpose: Display serial number and expiration management interface

Features:

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

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Select Products
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Product and Quantity Entry
- Select product with variants (size/color)
- Specify total quantity needing serials
- Set store location
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Serial Details Entry
FOR EACH quantity unit:
โ”‚
โ†’ Enter/Generate serial number
โ†’ Set start date (production/purchase)
โ†’ Set end date (expiration)
โ†’ Enter quantity per serial
โ†’ Add comments/notes
โ”‚ โ””โ”€โ†’ [Cars] Enter chassis, motor, color โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Process and Validate
- Generate unique serial numbers if needed
- Validate date ranges
- Check for duplicate serials
- Insert/update productserial records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Real-time Updates (AJAX)
- Return generated serial IDs
- Update interface without page reload
- Enable progressive entry
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty) or `do=show`Default actionSerial entry interface
`do=add``add()`Process batch serial entries
`do=addAjax``addAjax()`AJAX serial processing
### Required Parameters

Batch Entry (do=add):

---

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

---

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

---

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

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur

โ†‘