import request from '@/config/axios'

// 记账凭证明细 VO
export interface BookkeepingVoucherItemVO {
  id?: number
  summary?: string
  subjectId: number
  subjectName?: string
  debitAmount?: number
  creditAmount?: number
}

// 记账凭证 VO
export interface BookkeepingVoucherVO {
  id?: number
  voucherNo?: string
  voucherDate: string
  summary: string
  debitTotal?: number
  creditTotal?: number
  creatorUserId?: number
  creatorUserName?: string
  auditorUserId?: number
  auditorUserName?: string
  auditTime?: string
  systemName?: string
  remark?: string
  status?: number
  createTime?: string
  items?: BookkeepingVoucherItemVO[]
}

// 记账凭证 API
export const BookkeepingVoucherApi = {
  // 查询记账凭证分页
  getVoucherPage: async (params: any) => {
    return await request.get({ url: `/erp/finance/bookkeeping-voucher/page`, params })
  },

  // 查询记账凭证详情
  getVoucher: async (id: number) => {
    return await request.get({ url: `/erp/finance/bookkeeping-voucher/get?id=` + id })
  },

  // 新增记账凭证
  createVoucher: async (data: BookkeepingVoucherVO) => {
    return await request.post({ url: `/erp/finance/bookkeeping-voucher/create`, data })
  },

  // 修改记账凭证
  updateVoucher: async (data: BookkeepingVoucherVO) => {
    return await request.put({ url: `/erp/finance/bookkeeping-voucher/update`, data })
  },

  // 审核记账凭证
  auditVoucher: async (id: number) => {
    return await request.put({ url: `/erp/finance/bookkeeping-voucher/audit?id=` + id })
  },

  // 反审核记账凭证
  unauditVoucher: async (id: number) => {
    return await request.put({ url: `/erp/finance/bookkeeping-voucher/unaudit?id=` + id })
  },

  // 删除记账凭证
  deleteVoucher: async (id: number) => {
    return await request.delete({ url: `/erp/finance/bookkeeping-voucher/delete?id=` + id })
  },

  // 导出记账凭证 Excel
  exportVoucher: async (params: any) => {
    return await request.download({ url: `/erp/finance/bookkeeping-voucher/export-excel`, params })
  }
}
