Fixed model, added created_date and checkout_date
This commit is contained in:
parent
c24c875336
commit
7d8983e0dd
2 changed files with 48 additions and 24 deletions
|
|
@ -8,8 +8,8 @@ with
|
|||
select * from {{ ref("int_edeposit__verifications") }}
|
||||
),
|
||||
stg_core__edeposit_user as (select * from {{ ref("stg_core__edeposit_user") }}),
|
||||
stg_xedotcom__exchange_rates as (
|
||||
select * from {{ ref("stg_xedotcom__exchange_rates") }}
|
||||
int_daily_currency_exchange_rates as (
|
||||
select * from {{ ref("int_daily_currency_exchange_rates") }}
|
||||
),
|
||||
edeposit_records as (
|
||||
select
|
||||
|
|
@ -17,9 +17,8 @@ with
|
|||
v.id_user_partner,
|
||||
v.id_booking,
|
||||
eu.currency,
|
||||
er.rate,
|
||||
cer.rate,
|
||||
v.is_cancelled,
|
||||
v.creation_at_utc,
|
||||
case
|
||||
when v.verification_status in {{ ok_status }}
|
||||
then v.nightly_fee_local * v.number_nights
|
||||
|
|
@ -27,7 +26,7 @@ with
|
|||
end as ok_status_fee_in_txn_currency,
|
||||
case
|
||||
when v.verification_status in {{ ok_status }}
|
||||
then er.rate * v.nightly_fee_local * v.number_nights
|
||||
then cer.rate * v.nightly_fee_local * v.number_nights
|
||||
else 0
|
||||
end as ok_status_fee_in_gbp,
|
||||
case
|
||||
|
|
@ -37,17 +36,17 @@ with
|
|||
end as rejected_fee_in_txn_currency,
|
||||
case
|
||||
when v.verification_status = '{{ rejected_status }}'
|
||||
then er.rate * {{ rejected_fee }}
|
||||
then cer.rate * {{ rejected_fee }}
|
||||
else 0
|
||||
end as rejected_fee_in_gbp,
|
||||
to_char(v.checkout_at_utc, 'YYYY-MM') as year_month_checkout
|
||||
from int_edeposit__verifications v
|
||||
inner join stg_core__edeposit_user eu on v.id_user_partner = eu.id_user_partner
|
||||
inner join
|
||||
stg_xedotcom__exchange_rates er
|
||||
on er.from_currency = eu.currency
|
||||
and er.rate_date_utc = v.checkout_date_utc
|
||||
and er.to_currency = 'GBP'
|
||||
left join
|
||||
int_daily_currency_exchange_rates cer
|
||||
on cer.from_currency = eu.currency
|
||||
and cer.rate_date_utc = v.checkout_date_utc
|
||||
and cer.to_currency = 'GBP'
|
||||
where version = 'V2'
|
||||
),
|
||||
monthly_cancellation_threshold as (
|
||||
|
|
@ -65,12 +64,13 @@ with
|
|||
group by id_user_partner, year_month_checkout
|
||||
)
|
||||
select
|
||||
id_verification,
|
||||
currency,
|
||||
ok_status_fee_in_txn_currency,
|
||||
ok_status_fee_in_gbp,
|
||||
rejected_fee_in_txn_currency,
|
||||
rejected_fee_in_gbp,
|
||||
v.id_verification,
|
||||
v.id_booking,
|
||||
er.currency,
|
||||
er.ok_status_fee_in_txn_currency,
|
||||
er.ok_status_fee_in_gbp,
|
||||
er.rejected_fee_in_txn_currency,
|
||||
er.rejected_fee_in_gbp,
|
||||
case
|
||||
when ct.is_cancellation_threshold_surpassed is true
|
||||
then {{ cancellation_fee }}
|
||||
|
|
@ -80,9 +80,12 @@ select
|
|||
when ct.is_cancellation_threshold_surpassed is true
|
||||
then rate * {{ cancellation_fee }}
|
||||
else 0
|
||||
end as cancelled_fee_in_gbp
|
||||
from edeposit_records er
|
||||
left join
|
||||
end as cancelled_fee_in_gbp,
|
||||
v.created_date_utc,
|
||||
v.checkout_date_utc
|
||||
from int_edeposit__verifications v
|
||||
inner join edeposit_records er on er.id_verification = v.id_verification
|
||||
inner join
|
||||
monthly_cancellation_threshold ct
|
||||
on (
|
||||
er.id_user_partner = ct.id_user_partner
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue