财务凭证管理

This commit is contained in:
砂糖
2025-08-13 17:48:09 +08:00
parent c0a2461d13
commit 9a660b910b
5 changed files with 187 additions and 76 deletions

View File

@@ -42,3 +42,21 @@ export function delFinancialDocument(documentId) {
method: 'delete'
})
}
// 创建财务单据,带明细,使用借贷记账法
export function addFinancialDocumentWithDetail(data) {
return request({
url: '/klp/financialDocument/addDetail',
method: 'post',
data: data
})
}
// 查询带明细的财务单据
export function listFinancialDocumentWithDetail(query) {
return request({
url: '/klp/financialDocument/ListDetail',
method: 'get',
params: query
})
}

View File

@@ -16,6 +16,8 @@
return this.value;
},
set(value) {
console.log(value, 'value');
this.$emit('change', value);
this.$emit('input', value);
}
}

View File

@@ -10,8 +10,8 @@
placeholder="请选择单据日期">
</el-date-picker>
</el-form-item>
<el-form-item label="关联订单" prop="orderId">
<el-input v-model="form.orderId" placeholder="请输入关联订单" />
<el-form-item label="关联订单" prop="relatedOrderId">
<el-input v-model="form.relatedOrderId" placeholder="请输入关联订单" />
</el-form-item>
</el-form>
</el-row>
@@ -19,12 +19,17 @@
<el-row>
<el-table :data="tableData" style="width: 100%" empty-text="暂无数据">
<el-table-column label="序号" type="index" width="50" align="center" />
<el-table-column prop="summary" label="摘要">
<el-table-column prop="voucherNo" label="摘要">
<template slot-scope="scope">
<el-input v-model="scope.row.summary" placeholder="请输入摘要" @change="handleRowChange(scope.row)" />
<el-input v-model="scope.row.voucherNo" placeholder="请输入摘要" @input="handleCreditInput(scope.row)" @change="handleRowChange(scope.row)" />
</template>
</el-table-column>
<el-table-column prop="accountingId" label="会计科目">
<!-- <el-table-column prop="voucherNo" label="单号">
<template slot-scope="scope">
<el-input v-model="scope.row.voucherNo" placeholder="请输入单号" @input="handleCreditInput(scope.row)" @change="handleRowChange(scope.row)" />
</template>
</el-table-column> -->
<el-table-column prop="accountId" label="会计科目">
<template slot-scope="scope">
<amount-select v-model="scope.row.accountId" placeholder="请输入会计科目" @change="handleRowChange(scope.row)" />
</template>
@@ -52,6 +57,9 @@
:disabled="tableData.length <= 1">
删除
</el-button>
<el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.$index)" v-if="!isCreate">
变更
</el-button>
</template>
</el-table-column>
</el-table>
@@ -73,13 +81,16 @@
</el-row>
<el-row>
<el-button type="primary" @click="handleCreate">创建凭证</el-button>
<el-button v-if="isCreate" type="primary" @click="handleCreate">创建凭证</el-button>
<el-button v-else type="primary" @click="handleChange">变更凭证信息</el-button>
</el-row>
</div>
</template>
<script>
import AmountSelect from '@/components/KLPService/AmountSelect/index.vue';
import { addFinancialDocumentWithDetail, updateFinancialDocument } from "@/api/finance/financialDocument";
import { updateJournalEntry } from "@/api/finance/jouneryEntry";
export default {
components: {
@@ -90,15 +101,17 @@ export default {
form: {
docNo: undefined,
docDate: undefined,
orderId: undefined
relatedOrderId: undefined
},
tableData: [{
summary: '',
accountingId: '',
voucherNo: '',
accountId: undefined,
debitAmount: 0,
creditAmount: 0,
remark: ''
}]
remark: '',
voucherNo: ''
}],
isCreate: false
}
},
computed: {
@@ -130,10 +143,34 @@ export default {
}
}
},
props: {
initData: {
type: Object,
required: false,
default: () => ({})
}
},
watch: {
initData: {
handler(newVal) {
console.log(newVal, 'watchData');
if (newVal) {
this.tableData = newVal.detailList;
this.form.docNo = newVal.docNo;
this.form.docDate = newVal.docDate;
this.form.relatedOrderId = newVal.relatedOrderId;
this.isCreate = false;
} else {
this.isCreate = true;
}
},
immediate: true
}
},
methods: {
// 判断行是否有内容
isRowNotEmpty(row) {
return row.summary || row.accountingId ||
return row.voucherNo || row.accountingId ||
(row.debitAmount && row.debitAmount > 0) ||
(row.creditAmount && row.creditAmount > 0) ||
row.remark;
@@ -173,11 +210,12 @@ export default {
// 添加空行
addEmptyRow() {
this.tableData.push({
summary: '',
accountingId: '',
voucherNo: '',
accountId: undefined,
debitAmount: 0,
creditAmount: 0,
remark: ''
remark: '',
voucherNo: ''
});
},
@@ -250,66 +288,112 @@ export default {
},
handleCreate() {
// 验证所有行的借贷金额是否符合规则
const invalidRows = this.tableData.findIndex(row => {
return this.isRowNotEmpty(row) &&
row.debitAmount > 0 &&
row.creditAmount > 0;
});
// 收集所有错误信息
const errors = [];
const { form, tableData } = this;
// 凭证编号,单据日期和关联订单必填
if (!this.form.docNo) {
this.$message.error('凭证编号必填');
return;
}
if (!this.form.docDate) {
this.$message.error('单据日期必填');
return;
}
if (!this.form.orderId) {
this.$message.error('关联订单必填');
return;
}
if (invalidRows !== -1) {
this.$message.error('存在同时填写借方和贷方金额的行,请检查');
return;
}
// 过滤掉空行后提交
const validData = this.tableData.filter(row => this.isRowNotEmpty(row));
// 1. 基础表单必填项校验
if (!form.docNo) errors.push('凭证编号必填');
if (!form.docDate) errors.push('单据日期必填');
// 注意原模板中是relatedOrderId保持变量名一致
if (!form.relatedOrderId) errors.push('关联订单必填');
// 2. 过滤有效行并检查基本存在性
const validData = tableData.filter(row => this.isRowNotEmpty(row));
if (validData.length === 0) {
this.$message.warning('请至少填写一行凭证数据');
errors.push('请至少填写一行凭证数据');
}
// 3. 表格行级校验(仅当有有效行时)
if (validData.length > 0) {
// 3.1 检查每一行的必填项
validData.forEach((row, index) => {
const rowNum = index + 1; // 行号从1开始
if (!row.voucherNo) errors.push(`${rowNum}行:请填写摘要`);
// 注意原模板中是accountingId保持变量名一致
if (!row.accountId) errors.push(`${rowNum}行:请填写会计科目`);
// 检查是否存在voucherNo字段如果实际业务需要
if (row.voucherNo === undefined && !row.voucherNo) {
errors.push(`${rowNum}行:请填写单号`);
}
// 3.2 检查每行是否同时有借贷金额
if (row.debitAmount > 0 && row.creditAmount > 0) {
errors.push(`${rowNum}行:不能同时填写借方和贷方金额`);
}
// 3.3 检查每行是否至少有一个金额
if (!(row.debitAmount > 0 || row.creditAmount > 0)) {
errors.push(`${rowNum}行:请填写借方或贷方金额`);
}
});
// 4. 整体金额校验
// 处理浮点数精度问题
if (Math.abs(this.debitAmount - this.creditAmount) > 0.01) {
errors.push(`借贷金额必须相等(借方:${this.debitAmount.toFixed(2)},贷方:${this.creditAmount.toFixed(2)}`);
}
}
if (errors.length > 0) {
this.$message({
dangerouslyUseHTMLString: true,
message: errors.map(error => `<p>${error}</p>`).join(''),
type: 'error'
})
return;
}
// 所有的科目必须填写
const accountIds = validData.map(row => row.accountId);
if (accountIds.some(id => !id)) {
this.$message.error('请填写所有会计科目');
return;
}
// 每一行至少包含借方或贷方金额
const hasDebitOrCredit = validData.some(row => row.debitAmount > 0 || row.creditAmount > 0);
if (!hasDebitOrCredit) {
this.$message.error('请至少填写一行借方或贷方金额');
return;
}
// 借贷必须相同
if (this.debitAmount !== this.creditAmount) {
this.$message.error('借方和贷方金额必须相同');
return;
}
console.log('表单数据:', this.form, this.debitAmount, this.creditAmount);
console.log('表格数据:', validData);
// 这里可以添加提交逻辑
// 6. 提交数据
addFinancialDocumentWithDetail({
docNo: form.docNo,
docDate: form.docDate,
// 保持变量名一致
relatedOrderId: form.relatedOrderId,
amount: this.debitAmount,
details: validData.map((row, idx) => ({
// voucherNo: row.voucherNo,
voucherNo: row.voucherNo,
// 保持变量名一致
accountId: row.accountId,
debitAmount: row.debitAmount,
creditAmount: row.creditAmount,
remark: row.remark,
lineNo: idx + 1,
entryDate: form.docDate
}))
}).then(response => {
this.$message.success('凭证创建成功');
}
this.$emit('success');
}).catch(error => {
this.$message.error('凭证创建失败:' + (error.message || '未知错误'));
this.$emit('error', error);
});
},
handleEdit(index) {
// 找到对应的列变更
const row = this.tableData[index];
updateJournalEntry(row).then(response => {
this.$message.success('明细变更成功');
}).catch(error => {
this.$message.error('明细变更失败:' + (error.message || '未知错误'));
});
},
handleChange() {
updateFinancialDocument({
documentId: this.initData.documentId,
docNo: this.form.docNo,
docDate: this.form.docDate,
relatedOrderId: this.form.relatedOrderId,
amount: this.debitAmount,
}).then(response => {
this.$message.success('凭证变更成功');
}).catch(error => {
this.$message.error('凭证变更失败:' + (error.message || '未知错误'));
});
}
}
}
</script>

