Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added transaction_amount to balance_sheet & income_statement #151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions models/netsuite2/netsuite2__balance_sheet.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions models/netsuite2/netsuite2__income_statement.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand Down Expand Up @@ -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') }},
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down