Skip to main content
Version: 1.0.0
Last Updated: 2025-11-26
Related Documentation: FA-01 through FA-09 specifications

Overview

This document provides a comprehensive reference for all frontend hooks, components, and utilities in the Finance & Accounting (FA) module. All FA APIs follow Constitutional guidelines for import paths, RLS enforcement, and integration patterns.

Table of Contents

  1. Hooks
  2. Components
  3. Utilities
  4. Types
  5. Edge Functions

Hooks

Chart of Accounts & Funds (FA-01)

useAccounts

Fetch chart of accounts with filtering and search.
Returns:
  • accounts: FAAccount[] - Array of account records
  • isLoading: boolean - Loading state
  • error: Error | null - Error object if query failed
RLS: Requires has_org_access(auth.uid(), organization_id)

useAccountDetail

Fetch single account with balances (when FA-02 implemented).
Returns:
  • account: FAAccount - Account record
  • balances: { debit: number; credit: number; balance: number } - Account balances
  • isLoading: boolean

useFunds

Fetch list of funds.
Returns:
  • funds: FAFund[] - Array of fund records
  • isLoading: boolean

useDepartments

Fetch department hierarchy.
Returns:
  • departments: FADepartment[] - Array of department records with parent-child relationships
  • isLoading: boolean

usePrograms

Fetch program list.
Returns:
  • programs: FAProgram[] - Array of program records
  • isLoading: boolean

useFiscalPeriods

Fetch fiscal periods for a year.
Returns:
  • periods: FAFiscalPeriod[] - Array of fiscal periods
  • currentPeriod: FAFiscalPeriod | null - Current open period
  • isLoading: boolean

useAccountMutation

Create, update, delete accounts.
RLS: Requires fa_is_finance_admin(auth.uid(), organization_id)

General Ledger (FA-02)

useJournalEntries

Fetch journal entries with filtering.

useTrialBalance

Fetch trial balance for a period.
Returns:
  • trialBalance: TrialBalanceRow[] - Array of account balances
  • totals: { totalDebits: number; totalCredits: number } - Trial balance totals
  • isLoading: boolean

useJournalEntryMutation

Create, post, void journal entries.

Accounts Payable (FA-04)

useVendors

Fetch vendor list.

useVendorBills

Fetch vendor bills.

usePayments

Fetch payments.

useVendorBillMutation

Create, approve, pay vendor bills.

Accounts Receivable (FA-06)

useCustomers

Fetch customer list.

useInvoices

Fetch invoices.

useCustomerPayments

Fetch customer payments.

Financial Reporting (FA-07)

useReportDefinitions

Fetch saved report definitions.

useReportExecution

Execute financial report.

useReportSchedules

Fetch scheduled reports.

Budgeting (FA-08)

useBudgets

Fetch budgets.

useBudgetVsActual

Fetch budget vs actual comparison.
Returns:
  • data: BudgetVsActualRow[] - Array of budget vs actual comparisons
  • isLoading: boolean

useBudgetAlerts

Fetch budget alerts for exceeded thresholds.

Multi-Entity Consolidation (FA-09)

useEntities

Fetch legal entities.

useEntityHierarchy

Fetch entity hierarchy with ownership percentages.
Returns:
  • hierarchy: EntityNode[] - Tree structure of entities with children
  • isLoading: boolean

useIntercompanyBalances

Fetch inter-company balances for reconciliation.
Returns:
  • balances: IntercompanyBalance[] - Array of inter-company transactions
  • isBalanced: boolean - True if all inter-company accounts net to zero
  • isLoading: boolean

useRunConsolidation

Execute consolidation process.

Module Settings (FA-10)

useFAModuleSettings

Fetch and update FA module settings.
RLS: View requires org access, update requires org_admin

Components

Account Selector

Select from chart of accounts with filtering.

Fund Selector

Select from available funds.

Department Selector

Select from department hierarchy.

Journal Entry Form

Create and edit journal entries.

Trial Balance Report

Display trial balance with drill-down.

Utilities

Account Number Formatting


Balance Calculation


Fiscal Period Helpers


Types

Core Types


Edge Functions

execute-report

Execute financial report and return data. Endpoint: supabase/functions/execute-report/index.ts Request:
Response:

consolidate-entities

Run multi-entity consolidation. Endpoint: supabase/functions/consolidate-entities/index.ts Request:
Response:

check-budget-alerts

Scheduled function to check budget thresholds. Endpoint: supabase/functions/check-budget-alerts/index.ts Trigger: Cron (daily at 8 AM) Behavior:
  • Queries fa_budget_vs_actual_view
  • Compares variance to module settings thresholds
  • Creates fa_budget_alerts records
  • Publishes budget_exceeded events
  • Sends notifications via PF-10

Error Handling

All FA hooks use consistent error handling:
Mutations use toast notifications for success/error:

RLS Reference

All FA tables enforce RLS with these common patterns: View Access:
Admin Modify:
Helper Functions:
  • has_org_access(user_id, org_id) - User belongs to organization
  • fa_is_finance_admin(user_id, org_id) - User has org_admin or platform_admin role

Import Paths

CORRECT:
WRONG:

Version History

  • v1.0.0 (2025-11-26): Initial API reference for FA-01 through FA-10