import { apiRequestBlob, apiRequestData } from "./http"; import type { RiskFlag } from "./feeControl"; export type ApOperationsExportFormat = "csv" | "xlsx"; export type ApOperationsRiskBucket = "all" | "exception" | "budget_overspend"; export type ApOperationsPendingEntityType = "reimbursement" | "travel_order"; export type ApPendingPaymentBatchSummary = { id: string; batchNo: string; entityType: string; name: string; status: string; totalAmount: string; highRisk: boolean; createdAt: string | null; }; export type ApFailedPaymentBatchItemSummary = { id: string; paymentBatchId: string; entityId: string; entityCode: string; entityTitle: string; amount: string; currencyCode: string; failureCode: string | null; failureMessage: string | null; createdAt: string | null; }; export type ApPartialMatchItemSummary = { id: string; travelReconciliationBatchId: string; travelOrderId: string | null; travelRequestId: string | null; matchStatus: string; resolutionStatus: string; anomalyCode: string | null; orderAmount: string | null; transactionAmount: string | null; currency: string; createdAt: string | null; }; export type ApOperationsSummary = { summary: { pendingPaymentCount: number; partialMatchCount: number; exceptionCount: number; budgetOverspendCount: number; }; pendingPaymentBatches: ApPendingPaymentBatchSummary[]; failedPaymentBatchItems: ApFailedPaymentBatchItemSummary[]; exceptionRiskFlags: RiskFlag[]; budgetOverspendRisks: RiskFlag[]; partialMatchItems: ApPartialMatchItemSummary[]; }; export async function fetchApOperations() { return apiRequestData("/api/ap-operations"); } export async function exportApOperations(params: { format: ApOperationsExportFormat; pendingEntityType?: ApOperationsPendingEntityType; pendingCreatedAtFrom?: string; pendingCreatedAtTo?: string; riskBucket?: ApOperationsRiskBucket; }) { return apiRequestBlob("/api/exports/ap-operations", { method: "POST", headers: { "content-type": "application/json", }, body: JSON.stringify(params), }); }