with
    xero__bank_transaction_line_items as (
        select * from {{ ref("xero__bank_transaction_line_items") }}
    ),
    xero__bank_transactions as (select * from {{ ref("xero__bank_transactions") }}),
    xero__contacts as (select * from {{ ref("xero__contacts") }})
select

    btli.id_bank_transaction,
    btli.id_line_item,
    btli.line_description,
    btli.id_account,
    btli.account_code,
    btli.account_name,
    btli.item_code,
    btli.quantity,
    btli.unit_amount,
    btli.line_amount_local_curr,
    btli.line_amount_in_gbp,
    btli.line_amount_wo_taxes_local_curr,
    btli.line_amount_wo_taxes_in_gbp,
    btli.tax_amount_local_curr,
    btli.tax_amount_in_gbp,
    btli.tax_type,
    btli.transaction_currency_iso_4217,

    bt.id_prepayment,
    bt.id_overpayment,
    bt.id_contact,
    bt.id_bank_account,
    bt.reference,
    bt.transaction_type,
    bt.transaction_sign,
    bt.transaction_status,
    bt.transaction_at_utc,
    bt.transaction_date_utc,
    bt.date_string,
    bt.total_amount_local_curr,
    bt.total_amount_in_gbp,
    bt.total_amount_wo_tax_local_curr,
    bt.total_amount_wo_tax_in_gbp,
    bt.total_tax_local_curr,
    bt.total_tax_in_gbp,
    bt.exchange_rate_to_gbp,
    bt.line_amount_tax_inclusiveness,
    bt.is_reconciled,
    bt.has_attachments,
    bt.url,
    bt.external_link_provider_name,

    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__bank_transaction_line_items btli
left join
    xero__bank_transactions bt on bt.id_bank_transaction = btli.id_bank_transaction
left join xero__contacts c on c.id_contact = bt.id_contact
