Dailyentry Documentation
Daily Entry (Journal Entry) Controller Documentation
File: /controllers/dailyentry.php
Purpose: Manages journal entries for double-entry bookkeeping system
Last Updated: December 19, 2024
Total Functions: 8
Lines of Code: 755
---
๐ Overview
The Daily Entry Controller is the core component for managing journal entries in the double-entry bookkeeping system. It handles:
- โข Manual journal entry creation and management
- โข Automated journal entries from sales/purchase transactions
- โข Entry reversal and correction functionality
- โข Opening balance entries
- โข Multi-branch journal entry support
- โข Account balance calculations and updates
- โข Cost center allocation
- โข Debit/credit balance validation
- โข Entry search and filtering
- โข Journal entry reporting and printing
Primary Functions
- โ Create manual journal entries (debit/credit)
- โ Display journal entry listing with filters
- โ Reverse journal entries with automatic posting
- โ Opening balance entry management
- โ Multi-branch support
- โ Cost center integration
- โ Account balance updates
- โ Entry printing and reporting
- โ Date range filtering
- โ Account-specific filtering
Related Controllers
- โข accountstree.php - Chart of accounts structure
- โข sellbillController.php - Auto journal entries from sales
- โข buyBillController.php - Auto journal entries from purchases
- โข expensesController.php - Expense journal entries
- โข saveController.php - Cash transaction entries
- โข bankController.php - Bank transaction entries
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **dailyentry** | Main journal entries | id, thedate, totalcreditor, totaldebtor, entryComment, userid, branchid, related, reverseofid | |
| **dailyentrycreditor** | Credit side entries | dailyentryid, accountstreeid, value, dComment, costcenterid | |
| **dailyentrydebtor** | Debit side entries | dailyentryid, accountstreeid, value, dComment, costcenterid |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **accountstree** | Chart of accounts | Referenced by creditor/debtor entries | |
| **costcenter** | Cost centers | Referenced by creditor/debtor entries | |
| **branch** | Branch management | Multi-branch support | |
| **programsetting** | System configuration | Entry behavior settings |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **savedaily** | Cash movements | Auto-posted from cash entries | |
| **accountmovement** | Account movements | Auto-posted from bank entries | |
| **sellbill** | Sales transactions | Generate automatic entries | |
| **buybill** | Purchase transactions | Generate automatic entries |
๐ง Key Functions
1. Main Display (Default Action)
Purpose: Display journal entry interface with entry listing
Line: 214
Parameters (via $_POST):
- โข
dailyentryid- Specific entry ID(s) to display - โข
datefrom- Start date filter - โข
dateto- End date filter - โข
layingOrder- Account filter - โข
branchid- Branch filter
Process Flow:
Business Logic:
- โข Updates branch IDs for entries without branches
- โข Loads cost centers for allocation
- โข Applies date filters (defaults to today)
- โข Generates comprehensive entry listing
2. DrawTableNew($dailyentryid, $startDate, $endDate, $layingOrder, $branchid, $print)
Purpose: Generate journal entry listing table with advanced formatting
Line: 341
Parameters:
- โข
$dailyentryid(string) - Comma-separated entry IDs - โข
$startDate(date) - Filter start date - โข
$endDate(date) - Filter end date - โข
$layingOrder(string) - Account code filter - โข
$branchid(int) - Branch ID filter - โข
$print(int) - Print mode flag (0=screen, 1=print)
Process Flow:
Advanced Features:
- โข Optimized SQL queries with proper joins
- โข Memory-efficient array indexing
- โข Print-friendly date formatting
- โข Integrated debit/credit display
3. reverse()
Purpose: Reverse a journal entry by creating opposite entry
Line: 591
URL: ?do=reverse&id={entry_id}
Process Flow:
Critical Business Rules:
- โข Can only reverse entries once (reverseofid != -10)
- โข Creates new entry with swapped debit/credit sides
- โข Updates account balances automatically
- โข Applies plugin effects for cash/bank accounts
- โข Links reversal to original entry
4. affectAccount($CreditorOrDebtorObj, $type)
Purpose: Update account balances based on journal entry
Line: 668
Parameters:
- โข
$CreditorOrDebtorObj- Credit or debit entry object - โข
$type- Entry type (0=debit, 1=credit)
Double-Entry Logic:
5. whatToDo($accountType, $numSign, $type)
Purpose: Determine if account balance should increase or decrease
Line: 691
Parameters:
- โข
$accountType(int) - Account classification (0-5) - โข
$numSign(string) - Always 'positive' - โข
$type(int) - Entry type (0=debit, 1=credit)
Returns: 'increase' or 'decrease'
6. openingentry
Purpose: Display opening balance entry form
Line: 286
Process:
- โข Loads all leaf accounts (final level accounts)
- โข Applies visibility filters for clients/suppliers
- โข Displays opening balance entry interface
7. openingbalance
Purpose: Display opening balance management interface
Line: 307
Process:
- โข Similar to opening entry but for balance management
- โข Supports bulk opening balance entry
8. print
Purpose: Generate printable journal entry report
Line: 264
Process:
- โข Uses same filtering as main display
- โข Formats for print layout
- โข Generates printer-friendly output
---
๐ Business Logic Flow
Journal Entry Creation Workflow
Entry Reversal Workflow
Double-Entry Bookkeeping Rules
Fundamental Equation: Assets = Liabilities + Equity
Entry Rules:
1. Every entry must balance (Total Debits = Total Credits)
2. Account nature determines effect:
- Debit increases: Assets, Expenses, Cost of Sales
- Credit increases: Liabilities, Equity, Revenue
3. Journal entries auto-update account balances
4. Reversals create exact opposite entries
---
โ ๏ธ Common Issues
1. Unbalanced Entries
Issue: Total debits โ total credits
Prevention: Client-side validation before submission
Fix: System should reject unbalanced entries
2. Branch Assignment
Issue: Entries created without branch assignment
Solution: System auto-updates entries with user's branch ID:
// Auto-update branch IDs for entries without branches
$allnothavebranch = $dailyEntryEX->queryAllnothavebranch();
foreach ($allnothavebranch as $entry) {
$dailyEntryEX->updatebranchid($entry->value, $entry->id);
}
3. Account Balance Corruption
Issue: Manual balance changes cause inconsistency
Prevention: Only update balances through journal entries
Fix: Rebuild balances from journal entry history
4. Reversal Chain Issues
Issue: Attempting to reverse already reversed entries
Prevention: Check reverseofid status before reversal:
if ($olddailyEntry->reverseofid != -10) {
// Proceed with reversal
}
5. Cost Center Allocation
Issue: Missing cost center assignments
Solution: Validate cost center requirements for expense accounts
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core operations - โข
../public/authentication.php- Security - โข
affectplugins.php- Plugin system integration - โข
dailyentryfun.php- Daily entry utilities - โข
../models/sql/Transaction.class.php- Database transactions
Critical DAOs
- โข
DailyentryDAO- Main entry operations - โข
DailyentrycreditorDAO- Credit side management - โข
DailyentrydebtorDAO- Debit side management - โข
AccountstreeDAO- Account balance updates - โข
CostcenterDAO- Cost center operations
Plugin Integration
The system includes affectplugins.php which handles:
- โข Cash register updates for cash accounts
- โข Bank account balance synchronization
- โข Supplier/client balance updates
- โข Inventory valuation adjustments
---
๐ฏ Entry Types and Status Codes
Entry Status (condition)
- โข 0: Active entry
- โข 1: Draft entry (not posted)
Reverse Status (reverseofid)
- โข 0: Normal entry (not reversed/reversal)
- โข Positive number: Entry ID this is a reversal of
- โข -10: Entry has been reversed (cannot be reversed again)
Entry Source (fromFlag)
- โข 0: Manual journal entry
- โข 1: Auto-generated from sales
- โข 2: Auto-generated from purchases
- โข 3: Auto-generated from expenses
- โข 4: Auto-generated from cash transactions
- โข 5: Auto-generated from bank transactions
Related Entry Grouping (related)
- โข Groups related entries together (e.g., multiple entries from one transaction)
---
๐ฒ Best Practices
1. Entry Creation
- โข Always validate debit/credit balance before saving
- โข Include meaningful entry comments
- โข Assign appropriate cost centers for tracking
- โข Use consistent date formatting
2. Account Selection
- โข Use leaf accounts only (not parent accounts)
- โข Verify account nature matches entry intention
- โข Check account permissions for user access
3. Reversal Management
- โข Add clear reversal reasons in comments
- โข Check reversal permissions before allowing
- โข Maintain audit trail of all reversals
4. Multi-Branch Support
- โข Ensure proper branch assignment
- โข Filter entries by user branch permissions
- โข Maintain branch-specific reporting
---
Critical Note: This controller is the heart of the accounting system. All financial transactions flow through journal entries. Any modifications should preserve the double-entry bookkeeping integrity and maintain proper audit trails.