modified model
This commit is contained in:
parent
4cfc0dcd45
commit
906bccce0e
2 changed files with 91 additions and 0 deletions
|
|
@ -0,0 +1,60 @@
|
||||||
|
{% set ok_status = ("Approved", "Flagged") %}
|
||||||
|
{% set rejected_status = "Rejected" %}
|
||||||
|
{% set rejected_fee = 0.25 %}
|
||||||
|
{% set cancellation_fee = 0.25 %}
|
||||||
|
{% set cancellation_threshold = 0.05 %}
|
||||||
|
with
|
||||||
|
int_edeposit__verifications as (
|
||||||
|
select * from {{ ref("int_edeposit__verifications") }}
|
||||||
|
),
|
||||||
|
edeposit_records as (
|
||||||
|
select
|
||||||
|
id_verification,
|
||||||
|
id_user_partner,
|
||||||
|
id_booking,
|
||||||
|
is_cancelled,
|
||||||
|
creation_at_utc,
|
||||||
|
case
|
||||||
|
when verification_status in {{ ok_status }}
|
||||||
|
then nightly_fee_local * number_nights
|
||||||
|
else 0
|
||||||
|
end as ok_status_fee,
|
||||||
|
case
|
||||||
|
when verification_status = '{{ rejected_status }}'
|
||||||
|
then {{ rejected_fee }}
|
||||||
|
else 0
|
||||||
|
end as rejected_fee,
|
||||||
|
to_char(checkout_at_utc, 'YYYY-MM') as year_month_checkout
|
||||||
|
from int_edeposit__verifications
|
||||||
|
where version = 'V2'
|
||||||
|
),
|
||||||
|
monthly_cancellation_threshold as (
|
||||||
|
select
|
||||||
|
id_user_partner,
|
||||||
|
year_month_checkout,
|
||||||
|
case
|
||||||
|
when
|
||||||
|
sum(cast(is_cancelled as integer))::decimal / count(id_booking)
|
||||||
|
>= {{ cancellation_threshold }}
|
||||||
|
then true
|
||||||
|
else false
|
||||||
|
end as is_cancellation_threshold_surpassed
|
||||||
|
from edeposit_records
|
||||||
|
group by id_user_partner, year_month_checkout
|
||||||
|
)
|
||||||
|
select
|
||||||
|
id_verification,
|
||||||
|
ok_status_fee,
|
||||||
|
rejected_fee,
|
||||||
|
case
|
||||||
|
when ct.is_cancellation_threshold_surpassed is true
|
||||||
|
then {{ cancellation_fee }}
|
||||||
|
else 0
|
||||||
|
end as cancelled_fee
|
||||||
|
from edeposit_records er
|
||||||
|
left join
|
||||||
|
monthly_cancellation_threshold ct
|
||||||
|
on (
|
||||||
|
er.id_user_partner = ct.id_user_partner
|
||||||
|
and er.year_month_checkout = ct.year_month_checkout
|
||||||
|
)
|
||||||
|
|
@ -206,3 +206,34 @@ models:
|
||||||
- name: created_date_utc
|
- name: created_date_utc
|
||||||
data_type: date
|
data_type: date
|
||||||
description: "Date of creation of the verification in the system"
|
description: "Date of creation of the verification in the system"
|
||||||
|
- name: int_edeposit__verification_fees
|
||||||
|
description:
|
||||||
|
"This table shows all fee charges per verification for E-deposit.
|
||||||
|
Cancellation fee is charged when the monthly rate of cancelled bookings over
|
||||||
|
total booking of the partner surpasses the threshold (currently set at 0.05).
|
||||||
|
Both cancellation and rejection fees are set to 0.25 though it might change"
|
||||||
|
columns:
|
||||||
|
- name: id_verification
|
||||||
|
data_type: text
|
||||||
|
description: "unique Superhog generated id for this verification"
|
||||||
|
tests:
|
||||||
|
- unique
|
||||||
|
- not_null
|
||||||
|
|
||||||
|
- name: ok_status_fee
|
||||||
|
data_type: numeric
|
||||||
|
description: "fee charged for approved or flagged verifications"
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
|
||||||
|
- name: rejected_fee
|
||||||
|
data_type: numeric
|
||||||
|
description: "fee charged for rejected verifications"
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
|
||||||
|
- name: cancelled_fee
|
||||||
|
data_type: numeric
|
||||||
|
description: "fee charged for cancelled verifications"
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue