# UpdateSalesInvoice

## Permission Scope

salesBilling

## Overview

UpdateSalesInvoice revises mutable draft invoice fields before issue. It supports correction of line composition, customer-facing references, and draft billing metadata.

## Business Rules

- Only DRAFT invoices may be updated directly.
- Updated invoice lines must still satisfy quantity and reference validity rules.

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B[Load invoice]
    B --> C{Status is DRAFT?}
    C -->|No| D[Return INVOICE_NOT_EDITABLE]
    C -->|Yes| E[Validate changed fields and lines]
    E --> F[Persist updates]
    F --> G[Return updated invoice]
```

## External Dependencies

- [getSalesInvoice](../queries/GetSalesInvoice.md) - Load current invoice state before applying changes.

## Error Scenarios

- **SALES_INVOICE_NOT_FOUND**: Referenced sales invoice does not exist
- **INVOICE_NOT_EDITABLE**: Only DRAFT invoices may be updated.
- **INVALID_INVOICE_LINE**: Invoice line content is incomplete or invalid

## Test Cases

- updates draft invoice metadata
- returns error when updating an issued invoice
- returns error when updated line content is invalid
