Accounts Module
This module forms the financial backbone of the ERP, handling double-entry bookkeeping, financial statements, and general ledger management.
Module Relationship Diagram
erDiagram
LEVEL_ONES ||--|{ LEVEL_TWOS : "parent of"
LEVEL_ONES ||--|{ LEVEL_THREES : "parent of"
LEVEL_ONES ||--|{ ACCOUNTS : "parent of"
LEVEL_TWOS ||--|{ LEVEL_THREES : "parent of"
LEVEL_TWOS ||--|{ ACCOUNTS : "parent of"
LEVEL_THREES ||--|{ ACCOUNTS : "parent of"
REGISTER_BANKS ||--|{ BANK_BRANCHES : "has"
REGISTER_BANKS ||--|{ BANK_ACCOUNTS : "has"
BANK_BRANCHES ||--|{ BANK_ACCOUNTS : "has"
ACCOUNTS ||--o{ BANK_ACCOUNTS : "linked to"
BANK_ACCOUNTS ||--o{ BANK_CHEQUES : "has"
FINANCIAL_YEARS ||--|{ FINANCIAL_PERIODS : "has"
FINANCIAL_YEARS ||--|{ BUDGETS : "has"
FINANCIAL_YEARS ||--o{ VOUCHERS : "period"
FINANCIAL_YEARS ||--o{ EXPENSES : "period"
FINANCIAL_YEARS ||--o{ FUNDS_TRANSFERS : "period"
FINANCIAL_YEARS ||--o{ OTHER_INCOMES : "period"
FINANCIAL_YEARS ||--o{ DEBIT_CREDIT_NOTES : "period"
FINANCIAL_YEARS ||--o{ OPENING_BALANCES : "period"
BUDGETS ||--|{ BUDGET_LINES : "details"
ACCOUNTS ||--o{ BUDGET_LINES : "budgeted for"
FINANCIAL_PERIODS ||--o{ BUDGET_LINES : "period"
VOUCHERS ||--|{ TRANSACTIONS : "details"
ACCOUNTS ||--o{ TRANSACTIONS : "affected by"
ACCOUNTS ||--o{ OPENING_BALANCES : "has"
ACCOUNTS ||--o{ DAILY_CLOSING_BALANCES : "has"
BRANCHES ||--o{ BUDGETS : "location"
BRANCHES ||--o{ VOUCHERS : "location"
BRANCHES ||--o{ EXPENSES : "location"
BRANCHES ||--o{ FUNDS_TRANSFERS : "from/to"
BRANCHES ||--o{ OTHER_INCOMES : "location"
BRANCHES ||--o{ DEBIT_CREDIT_NOTES : "location"
BRANCHES ||--o{ OPENING_BALANCES : "location"
BRANCHES ||--o{ DAILY_CLOSING_BALANCES : "location"
VOUCHERS ||--o{ EXPENSES : "references"
VOUCHERS ||--o{ FUNDS_TRANSFERS : "references"
VOUCHERS ||--o{ OTHER_INCOMES : "references"
VOUCHERS ||--o{ DEBIT_CREDIT_NOTES : "references"
LEVEL_ONES {
bigint id PK
string level_one_name
string level_one_code
boolean is_active
}
LEVEL_TWOS {
bigint id PK
bigint level_one_id FK
string level_two_name
string level_two_code
boolean is_active
}
LEVEL_THREES {
bigint id PK
bigint level_one_id FK
bigint level_two_id FK
string level_three_name
string level_three_code
boolean is_active
}
ACCOUNTS {
bigint id PK
bigint level_one_id FK
bigint level_two_id FK
bigint level_three_id FK
string account_name
string account_code
boolean is_active
}
REGISTER_BANKS {
bigint id PK
string bank_name
string bank_code
string bank_swift_code
text head_office_address
string contact_person
boolean is_active
}
BANK_BRANCHES {
bigint id PK
bigint bank_id FK
bigint region_id FK
string branch_name
string branch_code
string branch_address
string branch_contact_number
string manager_name
boolean is_active
}
BANK_ACCOUNTS {
bigint id PK
string account_number
string account_name
string account_type
bigint bank_id FK
bigint bank_branch_id FK
bigint account_id FK
boolean is_active
}
BANK_CHEQUES {
bigint id PK
bigint bank_account_id FK
string cheque_number
date issue_date
date pay_date
decimal amount
string payee_name
enum status
string reference_type
integer reference_id
text remarks
}
FINANCIAL_YEARS {
bigint id PK
string year_code
string financial_year
date start_date
date end_date
enum status
}
FINANCIAL_PERIODS {
bigint id PK
bigint financial_year_id FK
string period_code
enum period_type
date start_date
date end_date
enum status
}
BUDGETS {
bigint id PK
string budget_name
bigint financial_year_id FK
bigint branch_id FK
enum status
text remarks
}
BUDGET_LINES {
bigint id PK
bigint budget_id FK
bigint account_id FK
bigint financial_period_id FK
decimal budgeted_amount
decimal actual_amount
decimal remaining_amount
boolean overspend_allowed
}
VOUCHERS {
bigint id PK
bigint branch_id FK
bigint created_by FK
bigint financial_year_id FK
json financial_period_ids
enum voucher_type
string voucher_number
date voucher_date
text narration
enum reference_type
bigint reference_id
boolean posted
enum status
json debit
json credit
json cheque
}
TRANSACTIONS {
bigint id PK
bigint voucher_id FK
bigint account_id FK
decimal debit
decimal credit
text description
string reference_type
integer reference_id
}
EXPENSES {
bigint id PK
string expense_number
date expense_date
decimal amount
enum mode_of_payment
enum status
string remarks
bigint created_by FK
bigint branch_id FK
bigint financial_year_id FK
json financial_period_ids
json debit
json credit
json cheque
}
FUNDS_TRANSFERS {
bigint id PK
string transfer_number
date transfer_date
date received_date
decimal amount
enum mode_of_payment
enum status
json debit
json credit
json cheque
string remarks
bigint from_branch_id FK
bigint to_branch_id FK
bigint created_by FK
bigint branch_id FK
bigint financial_year_id FK
json financial_period_ids
}
OTHER_INCOMES {
bigint id PK
string income_number
date income_date
decimal amount
enum mode_of_payment
enum status
json debit
json credit
json cheque
string remarks
bigint created_by FK
bigint branch_id FK
bigint financial_year_id FK
json financial_period_ids
}
DEBIT_CREDIT_NOTES {
bigint id PK
string note_number
date note_date
decimal amount
enum note_classification
enum recipient_type
bigint recipient_id
enum type
text remarks
bigint created_by FK
bigint branch_id FK
bigint financial_year_id FK
json financial_period_ids
}
OPENING_BALANCES {
bigint id PK
bigint account_id FK
bigint financial_year_id FK
bigint branch_id FK
decimal opening_debit
decimal opening_credit
text narration
boolean is_migrated
}
DAILY_CLOSING_BALANCES {
bigint id PK
bigint account_id FK
bigint branch_id FK
date closing_date
decimal opening_balance
decimal total_debit
decimal total_credit
decimal closing_balance
}
Opening Balance Scenario
Step 1: Create Ledger Accounts
First, the foundational ledger accounts are defined. (Chart of Accounts hierarchy tables are omitted for brevity).
| ID | Account Code | Name |
|---|---|---|
| 1 | 101-001 | Cash in Hand |
| 2 | 102-001 | Trade Debtors |
| 3 | 201-001 | Trade Creditors |
| 4 | 301-001 | Retained Earnings |
| 5 | 401-001 | Product Sales |
Opening Balance Scenarios
Scenario 1: Initial Data Migration
During a one-time migration, the closing balances from a legacy system are entered into the `OPENING_BALANCES` table for the first financial year (e.g., FY2025). The `is_migrated` flag is set to true.
| ID | Account ID | FY ID | Debit | Credit | Narration | Is Migrated |
|---|---|---|---|---|---|---|
| 1 | 1 (Cash) | 2025 | 50,000.00 | 0.00 | Migrated from legacy system | true |
| 2 | 2 (A/R) | 2025 | 20,000.00 | 0.00 | Migrated from legacy system | true |
| 3 | 3 (A/P) | 2025 | 0.00 | 10,000.00 | Migrated from legacy system | true |
| 4 | 4 (Equity) | 2025 | 0.00 | 60,000.00 | Migrated from legacy system | true |
Scenario 2: Automated Year-End Closing
At the end of a financial year (e.g., FY2025), the system calculates the closing balance for each account. These closing balances are then automatically carried forward to populate the `OPENING_BALANCES` table for the next financial year (FY2026). The `is_migrated` flag is `false`.
Example: Closing Balances at end of FY2025
Assume after a year of transactions, the final balances are as follows:
- Cash: 75,000 Dr
- Trade Debtors: 30,000 Dr
- Trade Creditors: 15,000 Cr
- Retained Earnings: 60,000 Cr
- Current Year Profit: 30,000 Cr
Result: `OPENING_BALANCES` table for FY2026
The system generates these records for the new year. Note that the previous year's profit is rolled into Retained Earnings.
| ID | Account ID | FY ID | Debit | Credit | Narration | Is Migrated |
|---|---|---|---|---|---|---|
| 5 | 1 (Cash) | 2026 | 75,000.00 | 0.00 | Rollover from FY2025 | false |
| 6 | 2 (A/R) | 2026 | 30,000.00 | 0.00 | Rollover from FY2025 | false |
| 7 | 3 (A/P) | 2026 | 0.00 | 15,000.00 | Rollover from FY2025 | false |
| 8 | 4 (Equity) | 2026 | 0.00 | 90,000.00 | Rollover from FY2025 (60k + 30k profit) | false |
Step 3: Record Transactional Movement
As business occurs, new vouchers and transactions are created. These represent the *movement* within the period and are kept separate from the opening balances.
VOUCHERS (Example: A Sales Invoice)
| ID | Type | Number | Date | FY ID |
|---|---|---|---|---|
| 2 | Sales | SI-0001 | 2025-01-10 | 2025 |
TRANSACTIONS (For Voucher ID: 2)
| Acc. ID | Description | Debit | Credit |
|---|---|---|---|
| 2 (A/R) | Sale to Customer A | 5,000.00 | 0.00 |
| 5 (Sales) | Sale to Customer A | 0.00 | 5,000.00 |
Reports: Combining Opening Balance + Movement
Example Report 1: Trial Balance (as of 2025-01-31)
The Trial Balance calculates a closing balance by summing the opening balance with all transactional movements up to the report date. The formula is: `Closing = Opening + Movement`.
| Account | Opening | Movement | Closing |
|---|---|---|---|
| Cash in Hand | 50,000 Dr | 0 | 50,000 Dr |
| Trade Debtors | 20,000 Dr | 5,000 Dr | 25,000 Dr |
| Trade Creditors | 10,000 Cr | 0 | 10,000 Cr |
| Retained Earnings | 60,000 Cr | 0 | 60,000 Cr |
| Product Sales | 0 | 5,000 Cr | 5,000 Cr |
| Totals | 75,000 Dr = 75,000 Cr |
Example Report 2: Balance Sheet (as of 2025-01-31)
The Balance Sheet uses the final *closing* balances from the Trial Balance to present the company's financial position at a point in time.
| Assets | |
|---|---|
| Current Assets | |
| Cash in Hand | 50,000.00 |
| Trade Debtors | 25,000.00 |
| Total Current Assets | 75,000.00 |
| Total Assets | 75,000.00 |
| Liabilities & Equity | |
|---|---|
| Current Liabilities | |
| Trade Creditors | 10,000.00 |
| Total Current Liabilities | 10,000.00 |
| Equity | |
| Retained Earnings | 60,000.00 |
| Current Year Profit | 5,000.00 |
| Total Equity | 65,000.00 |
| Total Liabilities & Equity | 75,000.00 |
Module Flow Diagram
flowchart LR
%% ================= CORE =================
%% Centralized ledger that records every debit & credit
TRANSACTIONS[📊 Transactions Debit & Credit Entries ]:::txn
LEDGER_ACCOUNTS[📒 Ledger Accounts]:::account
LEDGER_ACCOUNTS --> |Account's Id in Transaction| TRANSACTIONS
%% ================= OPENING =================
%% Opening Balances entered at system start
subgraph OpeningFlow["🔑 Opening Balance"]
direction LR
Admin([System Setup]):::external --> |Voucher Type => Opening| OpeningVoucher[[Voucher]]:::voucher
OpeningVoucher --> OpeningTxn[(Opening Entry)]:::process
end
OpeningTxn --> TRANSACTIONS
%% ================= PAYMENT =================
subgraph PaymentFlow["💵 Payment Flow"]
direction LR
CashBank[Cash/Bank Account]:::account --> |Voucher Type => Payment| PaymentVoucher[[Voucher]]:::voucher
PaymentVoucher --> PaymentTxn[(Debit & Credit)]:::process
end
PaymentTxn --> TRANSACTIONS
%% ================= RECEIPT =================
subgraph ReceiptFlow["💰 Receipt Flow"]
direction LR
Customer([Customer]):::external --> |Voucher Type => Receipt| ReceiptVoucher[[Voucher]]:::voucher
ReceiptVoucher --> ReceiptTxn[(Debit & Credit)]:::process
end
ReceiptTxn --> TRANSACTIONS
%% ================= JOURNAL =================
subgraph JournalFlow["📑 Journal Entry"]
direction LR
Accountant([Accountant]):::external --> |Voucher Type => Journal| JournalVoucher[[Voucher]]:::voucher
JournalVoucher -->|Manual entry| JournalTxn[(Debit & Credit)]:::process
end
JournalTxn --> TRANSACTIONS
%% ================= CONTRA =================
subgraph ContraFlow["🔄 Contra Entry Pending"]
direction LR
CashBank1[Cash/Bank]:::account --> |Voucher Type => Contra| ContraVoucher[[Voucher]]:::voucher
ContraVoucher --> ContraTxn[(Cash ↔ Bank Transfer)]:::process
end
ContraTxn --> TRANSACTIONS
%% ================= TRANSFER =================
subgraph TransferFlow["🏦 Fund Transfer"]
direction LR
BranchFrom([Branch A]):::external --> |Voucher Type => Transfer| TransferVoucher[[Voucher]]:::voucher
TransferVoucher --> TransferTxn[(Debit & Credit)]:::process
end
TransferTxn --> TRANSACTIONS
%% ================= CHART OF ACCOUNTS =================
subgraph ChartOfAccounts["📘 Chart of Accounts"]
direction LR
ACCOUNT_CATEGORIES["Categories (Asset, Liability, Equity, Income, Expense)"]:::struct
ACCOUNT_GROUPS["Groups (Current Asset, Non-Current Asset)"]:::struct
ACCOUNT_TYPES["Types (Bank, AR, AP)"]:::struct
LEDGER_ACCOUNTS
end
ACCOUNT_CATEGORIES --> ACCOUNT_GROUPS --> ACCOUNT_TYPES --> LEDGER_ACCOUNTS
%% ================== STYLES (CORRECTED) ==================
classDef external fill:#d5b3ff,stroke:#333,stroke-width:1px,color:#000,font-weight:bold,font-size:14px
classDef struct fill:#a3c9f7,stroke:#333,stroke-width:1px,color:#000,font-weight:bold,font-size:14px
classDef account fill:#b7f7b3,stroke:#333,stroke-width:1px,color:#000,font-weight:bold,font-size:14px
classDef voucher fill:#ffcda3,stroke:#333,stroke-width:1px,color:#000,font-weight:bold,font-size:14px
classDef process fill:#a3c9f7,stroke:#333,stroke-width:1px,color:#000,font-weight:bold,font-size:14px
classDef txn fill:#f7b3b3,stroke:#333,stroke-width:1px,color:#000,font-weight:bold,font-size:14px
Entity Documentation
Account Categories
The five fundamental types of accounts (Assets, Liabilities, etc.).
Account Groups
Sub-classifications like 'Current Assets'.
Account Types
Specific types like 'Bank Accounts'.
Ledger Accounts
The individual accounts for posting.
Voucher
Documents that record a financial transaction, such as payments, receipts, or journal entries.
Transactions
Individual debit or credit entries posted to ledger accounts as part of vouchers.
Transfers
Records of funds moved between two ledger accounts, such as internal bank transfers.
Journal Entries
Manual entries for adjustments, corrections, or non-standard transactions in the ledger.