updates
This commit is contained in:
175
Frontend/src/services/api/invoiceService.ts
Normal file
175
Frontend/src/services/api/invoiceService.ts
Normal file
@@ -0,0 +1,175 @@
|
||||
import apiClient from './apiClient';
|
||||
|
||||
export interface InvoiceItem {
|
||||
id: number;
|
||||
description: string;
|
||||
quantity: number;
|
||||
unit_price: number;
|
||||
tax_rate: number;
|
||||
discount_amount: number;
|
||||
line_total: number;
|
||||
room_id?: number;
|
||||
service_id?: number;
|
||||
}
|
||||
|
||||
export interface Invoice {
|
||||
id: number;
|
||||
invoice_number: string;
|
||||
booking_id: number;
|
||||
user_id: number;
|
||||
issue_date: string;
|
||||
due_date: string;
|
||||
paid_date?: string;
|
||||
subtotal: number;
|
||||
tax_rate: number;
|
||||
tax_amount: number;
|
||||
discount_amount: number;
|
||||
total_amount: number;
|
||||
amount_paid: number;
|
||||
balance_due: number;
|
||||
status: 'draft' | 'sent' | 'paid' | 'overdue' | 'cancelled';
|
||||
company_name?: string;
|
||||
company_address?: string;
|
||||
company_phone?: string;
|
||||
company_email?: string;
|
||||
company_tax_id?: string;
|
||||
company_logo_url?: string;
|
||||
customer_name: string;
|
||||
customer_email: string;
|
||||
customer_address?: string;
|
||||
customer_phone?: string;
|
||||
customer_tax_id?: string;
|
||||
notes?: string;
|
||||
terms_and_conditions?: string;
|
||||
payment_instructions?: string;
|
||||
items: InvoiceItem[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface InvoiceResponse {
|
||||
status: string;
|
||||
message?: string;
|
||||
data: {
|
||||
invoice?: Invoice;
|
||||
invoices?: Invoice[];
|
||||
total?: number;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
total_pages?: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface CreateInvoiceData {
|
||||
booking_id: number;
|
||||
tax_rate?: number;
|
||||
discount_amount?: number;
|
||||
due_days?: number;
|
||||
company_name?: string;
|
||||
company_address?: string;
|
||||
company_phone?: string;
|
||||
company_email?: string;
|
||||
company_tax_id?: string;
|
||||
company_logo_url?: string;
|
||||
customer_tax_id?: string;
|
||||
notes?: string;
|
||||
terms_and_conditions?: string;
|
||||
payment_instructions?: string;
|
||||
}
|
||||
|
||||
export interface UpdateInvoiceData {
|
||||
company_name?: string;
|
||||
company_address?: string;
|
||||
company_phone?: string;
|
||||
company_email?: string;
|
||||
company_tax_id?: string;
|
||||
company_logo_url?: string;
|
||||
notes?: string;
|
||||
terms_and_conditions?: string;
|
||||
payment_instructions?: string;
|
||||
status?: string;
|
||||
due_date?: string;
|
||||
tax_rate?: number;
|
||||
discount_amount?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all invoices
|
||||
* GET /api/invoices
|
||||
*/
|
||||
export const getInvoices = async (params?: {
|
||||
booking_id?: number;
|
||||
status?: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}): Promise<InvoiceResponse> => {
|
||||
const response = await apiClient.get<InvoiceResponse>('/invoices', { params });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get invoice by ID
|
||||
* GET /api/invoices/:id
|
||||
*/
|
||||
export const getInvoiceById = async (id: number): Promise<InvoiceResponse> => {
|
||||
const response = await apiClient.get<InvoiceResponse>(`/invoices/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get invoices by booking ID
|
||||
* GET /api/invoices/booking/:bookingId
|
||||
*/
|
||||
export const getInvoicesByBooking = async (bookingId: number): Promise<InvoiceResponse> => {
|
||||
const response = await apiClient.get<InvoiceResponse>(`/invoices/booking/${bookingId}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create invoice from booking
|
||||
* POST /api/invoices
|
||||
*/
|
||||
export const createInvoice = async (data: CreateInvoiceData): Promise<InvoiceResponse> => {
|
||||
const response = await apiClient.post<InvoiceResponse>('/invoices', data);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update invoice
|
||||
* PUT /api/invoices/:id
|
||||
*/
|
||||
export const updateInvoice = async (id: number, data: UpdateInvoiceData): Promise<InvoiceResponse> => {
|
||||
const response = await apiClient.put<InvoiceResponse>(`/invoices/${id}`, data);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mark invoice as paid
|
||||
* POST /api/invoices/:id/mark-paid
|
||||
*/
|
||||
export const markInvoiceAsPaid = async (id: number, amount?: number): Promise<InvoiceResponse> => {
|
||||
const response = await apiClient.post<InvoiceResponse>(`/invoices/${id}/mark-paid`, { amount });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete invoice
|
||||
* DELETE /api/invoices/:id
|
||||
*/
|
||||
export const deleteInvoice = async (id: number): Promise<{ status: string; message: string }> => {
|
||||
const response = await apiClient.delete<{ status: string; message: string }>(`/invoices/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
const invoiceService = {
|
||||
getInvoices,
|
||||
getInvoiceById,
|
||||
getInvoicesByBooking,
|
||||
createInvoice,
|
||||
updateInvoice,
|
||||
markInvoiceAsPaid,
|
||||
deleteInvoice,
|
||||
};
|
||||
|
||||
export default invoiceService;
|
||||
|
||||
Reference in New Issue
Block a user