> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Finance & Accounting Entity Relationship Diagram

> > Version: 1.0.0 > Last Updated: 2026-01-11 > Module: Finance & Accounting > Prefix: fa_ > Tables: 45

> **Version:** 1.0.0\
> **Last Updated:** 2026-01-11\
> **Module:** Finance & Accounting\
> **Prefix:** `fa_`\
> **Tables:** 45

## Changelog

* **1.0.0** (2026-01-11): Initial ERD documentation

## Overview

The Finance & Accounting module provides nonprofit fund accounting capabilities including general ledger, accounts receivable, accounts payable, budgeting, and financial reporting.

## Chart of Accounts ERD

```mermaid theme={null}
erDiagram
    fa_accounts ||--o{ fa_accounts : "parent-child"
    fa_accounts ||--o{ fa_journal_entry_lines : "posted to"
    fa_accounts }o--|| fa_account_types : "has type"
    fa_accounts }o--|| fa_funds : "default fund"
    
    fa_account_types ||--o{ fa_accounts : categorizes
    
    fa_accounts {
        uuid id PK
        uuid organization_id FK
        string account_number
        string name
        enum account_type
        enum account_subtype
        string normal_balance
        uuid parent_account_id FK
        boolean is_control_account
        decimal current_balance
        jsonb custom_fields
    }
    
    fa_account_types {
        uuid id PK
        uuid organization_id FK
        string name
        enum account_type
        enum account_subtype
        string normal_balance
        integer display_order
    }
    
    fa_funds {
        uuid id PK
        uuid organization_id FK
        string fund_number
        string name
        enum fund_type
        string donor_restriction
        decimal balance
        boolean is_active
    }
```

## Journal Entries ERD

```mermaid theme={null}
erDiagram
    fa_journal_entries ||--o{ fa_journal_entry_lines : contains
    fa_journal_entries }o--|| fa_fiscal_periods : "posted in"
    fa_journal_entry_lines }o--|| fa_accounts : "debits/credits"
    fa_journal_entry_lines }o--|| fa_funds : "allocated to"
    fa_journal_entry_lines }o--|| fa_programs : "program expense"
    
    fa_journal_entries {
        uuid id PK
        uuid organization_id FK
        string entry_number
        date transaction_date
        date posting_date
        string description
        enum status
        enum source_type
        uuid source_id FK
        uuid period_id FK
        timestamp posted_at
        uuid posted_by FK
    }
    
    fa_journal_entry_lines {
        uuid id PK
        uuid journal_entry_id FK
        uuid account_id FK
        uuid fund_id FK
        uuid department_id FK
        uuid program_id FK
        integer line_number
        decimal debit_amount
        decimal credit_amount
        string description
    }
    
    fa_fiscal_periods {
        uuid id PK
        uuid organization_id FK
        uuid fiscal_year_id FK
        integer period_number
        string period_name
        date start_date
        date end_date
        enum status
    }
    
    fa_fiscal_years {
        uuid id PK
        uuid organization_id FK
        string year_code
        date start_date
        date end_date
        boolean is_current
    }
```

## Accounts Receivable ERD

```mermaid theme={null}
erDiagram
    fa_customers ||--o{ fa_invoices : receives
    fa_customers ||--o{ fa_customer_payments : makes
    fa_invoices ||--o{ fa_invoice_lines : contains
    fa_invoices ||--o{ fa_ar_payment_applications : "applied to"
    fa_customer_payments ||--o{ fa_ar_payment_applications : applies
    fa_customers ||--o{ fa_credit_memos : issued
    
    fa_customers {
        uuid id PK
        uuid organization_id FK
        string customer_number
        string customer_name
        enum customer_type
        string contact_email
        string billing_address_line1
        integer payment_terms_days
        jsonb custom_fields
    }
    
    fa_invoices {
        uuid id PK
        uuid organization_id FK
        uuid customer_id FK
        string invoice_number
        date invoice_date
        date due_date
        decimal subtotal
        decimal tax_amount
        decimal total_amount
        decimal balance_due
        enum status
    }
    
    fa_invoice_lines {
        uuid id PK
        uuid invoice_id FK
        uuid account_id FK
        integer line_number
        string description
        decimal quantity
        decimal unit_price
        decimal line_amount
    }
    
    fa_customer_payments {
        uuid id PK
        uuid organization_id FK
        uuid customer_id FK
        string payment_number
        date payment_date
        decimal payment_amount
        string payment_method
        decimal applied_amount
        enum status
    }
```

## Accounts Payable ERD

