Depositcheck Documentation
Check Deposit Controller Documentation
File: /controllers/depositcheckController.php
Purpose: Manages check deposits from customers to bank accounts, reducing customer debt and increasing bank balances
Last Updated: December 20, 2024
Total Functions: 8+
Lines of Code: ~1,229
---
๐ Overview
The Check Deposit Controller handles the process of depositing customer checks into bank accounts. This is a critical financial operation that:
- โข Records customer check deposits to specific bank accounts
- โข Reduces customer debt by the deposited amount
- โข Updates bank account balances and movements
- โข Generates proper accounting entries for the transactions
- โข Supports integration with premium payment systems
- โข Provides comprehensive tracking and reversal capabilities
Primary Functions
- โ Process customer check deposits to bank accounts
- โ Update customer debt balances automatically
- โ Track bank account balance changes
- โ Generate accounting entries (daily entries)
- โ Handle premium payment allocations
- โ Support deposit reversal (cancellation)
- โ Maintain detailed audit trails
- โ Integrate with concurrent user protection
Related Controllers
- โข datedCheckedController.php - Post-dated check management
- โข clientPayedDeptController.php - Customer payments
- โข bankaccountController.php - Bank account operations
- โข accountmovementController.php - Account movement tracking
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **checkdeposit** | Check deposit master records | checkdepositid, clientid, bankaccountid, checkdepositamount, checkdepositdate, conditions, dailyentryid | |
| **clientdebtchange** | Customer debt transaction log | clientdebtchangeid, clientid, clientdebtchangeamount, clientdebtchangetype, clientdebtchangedate, tablename | |
| **accountmovement** | Bank account movement tracking | accountmovementid, accountid, accountmovementamount, accountmovementtype, tablename, accountmovementmodelid |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **bankaccount** | Bank account master data | accountid, bankid, accountbeginingbalance, accountdate, treeId | |
| **bank** | Bank master information | bankid, bankname | |
| **client** | Customer master data | clientid, clientname, clientdebt, treeId, inUse |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **premium** | Premium/installment tracking | premiumid, value, rest, payed, clientid | |
| **dailyentry** | Accounting entries | dailyentryid, entryComment, entryDate | |
| **accountstree** | Chart of accounts | id, name, parent, theValue |
๐ Key Functions
1. Default Action - Add Form Display
Location: Line 172
Purpose: Display the check deposit form with necessary dropdowns
Process Flow:
1. Load all banks with extended information
2. Load all customer data
3. Set today's date as default
4. Display deposit form template
Key Variables:
- โข
$bank- All available banks - โข
$allclientdata- All customers for selection - โข
$today- Current date
---
2. add() - Process Check Deposit
Location: Line 480
Purpose: Core function to process customer check deposits
Function Signature:
function add()
Process Flow:
1. Transaction Start: Initialize transaction for data consistency
2. Input Processing: Extract and validate POST parameters
3. Client Debt Management:
- Lock client using concurrent access protection
- Reduce customer debt by deposit amount
- Log debt change in clientdebtchange table
4. Bank Account Updates:
- Increase bank account balance
- Create account movement record
5. Check Deposit Record: Insert main deposit record
6. Accounting Integration: Generate daily entry
7. Premium Handling: Process installment payments if applicable
8. Transaction Commit: Finalize all changes
Key Variables:
- โข
$clientid- Customer making deposit - โข
$accountid- Target bank account - โข
$checkwithdrawalamount- Deposit amount - โข
$checkdate- Deposit date
---
3. show() - Display Deposits
Location: Line 782
Purpose: Display check deposits based on various filters
Filter Options:
- โข Date Range: From and to dates
- โข Customer: Specific customer deposits
- โข Single Deposit: By deposit ID
- โข Today Only: Default view
Process Flow:
1. Parse filter parameters from request
2. Build appropriate query based on filters
3. Execute query through extended DAO
4. Assign results to template
5. Display with appropriate message
Query Patterns:
// Date range query
$shownData = $CheckdepositEX->queryWithDateExt($from, $to);
// Customer specific query
$shownData = $CheckdepositEX->queryWithClientIdExt($clientId);
// Single deposit query
$temp = $CheckdepositEX->loadEX($id);
---
4. delete() - Reverse Check Deposit
Location: Line 869
Purpose: Reverse/cancel a check deposit transaction
Function Signature:
function delete($id, $dailentry)
Process Flow:
1. Transaction Start: Begin reversal transaction
2. Load Original Data: Get deposit details
3. Reverse Customer Debt: Add back the deposit amount to customer debt
4. Reverse Bank Account: Subtract deposit from bank balance
5. Log Reversal: Create debt change and account movement records
6. Update Status: Mark deposit as cancelled (conditions=1)
7. Reverse Accounting: Call reverseEntryWithItsID() to reverse daily entry
Key Features:
- โข Maintains audit trail of reversal
- โข Supports both same-day and historical reversals
- โข Handles concurrent user scenarios
- โข Preserves original transaction data
---
5. edit() - Load Deposit for Editing
Location: Line 1058
Purpose: Load deposit data for modification
Process Flow:
1. Get deposit ID from POST or GET
2. Load extended deposit information
3. Load related customer data
4. Return deposit object for template
---
6. update() - Update Deposit Details
Location: Line 1091
Purpose: Update non-financial deposit details
Process Flow:
1. Extract update parameters
2. Update deposit user and note fields
3. Preserve financial data integrity
Note: Only updates metadata, not financial amounts
---
7. execute() - Batch Operations
Location: Line 1137
Purpose: Process multiple deposits in batch (mainly deletions)
Process Flow:
1. Parse operation type and selected items
2. Loop through selected deposits
3. Execute operation (typically deletion)
4. Accumulate results and error messages
5. Display operation summary
---
8. getClientDataFromClientInUseSP() - Concurrent Access Protection
Location: Line 1191
Purpose: Safely access customer data with locking mechanism
Function Signature:
function getClientDataFromClientInUseSP($clientid)
Process Flow:
1. Check if customer is being used by another process
2. Wait if customer is locked (up to 15 seconds)
3. Force unlock if wait time exceeds limit
4. Return customer data when available
Concurrency Features:
- โข Prevents simultaneous debt modifications
- โข Automatic timeout and recovery
- โข Live backup logging for force unlocks
---
๐ Workflows
Workflow 1: Standard Check Deposit
Workflow 2: Check Deposit Reversal
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default | Display check deposit form | |
| `do=add` | `add()` | Process new check deposit | |
| `do=show` | `show()` | Display deposits with filters | |
| `do=delete` | `delete()` | Cancel/reverse check deposit | |
| `do=edit` | `edit()` | Load deposit for editing | |
| `do=update` | `update()` | Update deposit details | |
| `do=details` | `edit()` | View deposit details | |
| `do=executeOperation` | `execute()` + `show()` | Batch operations on deposits | |
| `do=editprint` | `edit()` | Print-friendly edit view | |
| `do=editprint2` | `edit()` | Alternative print format with Arabic number conversion |
Add Deposit (do=add):
- โข
clientid- Customer ID - โข
accountid- Bank account ID - โข
txtAmount- Deposit amount - โข
ddlBank- Bank ID - โข
checkdate- Deposit date
Show Deposits (do=show):
- โข
clientid- Filter by customer (optional) - โข
from- Start date (optional) - โข
to- End date (optional) - โข
id- Specific deposit ID (optional)
Delete Deposit (do=delete):
- โข
id- Deposit ID to cancel - โข
action- Daily entry ID for reversal
---
๐งฎ Calculation Methods
Debt Balance Update
// Reduce customer debt by deposit amount
$Client->clientdebt = ($debtBefore - $checkwithdrawalamount);
// Log the debt change
$Clientdebtchange->clientdebtchangetype = 1; // Decrease
$Clientdebtchange->clientdebtchangeamount = $checkwithdrawalamount;
$Clientdebtchange->clientdebtchangeafter = $debtBefore - $checkwithdrawalamount;
Bank Account Balance Update
// Increase bank account balance
$account->accountbeginingbalance = $accountBefore + $checkwithdrawalamount;
// Track account movement
$accountMove->accountmovementtype = 0; // Increase
$accountMove->accountmovementafter = $accountBefore + $checkwithdrawalamount;
Premium Payment Allocation
if ($dept_rest < $checkwithdrawalamount) {
// Close current installment and apply excess to next
$rest = $checkwithdrawalamount - $dept_rest;
$premiumData->payed = 1;
$premiumData->rest = $premiumData->rest + $rest;
}
---
๐ Security & Permissions
Authentication Requirements
include_once("../public/authentication.php");
User Activity Tracking
- โข All records include
useridfield - โข Timestamp tracking on all operations
- โข Audit trail through clientdebtchange and accountmovement tables
Concurrent Access Protection
// Prevent simultaneous customer debt modifications
$client_data = $ClientEX->callClientInUseSP($clientid);
while ($client_data->clientdebt == 'in_use') {
sleep(1); // Wait for other process to complete
$noOfTries++;
if ($noOfTries > 15) {
// Force unlock after 15 seconds
R::exec('UPDATE client SET inUse = 0 where clientid = ' . $clientid);
}
}
---
๐ Performance Considerations
Database Optimization Tips
1. Indexes Required:
- checkdeposit(clientid, checkdepositdate)
- checkdeposit(bankaccountid, checkdepositdate)
- clientdebtchange(clientid, clientdebtchangedate)
- accountmovement(accountid, accountmovementdate)
2. Query Optimization:
- Use date filtering with proper indexes
- Avoid SELECT * in large tables
- Use prepared statements for repeated queries
3. Concurrency Management:
- Minimal lock duration on customer records
- Automatic timeout and recovery mechanisms
- Live backup logging for debugging
Known Performance Considerations
- โข Customer locking may cause delays under high concurrency
- โข Large date ranges in show() may return excessive data
- โข Premium payment processing adds complexity to deposit transactions
---
๐ Common Issues & Troubleshooting
1. Customer Lock Timeout
Issue: Deposit fails with "customer in use" error
Cause: Another process has locked the customer record
Solutions:
- โข Wait for automatic timeout (15 seconds)
- โข Check for stuck processes holding locks
- โข Force unlock using database direct access
2. Accounting Entry Mismatch
Issue: Daily entry amounts don't match deposit amounts
Cause: Error in daily entry generation or account tree setup
Debug:
-- Check daily entry details
SELECT * FROM dailyentry WHERE dailyentryid = [ENTRY_ID];
SELECT * FROM dailyentrycreditor WHERE dailyentryid = [ENTRY_ID];
SELECT * FROM dailyentrydebtorcredit WHERE dailyentryid = [ENTRY_ID];
3. Bank Balance Discrepancy
Issue: Bank account balance doesn't match sum of movements
Cause: Failed transaction or missing movement record
Verification:
-- Verify movement records
SELECT SUM(CASE WHEN accountmovementtype = 0 THEN accountmovementamount
ELSE -accountmovementamount END) as net_movement
FROM accountmovement
WHERE accountid = [ACCOUNT_ID] AND tablename = 'depositcheckController.php';
4. Premium Payment Allocation Errors
Issue: Installment payments not properly allocated
Cause: Logic error in premium processing or missing premium records
Debug Steps:
1. Verify premium records exist for customer
2. Check payment allocation logic
3. Ensure premium rest calculations are correct
---
๐งช Testing Scenarios
Test Case 1: Basic Check Deposit
1. Create customer with existing debt
2. Process check deposit for partial debt amount
3. Verify customer debt reduced correctly
4. Confirm bank account balance increased
5. Check daily entry created properly
Test Case 2: Concurrent Access
1. Start deposit process for customer A
2. Simultaneously start another process for same customer
3. Verify second process waits appropriately
4. Confirm no data corruption occurs
5. Validate final balances are correct
Test Case 3: Deposit Reversal
1. Create and process check deposit
2. Reverse the deposit transaction
3. Verify customer debt restored to original
4. Confirm bank account balance reduced
5. Check daily entry reversal created
Test Case 4: Premium Payment Integration
1. Set up customer with installment payments
2. Process deposit with premium allocation
3. Verify installments marked as paid
4. Check excess amount applied to next installment
5. Confirm premium payment records updated
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข datedCheckedController.md - Post-dated check management
- โข Database Schema Documentation - Table relationships
- โข Concurrent Access Protection - Multi-user safety features
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur