merge: bring latest origin/main into dev (main wins conflicts)
This commit is contained in:
@@ -86,6 +86,9 @@ type SyncResult = {
|
||||
alreadyLinked?: boolean;
|
||||
personId?: string | null;
|
||||
personName?: string | null;
|
||||
duplicateOfCode?: number | null;
|
||||
duplicatePersonId?: string | null;
|
||||
duplicatePersonName?: string | null;
|
||||
};
|
||||
const syncResults = ref<SyncResult[]>([]);
|
||||
/** هر درخواست listAll یک بازهٔ ۲۰۰۰ کدی است؛ بعد از دو بازهٔ خالی پشتسرهم، خواندن تمام میشود */
|
||||
@@ -188,9 +191,95 @@ async function saveAutoSync() {
|
||||
}
|
||||
}
|
||||
|
||||
/** همهٔ مشتریان تهحساب را میخواند: تازهها وارد، لینکشدهها پروفایلشان بهروز میشود */
|
||||
async function syncCustomersNow() {
|
||||
if (!sync.connectionId) {
|
||||
error.value = 'اتصال را انتخاب کنید.';
|
||||
return;
|
||||
}
|
||||
syncBusy.value = true;
|
||||
importOverlay.open = true;
|
||||
importOverlay.progress = null;
|
||||
importOverlay.message =
|
||||
'در حال همگامسازی همهٔ مشتریان… نام، موبایل، کد ملی، آدرس، شهر، رسته و گروه بهروز میشود.';
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
try {
|
||||
const { data } = await api.post<{
|
||||
imported: number;
|
||||
updated: number;
|
||||
duplicate: number;
|
||||
failed: number;
|
||||
summary: string;
|
||||
error: string | null;
|
||||
}>('/integrations/tahesab/sync/customers-now', {
|
||||
connectionId: sync.connectionId,
|
||||
});
|
||||
ok.value = data.summary;
|
||||
if (data.error) error.value = data.error;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = apiErr(e, 'همگامسازی مشتریان ناموفق بود');
|
||||
} finally {
|
||||
syncBusy.value = false;
|
||||
importOverlay.open = false;
|
||||
}
|
||||
}
|
||||
/** همان قاعدهٔ سرور: موبایل ایران 09… است، بقیهٔ شمارهها فقط رقماند. */
|
||||
function customerPhoneKey(value?: string | null): string {
|
||||
const fa = '۰۱۲۳۴۵۶۷۸۹';
|
||||
const ar = '٠١٢٣٤٥٦٧٨٩';
|
||||
let digits = String(value ?? '')
|
||||
.replace(/[۰-۹٠-٩]/g, (ch) => {
|
||||
const faIndex = fa.indexOf(ch);
|
||||
return String(faIndex >= 0 ? faIndex : ar.indexOf(ch));
|
||||
})
|
||||
.replace(/\D/g, '');
|
||||
if (!digits) return '';
|
||||
if (digits.startsWith('0098') && digits.length >= 14) digits = digits.slice(4);
|
||||
else if (digits.startsWith('98') && digits.length >= 12) digits = digits.slice(2);
|
||||
if (digits.length === 10 && digits.startsWith('9')) digits = `0${digits}`;
|
||||
return digits;
|
||||
}
|
||||
|
||||
const linkedPhoneOwners = computed(() => {
|
||||
const owners = new Map<string, { code: number; personId: string | null; personName: string | null }>();
|
||||
for (const row of syncResults.value) {
|
||||
if (!row.alreadyLinked || row.moshtariCode == null) continue;
|
||||
const key = customerPhoneKey(row.tel);
|
||||
if (key && !owners.has(key)) {
|
||||
owners.set(key, {
|
||||
code: row.moshtariCode,
|
||||
personId: row.personId ?? null,
|
||||
personName: row.personName ?? null,
|
||||
});
|
||||
}
|
||||
}
|
||||
return owners;
|
||||
});
|
||||
|
||||
function duplicateOwner(row: SyncResult) {
|
||||
if (row.alreadyLinked || row.moshtariCode == null) return null;
|
||||
if (row.duplicateOfCode != null) {
|
||||
return {
|
||||
code: row.duplicateOfCode,
|
||||
personId: row.duplicatePersonId ?? null,
|
||||
personName: row.duplicatePersonName ?? null,
|
||||
};
|
||||
}
|
||||
const key = customerPhoneKey(row.tel);
|
||||
if (!key) return null;
|
||||
const owner = linkedPhoneOwners.value.get(key);
|
||||
if (!owner || owner.code === row.moshtariCode) return null;
|
||||
return owner;
|
||||
}
|
||||
|
||||
const duplicateCustomerCount = computed(
|
||||
() => syncResults.value.filter((row) => duplicateOwner(row)).length,
|
||||
);
|
||||
const syncVisibleResults = computed(() =>
|
||||
syncOnlyNew.value
|
||||
? syncResults.value.filter((r) => !r.alreadyLinked)
|
||||
? syncResults.value.filter((row) => !row.alreadyLinked && !duplicateOwner(row))
|
||||
: syncResults.value,
|
||||
);
|
||||
const syncTableTotalPages = computed(() =>
|
||||
@@ -227,7 +316,7 @@ const productCategoryLabel = ref('کارساخته');
|
||||
|
||||
function pendingImportCodes() {
|
||||
return syncResults.value
|
||||
.filter((r) => r.moshtariCode != null && !r.alreadyLinked)
|
||||
.filter((r) => r.moshtariCode != null && !r.alreadyLinked && !duplicateOwner(r))
|
||||
.map((r) => r.moshtariCode as number);
|
||||
}
|
||||
|
||||
@@ -501,10 +590,12 @@ async function searchTahesab(mode: 'range' | 'filter') {
|
||||
ok.value = 'نتیجهای یافت نشد.';
|
||||
} else {
|
||||
const linked = syncResults.value.filter((r) => r.alreadyLinked).length;
|
||||
const pending = syncResults.value.length - linked;
|
||||
const duplicate = syncResults.value.filter((r) => duplicateOwner(r)).length;
|
||||
const pending = syncResults.value.length - linked - duplicate;
|
||||
ok.value =
|
||||
`${toFaDigits(syncResults.value.length)} مشتری پیدا شد` +
|
||||
` · ${toFaDigits(linked)} قبلاً وارد شده · ${toFaDigits(pending)} واردنشده`;
|
||||
` · ${toFaDigits(linked)} قبلاً وارد شده · ${toFaDigits(pending)} واردنشده` +
|
||||
(duplicate ? ` · ${toFaDigits(duplicate)} شماره تکراری` : '');
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = apiErr(e, 'جستجو ناموفق');
|
||||
@@ -973,29 +1064,154 @@ onMounted(load);
|
||||
extra="آدرس سرور وبسرویس تهحساب"
|
||||
:rules="[{ required: true, message: 'آدرس وبسرویس را وارد کنید.' }]"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="form.baseUrl"
|
||||
dir="ltr"
|
||||
placeholder="https://IP:8081 یا https://api.tahesab.ir"
|
||||
@blur="onBaseUrlBlur"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item
|
||||
label="نام دیتابیس (DBName)"
|
||||
name="dbName"
|
||||
:rules="[{ required: true, message: 'نام دیتابیس را وارد کنید.' }]"
|
||||
فعالسازی SSL خودامضا
|
||||
</UiButton>
|
||||
<UiButton variant="ghost" size="sm" @click="startEdit(row)">
|
||||
<template #icon>
|
||||
<UiIcon name="pencil" />
|
||||
</template>
|
||||
ویرایش
|
||||
</UiButton>
|
||||
<UiButton variant="ghost" size="sm" @click="testConn(row.id)">
|
||||
<template #icon>
|
||||
<UiIcon name="refresh" />
|
||||
</template>
|
||||
تست اتصال
|
||||
</UiButton>
|
||||
<UiButton variant="danger" size="sm" @click="removeConn(row.id)">
|
||||
<template #icon>
|
||||
<UiIcon name="trash" />
|
||||
</template>
|
||||
حذف
|
||||
</UiButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</UiCard>
|
||||
|
||||
<UiCard :title="editingId ? 'ویرایش اتصال تهحساب' : 'افزودن اتصال جدید تهحساب'" class="section-card">
|
||||
<form class="crm-form" @submit.prevent="save">
|
||||
<div class="crm-form-grid-2">
|
||||
<UiField label="عنوان اتصال" required>
|
||||
<UiInput v-model="form.label" required maxlength="120" placeholder="مثلاً شعبه مرکزی، دیتابیس مالی" />
|
||||
</UiField>
|
||||
|
||||
<UiField label="آدرس وبسرویس (Base URL)" required hint="آدرس سرور وبسرویس تهحساب">
|
||||
<UiInput
|
||||
v-model="form.baseUrl"
|
||||
required
|
||||
dir="ltr"
|
||||
placeholder="https://IP:8081 یا https://api.tahesab.ir"
|
||||
@blur="onBaseUrlBlur"
|
||||
/>
|
||||
</UiField>
|
||||
|
||||
<UiField label="نام دیتابیس (DBName)" required>
|
||||
<UiInput v-model="form.dbName" required dir="ltr" placeholder="DB یا TahesabDB" />
|
||||
</UiField>
|
||||
|
||||
<UiField label="توکن دسترسی (Bearer Token)" :required="!editingId" :hint="editingId ? 'خالی بگذارید تا توکن فعلی تغییر نکند.' : 'توکن احراز هویت وبسرویس'">
|
||||
<UiInput
|
||||
v-model="form.token"
|
||||
:required="!editingId"
|
||||
type="password"
|
||||
dir="ltr"
|
||||
autocomplete="new-password"
|
||||
placeholder="توکن امنیتی..."
|
||||
/>
|
||||
</UiField>
|
||||
</div>
|
||||
|
||||
<div class="checkbox-group">
|
||||
<label class="custom-check">
|
||||
<input v-model="form.isDefault" type="checkbox" />
|
||||
<span>اتصال پیشفرض سازمان</span>
|
||||
</label>
|
||||
<label class="custom-check">
|
||||
<input v-model="form.enabled" type="checkbox" />
|
||||
<span>اتصال فعال باشد</span>
|
||||
</label>
|
||||
<label class="custom-check highlight">
|
||||
<input v-model="form.allowInsecureTls" type="checkbox" />
|
||||
<span>پذیرش گواهی SSL خودامضا (برای IP محلی یا پورت داخلی بدون گواهی رسمی)</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-actions-row">
|
||||
<UiButton type="submit" :loading="saving">
|
||||
{{ editingId ? 'بهروزرسانی اتصال' : 'افزودن اتصال' }}
|
||||
</UiButton>
|
||||
<UiButton v-if="editingId" variant="ghost" type="button" @click="resetForm">
|
||||
انصراف
|
||||
</UiButton>
|
||||
</div>
|
||||
</form>
|
||||
</UiCard>
|
||||
|
||||
<UiCard title="وارد کردن و همگامسازی مشتریان از تهحساب" class="section-card">
|
||||
<p class="sync-desc">
|
||||
با استفاده از این بخش میتوانید اشخاص و طرفحسابهای تهحساب را به عنوان مخاطب وارد نرمافزار کرده و سوابق مالی آنها را پیوند دهید.
|
||||
</p>
|
||||
|
||||
<div class="crm-form">
|
||||
<UiField label="اتصال مورد نظر جهت همگامسازی" required>
|
||||
<UiSelect v-model="sync.connectionId">
|
||||
<option disabled value="">انتخاب اتصال</option>
|
||||
<option v-for="row in items" :key="row.id" :value="row.id">
|
||||
{{ row.label }} ({{ row.dbName }})
|
||||
</option>
|
||||
</UiSelect>
|
||||
</UiField>
|
||||
|
||||
<div class="sync-sub-section">
|
||||
<h4 class="sync-subhead">بروزرسانی خودکار</h4>
|
||||
<p class="sync-sub-desc">
|
||||
«همگامسازی الان» همهٔ مشتریان تهحساب را میخواند: تازهها را وارد میکند و برای مشتریهای از قبل
|
||||
لینکشده نام، موبایل، کد ملی، آدرس، شهر، رسته و گروه را از تهحساب تازه میکند. زمانبندی زیر
|
||||
همان کار را در ساعتهای انتخابی (به وقت تهران) تکرار میکند. خاموش یعنی فقط ورود دستی.
|
||||
</p>
|
||||
<UiField label="تعداد در روز">
|
||||
<UiSelect
|
||||
:model-value="autoCount"
|
||||
:disabled="!sync.connectionId || autoSyncSaving"
|
||||
@update:model-value="onAutoCount"
|
||||
>
|
||||
<a-input v-model:value="form.dbName" dir="ltr" placeholder="DB یا TahesabDB" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item
|
||||
label="توکن دسترسی (Bearer Token)"
|
||||
name="token"
|
||||
:extra="editingId ? 'خالی بگذارید تا توکن فعلی تغییر نکند.' : 'توکن احراز هویت وبسرویس'"
|
||||
:rules="[{ required: !editingId, message: 'توکن الزامی است.' }]"
|
||||
<option value="0">خاموش</option>
|
||||
<option v-for="n in 6" :key="n" :value="String(n)">
|
||||
{{ toFaDigits(n) }} بار
|
||||
</option>
|
||||
</UiSelect>
|
||||
</UiField>
|
||||
<div v-if="Number(autoCount) > 0" class="crm-form-grid-3">
|
||||
<UiField
|
||||
v-for="(_, index) in autoHours"
|
||||
:key="index"
|
||||
:label="`ساعت ${toFaDigits(index + 1)}`"
|
||||
>
|
||||
<UiSelect
|
||||
:model-value="autoHours[index]"
|
||||
:disabled="autoSyncSaving"
|
||||
@update:model-value="setAutoHour(index, $event)"
|
||||
>
|
||||
<option v-for="hour in 24" :key="hour - 1" :value="String(hour - 1)">
|
||||
{{ hourLabel(hour - 1) }}
|
||||
</option>
|
||||
</UiSelect>
|
||||
</UiField>
|
||||
</div>
|
||||
<div class="sync-buttons">
|
||||
<UiButton
|
||||
:loading="syncBusy"
|
||||
:disabled="!sync.connectionId || syncBusy || autoSyncSaving"
|
||||
@click="syncCustomersNow"
|
||||
>
|
||||
همگامسازی الان (وارد + بهروز کردن قبلیها)
|
||||
</UiButton>
|
||||
<UiButton
|
||||
variant="secondary"
|
||||
:loading="autoSyncSaving"
|
||||
:disabled="!sync.connectionId || syncBusy"
|
||||
@click="saveAutoSync"
|
||||
>
|
||||
<a-input-password
|
||||
v-model:value="form.token"
|
||||
@@ -1223,68 +1439,83 @@ onMounted(load);
|
||||
<a-card v-if="syncResults.length" type="inner">
|
||||
<template #title>
|
||||
نتایج جستجو ({{ syncVisibleResults.length }}<template v-if="syncOnlyNew"> از {{ syncResults.length }}</template>)
|
||||
</template>
|
||||
<a-flex vertical :gap="12">
|
||||
<a-flex justify="flex-end">
|
||||
<TableColumnsMenu table-key="tahesab.customers" align="end" />
|
||||
</a-flex>
|
||||
<a-table
|
||||
:columns="customerColumns"
|
||||
:data-source="syncPagedResults"
|
||||
:pagination="false"
|
||||
:row-key="(r: SyncResult) => String(r.moshtariCode)"
|
||||
:scroll="{ x: 640 }"
|
||||
</h4>
|
||||
<p v-if="duplicateCustomerCount" class="sync-sub-desc">
|
||||
{{ toFaDigits(duplicateCustomerCount) }} مشتری شمارهٔ تکراری دارند و جداگانه وارد نمیشوند؛ همان شخص با کد دیگری از قبل لینک است.
|
||||
</p>
|
||||
<div class="tc-row">
|
||||
<TableColumnsMenu table-key="tahesab.customers" align="end" />
|
||||
</div>
|
||||
<div class="crm-table-container">
|
||||
<table
|
||||
v-table-cols="'tahesab.customers'"
|
||||
class="crm-table"
|
||||
:style="{ '--row-start': (syncTablePage - 1) * syncTablePageSize }"
|
||||
>
|
||||
<template #emptyText>همهٔ مشتریان این نتایج قبلاً وارد شدهاند.</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'کد مشتری'">
|
||||
{{ (record as SyncResult).moshtariCode }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'نام و نام خانوادگی'">
|
||||
<a-typography-text strong>{{ (record as SyncResult).name || 'بدون نام' }}</a-typography-text>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'تلفن'">
|
||||
<span dir="ltr">{{ (record as SyncResult).tel }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'وضعیت لینک'">
|
||||
<a-tag v-if="(record as SyncResult).alreadyLinked" color="success" :bordered="false">
|
||||
لینک شده{{ (record as SyncResult).personName ? ` (${(record as SyncResult).personName})` : '' }}
|
||||
</a-tag>
|
||||
<a-tag v-else color="default" :bordered="false">آماده ورود</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'عملیات'">
|
||||
<a-button
|
||||
v-if="!(record as SyncResult).alreadyLinked"
|
||||
type="primary"
|
||||
:disabled="!(record as SyncResult).moshtariCode || syncBusy"
|
||||
@click="importOne((record as SyncResult).moshtariCode!)"
|
||||
>
|
||||
وارد کردن
|
||||
</a-button>
|
||||
<RouterLink
|
||||
v-else-if="(record as SyncResult).personId"
|
||||
:to="{ name: 'person-detail', params: { id: (record as SyncResult).personId } }"
|
||||
>
|
||||
<a-button type="text">مشاهده شخص</a-button>
|
||||
</RouterLink>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
<a-flex v-if="syncVisibleResults.length > SYNC_TABLE_PAGE_SIZES[0]" justify="flex-end">
|
||||
<a-pagination
|
||||
:current="syncTablePage"
|
||||
:total="syncVisibleResults.length"
|
||||
:page-size="syncTablePageSize"
|
||||
:page-size-options="SYNC_TABLE_PAGE_SIZES.map(String)"
|
||||
show-size-changer
|
||||
@change="onSyncTablePageChange"
|
||||
@update:page-size="(n: number) => (syncTablePageSize = n)"
|
||||
/>
|
||||
</a-flex>
|
||||
</a-flex>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</a-card>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>کد مشتری</th>
|
||||
<th>نام و نام خانوادگی</th>
|
||||
<th>تلفن</th>
|
||||
<th>وضعیت لینک</th>
|
||||
<th>عملیات</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="!syncPagedResults.length">
|
||||
<td colspan="5" class="sync-empty-row">
|
||||
مشتری تازهای برای ورود نیست. شمارههای تکراری از قبل با کد دیگری لینک شدهاند.
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-for="r in syncPagedResults" :key="String(r.moshtariCode)">
|
||||
<td class="font-mono">{{ r.moshtariCode }}</td>
|
||||
<td class="font-bold">{{ r.name || 'بدون نام' }}</td>
|
||||
<td class="font-mono" dir="ltr">{{ r.tel }}</td>
|
||||
<td>
|
||||
<UiBadge v-if="r.alreadyLinked" variant="success">
|
||||
لینک شده{{ r.personName ? ` (${r.personName})` : '' }}
|
||||
</UiBadge>
|
||||
<UiBadge v-else-if="duplicateOwner(r)" variant="warning">
|
||||
شماره تکراری، کد {{ toFaDigits(duplicateOwner(r)!.code) }}
|
||||
</UiBadge>
|
||||
<UiBadge v-else variant="neutral">آماده ورود</UiBadge>
|
||||
</td>
|
||||
<td>
|
||||
<UiButton
|
||||
v-if="!r.alreadyLinked && !duplicateOwner(r)"
|
||||
size="sm"
|
||||
:disabled="!r.moshtariCode || syncBusy"
|
||||
@click="importOne(r.moshtariCode!)"
|
||||
>
|
||||
وارد کردن
|
||||
</UiButton>
|
||||
<RouterLink
|
||||
v-else-if="r.personId || duplicateOwner(r)?.personId"
|
||||
:to="{ name: 'person-detail', params: { id: (r.personId || duplicateOwner(r)?.personId)! } }"
|
||||
>
|
||||
<UiButton variant="ghost" size="sm">
|
||||
مشاهده شخص
|
||||
</UiButton>
|
||||
</RouterLink>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<UiPagination
|
||||
v-if="syncVisibleResults.length > SYNC_TABLE_PAGE_SIZES[0]"
|
||||
:page="syncTablePage"
|
||||
:total-pages="syncTableTotalPages"
|
||||
:total-items="syncVisibleResults.length"
|
||||
:page-size="syncTablePageSize"
|
||||
:page-size-options="SYNC_TABLE_PAGE_SIZES"
|
||||
class="sync-table-pagination"
|
||||
@update:page="onSyncTablePageChange"
|
||||
@update:page-size="syncTablePageSize = $event"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</UiCard>
|
||||
|
||||
<a-card title="وارد کردن کارساخته از تهحساب به محصولات" :bordered="false">
|
||||
<a-flex vertical :gap="16">
|
||||
|
||||
Reference in New Issue
Block a user