mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
fix(GeneralLedger).
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { isEmpty, get, last } from 'lodash';
|
||||
import { isEmpty, get, last, sumBy } from 'lodash';
|
||||
import {
|
||||
IGeneralLedgerSheetQuery,
|
||||
IGeneralLedgerSheetAccount,
|
||||
@@ -19,7 +19,6 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
accounts: IAccount[];
|
||||
query: IGeneralLedgerSheetQuery;
|
||||
openingBalancesJournal: IJournalPoster;
|
||||
closingBalancesJournal: IJournalPoster;
|
||||
transactions: IJournalPoster;
|
||||
contactsMap: Map<number, IContact>;
|
||||
baseCurrency: string;
|
||||
@@ -39,7 +38,7 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
contactsByIdMap: Map<number, IContact>,
|
||||
transactions: IJournalPoster,
|
||||
openingBalancesJournal: IJournalPoster,
|
||||
closingBalancesJournal: IJournalPoster,
|
||||
|
||||
baseCurrency: string
|
||||
) {
|
||||
super();
|
||||
@@ -51,7 +50,6 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
this.contactsMap = contactsByIdMap;
|
||||
this.transactions = transactions;
|
||||
this.openingBalancesJournal = openingBalancesJournal;
|
||||
this.closingBalancesJournal = closingBalancesJournal;
|
||||
this.baseCurrency = baseCurrency;
|
||||
}
|
||||
|
||||
@@ -162,9 +160,10 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
* @return {IGeneralLedgerSheetAccountBalance}
|
||||
*/
|
||||
private accountClosingBalance(
|
||||
account: IAccount
|
||||
openingBalance: number,
|
||||
transactions: IGeneralLedgerSheetAccountTransaction[]
|
||||
): IGeneralLedgerSheetAccountBalance {
|
||||
const amount = this.closingBalancesJournal.getAccountBalance(account.id);
|
||||
const amount = this.calcClosingBalance(openingBalance, transactions);
|
||||
const formattedAmount = this.formatTotalNumber(amount);
|
||||
const currencyCode = this.baseCurrency;
|
||||
const date = this.query.toDate;
|
||||
@@ -172,6 +171,13 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
return { amount, formattedAmount, currencyCode, date };
|
||||
}
|
||||
|
||||
private calcClosingBalance(
|
||||
openingBalance: number,
|
||||
transactions: IGeneralLedgerSheetAccountTransaction[]
|
||||
) {
|
||||
return openingBalance + sumBy(transactions, (trans) => trans.amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreive general ledger accounts sections.
|
||||
* @param {IAccount} account
|
||||
@@ -179,7 +185,15 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
*/
|
||||
private accountMapper(account: IAccount): IGeneralLedgerSheetAccount {
|
||||
const openingBalance = this.accountOpeningBalance(account);
|
||||
const closingBalance = this.accountClosingBalance(account);
|
||||
|
||||
const transactions = this.accountTransactionsMapper(
|
||||
account,
|
||||
openingBalance.amount
|
||||
);
|
||||
const closingBalance = this.accountClosingBalance(
|
||||
openingBalance.amount,
|
||||
transactions
|
||||
);
|
||||
|
||||
return {
|
||||
id: account.id,
|
||||
@@ -188,10 +202,7 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
||||
index: account.index,
|
||||
parentAccountId: account.parentAccountId,
|
||||
openingBalance,
|
||||
transactions: this.accountTransactionsMapper(
|
||||
account,
|
||||
openingBalance.amount
|
||||
),
|
||||
transactions,
|
||||
closingBalance,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -134,12 +134,7 @@ export default class GeneralLedgerService {
|
||||
});
|
||||
// Retreive opening balance credit/debit sumation.
|
||||
const openingBalanceTrans = await transactionsRepository.journal({
|
||||
toDate: filter.fromDate,
|
||||
sumationCreditDebit: true,
|
||||
});
|
||||
// Retreive closing balance credit/debit sumation.
|
||||
const closingBalanceTrans = await transactionsRepository.journal({
|
||||
toDate: filter.toDate,
|
||||
toDate: moment(filter.fromDate).subtract(1, 'day'),
|
||||
sumationCreditDebit: true,
|
||||
});
|
||||
// Transform array transactions to journal collection.
|
||||
@@ -154,12 +149,6 @@ export default class GeneralLedgerService {
|
||||
tenantId,
|
||||
accountsGraph
|
||||
);
|
||||
// Accounts closing transactions.
|
||||
const closingTransJournal = Journal.fromTransactions(
|
||||
closingBalanceTrans,
|
||||
tenantId,
|
||||
accountsGraph
|
||||
);
|
||||
// General ledger report instance.
|
||||
const generalLedgerInstance = new GeneralLedgerSheet(
|
||||
tenantId,
|
||||
@@ -168,7 +157,6 @@ export default class GeneralLedgerService {
|
||||
contactsByIdMap,
|
||||
transactionsJournal,
|
||||
openingTransJournal,
|
||||
closingTransJournal,
|
||||
baseCurrency
|
||||
);
|
||||
// Retrieve general ledger report data.
|
||||
|
||||
Reference in New Issue
Block a user