Add supplier claims management components and API integration
This commit is contained in:
@@ -5,10 +5,11 @@ export { stores } from './stores'
|
||||
export { suppliers } from './suppliers'
|
||||
export { users, roles, permissions } from './users'
|
||||
export { drivers, compliance } from './drivers'
|
||||
export { purchaseOrders, grn } from './procurement'
|
||||
export { purchaseOrders, grn, purchaseReturns } from './procurement'
|
||||
export { rides, loadingSheets, deliveryTasks } from './operations'
|
||||
export { stock } from './stock'
|
||||
export { sales, orders, payments } from './sales'
|
||||
export { saleReturns, claims, supplierClaims } from './returns-claims'
|
||||
export { getPaginatedItems } from './paginated'
|
||||
|
||||
export type { PageParams } from './master'
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
PurchaseOrderResponse,
|
||||
GrnResponse,
|
||||
PurchaseOrderStatus,
|
||||
PurchaseReturnResponse,
|
||||
} from '@/types/api'
|
||||
|
||||
import type { PageParams } from './master'
|
||||
@@ -19,6 +20,19 @@ export interface PurchaseOrderItemBody {
|
||||
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 {
|
||||
@@ -36,8 +50,11 @@ export const purchaseOrders = {
|
||||
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),
|
||||
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) ─────────────────────────────────────────────────────
|
||||
@@ -53,6 +70,8 @@ export interface GrnBody {
|
||||
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 = {
|
||||
@@ -65,3 +84,28 @@ export const grn = {
|
||||
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),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
import { api } from '@/lib/api'
|
||||
import type {
|
||||
SaleReturnResponse,
|
||||
ReturnMode,
|
||||
ReturnReasonCode,
|
||||
ClaimResponse,
|
||||
SupplierClaimResponse,
|
||||
SupplierClaimIssueType,
|
||||
SupplierClaimResolutionType,
|
||||
} from '@/types/api'
|
||||
|
||||
// ─── Sale Returns (order returns) ──────────────────────────────────────────────
|
||||
|
||||
export interface SaleReturnItemBody {
|
||||
itemId: string
|
||||
quantity: number
|
||||
reasonCode: ReturnReasonCode
|
||||
}
|
||||
|
||||
export interface SaleReturnBody {
|
||||
mode: ReturnMode
|
||||
items: SaleReturnItemBody[]
|
||||
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
||||
createdByUserId: string
|
||||
}
|
||||
|
||||
export interface UpdateSaleReturnReasonsBody {
|
||||
items: { itemId: string; reasonCode: ReturnReasonCode }[]
|
||||
}
|
||||
|
||||
export const saleReturns = {
|
||||
list: () =>
|
||||
api.get<SaleReturnResponse[]>('/returns').then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<SaleReturnResponse>(`/returns/${id}`).then(r => r.data),
|
||||
|
||||
listByOrder: (orderId: string) =>
|
||||
api.get<SaleReturnResponse[]>(`/orders/${orderId}/returns`).then(r => r.data),
|
||||
|
||||
create: (orderId: string, body: SaleReturnBody) =>
|
||||
api.post<SaleReturnResponse>(`/orders/${orderId}/returns`, body).then(r => r.data),
|
||||
|
||||
updateReasons: (id: string, body: UpdateSaleReturnReasonsBody) =>
|
||||
api.patch<SaleReturnResponse>(`/returns/${id}/reasons`, body).then(r => r.data),
|
||||
}
|
||||
|
||||
// ─── Claims (agency claims) ────────────────────────────────────────────────────
|
||||
|
||||
export interface ClaimBody {
|
||||
agencyUserId: string
|
||||
details: string
|
||||
}
|
||||
|
||||
export interface SettleClaimBody {
|
||||
settlementAmount: number
|
||||
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
||||
settledByUserId: string
|
||||
}
|
||||
|
||||
export const claims = {
|
||||
list: () =>
|
||||
api.get<ClaimResponse[]>('/claims').then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<ClaimResponse>(`/claims/${id}`).then(r => r.data),
|
||||
|
||||
create: (body: ClaimBody) =>
|
||||
api.post<ClaimResponse>('/claims', body).then(r => r.data),
|
||||
|
||||
update: (id: string, body: ClaimBody) =>
|
||||
api.put<ClaimResponse>(`/claims/${id}`, body).then(r => r.data),
|
||||
|
||||
settle: (id: string, body: SettleClaimBody) =>
|
||||
api.post<ClaimResponse>(`/claims/${id}/settle`, body).then(r => r.data),
|
||||
}
|
||||
|
||||
// ─── Supplier Claims ────────────────────────────────────────────────────────────
|
||||
|
||||
export interface SupplierClaimItemBody {
|
||||
itemId: string
|
||||
quantity: number
|
||||
issueType: SupplierClaimIssueType
|
||||
}
|
||||
|
||||
export interface SupplierClaimBody {
|
||||
goodsReceiptId?: string
|
||||
details: string
|
||||
evidenceUrl?: string
|
||||
items: SupplierClaimItemBody[]
|
||||
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
||||
raisedByUserId: string
|
||||
}
|
||||
|
||||
export interface ApproveSupplierClaimBody {
|
||||
resolutionType: SupplierClaimResolutionType
|
||||
resolutionAmount?: number
|
||||
resolutionNotes?: string
|
||||
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
||||
approvedByUserId: string
|
||||
}
|
||||
|
||||
export interface RejectSupplierClaimBody {
|
||||
resolutionNotes?: string
|
||||
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
||||
rejectedByUserId: string
|
||||
}
|
||||
|
||||
export const supplierClaims = {
|
||||
list: () =>
|
||||
api.get<SupplierClaimResponse[]>('/supplier-claims').then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<SupplierClaimResponse>(`/supplier-claims/${id}`).then(r => r.data),
|
||||
|
||||
listByPurchaseOrder: (purchaseOrderId: string) =>
|
||||
api.get<SupplierClaimResponse[]>(`/purchase-orders/${purchaseOrderId}/claims`).then(r => r.data),
|
||||
|
||||
create: (purchaseOrderId: string, body: SupplierClaimBody) =>
|
||||
api.post<SupplierClaimResponse>(`/purchase-orders/${purchaseOrderId}/claims`, body).then(r => r.data),
|
||||
|
||||
update: (id: string, body: { details: string; evidenceUrl?: string; items: SupplierClaimItemBody[] }) =>
|
||||
api.put<SupplierClaimResponse>(`/supplier-claims/${id}`, body).then(r => r.data),
|
||||
|
||||
approve: (id: string, body: ApproveSupplierClaimBody) =>
|
||||
api.post<SupplierClaimResponse>(`/supplier-claims/${id}/approve`, body).then(r => r.data),
|
||||
|
||||
reject: (id: string, body: RejectSupplierClaimBody) =>
|
||||
api.post<SupplierClaimResponse>(`/supplier-claims/${id}/reject`, body).then(r => r.data),
|
||||
}
|
||||
Reference in New Issue
Block a user