2024-05-17 11:43:42 +02:00
|
|
|
with stg_xero__credit_notes as (select * from {{ ref("stg_xero__credit_notes") }})
|
2024-05-16 18:21:32 +02:00
|
|
|
|
|
|
|
|
select
|
|
|
|
|
id_credit_note,
|
|
|
|
|
full_contact_details ->> 'ContactID' as id_contact,
|
|
|
|
|
reference,
|
|
|
|
|
credit_note_number,
|
|
|
|
|
credit_note_issued_at_utc,
|
|
|
|
|
credit_note_issued_date_utc,
|
|
|
|
|
credit_note_type,
|
2024-05-17 11:43:42 +02:00
|
|
|
credit_note_currency_iso_4217,
|
2024-05-16 18:21:32 +02:00
|
|
|
exchange_rate_to_gbp,
|
|
|
|
|
total_amount_local_curr,
|
|
|
|
|
(total_amount_local_curr * exchange_rate_to_gbp)::numeric(
|
|
|
|
|
18, 4
|
|
|
|
|
) as total_amount_in_gbp,
|
|
|
|
|
subtotal_local_curr,
|
|
|
|
|
(subtotal_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as subtotal_in_gbp,
|
|
|
|
|
total_tax_local_curr,
|
|
|
|
|
(total_tax_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_tax_in_gbp,
|
|
|
|
|
remaining_credit_local_curr,
|
|
|
|
|
(remaining_credit_local_curr * exchange_rate_to_gbp)::numeric(
|
|
|
|
|
18, 4
|
|
|
|
|
) as remaining_credit_in_gbp,
|
|
|
|
|
applied_amount,
|
|
|
|
|
credit_note_status,
|
2024-05-23 16:23:52 +02:00
|
|
|
full_contact_details,
|
2024-05-16 18:21:32 +02:00
|
|
|
credit_note_due_date,
|
2024-05-23 16:23:52 +02:00
|
|
|
line_items,
|
2024-05-16 18:21:32 +02:00
|
|
|
date_string,
|
|
|
|
|
due_date_string,
|
|
|
|
|
allocations,
|
|
|
|
|
has_been_sent_to_contact,
|
|
|
|
|
has_attachments,
|
|
|
|
|
updated_at_utc,
|
|
|
|
|
id_branding_theme,
|
|
|
|
|
was_fully_paid_on_date_utc,
|
|
|
|
|
line_amount_tax_inclusiveness,
|
|
|
|
|
updated_date_utc,
|
2025-03-04 10:12:03 +00:00
|
|
|
case
|
|
|
|
|
when credit_note_number ~ '^CN-20\d{2}-.*' and credit_note_type = 'ACCRECCREDIT'
|
|
|
|
|
then true
|
|
|
|
|
else false
|
|
|
|
|
end as is_credit_note_posted_in_hyperline,
|
2024-05-16 18:21:32 +02:00
|
|
|
dwh_extracted_at_utc
|
|
|
|
|
from stg_xero__credit_notes
|