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

bug/account-type-id #84

Merged
merged 17 commits into from
Oct 2, 2023
272 changes: 0 additions & 272 deletions models/netsuite.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ transactions_with_converted_amounts as (
unconverted_amount as converted_amount_using_reporting_month,
{% endif %}
case
when lower(accounts.type_name) in ('income','other income','expense','other expense','other income','cost of goods sold') then true
when lower(accounts.account_type_id) in ('income','othincome','expense','othexpense','cogs') then true
else false
end as is_income_statement,
case
when lower(accounts.type_name) in ('accounts receivable', 'bank', 'deferred expense', 'fixed asset', 'other asset', 'other current asset', 'unbilled receivable', 'prepaid expense') then 'Asset'
when lower(accounts.type_name) in ('cost of goods sold', 'expense', 'other expense') then 'Expense'
when lower(accounts.type_name) in ('income', 'other income') then 'Income'
when lower(accounts.type_name) in ('accounts payable', 'credit card', 'deferred revenue', 'long term liability', 'other current liability') then 'Liability'
when lower(accounts.type_name) in ('equity', 'retained earnings', 'net income') then 'Equity'
when lower(accounts.type_name) in ('non posting', 'statistical') then 'Other'
when lower(accounts.account_type_id) in ('acctrec', 'bank', 'deferexpense', 'fixedasset', 'othasset', 'othcurrasset', 'unbilledrec') then 'Asset'
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
when lower(accounts.account_type_id) in ('cogs', 'expense', 'othexpense') then 'Expense'
when lower(accounts.account_type_id) in ('income', 'othincome') then 'Income'
when lower(accounts.account_type_id) in ('acctpay', 'credcard', 'deferrevenue', 'longtermliab', 'othcurrliab') then 'Liability'
when lower(accounts.account_type_id) in ('equity', 'retained_earnings', 'net_income') then 'Equity'
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
when lower(accounts.account_type_id) in ('nonposting', 'stat') then 'Other'
else null
end as account_category
from transactions_in_every_calculation_period_w_exchange_rates
Expand Down
34 changes: 21 additions & 13 deletions models/netsuite2/netsuite2__balance_sheet.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ balance_sheet as (
when not accounts.is_balancesheet then 'Retained Earnings'
else accounts.type_name
end as account_type_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'
else accounts.account_type_id
end as account_type_id,
case
when not accounts.is_balancesheet then null
else accounts.account_id
Expand All @@ -72,19 +79,19 @@ balance_sheet as (
end as converted_amount,

case
when lower(accounts.type_name) = 'bank' then 1
when lower(accounts.type_name) = 'accounts receivable' then 2
when lower(accounts.type_name) = 'unbilled receivable' then 3
when lower(accounts.type_name) = 'other current asset' then 4
when lower(accounts.type_name) = 'fixed asset' then 5
when lower(accounts.type_name) = 'other asset' then 6
when lower(accounts.type_name) in ('deferred expense', 'prepaid expense') then 7
when lower(accounts.type_name) = 'accounts payable' then 8
when lower(accounts.type_name) = 'credit card' then 9
when lower(accounts.type_name) = 'other current liability' then 10
when lower(accounts.type_name) = 'long term liability' then 11
when lower(accounts.type_name) = 'deferred revenue' then 12
when lower(accounts.type_name) = 'equity' then 13
when lower(accounts.account_type_id) = 'bank' then 1
when lower(accounts.account_type_id) = 'acctrec' then 2
when lower(accounts.account_type_id) = 'unbilledrec' then 3
when lower(accounts.account_type_id) = 'othcurrasset' then 4
when lower(accounts.account_type_id) = 'fixedasset' then 5
when lower(accounts.account_type_id) = 'othasset' then 6
when lower(accounts.account_type_id) = 'deferexpense' then 7
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
when lower(accounts.account_type_id) = 'acctpay' then 8
when lower(accounts.account_type_id) = 'credcard' then 9
when lower(accounts.account_type_id) = 'othcurrliab' then 10
when lower(accounts.account_type_id) = 'longtermliab' then 11
when lower(accounts.account_type_id) = 'deferrevenue' then 12
when lower(accounts.account_type_id) = 'equity' then 13
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 15
Expand Down Expand Up @@ -136,6 +143,7 @@ balance_sheet as (
'Equity' as account_category,
'Cumulative Translation Adjustment' as account_name,
'Cumulative Translation Adjustment' as account_type_name,
'cumulative_translation_adjustment' as account_type_id,
null as account_id,
null as account_number,

Expand Down
11 changes: 6 additions & 5 deletions models/netsuite2/netsuite2__income_statement.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ income_statement as (
reporting_accounting_periods.is_closed as is_accounting_period_closed,
accounts.name as account_name,
accounts.type_name as account_type_name,
accounts.account_type_id,
accounts.account_id as account_id,
accounts.account_number,
subsidiaries.subsidiary_id,
Expand All @@ -81,11 +82,11 @@ income_statement as (
{{ fivetran_utils.persist_pass_through_columns('departments_pass_through_columns', identifier='departments') }},

transactions_with_converted_amounts.account_category as account_category,
case when lower(accounts.type_name) = 'income' then 1
when lower(accounts.type_name) = 'cost of goods sold' then 2
when lower(accounts.type_name) = 'expense' then 3
when lower(accounts.type_name) = 'other income' then 4
when lower(accounts.type_name) = 'other expense' then 5
case when lower(accounts.account_type_id) = 'income' then 1
when lower(accounts.account_type_id) = 'COGS' then 2
when lower(accounts.account_type_id) = 'expense' then 3
when lower(accounts.account_type_id) = 'othincome' then 4
when lower(accounts.account_type_id) = 'othexpense' then 5
else null
end as income_statement_sort_helper

Expand Down
Loading