2024-05-13 15:17:46 +02:00
|
|
|
with stg_xero__invoices as (select * from {{ ref("stg_xero__invoices") }})
|
|
|
|
|
|
|
|
|
|
select
|
|
|
|
|
id_invoice,
|
2024-05-13 15:53:44 +02:00
|
|
|
full_contact_details ->> 'ContactID' as id_contact,
|
2024-05-13 15:17:46 +02:00
|
|
|
reference,
|
|
|
|
|
invoice_number,
|
2024-07-08 16:31:53 +02:00
|
|
|
invoice_issued_at_utc,
|
2024-05-13 15:17:46 +02:00
|
|
|
invoice_issued_date_utc,
|
|
|
|
|
invoice_due_date_utc,
|
|
|
|
|
was_fully_paid_on_date_utc,
|
|
|
|
|
invoice_type,
|
|
|
|
|
invoice_currency_iso_4217,
|
|
|
|
|
exchange_rate_to_gbp,
|
|
|
|
|
total_amount_local_curr,
|
2024-05-14 12:26:02 +02:00
|
|
|
(total_amount_local_curr * exchange_rate_to_gbp)::numeric(
|
|
|
|
|
18, 4
|
|
|
|
|
) as total_amount_in_gbp,
|
2024-05-13 15:17:46 +02:00
|
|
|
total_amount_wo_tax_local_curr,
|
2024-05-14 12:26:02 +02:00
|
|
|
(total_amount_wo_tax_local_curr * exchange_rate_to_gbp)::numeric(
|
|
|
|
|
18, 4
|
|
|
|
|
) as total_amount_wo_tax_in_gbp,
|
2024-05-13 15:17:46 +02:00
|
|
|
total_tax_local_curr,
|
2024-05-14 12:26:02 +02:00
|
|
|
(total_tax_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_tax_in_gbp,
|
2024-05-13 15:17:46 +02:00
|
|
|
total_due_local_curr,
|
2024-05-14 12:26:02 +02:00
|
|
|
(total_due_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_due_in_gbp,
|
2024-05-13 15:17:46 +02:00
|
|
|
total_paid_local_curr,
|
2024-05-14 12:26:02 +02:00
|
|
|
(total_paid_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_paid_in_gbp,
|
2024-05-13 15:17:46 +02:00
|
|
|
invoice_status,
|
2024-05-13 15:47:44 +02:00
|
|
|
full_contact_details,
|
2024-05-13 15:17:46 +02:00
|
|
|
payments,
|
|
|
|
|
has_errors,
|
|
|
|
|
line_items,
|
|
|
|
|
credit_notes,
|
|
|
|
|
prepayments,
|
|
|
|
|
overpayments,
|
|
|
|
|
is_discounted,
|
|
|
|
|
date_string,
|
|
|
|
|
due_date_string,
|
|
|
|
|
has_been_sent_to_contact,
|
|
|
|
|
total_discount,
|
|
|
|
|
total_credited_local_curr,
|
|
|
|
|
has_attachments,
|
|
|
|
|
updated_at_utc,
|
|
|
|
|
updated_date_utc,
|
|
|
|
|
id_branding_theme,
|
|
|
|
|
invoice_url,
|
|
|
|
|
line_amount_tax_inclusiveness,
|
|
|
|
|
payment_planned_date_utc,
|
|
|
|
|
payment_expected_date_utc,
|
2025-03-04 10:12:03 +00:00
|
|
|
case
|
|
|
|
|
when invoice_number ~ '^20\d{2}-.*' and invoice_type = 'ACCREC'
|
|
|
|
|
then true
|
|
|
|
|
else false
|
|
|
|
|
end as is_invoice_posted_in_hyperline,
|
2024-05-13 15:17:46 +02:00
|
|
|
dwh_extracted_at_utc
|
|
|
|
|
from stg_xero__invoices
|