Dailyentryfun Documentation

Daily Entry Functions Controller Documentation

File: /controllers/dailyentryfun.php

Purpose: Core accounting utility functions for managing daily journal entries, accounts tree, and accounting operations

Last Updated: December 20, 2024

Total Functions: 25+

Lines of Code: ~858

---

๐Ÿ“‹ Overview

The Daily Entry Functions Controller serves as the backbone of the accounting system, providing essential utility functions for:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**accountstree**Chart of accounts masterid, name, parent, itemtype, itemtype2, theValue, userid, reportid
**dailyentry**Journal entry headersid, totalcreditor, totaldebtor, thedate, userid, entryComment, operationId
**dailyentrycreditor**Credit side entriesid, dailyentryid, accountstreeid, value, dComment, costcenterid
**dailyentrydebtor**Debit side entriesid, dailyentryid, accountstreeid, value, dComment, costcenterid
**costcenter**Cost center master dataid, name, description
**costcenterdetail**Cost center allocationsid, costcenterid, costamount, modelid, tablename, type
### Account Types (itemtype)

TypeDescriptionNature
**0**ู…ุตุฑูˆูุงุช (Expenses)Debit balance
**1**ุฎุตูˆู… (Liabilities)Credit balance
**2**ุฅูŠุฑุงุฏุงุช (Income)Credit balance
**3**ุฃุตูˆู„ (Assets)Debit balance
**4**ุญู‚ูˆู‚ ุงู„ู…ู„ูƒูŠุฉ (Equity)Credit balance
**5**ู…ุณุญูˆุจุงุช (Drawings)Debit balance
---

๐Ÿ”‘ Key Functions

1. addTreeElement() - Add Account to Chart

Location: Line 94

Purpose: Add new account to the chart of accounts with validation

Function Signature:

function addTreeElement($name, $parent, $itemtype, $itemfrom, $itemtype2, $notes = '', $theOrder = 0, $theValue = 0, $reportid = 0)

Parameters:

Return Values:

Validation:

---

2. insertEntery() - Create Journal Entry

Location: Line 337

Purpose: Insert complete double-entry journal transaction with validation

Function Signature:

function insertEntery($dailyEntryObj = NULL, $dailyEntryDebtorArray, $dailyEntryCreditorArray, $stopEntryTransaction = 0, $operationId = 0, $operationDetailLink = '')

Process Flow:

1. Validation: Ensure total debits = total credits and โ‰  0

2. Entry Header: Create dailyentry record with totals and metadata

3. Debit Entries: Process each debit line item

- Insert dailyentrydebtor record

- Update account balance via affectAccount()

- Handle cost center allocation if specified

- Execute plugin effects if fromFlag = 2

4. Credit Entries: Process each credit line item (same pattern)

5. Transaction Control: Commit on success, rollback on failure

Return Values:

Features:

---

3. reverseEntryWithItsID() - Reverse Journal Entry

Location: Line 495

Purpose: Create reversing entry to cancel out original transaction

Function Signature:

function reverseEntryWithItsID($id, $stopEntryTransaction = 0)

Process Flow:

1. Load original entry and validate not already reversed

2. Mark original entry as reversed (reverseofid = -10)

3. Create new entry with reversed debits/credits:

- Original debits โ†’ new credits

- Original credits โ†’ new debits

4. Update account balances with reversed amounts

5. Set comment: "ุชู… ุนูƒุณ ุงู„ู‚ูŠุฏ ุฑู‚ู… {id}"

Reversal Status Codes:

---

4. affectAccount() - Update Account Balance

Location: Line 759

Purpose: Update account balance based on transaction type and account nature

Function Signature:

function affectAccount($CreditorOrDebtorObj, $type)

Account Effect Logic:

// For Assets (3), Expenses (0), Drawings (5):
if ($type == 0) { // Debit side
    $operation = 'increase'; // Normal balance side
} else { // Credit side
    $operation = 'decrease'; // Contra balance side  
}

// For Liabilities (1), Income (2), Equity (4):
if ($type == 0) { // Debit side
    $operation = 'decrease'; // Contra balance side
} else { // Credit side  
    $operation = 'increase'; // Normal balance side
}

Parameters:

---

5. insertCostCenterDetail() - Track Cost Allocations

Location: Line 820

Purpose: Record cost center allocation for management reporting

