# Description Adds flag to identify invoices/credit notes that are posted in Hyperline. For Invoices, these need to be ACCREC and follow a convention of 20XX-Y For Credit Notes, these need to be ACCRECCREDIT and follow a convention of CN-20XX-Y # Checklist - [X] The edited models and dependants run properly with production data. - [X] The edited models are sufficiently documented. - [X] The edited models contain PK tests, and I've ran and passed them. - [X] I have checked for DRY opportunities with other models and docs. - [X] I've picked the right materialization for the affected models. # Other - [ ] Check if a full-refresh is required after this PR is merged. Related work items: #28146
57 lines
1.7 KiB
SQL
57 lines
1.7 KiB
SQL
with stg_xero__invoices as (select * from {{ ref("stg_xero__invoices") }})
|
|
|
|
select
|
|
id_invoice,
|
|
full_contact_details ->> 'ContactID' as id_contact,
|
|
reference,
|
|
invoice_number,
|
|
invoice_issued_at_utc,
|
|
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,
|
|
(total_amount_local_curr * exchange_rate_to_gbp)::numeric(
|
|
18, 4
|
|
) as total_amount_in_gbp,
|
|
total_amount_wo_tax_local_curr,
|
|
(total_amount_wo_tax_local_curr * exchange_rate_to_gbp)::numeric(
|
|
18, 4
|
|
) as total_amount_wo_tax_in_gbp,
|
|
total_tax_local_curr,
|
|
(total_tax_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_tax_in_gbp,
|
|
total_due_local_curr,
|
|
(total_due_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_due_in_gbp,
|
|
total_paid_local_curr,
|
|
(total_paid_local_curr * exchange_rate_to_gbp)::numeric(18, 4) as total_paid_in_gbp,
|
|
invoice_status,
|
|
full_contact_details,
|
|
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,
|
|
case
|
|
when invoice_number ~ '^20\d{2}-.*' and invoice_type = 'ACCREC'
|
|
then true
|
|
else false
|
|
end as is_invoice_posted_in_hyperline,
|
|
dwh_extracted_at_utc
|
|
from stg_xero__invoices
|