# CreateSalesPaymentTerm

## Permission Scope

salesPricing

## Overview

CreateSalesPaymentTerm creates a draft payment-term definition with one or more schedule lines and optional early-payment discount metadata.

## Business Rules

- Record is always created in DRAFT status.
- 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 create request] --> B[Validate references and required fields]
    B --> C{Validation passed?}
    C -->|No| D[Return validation error]
    C -->|Yes| E[Insert draft SalesPaymentTerm record]
    E --> F[Return created 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
- **INVALID_PAYMENT_SCHEDULE**: Schedule lines do not satisfy payment-term rules.

## Test Cases

- creates a payment term with valid schedule lines
- throws when required SalesPaymentTerm fields are missing
- creates the SalesPaymentTerm in DRAFT status