Function Signature:

function insertCostCenterDetail($Costcenterid, $val, $dailyentryid, $comment, $controllerName, $costCenterType = -1)

Purpose: Links specific amounts to cost centers for:

---

๐Ÿ”„ Workflows

Workflow 1: Complete Journal Entry Creation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Prepare Entry Data Arrays
- $dailyEntryDebtorArray (from accounts)
- $dailyEntryCreditorArray (to accounts)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Validation Phase
- Calculate total debits: sum($dailyEntryDebtorArray)
- Verify: debits = credits AND โ‰  0
- FAIL โ†’ Return [-1, 0]
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Create Entry Header (dailyentry)
- totalcreditor = calculated total
- totaldebtor = calculated total
- thedate = today OR specified date
- userid = $_SESSION['userid']
- entryComment = description
- branchid = $_SESSION['branchId']
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Process Debit Entries
FOR EACH debit in $dailyEntryDebtorArray:
โ”‚
โ†’ Insert dailyentrydebtor record
โ”‚ โ”œโ”€ Link to main entry ID
โ”‚ โ”‚ โ””โ”€ Store account, amount, comment โ”‚
โ”‚
โ†’ Update Account Balance
โ”‚ โ”œโ”€ Load account from accountstree
โ”‚ โ”œโ”€ Determine operation (increase/decrease)
โ”‚ โ”‚ โ””โ”€ Update account theValue โ”‚
โ”‚
โ†’ Handle Cost Center (if specified)
โ”‚ โ”‚ โ””โ”€ Insert costcenterdetail record โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Execute Plugin Effects (if fromFlag = 2) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Process Credit Entries
FOR EACH credit in $dailyEntryCreditorArray:
โ”‚
โ†’ Insert dailyentrycreditor record
โ†’ Update Account Balance (opposite direction)
โ†’ Handle Cost Center (if specified)
โ”‚ โ””โ”€โ†’ Execute Plugin Effects (if fromFlag = 2) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Transaction Finalization
- Commit transaction (if managing transaction)
- Return [1, $dailyEntryId]
ERROR HANDLING:
- Rollback transaction on any exception
- Return [-2, 0] with error message
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

Workflow 2: Account Tree Management

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Add New Account
Parameters: name, parent, type, etc.
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Name Validation
- Check isUniqueName(name, parent)
- Search both 'name' and 'customName' fields
- Within same parent group only
IF DUPLICATE FOUND:
โ†’ Check if soft-deleted (del = 1)
โ†’ If yes: restore it (del = 0)
โ”‚ โ””โ”€โ†’ If no: return -1 (error) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Inherit Parent Properties
- Load parent account data
- Inherit: accountNature, listId, reportid
- Set default reportid = 2 for expenses/income
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Create Account Record
- name = specified name
- customName = name (can be changed later)
- parent = parent account ID
- itemtype = account type (0-5)
- itemtype2 = 1 for leaf, 0 for parent
- theValue = initial balance (if leaf)
- userid = $_SESSION['userid']
- sysdate = current timestamp
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Success Response
- Insert into accountstree table
- Return new account ID
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ Usage Examples

Example 1: Simple Expense Entry

// Record office supplies expense paid from cash
$dailyEntry = new Dailyentry();
$dailyEntry->entryComment = 'Office supplies purchase';

// Debit: Office Supplies Expense
$debitEntry = new Dailyentrydebtor();
$debitEntry->accountstreeid = 150; // Office Supplies account
$debitEntry->value = 500.00;
$debitEntry->dComment = 'Printer paper and pens';

// Credit: Cash Account  
$creditEntry = new Dailyentrycreditor();
$creditEntry->accountstreeid = 101; // Cash account
$creditEntry->value = 500.00;
$creditEntry->dComment = 'Payment for supplies';

$result = insertEntery($dailyEntry, [$debitEntry], [$creditEntry]);
// Returns: [1, 1234] where 1234 is the new entry ID

Example 2: Sales Transaction Entry

// Record cash sale with multiple accounts affected
$dailyEntry = new Dailyentry();
$dailyEntry->entryComment = 'Cash sale - invoice #12345';
$dailyEntry->operationId = 12345;
$dailyEntry->operationDetailLink = 'sellbillController.php?id=12345';

// Debit entries
$debitEntries = [];

