more credit note work
This commit is contained in:
parent
8f6e92c187
commit
791cbd47e8
3 changed files with 72 additions and 3 deletions
|
|
@ -0,0 +1,69 @@
|
||||||
|
with int_xero__credit_notes as (select * from {{ ref("int_xero__credit_notes") }})
|
||||||
|
|
||||||
|
select
|
||||||
|
cn.id_credit_note,
|
||||||
|
j.id_line_item,
|
||||||
|
j.id_item,
|
||||||
|
j.item_code,
|
||||||
|
j.quantity::numeric,
|
||||||
|
j.unit_amount::numeric,
|
||||||
|
j.line_amount_local_curr::numeric,
|
||||||
|
(j.line_amount_local_curr::numeric * cn.exchange_rate_to_gbp)::numeric(
|
||||||
|
18, 4
|
||||||
|
) as line_amount_in_gbp,
|
||||||
|
case
|
||||||
|
when cn.line_amount_tax_inclusiveness = 'Inclusive'
|
||||||
|
then j.line_amount_local_curr::numeric - j.tax_amount_local_curr::numeric
|
||||||
|
when cn.line_amount_tax_inclusiveness = 'Exclusive'
|
||||||
|
then j.line_amount_local_curr::numeric
|
||||||
|
when cn.line_amount_tax_inclusiveness = 'NoTax'
|
||||||
|
then j.line_amount_local_curr::numeric
|
||||||
|
else null
|
||||||
|
end as line_amount_wo_taxes_local_curr,
|
||||||
|
case
|
||||||
|
when cn.line_amount_tax_inclusiveness = 'Inclusive'
|
||||||
|
then
|
||||||
|
(j.line_amount_local_curr::numeric * cn.exchange_rate_to_gbp)::numeric(
|
||||||
|
18,
|
||||||
|
4
|
||||||
|
) - (j.tax_amount_local_curr::numeric * cn.exchange_rate_to_gbp)::numeric(
|
||||||
|
18, 4
|
||||||
|
)
|
||||||
|
when cn.line_amount_tax_inclusiveness = 'Exclusive'
|
||||||
|
then
|
||||||
|
(j.line_amount_local_curr::numeric * cn.exchange_rate_to_gbp)::numeric(
|
||||||
|
18, 4
|
||||||
|
)
|
||||||
|
when cn.line_amount_tax_inclusiveness = 'NoTax'
|
||||||
|
then
|
||||||
|
(j.line_amount_local_curr::numeric * cn.exchange_rate_to_gbp)::numeric(
|
||||||
|
18, 4
|
||||||
|
)
|
||||||
|
else null
|
||||||
|
end as line_amount_wo_taxes_in_gbp,
|
||||||
|
j.tax_amount_local_curr::numeric,
|
||||||
|
(j.tax_amount_local_curr::numeric * cn.exchange_rate_to_gbp)::numeric(
|
||||||
|
18, 4
|
||||||
|
) as tax_amount_in_gbp,
|
||||||
|
j.tax_type,
|
||||||
|
cn.credit_note_currency_iso_4217,
|
||||||
|
j.line_description
|
||||||
|
from int_xero__credit_notes cn
|
||||||
|
cross join
|
||||||
|
lateral(
|
||||||
|
select
|
||||||
|
(jsonb_array_elements(cn.line_items) ->> 'LineItemID') as id_line_item,
|
||||||
|
(jsonb_array_elements(cn.line_items) -> 'Item') ->> 'ItemID' as id_item,
|
||||||
|
(jsonb_array_elements(cn.line_items) -> 'Item') ->> 'Code' as item_code,
|
||||||
|
(jsonb_array_elements(cn.line_items) -> 'Item') ->> 'Name' as item_name,
|
||||||
|
(jsonb_array_elements(cn.line_items) ->> 'Quantity') as quantity,
|
||||||
|
(jsonb_array_elements(cn.line_items) ->> 'UnitAmount') as unit_amount,
|
||||||
|
(
|
||||||
|
jsonb_array_elements(cn.line_items) ->> 'LineAmount'
|
||||||
|
) as line_amount_local_curr,
|
||||||
|
(
|
||||||
|
jsonb_array_elements(cn.line_items) ->> 'TaxAmount'
|
||||||
|
) as tax_amount_local_curr,
|
||||||
|
(jsonb_array_elements(cn.line_items) ->> 'TaxType') as tax_type,
|
||||||
|
(jsonb_array_elements(cn.line_items) ->> 'Description') as line_description
|
||||||
|
) j
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
with stg_xero__credit_notes as (select * from {{ ref("stg_xero__credit_notes") }}),
|
with stg_xero__credit_notes as (select * from {{ ref("stg_xero__credit_notes") }})
|
||||||
|
|
||||||
select
|
select
|
||||||
id_credit_note,
|
id_credit_note,
|
||||||
|
|
@ -8,7 +8,7 @@ select
|
||||||
credit_note_issued_at_utc,
|
credit_note_issued_at_utc,
|
||||||
credit_note_issued_date_utc,
|
credit_note_issued_date_utc,
|
||||||
credit_note_type,
|
credit_note_type,
|
||||||
invoice_currency_iso_4217,
|
credit_note_currency_iso_4217,
|
||||||
exchange_rate_to_gbp,
|
exchange_rate_to_gbp,
|
||||||
total_amount_local_curr,
|
total_amount_local_curr,
|
||||||
(total_amount_local_curr * exchange_rate_to_gbp)::numeric(
|
(total_amount_local_curr * exchange_rate_to_gbp)::numeric(
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ with
|
||||||
{{ adapter.quote("Date") }} as credit_note_issued_at_utc,
|
{{ adapter.quote("Date") }} as credit_note_issued_at_utc,
|
||||||
cast({{ adapter.quote("Date") }} as date) as credit_note_issued_date_utc,
|
cast({{ adapter.quote("Date") }} as date) as credit_note_issued_date_utc,
|
||||||
{{ adapter.quote("Type") }} as credit_note_type,
|
{{ adapter.quote("Type") }} as credit_note_type,
|
||||||
{{ adapter.quote("CurrencyCode") }} as invoice_currency_iso_4217,
|
{{ adapter.quote("CurrencyCode") }} as credit_note_currency_iso_4217,
|
||||||
1 / {{ adapter.quote("CurrencyRate") }} as exchange_rate_to_gbp,
|
1 / {{ adapter.quote("CurrencyRate") }} as exchange_rate_to_gbp,
|
||||||
{{ adapter.quote("Total") }} as total_amount_local_curr,
|
{{ adapter.quote("Total") }} as total_amount_local_curr,
|
||||||
{{ adapter.quote("SubTotal") }} as subtotal_local_curr,
|
{{ adapter.quote("SubTotal") }} as subtotal_local_curr,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue