feat(tahesab): add local status reset before resending wiped documents
Confirm and call reset-local so the pending count includes previously successful rows, then send all as usual. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -101,6 +101,14 @@ export const stopTahesabDocSync = async () =>
|
|||||||
'/admin/tahesab/doc-sync/stop'
|
'/admin/tahesab/doc-sync/stop'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const resetTahesabLocalDocs = async () =>
|
||||||
|
await useAxios.post<{
|
||||||
|
ok: boolean
|
||||||
|
message: string
|
||||||
|
cleared: number
|
||||||
|
summary: TahesabPendingSummary
|
||||||
|
}>('/admin/tahesab/doc-sync/reset-local')
|
||||||
|
|
||||||
export const startTahesabCustomerOutbound = async () =>
|
export const startTahesabCustomerOutbound = async () =>
|
||||||
await useAxios.post<{ ok: boolean; message: string; doc_sync: TahesabDocSyncState }>(
|
await useAxios.post<{ ok: boolean; message: string; doc_sync: TahesabDocSyncState }>(
|
||||||
'/admin/tahesab/customer-sync/outbound/start'
|
'/admin/tahesab/customer-sync/outbound/start'
|
||||||
|
|||||||
@@ -7,24 +7,38 @@
|
|||||||
<p class="mb-0 mt-1 text-xs leading-relaxed text-gray-500">
|
<p class="mb-0 mt-1 text-xs leading-relaxed text-gray-500">
|
||||||
با یک کلیک همهٔ سفارشها و شارژهای جاافتاده یکییکی و با فاصله به تهحساب میروند.
|
با یک کلیک همهٔ سفارشها و شارژهای جاافتاده یکییکی و با فاصله به تهحساب میروند.
|
||||||
بعد از سندها، مشتریان پنلِ بدون کد هم همانجا ثبت میشوند. پیشرفت را میتوانید کوچک کنید.
|
بعد از سندها، مشتریان پنلِ بدون کد هم همانجا ثبت میشوند. پیشرفت را میتوانید کوچک کنید.
|
||||||
|
اگر سندها در تهحساب پاک شده، اول وضعیت محلی را بازنشانی کنید.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<a-button
|
<div class="flex w-full shrink-0 flex-col gap-2 sm:w-auto">
|
||||||
type="primary"
|
<a-button
|
||||||
class="!w-full shrink-0 sm:!w-auto"
|
type="primary"
|
||||||
:loading="store.starting || store.active"
|
class="!w-full sm:!w-auto"
|
||||||
:disabled="store.active"
|
:loading="store.starting || store.active"
|
||||||
@click="onStart"
|
:disabled="store.active || store.resetting"
|
||||||
>
|
@click="onStart"
|
||||||
{{ store.active ? 'در حال ارسال…' : 'ارسال همه سندها' }}
|
>
|
||||||
</a-button>
|
{{ store.active ? 'در حال ارسال…' : 'ارسال همه سندها' }}
|
||||||
|
</a-button>
|
||||||
|
<a-button
|
||||||
|
class="!w-full sm:!w-auto"
|
||||||
|
:loading="store.resetting"
|
||||||
|
:disabled="store.active"
|
||||||
|
@click="onReset"
|
||||||
|
>
|
||||||
|
بازنشانی وضعیت محلی
|
||||||
|
</a-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { message } from 'ant-design-vue'
|
import { createVNode } from 'vue'
|
||||||
|
import { message, Modal } from 'ant-design-vue'
|
||||||
|
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
|
||||||
import { useTahesabDocSyncStore } from '@/store/tahesabDocSyncStore'
|
import { useTahesabDocSyncStore } from '@/store/tahesabDocSyncStore'
|
||||||
|
|
||||||
|
const emit = defineEmits<{ refreshed: [] }>()
|
||||||
const store = useTahesabDocSyncStore()
|
const store = useTahesabDocSyncStore()
|
||||||
|
|
||||||
async function onStart() {
|
async function onStart() {
|
||||||
@@ -34,4 +48,31 @@ async function onStart() {
|
|||||||
message.error(e?.response?.data?.message || e?.message || 'شروع ارسال ناموفق بود')
|
message.error(e?.response?.data?.message || e?.message || 'شروع ارسال ناموفق بود')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onReset() {
|
||||||
|
Modal.confirm({
|
||||||
|
title: 'بازنشانی وضعیت محلی؟',
|
||||||
|
icon: createVNode(ExclamationCircleOutlined),
|
||||||
|
content:
|
||||||
|
'سندهایی که پنل آنها را موفق میداند دوباره در صف ارسال میآیند. خودِ تهحساب عوض نمیشود. کد مشتری پنل دست نمیخورد.',
|
||||||
|
okText: 'بازنشانی کن',
|
||||||
|
cancelText: 'انصراف',
|
||||||
|
centered: true,
|
||||||
|
onOk: runReset,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runReset() {
|
||||||
|
try {
|
||||||
|
const res = await store.resetLocal()
|
||||||
|
if (!res) return
|
||||||
|
message.success(res.message || 'وضعیت محلی بهروز شد')
|
||||||
|
if (res.summary?.total) {
|
||||||
|
message.info(`${res.summary.total} سند در صف ارسال است — حالا ارسال همه را بزنید`)
|
||||||
|
}
|
||||||
|
emit('refreshed')
|
||||||
|
} catch (e: any) {
|
||||||
|
message.error(e?.response?.data?.message || e?.message || 'بازنشانی ناموفق بود')
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
</a-button>
|
</a-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<TahesabDocSyncBox v-if="!customerId" />
|
<TahesabDocSyncBox v-if="!customerId" @refreshed="onDocSyncRefreshed" />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="(pending?.total ?? 0) > 0"
|
v-if="(pending?.total ?? 0) > 0"
|
||||||
@@ -398,6 +398,11 @@ async function loadPending() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function onDocSyncRefreshed() {
|
||||||
|
await loadPending()
|
||||||
|
if (docsView.value === 'failed') await loadFailedDocs()
|
||||||
|
}
|
||||||
|
|
||||||
async function loadFailedDocs() {
|
async function loadFailedDocs() {
|
||||||
failedLoading.value = true
|
failedLoading.value = true
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
startTahesabCustomerInbound,
|
startTahesabCustomerInbound,
|
||||||
startTahesabCustomerOutbound,
|
startTahesabCustomerOutbound,
|
||||||
stopTahesabDocSync,
|
stopTahesabDocSync,
|
||||||
|
resetTahesabLocalDocs,
|
||||||
type TahesabDocSyncState,
|
type TahesabDocSyncState,
|
||||||
} from '@/api/tahesab'
|
} from '@/api/tahesab'
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ export const useTahesabDocSyncStore = defineStore('tahesabDocSync', () => {
|
|||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
const minimized = ref(false)
|
const minimized = ref(false)
|
||||||
const starting = ref(false)
|
const starting = ref(false)
|
||||||
|
const resetting = ref(false)
|
||||||
const message = ref('')
|
const message = ref('')
|
||||||
let timer: ReturnType<typeof setInterval> | null = null
|
let timer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
@@ -188,11 +190,27 @@ export const useTahesabDocSyncStore = defineStore('tahesabDocSync', () => {
|
|||||||
minimized.value = false
|
minimized.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resetLocal() {
|
||||||
|
if (resetting.value || state.value.running) return null
|
||||||
|
resetting.value = true
|
||||||
|
try {
|
||||||
|
const res = await resetTahesabLocalDocs()
|
||||||
|
message.value = res.message || ''
|
||||||
|
apply(res.summary?.doc_sync)
|
||||||
|
visible.value = false
|
||||||
|
minimized.value = false
|
||||||
|
return res
|
||||||
|
} finally {
|
||||||
|
resetting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
state,
|
state,
|
||||||
visible,
|
visible,
|
||||||
minimized,
|
minimized,
|
||||||
starting,
|
starting,
|
||||||
|
resetting,
|
||||||
message,
|
message,
|
||||||
active,
|
active,
|
||||||
finished,
|
finished,
|
||||||
@@ -204,6 +222,7 @@ export const useTahesabDocSyncStore = defineStore('tahesabDocSync', () => {
|
|||||||
start,
|
start,
|
||||||
startOutbound,
|
startOutbound,
|
||||||
startInbound,
|
startInbound,
|
||||||
|
resetLocal,
|
||||||
stop,
|
stop,
|
||||||
minimize,
|
minimize,
|
||||||
expand,
|
expand,
|
||||||
|
|||||||
Reference in New Issue
Block a user