# UpdateJournalLine

## Overview

updateJournalLine modifies an existing line item on a DRAFT journal entry. Updatable fields include the GL account reference, debit or credit amount, currency, exchange rate, and line-level description. Lines on posted or reversed entries are immutable and cannot be updated.

## Business Rules

- Journal line must exist and its parent journal entry must be in DRAFT status
- Lines on POSTED or REVERSED entries cannot be updated
- Updated account reference must be a valid GL account from coa-management
- Updated debit/credit must follow the same rules as creation (one or the other, positive values)
- Multi-currency updates must include valid currency and exchange rate
- Functional currency amount is recomputed when amount or exchange rate changes
- Emits an audit event recording previous and new field values, acting user, and timestamp

## Process Flow

```mermaid
flowchart TD
    A[Receive update journal line request] --> B{Journal line exists?}
    B -->|No| C[Return error: journal line not found]
    B -->|Yes| D{Parent entry status is DRAFT?}
    D -->|No| E[Return error: cannot modify lines on non-draft entry]
    D -->|Yes| F{Updated fields valid?}
    F -->|No| G[Return error: validation failed]
    F -->|Yes| H[Update journal line fields]
    H --> I[Recompute functional currency amount if needed]
    I --> J[Emit audit event]
    J --> K[Return updated journal line]
```

## External Dependencies

- [coa-management::getAccount](../../../coa-management/docs/queries/GetAccount.md) - Validates that the updated GL account reference exists
- [primitives::getCurrency](../../../primitives/docs/queries/GetCurrency.md) - Validates that the updated currency exists and is active

## Error Scenarios

- **JOURNAL_LINE_NOT_FOUND**: Referenced journal line does not exist
- **INVALID_STATUS_FOR_LINE_UPDATE**: Parent journal entry is not in DRAFT status
- **ACCOUNT_NOT_FOUND**: Updated GL account reference does not exist
- **INVALID_DEBIT_CREDIT**: Updated debit/credit values violate constraints (both specified, both zero, or negative)
- **CURRENCY_NOT_FOUND**: Updated currency does not exist or is not active

## Test Cases

- returns error when journal line does not exist
- returns error when parent journal entry is in POSTED status
- returns error when parent journal entry is in REVERSED status
- returns error when updated GL account does not exist
- returns error when updated GL account is not active
- returns error when updated debit/credit values are invalid
- returns error when updated currency does not exist
- updates GL account reference on a journal line
- updates debit amount on a journal line
- updates credit amount on a journal line
- updates currency and exchange rate on a journal line
- recomputes functional currency amount after update
- updates line-level description
- emits audit event recording previous and new field values and acting user
