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:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Inventory Tables

Table NamePurposeKey Columns
**store** (via StoreMySqlExtDAO)Store information with valuation methodsstoreId, storeName, inventory valuation methods
**storedetail**Store inventory quantitiesstoredetailid, storeId, productid, productquantity
**sizecolorstoredetail**Size/color variant inventorysizecolorstoredetailid, storeId, productid, sizeid, colorid, quantity
**product**Product pricing informationproductId, productName, productBuyPrice, productSellAllPrice, productSellUnitPrice, productSellHalfPrice
### Extended Pricing Tables (Accessed via DAO)

Table NamePurposeKey Columns
**productunit**Extended pricing methodsproductunitid, productid, lastbuyprice, lastbuyprice_withDiscount, meanbuyprice, meanbuyprice_withDiscount
### System Tables

Table NamePurposeKey Columns
**youtubelink**Tutorial linksyoutubelinkid, 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:

---

๐Ÿ”„ Workflows

Workflow 1: Detailed Store Valuation Analysis

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Store Valuation Request
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Initialize Valuation Process
- Load YouTube tutorial links
- Determine report mode (detailed vs summary)
- Set up template variables
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Load Main Store Inventory Data
- Call myStoreEx->storeEvaluationAtAllPricesDetailed()
- Retrieve inventory quantities by store
- Load pricing data for all methods:
โ”œโ”€ Product buy price
โ”œโ”€ Product sell all price
โ”œโ”€ Product sell unit price
โ”œโ”€ Product sell half price
โ”œโ”€ Last buy price
โ”œโ”€ Last buy price with discount
โ”œโ”€ Mean buy price
โ”‚ โ””โ”€ Mean buy price with discount โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Process Size/Color Variant Inventory
FOR EACH store in main data:
โ”‚
โ†’ Call storeEvaluationAtAllPricesDetailedNew()
โ”‚ โ”‚ โ””โ”€ Load size/color variant inventory โ”‚
โ”‚
โ†’ Aggregate variant totals with main inventory
โ”‚ โ”œโ”€ Add variant quantities to main quantities
โ”‚ โ”œโ”€ Add variant values to main values
โ”‚ โ”œโ”€ Include all pricing methods
โ”‚ โ”‚ โ””โ”€ Maintain store-level segregation โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Update comprehensive store totals โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Calculate Comprehensive Valuations
FOR EACH store:
โ”‚
โ†’ Total Quantity Valuation
โ”‚ โ”œโ”€ totQty = main inventory + variant inventory
โ”‚ โ”‚ โ””โ”€ totQty_n = negative inventory adjustments โ”‚
โ”‚
โ†’ Buy Price Valuations
โ”‚ โ”œโ”€ tot_productBuyPrice = qty ร— buy price
โ”‚ โ”œโ”€ tot_lastbuyprice = qty ร— last buy price
โ”‚ โ”œโ”€ tot_lastbuyprice_withDiscount
โ”‚ โ”œโ”€ tot_meanbuyprice = qty ร— mean buy price
โ”‚ โ”‚ โ””โ”€ tot_meanbuyprice_withDiscount โ”‚
โ”‚
โ†’ Sell Price Valuations
โ”‚ โ”œโ”€ tot_productSellAllPrice = qty ร— sell all
โ”‚ โ”œโ”€ tot_productSellUnitPrice = qty ร— sell unit
โ”‚ โ”‚ โ””โ”€ tot_productSellHalfPrice = qty ร— sell half โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Handle Negative Inventory Values โ”‚
โ”œโ”€ Separate negative quantities
โ”‚ โ””โ”€ Calculate negative value impacts โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Generate Financial Analysis Report
- Assign comprehensive data to Smarty template
- Include detailed breakdown by store
- Show all pricing method valuations
- Display via showDetailed.html template
- Enable custom store validation scripts
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

Workflow 2: Summary Store Valuation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Summary Valuation Request
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Load Summary Data
- Call myStoreEx->storeEvaluationAtAllPrices()
- Retrieve aggregated store valuations
- Focus on key financial metrics
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Generate Summary Report
- Assign summary data to Smarty template
- Display via show.html template
- Provide high-level financial overview
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionStore inventory valuation analysis
`do=sucess`Success pageDisplay success message
`do=error`Error pageDisplay error message
### Configuration Variables

---

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

---

Documented By: AI Assistant

Review Status: โœ… Complete

Security Review: โš ๏ธ Missing explicit permission checks

Next Review: When major changes occur