# cancelAccountReceivableDocument

## Overview

Cancels a **DRAFT or REGISTERED** customer invoice, transitioning the `AccountReceivableDocument` from DRAFT or REGISTERED to CANCELLED. Cancellation discards an invoice that has not yet been posted and never touches the general ledger. Only DRAFT or REGISTERED documents can be cancelled — a POSTED invoice must be corrected with [correctAccountReceivableDocument](./correctAccountReceivableDocument.md), not cancelled, so its journal entry is properly amended. When a REGISTERED document is cancelled the linked sales order's billing status is recalculated in the same transaction. `id` is the AccountReceivableDocument id.

## Modules Commands Used

- [account-receivable] cancelAccountReceivableDocument

## 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 DRAFT or REGISTERED status; only DRAFT or REGISTERED documents can be cancelled. |
| ACCOUNT_RECEIVABLE_SALES_ORDER_BILLING_SYNC_FAILED | The linked sales order's billing status could not be recalculated after cancellation. |
