# createOutgoingPayment

## Overview

Creates an editable **DRAFT** outgoing payment — the document that records paying a supplier and settling its open account-payable items. The native command validates the owning company, the supplier business partner, the payment currency, and the cash/bank GL account the payment is drawn from, then inserts an `OutgoingPayment` (status DRAFT) with `paymentDate` and a positive `totalAmount`. Any supplied `settlements` are recorded as `AccountPayableSettlement` rows, each allocating part of the payment to an `AccountPayableDueScheduleLine` — an invoice's due installment, or a credit memo's negative installment (erp-kit 0.51 lets one payment settle invoices and credit memos together at their signed net). Creation performs **no GL posting**; the balanced cash-disbursement entry is booked later by [postOutgoingPayment](./postOutgoingPayment.md). Settlements may be empty at creation and edited until the payment is posted.

## Modules Commands Used

- [account-payable] createOutgoingPayment

## Exception Handling

| Error Code | Description |
| --- | --- |
| ACCOUNT_PAYABLE_COMPANY_NOT_FOUND | The owning company does not exist. |
| ACCOUNT_PAYABLE_COMPANY_INACTIVE | The owning company is not active. |
| ACCOUNT_PAYABLE_AP_BUSINESS_PARTNER_NOT_FOUND | The supplier business partner does not exist. |
| ACCOUNT_PAYABLE_AP_INVALID_BUSINESS_PARTNER | The business partner is not a valid supplier. |
| ACCOUNT_PAYABLE_AP_CURRENCY_NOT_FOUND | The payment currency does not exist. |
| ACCOUNT_PAYABLE_ACCOUNT_NOT_FOUND | The cash/bank payment account does not exist. |
| ACCOUNT_PAYABLE_ACCOUNT_INACTIVE | The cash/bank payment account is not ACTIVE. |
| ACCOUNT_PAYABLE_ACCOUNT_COMPANY_MISMATCH | The payment account belongs to a different company. |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_INVALID_AMOUNT | The payment total is not a positive value. |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_SETTLEMENT_INVALID | A settlement allocation has an invalid amount or an ineligible target line. |