View File

@@ -201,7 +201,7 @@
</template>
<script>
import { listJournalEntry, getJournalEntry, delJournalEntry, addJournalEntry, updateJournalEntry } from "@/api/finance/jouneryEntry";
import { listJournalEntry, getJournalEntry, delJournalEntry, addJournalEntry, updateJournalEntry, addFinancialDocumentWithDetail } from "@/api/finance/jouneryEntry";
export default {
name: "JournalEntry",

View File

@@ -106,7 +106,7 @@
</el-table>
<pagination
v-show="total>0"
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@@ -115,15 +115,13 @@
<!-- 添加或修改财务单据对话框 -->
<el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
<create-document ref="createDocument" />
<create-document ref="createDocument" :initData="currentRow" @success="handleSuccess" @error="handleError" />
</el-dialog>
</div>
</template>
<script>
import { listFinancialDocument, getFinancialDocument, delFinancialDocument, addFinancialDocument, updateFinancialDocument } from "@/api/finance/financialDocument";
import { listFinancialDocumentWithDetail, getFinancialDocument, delFinancialDocument, addFinancialDocument, updateFinancialDocument } from "@/api/finance/financialDocument";
import CreateDocument from "./components/Voucher.vue";
export default {
@@ -168,7 +166,8 @@ export default {
form: {},
// 表单校验
rules: {
}
},
currentRow: {},
};
},
created() {
@@ -178,7 +177,7 @@ export default {
/** 查询财务单据列表 */
getList() {
this.loading = true;
listFinancialDocument(this.queryParams).then(response => {
listFinancialDocumentWithDetail(this.queryParams).then(response => {
this.financialDocumentList = response.rows;
this.total = response.total;
this.loading = false;
@@ -234,6 +233,7 @@ export default {
handleUpdate(row) {
this.loading = true;
this.reset();
this.currentRow = row;
const documentId = row.documentId || this.ids
getFinancialDocument(documentId).then(response => {
this.loading = false;
@@ -287,6 +287,13 @@ export default {
this.download('klp/financialDocument/export', {
...this.queryParams
}, `financialDocument_${new Date().getTime()}.xlsx`)
},
handleSuccess() {
this.open = false;
this.getList();
},
handleError(error) {
this.$message.error(error);
}
}
};