This commit is contained in:
2026-08-20 18:02:24 +08:00
parent c93eea89c8
commit b0d527b016
8 changed files with 288 additions and 32 deletions
@@ -3,7 +3,7 @@ import { http } from '@/shared/api/http'
import {
adjustInboundFeeDetail, createInboundFeeDetail, deleteInboundFeeDetail, listInboundFeeDetails,
listInboundFeeItemOptions, listInboundFeeSupplierOptions, reviewInboundFeeDetail,
updateInboundFeeDetail, voidInboundFeeDetail, type SaveInboundFeeDetailRequest,
updateInboundFeeDetail, uploadInboundFeePaymentVoucher, voidInboundFeeDetail, type SaveInboundFeeDetailRequest,
} from './inboundFeeDetails'
vi.mock('@/shared/api/http', async () => {
@@ -19,7 +19,7 @@ describe('inbound fee-detail API', () => {
})
it('maps the complete write contract and optimistic version', async () => {
const payload: SaveInboundFeeDetailRequest = { feeItemId: '31', direction: 'PAYABLE', businessDate: '2026-08-12', unitPrice: 12.5, currency: 'CNY', amount: 125, supplierId: '41', remark: '验收' }
const payload: SaveInboundFeeDetailRequest = { feeItemId: '31', direction: 'PAYABLE', businessDate: '2026-08-12', unitPrice: 12.5, currency: 'CNY', amount: 125, supplierId: '41', settlementMode: 'DIRECT_PAID', paidAt: '2026-08-12T10:30:00', paymentMethod: 'BANK_TRANSFER', paymentReferenceNo: 'BANK-31', paymentVoucherFileIds: ['9001'], remark: '验收' }
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: [] })
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: null })
vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: payload })
@@ -34,6 +34,14 @@ describe('inbound fee-detail API', () => {
expect(http.delete).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11', { params: { accountId: '100' } })
})
it('reuses the scoped FINANCE_VOUCHER upload and fails closed on customer mismatch', async () => {
vi.mocked(http.post).mockResolvedValueOnce({ code: '200', data: { fileId: 9001, tenantId: 100, fileName: '付款凭证.pdf' } })
await expect(uploadInboundFeePaymentVoucher('100', new File(['x'], '付款凭证.pdf'))).resolves.toEqual({ fileId: '9001', fileName: '付款凭证.pdf' })
expect(http.post).toHaveBeenCalledWith('/platform/finance/v1/vouchers', expect.any(FormData), { params: { customerId: '100' }, headers: { 'Content-Type': 'multipart/form-data' } })
vi.mocked(http.post).mockResolvedValueOnce({ code: '200', data: { fileId: 9002, tenantId: 101, fileName: '错客户.pdf' } })
await expect(uploadInboundFeePaymentVoucher('100', new File(['x'], '错客户.pdf'))).rejects.toThrow('付款凭证与当前客户不匹配')
})
it('keeps an empty supplier category as null and rejects an unknown non-empty category', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [
{ id: 31, feeTypeName: '拖车费', feeCode: 'TRUCKING', supplierCategory: 'TRUCKING', warehousePayable: true },
@@ -3,6 +3,8 @@ import { listSuppliers, type SupplierCategory } from '@/modules/suppliers'
export type InboundFeeDirection = 'RECEIVABLE' | 'PAYABLE'
export type InboundFeeReviewStatus = 'PENDING' | 'APPROVED' | 'REJECTED'
export type FeeSettlementMode = 'ON_ACCOUNT' | 'DIRECT_PAID'
export type FeePaymentMethod = 'ONLINE' | 'BANK_TRANSFER' | 'CASH' | 'OTHER'
export interface InboundFeeDetail {
id: string | number
@@ -15,6 +17,11 @@ export interface InboundFeeDetail {
supplierId: string | number | null
supplierName: string | null
supplierCategory: SupplierCategory | null
settlementMode?: FeeSettlementMode | null
paidAt?: string | null
paymentMethod?: FeePaymentMethod | null
paymentReferenceNo?: string | null
paymentVoucherFileIds?: Array<string | number> | null
businessDate: string
customerName: string | null
feeTypeNameSnapshot: string
@@ -37,6 +44,11 @@ export interface SaveInboundFeeDetailRequest {
currency: string
amount: number
supplierId: string | number | null
settlementMode: FeeSettlementMode | null
paidAt: string | null
paymentMethod: FeePaymentMethod | null
paymentReferenceNo: string | null
paymentVoucherFileIds: Array<string | number> | null
remark: string | null
}
@@ -50,6 +62,7 @@ export interface InboundFeeItemOption {
}
export interface InboundFeeSupplierOption { id: string; supplierName: string; category: SupplierCategory }
export interface FeePaymentVoucher { fileId: string; fileName: string }
const supplierCategories: SupplierCategory[] = ['BOOKING', 'CUSTOMS', 'TRUCKING', 'CERTIFICATE']
@@ -123,3 +136,14 @@ export async function listInboundFeeSupplierOptions(category: SupplierCategory |
id: supplier.id, supplierName: supplier.name, category: supplier.category,
}))
}
export async function uploadInboundFeePaymentVoucher(customerId: string, file: File): Promise<FeePaymentVoucher> {
const body = new FormData(); body.append('file', file)
const raw = unwrapApiResponse(await http.post<unknown, ApiEnvelope<Record<string, unknown>>>('/platform/finance/v1/vouchers', body, {
params: { customerId }, headers: { 'Content-Type': 'multipart/form-data' },
}))
const fileId = raw.fileId == null ? '' : String(raw.fileId)
const echoedCustomerId = raw.tenantId == null ? String(raw.customerId ?? customerId) : String(raw.tenantId)
if (!fileId || echoedCustomerId !== customerId) throw new Error('付款凭证与当前客户不匹配')
return { fileId, fileName: String(raw.fileName || raw.file_name || file.name) }
}