Movementmanage Documentation
Movement Management Controller Documentation
File: /controllers/movementmanageController.php
Purpose: Tracks and reports user activities and system operations across the ERP system
Last Updated: December 20, 2024
Total Functions: 10
Lines of Code: ~282
---
๐ Overview
The Movement Management Controller provides comprehensive audit trail and user activity tracking functionality. It manages:
- โข User activity logging and monitoring
- โข System operation tracking across all modules
- โข Detailed audit reports with filtering capabilities
- โข User behavior analysis and reporting
- โข Movement data archival and cleanup
- โข Security monitoring and access tracking
- โข Performance analytics for system usage
Primary Functions
- โ Display user movement reports with filtering
- โ Track operations by date range
- โ Filter activities by specific users
- โ Monitor specific operation types
- โ Combine multiple filter criteria
- โ Archive old movement data
- โ Maintain deleted movement records
- โ User activity analytics
Related Controllers
- โข userController.php - User management
- โข usergroupController.php - User group permissions
- โข All system controllers contribute movement data
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **movementmanage** | Active user movements | movementmanageid, operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType | |
| **movementmanagedeleted** | Archived movements | movementmanagedeleted, operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **user** | System users | userid, employeename, viewclients, viewbills, usergroupid | |
| **usergroup** | User permission groups | usergroupid, usergroupname | |
| **youtubelink** | Tutorial references | youtubelinkid, title, url |
๐ Key Functions
1. Default Action (show) - Movement Report Display
Location: Lines 88-150
Purpose: Main interface for viewing user movement reports with advanced filtering
Function Signature:
if (empty($do) || $do == "show")
Input Parameters:
- โข
from/to- Date range filters - โข
usersearchid- Specific user filter - โข
operationname- Operation type filter - โข
nameopration- Operation display name
Process Flow:
1. Load user data for dropdown filters
2. Load YouTube tutorials for help system
3. Parse filter parameters from request
4. Execute appropriate filtering function based on criteria
5. Generate descriptive message for report header
6. Display results via movement template
Complex Filter Logic:
// Filter combinations with priority
if (date range AND no user AND no operation) {
showByDate($startDate, $endDate);
} elseif (user only AND no date AND no operation) {
showByUser($userSearchId);
} elseif (operation only AND no date AND no user) {
showByOperationName($operationName);
} elseif (date range AND user AND no operation) {
showByDateAndUser($startDate, $endDate, $userSearchId);
} elseif (date range AND operation AND no user) {
showByDateAndOperationName($startDate, $endDate, $operationName);
} elseif (user AND operation AND no date) {
showByUserAndOperationName($userSearchId, $operationName);
}
---
2. loadUser() - User Data Loading
Location: Lines 172-178
Purpose: Load active users for filter dropdown
Function Signature:
function loadUser()
Process Flow:
1. Query users with conditions = 0 (active only)
2. Return user array for template assignment
---
3. showByDate() - Date Range Filtering
Location: Lines 189-199
Purpose: Display movements within specific date range
Function Signature:
function showByDate($startDate, $endDate)
Process Flow:
1. Query active movements within date range
2. Query deleted movements within same range
3. Assign both datasets to template
4. Generate combined report
Data Sources:
- โข
movementmanageData- Active movement records - โข
movementmanageDataDel- Archived movement records
---
4. showByUser() - User-Specific Reports
Location: Lines 201-211
Purpose: Display all movements for a specific user
Function Signature:
function showByUser($userSearchId)
Process Flow:
1. Query movements filtered by user ID
2. Include both active and deleted records
3. Provide complete user activity history
---
5. showByOperationName() - Operation Type Reports
Location: Lines 213-223
Purpose: Display movements for specific operation types
Function Signature:
function showByOperationName($operationName)
Process Flow:
1. Filter movements by operation name
2. Show system-wide usage of specific features
3. Include archived data for complete picture
Operation Examples:
- โข
sellbillController.php- Sales operations - โข
buyBillController.php- Purchase operations - โข
clientController.php- Customer management - โข
productController.php- Product management
---
6. showByDateAndUser() - Combined Date/User Filter
Location: Lines 225-235
Purpose: User activity within specific date range
Function Signature:
function showByDateAndUser($startDate, $endDate, $userSearchId)
Business Use Cases:
- โข Employee productivity tracking
- โข Security auditing for specific users
- โข Time-based activity analysis
---
7. showByDateAndOperationName() - Combined Date/Operation Filter
Location: Lines 237-247
Purpose: System feature usage within date range
Function Signature:
function showByDateAndOperationName($startDate, $endDate, $operationName)
Business Use Cases:
- โข Feature adoption tracking
- โข System performance analysis
- โข Module usage statistics
---
8. showByUserAndOperationName() - Combined User/Operation Filter
Location: Lines 249-259
Purpose: Specific user's usage of specific operations
Function Signature:
function showByUserAndOperationName($userSearchId, $operationName)
Business Use Cases:
- โข Individual training needs assessment
- โข Role-based usage analysis
- โข Security monitoring for sensitive operations
---
9. delete() - Movement Data Archival
Location: Lines 152-160 and 261-280
Purpose: Archive old movement data and clean up active table
Function Signature:
function delete($startDate, $endDate)
Process Flow:
1. Query movements to be archived within date range
2. Copy each record to movementmanagedeleted table
3. Preserve all original data fields
4. Delete records from active movementmanage table
5. Redirect to success page
Archival Logic:
$dataThatWillBeDeleted = $myMovementmanageEx->queryAllWithOpnameAndDateSimple($startDate, $endDate);
foreach ($dataThatWillBeDeleted as $value) {
$movementManageDeleted->operationname = $value->operationname;
$movementManageDeleted->movementmanagedate = $value->movementmanagedate;
$movementManageDeleted->userid = $value->userid;
$movementManageDeleted->currentDo = $value->currentDo;
$movementManageDeleted->ip = $value->ip;
$movementManageDeleted->mac = $value->mac;
$movementManageDeleted->deviceType = $value->deviceType;
$movementManageDeletedDAO->insert($movementManageDeleted);
}
$myMovementmanageEx->deleteByMovementmanagedateEX($startDate, $endDate);
Data Preservation: Complete movement history maintained in archive table
---
๐ Workflows
Workflow 1: User Activity Analysis
---
Workflow 2: Movement Data Lifecycle
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | show() | Display movement reports interface | |
| `do=show` | show() | Same as empty - main reporting | |
| `do=delete` | delete() | Archive movement data by date range | |
| `do=sucess` | Success page | Show operation success message | |
| `do=error` | Error page | Show operation error message |
| Parameter | Type | Description | |
|---|---|---|---|
| `from` | Date | Start date for filtering (YYYY-MM-DD) | |
| `to` | Date | End date for filtering (YYYY-MM-DD) | |
| `usersearchid` | Integer | User ID filter | |
| `operationname` | String | Operation type filter | |
| `nameopration` | String | Operation display name (POST) |
| Parameter | Type | Description | |
|---|---|---|---|
| `from2` | Date | Start date for archival | |
| `to2` | Date | End date for archival |
๐งฎ Calculation Methods
Report Message Generation
// Dynamic message building based on filters
$message = "ุชูุฑูุฑ ุญุฑูุฉ ุงูู
ุณุชุฎุฏู
ูู";
if (isset($startDate) && $startDate != "") {
$message .= " ู
ู ุชุงุฑูุฎ:" . $startDate . "ุงูู ุชุงุฑูุฎ :" . $endDate;
}
if (isset($userSearchId) && $userSearchId != "-1") {
$myuserdata = $myUserRecord->load($userSearchId);
$message .= " ููู
ูุธู :" . $myuserdata->employeename;
}
if (isset($operationName) && $operationName != "-1") {
$message .= " ูู ุนู
ููู :" . $nameopration;
}
User Permission Integration
$userGroup = $myUserGroupRecord->load($_SESSION['usergroupid']);
$smarty->assign("userGroup", $userGroup);
$smarty->assign("sessionuserid", $_SESSION['userid']);
---
๐ Security & Permissions
User Group Authorization
// Load user group permissions for access control
$userGroup = $myUserGroupRecord->load($_SESSION['usergroupid']);
Session-Based Access
- โข All operations require valid user session
- โข User ID tracked for audit purposes
- โข Permission level checking via user groups
Sensitive Data Protection
- โข IP and MAC address tracking for security
- โข Device type identification
- โข Complete audit trail for compliance
---
๐ Performance Considerations
Database Optimization
1. Critical Indexes Needed:
- movementmanage(movementmanagedate, userid)
- movementmanage(operationname, movementmanagedate)
- movementmanagedeleted(movementmanagedate, userid)
- movementmanagedeleted(operationname, movementmanagedate)
2. Query Performance:
- Date range queries should use indexed columns
- Extended DAO methods provide optimized queries
- Archive cleanup improves active table performance
Memory Management
- โข Large date ranges may return significant data
- โข Consider pagination for very large result sets
- โข Archive process handles bulk operations efficiently
Archival Strategy
// Efficient bulk archival process
foreach ($dataThatWillBeDeleted as $value) {
// Copy to archive table
$movementManageDeletedDAO->insert($movementManageDeleted);
}
// Bulk delete from active table
$myMovementmanageEx->deleteByMovementmanagedateEX($startDate, $endDate);
---
๐ Common Issues & Troubleshooting
1. Large Dataset Performance
Issue: Reports slow with large movement datasets
Cause: Missing database indexes on filter columns
Fix: Add compound indexes:
CREATE INDEX idx_movement_date_user ON movementmanage(movementmanagedate, userid);
CREATE INDEX idx_movement_operation_date ON movementmanage(operationname, movementmanagedate);
2. Archival Process Failures
Issue: Archive operation fails partway through
Cause: Transaction not properly handled
Fix: Wrap in transaction:
try {
R::begin();
// Archive operations
R::commit();
} catch (Exception $e) {
R::rollback();
throw $e;
}
3. Memory Issues with Large Archives
Issue: Out of memory during large archival operations
Cause: Loading entire dataset into memory
Fix: Process in batches:
$batchSize = 1000;
$offset = 0;
do {
$batch = $myMovementmanageEx->queryBatch($startDate, $endDate, $offset, $batchSize);
// Process batch
$offset += $batchSize;
} while (count($batch) > 0);
4. Filter Combination Logic
Issue: Complex filter combinations not working correctly
Cause: Incorrect boolean logic in filter processing
Fix: Simplify filter logic with clear precedence:
$hasDate = !empty($startDate) && !empty($endDate);
$hasUser = !empty($userSearchId) && $userSearchId != "-1";
$hasOperation = !empty($operationName) && $operationName != "-1";
if ($hasDate && $hasUser && $hasOperation) {
// All three filters
} elseif ($hasDate && $hasUser) {
// Date and user
} // Continue with clear logic
---
๐งช Testing Scenarios
Test Case 1: Basic Movement Reporting
1. Access movement reports with no filters
2. Apply date range filter and verify results
3. Filter by specific user and check data
4. Test operation type filtering
Test Case 2: Complex Filter Combinations
1. Combine date range with user filter
2. Test date range with operation filter
3. Apply user and operation filters together
4. Verify all combinations work correctly
Test Case 3: Data Archival Process
1. Create test movement data
2. Run archival process for specific date range
3. Verify data moved to archive table
4. Confirm data removed from active table
5. Test archived data still searchable
Test Case 4: Performance Testing
1. Generate large movement dataset
2. Test report performance with various filters
3. Measure archival process speed
4. Verify memory usage within limits
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข User Management Documentation - User and group setup
- โข System Audit Guide - Compliance and security
- โข Database Maintenance Guide - Performance optimization
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When archival strategy needs optimization