fix(tahesab): polish sales report page chrome

Match leads/invoices header layout, keep title clean, and add a clear apply-filters action for the date range.
This commit is contained in:
2026-10-22 19:47:58 +03:30
parent ade43fea0f
commit 6d8ede8e2a
+121 -51
View File
@@ -1,8 +1,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'; import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { theme } from 'ant-design-vue';
import type { TableColumnsType, TablePaginationConfig } from 'ant-design-vue'; import type { TableColumnsType, TablePaginationConfig } from 'ant-design-vue';
import { ReloadOutlined, SyncOutlined } from '@ant-design/icons-vue'; import {
ArrowRightOutlined,
FilterOutlined,
SearchOutlined,
SyncOutlined,
} from '@ant-design/icons-vue';
import { import {
TAHESAB_ASNAD_KIND_LABELS, TAHESAB_ASNAD_KIND_LABELS,
TAHESAB_ASNAD_KINDS, TAHESAB_ASNAD_KINDS,
@@ -28,6 +34,7 @@ import { useCustomerGroups } from '@/lib/customer-groups';
import JalaliDateInput from '@/components/JalaliDateInput.vue'; import JalaliDateInput from '@/components/JalaliDateInput.vue';
const router = useRouter(); const router = useRouter();
const { token } = theme.useToken();
const { groups: customerGroups, load: loadCustomerGroups } = useCustomerGroups(); const { groups: customerGroups, load: loadCustomerGroups } = useCustomerGroups();
const connections = ref<TahesabConnectionDto[]>([]); const connections = ref<TahesabConnectionDto[]>([]);
@@ -87,7 +94,9 @@ function metalLabel(v: number | null) {
function formatNum(n: number | null | undefined) { function formatNum(n: number | null | undefined) {
if (n == null) return '—'; if (n == null) return '—';
return toFaDigits(new Intl.NumberFormat('fa-IR', { maximumFractionDigits: 3 }).format(n)); return toFaDigits(
new Intl.NumberFormat('fa-IR', { maximumFractionDigits: 3 }).format(n),
);
} }
function formatMali(n: number | null | undefined) { function formatMali(n: number | null | undefined) {
@@ -96,7 +105,13 @@ function formatMali(n: number | null | undefined) {
} }
const columns: TableColumnsType<TahesabAsnadLineDto> = [ const columns: TableColumnsType<TahesabAsnadLineDto> = [
{ title: 'تاریخ', dataIndex: 'tarikh', key: 'tarikh', width: 110 }, {
title: 'تاریخ',
dataIndex: 'tarikh',
key: 'tarikh',
width: 110,
customRender: ({ text }) => toFaDigits(String(text ?? '')),
},
{ {
title: 'شخص', title: 'شخص',
key: 'person', key: 'person',
@@ -162,6 +177,16 @@ const filterParams = computed(() => {
}; };
}); });
const lastSyncedLabel = computed(() => {
const raw = summary.value?.lastSyncedAt;
if (!raw) return null;
try {
return toFaDigits(new Date(raw).toLocaleString('fa-IR'));
} catch {
return null;
}
});
async function loadConnections() { async function loadConnections() {
const { data } = await api.get<TahesabConnectionDto[]>( const { data } = await api.get<TahesabConnectionDto[]>(
'/integrations/tahesab/connections/public', '/integrations/tahesab/connections/public',
@@ -263,7 +288,7 @@ async function pollJob(jobId: string) {
async function startSync() { async function startSync() {
const params = filterParams.value; const params = filterParams.value;
if (!params) { if (!params) {
error.value = 'تاریخ از و تا را انتخاب کنید.'; error.value = 'ابتدا بازه تاریخ را مشخص کنید، بعد به‌روزرسانی را بزنید.';
return; return;
} }
syncing.value = true; syncing.value = true;
@@ -289,6 +314,11 @@ async function startSync() {
} }
} }
function applyFilters() {
page.value = 1;
void loadReport();
}
function onTableChange(pag: TablePaginationConfig) { function onTableChange(pag: TablePaginationConfig) {
page.value = pag.current ?? 1; page.value = pag.current ?? 1;
pageSize.value = pag.pageSize ?? 50; pageSize.value = pag.pageSize ?? 50;
@@ -313,55 +343,72 @@ onUnmounted(() => stopPoll());
</script> </script>
<template> <template>
<a-flex vertical :gap="16"> <a-row :gutter="[24, 24]">
<a-row :gutter="[16, 16]" align="middle" justify="space-between"> <a-col :span="24">
<a-col :xs="24" :md="14"> <a-flex
<a-typography-title :level="3" style="margin: 0"> justify="space-between"
align="center"
wrap="wrap"
:gap="token.marginSM"
>
<div>
<a-typography-title :level="3" :style="{ margin: 0 }">
گزارش فروش ته‌حساب گزارش فروش ته‌حساب
</a-typography-title> </a-typography-title>
<a-typography-text type="secondary"> <a-typography-text type="secondary">
اسنپ‌شات اسناد مشتریان لینک‌شده — طبقه‌بندی فروش/مرجوعی تقریبی است و بعد از بازخورد کارفرما اصلاح می‌شود. فروش و مرجوعی مشتریان لینک‌شده بر اساس بازه تاریخ
</a-typography-text> </a-typography-text>
</a-col> </div>
<a-col :xs="24" :md="10"> <a-space :size="8" wrap>
<a-flex justify="flex-end" wrap="wrap" :gap="8"> <a-button @click="router.push({ name: 'reports' })">
<a-button @click="router.push({ name: 'reports' })">بازگشت به گزارش‌ها</a-button> <template #icon><ArrowRightOutlined /></template>
<a-button :loading="loading" @click="loadReport"> بازگشت
<template #icon><ReloadOutlined /></template>
نمایش
</a-button> </a-button>
<a-button type="primary" :loading="syncing" @click="startSync"> <a-button type="primary" :loading="syncing" @click="startSync">
<template #icon><SyncOutlined /></template> <template #icon><SyncOutlined /></template>
به‌روزرسانی از ته‌حساب به‌روزرسانی از ته‌حساب
</a-button> </a-button>
</a-space>
</a-flex> </a-flex>
</a-col> </a-col>
</a-row>
<a-alert v-if="error" type="error" show-icon :message="error" closable @close="error = ''" /> <a-col v-if="error" :span="24">
<a-alert v-if="syncHint" type="info" show-icon :message="syncHint" /> <a-alert type="error" show-icon :message="error" closable @close="error = ''" />
</a-col>
<a-col v-if="syncHint" :span="24">
<a-alert type="info" show-icon :message="syncHint" />
</a-col>
<a-card :bordered="false" title="فیلترها"> <a-col :span="24">
<a-form layout="vertical"> <a-card :bordered="false">
<template #title>
<a-space :size="8">
<FilterOutlined />
<span>فیلترها</span>
</a-space>
</template>
<a-form layout="vertical" @finish="applyFilters">
<a-row :gutter="[16, 8]"> <a-row :gutter="[16, 8]">
<a-col :xs="24" :sm="12" :md="8" :lg="6"> <a-col :xs="24" :sm="12" :md="8" :lg="6">
<a-form-item label="اتصال ته‌حساب"> <a-form-item label="اتصال">
<a-select <a-select
v-model:value="connectionId" v-model:value="connectionId"
:options="connections.map((c) => ({ value: c.id, label: c.label }))" :options="
placeholder="اتصال" connections.map((c) => ({ value: c.id, label: c.label }))
"
placeholder="اتصال ته‌حساب"
allow-clear allow-clear
/> />
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :xs="24" :sm="12" :md="8" :lg="6"> <a-col :xs="24" :sm="12" :md="8" :lg="6">
<a-form-item label="از تاریخ"> <a-form-item label="از تاریخ" required>
<JalaliDateInput v-model="fromDate" placeholder="از" /> <JalaliDateInput v-model="fromDate" placeholder="از تاریخ" />
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :xs="24" :sm="12" :md="8" :lg="6"> <a-col :xs="24" :sm="12" :md="8" :lg="6">
<a-form-item label="تا تاریخ"> <a-form-item label="تا تاریخ" required>
<JalaliDateInput v-model="toDate" placeholder="تا" /> <JalaliDateInput v-model="toDate" placeholder="تا تاریخ" />
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :xs="24" :sm="12" :md="8" :lg="6"> <a-col :xs="24" :sm="12" :md="8" :lg="6">
@@ -371,7 +418,12 @@ onUnmounted(() => stopPoll());
mode="multiple" mode="multiple"
allow-clear allow-clear
placeholder="همه گروه‌ها" placeholder="همه گروه‌ها"
:options="(customerGroups as CustomerGroupDto[]).map((g) => ({ value: g.id, label: g.name }))" :options="
(customerGroups as CustomerGroupDto[]).map((g) => ({
value: g.id,
label: g.name,
}))
"
:max-tag-count="2" :max-tag-count="2"
/> />
</a-form-item> </a-form-item>
@@ -382,7 +434,7 @@ onUnmounted(() => stopPoll());
v-model:value="kinds" v-model:value="kinds"
mode="multiple" mode="multiple"
:options="kindOptions" :options="kindOptions"
placeholder="نوع" placeholder="فروش / مرجوعی / …"
:max-tag-count="2" :max-tag-count="2"
/> />
</a-form-item> </a-form-item>
@@ -407,39 +459,50 @@ onUnmounted(() => stopPoll());
:filter-option="false" :filter-option="false"
:options="personOptions" :options="personOptions"
@search="searchPeople" @search="searchPeople"
/> >
<template #suffixIcon><SearchOutlined /></template>
</a-select>
</a-form-item> </a-form-item>
</a-col> </a-col>
</a-row> </a-row>
<a-flex justify="space-between" align="center" wrap="wrap" :gap="8">
<a-typography-text v-if="lastSyncedLabel" type="secondary">
آخرین همگام‌سازی: {{ lastSyncedLabel }}
</a-typography-text>
<a-typography-text v-else type="secondary">
بعد از انتخاب بازه، فیلتر را اعمال کنید یا از ته‌حساب به‌روز کنید.
</a-typography-text>
<a-button type="primary" html-type="submit" :loading="loading">
اعمال فیلتر
</a-button>
</a-flex>
</a-form> </a-form>
</a-card> </a-card>
</a-col>
<a-row v-if="summary" :gutter="[16, 16]"> <a-col v-if="summary" :xs="24" :sm="8">
<a-col :xs="24" :sm="8">
<a-card :bordered="false"> <a-card :bordered="false">
<a-statistic title="تعداد ردیف" :value="summary.totalLines" /> <a-statistic
title="تعداد ردیف"
:value="summary.totalLines"
:formatter="(val) => toFaDigits(String(val))"
/>
</a-card> </a-card>
</a-col> </a-col>
<a-col :xs="24" :sm="8"> <a-col v-if="summary" :xs="24" :sm="8">
<a-card :bordered="false"> <a-card :bordered="false">
<a-statistic title="جمع مبلغ" :value="formatMali(summary.maliSum)" /> <a-statistic title="جمع مبلغ" :value="formatMali(summary.maliSum)" />
</a-card> </a-card>
</a-col> </a-col>
<a-col :xs="24" :sm="8"> <a-col v-if="summary" :xs="24" :sm="8">
<a-card :bordered="false"> <a-card :bordered="false">
<a-statistic title="جمع وزن" :value="formatNum(summary.vaznSum)" /> <a-statistic title="جمع وزن" :value="formatNum(summary.vaznSum)" />
</a-card> </a-card>
</a-col> </a-col>
</a-row>
<a-row v-if="summary?.byKind?.length" :gutter="[16, 16]"> <a-col v-if="summary?.byKind?.length" :xs="24" :lg="12">
<a-col :xs="24" :lg="12">
<a-card :bordered="false" title="به تفکیک نوع"> <a-card :bordered="false" title="به تفکیک نوع">
<a-list <a-list :data-source="summary.byKind" item-layout="horizontal">
:data-source="summary.byKind"
item-layout="horizontal"
size="small"
>
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<a-list-item-meta :title="item.label"> <a-list-item-meta :title="item.label">
@@ -453,12 +516,11 @@ onUnmounted(() => stopPoll());
</a-list> </a-list>
</a-card> </a-card>
</a-col> </a-col>
<a-col :xs="24" :lg="12"> <a-col v-if="summary?.byGroup?.length" :xs="24" :lg="12">
<a-card :bordered="false" title="به تفکیک گروه"> <a-card :bordered="false" title="به تفکیک گروه">
<a-list <a-list
:data-source="summary.byGroup.slice(0, 8)" :data-source="summary.byGroup.slice(0, 8)"
item-layout="horizontal" item-layout="horizontal"
size="small"
> >
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
@@ -473,15 +535,17 @@ onUnmounted(() => stopPoll());
</a-list> </a-list>
</a-card> </a-card>
</a-col> </a-col>
</a-row>
<a-card v-if="summary?.distinctNos?.length" :bordered="false" title="مقادیر خام NO در این بازه"> <a-col v-if="summary?.distinctNos?.length" :span="24">
<a-card :bordered="false" title="انواع سند خام (NO)">
<a-space wrap> <a-space wrap>
<a-tag v-for="no in summary.distinctNos" :key="no">{{ no }}</a-tag> <a-tag v-for="no in summary.distinctNos" :key="no">{{ no }}</a-tag>
</a-space> </a-space>
</a-card> </a-card>
</a-col>
<a-card :bordered="false" title="ردیف‌ها"> <a-col :span="24">
<a-card :bordered="false" title="ردیف‌های گزارش">
<a-table <a-table
:columns="columns" :columns="columns"
:data-source="report?.items ?? []" :data-source="report?.items ?? []"
@@ -491,12 +555,18 @@ onUnmounted(() => stopPoll());
pageSize, pageSize,
total: report?.total ?? 0, total: report?.total ?? 0,
showSizeChanger: true, showSizeChanger: true,
showTotal: (total) => `${toFaDigits(String(total))} ردیف`,
pageSizeOptions: ['20', '50', '100'], pageSizeOptions: ['20', '50', '100'],
}" }"
row-key="id" row-key="id"
:scroll="{ x: 1100 }" :scroll="{ x: 1100 }"
@change="onTableChange" @change="onTableChange"
/> >
<template #emptyText>
<a-empty description="برای این بازه ردیفی نیست. بازه را اعمال کنید یا از ته‌حساب به‌روز کنید." />
</template>
</a-table>
</a-card> </a-card>
</a-flex> </a-col>
</a-row>
</template> </template>