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:
- โข Real-time inventory reports across all warehouses
- โข Stock level analysis by product and category
- โข Multi-store inventory comparisons
- โข Size and color variant inventory tracking
- โข Product cost analysis with different evaluation methods
- โข Inventory valuation reports
- โข Stock movement history
- โข Product categorization and filtering
- โข Barcode and batch tracking integration
Primary Functions
- โ Display inventory by store and product
- โ Multi-store inventory reports
- โ Product category-based filtering
- โ Size and color variant tracking
- โ Real-time stock level monitoring
- โ Cost evaluation using different methods
- โ Inventory valuation reports
- โ Product search and filtering
- โ Stock movement analysis
- โ Export capabilities
- โ Barcode integration
- โ YouTube product link management
Related Controllers
- โข storeController.php - Store management
- โข productController.php - Product management
- โข buyBillController.php - Purchase operations
- โข sellbillController.php - Sales operations
- โข storemovementController.php - Stock transfers
- โข returnBuyBillController.php - Purchase returns
- โข returnSellBillController.php - Sales returns
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **storedetail** | Main inventory records | storedetailid, storeid, productid, productquantity, productquantityotherunit, unittype | |
| **sizecolorstoredetail** | Size/color variant inventory | sizecolorstoredetailid, storedetailid, sizeid, colorid, productquantity | |
| **storereport** | Stock movement history | storereportid, productid, storeid, storereporttype, storereportmodelid |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **product** | Product master data | storedetail.productid | |
| **productcat** | Product categories | product.productCatId | |
| **productunit** | Units of measurement | product.productunitid | |
| **productingredients** | Product ingredients/components | For composite products | |
| **youtubelink** | Product video links | product.productid |
| Table Name | Purpose | Relationship |
|---|---|---|
| **store** | Store/warehouse master | storedetail.storeid |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **buybilldetail** | Purchase history | For cost calculations | |
| **returnbuybilldetail** | Return history | For cost adjustments | |
| **buypriceshistorybook** | Price history | For inventory evaluation |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **programsettings** | System configuration | Inventory evaluation methods | |
| **usergroup** | User permissions | Access 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):
- โข
search- Search type and criteria - โข
productId- Specific product filter - โข
storeId- Specific store filter - โข
categoryIds- Product category filters - โข
unittype- Unit type filter
Business Logic Flow:
Database Operations:
- โข SELECT from
storedetailwith complex joins - โข SELECT from
product,productcat,store - โข Calculate costs using
buypriceshistorybook - โข Apply inventory evaluation methods
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:
- โข FIFO (First In, First Out)
- โข LIFO (Last In, First Out)
- โข Average cost method
- โข Last price method
- โข Tax-inclusive pricing
- โข Discount-adjusted pricing
3. showStoreSizeAndColor()
Purpose: Display inventory with size and color variant breakdown
Called By: ?do=showsizeandcolor
Line: 1618
Database Operations:
- โข JOIN
storedetailwithsizecolorstoredetail - โข SELECT size and color information
- โข Calculate variant-specific quantities and costs
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):
- โข
productname- Product name search term - โข
storeid- Store filter - โข
catids- Category filter array
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:
- โข Product category criteria
- โข Store ID filter
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:
- โข
$productId- Product identifier - โข
$unitId- Unit identifier
Returns: Unit conversion data for calculations
13. CURL_IT2($data_arr, $url)
Purpose: Handle external API communications
Line: 2539
Parameters:
- โข
$data_arr- Data to send - โข
$url- Target URL
---
๐ Business Logic Flow
Inventory Cost Calculation Flow
Multi-Store Inventory Workflow
Files Involved:
- โข View:
/views/default/storedetail/storedetail_show.html - โข Model:
/models/dto/Storedetail.class.php - โข DAO:
/models/mysql/StoredetailMySqlDAO.class.php - โข Language:
/views/languages/[lang]/storedetail/storedetail.php
---
โ ๏ธ 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
- โข
StoredetailDAO- Inventory operations - โข
StoreDAO- Store management - โข
ProductDAO- Product information - โข
ProductcatDAO- Category management - โข
BuybilldetailDAO- Purchase history - โข
ReturnbuybilldetailDAO- Return history - โข
ProductunitDAO- Unit conversions - โข
SizecolorstoredetailDAO- Variant tracking - โข
ProductingredientsDAO- Component tracking - โข
YoutubeLinkDAO- Product media
Related Views
- โข
/views/default/storedetail/storedetail_show.html- Main inventory view - โข
/views/default/storedetail/storedetail_sizecolor.html- Variant view
JavaScript Files
- โข
/views/default/assets/js/storedetail.js- Inventory functionality - โข
/views/default/assets/js/reports.js- Report generation
---
๐ฏ URL Routes & Actions
| Action (`?do=`) | Method | Description | View Template | |
|---|---|---|---|---|
| show (default) | GET/POST | Display inventory report | storedetail_show.html | |
| showsizeandcolor | GET | Show size/color variants | storedetail_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
- โข Inventory viewing rights
- โข Store access permissions (user can only see assigned stores)
- โข Product category access
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
- โข Inventory calculations are real-time and can be resource-intensive
- โข Cost evaluation method affects all inventory valuations
- โข Multi-store permissions are strictly enforced
- โข Size/color variants require separate tracking
- โข Unit conversions must be accurate for proper reporting
- โข YouTube links provide product enhancement capabilities
Future Improvements
- โป๏ธ Add inventory forecasting
- โป๏ธ Implement low stock alerts
- โป๏ธ Add ABC analysis reporting
- โป๏ธ Implement inventory aging reports
- โป๏ธ Add barcode scanning integration
- โป๏ธ Optimize performance for large datasets
- โป๏ธ Add inventory audit capabilities
---
๐ Related Documentation
- โข Store Management
- โข Product Management
- โข Stock Movements
- โข Inventory Reports
- โข Cost Accounting Methods