add new columns
This commit is contained in:
parent
0aaec6a619
commit
bde6f12404
1 changed files with 35 additions and 1 deletions
|
|
@ -13,6 +13,7 @@ with
|
||||||
stg_core__payment as (select * from {{ ref("stg_core__payment") }}),
|
stg_core__payment as (select * from {{ ref("stg_core__payment") }}),
|
||||||
stg_core__payment_status as (select * from {{ ref("stg_core__payment_status") }}),
|
stg_core__payment_status as (select * from {{ ref("stg_core__payment_status") }}),
|
||||||
int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }}),
|
int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }}),
|
||||||
|
int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}),
|
||||||
stg_seed__guest_services_vat_rates_by_country as (
|
stg_seed__guest_services_vat_rates_by_country as (
|
||||||
select * from {{ ref("stg_seed__guest_services_vat_rates_by_country") }}
|
select * from {{ ref("stg_seed__guest_services_vat_rates_by_country") }}
|
||||||
)
|
)
|
||||||
|
|
@ -43,9 +44,38 @@ select
|
||||||
vtp.id_verification,
|
vtp.id_verification,
|
||||||
v.id_verification_request,
|
v.id_verification_request,
|
||||||
vpt.verification_payment_type,
|
vpt.verification_payment_type,
|
||||||
p.amount as amount_in_txn_currency,
|
|
||||||
p.currency,
|
p.currency,
|
||||||
|
p.amount as amount_in_txn_currency,
|
||||||
(p.amount * r.rate) as amount_in_gbp,
|
(p.amount * r.rate) as amount_in_gbp,
|
||||||
|
p.amount as payment_amount_in_txn_currency,
|
||||||
|
(p.amount * r.rate) as payment_amount_in_gbp,
|
||||||
|
p.amount as total_amount_in_txn_currency,
|
||||||
|
(p.amount * r.rate) as total_amount_in_in_gbp,
|
||||||
|
/*
|
||||||
|
Helping comment for logic below.
|
||||||
|
Given that guest payments are tax inclusive, the tax (column
|
||||||
|
tax_amount_in_txn_currency) is calculated as:
|
||||||
|
paid by guest
|
||||||
|
tax = paid by guest - ( ------------- )
|
||||||
|
1 + VAT Rate
|
||||||
|
|
||||||
|
The amount without tax (column amount_without_taxes_in_txn_currency) gets
|
||||||
|
calculated as:
|
||||||
|
paid by guest
|
||||||
|
amount without tax = ( ------------- )
|
||||||
|
1 + VAT Rate
|
||||||
|
*/
|
||||||
|
(p.amount - (p.amount / (1 + vat.vat_rates))) as tax_amount_in_txn_currency,
|
||||||
|
(p.amount - (p.amount / (1 + vat.vat_rates))) * r.rate as tax_amount_in_gbp,
|
||||||
|
(p.amount / (1 + vat.vat_rates)) as amount_without_taxes_in_txn_currency,
|
||||||
|
(p.amount / (1 + vat.vat_rates)) * r.rate as amount_without_taxes_in_gbp,
|
||||||
|
vat.vat_rate as applicable_vat_tax_rate,
|
||||||
|
case
|
||||||
|
when vat.vat_rate = 0
|
||||||
|
then false
|
||||||
|
when vat.vat_rate < 1 and vat.vat_rate > 0
|
||||||
|
then true
|
||||||
|
end as is_vat_taxed,
|
||||||
ps.payment_status,
|
ps.payment_status,
|
||||||
p.notes
|
p.notes
|
||||||
from stg_core__verification_to_payment vtp
|
from stg_core__verification_to_payment vtp
|
||||||
|
|
@ -63,3 +93,7 @@ left join
|
||||||
left join
|
left join
|
||||||
stg_core__verification_request vr
|
stg_core__verification_request vr
|
||||||
on v.id_verification_request = vr.id_verification_request
|
on v.id_verification_request = vr.id_verification_request
|
||||||
|
left join int_core__unified_user uu on vtp.id_guest_user == uu.id_user
|
||||||
|
left join
|
||||||
|
stg_seed__guest_services_vat_rates_by_country vat
|
||||||
|
on uu.billing_country_iso_3 == vat.alpha_3
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue