import { api as apiClient } from "@/auth/http"; import { URL_CONSTANTS } from "@/constants/URLS"; import type { EimsInvoiceStatusView, EimsModeOfPayment, EimsReceiptView, EimsVerifyResult, } from "@/types/eims"; /** * MoR EIMS filing actions on an invoice. * * Registration is irreversible at the tax authority, so these are admin actions rather than part * of the ordinary invoice screen: the normal production path is the API's cron sweep. */ export const eimsService = { status(invoiceId: string): Promise { return apiClient .get(URL_CONSTANTS.EIMS.STATUS(invoiceId)) .then((r) => r.data); }, register(invoiceId: string): Promise { return apiClient .post(URL_CONSTANTS.EIMS.REGISTER(invoiceId)) .then((r) => r.data); }, verify(invoiceId: string): Promise { return apiClient .post(URL_CONSTANTS.EIMS.VERIFY(invoiceId)) .then((r) => r.data); }, /** Record an IRN confirmed with MoR, or discard the attempt. Clears the system-wide block. */ resolve( invoiceId: string, input: { irn?: string; discard?: boolean }, ): Promise { return apiClient .post(URL_CONSTANTS.EIMS.RESOLVE(invoiceId), input) .then((r) => r.data); }, /** Cancel the invoice's registered EIMS document. Refuses (409) an already-cancelled one. */ cancel( invoiceId: string, input: { reasonCode: string; remark?: string }, ): Promise { return apiClient .post(URL_CONSTANTS.EIMS.CANCEL(invoiceId), input) .then((r) => r.data); }, registerSalesReceipt( invoiceId: string, input: { modeOfPayment: EimsModeOfPayment; reason?: string; collectedAmount?: number }, ): Promise { return apiClient .post(URL_CONSTANTS.EIMS.RECEIPT_SALES(invoiceId), input) .then((r) => r.data); }, registerWithholdingReceipt( invoiceId: string, input: { type: string; preTaxAmount: number; withholdingAmount: number; reason?: string }, ): Promise { return apiClient .post(URL_CONSTANTS.EIMS.RECEIPT_WITHHOLDING(invoiceId), input) .then((r) => r.data); }, listReceipts(invoiceId: string): Promise { return apiClient .get(URL_CONSTANTS.EIMS.RECEIPTS(invoiceId)) .then((r) => r.data); }, /** Blob download — same pattern as `invoicesService.downloadDocument`. */ downloadReceiptDocument(invoiceId: string, receiptId: string) { return apiClient.get(URL_CONSTANTS.EIMS.RECEIPT_DOCUMENT(invoiceId, receiptId), { responseType: "blob", }); }, };