137 lines
3.4 KiB
TypeScript
137 lines
3.4 KiB
TypeScript
import { request } from "./http";
|
|
|
|
export interface PurchaseOrderLine {
|
|
id: number;
|
|
purchase_order_id: number;
|
|
product_id: number | null;
|
|
description: string;
|
|
quantity: number;
|
|
unit_price: number;
|
|
tva_rate: number;
|
|
discount_pct: number;
|
|
total_ht: number;
|
|
created_at: string;
|
|
updated_at: string;
|
|
product?: any;
|
|
}
|
|
|
|
export interface PurchaseOrder {
|
|
id: number;
|
|
fournisseur_id: number;
|
|
po_number: string;
|
|
status: 'brouillon' | 'confirmee' | 'livree' | 'facturee' | 'annulee';
|
|
order_date: string;
|
|
expected_date: string | null;
|
|
currency: string;
|
|
total_ht: number;
|
|
total_tva: number;
|
|
total_ttc: number;
|
|
notes: string | null;
|
|
delivery_address: string | null;
|
|
created_at: string;
|
|
updated_at: string;
|
|
fournisseur?: any;
|
|
lines?: PurchaseOrderLine[];
|
|
}
|
|
|
|
export interface PurchaseOrderListResponse {
|
|
data: PurchaseOrder[];
|
|
meta?: {
|
|
current_page: number;
|
|
last_page: number;
|
|
per_page: number;
|
|
total: number;
|
|
};
|
|
}
|
|
|
|
export interface PurchaseOrderResponse {
|
|
data: PurchaseOrder;
|
|
}
|
|
|
|
export interface CreatePurchaseOrderLinePayload {
|
|
product_id?: number | null;
|
|
description: string;
|
|
quantity: number;
|
|
unit_price: number;
|
|
tva_rate?: number;
|
|
discount_pct?: number;
|
|
}
|
|
|
|
export interface CreatePurchaseOrderPayload {
|
|
fournisseur_id: number;
|
|
po_number?: string;
|
|
status?: string;
|
|
order_date?: string;
|
|
expected_date?: string | null;
|
|
currency?: string;
|
|
notes?: string | null;
|
|
delivery_address?: string | null;
|
|
lines?: CreatePurchaseOrderLinePayload[];
|
|
}
|
|
|
|
export interface UpdatePurchaseOrderPayload extends Partial<CreatePurchaseOrderPayload> {
|
|
id: number;
|
|
}
|
|
|
|
export const PurchaseOrderService = {
|
|
async getAllPurchaseOrders(params?: {
|
|
page?: number;
|
|
per_page?: number;
|
|
search?: string;
|
|
status?: string;
|
|
fournisseur_id?: number;
|
|
}): Promise<PurchaseOrderListResponse> {
|
|
const response = await request<PurchaseOrderListResponse>({
|
|
url: "/api/purchase-orders",
|
|
method: "get",
|
|
params,
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async getPurchaseOrder(id: number): Promise<PurchaseOrderResponse> {
|
|
const response = await request<PurchaseOrderResponse>({
|
|
url: `/api/purchase-orders/${id}`,
|
|
method: "get",
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async createPurchaseOrder(payload: CreatePurchaseOrderPayload): Promise<PurchaseOrderResponse> {
|
|
const response = await request<PurchaseOrderResponse>({
|
|
url: "/api/purchase-orders",
|
|
method: "post",
|
|
data: payload,
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async updatePurchaseOrder(payload: UpdatePurchaseOrderPayload): Promise<PurchaseOrderResponse> {
|
|
const { id, ...updateData } = payload;
|
|
const response = await request<PurchaseOrderResponse>({
|
|
url: `/api/purchase-orders/${id}`,
|
|
method: "put",
|
|
data: updateData,
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async deletePurchaseOrder(id: number): Promise<{ success: boolean; message: string }> {
|
|
const response = await request<{ success: boolean; message: string }>({
|
|
url: `/api/purchase-orders/${id}`,
|
|
method: "delete",
|
|
});
|
|
return response;
|
|
},
|
|
|
|
async getByFournisseur(fournisseurId: number): Promise<PurchaseOrderListResponse> {
|
|
const response = await request<PurchaseOrderListResponse>({
|
|
url: `/api/fournisseurs/${fournisseurId}/purchase-orders`,
|
|
method: "get",
|
|
});
|
|
return response;
|
|
},
|
|
};
|
|
|
|
export default PurchaseOrderService;
|