Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ERP Template

The ERP (Enterprise Resource Planning) template provides comprehensive inventory management, purchasing, and warehouse operations through a conversational AI interface.

Topic: Enterprise Resource Planning & Inventory

This template is perfect for:

  • Warehouse management
  • Inventory tracking
  • Purchase order processing
  • Stock transfers
  • Cycle counting and audits

The Code

ADD TOOL "inventory-management"
ADD TOOL "purchasing"
ADD TOOL "erp-jobs"

SET CONTEXT "erp" AS "You are an ERP assistant helping with inventory management, purchasing, and warehouse operations. Help users receive inventory, ship orders, check stock levels, transfer between warehouses, and conduct cycle counts."

CLEAR SUGGESTIONS

ADD SUGGESTION "receive" AS "Receive inventory"
ADD SUGGESTION "ship" AS "Ship order"
ADD SUGGESTION "stock" AS "Check stock"
ADD SUGGESTION "transfer" AS "Transfer stock"
ADD SUGGESTION "count" AS "Cycle count"
ADD SUGGESTION "purchase" AS "Create PO"

BEGIN TALK
**ERP Inventory Manager**

I can help you with:
• Receive inventory from purchase orders
• Ship orders to customers
• Check stock levels across warehouses
• Transfer stock between locations
• Conduct cycle counts
• Create and manage purchase orders

What would you like to do?
END TALK

BEGIN SYSTEM PROMPT
You are an ERP inventory management assistant.

Key operations:
- receive_inventory: Process incoming goods from POs
- ship_inventory: Process outgoing shipments for sales orders
- check_stock: Query inventory levels
- transfer_stock: Move inventory between warehouses
- cycle_count: Physical inventory verification

Always confirm quantities before processing.
Log all transactions for audit trail.
Alert on low stock and reorder points.
END SYSTEM PROMPT

Sample Dialogs

These conversations show how the ERP template works in real-world scenarios.

Dialog 1: Receiving Inventory

Dialog 2: Check Stock Levels

Dialog 3: Ship an Order

Dialog 4: Transfer Stock

Keywords Used

KeywordPurpose
ADD TOOLRegister ERP operation tools
SET CONTEXTDefine ERP assistant behavior
FINDQuery inventory and orders
SAVERecord transactions
UPDATEModify stock levels
SEND MAILNotify stakeholders

Template Structure

erp.gbai/
├── erp.gbdialog/
│   ├── inventory-management.bas  # Stock operations
│   ├── purchasing.bas            # PO management
│   ├── erp-jobs.bas             # Scheduled tasks
│   └── tables.bas               # Data structures
└── erp.gbot/
    └── config.csv               # Configuration

Data Tables

Items Table

FieldDescription
idUnique item identifier
item_codeSKU/product code
nameItem description
categoryProduct category
unit_of_measureUOM (each, case, etc.)
minimum_stock_levelReorder threshold
reorder_pointWhen to reorder
reorder_quantityHow much to order
average_costWeighted average cost
last_costMost recent purchase cost

Inventory Stock Table

FieldDescription
item_idReference to item
warehouse_idLocation
quantity_on_handPhysical count
quantity_reservedAllocated to orders
quantity_availableOn hand minus reserved
last_movement_dateLast transaction
last_counted_dateLast physical count

Inventory Transactions Table

FieldDescription
transaction_typereceipt, shipment, transfer, adjustment
transaction_numberUnique reference
item_idItem affected
warehouse_idLocation
quantityAmount (+/-)
unit_costCost per unit
reference_typePO, SO, Transfer
reference_idSource document

Inventory Management Tool

PARAM action AS STRING LIKE "check_stock" DESCRIPTION "Action: receive_inventory, ship_inventory, check_stock, transfer_stock, cycle_count"
PARAM item_data AS OBJECT LIKE "{po_number: 'PO-123'}" DESCRIPTION "Data object with action-specific parameters"

DESCRIPTION "Manage inventory operations"

user_id = GET "session.user_id"
warehouse_id = GET "session.warehouse_id"

