From 1e35635170c7698cc9e11e64c443c64915e05d63 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Mon, 16 May 2022 23:49:22 +0530 Subject: [PATCH] incr: get cash flow to display --- backend/database/bespoke.ts | 2 +- reports/Cashflow/Cashflow.ts | 52 ------- src/components/Charts/LineChart.vue | 11 +- src/pages/Dashboard/Cashflow.vue | 203 ++++++++++++---------------- src/pages/Dashboard/Dashboard.vue | 9 +- src/utils/chart.ts | 13 +- src/utils/misc.ts | 4 +- 7 files changed, 106 insertions(+), 188 deletions(-) delete mode 100644 reports/Cashflow/Cashflow.ts diff --git a/backend/database/bespoke.ts b/backend/database/bespoke.ts index 64db95ba..92315508 100644 --- a/backend/database/bespoke.ts +++ b/backend/database/bespoke.ts @@ -67,7 +67,7 @@ export class BespokeQueries { .select('name') .where('accountType', 'in', ['Cash', 'Bank']) .andWhere('isGroup', false); - const dateAsMonthYear = db.knex!.raw('strftime("%m-%Y", ??)', 'date'); + const dateAsMonthYear = db.knex!.raw('strftime("%Y-%m", ??)', 'date'); return await db.knex!('AccountingLedgerEntry') .where('reverted', false) .sum({ diff --git a/reports/Cashflow/Cashflow.ts b/reports/Cashflow/Cashflow.ts deleted file mode 100644 index 568b044a..00000000 --- a/reports/Cashflow/Cashflow.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Fyo } from 'fyo'; -import { DateTime } from 'luxon'; -import { - getFiscalYear, - getPeriodList, -} from 'reports/FinancialStatements/financialStatements'; -import { FinancialStatementOptions } from 'reports/types'; - -class Cashflow { - fyo: Fyo; - constructor(fyo: Fyo) { - this.fyo = fyo; - } - async run(options: FinancialStatementOptions) { - const { fromDate, toDate, periodicity } = options; - const res = await this.fyo.db.getCashflow(fromDate, toDate); - const fiscalYear = await getFiscalYear(this.fyo); - const periodList = getPeriodList( - fromDate, - toDate, - periodicity!, - fiscalYear - ); - - const data = periodList.map((periodKey) => { - const monthYear = this.getMonthYear(periodKey, 'MMM yyyy'); - const cashflowForPeriod = res.find((d) => d['month-year'] === monthYear); - - if (cashflowForPeriod) { - return { ...cashflowForPeriod, periodKey }; - } - - return { - inflow: 0, - outflow: 0, - periodKey, - 'month-year': monthYear, - }; - }); - - return { - data, - periodList, - }; - } - - getMonthYear(periodKey: string, format: string) { - return DateTime.fromFormat(periodKey, format).toFormat('MM-yyyy'); - } -} - -export default Cashflow; diff --git a/src/components/Charts/LineChart.vue b/src/components/Charts/LineChart.vue index 3c30bb83..9e17ad8f 100644 --- a/src/components/Charts/LineChart.vue +++ b/src/components/Charts/LineChart.vue @@ -26,7 +26,7 @@ /> -