diff --git a/models/netsuite2/netsuite2__balance_sheet.sql b/models/netsuite2/netsuite2__balance_sheet.sql index c4417ab..3579b10 100644 --- a/models/netsuite2/netsuite2__balance_sheet.sql +++ b/models/netsuite2/netsuite2__balance_sheet.sql @@ -51,6 +51,11 @@ subsidiaries as ( from {{ var('netsuite2_subsidiaries') }} ), +currencies as ( + select * + from {{ var('netsuite2_currencies') }} +), + balance_sheet as ( select transactions_with_converted_amounts.transaction_id, @@ -59,6 +64,7 @@ balance_sheet as ( transactions_with_converted_amounts._fivetran_synced_date, subsidiaries.full_name as subsidiary_full_name, subsidiaries.name as subsidiary_name, + subsidiaries_currencies.symbol as subsidiary_currency_symbol, {% if var('netsuite2__multibook_accounting_enabled', false) %} transactions_with_converted_amounts.accounting_book_id, @@ -138,6 +144,13 @@ balance_sheet as ( else 0 end as converted_amount, + case + when not accounts.is_balancesheet then -unconverted_amount + when accounts.is_balancesheet and not accounts.is_leftside then -unconverted_amount + when accounts.is_balancesheet and accounts.is_leftside then unconverted_amount + else 0 + end as transaction_amount, + case when lower(accounts.account_type_id) = 'bank' then 1 when lower(accounts.account_type_id) = 'acctrec' then 2 @@ -198,6 +211,9 @@ balance_sheet as ( left join subsidiaries on subsidiaries.subsidiary_id = transactions_with_converted_amounts.subsidiary_id + left join currencies subsidiaries_currencies + on subsidiaries_currencies.currency_id = subsidiaries.currency_id + where reporting_accounting_periods.fiscal_calendar_id = (select fiscal_calendar_id from subsidiaries where parent_id is null) and transaction_accounting_periods.fiscal_calendar_id = (select fiscal_calendar_id from subsidiaries where parent_id is null) and (accounts.is_balancesheet @@ -212,6 +228,7 @@ balance_sheet as ( transactions_with_converted_amounts._fivetran_synced_date, subsidiaries.full_name as subsidiary_full_name, subsidiaries.name as subsidiary_name, + subsidiaries_currencies.symbol as subsidiary_currency_symbol, {% if var('netsuite2__multibook_accounting_enabled', false) %} transactions_with_converted_amounts.accounting_book_id, @@ -249,6 +266,9 @@ balance_sheet as ( when lower(accounts.general_rate_type) in ('historical', 'average') then converted_amount_using_transaction_accounting_period else converted_amount_using_reporting_month end as converted_amount, + + unconverted_amount as transaction_amount, + 16 as balance_sheet_sort_helper --Below is only used if balance sheet transaction detail columns are specified dbt_project.yml file. @@ -284,6 +304,9 @@ balance_sheet as ( left join subsidiaries on subsidiaries.subsidiary_id = transactions_with_converted_amounts.subsidiary_id + left join currencies subsidiaries_currencies + on subsidiaries_currencies.currency_id = subsidiaries.currency_id + where reporting_accounting_periods.fiscal_calendar_id = (select fiscal_calendar_id from subsidiaries where parent_id is null) and (accounts.is_balancesheet or transactions_with_converted_amounts.is_income_statement) diff --git a/models/netsuite2/netsuite2__income_statement.sql b/models/netsuite2/netsuite2__income_statement.sql index d0a79f5..cedd9ed 100644 --- a/models/netsuite2/netsuite2__income_statement.sql +++ b/models/netsuite2/netsuite2__income_statement.sql @@ -51,6 +51,11 @@ subsidiaries as ( from {{ var('netsuite2_subsidiaries') }} ), +currencies as ( + select * + from {{ var('netsuite2_currencies') }} +), + transaction_lines as ( select * from {{ ref('int_netsuite2__transaction_lines') }} @@ -101,7 +106,8 @@ income_statement as ( accounts.account_number, subsidiaries.subsidiary_id, subsidiaries.full_name as subsidiary_full_name, - subsidiaries.name as subsidiary_name + subsidiaries.name as subsidiary_name, + subsidiaries_currencies.symbol as subsidiary_currency_symbol --The below script allows for accounts table pass through columns. {{ fivetran_utils.persist_pass_through_columns('accounts_pass_through_columns', identifier='accounts') }}, @@ -137,7 +143,9 @@ income_statement as ( {% endif %} - , -converted_amount_using_transaction_accounting_period as converted_amount + , -converted_amount_using_transaction_accounting_period as converted_amount, + + -unconverted_amount as transaction_amount from transactions_with_converted_amounts @@ -167,6 +175,9 @@ income_statement as ( left join subsidiaries on transactions_with_converted_amounts.subsidiary_id = subsidiaries.subsidiary_id + left join currencies subsidiaries_currencies + on subsidiaries_currencies.currency_id = subsidiaries.currency_id + --Below is only used if income statement transaction detail columns are specified dbt_project.yml file. {% if var('income_statement_transaction_detail_columns') != []%} join transaction_details