Skip to content

Commit

Permalink
refactor: standardize account & account set types used in reports (#204)
Browse files Browse the repository at this point in the history
* refactor: rename ChartOfAccountsAccountSet in admin schema

* feat: add 'account_set_and_balance' ledger service function

* refactor: change gql names for accounts with balances

* refactor: rename gql TrialBalance object

* refactor: rename AccountSetMemberWithBalance in gql layer

* refactor: rename 'chart_of_accounts_category_account' function

* refactor: rename CategorySubAccount types in ledger service

* refactor: rename 'account_set...' ledger service functions

* refactor: rename types with 'MemberBalance' in ledger service

* refactor: rename 'member_balances' to 'sub_accounts'

* refactor: nest trial-balance balances in cala query

* refactor: implement From traits for LedgerAccountBalancesByCurrency

* refactor: add 'accounts' name to trial-balance cala query

* refactor: add 'details' fragments to trial-balance cala query

* refactor: add id to 'LedgerAccountSetAndSubAccountsWithBalance' type

* refactor: add new type for TrialBalance top-level report

* feat: implement 'paginated_account_set_and_sub_accounts_with_balance'
ledger service method

* chore: change 'AccountSetAndSubAccounts' field to use pagination

* feat: add 'accountSetWithBalance' query to admin graphql

* refactor: rename account-set query in bats

* test: add checks for account-set-details-with-balance query
  • Loading branch information
vindard authored Jul 19, 2024
1 parent de469cb commit 8a1e2b0
Show file tree
Hide file tree
Showing 23 changed files with 1,220 additions and 486 deletions.
6 changes: 3 additions & 3 deletions apps/admin-panel/app/chart-of-accounts/accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import React from "react"
import { IoCaretDownSharp, IoCaretForwardSharp } from "react-icons/io5"

import {
ChartOfAccountsSubAccount,
AccountSetSubAccount,
useChartOfAccountsAccountSetQuery,
} from "@/lib/graphql/generated"
import { TableCell, TableRow } from "@/components/primitive/table"

type AccountProps = {
depth?: number
account: ChartOfAccountsSubAccount
account: AccountSetSubAccount
}

const SubAccountsForAccountSet: React.FC<AccountProps> = ({ account, depth = 0 }) => {
Expand All @@ -22,7 +22,7 @@ const SubAccountsForAccountSet: React.FC<AccountProps> = ({ account, depth = 0 }
},
})

const subAccounts = data?.chartOfAccountsAccountSet?.subAccounts.edges
const subAccounts = data?.accountSet?.subAccounts.edges