```mermaid theme={null}
erDiagram
    fa_vendors ||--o{ fa_bills : receives
    fa_vendors ||--o{ fa_vendor_payments : "paid by"
    fa_bills ||--o{ fa_bill_lines : contains
    fa_bills ||--o{ fa_ap_payment_applications : "paid by"
    fa_vendor_payments ||--o{ fa_ap_payment_applications : applies
    
    fa_vendors {
        uuid id PK
        uuid organization_id FK
        string vendor_number
        string vendor_name
        string tax_id
        string contact_email
        integer payment_terms_days
        uuid default_expense_account_id FK
        jsonb custom_fields
    }
    
    fa_bills {
        uuid id PK
        uuid organization_id FK
        uuid vendor_id FK
        string bill_number
        string vendor_invoice_number
        date bill_date
        date due_date
        decimal total_amount
        decimal amount_paid
        enum status
    }
    
    fa_bill_lines {
        uuid id PK
        uuid bill_id FK
        uuid account_id FK
        uuid fund_id FK
        integer line_number
        string description
        decimal quantity
        decimal unit_price
        decimal line_amount
    }
    
    fa_vendor_payments {
        uuid id PK
        uuid organization_id FK
        uuid bank_account_id FK
        string payment_number
        date payment_date
        decimal payment_amount
        string payment_method
        string check_number
        enum status
    }
```

## Budgeting ERD

```mermaid theme={null}
erDiagram
    fa_budgets ||--o{ fa_budget_lines : contains
    fa_budgets }o--|| fa_fiscal_years : "for year"
    fa_budget_lines }o--|| fa_accounts : "budgets account"
    fa_budget_lines }o--|| fa_funds : "by fund"
    fa_budgets ||--o{ fa_budget_approvals : "approval history"
    fa_budgets ||--o{ fa_budget_alerts : generates
    
    fa_budgets {
        uuid id PK
        uuid organization_id FK
        uuid fiscal_year_id FK
        string version_name
        enum version_type
        enum status
        boolean is_active
        boolean is_locked
        uuid approved_by FK
        timestamp approved_at
    }
    
    fa_budget_lines {
        uuid id PK
        uuid budget_id FK
        uuid account_id FK
        uuid fund_id FK
        uuid department_id FK
        uuid program_id FK
        date period_start
        date period_end
        decimal budget_amount
        text notes
    }
    
    fa_budget_alerts {
        uuid id PK
        uuid organization_id FK
        uuid budget_id FK
        uuid account_id FK
        decimal budget_amount
        decimal actual_amount
        decimal variance_amount
        decimal variance_percent
        enum alert_status
    }
```

## Banking ERD

```mermaid theme={null}
erDiagram
    fa_bank_accounts ||--o{ fa_bank_statements : receives
    fa_bank_accounts ||--o{ fa_bank_reconciliations : reconciled
    fa_bank_statements ||--o{ fa_bank_statement_lines : contains
    fa_bank_accounts }o--|| fa_accounts : "GL account"
    
    fa_bank_accounts {
        uuid id PK
        uuid organization_id FK
        uuid gl_account_id FK
        string bank_name
        string account_name
        string account_number
        string routing_number
        string account_type
        boolean is_active
    }
    
    fa_bank_statements {
        uuid id PK
        uuid organization_id FK
        uuid bank_account_id FK
        date statement_date
        date period_start_date
        date period_end_date
        decimal beginning_balance
        decimal ending_balance
        decimal total_debits
        decimal total_credits
    }
    
    fa_bank_reconciliations {
        uuid id PK
        uuid organization_id FK
        uuid bank_account_id FK
        uuid statement_id FK
        date reconciliation_date
        decimal bank_ending_balance
        decimal gl_ending_balance
        decimal cleared_balance
        decimal difference
        enum status
    }
```

## RLS Policy Coverage

| Table                     | SELECT | INSERT | UPDATE | DELETE | WITH CHECK | Status   |
| ------------------------- | ------ | ------ | ------ | ------ | ---------- | -------- |
| fa\_accounts              | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |
| fa\_funds                 | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |
| fa\_journal\_entries      | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |
| fa\_journal\_entry\_lines | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |
| fa\_invoices              | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |
| fa\_customers             | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |
| fa\_bills                 | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |
| fa\_vendors               | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |
| fa\_budgets               | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |
| fa\_bank\_accounts        | ✅      | ✅      | ✅      | ✅      | ✅          | Complete |

## Key Tables

### fa\_accounts

Chart of accounts with hierarchical structure and fund accounting support.

### fa\_journal\_entries

Double-entry journal entries with multi-dimensional posting (fund, department, program).

### fa\_invoices

Customer invoices for accounts receivable management.

### fa\_bills

Vendor bills for accounts payable management.

### fa\_budgets

Annual/project budgets with version control and approval workflow.

## Helper Functions

| Function                                         | Purpose                        |
| ------------------------------------------------ | ------------------------------ |
| `fa_has_org_access(org_id, user_id)`             | Check FA module access         |
| `fa_get_account_balance(account_id, as_of_date)` | Calculate account balance      |
| `fa_get_budget_variance(budget_id, period_id)`   | Calculate budget vs actual     |
| `fa_post_journal_entry(entry_id)`                | Post entry and update balances |

## Cross-Module Dependencies

* **PF:** Organizations, profiles, departments
* **HR:** Payroll journal entries, expense reports
* **RH:** Resident billing, charge posting
* **FM:** Asset depreciation, maintenance costs
