From ecba39c6c99957ff9b8ac5c686a66c6ee80fcd75 Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Fri, 18 Jul 2025 03:40:13 +0000 Subject: [PATCH] bug fix in accounting document edit --- webUI/src/views/acc/accounting/mod.vue | 84 +++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/webUI/src/views/acc/accounting/mod.vue b/webUI/src/views/acc/accounting/mod.vue index 4fb932c8..95e085e5 100644 --- a/webUI/src/views/acc/accounting/mod.vue +++ b/webUI/src/views/acc/accounting/mod.vue @@ -300,22 +300,31 @@ - + - + + + + @@ -407,6 +416,45 @@ export default { computed: { docId() { return this.$route.params.id; + }, + // محاسبه reactive جمع‌ها + calculatedTotalBd() { + const total = this.form.rows.reduce((sum, row) => { + const value = parseInt(row.bd || 0); + return isNaN(value) ? sum : sum + value; + }, 0); + return total; + }, + calculatedTotalBs() { + const total = this.form.rows.reduce((sum, row) => { + const value = parseInt(row.bs || 0); + return isNaN(value) ? sum : sum + value; + }, 0); + return total; + }, + // محاسبه اختلاف جمع بدهکار و بستانکار + calculatedDifference() { + return this.calculatedTotalBd - this.calculatedTotalBs; + }, + // تعیین رنگ مناسب برای اختلاف + differenceColor() { + if (this.calculatedDifference === 0) { + return 'success'; + } else if (this.calculatedDifference > 0) { + return 'warning'; + } else { + return 'error'; + } + }, + // تعیین متن مناسب برای اختلاف + differenceText() { + if (this.calculatedDifference === 0) { + return 'متوازن'; + } else if (this.calculatedDifference > 0) { + return `بدهکار بیشتر: ${this.calculatedDifference.toLocaleString()}`; + } else { + return `بستانکار بیشتر: ${Math.abs(this.calculatedDifference).toLocaleString()}`; + } } }, mounted() { @@ -417,6 +465,17 @@ export default { this.loading = false; }); }, + watch: { + // نظارت بر تغییرات در ردیف‌ها برای validation خودکار + 'form.rows': { + handler() { + this.$nextTick(() => { + this.calculateTotals(); + }); + }, + deep: true + } + }, methods: { showSnackbar(text, color = 'success') { this.snackbar.text = text; @@ -489,7 +548,10 @@ export default { } })); + // فراخوانی calculateTotals بعد از اطمینان از به‌روزرسانی تمام مقادیر + this.$nextTick(() => { this.calculateTotals(); + }); } else { this.error = response.data.message || 'خطا در بارگذاری سند'; } @@ -499,12 +561,17 @@ export default { }, addRow() { this.form.rows.push({ ref: null, refName: '', bd: '0', bs: '0', des: '', detail: '', selectedAccounts: [], bankAccount: null, cashdesk: null, salary: null, commodity: null, commodityCount: null, person: null, tableType: null }); + this.$nextTick(() => { + this.calculateTotals(); + }); }, removeRow(item) { const index = this.form.rows.indexOf(item); if (index >= 0) { this.form.rows.splice(index, 1); + this.$nextTick(() => { this.calculateTotals(); + }); } }, calculateTotals() { @@ -518,8 +585,7 @@ export default { return; } this.error = null; - this.totalBd = this.form.rows.reduce((sum, row) => sum + parseInt(row.bd || 0), 0); - this.totalBs = this.form.rows.reduce((sum, row) => sum + parseInt(row.bs || 0), 0); + // حالا از computed properties استفاده می‌کنیم، نیازی به محاسبه دستی نیست }, validateDebitCredit(row) { if (parseInt(row.bd) > 0 && parseInt(row.bs) > 0) { @@ -530,6 +596,10 @@ export default { } else if (row.bs > 0) { row.bs = '0'; } + // فراخوانی مجدد calculateTotals بعد از تغییر مقادیر + this.$nextTick(() => { + this.calculateTotals(); + }); return false; } return true; @@ -587,7 +657,7 @@ export default { return; } - if (this.totalBd !== this.totalBs) { + if (this.calculatedTotalBd !== this.calculatedTotalBs) { this.error = 'جمع بدهکار و بستانکار باید برابر باشد'; return; }