# GetSubledgerTransferStatus

## Overview

GetSubledgerTransferStatus returns the transfer completeness status for all subledger modules for a given accounting period. For each registered subledger module (purchase, sales, inventory, manufacturing), the query reports the total expected handoff events, the number of acknowledged (successfully posted) events, and the number of outstanding (pending) events. This query is a critical input to the period-end close workflow, where subledger transfer verification must pass before the close can proceed.

## Business Rules

- Accepts a single lookup parameter: `{ accountingPeriodId }`
- Returns a status record per subledger module: purchase, sales, inventory, manufacturing
- Each module status includes:
  - `totalExpected` — total number of handoff events expected for the period
  - `acknowledged` — number of events successfully posted and acknowledged
  - `outstanding` — number of events not yet posted or acknowledged (`totalExpected - acknowledged`)
- The query aggregates data from subledger handoff event records and their acknowledgment status
- Returns the status for all registered subledger modules, even if a module has zero expected events
- Used by the period-end close workflow to determine whether subledger verification can pass

## Process Flow

```mermaid
flowchart TD
    A[Receive input with accountingPeriodId] --> B[Query handoff events for the accounting period]
    B --> C[Group events by source subledger module]
    C --> D[For each module: count total expected events]
    D --> E[For each module: count acknowledged events]
    E --> F[For each module: compute outstanding = total - acknowledged]
    F --> G[Return status per subledger module]
```

## External Dependencies

- None

## Error Scenarios

- **ACCOUNTING_PERIOD_NOT_FOUND**: The specified accounting period does not exist — caller receives an error

## Test Cases

- returns error when accounting period does not exist
- returns status for all 4 modules
- returns zero counts when no entries exist
- correctly counts posted vs draft entries
- returns correct outstanding counts
