mirror of
https://github.com/frappe/books.git
synced 2024-12-22 19:09:01 +00:00
incr: speed things up by like 20x or somthn
This commit is contained in:
parent
1e88c5511f
commit
c95473c6b0
@ -1,9 +1,7 @@
|
|||||||
import { Fyo, t } from 'fyo';
|
import { Fyo, t } from 'fyo';
|
||||||
import { Action } from 'fyo/model/types';
|
import { Action } from 'fyo/model/types';
|
||||||
import { isPesa } from 'fyo/utils';
|
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { ModelNameEnum } from 'models/types';
|
import { ModelNameEnum } from 'models/types';
|
||||||
import Money from 'pesa/dist/types/src/money';
|
|
||||||
import { Report } from 'reports/Report';
|
import { Report } from 'reports/Report';
|
||||||
import { ColumnField, ReportData } from 'reports/types';
|
import { ColumnField, ReportData } from 'reports/types';
|
||||||
import { Field, FieldTypeEnum, RawValue } from 'schemas/types';
|
import { Field, FieldTypeEnum, RawValue } from 'schemas/types';
|
||||||
@ -27,9 +25,9 @@ interface LedgerEntry {
|
|||||||
name: number;
|
name: number;
|
||||||
account: string;
|
account: string;
|
||||||
date: Date | null;
|
date: Date | null;
|
||||||
debit: Money | null;
|
debit: number | null;
|
||||||
credit: Money | null;
|
credit: number | null;
|
||||||
balance: Money | null;
|
balance: number | null;
|
||||||
referenceType: string;
|
referenceType: string;
|
||||||
referenceName: string;
|
referenceName: string;
|
||||||
party: string;
|
party: string;
|
||||||
@ -58,22 +56,12 @@ export class GeneralLedger extends Report {
|
|||||||
|
|
||||||
async setReportData(filter?: string) {
|
async setReportData(filter?: string) {
|
||||||
if (filter !== 'grouped' || this._rawData.length === 0) {
|
if (filter !== 'grouped' || this._rawData.length === 0) {
|
||||||
console.time('_setRawData');
|
|
||||||
await this._setRawData();
|
await this._setRawData();
|
||||||
console.timeEnd('_setRawData');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.time('_getGroupedMap');
|
|
||||||
const map = this._getGroupedMap();
|
const map = this._getGroupedMap();
|
||||||
console.timeEnd('_getGroupedMap');
|
|
||||||
|
|
||||||
console.time('_getTotalsAndSetBalance');
|
|
||||||
const { totalDebit, totalCredit } = this._getTotalsAndSetBalance(map);
|
const { totalDebit, totalCredit } = this._getTotalsAndSetBalance(map);
|
||||||
console.timeEnd('_getTotalsAndSetBalance');
|
|
||||||
|
|
||||||
console.time('_consolidateEntries');
|
|
||||||
const consolidated = this._consolidateEntries(map);
|
const consolidated = this._consolidateEntries(map);
|
||||||
console.timeEnd('_consolidateEntries');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push a blank row if last row isn't blank
|
* Push a blank row if last row isn't blank
|
||||||
@ -91,7 +79,7 @@ export class GeneralLedger extends Report {
|
|||||||
date: null,
|
date: null,
|
||||||
debit: totalDebit,
|
debit: totalDebit,
|
||||||
credit: totalCredit,
|
credit: totalCredit,
|
||||||
balance: totalDebit.sub(totalCredit),
|
balance: totalDebit - totalCredit,
|
||||||
referenceType: '',
|
referenceType: '',
|
||||||
referenceName: '',
|
referenceName: '',
|
||||||
party: '',
|
party: '',
|
||||||
@ -99,9 +87,7 @@ export class GeneralLedger extends Report {
|
|||||||
reverts: '',
|
reverts: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
console.time('_convertEntriesToReportData');
|
|
||||||
this.reportData = this._convertEntriesToReportData(consolidated);
|
this.reportData = this._convertEntriesToReportData(consolidated);
|
||||||
console.timeEnd('_convertEntriesToReportData');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_convertEntriesToReportData(entries: LedgerEntry[]): ReportData {
|
_convertEntriesToReportData(entries: LedgerEntry[]): ReportData {
|
||||||
@ -133,7 +119,7 @@ export class GeneralLedger extends Report {
|
|||||||
value = this.fyo.format(value, FieldTypeEnum.Date);
|
value = this.fyo.format(value, FieldTypeEnum.Date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPesa(value)) {
|
if (typeof value === 'number') {
|
||||||
align = 'right';
|
align = 'right';
|
||||||
value = this.fyo.format(value, FieldTypeEnum.Currency);
|
value = this.fyo.format(value, FieldTypeEnum.Currency);
|
||||||
}
|
}
|
||||||
@ -186,20 +172,20 @@ export class GeneralLedger extends Report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getTotalsAndSetBalance(map: GroupedMap) {
|
_getTotalsAndSetBalance(map: GroupedMap) {
|
||||||
let totalDebit = this.fyo.pesa(0);
|
let totalDebit = 0;
|
||||||
let totalCredit = this.fyo.pesa(0);
|
let totalCredit = 0;
|
||||||
|
|
||||||
for (const key of map.keys()) {
|
for (const key of map.keys()) {
|
||||||
let balance = this.fyo.pesa(0);
|
let balance = 0;
|
||||||
let debit = this.fyo.pesa(0);
|
let debit = 0;
|
||||||
let credit = this.fyo.pesa(0);
|
let credit = 0;
|
||||||
|
|
||||||
for (const entry of map.get(key)!) {
|
for (const entry of map.get(key)!) {
|
||||||
debit = debit.add(entry.debit!);
|
debit += entry.debit!;
|
||||||
credit = credit.add(entry.credit!);
|
credit += entry.credit!;
|
||||||
|
|
||||||
const diff = entry.debit!.sub(entry.credit!);
|
const diff = entry.debit! - entry.credit!;
|
||||||
balance = balance.add(diff);
|
balance += diff;
|
||||||
entry.balance = balance;
|
entry.balance = balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +199,7 @@ export class GeneralLedger extends Report {
|
|||||||
date: null,
|
date: null,
|
||||||
debit,
|
debit,
|
||||||
credit,
|
credit,
|
||||||
balance: debit.sub(credit),
|
balance: debit - credit,
|
||||||
referenceType: '',
|
referenceType: '',
|
||||||
referenceName: '',
|
referenceName: '',
|
||||||
party: '',
|
party: '',
|
||||||
@ -225,8 +211,8 @@ export class GeneralLedger extends Report {
|
|||||||
/**
|
/**
|
||||||
* Total debit and credit for the final row
|
* Total debit and credit for the final row
|
||||||
*/
|
*/
|
||||||
totalDebit = totalDebit.add(debit);
|
totalDebit += debit;
|
||||||
totalCredit = totalCredit.add(credit);
|
totalCredit += credit;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { totalDebit, totalCredit };
|
return { totalDebit, totalCredit };
|
||||||
@ -280,7 +266,7 @@ export class GeneralLedger extends Report {
|
|||||||
'reverts',
|
'reverts',
|
||||||
];
|
];
|
||||||
|
|
||||||
const filters = this._getFilters();
|
const filters = this._getQueryFilters();
|
||||||
const entries = (await this.fyo.db.getAllRaw(
|
const entries = (await this.fyo.db.getAllRaw(
|
||||||
ModelNameEnum.AccountingLedgerEntry,
|
ModelNameEnum.AccountingLedgerEntry,
|
||||||
{
|
{
|
||||||
@ -294,9 +280,9 @@ export class GeneralLedger extends Report {
|
|||||||
name: parseInt(entry.name),
|
name: parseInt(entry.name),
|
||||||
account: entry.account,
|
account: entry.account,
|
||||||
date: new Date(entry.date),
|
date: new Date(entry.date),
|
||||||
debit: this.fyo.pesa(entry.debit),
|
debit: parseFloat(entry.debit),
|
||||||
credit: this.fyo.pesa(entry.credit),
|
credit: parseFloat(entry.credit),
|
||||||
balance: this.fyo.pesa(0),
|
balance: 0,
|
||||||
referenceType: entry.referenceType,
|
referenceType: entry.referenceType,
|
||||||
referenceName: entry.referenceName,
|
referenceName: entry.referenceName,
|
||||||
party: entry.party,
|
party: entry.party,
|
||||||
@ -306,7 +292,7 @@ export class GeneralLedger extends Report {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_getFilters(): QueryFilter {
|
_getQueryFilters(): QueryFilter {
|
||||||
const filters: QueryFilter = {};
|
const filters: QueryFilter = {};
|
||||||
const stringFilters = ['account', 'party', 'referenceName'];
|
const stringFilters = ['account', 'party', 'referenceName'];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user