Skip to content

Commit

Permalink
feat: Computed Net Income under Equity in Balance Sheet report. (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia authored Oct 26, 2023
1 parent 08ac5f4 commit e070ac7
Show file tree
Hide file tree
Showing 27 changed files with 1,463 additions and 253 deletions.
3 changes: 2 additions & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"crypto-random-string": "^3.2.0",
"csurf": "^1.10.0",
"deep-map": "^2.0.0",
"deepdash": "^5.3.7",
"deepdash": "^5.3.9",
"dotenv": "^8.1.0",
"errorhandler": "^1.5.1",
"es6-weak-map": "^2.0.3",
Expand Down Expand Up @@ -95,6 +95,7 @@
"rate-limiter-flexible": "^2.1.14",
"reflect-metadata": "^0.1.13",
"rtl-detect": "^1.0.4",
"source-map-loader": "^4.0.1",
"ts-transformer-keys": "^0.4.2",
"tsyringe": "^4.3.0",
"typedi": "^0.8.0",
Expand Down
1 change: 1 addition & 0 deletions packages/server/resources/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@
"balance_sheet.long_term_liabilities": "Long-Term Liabilities",
"balance_sheet.non_current_liabilities": "Non-Current Liabilities",
"balance_sheet.equity": "Equity",
"balance_sheet.net_income": "Net Income",

"balance_sheet.account_name": "Account name",
"balance_sheet.total": "Total",
Expand Down
33 changes: 29 additions & 4 deletions packages/server/src/interfaces/BalanceSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum BALANCE_SHEET_SCHEMA_NODE_TYPE {
AGGREGATE = 'AGGREGATE',
ACCOUNTS = 'ACCOUNTS',
ACCOUNT = 'ACCOUNT',
NET_INCOME = 'NET_INCOME',
}

export enum BALANCE_SHEET_NODE_TYPE {
Expand All @@ -33,6 +34,7 @@ export enum BALANCE_SHEET_SCHEMA_NODE_ID {
LOGN_TERM_LIABILITY = 'LOGN_TERM_LIABILITY',
NON_CURRENT_LIABILITY = 'NON_CURRENT_LIABILITY',
EQUITY = 'EQUITY',
NET_INCOME = 'NET_INCOME',
}

// Balance sheet query.
Expand Down Expand Up @@ -87,7 +89,6 @@ export interface IBalanceSheetDOO {
meta: IBalanceSheetMeta;
}


export interface IBalanceSheetCommonNode {
total: IBalanceSheetTotal;
horizontalTotals?: IBalanceSheetTotal[];
Expand All @@ -108,7 +109,7 @@ export interface IBalanceSheetAggregateNode extends IBalanceSheetCommonNode {
id: string;
name: string;
nodeType: BALANCE_SHEET_SCHEMA_NODE_TYPE.AGGREGATE;
children?: (IBalanceSheetAggregateNode | IBalanceSheetAccountNode)[];
children?: IBalanceSheetDataNode[];
}

export interface IBalanceSheetTotal {
Expand All @@ -118,6 +119,13 @@ export interface IBalanceSheetTotal {
date?: string | Date;
}

export interface IBalanceSheetAccountsNode extends IBalanceSheetCommonNode {
id: number | string;
name: string;
nodeType: BALANCE_SHEET_SCHEMA_NODE_TYPE.ACCOUNTS;
children: IBalanceSheetAccountNode[];
}

export interface IBalanceSheetAccountNode extends IBalanceSheetCommonNode {
id: number;
index: number;
Expand All @@ -128,7 +136,17 @@ export interface IBalanceSheetAccountNode extends IBalanceSheetCommonNode {
children?: IBalanceSheetAccountNode[];
}

export type IBalanceSheetDataNode = IBalanceSheetAggregateNode;
export interface IBalanceSheetNetIncomeNode extends IBalanceSheetCommonNode {
id: number;
name: string;
nodeType: BALANCE_SHEET_SCHEMA_NODE_TYPE.NET_INCOME;
}

export type IBalanceSheetDataNode =
| IBalanceSheetAggregateNode
| IBalanceSheetAccountNode
| IBalanceSheetAccountsNode
| IBalanceSheetNetIncomeNode;

export interface IBalanceSheetPercentageAmount {
amount: number;
Expand All @@ -150,9 +168,16 @@ export interface IBalanceSheetSchemaAccountNode {
accountsTypes: string[];
}

export interface IBalanceSheetSchemaNetIncomeNode {
id: string;
name: string;
type: BALANCE_SHEET_SCHEMA_NODE_TYPE;
}

export type IBalanceSheetSchemaNode =
| IBalanceSheetSchemaAccountNode
| IBalanceSheetSchemaAggregateNode;
| IBalanceSheetSchemaAggregateNode
| IBalanceSheetSchemaNetIncomeNode;

export interface IBalanceSheetDatePeriods {
assocAccountNodeDatePeriods(node): any;
Expand Down
5 changes: 5 additions & 0 deletions packages/server/src/interfaces/Ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export interface ILedger {
filter(cb: (entry: ILedgerEntry) => boolean): ILedger;

whereAccountId(accountId: number): ILedger;
whereAccountsIds(accountsIds: number[]): ILedger;
whereContactId(contactId: number): ILedger;
whereFromDate(fromDate: Date | string): ILedger;
whereToDate(toDate: Date | string): ILedger;
whereCurrencyCode(currencyCode: string): ILedger;
whereBranch(branchId: number): ILedger;
whereItem(itemId: number): ILedger;
whereProject(projectId: number): ILedger;

getClosingBalance(): number;
getForeignClosingBalance(): number;
Expand All @@ -21,6 +23,9 @@ export interface ILedger {

getContactsIds(): number[];
getAccountsIds(): number[];

reverse(): ILedger;
isEmpty(): boolean;
}

export interface ILedgerEntry {
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@
"balance_sheet.long_term_liabilities": "Long-Term Liabilities",
"balance_sheet.non_current_liabilities": "Non-Current Liabilities",
"balance_sheet.equity": "Equity",
"balance_sheet.net_income": "Net Income",

"balance_sheet.account_name": "Account name",
"balance_sheet.total": "Total",
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/services/Accounting/Ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export default class Ledger implements ILedger {

/**
* Filters entries by the given accounts ids then returns a new ledger.
* @param {number[]} accountsIds - Accounts ids.
* @param {number[]} accountIds
* @returns {ILedger}
*/
public whereAccountsIds(accountsIds: number[]): ILedger {
return this.filter((entry) => accountsIds.indexOf(entry.accountId) !== -1);
public whereAccountsIds(accountIds: number[]): ILedger {
return this.filter((entry) => accountIds.indexOf(entry.accountId) !== -1);
}

/**
Expand Down
Loading

0 comments on commit e070ac7

Please sign in to comment.