fixsome changes
This commit is contained in:
@@ -12,12 +12,45 @@ export function findMethodPriceEntry(
|
||||
): MethodePrices | undefined {
|
||||
if (!readingMethod) return undefined
|
||||
|
||||
return prices.find(
|
||||
(entry) =>
|
||||
entry.key === readingMethod ||
|
||||
entry.id === readingMethod ||
|
||||
entry.name === readingMethod
|
||||
)
|
||||
const needle = String(readingMethod).trim()
|
||||
if (!needle) return undefined
|
||||
|
||||
return prices.find((entry) => {
|
||||
const key = String(entry.key ?? '').trim()
|
||||
const id = String(entry.id ?? '').trim()
|
||||
const name = String(entry.name ?? '').trim()
|
||||
return key === needle || id === needle || name === needle
|
||||
})
|
||||
}
|
||||
|
||||
/** مقدار value سلکت مرجع — key خالی را با ?? نگه نمیدارد */
|
||||
export function canonicalMethodPriceId(entry: MethodePrices): string {
|
||||
return String(entry.key || entry.id || entry.name || '').trim()
|
||||
}
|
||||
|
||||
/** reading_method ذخیرهشده (name/key/id) را به id سلکت همتراز میکند */
|
||||
export function resolveReadingMethodForSelect(
|
||||
raw: string | null | undefined,
|
||||
prices: MethodePrices[]
|
||||
): string | null | undefined {
|
||||
if (raw == null) return raw
|
||||
const trimmed = String(raw).trim()
|
||||
if (!trimmed) return raw
|
||||
|
||||
const entry = findMethodPriceEntry(prices, trimmed)
|
||||
if (!entry) return trimmed
|
||||
|
||||
return canonicalMethodPriceId(entry) || trimmed
|
||||
}
|
||||
|
||||
/** مرجع روی محصول هست ولی در فید/لیست فعلی همکار پیدا نمیشود */
|
||||
export function isOrphanReadingMethod(
|
||||
raw: string | null | undefined,
|
||||
prices: MethodePrices[]
|
||||
): boolean {
|
||||
const trimmed = String(raw ?? '').trim()
|
||||
if (!trimmed || !prices.length) return false
|
||||
return !findMethodPriceEntry(prices, trimmed)
|
||||
}
|
||||
|
||||
export function normalizeReferenceBase(entry: MethodePrices): { base: number; profit: number } {
|
||||
@@ -117,7 +150,12 @@ export function computeProductEditorPricePreview(input: {
|
||||
}
|
||||
const entry = findMethodPriceEntry(input.pricesData, input.form.reading_method)
|
||||
if (!entry) {
|
||||
return { status: 'empty', message: '' }
|
||||
return {
|
||||
status: 'empty',
|
||||
message: input.pricesData.length
|
||||
? 'مرجع در لیست قیمت یافت نشد'
|
||||
: 'لیست قیمت مرجع خالی است — بروزرسانی را بزنید',
|
||||
}
|
||||
}
|
||||
const { base } = normalizeReferenceBase(entry)
|
||||
if (base <= 0) {
|
||||
@@ -177,7 +215,12 @@ export function computeProductEditorPricePreview(input: {
|
||||
}
|
||||
const entry = findMethodPriceEntry(input.pricesData, input.form.reading_method)
|
||||
if (!entry) {
|
||||
return { status: 'empty', message: '' }
|
||||
return {
|
||||
status: 'empty',
|
||||
message: input.pricesData.length
|
||||
? 'مرجع در لیست قیمت یافت نشد'
|
||||
: 'لیست قیمت مرجع خالی است — بروزرسانی را بزنید',
|
||||
}
|
||||
}
|
||||
const { base, profit } = normalizeReferenceBase(entry)
|
||||
const liveAmount = adjustedProductPrice(base, profit, offsetPercent)
|
||||
@@ -232,7 +275,12 @@ export function computeProductEditorPricePreview(input: {
|
||||
}
|
||||
const entry = findMethodPriceEntry(input.pricesData, input.form.reading_method)
|
||||
if (!entry) {
|
||||
return { status: 'empty', message: '' }
|
||||
return {
|
||||
status: 'empty',
|
||||
message: input.pricesData.length
|
||||
? 'مرجع در لیست قیمت یافت نشد'
|
||||
: 'لیست قیمت مرجع خالی است — بروزرسانی را بزنید',
|
||||
}
|
||||
}
|
||||
const { base, profit } = normalizeReferenceBase(entry)
|
||||
const liveAmount = adjustedProductPrice(base, profit, offsetPercent)
|
||||
|
||||
Reference in New Issue
Block a user