Storedetailprice Documentation

Store Detail Price Controller Documentation

File: /controllers/storedetailpriceController.php

Purpose: Product inventory price list reporting and analysis system

Last Updated: December 20, 2024

Total Functions: 15+

Lines of Code: ~1,133

---

๐Ÿ“‹ Overview

The Store Detail Price Controller is a specialized inventory reporting module that provides detailed product price analysis and inventory valuation capabilities. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**storedetail**Store inventory quantitiesstoredetailid, storeid, productid, productquantity, storedetaildate
**product**Product master dataproductId, productName, productCatId, productBuyPrice, productSellAllPrice, logo
**store**Store/warehouse definitionsstoreid, storeName
**productcat**Product categoriesproductCatId, productCatName, productCatParent
### Price Tables

Table NamePurposeKey Columns
**product**Multi-level pricingprice4, price5, price6, price7, price8, price9, price10, price11, price12, price13
**product**Buy price trackinglastbuyprice, lastbuyprice_withDiscount, meanbuyprice, meanbuyprice_withDiscount
**product**Sell pricingproductSellUnitPrice, productSellAllPrice, productSellHalfPrice, selldiscount
### System Tables

Table NamePurposeKey Columns
**programsettings**System configurationlastprice, Inventoryevaluation, usedParcode, parcodeDigits
**buybilldetail**Purchase historybuybilldetailproductid, buybilldetailprice
**returnbuybilldetail**Purchase returnsreturnbuybilldetailproductid
**usergroup**User permissionsusergroupid, hidecat
**youtubelink**Help tutorialsyoutubelinkid, title, url
---

๐Ÿ”‘ Key Functions

1. show() / Default Action - Main Price Report

Location: Line 129

Purpose: Generate comprehensive product price list with filtering options

Function Signature:

// Triggered when: do=show or empty $do
if ($do == "show" || empty($do))

Process Flow:

1. Load store data for dropdown selection

2. Get category hierarchy for filtering

3. Process POST parameters for filtering criteria

4. Call show() function with filters

5. Display results via showprice.html template

Features:

---

2. show() - Core Report Generation Logic

Location: Line 291

Purpose: Build detailed product price report with customizable columns

Function Signature:

function show()

Process Flow:

1. Parse request parameters for filters and display options

2. Build dynamic SELECT columns based on user choices

3. Construct WHERE clause with filters:

- Product ID filter

- Store ID filter

- Category ID filter (with subcategories)

- Quantity range filters

- Zero quantity hiding

4. Execute query via queryWithqueryStringprice()

5. Process each product record:

- Apply inventory valuation method

- Calculate product paths/categories

- Apply discount calculations

- Generate barcodes

6. Return data array and sum value

Dynamic Column Building:

if (isset($productSellUnitPrice) && $productSellUnitPrice == '1') {
    $str2 .= ',product.productSellUnitPrice';
}
// Repeated for all optional columns

Inventory Valuation Methods:

switch ($Programsettingdata->Inventoryevaluation) {
    case "first": $pro_price = (float) $myproduct->productBuyPrice; break;
    case "last": $pro_price = (float) $myproduct->lastbuyprice; break;
    case "mean": $pro_price = (float) $myproduct->meanbuyprice; break;
    case "last_discount": $pro_price = (float) $myproduct->lastbuyprice_withDiscount; break;
    case "mean_discount": $pro_price = (float) $myproduct->meanbuyprice_withDiscount; break;
    default: $pro_price = (float) $myproduct->overAllAveragePrice; break;
}

---

3. showByProductNameAndStore() - Product/Store Report

Location: Line 736

Purpose: Generate report for specific product in specific store

Function Signature:

function showByProductNameAndStore()

Process Flow:

1. Get product ID and store ID from request

2. Query storedetail by product and store

3. Apply inventory valuation calculations

4. Calculate product category paths

5. Return formatted data array

---

4. showBystoreName() - Store-Based Report

Location: Line 819

Purpose: Show all products in a specific store

Function Signature:

function showBystoreName()

Process Flow:

1. Get store ID from request

2. Query all products in specified store

3. Apply valuation calculations for each product

4. Return comprehensive store inventory report

---

5. showByProductCatNameAndStoreId() - Category/Store Report

Location: Line 902

Purpose: Filter products by category within specific store

Function Signature:

function showByProductCatNameAndStoreId()

Process Flow:

1. Get category and store IDs

2. Query products matching category in store

3. Process inventory valuations

4. Generate category-specific report

---

6. getCategoryChilds() - Category Hierarchy

Location: Line 1084

Purpose: Build hierarchical category structure for filtering

Function Signature:

function getCategoryChilds($parentid = 0)

Returns:

return array($parentobject, $childsArray);
// [0] = Parent category object
// [1] = Array of child categories

---

7. getAllSubCat() - Recursive Category Processing

Location: Line 1094

