feat(orders): issued-order query options + types
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
75
src/admin/lib/queries/issued-orders.ts
Normal file
75
src/admin/lib/queries/issued-orders.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import { queryOptions } from "@tanstack/react-query";
|
||||||
|
import { jsonQuery, paginatedJsonQuery } from "../apiAdapter";
|
||||||
|
|
||||||
|
export interface IssuedOrder {
|
||||||
|
id: number;
|
||||||
|
po_number: string | null;
|
||||||
|
customer_id: number | null;
|
||||||
|
customer_name: string | null;
|
||||||
|
status: string;
|
||||||
|
currency: string | null;
|
||||||
|
order_date: string | null;
|
||||||
|
subtotal: number;
|
||||||
|
vat_amount: number;
|
||||||
|
total: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IssuedOrderItem {
|
||||||
|
id?: number;
|
||||||
|
description: string | null;
|
||||||
|
item_description: string | null;
|
||||||
|
quantity: number | string | null;
|
||||||
|
unit: string | null;
|
||||||
|
unit_price: number | string | null;
|
||||||
|
vat_rate: number | string | null;
|
||||||
|
position?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IssuedOrderDetail extends IssuedOrder {
|
||||||
|
apply_vat: boolean | null;
|
||||||
|
vat_rate: number | string | null;
|
||||||
|
exchange_rate: number | string | null;
|
||||||
|
delivery_date: string | null;
|
||||||
|
language: string | null;
|
||||||
|
delivery_terms: string | null;
|
||||||
|
payment_terms: string | null;
|
||||||
|
issued_by: string | null;
|
||||||
|
notes: string | null;
|
||||||
|
internal_notes: string | null;
|
||||||
|
items: IssuedOrderItem[];
|
||||||
|
customer: Record<string, unknown> | null;
|
||||||
|
valid_transitions: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const issuedOrderListOptions = (filters: {
|
||||||
|
search?: string;
|
||||||
|
sort?: string;
|
||||||
|
order?: string;
|
||||||
|
page?: number;
|
||||||
|
perPage?: number;
|
||||||
|
status?: string;
|
||||||
|
}) =>
|
||||||
|
queryOptions({
|
||||||
|
queryKey: ["issued-orders", "list", filters],
|
||||||
|
queryFn: () => {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (filters.search) params.set("search", filters.search);
|
||||||
|
if (filters.sort) params.set("sort", filters.sort);
|
||||||
|
if (filters.order) params.set("order", filters.order);
|
||||||
|
if (filters.page) params.set("page", String(filters.page));
|
||||||
|
if (filters.perPage) params.set("per_page", String(filters.perPage));
|
||||||
|
if (filters.status) params.set("status", filters.status);
|
||||||
|
const qs = params.toString();
|
||||||
|
return paginatedJsonQuery<IssuedOrder>(
|
||||||
|
`/api/admin/issued-orders${qs ? `?${qs}` : ""}`,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const issuedOrderDetailOptions = (id: string | undefined) =>
|
||||||
|
queryOptions({
|
||||||
|
queryKey: ["issued-orders", id],
|
||||||
|
queryFn: () =>
|
||||||
|
jsonQuery<IssuedOrderDetail>(`/api/admin/issued-orders/${id}`),
|
||||||
|
enabled: !!id,
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user