bug fix in accounting document edit

This commit is contained in:
Hesabix 2025-07-18 03:40:13 +00:00
parent fc2aa36b0e
commit ecba39c6c9

View file

@ -300,22 +300,31 @@
</div> </div>
<v-row class="mt-4"> <v-row class="mt-4">
<v-col cols="6"> <v-col cols="4">
<v-text-field <v-text-field
v-model="totalBd" :model-value="calculatedTotalBd"
label="جمع بدهکار" label="جمع بدهکار"
readonly readonly
dense dense
></v-text-field> ></v-text-field>
</v-col> </v-col>
<v-col cols="6"> <v-col cols="4">
<v-text-field <v-text-field
v-model="totalBs" :model-value="calculatedTotalBs"
label="جمع بستانکار" label="جمع بستانکار"
readonly readonly
dense dense
></v-text-field> ></v-text-field>
</v-col> </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-row>
</v-form> </v-form>
</v-container> </v-container>
@ -407,6 +416,45 @@ export default {
computed: { computed: {
docId() { docId() {
return this.$route.params.id; 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() { mounted() {
@ -417,6 +465,17 @@ export default {
this.loading = false; this.loading = false;
}); });
}, },
watch: {
// نظارت بر تغییرات در ردیفها برای validation خودکار
'form.rows': {
handler() {
this.$nextTick(() => {
this.calculateTotals();
});
},
deep: true
}
},
methods: { methods: {
showSnackbar(text, color = 'success') { showSnackbar(text, color = 'success') {
this.snackbar.text = text; this.snackbar.text = text;
@ -489,7 +548,10 @@ export default {
} }
})); }));
// فراخوانی calculateTotals بعد از اطمینان از بهروزرسانی تمام مقادیر
this.$nextTick(() => {
this.calculateTotals(); this.calculateTotals();
});
} else { } else {
this.error = response.data.message || 'خطا در بارگذاری سند'; this.error = response.data.message || 'خطا در بارگذاری سند';
} }
@ -499,12 +561,17 @@ export default {
}, },
addRow() { 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.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) { removeRow(item) {
const index = this.form.rows.indexOf(item); const index = this.form.rows.indexOf(item);
if (index >= 0) { if (index >= 0) {
this.form.rows.splice(index, 1); this.form.rows.splice(index, 1);
this.$nextTick(() => {
this.calculateTotals(); this.calculateTotals();
});
} }
}, },
calculateTotals() { calculateTotals() {
@ -518,8 +585,7 @@ export default {
return; return;
} }
this.error = null; this.error = null;
this.totalBd = this.form.rows.reduce((sum, row) => sum + parseInt(row.bd || 0), 0); // حالا از computed properties استفاده میکنیم، نیازی به محاسبه دستی نیست
this.totalBs = this.form.rows.reduce((sum, row) => sum + parseInt(row.bs || 0), 0);
}, },
validateDebitCredit(row) { validateDebitCredit(row) {
if (parseInt(row.bd) > 0 && parseInt(row.bs) > 0) { if (parseInt(row.bd) > 0 && parseInt(row.bs) > 0) {
@ -530,6 +596,10 @@ export default {
} else if (row.bs > 0) { } else if (row.bs > 0) {
row.bs = '0'; row.bs = '0';
} }
// فراخوانی مجدد calculateTotals بعد از تغییر مقادیر
this.$nextTick(() => {
this.calculateTotals();
});
return false; return false;
} }
return true; return true;
@ -587,7 +657,7 @@ export default {
return; return;
} }
if (this.totalBd !== this.totalBs) { if (this.calculatedTotalBd !== this.calculatedTotalBs) {
this.error = 'جمع بدهکار و بستانکار باید برابر باشد'; this.error = 'جمع بدهکار و بستانکار باید برابر باشد';
return; return;
} }