# CreateSalesCreditNote

## Permission Scope

salesBilling

## Overview

CreateSalesCreditNote creates a draft commercial correction document against an issued invoice. It records affected invoice lines or correction amounts before the credit note is issued.

## Business Rules

- Referenced invoice must already be ISSUED.
- At least one correction line or correction amount is required.
- Correction lines must reference valid issued invoice lines.

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B[Load issued invoice]
    B --> C[Validate correction lines and reasons]
    C --> D[Insert draft credit note and lines]
    D --> E[Return draft credit note]
```

## External Dependencies

- [getSalesInvoice](../queries/GetSalesInvoice.md) - Validate the invoice being corrected.

## Error Scenarios

- **SALES_INVOICE_NOT_FOUND**: Referenced sales invoice does not exist
- **INVOICE_NOT_ISSUED**: Credit notes require an issued invoice.
- **INVALID_CREDIT_NOTE_LINE**: Credit note correction line or amount is invalid

## Test Cases

- creates a draft credit note against an issued invoice
- throws when invoice is not issued
- throws when no correction line is provided
