import { useMessage } from '@eciol/ant-ui'; import { request } from '@eciol/request'; import { blobToJson, downloadByData, replaceVariables } from '@eciol/shared'; import type { PayableService } from '@/api'; import { FilterJson } from '@/api'; import { useUserStoreWithOut } from '@/store/modules/user'; import { generateFileName, PaymentChannelEnum } from '@/utils'; import type { PayApplyService } from './typing'; enum Api { GetPayApplyList = '/api/Payapply/QueryPage', GetPayApplyDetail = '/api/Payapply/{orgId}/{id}', CreatePayApply = '/api/Payapply/{orgId}', DeletePayApply = '/api/Payapply/{orgId}/{id}', JoinPayApply = '/api/Payapply/{orgId}/{id}/join', SubmitPayApply = '/api/Payapply/{orgId}/submit', GetPayApplyApproveList = '/api/PayapplyApprove/QueryPage', ApprovePayApply = '/api/PayapplyApprove/{orgId}/approvebyvm', SubmitApprovePayApply = '/api/PayapplyApprove/{orgId}/submitbyvm', ReturnApprovePayApply = '/api/PayapplyApprove/{orgId}/rejectbyvm', GetGroupPayApplyDetail = '/api/PayapplyApprove/{id}/GetByVM', DeApprovePayApply = '/api/PayapplyApprove/{orgId}/de-approve', DismissPayApply = '/api/PayapplyApprove/DelApplicationByVM', DismissOnlyPayApply = '/api/PayapplyApprove/{id}', GetAdjustmentPayApplyDetail = '/api/PayapplyApprove/GetPayapplyPaymentInfo', GenerationPayBillsDetail = '/api/Payapply/{orgId}/generation', GetRemindOptions = '/api/Payapply/{orgId}/remind', SupplementInvoiceDetail = '/api/Payapply/{orgId}/supplement', GetInvoiceDetail = '/api/Payapply/{orgId}/invoice', GetPayStatistics = '/api/Payapply/{orgId}/statistics', BatchGenerationPayBills = '/api/Payapply/{orgId}/batch', ExportFarsion = '/api/Payapply/{orgId}/export-farsion', GetInvoiceInfo = '/api/Payapply/{orgId}/supplement-invoice', PayapplyCreate = '/api/PayapplyChange/PayapplyCreate', SecureInvoice = '/api/Payapply/{orgId}/secureinvoice', } /** * 获取应付单列表 */ function getPayApplyList(data: PayApplyService.GetPayApplyListParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: Api.GetPayApplyList, data: { ...data, orgId: getCompanyId }, }, { showLoading: true, }, ); } /** * 获取应付单详情 */ function getPayApplyDetail(id: number) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.GetPayApplyDetail, { id, orgId: getCompanyId }), }, { showLoading: true, }, ); } /** * 获取应付单详情 */ function getGroupPayApplyDetail(id: number) { return request.get( { url: replaceVariables(Api.GetGroupPayApplyDetail, { id }), }, { showLoading: true, }, ); } /** * 新建应付单 */ function createPayApply(data: PayableService.PayableItem) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.CreatePayApply, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'ADD', successMessageMode: 'message', operationType: 'ADD', }, ); } /** * 删除付款申请单 */ function deletePayApply(id: number) { const { getCompanyId } = useUserStoreWithOut(); return request.delete( { url: replaceVariables(Api.DeletePayApply, { id, orgId: getCompanyId }), }, { showLoading: true, successMessageMode: 'message', successMessage: '删除成功!', }, ); } /** * 付款申请单加入关联查询 */ function joinPayApply(id: number, orgId) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.JoinPayApply, { id, orgId: orgId ?? getCompanyId }), }, { showLoading: true, }, ); } /** * 提交付款申请单 */ function submitPayApply(ids: number[]) { const { getCompanyId } = useUserStoreWithOut(); return request.put( { url: replaceVariables(Api.SubmitPayApply, { orgId: getCompanyId }), data: ids, }, { showLoading: true, loadingTip: 'SUBMIT', operationType: 'SUBMIT', successMessageMode: 'message', }, ); } /** * 获取应付单审核列表 */ function getPayApplyApproveList(data: PayApplyService.GetPayApplyListParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: Api.GetPayApplyApproveList, data: { ...data, orgId: getCompanyId }, }, { showLoading: true, }, ); } /** * 确认支付付款申请单 */ function approvePayApply(data: PayApplyService.ApprovePayApplyParams[]) { const { getCompanyId } = useUserStoreWithOut(); return request.put( { url: replaceVariables(Api.ApprovePayApply, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '支付成功', successMessageMode: 'message', }, ); } /** * 提交付款申请单 */ function submitApprovePayApply(data: PayApplyService.ApprovePayApplyParams[]) { const { getCompanyId } = useUserStoreWithOut(); return request.put( { url: replaceVariables(Api.SubmitApprovePayApply, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '提交成功', successMessageMode: 'message', }, ); } /** * 打回付款申请单 */ function returnApprovePayApply(data: PayApplyService.ApprovePayApplyParams[]) { const { getCompanyId } = useUserStoreWithOut(); return request.put( { url: replaceVariables(Api.ReturnApprovePayApply, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '打回成功', successMessageMode: 'message', }, ); } /** * 反审核付款申请单 */ function deApprovePayApply(data: PayApplyService.ApprovePayApplyParams[]) { const { getCompanyId } = useUserStoreWithOut(); return request.put( { url: replaceVariables(Api.DeApprovePayApply, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '反审核成功', successMessageMode: 'message', }, ); } /** * 解散付款申请单 */ function dismissPayApply(data: PayApplyService.ApprovePayApplyParams[]) { return request.post( { url: Api.DismissPayApply, data, }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '解散成功', successMessageMode: 'message', }, ); } /** * 解散单个付款申请单 */ function dismissOnlyPayApply(data: PayApplyService.ApprovePayApplyParams) { return request.delete( { url: replaceVariables(Api.DismissOnlyPayApply, { id: data.id }), }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '解散成功', successMessageMode: 'message', }, ); } /** * 获取下推付款申请单详情 */ function generationPayBillsDetail(params: { ids: string }) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.GenerationPayBillsDetail, { orgId: getCompanyId }), params, }, { showLoading: true, }, ); } /** * 下推生成付款单 */ function generationPayBills(data: PayApplyService.GenerationPayBillsParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.GenerationPayBillsDetail, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'EMPTY', successMessageMode: 'message', successMessage: '生成付款单成功', }, ); } /** * 获取发票提醒选项 */ function getRemindOptions() { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.GetRemindOptions, { orgId: getCompanyId }), }, { showLoading: true, }, ); } /** * 提醒译员邮件 */ function remindEmail(data) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.GetRemindOptions, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'EMPTY', successMessageMode: 'message', successMessage: '发送成功', }, ); } /** * 获取补录发票详情 */ function supplementInvoiceDetail(params: { ids: string }) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.SupplementInvoiceDetail, { orgId: getCompanyId }), params, }, { showLoading: true, }, ); } /** * 补录发票 */ function supplementInvoice(data: PayApplyService.GenerationPayBillsParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.SupplementInvoiceDetail, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'EMPTY', successMessageMode: 'message', successMessage: '补录发票成功', }, ); } /** * 获取发票信息 */ function getInvoiceDetail(params: { id: string }) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.GetInvoiceDetail, { orgId: getCompanyId }), params, }, { showLoading: true, }, ); } /** * 解析文件获取发票服务信息 */ function getInvoiceInfo(params: { ids: string; fileId: string }) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.GetInvoiceInfo, { orgId: getCompanyId }), params, }, { showLoading: true, }, ); } /** * 获取支付统计信息 */ async function getPayStatistics(data) { const { getCompanyId } = useUserStoreWithOut(); const result = await request.post( { url: replaceVariables(Api.GetPayStatistics, { orgId: getCompanyId }), data, }, { showLoading: true, }, ); const _data = result.sort((a, b) => a.paymentChannel - b.paymentChannel); const mergedArray: PayApplyService.GetPayStatisticsResult = Object.values( _data.reduce((result, item) => { if (result[item.paymentChannel]) { Object.assign(result[item.paymentChannel].data ?? {}, item.data); } else { result[item.paymentChannel] = item; } return result; }, {}), ); return mergedArray.map((item) => { if (item.paymentChannel === PaymentChannelEnum.外币支付) { const paymentChannelFields = ['Paypal Account', 'Bank Account']; item.paymentChannelList = Object.keys(item.data) .filter((key) => paymentChannelFields.includes(key)) .map((key) => ({ label: item.data[key], value: key, })); item.currentList = Object.keys(item.data) .filter((key) => !paymentChannelFields.includes(key)) .map((key) => ({ label: item.data[key], value: key, })); } else { item.data = Object.keys(item.data).map((key) => ({ label: item.data[key], value: key, })); } return item; }); } /** * 批量生成付款单 */ function batchGenerationPayBills(data: number[]) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.BatchGenerationPayBills, { orgId: getCompanyId }), data, }, { showLoading: true, }, ); } /** * 导出结算单PDF(快商) */ async function exportFarsion(data: FilterJson['filtersConditions']) { const { createMessage } = useMessage(); const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: replaceVariables(Api.ExportFarsion, { orgId: getCompanyId }), data, responseType: 'blob', timeout: 5 * 60 * 1000, }, { showLoading: true, successMessage: '导出成功', successMessageMode: 'message', isTransformResponse: false, }, ); if (_data.type === 'application/json') { const result = await blobToJson(_data); createMessage.error(result.message); return false; } downloadByData(_data, generateFileName({ fileName: '电子结算单明细', suffix: 'pdf' })); createMessage.success('导出成功'); } // 获取调整付款申请单账户详情 function getAdjustmentPayApplyDetail(data) { return request.post( { url: Api.GetAdjustmentPayApplyDetail, data, }, { showLoading: true, }, ); } // 调整付款申请单账户 function adjustmentPayApply(data) { return request.post( { // url: Api.AdjustmentPayApply, url: Api.PayapplyCreate, data, }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '变更成功', successMessageMode: 'message', }, ); } // 解除发票 function secureInvoice(data: { id: number }) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.SecureInvoice, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '解除成功', successMessageMode: 'message', }, ); } export { adjustmentPayApply, approvePayApply, batchGenerationPayBills, createPayApply, deApprovePayApply, deletePayApply, dismissOnlyPayApply, dismissPayApply, exportFarsion, generationPayBills, generationPayBillsDetail, getAdjustmentPayApplyDetail, getGroupPayApplyDetail, getInvoiceDetail, getInvoiceInfo, getPayApplyApproveList, getPayApplyDetail, getPayApplyList, getPayStatistics, getRemindOptions, joinPayApply, remindEmail, returnApprovePayApply, secureInvoice, submitApprovePayApply, submitPayApply, supplementInvoice, supplementInvoiceDetail, }; export type { PayApplyService } from './typing';