fix(BalanceSheet): calculate the section total.

fix(MakeJournal): write transaction number and reference.
This commit is contained in:
a.bouhuolia
2021-03-06 12:15:35 +02:00
parent 9c2dfc7bd2
commit 0f5b34f125
3 changed files with 15 additions and 11 deletions

View File

@@ -7,6 +7,7 @@ export interface IManualJournal {
date: Date | string; date: Date | string;
journalNumber: number; journalNumber: number;
journalType: string; journalType: string;
reference: string;
amount: number; amount: number;
publishedAt: Date | null; publishedAt: Date | null;
description: string; description: string;

View File

@@ -286,8 +286,13 @@ export default class JournalCommands {
* @param {number} manualJournalId * @param {number} manualJournalId
*/ */
async manualJournal(manualJournalObj: IManualJournal) { async manualJournal(manualJournalObj: IManualJournal) {
const commonEntry = {
transaction_number: manualJournalObj.journalNumber,
reference_number: manualJournalObj.reference,
};
manualJournalObj.entries.forEach((entry: IManualJournalEntry) => { manualJournalObj.entries.forEach((entry: IManualJournalEntry) => {
const jouranlEntry = new JournalEntry({ const jouranlEntry = new JournalEntry({
...commonEntry,
debit: entry.debit, debit: entry.debit,
credit: entry.credit, credit: entry.credit,
account: entry.accountId, account: entry.accountId,

View File

@@ -107,7 +107,7 @@ export default class BalanceSheetStatement extends FinancialSheet {
): IBalanceSheetAccountTotal[] { ): IBalanceSheetAccountTotal[] {
return this.dateRangeSet.map((date, index) => { return this.dateRangeSet.map((date, index) => {
const amount = sumBy(accounts, `totalPeriods[${index}].amount`); const amount = sumBy(accounts, `totalPeriods[${index}].amount`);
const formattedAmount = this.formatNumber(amount) const formattedAmount = this.formatNumber(amount);
const currencyCode = this.baseCurrency; const currencyCode = this.baseCurrency;
return { date, amount, formattedAmount, currencyCode }; return { date, amount, formattedAmount, currencyCode };
@@ -198,14 +198,15 @@ export default class BalanceSheetStatement extends FinancialSheet {
!(section.total.amount === 0 && this.query.noneZero) !(section.total.amount === 0 && this.query.noneZero)
); );
const children = flatToNestedArray(filteredAccounts, {
id: 'id',
parentId: 'parentAccountId',
});
// Gets total amount of the given accounts. // Gets total amount of the given accounts.
const totalAmount = sumBy(filteredAccounts, 'total.amount'); const totalAmount = sumBy(children, 'total.amount');
return { return {
children: flatToNestedArray(filteredAccounts, { children,
id: 'id',
parentId: 'parentAccountId',
}),
total: { total: {
amount: totalAmount, amount: totalAmount,
formattedAmount: this.formatTotalNumber(totalAmount), formattedAmount: this.formatTotalNumber(totalAmount),
@@ -250,17 +251,14 @@ export default class BalanceSheetStatement extends FinancialSheet {
*/ */
private balanceSheetStructureMapper( private balanceSheetStructureMapper(
structure: IBalanceSheetStructureSection, structure: IBalanceSheetStructureSection,
accounts: IAccount & { type: IAccountType }[], accounts: IAccount & { type: IAccountType }[]
): IBalanceSheetSection { ): IBalanceSheetSection {
const result = { const result = {
name: structure.name, name: structure.name,
sectionType: structure.sectionType, sectionType: structure.sectionType,
type: structure.type, type: structure.type,
...(structure.type === 'accounts_section' ...(structure.type === 'accounts_section'
? this.structureRelatedAccountsMapper( ? this.structureRelatedAccountsMapper(structure.accountsTypes, accounts)
structure.accountsTypes,
accounts
)
: this.structureSectionMapper(structure, accounts)), : this.structureSectionMapper(structure, accounts)),
}; };
return result; return result;