# CalculateInvoiceDueSchedule

## Overview

CalculateInvoiceDueSchedule computes the receivable due schedule for an invoice date and sales payment term. It expands installment lines, end-of-month rules, and early-payment discount windows into deterministic due-schedule output.

## Business Rules

- Invoice date and payment-term reference are required inputs.
- Percentage-based schedules must resolve to a full payable baseline.
- End-of-month rules must use calendar-month logic rather than a fixed offset shortcut.

## Process Flow

```mermaid
flowchart TD
    A[Receive invoice date and payment term] --> B[Load payment-term definition]
    B --> C[Expand schedule-line rules]
    C --> D[Calculate due dates and discount windows]
    D --> E[Return computed due schedule]
```

## External Dependencies

- [getSalesPaymentTerm](../queries/GetSalesPaymentTerm.md) - Load the assigned payment-term definition.

## Error Scenarios

- **PAYMENT_TERM_NOT_FOUND**: Referenced payment term does not exist.
- **INVALID_PAYMENT_TERM_DEFINITION**: Payment term definition cannot produce a deterministic due schedule.

## Test Cases

- calculates net-day due schedule
- calculates installment due schedule
- calculates end-of-month due schedule
- throws when payment term definition is invalid
