# postAccountPayableDocument

## Overview

Posts a REGISTERED vendor invoice to the general ledger, transitioning the `AccountPayableDocument` 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 payable control account, and posts it directly in financial-accounting within the same transaction. For an `INVOICE` the distribution accounts are **debited** and the payable control account is **credited** (a `CREDIT_MEMO` reverses this). The journal entry carries `sourceDocumentType` ACCOUNT_PAYABLE_DOCUMENT and `sourceDocumentId` equal to the AP document id, and `postedAt` is stamped on the document on success. Posting **refuses to run while any active (unreleased) hold remains**, and requires the document currency to equal the company's base currency (financial-accounting journal lines are base-currency amounts).

## Modules Commands Used

- [account-payable] postAccountPayableDocument

## Exception Handling

| Error Code | Description |
| --- | --- |
| ACCOUNT_PAYABLE_AP_DOCUMENT_NOT_FOUND | No account payable document exists for the given ID. |
| ACCOUNT_PAYABLE_AP_INVALID_DOCUMENT_STATUS | The document is not in REGISTERED status; only REGISTERED documents can be posted. |
| ACCOUNT_PAYABLE_AP_DOCUMENT_HAS_ACTIVE_HOLD | The document still has an active (unreleased) payment hold, which blocks posting. |
| ACCOUNT_PAYABLE_AP_POSTING_CURRENCY_MISMATCH | The document currency does not match the company's base currency. |
| ACCOUNT_PAYABLE_AP_ACCOUNTING_PERIOD_NOT_FOUND | No accounting period covers the document's posting date. |
| ACCOUNT_PAYABLE_AP_LINE_TOTAL_MISMATCH | The line or distribution totals do not reconcile with the document total. |
| ACCOUNT_PAYABLE_AP_MINIMUM_LINES_NOT_MET | The document has no line or no distribution to post. |
| ACCOUNT_PAYABLE_ACCOUNT_NOT_FOUND | A referenced GL account (payable control or distribution) does not exist. |
| ACCOUNT_PAYABLE_ACCOUNT_INACTIVE | A referenced GL account is not ACTIVE. |
| ACCOUNT_PAYABLE_COMPANY_NOT_FOUND | The document's company does not exist. |
| ACCOUNT_PAYABLE_AP_JOURNAL_ENTRY_CREATE_FAILED | The journal entry could not be created. |
| ACCOUNT_PAYABLE_AP_JOURNAL_ENTRY_POST_FAILED | The journal entry could not be posted to the general ledger. |
