KnownWays Documentation

Known Ways Controller Documentation

File: /controllers/knownWaysController.php

Purpose: Manage customer acquisition channels and marketing source tracking for lead generation analysis

Last Updated: December 20, 2024

Total Functions: 6+

Lines of Code: ~252

---

๐Ÿ“‹ Overview

The Known Ways Controller manages a critical marketing and customer acquisition system that tracks how customers discover and connect with the business. This system enables comprehensive lead source analysis, marketing ROI tracking, and customer acquisition channel optimization by maintaining a master list of referral sources, marketing channels, and customer discovery methods.

Key Capabilities

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**knownways**Customer acquisition channelsid, name
### Integration Tables (Referenced)

Table NamePurposeKey Columns
**sellbill**Sales bills with known ways trackingsellbillid, knownwayid, sellbillclientid, conditions
### Configuration Tables

Table NamePurposeKey Columns
**youtubelink**Tutorial referencesyoutubelinkid, title, url
---

๐Ÿ”‘ Key Functions

1. add() - Create Known Way/Channel

Location: Line 192-202

Purpose: Create new customer acquisition channel or referral source

Function Signature:

function add()
// POST Parameter: name - Channel/source name

Implementation:

global $knownWays;
global $knownWaysDAO;

$name = $_POST['name'];

$knownWays->name = $name;
$knownWaysDAO->insert($knownWays);

Features:

---

2. show() - List All Known Ways

Location: Line 220-228

Purpose: Display all customer acquisition channels for management

Function Signature:

function show()
// Returns: Array of all known ways

Implementation:

global $knownWays;
global $knownWaysDAO;

$knownWaysData = $knownWaysDAO->queryAll();

return $knownWaysData;

Features:

---

3. delete() - Protected Deletion with Integrity Check

Location: Line 204-217

Purpose: Safely delete known way with referential integrity protection

Function Signature:

function delete($id)
// Parameter: id - Known way ID to delete
// Returns: 0 = success, 1 = cannot delete (has references)

Implementation:

global $knownWaysDAO;
global $sellBillExt;

// Check for sales bills using this known way
$allBills = $sellBillExt->queryAllByKnownWay($id);
if (count($allBills) > 0) {
    return 1; // Cannot delete - has references
} else {
    $knownWaysDAO->delete($id);
    return 0; // Deletion successful
}

Protection Logic:

1. Reference Check: Query all sales bills using this known way

2. Integrity Protection: If bills exist, prevent deletion

3. Safe Deletion: Only delete if no references exist

4. User Feedback: Return status code for appropriate messaging

Business Logic:

---

4. edit() - Load for Editing

Location: Line 231-236

Purpose: Load known way data for editing interface

Function Signature:

function edit($id)
// Parameter: id - Known way ID
// Returns: Known way object

Implementation:

global $knownWaysDAO;
$loadData = $knownWaysDAO->load($id);
return ($loadData);

---

5. update() - Modify Known Way

Location: Line 239-251

Purpose: Update existing known way information

Function Signature:

function update()
// POST Parameters: name, id

Implementation:

global $knownWays;
global $knownWaysDAO;

$name = $_POST['name'];
$id = $_POST['id'];

$knownWays->name = $name;
$knownWays->id = $id;
$knownWaysDAO->update($knownWays);

---

๐Ÿ”„ Workflows

Workflow 1: Customer Acquisition Channel Setup

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Setup Marketing Channel Tracking
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Identify Customer Acquisition Channels
- Website/Online search
- Social media platforms
- Referrals (word of mouth)
- Advertising campaigns
- Trade shows/events
- Partner referrals
- Cold calling/outreach
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Create Known Ways Records
FOR EACH Channel/Source:
โ”‚
โ†’ Enter descriptive channel name
โ†’ Create known way record
โ†’ Make available for sales team
โ”‚ โ””โ”€โ†’ Document channel for training โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Integrate with Sales Process
- Train sales team on channel selection
- Require channel selection on new sales bills
- Establish consistent tracking procedures
- Monitor channel usage and effectiveness
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Enable Marketing Analysis
- Generate channel performance reports
- Analyze customer acquisition costs
- Track conversion rates by channel
- Optimize marketing spend allocation
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

Workflow 2: Known Way Lifecycle Management

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Manage Known Way Lifecycle
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Regular Channel Review
- Review all existing known ways
- Assess channel relevance and effectiveness
- Identify outdated or redundant channels
- Plan for new channel additions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Channel Update Process
IF Channel Needs Update:
โ”‚ - Load existing channel data
โ”‚ - Update channel name/description
โ”‚ - Save changes
IF New Channel Needed:
โ”‚ - Create new known way record
โ”‚ - Train team on new channel
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Channel Deletion Assessment
- Attempt to delete obsolete channel
- IF Sales bills reference channel:
โ”‚ - Display cannot delete message
โ”‚ - Keep channel for historical integrity
โ”‚ - Consider marking as inactive (enhancement)
- IF No references exist:
โ”‚ - Safely delete channel
โ”‚ - Confirm deletion success
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Documentation and Training Update
- Update sales team training materials
- Communicate channel changes to team
- Update marketing tracking procedures
- Refresh reporting configurations
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
(empty)Default displayShow known ways creation form
`do=add``add()`Create new known way
`do=show``show()`Display all known ways
`do=delete``delete()`Delete known way (with protection)
`do=edit``edit()`Show known way edit form
`do=update``update()`Save known way changes
`do=sucess`Success pageDisplay success message
`do=error`Error pageDisplay error message
### Required Parameters by Action

Create Known Way (do=add):

Update Known Way (do=update):

Delete/Edit Operations:

---

๐Ÿงฎ Business Logic and Validation

Known Way Creation Logic

// Simple creation with name validation
if (!empty($name)) {
    $knownWays->name = $name;
    $knownWaysDAO->insert($knownWays);
}

Referential Integrity Protection

// Protection logic in delete function
$allBills = $sellBillExt->queryAllByKnownWay($id);
if (count($allBills) > 0) {
    return 1; // Cannot delete - has references
} else {
    $knownWaysDAO->delete($id);
    return 0; // Safe to delete
}

User Feedback Logic

// In delete action processing
$policyValid = delete($id);
if ($policyValid == 1) {
    $url = "knownWaysController.php?do=show";
    $smarty->assign('urldirect', $url);
    $note = "ู„ุง ูŠู…ูƒู† ุญุฐู ู‡ุฐุง ุงู„ุนู†ุตุฑ ู„ูˆุฌูˆุฏ ููˆุงุชูŠุฑ ุจูŠุน ู…ุฑุชุจุทุฉ ุจู‡";
    $smarty->assign('msgnote', $note);
    $smarty->display("notes2.html");
} else {
    header("location:?do=sucess");
}

---

๐Ÿ”’ Security & Permissions

Authentication Requirements

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

Input Validation

$name = $_POST['name'];
$id = $_POST['id'];

Security Features:

---

๐Ÿ› Common Issues & Troubleshooting

1. Deletion Prevention Message

Issue: Users cannot delete known ways that have sales bill references

Solution: This is expected behavior to protect data integrity

User Guidance:

"Cannot delete this item because there are sales bills linked to it"
(ู„ุง ูŠู…ูƒู† ุญุฐู ู‡ุฐุง ุงู„ุนู†ุตุฑ ู„ูˆุฌูˆุฏ ููˆุงุชูŠุฑ ุจูŠุน ู…ุฑุชุจุทุฉ ุจู‡)

Options for Users:

2. Missing Known Ways Integration

Issue: Sales bills created without known way selection

Prevention: Ensure sellbillController.php requires known way selection

3. Duplicate Known Ways

Enhancement Needed: Add duplicate name prevention:

function checkDuplicateName($name, $excludeId = null) {
    global $knownWaysDAO;
    $existing = $knownWaysDAO->queryByName($name);
    if ($excludeId) {
        $existing = array_filter($existing, function($item) use ($excludeId) {
            return $item->id != $excludeId;
        });
    }
    return count($existing) > 0;
}

4. Known Ways Reporting

Integration Point: Ensure knownwaysreportController.php properly references this data

---

๐Ÿ“Š Performance Considerations

Database Optimization

1. Essential Indexes:

   -- Known ways table
   CREATE INDEX idx_knownways_name ON knownways(name);
   
   -- Sales bill integration
   CREATE INDEX idx_sellbill_knownway ON sellbill(knownwayid, conditions);
   ```

2. **Query Optimization**:
   - Simple table structure enables fast queries
   - Referential integrity check may be slow with large sales volumes
   - Consider caching known ways for dropdown lists

### Memory Management
- Lightweight controller with minimal memory usage
- Efficient data structures for small master data table
- Standard cleanup practices

---

## ๐Ÿ“ˆ Marketing Analytics Integration

### Customer Acquisition Tracking
sql

-- Example analytics queries that would use this data

SELECT

kw.name as channel,

COUNT(sb.sellbillid) as sales_count,

SUM(sb.sellbillaftertotalbill) as total_sales,

AVG(sb.sellbillaftertotalbill) as avg_sale_value

FROM knownways kw

LEFT JOIN sellbill sb ON kw.id = sb.knownwayid

WHERE sb.conditions = 0

GROUP BY kw.id, kw.name

ORDER BY total_sales DESC;

### Channel Performance Metrics
- **Sales Volume by Channel**: Total sales attributed to each acquisition channel
- **Conversion Rate by Channel**: Sales conversion from leads by channel
- **Average Order Value by Channel**: Value analysis by acquisition source
- **Customer Lifetime Value by Channel**: Long-term value analysis
- **Cost per Acquisition by Channel**: ROI analysis for marketing spend

### Common Marketing Channels Examples
1. **Digital Channels**:
   - Google Search
   - Facebook Ads
   - LinkedIn
   - Instagram
   - Website Organic

2. **Traditional Channels**:
   - Print Advertising
   - Radio/TV
   - Trade Shows
   - Direct Mail

3. **Referral Channels**:
   - Customer Referral
   - Partner Referral
   - Employee Referral
   - Affiliate Program

4. **Direct Channels**:
   - Walk-in
   - Phone Call
   - Email Direct
   - Cold Outreach

---

## ๐Ÿงช Testing Scenarios

### Test Case 1: Known Ways CRUD Operations

1. Create new known way with valid name

2. Verify known way appears in listing

3. Edit known way name

4. Confirm changes saved correctly

5. Test deletion of unused known way

6. Verify deletion success

### Test Case 2: Referential Integrity Protection

1. Create known way and assign to sales bill

2. Attempt to delete known way

3. Verify deletion is prevented

4. Check appropriate error message displayed

5. Confirm known way still exists after failed deletion

### Test Case 3: Sales Bill Integration

1. Verify known ways appear in sales bill forms

2. Test sales bill creation with known way assignment

3. Check known way properly saved with sales bill

4. Validate reporting shows correct attribution

### Test Case 4: Data Quality

1. Test with empty known way names

2. Test with very long names

3. Test special characters in names

4. Verify proper encoding (Arabic text support)

```

---

๐Ÿ“š Related Documentation

---

๐ŸŽฏ Enhancement Opportunities

Potential Improvements

1. Status Management: Add active/inactive status for known ways

2. Category Grouping: Group channels by type (digital, traditional, referral)

3. Cost Tracking: Add marketing cost tracking per channel

4. Description Field: Add detailed description beyond just name

5. Duplicate Prevention: Add validation to prevent duplicate names

6. Bulk Operations: Support bulk import/export of channels

7. Usage Statistics: Track frequency of channel usage

8. Historical Tracking: Track when channels were created/modified

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur