Dailyentrymany Documentation

Daily Entry Many Controller Documentation

File: /controllers/dailyentrymany.php

Purpose: Bulk daily journal entry creation and management with advanced filtering and display capabilities

Last Updated: December 20, 2024

Total Functions: 8+

Lines of Code: ~756

---

๐Ÿ“‹ Overview

The Daily Entry Many Controller provides comprehensive functionality for managing multiple daily journal entries with advanced filtering, grouping, and display capabilities. It serves as the primary interface for:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**dailyentry**Journal entry headersid, totalcreditor, totaldebtor, thedate, related, branchid, entryComment
**dailyentrycreditor**Credit side entriesid, dailyentryid, accountstreeid, value, dComment
**dailyentrydebtor**Debit side entriesid, dailyentryid, accountstreeid, value, dComment
**accountstree**Chart of accountsid, name, customName, parent
**branch**Business branchesbranchId, branchName
### Relationship Tables

Table NamePurposeKey Columns
**costcenter**Cost centers for allocationid, name, description
**user**System usersuserid, username
**youtubelink**Tutorial videosyoutubelinkid, title, url
**programsettings**System configurationprogramsettingsid, settingkey, settingvalue
---

๐Ÿ”‘ Key Functions

1. Default Action - Entry Display & Filtering

Location: Line 190

Purpose: Main entry point for displaying filtered daily entries with grouping

Process Flow:

1. Load user data and branch information

2. Load cost centers and tutorial links

3. Parse filter parameters (dates, branch, entry ID)

4. Set default date range if no filters provided

5. Call DrawTableNew() to generate entry display

6. Display via dailyentrymanyview/add.html template

Filter Parameters:

---

2. DrawTableNew() - Advanced Entry Retrieval

Location: Line 276

Purpose: Build complex query and retrieve grouped daily entries with account details

Function Signature:

function DrawTableNew($dailyentryid, $startDate, $endDate, $layingOrder, $branchid, $print = 0)

Process Flow:

1. Build Dynamic Query:

   $queryString = '';
   if (!empty($startDate)) {
       $queryString .= ' and dailyentry.thedate >= "' . $startDate . '" ';
   }
   if (!empty($endDate)) {
       $queryString .= ' and dailyentry.thedate <= "' . $endDate . '" ';
   }
   if ($branchid > 0) {
       $queryString .= ' and dailyentry.branchid = "' . $branchid . '" ';
   }
   ```

2. **Retrieve Entry Headers**:
   ```php
   $dailyEntryData = R::getAll('SELECT dailyentry.* ' . $branch_name . '
               FROM dailyentry ' . $jon_branch . '
               where 1 ' . $queryString . ' 
               order by dailyentry.related desc,dailyentry.id desc');
   ```

3. **Load Credit Entries with Account Names**:
   ```php
   $allDailyEnteryCreditor = R::getAll('SELECT 
       dailyentrycreditor.id as idChild,
       dailyentrycreditor.dailyentryid,
       dailyentrycreditor.accountstreeid,
       dailyentrycreditor.value,
       dailyentrycreditor.dComment as dComment,
       1 as type,
       concat(dailyentrycreditor.accountstreeid,"-",parent.customName,"/",accountstree.customName) as accountstreeName
       FROM dailyentrycreditor
       join accountstree on accountstree.id = dailyentrycreditor.accountstreeid
       join accountstree parent on parent.id = accountstree.parent
       where dailyentrycreditor.dailyentryid in(' . implode(',', $dailyEntryIdsArr) . ')');
   ```

4. **Group by Related Entries**:
   - Sort entries by `related` field
   - Group related transactions together
   - Assign to template variables for display

**Template Variables**:
- `$allDailyEntery{N}` - Entry group N data
- `$relatedArr` - Array of related group IDs
- `$allDailyEntery` - Complete entry dataset
- `$allDailyEnteryCount` - Total entry count

---

### 3. **reverse()** - Entry Reversal Operation
**Location**: Line 554  
**Purpose**: Reverse a specific journal entry and update related accounts

**Function Signature**:
php

function reverse()

**Process Flow**:
1. Get entry ID from GET parameter
2. Load original entry and validate not already reversed
3. Mark original as reversed (`reverseofid = -10`)
4. Load all debit and credit details
5. Create new entry with reversed amounts:
   - Original debits โ†’ new credits
   - Original credits โ†’ new debits
6. Update account balances via `affectAccount()`
7. Execute plugin effects if applicable

**Reversal Rules**:
php

// Original Entry Structure:

// Debit: Office Supplies $500

// Credit: Cash $500

// Reversing Entry Created:

// Debit: Cash $500

// Credit: Office Supplies $500

---

### 4. **affectAccount()** - Account Balance Updates
**Location**: Line 630  
**Purpose**: Update account balances based on transaction type and account nature

**Function Signature**:
php

function affectAccount($CreditorOrDebtorObj, $type)

**Account Effect Logic**:
php

$operation = whatToDo($accountsTree->itemtype, 'positive', $type);

if ($operation == 'increase') {

$accountsTree->theValue += $CreditorOrDebtorObj->value;

}

if ($operation == 'decrease') {

$accountsTree->theValue -= $CreditorOrDebtorObj->value;

}

**Account Type Logic (whatToDo)**:
- **Assets/Expenses/Drawings**: Debit increases, Credit decreases
- **Liabilities/Income/Equity**: Credit increases, Debit decreases

---

### 5. **sortByRelated()** - Entry Sorting
**Location**: Line 717  
**Purpose**: Sort entries by related field for proper grouping display

**Function Signature**:
php

function sortByRelated($type) // $type = 'asc' or 'desc'

**Sorting Logic**:
- Bubble sort implementation on global `$allDailyEntery` array
- Sorts by `related` field to group related transactions
- Used for display organization

---

## ๐Ÿ”„ Workflows

### Workflow 1: Daily Entry Display with Filtering

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

โ”‚ START: Access Daily Entry Manager โ”‚

โ”‚ URL: dailyentrymany.php?filters โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 1. Initialize Controller โ”‚

โ”‚ - Load user permissions and branch data โ”‚

โ”‚ - Load cost centers for allocation โ”‚

โ”‚ - Load YouTube tutorial links โ”‚

โ”‚ - Load system settings โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 2. Parse Filter Parameters โ”‚

โ”‚ - dailyentryid = related group filter โ”‚

โ”‚ - datefrom / dateto = date range โ”‚

โ”‚ - branchid = branch filter โ”‚

โ”‚ - layingOrder = account ordering (unused) โ”‚

โ”‚ โ”‚

โ”‚ DEFAULT: If no dates provided: โ”‚

โ”‚ - datefrom = today โ”‚

โ”‚ - dateto = today โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 3. Build Dynamic Query (DrawTableNew) โ”‚

โ”‚ - Start with base dailyentry query โ”‚

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

โ”‚ - Add branch filter if specified โ”‚

โ”‚ - Add related entry filter if specified โ”‚

โ”‚ - Join branch table for branch names โ”‚

โ”‚ - Order by related desc, id desc โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 4. Retrieve Entry Data โ”‚

โ”‚ A. Get Entry Headers: โ”‚

โ”‚ - All matching daily entries โ”‚

โ”‚ - Include branch name if date filter used โ”‚

โ”‚ โ”‚

โ”‚ B. Get Credit Details: โ”‚

โ”‚ - All credit entries for matched entries โ”‚

โ”‚ - Join with accountstree for account names โ”‚

โ”‚ - Build hierarchical account names (parent/child) โ”‚

โ”‚ โ”‚

โ”‚ C. Get Debit Details: โ”‚

โ”‚ - All debit entries for matched entries โ”‚

โ”‚ - Join with accountstree for account names โ”‚

โ”‚ - Build hierarchical account names โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 5. Process and Group Data โ”‚

โ”‚ A. Merge Entry Headers with Details: โ”‚

โ”‚ - Combine header data with credit/debit lines โ”‚

โ”‚ - Create unified entry objects โ”‚

โ”‚ โ”‚

โ”‚ B. Group by Related Field: โ”‚

โ”‚ - Sort entries by related field โ”‚

โ”‚ - Group related transactions together โ”‚

โ”‚ - Assign to template variables by group โ”‚

โ”‚ โ”‚

โ”‚ C. Format for Display: โ”‚

โ”‚ - Format dates for print mode if requested โ”‚

โ”‚ - Hide duplicate entry IDs in same group โ”‚

โ”‚ - Organize debits first, then credits per entry โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 6. Assign to Template & Display โ”‚

โ”‚ - $allDailyEntery{N} for each related group โ”‚

โ”‚ - $relatedArr = array of group IDs โ”‚

โ”‚ - $allDailyEntery = complete dataset โ”‚

โ”‚ - Display via add.html or print.html template โ”‚

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

---

### Workflow 2: Entry Reversal Process

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

โ”‚ START: Reverse Entry Request โ”‚

โ”‚ URL: dailyentrymany.php?do=reverse&id={entryId} โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 1. Begin Transaction โ”‚

โ”‚ - Start database transaction for safety โ”‚

โ”‚ - Get entry ID from GET parameter โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 2. Load & Validate Original Entry โ”‚

โ”‚ - Load dailyentry record by ID โ”‚

โ”‚ - Check reverseofid โ‰  -10 (not already reversed) โ”‚

โ”‚ - Get all related debit/credit details โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 3. Mark Original as Reversed โ”‚

โ”‚ - Set original.reverseofid = -10 โ”‚

โ”‚ - Update original entry record โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 4. Create Reversing Entry Header โ”‚

โ”‚ - totalcreditor = original.totaldebtor (swapped) โ”‚

โ”‚ - totaldebtor = original.totalcreditor (swapped) โ”‚

โ”‚ - thedate = today โ”‚

โ”‚ - userid = current user โ”‚

โ”‚ - reverseofid = original.id โ”‚

โ”‚ - entryComment = "ุชู… ุนูƒุณ ุงู„ู‚ูŠุฏ ุฑู‚ู… {original.id}" โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 5. Create Reversed Detail Lines โ”‚

โ”‚ A. Convert Original Debits to Credits: โ”‚

โ”‚ FOR EACH original debit entry: โ”‚

โ”‚ - Create new credit entry โ”‚

โ”‚ - Same account, same amount โ”‚

โ”‚ - Update account balance (credit effect) โ”‚

โ”‚ - Execute plugin effects if applicable โ”‚

โ”‚ โ”‚

โ”‚ B. Convert Original Credits to Debits: โ”‚

โ”‚ FOR EACH original credit entry: โ”‚

โ”‚ - Create new debit entry โ”‚

โ”‚ - Same account, same amount โ”‚

โ”‚ - Update account balance (debit effect) โ”‚

โ”‚ - Execute plugin effects if applicable โ”‚

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

โ”‚

โ–ผ

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

โ”‚ 6. Finalize Transaction โ”‚

โ”‚ - Commit transaction if all successful โ”‚

โ”‚ - Redirect to main view โ”‚

โ”‚ โ”‚

โ”‚ ERROR HANDLING: โ”‚

โ”‚ - Rollback transaction on any failure โ”‚

โ”‚ - Redirect to error page โ”‚

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

---

## ๐ŸŒ URL Routes & Actions

| URL Parameter | Function Called | Description |
|---------------|----------------|-------------|
| `(empty)` | Default action | Display filtered daily entries |
| `do=reverse&id={id}` | `reverse()` | Reverse specific journal entry |
| `do=print` | Default + print mode | Print-friendly entry display |
| `do=sucess` | Template display | Success confirmation page |
| `do=error` | Template display | Error message page |

### URL Parameters
**Main Display**:
- `dailyentryid` - Filter by related entry group
- `datefrom` - Start date filter (YYYY-MM-DD)
- `dateto` - End date filter (YYYY-MM-DD)  
- `branchid` - Branch ID filter
- `layingOrder` - Account ordering (future use)

**Reversal Operation**:
- `do=reverse` - Action to reverse entry
- `id` - Daily entry ID to reverse

**Print Mode**:
- `do=print` - Enable print formatting
- Same filter parameters as main display

---

## ๐Ÿงฎ Data Processing & Calculations

### Entry Grouping Logic
php

// Group entries by 'related' field

foreach ($allDailyEntery as $value) {

if ($related != $value->related) {

// Start new group

$smarty->assign("allDailyEntery" . $related, $allDailyEnteryRelated);

$allDailyEnteryRelated = array();

$related = $value->related;

array_push($relatedArr, $related);

}

array_push($allDailyEnteryRelated, $value);

}

### Account Name Building
php

// Create hierarchical account names: "Parent / Child"

concat(accountid, "-", parent.customName, "/", accountstree.customName) as accountstreeName

### Print Mode Formatting
php

if ($print == 1) {

$dataCreditor->dDateTime = date("Y-m-d", strtotime($dataCreditor->dDateTime));

}

### Entry ID Display Logic
php

if ($dataCreditor->id == $prviosId) {

$dataCreditor->id = ''; // Hide duplicate IDs in same group

} else {

$prviosId = $dataCreditor->id;

}

---

## ๐Ÿ”’ Security & Permissions

### Access Control
- Requires active user session (`$_SESSION['userid']`)
- Branch-level access control via `$_SESSION['branchId']`
- User permission checks for view access

### Data Validation
- Date format validation for filtering
- Numeric validation for entry IDs
- SQL injection prevention via parameterized queries

### Transaction Safety
- Database transactions wrap reversal operations
- Automatic rollback on any operation failure
- Audit trail maintained via entry comments

---

## ๐Ÿ“Š Performance Considerations

### Database Optimization
1. **Critical Indexes**:
   - `dailyentry(thedate, branchid, related)`
   - `dailyentrycreditor(dailyentryid)`
   - `dailyentrydebtor(dailyentryid)`
   - `accountstree(id, parent)`

2. **Query Performance**:
   - Uses IN clauses for bulk detail loading
   - Efficient JOINs for account name resolution
   - Date range filtering at database level

3. **Memory Management**:
   - Large date ranges can return thousands of entries
   - Consider pagination for very active periods
   - Template variable cleanup between groups

### Known Performance Issues
sql

-- This can be slow with large datasets

SELECT dailyentry.* FROM dailyentry

WHERE thedate >= '2023-01-01' AND thedate <= '2023-12-31'

ORDER BY related DESC, id DESC;

-- Solution: Add composite index

CREATE INDEX idx_entry_date_related ON dailyentry(thedate, related, id);

---

## ๐Ÿ› Common Issues & Troubleshooting

### 1. **No Entries Displayed**
**Issue**: Filter returns empty results  
**Cause**: Date range too narrow or incorrect branch selection

**Debug**:
php

// Check generated query

echo "Query String: " . $queryString;

// Verify filter parameters

var_dump($datefrom, $dateto, $branchid);

### 2. **Reversal Fails**
**Issue**: Entry reversal throws transaction error  
**Cause**: Entry already reversed or account balance issues

**Debug**:
php

$entry = $dailyEntryDAO->load($id);

if ($entry->reverseofid == -10) {

echo "Entry already reversed";

}

### 3. **Missing Account Names**
**Issue**: Account names show as numbers instead of names  
**Cause**: Account tree relationship broken or missing accounts

**Debug**:
sql

-- Check for orphaned accounts

SELECT * FROM dailyentrycreditor dc

LEFT JOIN accountstree a ON dc.accountstreeid = a.id

WHERE a.id IS NULL;

### 4. **Incorrect Entry Grouping**
**Issue**: Related entries not grouped properly  
**Cause**: Missing or incorrect 'related' field values

**Debug**:
sql

-- Check related field consistency

SELECT related, COUNT(*) FROM dailyentry

WHERE thedate BETWEEN ? AND ?

GROUP BY related ORDER BY related;

---

## ๐Ÿงช Testing Scenarios

### Test Case 1: Basic Entry Display

1. Access dailyentrymany.php with no parameters

2. Verify default date range (today)

3. Check entry display with proper grouping

4. Verify account name resolution

5. Test print mode formatting

### Test Case 2: Date Range Filtering

1. Set specific date range (e.g., last month)

2. Verify only entries in range displayed

3. Test edge cases (same start/end date)

4. Check performance with large date ranges

5. Verify branch filtering works correctly

### Test Case 3: Entry Reversal

1. Create test journal entry

2. Note original account balances

3. Reverse the entry via web interface

4. Verify original marked as reversed

5. Check new reversing entry created

6. Confirm account balances restored

7. Attempt to reverse already-reversed entry (should fail)

### Test Case 4: Complex Entry Grouping

1. Create multiple related entries (same 'related' value)

2. Verify they display as single group

3. Test sorting within groups

4. Check template variable assignment

5. Verify print formatting maintains grouping

```

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When bulk entry features change