fix some bugs from accounting
This commit is contained in:
@@ -143,6 +143,7 @@ import type { ChargeTarget } from '@/model/wallet'
|
|||||||
import type { WalletAssetsSummary, WalletInventoryCard, WalletMetalTotal } from '@/model/walletAssets'
|
import type { WalletAssetsSummary, WalletInventoryCard, WalletMetalTotal } from '@/model/walletAssets'
|
||||||
import { usePrice } from '@core/utils/usePrice'
|
import { usePrice } from '@core/utils/usePrice'
|
||||||
import { formatMetalDisplayValue } from '@/utils/metalWeight'
|
import { formatMetalDisplayValue } from '@/utils/metalWeight'
|
||||||
|
import { isMeltedTradeGroup } from '@/utils/productCategories'
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@@ -247,10 +248,16 @@ function balanceForTarget(target: ChargeTarget) {
|
|||||||
const card = inventoryCards().find((row) => Number(row.product_id) === Number(target.product_id))
|
const card = inventoryCards().find((row) => Number(row.product_id) === Number(target.product_id))
|
||||||
if (card) return formatCard(card)
|
if (card) return formatCard(card)
|
||||||
|
|
||||||
const unit = target.unit || (target.trade_by_quantity ? 'عدد' : 'گرم')
|
// تعدادی: همیشه «عدد» — نه گرم (وزن هر قطعه در فیلد unit محصول است)
|
||||||
if (target.trade_by_quantity) {
|
const isCount =
|
||||||
return `۰ ${unit}`
|
target.allows_decimal === false ||
|
||||||
|
target.unit === 'عدد' ||
|
||||||
|
(target.trade_by_quantity === false && !isMeltedTradeGroup(target.group_type))
|
||||||
|
|
||||||
|
if (isCount) {
|
||||||
|
return '۰ عدد'
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatMetalDisplayValue(0, target.metal_id ?? 1)
|
return formatMetalDisplayValue(0, target.metal_id ?? 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ export interface ChargeTarget {
|
|||||||
metal_id?: number
|
metal_id?: number
|
||||||
uses_main_wallet?: boolean
|
uses_main_wallet?: boolean
|
||||||
trade_by_quantity?: boolean
|
trade_by_quantity?: boolean
|
||||||
|
/** false برای محصولات تعدادی — فقط عدد صحیح */
|
||||||
|
allows_decimal?: boolean
|
||||||
group_type?: string
|
group_type?: string
|
||||||
active?: boolean
|
active?: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
v-model:value="modelValue.amountAbs"
|
v-model:value="modelValue.amountAbs"
|
||||||
:addon-before="resolvedUnit"
|
:addon-before="resolvedUnit"
|
||||||
:type="resolvedInputType"
|
:type="resolvedInputType"
|
||||||
|
:step="integerOnly ? 1 : undefined"
|
||||||
:place-holder="amountPlaceholder"
|
:place-holder="amountPlaceholder"
|
||||||
/>
|
/>
|
||||||
<div v-if="isMoney && Number(modelValue.amountAbs) > 10" class="wallet-charge-form__hint">
|
<div v-if="isMoney && Number(modelValue.amountAbs) > 10" class="wallet-charge-form__hint">
|
||||||
@@ -66,11 +67,14 @@ const props = withDefaults(
|
|||||||
unitLabel?: string
|
unitLabel?: string
|
||||||
/** true = ورودی قیمتی (ریال)، false = عددی */
|
/** true = ورودی قیمتی (ریال)، false = عددی */
|
||||||
isMoney?: boolean
|
isMoney?: boolean
|
||||||
|
/** محصولات تعدادی — فقط عدد صحیح */
|
||||||
|
integerOnly?: boolean
|
||||||
/** نام کیف پول برای پیشنمایش */
|
/** نام کیف پول برای پیشنمایش */
|
||||||
walletLabel?: string
|
walletLabel?: string
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
variant: 'money',
|
variant: 'money',
|
||||||
|
integerOnly: false,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -80,6 +84,7 @@ const resolvedUnit = computed(
|
|||||||
() => props.unitLabel ?? (props.variant === 'money' ? 'ریال' : 'گرم'),
|
() => props.unitLabel ?? (props.variant === 'money' ? 'ریال' : 'گرم'),
|
||||||
)
|
)
|
||||||
const isMoney = computed(() => props.isMoney ?? props.variant === 'money')
|
const isMoney = computed(() => props.isMoney ?? props.variant === 'money')
|
||||||
|
const integerOnly = computed(() => props.integerOnly === true)
|
||||||
const resolvedInputType = computed(() => (isMoney.value ? 'price' : 'number'))
|
const resolvedInputType = computed(() => (isMoney.value ? 'price' : 'number'))
|
||||||
const isDischarge = computed(() => props.modelValue.direction === 'discharge')
|
const isDischarge = computed(() => props.modelValue.direction === 'discharge')
|
||||||
|
|
||||||
@@ -107,15 +112,17 @@ const amountLabel = computed(() =>
|
|||||||
|
|
||||||
const noteLabel = computed(() => (isDischarge.value ? 'علت دشارژ' : 'علت شارژ'))
|
const noteLabel = computed(() => (isDischarge.value ? 'علت دشارژ' : 'علت شارژ'))
|
||||||
|
|
||||||
const amountPlaceholder = computed(() =>
|
const amountPlaceholder = computed(() => {
|
||||||
isMoney.value ? 'مثلاً ۱۰۰٬۰۰۰' : 'مثلاً ۰.۵',
|
if (isMoney.value) return 'مثلاً ۱۰۰٬۰۰۰'
|
||||||
)
|
if (integerOnly.value) return 'مثلاً ۱'
|
||||||
|
return 'مثلاً ۰.۵'
|
||||||
|
})
|
||||||
|
|
||||||
const notePlaceholder = computed(() =>
|
const notePlaceholder = computed(() =>
|
||||||
isDischarge.value ? 'دلیل کسر موجودی' : 'دلیل افزایش موجودی',
|
isDischarge.value ? 'دلیل کسر موجودی' : 'دلیل افزایش موجودی',
|
||||||
)
|
)
|
||||||
|
|
||||||
const amountRules = [
|
const amountRules = computed(() => [
|
||||||
...inputRules('مقدار'),
|
...inputRules('مقدار'),
|
||||||
{
|
{
|
||||||
validator: (_rule: unknown, value: string | number | undefined) => {
|
validator: (_rule: unknown, value: string | number | undefined) => {
|
||||||
@@ -123,10 +130,13 @@ const amountRules = [
|
|||||||
if (!num) {
|
if (!num) {
|
||||||
return Promise.reject('مقدار باید بیشتر از صفر باشد')
|
return Promise.reject('مقدار باید بیشتر از صفر باشد')
|
||||||
}
|
}
|
||||||
|
if (integerOnly.value && Math.abs(num - Math.round(num)) > 0.000001) {
|
||||||
|
return Promise.reject('برای محصول تعدادی فقط عدد صحیح مجاز است')
|
||||||
|
}
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
])
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
validateFields: () => formRef.value?.validateFields(),
|
validateFields: () => formRef.value?.validateFields(),
|
||||||
|
|||||||
@@ -42,8 +42,9 @@
|
|||||||
<WalletChargeForm
|
<WalletChargeForm
|
||||||
ref="formRef"
|
ref="formRef"
|
||||||
:model-value="formCharge"
|
:model-value="formCharge"
|
||||||
:unit-label="selectedTarget?.unit ?? 'ریال'"
|
:unit-label="chargeUnitLabel"
|
||||||
:is-money="selectedTarget?.kind === 'money'"
|
:is-money="selectedTarget?.kind === 'money'"
|
||||||
|
:integer-only="isIntegerOnlyTarget"
|
||||||
:wallet-label="selectedTarget?.label"
|
:wallet-label="selectedTarget?.label"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -56,6 +57,7 @@ import CustomerWalletBalancePanel from '@/components/customer/CustomerWalletBala
|
|||||||
import { getCustomersList } from '@/api/customer'
|
import { getCustomersList } from '@/api/customer'
|
||||||
import type { Charge, ChargeTarget } from '@/model/wallet'
|
import type { Charge, ChargeTarget } from '@/model/wallet'
|
||||||
import type { Customer } from '@/model/customer'
|
import type { Customer } from '@/model/customer'
|
||||||
|
import { isMeltedTradeGroup } from '@/utils/productCategories'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
formCharge: Charge
|
formCharge: Charge
|
||||||
@@ -111,6 +113,22 @@ const targetOptions = computed(() =>
|
|||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** تعدادی: فقط عدد صحیح — از allows_decimal سرور یا واحد «عدد» */
|
||||||
|
const isIntegerOnlyTarget = computed(() => {
|
||||||
|
const target = props.selectedTarget
|
||||||
|
if (!target || target.kind === 'money') return false
|
||||||
|
if (typeof target.allows_decimal === 'boolean') return !target.allows_decimal
|
||||||
|
if (target.unit === 'عدد') return true
|
||||||
|
// fallback قبل از آپدیت سرور: تعدادی ≠ آبشده/کاتد
|
||||||
|
return target.trade_by_quantity === false && !isMeltedTradeGroup(target.group_type)
|
||||||
|
})
|
||||||
|
|
||||||
|
const chargeUnitLabel = computed(() => {
|
||||||
|
if (props.selectedTarget?.kind === 'money') return 'ریال'
|
||||||
|
if (isIntegerOnlyTarget.value) return 'عدد'
|
||||||
|
return props.selectedTarget?.unit ?? 'گرم'
|
||||||
|
})
|
||||||
|
|
||||||
function filterCustomer(input: string, option?: { label?: string }) {
|
function filterCustomer(input: string, option?: { label?: string }) {
|
||||||
return String(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
return String(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user