Storedetail Documentation

Store Detail Controller Documentation

File: /controllers/storedetailController.php

Purpose: Manages inventory reports, stock levels, and warehouse inventory analysis across stores

Last Updated: December 19, 2024

Total Functions: 13

Lines of Code: 2,576

---

๐Ÿ“‹ Overview

The Store Detail Controller is the primary inventory management and reporting interface for the ERP system. It provides:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**storedetail**Main inventory recordsstoredetailid, storeid, productid, productquantity, productquantityotherunit, unittype
**sizecolorstoredetail**Size/color variant inventorysizecolorstoredetailid, storedetailid, sizeid, colorid, productquantity
**storereport**Stock movement historystorereportid, productid, storeid, storereporttype, storereportmodelid
### Product Tables

Table NamePurposeRelationship
**product**Product master datastoredetail.productid
**productcat**Product categoriesproduct.productCatId
**productunit**Units of measurementproduct.productunitid
**productingredients**Product ingredients/componentsFor composite products
**youtubelink**Product video linksproduct.productid
### Store Tables

Table NamePurposeRelationship
**store**Store/warehouse masterstoredetail.storeid
### Purchase History Tables

Table NamePurposeRelationship
**buybilldetail**Purchase historyFor cost calculations
**returnbuybilldetail**Return historyFor cost adjustments
**buypriceshistorybook**Price historyFor inventory evaluation
### Reference Tables

Table NamePurposeRelationship
**programsettings**System configurationInventory evaluation methods
**usergroup**User permissionsAccess control
---

๐Ÿ”ง Key Functions

1. show()

Purpose: Main inventory display with filtering and search capabilities

Called By: Default action ?do=show or empty $do

Line: 178

Parameters (via $_POST/$_REQUEST):

Business Logic Flow:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Load store
permissions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Load product
categories
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Apply search
filters
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Calculate
inventory costs
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Format data
for display
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
report template
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Database Operations:

2. showunittype($unittype)

Purpose: Display inventory filtered by specific unit type

Parameters: $unittype - Unit type (1=main unit, 2=secondary unit)

Line: 886

Business Logic: Complex inventory calculation supporting multiple unit types and cost evaluation methods including:

3. showStoreSizeAndColor()

Purpose: Display inventory with size and color variant breakdown

Called By: ?do=showsizeandcolor

Line: 1618

Database Operations:

4. getAllSubCat($catid)

Purpose: Recursively get all subcategories for filtering

Parameters: $catid - Parent category ID

Line: 2174

Returns: Array of all subcategory IDs including nested levels

5. showByProductNameAndStore()

Purpose: Filter inventory by product name and store

Line: 2200

Parameters (via $_POST):

6. showBystoreName()

Purpose: Filter inventory by store name

Line: 2284

Parameters: Store name search criteria

7. showByProductCatNameAndStoreId()

Purpose: Filter inventory by product category and store

Line: 2369

Parameters:

8. showAll()

Purpose: Display complete inventory without filters

Line: 2455

Business Logic: Loads all inventory records with full product and store information

9. loadProducts()

Purpose: Load product master data for dropdowns

Line: 529

Returns: Array of products with IDs and names

10. loadStore()

Purpose: Load store master data based on user permissions

Line: 540

Returns: Array of stores accessible to current user

11. loadProductCategories()

Purpose: Load hierarchical product category structure

Line: 550

Returns: Nested array of product categories

12. loadProductUnitWithProductAndUnit($productId, $unitId)

Purpose: Load product unit conversion information

Line: 2528

Parameters:

Returns: Unit conversion data for calculations

13. CURL_IT2($data_arr, $url)

Purpose: Handle external API communications

Line: 2539

Parameters:

---

๐Ÿ”„ Business Logic Flow

Inventory Cost Calculation Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Product in
Inventory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Get Purchase
History
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Apply Inventory
Evaluation
Method
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
FIFO Method
(First In First Out)โ”‚ (Average Cost)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Use oldest
purchase prices
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Apply Discounts
and Taxes
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Final Unit Cost
Calculation
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Multi-Store Inventory Workflow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
User selects
search criteria
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Check user
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Load allowed
stores list
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Apply product
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Query inventory
across stores
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Calculate costs
per store
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Format results
for display
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Files Involved:

---

โš ๏ธ Common Issues

Issue 1: Performance with Large Inventories

Problem: Slow loading when displaying thousands of products

Cause: Complex cost calculations and joins

Fix: Implement pagination and indexing optimization

Issue 2: Inventory Evaluation Method Complexity

Problem: Different cost calculation methods producing varying results

Cause: Complex business rules for FIFO, LIFO, and average costing

Fix: Clear method selection and consistent application

Issue 3: Multi-Unit Conversions

Problem: Incorrect quantity calculations with unit conversions

Cause: Complex unit relationship calculations

Fix: Proper unit conversion handling in loadProductUnitWithProductAndUnit()

Issue 4: Size/Color Variant Tracking

Problem: Inventory discrepancies with product variants

Cause: Complex variant relationship management

Fix: Proper handling in showStoreSizeAndColor()

---

๐Ÿ”— Dependencies

Includes

include("../public/impOpreation.php");
include_once("../public/config.php");
include_once("../public/reportfunctions.php");
include("../public/include_dao.php");

Required DAOs

Related Views

JavaScript Files

---

๐ŸŽฏ URL Routes & Actions

Action (`?do=`)MethodDescriptionView Template
show (default)GET/POSTDisplay inventory reportstoredetail_show.html
showsizeandcolorGETShow size/color variantsstoredetail_sizecolor.html
---

๐Ÿ“Š Inventory Evaluation Methods

Cost Calculation Methods

The system supports multiple inventory evaluation methods configured in programsettings:

1. FIFO (First In, First Out)

- Uses oldest purchase prices first

- Best for perishable goods

- More accurate during inflation

2. LIFO (Last In, First Out)

- Uses newest purchase prices first

- Better tax benefits during inflation

- May not reflect actual flow

3. Average Cost Method

- Weighted average of all purchases

- Smooths price fluctuations

- Simple and consistent

4. Last Price Method

- Uses most recent purchase price

- Quick calculation

- May not be representative

5. Tax-Inclusive Methods

- Includes taxes in cost calculations

- Better for tax reporting

- More complex calculations

---

๐Ÿ” Permissions & Security

Required Permissions

Security Checks

include_once("../public/authentication.php");

Store-Level Security

if ($_SESSION['storeids'] == 0) {
    // User can access all stores
} else {
    // Restrict to user's assigned stores
    $condition = 'store.storeId in (' . $_SESSION['storeids'] . ')';
}

---

๐Ÿ“ Notes

Important Considerations

Future Improvements

---

๐Ÿ“š Related Documentation