return subAccounts?.map((subAccount) => (
<Account key={subAccount.node.id} account={subAccount.node} depth={depth + 1} />
Expand Down
4 changes: 2 additions & 2 deletions apps/admin-panel/app/trial-balance/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function TrialBalancePage() {
const { data, loading } = useGetTrialBalanceQuery()

const balance = data?.trialBalance?.balance
const memberBalances = data?.trialBalance?.memberBalances
const subAccounts = data?.trialBalance?.subAccounts

if (loading || !balance) return <div>Loading...</div>

Expand Down Expand Up @@ -92,7 +92,7 @@ function TrialBalancePage() {
<TableHead className="text-right">Net</TableHead>
</TableHeader>
<TableBody>
{memberBalances?.map((memberBalance, index) => (
{subAccounts?.map((memberBalance, index) => (
<TableRow key={index}>
<TableCell>{memberBalance.name}</TableCell>
<TableCell className="w-48">
Expand Down
159 changes: 101 additions & 58 deletions apps/admin-panel/lib/graphql/generated/index.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { gql } from "@apollo/client"

gql`
query ChartOfAccountsAccountSet($accountSetId: UUID!, $first: Int!, $after: String) {
chartOfAccountsAccountSet(accountSetId: $accountSetId) {
accountSet(accountSetId: $accountSetId) {
id
name
subAccounts(first: $first, after: $after) {
edges {
Expand Down
6 changes: 3 additions & 3 deletions apps/admin-panel/lib/graphql/query/get-trial-balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ gql`
balance {
...balancesByCurrency
}
memberBalances {
... on AccountBalance {
subAccounts {
... on AccountWithBalance {
name
balance {
...balancesByCurrency
}
}
... on AccountSetBalance {
... on AccountSetWithBalance {
name
balance {
...balancesByCurrency
Expand Down
88 changes: 88 additions & 0 deletions bats/admin-gql/account-set-details-with-balance.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
query AccountSet($accountSetId: UUID!, $first: Int!, $after: String) {
accountSetWithBalance(accountSetId: $accountSetId) {
id
name
balance {
...balancesByCurrency
}
subAccounts(first: $first, after: $after) {
edges {
cursor
node {
__typename
... on AccountWithBalance {
__typename
id
name
balance {
...balancesByCurrency
}
}
... on AccountSetWithBalance {
__typename
id
name
hasSubAccounts
balance {
...balancesByCurrency
}
}
}
}
}
}
}

fragment balancesByCurrency on AccountBalancesByCurrency {
btc: btc {
...btcBalances
}
usd: usd {
...usdBalances
}
usdt: usdt {
...usdBalances
}
}

fragment btcBalances on LayeredBtcAccountBalances {
all {
...btcLayers
}
settled {
...btcLayers
}
pending {
...btcLayers
}
encumbrance {
...btcLayers
}
}

fragment usdBalances on LayeredUsdAccountBalances {
all {
...usdLayers
}
settled {
...usdLayers
}
pending {
...usdLayers
}
encumbrance {
...usdLayers
}
}

fragment usdLayers on UsdAccountBalance {
netDebit
debit
credit
}

fragment btcLayers on BtcAccountBalance {
netDebit
debit
credit
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
query ChartOfAccountsAccountSet(
$accountSetId: UUID!
$first: Int!
$after: String
) {
chartOfAccountsAccountSet(accountSetId: $accountSetId) {
query AccountSetDetails($accountSetId: UUID!, $first: Int!, $after: String) {
accountSet(accountSetId: $accountSetId) {
name
subAccounts(first: $first, after: $after) {
edges {
Expand Down
6 changes: 3 additions & 3 deletions bats/admin-gql/trial-balance.gql
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ query TrialBalance {
balance {
...balancesByCurrency
}
memberBalances {
... on AccountBalance {
subAccounts {
... on AccountWithBalance {
name
balance {
...balancesByCurrency
}
}
... on AccountSetBalance {
... on AccountSetWithBalance {
name
balance {
...balancesByCurrency
Expand Down
23 changes: 18 additions & 5 deletions bats/chart-of-accounts.bats
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ teardown_file() {
first: 100,
}'
)
exec_admin_graphql 'chart-of-accounts-account-set' "$variables"
num_accounts=$(graphql_output '.data.chartOfAccountsAccountSet.subAccounts.edges | length')
first_cursor=$(graphql_output '.data.chartOfAccountsAccountSet.subAccounts.edges[0].cursor')
exec_admin_graphql 'account-set-details' "$variables"
num_accounts=$(graphql_output '.data.accountSet.subAccounts.edges | length')
first_cursor=$(graphql_output '.data.accountSet.subAccounts.edges[0].cursor')
[[ "$num_accounts" -gt "0" ]] || exit 1

exec_admin_graphql 'account-set-details-with-balance' "$variables"
num_accounts_with_balance=$(graphql_output '.data.accountSetWithBalance.subAccounts.edges | length')
first_cursor_with_balance=$(graphql_output '.data.accountSetWithBalance.subAccounts.edges[0].cursor')
btc_balance=$(graphql_output '.data.accountSetWithBalance.subAccounts.edges[0].node.balance.btc.all.netDebit')
[[ "$num_accounts_with_balance" -gt "0" ]] || exit 1
[[ "$btc_balance" == "0" ]] || exit 1
[[ "$first_cursor" == "$first_cursor_with_balance" ]] || exit 1

# Fetch paginated page
variables=$(
jq -n \
Expand All @@ -55,8 +63,13 @@ teardown_file() {
after: $after
}'
)
exec_admin_graphql 'chart-of-accounts-account-set' "$variables"
num_accounts_paginated=$(graphql_output '.data.chartOfAccountsAccountSet.subAccounts.edges | length')
exec_admin_graphql 'account-set-details' "$variables"
num_accounts_paginated=$(graphql_output '.data.accountSet.subAccounts.edges | length')
[[ "$num_accounts_paginated" -gt "0" ]] || exit 1
[[ "$num_accounts_paginated" -lt "$num_accounts" ]] || exit 1

exec_admin_graphql 'account-set-details-with-balance' "$variables"
num_accounts_paginated_with_balance=$(graphql_output '.data.accountSetWithBalance.subAccounts.edges | length')
[[ "$num_accounts_paginated_with_balance" -gt "0" ]] || exit 1
[[ "$num_accounts_paginated_with_balance" -lt "$num_accounts_with_balance" ]] || exit 1
}
Loading

0 comments on commit 8a1e2b0

Please sign in to comment.