# SalesCreditNote

## Description

SalesCreditNote is the commercial correction document issued after an invoice already exists. It reduces billed quantity or amount for allowances, disputes, or price corrections while preserving the original invoice as immutable evidence.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Draft: createSalesCreditNote
    Draft --> Issued: issueSalesCreditNote
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| issue | DRAFT | ISSUED | [issueSalesCreditNote](../command/IssueSalesCreditNote.md) |

### Command Definitions

- [createSalesCreditNote](../command/CreateSalesCreditNote.md) - Create a draft credit note referencing an issued invoice and one or more affected invoice lines.
- [updateSalesCreditNote](../command/UpdateSalesCreditNote.md) - Correct draft credit-note amounts, reasons, or references before issue.
- [issueSalesCreditNote](../command/IssueSalesCreditNote.md) - Validate the commercial correction and issue the immutable credit note.

### Query Definitions

- [getSalesCreditNote](../query/GetSalesCreditNote.md) - Retrieve one credit note with correction metadata and affected lines.
- [listSalesCreditNotesByInvoice](../query/ListSalesCreditNotesByInvoice.md) - List all credit corrections issued against one invoice.

### Models

- SalesCreditNote
- SalesCreditNoteLine

### Invariants

- Every credit note belongs to exactly one company and references one issued sales invoice.
- A credit note must preserve correction reason, tax basis, customer identity, and linked invoice identity at issue time.
- The cumulative credited quantity or amount against any invoice line cannot exceed the original issued quantity or amount without a documented override policy.

### Relationships

- **Owns SalesCreditNoteLine**: Line-level corrections specify the quantities or amounts being reduced.
- **References SalesInvoice**: `salesInvoiceId` identifies the invoice being corrected.
- **References SalesOrder**: Credit notes preserve the originating commercial context through the linked invoice lines.
