Files
ERP_Distribution/distribution_fe/lib/api/expenses.ts
T
Kalana B. Thilakarathna c775146b64
CI/CD - ERP Distribution / Build & Deploy Frontend (pull_request) Failing after 13m39s
CI/CD - ERP Distribution / Build & Deploy Backend (pull_request) Failing after 15m1s
10.
Implementation
A partner, not just software
HexDive Technologies' local team handles setup, data migration, training and ongoing support — in Sinhala, Tamil and English. [confirm]

1
Discovery
Map your network, products and processes.

2
Configuration
Set up depots, pricing, schemes, routes and users.

3
Migration & training
Move your data and train every team.

4
Go-live & support
Dedicated account manager and local support desk.
2026-10-22 17:47:49 +05:30

118 lines
3.8 KiB
TypeScript

import { api } from '@/lib/api'
import type {
CreateExpenseCategoryRequest,
CreateExpenseRequest,
CreateExpenseVendorRequest,
CreateRecurringExpenseRequest,
ExpenseAction,
ExpenseAttachmentResponse,
ExpenseCategoryResponse,
ExpensePaymentRequest,
ExpenseResponse,
ExpenseStatus,
ExpenseVendorResponse,
PagedExpenseVendorsResponse,
PagedExpensesResponse,
PagedRecurringExpensesResponse,
RecurringExpenseResponse,
RunDueResponse,
UpdateExpenseCategoryRequest,
UpdateExpenseDraftRequest,
UpdateExpenseVendorRequest,
UpdateRecurringExpenseRequest,
} from '@/types/expenses'
// Categories
export const expenseCategories = {
tree: () =>
api.get<ExpenseCategoryResponse[]>('/expense-categories').then(r => r.data),
create: (body: CreateExpenseCategoryRequest) =>
api.post<ExpenseCategoryResponse>('/expense-categories', body).then(r => r.data),
update: (id: string, body: UpdateExpenseCategoryRequest) =>
api.put<ExpenseCategoryResponse>(`/expense-categories/${id}`, body).then(r => r.data),
}
// Vendors
export const expenseVendors = {
list: (params?: { search?: string; page?: number; pageSize?: number }) =>
api.get<PagedExpenseVendorsResponse>('/expense-vendors', { params }).then(r => r.data),
create: (body: CreateExpenseVendorRequest) =>
api.post<ExpenseVendorResponse>('/expense-vendors', body).then(r => r.data),
update: (id: string, body: UpdateExpenseVendorRequest) =>
api.put<ExpenseVendorResponse>(`/expense-vendors/${id}`, body).then(r => r.data),
}
// Expenses
export interface ExpenseListParams {
status?: ExpenseStatus
categoryId?: string
warehouseId?: string
from?: string
to?: string
page?: number
pageSize?: number
}
export const expenses = {
list: (params?: ExpenseListParams) =>
api.get<PagedExpensesResponse>('/expenses', { params }).then(r => r.data),
get: (id: string) =>
api.get<ExpenseResponse>(`/expenses/${id}`).then(r => r.data),
create: (body: CreateExpenseRequest, action: ExpenseAction = 'Draft') =>
api.post<ExpenseResponse>('/expenses', body, { params: { action } }).then(r => r.data),
updateDraft: (id: string, body: UpdateExpenseDraftRequest) =>
api.put<ExpenseResponse>(`/expenses/${id}`, body).then(r => r.data),
post: (id: string) =>
api.post<ExpenseResponse>(`/expenses/${id}/post`).then(r => r.data),
pay: (id: string, body: ExpensePaymentRequest) =>
api.post<ExpenseResponse>(`/expenses/${id}/pay`, body).then(r => r.data),
void: (id: string, reason?: string) =>
api.post<ExpenseResponse>(`/expenses/${id}/void`, { reason }).then(r => r.data),
uploadAttachment: (expenseId: string, file: File) => {
const form = new FormData()
form.append('file', file)
return api.post<ExpenseAttachmentResponse>(`/expenses/${expenseId}/attachments`, form, {
headers: { 'Content-Type': 'multipart/form-data' },
}).then(r => r.data)
},
downloadAttachmentUrl: (attachmentId: string) =>
`${api.defaults.baseURL}/expense-attachments/${attachmentId}/download`,
deleteAttachment: (attachmentId: string) =>
api.delete(`/expense-attachments/${attachmentId}`),
}
// Recurring
export const recurringExpenses = {
list: (params?: { page?: number; pageSize?: number }) =>
api.get<PagedRecurringExpensesResponse>('/recurring-expenses', { params }).then(r => r.data),
create: (body: CreateRecurringExpenseRequest) =>
api.post<RecurringExpenseResponse>('/recurring-expenses', body).then(r => r.data),
update: (id: string, body: UpdateRecurringExpenseRequest) =>
api.put<RecurringExpenseResponse>(`/recurring-expenses/${id}`, body).then(r => r.data),
toggle: (id: string, paused: boolean) =>
api.post<RecurringExpenseResponse>(`/recurring-expenses/${id}/toggle`, { paused }).then(r => r.data),
runDue: () =>
api.post<RunDueResponse>('/recurring-expenses/run-due').then(r => r.data),
}