import axios, { AxiosResponse } from 'axios'; import { Invoice, SalesStatistics as SalesStatistics, LineItem } from '@/types'; const API_URL = '/api/invoices'; const LINE_ITEM_API_URL = '/api/lineitems'; export default { /** * Retrieves all invoices * @returns Promise */ async getAllInvoices(): Promise { const response = await axios.get(API_URL); return response.data; }, /** * Retrieves invoice summary for all time * @returns Promise */ async getSummaryAll(): Promise { const response = await axios.get(`${API_URL}/summary`); return response.data; }, /** * Retrieves invoice summary for the current year * @returns Promise */ async getSummaryThisYear(): Promise { const response = await axios.get(`${API_URL}/summaryThisYear`); return response.data; }, /** * Retrieves invoice summary for before the current year * @returns Promise */ async getSummaryBeforeThisYear(): Promise { const response = await axios.get(`${API_URL}/summaryBeforeThisYear`); return response.data; }, /** * Retrieves sales statistics * @returns Promise */ async getSalesStatistics(): Promise { const response = await axios.get(`${API_URL}/salesStatistics`); return response.data; }, /** * Creates a new invoice * @param invoice - The invoice data to create * @returns Promise */ async createInvoice(invoice: Partial): Promise { const response = await axios.post(API_URL, invoice); return response.data; }, /** * Updates an existing invoice * @param invoice - The invoice object to update * @returns Promise */ async updateInvoice(invoice: Partial): Promise { const response = await axios.put(`${API_URL}/${invoice.id}`, invoice); return response.data; }, /** * Deletes an invoice by ID * @param invoiceId - The id of the invoice to delete * @returns Promise */ async deleteInvoice(invoiceId: number): Promise { const response = await axios.delete(`${API_URL}/${invoiceId}`); return response.data; }, /** * Retrieves line items for a specific invoice * @param invoiceId - The ID of the invoice * @returns Promise */ async getLineItems(invoiceId: number): Promise { const response = await axios.get(`${LINE_ITEM_API_URL}/${invoiceId}`); return response.data; }, /** * Sends a reminder for an invoice * @param invoiceId - The ID of the invoice to remind * @param to - Email address to send the reminder to * @param cc - Optional email address to CC the reminder to * @returns Promise */ async remindInvoice(invoiceId: number, to: string, cc?: string): Promise { const params = { to, cc }; const response = await axios.get(`${API_URL}/${invoiceId}/remind`, { params }); return response.data; }, /** * Exports an invoice as PDF * @param invoiceId - The ID of the invoice to export * @returns Promise */ async exportPdf(invoiceId: number): Promise { const response = await axios.get(`${API_URL}/${invoiceId}/pdf`, { responseType: 'blob' }); return response.data; }, /** * Exports an invoice as XML * @param invoiceId - The ID of the invoice to export * @returns Promise */ async exportXml(invoiceId: number): Promise { const response = await axios.get(`${API_URL}/${invoiceId}/xml`, { responseType: 'blob' }); return response.data; } };