Add lead funnel, stage conversion, and dwell reports to the report builder.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-18 17:29:58 +03:30
co-authored by Cursor
parent 2788103488
commit 968252ec2f
6 changed files with 944 additions and 27 deletions
+77 -2
View File
@@ -5387,7 +5387,7 @@ export interface ReportsViewFilters {
period: string;
from?: string;
to?: string;
/** dashboard | builder */
/** dashboard | builder | leads */
mode?: string;
builder?: {
metric?: string;
@@ -5407,7 +5407,12 @@ export type ReportsBuilderMetric =
| "activities_done"
| "people_created"
| "invoice_amount"
| "invoice_count";
| "invoice_count"
| "leads_created"
| "leads_converted"
| "leads_lost"
| "leads_active"
| "leads_avg_dwell_hours";
export const REPORTS_BUILDER_METRICS: ReportsBuilderMetric[] = [
"won_amount",
@@ -5419,6 +5424,11 @@ export const REPORTS_BUILDER_METRICS: ReportsBuilderMetric[] = [
"people_created",
"invoice_amount",
"invoice_count",
"leads_created",
"leads_converted",
"leads_lost",
"leads_active",
"leads_avg_dwell_hours",
];
export const REPORTS_BUILDER_METRIC_LABELS: Record<
@@ -5434,6 +5444,11 @@ export const REPORTS_BUILDER_METRIC_LABELS: Record<
people_created: "مشتریان جدید",
invoice_amount: "مبلغ فاکتور",
invoice_count: "تعداد فاکتور",
leads_created: "لیدهای ایجادشده",
leads_converted: "لیدهای تبدیل‌شده",
leads_lost: "لیدهای ازدست‌رفته",
leads_active: "لیدهای فعال (فعلی)",
leads_avg_dwell_hours: "میانگین ماندن در مرحله لید (ساعت)",
};
/** ابعاد گروه‌بندی گزارش‌ساز */
@@ -5443,6 +5458,7 @@ export type ReportsBuilderDimension =
| "team"
| "source"
| "stage"
| "lead_stage"
| "month"
| "status";
@@ -5452,6 +5468,7 @@ export const REPORTS_BUILDER_DIMENSIONS: ReportsBuilderDimension[] = [
"team",
"source",
"stage",
"lead_stage",
"month",
"status",
];
@@ -5465,10 +5482,26 @@ export const REPORTS_BUILDER_DIMENSION_LABELS: Record<
team: "تیم",
source: "منبع",
stage: "مرحله مسیر فروش",
lead_stage: "مرحله / ستون لید",
month: "ماه",
status: "وضعیت معامله",
};
/** متریک‌های مربوط به لید در گزارش‌ساز */
export const REPORTS_LEAD_BUILDER_METRICS: ReportsBuilderMetric[] = [
"leads_created",
"leads_converted",
"leads_lost",
"leads_active",
"leads_avg_dwell_hours",
];
export function isReportsLeadBuilderMetric(
metric: ReportsBuilderMetric,
): boolean {
return (REPORTS_LEAD_BUILDER_METRICS as string[]).includes(metric);
}
export interface ReportsBuilderQuery {
metric: ReportsBuilderMetric;
dimension: ReportsBuilderDimension;
@@ -5484,6 +5517,48 @@ export interface ReportsBuilderRowDto {
value: number;
}
/** تحلیل اختصاصی کانبان لیدها (قیف، تبدیل بین‌مرحله‌ای، ماندگاری) */
export interface ReportsLeadsFunnelStageDto {
stageId: string;
stageName: string;
count: number;
sharePercent: number;
/** نسبت به ستون قبلی در ترتیب کانبان؛ null برای اولی */
conversionFromPrevPercent: number | null;
avgDwellHours: number | null;
}
export interface ReportsLeadsTransitionDto {
fromStageId: string;
fromStageName: string;
toStageId: string;
toStageName: string;
count: number;
/** درصد از کل خروجی‌های fromStage در بازه */
conversionPercent: number;
}
export interface ReportsLeadsDwellDto {
stageId: string;
stageName: string;
avgHours: number;
sampleCount: number;
}
export interface ReportsLeadsAnalyticsDto {
from: string;
to: string;
created: number;
converted: number;
lost: number;
active: number;
/** تبدیل‌شده ÷ (تبدیل‌شده + ازدست‌رفته) در بازه؛ اگر مخرج صفر باشد ۰ */
conversionRate: number;
funnel: ReportsLeadsFunnelStageDto[];
transitions: ReportsLeadsTransitionDto[];
dwellByStage: ReportsLeadsDwellDto[];
}
export interface ReportsBuilderResultDto {
metric: ReportsBuilderMetric;
metricLabel: string;