Files
ERP_Distribution/distribution_fe/lib/api/sales.ts
T
Kalana B. Thilakarathna 2de9e5e4ad
CI/CD - ERP Distribution / Build & Deploy Frontend (pull_request) Failing after 13m13s
CI/CD - ERP Distribution / Build & Deploy Backend (pull_request) Failing after 14m28s
Add manual invoice creation mode with new API & UI flow
Introduced "ModeB" for manual invoice creation in system config. Added backend endpoints and service logic for creating invoices from confirmed Shop POs, with validation and error handling. Updated DTOs to support optional CreatedByUserId. On the frontend, added configuration card to toggle modes, a dialog for manual invoice creation, and UI updates to support the new workflow. Enables admins to choose between automatic and manual invoice creation.
2026-10-20 13:38:43 +05:30

121 lines
4.2 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),
confirmedWithoutInvoice: (params?: { agentId?: string; routeId?: string; shopId?: string }) =>
api.get<ShopPOResponse[]>('/shop-pos/confirmed-without-invoice', { params }).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),
create: (shopPOId: string, createdByUserId?: string | null) =>
api.post<InvoiceResponse>('/invoices', { shopPOId, createdByUserId }).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),
}