Store Movement Controller Documentation
File: /controllers/storemovementController.php
Purpose: Manages inventory transfers between warehouses, stock movements, and inter-store logistics
Last Updated: December 19, 2024
Total Functions: 34
Lines of Code: 3,697
---
๐ Overview
The Store Movement Controller handles all operations related to transferring inventory between different warehouses/stores. It manages:
- โข Inter-store inventory transfers
- โข Stock movement tracking and approval workflows
- โข Temporary transfer operations (pending confirmations)
- โข Bulk product transfers between stores
- โข Serial number transfers for tracked products
- โข Daily accounting entries for transfers
- โข Transfer operation reversals
- โข Cost center allocations for movements
- โข Barcode-based transfer operations
- โข Multi-user approval workflows
Primary Functions
- โ Create stock transfer orders
- โ Process inter-store transfers
- โ Manage temporary transfers (pending)
- โ Bulk transfer operations
- โ Track serial numbers in transfers
- โ Generate daily accounting entries
- โ Reverse/cancel transfers
- โ Handle transfer approvals
- โ Process transfer receipts
- โ Cost-based transfer pricing
- โ Barcode scanning integration
- โ Multi-store permissions
Related Controllers
- โข storeController.php - Store management
- โข storedetailController.php - Inventory details
- โข productController.php - Product management
- โข buyBillController.php - Purchase operations
- โข sellbillController.php - Sales operations
- โข returnBuyBillController.php - Purchase returns
- โข returnSellBillController.php - Sales returns
- โข dailyentryController.php - Accounting entries
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **storemovement** | Main transfer records | storemovementid, operationnum, storemovementfrom, storemovementto, storemovementproductid, storemovementquantity, storemovementdate | |
| **otherstoremovement** | Alternative movement tracking | otherstoremovementid, operationnum, storeid, productid, quantity, operationtype |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **storedetail** | Stock levels by store | Updated for from/to stores | |
| **sizecolorstoredetail** | Variant-specific stock | For size/color transfers | |
| **storereport** | Stock movement audit | Complete audit trail | |
| **buypriceshistorybook** | Cost tracking | Cost-based transfers | |
| **productserial** | Serial number tracking | For serialized transfers |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **store** | Store/warehouse master | storemovement.storemovementfrom/to | |
| **product** | Product master data | storemovement.storemovementproductid | |
| **programsettings** | System configuration | Cost calculation methods | |
| **user** | User management | Transfer authorization | |
| **usergroup** | Permission groups | Access control |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **dailyentry** | Accounting journal | Auto-generated entries | |
| **costcenter** | Cost center tracking | Cost allocation |
๐ง Key Functions
1. add()
Purpose: Create new stock transfer between stores
Called By: Form submission with ?do=add
Line: 1139
Parameters (via $_POST):
- โข
operation- Operation type (1=delete, 2=add) - โข
manyParcodesstoreidfrom- Source store ID - โข
manyParcodesstoreidto- Destination store ID - โข
manyParcodesbatchdata- Batch transfer data - โข
selectedProducts- Products to transfer - โข
quantities- Transfer quantities - โข
serialNumbers- Serial numbers (if applicable)
Business Logic Flow:
2. addAllStoreProducts()
Purpose: Bulk transfer of all products from one store to another
Line: 1432
Parameters:
- โข Source store ID
- โข Destination store ID
- โข Transfer all available inventory
Database Operations:
- โข SELECT all products from source store
- โข CREATE transfer records for each product
- โข UPDATE inventory levels
- โข INSERT audit trails
3. executeOperation()
Purpose: Finalize pending transfer operations
Called By: ?do=executeOperation
Line: 2958
Business Logic: Converts pending transfers to completed transfers by:
- โข Updating destination store inventory
- โข Finalizing transfer records
- โข Creating accounting entries
- โข Updating serial number ownership
4. showAll()
Purpose: Display list of all transfer operations
Line: 1929
Returns: Formatted list with:
- โข Transfer operation numbers
- โข Source and destination stores
- โข Transfer dates and statuses
- โข Product details
- โข Action buttons
5. showByDate($startDate, $endDate, $storeId)
Purpose: Filter transfers by date range and store
Line: 1942
Parameters:
- โข
$startDate- Start of date range - โข
$endDate- End of date range - โข
$storeId- Optional store filter
6. tempdelete($transferproductId)
Purpose: Temporarily delete/cancel a pending transfer item
Line: 2376
Parameters: $transferproductId - Transfer item to cancel
Database Operations:
- โข Restore source store inventory
- โข DELETE transfer record
- โข INSERT reversal audit record
7. returndelete($transferproductId)
Purpose: Reverse a completed transfer operation
Line: 2642
Parameters: $transferproductId - Transfer to reverse
Business Logic: Complex reversal process including:
- โข Restore source store inventory
- โข Remove destination store inventory
- โข Reverse accounting entries
- โข Update serial number ownership
8. getStoredetailData($storeid, $productid, $sizeColorStoreDetailId, $sizeId, $colorId)
Purpose: Retrieve current inventory levels for transfer validation
Line: 2996
Parameters:
- โข
$storeid- Store identifier - โข
$productid- Product identifier - โข
$sizeColorStoreDetailId- Variant ID - โข
$sizeId,$colorId- Variant dimensions
9. increaseProductQuantity($storedetailId, $productquantityBefore, $productChangeAmount, $sizeColorStoreDetailId, $sizeId, $colorId, $movementRow)
Purpose: Increase inventory in destination store
Line: 3045
Database Operations:
- โข UPDATE
storedetailSET quantity = quantity + amount - โข UPDATE
sizecolorstoredetailfor variants - โข INSERT
storereportaudit record
10. decreaseProductQuantity($storedetailId, $productquantityBefore, $productChangeAmount, $sizeColorStoreDetailId, $sizeId, $colorId, $movementRow)
Purpose: Decrease inventory in source store
Line: 3109
Business Logic: Validates sufficient inventory before decreasing
11. makeStoreMovementDailyEntry($mainData, $detailArr, $type)
Purpose: Create accounting entries for transfers
Line: 3556
Parameters:
- โข
$mainData- Main transfer information - โข
$detailArr- Detail records - โข
$type- Entry type (0=full cycle, 1=from only, 2=to only)
Accounting Logic: Creates proper debit/credit entries based on cost center configuration
12. decreaseFromHandleBuyPricesHistoryBook($storemovement, $soldQuantity)
Purpose: Handle cost tracking when transferring inventory
Line: 3231
Business Logic: Updates purchase price history for accurate costing
13. increaseHandleBuyPricesHistoryBook($storemovement)
Purpose: Handle cost tracking when receiving transferred inventory
Line: 3296
14. decreaseProductParcodeSerialQuantity($moveRow, $storeId)
Purpose: Handle serial number transfers for barcoded products
Line: 3418
Business Logic: Complex serial number management including:
- โข Find available serial numbers
- โข Update serial quantities
- โข Track serial ownership transfers
- โข Handle barcode product variants
---
๐ Business Logic Flow
Complete Transfer Workflow
Transfer Cancellation Workflow
Files Involved:
- โข View:
/views/default/storemovement/storemovement_add.html - โข Model:
/models/dto/Storemovement.class.php - โข DAO:
/models/mysql/StoremovementMySqlDAO.class.php - โข Daily Entry:
/controllers/dailyentryfun.php
---
โ ๏ธ Common Issues
Issue 1: Insufficient Inventory
Problem: Attempting to transfer more inventory than available
Cause: Concurrent operations or data inconsistency
Fix: Real-time inventory validation before transfer
Files: Various quantity check functions
Issue 2: Serial Number Tracking
Problem: Serial numbers getting lost or duplicated in transfers
Cause: Complex barcode and serial number relationships
Fix: Comprehensive tracking in decreaseProductParcodeSerialQuantity()
Line: 3418
Issue 3: Daily Entry Generation
Problem: Incorrect accounting entries for transfers
Cause: Complex cost center and account mapping
Fix: Proper configuration in makeStoreMovementDailyEntry()
Line: 3556
Issue 4: Permission Violations
Problem: Users transferring between unauthorized stores
Cause: Insufficient permission checking
Fix: Store-level permission validation throughout
---
๐ Dependencies
Includes
include_once("../models/sql/Transaction.class.php");
include("../public/impOpreation.php");
include_once("../public/config.php");
include("../public/include_dao.php");
include_once("dailyentryfun.php");
Required DAOs
- โข
StoremovementDAO- Transfer operations - โข
StorereportDAO- Audit trail - โข
StoredetailDAO- Inventory management - โข
StoreDAO- Store information - โข
ProductDAO- Product data - โข
OtherstoremovementDAO- Alternative tracking - โข
SizecolorstoredetailDAO- Variant tracking - โข
BuypriceshistorybookDAO- Cost tracking - โข
ProductserialDAO- Serial numbers - โข
UsergroupDAO- Permissions
Related Views
- โข
/views/default/storemovement/storemovement_add.html- Transfer form - โข
/views/default/storemovement/storemovement_show.html- Transfer list - โข
/views/default/storemovement/storemovement_edit.html- Edit transfers
JavaScript Files
- โข
/views/default/assets/js/storemovement.js- Transfer functionality - โข
/views/default/assets/js/barcode.js- Barcode scanning
---
๐ฏ URL Routes & Actions
| Action (`?do=`) | Method | Description | View Template | |
|---|---|---|---|---|
| (empty) | GET | Display transfer form | storemovement_add.html | |
| add | POST | Create transfer | - | |
| addAllStoreProducts | POST | Bulk transfer all products | - | |
| show | GET | Display transfers list | storemovement_show.html | |
| showdetails | GET | Show transfer details | storemovement_details.html | |
| edit | GET/POST | Edit transfer | storemovement_edit.html | |
| editshow | GET | Show edit form | storemovement_edit.html | |
| executeOperation | POST | Finalize transfers | - | |
| tempdelete | POST | Cancel pending transfer | - | |
| returndelete | POST | Reverse completed transfer | - | |
| recieve | POST | Receive transfer | - | |
| prepare | POST | Prepare transfer | - |
๐ Transfer Operation Types
Operation Categories
1. Standard Transfers (operation=2)
- Normal store-to-store transfers
- Full workflow with approval
2. Deletion/Reversal (operation=1)
- Cancel pending transfers
- Reverse completed transfers
3. Bulk Operations
- Transfer all products from store
- Category-based transfers
4. Serial Number Transfers
- Tracked product movements
- Barcode-based operations
---
๐ Permissions & Security
Required Permissions
- โข Store movement creation rights
- โข Source store access
- โข Destination store access
- โข Product management permissions
Store-Level Security
// Check user's assigned stores
if ($_SESSION['storeids'] == 0) {
// User can access all stores
} else {
// Restrict to assigned stores
$condition = 'store.storeId in (' . $_SESSION['storeids'] . ')';
}
Operation Authorization
// Store supervisor permissions
$userData->storeSupervisorStores = explode(',', $userData->storeSupervisorStores);
---
๐ Notes
Important Considerations
- โข All transfers must maintain accurate inventory levels
- โข Serial numbers require careful tracking across stores
- โข Daily entries must be properly generated for accounting
- โข Cost center allocations affect financial reporting
- โข Pending transfers can be cancelled; completed transfers require reversal
- โข Bulk operations can significantly impact performance
Future Improvements
- โป๏ธ Add transfer approval workflows
- โป๏ธ Implement transfer scheduling
- โป๏ธ Add GPS tracking for physical movements
- โป๏ธ Implement transfer cost optimization
- โป๏ธ Add mobile app for warehouse operations
- โป๏ธ Implement automated transfer suggestions
- โป๏ธ Add transfer performance analytics
---
๐ Related Documentation
- โข Store Management
- โข Inventory Details
- โข Daily Entries
- โข Warehouse Operations
- โข Cost Center Accounting