Storetransferrequest Documentation

Store Transfer Request Controller Documentation

File: /controllers/storetransferrequestController.php

Purpose: Manages inter-store product transfers with delivery tracking, approvals, and inventory management

Last Updated: December 21, 2024

Total Functions: 29

Lines of Code: ~2816

---

๐Ÿ“‹ Overview

The Store Transfer Request Controller is a comprehensive inventory transfer management system that handles product movement between stores with sophisticated approval workflows, delivery tracking, and financial integration. This is one of the most complex controllers in the system, providing:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**storemovement**Transfer recordstransferproductid, storeidfrom, storeidto, productid, transferproductamount, operationnum, recieveType
**storedetail**Store inventorystoredetailid, productid, storeid, productquantity
**storereport**Audit trailstorereportid, productid, storeid, productquantity, tablename, processname
### Product Management

Table NamePurposeKey Columns
**product**Product masterproductId, productName, productCatId
**sizecolorstoredetail**Size/color variantssizeid, colorid, productid, storeid, quantity
**productserial**Serial trackingproductserailid, productid, serialnumber, expireDate
### System Tables

Table NamePurposeKey Columns
**store**Store masterstoreId, storeName
**user**System usersuserid, employeename, usergroupid
**programsettings**System configprogramsettingsid, workerbetweenstores
---

๐Ÿ”‘ Key Functions

Core Transfer Operations

1. Default Action - Transfer Interface

Location: Line 179

Purpose: Display the transfer request interface with store and driver selection

2. add() - Create Transfer Request

Location: Line 577

Purpose: Create transfer requests with inventory validation and operation numbering

Process Flow:

1. Validate inventory availability at source store

2. Create transfer records with unique operation number

3. Update source store inventory (decrease)

4. Update destination store inventory (increase) - if immediate mode

5. Create store reports for audit trail

6. Generate daily accounting entries

3. addDealWithStoreFromOnly() - Source Store Only Processing

Location: Line 823

Purpose: Handle transfers where only source store is processed immediately

4. addDealWithStoreToOnly() - Destination Store Processing

Location: Line 524

Purpose: Process destination store updates when transfers are received

Approval and Receiving

5. recieveproduct - Product Receiving

Location: Line 508

Purpose: Handle product receiving at destination stores with delivery confirmation

Process Flow:

1. Load transfer record

2. Validate receiving permissions

3. Update delivery information (driver, date)

4. Process destination store inventory updates

5. Create accounting entries for received goods

Display and Reporting

6. show - Transfer Display Interface

Location: Line 256

Purpose: Display transfer records with filtering options

7. showByoperationnum() - Operation-Based Display

Location: Multiple locations

Purpose: Display transfers grouped by operation number

8. showByDate() - Date-Based Display

Purpose: Display transfers within date ranges

Deletion and Rollback

9. returndelete() - Single Transfer Reversal

Purpose: Reverse individual transfer operations

10. returndelete2() - Batch Transfer Reversal

Purpose: Reverse entire operation batches

11. tempdelete() - Temporary Deletion

Purpose: Temporarily remove transfer records

Utility Functions

12. getStoredetailData() - Inventory Data Retrieval

Purpose: Get current inventory levels for products

13. insertStoredetail() - Inventory Record Creation

Purpose: Create new inventory records for products

14. insertStorereport() - Audit Trail Creation

Purpose: Create audit trail entries for all transfers

15. increaseProductQuantity() - Inventory Increase

Purpose: Increase product quantities at destination stores

16. decreaseProductQuantity() - Inventory Decrease

Purpose: Decrease product quantities at source stores

---

๐Ÿ”„ Workflows

