CashTransfer Documentation
Cash Transfer Controller Documentation
File: /controllers/cashTransferController.php
Purpose: Manage cash transfers between bank accounts and cash registers with full transaction tracking
Last Updated: December 20, 2024
Total Functions: 8+
Lines of Code: ~664
---
๐ Overview
The Cash Transfer Controller manages cash movements between bank accounts and cash registers, providing complete transaction tracking and accounting integration. It handles:
- โข Bank-to-cash register transfers (withdrawals)
- โข Cash register-to-bank transfers (deposits)
- โข Account balance updates with transaction history
- โข Daily entry accounting integration
- โข Transaction reversal and cancellation
- โข Batch operation processing
- โข Print-friendly transfer receipts
- โข Multi-user permission support
Primary Functions
- โ Process cash transfers between banks and registers
- โ Update bank account and cash register balances
- โ Create corresponding accounting entries
- โ Track transaction history with audit trail
- โ Support transaction reversal and cancellation
- โ Generate transfer reports and receipts
- โ Handle batch transfer operations
- โ Integrate with daily entry accounting system
Related Controllers
- โข saveController.php - Cash register management
- โข bankaccountController.php - Bank account operations
- โข dailyentry.php - Accounting integration
- โข savedailyController.php - Cash transaction history
---
๐๏ธ Database Tables
Primary Transaction Tables
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **cashtransfer** | Cash transfer records | cashtransferid, bankaccountid, saveid, cashtransferamount, type, conditions, dailyentryid | |
| **accountmovement** | Bank account movements | accountmovementid, accountid, accountmovementamount, accountmovementtype, processname | |
| **savedaily** | Cash register history | savedailyid, saveid, savedailychangeamount, savedailychangetype, processname |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **bankaccount** | Bank account master | accountid, bankid, accountnumber, accountbeginingbalance, treeId | |
| **save** | Cash registers | saveid, savename, savecurrentvalue, treeId | |
| **bank** | Bank information | bankid, bankname |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **dailyentry** | Journal entry headers | id, dDateTime, entryComment | |
| **dailyentrydebtor** | Debit entries | id, dailyentryid, accountstreeid, value | |
| **dailyentrycreditor** | Credit entries | id, dailyentryid, accountstreeid, value | |
| **accountstree** | Chart of accounts | id, customName, parent |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **youtubelink** | Tutorial videos | youtubelinkid, title, url |
๐ Key Functions
1. add() - Create Cash Transfer
Location: Line 254
Purpose: Process new cash transfer with complete transaction handling
Function Signature:
function add()
Process Flow:
1. Extract and validate form parameters
2. Determine transfer type and direction
3. Create cash transfer record
4. Update cash register balance
5. Update bank account balance
6. Create transaction history records
7. Generate accounting entries
8. Commit transaction with safety
Transfer Types:
if ($transfer == 1) { // Bank to Cash Register
$type = 1;
$processname = "ุชุญููู ููุฏู ู
ู ุงูุจูู ุฅูู ุงูุฎุฒูุฉ";
$savedailychangetype = 0; // Cash increase
$accountmovementtype = 1; // Bank decrease
} else if ($transfer == 2) { // Cash Register to Bank
$type = 2;
$processname = "ุชุญููู ููุฏู ู
ู ุงูุฎุฒูุฉ ุฅูู ุงูุจูู";
$savedailychangetype = 1; // Cash decrease
$accountmovementtype = 0; // Bank increase
}
Cash Register Balance Update:
$savesData = $saveExt->loadForUpdateEx($saveId);
$saveBefore = $savesData->savecurrentvalue;
if ($transfer == 1) { // Bank to Cash
$saveAfter = ($savesData->savecurrentvalue + $amount);
} else if ($transfer == 2) { // Cash to Bank
$saveAfter = ($savesData->savecurrentvalue - $amount);
}
$save->savecurrentvalue = $saveAfter;
$save->saveid = $saveId;
$saveExt->updateSaveValue($save);
Bank Account Balance Update:
$accoundatat = $accountDAO->load($accountid);
$accountBefore = $accoundatat->accountbeginingbalance;
if ($accountmovementtype == 1) { // Bank decrease
$account->accountbeginingbalance = $accountBefore - $amount;
$accountmovementafter = $accountBefore - $amount;
} elseif ($accountmovementtype == 0) { // Bank increase
$account->accountbeginingbalance = $accountBefore + $amount;
$accountmovementafter = $accountBefore + $amount;
}
$accountExt->updateacount($account);
---
2. Accounting Integration
Location: Line 385-414
Purpose: Create double-entry accounting records for cash transfers
Process Flow:
1. Determine debit and credit accounts based on transfer direction
2. Create daily entry header
3. Set up debtor and creditor arrays
4. Call accounting integration function
5. Update transfer record with daily entry ID
Account Determination Logic:
$baccountData = $accountDAO->load($accountid);
$accountTreeId = $baccountData->treeId;
$saveData = $savesDAO->load($saveId);
$saveTreeId = $saveData->treeId;
if ($transfer == 1) { // Bank to Cash: Debit=Cash, Credit=Bank
$dailyEntryDebtor->accountstreeid = $saveTreeId;
$dailyEntryCreditor->accountstreeid = $accountTreeId;
} else { // Cash to Bank: Debit=Bank, Credit=Cash
$dailyEntryDebtor->accountstreeid = $accountTreeId;
$dailyEntryCreditor->accountstreeid = $saveTreeId;
}
Daily Entry Creation:
$dailyEntry->dDateTime = date('Y-m-d H:i:s');
$dailyEntry->entryComment = $processname;
$dailyEntryDebtor->value = $amount;
$dailyEntryCreditor->value = $amount;
$returnedData = insertEntery($dailyEntry, $dailyEntryDebtorArray,
$dailyEntryCreditorArray, 1, $cashTransferId,
'cashTransferController.php?do=editprint&id=' . $cashTransferId);
---
3. show() - Transfer History Display
Location: Line 459
Purpose: Display transfer history with flexible filtering options
Function Signature:
function show()
Filtering Options:
1. Date Range Filter: Show transfers between specified dates
2. Cash Register Filter: Show transfers for specific register
3. Default View: Show today's transfers
Filter Logic:
if (isset($to) && $to != "" && isset($from) && $from != "") {
// Date range filter
$shownData = $cashTransferExt->queryCashTransferBydate($from, $to);
$message = "ุนุฑุถ ุงูุชุญูููุงุช ุงูููุฏูุฉ ู
ู ุชุงุฑูุฎ : " . $from . " ุงูู ุชุงุฑูุฎ " . $to;
} elseif (isset($saveid) && $saveid != "-1") {
// Cash register filter
$saveData = $savesDAO->load($saveid);
$shownData = $cashTransferExt->queryCashTransferBySaveId($saveid);
$message = "ุนุฑุถ ุงูุชุญูููุงุช ุงูููุฏูุฉ ู
ู ูุฅูู ุงูุฎุฒูุฉ : " . $saveData->savename;
} else {
// Default: today's transfers
$shownData = $cashTransferExt->queryCashTransferBydate(date("Y-m-d"), date("Y-m-d"));
$message = "ุนุฑุถ ุงูุชุญูููุงุช ุงูููุฏูุฉ ู
ู ุชุงุฑูุฎ : " . date("Y-m-d") . " ุงูู ุชุงุฑูุฎ : " . date("Y-m-d");
}
---
4. delete() - Transfer Reversal
Location: Line 493
Purpose: Reverse cash transfer with complete transaction rollback
Function Signature:
function delete($id)
Process Flow:
1. Load original transfer data
2. Reverse cash register balance changes
3. Reverse bank account balance changes
4. Create reversal transaction history
5. Mark transfer as cancelled
6. Reverse accounting entries
7. Commit all changes
Cash Register Reversal:
if ($type == 1) { // Original was bank to cash, so reverse: decrease cash
$saveAfter = ($savedata->savecurrentvalue - $amount);
$savedailychangetype = 1;
$processname = "ุฅูุบุงุก ุชุญููู ููุฏู ู
ู ุงูุจูู ุฅูู ุงูุฎุฒูุฉ";
} else if ($type == 2) { // Original was cash to bank, so reverse: increase cash
$saveAfter = ($savedata->savecurrentvalue + $amount);
$savedailychangetype = 0;
$processname = "ุฅูุบุงุก ุชุญููู ููุฏู ู
ู ุงูุฎุฒูุฉ ุฅูู ุงูุจูู";
}
Bank Account Reversal:
if ($type == 1) { // Reverse bank decrease
$accountAfter = $accountBefore + $cashtransferamount;
$accountmovementtype = 0;
} else if ($type == 2) { // Reverse bank increase
$accountAfter = $accountBefore - $cashtransferamount;
$accountmovementtype = 1;
}
---
5. execute() - Batch Operations
Location: Line 612
Purpose: Process batch transfer operations with error handling
Function Signature:
function execute()
Process Flow:
1. Parse operation type and selected transfers
2. Iterate through selected transfer IDs
3. Validate operation permissions
4. Execute operation (currently only deletion supported)
5. Track success/failure for each operation
6. Display consolidated results
Batch Processing Logic:
foreach ($choosedItemArr as $checkId) {
$checkdata = $cashTransferDAO->load($checkId);
$conditions = $checkdata->conditions;
if ($operationType == '1' && $conditions == 0) { // Delete if not cancelled
try {
$note = delete($checkId);
if ($note != "sucess") {
$outputString .= $cashtransfernumber . ": " . $note . "<br/>";
} else {
$outputString .= $cashtransfernumber . ": ุชู
ุช ุงูุนู
ููุฉ ุจูุฌุงุญ <br/>";
}
} catch (Exception $e) {
// Error handling
}
} else {
$outputString .= $cashtransfernumber . ": ูุง ูู
ูู ุงูุบุงุก ูุฐุง ุงูุดูู ูุงูู ู
ูุบู ุณุงุจูุง<br/>";
}
}
---
6. edit() - Transfer Receipt Display
Location: Line 444
Purpose: Display transfer details for printing
Function Signature:
function edit()
Process Flow:
1. Get transfer ID from URL
2. Load extended transfer data
3. Display via print template
---
7. getSaves() - Cash Register List
Location: Line 247
Purpose: Load available cash registers for selection
Function Signature:
function getSaves()
Returns: Array of active cash register records
---
๐ Workflows
Workflow 1: Cash Transfer Processing
---
Workflow 2: Transfer Reversal Process
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Show form | Display transfer creation interface | |
| `do=add` | `add()` | Process new cash transfer | |
| `do=show` | `show()` | Display transfer history with filters | |
| `do=editprint` | `edit()` | Show printable transfer receipt | |
| `do=executeOperation` | `execute()` | Process batch operations | |
| `do=delete` | `delete()` | Reverse individual transfer | |
| `do=details` | Show details | Display transfer details view | |
| `do=sucess` | Show template | Display success message | |
| `do=error` | Show template | Display error message |
Transfer Creation (do=add):
- โข
transfer- Direction (1=bank to cash, 2=cash to bank) - โข
save- Cash register ID - โข
accountid- Bank account ID - โข
txtAmount- Transfer amount - โข
textNote- Transfer notes - โข
txtcheckNum- Reference number - โข
txtUser- User name - โข
ddlBank- Bank ID
Transfer History (do=show):
- โข
saveid- Cash register filter (optional) - โข
from- Start date filter (optional) - โข
to- End date filter (optional)
Batch Operations (do=executeOperation):
- โข
operation- Operation type (1=delete) - โข
choosedItem[]- Array of transfer IDs - โข
dailyentryid[]- Array of accounting entry IDs
Transfer Reversal (do=delete):
- โข
transferId- Transfer ID to reverse - โข
action- Daily entry ID for reversal
---
๐งฎ Balance Calculation Logic
Cash Register Balance Updates
// For BankโCash transfers (type 1)
$saveAfter = $saveBefore + $amount;
$savedailychangetype = 0; // Increase
// For CashโBank transfers (type 2)
$saveAfter = $saveBefore - $amount;
$savedailychangetype = 1; // Decrease
Bank Account Balance Updates
// For BankโCash transfers (decrease bank)
$accountAfter = $accountBefore - $amount;
$accountmovementtype = 1; // Withdrawal
// For CashโBank transfers (increase bank)
$accountAfter = $accountBefore + $amount;
$accountmovementtype = 0; // Deposit
Accounting Entry Logic
// BankโCash: Debit Cash Account, Credit Bank Account
if ($transfer == 1) {
$dailyEntryDebtor->accountstreeid = $saveTreeId; // Cash register
$dailyEntryCreditor->accountstreeid = $accountTreeId; // Bank account
}
// CashโBank: Debit Bank Account, Credit Cash Account
else {
$dailyEntryDebtor->accountstreeid = $accountTreeId; // Bank account
$dailyEntryCreditor->accountstreeid = $saveTreeId; // Cash register
}
---
๐ Transaction Safety Features
Database Transactions
$cashTransactions = new Transaction();
try {
// All operations here
$cashTransactions->commit();
$message = 'ุชู
ุช ุงูุนู
ููุฉ ุจูุฌุงุญ';
} catch (Exception $ex) {
$cashTransactions->rollback();
$message = 'ุนููุง ููุฏ ุญุฏุซ ุฎุทุฃ';
}
Audit Trail Maintenance
- โข Original records preserved during reversals
- โข Complete transaction history in movement tables
- โข Accounting entries maintain double-entry integrity
- โข User and timestamp tracking for all operations
Error Recovery
- โข Automatic transaction rollback on failures
- โข Graceful error handling with user feedback
- โข Batch operation continues despite individual failures
---
๐ Security & Validation
Access Control
include_once("../public/authentication.php");
Input Validation
- โข Amount validation (positive numbers)
- โข Account existence validation
- โข Balance sufficiency checks
- โข User permission validation
Transaction Integrity
- โข Atomic operations with rollback support
- โข Balance consistency validation
- โข Duplicate prevention mechanisms
---
๐ Common Issues & Troubleshooting
1. Balance Inconsistencies
Issue: Cash register and bank balances don't match transaction history
Cause: Interrupted transactions or rollback failures
Debug:
-- Check balance vs. transaction sum
SELECT s.savename, s.savecurrentvalue,
SUM(CASE WHEN sd.savedailychangetype = 0 THEN sd.savedailychangeamount ELSE -sd.savedailychangeamount END) as calculated
FROM save s
LEFT JOIN savedaily sd ON sd.saveid = s.saveid
GROUP BY s.saveid;
2. Accounting Entry Mismatches
Issue: Daily entries don't balance
Cause: Incorrect debit/credit assignment
Fix: Verify account tree IDs and transfer direction logic
3. Transfer Reversal Failures
Issue: Cannot reverse completed transfers
Cause: Missing daily entry ID or permissions
Solution: Verify dailyentryid is populated and user has reversal permissions
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข saveController.md - Cash register management
- โข bankaccountController.md - Bank account operations
- โข dailyentry.md - Accounting integration
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur