# DeactivatePurchasePaymentTerm

## Permission Scope

purchasePricing

## Overview

DeactivatePurchasePaymentTerm retires a payment term from future draft procurement documents while preserving all historical snapshots already copied onto orders and bills.

## Business Rules

- Target payment term must exist
- Deactivating an already inactive payment term returns success without changing state
- A payment term cannot be deactivated while it is still configured as the default on an active supplier profile
- Historical purchase-order and purchase-bill snapshots remain valid after deactivation

## Process Flow

```mermaid
flowchart TD
    A[Receive deactivate request] --> B{Payment term exists?}
    B -->|No| C[Return PAYMENT_TERM_NOT_FOUND]
    B -->|Yes| D{Already inactive?}
    D -->|Yes| E[Return success with no-op]
    D -->|No| F{Used as active supplier default?}
    F -->|Yes| G[Return PAYMENT_TERM_IN_USE]
    F -->|No| H[Set status to INACTIVE]
    H --> I[Return deactivated term]
```

## External Dependencies

- [getSupplierProfile](../queries/GetSupplierProfile.md) - Check whether the term is still defaulted on any active supplier profile in scope

## Error Scenarios

- **PAYMENT_TERM_NOT_FOUND**: Referenced purchase payment term does not exist
- **PAYMENT_TERM_IN_USE**: Payment term is still configured as an active supplier default

## Test Cases

- deactivates an active payment term
- returns success when the payment term is already inactive
- returns error when payment term does not exist
- returns error when payment term is still configured as a supplier default
