๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

Notice Functions Documentation

File: /controllers/noticefunctions.php

Purpose: Utility functions for calculating business notifications and alerts across the system

Last Updated: December 20, 2024

Total Functions: 20+

Lines of Code: ~693

---

๐Ÿ“‹ Overview

The Notice Functions file provides centralized utility functions for calculating various business notifications used throughout the ERP system. These functions analyze data patterns, track business metrics, and generate alerts for critical business conditions requiring attention.

Primary Functions

---

๐Ÿ—„๏ธ Database Tables

Core Data Tables

Table NamePurposeKey Columns
**product**Product masterproductid, productName, productCatId
**storedetail**Inventory levelsproductid, storedetailquantity
**sellbilldetail**Sales historysellbilldetailproductid, sellbilldetaildate
**datedchecked**Check managementdatedcheckedid, checkvalue, done, addtype
**kempiala**Promissory noteskempialaid, kempialadate
**productrequest**Product requestsproductrequestid, status, seen, storeid
**otherrequest**General requestsotherrequestid, requestto, requesttoid
---

๐Ÿ”‘ Key Functions

1. calcNotice() - Main Notification Calculator

Location: Lines 107-173

Purpose: Calculate total notification count based on user group permissions

Function Signature:

function calcNotice()

Process Flow:

1. Load user group permissions

2. Calculate counts for each notification type:

- Product inventory alerts

- Non-selling products

- Promissory notes due

- Client checks due

- Supplier checks due

3. Apply user group filters to determine visible notifications

4. Return total notification count

User Group Permission Logic:

if ($Usergroup->productno == 0) {
    $sum += $productcount; // Include product notifications
}
if ($Usergroup->kempilano == 0) {
    $sum += $allkempilacount; // Include promissory note notifications
}
// ... additional permission checks

---

2. getProductRequestNotice() - Product Request Alerts

Location: Lines 175-216

Purpose: Calculate product request notification counts based on user role

Process Flow:

1. Admin Users (storeId == 0): See all requests across stores

- New requests: status = 0

- Accepted requests: status in (2, 3)

- Refused requests: status = 1

2. Store Users: See requests relevant to their store

- Incoming requests: Other stores requesting from them

- Response notifications: Status updates on their requests

---

3. getOtherRequestsNotice() - General Request Notifications

Location: Lines 298-373

Purpose: Calculate general business request notifications

Request Target Types:

---

4. getToWorkshopOrderNotice() - Workshop Delay Alerts

Location: Lines 375-425

Purpose: Calculate workshop order delay notifications

Delay Categories:

1. Delivery Delays: Orders not delivered to workshop on time

2. Workshop Processing Delays: Orders exceeding workshop timeout

3. Return Delays: Completed orders not returned to branch

Permission Logic:

if ($_SESSION['userid'] == 1) {
    $showOnlyToQyeryString = ""; // Admin sees all
} else {
    $showOnlyToQyeryString = " and ( branchId = " . $_SESSION['branchId'] . 
                           " or driverId = " . $_SESSION['userid'] . 
                           " or driverIdBack = " . $_SESSION['userid'] . " ) ";
}

---

5. showallproductx2() - Low Stock Product Analysis

Location: Lines 549-568

Purpose: Identify products requiring restocking attention

Features:

---

6. productnotsell() - Non-Selling Product Detection

Location: Lines 585-613

Purpose: Identify products with no sales in past 7 days

Date Logic:

$today = date("Y-m-d");
$todayfor7days = date("Y-m-d", strtotime($today . ' - 7 day'));
$allsell = $SellbilldetailEX->queryproductnotsell($todayfor7days, $today);

---

7. checkforclient() / checkforsupplier() - Check Due Monitoring

Location: Lines 615-639

Purpose: Monitor checks becoming due within 7 days

---

8. dateTimeDiff2() - Workshop Time Calculation

Location: Lines 664-671

Purpose: Calculate time differences for workshop delay detection

---

9. getInsuranceBillNotifNotice() - Insurance Alert Counter

Location: Lines 673-681

Purpose: Count insurance bills requiring attention

---

10. getPremiumToday() - Daily Premium Alerts

Location: Lines 683-692

Purpose: Count premium payments due today for current user

---

๐Ÿ”„ Workflows

Notification Calculation Workflow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Calculate Total Notifications
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Load User Permissions
โ†’ Get user group from session
โ†’ Load permission settings
โ”‚ โ””โ”€โ†’ Determine which notifications user can see โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Calculate Individual Notification Counts
โ†’ showallproductx2() - Low stock products
โ†’ productnotsell() - Non-selling products
โ†’ showallkempila() - Due promissory notes
โ†’ checkforclient() - Client checks due
โ†’ checkforsupplier() - Supplier checks due
โ†’ getProductRequestNotice() - Product requests
โ†’ getOtherRequestsNotice() - General requests
โ†’ getToWorkshopOrderNotice() - Workshop delays
โ†’ getInsuranceBillNotifNotice() - Insurance bills
โ”‚ โ””โ”€โ†’ getPremiumToday() - Premium payments due โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Apply Permission Filters
โ†’ Check user group permission for each type
โ†’ Include/exclude counts based on permissions
โ”‚ โ””โ”€โ†’ Sum only allowed notification types โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Return Total Badge Count
โ”‚ โ””โ”€โ†’ Display notification badge in system header โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐Ÿงฎ Calculation Methods

Time Difference Calculation

function dateTimeDiff2($dateTime1, $dateTime2) {
    $dateTime1 = new DateTime($dateTime1);
    $dateTime2 = new DateTime($dateTime2);
    $diff = $dateTime2->diff($dateTime1);
    $hours = $diff->h + ($diff->days * 24);
    return $hours;
}

Product Path Generation

function getProductPath_recursive1($parentid, $categories, $level) {
    global $productCatExt;
    $catData = $productCatExt->getCategoryAndParentByCatId($parentid);
    
    if (count($catData) > 0 && $level < 2) {
        $categories .= $catData->productCatName . '/';
        $newParentId = $catData->productCatParent;
        return getProductPath_recursive1($newParentId, $categories, ($level + 1));
    }
    return substr($categories, 0, strlen($categories) - 1);
}

---

๐Ÿ”’ Security & Performance

Role-Based Access Control

// Store-level filtering for non-admin users
if ($storeId == 0 || empty($storeId)) {
    // Admin user - see all requests
    $newRequests = $productRequestExt->getRequestsWithString('and p.status = 0', ' and p.seen = 0', 0);
} else {
    // Store user - see only relevant requests
    $string2 = 'and p.status = 0 and p.storeid = ' . $storeId . ' ';
    $otherNewRequests = $productRequestExt->getRequestsWithString($string2, ' and p.seen = 0', 0);
}

Performance Considerations

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur

โ†‘