# PurchasePaymentTerm

## Description

PurchasePaymentTerm defines the supplier-facing settlement schedule that purchase orders and supplier bills snapshot for downstream payable processing. A term contains one or more schedule lines that express net-day, end-of-month, fixed-day, installment, and early-payment-discount logic.

The model stays inside purchase because it is part of the commercial agreement captured during procurement, but it is designed to hand a stable due schedule to downstream AP without requiring AP to re-interpret supplier contract language.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Active: createPurchasePaymentTerm
    Active --> Inactive: deactivatePurchasePaymentTerm
    Inactive --> Active: activatePurchasePaymentTerm
    Active --> Active: updatePurchasePaymentTerm
    Inactive --> Inactive: updatePurchasePaymentTerm
```

### Command Definitions

- [createPurchasePaymentTerm](../commands/CreatePurchasePaymentTerm.md) - Create a new active supplier payment term with at least one schedule line
- [updatePurchasePaymentTerm](../commands/UpdatePurchasePaymentTerm.md) - Update the definition of an existing payment term without changing historical snapshots
- [activatePurchasePaymentTerm](../commands/ActivatePurchasePaymentTerm.md) - Re-enable a deactivated payment term for new procurement documents
- [deactivatePurchasePaymentTerm](../commands/DeactivatePurchasePaymentTerm.md) - Prevent a payment term from being assigned to new procurement documents

### Query Definitions

- [getPurchasePaymentTerm](../queries/GetPurchasePaymentTerm.md) - Retrieve a payment term and all of its schedule lines
- [calculatePurchaseBillDueSchedule](../queries/CalculatePurchaseBillDueSchedule.md) - Convert a payment term plus bill inputs into payable installments and discount windows

### Models

- PurchasePaymentTerm
- PurchasePaymentTermLine

### Invariants

- Every payment term has at least one schedule line
- Percentage-based installment schedules must total exactly 100 percent before rounding
- Schedule lines must not contain negative percentage values or negative fixed amounts
- Early-payment discount dates must occur on or before the final due date generated by the term
- If a term offers discounting, it must explicitly record whether discount calculation uses `GROSS_AMOUNT` or `NET_AMOUNT`
- Installment rounding residual is absorbed by the final generated bill schedule line so total scheduled amount always equals the bill amount in transaction currency
- Inactive payment terms remain valid for historical purchase order and purchase bill snapshots but cannot be assigned to new drafts
- Exchange-rate conversion is out of scope for payment-term calculation; schedules are computed entirely in the bill transaction currency

### Relationships

- **Has Many PurchasePaymentTermLines**: Each term contains one or more schedule lines that define due-date and discount behavior
- **Referenced By SupplierProfile**: A [SupplierProfile](./SupplierProfile.md) may point to one default payment term
- **Snapshotted By PurchaseOrder**: A [PurchaseOrder](./PurchaseOrder.md) stores the chosen term as an immutable commercial snapshot
- **Snapshotted By PurchaseBill**: A [PurchaseBill](./PurchaseBill.md) carries the term snapshot forward into downstream payable readiness
