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
+2 -2
View File
@@ -21,7 +21,7 @@ export const createAddConst = async (obj: Const) => await useAxios.post<Const>(`
export const deleteConst = async (id: number) => await useAxios.delete<boolean>(`/api/const/${id}`)
export const updateBannerConst = async (obj: Const) =>
await useAxios.put<Const>(`/admin/const/2`, obj)
await useAxios.put<Const>(`/admin/const/${obj.id}`, obj)
export const getHeaderBannerConst = async () =>
await useAxios.get<Array<Const>>('/api/const/key/header_banner')
await useAxios.get<Const>('/api/const/key/header_banner')
+92
View File
@@ -0,0 +1,92 @@
import useAxios from '@core/utils/useAxios'
import type { TableInput } from '@core/type/baseTable'
export interface PargarRecord {
id: number
customer_id?: number
amount?: number
desc?: string
type?: string
sync_status?: 'pending' | 'success' | 'failed'
sync_log?: string | null
pargar_ref?: string | null
data?: string | null
res?: string | null
created_at?: string
customer?: {
id?: number
name?: string
mobile?: string
pargar_account_id?: string | number | null
}
}
export const getPargarTable = async (params: TableInput) =>
await useAxios.post<PargarRecord[]>('/admin/pargar/table', params)
export const getPargarDetail = async (id: number) =>
await useAxios.get<PargarRecord>(`/admin/pargar/${id}`)
export const retryPargarSanad = async (id: number) =>
await useAxios.post<{ ok: boolean; message: string; pargar?: PargarRecord }>(`/admin/pargar/${id}/retry`)
export const registerCustomerInPargar = async (customerId: number) =>
await useAxios.post<{ ok: boolean; message: string; pargar_account_id?: string | number }>(
`/admin/customer/${customerId}/pargar/register`
)
export interface PanelOnlyCustomer {
id: number
name: string
mobile: string
created_at: string
}
export interface PargarOnlyCustomer {
code: number
name: string
tel: string
gid: number | null
group: string
}
export interface CustomerSyncStatus {
panel_total: number
panel_registered: number
panel_only: number
pargar_total: number
pargar_only_count: number
panel_only_list: {
data: PanelOnlyCustomer[]
current_page: number
last_page: number
total: number
}
pargar_only_list: {
data: PargarOnlyCustomer[]
current_page: number
last_page: number
total: number
}
}
export const getCustomerSyncStatus = async (params?: {
search?: string
page?: number
pargar_page?: number
}) => await useAxios.get<CustomerSyncStatus>('/admin/pargar/customer-sync/status', { params })
export interface SyncPanelResult {
ok: boolean
success: number
failed: number
errors: { name: string; mobile: string; error: string }[]
}
export const syncPanelToPargar = async () =>
await useAxios.post<SyncPanelResult>('/admin/pargar/customer-sync/panel-to-pargar')
export const importFromPargar = async (customers: PargarOnlyCustomer[]) =>
await useAxios.post<SyncPanelResult>('/admin/pargar/customer-sync/import-from-pargar', {
customers,
})
+124
View File
@@ -0,0 +1,124 @@
<template>
<BasicModal
v-model:visible="visible"
:title="title"
:ok-text="confirmText"
:loading="loading"
width="32rem"
@ok="confirm"
@close="visible = false"
>
<div class="space-y-3 text-sm">
<div v-for="item in items" :key="item.label" class="flex justify-between gap-3 border-b border-gray-100 pb-2">
<span class="text-gray-500">{{ item.label }}</span>
<span class="text-left break-all">{{ item.value ?? '-' }}</span>
</div>
<div v-if="detail?.res" class="rounded-lg bg-gray-100 p-3 text-xs font-mono text-gray-700 whitespace-pre-wrap">{{ detail.res }}</div>
<div v-if="logText" class="rounded-lg bg-red-50 p-3 text-red-700 whitespace-pre-wrap">{{ logText }}</div>
</div>
</BasicModal>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import BasicModal from '@/components/BasicModal.vue'
import { message } from 'ant-design-vue/es'
import { getPargarDetail, retryPargarSanad, registerCustomerInPargar, type PargarRecord } from '@/api/pargar'
import { pargarStatusLabel } from '@/pages/menuPages/accounting/utils/pargarStatus'
const props = defineProps<{
modelValue: boolean
mode: 'retry-sanad' | 'register-customer'
pargarId?: number
customerId?: number
customerName?: string
}>()
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void
(e: 'success'): void
}>()
const loading = ref(false)
const detail = ref<PargarRecord | null>(null)
const visible = computed({
get: () => props.modelValue,
set: (value: boolean) => emit('update:modelValue', value)
})
const title = computed(() =>
props.mode === 'register-customer' ? 'ثبت مشتری در پرگار' : 'ارسال مجدد سند به پرگار'
)
const confirmText = computed(() =>
props.mode === 'register-customer' ? 'ثبت در پرگار' : 'ارسال مجدد'
)
const logText = computed(() => detail.value?.sync_log || '')
const items = computed(() => {
if (props.mode === 'register-customer') {
return [
{ label: 'نام مشتری', value: props.customerName || detail.value?.customer?.name },
{ label: 'شناسه مشتری', value: props.customerId || detail.value?.customer_id },
{ label: 'کد پرگار', value: detail.value?.customer?.pargar_account_id }
]
}
return [
{ label: 'شناسه سند', value: detail.value?.id },
{ label: 'مشتری', value: detail.value?.customer?.name },
{ label: 'موبایل', value: detail.value?.customer?.mobile },
{ label: 'نوع', value: detail.value?.type },
{ label: 'مقدار', value: detail.value?.amount },
{ label: 'شرح', value: detail.value?.desc },
{ label: 'وضعیت', value: pargarStatusLabel(detail.value?.sync_status, detail.value?.pargar_ref) },
{ label: 'کد پرگار', value: detail.value?.pargar_ref }
]
})
watch(
() => [props.modelValue, props.pargarId] as const,
async ([open, id]) => {
if (!open || props.mode !== 'retry-sanad' || !id) return
loading.value = true
try {
detail.value = await getPargarDetail(id)
} catch (e) {
console.error(e)
} finally {
loading.value = false
}
},
{ immediate: true }
)
async function confirm() {
loading.value = true
try {
if (props.mode === 'register-customer' && props.customerId) {
const result = await registerCustomerInPargar(props.customerId)
if (!result.ok) {
message.error(result.message || 'ثبت مشتری ناموفق بود')
return
}
message.success(result.message || 'مشتری در پرگار ثبت شد')
} else if (props.mode === 'retry-sanad' && props.pargarId) {
const result = await retryPargarSanad(props.pargarId)
if (!result.ok) {
message.error(result.message || 'ارسال مجدد ناموفق بود')
detail.value = result.pargar || detail.value
return
}
message.success(result.message || 'سند با موفقیت ثبت شد')
}
visible.value = false
emit('success')
} catch (e) {
console.error(e)
} finally {
loading.value = false
}
}
</script>
+1
View File
@@ -37,5 +37,6 @@ export interface Customer {
type_str: string
gold: number
moshtari_code?: string | number | null
pargar_account_id?: string | number | null
// print_name: string
}
@@ -0,0 +1,863 @@
<template>
<div class="cs-wrap">
<!-- ─── بنر آمار ─── -->
<div class="cs-banner">
<div class="cs-banner__title">همگام‌سازی مشتریان</div>
<!-- آمار اصلی: ردیف بالا -->
<div class="cs-stats-main">
<div class="cs-stat cs-stat--neutral">
<div class="cs-stat__num">
<template v-if="status">{{ status.panel_total }}</template>
<a-spin v-else size="small" />
</div>
<div class="cs-stat__label">مشتریان پنل</div>
</div>
<div class="cs-sep-arrows">
<Icon icon="vuesax-linear:arrow-left" :size="16" />
<Icon icon="vuesax-linear:arrow-right" :size="16" />
</div>
<div class="cs-stat cs-stat--pargar">
<div class="cs-stat__num">
<template v-if="status?.pargar_total != null">{{ status.pargar_total }}</template>
<a-spin v-else-if="loadingPargar" size="small" />
<span v-else class="cs-stat__hint">تب دوم</span>
</div>
<div class="cs-stat__label">مشتریان پرگار</div>
</div>
</div>
<!-- آمار تفاوت: ردیف پایین -->
<div class="cs-stats-diff">
<div class="cs-stat cs-stat--amber">
<div class="cs-stat__num">
<template v-if="status">{{ status.panel_only }}</template>
<a-spin v-else-if="loadingPanel" size="small" />
<span v-else>—</span>
</div>
<div class="cs-stat__label">پنل — بدون پرگار</div>
</div>
<div class="cs-stat cs-stat--sky">
<div class="cs-stat__num">
<template v-if="status?.pargar_only_count != null">{{ status.pargar_only_count }}</template>
<a-spin v-else-if="loadingPargar" size="small" />
<span v-else class="cs-stat__hint">تب دوم</span>
</div>
<div class="cs-stat__label">پرگار — بدون پنل</div>
</div>
</div>
<!-- progress -->
<div v-if="status" class="cs-progress">
<div class="cs-progress__labels">
<span>{{ registeredPercent }}٪ پنل در پرگار</span>
<span>{{ status.panel_registered }} / {{ status.panel_total }}</span>
</div>
<div class="cs-track"><div class="cs-track__fill" :style="{ width: registeredPercent + '%' }" /></div>
</div>
</div>
<!-- ─── تب‌ها ─── -->
<div class="cs-tabs">
<button
class="cs-tab"
:class="{ 'cs-tab--active': activeTab === 'panel' }"
@click="onTabChange('panel')"
>
<Icon icon="vuesax-linear:arrow-left" :size="14" />
پنل ← پرگار
<span v-if="status?.panel_only" class="cs-tab__badge cs-tab__badge--amber">{{ status.panel_only }}</span>
</button>
<button
class="cs-tab"
:class="{ 'cs-tab--active': activeTab === 'pargar' }"
@click="onTabChange('pargar')"
>
<Icon icon="vuesax-linear:arrow-right" :size="14" />
پرگار ← پنل
<span v-if="status?.pargar_only_count" class="cs-tab__badge cs-tab__badge--sky">{{ status.pargar_only_count }}</span>
</button>
</div>
<!-- ─── تب ۱: پنل → پرگار ─── -->
<div v-show="activeTab === 'panel'" class="cs-card">
<div class="cs-card__head">
<div class="cs-card__head-right">
<span class="cs-dot cs-dot--amber" />
<span class="cs-card__head-title">مشتریان پنل بدون کد پرگار</span>
</div>
<div class="cs-card__head-actions">
<a-input
v-model:value="panelSearch"
placeholder="جستجو..."
allow-clear
size="small"
class="cs-search"
@change="onPanelSearch"
/>
<a-button
type="primary"
size="small"
:loading="syncingPanel"
:disabled="!status?.panel_only"
@click="syncAllPanel"
>
<template #icon><Icon icon="vuesax-linear:send-2" :size="13" /></template>
ثبت همه در پرگار
</a-button>
</div>
</div>
<div v-if="syncingPanel || panelSyncResult" class="cs-result">
<template v-if="syncingPanel">
<a-spin size="small" />
<span>در حال ثبت مشتریان پنل در پرگار...</span>
</template>
<template v-else-if="panelSyncResult">
<span class="cs-result__ok">✓ {{ panelSyncResult.success }} موفق</span>
<span v-if="panelSyncResult.failed" class="cs-result__fail">✗ {{ panelSyncResult.failed }} ناموفق</span>
<a-button v-if="panelSyncResult.failed" type="link" size="small" @click="showPanelErrors = !showPanelErrors">
{{ showPanelErrors ? 'پنهان' : 'جزئیات' }}
</a-button>
<a-button type="link" size="small" @click="panelSyncResult = null">بستن</a-button>
</template>
<div v-if="showPanelErrors && panelSyncResult?.errors.length" class="cs-result__errors">
<div v-for="e in panelSyncResult.errors" :key="e.mobile"><b>{{ e.name }}</b> — {{ e.error }}</div>
</div>
</div>
<div v-if="loadingPanel" class="cs-loading"><a-spin /></div>
<template v-else-if="panelList.length">
<!-- موبایل -->
<div class="cs-mobile-list">
<div
v-for="c in panelList" :key="c.id"
class="cs-mobile-row"
:class="{ 'cs-mobile-row--done': panelDone.has(c.id) }"
>
<div class="cs-mobile-row__info">
<div class="cs-mobile-row__name">{{ c.name }}</div>
<div class="cs-mobile-row__mobile">{{ c.mobile }}</div>
</div>
<span v-if="panelDone.has(c.id)" class="cs-done-badge">✓ ثبت شد</span>
<a-button v-else type="primary" ghost size="small"
:loading="panelRegisteringId === c.id" @click="registerOnePanel(c)">
ارسال به پرگار
</a-button>
</div>
</div>
<!-- دسکتاپ -->
<table class="cs-table">
<thead><tr>
<th>#</th><th>نام مشتری</th><th>موبایل</th><th>تاریخ عضویت</th><th>عملیات</th>
</tr></thead>
<tbody>
<tr v-for="(c, idx) in panelList" :key="c.id"
:class="{ 'cs-table__row--done': panelDone.has(c.id) }">
<td class="cs-table__num">{{ (panelPagination.page - 1) * 20 + idx + 1 }}</td>
<td class="cs-table__name">{{ c.name }}</td>
<td class="cs-table__mobile">{{ c.mobile }}</td>
<td class="cs-table__date">{{ toJalali(c.created_at) }}</td>
<td class="cs-table__action">
<span v-if="panelDone.has(c.id)" class="cs-done-badge">✓ ثبت شد</span>
<a-button v-else type="primary" ghost size="small"
:loading="panelRegisteringId === c.id" @click="registerOnePanel(c)">
<template #icon><Icon icon="vuesax-linear:send-2" :size="13" /></template>
ارسال به پرگار
</a-button>
</td>
</tr>
</tbody>
</table>
<div v-if="panelPagination.lastPage > 1" class="cs-pagination">
<a-pagination
v-model:current="panelPagination.page"
:total="panelPagination.total"
:page-size="20" size="small" show-less-items
@change="p => loadPanel(p)"
/>
</div>
</template>
<div v-else class="cs-empty">
<div class="cs-empty__icon"><Icon icon="vuesax-linear:tick-circle" :size="28" /></div>
<div class="cs-empty__title">همه مشتریان پنل در پرگار ثبت شده‌اند</div>
</div>
</div>
<!-- ─── تب ۲: پرگار → پنل ─── -->
<div v-show="activeTab === 'pargar'" class="cs-card">
<div class="cs-card__head">
<div class="cs-card__head-right">
<span class="cs-dot cs-dot--sky" />
<span class="cs-card__head-title">مشتریان پرگار بدون حساب پنل</span>
</div>
<div class="cs-card__head-actions">
<a-button
type="primary"
size="small"
:loading="syncingPargar"
:disabled="!status?.pargar_only_count || selectedPargar.size === 0"
@click="importSelected"
>
<template #icon><Icon icon="vuesax-linear:import" :size="13" /></template>
وارد کردن انتخاب‌شده‌ها ({{ selectedPargar.size }})
</a-button>
<a-button
size="small"
:loading="importStore.active"
:disabled="!pargarOnlyList.length"
@click="importAll"
>
{{ importStore.active ? 'در حال وارد کردن…' : `وارد کردن همه (${status?.pargar_only_count ?? 0})` }}
</a-button>
</div>
</div>
<div v-if="syncingPargar || pargarSyncResult" class="cs-result">
<template v-if="syncingPargar">
<a-spin size="small" />
<span>در حال وارد کردن مشتریان پرگار به پنل...</span>
</template>
<template v-else-if="pargarSyncResult">
<span class="cs-result__ok">✓ {{ pargarSyncResult.success }} موفق</span>
<span v-if="pargarSyncResult.failed" class="cs-result__fail">✗ {{ pargarSyncResult.failed }} ناموفق</span>
<a-button v-if="pargarSyncResult.failed" type="link" size="small" @click="showPargarErrors = !showPargarErrors">
{{ showPargarErrors ? 'پنهان' : 'جزئیات' }}
</a-button>
<a-button type="link" size="small" @click="pargarSyncResult = null">بستن</a-button>
</template>
<div v-if="showPargarErrors && pargarSyncResult?.errors.length" class="cs-result__errors">
<div v-for="e in pargarSyncResult.errors" :key="e.name"><b>{{ e.name }}</b> — {{ e.error }}</div>
</div>
</div>
<div v-if="loadingPargar" class="cs-loading"><a-spin /></div>
<template v-else-if="pargarOnlyList.length">
<!-- موبایل -->
<div class="cs-mobile-list">
<div
v-for="c in pagedPargar" :key="c.code"
class="cs-mobile-row"
:class="{ 'cs-mobile-row--done': pargarDone.has(c.code) }"
>
<a-checkbox
:checked="selectedPargar.has(c.code)"
:disabled="pargarDone.has(c.code)"
class="cs-mobile-row__check"
@change="togglePargar(c.code)"
/>
<div class="cs-mobile-row__info">
<div class="cs-mobile-row__name">{{ c.name }}</div>
<div class="cs-mobile-row__mobile">{{ c.tel || '—' }} · کد {{ c.code }}</div>
</div>
<span v-if="pargarDone.has(c.code)" class="cs-done-badge">✓ وارد شد</span>
<a-button v-else type="primary" ghost size="small"
@click="importOne(c)">
وارد کردن
</a-button>
</div>
</div>
<!-- دسکتاپ -->
<table class="cs-table">
<thead><tr>
<th><a-checkbox :checked="allPageSelected" :indeterminate="someSelected" @change="toggleAll" /></th>
<th>#</th><th>نام مشتری</th><th>شماره تلفن</th><th>کد پرگار</th><th>گروه</th><th>عملیات</th>
</tr></thead>
<tbody>
<tr v-for="(c, idx) in pagedPargar" :key="c.code"
:class="{ 'cs-table__row--done': pargarDone.has(c.code) }">
<td>
<a-checkbox
:checked="selectedPargar.has(c.code)"
:disabled="pargarDone.has(c.code)"
@change="togglePargar(c.code)"
/>
</td>
<td class="cs-table__num">{{ (pargarPage - 1) * 20 + idx + 1 }}</td>
<td class="cs-table__name">{{ c.name }}</td>
<td class="cs-table__mobile">{{ c.tel || '—' }}</td>
<td class="cs-table__mobile">{{ c.code }}</td>
<td class="cs-table__date">{{ c.group || '—' }}</td>
<td class="cs-table__action">
<span v-if="pargarDone.has(c.code)" class="cs-done-badge">✓ وارد شد</span>
<a-button v-else type="primary" ghost size="small" @click="importOne(c)">
<template #icon><Icon icon="vuesax-linear:import" :size="13" /></template>
وارد کردن
</a-button>
</td>
</tr>
</tbody>
</table>
<div v-if="pargarLastPage > 1" class="cs-pagination">
<a-pagination
v-model:current="pargarPage"
:total="pargarOnlyList.length"
:page-size="20" size="small" show-less-items
@change="p => { pargarPage = p; selectedPargar.clear() }"
/>
</div>
</template>
<div v-else class="cs-empty">
<div class="cs-empty__icon"><Icon icon="vuesax-linear:tick-circle" :size="28" /></div>
<div class="cs-empty__title">همه مشتریان پرگار در پنل ثبت شده‌اند</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted, reactive, watch } from 'vue'
import { message } from 'ant-design-vue/es'
import Icon from '@core/components/BaseIcon/src/Icon.vue'
import { toJalali } from '@core/utils/useDataTime'
import {
getCustomerSyncStatus,
syncPanelToPargar,
importFromPargar,
registerCustomerInPargar,
type CustomerSyncStatus,
type PanelOnlyCustomer,
type PargarOnlyCustomer,
type SyncPanelResult,
} from '@/api/pargar'
import { useCustomerImportStore } from '@/store/customerImportStore'
const importStore = useCustomerImportStore()
// ─── state ───
const loadingPanel = ref(true) // شروع با true تا اولین load کامل بشه
const loadingPargar = ref(false)
const syncingPanel = ref(false)
const syncingPargar = ref(false)
const activeTab = ref<'panel' | 'pargar'>('panel')
const pargarFetched = ref(false) // آیا مشتریان پرگار قبلاً fetch شده؟
const status = ref<CustomerSyncStatus | null>(null)
// تب ۱
const panelSearch = ref('')
const panelList = ref<PanelOnlyCustomer[]>([])
const panelPagination = ref({ page: 1, lastPage: 1, total: 0 })
const panelDone = reactive(new Set<number>())
const panelRegisteringId = ref<number | null>(null)
const panelSyncResult = ref<SyncPanelResult | null>(null)
const showPanelErrors = ref(false)
// تب ۲
const pargarOnlyList = ref<PargarOnlyCustomer[]>([])
const pargarPage = ref(1)
const pargarDone = reactive(new Set<number>())
const selectedPargar = reactive(new Set<number>())
const pargarSyncResult = ref<SyncPanelResult | null>(null)
const showPargarErrors = ref(false)
// ─── computed ───
const registeredPercent = computed(() => {
if (!status.value?.panel_total) return 0
return Math.round((status.value.panel_registered / status.value.panel_total) * 100)
})
const pargarLastPage = computed(() => Math.max(1, Math.ceil(pargarOnlyList.value.length / 20)))
const pagedPargar = computed(() => {
const s = (pargarPage.value - 1) * 20
return pargarOnlyList.value.slice(s, s + 20)
})
const allPageSelected = computed(() =>
pagedPargar.value.length > 0 &&
pagedPargar.value.every(c => selectedPargar.has(c.code) || pargarDone.has(c.code))
)
const someSelected = computed(() =>
pagedPargar.value.some(c => selectedPargar.has(c.code)) && !allPageSelected.value
)
// ─── load panel only (سریع — بدون Pargar API) ───
let panelSearchTimer: ReturnType<typeof setTimeout> | null = null
async function load(panelPage = 1) {
loadingPanel.value = true
try {
const res = await getCustomerSyncStatus({
search: panelSearch.value || undefined,
page: panelPage,
})
// این درخواست داده‌های پرگار را شامل نمی‌شود؛ پس فیلدهای پرگار را دست‌نخورده نگه می‌داریم
if (status.value) {
status.value.panel_total = res.panel_total
status.value.panel_registered = res.panel_registered
status.value.panel_only = res.panel_only
status.value.panel_only_list = res.panel_only_list
} else {
status.value = res
}
panelList.value = res.panel_only_list.data
panelPagination.value = {
page: res.panel_only_list.current_page,
lastPage: res.panel_only_list.last_page,
total: res.panel_only_list.total,
}
} catch (e) { console.error(e) }
finally { loadingPanel.value = false }
}
// ─── load pargar customers (کند — فقط وقتی تب پرگار باز میشه) ───
async function loadPargar() {
if (pargarFetched.value) return
loadingPargar.value = true
try {
const res = await getCustomerSyncStatus({ include_pargar: 1 } as any)
if (status.value) {
status.value.pargar_total = res.pargar_total ?? 0
status.value.pargar_only_count = res.pargar_only_count ?? 0
} else {
status.value = res
}
pargarOnlyList.value = res.pargar_only_list?.data ?? []
pargarFetched.value = true
} catch (e) { console.error(e) }
finally { loadingPargar.value = false }
}
function onTabChange(tab: 'panel' | 'pargar') {
activeTab.value = tab
if (tab === 'pargar') loadPargar()
}
async function loadPanel(page = 1) {
loadingPanel.value = true
try {
const res = await getCustomerSyncStatus({ search: panelSearch.value || undefined, page })
if (status.value) {
status.value.panel_total = res.panel_total
status.value.panel_registered = res.panel_registered
status.value.panel_only = res.panel_only
}
panelList.value = res.panel_only_list.data
panelPagination.value = {
page: res.panel_only_list.current_page,
lastPage: res.panel_only_list.last_page,
total: res.panel_only_list.total,
}
} catch { } finally { loadingPanel.value = false }
}
function onPanelSearch() {
if (panelSearchTimer) clearTimeout(panelSearchTimer)
panelSearchTimer = setTimeout(() => loadPanel(1), 400)
}
// ─── تب ۱: عملیات ───
async function registerOnePanel(customer: PanelOnlyCustomer) {
panelRegisteringId.value = customer.id
try {
const res = await registerCustomerInPargar(customer.id)
if (res.ok) {
panelDone.add(customer.id)
if (status.value) { status.value.panel_registered++; status.value.panel_only-- }
message.success(`${customer.name} در پرگار ثبت شد`)
} else {
message.error((res as any).message || 'ثبت ناموفق بود')
}
} catch { message.error('خطا در ارتباط با سرور') }
finally { panelRegisteringId.value = null }
}
async function syncAllPanel() {
syncingPanel.value = true
panelSyncResult.value = null
showPanelErrors.value = false
try {
const res = await syncPanelToPargar()
panelSyncResult.value = res
if (res.success) message.success(`${res.success} مشتری ثبت شد`)
if (res.failed) message.warning(`${res.failed} مشتری ثبت نشد`)
await load(1)
panelDone.clear()
} catch { message.error('خطا در ارتباط با سرور') }
finally { syncingPanel.value = false }
}
// ─── تب ۲: عملیات ───
function togglePargar(code: number) {
if (selectedPargar.has(code)) selectedPargar.delete(code)
else selectedPargar.add(code)
}
function toggleAll() {
if (allPageSelected.value) {
pagedPargar.value.forEach(c => selectedPargar.delete(c.code))
} else {
pagedPargar.value.forEach(c => { if (!pargarDone.has(c.code)) selectedPargar.add(c.code) })
}
}
async function doImport(customers: PargarOnlyCustomer[]) {
syncingPargar.value = true
pargarSyncResult.value = null
showPargarErrors.value = false
try {
const res = await importFromPargar(customers)
pargarSyncResult.value = res
if (res.success) {
message.success(`${res.success} مشتری وارد پنل شد`)
customers.forEach(c => { if (!res.errors.find((e: any) => e.code === c.code)) pargarDone.add(c.code) })
if (status.value?.pargar_only_count != null) {
status.value.pargar_only_count = Math.max(0, status.value.pargar_only_count - res.success)
}
}
if (res.failed) message.warning(`${res.failed} مشتری وارد نشد`)
await loadPanel(panelPagination.value.page)
selectedPargar.clear()
} catch { message.error('خطا در ارتباط با سرور') }
finally { syncingPargar.value = false }
}
async function importOne(customer: PargarOnlyCustomer) { await doImport([customer]) }
async function importSelected() { await doImport(pargarOnlyList.value.filter(c => selectedPargar.has(c.code))) }
// «وارد کردن همه» با پروگرس‌بار سراسری و قابل مینیمایز (پس‌زمینه‌ای)
async function importAll() {
const pending = pargarOnlyList.value.filter(c => !pargarDone.has(c.code))
if (!pending.length) return
if (importStore.active) {
importStore.expand()
return
}
await importStore.start(pending)
}
// با پیشرفت عملیات سراسری، ردیف‌های وارد شده را همین‌جا هم تیک بزن
watch(() => importStore.doneCodes.length, () => {
importStore.doneCodes.forEach(code => pargarDone.add(code))
})
// پس از پایان کامل، آمار و لیست را تازه کن
watch(() => importStore.status, async (s, prev) => {
if (prev === 'running' && (s === 'done' || s === 'canceled')) {
selectedPargar.clear()
if (status.value?.pargar_only_count != null) {
status.value.pargar_only_count = Math.max(0, status.value.pargar_only_count - importStore.success)
}
await loadPanel(panelPagination.value.page)
}
})
onMounted(() => {
load(1)
// اگر عملیات سراسری در حال اجراست، ردیف‌های انجام‌شده را همگام کن
importStore.doneCodes.forEach(code => pargarDone.add(code))
})
</script>
<style lang="less" scoped>
.cs-wrap {
display: flex;
flex-direction: column;
gap: 14px;
padding: 8px 4px 24px;
}
/* ─── بنر ─── */
.cs-banner {
border-radius: 14px;
background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #0ea5e9 100%);
padding: 14px 16px;
color: #fff;
box-shadow: 0 4px 20px rgba(79, 70, 229, 0.35);
display: flex;
flex-direction: column;
gap: 12px;
@media (min-width: 640px) { padding: 20px 24px; gap: 16px; }
&__title { font-size: 14px; font-weight: 700; }
}
/* ردیف اصلی: پنل ↔ پرگار */
.cs-stats-main {
display: flex;
align-items: center;
gap: 8px;
}
/* ردیف تفاوت */
.cs-stats-diff {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.cs-sep-arrows {
display: flex;
flex-direction: column;
align-items: center;
color: rgba(255,255,255,0.4);
flex-shrink: 0;
line-height: 1;
}
.cs-stat {
border-radius: 10px;
padding: 8px 10px;
text-align: center;
flex: 1;
&--neutral { background: rgba(255,255,255,0.12); }
&--pargar { background: rgba(14,165,233,0.25); }
&--amber { background: rgba(251,191,36,0.2); }
&--sky { background: rgba(14,165,233,0.2); }
&__num {
font-size: 20px;
font-weight: 800;
line-height: 1;
min-height: 26px;
display: flex;
align-items: center;
justify-content: center;
@media (min-width: 640px) { font-size: 24px; }
}
&__label {
font-size: 10px;
color: rgba(255,255,255,0.65);
margin-top: 3px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
&__hint { font-size: 10px; color: rgba(255,255,255,0.4); font-weight: 400; }
}
/* progress */
.cs-progress {
&__labels {
display: flex;
justify-content: space-between;
font-size: 10px;
color: rgba(255,255,255,0.6);
margin-bottom: 5px;
}
}
.cs-track {
height: 7px;
border-radius: 99px;
background: rgba(255,255,255,0.2);
overflow: hidden;
&__fill {
height: 100%;
border-radius: 99px;
background: #34d399;
transition: width 0.7s ease;
}
}
/* ─── تب‌ها ─── */
.cs-tabs {
display: flex;
gap: 0;
border-bottom: 2px solid var(--admin-border);
overflow-x: auto;
&::-webkit-scrollbar { display: none; }
}
.cs-tab {
display: flex;
align-items: center;
gap: 5px;
padding: 8px 12px;
font-size: 12px;
font-weight: 600;
color: var(--admin-text-secondary);
background: transparent;
border: none;
border-bottom: 2px solid transparent;
margin-bottom: -2px;
cursor: pointer;
transition: all 0.2s;
white-space: nowrap;
flex-shrink: 0;
@media (min-width: 640px) { padding: 8px 16px; font-size: 13px; }
&:hover { color: var(--admin-text); }
&--active {
color: #7c3aed;
border-bottom-color: #7c3aed;
}
&__badge {
font-size: 11px;
font-weight: 700;
padding: 1px 6px;
border-radius: 99px;
&--amber { background: rgba(245,158,11,0.15); color: #d97706; }
&--sky { background: rgba(14,165,233,0.15); color: #0ea5e9; }
}
}
/* ─── کارت ─── */
.cs-card {
border-radius: 12px;
border: 1px solid var(--admin-border-strong);
background: var(--admin-bg-surface);
overflow: hidden;
&__head {
display: flex;
flex-direction: column;
gap: 10px;
padding: 12px 16px;
border-bottom: 1px solid var(--admin-border);
background: var(--admin-bg-muted);
@media (min-width: 640px) {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
}
&__head-right {
display: flex;
align-items: center;
gap: 8px;
}
&__head-title {
font-size: 13px;
font-weight: 600;
color: var(--admin-text);
}
&__head-actions {
display: flex;
gap: 6px;
align-items: center;
flex-wrap: wrap;
.ant-btn { flex-shrink: 0; }
}
}
/* روی موبایل دکمه‌های head رو کوچیک‌تر نشون بده */
@media (max-width: 639px) {
.cs-card__head-title { font-size: 12px; }
}
.cs-dot {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
flex-shrink: 0;
&--amber { background: #f59e0b; }
&--sky { background: #0ea5e9; }
}
.cs-search { width: 150px; }
@media (max-width: 639px) { .cs-search { flex: 1; min-width: 0; } }
/* ─── نتیجه sync ─── */
.cs-result {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
padding: 10px 16px;
border-bottom: 1px solid var(--admin-border);
background: var(--admin-bg-muted);
font-size: 13px;
color: var(--admin-text);
&__ok { background: rgba(52,211,153,0.15); color: #059669; font-weight: 600; border-radius: 99px; padding: 2px 10px; font-size: 12px; }
&__fail { background: rgba(239,68,68,0.12); color: #dc2626; font-weight: 600; border-radius: 99px; padding: 2px 10px; font-size: 12px; }
&__errors { width: 100%; margin-top: 4px; max-height: 100px; overflow-y: auto; border-radius: 8px; background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.2); padding: 8px 12px; font-size: 11px; color: #dc2626; line-height: 1.8; }
}
.cs-loading { display: flex; justify-content: center; padding: 48px; }
/* ─── موبایل ─── */
.cs-mobile-list {
display: block;
@media (min-width: 640px) { display: none; }
}
.cs-mobile-row {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 16px;
border-bottom: 1px solid var(--admin-border);
transition: opacity 0.2s;
&--done { opacity: 0.45; }
&__check { flex-shrink: 0; }
&__info { flex: 1; min-width: 0; }
&__name { font-size: 13px; font-weight: 600; color: var(--admin-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
&__mobile{ font-size: 11px; color: var(--admin-text-secondary); font-family: monospace; margin-top: 2px; }
}
/* ─── جدول دسکتاپ ─── */
.cs-table {
display: none;
width: 100%;
border-collapse: collapse;
font-size: 13px;
@media (min-width: 640px) { display: table; }
thead tr { background: var(--admin-bg-muted); border-bottom: 1px solid var(--admin-border); }
th { padding: 10px 14px; text-align: right; font-size: 11px; font-weight: 600; color: var(--admin-text-secondary); white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--admin-border); transition: background 0.15s; }
tbody tr:hover { background: var(--admin-bg-hover); }
tbody tr.cs-table__row--done { opacity: 0.45; }
td { padding: 10px 14px; color: var(--admin-text); }
&__num { color: var(--admin-text-secondary); font-size: 12px; width: 40px; }
&__name { font-weight: 600; }
&__mobile { font-family: monospace; font-size: 12px; color: var(--admin-text-muted); }
&__date { font-size: 12px; color: var(--admin-text-secondary); }
&__action { text-align: center; white-space: nowrap; }
}
.cs-done-badge {
display: inline-flex;
align-items: center;
background: rgba(52,211,153,0.15);
color: #059669;
font-size: 11px;
font-weight: 700;
padding: 2px 10px;
border-radius: 99px;
white-space: nowrap;
}
.cs-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 52px 16px;
gap: 8px;
&__icon { width: 52px; height: 52px; border-radius: 50%; background: rgba(52,211,153,0.12); color: #059669; display: flex; align-items: center; justify-content: center; }
&__title { font-size: 14px; font-weight: 700; color: var(--admin-text); }
}
.cs-pagination {
display: flex;
justify-content: center;
padding: 12px;
border-top: 1px solid var(--admin-border);
}
</style>
@@ -0,0 +1,79 @@
<template>
<MobileCardList
v-model:search="search"
:loading="loading"
:has-more="hasMore"
:show-empty="!loading && items.length === 0"
empty-text="سندی یافت نشد"
@search="reload"
@load-more="loadMore"
>
<PargarMobileListItem
v-for="item in items"
:key="item.id"
:item="item"
@open="openSheet"
/>
</MobileCardList>
<PargarMobileDetailSheet
v-model:visible="sheetVisible"
:item="selectedItem"
@retry="openRetry"
@register-customer="openRegister"
/>
<PargarRetryModal
v-model="retryVisible"
mode="retry-sanad"
:pargar-id="selectedItem?.id"
@success="onRetrySuccess"
/>
<PargarRetryModal
v-model="registerVisible"
mode="register-customer"
:customer-id="selectedItem?.customer_id"
:customer-name="selectedItem?.customer?.name"
@success="onRetrySuccess"
/>
</template>
<script setup lang="ts">
import { getPargarTable, type PargarRecord } from '@/api/pargar'
import MobileCardList from '@/components/mobile/MobileCardList.vue'
import { useMobileDetailSheet } from '@/components/mobile/composables/useMobileDetailSheet'
import { useMobileTableList } from '@/components/mobile/composables/useMobileTableList'
import PargarRetryModal from '@/components/PargarRetryModal.vue'
import PargarMobileDetailSheet from './PargarMobileDetailSheet.vue'
import PargarMobileListItem from './PargarMobileListItem.vue'
const { sheetVisible, selectedItem, openSheet, syncSelectedItem } = useMobileDetailSheet<PargarRecord>()
const retryVisible = ref(false)
const registerVisible = ref(false)
const { loading, search, items, hasMore, reload, loadMore, fetch } = useMobileTableList<PargarRecord>({
fetchApi: getPargarTable,
onFetched: (rows) => syncSelectedItem(rows)
})
function openRetry(item: PargarRecord) {
selectedItem.value = item
sheetVisible.value = false
retryVisible.value = true
}
function openRegister(item: PargarRecord) {
selectedItem.value = item
sheetVisible.value = false
registerVisible.value = true
}
async function onRetrySuccess() {
await fetch()
}
onMounted(() => reload())
defineExpose({ fetch })
</script>
@@ -0,0 +1,80 @@
<template>
<MobileDetailSheet v-model:visible="visibleProxy" :item="item" :title="sheetTitle">
<template #default="{ item: row }">
<MobileSheetHeader :title="sheetTitle" :show-title="isMobile">
<template #actions>
<MobileIconButton
v-if="!row.pargar_ref && !row.customer?.pargar_account_id"
plain
icon="vuesax-linear:profile-add"
color="#7C3AED"
:size="22"
@click="$emit('register-customer', row)"
/>
<MobileIconButton
v-if="canRetry(row)"
plain
icon="vuesax-linear:refresh-circle"
color="#CA8A04"
:size="22"
@click="$emit('retry', row)"
/>
</template>
</MobileSheetHeader>
<MobileInfoGrid>
<MobileDetailRow label="شناسه" :value="row.id" />
<MobileDetailRow label="مشتری" :value="row.customer?.name || '-'" />
<MobileDetailRow label="موبایل" :value="row.customer?.mobile || '-'" />
<MobileDetailRow label="نوع" :value="row.type || '-'" />
<MobileDetailRow label="مقدار" :value="row.amount ?? '-'" />
<MobileDetailRow label="شرح" full-width :value="row.desc || '-'" />
<MobileDetailRow label="وضعیت" :value="pargarStatusLabel(row.sync_status, row.pargar_ref)" />
<MobileDetailRow label="کد پرگار" :value="row.pargar_ref || '-'" />
<MobileDetailRow label="زمان" :value="row.created_at ? toJalali(row.created_at) : '-'" />
<MobileDetailRow v-if="row.res" label="پاسخ API" full-width :value="row.res" />
</MobileInfoGrid>
<div
v-if="row.sync_log"
class="mt-3 rounded-lg bg-red-50 p-3 text-sm text-red-700 whitespace-pre-wrap"
>
{{ row.sync_log }}
</div>
</template>
</MobileDetailSheet>
</template>
<script setup lang="ts">
import type { PargarRecord } from '@/api/pargar'
import MobileDetailRow from '@/components/mobile/MobileDetailRow.vue'
import MobileDetailSheet from '@/components/mobile/MobileDetailSheet.vue'
import MobileIconButton from '@/components/mobile/MobileIconButton.vue'
import MobileInfoGrid from '@/components/mobile/MobileInfoGrid.vue'
import MobileSheetHeader from '@/components/mobile/MobileSheetHeader.vue'
import { canRetryPargar, pargarStatusLabel } from '@/pages/menuPages/accounting/utils/pargarStatus'
import { isMobile } from '@core/utils/is'
import { toJalali } from '@core/utils/useDataTime'
const props = defineProps<{
visible: boolean
item: PargarRecord | null
}>()
const emit = defineEmits<{
(e: 'update:visible', value: boolean): void
(e: 'retry', item: PargarRecord): void
(e: 'register-customer', item: PargarRecord): void
}>()
const visibleProxy = computed({
get: () => props.visible,
set: (value: boolean) => emit('update:visible', value)
})
const sheetTitle = computed(() => props.item?.customer?.name || 'سند پرگار')
function canRetry(row: PargarRecord) {
return canRetryPargar(row)
}
</script>
@@ -0,0 +1,46 @@
<template>
<MobileCard clickable @click="$emit('open', item)">
<div class="space-y-1">
<div class="flex items-center justify-between gap-2">
<div class="truncate text-sm font-700 text-gray-900">{{ customerName }}</div>
<span class="shrink-0 rounded-full px-2 py-0.5 text-[11px] font-600" :class="statusClass">
{{ statusText }}
</span>
</div>
<div class="flex flex-wrap items-center gap-x-3 gap-y-0.5 text-xs text-gray-600">
<span>نوع: <span class="font-600 text-gray-900">{{ item.type || '-' }}</span></span>
<span>مقدار: <span class="font-600 text-gray-900">{{ item.amount ?? '-' }}</span></span>
</div>
<div class="text-xs text-gray-400">{{ createdAtLabel }}</div>
</div>
</MobileCard>
</template>
<script setup lang="ts">
import type { PargarRecord } from '@/api/pargar'
import MobileCard from '@/components/mobile/MobileCard.vue'
import { toJalali } from '@core/utils/useDataTime'
import { pargarStatusLabel } from '@/pages/menuPages/accounting/utils/pargarStatus'
const props = defineProps<{
item: PargarRecord
}>()
defineEmits<{
(e: 'open', item: PargarRecord): void
}>()
const customerName = computed(() => props.item.customer?.name || '-')
const createdAtLabel = computed(() =>
props.item.created_at ? toJalali(props.item.created_at) : '-'
)
const statusText = computed(() =>
pargarStatusLabel(props.item.sync_status, props.item.pargar_ref)
)
const statusClass = computed(() => {
const text = statusText.value
if (text === 'موفق') return 'bg-green-100 text-green-700'
if (text === 'ناموفق') return 'bg-red-100 text-red-700'
return 'bg-amber-100 text-amber-700'
})
</script>
@@ -0,0 +1,187 @@
<template>
<div class="min-w-0 w-full max-w-full overflow-x-hidden">
<BasicShowContext title="اسناد پرگار">
<div v-if="!isMobile" class="min-w-0 w-full max-w-full overflow-x-auto">
<BaseTable v-bind="tblProps" @register="submit" ref="tbl">
<template #action="{ record }">
<div class="flex justify-center gap-2">
<!-- دکمه ۱: اطلاعات کلی (همیشه نمایان) -->
<a-tooltip placement="bottom" class="cursor-pointer" @click="openInfo(record)">
<template #title><span>اطلاعات سند</span></template>
<Icon icon="vuesax-linear:stickynote" color="#10913A" />
</a-tooltip>
<!-- دکمه ۲: ثبت مشتری در پرگار (فقط اگر سند هنوز ثبت نشده و مشتری کد ندارد) -->
<a-tooltip
v-if="!record.pargar_ref && !record.customer?.pargar_account_id"
placement="bottom"
class="cursor-pointer"
@click="openRegister(record)"
>
<template #title><span>ثبت مشتری در پرگار</span></template>
<Icon icon="vuesax-linear:profile-add" color="#7C3AED" />
</a-tooltip>
<!-- دکمه ۳: ارسال به پرگار (فقط اگر هنوز در پرگار ثبت نشده) -->
<a-tooltip
v-if="!record.pargar_ref"
placement="bottom"
class="cursor-pointer"
@click="openSend(record)"
>
<template #title><span>ارسال به پرگار</span></template>
<Icon icon="vuesax-linear:send-2" color="#CA8A04" />
</a-tooltip>
</div>
</template>
</BaseTable>
</div>
<PargarMobileCardList v-else ref="mobileListRef" />
</BasicShowContext>
<!-- مودال اطلاعات کلی -->
<BasicModal v-model:visible="infoVisible" title="اطلاعات سند" width="36rem" :footer="null">
<div class="space-y-2 text-sm">
<div
v-for="item in infoItems"
:key="item.label"
class="flex justify-between gap-3 border-b border-gray-100 py-2"
>
<span class="text-gray-500">{{ item.label }}</span>
<span class="break-all text-left">{{ item.value ?? '-' }}</span>
</div>
<div v-if="selected?.res" class="rounded-lg bg-gray-100 p-3 text-xs font-mono text-gray-700 whitespace-pre-wrap">
{{ selected.res }}
</div>
<div v-if="selected?.sync_log" class="rounded-lg bg-red-50 p-3 text-red-700 whitespace-pre-wrap">
{{ selected.sync_log }}
</div>
</div>
</BasicModal>
<!-- مودال ارسال به پرگار -->
<PargarRetryModal
v-model="sendVisible"
mode="retry-sanad"
:pargar-id="selected?.id"
@success="fetch"
/>
<!-- مودال ثبت مشتری در پرگار -->
<PargarRetryModal
v-model="registerVisible"
mode="register-customer"
:customer-id="selected?.customer_id"
:customer-name="selected?.customer?.name"
@success="fetch"
/>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import useBaseTable from '@core/components/BaseTable/hooks/useBaseTable'
import type { TableInput } from '@core/type/baseTable'
import { getPargarTable, type PargarRecord } from '@/api/pargar'
import Icon from '@core/components/BaseIcon/src/Icon.vue'
import { isMobile } from '@core/utils/is'
import BasicModal from '@/components/BasicModal.vue'
import PargarRetryModal from '@/components/PargarRetryModal.vue'
import PargarMobileCardList from '@/pages/menuPages/accounting/components/PargarMobileCardList.vue'
import { pargarStatusLabel } from '@/pages/menuPages/accounting/utils/pargarStatus'
import { toJalali } from '@core/utils/useDataTime'
const [submit, reload] = useBaseTable()
const mobileListRef = ref<null | { fetch: () => Promise<void> }>(null)
const infoVisible = ref(false)
const sendVisible = ref(false)
const registerVisible = ref(false)
const selected = ref<PargarRecord | null>(null)
const columns = [
{
title: 'ردیف',
dataIndex: 'id',
key: 'id',
filterable: false,
sortable: false,
customRender: (r: any) => r.index + 1
},
{ title: 'مشتری', dataIndex: 'customer.name', key: 'customer.name', type: 'Text' },
{ title: 'نوع', dataIndex: 'type', key: 'type', type: 'Text' },
{ title: 'مقدار', dataIndex: 'amount', key: 'amount', type: 'Number' },
{ title: 'شرح', dataIndex: 'desc', key: 'desc', type: 'Text' },
{
title: 'وضعیت',
dataIndex: 'sync_status',
key: 'sync_status',
type: 'Text',
filterable: false,
customRender: (r: any) => pargarStatusLabel(r.record.sync_status, r.record.pargar_ref)
},
{
title: 'زمان',
dataIndex: 'created_at',
key: 'created_at',
type: 'Text',
customRender: (r: any) => toJalali(r.record.created_at)
},
{
title: 'عملیات',
dataIndex: 'action',
key: 'action',
slot: 'action',
filterable: false
}
]
const tblProps = ref({
columns,
api: (params: TableInput) => getPargarTable(params)
})
/** اطلاعاتی که برای هر سند حسابداری نیاز است (بدون جزئیات پرگار‌محور) */
const infoItems = computed(() => {
const row = selected.value
if (!row) return []
return [
{ label: 'شناسه سند', value: row.id },
{ label: 'مشتری', value: row.customer?.name },
{ label: 'موبایل', value: row.customer?.mobile },
{ label: 'نوع', value: row.type },
{ label: 'مقدار', value: row.amount },
{ label: 'شرح', value: row.desc },
{ label: 'زمان ثبت', value: row.created_at ? toJalali(row.created_at) : '-' },
{ label: 'وضعیت', value: pargarStatusLabel(row.sync_status, row.pargar_ref) },
{ label: 'کد پرگار', value: row.pargar_ref || 'ثبت نشده' }
]
})
function openInfo(record: PargarRecord) {
selected.value = record
infoVisible.value = true
}
function openSend(record: PargarRecord) {
selected.value = record
sendVisible.value = true
}
function openRegister(record: PargarRecord) {
selected.value = record
registerVisible.value = true
}
async function fetch() {
if (isMobile.value) {
await mobileListRef.value?.fetch?.()
return
}
await reload()
}
defineExpose({ fetch })
</script>
+11 -4
View File
@@ -3,16 +3,20 @@
<BasicMainCard>
<div
class="flex h-full w-full min-w-0 max-w-full flex-col overflow-x-hidden"
:class="activeTab === 'customer-sync' ? 'overflow-y-auto' : 'overflow-hidden'"
:class="activeTab === 'customer-sync' || activeTab === 'pargar-customer-sync' ? 'overflow-y-auto' : 'overflow-hidden'"
>
<ATabs v-model:activeKey="activeTab" class="mb-3 shrink-0">
<ATabPane key="reports" tab="گزارشات" />
<ATabPane v-if="tahesabEnabled" key="tahesab" tab="اسناد ته‌حساب" />
<ATabPane v-if="tahesabEnabled" key="customer-sync" tab="همگام سازی مشتریان در ته‌حساب" />
<ATabPane v-if="pargarEnabled" key="pargar" tab="اسناد پرگار" />
<ATabPane v-if="pargarEnabled" key="pargar-customer-sync" tab="همگام سازی مشتریان در پرگار" />
</ATabs>
<tbl v-if="activeTab === 'reports'" ref="table" class="min-h-0 flex-1" />
<tahesabTbl v-else-if="tahesabEnabled && activeTab === 'tahesab'" ref="tahesabTable" class="min-h-0 flex-1" />
<customerSync v-else-if="tahesabEnabled && activeTab === 'customer-sync'" class="shrink-0" />
<pargarTbl v-else-if="pargarEnabled && activeTab === 'pargar'" ref="pargarTable" class="min-h-0 flex-1" />
<pargarCustomerSync v-else-if="pargarEnabled && activeTab === 'pargar-customer-sync'" class="shrink-0" />
</div>
</BasicMainCard>
<BasicModal
@@ -134,6 +138,8 @@ import { ref } from 'vue'
import tbl from './components/table.vue'
import tahesabTbl from './components/tahesabTable.vue'
import customerSync from './components/TahesabCustomerSync.vue'
import pargarTbl from './components/pargarTable.vue'
import pargarCustomerSync from './components/PargarCustomerSync.vue'
import type { FormInstance } from 'ant-design-vue'
import BasicInfoModal from '@/components/BasicInfoModal/index.vue'
import { message } from 'ant-design-vue/es'
@@ -151,12 +157,13 @@ import type { last } from '@/model/price'
import { createOrder } from '@/api/order'
import { getCashBalance, getGoldBalance } from '@/components/mobile/utils/wallet'
import { metalLabel } from '@/utils/adminMetalLabels'
import { initTahesabSettingFromApi, tahesabEnabledSetting } from '@/utils/config'
import { initAccountingSettingsFromApi, tahesabEnabledSetting, pargarEnabledSetting } from '@/utils/config'
//loading
const loading = ref<boolean>(false)
const activeTab = ref<'reports' | 'tahesab' | 'customer-sync'>('reports')
const activeTab = ref<'reports' | 'tahesab' | 'customer-sync' | 'pargar' | 'pargar-customer-sync'>('reports')
const tahesabEnabled = tahesabEnabledSetting
const pargarEnabled = pargarEnabledSetting
//define store
const store = useStaticApiListsStore()
@@ -181,7 +188,7 @@ async function getCustomers() {
onMounted(() => {
getCustomers()
void initTahesabSettingFromApi()
void initAccountingSettingsFromApi()
})
//form
@@ -0,0 +1,12 @@
export function pargarStatusLabel(status?: string, pargarId?: string | null): string {
if (pargarId) return 'موفق'
if (status === 'failed') return 'ناموفق'
if (status === 'success') return 'موفق'
// pending = ردیف محلی ساخته شده ولی هنوز در نرم‌افزار پرگار ثبت نشده (نه «در صف»)
return 'ارسال نشده'
}
export function canRetryPargar(record: { pargar_ref?: string | null; sync_status?: string }): boolean {
return !record.pargar_ref || record.sync_status === 'failed'
}
+15 -9
View File
@@ -111,26 +111,32 @@ function handelRemoveFile(index: number, size: string) {
}
async function handleSubmit() {
if (!id) {
message.error('شناسه بنر یافت نشد؛ صفحه را رفرش کنید')
return
}
try {
await updateBannerConst({
id: 14,
id,
value: JSON.stringify(benefitsList.value),
key: "header_banner"
key: 'header_banner',
})
message.success("اطلاعات با موفقیت ذخیره شد")
message.success('اطلاعات با موفقیت ذخیره شد')
} catch (error) {
message.error("خطا در ذخیره اطلاعات")
message.error('خطا در ذخیره اطلاعات')
}
}
onMounted(async () => {
try {
const res = await getHeaderBannerConst()
if (res?.length > 0) {
id = res[0].id || res[0].const_id || null
benefitsList.value = parseBannerList(res[0].value)
if (!res) {
return
}
id = res.id ?? res.const_id ?? null
benefitsList.value = parseBannerList(res.value)
} catch (error) {
console.error('خطا در دریافت بنرها:', error)
}
@@ -151,4 +157,4 @@ onMounted(async () => {
overflow-y: auto;
box-sizing: border-box;
}
</style>
</style>
+1 -1
View File
@@ -323,7 +323,7 @@ const visibleSettingGroups = computed(() =>
const defaultOpenGroupId = computed(() => {
const visibleIds = visibleSettingGroups.value.map((g) => g.id)
const preferred = isSystemMode.value
? ['chart', 'pricing', 'payping', 'tahesab', 'store', 'general']
? ['chart', 'pricing', 'payping', 'accounting', 'store', 'general']
: ['general', 'content', 'pricing', 'price_source', 'referral']
const fromPreferred = preferred.find((id) => visibleIds.includes(id))
return fromPreferred ?? visibleIds[0]
@@ -142,10 +142,15 @@ export const SYSTEM_SETTING_GROUPS: SettingGroupDef[] = [
match: (k) => k.startsWith('payping_')
},
{
id: 'tahesab',
title: 'ته‌حساب',
id: 'accounting',
title: 'حسابداری',
icon: 'vuesax-linear:receipt-2',
match: (k) => k.startsWith('tahesab_') || k === 'send_to_tahesab'
match: (k) =>
k === 'accounting_provider'
|| k.startsWith('tahesab_')
|| k.startsWith('pargar_')
|| k === 'send_to_tahesab'
|| k === 'send_to_pargar'
},
{
id: 'infra',
@@ -115,6 +115,7 @@ const KEY_TYPE_FALLBACK: Record<string, SettingFieldType> = {
endDay: 'time',
show_last_price: 'switch',
send_to_tahesab: 'switch',
accounting_provider: 'select',
profit_gold_api_enabled: 'switch',
payping_round_toman: 'switch',
payping_strict_failed_withdraw: 'switch',
@@ -136,6 +137,9 @@ const KEY_TYPE_FALLBACK: Record<string, SettingFieldType> = {
tahesab_token: 'text',
tahesab_db: 'text',
tahesab_bank_account: 'text',
pargar_username: 'text',
pargar_password: 'text',
pargar_api_token: 'text',
support_messenger_id: 'text',
support_messenger_text: 'longtext',
invite_link_text: 'longtext',
@@ -145,6 +149,11 @@ const KEY_TYPE_FALLBACK: Record<string, SettingFieldType> = {
}
const SELECT_LABELS_BY_KEY: Record<string, Record<string, string>> = {
accounting_provider: {
none: 'هیچکدام',
pargar: 'پرگار',
tahesab: 'ته‌حساب'
},
support_messenger: {
bale: 'بله',
telegram: 'تلگرام',
@@ -156,6 +165,7 @@ const SELECT_LABELS_BY_KEY: Record<string, Record<string, string>> = {
}
const SELECT_OPTIONS_BY_KEY: Record<string, string> = {
accounting_provider: 'none,pargar,tahesab',
price_provider: 'montzar,zaarbox,main_product',
payping_gateway_name: 'sepal,',
unit: 'گرم,کیلوگرم',
@@ -400,7 +410,17 @@ const KEY_HELP_FALLBACK: Record<string, string> = {
payping_strict_failed_withdraw:
'روشن: در صورت برداشت ناموفق قبلی، تسویه جدید با احتیاط بیشتر انجام می‌شود.',
send_to_tahesab:
'روشن: واریز و برداشت مشتریان به‌صورت خودکار به ته‌حساب ارسال می‌شود.',
'تنظیم قدیمی — از «سیستم حسابداری» استفاده کنید.',
accounting_provider:
'سیستم حسابداری متصل: پرگار (API ورودی)، ته‌حساب (ارسال خودکار)، یا هیچکدام.',
send_to_pargar:
'تنظیم قدیمی — از «سیستم حسابداری» استفاده کنید.',
pargar_username:
'نام کاربری که نرم‌افزار پرگار برای login به /pargar/login استفاده می‌کند.',
pargar_password:
'رمز عبور login API پرگار — در پنل ثبت می‌شود و به پرگار داده می‌شود.',
pargar_api_token:
'توکن ثابت اختیاری برای احراز API پرگار (جایگزین توکن login).',
tahesab_host:
'آدرس سرور نرم‌افزار ته‌حساب در شبکه.',
tahesab_port:
@@ -450,7 +470,9 @@ export const KEY_LABEL_FALLBACK: Record<string, string> = {
montzar_open_sell: 'فروش از همکار',
external_order_api_enabled: 'API سفارش خارجی',
payping_fin_sync_enabled: 'همگام‌سازی با حسابداری مالی',
send_to_tahesab: 'ارسال خودکار به ته‌حساب',
accounting_provider: 'سیستم حسابداری',
send_to_tahesab: 'ارسال خودکار به ته‌حساب (قدیمی)',
send_to_pargar: 'ارسال خودکار به پرگار (قدیمی)',
support_messenger: 'پیام‌رسان پشتیبانی',
deposit_sms_support_number: 'شماره پشتیبانی واریز'
}
@@ -477,9 +499,10 @@ export const SETTING_LOCKED_KEYS = new Set([
'payping_gateway_items', 'payping_gateway_name',
'payping_round_toman', 'payping_start_url', 'payping_strict_failed_withdraw', 'payping_verify_url',
'price_extreme_date', 'price_provider', 'profit_gold_api_enabled',
'send_to_tahesab', 'service_charge_percentage',
'send_to_tahesab', 'send_to_pargar', 'accounting_provider', 'service_charge_percentage',
'sse_path',
'tahesab_bank_account', 'tahesab_db', 'tahesab_host', 'tahesab_port', 'tahesab_token',
'pargar_api_token', 'pargar_password', 'pargar_username',
'telegram_bot_token',
'unit',
'up_price', 'down_price',
@@ -66,6 +66,15 @@
<template #title><span>در ته‌حساب ثبت نشده — کلیک برای ثبت</span></template>
<Icon icon="vuesax-linear:profile-add" color="#CA8A04" />
</a-tooltip>
<a-tooltip
v-if="pargarEnabled && !record.pargar_account_id"
placement="bottom"
class="cursor-pointer"
@click="openPargarRegister(record)"
>
<template #title><span>در پرگار ثبت نشده — کلیک برای ثبت</span></template>
<Icon icon="vuesax-linear:profile-add" color="#7C3AED" />
</a-tooltip>
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('info', record)">
<template #title><span>مشخصات</span></template>
<Icon icon="vuesax-linear:stickynote" color="#10913A" />
@@ -148,6 +157,14 @@
:customer-name="tahesabCustomer?.name"
@success="fetch"
/>
<PargarRetryModal
v-if="pargarEnabled"
v-model="pargarRegisterVisible"
mode="register-customer"
:customer-id="pargarCustomer?.id"
:customer-name="pargarCustomer?.name"
@success="fetch"
/>
</BasicShowContext>
</div>
</template>
@@ -173,7 +190,8 @@ import { MODAL_ABOVE_ACTION_SHEET_Z_INDEX } from '@/constants/overlayZIndex'
import { isMobile } from '@core/utils/is'
import { metalLabel } from '@/utils/adminMetalLabels'
import TahesabRetryModal from '@/components/TahesabRetryModal.vue'
import { tahesabEnabledSetting, initTahesabSettingFromApi } from '@/utils/config'
import PargarRetryModal from '@/components/PargarRetryModal.vue'
import { tahesabEnabledSetting, pargarEnabledSetting, initAccountingSettingsFromApi } from '@/utils/config'
const [submit, reload] = useBaseTable()
const emits = defineEmits(['delete', 'edit', 'add', 'info', 'chargeMoney', 'chargeGold'])
@@ -184,6 +202,9 @@ const confirmInfo = ref<Customer>()
const tahesabRegisterVisible = ref(false)
const tahesabCustomer = ref<Customer>()
const tahesabEnabled = tahesabEnabledSetting
const pargarRegisterVisible = ref(false)
const pargarCustomer = ref<Customer>()
const pargarEnabled = pargarEnabledSetting
const mobileListRef = ref<null | { fetch: () => Promise<void> }>(null)
const tblProps = ref<any>({
@@ -203,7 +224,7 @@ const fetch = async () => {
defineExpose({ fetch })
onMounted(() => {
void initTahesabSettingFromApi()
void initAccountingSettingsFromApi()
})
async function changeCustomerActivationFunction(id: number) {
@@ -229,6 +250,11 @@ function openTahesabRegister(user: Customer) {
tahesabRegisterVisible.value = true
}
function openPargarRegister(user: Customer) {
pargarCustomer.value = user
pargarRegisterVisible.value = true
}
function handleArchive(customer: Customer) {
Modal.confirm({
title: 'آیا مشتری را بایگانی می کنید؟',
@@ -127,7 +127,7 @@ import {
needsWeightAssignment
} from '@/pages/menuPages/withdraw/utils/withdrawDisplay'
import TahesabRetryModal from '@/components/TahesabRetryModal.vue'
import { initTahesabSettingFromApi, tahesabEnabledSetting } from '@/utils/config'
import { initAccountingSettingsFromApi, tahesabEnabledSetting } from '@/utils/config'
const props = withDefaults(
defineProps<{
@@ -211,7 +211,7 @@ defineExpose({
})
onMounted(() => {
void initTahesabSettingFromApi()
void initAccountingSettingsFromApi()
})
import { status } from '@/pages/menuPages/withdraw/information/hooks/status'
+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
}