# postAccountReceivableDocument

## Overview

Posts a REGISTERED customer invoice to the general ledger, transitioning the `AccountReceivableDocument` from REGISTERED to POSTED. Posting is the accounting step that confirms the invoice: the native command resolves the accounting period for the invoice's posting date, builds a **balanced `JournalEntry`** from the invoice's distribution lines and the stored receivable control account, and posts it directly in financial-accounting within the same transaction. For an `INVOICE` the receivable control account is **debited** and the distribution/revenue accounts are **credited** (a `CREDIT_MEMO` reverses this). The journal entry carries `sourceDocumentType` SALES_INVOICE and `sourceDocumentId` equal to the AR document id, and `postedAt` is stamped on the document on success. Posting requires the document currency to equal the company's base currency (financial-accounting journal lines are base-currency amounts). Unlike the AP side there are no active holds that can block posting.

## Modules Commands Used

- [account-receivable] postAccountReceivableDocument

## Exception Handling

| Error Code | Description |
| --- | --- |
| ACCOUNT_RECEIVABLE_DOCUMENT_NOT_FOUND | No account receivable document exists for the given ID. |
| ACCOUNT_RECEIVABLE_INVALID_DOCUMENT_STATUS | The document is not in REGISTERED status; only REGISTERED documents can be posted. |
| ACCOUNT_RECEIVABLE_POSTING_CURRENCY_MISMATCH | The document currency does not match the company's base currency. |
| ACCOUNT_RECEIVABLE_ACCOUNTING_PERIOD_NOT_FOUND | No accounting period covers the document's posting date. |
| ACCOUNT_RECEIVABLE_LINE_TOTAL_MISMATCH | The line or distribution totals do not reconcile with the document total. |
| ACCOUNT_RECEIVABLE_MINIMUM_LINES_NOT_MET | The document has no line or no distribution to post. |
| ACCOUNT_RECEIVABLE_ACCOUNT_NOT_FOUND | A referenced GL account (receivable control or distribution) does not exist. |
| ACCOUNT_RECEIVABLE_ACCOUNT_INACTIVE | A referenced GL account is not ACTIVE. |
| ACCOUNT_RECEIVABLE_COMPANY_NOT_FOUND | The document's company does not exist. |
| ACCOUNT_RECEIVABLE_JOURNAL_ENTRY_CREATE_FAILED | The journal entry could not be created. |
| ACCOUNT_RECEIVABLE_JOURNAL_ENTRY_POST_FAILED | The journal entry could not be posted to the general ledger. |
