Developer Guide: Physical Stock Taking, Modifiers Engine & Manual GRN Receiving Protocol
lynx-anchor
lynx-anchor
lynx-anchor
lynx-anchor
This technical guide documents the Physical Inventory Audit & Stock Taking Subsystem, Item Modifiers & Recipe Deductions, Dietary Food Tagging, and the Strict Manual Goods Receiving Note (GRN) Protocol.
Table of Contents
- Physical Stock Taking & Inventory Variance Architecture
- Item Modifiers & Recipe Stock Deduction Engine
- Dietary Tagging in Item Master (
food_type,is_veg) - Waiter & Captain Floor App Kitchen KOT Pipeline
- Critical Protocol Correction: Manual GRN Receiving Rule
1. Physical Stock Taking & Inventory Variance Architecture
sequenceDiagram
autonumber
actor Auditor as Store Auditor / Manager
participant UI as Stock Taking Screen (stock_taking_screen.dart)
participant Ctrl as Stock Taking Controller (/api/inventory/stock-taking)
participant Ledger as Stock Ledger Table (stock_ledger)
participant DB as PostgreSQL (stock_taking, item_master)
Auditor->>UI: Filters by Department / Search Query
UI->>Ctrl: GET /api/inventory/stock-taking/sheet?department=DAIRY
Ctrl->>DB: Compute Current Balance for items: Opening + SUM(In - Out)
Ctrl-->>UI: Item list with system balances
Auditor->>UI: Inputs Counted / In-Hand Qty & Discrepancy Reason
UI->>UI: Compute Variance: Counted Qty - System Balance
Auditor->>UI: Clicks "Save & Reconcile Stock"
UI->>Ctrl: POST /api/inventory/stock-taking/reconcile { items: [{ item_id, system_qty, counted_qty, variance, reason }] }
loop For each item with variance != 0
alt Variance < 0 (Shortage / Damage / Theft)
Ctrl->>Ledger: INSERT transaction_type: 'STOCK_ADJUSTMENT', qty_out: |variance|
else Variance > 0 (Surplus / Found Stock)
Ctrl->>Ledger: INSERT transaction_type: 'STOCK_ADJUSTMENT', qty_in: variance
end
end
Ctrl->>DB: Archive Audit Session with audit_no (STK-YYYYMMDD-XXXX)
Ctrl-->>UI: 200 OK & Stock Balances Reconciled
Table Grid Schema:
| Column Key | Display Label | Type | Calculation / Source |
|---|---|---|---|
item_name | Item Name & Code | String | item_master.item_name |
unit | Unit of Measure | String | item_master.unit (e.g. PCS, KG, LTR) |
system_qty | Current Balance | Decimal | Live stock ledger calculation |
counted_qty | Counted / In Hand | Decimal | Editable auditor input |
variance | Variance | Decimal | $Counted Qty - System Balance$ |
reason | Reason / Remarks | String | Standardized enum reason code |
2. Item Modifiers & Recipe Stock Deduction Engine
Modifiers allow configurable add-ons and preparation variations (e.g. Extra Cheese, Almond Milk, Double Patty).
[!NOTE] Unified Item Master Architecture: Rather than maintaining a separate disconnected "Modifier Master", modifiers and add-ons are modeled as first-class items within
item_master(is_modifier = TRUE). This allows modifiers to have barcodes, tax rates, selling prices, and optional BOM raw material consumption links directly within the unified catalogue.
Database Schema in item_master:
ALTER TABLE item_master
ADD COLUMN IF NOT EXISTS is_modifier BOOLEAN DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS applicable_item_ids TEXT,
ADD COLUMN IF NOT EXISTS deduct_raw_item_id INTEGER REFERENCES item_master(id),
ADD COLUMN IF NOT EXISTS deduct_qty DECIMAL(12, 4) DEFAULT 0;
Raw Material Deduction on Sale:
When an item with modifier "Extra Cheese" (deduct_raw_item_id = 45 [Processed Cheese Block], deduct_qty = 0.05 KG) is sold:
if (modifier.deduct_raw_item_id && modifier.deduct_qty > 0) {
await db.models.stock_ledger.create({
outlet_id,
item_id: modifier.deduct_raw_item_id,
transaction_type: 'SALE_MODIFIER_CONSUMPTION',
qty_out: modifier.deduct_qty * salesItem.qty,
reference_id: `SALE-${saleId}`
});
}
3. Dietary Tagging in Item Master (food_type, is_veg)
Menu items support standardized dietary indicators across Floor Apps, QR Menus, and KDS:
ALTER TABLE item_master
ADD COLUMN IF NOT EXISTS food_type VARCHAR(20) DEFAULT 'VEG',
ADD COLUMN IF NOT EXISTS dietary_type VARCHAR(20) DEFAULT 'VEG',
ADD COLUMN IF NOT EXISTS is_veg BOOLEAN DEFAULT TRUE;
VEG/is_veg = true: Rendered with Green Veg emblem ().NON_VEG/is_veg = false: Rendered with Red Non-Veg emblem ().EGG: Rendered with Yellow Egg emblem ().
4. Waiter & Captain Floor App Kitchen KOT Pipeline
The mobile Floor App (waiter_auth_screen.dart and captain_dashboard_screen.dart) enables floor servers to post orders directly to the kitchen:
- Select active table $\rightarrow$ Pick dishes with modifier add-ons $\rightarrow$ Tap Send KOT.
- Atomic KOT insertion into
kot_headersandkot_items. - Kitchen Display Screens (KDS) update live via WebSocket event
NEW_KOT_ORDER. - Thermal kitchen printers automatically spool KOT chits.
5. Critical Protocol Correction: Manual GRN Receiving Rule
[!IMPORTANT] CORRECTION TO PREVIOUS DOCUMENTATION: Previous draft documentation incorrectly stated that Goods Receiving Notes (GRN) are automatically generated when Purchase Orders are placed or when items are purchased on the B2B Marketplace.
THE REALITY & ENFORCED RULE: Goods Receiving Notes (GRN) / Receiving are NEVER created automatically. In enterprise retail and inventory governance:
- Placing a Purchase Order (PO) only creates a purchase contract (
status: 'PENDING').- Inventory balances in
stock_ledgeranditem_masterMUST NOTincrease until physical goods actually arrive at the store.- The store operator / warehouse receiver must open Purchases $\rightarrow$ Goods Receiving (GRN), physically count and inspect delivered packages, verify batch/expiry dates, enter actual accepted quantities, and manually click Save & Receive Stock.
- Only after this manual operator action is the formal
GRN-record generated and inventory debited to the stock ledger.