Store Report Controller Documentation
File: /controllers/storereportController.php
Purpose: Manages inventory reports, stock movements, and warehouse analytics
Last Updated: December 19, 2024
Total Functions: 11
Lines of Code: 1,069
---
๐ Overview
The Store Report Controller provides comprehensive inventory reporting and stock movement analysis for the ERP system. It handles:
- โข Stock movement reports by product, store, and date ranges
- โข Inventory level tracking and analysis
- โข Credit and debit transaction summaries
- โข Product movement history tracking
- โข Size and color variant inventory reporting
- โข Multi-store inventory comparisons
- โข Detailed transaction audit trails
- โข Real-time stock position monitoring
- โข Category-based inventory analysis
- โข Integration with buy/sell transaction details
Primary Functions
- โ Generate stock movement reports
- โ Track inventory levels by store
- โ Monitor product movement history
- โ Analyze credit/debit transactions
- โ Support size/color variant tracking
- โ Filter reports by date ranges
- โ Compare multi-store inventory
- โ Generate audit trails
- โ Calculate stock summaries
- โ Handle category-based reporting
Related Controllers
- โข sellbillController.php - Sales transaction impact
- โข buyBillController.php - Purchase transaction impact
- โข productController.php - Product master data
- โข storeController.php - Store/warehouse management
- โข balancereportController.php - Financial inventory valuation
- โข FinancialPositionController.php - Asset valuation
- โข FaidaController.php - Profit analysis
---
๐๏ธ Database Tables
Core Reporting Tables
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `storereport` | Stock movements | storereportid, productid, storeid, productquantity, productbefore, productafter, processname, tablename, storereportdate | |
| `storedetail` | Current inventory | storedetailid, storeid, productid, productquantity, storedetaildate | |
| `sizecolorstoredetail` | Size/color inventory | id, storeid, productid, sizeid, colorid, quantity |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `sellbilldetail` | Sales transactions | sellbilldetailid, sellbilldetailproductid, sellbilldetailquantity, sellbillid | |
| `returnsellbilldetail` | Sales returns | returnsellbilldetailid, returnsellbilldetailproductid, returnsellbilldetailquantity | |
| `buybilldetail` | Purchase transactions | buybilldetailid, buybilldetailproductid, buybilldetailquantity, buybillid | |
| `returnbuybilldetail` | Purchase returns | returnbuybilldetailid, returnbuybilldetailproductid, returnbuybilldetailquantity |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `store` | Store/warehouse master | storeid, storename, storeaddress, conditions | |
| `product` | Product catalog | productId, productName, productcode, productcatid | |
| `productcat` | Product categories | productcatid, productcatname, productcatparent | |
| `sizecolor` | Size/color definitions | sizecolorid, sizecolorname, sizecolortype |
๐ง Key Functions
Core Display Functions
Main Report Display (Lines 197-277)
Purpose: Main entry point for store reports with filtering options
Parameters:
- โข
$_GET['storeId']- Filter by store - โข
$_GET['productId']- Filter by product - โข
$_GET['startDate'],$_GET['endDate']- Date range
Process Flow:
Summary Calculation Functions
sumCredit() (Lines 289-335)
Purpose: Calculates total credit transactions (increases in inventory)
Returns: Total credit amount across all stores and products
Process Flow:
sumCreditByStoreId($StoreId) (Lines 336-385)
Purpose: Calculates credit transactions for a specific store
Parameters: $StoreId - Store identifier
Returns: Total credit amount for the specified store
sumCreditByProductId($ProductId) (Lines 386-435)
Purpose: Calculates credit transactions for a specific product
Parameters: $ProductId - Product identifier
Returns: Total credit amount for the specified product
sumCreditByProductIdAndStoreId($ProductId, $storeId) (Lines 436-527)
Purpose: Calculates credit transactions for specific product and store combination
Parameters: $ProductId, $storeId
Returns: Total credit amount for the product-store combination
Report Generation Functions
showByProductName($productid) (Lines 528-536)
Purpose: Generates report filtered by product
Parameters: $productid - Product identifier
Returns: Store report data for the specific product
showBystoreName($storeid) (Lines 537-545)
Purpose: Generates report filtered by store
Parameters: $storeid - Store identifier
Returns: Store report data for the specific store
showByDate($startDate, $endDate) (Lines 546-554)
Purpose: Generates report filtered by date range
Parameters: $startDate, $endDate - Date range
Returns: Store report data for the date range
showByStoreAndProductAndDate($productid, $storeid, $startDate, $endDate, $order, $bure) (Lines 555-1044)
Purpose: Comprehensive report with multiple filters
Parameters:
- โข
$productid- Product filter - โข
$storeid- Store filter - โข
$startDate,$endDate- Date range - โข
$order- Sort order - โข
$bure- Additional filter parameter
Process Flow:
Detailed Logic:
- โข Builds complex WHERE clauses based on provided filters
- โข Handles category hierarchy for product filtering
- โข Supports both product and store filtering simultaneously
- โข Enriches results with product names, store names, and user information
- โข Calculates running totals and balances
Utility Functions
loadStore() (Lines 280-288)
Purpose: Loads all active stores for dropdown selection
Returns: Array of store data
getProductPath_recursive($parentid, $categories) (Lines 1045-1061)
Purpose: Recursively builds product category hierarchy path
Parameters: $parentid, $categories - Category data
Returns: Category path string
showAll() (Lines 1062-1069)
Purpose: Displays all store report data without filters
Returns: Complete unfiltered store report data
---
๐ Business Logic Flow
Store Report Generation Process
User Request โ Load UI Filters โ Validate Parameters
โ
Build Query Conditions โ Execute Database Query โ Process Results
โ
Calculate Summaries โ Enrich Data โ Format Display โ Return Report
Inventory Movement Tracking
Report Filtering Logic
All Data โ Apply Store Filter โ Apply Product Filter โ Apply Date Range
โ
Category Filter โ Size/Color Filter โ User Permissions โ Final Results
---
โ ๏ธ Common Issues
Performance Issues
1. Large date ranges: Extensive periods may cause slow report generation
2. Complex filtering: Multiple simultaneous filters can impact query performance
3. No pagination: Large result sets may cause memory issues
Data Accuracy Issues
1. Real-time consistency: Reports may show slight delays during high transaction periods
2. Category hierarchy: Deep category structures may cause recursive lookup delays
3. Size/color variants: Additional complexity in inventory calculations
Business Logic Warnings
1. Permission checks: Some reports may show unauthorized data
2. Negative inventory: No validation for impossible negative stock levels
3. Date validation: No validation for future dates in historical reports
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core operations - โข
../public/include_dao.php- All DAO includes - โข
../public/config.php- Database configuration - โข
../public/authentication.php- User authentication
Database Dependencies
- โข Complete transaction history for accurate movement tracking
- โข Proper foreign key relationships between tables
- โข User group permissions for data access control
- โข Product category hierarchy structure
External Dependencies
- โข Smarty templating engine for report display
- โข User session management for permissions
- โข Date/time utilities for range filtering
- โข YouTube integration for help videos
Related Controllers
- โข Transaction controllers for movement source data
- โข Product management for master data
- โข Store management for warehouse information
- โข User management for permissions and audit trails
---
Inventory Tracking Notes:
- โข Stock Movements are tracked in real-time through storereport table
- โข Credit Transactions increase inventory (purchases, returns to inventory)
- โข Debit Transactions decrease inventory (sales, returns from inventory)
- โข Size/Color Variants require separate tracking through sizecolorstoredetail
- โข Audit Trail maintains complete movement history with user and timestamp
- โข Category Hierarchy supports multi-level product categorization for reporting