Files
ERP_Distribution/distribution_fe/lib/api/sales.ts
T
DeepnaPooja 35fa3b19e3
CI/CD - ERP Distribution / Build & Deploy Frontend (pull_request) Failing after 13m56s
CI/CD - ERP Distribution / Build & Deploy Backend (pull_request) Failing after 15m12s
Add loading sheet item selection
2026-09-22 17:03:24 +05:30

105 lines
3.2 KiB
TypeScript

import { api } from '@/lib/api'
import type {
PaginatedResponse,
ShopPOResponse,
InvoiceResponse,
InvoiceStatus,
PaymentResponse,
PaymentMethod,
EntryMode,
ShopPOStatus,
} from '@/types/api'
import type { PageParams } from './master'
// ─── Shop POs ─────────────────────────────────────────────────────────────────
export interface ShopPOItemBody {
itemId: string
quantity: number
unitPrice?: number | null
}
export interface CreateShopPOBody {
storeId: string
items: ShopPOItemBody[]
}
export interface UpdateShopPOItemsBody {
items: ShopPOItemBody[]
}
export interface ShopPOListParams extends PageParams {
agentId?: string
routeId?: string
regionId?: string
shopId?: string
confirmed?: boolean
status?: ShopPOStatus
}
export const shopPos = {
list: (params?: ShopPOListParams) =>
api.get<PaginatedResponse<ShopPOResponse>>('/shop-pos', { params }).then(r => r.data),
get: (id: string) =>
api.get<ShopPOResponse>(`/shop-pos/${id}`).then(r => r.data),
create: (body: CreateShopPOBody) =>
api.post<ShopPOResponse>('/shop-pos', body).then(r => r.data),
updateItems: (id: string, body: UpdateShopPOItemsBody) =>
api.put<ShopPOResponse>(`/shop-pos/${id}/items`, body).then(r => r.data),
confirm: (id: string) =>
api.post<ShopPOResponse>(`/shop-pos/${id}/confirm`).then(r => r.data),
confirmAndCreateInvoice: (id: string) =>
api.post<ShopPOResponse>(`/shop-pos/${id}/confirm-and-create-invoice`).then(r => r.data),
cancel: (id: string) =>
api.post<ShopPOResponse>(`/shop-pos/${id}/cancel`).then(r => r.data),
}
// ─── Invoices ─────────────────────────────────────────────────────────────────
export interface InvoiceListParams extends PageParams {
agentId?: string
routeId?: string
shopId?: string
status?: InvoiceStatus
}
export const invoices = {
list: (params?: InvoiceListParams) =>
api.get<PaginatedResponse<InvoiceResponse>>('/invoices', { params }).then(r => r.data),
get: (id: string) =>
api.get<InvoiceResponse>(`/invoices/${id}`).then(r => r.data),
print: (id: string) =>
api.post<InvoiceResponse>(`/invoices/${id}/print`).then(r => r.data),
finalize: (id: string) =>
api.post<InvoiceResponse>(`/invoices/${id}/finalize`).then(r => r.data),
}
// ─── Payments ─────────────────────────────────────────────────────────────────
export interface PaymentBody {
amount: number
method: PaymentMethod
entryMode?: EntryMode
chequeNumber?: string | null
chequeDate?: string | null
collectedByUserId?: string | null
}
export const payments = {
listByInvoice: (invoiceId: string) =>
api.get<PaymentResponse[]>(`/invoices/${invoiceId}/payments`).then(r => r.data),
create: (invoiceId: string, body: PaymentBody) =>
api.post<PaymentResponse>(`/invoices/${invoiceId}/payments`, body).then(r => r.data),
}