fix somw bug
This commit is contained in:
+5
-2
@@ -44,8 +44,11 @@ export interface PargarSyncWalletResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const syncCustomerWalletFromPargar = async (customerId: number) =>
|
export const syncCustomerWalletFromPargar = async (customerId: number, force = false) =>
|
||||||
await useAxios.post<PargarSyncWalletResult>(`/admin/customer/${customerId}/pargar/sync-wallet`)
|
await useAxios.post<PargarSyncWalletResult>(
|
||||||
|
`/admin/customer/${customerId}/pargar/sync-wallet`,
|
||||||
|
{ force }
|
||||||
|
)
|
||||||
|
|
||||||
export interface PanelOnlyCustomer {
|
export interface PanelOnlyCustomer {
|
||||||
id: number
|
id: number
|
||||||
|
|||||||
@@ -333,7 +333,9 @@ function linesForMetal(metalId: number) {
|
|||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({ reload: () => props.customerId && load(props.customerId) })
|
defineExpose({
|
||||||
|
reload: () => (props.customerId ? load(props.customerId) : Promise.resolve())
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<template>
|
||||||
|
<div class="pargar-wallet-sync">
|
||||||
|
<div class="pargar-wallet-sync__head">
|
||||||
|
<div class="pargar-wallet-sync__icon" aria-hidden="true">
|
||||||
|
<Icon icon="vuesax-linear:refresh-circle" :size="18" color="var(--admin-primary, #10913A)" />
|
||||||
|
</div>
|
||||||
|
<div class="pargar-wallet-sync__copy min-w-0 flex-1">
|
||||||
|
<p class="pargar-wallet-sync__title">همگامسازی با پرگار</p>
|
||||||
|
<p class="pargar-wallet-sync__hint">
|
||||||
|
{{
|
||||||
|
canSync
|
||||||
|
? 'اول اسنادِ اعمالنشده، بعد همترازی مانده — خودکار از پرگار کیف عوض نمیشود'
|
||||||
|
: 'ابتدا کد حسابداری پرگار را برای این مشتری ثبت کنید'
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a-button
|
||||||
|
type="primary"
|
||||||
|
block
|
||||||
|
size="small"
|
||||||
|
class="pargar-wallet-sync__btn"
|
||||||
|
:loading="loading"
|
||||||
|
:disabled="!canSync"
|
||||||
|
@click="$emit('sync')"
|
||||||
|
>
|
||||||
|
همگامسازی مانده و اسناد
|
||||||
|
</a-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import Icon from '@core/components/BaseIcon/src/Icon.vue'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
loading?: boolean
|
||||||
|
canSync?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
defineEmits<{
|
||||||
|
(e: 'sync'): void
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.pargar-wallet-sync {
|
||||||
|
@apply mb-2.5 rounded-xl border border-base p-2.5;
|
||||||
|
background: var(--admin-surface-muted, var(--admin-bg-muted, #f8fafc));
|
||||||
|
}
|
||||||
|
|
||||||
|
.pargar-wallet-sync__head {
|
||||||
|
@apply mb-2.5 flex items-start gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pargar-wallet-sync__icon {
|
||||||
|
@apply flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pargar-wallet-sync__title {
|
||||||
|
@apply m-0 text-sm font-700;
|
||||||
|
color: var(--admin-text, inherit);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pargar-wallet-sync__hint {
|
||||||
|
@apply m-0 mt-0.5 text-xs leading-5;
|
||||||
|
color: var(--admin-text-secondary, #6b7280);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pargar-wallet-sync__btn {
|
||||||
|
@apply font-600;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -158,20 +158,6 @@
|
|||||||
title="کد حسابداری"
|
title="کد حسابداری"
|
||||||
:value="accountingCodeValue"
|
:value="accountingCodeValue"
|
||||||
/>
|
/>
|
||||||
<div
|
|
||||||
v-if="pargarWalletSyncVisible"
|
|
||||||
class="col-span-2 flex items-end md:col-span-3 xl:col-span-4"
|
|
||||||
>
|
|
||||||
<a-button
|
|
||||||
type="primary"
|
|
||||||
ghost
|
|
||||||
size="small"
|
|
||||||
:loading="pargarSyncLoading"
|
|
||||||
@click="syncPargarWallet"
|
|
||||||
>
|
|
||||||
دریافت مانده از پرگار
|
|
||||||
</a-button>
|
|
||||||
</div>
|
|
||||||
<BasicInfoItem
|
<BasicInfoItem
|
||||||
title="تاریخ تولد"
|
title="تاریخ تولد"
|
||||||
:value="userInfo?.birth_date ? toJalaliNoTime(userInfo?.birth_date) : '_'"
|
:value="userInfo?.birth_date ? toJalaliNoTime(userInfo?.birth_date) : '_'"
|
||||||
@@ -204,22 +190,36 @@
|
|||||||
</BasicInfoItem>
|
</BasicInfoItem>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CustomerWalletBalancePanel
|
<div v-if="userInfo?.id && isMobile" class="mt-2 space-y-2">
|
||||||
v-if="userInfo?.id && isMobile"
|
<PargarWalletSyncAction
|
||||||
ref="walletPanelMobile"
|
v-if="pargarWalletSyncVisible"
|
||||||
:customer-id="userInfo.id"
|
:loading="pargarSyncLoading"
|
||||||
compact
|
:can-sync="pargarWalletCanSync"
|
||||||
:charge-targets="infoChargeTargets"
|
@sync="syncPargarWallet"
|
||||||
:interactive="false"
|
/>
|
||||||
class="mt-2"
|
<CustomerWalletBalancePanel
|
||||||
/>
|
:key="`wallet-mobile-${walletPanelKey}`"
|
||||||
|
ref="walletPanelMobile"
|
||||||
|
:customer-id="userInfo.id"
|
||||||
|
compact
|
||||||
|
:charge-targets="infoChargeTargets"
|
||||||
|
:interactive="false"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<aside
|
<aside
|
||||||
v-if="userInfo?.id && !isMobile"
|
v-if="userInfo?.id && !isMobile"
|
||||||
class="surface-muted min-w-0 rounded-xl border border-base p-2.5 lg:order-1 lg:sticky lg:top-0"
|
class="surface-muted min-w-0 rounded-xl border border-base p-2.5 lg:order-1 lg:sticky lg:top-0"
|
||||||
>
|
>
|
||||||
|
<PargarWalletSyncAction
|
||||||
|
v-if="pargarWalletSyncVisible"
|
||||||
|
:loading="pargarSyncLoading"
|
||||||
|
:can-sync="pargarWalletCanSync"
|
||||||
|
@sync="syncPargarWallet"
|
||||||
|
/>
|
||||||
<CustomerWalletBalancePanel
|
<CustomerWalletBalancePanel
|
||||||
|
:key="`wallet-desktop-${walletPanelKey}`"
|
||||||
ref="walletPanelDesktop"
|
ref="walletPanelDesktop"
|
||||||
:customer-id="userInfo.id"
|
:customer-id="userInfo.id"
|
||||||
layout="sidebar"
|
layout="sidebar"
|
||||||
@@ -300,11 +300,11 @@ import type { DashboardHelp } from '@/pages/dashboard/dashboardSectionCopy'
|
|||||||
import DashboardLabelWithHelp from '@/pages/dashboard/components/DashboardLabelWithHelp.vue'
|
import DashboardLabelWithHelp from '@/pages/dashboard/components/DashboardLabelWithHelp.vue'
|
||||||
import {
|
import {
|
||||||
accountingProviderSetting,
|
accountingProviderSetting,
|
||||||
initAccountingSettingsFromApi,
|
initAccountingSettingsFromApi
|
||||||
pargarEnabledSetting
|
|
||||||
} from '@/utils/config'
|
} from '@/utils/config'
|
||||||
import { displayAccountingCode, isValidAccountingCode } from '@/utils/accountingCode'
|
import { displayAccountingCode, isValidAccountingCode } from '@/utils/accountingCode'
|
||||||
import { syncCustomerWalletFromPargar } from '@/api/pargar'
|
import { syncCustomerWalletFromPargar, type PargarSyncWalletResult } from '@/api/pargar'
|
||||||
|
import PargarWalletSyncAction from './components/PargarWalletSyncAction.vue'
|
||||||
|
|
||||||
const fnameHelp: DashboardHelp = {
|
const fnameHelp: DashboardHelp = {
|
||||||
description: 'نام کوچک مشتری که در اپ و پنل نمایش داده میشود.',
|
description: 'نام کوچک مشتری که در اپ و پنل نمایش داده میشود.',
|
||||||
@@ -572,30 +572,67 @@ const accountingCodeValue = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const pargarSyncLoading = ref(false)
|
const pargarSyncLoading = ref(false)
|
||||||
const walletPanelDesktop = ref<{ reload?: () => void } | null>(null)
|
const walletPanelDesktop = ref<{ reload?: () => void | Promise<void> } | null>(null)
|
||||||
const walletPanelMobile = ref<{ reload?: () => void } | null>(null)
|
const walletPanelMobile = ref<{ reload?: () => void | Promise<void> } | null>(null)
|
||||||
|
const walletPanelKey = ref(0)
|
||||||
|
|
||||||
|
/** فقط وقتی حسابداری روی پرگار تنظیم شده باشد */
|
||||||
const pargarWalletSyncVisible = computed(
|
const pargarWalletSyncVisible = computed(
|
||||||
() =>
|
() => accountingProviderSetting.value === 'pargar'
|
||||||
pargarEnabledSetting.value &&
|
|
||||||
accountingProviderSetting.value === 'pargar' &&
|
|
||||||
isValidAccountingCode(userInfo.value?.pargar_account_id)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const pargarWalletCanSync = computed(() =>
|
||||||
|
isValidAccountingCode(userInfo.value?.pargar_account_id)
|
||||||
|
)
|
||||||
|
|
||||||
|
async function refreshWalletPanels() {
|
||||||
|
await nextTick()
|
||||||
|
walletPanelKey.value += 1
|
||||||
|
await nextTick()
|
||||||
|
await Promise.allSettled([
|
||||||
|
Promise.resolve(walletPanelDesktop.value?.reload?.()),
|
||||||
|
Promise.resolve(walletPanelMobile.value?.reload?.()),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
async function syncPargarWallet() {
|
async function syncPargarWallet() {
|
||||||
if (!userInfo.value?.id) return
|
if (!userInfo.value?.id || !pargarWalletCanSync.value) return
|
||||||
pargarSyncLoading.value = true
|
pargarSyncLoading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await syncCustomerWalletFromPargar(userInfo.value.id)
|
const res = await syncCustomerWalletFromPargar(userInfo.value.id)
|
||||||
message.success(res.message || 'مانده از پرگار اعمال شد')
|
const applied =
|
||||||
walletPanelDesktop.value?.reload?.()
|
res.ok ||
|
||||||
walletPanelMobile.value?.reload?.()
|
(res.result?.documents?.applied ?? 0) > 0 ||
|
||||||
|
Boolean(res.result?.mande?.applied)
|
||||||
|
|
||||||
|
if (applied) {
|
||||||
|
message.success(res.message || 'مانده از پرگار روی کیف اعمال شد')
|
||||||
|
} else {
|
||||||
|
message.info(res.message || 'تغییری برای اعمال نبود')
|
||||||
|
}
|
||||||
|
|
||||||
|
await refreshWalletPanels()
|
||||||
refreshTransactionTable()
|
refreshTransactionTable()
|
||||||
|
refreshTable()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg =
|
// فقط خطای واقعی شبکه/سرور — پیام ۴۲۲ را interceptor هم نشان میدهد؛ دوباره نزن
|
||||||
(e as { response?: { data?: { message?: string } } })?.response?.data?.message ||
|
const data = (e as { response?: { data?: PargarSyncWalletResult } })?.response?.data
|
||||||
'اعمال مانده از پرگار ناموفق بود'
|
const status = (e as { response?: { status?: number } })?.response?.status
|
||||||
message.warning(msg)
|
const applied =
|
||||||
|
Boolean(data?.ok) ||
|
||||||
|
(data?.result?.documents?.applied ?? 0) > 0 ||
|
||||||
|
Boolean(data?.result?.mande?.applied)
|
||||||
|
|
||||||
|
await refreshWalletPanels()
|
||||||
|
refreshTransactionTable()
|
||||||
|
refreshTable()
|
||||||
|
|
||||||
|
if (applied) {
|
||||||
|
message.success(data?.message || 'مانده از پرگار روی کیف اعمال شد')
|
||||||
|
} else if (status !== 422) {
|
||||||
|
// ۴۲۲ را axios خودش با message.error نشان داده
|
||||||
|
message.warning(data?.message || 'اعمال مانده از پرگار ناموفق بود')
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
pargarSyncLoading.value = false
|
pargarSyncLoading.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user