2024-10-16 12:15:14 +00:00
|
|
|
{% set id_deal_pipelines_excluded = "('15380854')" %}
|
2025-05-19 15:41:48 +00:00
|
|
|
{% set generic_account_manager_names = "('HOST SERVICES')" %}
|
|
|
|
|
{% set guardhog_customer_conversion_source = "('GUARDHOG CUSTOMER CONVERSION')" %}
|
2024-10-16 12:15:14 +00:00
|
|
|
|
|
|
|
|
with
|
|
|
|
|
stg_hubspot__deals as (select * from {{ ref("stg_hubspot__deals") }}),
|
2025-05-16 11:08:17 +00:00
|
|
|
stg_seed__hubspot_account_owner as (
|
|
|
|
|
select * from {{ ref("stg_seed__hubspot_account_owner") }}
|
|
|
|
|
),
|
2024-10-16 12:15:14 +00:00
|
|
|
stg_hubspot__deal_pipeline_stages as (
|
|
|
|
|
select * from {{ ref("stg_hubspot__deal_pipeline_stages") }}
|
|
|
|
|
),
|
|
|
|
|
stg_hubspot__deal_pipelines as (
|
|
|
|
|
select * from {{ ref("stg_hubspot__deal_pipelines") }}
|
|
|
|
|
)
|
|
|
|
|
select
|
|
|
|
|
d.id_deal,
|
|
|
|
|
d.deal_name,
|
|
|
|
|
d.contract_signed_date_utc,
|
|
|
|
|
d.onboarding_date_utc,
|
|
|
|
|
d.live_date_utc,
|
|
|
|
|
d.cancellation_date_utc,
|
|
|
|
|
d.account_manager,
|
2025-05-19 15:41:48 +00:00
|
|
|
-- Following logic discussed with Alex A. on 2025-05-19 to determine the
|
|
|
|
|
-- onboarding owner
|
2025-05-16 11:08:17 +00:00
|
|
|
case
|
2025-05-19 15:41:48 +00:00
|
|
|
-- 1. If the cloned onboarding owner is not null, use that. This should reflect
|
|
|
|
|
-- most of the cases.
|
|
|
|
|
when d.onboarding_owner__cloned_ is not null
|
|
|
|
|
then d.onboarding_owner__cloned_
|
|
|
|
|
-- 2. If the cloned onboarding owner is null and the onboarding owner is not
|
|
|
|
|
-- null, use the second. It should cover few exceptional cases.
|
|
|
|
|
when d.onboarding_owner__cloned_ is null and d.onboarding_owner is not null
|
|
|
|
|
then d.onboarding_owner
|
|
|
|
|
-- 3. If the deal is a conversion from Guardhog to Truvi, the onboarding owner
|
|
|
|
|
-- should always be the HubSpot account owner.
|
|
|
|
|
when upper(d.deal_source) in {{ guardhog_customer_conversion_source }}
|
|
|
|
|
then hao.hubspot_account_owner
|
|
|
|
|
-- 4. If the onboarding owner is null and the account manager is in the generic
|
|
|
|
|
-- account manager names, use the HubSpot account owner. This is because is
|
|
|
|
|
-- actually a Sales person that handles the onboarding.
|
2025-05-16 11:08:17 +00:00
|
|
|
when
|
2025-05-19 15:41:48 +00:00
|
|
|
d.onboarding_owner__cloned_ is null
|
|
|
|
|
and upper(d.account_manager) in {{ generic_account_manager_names }}
|
2025-05-16 11:08:17 +00:00
|
|
|
then hao.hubspot_account_owner
|
2025-05-19 15:41:48 +00:00
|
|
|
-- For all other cases, set the onboarding owner to null.
|
2025-05-16 11:08:17 +00:00
|
|
|
else null
|
|
|
|
|
end as onboarding_owner,
|
2024-10-16 12:15:14 +00:00
|
|
|
dp.deal_pipeline_name as deal_pipeline,
|
|
|
|
|
dps.stage_name as deal_hubspot_stage,
|
|
|
|
|
d.cancellation_category,
|
|
|
|
|
d.cancellation_details,
|
2024-12-17 09:02:11 +00:00
|
|
|
d.amount_of_properties,
|
2025-03-07 10:17:11 +01:00
|
|
|
d.last_contacted_date_utc,
|
|
|
|
|
d.amount_times_contacted,
|
2025-04-04 08:40:38 +00:00
|
|
|
d.integration_type,
|
2025-03-24 11:20:03 +00:00
|
|
|
d.dashboard_type,
|
|
|
|
|
d.pricing_structure,
|
|
|
|
|
d.partnership_services,
|
2025-05-16 11:08:17 +00:00
|
|
|
d.expressed_service_interest,
|
2024-10-16 12:15:14 +00:00
|
|
|
d.created_at_utc,
|
|
|
|
|
d.created_date_utc,
|
|
|
|
|
d.updated_at_utc,
|
|
|
|
|
d.updated_date_utc
|
|
|
|
|
from stg_hubspot__deals d
|
|
|
|
|
left join stg_hubspot__deal_pipeline_stages dps on d.id_deal_stage = dps.id_stage
|
|
|
|
|
left join stg_hubspot__deal_pipelines dp on dps.id_deal_pipeline = dp.id_deal_pipeline
|
2025-05-16 11:08:17 +00:00
|
|
|
left join
|
|
|
|
|
stg_seed__hubspot_account_owner hao
|
|
|
|
|
on d.id_hubspot_account_owner = hao.id_hubspot_account_owner
|
2024-10-16 12:15:14 +00:00
|
|
|
-- Exclude Guardhog pipelines
|
|
|
|
|
where dps.id_deal_pipeline not in {{ id_deal_pipelines_excluded }}
|