-
Notifications
You must be signed in to change notification settings - Fork 39
Feature/retained earnings to sub calendar #187
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
Changes from all commits
1129129
7524475
5d7c10a
ec44d16
cd62249
96fad8b
28b05cf
c7c4e49
9cce631
c798f55
7d52e5c
3376743
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| _fivetran_id,_fivetran_deleted,_fivetran_synced,accountingperiod,date_deleted,fiscalcalendar,parent | ||
| t6+LTClexXfChh/pMhoj1F9SpSs=,FALSE,2022-07-10 22:17:10,280,,1,244 | ||
| hbwug8y6jPTTembEaYVZlsljZuQ=,FALSE,2022-07-10 22:17:10,330,,1,239 | ||
| hxkIkIIeDjsG8OgPAlvQVe9a6TE=,FALSE,2022-07-10 22:17:10,348,,2,274 | ||
| H00Ert0t6kQHovZX4pHHC4N4d0Y=,FALSE,2022-07-10 22:17:10,6,,2,1 | ||
| KI+pra1uPLFPsBHFuvT/tXCaWdg=,FALSE,2022-07-10 22:17:10,21,,3,171 | ||
| JIpeyH5xsYzCF0YbPKr7obXrkhA=,FALSE,2022-07-10 22:17:10,20,,3,205 | ||
| _fivetran_id,_fivetran_deleted,_fivetran_synced,accountingperiod,date_deleted,fiscalcalendar,fullname,parent | ||
| t6+LTClexXfChh/pMhoj1F9SpSs=,FALSE,2022-07-10 22:17:10,280,,1,FY2023 : Q1 2023,244 | ||
| hbwug8y6jPTTembEaYVZlsljZuQ=,FALSE,2022-07-10 22:17:10,330,,1,FY2023 : Q4 2023,239 | ||
| hxkIkIIeDjsG8OgPAlvQVe9a6TE=,FALSE,2022-07-10 22:17:10,348,,2,FY2024 : Q2 2024,274 | ||
| H00Ert0t6kQHovZX4pHHC4N4d0Y=,FALSE,2022-07-10 22:17:10,6,,2,FY2022 : Jan 2022,1 | ||
| KI+pra1uPLFPsBHFuvT/tXCaWdg=,FALSE,2022-07-10 22:17:10,21,,3,FY2022 : Q2 2022,171 | ||
| JIpeyH5xsYzCF0YbPKr7obXrkhA=,FALSE,2022-07-10 22:17:10,20,,3,FY2022 : Q1 2022,205 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| {%- set multibook_accounting_enabled = var('netsuite2__multibook_accounting_enabled', false) -%} | ||
| {%- set using_to_subsidiary = var('netsuite2__using_to_subsidiary', false) -%} | ||
| {%- set using_exchange_rate = var('netsuite2__using_exchange_rate', true) -%} | ||
| {%- set using_to_subsidiary_and_exchange_rate = (var('netsuite2__using_to_subsidiary', false) and var('netsuite2__using_exchange_rate', true)) -%} | ||
| {%- set balance_sheet_transaction_detail_columns = var('balance_sheet_transaction_detail_columns', []) -%} | ||
| {%- set accounts_pass_through_columns = var('accounts_pass_through_columns', []) -%} | ||
| {%- set lookback_window = var('lookback_window', 3) -%} | ||
|
|
@@ -54,14 +53,6 @@ currencies as ( | |
| select * | ||
| from {{ ref('stg_netsuite2__currencies') }} | ||
| ), | ||
|
|
||
| primary_subsidiary_calendar as ( | ||
| select | ||
| fiscal_calendar_id, | ||
| source_relation | ||
| from subsidiaries | ||
| where parent_id is null | ||
| ), | ||
|
Comment on lines
-57
to
-64
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lines 224 and 329 take over for this. |
||
|
|
||
| balance_sheet as ( | ||
| select | ||
|
|
@@ -79,14 +70,15 @@ balance_sheet as ( | |
| transactions_with_converted_amounts.accounting_book_name, | ||
| {% endif %} | ||
|
|
||
| {% if using_to_subsidiary and using_exchange_rate %} | ||
| {% if using_to_subsidiary_and_exchange_rate %} | ||
| transactions_with_converted_amounts.to_subsidiary_id, | ||
| transactions_with_converted_amounts.to_subsidiary_name, | ||
| transactions_with_converted_amounts.to_subsidiary_currency_symbol, | ||
| {% endif %} | ||
|
|
||
| reporting_accounting_periods.accounting_period_id as accounting_period_id, | ||
| reporting_accounting_periods.ending_at as accounting_period_ending, | ||
| reporting_accounting_periods.accounting_period_full_name, | ||
| reporting_accounting_periods.name as accounting_period_name, | ||
| reporting_accounting_periods.is_adjustment as is_accounting_period_adjustment, | ||
| reporting_accounting_periods.is_closed as is_accounting_period_closed, | ||
|
|
@@ -202,7 +194,7 @@ balance_sheet as ( | |
| and transaction_details.accounting_book_id = transactions_with_converted_amounts.accounting_book_id | ||
| {% endif %} | ||
|
|
||
| {% if using_to_subsidiary and using_exchange_rate %} | ||
| {% if using_to_subsidiary_and_exchange_rate %} | ||
| and transaction_details.to_subsidiary_id = transactions_with_converted_amounts.to_subsidiary_id | ||
| {% endif %} | ||
| {% endif %} | ||
|
|
@@ -211,31 +203,33 @@ balance_sheet as ( | |
| on accounts.account_id = transactions_with_converted_amounts.account_id | ||
| and accounts.source_relation = transactions_with_converted_amounts.source_relation | ||
|
|
||
| left join accounting_periods as reporting_accounting_periods | ||
| left join subsidiaries | ||
| on subsidiaries.subsidiary_id = transactions_with_converted_amounts.subsidiary_id | ||
| and subsidiaries.source_relation = transactions_with_converted_amounts.source_relation | ||
|
|
||
| {% if using_to_subsidiary_and_exchange_rate %} | ||
| left join subsidiaries as to_subsidiaries | ||
| on to_subsidiaries.subsidiary_id = coalesce(transactions_with_converted_amounts.to_subsidiary_id, subsidiaries.subsidiary_id) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. coalesce because |
||
| and to_subsidiaries.source_relation = transactions_with_converted_amounts.source_relation | ||
| {% endif %} | ||
|
|
||
| left join accounting_periods as reporting_accounting_periods | ||
| on reporting_accounting_periods.accounting_period_id = transactions_with_converted_amounts.reporting_accounting_period_id | ||
| and reporting_accounting_periods.source_relation = transactions_with_converted_amounts.source_relation | ||
| and reporting_accounting_periods.fiscal_calendar_id = {{ 'to_subsidiaries' if using_to_subsidiary_and_exchange_rate else 'subsidiaries' }}.fiscal_calendar_id | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, is this join here necessary if not using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question for the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I take this out I do get fanout. See the row count for dev vs. prod. Previously this was handled by the old line 230 |
||
|
|
||
| left join accounting_periods as transaction_accounting_periods | ||
| on transaction_accounting_periods.accounting_period_id = transactions_with_converted_amounts.transaction_accounting_period_id | ||
| and transaction_accounting_periods.source_relation = transactions_with_converted_amounts.source_relation | ||
|
|
||
| left join subsidiaries | ||
| on subsidiaries.subsidiary_id = transactions_with_converted_amounts.subsidiary_id | ||
| and subsidiaries.source_relation = transactions_with_converted_amounts.source_relation | ||
| and transaction_accounting_periods.fiscal_calendar_id = {{ 'to_subsidiaries' if using_to_subsidiary_and_exchange_rate else 'subsidiaries' }}.fiscal_calendar_id | ||
|
|
||
| left join currencies subsidiaries_currencies | ||
| on subsidiaries_currencies.currency_id = subsidiaries.currency_id | ||
| and subsidiaries_currencies.source_relation = subsidiaries.source_relation | ||
|
|
||
| join primary_subsidiary_calendar | ||
| on reporting_accounting_periods.fiscal_calendar_id = primary_subsidiary_calendar.fiscal_calendar_id | ||
| and reporting_accounting_periods.source_relation = primary_subsidiary_calendar.source_relation | ||
|
|
||
| and transaction_accounting_periods.fiscal_calendar_id = primary_subsidiary_calendar.fiscal_calendar_id | ||
| and transaction_accounting_periods.source_relation = primary_subsidiary_calendar.source_relation | ||
|
|
||
| where accounts.is_balancesheet | ||
| or transactions_with_converted_amounts.is_income_statement | ||
| where (accounts.is_balancesheet | ||
| or transactions_with_converted_amounts.is_income_statement) | ||
| and transactions_with_converted_amounts.reporting_accounting_period_id is not null | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we no long have an inner join, line 232 accomplishes the same thing. |
||
|
|
||
| union all | ||
|
|
||
|
|
@@ -254,14 +248,15 @@ balance_sheet as ( | |
| transactions_with_converted_amounts.accounting_book_name, | ||
| {% endif %} | ||
|
|
||
| {% if using_to_subsidiary and using_exchange_rate %} | ||
| {% if using_to_subsidiary_and_exchange_rate %} | ||
| transactions_with_converted_amounts.to_subsidiary_id, | ||
| transactions_with_converted_amounts.to_subsidiary_name, | ||
| transactions_with_converted_amounts.to_subsidiary_currency_symbol, | ||
| {% endif %} | ||
|
|
||
| reporting_accounting_periods.accounting_period_id as accounting_period_id, | ||
| reporting_accounting_periods.ending_at as accounting_period_ending, | ||
| reporting_accounting_periods.accounting_period_full_name, | ||
| reporting_accounting_periods.name as accounting_period_name, | ||
| reporting_accounting_periods.is_adjustment as is_accounting_period_adjustment, | ||
| reporting_accounting_periods.is_closed as is_accounting_period_closed, | ||
|
|
@@ -310,7 +305,7 @@ balance_sheet as ( | |
| and transaction_details.accounting_book_id = transactions_with_converted_amounts.accounting_book_id | ||
| {% endif %} | ||
|
|
||
| {% if using_to_subsidiary and using_exchange_rate %} | ||
| {% if using_to_subsidiary_and_exchange_rate %} | ||
| and transaction_details.to_subsidiary_id = transactions_with_converted_amounts.to_subsidiary_id | ||
| {% endif %} | ||
| {% endif %} | ||
|
|
@@ -319,29 +314,33 @@ balance_sheet as ( | |
| on accounts.account_id = transactions_with_converted_amounts.account_id | ||
| and accounts.source_relation = transactions_with_converted_amounts.source_relation | ||
|
|
||
| left join accounting_periods as reporting_accounting_periods | ||
| on reporting_accounting_periods.accounting_period_id = transactions_with_converted_amounts.reporting_accounting_period_id | ||
| and reporting_accounting_periods.source_relation = transactions_with_converted_amounts.source_relation | ||
|
|
||
| left join subsidiaries | ||
| on subsidiaries.subsidiary_id = transactions_with_converted_amounts.subsidiary_id | ||
| and subsidiaries.source_relation = transactions_with_converted_amounts.source_relation | ||
|
|
||
| {% if using_to_subsidiary_and_exchange_rate %} | ||
| left join subsidiaries as to_subsidiaries | ||
| on to_subsidiaries.subsidiary_id = coalesce(transactions_with_converted_amounts.to_subsidiary_id, subsidiaries.subsidiary_id) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. coalesce because |
||
| and to_subsidiaries.source_relation = transactions_with_converted_amounts.source_relation | ||
| {% endif %} | ||
|
|
||
| left join accounting_periods as reporting_accounting_periods | ||
| on reporting_accounting_periods.accounting_period_id = transactions_with_converted_amounts.reporting_accounting_period_id | ||
| and reporting_accounting_periods.source_relation = transactions_with_converted_amounts.source_relation | ||
| and reporting_accounting_periods.fiscal_calendar_id = {{ 'to_subsidiaries' if using_to_subsidiary_and_exchange_rate else 'subsidiaries' }}.fiscal_calendar_id | ||
|
|
||
| left join currencies subsidiaries_currencies | ||
| on subsidiaries_currencies.currency_id = subsidiaries.currency_id | ||
| and subsidiaries_currencies.source_relation = subsidiaries.source_relation | ||
|
|
||
| join primary_subsidiary_calendar | ||
| on reporting_accounting_periods.fiscal_calendar_id = primary_subsidiary_calendar.fiscal_calendar_id | ||
| and reporting_accounting_periods.source_relation = primary_subsidiary_calendar.source_relation | ||
|
|
||
| where accounts.is_balancesheet | ||
| or transactions_with_converted_amounts.is_income_statement | ||
| where (accounts.is_balancesheet | ||
| or transactions_with_converted_amounts.is_income_statement) | ||
| and transactions_with_converted_amounts.reporting_accounting_period_id is not null | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Compensates for the lack on inner join. |
||
| ), | ||
|
|
||
| surrogate_key as ( | ||
| {% set surrogate_key_fields = ['source_relation', 'transaction_line_id', 'transaction_id', 'accounting_period_id', 'account_name', 'account_id'] %} | ||
| {% do surrogate_key_fields.append('to_subsidiary_id') if using_to_subsidiary and using_exchange_rate %} | ||
| {% do surrogate_key_fields.append('to_subsidiary_id') if using_to_subsidiary_and_exchange_rate %} | ||
| {% do surrogate_key_fields.append('accounting_book_id') if multibook_accounting_enabled %} | ||
|
|
||
| select | ||
|
|
@@ -352,4 +351,4 @@ balance_sheet as ( | |
| ) | ||
|
|
||
| select * | ||
| from surrogate_key | ||
| from surrogate_key | ||

Uh oh!
There was an error while loading. Please reload this page.