Skip to content

Commit

Permalink
Add additional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jmongerlyra committed Aug 30, 2024
1 parent dc306db commit 8a58dc2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ joined as (
accounting_books.accounting_book_name,
{% endif %}

transaction_accounting_lines.exchange_rate,
transaction_accounting_lines.amount,
transaction_accounting_lines.credit_amount,
transaction_accounting_lines.debit_amount,
Expand All @@ -54,6 +55,7 @@ joined as (
transaction_accounting_lines.account_id,
accounting_books.accounting_book_id,
accounting_books.accounting_book_name,
transaction_accounting_lines.exchange_rate,
transaction_accounting_lines.amount,
transaction_accounting_lines.credit_amount,
transaction_accounting_lines.debit_amount,
Expand Down
17 changes: 16 additions & 1 deletion models/netsuite2/netsuite2__balance_sheet.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ balance_sheet as (
transactions_with_converted_amounts.transaction_line_id,
transactions_with_converted_amounts.subsidiary_id,
transactions_with_converted_amounts._fivetran_synced_date,
subsidiaries.full_name as subsidiary_full_name,
subsidiaries.name as subsidiary_name,

{% if var('netsuite2__multibook_accounting_enabled', false) %}
Expand Down Expand Up @@ -88,6 +89,13 @@ balance_sheet as (
and {{ dbt.date_trunc('year', 'reporting_accounting_periods.starting_at') }} = {{ dbt.date_trunc('year', 'transaction_accounting_periods.starting_at') }}
and reporting_accounting_periods.fiscal_calendar_id = transaction_accounting_periods.fiscal_calendar_id) then 'Net Income'
when not accounts.is_balancesheet then 'Retained Earnings'
else accounts.display_name
end as account_display_name,
case
when (not accounts.is_balancesheet
and {{ dbt.date_trunc('year', 'reporting_accounting_periods.starting_at') }} = {{ dbt.date_trunc('year', 'transaction_accounting_periods.starting_at') }}
and reporting_accounting_periods.fiscal_calendar_id = transaction_accounting_periods.fiscal_calendar_id) then 'Net Income'
when not accounts.is_balancesheet then 'Retained Earnings'
when lower(accounts.special_account_type_id) = 'retearnings' then 'Retained Earnings'
when lower(accounts.special_account_type_id) in ('cta-e', 'cumultransadj') then 'Cumulative Translation Adjustment'
else accounts.type_name
Expand All @@ -108,7 +116,11 @@ balance_sheet as (
case
when not accounts.is_balancesheet then null
else accounts.account_number
end as account_number
end as account_number,
case
when not accounts.is_balancesheet then false
else accounts.is_leftside
end as is_account_leftside

--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 @@ -195,6 +207,7 @@ balance_sheet as (
transactions_with_converted_amounts.transaction_line_id,
transactions_with_converted_amounts.subsidiary_id,
transactions_with_converted_amounts._fivetran_synced_date,
subsidiaries.full_name as subsidiary_full_name,
subsidiaries.name as subsidiary_name,

{% if var('netsuite2__multibook_accounting_enabled', false) %}
Expand All @@ -215,10 +228,12 @@ balance_sheet as (
reporting_accounting_periods.is_closed as is_accounting_period_closed,
'Equity' as account_category,
'Cumulative Translation Adjustment' as account_name,
'Cumulative Translation Adjustment' as account_display_name,
'Cumulative Translation Adjustment' as account_type_name,
'cumulative_translation_adjustment' as account_type_id,
null as account_id,
null as account_number,
false as is_account_leftside,

{% if var('accounts_pass_through_columns') %}
{% for field in var('accounts_pass_through_columns') %}
Expand Down
1 change: 1 addition & 0 deletions models/netsuite2/netsuite2__income_statement.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ income_statement as (
reporting_accounting_periods.is_adjustment as is_accounting_period_adjustment,
reporting_accounting_periods.is_closed as is_accounting_period_closed,
accounts.name as account_name,
accounts.display_name as account_display_name,
accounts.type_name as account_type_name,
accounts.account_type_id,
accounts.account_id as account_id,
Expand Down
21 changes: 19 additions & 2 deletions models/netsuite2/netsuite2__transaction_details.sql
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ transaction_details as (
transactions._fivetran_synced_date,
transactions.transaction_number,
coalesce(transaction_lines.entity_id, transactions.entity_id) as entity_id,
transactions.is_intercompany_adjustment as is_transaction_intercompany_adjustment
transactions.is_intercompany_adjustment as is_transaction_intercompany_adjustment,
transactions.is_reversal,
transactions.reversal_transaction_id,
transactions.reversal_date,
transactions.is_reversal_defer

--The below script allows for transactions table pass through columns.
{{ fivetran_utils.persist_pass_through_columns('transactions_pass_through_columns', identifier='transactions') }}
Expand All @@ -137,6 +141,7 @@ transaction_details as (
accounting_periods.is_adjustment as is_accounting_period_adjustment,
accounting_periods.is_closed as is_accounting_period_closed,
accounts.name as account_name,
accounts.display_name as account_display_name,
accounts.type_name as account_type_name,
accounts.account_type_id,
accounts.account_id as account_id,
Expand All @@ -149,6 +154,7 @@ transaction_details as (
lower(accounts.account_type_id) = 'acctpay' as is_accounts_payable,
lower(accounts.account_type_id) = 'acctrec' as is_accounts_receivable,
accounts.is_eliminate as is_account_intercompany,
transaction_lines.is_eliminate,
coalesce(parent_account.name, accounts.name) as parent_account_name,
lower(accounts.account_type_id) in ('expense', 'othexpense', 'deferexpense') as is_expense_account,
lower(accounts.account_type_id) in ('income', 'othincome') as is_income_account,
Expand All @@ -175,21 +181,29 @@ transaction_details as (
currencies.name as currency_name,
currencies.symbol as currency_symbol,
transaction_lines.department_id,
transaction_lines.exchange_rate,
departments.full_name as department_full_name,
departments.name as department_name

--The below script allows for departments table pass through columns.
{{ fivetran_utils.persist_pass_through_columns('departments_pass_through_columns', identifier='departments') }},

subsidiaries.subsidiary_id,
subsidiaries.full_name as subsidiary_full_name,
subsidiaries.name as subsidiary_name,
subsidiaries_currencies.symbol as subsidiary_currency_symbol,
case
when lower(accounts.account_type_id) in ('income', 'othincome') then -transactions_with_converted_amounts.converted_amount_using_transaction_accounting_period
else transactions_with_converted_amounts.converted_amount_using_transaction_accounting_period
end as converted_amount,
case
when lower(accounts.account_type_id) in ('income', 'othincome') then -transaction_lines.amount
else transaction_lines.amount
end as transaction_amount
end as transaction_amount,
case
when lower(accounts.account_type_id) in ('income', 'othincome') then -transaction_lines.netamount
else transaction_lines.netamount
end as transaction_line_amount
from transaction_lines

join transactions
Expand Down Expand Up @@ -241,6 +255,9 @@ transaction_details as (

join subsidiaries
on subsidiaries.subsidiary_id = transaction_lines.subsidiary_id

left join currencies subsidiaries_currencies
on subsidiaries_currencies.currency_id = subsidiaries.currency_id

where (accounting_periods.fiscal_calendar_id is null
or accounting_periods.fiscal_calendar_id = (select fiscal_calendar_id from subsidiaries where parent_id is null))
Expand Down

0 comments on commit 8a58dc2

Please sign in to comment.