Workflow 1: Complete Transfer Process

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Store Transfer Request
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Create Transfer Request
- Select source and destination stores
- Select products and quantities
- Choose receive type (immediate/approval required)
- Assign delivery driver if needed
- Generate unique operation number
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Validate and Process Request
- Check inventory availability at source store
- Validate size/color variants if applicable
- Create transfer records in database
- Update source store inventory (decrease)
- Create store report entries for audit
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Handle Transfer Type
IF immediate transfer (workerbetweenstores = 0):
โ†’ Process destination store immediately
โ†’ Update destination inventory (increase)
โ”‚ โ””โ”€โ†’ Create accounting entries โ”‚
ELSE (approval required):
โ†’ Mark for delivery/approval
โ†’ Assign to driver if specified
โ”‚ โ””โ”€โ†’ Wait for receiving confirmation โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Delivery and Receiving (if approval workflow)
- Driver delivers products to destination store
- Destination store staff receives products
- Update delivery timestamps and confirmation
- Process destination store inventory updates
- Create final accounting entries
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Complete Transfer
- All inventory quantities updated correctly
- Accounting entries created and balanced
- Audit trail complete in store reports
- Transfer marked as completed
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Workflow 2: Size/Color Product Handling

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Complex Product Transfer
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Parse Complex Product ID
IF productId contains "hasSizeColor":
โ†’ Extract base product ID
โ†’ Extract size ID from complex string
โ†’ Extract color ID from complex string
โ”‚ โ””โ”€โ†’ Format: "123hasSizeColor-5-7" โ”‚
Results: productId=123, sizeId=5, colorId=7
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Handle Inventory for Variants
- Update main product inventory (storedetail table)
- Update size/color inventory (sizecolorstoredetail)
- Ensure both records exist at source and destination
- Handle creation of missing variant records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Process Transfer with Variant Data
- Transfer includes size/color information
- Store reports include variant details
- Accounting entries account for specific variants
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionDisplay transfer interface
`do=add``add()`Create new transfer request
`do=show`Show interfaceDisplay transfer records
`do=showdetails`Detail viewShow detailed transfer information
`do=recieveproduct``recieveproduct`Receive products at destination
`do=returndelete``returndelete()`Reverse single transfer
`do=returndelete2``returndelete2()`Reverse operation batch
`do=tempdelete``tempdelete()`Temporarily delete transfer
`do=tempdelete2``tempdelete2()`Temporarily delete batch
`do=edit`Edit interfaceEdit transfer details
`do=editprint`Print editPrint editable transfer
`do=recieve`Receive interfaceDisplay receiving interface
### Required Parameters by Action

Create Transfer (do=add):

Receive Products (do=recieveproduct):

Show Transfers (do=show):

---

๐Ÿงฎ Calculation Methods

Inventory Quantity Updates

Source Store Decrease:

$currentQuantity = $storeDetail->productquantity;
$newQuantity = $currentQuantity - $transferAmount;
$storeDetail->productquantity = $newQuantity;

Destination Store Increase:

$currentQuantity = $storeDetail->productquantity;
$newQuantity = $currentQuantity + $transferAmount;
$storeDetail->productquantity = $newQuantity;

Size/Color Variant Updates:

// Update both main inventory and variant inventory
$sizeColorDetail = $sizeColorDAO->load($sizeColorStoreDetailId);
$newVariantQty = $sizeColorDetail->quantity - $transferAmount;
$sizeColorDetail->quantity = $newVariantQty;

Operation Number Generation

// Get next operation number
$nextId = $myStoremovementEx->queryAlloperationnum();
$last_val = $nextId[0];
$operationNum = $last_val->operationnum + 1;

---

๐Ÿ”’ Security & Permissions

Authentication

Store Access Control

$userData = $userDAO->load($_SESSION['userid']);
$userData->storeSupervisorStores = explode(',', $userData->storeSupervisorStores);

Transaction Safety

---

๐Ÿ“Š Performance Considerations

Critical Indexes Required

1. storemovement(operationnum, transferproductdate)

2. storedetail(productid, storeid)

3. sizecolorstoredetail(productid, storeid, sizeid, colorid)

4. storereport(tablename, recordid)

Optimization Tips

---

๐Ÿ› Common Issues & Troubleshooting

1. Inventory Sync Issues

Issue: Source and destination inventories don't balance

Cause: Transaction failures or partial updates

2. Operation Number Conflicts

Issue: Duplicate operation numbers generated

Cause: Concurrency in operation number generation

3. Size/Color Variant Problems

Issue: Complex product IDs not parsing correctly

Cause: Incorrect format or missing variant data

4. Approval Workflow Issues

Issue: Transfers stuck in pending state

Cause: Missing delivery confirmation or permission issues

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur