with
    xero__invoices as (select * from {{ ref("xero__invoices") }}),
    xero__contacts as (select * from {{ ref("xero__contacts") }}),
    xero__invoice_line_items as (select * from {{ ref("xero__invoice_line_items") }})

select
    li.id_line_item,
    li.id_item,
    li.item_code,
    li.quantity,
    li.unit_amount,
    li.line_amount_local_curr,
    li.line_amount_in_gbp,
    li.line_amount_wo_taxes_local_curr,
    li.line_amount_wo_taxes_in_gbp,
    li.tax_amount_local_curr,
    li.tax_amount_in_gbp,
    li.tax_type,
    li.line_description,

    i.id_invoice,
    i.reference,
    i.invoice_number,
    i.invoice_issued_date_utc,
    i.invoice_due_date_utc,
    i.was_fully_paid_on_date_utc,
    i.invoice_type,
    i.invoice_currency_iso_4217,
    i.exchange_rate_to_gbp,
    i.total_amount_local_curr,
    i.total_amount_in_gbp,
    i.total_amount_wo_tax_local_curr,
    i.total_amount_wo_tax_in_gbp,
    i.total_tax_local_curr,
    i.total_tax_in_gbp,
    i.total_due_local_curr,
    i.total_due_in_gbp,
    i.total_paid_local_curr,
    i.total_paid_in_gbp,
    i.invoice_status,
    i.has_errors,
    i.is_discounted,
    i.date_string,
    i.due_date_string,
    i.has_been_sent_to_contact,
    i.total_discount,
    i.total_credited_local_curr,
    i.has_attachments,
    i.line_amount_tax_inclusiveness,
    i.payment_planned_date_utc,
    i.payment_expected_date_utc,

    c.id_contact,
    c.account_number,
    c.id_deal,
    c.contact_name,
    c.is_customer,
    c.is_supplier,
    c.tax_number,
    c.contact_first_name,
    c.contact_last_name,
    c.phones,
    c.website,
    c.balances,
    c.discount,
    c.addresses,
    c.attachments,
    c.email_addresses,
    c.payment_terms,
    c.batch_payments,
    c.branding_theme,
    c.contact_groups,
    c.contact_number,
    c.contact_status,
    c.skyper_user_name,
    c.contact_persons,
    c.xero_network_key,
    c.default_currency_iso_4217,
    c.validation_errors,
    c.bank_account_details,
    c.has_validation_errors,
    c.tracking_category_name,
    c.account_payable_tax_type,
    c.tracking_category_option,
    c.sales_default_account_code,
    c.sales_tracking_categories,
    c.account_receivable_tax_type,
    c.purchases_default_account_code,
    c.purchases_tracking_categories

from xero__invoice_line_items li
left join xero__invoices i on li.id_invoice = i.id_invoice
left join xero__contacts c on i.id_contact = c.id_contact
