# Bank Reconciliation

## Overview

Bank Reconciliation connects bank-reported account movements with AP/AR-owned payment documents without making GL open items the business matching source of truth.

## Business Purpose

- Explain which posted payments correspond to which bank movements
- Support 1:1, 1:N, N:1, and N:M matching with one data shape
- Keep invoice allocation in AP/AR and bank confirmation in Cash Management
- Preserve reconciliation and reversal history
- Expose the current statement-line reconciliation state without replaying history

## Process Flow

```mermaid
flowchart LR
    BSL[Bank Statement Line] --> BRI[Bank Reconciliation Item]
    BR[Bank Reconciliation] --> BRI
    BRI --> IP[Incoming Payment]
    BRI --> OP[Outgoing Payment]
    IP --> ARS[AR Settlement]
    OP --> APS[AP Settlement]
    ARS --> ARD[AR Due Schedule]
    APS --> APD[AP Due Schedule]
```

## Scenario Patterns

- One bank line matched to one payment
- One aggregate bank line matched to several payments
- Several bank lines matched to one payment
- Several bank lines and payments confirmed as one balanced group
- Unreconciliation followed by a new reconciliation group
- Reversal restoring all source amounts

## Test Cases

- Statement and payment sides must balance
- Incoming groups accept only CREDIT statement lines
- Outgoing groups accept only DEBIT statement lines
- Each statement line is reconciled for its full amount in one effective group
- Reconciliation updates `BankStatementLine.reconciliationStatus` and `currentBankReconciliationId`
- Reversal restores the statement line's current reconciliation state so it can be reconciled again
- Concurrent reconciliation is serialized by locking the BankAccount

## Reference Links

- [BankReconciliation](../model/BankReconciliation.md)
- [BankReconciliationItem](../model/BankReconciliationItem.md)
