๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

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:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**storedetail**Store inventory quantitiesstoredetailid, productid, storeid, productquantity, userid, storedetaildate
**storereport**Inventory movement historystorereportid, productid, storeid, productbefore, productafter, productquantity, storereporttype, tablename, userid, storereportdate
### Reference Tables

Table NamePurposeKey Columns
**store**Store locationsstoreId, storeName, conditions
**product**Product master dataproductId, productName, productCatId
**productcat**Product categoriesproductCatId, productCatName
**programsettings**System configurationprogramsettingsid, setting values
**youtubelink**Tutorial linksyoutubelinkid, 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:

---

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:

---

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:

---

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:

Query Logic:

$queryStringJoin = ' and storereport.tablename = "inventoryController.php" ';
$queryString = " where storereport.storereportid is NULL ";

$noInventory = $storeDetailExt->queryProductsNotInInventoryNoServiceFatma($queryStringJoin, $queryString);

Data Processing:

---

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

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Select Stores
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Store Selection
- Load all available stores
- Allow multi-selection or "all stores"
- Filter by active stores only
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Initialize Inventory Session
- Prepare selected stores data
- Generate JSON for JavaScript processing
- Setup barcode scanning interface
- Display progress tracking
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Barcode Scanning Process
- Scan product barcodes
- Display current quantities
- Enter actual counted quantities
- Process multiple products per session
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Process Inventory Adjustments
FOR EACH scanned product:
โ”‚
โ†’ Calculate quantity difference
โ”‚
โ†’ Update store detail quantities
โ”‚
โ†’ Generate store report entry
โ”‚ โ”œโ”€ Record before/after quantities
โ”‚ โ”œโ”€ Set adjustment type and reason
โ”‚ โ”‚ โ””โ”€ Link to inventory controller โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Track completion progress โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Complete Inventory Process
- Display completion summary
- Provide option to continue with new stores
- Generate completion report
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

Workflow 2: Products Without Inventory Report

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Generate Uninventoried Products Report
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Set Search Parameters
- Select date range for inventory records
- Choose stores to include
- Set service vs. regular product filter
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Query Missing Products
- Find products with store quantities
- Exclude products with inventory records
- Filter by date range and store selection
- Group results by product ID
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Process and Display Results
- Group quantities by store
- Display product details and current quantities
- Show which stores need inventory for each product
- Provide links to process inventory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionStore selection interface
`do=start`Store initializationStart inventory for selected stores
`do=doinventory``add()`Process barcode inventory adjustments
`do=productwithoutInventory`Report generationShow uninventoried products
### Required Parameters

Start Inventory (do=start):

Process Inventory (do=doinventory):

Products Without Inventory (do=productwithoutInventory):

---

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

---

๐Ÿ”’ Security & Permissions

Authentication Required

Input Validation

Data Protection

---

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

---

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

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

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur

โ†‘