more bug fix in cost mod

This commit is contained in:
Hesabix 2025-04-04 20:07:58 +00:00
parent 77977b54a5
commit 2ac59fa0c7
4 changed files with 97 additions and 132 deletions

View file

@ -1,115 +1,83 @@
<template>
<v-text-field
v-model="formattedValue"
v-bind="$attrs"
type="text"
:rules="combinedRules"
@keypress="handleKeypress"
@input="syncValue"
dir="ltr"
dense
/>
</template>
<script>
export default {
name: 'Hnumberinput',
inheritAttrs: false,
props: {
modelValue: {
type: [Number, String],
default: null
},
rules: {
type: Array,
default: () => []
}
<v-text-field
v-model="inputValue"
v-bind="$attrs"
type="text"
:rules="combinedRules"
@keypress="restrictToNumbers"
dir="ltr"
dense
/>
</template>
<script>
export default {
name: 'HNumberInput',
inheritAttrs: false,
props: {
modelValue: {
type: [Number, String],
default: null
},
data() {
return {
internalValue: '' // مقدار خام به صورت رشته
}
},
computed: {
formattedValue() {
if (!this.internalValue) return ''
return Number(this.internalValue).toLocaleString('fa-IR')
},
combinedRules() {
return [
v => !v || !isNaN(this.normalizeNumber(v)) || 'فقط عدد مجاز است',
...this.rules
]
}
},
watch: {
modelValue(newVal) {
this.internalValue = newVal !== null && newVal !== undefined ? String(newVal) : ''
}
},
mounted() {
this.internalValue = this.modelValue !== null && this.modelValue !== undefined ? String(this.modelValue) : ''
},
methods: {
normalizeNumber(value) {
if (!value) return ''
let result = value.toString()
const persianNumbers = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g]
const arabicNumbers = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g]
for (let i = 0; i < 10; i++) {
result = result.replace(persianNumbers[i], i).replace(arabicNumbers[i], i)
rules: {
type: Array,
default: () => []
}
},
data() {
return {
inputValue: ''
}
},
computed: {
combinedRules() {
return [
v => !v || /^\d+$/.test(v.replace(/[^0-9]/g, '')) || 'فقط عدد انگلیسی مجاز است',
...this.rules
]
}
},
watch: {
modelValue: {
immediate: true,
handler(newVal) {
if (newVal !== null && newVal !== undefined) {
const cleaned = String(newVal).replace(/[^0-9]/g, '')
this.inputValue = cleaned ? Number(cleaned).toLocaleString('en-US') : ''
} else {
this.inputValue = ''
}
return result.replace(/[^0-9]/g, '')
},
handleKeypress(event) {
event.preventDefault() // جلوگیری از رفتار پیشفرض برای کنترل کامل
const charCode = event.charCode
const char = String.fromCharCode(charCode)
// فقط اعداد رو قبول کن
if (charCode >= 48 && charCode <= 57) { // اعداد انگلیسی
const newValue = this.internalValue + char
const normalized = this.normalizeNumber(newValue)
this.internalValue = normalized
this.$emit('update:modelValue', normalized ? Number(normalized) : null)
} else if (charCode >= 1632 && charCode <= 1641) { // اعداد عربی
const arabicToEnglish = String.fromCharCode(charCode - 1584)
const newValue = this.internalValue + arabicToEnglish
const normalized = this.normalizeNumber(newValue)
this.internalValue = normalized
this.$emit('update:modelValue', normalized ? Number(normalized) : null)
} else if (charCode >= 1776 && charCode <= 1785) { // اعداد فارسی
const persianToEnglish = String.fromCharCode(charCode - 1728)
const newValue = this.internalValue + persianToEnglish
const normalized = this.normalizeNumber(newValue)
this.internalValue = normalized
this.$emit('update:modelValue', normalized ? Number(normalized) : null)
}
},
syncValue(event) {
const rawInput = event.target.value
const normalized = this.normalizeNumber(rawInput)
this.internalValue = normalized
this.$emit('update:modelValue', normalized ? Number(normalized) : null)
this.$nextTick(() => {
event.target.value = this.formattedValue
})
}
},
inputValue(newVal) {
if (newVal === '' || newVal === null || newVal === undefined) {
this.$emit('update:modelValue', 0) // وقتی خالی است، صفر ارسال شود
} else {
const cleaned = String(newVal).replace(/[^0-9]/g, '')
const numericValue = cleaned ? Number(cleaned) : 0
this.$emit('update:modelValue', numericValue)
}
}
},
methods: {
restrictToNumbers(event) {
const charCode = event.charCode
if (charCode < 48 || charCode > 57) {
event.preventDefault()
}
}
}
</script>
<style scoped>
:deep(.v-text-field input) {
direction: ltr;
text-align: left;
}
</style>
}
</script>
<style scoped>
:deep(.v-text-field input) {
direction: ltr;
text-align: left;
}
</style>

View file

@ -496,7 +496,6 @@ export default {
this.totalItems = 0;
}
console.log('آیتم‌های ذخیره شده:', this.items);
if (this.modelValue) {
if (this.returnObject) {
@ -506,7 +505,6 @@ export default {
}
}
} catch (error) {
console.error('خطا در دریافت داده‌ها:', error);
this.showMessage('خطا در بارگذاری داده‌ها', 'error');
this.items = [];
this.totalItems = 0;

View file

@ -146,12 +146,11 @@
<template #expanded-row="{ columns, item }">
<tr>
<td :colspan="columns.length" class="expanded-row">
<v-container>
<v-container class="pa-0 ma-0">
<v-row>
<v-col cols="12">
<h4>مراکز هزینه</h4>
<v-list dense>
<v-list-item v-for="(center, index) in item.costCenters" :key="index">
<v-list density="compact" class="pa-0 ma-0">
<v-list-item :border="true" v-for="(center, index) in item.costCenters" :key="index">
<v-list-item-title>
{{ center.name }}
{{ $t('dialog.acc_price') }} : {{ $filters.formatNumber(center.amount) }}

View file

@ -88,7 +88,7 @@
<!-- مرکز هزینه -->
<template v-for="(item, index) in costs" :key="'cost'+index">
<v-card class="mb-4">
<v-toolbar color="grey-darken-3" density="compact">
<v-toolbar color="primary" density="compact">
<v-toolbar-title class="text-white text--secondary">
<span class="text-error me-2">{{ index + 1 }}</span>
<v-icon color="white">mdi-ticket</v-icon>
@ -130,7 +130,7 @@
<!-- حساب بانکی -->
<template v-for="(item, index) in banks" :key="'bank'+index">
<v-card class="mb-4">
<v-toolbar color="grey-lighten-3" density="compact">
<v-toolbar color="grey-lighten-2" density="compact">
<v-toolbar-title>
<span class="me-2">{{ index + 1 }}</span>
<v-icon>mdi-bank</v-icon>
@ -408,20 +408,20 @@ export default {
calc() {
this.sum = 0;
this.costs.forEach((item) => {
this.sum = parseInt(this.sum) + parseInt(item.amount);
this.sum = parseInt(this.sum) + (parseInt(item.amount) || 0);
});
let side = 0;
this.banks.forEach((item) => {
side = parseInt(side) + parseInt(item.amount);
side = parseInt(side) + (parseInt(item.amount) || 0);
});
this.salarys.forEach((item) => {
side = parseInt(side) + parseInt(item.amount);
side = parseInt(side) + (parseInt(item.amount) || 0);
});
this.cashdesks.forEach((item) => {
side = parseInt(side) + parseInt(item.amount);
side = parseInt(side) + (parseInt(item.amount) || 0);
});
this.persons.forEach((item) => {
side = parseInt(side) + parseInt(item.amount);
side = parseInt(side) + (parseInt(item.amount) || 0);
});
this.balance = parseInt(this.sum) - parseInt(side);
@ -471,7 +471,6 @@ export default {
addSalary() {
this.salarys.push({
id: '',
salary: null,
amount: '',
des: ''
})
@ -513,14 +512,14 @@ export default {
}
else if (item.type == 'bank') {
this.banks.push({
id: item.bank,
id: item.bank.id,
amount: item.bs,
des: item.des
});
}
else if (item.type == 'cashdesk') {
this.cashdesks.push({
id: item.cashdesk,
person: item.cashdesk.id,
amount: item.bs,
des: item.des
});
@ -528,7 +527,6 @@ export default {
else if (item.type == 'salary') {
this.salarys.push({
id: item.salary.id,
salary: item.salary,
amount: item.bs,
des: item.des
});
@ -542,6 +540,7 @@ export default {
});
}
})
this.calc();
});
}
else {
@ -601,20 +600,20 @@ export default {
}
});
this.salarys.forEach((item) => {
if (item.person == null || item.person == '') {
if (item.id == null || item.id == '') {
sideOK = false;
}
})
});
this.cashdesks.forEach((item) => {
if (item.person == null || item.person == '') {
sideOK = false;
}
})
});
this.persons.forEach((item) => {
if (item.id == null || item.id == '') {
sideOK = false;
}
})
});
if (sideOK == false) {
Swal.fire({
text: 'یکی از طرف‌های حساب انتخاب نشده است.',
@ -666,12 +665,13 @@ export default {
this.salarys.forEach((item) => {
if (item.des == '') item.des = 'هزینه'
rows.push({
id: item.person,
id: item.id,
bs: parseInt(item.amount),
bd: 0,
des: item.des,
type: 'salary',
table: 124
table: 124,
salary: this.listSalarys.find(s => s.id === item.id)
});
})