mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat: Financial statements dependency graph calculate.
This commit is contained in:
@@ -9,7 +9,8 @@ import {
|
||||
import CachableQueryBuilder from '@/lib/Cachable/CachableQueryBuilder';
|
||||
import CachableModel from '@/lib/Cachable/CachableModel';
|
||||
import DateSession from '@/models/DateSession';
|
||||
|
||||
import { flatToNestedArray } from '@/utils';
|
||||
import DependencyGraph from '@/lib/DependencyGraph';
|
||||
|
||||
export default class Account extends mixin(TenantModel, [CachableModel, DateSession]) {
|
||||
/**
|
||||
@@ -26,6 +27,25 @@ export default class Account extends mixin(TenantModel, [CachableModel, DateSess
|
||||
return CachableQueryBuilder;
|
||||
}
|
||||
|
||||
static query(...args) {
|
||||
return super.query(...args).runAfter((result) => {
|
||||
if (Array.isArray(result)) {
|
||||
return this.isDepGraph ?
|
||||
Account.toDependencyGraph(result) :
|
||||
this.collection.from(result);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the array result to dependency graph.
|
||||
*/
|
||||
static depGraph() {
|
||||
this.isDepGraph = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model modifiers.
|
||||
*/
|
||||
@@ -106,4 +126,19 @@ export default class Account extends mixin(TenantModel, [CachableModel, DateSess
|
||||
accountNormal: account.type.normal,
|
||||
}))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts flatten accounts list to nested array.
|
||||
* @param {Array} accounts
|
||||
* @param {Object} options
|
||||
*/
|
||||
static toNestedArray(accounts, options = { children: 'children' }) {
|
||||
return flatToNestedArray(accounts, { id: 'id', parentId: 'parentAccountId' })
|
||||
}
|
||||
|
||||
static toDependencyGraph(accounts) {
|
||||
return DependencyGraph.fromArray(
|
||||
accounts, { itemId: 'id', parentItemId: 'parentAccountId' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Model } from 'objection';
|
||||
import { Model, mixin } from 'objection';
|
||||
import moment from 'moment';
|
||||
import TenantModel from '@/models/TenantModel';
|
||||
import CachableQueryBuilder from '@/lib/Cachable/CachableQueryBuilder';
|
||||
import CachableModel from '@/lib/Cachable/CachableModel';
|
||||
import DateSession from '@/models/DateSession';
|
||||
|
||||
|
||||
export default class AccountTransaction extends TenantModel {
|
||||
export default class AccountTransaction extends mixin(TenantModel, [CachableModel, DateSession]) {
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
|
||||
@@ -32,6 +32,11 @@ export default class Option extends TenantModel {
|
||||
return MetableCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the given options is defined or either not.
|
||||
* @param {Array} options
|
||||
* @return {Boolean}
|
||||
*/
|
||||
static validateDefined(options) {
|
||||
const notDefined = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user