From 67f35b5f790aebcecaebd8513be9ca455306a56d Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 17 May 2022 13:38:12 +0530 Subject: [PATCH] incr: get top expenses to display --- backend/database/bespoke.ts | 10 ++++------ src/pages/Dashboard/Dashboard.vue | 22 +++++++++------------- src/pages/Dashboard/Expenses.vue | 26 +++++++++++++++++++------- src/pages/Dashboard/UnpaidInvoices.vue | 6 +++--- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/backend/database/bespoke.ts b/backend/database/bespoke.ts index bd5cc50d..76316dfc 100644 --- a/backend/database/bespoke.ts +++ b/backend/database/bespoke.ts @@ -32,13 +32,11 @@ export class BespokeQueries { const topExpenses = await db .knex!.select({ - total: db.knex!.raw('sum(cast(?? as real)) - sum(cast(?? as real))', [ - 'debit', - 'credit', - ]), + total: db.knex!.raw('sum(cast(debit as real) - cast(credit as real))'), }) .select('account') .from('AccountingLedgerEntry') + .where('reverted', false) .where('account', 'in', expenseAccounts) .whereBetween('date', [fromDate, toDate]) .groupBy('account') @@ -89,7 +87,7 @@ export class BespokeQueries { ) { const income = await db.knex!.raw( ` - select sum(credit - debit) as balance, strftime('%Y-%m', date) as yearmonth + select sum(cast(credit as real) - cast(debit as real)) as balance, strftime('%Y-%m', date) as yearmonth from AccountingLedgerEntry where reverted = false and @@ -105,7 +103,7 @@ export class BespokeQueries { const expense = await db.knex!.raw( ` - select sum(debit - credit) as balance, strftime('%Y-%m', date) as yearmonth + select sum(cast(debit as real) - cast(credit as real)) as balance, strftime('%Y-%m', date) as yearmonth from AccountingLedgerEntry where reverted = false and diff --git a/src/pages/Dashboard/Dashboard.vue b/src/pages/Dashboard/Dashboard.vue index ff95573f..96c5ee17 100644 --- a/src/pages/Dashboard/Dashboard.vue +++ b/src/pages/Dashboard/Dashboard.vue @@ -2,16 +2,14 @@