forked from morrning/hesabixCore
bug fix in accounting document edit
This commit is contained in:
parent
fc2aa36b0e
commit
ecba39c6c9
|
@ -300,22 +300,31 @@
|
|||
</div>
|
||||
|
||||
<v-row class="mt-4">
|
||||
<v-col cols="6">
|
||||
<v-col cols="4">
|
||||
<v-text-field
|
||||
v-model="totalBd"
|
||||
:model-value="calculatedTotalBd"
|
||||
label="جمع بدهکار"
|
||||
readonly
|
||||
dense
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
<v-col cols="6">
|
||||
<v-col cols="4">
|
||||
<v-text-field
|
||||
v-model="totalBs"
|
||||
:model-value="calculatedTotalBs"
|
||||
label="جمع بستانکار"
|
||||
readonly
|
||||
dense
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
<v-col cols="4">
|
||||
<v-text-field
|
||||
:model-value="differenceText"
|
||||
readonly
|
||||
dense
|
||||
variant="outlined"
|
||||
:color="differenceColor"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-form>
|
||||
</v-container>
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue