69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import type { SelectItem } from '@/models/SelectItem'
|
|||
|
|
import { isBoursecuProject } from '@/utils/config'
|
||
|
|
|
||
|
|
export const BOURSECU_GROUP_MAFTOL = 'مفتول مس'
|
||
|
|
export const BOURSECU_GROUP_KATAD = 'کاتد مس'
|
||
|
|
export const BOURSECU_GROUP_ABSHODE = 'آبشده'
|
||
|
|
|
||
|
|
const DEFAULT_TYPE_DEAL: SelectItem[] = [
|
||
|
|
{ value: 'نقدی', key: 'cash' },
|
||
|
|
{ value: 'طلایی', key: 'gold' },
|
||
|
|
]
|
||
|
|
|
||
|
|
const MAFTOL_TYPE_DEAL: SelectItem[] = [
|
||
|
|
{ value: 'کاتد', key: 'katod' },
|
||
|
|
{ value: 'نقدی', key: 'cash' },
|
||
|
|
]
|
||
|
|
|
||
|
|
const GOLD_ONLY_TYPE_DEAL: SelectItem[] = [
|
||
|
|
{ value: 'طلایی', key: 'gold' },
|
||
|
|
]
|
||
|
|
|
||
|
|
export function normalizeProductGroupType(groupType?: string | null) {
|
||
|
|
return (groupType ?? '').trim()
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isBoursecuDealProductGroup(groupType?: string | null) {
|
||
|
|
if (!isBoursecuProject()) {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
|
||
|
|
const group = normalizeProductGroupType(groupType)
|
||
|
|
return group === BOURSECU_GROUP_MAFTOL
|
||
|
|
|| group === BOURSECU_GROUP_KATAD
|
||
|
|
|| group === BOURSECU_GROUP_ABSHODE
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isMaftolMesGroup(groupType?: string | null) {
|
||
|
|
return normalizeProductGroupType(groupType) === BOURSECU_GROUP_MAFTOL
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isGoldOnlyDealGroup(groupType?: string | null) {
|
||
|
|
const group = normalizeProductGroupType(groupType)
|
||
|
|
return group === BOURSECU_GROUP_KATAD || group === BOURSECU_GROUP_ABSHODE
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getProductDealMethodOptions(groupType?: string | null): SelectItem[] {
|
||
|
|
if (!isBoursecuProject()) {
|
||
|
|
return DEFAULT_TYPE_DEAL
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isMaftolMesGroup(groupType)) {
|
||
|
|
return MAFTOL_TYPE_DEAL
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isGoldOnlyDealGroup(groupType)) {
|
||
|
|
return GOLD_ONLY_TYPE_DEAL
|
||
|
|
}
|
||
|
|
|
||
|
|
return DEFAULT_TYPE_DEAL
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getDefaultProductDealMethod(groupType?: string | null) {
|
||
|
|
return getProductDealMethodOptions(groupType)[0]?.key ?? 'cash'
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isCashLikeDealMethod(method?: string | null) {
|
||
|
|
return method === 'cash' || method === 'katod'
|
||
|
|
}
|