added pargar accounting

This commit is contained in:
2026-07-05 16:41:45 +03:30
parent 86e6c3c16f
commit 8d8be02d96
18 changed files with 1649 additions and 31 deletions
+72 -5
View File
@@ -1,6 +1,8 @@
import { ref } from 'vue'
import { setCachedMainMetal } from '@/utils/metalLabels'
export type AccountingProvider = 'none' | 'pargar' | 'tahesab'
export function getConfigApp(key: string) {
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user : {}
@@ -19,13 +21,53 @@ export const bannerEnabledSetting = ref(false)
/** reactive — نمایش UI ته‌حsاب در حسابداری و ... */
export const tahesabEnabledSetting = ref(false)
/** reactive — نمایش UI پرگar در حسابداری و ... */
export const pargarEnabledSetting = ref(false)
export const accountingProviderSetting = ref<AccountingProvider>('none')
let tahesabEnabledFromSettings: boolean | null = null
let pargarEnabledFromSettings: boolean | null = null
let accountingProviderFromSettings: AccountingProvider | null = null
function isSwitchOn(value: string | undefined | null): boolean {
const v = (value ?? '').trim().toLowerCase()
return v === 'true' || v === '1' || v === 'yes'
}
function normalizeAccountingProvider(value: string | undefined | null): AccountingProvider {
const v = (value ?? '').trim().toLowerCase()
if (v === 'pargar' || v === 'tahesab') return v
return 'none'
}
function resolveAccountingProviderFromRows(
list: Array<{ key?: string; value?: string | null }>
): AccountingProvider {
const row = list.find((item) => item.key === 'accounting_provider')
if (row?.value !== undefined && row?.value !== null && String(row.value).trim() !== '') {
return normalizeAccountingProvider(row.value)
}
const pargarLegacy = list.find((item) => item.key === 'send_to_pargar')
if (pargarLegacy && isSwitchOn(pargarLegacy.value)) return 'pargar'
const tahesabLegacy = list.find((item) => item.key === 'send_to_tahesab')
if (tahesabLegacy && isSwitchOn(tahesabLegacy.value)) return 'tahesab'
return 'none'
}
export function applyAccountingProviderFromRows(
list: Array<{ key?: string; value?: string | null }>
): void {
const provider = resolveAccountingProviderFromRows(list)
accountingProviderFromSettings = provider
accountingProviderSetting.value = provider
setTahesabEnabledFromSettings(provider === 'tahesab')
setPargarEnabledFromSettings(provider === 'pargar')
}
export function setStoreModeFromSettings(value: boolean): void {
storeModeFromSettings = value
}
@@ -39,6 +81,11 @@ export function setTahesabEnabledFromSettings(value: boolean): void {
tahesabEnabledSetting.value = value
}
export function setPargarEnabledFromSettings(value: boolean): void {
pargarEnabledFromSettings = value
pargarEnabledSetting.value = value
}
export function applyBannerEnabledFromRows(rows: Array<{ key?: string; value?: string | null }>) {
const row = rows.find((item) => item.key === 'banner_enabled')
setBannerEnabledFromSettings(row ? isSwitchOn(row.value) : false)
@@ -55,9 +102,8 @@ async function bootstrapSettingsFromApi(): Promise<void> {
const isStoreRow = list.find((item) => item.key === 'is_store')
const mainWalletRow = list.find((item) => item.key === 'main_wallet_products')
const mainMetalRow = list.find((item) => item.key === 'main_metal')
const tahesabRow = list.find((item) => item.key === 'send_to_tahesab')
storeModeFromSettings = isStoreRow ? isSwitchOn(isStoreRow.value) : false
setTahesabEnabledFromSettings(tahesabRow ? isSwitchOn(tahesabRow.value) : false)
applyAccountingProviderFromRows(list)
applyBannerEnabledFromRows(list)
setCachedMainMetal(mainMetalRow?.value)
const { setCachedMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
@@ -65,7 +111,7 @@ async function bootstrapSettingsFromApi(): Promise<void> {
} catch {
storeModeFromSettings = false
setBannerEnabledFromSettings(false)
setTahesabEnabledFromSettings(false)
applyAccountingProviderFromRows([])
setCachedMainMetal(null)
const { setCachedMainWalletProductIds } = await import('@/components/mobile/utils/wallet')
setCachedMainWalletProductIds([])
@@ -95,10 +141,31 @@ export function isTahesabEnabled(): boolean {
return tahesabEnabledFromSettings === true
}
export async function initTahesabSettingFromApi(): Promise<boolean> {
if (tahesabEnabledFromSettings !== null) return tahesabEnabledFromSettings === true
export function isPargarEnabled(): boolean {
return pargarEnabledFromSettings === true
}
export function getAccountingProvider(): AccountingProvider {
return accountingProviderFromSettings ?? 'none'
}
/** بارگذاری accounting_provider و فلگ‌های UI */
export async function initAccountingSettingsFromApi(): Promise<AccountingProvider> {
if (accountingProviderFromSettings !== null) return accountingProviderFromSettings
await bootstrapSettingsFromApi()
return accountingProviderFromSettings ?? 'none'
}
/** @deprecated از initAccountingSettingsFromApi استفاده کنید */
export async function initTahesabSettingFromApi(): Promise<boolean> {
await initAccountingSettingsFromApi()
return tahesabEnabledFromSettings === true
}
/** @deprecated از initAccountingSettingsFromApi استفاده کنید */
export async function initPargarSettingFromApi(): Promise<boolean> {
await initAccountingSettingsFromApi()
return pargarEnabledFromSettings === true
}