IF action = "receive_inventory" THEN
    po_number = item_data.po_number
    po = FIND "purchase_orders", "po_number = '" + po_number + "'"
    
    IF NOT po THEN
        TALK "Purchase order not found."
        RETURN NULL
    END IF
    
    po_lines = FIND "purchase_order_lines", "po_id = '" + po.id + "'"
    
    FOR EACH line IN po_lines
        item = FIND "items", "id = '" + line.item_id + "'"
        
        TALK "Receiving " + item.name + " - Ordered: " + line.quantity_ordered
        TALK "Enter quantity received:"
        HEAR qty_received AS INTEGER
        
        ' Update stock
        stock = FIND "inventory_stock", "item_id = '" + item.id + "' AND warehouse_id = '" + warehouse_id + "'"
        
        IF NOT stock THEN
            WITH newStock
                item_id = item.id
                warehouse_id = warehouse_id
                quantity_on_hand = qty_received
            END WITH
            SAVE "inventory_stock", newStock
        ELSE
            new_qty = stock.quantity_on_hand + qty_received
            UPDATE "inventory_stock" SET quantity_on_hand = new_qty WHERE id = stock.id
        END IF
        
        ' Create transaction record
        WITH transaction
            transaction_type = "receipt"
            item_id = item.id
            warehouse_id = warehouse_id
            quantity = qty_received
            unit_cost = line.unit_price
            reference_type = "purchase_order"
            reference_id = po.id
            created_at = NOW()
        END WITH
        
        SAVE "inventory_transactions", transaction
    NEXT
    
    UPDATE "purchase_orders" SET status = "received" WHERE id = po.id
    TALK "Purchase order " + po_number + " received."
END IF

IF action = "check_stock" THEN
    item_search = item_data.item_search
    items = FIND "items", "name LIKE '%" + item_search + "%'"
    
    FOR EACH item IN items
        TALK "📦 " + item.name + " (" + item.item_code + ")"
        
        stocks = FIND "inventory_stock", "item_id = '" + item.id + "'"
        total = 0
        
        FOR EACH stock IN stocks
            warehouse = FIND "warehouses", "id = '" + stock.warehouse_id + "'"
            TALK "  " + warehouse.name + ": " + stock.quantity_on_hand
            total = total + stock.quantity_on_hand
        NEXT
        
        TALK "  **TOTAL:** " + total
        
        IF total < item.minimum_stock_level THEN
            TALK "  ⚠️ Below minimum (" + item.minimum_stock_level + ")"
        END IF
    NEXT
END IF

Scheduled Jobs: erp-jobs.bas

PARAM jobname AS STRING DESCRIPTION "Job to execute"

IF jobname = "low stock alert" THEN
    SET SCHEDULE "0 8 * * *"  ' Daily at 8 AM
    
    ' Find items below reorder point
    low_items = SQL "SELECT i.*, s.quantity_on_hand 
                     FROM items i 
                     JOIN inventory_stock s ON i.id = s.item_id 
                     WHERE s.quantity_on_hand <= i.reorder_point"
    
    IF UBOUND(low_items) > 0 THEN
        report = "Low Stock Alert\n\n"
        FOR EACH item IN low_items
            report = report + item.name + ": " + item.quantity_on_hand + " (reorder at " + item.reorder_point + ")\n"
        NEXT
        
        SEND MAIL "purchasing@company.com", "Daily Low Stock Alert", report
    END IF
END IF

IF jobname = "pending shipments" THEN
    SET SCHEDULE "0 7 * * *"  ' Daily at 7 AM
    
    pending = FIND "sales_orders", "status = 'ready_to_ship'"
    
    TALK "📦 " + UBOUND(pending) + " orders ready to ship today."
    
    SEND MAIL "warehouse@company.com", "Pending Shipments", 
        UBOUND(pending) + " orders need to be shipped today."
END IF

Best Practices

  1. Always Verify Quantities: Confirm counts before processing
  2. Maintain Audit Trail: Log all inventory movements
  3. Regular Cycle Counts: Schedule periodic physical inventory
  4. Monitor Reorder Points: Act on low stock alerts promptly
  5. Validate PO/SO Numbers: Check document existence before processing
  6. Cost Tracking: Maintain accurate cost records for COGS