fix: alinear KPIs BPS al milímetro con Ads Manager y Clientify Online
Meta solo cuenta registration leads; Google guarda fracciones y redondea al sumar; ventas CRM usan pipeline Online con importe > 0. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -268,6 +268,11 @@ async function upsertDeal(tenantId: string, d: Json) {
|
||||
}
|
||||
}
|
||||
const closed = str(d.actual_closed_date, 40);
|
||||
const pipeUrl = str(d.pipeline, 200);
|
||||
let pipelineId: string | null = null;
|
||||
if (pipeUrl.includes('/pipelines/')) {
|
||||
pipelineId = pipeUrl.replace(/\/$/, '').split('/').pop() || null;
|
||||
}
|
||||
const row = {
|
||||
id,
|
||||
tenant_id: tenantId,
|
||||
@@ -277,6 +282,8 @@ async function upsertDeal(tenantId: string, d: Json) {
|
||||
amount: n(d.amount ?? d.amount_user),
|
||||
won_at: stage === 'won' && closed ? closed : null,
|
||||
lost_at: stage === 'lost' && closed ? closed : null,
|
||||
pipeline_id: pipelineId,
|
||||
pipeline_name: str(d.pipeline_desc, 120) || null,
|
||||
};
|
||||
const base = supabaseUrl();
|
||||
await fetch(
|
||||
|
||||
@@ -138,7 +138,7 @@ async function fetchWonDeals(
|
||||
tenantId: string | null,
|
||||
useServiceRole: boolean
|
||||
): Promise<DealWonRow[]> {
|
||||
const select = 'amount,won_at,stage,tenant_id';
|
||||
const select = 'amount,won_at,stage,tenant_id,pipeline_id,pipeline_name';
|
||||
const pageSize = 1000;
|
||||
const out: DealWonRow[] = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user