Files
boursecu_admin/src/api/tahesab.ts
T

134 lines
3.8 KiB
TypeScript
Raw Normal View History

2026-06-26 17:41:52 +03:30
import useAxios from '@core/utils/useAxios'
import type { TableInput } from '@core/type/baseTable'
export interface TahesabRecord {
2026-08-27 16:15:11 +03:30
id?: number | null
2026-06-26 17:41:52 +03:30
customer_id?: number
amount?: number
desc?: string
type?: string
2026-08-27 16:15:11 +03:30
sync_status?: 'pending' | 'success' | 'failed' | 'missing'
2026-06-26 17:41:52 +03:30
sync_log?: string | null
tahesab_id?: string | null
data?: string | null
res?: string | null
created_at?: string
2026-08-27 16:15:11 +03:30
withdraw_id?: number | null
order_id?: number | null
issue_kind?: 'failed' | 'missing'
sync_target?: { type: 'row' | 'withdraw' | 'order'; id: number }
2026-06-26 17:41:52 +03:30
customer?: {
id?: number
name?: string
mobile?: string
moshtari_code?: string | number | null
}
}
2026-08-27 16:15:11 +03:30
export const getTahesabTable = async (params: TableInput & { view?: string }) =>
2026-06-26 17:41:52 +03:30
await useAxios.post<TahesabRecord[]>('/admin/tahesab/table', params)
export const getTahesabDetail = async (id: number) =>
await useAxios.get<TahesabRecord>(`/admin/tahesab/${id}`)
export const retryTahesabSanad = async (id: number) =>
await useAxios.post<{ ok: boolean; message: string; tahesab?: TahesabRecord }>(`/admin/tahesab/${id}/retry`)
2026-08-27 16:15:11 +03:30
export interface TahesabPendingSummary {
failed_rows: number
missing_withdraws: number
missing_orders: number
total: number
}
export interface TahesabSyncAllResult {
ok: boolean
retried: number
backfilled_withdraws: number
backfilled_orders: number
failed: number
errors: string[]
summary: TahesabPendingSummary
}
export const getTahesabPendingSummary = async (customerId?: number) =>
await useAxios.get<TahesabPendingSummary>('/admin/tahesab/pending-summary', {
params: customerId ? { customer_id: customerId } : undefined
})
export const getTahesabPendingDocs = async (customerId?: number, limit = 200) =>
await useAxios.get<{ rows: TahesabRecord[]; summary: TahesabPendingSummary }>(
'/admin/tahesab/pending-docs',
{ params: { ...(customerId ? { customer_id: customerId } : {}), limit } }
)
export const syncOneTahesab = async (type: 'row' | 'withdraw' | 'order', id: number) =>
await useAxios.post<{ ok: boolean; message: string }>('/admin/tahesab/sync-one', { type, id })
export const syncAllTahesabPending = async (limit = 80, customerId?: number) =>
await useAxios.post<TahesabSyncAllResult>('/admin/tahesab/sync-all-pending', {
limit,
...(customerId ? { customer_id: customerId } : {})
})
2026-06-26 17:41:52 +03:30
export const registerCustomerInTahesab = async (customerId: number) =>
await useAxios.post<{ ok: boolean; message: string; moshtari_code?: string | number }>(
`/admin/customer/${customerId}/tahesab/register`
)
2026-06-28 21:48:17 +03:30
export interface PanelOnlyCustomer {
id: number
name: string
mobile: string
created_at: string
}
export interface TahesabOnlyCustomer {
code: number
name: string
tel: string
gid: number | null
group: string
}
export interface CustomerSyncStatus {
panel_total: number
panel_registered: number
panel_only: number
tahesab_total: number
tahesab_only_count: number
panel_only_list: {
data: PanelOnlyCustomer[]
current_page: number
last_page: number
total: number
}
tahesab_only_list: {
data: TahesabOnlyCustomer[]
current_page: number
last_page: number
total: number
}
}
export const getCustomerSyncStatus = async (params?: {
search?: string
page?: number
tahesab_page?: number
}) => await useAxios.get<CustomerSyncStatus>('/admin/tahesab/customer-sync/status', { params })
export interface SyncPanelResult {
ok: boolean
success: number
failed: number
errors: { name: string; mobile: string; error: string }[]
}
export const syncPanelToTahesab = async () =>
await useAxios.post<SyncPanelResult>('/admin/tahesab/customer-sync/panel-to-tahesab')
export const importFromTahesab = async (customers: TahesabOnlyCustomer[]) =>
await useAxios.post<SyncPanelResult>('/admin/tahesab/customer-sync/import-from-tahesab', {
customers,
})