mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat: general ledger filter nodes
This commit is contained in:
@@ -261,18 +261,8 @@ export default class GeneralLedgerSheet extends R.compose(
|
|||||||
if (isEmpty(this.query.accountsIds)) {
|
if (isEmpty(this.query.accountsIds)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Returns true if the given account id included in the filter.
|
// Returns true if the given account id includes transactions.
|
||||||
const isIncluded = this.query.accountsIds.includes(accountId);
|
return this.repository.accountNodesIncludeTransactions.includes(accountId);
|
||||||
|
|
||||||
const parentAccountIds =
|
|
||||||
this.repository.accountsGraph.dependantsOf(accountId);
|
|
||||||
|
|
||||||
// Returns true if one of the parent account id exists in the filter.
|
|
||||||
const accountIdInChildren = R.any(
|
|
||||||
(parentAccountId) => R.includes(parentAccountId, this.query.accountsIds),
|
|
||||||
parentAccountIds
|
|
||||||
);
|
|
||||||
return isIncluded || accountIdInChildren;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -290,12 +280,7 @@ export default class GeneralLedgerSheet extends R.compose(
|
|||||||
const closingBalanceSubaccounts =
|
const closingBalanceSubaccounts =
|
||||||
this.accountClosingBalanceWithSubaccountsTotal(account.id);
|
this.accountClosingBalanceWithSubaccountsTotal(account.id);
|
||||||
|
|
||||||
return R.compose(
|
const initialNode = {
|
||||||
R.when(
|
|
||||||
() => this.isAccountNodeIncludesClosingSubaccounts(account.id),
|
|
||||||
R.assoc('closingBalanceSubaccounts', closingBalanceSubaccounts)
|
|
||||||
)
|
|
||||||
)({
|
|
||||||
id: account.id,
|
id: account.id,
|
||||||
name: account.name,
|
name: account.name,
|
||||||
code: account.code,
|
code: account.code,
|
||||||
@@ -304,7 +289,14 @@ export default class GeneralLedgerSheet extends R.compose(
|
|||||||
openingBalance,
|
openingBalance,
|
||||||
transactions,
|
transactions,
|
||||||
closingBalance,
|
closingBalance,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
return R.compose(
|
||||||
|
R.when(
|
||||||
|
() => this.isAccountNodeIncludesClosingSubaccounts(account.id),
|
||||||
|
R.assoc('closingBalanceSubaccounts', closingBalanceSubaccounts)
|
||||||
|
)
|
||||||
|
)(initialNode);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -356,16 +348,7 @@ export default class GeneralLedgerSheet extends R.compose(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Returns true if the given account id exists in the filter.
|
// Returns true if the given account id exists in the filter.
|
||||||
const isIncluded = this.query.accountsIds?.includes(node.id);
|
return this.repository.accountNodeInclude?.includes(node.id);
|
||||||
|
|
||||||
const parentAccountIds = this.repository.accountsGraph.dependantsOf(
|
|
||||||
node.id
|
|
||||||
);
|
|
||||||
// Returns true if one of th parent account ids exist in the filter.
|
|
||||||
const oneParentAccountIdExistInFilter = parentAccountIds.some((id) =>
|
|
||||||
this.query.accountsIds?.includes(id)
|
|
||||||
);
|
|
||||||
return isIncluded || oneParentAccountIdExistInFilter;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import * as R from 'ramda';
|
||||||
import {
|
import {
|
||||||
IAccount,
|
IAccount,
|
||||||
IAccountTransaction,
|
IAccountTransaction,
|
||||||
@@ -9,6 +10,7 @@ import {
|
|||||||
import Ledger from '@/services/Accounting/Ledger';
|
import Ledger from '@/services/Accounting/Ledger';
|
||||||
import { transformToMap } from '@/utils';
|
import { transformToMap } from '@/utils';
|
||||||
import { Tenant } from '@/system/models';
|
import { Tenant } from '@/system/models';
|
||||||
|
import { flatten, isEmpty, uniq } from 'lodash';
|
||||||
|
|
||||||
export class GeneralLedgerRepository {
|
export class GeneralLedgerRepository {
|
||||||
public filter: IGeneralLedgerSheetQuery;
|
public filter: IGeneralLedgerSheetQuery;
|
||||||
@@ -30,6 +32,9 @@ export class GeneralLedgerRepository {
|
|||||||
public tenantId: number;
|
public tenantId: number;
|
||||||
public tenant: ITenant;
|
public tenant: ITenant;
|
||||||
|
|
||||||
|
public accountNodesIncludeTransactions: Array<number> = [];
|
||||||
|
public accountNodeInclude: Array<number> = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param models
|
* @param models
|
||||||
@@ -54,8 +59,10 @@ export class GeneralLedgerRepository {
|
|||||||
await this.initAccounts();
|
await this.initAccounts();
|
||||||
await this.initAccountsGraph();
|
await this.initAccountsGraph();
|
||||||
await this.initContacts();
|
await this.initContacts();
|
||||||
await this.initTransactions();
|
|
||||||
await this.initAccountsOpeningBalance();
|
await this.initAccountsOpeningBalance();
|
||||||
|
this.initAccountNodesIncludeTransactions();
|
||||||
|
await this.initTransactions();
|
||||||
|
this.initAccountNodesIncluded();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,7 +109,12 @@ export class GeneralLedgerRepository {
|
|||||||
toDate: this.filter.toDate,
|
toDate: this.filter.toDate,
|
||||||
branchesIds: this.filter.branchesIds,
|
branchesIds: this.filter.branchesIds,
|
||||||
})
|
})
|
||||||
.orderBy('date', 'ASC');
|
.orderBy('date', 'ASC')
|
||||||
|
.onBuild((query) => {
|
||||||
|
if (this.filter.accountsIds?.length > 0) {
|
||||||
|
query.whereIn('accountId', this.accountNodesIncludeTransactions);
|
||||||
|
}
|
||||||
|
});
|
||||||
// Transform array transactions to journal collection.
|
// Transform array transactions to journal collection.
|
||||||
this.transactionsLedger = Ledger.fromTransactions(this.transactions);
|
this.transactionsLedger = Ledger.fromTransactions(this.transactions);
|
||||||
}
|
}
|
||||||
@@ -124,4 +136,45 @@ export class GeneralLedgerRepository {
|
|||||||
this.openingBalanceTransactions
|
this.openingBalanceTransactions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the account nodes that should include transactions.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
public initAccountNodesIncludeTransactions() {
|
||||||
|
if (isEmpty(this.filter.accountsIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const childrenNodeIds = this.filter.accountsIds?.map(
|
||||||
|
(accountId: number) => {
|
||||||
|
return this.accountsGraph.dependenciesOf(accountId);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const nodeIds = R.concat(this.filter.accountsIds, childrenNodeIds);
|
||||||
|
|
||||||
|
this.accountNodesIncludeTransactions = uniq(flatten(nodeIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the account node ids should be included,
|
||||||
|
* if the filter by acounts is presented.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
public initAccountNodesIncluded() {
|
||||||
|
if (isEmpty(this.filter.accountsIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const nodeIds = this.filter.accountsIds.map((accountId) => {
|
||||||
|
const childrenIds = this.accountsGraph.dependenciesOf(accountId);
|
||||||
|
const parentIds = this.accountsGraph.dependantsOf(accountId);
|
||||||
|
|
||||||
|
return R.concat(childrenIds, parentIds);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.accountNodeInclude = R.compose(
|
||||||
|
R.uniq,
|
||||||
|
R.flatten,
|
||||||
|
R.concat(this.filter.accountsIds)
|
||||||
|
)(nodeIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user