Storemovement Documentation

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:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**storemovement**Main transfer recordsstoremovementid, operationnum, storemovementfrom, storemovementto, storemovementproductid, storemovementquantity, storemovementdate
**otherstoremovement**Alternative movement trackingotherstoremovementid, operationnum, storeid, productid, quantity, operationtype
### Inventory Tables (Updated)

Table NamePurposeRelationship
**storedetail**Stock levels by storeUpdated for from/to stores
**sizecolorstoredetail**Variant-specific stockFor size/color transfers
**storereport**Stock movement auditComplete audit trail
**buypriceshistorybook**Cost trackingCost-based transfers
**productserial**Serial number trackingFor serialized transfers
### Reference Tables

Table NamePurposeRelationship
**store**Store/warehouse masterstoremovement.storemovementfrom/to
**product**Product master datastoremovement.storemovementproductid
**programsettings**System configurationCost calculation methods
**user**User managementTransfer authorization
**usergroup**Permission groupsAccess control
### Financial Tables

Table NamePurposeRelationship
**dailyentry**Accounting journalAuto-generated entries
**costcenter**Cost center trackingCost allocation
---

๐Ÿ”ง Key Functions

1. add()

Purpose: Create new stock transfer between stores

Called By: Form submission with ?do=add

Line: 1139

Parameters (via $_POST):

Business Logic Flow:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
User initiates
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Validate stores
and permissions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Check source
store inventory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Generate
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Create transfer
records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Update source
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Create pending
receipt records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Generate daily
entry record
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2. addAllStoreProducts()

Purpose: Bulk transfer of all products from one store to another

Line: 1432

Parameters:

Database Operations:

3. executeOperation()

Purpose: Finalize pending transfer operations

Called By: ?do=executeOperation

Line: 2958

Business Logic: Converts pending transfers to completed transfers by:

4. showAll()

Purpose: Display list of all transfer operations

Line: 1929

Returns: Formatted list with:

5. showByDate($startDate, $endDate, $storeId)

Purpose: Filter transfers by date range and store

Line: 1942

Parameters:

6. tempdelete($transferproductId)

Purpose: Temporarily delete/cancel a pending transfer item

Line: 2376

Parameters: $transferproductId - Transfer item to cancel

Database Operations:

7. returndelete($transferproductId)

Purpose: Reverse a completed transfer operation

Line: 2642

Parameters: $transferproductId - Transfer to reverse

Business Logic: Complex reversal process including:

8. getStoredetailData($storeid, $productid, $sizeColorStoreDetailId, $sizeId, $colorId)

Purpose: Retrieve current inventory levels for transfer validation

Line: 2996

Parameters:

9. increaseProductQuantity($storedetailId, $productquantityBefore, $productChangeAmount, $sizeColorStoreDetailId, $sizeId, $colorId, $movementRow)

Purpose: Increase inventory in destination store

Line: 3045

Database Operations:

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:

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:

---

๐Ÿ”„ Business Logic Flow

Complete Transfer Workflow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
(add operation)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Generate Op Num
& Validate
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Decrease Source
Store Inventory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Create Pending
Transfer Record
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
(Physical Move)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Receive at
Destination
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Execute
Operation
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Increase Dest
Store Inventory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Complete Daily
Entry Record
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Transfer Cancellation Workflow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Record Exists
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
User Requests
Cancellation
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Restore Source
Store Inventory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Delete Transfer
Records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Create Audit
Trail Entry
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Files Involved:

---

โš ๏ธ 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

Related Views

JavaScript Files

---

๐ŸŽฏ URL Routes & Actions

Action (`?do=`)MethodDescriptionView Template
(empty)GETDisplay transfer formstoremovement_add.html
addPOSTCreate transfer-
addAllStoreProductsPOSTBulk transfer all products-
showGETDisplay transfers liststoremovement_show.html
showdetailsGETShow transfer detailsstoremovement_details.html
editGET/POSTEdit transferstoremovement_edit.html
editshowGETShow edit formstoremovement_edit.html
executeOperationPOSTFinalize transfers-
tempdeletePOSTCancel pending transfer-
returndeletePOSTReverse completed transfer-
recievePOSTReceive transfer-
preparePOSTPrepare 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-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

Future Improvements

---

๐Ÿ“š Related Documentation