Sync Tahesab wallet balance on import and let admins resolve conflicts.

Add customer search on the Tahesab-only list, bulk/per-customer mande sync UI, and a decision modal when app balance differs from Tahesab.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-30 14:16:36 +03:30
co-authored by Cursor
parent 084b449177
commit 04cc03fe25
7 changed files with 761 additions and 8 deletions
@@ -26,8 +26,24 @@
<p class="m-0 text-xs" style="color: var(--admin-text-secondary)">
برای پاک کردن کد، فیلد را خالی بگذارید و ذخیره کنید.
</p>
<p
v-if="provider === 'tahesab'"
class="m-0 text-xs"
style="color: var(--admin-text-secondary)"
>
بعد از ذخیره کد ته‌حساب، اگر موجودی اپ با مانده ته‌حساب فرق داشته باشد از شما تصمیم گرفته می‌شود.
</p>
</div>
</BasicModal>
<TahesabMandeDecisionModal
v-model:visible="decisionVisible"
:app-gold="decision?.app_gold"
:app-cash="decision?.app_cash"
:tahesab-gold="decision?.tahesab_gold"
:tahesab-cash="decision?.tahesab_cash"
@decide="onDecide"
/>
</template>
<script setup lang="ts">
@@ -35,10 +51,15 @@ import { computed, ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import BasicModal from '@/components/BasicModal.vue'
import { updateCustomer } from '@/api/customer'
import {
syncCustomerWalletFromTahesab,
type TahesabWalletSyncResult,
} from '@/api/tahesab'
import type { Customer } from '@/model/customer'
import type { AccountingProvider } from '@/utils/config'
import { displayAccountingCode, normalizeAccountingCode } from '@/utils/accountingCode'
import { isMobile } from '@core/utils/is'
import TahesabMandeDecisionModal from './TahesabMandeDecisionModal.vue'
const props = defineProps<{
visible: boolean
@@ -53,6 +74,9 @@ const emit = defineEmits<{
const loading = ref(false)
const code = ref('')
const decisionVisible = ref(false)
const decision = ref<TahesabWalletSyncResult['result'] | null>(null)
const savedCustomerId = ref<number | null>(null)
const visibleProxy = computed({
get: () => props.visible,
@@ -79,6 +103,50 @@ function close() {
visibleProxy.value = false
}
async function maybeSyncTahesabWallet(customerId: number, previousCode: string, nextCode: string) {
if (props.provider !== 'tahesab') return
if (!nextCode || nextCode === previousCode) return
try {
const res = await syncCustomerWalletFromTahesab(customerId, { ask_if_conflict: true })
if (res.needs_decision || res.result?.needs_decision) {
decision.value = res.result ?? null
savedCustomerId.value = customerId
decisionVisible.value = true
return
}
if (res.result?.applied) {
message.success(res.message || 'مانده ته‌حساب روی کیف اعمال شد')
} else if (res.message) {
message.info(res.message)
}
} catch (e) {
// خطای همگام‌سازی مانع ذخیره کد نیست
console.error(e)
}
}
async function onDecide(mode: 'overwrite' | 'keep') {
const customerId = savedCustomerId.value
decisionVisible.value = false
if (!customerId) return
try {
const res = await syncCustomerWalletFromTahesab(customerId, {
overwrite: mode === 'overwrite',
keep: mode === 'keep',
ask_if_conflict: false,
})
if (mode === 'keep') {
message.info(res.message || 'موجودی اپ حفظ شد')
} else {
message.success(res.message || 'مانده ته‌حساب روی کیف اعمال شد')
}
emit('success')
} catch (e) {
console.error(e)
}
}
async function submit() {
if (!props.customer?.id) return
if (props.provider !== 'pargar' && props.provider !== 'tahesab' && props.provider !== 'zarin') {
@@ -86,6 +154,7 @@ async function submit() {
return
}
const previousCode = normalizeAccountingCode(currentCodeOf(props.customer))
const normalized = normalizeAccountingCode(code.value)
const payload =
props.provider === 'pargar'
@@ -98,6 +167,7 @@ async function submit() {
message.success('کد حسابداری ذخیره شد.')
emit('success')
close()
await maybeSyncTahesabWallet(props.customer.id, previousCode, normalized)
} catch (e) {
console.error(e)
} finally {