Purpose: Recursively get all subcategories for filtering

Function Signature:

function getAllSubCat($catid, $mode)

Modes:

Global Variables Updated:

---

8. getProductPath_recursive() - Product Category Path

Location: Line 1049

Purpose: Build full category path for product display

Function Signature:

function getProductPath_recursive($parentid, $categories)

Returns: String like "Electronics/Computers/Laptops"

---

๐Ÿ”„ Workflows

Workflow 1: Basic Price List Generation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Access Price Report
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Load Initial Form
- Load store dropdown data
- Load category hierarchy
- Set default display options
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2User Selects Filters
- Choose store (optional)
- Select category (optional)
- Choose display columns
- Set quantity filters
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Build Dynamic Query
- Construct SELECT clause with chosen columns
- Build WHERE clause with filters
- Include category subcategories if applicable
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Execute Query and Process Results
FOR EACH product found:
โ”‚
โ†’ Apply inventory valuation method
โ”‚ (first/last/mean/discount/tax)
โ”‚
โ†’ Calculate product category path
โ”‚ (recursive parent lookup)
โ”‚
โ†’ Apply discount calculations
โ”‚ (direct amount or percentage)
โ”‚
โ”‚ โ””โ”€โ†’ Generate barcode if needed โ”‚
(ID-based or custom parcode)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Calculate Totals and Display
- Sum inventory values
- Apply template formatting
- Display via showprice.html
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐Ÿงฎ Calculation Methods

Inventory Valuation Options

switch ($Programsettingdata->Inventoryevaluation) {
    case "first":           // Original purchase price
    case "last":            // Latest purchase price  
    case "mean":            // Average purchase price
    case "last_discount":   // Latest with discount
    case "mean_discount":   // Average with discount
    case "tax":             // Latest with tax
    case "mean_tax":        // Average with tax
    default:                // Overall average
}

Discount Processing

if ($selldiscount == 1 && $storedetail->selldiscount > 0) {
    if ($storedetail->discounttype == 0) { // Direct discount
        $storedetail->productSellAllPrice -= $storedetail->selldiscount;
    } elseif ($storedetail->discounttype == 1) { // Percentage
        $storedetail->productSellAllPrice -= 
            $storedetail->productSellAllPrice * ($storedetail->selldiscount / 100);
    }
}

Barcode Generation

if ($Programsettingdata->usedParcode == 1) { // ID-based
    $storedetail->parcode = "i" . addPreDigitsToNum($myproduct->productId);
} else { // Custom parcode
    $storedetail->parcode = $myproduct->parcode;
}

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty) or `do=show`Default actionMain price report form and results
### Required Parameters

Main Price Report:

---

๐Ÿ”’ Security & Permissions

User Permission Levels

$usergroupdata = $myUserGroupRecord->load($_SESSION['usergroupid']);
if ($usergroupdata->hidecat == 1) {
    // Show full product category paths
    $storedetail->productName = $storedetail->productName . '/' . $pathArr;
} else {
    // Show product name only
    $storedetail->productName = $storedetail->productName;
}

Input Sanitization

---

๐Ÿ“Š Performance Considerations

Database Optimization Tips

1. Required Indexes:

- storedetail(storeid, productid)

- product(productCatId)

- productcat(productCatParent)

2. Query Optimization:

- Dynamic column selection reduces data transfer

- Category hierarchy pre-built to avoid N+1 queries

- Price calculations done in PHP vs database

3. Memory Management:

- Large product catalogs may require pagination

- Category recursion depth should be monitored

Known Performance Issues

-- This recursive category lookup can be slow
SELECT * FROM productcat WHERE productCatParent = ?
-- Solution: Consider materialized category paths or LTREE

---

๐Ÿ› Common Issues & Troubleshooting

1. Missing Product Prices

Issue: Products show zero or null prices

Cause: Inventory valuation method references missing price fields

Debug:

SELECT productId, productBuyPrice, lastbuyprice, meanbuyprice 
FROM product WHERE productId = [ID];

2. Category Filter Not Working

Issue: Category filter doesn't include subcategories

Cause: getAllSubCat() not properly building category list

Fix: Check $catsIDS global variable building

3. Quantity Filters Ignored

Issue: Quantity range filters don't work

Cause: Float conversion or SQL syntax errors

Debug:

echo "Query: " . $queryString; // Check built query

---

๐Ÿงช Testing Scenarios

Test Case 1: Basic Price Report

1. Access controller without filters
2. Verify all stores and categories load
3. Check default column display
4. Confirm price calculations match settings

Test Case 2: Category Filtering

1. Select parent category
2. Verify subcategories included
3. Test leaf category selection
4. Check category path display

Test Case 3: Discount Application

1. Enable discount display option
2. Test both direct and percentage discounts
3. Verify calculations across all price levels
4. Check rounding accuracy

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur