New model for guests satisfaction report

This commit is contained in:
Joaquin Ossa 2024-07-02 14:22:04 +02:00
parent f9741d6f69
commit 0cda63d1a7

View file

@ -0,0 +1,60 @@
with
int_core__verification_payments as (
select * from {{ ref("int_core__verification_payments") }}
),
stg_core__guest_satisfaction_responses as (
select * from {{ ref("stg_core__guest_satisfaction_responses") }}
),
stg_core__verification_request as (
select * from {{ ref("stg_core__verification_request") }}
),
stg_core__verification as (select * from {{ ref("stg_core__verification") }}),
stg_core__user as (select * from {{ ref("stg_core__user") }}),
-- Create columns for which services did the guest pay for
payment_types as (
select
id_verification_request,
max(
case when verification_payment_type = 'CheckInCover' then 1 else 0 end
)::boolean as checkincover,
max(
case when verification_payment_type = 'Deposit' then 1 else 0 end
)::boolean as deposit,
max(
case when verification_payment_type = 'Waiver' then 1 else 0 end
)::boolean as waiver,
max(case when verification_payment_type = 'Fee' then 1 else 0 end)::boolean
as fee
from int_core__verification_payments
group by id_verification_request
)
select
gss.id_verification_request,
u.id_user as guestsuperhoguserid,
-- not show email if the guest is not contactable
case when gss.is_contactable is true then u.email else '' end as guestemailaddress,
gss.experience_rating,
gss.guest_comments,
case when gss.is_contactable is true then true else false end as is_contactable,
gss.created_at_utc,
gss.updated_at_utc,
case
when v.verification_value is not null
then v.verification_value
else 'No Payment Validation Option'
end as selectedpaymentoption,
extract(year from age(u.date_of_birth)) as ageofguest,
case when pt.checkincover is true then true else false end as checkincover,
case when pt.waiver is true then true else false end as waiver,
case when pt.deposit is true then true else false end as deposit,
case when pt.fee is true then true else false end as fee
from staging.stg_core__guest_satisfaction_responses gss
left join
staging.stg_core__verification_request vr
on vr.id_verification_request = gss.id_verification_request
left join
staging.stg_core__verification v
on v.id_verification = gss.id_verification_request
and v.verification = 'PaymentValidation'
left join staging.stg_core__user u on u.id_user = vr.id_user_guest
left join payment_types pt on gss.id_verification_request = pt.id_verification_request