112 lines
3.6 KiB
TypeScript
112 lines
3.6 KiB
TypeScript
import { api } from '@/lib/api'
|
|
import type {
|
|
PaginatedResponse,
|
|
PurchaseOrderResponse,
|
|
GrnResponse,
|
|
PurchaseOrderStatus,
|
|
PurchaseReturnResponse,
|
|
} 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[]
|
|
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
|
createdByUserId: string
|
|
}
|
|
|
|
export interface UpdatePurchaseOrderLineBody {
|
|
purchaseOrderItemId?: string
|
|
itemId: string
|
|
quantity: number
|
|
unitCost: number
|
|
}
|
|
|
|
export interface UpdatePurchaseOrderBody {
|
|
items: UpdatePurchaseOrderLineBody[]
|
|
}
|
|
|
|
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),
|
|
|
|
update: (id: string, body: UpdatePurchaseOrderBody) =>
|
|
api.put<PurchaseOrderResponse>(`/purchase-orders/${id}`, body).then(r => r.data),
|
|
|
|
cancel: (id: string, reason: string) =>
|
|
api.post<PurchaseOrderResponse>(`/purchase-orders/${id}/cancel`, { reason }).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[]
|
|
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
|
receivedByUserId: string
|
|
}
|
|
|
|
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),
|
|
}
|
|
|
|
// ─── Purchase Returns ─────────────────────────────────────────────────────────
|
|
|
|
export interface PurchaseReturnItemBody {
|
|
itemId: string
|
|
quantity: number
|
|
}
|
|
|
|
export interface PurchaseReturnBody {
|
|
reason: string
|
|
items: PurchaseReturnItemBody[]
|
|
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
|
createdByUserId: string
|
|
}
|
|
|
|
export const purchaseReturns = {
|
|
get: (id: string) =>
|
|
api.get<PurchaseReturnResponse>(`/purchase-returns/${id}`).then(r => r.data),
|
|
|
|
listByPurchaseOrder: (purchaseOrderId: string) =>
|
|
api.get<PurchaseReturnResponse[]>(`/purchase-orders/${purchaseOrderId}/returns`).then(r => r.data),
|
|
|
|
create: (purchaseOrderId: string, body: PurchaseReturnBody) =>
|
|
api.post<PurchaseReturnResponse>(`/purchase-orders/${purchaseOrderId}/returns`, body).then(r => r.data),
|
|
}
|