# BankReconciliation

## Description

BankReconciliation is an immutable confirmed reconciliation group. It connects a collection of bank statement lines to a collection of posted incoming or outgoing payments. The group records set-to-set equivalence and does not allocate every statement line to every payment.

## Domain Model Definitions

### Model type

AppendOnly

### Command Definitions

- [reconcileBankTransactions](../command/ReconcileBankTransactions.md) - Confirm a reconciliation group
- [reverseBankReconciliation](../command/ReverseBankReconciliation.md) - Add a reversing group

### Query Definitions

- None

### Models

- BankReconciliation
- BankReconciliationItem

### Invariants

- A group belongs to one BankAccount
- A group contains at least one BANK_STATEMENT_LINE item and at least one payment item
- Incoming and outgoing payments cannot be mixed in the minimum implementation
- CREDIT statement lines reconcile only with IncomingPayment
- DEBIT statement lines reconcile only with OutgoingPayment
- Statement-side and payment-side cleared totals are equal
- `action` is RECONCILE or UNRECONCILE
- Reversal adds an UNRECONCILE group and never mutates the original
- A reconciliation can be reversed at most once

### Relationships

- Belongs to BankAccount
- Has many BankReconciliationItems
