From 0f5b34f12565daf39cb7069849879f7d33adc18d Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Sat, 6 Mar 2021 12:15:35 +0200 Subject: [PATCH] fix(BalanceSheet): calculate the section total. fix(MakeJournal): write transaction number and reference. --- server/src/interfaces/ManualJournal.ts | 1 + .../services/Accounting/JournalCommands.ts | 5 +++++ .../BalanceSheet/BalanceSheet.ts | 20 +++++++++---------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/server/src/interfaces/ManualJournal.ts b/server/src/interfaces/ManualJournal.ts index 08b74b47c..58a148c61 100644 --- a/server/src/interfaces/ManualJournal.ts +++ b/server/src/interfaces/ManualJournal.ts @@ -7,6 +7,7 @@ export interface IManualJournal { date: Date | string; journalNumber: number; journalType: string; + reference: string; amount: number; publishedAt: Date | null; description: string; diff --git a/server/src/services/Accounting/JournalCommands.ts b/server/src/services/Accounting/JournalCommands.ts index f9f7fff83..4ae980b2b 100644 --- a/server/src/services/Accounting/JournalCommands.ts +++ b/server/src/services/Accounting/JournalCommands.ts @@ -286,8 +286,13 @@ export default class JournalCommands { * @param {number} manualJournalId */ async manualJournal(manualJournalObj: IManualJournal) { + const commonEntry = { + transaction_number: manualJournalObj.journalNumber, + reference_number: manualJournalObj.reference, + }; manualJournalObj.entries.forEach((entry: IManualJournalEntry) => { const jouranlEntry = new JournalEntry({ + ...commonEntry, debit: entry.debit, credit: entry.credit, account: entry.accountId, diff --git a/server/src/services/FinancialStatements/BalanceSheet/BalanceSheet.ts b/server/src/services/FinancialStatements/BalanceSheet/BalanceSheet.ts index 614b4f9bb..2fd256057 100644 --- a/server/src/services/FinancialStatements/BalanceSheet/BalanceSheet.ts +++ b/server/src/services/FinancialStatements/BalanceSheet/BalanceSheet.ts @@ -107,7 +107,7 @@ export default class BalanceSheetStatement extends FinancialSheet { ): IBalanceSheetAccountTotal[] { return this.dateRangeSet.map((date, index) => { const amount = sumBy(accounts, `totalPeriods[${index}].amount`); - const formattedAmount = this.formatNumber(amount) + const formattedAmount = this.formatNumber(amount); const currencyCode = this.baseCurrency; return { date, amount, formattedAmount, currencyCode }; @@ -198,14 +198,15 @@ export default class BalanceSheetStatement extends FinancialSheet { !(section.total.amount === 0 && this.query.noneZero) ); + const children = flatToNestedArray(filteredAccounts, { + id: 'id', + parentId: 'parentAccountId', + }); // Gets total amount of the given accounts. - const totalAmount = sumBy(filteredAccounts, 'total.amount'); + const totalAmount = sumBy(children, 'total.amount'); return { - children: flatToNestedArray(filteredAccounts, { - id: 'id', - parentId: 'parentAccountId', - }), + children, total: { amount: totalAmount, formattedAmount: this.formatTotalNumber(totalAmount), @@ -250,17 +251,14 @@ export default class BalanceSheetStatement extends FinancialSheet { */ private balanceSheetStructureMapper( structure: IBalanceSheetStructureSection, - accounts: IAccount & { type: IAccountType }[], + accounts: IAccount & { type: IAccountType }[] ): IBalanceSheetSection { const result = { name: structure.name, sectionType: structure.sectionType, type: structure.type, ...(structure.type === 'accounts_section' - ? this.structureRelatedAccountsMapper( - structure.accountsTypes, - accounts - ) + ? this.structureRelatedAccountsMapper(structure.accountsTypes, accounts) : this.structureSectionMapper(structure, accounts)), }; return result;