BankAccountDeficitKind Documentation
Bank Account Deficit Kind Controller Documentation
File: /controllers/bankAccountDeficitKindController.php
Purpose: Manages account movement type categories for bank deficit operations classification
Last Updated: December 20, 2024
Total Functions: 2
Lines of Code: ~189
---
๐ Overview
The Bank Account Deficit Kind Controller is a support module that manages the categorization system for account movement types. It provides:
- โข Creation and management of account movement categories
- โข Classification system for different types of bank deficit operations
- โข Reference data for dropdown selections in other bank modules
- โข Administrative interface for movement type configuration
- โข Audit trail for category modifications
Primary Functions
- โ Add new account movement kind categories
- โ Display list of existing movement kinds
- โ Provide reference data for other controllers
- โ Track creation dates and user ownership
- โ Support conditional filtering (active/inactive)
- โ Administrative management interface
Related Controllers
- โข bankAccountDeficitController.php - Uses movement kinds for categorization
- โข bankAccountOpController.php - Bank operations
- โข accountmovementController.php - General account movements
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns |
|---|---|---|
| **accountmovementkind** | Movement type categories | accountmovementkindid, accountmovementkindname, accountmovementkindcomment, conditions, userid, tablename |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **youtubelink** | Tutorial/help links | youtubelinkid, title, url | |
| **user** | System users | userid, username |
๐๏ธ Database Schema Details
accountmovementkind Table Structure
CREATE TABLE accountmovementkind (
accountmovementkindid INT PRIMARY KEY AUTO_INCREMENT,
accountmovementkindname VARCHAR(255) NOT NULL,
accountmovementkindcomment TEXT,
conditions TINYINT DEFAULT 0, -- 0=active, 1=inactive
accountmovementkinddate DATETIME,
tablename VARCHAR(100), -- Source controller tracking
userid INT, -- Creator/owner
FOREIGN KEY (userid) REFERENCES user(userid)
);
---
๐ Key Functions
1. Default Action - Add Category Form
Location: Line 67
Purpose: Display form for creating new movement kind categories
Process Flow:
1. Include authentication and permission checks
2. Display category creation form via add.html template
3. Set custom validation flag for form processing
Template Variables: None specific - basic form display
---
2. add() - Create Movement Kind Category
Location: Line 158
Purpose: Insert new account movement kind category into database
Function Signature:
function add()
Process Flow:
1. Extract Form Data:
$accountmovementkindname = $_POST["accountmovementkindname"];
$accountmovementkindcomment = $_POST["accountmovementkindcomment"];
```
2. **Set Category Properties**:
```php
$myAccountmovementkind->accountmovementkindname = $accountmovementkindname;
$myAccountmovementkind->accountmovementkindcomment = $accountmovementkindcomment;
$myAccountmovementkind->conditions = 0; // Active by default
$myAccountmovementkind->accountmovementkinddate = date('Y-m-d H:i:s');
$myAccountmovementkind->tablename = "bankAccountDeficitkindController.php";
$myAccountmovementkind->userid = $_SESSION['userid'];
```
3. **Insert Record**:
```php
$accountMovementId = $myAccountmovementkindRecord->insert($myAccountmovementkind);
```
**Return Value**: New record ID
**Key Features**:
- Auto-timestamps creation date
- Links to creating user for ownership tracking
- Source controller identification via `tablename`
- Default active status (`conditions = 0`)
---
### 3. **show()** - Display Category List
**Location**: Line 89
**Purpose**: Show all existing movement kind categories in a list format
**Process Flow**:
1. **Query All Categories**:
```php
$shownData = $myAccountmovementkindRecord->queryAll();
$smarty->assign("shownData", $shownData);
```
2. **Load Support Data**:
```php
$youtubes = $youtubeLinkDAO->queryAll();
$smarty->assign("youtubes", $youtubes);
```
3. **Display via Template**:
- Uses `show.html` template
- Shows all categories regardless of status
- Includes YouTube tutorial links
**Template Variables**:
- `$shownData` - Array of all movement kind categories
- `$youtubes` - Available tutorial links
---
### 4. **edit($id)** - Load Single Category (Stub)
**Location**: Line 177
**Purpose**: Load specific movement kind category for editing/display
**Function Signature**:
php
function edit($id)
**Current Implementation**:
php
$data = $myAccountmovementEx->loadMovementEX($id);
return $data;
**Note**: This function appears to have incorrect implementation - it loads account movements instead of movement kinds. This may be a bug or incomplete feature.
---
## ๐ Workflows
### Workflow 1: Creating New Movement Kind
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ START: Add Movement Kind โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 1. Display Add Form โ
โ - Show category name field โ
โ - Show description/comment field โ
โ - Include form validation โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 2. Process Form Submission โ
โ - Extract category name and comment โ
โ - Set creation timestamp โ
โ - Assign to current user โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 3. Insert into Database โ
โ - Create new accountmovementkind record โ
โ - Set active status (conditions = 0) โ
โ - Link to source controller โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 4. Redirect to Success/Error โ
โ - Show success message if completed โ
โ - Show error message if failed โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
---
### Workflow 2: Viewing Movement Kind List
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ START: View Categories โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 1. Query All Movement Kinds โ
โ - Load all records from accountmovementkind table โ
โ - Include both active and inactive categories โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 2. Load Additional Reference Data โ
โ - Load YouTube tutorial links โ
โ - Prepare template variables โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 3. Display Category List โ
โ - Show category names and descriptions โ
โ - Display creation dates and owners โ
โ - Include management actions (if implemented) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
---
## ๐ URL Routes & Actions
| URL Parameter | Function Called | Description |
|---------------|----------------|-------------|
| `do=` (empty) | Default action | Display add category form |
| `do=add` | `add()` | Process new category creation |
| `do=show` | Show categories | Display list of all categories |
| `do=editprint` | `edit()` | Load single category (implementation issue) |
| `do=sucess` | - | Show success message |
| `do=error` | - | Show error message |
### Required Parameters by Action
**Add Category** (`do=add`):
- `accountmovementkindname` - Category name (required)
- `accountmovementkindcomment` - Description/comment (optional)
**Show Categories** (`do=show`):
- No parameters required - shows all categories
**Edit Category** (`do=editprint`):
- `id` - Movement kind ID (Note: current implementation may be incorrect)
---
## ๐งฎ Data Management
### Category Properties
php
// Standard category structure
$category = new stdClass();
$category->accountmovementkindname = "Bank Service Charges";
$category->accountmovementkindcomment = "Monthly maintenance and transaction fees";
$category->conditions = 0; // Active
$category->accountmovementkinddate = "2024-12-20 10:30:00";
$category->tablename = "bankAccountDeficitkindController.php";
$category->userid = 123;
### Common Category Examples
- **Bank Service Charges** - Monthly fees, transaction costs
- **Interest Adjustments** - Interest income, penalty interest
- **Currency Exchange** - Foreign exchange gains/losses
- **Reconciliation Items** - Statement differences, corrections
- **Fee Reversals** - Refunded charges, credit adjustments
---
## ๐ Security & Permissions
### Authentication
- All actions require authentication via `include_once("../public/authentication.php")`
- Session-based user validation
- User ownership tracking for audit purposes
### Data Integrity
- Required field validation for category names
- Automatic timestamping for creation tracking
- Source controller identification for audit trails
### Access Control
- User-based creation tracking (`userid` field)
- Potential for user-specific category filtering (not currently implemented)
- Administrative access typically required
---
## ๐ก Usage in Other Controllers
### Integration with bankAccountDeficitController
php
// In deficit controller - load movement kinds for dropdown
$accountmovementkind = $myAccountmovementkindEx->queryAllExt();
$smarty->assign("accountmovementkind", $accountmovementkind);
// User selects movement kind when creating deficit adjustment
$accountmovementkindid = $_POST["accountmovementkindid"];
$myAccountmovement->accountmovementkindid = $accountmovementkindid;
### Common Query Patterns
sql
-- Get active movement kinds for dropdowns
SELECT * FROM accountmovementkind
WHERE conditions = 0
ORDER BY accountmovementkindname;
-- Get movement kinds by user
SELECT * FROM accountmovementkind
WHERE userid = ? AND conditions = 0;
-- Usage statistics
SELECT amk.accountmovementkindname, COUNT(am.accountmovementid) as usage_count
FROM accountmovementkind amk
LEFT JOIN accountmovement am ON am.accountmovementkindid = amk.accountmovementkindid
GROUP BY amk.accountmovementkindid;
---
## ๐ Known Issues & Limitations
### 1. **Incomplete Edit Function**
**Issue**: The `edit()` function loads account movements instead of movement kinds
php
// Current implementation (incorrect)
$data = $myAccountmovementEx->loadMovementEX($id);
// Should be (correction needed)
$data = $myAccountmovementkindRecord->load($id);
### 2. **No Update/Delete Functionality**
**Issue**: Controller only supports add and show operations
**Impact**: Cannot modify or remove categories after creation
**Workaround**: Use database directly or implement missing functions
### 3. **Limited Error Handling**
**Issue**: Basic transaction handling without detailed error reporting
**Impact**: Generic error messages on failures
**Enhancement**: Add specific validation and error reporting
---
## ๐ง Potential Improvements
### 1. **Complete CRUD Operations**
php
// Add missing update function
function update() {
global $myAccountmovementkind;
global $myAccountmovementkindRecord;
$id = $_POST['accountmovementkindid'];
$name = $_POST['accountmovementkindname'];
$comment = $_POST['accountmovementkindcomment'];
$myAccountmovementkind->accountmovementkindid = $id;
$myAccountmovementkind->accountmovementkindname = $name;
$myAccountmovementkind->accountmovementkindcomment = $comment;
return $myAccountmovementkindRecord->update($myAccountmovementkind);
}
### 2. **Category Status Management**
php
// Add activation/deactivation
function toggleStatus($id) {
global $myAccountmovementkindRecord;
$category = $myAccountmovementkindRecord->load($id);
$category->conditions = $category->conditions == 0 ? 1 : 0;
return $myAccountmovementkindRecord->update($category);
}
### 3. **Enhanced Validation**
php
// Add name uniqueness check
function validateUniqueName($name, $excludeId = null) {
global $myAccountmovementkindEx;
$existing = $myAccountmovementkindEx->queryByName($name);
return empty($existing) || ($excludeId && $existing->accountmovementkindid == $excludeId);
}
---
## ๐งช Testing Scenarios
### Test Case 1: Category Creation
1. Navigate to movement kind management
2. Fill in category name: "Bank Interest Income"
3. Add description: "Monthly interest credited by bank"
4. Submit form
5. Verify category appears in list
6. Check database record has correct timestamps and user ID
### Test Case 2: Category Listing
1. Create multiple categories with different users
2. Navigate to show page
3. Verify all categories display correctly
4. Check ordering and formatting
5. Confirm YouTube links load properly
### Test Case 3: Integration Testing
1. Create new movement kind category
2. Navigate to deficit adjustment form
3. Verify new category appears in dropdown
4. Create deficit adjustment using new category
5. Confirm category ID is stored in account movement
```
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข bankAccountDeficitController.md - Deficit management (primary consumer)
- โข Database Schema Documentation - Table relationships
- โข User Management Documentation - User roles and permissions
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When missing functions are implemented