@fayz-ai/plugin-crm 0.40.1 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CrmPage-DLFFHQJP.js → CrmPage-LPIRRUUT.js} +8 -5
- package/dist/CrmPage-LPIRRUUT.js.map +1 -0
- package/dist/components/ActivityTimeline.d.ts.map +1 -1
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/index.js +1 -19
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +2 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/main.browser.js +3 -1
- package/dist/migrations/main.browser.js.map +1 -1
- package/dist/migrations/main.js +270 -2
- package/dist/migrations/main.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/views/ActivityListView.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/CrmPage-DLFFHQJP.js.map +0 -1
|
@@ -66,6 +66,8 @@ export declare const MIGRATION_065_A_DEAL_HAS_CONTACT_ROUTES = "-- 065_a_deal_ha
|
|
|
66
66
|
export declare const MIGRATION_066_A_DRAFT_SEGMENT_SHOWS_WHO_IT_REACHES = "-- 066_a_draft_segment_shows_who_it_reaches.sql\n--\n-- The editor counted the draft (064) but did not say WHO: \"129 neg\u00F3cios\" with\n-- no way to see them means the person checks the segment somewhere else, or\n-- trusts it blind. This returns the rows a draft rule reaches (ids only; the\n-- screen reads names under its own RLS), capped, in the same rule engine.\n\nCREATE OR REPLACE FUNCTION public.crm_segment_preview_rows(\n p_source_view text, p_rules jsonb, p_unit uuid DEFAULT NULL, p_limit integer DEFAULT 500\n)\nRETURNS TABLE(id uuid, person_id uuid)\nLANGUAGE plpgsql\nSTABLE SECURITY DEFINER\nSET search_path TO ''\nAS $function$\nDECLARE\n v_tenant uuid := app.current_tenant_id();\n v_person text;\nBEGIN\n IF v_tenant IS NULL THEN\n RAISE EXCEPTION 'crm_segment_preview_rows: sem tenant na sess\u00E3o' USING ERRCODE = '42501';\n END IF;\n IF NOT app.has_permission('sales.read', NULL::uuid) THEN\n RAISE EXCEPTION 'crm_segment_preview_rows: exige sales.read' USING ERRCODE = '42501';\n END IF;\n IF p_source_view NOT IN ('people', 'v_crm_people_engagement', 'v_crm_deal_audience') THEN\n RAISE EXCEPTION 'crm_segment_preview_rows: leitura % n\u00E3o \u00E9 um p\u00FAblico', p_source_view USING ERRCODE = '22023';\n END IF;\n v_person := CASE WHEN p_source_view = 'v_crm_deal_audience' THEN 'person_id' ELSE 'id' END;\n RETURN QUERY EXECUTE format('SELECT s.id, s.%I FROM public.%I s WHERE %s LIMIT %s',\n v_person, p_source_view, public.crm_segment_where_for(p_source_view, p_rules, p_unit, v_tenant),\n greatest(1, least(coalesce(p_limit, 500), 2000)));\nEND $function$;\n\nREVOKE ALL ON FUNCTION public.crm_segment_preview_rows(text, jsonb, uuid, integer) FROM PUBLIC, anon;\nGRANT EXECUTE ON FUNCTION public.crm_segment_preview_rows(text, jsonb, uuid, integer) TO authenticated, service_role;\n";
|
|
67
67
|
export declare const MIGRATION_067_PARKED_STAGES_AND_HONEST_NUMBERS = "-- 067_parked_stages_and_honest_numbers.sql\n--\n-- Three corrections to how the CRM counts, and two panels that were \"em breve\".\n--\n-- 1. PARKED STAGES. \"Contato futuro\" and \"Lista de espera\" are not steps of\n-- the funnel: a deal there is waiting, not progressing. They inflated the\n-- conversion view (a stage after Ganho with 8 deals) and every pipeline\n-- total. A stage can now say it is parked; funnel, pipeline and rates skip\n-- it. Backfilled by code for the two stages every funnel here uses.\n--\n-- 2. CONVERSION = A WON DEAL. The KPI read \"lead para neg\u00F3cio\" (deals \u00F7 leads),\n-- which is meaningless where every lead gets a deal on arrival \u2014 it showed\n-- 101%. Conversion is now won \u00F7 deals that entered the flow (not parked, not\n-- archived); win rate is won \u00F7 closed (won + lost); the sales cycle is the\n-- average days from a deal's creation to its win.\n--\n-- 3. The two panels: `crm_operational_panel` (the seller's day: overdue and\n-- today's tasks, deals with no contact yet, stalled deals, conversations\n-- waiting on us) and `crm_maturity_panel` (is the CRM being used: deals with\n-- no owner / company / contact, contacts with no phone, activity logged per\n-- seller, messages that go through the platform).\n\nALTER TABLE public.plg_crm_pipeline_stages\n ADD COLUMN IF NOT EXISTS is_parked boolean NOT NULL DEFAULT false;\n\nCOMMENT ON COLUMN public.plg_crm_pipeline_stages.is_parked IS\n 'A waiting stage (Contato futuro, Lista de espera): outside the funnel, the conversion rate and the pipeline totals (067).';\n\nUPDATE public.plg_crm_pipeline_stages\n SET is_parked = true\n WHERE code IN ('contato-futuro', 'lista-de-espera') AND NOT is_parked;\n\n-- \u2500\u2500 the summary, with the numbers that mean something \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n--\n-- A NEW function and not a new `crm_summary`: changing its return type made\n-- the replay of 032 (which creates the old shape) fail. `crm_summary` stays\n-- exactly as 032 left it \u2014 restored here, because an earlier draft of this\n-- migration was applied with the wider shape \u2014 and `crm_flow_summary` carries\n-- the same columns plus the flow-aware ones.\nDROP FUNCTION IF EXISTS public.crm_summary();\ncreate or replace function public.crm_summary()\nreturns table (\n total_leads bigint,\n new_leads_this_month bigint,\n total_deals bigint,\n open_deals_value numeric,\n won_deals_this_month bigint,\n won_deals_value_this_month numeric,\n won_deals bigint,\n won_deals_value numeric,\n pending_activities bigint,\n overdue_activities bigint\n)\nlanguage plpgsql\nstable\nsecurity definer\nset search_path = public, app, pg_catalog\nas $$\ndeclare\n v_tenant uuid := app.current_tenant_id();\n v_foco uuid := nullif(app.current_unit_id(), '00000000-0000-0000-0000-000000000000'::uuid);\n v_negado boolean := app.current_unit_id() = '00000000-0000-0000-0000-000000000000'::uuid;\n v_unidades uuid[];\n v_sem_unidade boolean;\n v_dono boolean;\n v_uid uuid := auth.uid();\n v_mes date := date_trunc('month', now())::date;\n v_hoje date := now()::date;\nbegin\n -- Sem tenant, ou com unidade pedida que o usu\u00E1rio n\u00E3o tem: a pol\u00EDtica\n -- devolveria vazio, e aqui tamb\u00E9m. Nunca cair para \"a rede inteira\".\n if v_tenant is null or v_negado then\n return query select 0::bigint, 0::bigint, 0::bigint, 0::numeric,\n 0::bigint, 0::numeric, 0::bigint, 0::numeric,\n 0::bigint, 0::bigint;\n return;\n end if;\n\n select coalesce(array_agg(a.unit_id), '{}'::uuid[])\n into v_unidades\n from app.user_unit_access a\n where a.tenant_id = v_tenant\n and a.user_id = v_uid\n and (v_foco is null or a.unit_id = v_foco)\n and app.has_permission('crm.pipeline.read', a.unit_id);\n\n -- Linha sem unidade \u00E9 da rede: a pol\u00EDtica a mostra a quem tem a permiss\u00E3o no\n -- n\u00EDvel do tenant. Com uma unidade em foco ela continua aparecendo \u2014 \u00E9 o que\n -- a pol\u00EDtica diz, e \u00E9 por isso que os R$ 520.072,00 dos 1.599 neg\u00F3cios sem\n -- unidade aparecem em toda unidade. Assim \u00E9 no V1 tamb\u00E9m: l\u00E1 s\u00E3o 1.600\n -- oportunidades sem `unit_id`.\n v_sem_unidade := app.has_permission('crm.pipeline.read', null::uuid);\n v_dono := app.owner_scoped('crm.deal');\n\n return query\n with negocios as (\n select d.status, d.value, d.won_at, d.updated_at\n from public.plg_crm_deals d\n where d.tenant_id = v_tenant\n and ( (d.unit_id is null and v_sem_unidade)\n or (d.unit_id = any (v_unidades)))\n and (not v_dono or d.owner_id is null or d.owner_id = v_uid)\n ),\n pessoas as (\n select count(*) filter (where p.kind = 'lead') as leads,\n count(*) filter (where p.kind = 'lead' and p.created_at >= v_mes) as leads_mes\n from public.people p\n where p.tenant_id = v_tenant\n and (p.unit_id is null or p.unit_id = any (v_unidades))\n ),\n tarefas as (\n select count(*) filter (where a.completed_at is null) as pendentes,\n count(*) filter (where a.completed_at is null and a.due_date < v_hoje) as atrasadas\n from public.plg_crm_activities a\n where a.tenant_id = v_tenant\n )\n select pessoas.leads,\n pessoas.leads_mes,\n (select count(*) from negocios),\n (select coalesce(sum(value), 0) from negocios where status = 'open'),\n (select count(*) from negocios where status = 'won' and coalesce(won_at, updated_at) >= v_mes),\n (select coalesce(sum(value), 0) from negocios where status = 'won' and coalesce(won_at, updated_at) >= v_mes),\n (select count(*) from negocios where status = 'won'),\n (select coalesce(sum(value), 0) from negocios where status = 'won'),\n tarefas.pendentes,\n tarefas.atrasadas\n from pessoas, tarefas;\nend $$;\n\nrevoke all on function public.crm_summary() from public;\ngrant execute on function public.crm_summary() to authenticated, service_role;\n\nDROP FUNCTION IF EXISTS public.crm_flow_summary();\nCREATE FUNCTION public.crm_flow_summary()\n RETURNS TABLE(\n total_leads bigint, new_leads_this_month bigint, total_deals bigint, open_deals_value numeric,\n won_deals_this_month bigint, won_deals_value_this_month numeric, won_deals bigint, won_deals_value numeric,\n pending_activities bigint, overdue_activities bigint,\n entered_deals bigint, open_deals bigint, parked_deals bigint, lost_deals bigint, avg_cycle_days numeric\n )\n LANGUAGE plpgsql\n STABLE SECURITY DEFINER\n SET search_path TO 'public', 'app', 'pg_catalog'\nAS $function$\ndeclare\n v_tenant uuid := app.current_tenant_id();\n v_foco uuid := nullif(app.current_unit_id(), '00000000-0000-0000-0000-000000000000'::uuid);\n v_negado boolean := app.current_unit_id() = '00000000-0000-0000-0000-000000000000'::uuid;\n v_unidades uuid[];\n v_sem_unidade boolean;\n v_dono boolean;\n v_uid uuid := auth.uid();\n v_mes date := date_trunc('month', now())::date;\n v_hoje date := now()::date;\nbegin\n if v_tenant is null or v_negado then\n return query select 0::bigint, 0::bigint, 0::bigint, 0::numeric, 0::bigint, 0::numeric, 0::bigint, 0::numeric,\n 0::bigint, 0::bigint, 0::bigint, 0::bigint, 0::bigint, 0::bigint, null::numeric;\n return;\n end if;\n\n select coalesce(array_agg(a.unit_id), '{}'::uuid[])\n into v_unidades\n from app.user_unit_access a\n where a.tenant_id = v_tenant\n and a.user_id = v_uid\n and (v_foco is null or a.unit_id = v_foco)\n and app.has_permission('crm.pipeline.read', a.unit_id);\n v_sem_unidade := app.has_permission('crm.pipeline.read', null::uuid);\n v_dono := app.owner_scoped('crm.deal');\n\n return query\n with negocios as (\n select d.status, d.value, d.won_at, d.updated_at, d.created_at,\n coalesce(st.is_parked, false) as parked\n from public.plg_crm_deals d\n left join public.plg_crm_pipeline_stages st on st.id = d.stage_id\n where d.tenant_id = v_tenant\n and ( (d.unit_id is null and v_sem_unidade)\n or (d.unit_id = any (v_unidades)))\n and (not v_dono or d.owner_id is null or d.owner_id = v_uid)\n ),\n pessoas as (\n select count(*) filter (where p.kind = 'lead') as leads,\n count(*) filter (where p.kind = 'lead' and p.created_at >= v_mes) as leads_mes\n from public.people p\n where p.tenant_id = v_tenant\n and (p.unit_id is null or p.unit_id = any (v_unidades))\n ),\n tarefas as (\n select count(*) filter (where a.completed_at is null) as pendentes,\n count(*) filter (where a.completed_at is null and a.due_date < v_hoje) as atrasadas\n from public.plg_crm_activities a\n where a.tenant_id = v_tenant\n )\n select pessoas.leads,\n pessoas.leads_mes,\n (select count(*) from negocios where status <> 'archived'),\n (select coalesce(sum(value), 0) from negocios where status = 'open' and not parked),\n (select count(*) from negocios where status = 'won' and coalesce(won_at, updated_at) >= v_mes),\n (select coalesce(sum(value), 0) from negocios where status = 'won' and coalesce(won_at, updated_at) >= v_mes),\n (select count(*) from negocios where status = 'won'),\n (select coalesce(sum(value), 0) from negocios where status = 'won'),\n tarefas.pendentes,\n tarefas.atrasadas,\n (select count(*) from negocios where status <> 'archived' and not (status = 'open' and parked)),\n (select count(*) from negocios where status = 'open' and not parked),\n (select count(*) from negocios where status = 'open' and parked),\n (select count(*) from negocios where status = 'lost'),\n (select round(avg(extract(epoch from (coalesce(won_at, updated_at) - created_at)) / 86400)::numeric, 1)\n from negocios where status = 'won')\n from pessoas, tarefas;\nend $function$;\n\nREVOKE ALL ON FUNCTION public.crm_flow_summary() FROM PUBLIC, anon;\nGRANT EXECUTE ON FUNCTION public.crm_flow_summary() TO authenticated, service_role;\n\n-- \u2500\u2500 the seller's day \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nCREATE OR REPLACE FUNCTION public.crm_operational_panel(p_stalled_days integer DEFAULT 14)\nRETURNS jsonb\nLANGUAGE plpgsql\nSTABLE SECURITY DEFINER\nSET search_path TO 'public', 'app', 'pg_catalog'\nAS $function$\ndeclare\n v_tenant uuid := app.current_tenant_id();\n v_foco uuid := nullif(app.current_unit_id(), '00000000-0000-0000-0000-000000000000'::uuid);\n v_out jsonb;\nbegin\n if v_tenant is null then raise exception 'crm_operational_panel: sem tenant na sess\u00E3o' using errcode = '42501'; end if;\n if not app.has_permission('sales.read', null::uuid) then raise exception 'crm_operational_panel: exige sales.read' using errcode = '42501'; end if;\n\n with deals as (\n select d.id, d.assigned_to_id as owner, d.created_at, d.updated_at, d.stage_id, st.name as stage, st.\"order\" as stage_order\n from public.plg_crm_deals d\n join public.plg_crm_pipeline_stages st on st.id = d.stage_id\n where d.tenant_id = v_tenant and d.status = 'open' and not st.is_parked and not st.is_won and not st.is_lost\n and (v_foco is null or d.unit_id is null or d.unit_id = v_foco)\n ),\n contacted as (\n select distinct a.deal_id from public.plg_crm_activities a\n where a.tenant_id = v_tenant and a.deal_id is not null\n and a.activity_type in ('whatsapp', 'call', 'email', 'meeting', 'visit', 'note')\n ),\n per_deal as (\n select d.*,\n (d.updated_at < now() - make_interval(days => p_stalled_days)) as stalled,\n (c.deal_id is null) as uncontacted\n from deals d left join contacted c on c.deal_id = d.id\n ),\n tasks as (\n select a.assigned_to_id as owner,\n count(*) filter (where a.due_date < current_date) as overdue,\n count(*) filter (where a.due_date = current_date) as today\n from public.plg_crm_activities a\n where a.tenant_id = v_tenant and a.completed_at is null and a.activity_type = 'task'\n group by 1\n ),\n waiting as (\n select c.lead_owner_id as owner, count(*) as n\n from public.v_conversations c\n where c.tenant_id = v_tenant and c.status = 'open' and c.last_message_direction = 'inbound'\n and not (c.acknowledged_at is not null and c.acknowledged_at >= c.last_message_at)\n group by 1\n ),\n owners as (\n select owner::text as owner from per_deal union select owner::text from tasks union select owner::text from waiting\n ),\n team as (\n select m.user_id::text as user_id, p.name\n from public.v_authz_memberships m join public.people p on p.id = m.person_id\n where m.tenant_id = v_tenant\n )\n select jsonb_build_object(\n 'totals', jsonb_build_object(\n 'open_deals', (select count(*) from per_deal),\n 'stalled', (select count(*) from per_deal where stalled),\n 'uncontacted', (select count(*) from per_deal where uncontacted),\n 'overdue_tasks', (select coalesce(sum(overdue), 0) from tasks),\n 'today_tasks', (select coalesce(sum(today), 0) from tasks),\n 'waiting_conversations', (select coalesce(sum(n), 0) from waiting)\n ),\n 'by_owner', coalesce((\n select jsonb_agg(jsonb_build_object(\n 'owner_id', o.owner,\n 'name', coalesce((select t.name from team t where t.user_id = o.owner limit 1), case when o.owner is null then 'Sem dono' else 'Sem nome' end),\n 'open_deals', (select count(*) from per_deal d where d.owner::text is not distinct from o.owner),\n 'stalled', (select count(*) from per_deal d where d.owner::text is not distinct from o.owner and d.stalled),\n 'uncontacted', (select count(*) from per_deal d where d.owner::text is not distinct from o.owner and d.uncontacted),\n 'overdue_tasks', coalesce((select t.overdue from tasks t where t.owner::text is not distinct from o.owner), 0),\n 'today_tasks', coalesce((select t.today from tasks t where t.owner::text is not distinct from o.owner), 0),\n 'waiting_conversations', coalesce((select w.n from waiting w where w.owner::text is not distinct from o.owner), 0)\n ) order by o.owner nulls last)\n from owners o), '[]'::jsonb),\n 'by_stage', coalesce((\n select jsonb_agg(jsonb_build_object('stage', s.stage, 'open', s.open, 'stalled', s.stalled, 'avg_days', s.avg_days) order by s.stage_order)\n from (select stage, stage_order, count(*) as open, count(*) filter (where stalled) as stalled,\n round(avg(extract(epoch from (now() - updated_at)) / 86400)::numeric, 1) as avg_days\n from per_deal group by stage, stage_order) s), '[]'::jsonb)\n ) into v_out;\n return v_out;\nend $function$;\n\nREVOKE ALL ON FUNCTION public.crm_operational_panel(integer) FROM PUBLIC, anon;\nGRANT EXECUTE ON FUNCTION public.crm_operational_panel(integer) TO authenticated, service_role;\n\n-- \u2500\u2500 is the CRM being used \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nCREATE OR REPLACE FUNCTION public.crm_maturity_panel()\nRETURNS jsonb\nLANGUAGE plpgsql\nSTABLE SECURITY DEFINER\nSET search_path TO 'public', 'app', 'pg_catalog'\nAS $function$\ndeclare\n v_tenant uuid := app.current_tenant_id();\n v_foco uuid := nullif(app.current_unit_id(), '00000000-0000-0000-0000-000000000000'::uuid);\n v_out jsonb;\nbegin\n if v_tenant is null then raise exception 'crm_maturity_panel: sem tenant na sess\u00E3o' using errcode = '42501'; end if;\n if not app.has_permission('sales.read', null::uuid) then raise exception 'crm_maturity_panel: exige sales.read' using errcode = '42501'; end if;\n\n with deals as (\n select d.* from public.plg_crm_deals d\n where d.tenant_id = v_tenant and d.status in ('open', 'won', 'lost')\n and (v_foco is null or d.unit_id is null or d.unit_id = v_foco)\n ),\n team as (\n select m.user_id, p.name from public.v_authz_memberships m join public.people p on p.id = m.person_id\n where m.tenant_id = v_tenant and m.active\n ),\n acts as (\n select a.created_by, a.activity_type, a.created_at from public.plg_crm_activities a\n where a.tenant_id = v_tenant and a.created_at > now() - interval '30 days'\n and a.activity_type not in ('stage_changed', 'deal_created', 'lead_created', 'deal_archived', 'lead_archived', 'quote_created')\n ),\n msgs as (\n select m.direction, m.sender_kind, m.sender_label, m.author from public.plg_conversation_messages m\n where m.tenant_id = v_tenant and m.channel = 'whatsapp' and m.at > now() - interval '30 days'\n )\n select jsonb_build_object(\n 'deals', (select count(*) from deals),\n 'hygiene', jsonb_build_object(\n 'no_owner', (select count(*) from deals where assigned_to_id is null),\n 'no_company', (select count(*) from deals where company_id is null),\n 'no_contact', (select count(*) from deals where contact_id is null),\n 'no_phone', (select count(*) from deals d left join public.people p on p.id = d.contact_id\n where coalesce(p.phone, '') = ''\n and not exists (select 1 from public.plg_crm_person_phones ph where ph.person_id = d.contact_id)),\n 'stale_30d', (select count(*) from deals where status = 'open' and updated_at < now() - interval '30 days')\n ),\n 'activity_by_seller', coalesce((\n select jsonb_agg(jsonb_build_object(\n 'user_id', t.user_id, 'name', t.name,\n 'last_7d', (select count(*) from acts a where a.created_by = t.user_id and a.created_at > now() - interval '7 days'),\n 'last_30d', (select count(*) from acts a where a.created_by = t.user_id),\n 'whatsapp_30d', (select count(*) from acts a where a.created_by = t.user_id and a.activity_type = 'whatsapp')\n ) order by (select count(*) from acts a where a.created_by = t.user_id) desc, t.name) from team t), '[]'::jsonb),\n 'inbox', jsonb_build_object(\n 'inbound_30d', (select count(*) from msgs where direction = 'inbound'),\n 'outbound_platform_30d', (select count(*) from msgs where direction = 'outbound' and coalesce(sender_label, '') <> 'Pelo celular'),\n 'outbound_phone_30d', (select count(*) from msgs where direction = 'outbound' and sender_label = 'Pelo celular'),\n 'outbound_campaign_30d', (select count(*) from msgs where direction = 'outbound' and sender_kind = 'automation')\n )\n ) into v_out;\n return v_out;\nend $function$;\n\nREVOKE ALL ON FUNCTION public.crm_maturity_panel() FROM PUBLIC, anon;\nGRANT EXECUTE ON FUNCTION public.crm_maturity_panel() TO authenticated, service_role;\n";
|
|
68
68
|
export declare const MIGRATION_068_A_PHONE_HAS_A_STATUS = "-- 068_a_phone_has_a_status.sql\n--\n-- Contact disposition, the phone half (GoHighLevel calls it DND/disposition).\n--\n-- A seller who learns that a number is wrong, has no WhatsApp or never picks\n-- up had nowhere to write it down: the next campaign touch went to the same\n-- number, and so did the next seller. This is that fact, once per tenant and\n-- per number \u2014 not per person, because the same number sits on a person, on\n-- their company and on the Receita record, and \"wrong number\" is true of the\n-- number wherever it shows up.\n--\n-- plg_crm_phone_status one row per (tenant, phone_e164); the last word\n-- wins, with who said it, when, and why.\n-- crm_set_phone_status the one door to write it, for the seller's screen\n-- and for the integration service (service_role).\n--\n-- And the routes a journey walks (065) grow the last resort the sales team\n-- asked for: when every person is exhausted, the company's own phone and the\n-- phones the Receita has on file \u2014 after the people, never instead of them.\n-- crm_phone_is_mobile says whether a number is a BR mobile (only a mobile can\n-- have WhatsApp) and the number's status, so the engine can skip what a seller\n-- already marked as dead.\n\n-- \u2500\u2500 the status of a phone \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nCREATE TABLE IF NOT EXISTS public.plg_crm_phone_status (\n id uuid PRIMARY KEY DEFAULT gen_random_uuid(),\n tenant_id uuid NOT NULL REFERENCES public.tenants(id) ON DELETE CASCADE,\n phone_e164 text NOT NULL,\n status text NOT NULL,\n reason text,\n source text NOT NULL DEFAULT 'seller',\n -- Whose number it was when it was marked, when known. Not a foreign key:\n -- merging or deleting the person must not erase what was learned about the\n -- number.\n person_id uuid,\n set_by uuid,\n -- Kept as text on purpose (same discipline as created_by_name, 042): the\n -- screen shows who said it without reading auth.users.\n set_by_name text,\n created_at timestamptz NOT NULL DEFAULT now(),\n updated_at timestamptz NOT NULL DEFAULT now(),\n CONSTRAINT plg_crm_phone_status_status\n CHECK (status IN ('ok', 'wrong_number', 'no_whatsapp', 'no_answer', 'invalid')),\n CONSTRAINT plg_crm_phone_status_source\n CHECK (source IN ('seller', 'campaign', 'provider', 'import')),\n CONSTRAINT plg_crm_phone_status_once UNIQUE (tenant_id, phone_e164)\n);\n\nCOMMENT ON TABLE public.plg_crm_phone_status IS\n 'What the house knows about a phone number (068): wrong number, no WhatsApp, never answers, invalid \u2014 or ok again. One row per tenant and number; the last word wins. Written through crm_set_phone_status.';\n\nALTER TABLE public.plg_crm_phone_status ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.plg_crm_phone_status FORCE ROW LEVEL SECURITY;\n\n-- The same predicates as plg_crm_person_phones (013): read with sales.read,\n-- write with sales.edit, always inside the session's tenant.\nDROP POLICY IF EXISTS plg_crm_phone_status_authz_select ON public.plg_crm_phone_status;\nCREATE POLICY plg_crm_phone_status_authz_select ON public.plg_crm_phone_status\n FOR SELECT TO authenticated USING (\n tenant_id = (SELECT app.current_tenant_id())\n AND (SELECT app.has_permission('sales.read', NULL::uuid)));\n\nDROP POLICY IF EXISTS plg_crm_phone_status_authz_insert ON public.plg_crm_phone_status;\nCREATE POLICY plg_crm_phone_status_authz_insert ON public.plg_crm_phone_status\n FOR INSERT TO authenticated WITH CHECK (\n tenant_id = (SELECT app.current_tenant_id())\n AND (SELECT app.has_permission('sales.edit', NULL::uuid)));\n\nDROP POLICY IF EXISTS plg_crm_phone_status_authz_update ON public.plg_crm_phone_status;\nCREATE POLICY plg_crm_phone_status_authz_update ON public.plg_crm_phone_status\n FOR UPDATE TO authenticated USING (\n tenant_id = (SELECT app.current_tenant_id())\n AND (SELECT app.has_permission('sales.edit', NULL::uuid)))\n WITH CHECK (\n tenant_id = (SELECT app.current_tenant_id())\n AND (SELECT app.has_permission('sales.edit', NULL::uuid)));\n\nDROP POLICY IF EXISTS plg_crm_phone_status_authz_delete ON public.plg_crm_phone_status;\nCREATE POLICY plg_crm_phone_status_authz_delete ON public.plg_crm_phone_status\n FOR DELETE TO authenticated USING (\n tenant_id = (SELECT app.current_tenant_id())\n AND (SELECT app.has_permission('sales.edit', NULL::uuid)));\n\nGRANT SELECT, INSERT, UPDATE, DELETE ON public.plg_crm_phone_status TO authenticated;\nGRANT ALL ON public.plg_crm_phone_status TO service_role;\n\n-- \u2500\u2500 the one door to write it \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n--\n-- SECURITY DEFINER so the integration service (service_role, no tenant in the\n-- session) and the seller's screen take the same path. Who may call:\n-- * service_role \u2014 the tenant comes from the session when there is one,\n-- else from p_person. Neither \u2192 refused: a number alone does not say\n-- whose CRM it belongs to.\n-- * a signed-in member of the session's tenant who can work deals or\n-- conversations (sales.edit, crm.pipeline.edit or conversations.create \u2014\n-- the SDR role holds the last two without the first being enough).\nCREATE OR REPLACE FUNCTION public.crm_set_phone_status(\n p_phone text,\n p_status text,\n p_reason text,\n p_source text DEFAULT 'seller',\n p_person uuid DEFAULT NULL\n)\nRETURNS uuid\nLANGUAGE plpgsql\nSECURITY DEFINER\nSET search_path TO ''\nAS $function$\nDECLARE\n v_service boolean := coalesce(auth.role(), '') = 'service_role';\n v_tenant uuid := app.current_tenant_id();\n v_uid uuid := auth.uid();\n v_phone text := public.crm_phone_e164(p_phone);\n v_status text := lower(trim(coalesce(p_status, '')));\n v_source text := lower(trim(coalesce(p_source, 'seller')));\n v_name text;\n v_id uuid;\nBEGIN\n IF v_phone IS NULL THEN\n RAISE EXCEPTION 'crm_set_phone_status: % is not a phone number', coalesce(p_phone, 'null')\n USING ERRCODE = '22023';\n END IF;\n IF v_status NOT IN ('ok', 'wrong_number', 'no_whatsapp', 'no_answer', 'invalid') THEN\n RAISE EXCEPTION 'crm_set_phone_status: unknown status %', p_status USING ERRCODE = '22023';\n END IF;\n IF v_source NOT IN ('seller', 'campaign', 'provider', 'import') THEN\n RAISE EXCEPTION 'crm_set_phone_status: unknown source %', p_source USING ERRCODE = '22023';\n END IF;\n\n IF v_service THEN\n IF v_tenant IS NULL AND p_person IS NOT NULL THEN\n SELECT p.tenant_id INTO v_tenant FROM public.people p WHERE p.id = p_person;\n END IF;\n IF v_tenant IS NULL THEN\n RAISE EXCEPTION 'crm_set_phone_status: no tenant (send p_person or a tenant claim)'\n USING ERRCODE = '42501';\n END IF;\n ELSE\n IF v_tenant IS NULL OR v_uid IS NULL THEN\n RAISE EXCEPTION 'crm_set_phone_status: no tenant in the session' USING ERRCODE = '42501';\n END IF;\n IF NOT (app.has_permission_anywhere('sales.edit')\n OR app.has_permission_anywhere('crm.pipeline.edit')\n OR app.has_permission_anywhere('conversations.create')) THEN\n RAISE EXCEPTION 'crm_set_phone_status: requires sales.edit, crm.pipeline.edit or conversations.create'\n USING ERRCODE = '42501';\n END IF;\n END IF;\n\n -- A person from another tenant is not a fact about this one.\n IF p_person IS NOT NULL\n AND NOT EXISTS (SELECT 1 FROM public.people p WHERE p.id = p_person AND p.tenant_id = v_tenant) THEN\n RAISE EXCEPTION 'crm_set_phone_status: person % is not in this tenant', p_person USING ERRCODE = '42501';\n END IF;\n\n IF v_uid IS NOT NULL THEN\n SELECT coalesce(nullif(u.raw_user_meta_data->>'full_name', ''),\n nullif(u.raw_user_meta_data->>'name', ''),\n u.email)\n INTO v_name\n FROM auth.users u WHERE u.id = v_uid;\n END IF;\n\n INSERT INTO public.plg_crm_phone_status AS s\n (tenant_id, phone_e164, status, reason, source, person_id, set_by, set_by_name)\n VALUES (v_tenant, v_phone, v_status, nullif(trim(coalesce(p_reason, '')), ''), v_source, p_person, v_uid,\n coalesce(v_name, CASE WHEN v_service THEN 'Sistema' END))\n ON CONFLICT (tenant_id, phone_e164) DO UPDATE\n SET status = EXCLUDED.status,\n reason = EXCLUDED.reason,\n source = EXCLUDED.source,\n person_id = coalesce(EXCLUDED.person_id, s.person_id),\n set_by = EXCLUDED.set_by,\n set_by_name = EXCLUDED.set_by_name,\n updated_at = now()\n RETURNING s.id INTO v_id;\n\n RETURN v_id;\nEND\n$function$;\n\nREVOKE ALL ON FUNCTION public.crm_set_phone_status(text, text, text, text, uuid) FROM PUBLIC, anon;\nGRANT EXECUTE ON FUNCTION public.crm_set_phone_status(text, text, text, text, uuid) TO authenticated, service_role;\n\nCOMMENT ON FUNCTION public.crm_set_phone_status(text, text, text, text, uuid) IS\n 'Marks a phone number (normalised with crm_phone_e164) as ok / wrong_number / no_whatsapp / no_answer / invalid for the tenant, with who, why and from where (seller, campaign, provider, import). Returns the row id (068).';\n\n-- \u2500\u2500 a BR mobile \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n-- +55, a two-digit area code (no leading 0) and nine digits starting with 9.\n-- Only a mobile can have WhatsApp; a landline route is still a route for a\n-- call task.\nCREATE OR REPLACE FUNCTION public.crm_phone_is_mobile(p_e164 text)\nRETURNS boolean\nLANGUAGE sql\nIMMUTABLE\nSET search_path TO ''\nAS $function$\n SELECT coalesce(p_e164 ~ '^\\+55[1-9][0-9]9[0-9]{8}$', false)\n$function$;\n\nGRANT EXECUTE ON FUNCTION public.crm_phone_is_mobile(text) TO authenticated, service_role;\n\n-- \u2500\u2500 the routes, with the company's phones as the last resort \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n--\n-- The people part is 065 unchanged. Then, ranked after everybody (30): the\n-- company's own phone, then each phone the Receita lists, minus any number a\n-- person already carries. They go to the deal's contact (the reply lands on\n-- the deal's thread) and are named after them, falling back to the company.\n--\n-- Same RETURNS TABLE as 065: a changed shape cannot be replayed (065 runs\n-- CREATE OR REPLACE again on db-from-zero, and Postgres refuses to change a\n-- return type that way). Whether a number is a mobile is\n-- crm_phone_is_mobile(phone_e164); its status is plg_crm_phone_status, read\n-- by the caller when it needs it.\nCREATE OR REPLACE FUNCTION public.crm_deal_contact_routes(p_deal uuid)\nRETURNS TABLE(route integer, person_id uuid, name text, phone_e164 text, email text, via text)\nLANGUAGE sql\nSTABLE\nSET search_path TO ''\nAS $function$\n WITH deal AS (\n SELECT d.id, d.tenant_id, d.contact_id, d.company_id\n FROM public.plg_crm_deals d WHERE d.id = p_deal\n ),\n grp AS (\n SELECT m2.company_id\n FROM deal\n JOIN public.plg_crm_company_group_members m1 ON m1.company_id = deal.company_id\n JOIN public.plg_crm_company_group_members m2 ON m2.group_id = m1.group_id\n WHERE m2.company_id <> deal.company_id\n ),\n who AS (\n SELECT deal.contact_id AS person_id, 0 AS rank, 'primary'::text AS via FROM deal WHERE deal.contact_id IS NOT NULL\n UNION ALL\n SELECT cp.person_id, 10 + CASE WHEN cp.is_primary THEN 0 ELSE 1 END, 'company'\n FROM deal JOIN public.plg_crm_company_people cp ON cp.company_id = deal.company_id\n WHERE cp.person_id IS DISTINCT FROM deal.contact_id\n UNION ALL\n SELECT cp.person_id, 20 + CASE WHEN cp.is_primary THEN 0 ELSE 1 END, 'group'\n FROM grp JOIN public.plg_crm_company_people cp ON cp.company_id = grp.company_id\n ),\n person AS (\n SELECT DISTINCT ON (w.person_id) w.person_id, w.rank, w.via, p.name, p.email, p.phone\n FROM who w JOIN public.people p ON p.id = w.person_id\n WHERE p.merged_into_id IS NULL AND coalesce(p.is_active, true)\n ORDER BY w.person_id, w.rank\n ),\n phones AS (\n SELECT pe.person_id, pe.rank, pe.via, pe.name, pe.email, public.crm_phone_e164(pe.phone) AS phone_e164, 0 AS ord\n FROM person pe\n UNION ALL\n SELECT pe.person_id, pe.rank, pe.via, pe.name, pe.email, public.crm_phone_e164(ph.phone),\n CASE WHEN ph.is_primary THEN 1 ELSE 2 END\n FROM person pe JOIN public.plg_crm_person_phones ph ON ph.person_id = pe.person_id\n ),\n dedup AS (\n SELECT DISTINCT ON (coalesce(ph.phone_e164, 'person:' || ph.person_id::text))\n ph.person_id, ph.rank, ph.via, ph.name, ph.email, ph.phone_e164, ph.ord\n FROM phones ph\n WHERE ph.phone_e164 IS NOT NULL OR ph.email IS NOT NULL\n ORDER BY coalesce(ph.phone_e164, 'person:' || ph.person_id::text), ph.rank, ph.ord\n ),\n numbered AS (\n SELECT d.*, row_number() OVER (PARTITION BY d.person_id ORDER BY d.ord) AS nth\n FROM dedup d\n ),\n people_rows AS (\n SELECT n.rank, n.person_id, n.name, n.phone_e164, n.email,\n CASE WHEN n.via = 'primary' AND n.nth > 1 THEN 'other_phone' ELSE n.via END AS via,\n n.nth AS ord\n FROM numbered n\n WHERE n.phone_e164 IS NOT NULL\n OR NOT EXISTS (SELECT 1 FROM numbered o WHERE o.person_id = n.person_id AND o.phone_e164 IS NOT NULL)\n ),\n -- The last resort: the company's phones.\n co AS (\n SELECT c.name, c.phone, c.metadata\n FROM deal JOIN public.plg_crm_companies c ON c.id = deal.company_id\n ),\n co_phones AS (\n SELECT public.crm_phone_e164(co.phone) AS phone_e164, 0::bigint AS ord, 'company_phone'::text AS via\n FROM co\n UNION ALL\n -- `telefones` is an array of strings (\"+55\u2026\"); an object entry from an\n -- older enrichment is read by its usual keys rather than dropped.\n SELECT public.crm_phone_e164(CASE jsonb_typeof(t.v)\n WHEN 'string' THEN t.v #>> '{}'\n WHEN 'object' THEN coalesce(t.v->>'numero', t.v->>'telefone', t.v->>'phone')\n END),\n t.i, 'receita'\n FROM co\n CROSS JOIN LATERAL jsonb_array_elements(\n CASE WHEN jsonb_typeof(co.metadata->'receita'->'telefones') = 'array'\n THEN co.metadata->'receita'->'telefones' ELSE '[]'::jsonb END\n ) WITH ORDINALITY AS t(v, i)\n ),\n co_rows AS (\n SELECT DISTINCT ON (cp.phone_e164) cp.phone_e164, cp.ord, cp.via\n FROM co_phones cp\n WHERE cp.phone_e164 IS NOT NULL\n AND NOT EXISTS (SELECT 1 FROM people_rows pr WHERE pr.phone_e164 = cp.phone_e164)\n ORDER BY cp.phone_e164, cp.ord\n ),\n all_rows AS (\n SELECT pr.rank, pr.person_id, pr.name, pr.phone_e164, pr.email, pr.via, pr.ord::bigint AS ord\n FROM people_rows pr\n UNION ALL\n SELECT 30, deal.contact_id,\n coalesce((SELECT p.name FROM public.people p WHERE p.id = deal.contact_id), (SELECT co.name FROM co)),\n cr.phone_e164, NULL::text, cr.via, cr.ord\n FROM co_rows cr CROSS JOIN deal\n )\n SELECT row_number() OVER (ORDER BY a.rank, a.person_id, a.ord)::integer,\n a.person_id, a.name, a.phone_e164, a.email, a.via\n FROM all_rows a\n ORDER BY a.rank, a.person_id, a.ord\n$function$;\n\nREVOKE ALL ON FUNCTION public.crm_deal_contact_routes(uuid) FROM PUBLIC, anon;\nGRANT EXECUTE ON FUNCTION public.crm_deal_contact_routes(uuid) TO authenticated, service_role;\n\nCOMMENT ON FUNCTION public.crm_deal_contact_routes(uuid) IS\n 'Every way to reach a deal, best first (065): the contact, their other phones, the company''s people, the group''s people, then (068) the company phone and the Receita phones. Mobile: crm_phone_is_mobile(phone_e164); status: plg_crm_phone_status.';\n";
|
|
69
|
+
export declare const MIGRATION_069_EVERY_ACTION_IS_ON_THE_TIMELINE = "-- ============================================================================\n-- 069_every_action_is_on_the_timeline \u2014 the database writes the CRM's history,\n-- with who did it.\n--\n-- Julio created \u00ABKaryna Gon\u00E7alves / Prime Interway\u00BB on 10-28 and the card's\n-- timeline said \"Nenhuma atividade ainda\". The facts \"lead created\", \"deal\n-- created\" and \"moved to <stage>\" were written by the SCREEN after its save,\n-- best-effort, and swallowed when they failed; the database only logged leads\n-- that came from a public form. 333 of 375 leads had no \"lead created\", and\n-- none of the 229 stage changes said who moved the card.\n--\n-- One writer now, the database:\n--\n-- * every activity records its author: `created_by` defaults to\n-- `auth.uid()`, and `created_by_name` is filled from the team when absent;\n-- * a lead arriving (any source) logs `lead_created`, by whoever created it;\n-- * a deal inserted logs `deal_created`;\n-- * a deal changing stage logs `stage_changed` / `deal_won` / `deal_lost`\n-- with the stage's name;\n-- * a deal changing hands logs `deal_assigned` with the new owner's name.\n--\n-- The client stops writing the first three (same release). A tab still on the\n-- old bundle would write its copy too; the activities trigger drops that twin\n-- (a \"created\" fact exists once, a stage move once per 15 seconds).\n--\n-- History: leads and lead-born deals without their \"created\" fact get one,\n-- dated and signed from the record itself. Deals with no lead (the V1 sales\n-- imported as cards) are left alone.\n--\n-- Idempotent and replay-safe.\n-- ============================================================================\n\nALTER TABLE public.plg_crm_activities\n ALTER COLUMN created_by SET DEFAULT auth.uid();\n\nCREATE OR REPLACE FUNCTION public.plg_crm_member_name(p_user uuid, p_tenant uuid)\nRETURNS text\nLANGUAGE sql\nSTABLE\nSECURITY DEFINER\nSET search_path = ''\nAS $$\n SELECT p.name\n FROM public.v_team_members m\n JOIN public.people p ON p.id = m.person_id\n WHERE p_user IS NOT NULL AND m.user_id = p_user AND m.tenant_id = p_tenant\n LIMIT 1\n$$;\n\nREVOKE ALL ON FUNCTION public.plg_crm_member_name(uuid, uuid) FROM PUBLIC;\nGRANT EXECUTE ON FUNCTION public.plg_crm_member_name(uuid, uuid) TO authenticated, service_role;\n\nCREATE OR REPLACE FUNCTION public.plg_crm_activity_names_its_author()\nRETURNS trigger\nLANGUAGE plpgsql\nSECURITY DEFINER\nSET search_path = ''\nAS $$\nBEGIN\n -- A tab on the old bundle still writes its own copy of what the triggers\n -- below now write. The twin is dropped: a \"created\" fact exists once, a\n -- stage move once per 15 seconds.\n IF NEW.activity_type IN ('lead_created', 'deal_created') AND EXISTS (\n SELECT 1 FROM public.plg_crm_activities a\n WHERE a.activity_type = NEW.activity_type\n AND ((NEW.activity_type = 'lead_created' AND a.lead_id = NEW.lead_id AND a.deal_id IS NULL)\n OR (NEW.activity_type = 'deal_created' AND a.deal_id = NEW.deal_id))) THEN\n RETURN NULL;\n END IF;\n IF NEW.activity_type IN ('stage_changed', 'deal_won', 'deal_lost') AND NEW.deal_id IS NOT NULL AND EXISTS (\n SELECT 1 FROM public.plg_crm_activities a\n WHERE a.deal_id = NEW.deal_id AND a.activity_type = NEW.activity_type\n AND a.description IS NOT DISTINCT FROM NEW.description\n AND a.created_at > now() - interval '15 seconds') THEN\n RETURN NULL;\n END IF;\n IF NEW.created_by IS NOT NULL AND (NEW.created_by_name IS NULL OR btrim(NEW.created_by_name) = '') THEN\n NEW.created_by_name := public.plg_crm_member_name(NEW.created_by, NEW.tenant_id);\n END IF;\n RETURN NEW;\nEND;\n$$;\n\nDROP TRIGGER IF EXISTS plg_crm_activity_names_its_author ON public.plg_crm_activities;\nCREATE TRIGGER plg_crm_activity_names_its_author\n BEFORE INSERT ON public.plg_crm_activities\n FOR EACH ROW EXECUTE FUNCTION public.plg_crm_activity_names_its_author();\n\n-- A lead arriving, from any source (it used to be public forms only).\nCREATE OR REPLACE FUNCTION public.crm_log_public_lead_activity(p_lead_id uuid, p_deal_id uuid)\nRETURNS void\nLANGUAGE plpgsql\nSECURITY DEFINER\nSET search_path TO 'public'\nAS $function$\nDECLARE\n v_lead public.people%ROWTYPE;\n v_deal_id uuid := p_deal_id;\nBEGIN\n SELECT * INTO v_lead FROM public.people WHERE id = p_lead_id;\n IF NOT FOUND OR v_lead.kind <> 'lead' THEN RETURN; END IF;\n\n IF v_deal_id IS NULL THEN\n SELECT order_id INTO v_deal_id\n FROM public.plg_crm_deal_extensions WHERE lead_id = v_lead.id;\n END IF;\n\n INSERT INTO public.plg_crm_activities\n (tenant_id, unit_id, lead_id, contact_name, activity_type, title, description, completed_at, created_at, created_by)\n SELECT\n v_lead.tenant_id, v_lead.unit_id, v_lead.id, v_lead.name, 'lead_created', v_lead.name,\n NULLIF(v_lead.metadata->>'sourceName', ''),\n v_lead.created_at, v_lead.created_at, v_lead.created_by\n WHERE NOT EXISTS (\n SELECT 1 FROM public.plg_crm_activities a\n WHERE a.lead_id = v_lead.id AND a.activity_type = 'lead_created'\n );\n\n IF v_deal_id IS NOT NULL THEN\n INSERT INTO public.plg_crm_activities\n (tenant_id, unit_id, deal_id, lead_id, contact_name, activity_type, title, completed_at, created_at, created_by)\n SELECT\n v_lead.tenant_id, v_lead.unit_id, v_deal_id, v_lead.id, v_lead.name, 'deal_created', v_lead.name,\n v_lead.created_at, v_lead.created_at, v_lead.created_by\n WHERE NOT EXISTS (\n SELECT 1 FROM public.plg_crm_activities a\n WHERE a.deal_id = v_deal_id AND a.activity_type = 'deal_created'\n );\n END IF;\nEND;\n$function$;\n\nCREATE OR REPLACE FUNCTION public.plg_crm_deal_on_the_timeline()\nRETURNS trigger\nLANGUAGE plpgsql\nSECURITY DEFINER\nSET search_path = ''\nAS $$\nDECLARE\n v_stage record;\n v_type text;\n v_who text;\nBEGIN\n -- Never let the history break the write it describes.\n BEGIN\n IF TG_OP = 'INSERT' THEN\n INSERT INTO public.plg_crm_activities\n (tenant_id, unit_id, deal_id, lead_id, contact_id, activity_type, title, completed_at, created_at, created_by)\n SELECT NEW.tenant_id, NEW.unit_id, NEW.id, NEW.lead_id, NEW.contact_id, 'deal_created',\n coalesce(nullif(NEW.title, ''), 'Neg\u00F3cio'), NEW.created_at, NEW.created_at,\n coalesce(auth.uid(), NEW.owner_id)\n WHERE NOT EXISTS (SELECT 1 FROM public.plg_crm_activities a\n WHERE a.deal_id = NEW.id AND a.activity_type = 'deal_created');\n RETURN NULL;\n END IF;\n\n IF NEW.stage_id IS DISTINCT FROM OLD.stage_id AND NEW.stage_id IS NOT NULL THEN\n SELECT s.name, s.is_won, s.is_lost INTO v_stage\n FROM public.plg_crm_pipeline_stages s WHERE s.id = NEW.stage_id;\n v_type := CASE WHEN v_stage.is_won THEN 'deal_won' WHEN v_stage.is_lost THEN 'deal_lost' ELSE 'stage_changed' END;\n INSERT INTO public.plg_crm_activities\n (tenant_id, unit_id, deal_id, lead_id, contact_id, activity_type, title, description, completed_at, created_by)\n SELECT NEW.tenant_id, NEW.unit_id, NEW.id, NEW.lead_id, NEW.contact_id, v_type,\n coalesce(nullif(NEW.title, ''), 'Neg\u00F3cio'), v_stage.name, now(), auth.uid();\n END IF;\n\n IF NEW.assigned_to_id IS DISTINCT FROM OLD.assigned_to_id THEN\n v_who := public.plg_crm_member_name(NEW.assigned_to_id, NEW.tenant_id);\n INSERT INTO public.plg_crm_activities\n (tenant_id, unit_id, deal_id, lead_id, contact_id, activity_type, title, description, completed_at, created_by)\n VALUES (NEW.tenant_id, NEW.unit_id, NEW.id, NEW.lead_id, NEW.contact_id, 'deal_assigned',\n coalesce(nullif(NEW.title, ''), 'Neg\u00F3cio'),\n CASE WHEN NEW.assigned_to_id IS NULL THEN 'Sem respons\u00E1vel' ELSE 'Respons\u00E1vel: ' || coalesce(v_who, 'outra pessoa') END,\n now(), auth.uid());\n END IF;\n EXCEPTION WHEN OTHERS THEN\n RAISE WARNING 'plg_crm_deal_on_the_timeline failed for deal %: %', NEW.id, SQLERRM;\n END;\n RETURN NULL;\nEND;\n$$;\n\nDROP TRIGGER IF EXISTS plg_crm_deal_on_the_timeline_insert ON public.plg_crm_deals;\nCREATE TRIGGER plg_crm_deal_on_the_timeline_insert\n AFTER INSERT ON public.plg_crm_deals\n FOR EACH ROW WHEN (NEW.lead_id IS NOT NULL OR NEW.pipeline_id IS NOT NULL)\n EXECUTE FUNCTION public.plg_crm_deal_on_the_timeline();\n\nDROP TRIGGER IF EXISTS plg_crm_deal_on_the_timeline_update ON public.plg_crm_deals;\nCREATE TRIGGER plg_crm_deal_on_the_timeline_update\n AFTER UPDATE OF stage_id, assigned_to_id ON public.plg_crm_deals\n FOR EACH ROW EXECUTE FUNCTION public.plg_crm_deal_on_the_timeline();\n\n-- History. Leads first, then the deals born from them.\nINSERT INTO public.plg_crm_activities\n (tenant_id, unit_id, lead_id, contact_name, activity_type, title, description, completed_at, created_at, created_by)\nSELECT p.tenant_id, p.unit_id, p.id, p.name, 'lead_created', p.name,\n NULLIF(p.metadata->>'sourceName', ''), p.created_at, p.created_at, p.created_by\n FROM public.people p\n WHERE p.kind = 'lead'\n AND NOT EXISTS (SELECT 1 FROM public.plg_crm_activities a\n WHERE a.lead_id = p.id AND a.activity_type = 'lead_created');\n\nINSERT INTO public.plg_crm_activities\n (tenant_id, unit_id, deal_id, lead_id, contact_id, contact_name, activity_type, title, completed_at, created_at, created_by)\nSELECT d.tenant_id, d.unit_id, d.id, d.lead_id, d.contact_id, p.name, 'deal_created',\n coalesce(nullif(d.title, ''), p.name, 'Neg\u00F3cio'), d.created_at, d.created_at,\n coalesce(p.created_by, d.owner_id)\n FROM public.plg_crm_deals d\n LEFT JOIN public.people p ON p.id = d.lead_id\n WHERE d.lead_id IS NOT NULL\n AND NOT EXISTS (SELECT 1 FROM public.plg_crm_activities a\n WHERE a.deal_id = d.id AND a.activity_type = 'deal_created');\n\n-- The author's name on what history now carries an author for.\nUPDATE public.plg_crm_activities a\n SET created_by_name = public.plg_crm_member_name(a.created_by, a.tenant_id)\n WHERE a.created_by IS NOT NULL AND (a.created_by_name IS NULL OR btrim(a.created_by_name) = '')\n AND a.activity_type IN ('lead_created', 'deal_created');\n";
|
|
70
|
+
export declare const MIGRATION_070_A_DEAL_LIVES_IN_ITS_LEADS_UNIT = "-- ============================================================================\n-- 070_a_deal_lives_in_its_leads_unit \u2014 a deal without a unit takes its lead's.\n--\n-- \u00ABKaryna Gon\u00E7alves / Prime Interway\u00BB was created with no unit while its lead\n-- and every activity on it were ChefControl's. A deal with no unit shows in\n-- every unit, its activities only in theirs: with BeautyControl selected the\n-- card opened and said \"Nenhuma atividade ainda\" over five activities (11-03).\n-- A deal now takes its lead's (or contact's) unit when it has none; the four\n-- deals in that state are corrected.\n--\n-- Idempotent and replay-safe.\n-- ============================================================================\n\nCREATE OR REPLACE FUNCTION public.plg_crm_deal_takes_its_leads_unit()\nRETURNS trigger\nLANGUAGE plpgsql\nSECURITY DEFINER\nSET search_path = ''\nAS $$\nBEGIN\n IF NEW.unit_id IS NULL AND coalesce(NEW.lead_id, NEW.contact_id) IS NOT NULL THEN\n SELECT p.unit_id INTO NEW.unit_id\n FROM public.people p\n WHERE p.id = coalesce(NEW.lead_id, NEW.contact_id) AND p.tenant_id = NEW.tenant_id;\n END IF;\n RETURN NEW;\nEND;\n$$;\n\nDROP TRIGGER IF EXISTS plg_crm_deal_takes_its_leads_unit ON public.plg_crm_deals;\nCREATE TRIGGER plg_crm_deal_takes_its_leads_unit\n BEFORE INSERT OR UPDATE OF lead_id, contact_id ON public.plg_crm_deals\n FOR EACH ROW EXECUTE FUNCTION public.plg_crm_deal_takes_its_leads_unit();\n\nUPDATE public.plg_crm_deals d\n SET unit_id = p.unit_id\n FROM public.people p\n WHERE d.unit_id IS NULL AND p.id = coalesce(d.lead_id, d.contact_id)\n AND p.tenant_id = d.tenant_id AND p.unit_id IS NOT NULL;\n\n-- The facts 069 wrote for those deals carry the unit too.\nUPDATE public.plg_crm_activities a\n SET unit_id = d.unit_id\n FROM public.plg_crm_deals d\n WHERE a.unit_id IS NULL AND a.deal_id = d.id AND d.unit_id IS NOT NULL;\n";
|
|
69
71
|
export declare const MIGRATIONS: Array<{
|
|
70
72
|
id: string;
|
|
71
73
|
sql: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB,0+/EAykDlC,CAAA;AAED,eAAO,MAAM,yCAAyC,8qYAkOrD,CAAA;AAED,eAAO,MAAM,+CAA+C,0onBAwT3D,CAAA;AAED,eAAO,MAAM,oDAAoD,8jpBAsYhE,CAAA;AAED,eAAO,MAAM,8CAA8C,gp4BAugB1D,CAAA;AAED,eAAO,MAAM,iDAAiD,47QA4J7D,CAAA;AAED,eAAO,M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,CAAA;AAED,eAAO,MAAM,6CAA6C,i6KAgIzD,CAAA;AAED,eAAO,MAAM,2CAA2C,u7HAsEvD,CAAA;AAED,eAAO,MAAM,kDAAkD,mgFA8D9D,CAAA;AAED,eAAO,MAAM,iDAAiD,o0aA+M7D,CAAA;AAED,eAAO,MAAM,gDAAgD,4gSAuJ5D,CAAA;AAED,eAAO,MAAM,8CAA8C,iybAkQ1D,CAAA;AAED,eAAO,MAAM,wCAAwC,64JAiHpD,CAAA;AAED,eAAO,MAAM,yDAAyD,k/HA4FrE,CAAA;AAED,eAAO,MAAM,wCAAwC,6gWAiLpD,CAAA;AAED,eAAO,MAAM,qDAAqD,gvNAuHjE,CAAA;AAED,eAAO,MAAM,iDAAiD,q2YAoR7D,CAAA;AAED,eAAO,MAAM,4CAA4C,s2CAsBxD,CAAA;AAED,eAAO,MAAM,qCAAqC,inaA4RjD,CAAA;AAED,eAAO,MAAM,uCAAuC,knJAoGnD,CAAA;AAED,eAAO,MAAM,kDAAkD,6zDAoC9D,CAAA;AAED,eAAO,MAAM,8CAA8C,igmBAiX1D,CAAA;AAED,eAAO,MAAM,kCAAkC,iwgBAmU9C,CAAA;AAED,eAAO,MAAM,6CAA6C,ujUA2NzD,CAAA;AAED,eAAO,MAAM,4CAA4C,i4DA6CxD,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAuEzD,CAAA"}
|
|
@@ -67,8 +67,10 @@ var MIGRATION_065_A_DEAL_HAS_CONTACT_ROUTES = "";
|
|
|
67
67
|
var MIGRATION_066_A_DRAFT_SEGMENT_SHOWS_WHO_IT_REACHES = "";
|
|
68
68
|
var MIGRATION_067_PARKED_STAGES_AND_HONEST_NUMBERS = "";
|
|
69
69
|
var MIGRATION_068_A_PHONE_HAS_A_STATUS = "";
|
|
70
|
+
var MIGRATION_069_EVERY_ACTION_IS_ON_THE_TIMELINE = "";
|
|
71
|
+
var MIGRATION_070_A_DEAL_LIVES_IN_ITS_LEADS_UNIT = "";
|
|
70
72
|
var MIGRATIONS = [];
|
|
71
73
|
|
|
72
|
-
export { MIGRATIONS, MIGRATION_000_BASELINE, MIGRATION_001_DE_ONDE_VEIO_E_QUEM_INDICOU, MIGRATION_002_A_PERGUNTA_QUE_O_CLIENTE_RESPONDE, MIGRATION_003_O_CLIENTE_RESPONDE_NO_PROPRIO_TELEFONE, MIGRATION_004_UM_RECORTE_DE_GENTE_QUE_TEM_NOME, MIGRATION_005_A_ETAPA_GANHA_UM_CODIGO_E_UM_COMECO, MIGRATION_006_A_ESCADA_DO_RELACIONAMENTO, MIGRATION_008_A_REGUA_DA_REDE_E_PUBLICA, MIGRATION_009_THE_LEAD_OFFER_CASCADES, MIGRATION_010_THE_BOARD_HEARS_THE_DEAL, MIGRATION_011_A_FUNNEL_IS_BORN_USABLE, MIGRATION_012_THE_CRM_SAYS_WHAT_HAPPENED, MIGRATION_013_THE_COMPANY_HOLDS_ITS_PEOPLE, MIGRATION_014_THE_SECOND_FORM_IS_THE_SAME_PERSON, MIGRATION_015_THE_FAMILY_OWNS_MORE_THAN_ONE_HOUSE, MIGRATION_016_THE_STRANGER_ONLY_EDITS_WHAT_IT_MADE, MIGRATION_017_TWO_FORMS_ONE_PERSON_AND_THE_INTEREST_ADDS_UP, MIGRATION_018_THE_ROTA_SKIPS_WHO_LEFT_AND_THE_SCREEN_SHOWS_WHO_WAITS, MIGRATION_019_QUEM_AINDA_COMPRA_E_QUEM_SUMIU, MIGRATION_020_O_STATUS_E_CONSEQUENCIA_DO_QUE_FOI_FEITO, MIGRATION_021_O_AGENTE_MEXE_NO_CARD, MIGRATION_022_A_LISTA_DO_FUNIL_PERGUNTA_POR_CIDADE, MIGRATION_023_O_CONTATO_DIZ_DE_QUE_EMPRESA_ELE_E, MIGRATION_024_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E, MIGRATION_025_O_CARD_DIZ_QUEM_E_O_VENDEDOR, MIGRATION_026_A_LEITURA_DO_FUNIL_SAI_DO_LACO, MIGRATION_027_A_NOTA_DO_NEGOCIO_CHEGA_NA_BUSCA, MIGRATION_028_O_LEAD_DIZ_QUANTO_VALE_E_POR_QUE, MIGRATION_029_A_PORTA_DE_SERVICO_FECHA_ATRAS_DE_QUEM_ENTROU_DEPOIS, MIGRATION_030_A_LISTA_DE_ORCAMENTOS_NAO_VARRE_O_HISTORICO, MIGRATION_031_O_NOME_DO_CONTATO_ENTRA_NO_CARD, MIGRATION_032_O_PAINEL_DE_VENDAS_CONTA_NO_BANCO, MIGRATION_033_O_ENGAJAMENTO_NAO_SOMA_OS_PEDIDOS_DA_PLATAFORMA, MIGRATION_034_O_GRAFICO_DO_FUNIL_CONTA_A_ETAPA_INTEIRA, MIGRATION_035_QUEM_ESTA_NO_FUNIL_E_UM_LEAD, MIGRATION_036_O_FUNIL_DO_V1_ENTRA_NO_LUGAR_DO_FUNIL_DE_FABRICA, MIGRATION_037_O_NEGOCIO_E_O_ORCAMENTO_ATRAVESSAM_O_HISTORICO_FICA, MIGRATION_038_CANAL_ORIGEM_E_CAMPANHA_SAO_TRES_PERGUNTAS, MIGRATION_039_A_BANDEIRA_AGRUPA_O_QUE_A_RAIZ_DO_CNPJ_NAO_VE, MIGRATION_040_O_CARD_DO_FUNIL_NAO_LE_A_AGENDA_INTEIRA, MIGRATION_041_O_NOME_NO_CARD_E_DO_NEGOCIO_NAO_DA_AGENDA, MIGRATION_042_A_ATIVIDADE_DIZ_QUEM_A_FEZ, MIGRATION_043_A_CADENCIA_PARA_DE_ESPERAR_UM_FATO_QUE_NUNCA_CHEGA, MIGRATION_044_O_STATUS_NAO_E_UM_ACONTECIMENTO, MIGRATION_045_CONTATO_FEITO_E_CONTATO_QUE_ALGUEM_FEZ, MIGRATION_046_A_PASTILHA_DO_CARD_SO_FALA_QUANDO_TEM_O_QUE_DIZER, MIGRATION_047_O_DONO_DO_LEAD_TEM_UM_LUGAR_SO, MIGRATION_048_A_EMPRESA_TAMBEM_TEM_UM_ARROBA, MIGRATION_049_O_ARROBA_CHEGA_ATE_A_LISTA, MIGRATION_050_A_REUNIAO_E_UMA_ESPECIE_DECLARADA, MIGRATION_051_O_CRACHA_E_O_TELEFONE_RECUSADO_APARECEM, MIGRATION_052_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E, MIGRATION_053_A_ATIVIDADE_DIZ_DE_QUEM_ELA_E, MIGRATION_054_A_LISTA_DE_LEADS_PERGUNTA_POR_CIDADE, MIGRATION_055_A_CESTA_DO_INTERESSE_TEM_ONDE_MORAR, MIGRATION_056_O_INTERESSE_ENTRA_PELO_AGENDAMENTO, MIGRATION_057_O_NEGOCIO_E_DO_GRUPO_NAO_DO_CNPJ, MIGRATION_058_O_CARD_DIZ_O_NOME_DO_GRUPO, MIGRATION_059_A_EMPRESA_MOSTRA_O_INSTAGRAM_QUE_ELA_GUARDA, MIGRATION_060_O_FUNIL_SABE_DE_QUEM_ELE_E, MIGRATION_061_A_CONVERSAO_RESPEITA_O_FILTRO_DO_QUADRO, MIGRATION_062_THE_WHOLE_CRM_SAYS_WHICH_UNIT_IT_IS, MIGRATION_063_THE_ROTA_ENGINE_IS_SERVER_ONLY, MIGRATION_064_SEGMENTS_REACH_THE_DEAL, MIGRATION_065_A_DEAL_HAS_CONTACT_ROUTES, MIGRATION_066_A_DRAFT_SEGMENT_SHOWS_WHO_IT_REACHES, MIGRATION_067_PARKED_STAGES_AND_HONEST_NUMBERS, MIGRATION_068_A_PHONE_HAS_A_STATUS };
|
|
74
|
+
export { MIGRATIONS, MIGRATION_000_BASELINE, MIGRATION_001_DE_ONDE_VEIO_E_QUEM_INDICOU, MIGRATION_002_A_PERGUNTA_QUE_O_CLIENTE_RESPONDE, MIGRATION_003_O_CLIENTE_RESPONDE_NO_PROPRIO_TELEFONE, MIGRATION_004_UM_RECORTE_DE_GENTE_QUE_TEM_NOME, MIGRATION_005_A_ETAPA_GANHA_UM_CODIGO_E_UM_COMECO, MIGRATION_006_A_ESCADA_DO_RELACIONAMENTO, MIGRATION_008_A_REGUA_DA_REDE_E_PUBLICA, MIGRATION_009_THE_LEAD_OFFER_CASCADES, MIGRATION_010_THE_BOARD_HEARS_THE_DEAL, MIGRATION_011_A_FUNNEL_IS_BORN_USABLE, MIGRATION_012_THE_CRM_SAYS_WHAT_HAPPENED, MIGRATION_013_THE_COMPANY_HOLDS_ITS_PEOPLE, MIGRATION_014_THE_SECOND_FORM_IS_THE_SAME_PERSON, MIGRATION_015_THE_FAMILY_OWNS_MORE_THAN_ONE_HOUSE, MIGRATION_016_THE_STRANGER_ONLY_EDITS_WHAT_IT_MADE, MIGRATION_017_TWO_FORMS_ONE_PERSON_AND_THE_INTEREST_ADDS_UP, MIGRATION_018_THE_ROTA_SKIPS_WHO_LEFT_AND_THE_SCREEN_SHOWS_WHO_WAITS, MIGRATION_019_QUEM_AINDA_COMPRA_E_QUEM_SUMIU, MIGRATION_020_O_STATUS_E_CONSEQUENCIA_DO_QUE_FOI_FEITO, MIGRATION_021_O_AGENTE_MEXE_NO_CARD, MIGRATION_022_A_LISTA_DO_FUNIL_PERGUNTA_POR_CIDADE, MIGRATION_023_O_CONTATO_DIZ_DE_QUE_EMPRESA_ELE_E, MIGRATION_024_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E, MIGRATION_025_O_CARD_DIZ_QUEM_E_O_VENDEDOR, MIGRATION_026_A_LEITURA_DO_FUNIL_SAI_DO_LACO, MIGRATION_027_A_NOTA_DO_NEGOCIO_CHEGA_NA_BUSCA, MIGRATION_028_O_LEAD_DIZ_QUANTO_VALE_E_POR_QUE, MIGRATION_029_A_PORTA_DE_SERVICO_FECHA_ATRAS_DE_QUEM_ENTROU_DEPOIS, MIGRATION_030_A_LISTA_DE_ORCAMENTOS_NAO_VARRE_O_HISTORICO, MIGRATION_031_O_NOME_DO_CONTATO_ENTRA_NO_CARD, MIGRATION_032_O_PAINEL_DE_VENDAS_CONTA_NO_BANCO, MIGRATION_033_O_ENGAJAMENTO_NAO_SOMA_OS_PEDIDOS_DA_PLATAFORMA, MIGRATION_034_O_GRAFICO_DO_FUNIL_CONTA_A_ETAPA_INTEIRA, MIGRATION_035_QUEM_ESTA_NO_FUNIL_E_UM_LEAD, MIGRATION_036_O_FUNIL_DO_V1_ENTRA_NO_LUGAR_DO_FUNIL_DE_FABRICA, MIGRATION_037_O_NEGOCIO_E_O_ORCAMENTO_ATRAVESSAM_O_HISTORICO_FICA, MIGRATION_038_CANAL_ORIGEM_E_CAMPANHA_SAO_TRES_PERGUNTAS, MIGRATION_039_A_BANDEIRA_AGRUPA_O_QUE_A_RAIZ_DO_CNPJ_NAO_VE, MIGRATION_040_O_CARD_DO_FUNIL_NAO_LE_A_AGENDA_INTEIRA, MIGRATION_041_O_NOME_NO_CARD_E_DO_NEGOCIO_NAO_DA_AGENDA, MIGRATION_042_A_ATIVIDADE_DIZ_QUEM_A_FEZ, MIGRATION_043_A_CADENCIA_PARA_DE_ESPERAR_UM_FATO_QUE_NUNCA_CHEGA, MIGRATION_044_O_STATUS_NAO_E_UM_ACONTECIMENTO, MIGRATION_045_CONTATO_FEITO_E_CONTATO_QUE_ALGUEM_FEZ, MIGRATION_046_A_PASTILHA_DO_CARD_SO_FALA_QUANDO_TEM_O_QUE_DIZER, MIGRATION_047_O_DONO_DO_LEAD_TEM_UM_LUGAR_SO, MIGRATION_048_A_EMPRESA_TAMBEM_TEM_UM_ARROBA, MIGRATION_049_O_ARROBA_CHEGA_ATE_A_LISTA, MIGRATION_050_A_REUNIAO_E_UMA_ESPECIE_DECLARADA, MIGRATION_051_O_CRACHA_E_O_TELEFONE_RECUSADO_APARECEM, MIGRATION_052_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E, MIGRATION_053_A_ATIVIDADE_DIZ_DE_QUEM_ELA_E, MIGRATION_054_A_LISTA_DE_LEADS_PERGUNTA_POR_CIDADE, MIGRATION_055_A_CESTA_DO_INTERESSE_TEM_ONDE_MORAR, MIGRATION_056_O_INTERESSE_ENTRA_PELO_AGENDAMENTO, MIGRATION_057_O_NEGOCIO_E_DO_GRUPO_NAO_DO_CNPJ, MIGRATION_058_O_CARD_DIZ_O_NOME_DO_GRUPO, MIGRATION_059_A_EMPRESA_MOSTRA_O_INSTAGRAM_QUE_ELA_GUARDA, MIGRATION_060_O_FUNIL_SABE_DE_QUEM_ELE_E, MIGRATION_061_A_CONVERSAO_RESPEITA_O_FILTRO_DO_QUADRO, MIGRATION_062_THE_WHOLE_CRM_SAYS_WHICH_UNIT_IT_IS, MIGRATION_063_THE_ROTA_ENGINE_IS_SERVER_ONLY, MIGRATION_064_SEGMENTS_REACH_THE_DEAL, MIGRATION_065_A_DEAL_HAS_CONTACT_ROUTES, MIGRATION_066_A_DRAFT_SEGMENT_SHOWS_WHO_IT_REACHES, MIGRATION_067_PARKED_STAGES_AND_HONEST_NUMBERS, MIGRATION_068_A_PHONE_HAS_A_STATUS, MIGRATION_069_EVERY_ACTION_IS_ON_THE_TIMELINE, MIGRATION_070_A_DEAL_LIVES_IN_ITS_LEADS_UNIT };
|
|
73
75
|
//# sourceMappingURL=main.browser.js.map
|
|
74
76
|
//# sourceMappingURL=main.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../node_modules/.cache/fayz-migration-stubs/main.ts"],"names":[],"mappings":";AAEO,IAAM,sBAAA,GAAyB;AAC/B,IAAM,yCAAA,GAA4C;AAClD,IAAM,+CAAA,GAAkD;AACxD,IAAM,oDAAA,GAAuD;AAC7D,IAAM,8CAAA,GAAiD;AACvD,IAAM,iDAAA,GAAoD;AAC1D,IAAM,wCAAA,GAA2C;AACjD,IAAM,uCAAA,GAA0C;AAChD,IAAM,qCAAA,GAAwC;AAC9C,IAAM,sCAAA,GAAyC;AAC/C,IAAM,qCAAA,GAAwC;AAC9C,IAAM,wCAAA,GAA2C;AACjD,IAAM,0CAAA,GAA6C;AACnD,IAAM,gDAAA,GAAmD;AACzD,IAAM,iDAAA,G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,GAAwD;AAC9D,IAAM,iDAAA,GAAoD;AAC1D,IAAM,4CAAA,GAA+C;AACrD,IAAM,qCAAA,GAAwC;AAC9C,IAAM,uCAAA,GAA0C;AAChD,IAAM,kDAAA,GAAqD;AAC3D,IAAM,8CAAA,GAAiD;AACvD,IAAM,kCAAA,GAAqC;AAC3C,IAAM,aAAiD","file":"main.browser.js","sourcesContent":["// GENERATED by scripts/tsup-migrations.mjs — the browser build of a\n// migrations barrel: the same names, no SQL. See that script for why.\nexport const MIGRATION_000_BASELINE = ''\nexport const MIGRATION_001_DE_ONDE_VEIO_E_QUEM_INDICOU = ''\nexport const MIGRATION_002_A_PERGUNTA_QUE_O_CLIENTE_RESPONDE = ''\nexport const MIGRATION_003_O_CLIENTE_RESPONDE_NO_PROPRIO_TELEFONE = ''\nexport const MIGRATION_004_UM_RECORTE_DE_GENTE_QUE_TEM_NOME = ''\nexport const MIGRATION_005_A_ETAPA_GANHA_UM_CODIGO_E_UM_COMECO = ''\nexport const MIGRATION_006_A_ESCADA_DO_RELACIONAMENTO = ''\nexport const MIGRATION_008_A_REGUA_DA_REDE_E_PUBLICA = ''\nexport const MIGRATION_009_THE_LEAD_OFFER_CASCADES = ''\nexport const MIGRATION_010_THE_BOARD_HEARS_THE_DEAL = ''\nexport const MIGRATION_011_A_FUNNEL_IS_BORN_USABLE = ''\nexport const MIGRATION_012_THE_CRM_SAYS_WHAT_HAPPENED = ''\nexport const MIGRATION_013_THE_COMPANY_HOLDS_ITS_PEOPLE = ''\nexport const MIGRATION_014_THE_SECOND_FORM_IS_THE_SAME_PERSON = ''\nexport const MIGRATION_015_THE_FAMILY_OWNS_MORE_THAN_ONE_HOUSE = ''\nexport const MIGRATION_016_THE_STRANGER_ONLY_EDITS_WHAT_IT_MADE = ''\nexport const MIGRATION_017_TWO_FORMS_ONE_PERSON_AND_THE_INTEREST_ADDS_UP = ''\nexport const MIGRATION_018_THE_ROTA_SKIPS_WHO_LEFT_AND_THE_SCREEN_SHOWS_WHO_WAITS = ''\nexport const MIGRATION_019_QUEM_AINDA_COMPRA_E_QUEM_SUMIU = ''\nexport const MIGRATION_020_O_STATUS_E_CONSEQUENCIA_DO_QUE_FOI_FEITO = ''\nexport const MIGRATION_021_O_AGENTE_MEXE_NO_CARD = ''\nexport const MIGRATION_022_A_LISTA_DO_FUNIL_PERGUNTA_POR_CIDADE = ''\nexport const MIGRATION_023_O_CONTATO_DIZ_DE_QUE_EMPRESA_ELE_E = ''\nexport const MIGRATION_024_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E = ''\nexport const MIGRATION_025_O_CARD_DIZ_QUEM_E_O_VENDEDOR = ''\nexport const MIGRATION_026_A_LEITURA_DO_FUNIL_SAI_DO_LACO = ''\nexport const MIGRATION_027_A_NOTA_DO_NEGOCIO_CHEGA_NA_BUSCA = ''\nexport const MIGRATION_028_O_LEAD_DIZ_QUANTO_VALE_E_POR_QUE = ''\nexport const MIGRATION_029_A_PORTA_DE_SERVICO_FECHA_ATRAS_DE_QUEM_ENTROU_DEPOIS = ''\nexport const MIGRATION_030_A_LISTA_DE_ORCAMENTOS_NAO_VARRE_O_HISTORICO = ''\nexport const MIGRATION_031_O_NOME_DO_CONTATO_ENTRA_NO_CARD = ''\nexport const MIGRATION_032_O_PAINEL_DE_VENDAS_CONTA_NO_BANCO = ''\nexport const MIGRATION_033_O_ENGAJAMENTO_NAO_SOMA_OS_PEDIDOS_DA_PLATAFORMA = ''\nexport const MIGRATION_034_O_GRAFICO_DO_FUNIL_CONTA_A_ETAPA_INTEIRA = ''\nexport const MIGRATION_035_QUEM_ESTA_NO_FUNIL_E_UM_LEAD = ''\nexport const MIGRATION_036_O_FUNIL_DO_V1_ENTRA_NO_LUGAR_DO_FUNIL_DE_FABRICA = ''\nexport const MIGRATION_037_O_NEGOCIO_E_O_ORCAMENTO_ATRAVESSAM_O_HISTORICO_FICA = ''\nexport const MIGRATION_038_CANAL_ORIGEM_E_CAMPANHA_SAO_TRES_PERGUNTAS = ''\nexport const MIGRATION_039_A_BANDEIRA_AGRUPA_O_QUE_A_RAIZ_DO_CNPJ_NAO_VE = ''\nexport const MIGRATION_040_O_CARD_DO_FUNIL_NAO_LE_A_AGENDA_INTEIRA = ''\nexport const MIGRATION_041_O_NOME_NO_CARD_E_DO_NEGOCIO_NAO_DA_AGENDA = ''\nexport const MIGRATION_042_A_ATIVIDADE_DIZ_QUEM_A_FEZ = ''\nexport const MIGRATION_043_A_CADENCIA_PARA_DE_ESPERAR_UM_FATO_QUE_NUNCA_CHEGA = ''\nexport const MIGRATION_044_O_STATUS_NAO_E_UM_ACONTECIMENTO = ''\nexport const MIGRATION_045_CONTATO_FEITO_E_CONTATO_QUE_ALGUEM_FEZ = ''\nexport const MIGRATION_046_A_PASTILHA_DO_CARD_SO_FALA_QUANDO_TEM_O_QUE_DIZER = ''\nexport const MIGRATION_047_O_DONO_DO_LEAD_TEM_UM_LUGAR_SO = ''\nexport const MIGRATION_048_A_EMPRESA_TAMBEM_TEM_UM_ARROBA = ''\nexport const MIGRATION_049_O_ARROBA_CHEGA_ATE_A_LISTA = ''\nexport const MIGRATION_050_A_REUNIAO_E_UMA_ESPECIE_DECLARADA = ''\nexport const MIGRATION_051_O_CRACHA_E_O_TELEFONE_RECUSADO_APARECEM = ''\nexport const MIGRATION_052_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E = ''\nexport const MIGRATION_053_A_ATIVIDADE_DIZ_DE_QUEM_ELA_E = ''\nexport const MIGRATION_054_A_LISTA_DE_LEADS_PERGUNTA_POR_CIDADE = ''\nexport const MIGRATION_055_A_CESTA_DO_INTERESSE_TEM_ONDE_MORAR = ''\nexport const MIGRATION_056_O_INTERESSE_ENTRA_PELO_AGENDAMENTO = ''\nexport const MIGRATION_057_O_NEGOCIO_E_DO_GRUPO_NAO_DO_CNPJ = ''\nexport const MIGRATION_058_O_CARD_DIZ_O_NOME_DO_GRUPO = ''\nexport const MIGRATION_059_A_EMPRESA_MOSTRA_O_INSTAGRAM_QUE_ELA_GUARDA = ''\nexport const MIGRATION_060_O_FUNIL_SABE_DE_QUEM_ELE_E = ''\nexport const MIGRATION_061_A_CONVERSAO_RESPEITA_O_FILTRO_DO_QUADRO = ''\nexport const MIGRATION_062_THE_WHOLE_CRM_SAYS_WHICH_UNIT_IT_IS = ''\nexport const MIGRATION_063_THE_ROTA_ENGINE_IS_SERVER_ONLY = ''\nexport const MIGRATION_064_SEGMENTS_REACH_THE_DEAL = ''\nexport const MIGRATION_065_A_DEAL_HAS_CONTACT_ROUTES = ''\nexport const MIGRATION_066_A_DRAFT_SEGMENT_SHOWS_WHO_IT_REACHES = ''\nexport const MIGRATION_067_PARKED_STAGES_AND_HONEST_NUMBERS = ''\nexport const MIGRATION_068_A_PHONE_HAS_A_STATUS = ''\nexport const MIGRATIONS: Array<{ id: string; sql: string }> = []\n"]}
|
|
1
|
+
{"version":3,"sources":["../../node_modules/.cache/fayz-migration-stubs/main.ts"],"names":[],"mappings":";AAEO,IAAM,sBAAA,GAAyB;AAC/B,IAAM,yCAAA,GAA4C;AAClD,IAAM,+CAAA,GAAkD;AACxD,IAAM,oDAAA,GAAuD;AAC7D,IAAM,8CAAA,GAAiD;AACvD,IAAM,iDAAA,GAAoD;AAC1D,IAAM,wCAAA,GAA2C;AACjD,IAAM,uCAAA,GAA0C;AAChD,IAAM,qCAAA,GAAwC;AAC9C,IAAM,sCAAA,GAAyC;AAC/C,IAAM,qCAAA,GAAwC;AAC9C,IAAM,wCAAA,GAA2C;AACjD,IAAM,0CAAA,GAA6C;AACnD,IAAM,gDAAA,GAAmD;AACzD,IAAM,iDAAA,GAAoD;AAC1D,IAAM,kDAAA,GAAqD;AAC3D,IAAM,2DAAA,GAA8D;AACpE,IAAM,oEAAA,GAAuE;AAC7E,IAAM,4CAAA,GAA+C;AACrD,IAAM,sDAAA,GAAyD;AAC/D,IAAM,mCAAA,GAAsC;AAC5C,IAAM,kDAAA,GAAqD;AAC3D,IAAM,gDAAA,GAAmD;AACzD,IAAM,6CAAA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A,GAA+C;AACrD,IAAM,aAAiD","file":"main.browser.js","sourcesContent":["// GENERATED by scripts/tsup-migrations.mjs — the browser build of a\n// migrations barrel: the same names, no SQL. See that script for why.\nexport const MIGRATION_000_BASELINE = ''\nexport const MIGRATION_001_DE_ONDE_VEIO_E_QUEM_INDICOU = ''\nexport const MIGRATION_002_A_PERGUNTA_QUE_O_CLIENTE_RESPONDE = ''\nexport const MIGRATION_003_O_CLIENTE_RESPONDE_NO_PROPRIO_TELEFONE = ''\nexport const MIGRATION_004_UM_RECORTE_DE_GENTE_QUE_TEM_NOME = ''\nexport const MIGRATION_005_A_ETAPA_GANHA_UM_CODIGO_E_UM_COMECO = ''\nexport const MIGRATION_006_A_ESCADA_DO_RELACIONAMENTO = ''\nexport const MIGRATION_008_A_REGUA_DA_REDE_E_PUBLICA = ''\nexport const MIGRATION_009_THE_LEAD_OFFER_CASCADES = ''\nexport const MIGRATION_010_THE_BOARD_HEARS_THE_DEAL = ''\nexport const MIGRATION_011_A_FUNNEL_IS_BORN_USABLE = ''\nexport const MIGRATION_012_THE_CRM_SAYS_WHAT_HAPPENED = ''\nexport const MIGRATION_013_THE_COMPANY_HOLDS_ITS_PEOPLE = ''\nexport const MIGRATION_014_THE_SECOND_FORM_IS_THE_SAME_PERSON = ''\nexport const MIGRATION_015_THE_FAMILY_OWNS_MORE_THAN_ONE_HOUSE = ''\nexport const MIGRATION_016_THE_STRANGER_ONLY_EDITS_WHAT_IT_MADE = ''\nexport const MIGRATION_017_TWO_FORMS_ONE_PERSON_AND_THE_INTEREST_ADDS_UP = ''\nexport const MIGRATION_018_THE_ROTA_SKIPS_WHO_LEFT_AND_THE_SCREEN_SHOWS_WHO_WAITS = ''\nexport const MIGRATION_019_QUEM_AINDA_COMPRA_E_QUEM_SUMIU = ''\nexport const MIGRATION_020_O_STATUS_E_CONSEQUENCIA_DO_QUE_FOI_FEITO = ''\nexport const MIGRATION_021_O_AGENTE_MEXE_NO_CARD = ''\nexport const MIGRATION_022_A_LISTA_DO_FUNIL_PERGUNTA_POR_CIDADE = ''\nexport const MIGRATION_023_O_CONTATO_DIZ_DE_QUE_EMPRESA_ELE_E = ''\nexport const MIGRATION_024_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E = ''\nexport const MIGRATION_025_O_CARD_DIZ_QUEM_E_O_VENDEDOR = ''\nexport const MIGRATION_026_A_LEITURA_DO_FUNIL_SAI_DO_LACO = ''\nexport const MIGRATION_027_A_NOTA_DO_NEGOCIO_CHEGA_NA_BUSCA = ''\nexport const MIGRATION_028_O_LEAD_DIZ_QUANTO_VALE_E_POR_QUE = ''\nexport const MIGRATION_029_A_PORTA_DE_SERVICO_FECHA_ATRAS_DE_QUEM_ENTROU_DEPOIS = ''\nexport const MIGRATION_030_A_LISTA_DE_ORCAMENTOS_NAO_VARRE_O_HISTORICO = ''\nexport const MIGRATION_031_O_NOME_DO_CONTATO_ENTRA_NO_CARD = ''\nexport const MIGRATION_032_O_PAINEL_DE_VENDAS_CONTA_NO_BANCO = ''\nexport const MIGRATION_033_O_ENGAJAMENTO_NAO_SOMA_OS_PEDIDOS_DA_PLATAFORMA = ''\nexport const MIGRATION_034_O_GRAFICO_DO_FUNIL_CONTA_A_ETAPA_INTEIRA = ''\nexport const MIGRATION_035_QUEM_ESTA_NO_FUNIL_E_UM_LEAD = ''\nexport const MIGRATION_036_O_FUNIL_DO_V1_ENTRA_NO_LUGAR_DO_FUNIL_DE_FABRICA = ''\nexport const MIGRATION_037_O_NEGOCIO_E_O_ORCAMENTO_ATRAVESSAM_O_HISTORICO_FICA = ''\nexport const MIGRATION_038_CANAL_ORIGEM_E_CAMPANHA_SAO_TRES_PERGUNTAS = ''\nexport const MIGRATION_039_A_BANDEIRA_AGRUPA_O_QUE_A_RAIZ_DO_CNPJ_NAO_VE = ''\nexport const MIGRATION_040_O_CARD_DO_FUNIL_NAO_LE_A_AGENDA_INTEIRA = ''\nexport const MIGRATION_041_O_NOME_NO_CARD_E_DO_NEGOCIO_NAO_DA_AGENDA = ''\nexport const MIGRATION_042_A_ATIVIDADE_DIZ_QUEM_A_FEZ = ''\nexport const MIGRATION_043_A_CADENCIA_PARA_DE_ESPERAR_UM_FATO_QUE_NUNCA_CHEGA = ''\nexport const MIGRATION_044_O_STATUS_NAO_E_UM_ACONTECIMENTO = ''\nexport const MIGRATION_045_CONTATO_FEITO_E_CONTATO_QUE_ALGUEM_FEZ = ''\nexport const MIGRATION_046_A_PASTILHA_DO_CARD_SO_FALA_QUANDO_TEM_O_QUE_DIZER = ''\nexport const MIGRATION_047_O_DONO_DO_LEAD_TEM_UM_LUGAR_SO = ''\nexport const MIGRATION_048_A_EMPRESA_TAMBEM_TEM_UM_ARROBA = ''\nexport const MIGRATION_049_O_ARROBA_CHEGA_ATE_A_LISTA = ''\nexport const MIGRATION_050_A_REUNIAO_E_UMA_ESPECIE_DECLARADA = ''\nexport const MIGRATION_051_O_CRACHA_E_O_TELEFONE_RECUSADO_APARECEM = ''\nexport const MIGRATION_052_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E = ''\nexport const MIGRATION_053_A_ATIVIDADE_DIZ_DE_QUEM_ELA_E = ''\nexport const MIGRATION_054_A_LISTA_DE_LEADS_PERGUNTA_POR_CIDADE = ''\nexport const MIGRATION_055_A_CESTA_DO_INTERESSE_TEM_ONDE_MORAR = ''\nexport const MIGRATION_056_O_INTERESSE_ENTRA_PELO_AGENDAMENTO = ''\nexport const MIGRATION_057_O_NEGOCIO_E_DO_GRUPO_NAO_DO_CNPJ = ''\nexport const MIGRATION_058_O_CARD_DIZ_O_NOME_DO_GRUPO = ''\nexport const MIGRATION_059_A_EMPRESA_MOSTRA_O_INSTAGRAM_QUE_ELA_GUARDA = ''\nexport const MIGRATION_060_O_FUNIL_SABE_DE_QUEM_ELE_E = ''\nexport const MIGRATION_061_A_CONVERSAO_RESPEITA_O_FILTRO_DO_QUADRO = ''\nexport const MIGRATION_062_THE_WHOLE_CRM_SAYS_WHICH_UNIT_IT_IS = ''\nexport const MIGRATION_063_THE_ROTA_ENGINE_IS_SERVER_ONLY = ''\nexport const MIGRATION_064_SEGMENTS_REACH_THE_DEAL = ''\nexport const MIGRATION_065_A_DEAL_HAS_CONTACT_ROUTES = ''\nexport const MIGRATION_066_A_DRAFT_SEGMENT_SHOWS_WHO_IT_REACHES = ''\nexport const MIGRATION_067_PARKED_STAGES_AND_HONEST_NUMBERS = ''\nexport const MIGRATION_068_A_PHONE_HAS_A_STATUS = ''\nexport const MIGRATION_069_EVERY_ACTION_IS_ON_THE_TIMELINE = ''\nexport const MIGRATION_070_A_DEAL_LIVES_IN_ITS_LEADS_UNIT = ''\nexport const MIGRATIONS: Array<{ id: string; sql: string }> = []\n"]}
|
package/dist/migrations/main.js
CHANGED
|
@@ -15183,6 +15183,272 @@ GRANT EXECUTE ON FUNCTION public.crm_deal_contact_routes(uuid) TO authenticated,
|
|
|
15183
15183
|
COMMENT ON FUNCTION public.crm_deal_contact_routes(uuid) IS
|
|
15184
15184
|
'Every way to reach a deal, best first (065): the contact, their other phones, the company''s people, the group''s people, then (068) the company phone and the Receita phones. Mobile: crm_phone_is_mobile(phone_e164); status: plg_crm_phone_status.';
|
|
15185
15185
|
`;
|
|
15186
|
+
var MIGRATION_069_EVERY_ACTION_IS_ON_THE_TIMELINE = `-- ============================================================================
|
|
15187
|
+
-- 069_every_action_is_on_the_timeline \u2014 the database writes the CRM's history,
|
|
15188
|
+
-- with who did it.
|
|
15189
|
+
--
|
|
15190
|
+
-- Julio created \xABKaryna Gon\xE7alves / Prime Interway\xBB on 10-28 and the card's
|
|
15191
|
+
-- timeline said "Nenhuma atividade ainda". The facts "lead created", "deal
|
|
15192
|
+
-- created" and "moved to <stage>" were written by the SCREEN after its save,
|
|
15193
|
+
-- best-effort, and swallowed when they failed; the database only logged leads
|
|
15194
|
+
-- that came from a public form. 333 of 375 leads had no "lead created", and
|
|
15195
|
+
-- none of the 229 stage changes said who moved the card.
|
|
15196
|
+
--
|
|
15197
|
+
-- One writer now, the database:
|
|
15198
|
+
--
|
|
15199
|
+
-- * every activity records its author: \`created_by\` defaults to
|
|
15200
|
+
-- \`auth.uid()\`, and \`created_by_name\` is filled from the team when absent;
|
|
15201
|
+
-- * a lead arriving (any source) logs \`lead_created\`, by whoever created it;
|
|
15202
|
+
-- * a deal inserted logs \`deal_created\`;
|
|
15203
|
+
-- * a deal changing stage logs \`stage_changed\` / \`deal_won\` / \`deal_lost\`
|
|
15204
|
+
-- with the stage's name;
|
|
15205
|
+
-- * a deal changing hands logs \`deal_assigned\` with the new owner's name.
|
|
15206
|
+
--
|
|
15207
|
+
-- The client stops writing the first three (same release). A tab still on the
|
|
15208
|
+
-- old bundle would write its copy too; the activities trigger drops that twin
|
|
15209
|
+
-- (a "created" fact exists once, a stage move once per 15 seconds).
|
|
15210
|
+
--
|
|
15211
|
+
-- History: leads and lead-born deals without their "created" fact get one,
|
|
15212
|
+
-- dated and signed from the record itself. Deals with no lead (the V1 sales
|
|
15213
|
+
-- imported as cards) are left alone.
|
|
15214
|
+
--
|
|
15215
|
+
-- Idempotent and replay-safe.
|
|
15216
|
+
-- ============================================================================
|
|
15217
|
+
|
|
15218
|
+
ALTER TABLE public.plg_crm_activities
|
|
15219
|
+
ALTER COLUMN created_by SET DEFAULT auth.uid();
|
|
15220
|
+
|
|
15221
|
+
CREATE OR REPLACE FUNCTION public.plg_crm_member_name(p_user uuid, p_tenant uuid)
|
|
15222
|
+
RETURNS text
|
|
15223
|
+
LANGUAGE sql
|
|
15224
|
+
STABLE
|
|
15225
|
+
SECURITY DEFINER
|
|
15226
|
+
SET search_path = ''
|
|
15227
|
+
AS $$
|
|
15228
|
+
SELECT p.name
|
|
15229
|
+
FROM public.v_team_members m
|
|
15230
|
+
JOIN public.people p ON p.id = m.person_id
|
|
15231
|
+
WHERE p_user IS NOT NULL AND m.user_id = p_user AND m.tenant_id = p_tenant
|
|
15232
|
+
LIMIT 1
|
|
15233
|
+
$$;
|
|
15234
|
+
|
|
15235
|
+
REVOKE ALL ON FUNCTION public.plg_crm_member_name(uuid, uuid) FROM PUBLIC;
|
|
15236
|
+
GRANT EXECUTE ON FUNCTION public.plg_crm_member_name(uuid, uuid) TO authenticated, service_role;
|
|
15237
|
+
|
|
15238
|
+
CREATE OR REPLACE FUNCTION public.plg_crm_activity_names_its_author()
|
|
15239
|
+
RETURNS trigger
|
|
15240
|
+
LANGUAGE plpgsql
|
|
15241
|
+
SECURITY DEFINER
|
|
15242
|
+
SET search_path = ''
|
|
15243
|
+
AS $$
|
|
15244
|
+
BEGIN
|
|
15245
|
+
-- A tab on the old bundle still writes its own copy of what the triggers
|
|
15246
|
+
-- below now write. The twin is dropped: a "created" fact exists once, a
|
|
15247
|
+
-- stage move once per 15 seconds.
|
|
15248
|
+
IF NEW.activity_type IN ('lead_created', 'deal_created') AND EXISTS (
|
|
15249
|
+
SELECT 1 FROM public.plg_crm_activities a
|
|
15250
|
+
WHERE a.activity_type = NEW.activity_type
|
|
15251
|
+
AND ((NEW.activity_type = 'lead_created' AND a.lead_id = NEW.lead_id AND a.deal_id IS NULL)
|
|
15252
|
+
OR (NEW.activity_type = 'deal_created' AND a.deal_id = NEW.deal_id))) THEN
|
|
15253
|
+
RETURN NULL;
|
|
15254
|
+
END IF;
|
|
15255
|
+
IF NEW.activity_type IN ('stage_changed', 'deal_won', 'deal_lost') AND NEW.deal_id IS NOT NULL AND EXISTS (
|
|
15256
|
+
SELECT 1 FROM public.plg_crm_activities a
|
|
15257
|
+
WHERE a.deal_id = NEW.deal_id AND a.activity_type = NEW.activity_type
|
|
15258
|
+
AND a.description IS NOT DISTINCT FROM NEW.description
|
|
15259
|
+
AND a.created_at > now() - interval '15 seconds') THEN
|
|
15260
|
+
RETURN NULL;
|
|
15261
|
+
END IF;
|
|
15262
|
+
IF NEW.created_by IS NOT NULL AND (NEW.created_by_name IS NULL OR btrim(NEW.created_by_name) = '') THEN
|
|
15263
|
+
NEW.created_by_name := public.plg_crm_member_name(NEW.created_by, NEW.tenant_id);
|
|
15264
|
+
END IF;
|
|
15265
|
+
RETURN NEW;
|
|
15266
|
+
END;
|
|
15267
|
+
$$;
|
|
15268
|
+
|
|
15269
|
+
DROP TRIGGER IF EXISTS plg_crm_activity_names_its_author ON public.plg_crm_activities;
|
|
15270
|
+
CREATE TRIGGER plg_crm_activity_names_its_author
|
|
15271
|
+
BEFORE INSERT ON public.plg_crm_activities
|
|
15272
|
+
FOR EACH ROW EXECUTE FUNCTION public.plg_crm_activity_names_its_author();
|
|
15273
|
+
|
|
15274
|
+
-- A lead arriving, from any source (it used to be public forms only).
|
|
15275
|
+
CREATE OR REPLACE FUNCTION public.crm_log_public_lead_activity(p_lead_id uuid, p_deal_id uuid)
|
|
15276
|
+
RETURNS void
|
|
15277
|
+
LANGUAGE plpgsql
|
|
15278
|
+
SECURITY DEFINER
|
|
15279
|
+
SET search_path TO 'public'
|
|
15280
|
+
AS $function$
|
|
15281
|
+
DECLARE
|
|
15282
|
+
v_lead public.people%ROWTYPE;
|
|
15283
|
+
v_deal_id uuid := p_deal_id;
|
|
15284
|
+
BEGIN
|
|
15285
|
+
SELECT * INTO v_lead FROM public.people WHERE id = p_lead_id;
|
|
15286
|
+
IF NOT FOUND OR v_lead.kind <> 'lead' THEN RETURN; END IF;
|
|
15287
|
+
|
|
15288
|
+
IF v_deal_id IS NULL THEN
|
|
15289
|
+
SELECT order_id INTO v_deal_id
|
|
15290
|
+
FROM public.plg_crm_deal_extensions WHERE lead_id = v_lead.id;
|
|
15291
|
+
END IF;
|
|
15292
|
+
|
|
15293
|
+
INSERT INTO public.plg_crm_activities
|
|
15294
|
+
(tenant_id, unit_id, lead_id, contact_name, activity_type, title, description, completed_at, created_at, created_by)
|
|
15295
|
+
SELECT
|
|
15296
|
+
v_lead.tenant_id, v_lead.unit_id, v_lead.id, v_lead.name, 'lead_created', v_lead.name,
|
|
15297
|
+
NULLIF(v_lead.metadata->>'sourceName', ''),
|
|
15298
|
+
v_lead.created_at, v_lead.created_at, v_lead.created_by
|
|
15299
|
+
WHERE NOT EXISTS (
|
|
15300
|
+
SELECT 1 FROM public.plg_crm_activities a
|
|
15301
|
+
WHERE a.lead_id = v_lead.id AND a.activity_type = 'lead_created'
|
|
15302
|
+
);
|
|
15303
|
+
|
|
15304
|
+
IF v_deal_id IS NOT NULL THEN
|
|
15305
|
+
INSERT INTO public.plg_crm_activities
|
|
15306
|
+
(tenant_id, unit_id, deal_id, lead_id, contact_name, activity_type, title, completed_at, created_at, created_by)
|
|
15307
|
+
SELECT
|
|
15308
|
+
v_lead.tenant_id, v_lead.unit_id, v_deal_id, v_lead.id, v_lead.name, 'deal_created', v_lead.name,
|
|
15309
|
+
v_lead.created_at, v_lead.created_at, v_lead.created_by
|
|
15310
|
+
WHERE NOT EXISTS (
|
|
15311
|
+
SELECT 1 FROM public.plg_crm_activities a
|
|
15312
|
+
WHERE a.deal_id = v_deal_id AND a.activity_type = 'deal_created'
|
|
15313
|
+
);
|
|
15314
|
+
END IF;
|
|
15315
|
+
END;
|
|
15316
|
+
$function$;
|
|
15317
|
+
|
|
15318
|
+
CREATE OR REPLACE FUNCTION public.plg_crm_deal_on_the_timeline()
|
|
15319
|
+
RETURNS trigger
|
|
15320
|
+
LANGUAGE plpgsql
|
|
15321
|
+
SECURITY DEFINER
|
|
15322
|
+
SET search_path = ''
|
|
15323
|
+
AS $$
|
|
15324
|
+
DECLARE
|
|
15325
|
+
v_stage record;
|
|
15326
|
+
v_type text;
|
|
15327
|
+
v_who text;
|
|
15328
|
+
BEGIN
|
|
15329
|
+
-- Never let the history break the write it describes.
|
|
15330
|
+
BEGIN
|
|
15331
|
+
IF TG_OP = 'INSERT' THEN
|
|
15332
|
+
INSERT INTO public.plg_crm_activities
|
|
15333
|
+
(tenant_id, unit_id, deal_id, lead_id, contact_id, activity_type, title, completed_at, created_at, created_by)
|
|
15334
|
+
SELECT NEW.tenant_id, NEW.unit_id, NEW.id, NEW.lead_id, NEW.contact_id, 'deal_created',
|
|
15335
|
+
coalesce(nullif(NEW.title, ''), 'Neg\xF3cio'), NEW.created_at, NEW.created_at,
|
|
15336
|
+
coalesce(auth.uid(), NEW.owner_id)
|
|
15337
|
+
WHERE NOT EXISTS (SELECT 1 FROM public.plg_crm_activities a
|
|
15338
|
+
WHERE a.deal_id = NEW.id AND a.activity_type = 'deal_created');
|
|
15339
|
+
RETURN NULL;
|
|
15340
|
+
END IF;
|
|
15341
|
+
|
|
15342
|
+
IF NEW.stage_id IS DISTINCT FROM OLD.stage_id AND NEW.stage_id IS NOT NULL THEN
|
|
15343
|
+
SELECT s.name, s.is_won, s.is_lost INTO v_stage
|
|
15344
|
+
FROM public.plg_crm_pipeline_stages s WHERE s.id = NEW.stage_id;
|
|
15345
|
+
v_type := CASE WHEN v_stage.is_won THEN 'deal_won' WHEN v_stage.is_lost THEN 'deal_lost' ELSE 'stage_changed' END;
|
|
15346
|
+
INSERT INTO public.plg_crm_activities
|
|
15347
|
+
(tenant_id, unit_id, deal_id, lead_id, contact_id, activity_type, title, description, completed_at, created_by)
|
|
15348
|
+
SELECT NEW.tenant_id, NEW.unit_id, NEW.id, NEW.lead_id, NEW.contact_id, v_type,
|
|
15349
|
+
coalesce(nullif(NEW.title, ''), 'Neg\xF3cio'), v_stage.name, now(), auth.uid();
|
|
15350
|
+
END IF;
|
|
15351
|
+
|
|
15352
|
+
IF NEW.assigned_to_id IS DISTINCT FROM OLD.assigned_to_id THEN
|
|
15353
|
+
v_who := public.plg_crm_member_name(NEW.assigned_to_id, NEW.tenant_id);
|
|
15354
|
+
INSERT INTO public.plg_crm_activities
|
|
15355
|
+
(tenant_id, unit_id, deal_id, lead_id, contact_id, activity_type, title, description, completed_at, created_by)
|
|
15356
|
+
VALUES (NEW.tenant_id, NEW.unit_id, NEW.id, NEW.lead_id, NEW.contact_id, 'deal_assigned',
|
|
15357
|
+
coalesce(nullif(NEW.title, ''), 'Neg\xF3cio'),
|
|
15358
|
+
CASE WHEN NEW.assigned_to_id IS NULL THEN 'Sem respons\xE1vel' ELSE 'Respons\xE1vel: ' || coalesce(v_who, 'outra pessoa') END,
|
|
15359
|
+
now(), auth.uid());
|
|
15360
|
+
END IF;
|
|
15361
|
+
EXCEPTION WHEN OTHERS THEN
|
|
15362
|
+
RAISE WARNING 'plg_crm_deal_on_the_timeline failed for deal %: %', NEW.id, SQLERRM;
|
|
15363
|
+
END;
|
|
15364
|
+
RETURN NULL;
|
|
15365
|
+
END;
|
|
15366
|
+
$$;
|
|
15367
|
+
|
|
15368
|
+
DROP TRIGGER IF EXISTS plg_crm_deal_on_the_timeline_insert ON public.plg_crm_deals;
|
|
15369
|
+
CREATE TRIGGER plg_crm_deal_on_the_timeline_insert
|
|
15370
|
+
AFTER INSERT ON public.plg_crm_deals
|
|
15371
|
+
FOR EACH ROW WHEN (NEW.lead_id IS NOT NULL OR NEW.pipeline_id IS NOT NULL)
|
|
15372
|
+
EXECUTE FUNCTION public.plg_crm_deal_on_the_timeline();
|
|
15373
|
+
|
|
15374
|
+
DROP TRIGGER IF EXISTS plg_crm_deal_on_the_timeline_update ON public.plg_crm_deals;
|
|
15375
|
+
CREATE TRIGGER plg_crm_deal_on_the_timeline_update
|
|
15376
|
+
AFTER UPDATE OF stage_id, assigned_to_id ON public.plg_crm_deals
|
|
15377
|
+
FOR EACH ROW EXECUTE FUNCTION public.plg_crm_deal_on_the_timeline();
|
|
15378
|
+
|
|
15379
|
+
-- History. Leads first, then the deals born from them.
|
|
15380
|
+
INSERT INTO public.plg_crm_activities
|
|
15381
|
+
(tenant_id, unit_id, lead_id, contact_name, activity_type, title, description, completed_at, created_at, created_by)
|
|
15382
|
+
SELECT p.tenant_id, p.unit_id, p.id, p.name, 'lead_created', p.name,
|
|
15383
|
+
NULLIF(p.metadata->>'sourceName', ''), p.created_at, p.created_at, p.created_by
|
|
15384
|
+
FROM public.people p
|
|
15385
|
+
WHERE p.kind = 'lead'
|
|
15386
|
+
AND NOT EXISTS (SELECT 1 FROM public.plg_crm_activities a
|
|
15387
|
+
WHERE a.lead_id = p.id AND a.activity_type = 'lead_created');
|
|
15388
|
+
|
|
15389
|
+
INSERT INTO public.plg_crm_activities
|
|
15390
|
+
(tenant_id, unit_id, deal_id, lead_id, contact_id, contact_name, activity_type, title, completed_at, created_at, created_by)
|
|
15391
|
+
SELECT d.tenant_id, d.unit_id, d.id, d.lead_id, d.contact_id, p.name, 'deal_created',
|
|
15392
|
+
coalesce(nullif(d.title, ''), p.name, 'Neg\xF3cio'), d.created_at, d.created_at,
|
|
15393
|
+
coalesce(p.created_by, d.owner_id)
|
|
15394
|
+
FROM public.plg_crm_deals d
|
|
15395
|
+
LEFT JOIN public.people p ON p.id = d.lead_id
|
|
15396
|
+
WHERE d.lead_id IS NOT NULL
|
|
15397
|
+
AND NOT EXISTS (SELECT 1 FROM public.plg_crm_activities a
|
|
15398
|
+
WHERE a.deal_id = d.id AND a.activity_type = 'deal_created');
|
|
15399
|
+
|
|
15400
|
+
-- The author's name on what history now carries an author for.
|
|
15401
|
+
UPDATE public.plg_crm_activities a
|
|
15402
|
+
SET created_by_name = public.plg_crm_member_name(a.created_by, a.tenant_id)
|
|
15403
|
+
WHERE a.created_by IS NOT NULL AND (a.created_by_name IS NULL OR btrim(a.created_by_name) = '')
|
|
15404
|
+
AND a.activity_type IN ('lead_created', 'deal_created');
|
|
15405
|
+
`;
|
|
15406
|
+
var MIGRATION_070_A_DEAL_LIVES_IN_ITS_LEADS_UNIT = `-- ============================================================================
|
|
15407
|
+
-- 070_a_deal_lives_in_its_leads_unit \u2014 a deal without a unit takes its lead's.
|
|
15408
|
+
--
|
|
15409
|
+
-- \xABKaryna Gon\xE7alves / Prime Interway\xBB was created with no unit while its lead
|
|
15410
|
+
-- and every activity on it were ChefControl's. A deal with no unit shows in
|
|
15411
|
+
-- every unit, its activities only in theirs: with BeautyControl selected the
|
|
15412
|
+
-- card opened and said "Nenhuma atividade ainda" over five activities (11-03).
|
|
15413
|
+
-- A deal now takes its lead's (or contact's) unit when it has none; the four
|
|
15414
|
+
-- deals in that state are corrected.
|
|
15415
|
+
--
|
|
15416
|
+
-- Idempotent and replay-safe.
|
|
15417
|
+
-- ============================================================================
|
|
15418
|
+
|
|
15419
|
+
CREATE OR REPLACE FUNCTION public.plg_crm_deal_takes_its_leads_unit()
|
|
15420
|
+
RETURNS trigger
|
|
15421
|
+
LANGUAGE plpgsql
|
|
15422
|
+
SECURITY DEFINER
|
|
15423
|
+
SET search_path = ''
|
|
15424
|
+
AS $$
|
|
15425
|
+
BEGIN
|
|
15426
|
+
IF NEW.unit_id IS NULL AND coalesce(NEW.lead_id, NEW.contact_id) IS NOT NULL THEN
|
|
15427
|
+
SELECT p.unit_id INTO NEW.unit_id
|
|
15428
|
+
FROM public.people p
|
|
15429
|
+
WHERE p.id = coalesce(NEW.lead_id, NEW.contact_id) AND p.tenant_id = NEW.tenant_id;
|
|
15430
|
+
END IF;
|
|
15431
|
+
RETURN NEW;
|
|
15432
|
+
END;
|
|
15433
|
+
$$;
|
|
15434
|
+
|
|
15435
|
+
DROP TRIGGER IF EXISTS plg_crm_deal_takes_its_leads_unit ON public.plg_crm_deals;
|
|
15436
|
+
CREATE TRIGGER plg_crm_deal_takes_its_leads_unit
|
|
15437
|
+
BEFORE INSERT OR UPDATE OF lead_id, contact_id ON public.plg_crm_deals
|
|
15438
|
+
FOR EACH ROW EXECUTE FUNCTION public.plg_crm_deal_takes_its_leads_unit();
|
|
15439
|
+
|
|
15440
|
+
UPDATE public.plg_crm_deals d
|
|
15441
|
+
SET unit_id = p.unit_id
|
|
15442
|
+
FROM public.people p
|
|
15443
|
+
WHERE d.unit_id IS NULL AND p.id = coalesce(d.lead_id, d.contact_id)
|
|
15444
|
+
AND p.tenant_id = d.tenant_id AND p.unit_id IS NOT NULL;
|
|
15445
|
+
|
|
15446
|
+
-- The facts 069 wrote for those deals carry the unit too.
|
|
15447
|
+
UPDATE public.plg_crm_activities a
|
|
15448
|
+
SET unit_id = d.unit_id
|
|
15449
|
+
FROM public.plg_crm_deals d
|
|
15450
|
+
WHERE a.unit_id IS NULL AND a.deal_id = d.id AND d.unit_id IS NOT NULL;
|
|
15451
|
+
`;
|
|
15186
15452
|
var MIGRATIONS = [
|
|
15187
15453
|
{ id: "000_baseline", sql: MIGRATION_000_BASELINE },
|
|
15188
15454
|
{ id: "001_de_onde_veio_e_quem_indicou", sql: MIGRATION_001_DE_ONDE_VEIO_E_QUEM_INDICOU },
|
|
@@ -15251,9 +15517,11 @@ var MIGRATIONS = [
|
|
|
15251
15517
|
{ id: "065_a_deal_has_contact_routes", sql: MIGRATION_065_A_DEAL_HAS_CONTACT_ROUTES },
|
|
15252
15518
|
{ id: "066_a_draft_segment_shows_who_it_reaches", sql: MIGRATION_066_A_DRAFT_SEGMENT_SHOWS_WHO_IT_REACHES },
|
|
15253
15519
|
{ id: "067_parked_stages_and_honest_numbers", sql: MIGRATION_067_PARKED_STAGES_AND_HONEST_NUMBERS },
|
|
15254
|
-
{ id: "068_a_phone_has_a_status", sql: MIGRATION_068_A_PHONE_HAS_A_STATUS }
|
|
15520
|
+
{ id: "068_a_phone_has_a_status", sql: MIGRATION_068_A_PHONE_HAS_A_STATUS },
|
|
15521
|
+
{ id: "069_every_action_is_on_the_timeline", sql: MIGRATION_069_EVERY_ACTION_IS_ON_THE_TIMELINE },
|
|
15522
|
+
{ id: "070_a_deal_lives_in_its_leads_unit", sql: MIGRATION_070_A_DEAL_LIVES_IN_ITS_LEADS_UNIT }
|
|
15255
15523
|
];
|
|
15256
15524
|
|
|
15257
|
-
export { MIGRATIONS, MIGRATION_000_BASELINE, MIGRATION_001_DE_ONDE_VEIO_E_QUEM_INDICOU, MIGRATION_002_A_PERGUNTA_QUE_O_CLIENTE_RESPONDE, MIGRATION_003_O_CLIENTE_RESPONDE_NO_PROPRIO_TELEFONE, MIGRATION_004_UM_RECORTE_DE_GENTE_QUE_TEM_NOME, MIGRATION_005_A_ETAPA_GANHA_UM_CODIGO_E_UM_COMECO, MIGRATION_006_A_ESCADA_DO_RELACIONAMENTO, MIGRATION_008_A_REGUA_DA_REDE_E_PUBLICA, MIGRATION_009_THE_LEAD_OFFER_CASCADES, MIGRATION_010_THE_BOARD_HEARS_THE_DEAL, MIGRATION_011_A_FUNNEL_IS_BORN_USABLE, MIGRATION_012_THE_CRM_SAYS_WHAT_HAPPENED, MIGRATION_013_THE_COMPANY_HOLDS_ITS_PEOPLE, MIGRATION_014_THE_SECOND_FORM_IS_THE_SAME_PERSON, MIGRATION_015_THE_FAMILY_OWNS_MORE_THAN_ONE_HOUSE, MIGRATION_016_THE_STRANGER_ONLY_EDITS_WHAT_IT_MADE, MIGRATION_017_TWO_FORMS_ONE_PERSON_AND_THE_INTEREST_ADDS_UP, MIGRATION_018_THE_ROTA_SKIPS_WHO_LEFT_AND_THE_SCREEN_SHOWS_WHO_WAITS, MIGRATION_019_QUEM_AINDA_COMPRA_E_QUEM_SUMIU, MIGRATION_020_O_STATUS_E_CONSEQUENCIA_DO_QUE_FOI_FEITO, MIGRATION_021_O_AGENTE_MEXE_NO_CARD, MIGRATION_022_A_LISTA_DO_FUNIL_PERGUNTA_POR_CIDADE, MIGRATION_023_O_CONTATO_DIZ_DE_QUE_EMPRESA_ELE_E, MIGRATION_024_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E, MIGRATION_025_O_CARD_DIZ_QUEM_E_O_VENDEDOR, MIGRATION_026_A_LEITURA_DO_FUNIL_SAI_DO_LACO, MIGRATION_027_A_NOTA_DO_NEGOCIO_CHEGA_NA_BUSCA, MIGRATION_028_O_LEAD_DIZ_QUANTO_VALE_E_POR_QUE, MIGRATION_029_A_PORTA_DE_SERVICO_FECHA_ATRAS_DE_QUEM_ENTROU_DEPOIS, MIGRATION_030_A_LISTA_DE_ORCAMENTOS_NAO_VARRE_O_HISTORICO, MIGRATION_031_O_NOME_DO_CONTATO_ENTRA_NO_CARD, MIGRATION_032_O_PAINEL_DE_VENDAS_CONTA_NO_BANCO, MIGRATION_033_O_ENGAJAMENTO_NAO_SOMA_OS_PEDIDOS_DA_PLATAFORMA, MIGRATION_034_O_GRAFICO_DO_FUNIL_CONTA_A_ETAPA_INTEIRA, MIGRATION_035_QUEM_ESTA_NO_FUNIL_E_UM_LEAD, MIGRATION_036_O_FUNIL_DO_V1_ENTRA_NO_LUGAR_DO_FUNIL_DE_FABRICA, MIGRATION_037_O_NEGOCIO_E_O_ORCAMENTO_ATRAVESSAM_O_HISTORICO_FICA, MIGRATION_038_CANAL_ORIGEM_E_CAMPANHA_SAO_TRES_PERGUNTAS, MIGRATION_039_A_BANDEIRA_AGRUPA_O_QUE_A_RAIZ_DO_CNPJ_NAO_VE, MIGRATION_040_O_CARD_DO_FUNIL_NAO_LE_A_AGENDA_INTEIRA, MIGRATION_041_O_NOME_NO_CARD_E_DO_NEGOCIO_NAO_DA_AGENDA, MIGRATION_042_A_ATIVIDADE_DIZ_QUEM_A_FEZ, MIGRATION_043_A_CADENCIA_PARA_DE_ESPERAR_UM_FATO_QUE_NUNCA_CHEGA, MIGRATION_044_O_STATUS_NAO_E_UM_ACONTECIMENTO, MIGRATION_045_CONTATO_FEITO_E_CONTATO_QUE_ALGUEM_FEZ, MIGRATION_046_A_PASTILHA_DO_CARD_SO_FALA_QUANDO_TEM_O_QUE_DIZER, MIGRATION_047_O_DONO_DO_LEAD_TEM_UM_LUGAR_SO, MIGRATION_048_A_EMPRESA_TAMBEM_TEM_UM_ARROBA, MIGRATION_049_O_ARROBA_CHEGA_ATE_A_LISTA, MIGRATION_050_A_REUNIAO_E_UMA_ESPECIE_DECLARADA, MIGRATION_051_O_CRACHA_E_O_TELEFONE_RECUSADO_APARECEM, MIGRATION_052_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E, MIGRATION_053_A_ATIVIDADE_DIZ_DE_QUEM_ELA_E, MIGRATION_054_A_LISTA_DE_LEADS_PERGUNTA_POR_CIDADE, MIGRATION_055_A_CESTA_DO_INTERESSE_TEM_ONDE_MORAR, MIGRATION_056_O_INTERESSE_ENTRA_PELO_AGENDAMENTO, MIGRATION_057_O_NEGOCIO_E_DO_GRUPO_NAO_DO_CNPJ, MIGRATION_058_O_CARD_DIZ_O_NOME_DO_GRUPO, MIGRATION_059_A_EMPRESA_MOSTRA_O_INSTAGRAM_QUE_ELA_GUARDA, MIGRATION_060_O_FUNIL_SABE_DE_QUEM_ELE_E, MIGRATION_061_A_CONVERSAO_RESPEITA_O_FILTRO_DO_QUADRO, MIGRATION_062_THE_WHOLE_CRM_SAYS_WHICH_UNIT_IT_IS, MIGRATION_063_THE_ROTA_ENGINE_IS_SERVER_ONLY, MIGRATION_064_SEGMENTS_REACH_THE_DEAL, MIGRATION_065_A_DEAL_HAS_CONTACT_ROUTES, MIGRATION_066_A_DRAFT_SEGMENT_SHOWS_WHO_IT_REACHES, MIGRATION_067_PARKED_STAGES_AND_HONEST_NUMBERS, MIGRATION_068_A_PHONE_HAS_A_STATUS };
|
|
15525
|
+
export { MIGRATIONS, MIGRATION_000_BASELINE, MIGRATION_001_DE_ONDE_VEIO_E_QUEM_INDICOU, MIGRATION_002_A_PERGUNTA_QUE_O_CLIENTE_RESPONDE, MIGRATION_003_O_CLIENTE_RESPONDE_NO_PROPRIO_TELEFONE, MIGRATION_004_UM_RECORTE_DE_GENTE_QUE_TEM_NOME, MIGRATION_005_A_ETAPA_GANHA_UM_CODIGO_E_UM_COMECO, MIGRATION_006_A_ESCADA_DO_RELACIONAMENTO, MIGRATION_008_A_REGUA_DA_REDE_E_PUBLICA, MIGRATION_009_THE_LEAD_OFFER_CASCADES, MIGRATION_010_THE_BOARD_HEARS_THE_DEAL, MIGRATION_011_A_FUNNEL_IS_BORN_USABLE, MIGRATION_012_THE_CRM_SAYS_WHAT_HAPPENED, MIGRATION_013_THE_COMPANY_HOLDS_ITS_PEOPLE, MIGRATION_014_THE_SECOND_FORM_IS_THE_SAME_PERSON, MIGRATION_015_THE_FAMILY_OWNS_MORE_THAN_ONE_HOUSE, MIGRATION_016_THE_STRANGER_ONLY_EDITS_WHAT_IT_MADE, MIGRATION_017_TWO_FORMS_ONE_PERSON_AND_THE_INTEREST_ADDS_UP, MIGRATION_018_THE_ROTA_SKIPS_WHO_LEFT_AND_THE_SCREEN_SHOWS_WHO_WAITS, MIGRATION_019_QUEM_AINDA_COMPRA_E_QUEM_SUMIU, MIGRATION_020_O_STATUS_E_CONSEQUENCIA_DO_QUE_FOI_FEITO, MIGRATION_021_O_AGENTE_MEXE_NO_CARD, MIGRATION_022_A_LISTA_DO_FUNIL_PERGUNTA_POR_CIDADE, MIGRATION_023_O_CONTATO_DIZ_DE_QUE_EMPRESA_ELE_E, MIGRATION_024_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E, MIGRATION_025_O_CARD_DIZ_QUEM_E_O_VENDEDOR, MIGRATION_026_A_LEITURA_DO_FUNIL_SAI_DO_LACO, MIGRATION_027_A_NOTA_DO_NEGOCIO_CHEGA_NA_BUSCA, MIGRATION_028_O_LEAD_DIZ_QUANTO_VALE_E_POR_QUE, MIGRATION_029_A_PORTA_DE_SERVICO_FECHA_ATRAS_DE_QUEM_ENTROU_DEPOIS, MIGRATION_030_A_LISTA_DE_ORCAMENTOS_NAO_VARRE_O_HISTORICO, MIGRATION_031_O_NOME_DO_CONTATO_ENTRA_NO_CARD, MIGRATION_032_O_PAINEL_DE_VENDAS_CONTA_NO_BANCO, MIGRATION_033_O_ENGAJAMENTO_NAO_SOMA_OS_PEDIDOS_DA_PLATAFORMA, MIGRATION_034_O_GRAFICO_DO_FUNIL_CONTA_A_ETAPA_INTEIRA, MIGRATION_035_QUEM_ESTA_NO_FUNIL_E_UM_LEAD, MIGRATION_036_O_FUNIL_DO_V1_ENTRA_NO_LUGAR_DO_FUNIL_DE_FABRICA, MIGRATION_037_O_NEGOCIO_E_O_ORCAMENTO_ATRAVESSAM_O_HISTORICO_FICA, MIGRATION_038_CANAL_ORIGEM_E_CAMPANHA_SAO_TRES_PERGUNTAS, MIGRATION_039_A_BANDEIRA_AGRUPA_O_QUE_A_RAIZ_DO_CNPJ_NAO_VE, MIGRATION_040_O_CARD_DO_FUNIL_NAO_LE_A_AGENDA_INTEIRA, MIGRATION_041_O_NOME_NO_CARD_E_DO_NEGOCIO_NAO_DA_AGENDA, MIGRATION_042_A_ATIVIDADE_DIZ_QUEM_A_FEZ, MIGRATION_043_A_CADENCIA_PARA_DE_ESPERAR_UM_FATO_QUE_NUNCA_CHEGA, MIGRATION_044_O_STATUS_NAO_E_UM_ACONTECIMENTO, MIGRATION_045_CONTATO_FEITO_E_CONTATO_QUE_ALGUEM_FEZ, MIGRATION_046_A_PASTILHA_DO_CARD_SO_FALA_QUANDO_TEM_O_QUE_DIZER, MIGRATION_047_O_DONO_DO_LEAD_TEM_UM_LUGAR_SO, MIGRATION_048_A_EMPRESA_TAMBEM_TEM_UM_ARROBA, MIGRATION_049_O_ARROBA_CHEGA_ATE_A_LISTA, MIGRATION_050_A_REUNIAO_E_UMA_ESPECIE_DECLARADA, MIGRATION_051_O_CRACHA_E_O_TELEFONE_RECUSADO_APARECEM, MIGRATION_052_O_NEGOCIO_DIZ_DE_QUE_CASA_ELE_E, MIGRATION_053_A_ATIVIDADE_DIZ_DE_QUEM_ELA_E, MIGRATION_054_A_LISTA_DE_LEADS_PERGUNTA_POR_CIDADE, MIGRATION_055_A_CESTA_DO_INTERESSE_TEM_ONDE_MORAR, MIGRATION_056_O_INTERESSE_ENTRA_PELO_AGENDAMENTO, MIGRATION_057_O_NEGOCIO_E_DO_GRUPO_NAO_DO_CNPJ, MIGRATION_058_O_CARD_DIZ_O_NOME_DO_GRUPO, MIGRATION_059_A_EMPRESA_MOSTRA_O_INSTAGRAM_QUE_ELA_GUARDA, MIGRATION_060_O_FUNIL_SABE_DE_QUEM_ELE_E, MIGRATION_061_A_CONVERSAO_RESPEITA_O_FILTRO_DO_QUADRO, MIGRATION_062_THE_WHOLE_CRM_SAYS_WHICH_UNIT_IT_IS, MIGRATION_063_THE_ROTA_ENGINE_IS_SERVER_ONLY, MIGRATION_064_SEGMENTS_REACH_THE_DEAL, MIGRATION_065_A_DEAL_HAS_CONTACT_ROUTES, MIGRATION_066_A_DRAFT_SEGMENT_SHOWS_WHO_IT_REACHES, MIGRATION_067_PARKED_STAGES_AND_HONEST_NUMBERS, MIGRATION_068_A_PHONE_HAS_A_STATUS, MIGRATION_069_EVERY_ACTION_IS_ON_THE_TIMELINE, MIGRATION_070_A_DEAL_LIVES_IN_ITS_LEADS_UNIT };
|
|
15258
15526
|
//# sourceMappingURL=main.js.map
|
|
15259
15527
|
//# sourceMappingURL=main.js.map
|