import axios from "@/config/axios"; import type { CreatePreInvoiceType, GetInvoiceResponseType, InvoiceItemDetailType, InvoiceType, UpdatePreInvoiceType, } from "../types/Types"; import type { InvoiceConfirmStatus } from "../enum/InvoiceEnum"; import type { BaseResponse } from "@/shared/types/Types"; export type GetInvoicesParams = { page?: number; statuses?: InvoiceConfirmStatus[]; search?: string | null; from?: string | null; to?: string | null; }; export type GetInvoiceTabCountsParams = Omit; export type InvoiceTabCountsResponseType = { pending: number; confirmed: number; archived: number; }; export const createInvoice = async (params: CreatePreInvoiceType) => { const { data } = await axios.post("/admin/invoice", params); return data; }; export const getInvoice = async ( params: GetInvoicesParams = {}, ): Promise => { const { page = 1, statuses, search, from, to } = params; const { data } = await axios.get("/admin/invoice", { params: { page, ...(statuses?.length ? { statuses: statuses.join(",") } : {}), ...(search ? { search } : {}), ...(from ? { from } : {}), ...(to ? { to } : {}), }, }); return data; }; export const getInvoiceTabCounts = async ( params: GetInvoiceTabCountsParams = {}, ): Promise => { const { search, from, to } = params; const { data } = await axios.get>( "/admin/invoice/tab-counts", { params: { ...(search ? { search } : {}), ...(from ? { from } : {}), ...(to ? { to } : {}), }, }, ); return data.data; }; export const getInvoiceById = async (id: string) => { const { data } = await axios.get<{ data: InvoiceType }>(`/admin/invoice/${id}`); return data; }; export const getInvoiceItemById = async (id: string) => { const { data } = await axios.get<{ data: InvoiceItemDetailType }>( `/admin/invoice/item/${id}`, ); return data; }; export const updateInvoice = async (id: string, params: UpdatePreInvoiceType) => { const { data } = await axios.patch(`/admin/invoice/${id}`, params); return data; }; export const archiveInvoice = async (id: string) => { const { data } = await axios.patch(`/admin/invoice/${id}/archive`); return data; };