# UpdateSalesPaymentTerm

## Permission Scope

salesPricing

## Overview

UpdateSalesPaymentTerm revises mutable SalesPaymentTerm fields while the record remains editable under policy.

## Business Rules

- The SalesPaymentTerm must exist before it can be updated.
- The SalesPaymentTerm must remain in an editable lifecycle state.
- At least one schedule line is required.
- Percentage-based schedules must total 100 percent.
- Discount cutoff must not fall after the final due date.

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B[Load SalesPaymentTerm]
    B --> C{Record editable?}
    C -->|No| D[Return SALESPAYMENTTERM_NOT_EDITABLE]
    C -->|Yes| E[Validate changed fields]
    E --> F[Persist updates]
    F --> G[Return updated SalesPaymentTerm]
```

## External Dependencies

- [organization::GetCompany](../../../organization/docs/queries/GetCompany.md) - Validate company scope for the term.

## Error Scenarios

- **SALESPAYMENTTERM_NOT_FOUND**: Referenced SalesPaymentTerm does not exist
- **SALESPAYMENTTERM_NOT_EDITABLE**: SalesPaymentTerm is not in an editable lifecycle state.
- **INVALID_PAYMENT_SCHEDULE**: Schedule lines do not satisfy payment-term rules.

## Test Cases

- updates mutable SalesPaymentTerm fields
- returns error when SalesPaymentTerm does not exist
- returns error when SalesPaymentTerm is not editable
