price handling
This commit is contained in:
@@ -6,6 +6,29 @@ export function inputRules(title?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
/** فیلد قیمت/عدد — خالی رد میشود، صفر مجاز است */
|
||||
export function requiredPriceRules(title?: string) {
|
||||
const label = title || 'مورد بالا'
|
||||
|
||||
return [
|
||||
{
|
||||
validator(_rule: unknown, value: unknown) {
|
||||
if (value === undefined || value === null || String(value).trim() === '') {
|
||||
return Promise.reject(`پر کردن ${label} الزامی است`)
|
||||
}
|
||||
|
||||
const num = Number(String(value).replaceAll(',', ''))
|
||||
if (!Number.isFinite(num)) {
|
||||
return Promise.reject('لطفاً عدد معتبر وارد کنید')
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
},
|
||||
trigger: ['change', 'blur'],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
export function inputRulesNumber(title?: string) {
|
||||
if (title) {
|
||||
return [
|
||||
|
||||
@@ -23,6 +23,10 @@ export function normalizeReferenceBase(entry: MethodePrices): { base: number; pr
|
||||
let base = Number(entry.price) || 0
|
||||
const profit = Number(entry.profit) || 0
|
||||
|
||||
if (base <= 0) {
|
||||
return { base: 0, profit: 0 }
|
||||
}
|
||||
|
||||
if (entry.name === GOLD_DOT_REFERENCE_NAME) {
|
||||
base = base / 4.3318
|
||||
}
|
||||
@@ -39,6 +43,20 @@ export function adjustedProductPrice(
|
||||
return Math.round(reference * (1 + (Number(offsetPercent) || 0) / 100))
|
||||
}
|
||||
|
||||
/** جمع مرجع — وقتی price صفر است profit نادیده گرفته میشود (مقدار قدیمی) */
|
||||
export function referenceProviderTotal(entry?: Pick<MethodePrices, 'price' | 'profit'> | null): number {
|
||||
if (!entry) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const price = Number(entry.price ?? 0)
|
||||
if (price <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return price + Number(entry.profit ?? 0)
|
||||
}
|
||||
|
||||
export function resolveAppBasePrice(lastPrice?: Partial<last> & { price?: number } | null): number {
|
||||
if (!lastPrice) return 0
|
||||
|
||||
@@ -118,7 +136,7 @@ export function computeProductEditorPricePreview(input: {
|
||||
: adjustedProductPrice(fallback, 0, offsetPercent)
|
||||
return { status: 'ready', amount, source: 'آخرین قیمت ذخیرهشده' }
|
||||
}
|
||||
return { status: 'empty', message: 'قیمت provider صفر است' }
|
||||
return { status: 'empty', message: 'قیمت مرجع صفر است' }
|
||||
}
|
||||
|
||||
if (!input.form.reading_method) {
|
||||
@@ -140,7 +158,7 @@ export function computeProductEditorPricePreview(input: {
|
||||
)
|
||||
return fallback > 0
|
||||
? { status: 'ready', amount: fallback, source: 'آخرین قیمت ذخیرهشده' }
|
||||
: { status: 'empty', message: 'قیمت provider صفر است' }
|
||||
: { status: 'empty', message: 'قیمت مرجع صفر است' }
|
||||
}
|
||||
|
||||
if (input.methodOption === '1') {
|
||||
@@ -169,5 +187,5 @@ export function computeProductEditorPricePreview(input: {
|
||||
)
|
||||
return fallback > 0
|
||||
? { status: 'ready', amount: fallback, source: 'آخرین قیمت ذخیرهشده' }
|
||||
: { status: 'empty', message: 'قیمت provider صفر است' }
|
||||
: { status: 'empty', message: 'قیمت مرجع صفر است' }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user