diff --git a/models/intermediate/core/int_core__verification_payments_v2.sql b/models/intermediate/core/int_core__verification_payments_v2.sql index 67406cf..183f01a 100644 --- a/models/intermediate/core/int_core__verification_payments_v2.sql +++ b/models/intermediate/core/int_core__verification_payments_v2.sql @@ -20,17 +20,24 @@ with stg_seed__guest_services_vat_rates_by_country as ( select * from {{ ref("stg_seed__guest_services_vat_rates_by_country") }} ), + int_core__payaway_per_month_user as ( + select * from {{ ref("int_core__payaway_per_month_user") }} + ), vat_details as ( select vtp.id_verification_to_payment, coalesce(vat.vat_rate, 0) as vat_rate, case - when vpt.verification_payment_type in {{ vat_applicable_services }} + when + vpt.verification_payment_type in {{ vat_applicable_services }} + and pamu.id_payaway_plan is null -- superhog takes waiver then true else false end as is_service_subject_to_vat, case - when vpt.verification_payment_type not in {{ vat_applicable_services }} + when + vpt.verification_payment_type not in {{ vat_applicable_services }} + or pamu.id_payaway_plan is not null -- host takes waiver then false when vat.vat_rate = 0 then false @@ -69,7 +76,15 @@ with left join stg_seed__guest_services_vat_rates_by_country vat on uu.billing_country_iso_3 = vat.alpha_3 - + left join stg_core__verification v on vtp.id_verification = v.id_verification + left join + stg_core__verification_request vr + on v.id_verification_request = vr.id_verification_request + left join + int_core__payaway_per_month_user pamu + on vr.id_user_host = pamu.id_user_host + and vtp.payment_due_at_utc + between pamu.active_in_month_start_date_utc and active_in_month_end_date_utc ) select vtp.id_verification_to_payment,