BankAccountOp Documentation

Bank Account Operations Controller Documentation

File: /controllers/bankAccountOpController.php

Purpose: Displays comprehensive bank account transaction history and operation monitoring

Last Updated: December 20, 2024

Total Functions: No custom functions (view-only controller)

Lines of Code: ~271

---

๐Ÿ“‹ Overview

The Bank Account Operations Controller is a specialized reporting and monitoring module that provides comprehensive views of all bank account activities across the system. It serves as a central hub for:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Read Operations)

Table NamePurposeKey Columns
**accountmovement**All account transactionsaccountmovementid, accountid, accountmovementamount, accountmovementtype, accountmovementdate, tablename, accountmovementmodelid
**bankaccount**Bank account master dataaccountid, accountname, bankname, accountbeginingbalance
### Transaction Source Tables (Referenced)

Table NamePurposeKey Columns
**checkdeposit**Check deposit transactionscheckdepositid, clientid, bankname, checkamount
**checkwithdrawal**Check withdrawal transactionscheckwithdrawalid, supplierid, checkamount
**cashtransfer**Cash transfer operationscashtransferid, type, savename, amount
**datedchecked**Post-dated check managementdatedcheckedid, clientNum, addType, done
**sellbill**Sales bill transactionssellbillid, sellbillclientid, sellbilltotalpayed
### Reference Tables

Table NamePurposeKey Columns
**client**Customer informationclientid, clientname
**supplier**Supplier informationsupplierid, suppliername
**youtubelink**Tutorial/help linksyoutubelinkid, title, url
---

๐Ÿ”‘ Key Functions & Actions

1. Default Action - Account Selection Interface

Location: Line 184

Purpose: Display account selection form for transaction viewing

Process Flow:

1. Load All Accounts with Bank Names:

   $allAccounts = $myBankaccountEx->queryAllWithBankName();
   $smarty->assign("allAccounts", $allAccounts);
   ```

2. **Setup Breadcrumb Navigation**:
   ```php
   $breadcrumbObject->add('ุงุฏุงุฑุฉ ุงู„ุจู†ูˆูƒ><a href="bankaccountController.php?do=show">ุญุณุงุจุงุช ุงู„ุจู†ูˆูƒ</a> > ุงุถุงูุฉ ุญุณุงุจ', 'bankaccountController.php', 0);
   ```

3. **Display Selection Interface**: Uses `show.html` template for account selection

**Template Variables**:
- `$allAccounts` - All bank accounts with bank names for dropdown
- `$breadCrumb` - Navigation breadcrumb

---

### 2. **show** - Transaction History Display
**Location**: Line 201  
**Purpose**: Display comprehensive transaction history for selected account with source identification

**Function Parameters**:
php

$accountId = filter_input(INPUT_POST, 'accountid'); // Target account

$from = filter_input(INPUT_POST, 'startDate'); // Date range start

$to = filter_input(INPUT_POST, 'endDate'); // Date range end

**Process Flow**:

#### **Step 1: Build Dynamic Query**
php

$query = '';

if ($accountId && $accountId != -1)

$query .= ' and accountmovement.accountid = ' . $accountId;

if ($from)

$query .= ' and date(accountmovement.accountmovementdate) >= "' . $from . '"';

if ($to)

$query .= ' and date(accountmovement.accountmovementdate) <= "' . $to . '"';

#### **Step 2: Load Movement Data**
php

$allMovements = $accountMovementExt->queryAllMovements2($query);

#### **Step 3: Source Transaction Identification and Enhancement**
For each movement record, identify source and enhance with related data:

**A. Check Deposits** (`depositcheckController.php`):
php

if ($movement->tablename == "depositcheckController.php") {

$depositData = $CheckdepositEX->loadEX($movement->accountmovementmodelid);

$movement->clientname = $depositData->clientname;

}

**B. Check Withdrawals** (`checkwithdrawalController.php`):
php

elseif ($movement->tablename == "checkwithdrawalController.php") {

$withdrawalData = $checkWithdrawalExtDAO->queryByIdExtwithsuplier($movement->accountmovementmodelid);

$movement->clientname = $withdrawalData->suppliername;

}

**C. Cash Transfers** (`cashTransferController.php`):
php

elseif ($movement->tablename == "cashTransferController.php") {

$transferData = $cashTransferExt->loadExt($movement->accountmovementmodelid);

if ($transferData->type == 1)

$movement->processname = "ุชุญูˆูŠู„ ู†ู‚ุฏูŠ ู…ู† ุจู†ูƒ (" . $movement->bankname . ") ุฅู„ู‰ ุฎุฒู†ุฉ (" . $transferData->savename . ")";

}

**D. Post-dated Checks** (`datedCheckedController.php`):
php

elseif ($movement->tablename == "datedCheckedController.php") {

$row = $datedCheckedDAO->load($movement->accountmovementmodelid);

if ($row->addType == 1) {

$supID = $row->clientNum;

$allSup = $supplierDAO->load($supID);

$clName = $allSup->suppliername;

} else {

$id1 = $row->clientNum;

$allClient = $clientDAO->load($id1);

$clName = $allClient->clientname;

}

$movement->clientname = $clName;

}

**E. Sales Bills** (`sellbillController.php`):
php

elseif ($movement->tablename == "sellbillController.php") {

$sellData = $mySellbillEx->loadExtWithClient($movement->accountmovementmodelid);

$movement->clientname = " " . $sellData->clientname . " / " . $movement->accountmovementmodelid . " ";

}

#### **Step 4: Display Enhanced Results**
php

$smarty->assign('allMovements', $allMovements);

// Load current account balance

$accountData = $myBankaccountRecord->load($accountId);

$smarty->assign('currentBalance', $accountData->accountbeginingbalance);

// Load support data

$youtubes = $youtubeLinkDAO->queryAll();

$smarty->assign("youtubes", $youtubes);

---

## ๐Ÿ”„ Workflows

### Workflow 1: Account Transaction History Viewing

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚ START: Select Account & Filters โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”‚

โ–ผ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚ 1. Account Selection โ”‚

โ”‚ - Choose from all available bank accounts โ”‚

โ”‚ - Optionally set date range filters โ”‚

โ”‚ - Submit search criteria โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”‚

โ–ผ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚ 2. Build Query with Filters โ”‚

โ”‚ - Add account ID filter (if specific account) โ”‚

โ”‚ - Add date range filters (if specified) โ”‚

โ”‚ - Apply to accountmovement table โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”‚

โ–ผ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚ 3. Load Base Movement Data โ”‚

โ”‚ - Query accountmovement table with filters โ”‚

โ”‚ - Get basic transaction information โ”‚

โ”‚ - Include amounts, dates, types โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”‚

โ–ผ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚ 4. Enhance Each Transaction โ”‚

โ”‚ FOR EACH movement: โ”‚

โ”‚ โ”‚ โ”‚

โ”‚ โ”œโ”€โ†’ Identify source controller (tablename) โ”‚

โ”‚ โ”‚ โ”‚

โ”‚ โ”œโ”€โ†’ Load related transaction details โ”‚

โ”‚ โ”‚ โ”œโ”€ Check deposits โ†’ client name โ”‚

โ”‚ โ”‚ โ”œโ”€ Check withdrawals โ†’ supplier name โ”‚

โ”‚ โ”‚ โ”œโ”€ Cash transfers โ†’ destination info โ”‚

โ”‚ โ”‚ โ”œโ”€ Dated checks โ†’ client/supplier โ”‚

โ”‚ โ”‚ โ””โ”€ Sales bills โ†’ customer info โ”‚

โ”‚ โ”‚ โ”‚

โ”‚ โ””โ”€โ†’ Enhance movement object with details โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”‚

โ–ผ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚ 5. Display Comprehensive Report โ”‚

โ”‚ - Show enhanced transaction list โ”‚

โ”‚ - Include source identification โ”‚

โ”‚ - Display current account balance โ”‚

โ”‚ - Provide links to source documents โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

## ๐ŸŒ URL Routes & Actions

| URL Parameter | Action Description | Template Used |
|---------------|-------------------|---------------|
| `do=` (empty) | Show account selection form | `bankAccountOpview/show.html` |
| `do=show` | Display transaction history for selected account | `bankAccountOpview/show.html` |

### Required Parameters by Action

**Account Selection** (Default):
- No parameters required - displays selection form

**Transaction History** (`do=show`):
- `accountid` - Bank account ID (from POST, -1 for all accounts)
- `startDate` - Start date filter (YYYY-MM-DD format, optional)
- `endDate` - End date filter (YYYY-MM-DD format, optional)

---

## ๐Ÿ“Š Transaction Source Integration

### Supported Transaction Sources

| Controller | Transaction Type | Data Enhancement | Key Information |
|------------|-----------------|------------------|-----------------|
| **depositcheckController.php** | Check deposits | Client name | Customer who deposited check |
| **checkwithdrawalController.php** | Check withdrawals | Supplier name | Supplier receiving payment |
| **cashTransferController.php** | Cash transfers | Transfer details | Source/destination information |
| **datedCheckedController.php** | Post-dated checks | Client/Supplier name | Based on addType flag |
| **sellbillController.php** | Sales transactions | Customer info | Customer and bill ID |

### Data Enhancement Logic

php

// Generic enhancement pattern

foreach ($allMovements as $movement) {

switch($movement->tablename) {

case "depositcheckController.php":

// Load deposit details and add client name

break;

case "checkwithdrawalController.php":

// Load withdrawal details and add supplier name

break;

case "cashTransferController.php":

// Load transfer details and enhance description

break;

// ... additional cases

}

}

---

## ๐Ÿงฎ Balance and Amount Display

### Current Balance Retrieval
php

// Get real-time account balance

$accountData = $myBankaccountRecord->load($accountId);

$currentBalance = $accountData->accountbeginingbalance;

$smarty->assign('currentBalance', $currentBalance);

### Transaction Amount Types
- **Positive Amounts**: Credits to account (deposits, transfers in)
- **Negative Amounts**: Debits from account (withdrawals, transfers out)
- **Movement Types**: Stored in `accountmovementtype` field

---

## ๐Ÿ”’ Security & Permissions

### Authentication
- All actions require authentication: `include_once("../public/authentication.php")`
- Session-based user validation
- Account access may be user-restricted (implementation dependent)

### Data Access
- Read-only operations - no data modifications
- Cross-references multiple transaction sources safely
- Uses parameterized queries through DAO layer

### Input Validation
php

// Secure input filtering

$accountId = filter_input(INPUT_POST, 'accountid');

$from = filter_input(INPUT_POST, 'startDate');

$to = filter_input(INPUT_POST, 'endDate');

---

## ๐ŸŽฏ Use Cases & Benefits

### 1. **Account Reconciliation**

Scenario: Monthly bank statement reconciliation

### 2. **Audit Trail Investigation**

Scenario: Investigating specific transaction

### 3. **Cash Flow Analysis**

Scenario: Analyzing account activity patterns

### 4. **Multi-Source Transaction Tracking**

Scenario: Understanding complete account picture

---

## ๐Ÿ“‹ Display Features

### Enhanced Transaction Information
Each transaction shows:
- **Basic Data**: Date, amount, type, before/after balances
- **Source Controller**: Which module created the transaction
- **Related Party**: Customer or supplier name (when applicable)
- **Process Description**: Human-readable transaction description
- **Link Capability**: Potential linking to source documents

### Account Balance Display
- **Current Balance**: Real-time account balance
- **Transaction History**: Before/after amounts for each transaction
- **Balance Tracking**: Running balance calculations

### Filtering Capabilities
- **By Account**: Specific account or all accounts
- **By Date Range**: Flexible start/end date filtering
- **Combined Filters**: Account + date range combinations

---

## ๐Ÿ› Troubleshooting

### Common Issues

1. **Missing Transaction Details**
   ```
   Issue: Transaction shows without client/supplier name
   Cause: Source data deleted or corrupted
   Solution: Check source table integrity
   ```

2. **Incorrect Balance Display**
   ```
   Issue: Current balance doesn't match transaction history
   Cause: Balance calculation errors or missing transactions
   Solution: Verify accountmovement completeness
   ```

3. **Source Document Not Found**
   ```
   Issue: Cannot load related transaction details
   Cause: Referenced record deleted or ID mismatch
   Solution: Check foreign key integrity
   ```

### Debug Queries
sql

-- Check transaction source integrity

SELECT DISTINCT tablename, COUNT(*) as count

FROM accountmovement

GROUP BY tablename;

-- Verify account balance consistency

SELECT a.accountname, a.accountbeginingbalance,

SUM(CASE WHEN am.accountmovementtype = 0 THEN am.accountmovementamount ELSE -am.accountmovementamount END) as calculated

FROM bankaccount a

LEFT JOIN accountmovement am ON a.accountid = am.accountid

GROUP BY a.accountid;

-- Find orphaned transactions

SELECT * FROM accountmovement am

WHERE am.tablename = 'checkdepositController.php'

AND NOT EXISTS (SELECT 1 FROM checkdeposit cd WHERE cd.checkdepositid = am.accountmovementmodelid);

---

## ๐Ÿ”ง Potential Enhancements

### 1. **Export Functionality**
php

// Add CSV/Excel export capability

function exportTransactions($accountId, $startDate, $endDate) {

// Generate export file with enhanced transaction data

}

### 2. **Advanced Filtering**
php

// Add transaction type and amount range filters

$transactionType = filter_input(INPUT_POST, 'transactionType');

$minAmount = filter_input(INPUT_POST, 'minAmount');

$maxAmount = filter_input(INPUT_POST, 'maxAmount');

### 3. **Real-time Updates**
javascript

// Add AJAX refresh for real-time balance updates

setInterval(function() {

updateCurrentBalance(accountId);

}, 30000); // Update every 30 seconds

### 4. **Transaction Linking**
php

// Add direct links to source documents

function generateTransactionLink($tablename, $modelid) {

$linkMap = [

'sellbillController.php' => "sellbillController.php?do=editprint&id={$modelid}",

'depositcheckController.php' => "depositcheckController.php?do=edit&id={$modelid}"

// ... additional mappings

];

return isset($linkMap[$tablename]) ? $linkMap[$tablename] : '#';

}

```

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When additional transaction sources are integrated