Files
ERP_Distribution/distribution_fe/lib/api/sales.ts
T
Kalana B. Thilakarathna eb0b042f0c
CI/CD - ERP Distribution / Build & Deploy Frontend (pull_request) Successful in 1m51s
CI/CD - ERP Distribution / Build & Deploy Backend (pull_request) Failing after 10m54s
feat: integrate payment functionality with new payment sheet and enhance supplier payments UI
2026-10-19 22:02:15 +05:30

115 lines
3.8 KiB
TypeScript

import { api } from '@/lib/api'
import type {
PaginatedResponse,
ShopPOResponse,
InvoiceResponse,
InvoiceStatus,
PaymentStatus,
PaymentResponse,
PaymentMethod,
EntryMode,
ShopPOStatus,
OutstandingPaymentsResponse,
} 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[]
raisedByUserId?: string | null
}
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, confirmedByUserId?: string | null) =>
api.post<ShopPOResponse>(`/shop-pos/${id}/confirm`, { confirmedByUserId }).then(r => r.data),
confirmAndCreateInvoice: (id: string, confirmedByUserId?: string | null) =>
api.post<ShopPOResponse>(`/shop-pos/${id}/confirm-and-create-invoice`, { confirmedByUserId }).then(r => r.data),
cancel: (id: string, reason: string, cancelledByUserId?: string | null) =>
api.post<ShopPOResponse>(`/shop-pos/${id}/cancel`, { reason, cancelledByUserId }).then(r => r.data),
}
// ─── Invoices ─────────────────────────────────────────────────────────────────
export interface InvoiceListParams extends PageParams {
agentId?: string
routeId?: string
shopId?: string
status?: InvoiceStatus
paymentStatus?: PaymentStatus
}
export const invoices = {
list: (params?: InvoiceListParams) =>
api.get<PaginatedResponse<InvoiceResponse>>('/invoices', { params }).then(r => r.data),
outstandingSummary: () =>
api.get<OutstandingPaymentsResponse>('/invoices/outstanding-summary').then(r => r.data),
get: (id: string) =>
api.get<InvoiceResponse>(`/invoices/${id}`).then(r => r.data),
print: (id: string, printedByUserId?: string | null) =>
api.post<InvoiceResponse>(`/invoices/${id}/print`, { printedByUserId }).then(r => r.data),
finalize: (id: string, finalizedByUserId?: string | null) =>
api.post<InvoiceResponse>(`/invoices/${id}/finalize`, { finalizedByUserId }).then(r => r.data),
}
// ─── Payments ─────────────────────────────────────────────────────────────────
export interface PaymentBody {
amount: number
method: PaymentMethod
entryMode?: EntryMode
bankAccountId?: string | null
chequeNumber?: string | null
chequeDate?: string | null
drawerBankName?: string | null
accountHolderName?: 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),
}