From 3cdba15b81ce4ddbf66c71d0306ea9cde6645074 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Fri, 13 May 2022 19:21:26 +0530 Subject: [PATCH] fix: dynamic link ref - gl ordering - report filtering - dummy dates - few other things --- dummy/helpers.ts | 2 +- dummy/index.ts | 18 ++++++---- reports/GeneralLedger/GeneralLedger.ts | 44 ++++++++++++++----------- reports/Report.ts | 9 +++-- schemas/app/AccountingLedgerEntry.json | 2 +- schemas/types.ts | 2 ++ src/components/Controls/DynamicLink.vue | 20 +++++++++-- src/components/Controls/Link.vue | 7 ++-- src/components/Dropdown.vue | 6 +++- src/pages/DatabaseSelector.vue | 24 ++++++++++++-- src/pages/Report.vue | 6 ++++ utils/index.ts | 4 ++- 12 files changed, 106 insertions(+), 38 deletions(-) diff --git a/dummy/helpers.ts b/dummy/helpers.ts index 462a94b7..2012d801 100644 --- a/dummy/helpers.ts +++ b/dummy/helpers.ts @@ -40,7 +40,7 @@ export function getRandomDates(count: number, months: number): Date[] { let endDate = DateTime.now(); if (months !== 0) { const back = endDate.minus({ months }); - endDate = DateTime.local(endDate.year, back.month, back.daysInMonth); + endDate = DateTime.local(back.year, back.month, back.daysInMonth); } const dates: Date[] = []; diff --git a/dummy/index.ts b/dummy/index.ts index b269b4c6..7eff9882 100644 --- a/dummy/index.ts +++ b/dummy/index.ts @@ -170,6 +170,17 @@ async function getPayments(fyo: Fyo, invoices: Invoice[]) { return payments; } +function getSalesInvoiceDates(years: number, baseCount: number): Date[] { + const dates: Date[] = []; + for (const months of range(0, years * 12)) { + const flow = getFlowConstant(months); + const count = Math.ceil(flow * baseCount * (Math.random() * 0.25 + 0.75)); + dates.push(...getRandomDates(count, months)); + } + + return dates; +} + async function getSalesInvoices( fyo: Fyo, years: number, @@ -184,12 +195,7 @@ async function getSalesInvoices( * Get certain number of entries for each month of the count * of years. */ - let dates: Date[] = []; - for (const months of range(0, years * 12)) { - const flow = getFlowConstant(months); - const count = Math.ceil(flow * baseCount * (Math.random() * 0.25 + 0.75)); - dates = dates.concat(getRandomDates(count, months)); - } + const dates = getSalesInvoiceDates(years, baseCount); /** * For each date create a Sales Invoice. diff --git a/reports/GeneralLedger/GeneralLedger.ts b/reports/GeneralLedger/GeneralLedger.ts index c37c4740..f26d0104 100644 --- a/reports/GeneralLedger/GeneralLedger.ts +++ b/reports/GeneralLedger/GeneralLedger.ts @@ -3,7 +3,7 @@ import { Action } from 'fyo/model/types'; import { DateTime } from 'luxon'; import { ModelNameEnum } from 'models/types'; import { Report } from 'reports/Report'; -import { ColumnField, ReportData } from 'reports/types'; +import { ColumnField, ReportData, ReportRow } from 'reports/types'; import { Field, FieldTypeEnum, RawValue } from 'schemas/types'; import { QueryFilter } from 'utils/db/types'; @@ -56,11 +56,13 @@ export class GeneralLedger extends Report { } async setReportData(filter?: string) { + let sort = true; if (filter !== 'grouped' || this._rawData.length === 0) { await this._setRawData(); + sort = false; } - const map = this._getGroupedMap(); + const map = this._getGroupedMap(sort); this._setIndexOnEntries(map); const { totalDebit, totalCredit } = this._getTotalsAndSetBalance(map); const consolidated = this._consolidateEntries(map); @@ -112,12 +114,15 @@ export class GeneralLedger extends Report { return reportData; } - _getRowFromEntry(entry: LedgerEntry, columns: ColumnField[]) { + _getRowFromEntry(entry: LedgerEntry, columns: ColumnField[]): ReportRow { if (entry.name === -3) { - return Array(columns.length).fill({ value: '' }); + return columns.map((c) => ({ + value: '', + width: c.width ?? 1, + })) as ReportRow; } - const row = []; + const row: ReportRow = []; for (const col of columns) { const align = col.align ?? 'left'; const width = col.width ?? 1; @@ -138,6 +143,8 @@ export class GeneralLedger extends Report { if (typeof value === 'boolean' && fieldname === 'reverted') { value = value ? t`Reverted` : ''; + } else { + value = String(value); } row.push({ @@ -231,7 +238,7 @@ export class GeneralLedger extends Report { return { totalDebit, totalCredit }; } - _getGroupedMap(): GroupedMap { + _getGroupedMap(sort: boolean): GroupedMap { let groupBy: keyof LedgerEntry = 'referenceName'; if (this.groupBy !== 'none') { groupBy = this.groupBy; @@ -240,13 +247,15 @@ export class GeneralLedger extends Report { /** * Sort rows by ascending or descending */ - this._rawData.sort((a, b) => { - if (this.ascending) { - return a.name - b.name; - } + if (sort) { + this._rawData.sort((a, b) => { + if (this.ascending) { + return +a.date! - +b.date!; + } - return b.name - a.name; - }); + return +b.date! - +a.date!; + }); + } /** * Map remembers the order of insertion @@ -285,6 +294,8 @@ export class GeneralLedger extends Report { { fields, filters, + orderBy: 'date', + order: this.ascending ? 'asc' : 'desc', } )) as RawLedgerEntry[]; @@ -309,7 +320,7 @@ export class GeneralLedger extends Report { const filters: QueryFilter = {}; const stringFilters = ['account', 'party', 'referenceName']; - for (const sf in stringFilters) { + for (const sf of stringFilters) { const value = this[sf]; if (value === undefined) { continue; @@ -361,6 +372,7 @@ export class GeneralLedger extends Report { label: t`Ref Name`, references: 'referenceType', placeholder: t`Ref Name`, + emptyMessage: t`Change Ref Type`, fieldname: 'referenceName', }, { @@ -489,10 +501,4 @@ 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: Always visible scrollbar - */ } diff --git a/reports/Report.ts b/reports/Report.ts index 6fada474..243d511f 100644 --- a/reports/Report.ts +++ b/reports/Report.ts @@ -42,7 +42,7 @@ export abstract class Report extends Observable { async set(key: string, value: RawValue) { const field = this.filters.find((f) => f.fieldname === key); - if (field === undefined || value === undefined) { + if (field === undefined) { return; } @@ -51,7 +51,12 @@ export abstract class Report extends Observable { return; } - this[key] = value; + if (getIsNullOrUndef(value)) { + delete this[key]; + } else { + this[key] = value; + } + this.columns = this.getColumns(); await this.setReportData(key); } diff --git a/schemas/app/AccountingLedgerEntry.json b/schemas/app/AccountingLedgerEntry.json index f59f8141..5c59ab65 100644 --- a/schemas/app/AccountingLedgerEntry.json +++ b/schemas/app/AccountingLedgerEntry.json @@ -8,7 +8,7 @@ { "fieldname": "date", "label": "Date", - "fieldtype": "Date", + "fieldtype": "Datetime", "readOnly": true }, { diff --git a/schemas/types.ts b/schemas/types.ts index c75f2278..113232d1 100644 --- a/schemas/types.ts +++ b/schemas/types.ts @@ -42,6 +42,7 @@ export interface OptionField extends BaseField { | FieldTypeEnum.AutoComplete | FieldTypeEnum.Color; options: SelectOption[]; + emptyMessage?: string; allowCustom?: boolean; } @@ -52,6 +53,7 @@ export interface TargetField extends BaseField { export interface DynamicLinkField extends BaseField { fieldtype: FieldTypeEnum.DynamicLink; + emptyMessage?: string; references: string; // Reference to an option field that links to schema } diff --git a/src/components/Controls/DynamicLink.vue b/src/components/Controls/DynamicLink.vue index bbd80669..08fc88ec 100644 --- a/src/components/Controls/DynamicLink.vue +++ b/src/components/Controls/DynamicLink.vue @@ -1,8 +1,10 @@ diff --git a/src/pages/Report.vue b/src/pages/Report.vue index d6e05c27..41e93c6f 100644 --- a/src/pages/Report.vue +++ b/src/pages/Report.vue @@ -37,6 +37,7 @@