implement transaction sign
This commit is contained in:
parent
618ce087a5
commit
e963ba274d
1 changed files with 24 additions and 4 deletions
|
|
@ -14,9 +14,12 @@ with
|
|||
cast({{ adapter.quote("Date") }} as date) as transaction_date_utc,
|
||||
{{ adapter.quote("DateString") }} as date_string,
|
||||
|
||||
{{ adapter.quote("Total") }} as total_amount_local_curr,
|
||||
{{ adapter.quote("SubTotal") }} as total_amount_wo_tax_local_curr,
|
||||
{{ adapter.quote("TotalTax") }} as total_tax_local_curr,
|
||||
{{ adapter.quote("Total") }}
|
||||
* ts.transaction_sign as total_amount_local_curr,
|
||||
{{ adapter.quote("SubTotal") }}
|
||||
* ts.transaction_sign as total_amount_wo_tax_local_curr,
|
||||
{{ adapter.quote("TotalTax") }}
|
||||
* ts.transaction_sign as total_tax_local_curr,
|
||||
{{ adapter.quote("CurrencyCode") }} as transaction_currency_iso_4217,
|
||||
1 / {{ adapter.quote("CurrencyRate") }} as exchange_rate_to_gbp,
|
||||
{{ adapter.quote("LineAmountTypes") }} as line_amount_tax_inclusiveness,
|
||||
|
|
@ -33,7 +36,24 @@ with
|
|||
{{ adapter.quote("UpdatedDateUTC") }} as updated_at_utc,
|
||||
cast({{ adapter.quote("UpdatedDateUTC") }} as date) as updated_date_utc,
|
||||
{{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc
|
||||
from raw_bank_transactions
|
||||
from raw_bank_transactions bt
|
||||
left join
|
||||
(
|
||||
-- making this tiny subquery to be able to reference the
|
||||
-- transaction_sign col above easily and avoid plastering the
|
||||
-- case-when a gazillion times.
|
||||
select
|
||||
{{ adapter.quote("BankTransactionID") }} as id_bank_transaction,
|
||||
case
|
||||
when {{ adapter.quote("Type") }} like '%SPEND%'
|
||||
then -1
|
||||
when {{ adapter.quote("Type") }} like '%RECEIVE%'
|
||||
then 1
|
||||
else null
|
||||
end as transaction_sign
|
||||
from raw_bank_transactions
|
||||
) ts
|
||||
on bt.{{ adapter.quote("BankTransactionID") }} = ts.id_bank_transaction
|
||||
)
|
||||
select *
|
||||
from stg_xero__bank_transactions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue