# Generate reports Source: https://fragment.dev/guides/generate-reports [Documentation index](https://fragment.dev/llms.txt) Fragment supports queries for generating common financial reports. [Visual: generateReports. View on the HTML page.](https://fragment.dev/guides/generate-reports) ## Balance sheet A balance sheet reports the net worth of a business at the end of a reporting period. ```graphql title="Balance sheet query" query GetBalanceSheet( $ledgerIk: SafeString! $balanceAtEndOf: LastMoment! $accountsFilter: LedgerAccountsFilterSet! $after: String ) { ledger(ledger: { ik: $ledgerIk }) { ledgerAccounts(filter: $accountsFilter, after: $after) { nodes { id name type balance(at: $balanceAtEndOf) } pageInfo { hasNextPage endCursor } } } } ``` ```json title="Balance sheet parameters" { "ledgerIk": "ik-used-to-create-ledger", "accountsFilter": { "type": { "in": ["asset", "liability"] } }, "balanceAtEndOf": "1969", "after": "{{data.ledger.ledgerAccounts.pageInfo.endCursor}}" } ``` Generate a balance sheet by querying `balance` on all `asset` and `liability` Ledger Accounts. Providing a [`LastMoment`](https://fragment.dev/markdown/api-reference/ledger-types.md#scalars-and-enums-lastmoment) to the `at` parameter on `balance` returns the balance at the end of that period. Values provided to `in` operators are OR'd, so both `asset` and `liability` accounts are returned. ## Income statement An income statement reports how a business's net worth changed over the course of a reporting period. ```graphql title="Income statement query" query GetIncomeStatement( $ledgerIk: SafeString! $balanceChangeDuring: Period! $accountsFilter: LedgerAccountsFilterSet! $after: String ) { ledger(ledger: { ik: $ledgerIk }) { ledgerAccounts(filter: $accountsFilter, after: $after) { nodes { path name type balanceChange(period: $balanceChangeDuring) } pageInfo { hasNextPage endCursor } } } } ``` ```json title="Income statement parameters" { "ledgerIk": "ik-used-to-create-ledger", "accountsFilter": { "type": { "in": ["income", "expense"] } }, "balanceChangeDuring": "1969", "after": "{{data.ledger.ledgerAccounts.pageInfo.endCursor}}" } ``` Generate an income statement by querying `balanceChange` on all `income` and `expense` Ledger Accounts. Providing a [`Period`](https://fragment.dev/markdown/api-reference/ledger-types.md#scalars-and-enums-period) to the `period` parameter on `balanceChange` retrieves the difference in the Ledger Account's balance between the start and end of that period. ## Account statement An account statement reports how a Ledger Account changed over the course of a reporting period. It contains a Ledger Account's starting balance, ending balance and all Ledger Lines posted to it. ```graphql title="Monthly account statement query" query GetAccountStatement( $accountMatch: LedgerAccountMatchInput! $startingBalanceAtEndOf: LastMoment! $endingBalanceAtEndOf: LastMoment! $linesFilter: LedgerLinesFilterSet! $after: String ) { ledgerAccount(ledgerAccount: $accountMatch) { path name type startingBalance: balance(at: $startingBalanceAtEndOf) endingBalance: balance(at: $endingBalanceAtEndOf) lines(filter: $linesFilter, after: $after) { nodes { id key posted description amount ledgerEntryId } pageInfo { hasNextPage endCursor } } } } ``` ```json title="Monthly account statement variables" { "accountMatch": { "ledger": { "ik": "ik-used-to-create-ledger" }, "path": "liabilities/customer-deposits/customer:123" }, "linesFilter": { "posted": { "after": "1969-07-01T00:00:00.000Z", "before": "1969-07-30T23:59:59.999Z" } }, "startingBalanceAtEndOf": "1969-06", "endingBalanceAtEndOf": "1969-07", "after": "{{data.ledgerAccount.lines.pageInfo.endCursor}}" } ``` Generate an account statement by querying for `balance` and `lines` on a Ledger Account. Get the starting balance by passing a [`DateTime`](https://fragment.dev/markdown/api-reference/ledger-types.md#scalars-and-enums-datetime) to the `at` parameter on `balance`. Use a GraphQL alias to make multiple `balance` queries within one request. To get all Ledger Lines that were posted during the reporting period, use the `filter` parameter on `lines`. The `after` and `before` filters are inclusive, so use timestamps for the first and last moments of the reporting period. ## Journal export A journal export lists all Ledger Entries posted to a Ledger during a reporting period. ```graphql title="Journal export query" query GetJournalExport( $ledgerIk: SafeString! $entriesFilter: LedgerEntriesFilterSet! $after: String ) { ledger(ledger: { ik: $ledgerIk }) { ledgerEntries(filter: $entriesFilter, after: $after) { nodes { id type posted description lines { nodes { id description account { name path type } amount } } } pageInfo { hasNextPage endCursor } } } } ``` ```json title="Journal export variables" { "ledgerIk": "ik-used-to-create-ledger", "entriesFilter": { "posted": { "after": "1969-01-01T00:00:00.000Z", "before": "1969-03-31T23:59:59.999Z" } }, "after": "{{data.ledger.ledgerEntries.pageInfo.endCursor}}" } ``` Generate a journal export by listing Ledger Entries. For each Ledger Entry, include its Ledger Lines and their Ledger Accounts. This can be a long list, so query `pageInfo` to get a [pagination cursor](https://fragment.dev/markdown/guides/query-data.md#basics-pagination). It can be passed to the `after` parameter on `ledgerEntries` to page through the results.