Alternative Store Movement Controller Documentation
File: /controllers/otherstoremovementController.php
Purpose: Manages alternative inventory movements including transfers, adjustments, and special stock operations with comprehensive audit trails
Last Updated: December 20, 2024
Total Functions: 15+
Lines of Code: ~27,869 (Large and complex controller)
---
๐ Overview
The Alternative Store Movement Controller handles specialized inventory operations that don't fit into the standard sales/purchase workflows. This includes:
- โข Store-to-Store Transfers: Moving inventory between warehouses
- โข Inventory Adjustments: Stock increases/decreases for corrections
- โข Product Returns: Processing returned merchandise
- โข Stock Corrections: Fixing quantity discrepancies
- โข Serial Number Tracking: Managing serialized products
- โข Size/Color Variants: Handling product variations
- โข Daily Entry Integration: Full accounting integration
- โข Comprehensive Auditing: Detailed movement tracking
Primary Functions
- โ Process inventory transfers between stores
- โ Handle inventory adjustments (increases/decreases)
- โ Manage product returns and exchanges
- โ Track serial numbers for products
- โ Handle size/color product variations
- โ Generate accounting entries for movements
- โ Support bulk operations on multiple items
- โ Provide detailed movement audit trails
- โ Integrate with user permission systems
Related Controllers
- โข storemovementController.php - Standard store movements
- โข storeController.php - Store management
- โข storedetailController.php - Inventory tracking
- โข sellbillController.php - Sales operations
- โข buyBillController.php - Purchase operations
---
๐๏ธ Database Tables
Primary Movement Tables
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **otherstoremovement** | Alternative movement records | otherstoremovementid, productid, quantity, movementtype, fromstoreid, tostoreid, userid, movementdate | |
| **storemovement** | Standard movement tracking | storemovementid, productid, fromstoreid, tostoreid, quantity, movementdate, conditions | |
| **storereport** | Movement audit reports | storereportid, productid, storeid, quantity, reportdate, reporttype |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **storedetail** | Product inventory by store | storedetailid, storeid, productid, productquantity, productBuyPrice, productSellPrice | |
| **store** | Store/warehouse master | storeId, storeName, storeLocation, conditions | |
| **product** | Product master data | productid, productname, productcode, productcategory |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **sizecolorstoredetail** | Size/color variant tracking | sizecolorstoredetailid, storedetailid, size, color, quantity | |
| **productserial** | Serial number tracking | productserialid, productid, serialnumber, sold, storeid |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **buypriceshistorybook** | Purchase price history | buypriceshistorybookid, productid, buyprice, quantity, buydate | |
| **dailyentry** | Accounting entries | dailyentryid, entryComment, entryDate | |
| **usergroup** | User permission groups | usergroupid, usergroupname, permissions | |
| **programsettings** | System configuration | programsettingsid, settingkey, settingvalue |
๐ Key Functions
1. Default Action - Movement Form Display
Location: Line 189
Purpose: Display the movement creation form with store and product selections
Process Flow:
1. Check user permissions and authentication
2. Load store negative balance settings
3. Configure search parameters (single store vs multi-store)
4. Load product data based on user store access
5. Prepare form with necessary dropdown data
6. Display movement form template
Key Features:
- โข Store permission filtering based on user access
- โข Product search optimization settings
- โข Negative inventory control settings
- โข User group permission integration
---
2. add - Create New Movement
Location: Line [Multiple locations for different movement types]
Purpose: Process new inventory movement transactions
Movement Types Supported:
- โข Type 0: Store-to-store transfer
- โข Type 1: Inventory adjustment (increase)
- โข Type 2: Inventory adjustment (decrease)
- โข Type 3: Product return processing
- โข Type 4: Special movement operations
Process Flow:
1. Input Validation: Validate movement parameters and permissions
2. Inventory Checking: Verify source store has sufficient quantity
3. Transaction Processing:
- Update source store inventory (decrease)
- Update destination store inventory (increase)
- Handle size/color variants if applicable
- Process serial numbers for tracked products
4. Price History Updates: Update purchase price history
5. Movement Logging: Create detailed audit records
6. Accounting Integration: Generate daily entries
7. Report Generation: Update movement reports
---
3. show - Display Movement History
Location: Line [Various show functions]
Purpose: Display movement history with filtering and search capabilities
Filter Options:
- โข Date Range: From/to date filtering
- โข Store: Source and destination store filtering
- โข Product: Specific product filtering
- โข Movement Type: Filter by operation type
- โข User: Filter by who performed the movement
Display Features:
- โข Paginated results for large datasets
- โข Sortable columns
- โข Detailed movement information
- โข Links to related transactions
- โข Export capabilities
---
4. edit - Modify Existing Movement
Location: Line [Edit functions]
Purpose: Allow modification of movement records (with restrictions)
Editable Fields:
- โข Movement notes/comments
- โข Non-financial metadata
- โข User assignments
Restrictions:
- โข Financial amounts cannot be changed after commitment
- โข Movements with accounting entries have limited editing
- โข User permission checks for modification rights
---
5. delete / tempdelete - Remove Movements
Location: Line [Delete functions]
Purpose: Reverse inventory movements with complete audit trail
Deletion Types:
- โข Soft Delete: Mark as deleted but preserve data
- โข Hard Delete: Remove from system (restricted)
- โข Reverse Movement: Create offsetting movement
Process Flow:
1. Validation: Check movement can be deleted
2. Inventory Reversal: Reverse all quantity changes
3. Accounting Reversal: Reverse daily entries
4. Audit Trail: Maintain deletion audit record
5. Status Update: Update movement status
---
6. Serial Number Management Functions
Location: Various locations throughout controller
Purpose: Handle serialized product tracking
Functions Include:
- โข assignSerial(): Assign serial numbers to products
- โข updateSerial(): Update serial status
- โข trackSerial(): Track serial movements
- โข validateSerial(): Ensure serial uniqueness
---
7. Size/Color Variant Functions
Location: Multiple locations
Purpose: Manage product variations with size and color attributes
Functions Include:
- โข updateSizeColor(): Update variant quantities
- โข transferVariants(): Move variants between stores
- โข validateVariants(): Ensure variant data integrity
---
8. Price History Functions
Location: Price history management sections
Purpose: Maintain accurate purchase price tracking
Functions Include:
- โข updateBuyPricesHistory(): Record price changes
- โข calculateAveragePrice(): Calculate weighted averages
- โข adjustPriceHistory(): Handle price adjustments
---
๐ Workflows
Workflow 1: Store-to-Store Transfer
Workflow 2: Inventory Adjustment Process
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default | Display movement form | |
| `do=add` | `add()` | Create new movement | |
| `do=show` | `show()` | Display movement history | |
| `do=edit` | `edit()` | Load movement for editing | |
| `do=update` | `update()` | Update movement record | |
| `do=delete` | `delete()` | Remove movement | |
| `do=tempdelete` | `tempdelete()` | Soft delete movement | |
| `do=executeOperation` | Batch operations | Process multiple movements |
Add Movement (do=add):
- โข
productid- Product to move - โข
quantity- Amount to move - โข
fromstoreid- Source store - โข
tostoreid- Destination store - โข
movementtype- Type of movement - โข
comment- Reason for movement
Show Movements (do=show):
- โข
from- Start date filter (optional) - โข
to- End date filter (optional) - โข
storeid- Store filter (optional) - โข
productid- Product filter (optional)
---
๐ง Technical Features
Concurrency Control
- โข User-based locking mechanisms
- โข Transaction isolation for critical updates
- โข Rollback capability for failed operations
- โข Optimistic locking for inventory quantities
Data Validation
- โข Negative inventory prevention (configurable)
- โข Quantity range validation
- โข Store permission verification
- โข Product existence validation
- โข Serial number uniqueness checks
Audit Trail Features
- โข Complete movement history tracking
- โข User action logging
- โข Before/after quantity snapshots
- โข Timestamp precision to seconds
- โข Linking to source transactions
Performance Optimizations
- โข Indexed queries for common filters
- โข Batch processing for bulk operations
- โข Cached store and product data
- โข Optimized recursive calculations
- โข Background processing for large operations
---
๐ Security & Permissions
User Access Control
// Store-based permission checking
if ($_SESSION['storeids'] == 0) {
// User has access to all stores
} else {
// Restrict to user's assigned stores only
$allowedStores = explode(',', $_SESSION['storeids']);
}
Operation Permissions
- โข Movement Creation: Requires specific user group permissions
- โข Movement Deletion: Higher permission level required
- โข Cross-Store Transfers: Must have access to both stores
- โข Bulk Operations: Administrative permission required
Data Protection
- โข Transaction-level data integrity
- โข Audit trail preservation
- โข Secure parameter validation
- โข SQL injection prevention
- โข Session-based authentication
---
๐ Performance Considerations
Query Optimization
1. Store Filtering: Index on (storeid, movementdate)
2. Product Filtering: Index on (productid, movementdate)
3. User Filtering: Index on (userid, movementdate)
4. Date Range Queries: Proper date indexing
Memory Management
- โข Large result set pagination
- โข Efficient array processing
- โข Memory cleanup for bulk operations
- โข Optimized recursive functions
Scalability Factors
- โข Performance degrades with large movement history
- โข Complex size/color variants increase processing time
- โข Serial number tracking adds overhead
- โข Accounting integration creates additional load
Recommended Optimizations
-- Key indexes for performance
CREATE INDEX idx_otherstoremovement_store_date ON otherstoremovement(fromstoreid, movementdate);
CREATE INDEX idx_otherstoremovement_product_date ON otherstoremovement(productid, movementdate);
CREATE INDEX idx_storedetail_store_product ON storedetail(storeid, productid);
CREATE INDEX idx_productserial_product ON productserial(productid, sold);
---
๐ Common Issues & Troubleshooting
1. Negative Inventory Errors
Issue: System prevents movements that would create negative inventory
Cause: Insufficient quantity in source store
Solutions:
- โข Check actual inventory levels
- โข Verify concurrent movements haven't reduced stock
- โข Review negative inventory settings
- โข Consider partial transfers
2. Serial Number Conflicts
Issue: Serial numbers show as duplicated or missing
Cause: Improper serial tracking during movements
Debug Steps:
-- Check for duplicate serials
SELECT serialnumber, COUNT(*)
FROM productserial
GROUP BY serialnumber
HAVING COUNT(*) > 1;
-- Verify serial ownership
SELECT ps.*, sd.storeid
FROM productserial ps
JOIN storedetail sd ON ps.productid = sd.productid
WHERE ps.serialnumber = '[SERIAL]';
3. Price History Inconsistencies
Issue: Average costs appear incorrect after movements
Cause: Price history not properly updated during transfers
Verification:
-- Check price history for product
SELECT * FROM buypriceshistorybook
WHERE productid = [ID]
ORDER BY buydate DESC;
-- Recalculate weighted average
SELECT
productid,
SUM(quantity * buyprice) / SUM(quantity) as weighted_avg
FROM buypriceshistorybook
WHERE productid = [ID]
GROUP BY productid;
4. Performance Issues with Large Datasets
Issue: Movement history queries take too long
Cause: Large movement history without proper indexing
Solutions:
- โข Add proper indexes (see Performance section)
- โข Implement date range restrictions
- โข Use pagination for large results
- โข Archive old movement data
---
๐งช Testing Scenarios
Test Case 1: Basic Store Transfer
1. Create product in Store A with quantity 100
2. Transfer 50 units to Store B
3. Verify Store A quantity = 50
4. Verify Store B quantity = 50
5. Check movement audit record created
6. Confirm price history updated
Test Case 2: Serial Number Tracking
1. Add serialized product with 5 units
2. Assign unique serial numbers to each unit
3. Transfer 2 units with serials to different store
4. Verify serials moved to correct store
5. Check remaining serials stay in original store
Test Case 3: Size/Color Variants
1. Create product with size/color variants
2. Set different quantities per variant
3. Transfer specific variants to new store
4. Verify only selected variants moved
5. Check variant quantities accurate in both stores
Test Case 4: Inventory Adjustment
1. Set initial product quantity to 100
2. Perform physical count showing 95
3. Create decrease adjustment for 5 units
4. Verify system quantity matches physical count
5. Check adjustment entry in accounting
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข Store Management Documentation - Store setup and configuration
- โข Inventory Tracking Guide - Product and quantity management
- โข Serial Number System - Serialized product handling
- โข Accounting Integration - Daily entry system
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur
Note: This controller is exceptionally large and complex. This documentation covers the major functions and workflows, but additional detailed analysis may be needed for specific advanced features.