diff --git a/reports/GeneralLedger/GeneralLedger.ts b/reports/GeneralLedger/GeneralLedger.ts index 71187800..437984cd 100644 --- a/reports/GeneralLedger/GeneralLedger.ts +++ b/reports/GeneralLedger/GeneralLedger.ts @@ -22,6 +22,7 @@ interface RawLedgerEntry { } interface LedgerEntry { + index?: string; name: number; account: string; date: Date | null; @@ -49,8 +50,8 @@ export class GeneralLedger extends Report { super(fyo); if (!this.toField) { - this.toField = DateTime.now().toISODate(); - this.fromField = DateTime.now().minus({ years: 1 }).toISODate(); + this.toDate = DateTime.now().toISODate(); + this.fromDate = DateTime.now().minus({ years: 1 }).toISODate(); } } @@ -60,13 +61,14 @@ export class GeneralLedger extends Report { } const map = this._getGroupedMap(); + this._setIndexOnEntries(map); const { totalDebit, totalCredit } = this._getTotalsAndSetBalance(map); const consolidated = this._consolidateEntries(map); /** * Push a blank row if last row isn't blank */ - if (consolidated.at(-1)!.name !== -3) { + if (consolidated.at(-1)?.name !== -3) { this._pushBlankEntry(consolidated); } @@ -90,42 +92,52 @@ export class GeneralLedger extends Report { this.reportData = this._convertEntriesToReportData(consolidated); } + _setIndexOnEntries(map: GroupedMap) { + let i = 1; + for (const key of map.keys()) { + for (const entry of map.get(key)!) { + entry.index = String(i); + i = i + 1; + } + } + } + _convertEntriesToReportData(entries: LedgerEntry[]): ReportData { const reportData = []; - const fieldnames = this.columns.map((f) => f.fieldname); for (const entry of entries) { - const row = this._getRowFromEntry(entry, fieldnames); + const row = this._getRowFromEntry(entry, this.columns); reportData.push(row); } return reportData; } - _getRowFromEntry(entry: LedgerEntry, fieldnames: string[]) { + _getRowFromEntry(entry: LedgerEntry, columns: ColumnField[]) { if (entry.name === -3) { - return Array(fieldnames.length).fill({ value: '' }); + return Array(columns.length).fill({ value: '' }); } const row = []; - for (const n of fieldnames) { - let value = entry[n as keyof LedgerEntry]; + for (const col of columns) { + const align = col.align ?? 'left'; + const width = col.width ?? 1; + const fieldname = col.fieldname; + + let value = entry[fieldname as keyof LedgerEntry]; if (value === null || value === undefined) { - row.push({ value: '' }); - continue; + value = ''; } - let align = 'left'; if (value instanceof Date) { value = this.fyo.format(value, FieldTypeEnum.Date); } - if (typeof value === 'number') { - align = 'right'; + if (typeof value === 'number' && fieldname !== 'index') { value = this.fyo.format(value, FieldTypeEnum.Currency); } - if (typeof value === 'boolean' && n === 'reverted' && value) { - value = t`Reverted`; + if (typeof value === 'boolean' && fieldname === 'reverted') { + value = value ? t`Reverted` : ''; } row.push({ @@ -133,6 +145,7 @@ export class GeneralLedger extends Report { bold: entry.name === -2, value, align, + width, }); } @@ -266,7 +279,7 @@ export class GeneralLedger extends Report { 'reverts', ]; - const filters = this._getQueryFilters(); + const filters = {} ?? this._getQueryFilters(); const entries = (await this.fyo.db.getAllRaw( ModelNameEnum.AccountingLedgerEntry, { @@ -338,16 +351,16 @@ export class GeneralLedger extends Report { { label: t`Journal Entries`, value: 'JournalEntry' }, ], - label: t`Reference Type`, + label: t`Ref Type`, fieldname: 'referenceType', - placeholder: t`Reference Type`, + placeholder: t`Ref Type`, default: 'All', }, { fieldtype: 'DynamicLink', - placeholder: t`Reference Name`, + label: t`Ref Name`, references: 'referenceType', - label: t`Reference Name`, + placeholder: t`Ref Name`, fieldname: 'referenceName', }, { @@ -377,19 +390,7 @@ export class GeneralLedger extends Report { fieldname: 'toDate', }, { - fieldtype: 'Check', - default: false, - label: t`Cancelled`, - fieldname: 'reverted', - }, - { - fieldtype: 'Check', - default: false, - label: t`Ascending`, - fieldname: 'ascending', - }, - { - fieldtype: 'Check', + fieldtype: 'Select', default: 'none', label: t`Group By`, fieldname: 'groupBy', @@ -400,11 +401,30 @@ export class GeneralLedger extends Report { { label: t`Reference`, value: 'referenceName' }, ], }, + { + fieldtype: 'Check', + default: false, + label: t`Include Cancelled`, + fieldname: 'reverted', + }, + { + fieldtype: 'Check', + default: false, + label: t`Ascending Order`, + fieldname: 'ascending', + }, ] as Field[]; } getColumns(): ColumnField[] { let columns = [ + { + label: t`#`, + fieldtype: 'Int', + fieldname: 'index', + align: 'right', + width: 0.5, + }, { label: t`Account`, fieldtype: 'Link', @@ -415,41 +435,43 @@ export class GeneralLedger extends Report { label: t`Date`, fieldtype: 'Date', fieldname: 'date', - width: 0.75, }, { label: t`Debit`, fieldtype: 'Currency', fieldname: 'debit', + align: 'right', width: 1.25, }, { label: t`Credit`, fieldtype: 'Currency', fieldname: 'credit', + align: 'right', width: 1.25, }, { label: t`Balance`, fieldtype: 'Currency', fieldname: 'balance', + align: 'right', width: 1.25, }, - { - label: t`Reference Type`, - fieldtype: 'Data', - fieldname: 'referenceType', - }, - { - label: t`Reference Name`, - fieldtype: 'Data', - fieldname: 'referenceName', - }, { label: t`Party`, fieldtype: 'Link', fieldname: 'party', }, + { + label: t`Ref Name`, + fieldtype: 'Data', + fieldname: 'referenceName', + }, + { + label: t`Ref Type`, + fieldtype: 'Data', + fieldname: 'referenceType', + }, { label: t`Reverted`, fieldtype: 'Check', @@ -467,4 +489,12 @@ export class GeneralLedger extends Report { getActions(): Action[] { return []; } + + /** + * TODO: Order by date and then the number + * TODO: Something is wrong with dummy data, there are entries from 2022 Dec + * TODO: Add pagination + * TODO: Always visible scrollbar + * TODO: Extract out list view report to a different component + */ } diff --git a/reports/index.ts b/reports/index.ts index d642dcc8..9a7b3036 100644 --- a/reports/index.ts +++ b/reports/index.ts @@ -1,2 +1,2 @@ import { GeneralLedger } from './GeneralLedger/GeneralLedger'; -export { GeneralLedger }; +export const reports = { GeneralLedger }; diff --git a/reports/types.ts b/reports/types.ts index 8c85141e..0a18d650 100644 --- a/reports/types.ts +++ b/reports/types.ts @@ -7,12 +7,14 @@ export interface ReportCell { bold?: boolean; italics?: boolean; align?: 'left' | 'right' | 'center'; + width?: number; value: string; } export type ReportRow = ReportCell[]; export type ReportData = ReportRow[]; export interface ColumnField extends BaseField { + align?: 'left' | 'right' | 'center'; width?: number; } diff --git a/src/components/Controls/Link.vue b/src/components/Controls/Link.vue index 6c3bc56d..9c064ec6 100644 --- a/src/components/Controls/Link.vue +++ b/src/components/Controls/Link.vue @@ -134,7 +134,7 @@ export default { }, async getFilters() { const { schemaName, fieldname } = this.df; - const getFilters = fyo.models[schemaName].filters[fieldname]; + const getFilters = fyo.models[schemaName]?.filters?.[fieldname]; if (getFilters === undefined) { return {}; diff --git a/src/pages/Report.vue b/src/pages/Report.vue index be290698..8c620771 100644 --- a/src/pages/Report.vue +++ b/src/pages/Report.vue @@ -1,6 +1,7 @@ diff --git a/src/renderer.ts b/src/renderer.ts index a7cbcb6c..51cb3e8c 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -1,6 +1,5 @@ import { ipcRenderer } from 'electron'; import { ConfigKeys } from 'fyo/core/types'; -import { GeneralLedger } from 'reports'; import { IPC_ACTIONS } from 'utils/messages'; import { App as VueApp, createApp } from 'vue'; import App from './App.vue'; @@ -106,6 +105,3 @@ function setOnWindow() { window.fyo = fyo; } } - -// @ts-ignore -window.GL = GeneralLedger; diff --git a/src/router.ts b/src/router.ts index c15a3440..9fc48c6a 100644 --- a/src/router.ts +++ b/src/router.ts @@ -8,7 +8,7 @@ import JournalEntryForm from 'src/pages/JournalEntryForm.vue'; import ListView from 'src/pages/ListView/ListView.vue'; import PrintView from 'src/pages/PrintView/PrintView.vue'; import QuickEditForm from 'src/pages/QuickEditForm.vue'; -// import Report from 'src/pages/Report.vue'; +import Report from 'src/pages/Report.vue'; import Settings from 'src/pages/Settings/Settings.vue'; import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'; import { fyo } from './initFyo'; @@ -87,14 +87,12 @@ const routes: RouteRecordRaw[] = [ component: PrintView, props: true, }, - /* { path: '/report/:reportName', name: 'Report', component: Report, props: true, }, - */ { path: '/chart-of-accounts', name: 'Chart Of Accounts', diff --git a/src/utils/sidebarConfig.ts b/src/utils/sidebarConfig.ts index cd8fa1af..6a7b6634 100644 --- a/src/utils/sidebarConfig.ts +++ b/src/utils/sidebarConfig.ts @@ -132,18 +132,18 @@ function getCompleteSidebar(): SidebarConfig { }, ], }, - /* { label: t`Reports`, name: t`reports`, icon: 'reports', - route: '/report/general-ledger', + route: '/report/GeneralLedger', items: [ { label: t`General Ledger`, name: 'general-ledger', - route: '/report/general-ledger', + route: '/report/GeneralLedger', }, + /* { label: t`Profit And Loss`, name: 'profit-and-loss', @@ -171,9 +171,9 @@ function getCompleteSidebar(): SidebarConfig { route: '/report/gstr-2', hidden: () => fyo.singles.AccountingSettings!.country !== 'India', }, + */ ], }, - */ { label: t`Setup`, name: t`setup`, diff --git a/utils/index.ts b/utils/index.ts index 9ee0bbfc..d6cd52a4 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -104,3 +104,22 @@ export function invertMap(map: Record): Record { return inverted; } + +export function time(func: (...args: K[]) => T, ...args: K[]): T { + const name = func.name; + console.time(name); + const stuff = func(...args); + console.timeEnd(name); + return stuff; +} + +export async function timeAsync( + func: (...args: K[]) => Promise, + ...args: K[] +): Promise { + const name = func.name; + console.time(name); + const stuff = await func(...args); + console.timeEnd(name); + return stuff; +}