data-dwh-dbt-project/models/intermediate/edeposit/int_edeposit__guesty_verifications.sql

26 lines
871 B
MySQL
Raw Normal View History

{% set ok_status = "Approved" %}
2024-09-04 17:24:55 +02:00
-- 2GBP/booked night if booking is approved, to be charged on checkout
{% set cost_per_night = 2 %}
2024-09-04 17:24:55 +02:00
with
int_edeposit__verifications as (
select * from {{ ref("int_edeposit__verifications") }}
)
select
v.id_verification,
v.id_booking,
2024-09-05 17:21:48 +02:00
v.verification_status,
2024-09-04 17:24:55 +02:00
v.is_cancelled,
-- when number_nights = 0 (booking's checkin and checkout are on the same day)
-- it's charged for just 1 night
case
2024-09-05 17:21:48 +02:00
when v.number_nights = 0 and v.verification_status = '{{ ok_status }}'
then {{ cost_per_night }}
2024-09-05 17:21:48 +02:00
when v.verification_status = '{{ ok_status }}'
then v.number_nights * {{ cost_per_night }}
else 0
end as ok_status_fee_in_gbp,
2024-09-04 17:24:55 +02:00
v.created_date_utc,
v.checkout_date_utc
from int_edeposit__verifications v
2024-09-05 17:21:48 +02:00
where v.version = 'V1' and v.id_booking is not null