147 lines
3.5 KiB
TypeScript
147 lines
3.5 KiB
TypeScript
import { request } from "./http";
|
|
|
|
export interface SupplierInvoiceLine {
|
|
id: number;
|
|
supplier_invoice_id: number;
|
|
product_id: number | null;
|
|
purchase_order_line_id: number | null;
|
|
description: string;
|
|
quantity: number;
|
|
unit_price: number;
|
|
tva_rate: number;
|
|
total_ht: number;
|
|
created_at: string;
|
|
updated_at: string;
|
|
product?: any;
|
|
}
|
|
|
|
export interface SupplierInvoice {
|
|
id: number;
|
|
fournisseur_id: number;
|
|
purchase_order_id: number | null;
|
|
invoice_number: string;
|
|
invoice_date: string;
|
|
due_date: string | null;
|
|
status: "brouillon" | "en_attente" | "payee" | "annulee";
|
|
currency: string;
|
|
total_ht: number;
|
|
total_tva: number;
|
|
total_ttc: number;
|
|
notes: string | null;
|
|
created_at: string;
|
|
updated_at: string;
|
|
fournisseur?: any;
|
|
purchase_order?: any;
|
|
lines?: SupplierInvoiceLine[];
|
|
}
|
|
|
|
export interface SupplierInvoiceListResponse {
|
|
data: SupplierInvoice[];
|
|
meta?: {
|
|
current_page: number;
|
|
last_page: number;
|
|
per_page: number;
|
|
total: number;
|
|
};
|
|
}
|
|
|
|
export interface SupplierInvoiceResponse {
|
|
data: SupplierInvoice;
|
|
}
|
|
|
|
export interface CreateSupplierInvoiceLinePayload {
|
|
product_id?: number | null;
|
|
purchase_order_line_id?: number | null;
|
|
description: string;
|
|
quantity: number;
|
|
unit_price: number;
|
|
tva_rate?: number;
|
|
}
|
|
|
|
export interface CreateSupplierInvoicePayload {
|
|
fournisseur_id: number;
|
|
purchase_order_id?: number | null;
|
|
invoice_number?: string;
|
|
invoice_date?: string;
|
|
due_date?: string | null;
|
|
status?: string;
|
|
currency?: string;
|
|
notes?: string | null;
|
|
lines?: CreateSupplierInvoiceLinePayload[];
|
|
}
|
|
|
|
export interface UpdateSupplierInvoicePayload
|
|
extends Partial<CreateSupplierInvoicePayload> {
|
|
id: number;
|
|
}
|
|
|
|
export const SupplierInvoiceService = {
|
|
async getAllSupplierInvoices(params?: {
|
|
page?: number;
|
|
per_page?: number;
|
|
search?: string;
|
|
status?: string;
|
|
fournisseur_id?: number;
|
|
}): Promise<SupplierInvoiceListResponse> {
|
|
const response = await request<SupplierInvoiceListResponse>({
|
|
url: "/api/supplier-invoices",
|
|
method: "get",
|
|
params,
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async getSupplierInvoice(id: number): Promise<SupplierInvoiceResponse> {
|
|
const response = await request<SupplierInvoiceResponse>({
|
|
url: `/api/supplier-invoices/${id}`,
|
|
method: "get",
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async createSupplierInvoice(
|
|
payload: CreateSupplierInvoicePayload
|
|
): Promise<SupplierInvoiceResponse> {
|
|
const response = await request<SupplierInvoiceResponse>({
|
|
url: "/api/supplier-invoices",
|
|
method: "post",
|
|
data: payload,
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async updateSupplierInvoice(
|
|
payload: UpdateSupplierInvoicePayload
|
|
): Promise<SupplierInvoiceResponse> {
|
|
const { id, ...updateData } = payload;
|
|
const response = await request<SupplierInvoiceResponse>({
|
|
url: `/api/supplier-invoices/${id}`,
|
|
method: "put",
|
|
data: updateData,
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async deleteSupplierInvoice(
|
|
id: number
|
|
): Promise<{ success: boolean; message: string }> {
|
|
const response = await request<{ success: boolean; message: string }>({
|
|
url: `/api/supplier-invoices/${id}`,
|
|
method: "delete",
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async getByFournisseur(
|
|
fournisseurId: number
|
|
): Promise<SupplierInvoiceListResponse> {
|
|
const response = await request<SupplierInvoiceListResponse>({
|
|
url: `/api/fournisseurs/${fournisseurId}/supplier-invoices`,
|
|
method: "get",
|
|
});
|
|
return response;
|
|
},
|
|
};
|
|
|
|
export default SupplierInvoiceService;
|