# RegisterAccountReceivableDocument

## Permission Scope

accountReceivableDocumentOperation

## Overview

registerAccountReceivableDocument transitions a complete DRAFT document to REGISTERED and synchronizes its sales-order billing quantities. This matches AccountPayableDocument registration semantics.

## Business Rules

- Only DRAFT documents can be registered
- Lines and distributions must sum to totalAmount
- At least one due-schedule line is required and the schedule must sum to totalAmount
- REGISTERED and POSTED INVOICE quantities count positively
- CREDIT_MEMO quantities count negatively

## Process Flow

```mermaid
flowchart TD
    A[Lock DRAFT document] --> B[Validate lines, distributions, and due schedule]
    B --> C[Mark REGISTERED]
    C --> D[Rebuild sales-order billing projection]
    D --> E[Return registered document]
```

## External Dependencies

- sales [RecalculateSalesOrderBillingStatus](../../../sales/docs/command/RecalculateSalesOrderBillingStatus.md)

## Error Scenarios

- **DOCUMENT_NOT_FOUND**: Referenced AR document does not exist
- **INVALID_DOCUMENT_STATUS**: AR document status does not allow this operation
- **LINE_TOTAL_MISMATCH**: Invoice line total does not equal the document total
- **DUE_SCHEDULE_INVALID**: Due schedule must be positive and equal the document total
- **SALES_ORDER_BILLING_SYNC_FAILED**: Sales-order billing projection could not be synchronized

## Test Cases

- registers a complete invoice and synchronizes sales billing
