StoreEvaluationAtAllPrices Documentation
Store Evaluation At All Prices Controller Documentation
File: /controllers/storeEvaluationAtAllPrices.php
Purpose: Comprehensive store inventory valuation using multiple pricing methods for financial analysis
Last Updated: December 21, 2024
Total Functions: 1
Lines of Code: ~144
---
๐ Overview
The Store Evaluation At All Prices Controller is a specialized financial analysis tool that provides comprehensive store inventory valuations using multiple pricing methods. It handles:
- โข Multi-store inventory valuation at various price points
- โข Detailed vs summary reporting modes
- โข Integration with size/color variant inventories
- โข Multiple pricing method analysis (buy, sell, wholesale, half-wholesale)
- โข Financial asset evaluation for accounting purposes
- โข Store-wise inventory asset breakdowns
- โข Tutorial integration for user guidance
Primary Functions
- โ Multi-store inventory valuation
- โ Multiple pricing method evaluation
- โ Size/color variant inventory integration
- โ Detailed and summary reporting modes
- โ Financial asset calculation
- โ Store-wise breakdown analysis
- โ Tutorial integration
Related Controllers
- โข storeController.php - Store management
- โข inventoryController.php - Inventory operations
- โข storedetailController.php - Store detail management
- โข productController.php - Product management
---
๐๏ธ Database Tables
Primary Inventory Tables
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **store** (via StoreMySqlExtDAO) | Store information with valuation methods | storeId, storeName, inventory valuation methods | |
| **storedetail** | Store inventory quantities | storedetailid, storeId, productid, productquantity | |
| **sizecolorstoredetail** | Size/color variant inventory | sizecolorstoredetailid, storeId, productid, sizeid, colorid, quantity | |
| **product** | Product pricing information | productId, productName, productBuyPrice, productSellAllPrice, productSellUnitPrice, productSellHalfPrice |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **productunit** | Extended pricing methods | productunitid, productid, lastbuyprice, lastbuyprice_withDiscount, meanbuyprice, meanbuyprice_withDiscount |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **youtubelink** | Tutorial links | youtubelinkid, title, url |
๐ Key Functions
1. Default Action - Store Valuation Analysis
Location: Line 83
Purpose: Generate comprehensive store inventory valuation report
Process Flow:
1. Load YouTube tutorial links for user guidance
2. Check reporting mode (detailed vs summary)
3. If detailed mode:
- Call storeEvaluationAtAllPricesDetailed() for main inventory
- Call storeEvaluationAtAllPricesDetailedNew() for size/color variants
- Aggregate totals across all pricing methods
4. If summary mode:
- Call storeEvaluationAtAllPrices() for high-level summary
5. Assign data to appropriate Smarty template
6. Display results with custom validation scripts
Key Features:
- โข Dual reporting modes for different analysis needs
- โข Integration of main inventory and variant inventory
- โข Comprehensive pricing method coverage
- โข Tutorial integration for user support
---
๐ Workflows
Workflow 1: Detailed Store Valuation Analysis
---
Workflow 2: Summary Store Valuation
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default action | Store inventory valuation analysis | |
| `do=sucess` | Success page | Display success message | |
| `do=error` | Error page | Display error message |
- โข
$getDeatilas- Controls detailed vs summary mode (1=detailed, 0=summary)
---
๐งฎ Calculation Methods
Store Data Structure with Pricing Methods
// Data structure populated by DAO methods
class StoreValuationData {
public $storeId; // Store identifier
public $storeName; // Store display name
// Quantity totals
public $totQty = 0; // Total positive quantities
public $totQty_n = 0; // Total negative quantities
// Buy price valuations
public $tot_productBuyPrice = 0; // Total at product buy price
public $tot_productBuyPrice_n = 0; // Negative at buy price
public $tot_lastbuyprice = 0; // Total at last buy price
public $tot_lastbuyprice_n = 0; // Negative at last buy price
public $tot_lastbuyprice_withDiscount = 0; // With discount applied
public $tot_lastbuyprice_withDiscount_n = 0; // Negative with discount
public $tot_meanbuyprice = 0; // Total at mean buy price
public $tot_meanbuyprice_n = 0; // Negative at mean buy price
public $tot_meanbuyprice_withDiscount = 0; // Mean with discount
public $tot_meanbuyprice_withDiscount_n = 0; // Negative mean with discount
// Sell price valuations
public $tot_productSellAllPrice = 0; // Total at sell all price
public $tot_productSellAllPrice_n = 0; // Negative at sell all
public $tot_productSellUnitPrice = 0; // Total at sell unit price
public $tot_productSellUnitPrice_n = 0; // Negative at sell unit
public $tot_productSellHalfPrice = 0; // Total at sell half price
public $tot_productSellHalfPrice_n = 0; // Negative at sell half
}
Variant Inventory Integration
// Integration of size/color variant data
foreach($storeData as $data) {
// Load variant inventory for this store
$scstoreData = $myStoreEx->storeEvaluationAtAllPricesDetailedNew($data->storeId);
// Aggregate all pricing methods
$data->totQty += $scstoreData->totQty;
$data->totQty_n += $scstoreData->totQty_n;
$data->tot_productBuyPrice += $scstoreData->tot_productBuyPrice;
$data->tot_productBuyPrice_n += $scstoreData->tot_productBuyPrice_n;
$data->tot_productSellAllPrice += $scstoreData->tot_productSellAllPrice;
$data->tot_productSellAllPrice_n += $scstoreData->tot_productSellAllPrice_n;
$data->tot_productSellUnitPrice += $scstoreData->tot_productSellUnitPrice;
$data->tot_productSellUnitPrice_n += $scstoreData->tot_productSellUnitPrice_n;
$data->tot_productSellHalfPrice += $scstoreData->tot_productSellHalfPrice;
$data->tot_productSellHalfPrice_n += $scstoreData->tot_productSellHalfPrice_n;
$data->tot_lastbuyprice += $scstoreData->tot_lastbuyprice;
$data->tot_lastbuyprice_n += $scstoreData->tot_lastbuyprice_n;
$data->tot_lastbuyprice_withDiscount += $scstoreData->tot_lastbuyprice_withDiscount;
$data->tot_lastbuyprice_withDiscount_n += $scstoreData->tot_lastbuyprice_withDiscount_n;
$data->tot_meanbuyprice += $scstoreData->tot_meanbuyprice;
$data->tot_meanbuyprice_n += $scstoreData->tot_meanbuyprice_n;
$data->tot_meanbuyprice_withDiscount += $scstoreData->tot_meanbuyprice_withDiscount;
$data->tot_meanbuyprice_withDiscount_n += $scstoreData->tot_meanbuyprice_withDiscount_n;
}
Pricing Method Explanations
// Different pricing methods for valuation
// 1. Product Buy Price - Original purchase price from product master
// 2. Product Sell All Price - Wholesale selling price
// 3. Product Sell Unit Price - Retail unit selling price
// 4. Product Sell Half Price - Half-wholesale selling price
// 5. Last Buy Price - Most recent purchase price
// 6. Last Buy Price with Discount - Recent price with discounts applied
// 7. Mean Buy Price - Average purchase price over time
// 8. Mean Buy Price with Discount - Average price with discounts
---
๐ Security & Permissions
Basic Access Control
// No explicit authentication check in this controller
// Relies on application-level security in impOpreation.php
// No store-level access restrictions implemented
// All users can view all store valuations
Security Note: This controller lacks explicit permission checking, making store valuation data accessible to all authenticated users.
---
๐ Performance Considerations
DAO Method Efficiency
1. Database Queries:
- Uses specialized DAO methods for valuation
- storeEvaluationAtAllPricesDetailed() - Main inventory
- storeEvaluationAtAllPricesDetailedNew() - Variant inventory
- Efficient aggregation at database level
2. Memory Usage:
- Minimal controller logic
- Heavy lifting done in DAO layer
- Efficient data structure for template rendering
3. Template Optimization:
- Separate templates for detailed vs summary
- Custom validation scripts loaded conditionally
Performance Monitoring
// Simple performance check
$startTime = microtime(true);
$storeData = $myStoreEx->storeEvaluationAtAllPricesDetailed();
$queryTime = microtime(true) - $startTime;
// Monitor for slow valuation queries
if ($queryTime > 5.0) {
error_log("Slow store valuation query: " . $queryTime . "s");
}
---
๐ Common Issues & Troubleshooting
1. Missing Valuation Data
Issue: Stores showing zero values across all pricing methods
Cause: Missing inventory records or pricing data
Debug:
-- Check if stores have inventory records
SELECT s.storeId, s.storeName, COUNT(sd.storedetailid) as inventory_count
FROM store s
LEFT JOIN storedetail sd ON s.storeId = sd.storeid
GROUP BY s.storeId;
-- Check for missing pricing data
SELECT productId, productName, productBuyPrice, productSellAllPrice
FROM product
WHERE productBuyPrice IS NULL OR productSellAllPrice IS NULL;
2. Negative Inventory Valuations
Issue: Negative quantities affecting valuation accuracy
Cause: Inventory adjustments or data integrity issues
Debug:
-- Find negative inventory quantities
SELECT storeid, productid, productquantity
FROM storedetail
WHERE productquantity < 0;
-- Check size/color variant negatives
SELECT storeid, productid, quantity, sizeid, colorid
FROM sizecolorstoredetail
WHERE quantity < 0;
3. Performance Issues with Large Inventories
Issue: Valuation reports taking too long to load
Cause: Inefficient DAO queries or missing indexes
Fix:
-- Ensure proper indexing for valuation queries
CREATE INDEX idx_storedetail_store_product ON storedetail(storeid, productid);
CREATE INDEX idx_sizecolor_store_product ON sizecolorstoredetail(storeid, productid);
---
๐งช Testing Scenarios
Test Case 1: Basic Store Valuation
1. Create stores with known inventory quantities
2. Set up products with different pricing methods
3. Run detailed valuation report
4. Verify calculations for each pricing method
5. Check totals match manual calculations
Test Case 2: Size/Color Variant Integration
1. Set up products with size/color variants
2. Add inventory to both main and variant tables
3. Run detailed valuation report
4. Verify variant quantities are included in totals
5. Check pricing calculations include variants
Test Case 3: Negative Inventory Handling
1. Create stores with negative inventory quantities
2. Run valuation report
3. Verify negative quantities are properly separated
4. Check that negative values don't skew positive totals
5. Confirm detailed breakdown shows negatives
Test Case 4: Summary vs Detailed Mode
1. Run valuation in both modes
2. Compare data consistency between modes
3. Verify summary provides appropriate aggregation
4. Check detailed mode includes all pricing methods
5. Confirm template rendering works for both
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข storeController.md - Store management
- โข inventoryController.md - Inventory operations
- โข StoreMySqlExtDAO.md - Store extended DAO methods
- โข Database Schema Documentation - Table relationships
---
Documented By: AI Assistant
Review Status: โ Complete
Security Review: โ ๏ธ Missing explicit permission checks
Next Review: When major changes occur