# SalesPaymentTerm

## Description

SalesPaymentTerm defines reusable receivable timing rules for sales orders and invoices. It stores one or more schedule lines plus optional early-payment discount metadata so invoice due schedules can be calculated deterministically from the invoice date without embedding finance logic into the customer master.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Draft: createSalesPaymentTerm
    Draft --> Active: activateSalesPaymentTerm
    Active --> Inactive: deactivateSalesPaymentTerm
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| activate | DRAFT | ACTIVE | [activateSalesPaymentTerm](../commands/ActivateSalesPaymentTerm.md) |
| deactivate | ACTIVE | INACTIVE | [deactivateSalesPaymentTerm](../commands/DeactivateSalesPaymentTerm.md) |

### Command Definitions

- [createSalesPaymentTerm](../commands/CreateSalesPaymentTerm.md) - Create a draft payment term with one or more schedule lines.
- [updateSalesPaymentTerm](../commands/UpdateSalesPaymentTerm.md) - Revise schedule lines or discount metadata while the term remains editable.
- [activateSalesPaymentTerm](../commands/ActivateSalesPaymentTerm.md) - Make the term assignable to new orders and invoices.
- [deactivateSalesPaymentTerm](../commands/DeactivateSalesPaymentTerm.md) - Prevent future assignment while preserving historical snapshots.

### Query Definitions

- [getSalesPaymentTerm](../queries/GetSalesPaymentTerm.md) - Retrieve one payment term and its schedule definition.
- [listSalesPaymentTerms](../queries/ListSalesPaymentTerms.md) - List payment terms available for commercial assignment.
- [calculateInvoiceDueSchedule](../queries/CalculateInvoiceDueSchedule.md) - Calculate the receivable schedule from an invoice date and term definition.

### Models

- SalesPaymentTerm

### Invariants

- Every payment term belongs to exactly one company.
- A payment term must contain at least one schedule line.
- Percentage-based schedule lines must sum to 100 percent across the term definition.
- When early-payment discount metadata exists, its cutoff date logic must not fall after the final due date.
- Only ACTIVE payment terms may be assigned to new draft sales orders or invoices.

### Relationships

- **Owns Payment-Term Schedule Lines**: A payment term contains one or more schedule definitions used to calculate due schedules.
- **References Company (cross-module)**: `companyId` isolates receivable policy by legal entity.
- **Referenced By SalesOrder**: Orders snapshot the assigned payment term for downstream billing.
- **Referenced By SalesInvoice**: Issued invoices carry the normalized due schedule derived from the term.
