CateResturant Documentation

Restaurant Category Controller Documentation

File: /controllers/cateResturantController.php

Purpose: Manages restaurant category configuration and product assignments for restaurant operations

Last Updated: December 20, 2024

Total Functions: 3

Lines of Code: ~315

---

๐Ÿ“‹ Overview

The Restaurant Category Controller is a specialized module for configuring restaurant product categories and their assignments. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**resturantcategory**Restaurant category assignmentsid, categoryId, productId, date
### Reference Tables

Table NamePurposeKey Columns
**productcat**Product categoriesproductCatId, productCatName, parentExt
**product**Product master dataproductId, productName, productCatId
**youtubelink**Tutorial videosyoutubelinkid, title, url
**programsettings**System configurationprogramsettingsid, settingkey, settingvalue
### Sales Integration Tables

Table NamePurposeKey Columns
**sellbill**Sales billssellbillid, sellbillclientid, sellbilltotalbill
**returnsellbill**Sales returnsreturnsellbillid, returnsellbillclientid
**sellbillandrutern**Combined billssellbillid, sellbillclientid, sellbillprice
**billsproduct**Bill productsbillsproductid, productid, quantity
**billsreturnproduct**Return productsbillsreturnproductid, productid, quantity
---

๐Ÿ”‘ Key Functions

1. show() / Default Action - Restaurant Category Configuration Display

Location: Line 188

Purpose: Display the restaurant category configuration interface with products and categories

Process Flow:

1. Include authentication check

2. Set default date parameters

3. Load category hierarchy via getCategoryChilds()

4. Load all products for assignment

5. Load YouTube tutorial links

6. Display via cateResturantview/show.html template

Template Variables:

---

2. add() - Restaurant Category Assignment

Location: Line 276

Purpose: Process restaurant category assignments for up to 3 categories

Function Signature:

function add()

Process Flow:

1. Get current date

2. Process three category/product pairs:

- productCatId1 / productSearchId1

- productCatId2 / productSearchId2

- productCatId3 / productSearchId3

3. For each pair:

- Create new Resturantcategory object

- Set category and product IDs

- Set current date

- Set fixed ID (1, 2, or 3)

- Update via DAO

Assignment Logic:

$resturantCategory = new Resturantcategory();
$resturantCategory->categoryId = $productCatId1;
$resturantCategory->productId = $productSearchId1;
$resturantCategory->date = $startDate;
$resturantCategory->id = 1;
$ResturantCategoryDAO->update($resturantCategory);

---

3. getAllSubCat() - Category Hierarchy Navigation

Location: Line 237

Purpose: Recursively traverse product category hierarchy

Function Signature:

function getAllSubCat($catid, $mode)

Parameters:

- 1 - Get all sub-categories

- 2 - Get last level categories only

Process Flow:

1. Query child categories for given parent

2. For each child:

- If mode 1: Add to category ID list and recurse

- If mode 2: Check if leaf node, add to last level list

3. Continue recursively until all levels processed

Global Variables Used:

---

๐Ÿ”„ Workflows

Workflow 1: Restaurant Category Configuration

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Restaurant Category Configuration
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Load Configuration Interface
- Authentication check
- Load category hierarchy
- Load product list
- Load tutorial links
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2User Selects Categories and Products
- Category 1 + Product 1
- Category 2 + Product 2
- Category 3 + Product 3
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Process Assignments
FOR EACH category/product pair:
โ”‚
โ†’ Create restaurant category object
โ”‚
โ†’ Set category and product IDs
โ”‚
โ†’ Set assignment date
โ”‚
โ”‚ โ””โ”€โ†’ Update database record โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Complete Assignment
- Redirect to success page
- Display confirmation message
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty) or `do=show`Default actionDisplay category configuration interface
`do=add``add()`Process category assignments
`do=sucess`N/ADisplay success message
`do=error`N/ADisplay error message
### Required Parameters by Action

Category Configuration Display (do=show):

Process Assignments (do=add):

---

๐Ÿงฎ Calculation Methods

Category Assignment Logic

// Process three fixed assignments
for ($i = 1; $i <= 3; $i++) {
    $resturantCategory = new Resturantcategory();
    $resturantCategory->categoryId = $_POST["productCatId{$i}"];
    $resturantCategory->productId = $_REQUEST["productId{$i}"];
    $resturantCategory->date = date('Y-m-d');
    $resturantCategory->id = $i;
    $ResturantCategoryDAO->update($resturantCategory);
}

Category Hierarchy Traversal

function getAllSubCat($catid, $mode) {
    $result = $productCatExt->queryByParentExt($catid);
    if (count($result) > 0) {
        foreach ($result as $data) {
            if ($mode == 1) {
                $catsIDS .= "," . $data->productCatId;
                getAllSubCat($data->productCatId, $mode);
            } elseif ($mode == 2) {
                $childData = $productCatExt->queryByParentExt($data->productCatId);
                if (count($childData) == 0) {
                    array_push($lastLevelCatIDS, $data->productCatId);
                } else {
                    getAllSubCat($data->productCatId, $mode);
                }
            }
        }
    }
}

---

๐Ÿ”’ Security & Permissions

Authentication Requirements

include_once("../public/authentication.php");

Input Sanitization

Data Validation

---

๐Ÿ“Š Performance Considerations

Database Optimization Tips

1. Indexes Required:

- resturantcategory(categoryId, productId)

- productcat(parentExt) for hierarchy queries

- product(productCatId) for category filtering

2. Query Optimization:

- Category hierarchy loaded once per page

- Product list cached in template

- Limited to 3 assignments reduces update overhead

3. Memory Management:

- Minimal data processing

- Simple object creation and updates

- No complex calculations or loops

---

๐Ÿ› Common Issues & Troubleshooting

1. Category Assignment Failures

Issue: Category assignments not saving properly

Cause: Missing product or category IDs in POST data

Debug:

var_dump($_POST['productCatId1'], $_REQUEST['productId1']);

2. Category Hierarchy Loading Issues

Issue: Categories not displaying in interface

Cause: Recursive function stack overflow or missing parent references

Fix:

// Add depth limit to recursive function
function getAllSubCat($catid, $mode, $depth = 0) {
    if ($depth > 10) return; // Prevent infinite recursion
    // ... existing code
    getAllSubCat($data->productCatId, $mode, $depth + 1);
}

3. Product Loading Performance

Issue: Slow page load when many products exist

Cause: Loading all products without pagination

Solution:

---

๐Ÿงช Testing Scenarios

Test Case 1: Basic Category Assignment

1. Access category configuration page
2. Select 3 different categories
3. Assign 3 different products
4. Submit assignments
5. Verify database updates
6. Check success page display

Test Case 2: Category Hierarchy Navigation

1. Load page with multi-level categories
2. Verify hierarchy displays correctly
3. Test category selection from different levels
4. Confirm parent-child relationships maintained

Test Case 3: Error Handling

1. Submit form with missing data
2. Verify error handling
3. Test with invalid category/product IDs
4. Confirm graceful error messages

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When restaurant module changes occur