fix: Trial balance sheet adjusted balance (#273)

This commit is contained in:
Ahmed Bouhuolia
2023-10-25 13:18:13 +02:00
committed by GitHub
parent 017908600e
commit 2c5537efad
16 changed files with 509 additions and 163 deletions

View File

@@ -1,5 +1,5 @@
import moment from 'moment';
import { defaultTo, uniqBy } from 'lodash';
import { defaultTo, sumBy, uniqBy } from 'lodash';
import { IAccountTransaction, ILedger, ILedgerEntry } from '@/interfaces';
export default class Ledger implements ILedger {
@@ -49,6 +49,15 @@ export default class Ledger implements ILedger {
return this.filter((entry) => entry.accountId === accountId);
}
/**
* Filters entries by the given accounts ids then returns a new ledger.
* @param {number[]} accountsIds - Accounts ids.
* @returns {ILedger}
*/
public whereAccountsIds(accountsIds: number[]): ILedger {
return this.filter((entry) => accountsIds.indexOf(entry.accountId) !== -1);
}
/**
* Filters entries that before or same the given date and returns a new ledger.
* @param {Date|string} fromDate
@@ -130,6 +139,22 @@ export default class Ledger implements ILedger {
return closingBalance;
}
/**
* Retrieves the closing credit of the entries.
* @returns {number}
*/
public getClosingCredit(): number {
return sumBy(this.entries, 'credit');
}
/**
* Retrieves the closing debit of the entries.
* @returns {number}
*/
public getClosingDebit(): number {
return sumBy(this.entries, 'debit');
}
/**
* Retrieve the closing balance of the entries.
* @returns {number}