diff --git a/backend/database/bespoke.ts b/backend/database/bespoke.ts index a2655841..8970e1ee 100644 --- a/backend/database/bespoke.ts +++ b/backend/database/bespoke.ts @@ -119,4 +119,15 @@ export class BespokeQueries { return { income, expense }; } + + static async getTotalCreditAndDebit(db: DatabaseCore) { + return await db.knex!.raw(` + select + account, + sum(cast(credit as real)) as totalCredit, + sum(cast(debit as real)) as totalDebit + from AccountingLedgerEntry + group by account + `); + } } diff --git a/backend/database/manager.ts b/backend/database/manager.ts index 3d86a612..ad948b29 100644 --- a/backend/database/manager.ts +++ b/backend/database/manager.ts @@ -1,11 +1,12 @@ import fs from 'fs/promises'; +import { DatabaseError } from 'fyo/utils/errors'; import path from 'path'; import { DatabaseDemuxBase, DatabaseMethod } from 'utils/db/types'; import { getSchemas } from '../../schemas'; import { databaseMethodSet, emitMainProcessError, - unlinkIfExists, + unlinkIfExists } from '../helpers'; import patches from '../patches'; import { BespokeQueries } from './bespoke'; @@ -148,7 +149,7 @@ export class DatabaseManager extends DatabaseDemuxBase { } if (!BespokeQueries.hasOwnProperty(method)) { - return; + throw new DatabaseError(`invalid bespoke db function ${method}`); } // @ts-ignore diff --git a/fyo/core/dbHandler.ts b/fyo/core/dbHandler.ts index 70ad8c22..da5fedec 100644 --- a/fyo/core/dbHandler.ts +++ b/fyo/core/dbHandler.ts @@ -14,7 +14,7 @@ import { DatabaseDemuxConstructor, DocValue, DocValueMap, - RawValueMap, + RawValueMap } from './types'; // Return types of Bespoke Queries @@ -23,6 +23,11 @@ type TotalOutstanding = { total: number; outstanding: number }; type Cashflow = { inflow: number; outflow: number; yearmonth: string }[]; type Balance = { balance: number; yearmonth: string }[]; type IncomeExpense = { income: Balance; expense: Balance }; +type TotalCreditAndDebit = { + account: string; + totalCredit: number; + totalDebit: number; +}; export class DatabaseHandler extends DatabaseBase { #fyo: Fyo; @@ -280,6 +285,12 @@ export class DatabaseHandler extends DatabaseBase { )) as IncomeExpense; } + async getTotalCreditAndDebit(): Promise { + return (await this.#demux.callBespoke( + 'getTotalCreditAndDebit' + )) as TotalCreditAndDebit[]; + } + /** * Internal methods */ diff --git a/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts b/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts index e556e95a..bfb0e0c9 100644 --- a/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts +++ b/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts @@ -11,7 +11,6 @@ export class AccountingLedgerEntry extends Doc { credit?: Money; referenceType?: string; referenceName?: string; - balance?: Money; reverted?: boolean; async revert() { @@ -46,7 +45,6 @@ export class AccountingLedgerEntry extends Doc { 'party', 'debit', 'credit', - 'balance', 'referenceName', 'reverted', ], diff --git a/schemas/app/Account.json b/schemas/app/Account.json index 400ee5bd..a45f2889 100644 --- a/schemas/app/Account.json +++ b/schemas/app/Account.json @@ -137,11 +137,5 @@ "default": false } ], - "quickEditFields": [ - "rootType", - "parentAccount", - "accountType", - "isGroup", - "balance" - ] + "quickEditFields": ["rootType", "parentAccount", "accountType", "isGroup"] } diff --git a/schemas/tests/testSchemaBuilder.spec.ts b/schemas/tests/testSchemaBuilder.spec.ts index 7f4e2cbc..56b5b6bf 100644 --- a/schemas/tests/testSchemaBuilder.spec.ts +++ b/schemas/tests/testSchemaBuilder.spec.ts @@ -26,7 +26,7 @@ test('Meta Properties', function (t) { }); test('Field Counts', function (t) { - t.equal(appSchemaMap.Account.fields?.length, 6); + t.equal(appSchemaMap.Account.fields?.length, 5); t.equal(appSchemaMap.JournalEntry.fields?.length, 9); t.equal(appSchemaMap.JournalEntryAccount.fields?.length, 3); t.equal(appSchemaMap.Party.fields?.length, 9); diff --git a/src/pages/ChartOfAccounts.vue b/src/pages/ChartOfAccounts.vue index 3173e374..d9cc4220 100644 --- a/src/pages/ChartOfAccounts.vue +++ b/src/pages/ChartOfAccounts.vue @@ -3,7 +3,10 @@ -
+