seahaven-ap/packages/shared/src/invoice-status.ts

37 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

/**
* Invoice status helpers for Ready-to-Pay and post pay-run alignment.
* Thin surface for AP-17; full pay-run logic stays in the API.
*/
export const INVOICE_STATUSES = [
"pending_approval",
"approved",
"scheduled",
"paid",
"rejected",
"void",
] as const;
export type InvoiceStatus = (typeof INVOICE_STATUSES)[number];
/** Invoices eligible for Select to Pay / pay-run selection. */
export const READY_TO_PAY_STATUSES = ["approved"] as const satisfies readonly InvoiceStatus[];
export function isInvoiceStatus(value: string): value is InvoiceStatus {
return (INVOICE_STATUSES as readonly string[]).includes(value);
}
export function isReadyToPay(status: InvoiceStatus | string): boolean {
return (READY_TO_PAY_STATUSES as readonly string[]).includes(status);
}
/** Status after a successful pay run groups the invoice into the payments queue. */
export function statusAfterPayRun(): InvoiceStatus {
return "scheduled";
}
/** Terminal paid status once the payment ladder reaches cleared (AP-17 wiring). */
export function statusAfterPaymentCleared(): InvoiceStatus {
return "paid";
}