2024-09-05 11:26:37 +02:00
|
|
|
{% set ok_status = "Approved" %}
|
2024-09-04 17:24:55 +02:00
|
|
|
-- 2GBP/booked night if booking is approved, to be charged on checkout
|
2024-09-05 11:26:37 +02:00
|
|
|
{% set cost_per_night = 2 %}
|
2024-09-04 17:24:55 +02:00
|
|
|
with
|
|
|
|
|
int_edeposit__verifications as (
|
|
|
|
|
select * from {{ ref("int_edeposit__verifications") }}
|
2024-09-13 16:14:03 +02:00
|
|
|
),
|
|
|
|
|
-- CTE to rank verifications by updated_at_utc per id_booking
|
|
|
|
|
ranked_verifications as (
|
|
|
|
|
select
|
|
|
|
|
v.*,
|
|
|
|
|
row_number() over (
|
2024-09-13 17:14:34 +02:00
|
|
|
partition by v.id_booking order by v.updated_at_utc asc
|
2024-09-13 16:14:03 +02:00
|
|
|
) as rn
|
|
|
|
|
from int_edeposit__verifications v
|
|
|
|
|
where v.version = 'V1' and v.id_booking is not null
|
2024-09-04 17:24:55 +02:00
|
|
|
)
|
|
|
|
|
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,
|
2024-09-13 16:14:03 +02:00
|
|
|
-- Charge for 1 night if number_nights = 0
|
2024-09-05 13:56:07 +02:00
|
|
|
case
|
2024-09-05 17:21:48 +02:00
|
|
|
when v.number_nights = 0 and v.verification_status = '{{ ok_status }}'
|
2024-09-05 13:56:07 +02:00
|
|
|
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
|
2024-09-05 13:56:07 +02:00
|
|
|
end as ok_status_fee_in_gbp,
|
2024-09-04 17:24:55 +02:00
|
|
|
v.created_date_utc,
|
|
|
|
|
v.checkout_date_utc
|
2024-09-13 16:14:03 +02:00
|
|
|
from ranked_verifications v
|
|
|
|
|
where
|
|
|
|
|
-- Select only the most recent verification for each id_booking
|
|
|
|
|
v.rn = 1
|