Storeinquiriesreport Documentation

Store Inquiries Report Controller Documentation

File: /controllers/storeinquiriesreportController.php

Purpose: Generates inventory inquiry reports with product details, pricing, and discounts

Last Updated: December 21, 2024

Total Functions: 1

Lines of Code: ~180

---

๐Ÿ“‹ Overview

The Store Inquiries Report Controller is a simple reporting module that provides detailed product information across multiple stores with discount calculations. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**storedetail**Product quantities in storesstoredetailid, productid, storeid, productquantity
**product**Product master dataproductId, productName, productSellAllPrice, productSellHalfPrice, productSellUnitPrice
**store**Store master datastoreId, storeName
### Reference Tables

Table NamePurposeKey Columns
**programsettings**System configurationprogramsettingsid, settingkey, settingvalue
**youtubelink**Tutorial linksyoutubelinkid, title, url
---

๐Ÿ”‘ Key Functions

1. showAll() - Product Search and Display

Location: Line 124

Purpose: Search for products by ID or barcode, apply discounts, and display detailed product information

Function Signature:

function showAll()

Process Flow:

1. Parse input parameters:

- productId - Product ID for search

- productparcode - Product barcode for search

- selldiscount - Flag to apply discounts

2. Handle size/color product variants:

- Extract product ID, size ID, and color ID from complex IDs

- Format: {productId}hasSizeColor-{sizeId}-{colorId}

3. Build query string based on search criteria

4. Execute product search via queryAllByProudctnameandParcode()

5. Apply discount calculations if requested:

- Fixed amount discount: Direct subtraction

- Percentage discount: Calculate percentage and subtract

6. Round percentage discounts to 2 decimal places

7. Return processed product data

Key Variables:

Discount Calculation Logic:

if ($selldiscount == 1 && $item->selldiscount > 0) {
    if ($all->discounttype == 0) { // Fixed amount discount
        $item->productSellAllPrice -= $item->selldiscount;
        $item->productSellHalfPrice -= $item->selldiscount;
        $item->productSellUnitPrice -= $item->selldiscount;
    } elseif ($item->discounttype == 1) { // Percentage discount
        $item->productSellAllPrice -= $item->productSellAllPrice * ($item->selldiscount / 100);
        $item->productSellHalfPrice -= $item->productSellHalfPrice * ($item->selldiscount / 100);
        $item->productSellUnitPrice -= $item->productSellUnitPrice * ($item->selldiscount / 100);
        // Round to 2 decimal places
        $item->productSellAllPrice = round($item->productSellAllPrice, 2);
        $item->productSellHalfPrice = round($item->productSellHalfPrice, 2);
        $item->productSellUnitPrice = round($item->productSellUnitPrice, 2);
    }
}

---

๐Ÿ”„ Workflows

Workflow 1: Product Search and Price Calculation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Product Search Request
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Parse Input Parameters
- Check if search by productId or barcode
- Extract discount flag
- Handle size/color product variants
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Build Query String
IF productId provided:
โ”‚
โ†’ Check for size/color variant
โ”‚ โ”œโ”€ Extract productId, sizeId, colorId
โ”‚ โ”‚ โ””โ”€ Add product filter to query โ”‚
โ”‚
ELSIF barcode provided:
โ”‚
โ”‚ โ””โ”€โ†’ Add barcode filter to query โ”‚
ELSE: Return empty result
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Execute Product Search
- Query database via queryAllByProudctnameandParcode()
- Retrieve all matching products
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Process Discount Calculations
IF selldiscount flag is set:
โ”‚
FOR EACH product with discount > 0:
โ”‚
IF discounttype == 0 (Fixed Amount):
โ”‚
โ†’ Subtract discount from all price levels
โ”‚
ELSIF discounttype == 1 (Percentage):
โ”‚
โ†’ Calculate percentage discount
โ†’ Apply to all price levels
โ”‚ โ””โ”€โ†’ Round results to 2 decimal places โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Return Processed Results
- Return array of products with adjusted prices
- Include all store details and quantities
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionDisplay search form
`do=showAll``showAll()`Execute product search and display results
### Required Parameters

Default Action (do= empty):

Product Search (do=showAll):

Special Parameter Handling

---

๐Ÿงฎ Calculation Methods

Discount Calculations

Fixed Amount Discount:

if ($item->discounttype == 0) {
    $newPrice = $originalPrice - $discountAmount;
}

Percentage Discount:

if ($item->discounttype == 1) {
    $discountAmount = $originalPrice * ($discountPercentage / 100);
    $newPrice = $originalPrice - $discountAmount;
    $newPrice = round($newPrice, 2); // Round to 2 decimal places
}

Size/Color Product Parsing

if (strpos($productId, "hasSizeColor") !== false) {
    $productIdComplex = explode('-', str_replace("hasSizeColor", "", $productId));
    $productId = $productIdComplex[0];    // Main product ID
    $sizeId = $productIdComplex[1];       // Size variant ID
    $colorId = $productIdComplex[2];      // Color variant ID
}

---

๐Ÿ”’ Security & Permissions

Input Sanitization

Authentication

Data Access Control

---

๐Ÿ“Š Performance Considerations

Database Optimization Tips

1. Indexes Required:

- product(productId) - Primary key (already exists)

- storedetail(productid, storeid) - Composite for joins

- product(productName) - For name-based searches

2. Query Optimization:

- Uses efficient DAO layer with prepared statements

- Single query retrieves all needed product/store data

- Minimal database round trips

Known Performance Issues

---

๐Ÿ› Common Issues & Troubleshooting

1. No Results Returned

Issue: Search returns empty result set

Cause: Both productId and barcode parameters are empty

Debug:

// Check query string construction
if (empty($productId) && empty($productparcode)) {
    $queryString .= "product.productId = ''"; // Returns no results
}

2. Discount Not Applied

Issue: Expected discount calculations not showing

Cause: selldiscount flag not set or product has no discount value

Fix:

// Ensure conditions are met
if ($selldiscount == 1 && $item->selldiscount > 0) {
    // Discount will be applied
}

3. Size/Color Products Not Found

Issue: Complex product IDs not parsing correctly

Cause: Incorrect format or missing size/color data

Debug:

// Verify format: "123hasSizeColor-5-7"
if (strpos($productId, "hasSizeColor") !== false) {
    // Should extract: productId=123, sizeId=5, colorId=7
}

---

๐Ÿงช Testing Scenarios

Test Case 1: Basic Product Search

1. Use valid product ID
2. Set selldiscount=0
3. Verify product details returned
4. Check all price fields populated

Test Case 2: Discount Application

1. Use product with configured discount
2. Set selldiscount=1  
3. Test both fixed amount and percentage discounts
4. Verify price calculations are correct
5. Check rounding for percentage discounts

Test Case 3: Size/Color Product Search

1. Use complex ID format: "123hasSizeColor-5-7"
2. Verify parsing extracts correct IDs
3. Check query finds specific variant
4. Validate result contains size/color data

Test Case 4: Barcode Search

1. Use product barcode instead of ID
2. Verify search finds correct product
3. Check all functionality works same as ID search

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur