add internal exchange rates
This commit is contained in:
parent
4b0b15814e
commit
25e9d040ff
1 changed files with 16 additions and 7 deletions
|
|
@ -1,7 +1,8 @@
|
|||
with
|
||||
stg_xero__bank_transactions as (
|
||||
select * from {{ ref("stg_xero__bank_transactions") }}
|
||||
)
|
||||
),
|
||||
int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }})
|
||||
select
|
||||
bt.id_bank_transaction,
|
||||
bt.id_prepayment,
|
||||
|
|
@ -10,21 +11,24 @@ select
|
|||
bt.transaction_type,
|
||||
bt.transaction_status,
|
||||
bt.transaction_at_utc,
|
||||
bt.transaction_date_utc,
|
||||
bt.date_string,
|
||||
bt.total_amount_local_curr,
|
||||
(bt.total_amount_local_curr * bt.exchange_rate_to_gbp)::numeric(
|
||||
(bt.total_amount_local_curr * coalesce(bt.exchange_rate_to_gbp, ser.rate))::numeric(
|
||||
18, 4
|
||||
) as total_amount_in_gbp,
|
||||
bt.total_amount_wo_tax_local_curr,
|
||||
(bt.total_amount_wo_tax_local_curr * bt.exchange_rate_to_gbp)::numeric(
|
||||
18, 4
|
||||
) as total_amount_wo_tax_in_gbp,
|
||||
(
|
||||
bt.total_amount_wo_tax_local_curr * coalesce(bt.exchange_rate_to_gbp, ser.rate)
|
||||
)::numeric(18, 4) as total_amount_wo_tax_in_gbp,
|
||||
bt.total_tax_local_curr,
|
||||
(bt.total_tax_local_curr * bt.exchange_rate_to_gbp)::numeric(
|
||||
(bt.total_tax_local_curr * coalesce(bt.exchange_rate_to_gbp, ser.rate))::numeric(
|
||||
18, 4
|
||||
) as total_tax_in_gbp,
|
||||
bt.transaction_currency_iso_4217,
|
||||
bt.exchange_rate_to_gbp,
|
||||
-- We try to use Xero's rate. If no rate is available, we fall back to the
|
||||
-- oficial dwh rate.
|
||||
coalesce(bt.exchange_rate_to_gbp, ser.rate) as exchange_rate_to_gbp,
|
||||
bt.line_amount_tax_inclusiveness,
|
||||
bt.full_contact_details,
|
||||
bt.line_items,
|
||||
|
|
@ -37,3 +41,8 @@ select
|
|||
bt.updated_date_utc,
|
||||
bt.dwh_extracted_at_utc
|
||||
from stg_xero__bank_transactions bt
|
||||
left join
|
||||
int_simple_exchange_rates ser
|
||||
on bt.transaction_currency_iso_4217 = ser.from_currency
|
||||
and ser.to_currency = 'GBP'
|
||||
and bt.transaction_date_utc = ser.rate_date_utc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue