# IssueSalesCreditNote

## Overview

IssueSalesCreditNote validates a draft credit note and freezes it as commercial correction evidence. It ensures cumulative credited quantity or amount remains within the allowed baseline of the original invoice.

## Business Rules

- Only DRAFT credit notes may be issued.
- The cumulative credited quantity or amount for each invoice line must not exceed the original issued baseline.
- Issueing the credit note must snapshot correction reason, tax basis, customer, and invoice identity.

## Process Flow

```mermaid
flowchart TD
    A[Receive issue request] --> B[Load draft credit note]
    B --> C[Validate cumulative credit baseline]
    C --> D[Snapshot correction metadata]
    D --> E[Set status to ISSUED]
    E --> F[Return issued credit note]
```

## External Dependencies

- [getSalesCreditNote](../queries/GetSalesCreditNote.md) - Load draft credit-note context and linked invoice lines.

## Error Scenarios

- **SALES_CREDIT_NOTE_NOT_FOUND**: Referenced sales credit note does not exist.
- **INVALID_CREDIT_NOTE_STATUS**: Only DRAFT credit notes may be issued.
- **CREDIT_LIMIT_EXCEEDED**: Cumulative credited quantity or amount exceeds the original invoice baseline.

## Test Cases

- issues a credit note within the original invoice baseline
- throws when credit quantity exceeds original billed quantity
- throws when credit note is not in DRAFT status
