- 新增 src/api/points.ts - 积分 API 客户端 - 新增 src/api/ledger.ts - 账务 API 客户端 - 新增 src/types/points.ts - 积分类型定义 - 新增 src/types/ledger.ts - 账务类型定义 - 更新 src/api/index.ts - 导出新增模块
142 lines
3.2 KiB
TypeScript
142 lines
3.2 KiB
TypeScript
/**
|
|
* 账务 API 客户端
|
|
* 提供会计科目、分录查询等功能
|
|
*/
|
|
import apiClient from './client'
|
|
import type {
|
|
AccountingSubject,
|
|
LedgerEntry,
|
|
LedgerEntryQuery,
|
|
} from '@/types/ledger'
|
|
import type { PageResponse } from '@/types/api'
|
|
|
|
export class LedgerAPI {
|
|
/**
|
|
* 获取会计科目列表
|
|
* @returns 会计科目列表
|
|
*/
|
|
static async getSubjects(): Promise<AccountingSubject[]> {
|
|
return apiClient.get('/ledger/subjects')
|
|
}
|
|
|
|
/**
|
|
* 获取会计科目详情
|
|
* @param code 科目代码
|
|
* @returns 会计科目
|
|
*/
|
|
static async getSubject(code: string): Promise<AccountingSubject> {
|
|
return apiClient.get(`/ledger/subjects/${code}`)
|
|
}
|
|
|
|
/**
|
|
* 获取分录详情
|
|
* @param id 分录ID
|
|
* @returns 分录详情(包含明细行)
|
|
*/
|
|
static async getEntry(id: number): Promise<LedgerEntry> {
|
|
return apiClient.get(`/ledger/entries/${id}`)
|
|
}
|
|
|
|
/**
|
|
* 获取账户分录列表
|
|
* @param accountId 账户ID
|
|
* @param accountType 账户类型 (physical/virtual)
|
|
* @param query 查询参数
|
|
* @returns 分页的分录列表
|
|
*/
|
|
static async getAccountEntries(
|
|
accountId: number,
|
|
accountType: 'physical' | 'virtual',
|
|
query?: LedgerEntryQuery
|
|
): Promise<PageResponse<LedgerEntry>> {
|
|
return apiClient.get(`/ledger/accounts/${accountId}/entries`, {
|
|
params: { account_type: accountType, ...query }
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 根据交易号获取分录
|
|
* @param txnNo 交易号
|
|
* @returns 分录详情
|
|
*/
|
|
static async getEntryByTxnNo(txnNo: string): Promise<LedgerEntry> {
|
|
return apiClient.get(`/ledger/entries/by-txn/${txnNo}`)
|
|
}
|
|
|
|
/**
|
|
* 获取账户余额变动历史
|
|
* @param accountId 账户ID
|
|
* @param accountType 账户类型
|
|
* @param query 查询参数
|
|
* @returns 余额变动记录
|
|
*/
|
|
static async getBalanceHistory(
|
|
accountId: number,
|
|
accountType: 'physical' | 'virtual',
|
|
query?: BalanceHistoryQuery
|
|
): Promise<PageResponse<BalanceChange>> {
|
|
return apiClient.get(`/ledger/accounts/${accountId}/balance-history`, {
|
|
params: { account_type: accountType, ...query }
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取科目汇总报表
|
|
* @param query 查询参数
|
|
* @returns 科目汇总数据
|
|
*/
|
|
static async getSubjectSummary(query: SubjectSummaryQuery): Promise<SubjectSummary[]> {
|
|
return apiClient.get('/ledger/reports/subject-summary', { params: query })
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 余额变动查询参数
|
|
*/
|
|
export interface BalanceHistoryQuery {
|
|
start_date?: string
|
|
end_date?: string
|
|
page?: number
|
|
page_size?: number
|
|
}
|
|
|
|
/**
|
|
* 余额变动记录
|
|
*/
|
|
export interface BalanceChange {
|
|
id: number
|
|
account_id: number
|
|
account_type: string
|
|
change_type: string
|
|
amount: string
|
|
balance_before: string
|
|
balance_after: string
|
|
txn_no?: string
|
|
description?: string
|
|
created_at: string
|
|
}
|
|
|
|
/**
|
|
* 科目汇总查询参数
|
|
*/
|
|
export interface SubjectSummaryQuery {
|
|
start_date: string
|
|
end_date: string
|
|
subject_code?: string
|
|
}
|
|
|
|
/**
|
|
* 科目汇总数据
|
|
*/
|
|
export interface SubjectSummary {
|
|
subject_code: string
|
|
subject_name: string
|
|
debit_total: string
|
|
credit_total: string
|
|
balance: string
|
|
transaction_count: number
|
|
}
|
|
|
|
export default LedgerAPI
|
|
|