# JournalLine

## Description

JournalLine represents a single debit or credit entry within a JournalEntry. Each line references a GL account from the coa-management module, specifies either a debit or credit amount (mutually exclusive), includes an optional line-level description, and optionally includes foreign currency details (currency code, exchange rate) with computed functional currency amounts. Journal lines are the atomic units of double-entry bookkeeping — they are always created, modified, and deleted in the context of their parent journal entry's lifecycle. Lines on a POSTED or REVERSED journal entry are immutable.

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- [addJournalLine](../commands/AddJournalLine.md) - Add a journal line to a DRAFT journal entry
- [updateJournalLine](../commands/UpdateJournalLine.md) - Update a journal line on a DRAFT journal entry
- [removeJournalLine](../commands/RemoveJournalLine.md) - Remove a journal line from a DRAFT journal entry

### Query Definitions

- [GetJournalEntry](../queries/GetJournalEntry.md) - Journal lines are returned as part of the parent journal entry

### Models

- JournalLine

### Invariants

- Each journal line must reference a valid GL account from an ACTIVE Chart of Accounts
- Each journal line must specify either a debit amount or a credit amount (not both, and not zero for both)
- Debit and credit amounts must be positive values
- Multi-currency journal lines must specify a currency code and exchange rate
- The functional currency amount is computed as the foreign amount multiplied by the exchange rate
- Journal lines without an explicit currency default to the company's functional (base) currency with an exchange rate of 1.0
- Journal lines referencing an inactive or draft GL account are rejected at posting time
- Journal lines referencing a deprecated GL account with a successor mapping are redirected to the successor account at posting time
- If the successor account is itself inactive or deprecated without a further successor, the posting is rejected
- Journal lines can only be added to, updated on, or removed from a DRAFT journal entry
- Balance validation for multi-currency entries is performed on the functional currency amounts, not the foreign currency amounts
- Line-level description is optional and can be updated while the parent journal entry is in DRAFT status
- RECEIVABLE and PAYABLE classified accounts block direct manual journal postings (control account constraint)

### Relationships

- **References JournalEntry**: Each journal line belongs to a JournalEntry via journalEntryId
- **References Account**: Each journal line references a GL Account via accountId (coa-management module)
- **References Currency**: Each journal line optionally references a Currency via currencyCode for multi-currency postings (primitives module)