// Cash received
$cashDebit = new Dailyentrydebtor();
$cashDebit->accountstreeid = 101; // Cash
$cashDebit->value = 1150.00;
$debitEntries[] = $cashDebit;

// Credit entries  
$creditEntries = [];

// Sales revenue
$salesCredit = new Dailyentrycreditor();
$salesCredit->accountstreeid = 201; // Sales Revenue
$salesCredit->value = 1000.00;
$creditEntries[] = $salesCredit;

// Sales tax
$taxCredit = new Dailyentrycreditor();
$taxCredit->accountstreeid = 210; // Sales Tax Payable
$taxCredit->value = 150.00;
$creditEntries[] = $taxCredit;

$result = insertEntery($dailyEntry, $debitEntries, $creditEntries);

---

๐Ÿ”’ Security & Permissions

User Access Control

Data Validation

Transaction Safety

---

๐Ÿ“Š Performance Considerations

Database Optimization

1. Indexes Required:

- accountstree(parent, del, name)

- accountstree(parent, del, customName)

- dailyentry(operationId)

- dailyentrycreditor(dailyentryid)

- dailyentrydebtor(dailyentryid)

2. Query Patterns:

- Frequent parent-child traversal in accounts tree

- Entry detail lookups by dailyentryid

- Account balance updates (single row updates)

Memory Management

---

๐Ÿ› Common Issues & Troubleshooting

1. "ู„ุงุจุฏ ุงู† ูŠูƒูˆู† ู…ุฌู…ูˆุน ู…ุฏูŠู† ูŠุณุงูˆู‰ ู…ุฌู…ูˆุน ุฏุงุฆู†" Error

Issue: Debits don't equal credits validation failure

Cause: Rounding errors or incorrect amount calculation

Debug:

$totalDebits = getTotal($dailyEntryDebtorArray);
$totalCredits = getTotal($dailyEntryCreditorArray);
echo "Debits: $totalDebits, Credits: $totalCredits";

2. "ุงุณู… ุงู„ุนู†ุตุฑ ู…ูƒุฑุฑ" Error

Issue: Account name already exists in parent group

Cause: Trying to create duplicate account name

Fix:

// Check before creating
$isUnique = isUniqueName($accountName, $parentId);
if (!$isUnique) {
    // Handle duplicate - maybe append suffix or use different name
}

3. Account Balance Calculation Errors

Issue: Account balances don't match expected values

Cause: Missing entries or incorrect account type logic

Debug:

// Check account type and recent entries
$account = $accountsTreeDAO->load($accountId);
echo "Account Type: " . $account->itemtype;
echo "Current Balance: " . $account->theValue;

// Check recent entries affecting this account
$recentDebits = $dailyEntryDebtorDAO->queryByAccountstreeid($accountId);
$recentCredits = $dailyEntryCreditorDAO->queryByAccountstreeid($accountId);

4. Transaction Rollback Issues

Issue: Partial entries created despite errors

Cause: Nested transaction handling or missing try-catch

Fix:

// Always use transaction wrapper
$transaction = new Transaction();
try {
    // Your journal entry operations
    insertEntery($entry, $debits, $credits, 1); // stopEntryTransaction = 1
    $transaction->commit();
} catch (Exception $e) {
    $transaction->rollback();
    // Handle error appropriately
}

---

๐Ÿงช Testing Scenarios

Test Case 1: Basic Double-Entry Validation

1. Create entry with unbalanced debits/credits
2. Verify function returns [-1, 0]  
3. Create entry with balanced amounts
4. Verify function returns [1, {id}]
5. Check database for correct entry creation

Test Case 2: Account Tree Hierarchy

1. Create parent account (itemtype2 = 0)
2. Create child accounts under parent
3. Test name uniqueness within parent
4. Verify inheritance of parent properties
5. Test account deletion and restoration

Test Case 3: Reversal Functionality

1. Create normal journal entry
2. Record original entry ID
3. Reverse the entry using reverseEntryWithItsID()
4. Verify original marked as reversed (reverseofid = -10)
5. Verify new reversing entry created
6. Check account balances return to pre-entry state

Test Case 4: Cost Center Integration

1. Create entry with cost center assignments
2. Verify costcenterdetail records created
3. Check cost allocation amounts match entry amounts
4. Test cost center reporting accuracy

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When accounting logic changes occur