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
- โข Master data management for customer acquisition channels
- โข Lead source tracking and categorization
- โข Marketing channel effectiveness analysis
- โข Referential integrity protection with sales bill integration
- โข CRUD operations for known ways/channels management
- โข Integration with sales bill customer acquisition tracking
- โข YouTube tutorial integration for user guidance
Primary Functions
- โ Create and manage customer acquisition channels (Known Ways)
- โ Track lead sources and referral methods
- โ Maintain referential integrity with sales bills
- โ Prevent deletion of channels with associated sales data
- โ Support marketing channel analysis and optimization
- โ Provide lead source categorization and management
- โ Integration with customer onboarding workflows
Related Controllers
- โข sellbillController.php - Sales bill integration
- โข clientController.php - Customer management
- โข knownwaysreportController.php - Known ways analytics
- โข marketingController.php - Marketing management (if exists)
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns |
|---|---|---|
| **knownways** | Customer acquisition channels | id, name |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **sellbill** | Sales bills with known ways tracking | sellbillid, knownwayid, sellbillclientid, conditions |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **youtubelink** | Tutorial references | youtubelinkid, 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:
- โข Simple channel creation
- โข Name-based identification
- โข Integration with sales tracking
- โข Immediate availability for sales bill assignment
---
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:
- โข Complete channel listing
- โข Management interface support
- โข Integration with reporting systems
---
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:
- โข Protects historical sales data integrity
- โข Prevents orphaned referral source references
- โข Maintains marketing analysis accuracy
- โข Ensures audit trail preservation
---
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
---
Workflow 2: Known Way Lifecycle Management
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| (empty) | Default display | Show 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 page | Display success message | |
| `do=error` | Error page | Display error message |
Create Known Way (do=add):
- โข
name- Channel/source name (required)
Update Known Way (do=update):
- โข
id- Known way ID (required) - โข
name- Updated channel name
Delete/Edit Operations:
- โข
id- Known way ID (required via GET parameter)
---
๐งฎ 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");
- โข All operations require valid user session
- โข Standard authentication integration
- โข Session-based access control
Input Validation
$name = $_POST['name'];
$id = $_POST['id'];
Security Features:
- โข Basic input handling through POST parameters
- โข DAO layer provides SQL injection protection
- โข Referential integrity protection through business logic
- โข Standard framework security measures
---
๐ 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:
- โข Keep the known way for historical data integrity
- โข Consider adding an "inactive" status (enhancement)
- โข Use different known way for new sales
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
- โข CLAUDE.md - PHP 8.2 migration guide
- โข sellbillController.md - Sales bill integration
- โข clientController.md - Customer management
- โข knownwaysreportController.md - Analytics and reporting
---
๐ฏ 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