68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import { api } from '@/lib/api'
|
|
import type {
|
|
PaginatedResponse,
|
|
PurchaseOrderResponse,
|
|
GrnResponse,
|
|
PurchaseOrderStatus,
|
|
} from '@/types/api'
|
|
|
|
import type { PageParams } from './master'
|
|
|
|
// ─── Purchase Orders ──────────────────────────────────────────────────────────
|
|
|
|
export interface PurchaseOrderItemBody {
|
|
itemId: string
|
|
quantity: number
|
|
unitCost: number
|
|
}
|
|
|
|
export interface PurchaseOrderBody {
|
|
supplierId: string
|
|
items: PurchaseOrderItemBody[]
|
|
}
|
|
|
|
export interface PurchaseOrderListParams extends PageParams {
|
|
supplierId?: string
|
|
status?: PurchaseOrderStatus
|
|
}
|
|
|
|
export const purchaseOrders = {
|
|
list: (params?: PurchaseOrderListParams) =>
|
|
api.get<PaginatedResponse<PurchaseOrderResponse>>('/purchase-orders', { params }).then(r => r.data),
|
|
|
|
get: (id: string) =>
|
|
api.get<PurchaseOrderResponse>(`/purchase-orders/${id}`).then(r => r.data),
|
|
|
|
create: (body: PurchaseOrderBody) =>
|
|
api.post<PurchaseOrderResponse>('/purchase-orders', body).then(r => r.data),
|
|
|
|
cancel: (id: string, cancelReason: string) =>
|
|
api.patch<PurchaseOrderResponse>(`/purchase-orders/${id}/cancel`, { cancelReason }).then(r => r.data),
|
|
}
|
|
|
|
// ─── Goods Receipts (GRN) ─────────────────────────────────────────────────────
|
|
|
|
export interface GrnItemBody {
|
|
purchaseOrderItemId: string
|
|
acceptedQuantity: number
|
|
rejectedQuantity: number
|
|
}
|
|
|
|
export interface GrnBody {
|
|
purchaseOrderId: string
|
|
warehouseId: string
|
|
receivedAt: string
|
|
items: GrnItemBody[]
|
|
}
|
|
|
|
export const grn = {
|
|
list: (params?: PageParams & { purchaseOrderId?: string }) =>
|
|
api.get<PaginatedResponse<GrnResponse>>('/goods-receipts', { params }).then(r => r.data),
|
|
|
|
get: (id: string) =>
|
|
api.get<GrnResponse>(`/goods-receipts/${id}`).then(r => r.data),
|
|
|
|
create: (body: GrnBody) =>
|
|
api.post<GrnResponse>('/goods-receipts', body).then(r => r.data),
|
|
}
|