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 @@
-
- -
- -
-
- - +
+ +
+ +
+
+ +
@@ -20,7 +18,7 @@ diff --git a/src/pages/Dashboard/Expenses.vue b/src/pages/Dashboard/Expenses.vue index 2f74a7e3..9e653d6e 100644 --- a/src/pages/Dashboard/Expenses.vue +++ b/src/pages/Dashboard/Expenses.vue @@ -7,9 +7,11 @@
-
+ +
+
@@ -18,8 +20,12 @@ @mouseover="active = i" @mouseleave="active = null" > -
-
{{ d.account }}
+
+

+ {{ d.account }} +

{{ fyo.format(d.total, 'Currency') }} @@ -38,6 +44,8 @@ @change="(value) => (active = value)" />

+ +
import { fyo } from 'src/initFyo'; import theme from 'src/theme'; -import { getDatesAndPeriodicity } from 'src/utils/misc'; +import { getDatesAndPeriodList } from 'src/utils/misc'; import DonutChart from '../../components/Charts/DonutChart.vue'; import PeriodSelector from './PeriodSelector'; import SectionHeader from './SectionHeader'; @@ -94,8 +102,12 @@ export default { }, methods: { async setData() { - const { fromDate, toDate } = await getDatesAndPeriodicity(this.period); - let topExpenses = await fyo.db.getTopExpenses(fromDate, toDate); + const { fromDate, toDate } = await getDatesAndPeriodList(this.period); + let topExpenses = await fyo.db.getTopExpenses( + fromDate.toISO(), + toDate.toISO() + ); + const shades = [ { class: 'bg-gray-800', hex: theme.backgroundColor.gray['800'] }, { class: 'bg-gray-600', hex: theme.backgroundColor.gray['600'] }, diff --git a/src/pages/Dashboard/UnpaidInvoices.vue b/src/pages/Dashboard/UnpaidInvoices.vue index 75499c04..b15a040f 100644 --- a/src/pages/Dashboard/UnpaidInvoices.vue +++ b/src/pages/Dashboard/UnpaidInvoices.vue @@ -1,5 +1,5 @@