fix: accounts types with new design.

This commit is contained in:
a.bouhuolia
2021-01-26 12:51:13 +02:00
parent a871aea84d
commit d789228038
24 changed files with 101 additions and 100 deletions

View File

@@ -269,7 +269,7 @@ export default class JournalCommands {
'reference_id',
Array.isArray(referenceId) ? referenceId : [referenceId]
)
.withGraphFetched('account.type');
.withGraphFetched('account');
this.journal.fromTransactions(transactions);
this.journal.removeEntries();

View File

@@ -165,7 +165,6 @@ export default class JournalPoster implements IJournalPoster {
private async convertBalanceChangesToArr(
accountsChange: IAccountsChange
) : Promise<{ account: number, change: number }[]>{
const { accountTypeRepository } = this.repositories;
const mappedList: { account: number, change: number }[] = [];
const accountsIds: number[] = Object.keys(accountsChange).map(id => parseInt(id, 10));
@@ -173,8 +172,8 @@ export default class JournalPoster implements IJournalPoster {
accountsIds.map(async (account: number) => {
const accountChange = accountsChange[account];
const accountNode = this.accountsDepGraph.getNodeData(account);
const accountTypeMeta = await accountTypeRepository.findOneById(accountNode.accountTypeId);
const { normal }: { normal: TEntryType } = accountTypeMeta;
const { normal }: { normal: TEntryType } = accountNode.accountNormal;
let change = 0;
if (accountChange.credit) {
@@ -333,7 +332,7 @@ export default class JournalPoster implements IJournalPoster {
...transaction,
referenceTypeFormatted: transaction.referenceTypeFormatted,
account: transaction.accountId,
accountNormal: get(transaction, 'account.type.normal'),
accountNormal: get(transaction, 'account.accountNormal'),
});
});
}

View File

@@ -184,7 +184,7 @@ export default class BalanceSheetStatement extends FinancialSheet {
const filteredAccounts = accounts
// Filter accounts that associated to the section accounts types.
.filter(
(account) => sectionAccountsTypes.indexOf(account.type.key) !== -1
(account) => sectionAccountsTypes.indexOf(account.accountType) !== -1
)
.map((account) => this.balanceSheetAccountMapper(account))
// Filter accounts that have no transaction when `noneTransactions` is on.

View File

@@ -70,7 +70,7 @@ export default class BalanceSheetStatementService
this.logger.info('[balance_sheet] trying to calculate the report.', { filter, tenantId });
// Retrieve all accounts on the storage.
const accounts = await accountRepository.all('type');
const accounts = await accountRepository.all();
const accountsGraph = await accountRepository.getDependencyGraph();
// Retrieve all journal transactions based on the given query.

View File

@@ -6,7 +6,6 @@ import {
IGeneralLedgerSheetAccountTransaction,
IAccount,
IJournalPoster,
IAccountType,
IJournalEntry,
IContact,
} from 'interfaces';
@@ -130,7 +129,7 @@ export default class GeneralLedgerSheet extends FinancialSheet {
* @return {IGeneralLedgerSheetAccountTransaction[]}
*/
private accountTransactionsMapper(
account: IAccount & { type: IAccountType },
account: IAccount,
openingBalance: number
): IGeneralLedgerSheetAccountTransaction[] {
const entries = this.transactions.getAccountEntries(account.id);
@@ -184,7 +183,7 @@ export default class GeneralLedgerSheet extends FinancialSheet {
* @return {IGeneralLedgerSheetAccount}
*/
private accountMapper(
account: IAccount & { type: IAccountType }
account: IAccount
): IGeneralLedgerSheetAccount {
const openingBalance = this.accountOpeningBalance(account);
const closingBalance = this.accountClosingBalance(account);
@@ -210,11 +209,11 @@ export default class GeneralLedgerSheet extends FinancialSheet {
* @return {IGeneralLedgerSheetAccount[]}
*/
private accountsWalker(
accounts: IAccount & { type: IAccountType }[]
accounts: IAccount[]
): IGeneralLedgerSheetAccount[] {
return (
accounts
.map((account: IAccount & { type: IAccountType }) =>
.map((account: IAccount) =>
this.accountMapper(account)
)
// Filter general ledger accounts that have no transactions

View File

@@ -89,7 +89,7 @@ export default class GeneralLedgerService {
key: 'base_currency',
});
// Retrieve all accounts with associated type from the storage.
const accounts = await accountRepository.all('type');
const accounts = await accountRepository.all();
const accountsGraph = await accountRepository.getDependencyGraph();
// Retrieve all contacts on the storage.

View File

@@ -12,6 +12,7 @@ import {
IProfitLossSheetTotalSection,
} from 'interfaces';
import { flatToNestedArray, dateRangeCollection } from 'utils';
import { ACCOUNT_TYPE } from 'data/AccountTypes';
export default class ProfitLossSheet extends FinancialSheet {
tenantId: number;
@@ -51,7 +52,7 @@ export default class ProfitLossSheet extends FinancialSheet {
}
get otherIncomeAccounts() {
return this.accounts.filter((a) => a.type.key === 'other_income');
return this.accounts.filter((a) => a.accountType === ACCOUNT_TYPE.OTHER_INCOME);
}
/**
@@ -59,7 +60,7 @@ export default class ProfitLossSheet extends FinancialSheet {
* @return {IAccount & { type: IAccountType }[]}
*/
get incomeAccounts() {
return this.accounts.filter((a) => a.type.key === 'income');
return this.accounts.filter((a) => a.accountType === ACCOUNT_TYPE.INCOME);
}
/**
@@ -67,7 +68,7 @@ export default class ProfitLossSheet extends FinancialSheet {
* @return {IAccount & { type: IAccountType }[]}
*/
get expensesAccounts() {
return this.accounts.filter((a) => a.type.key === 'expense');
return this.accounts.filter((a) => a.accountType === ACCOUNT_TYPE.EXPENSE);
}
/**
@@ -75,7 +76,7 @@ export default class ProfitLossSheet extends FinancialSheet {
* @return {IAccount & { type: IAccountType }[]}}
*/
get otherExpensesAccounts() {
return this.accounts.filter((a) => a.type.key === 'other_expense');
return this.accounts.filter((a) => a.accountType === ACCOUNT_TYPE.OTHER_EXPENSE);
}
/**
@@ -83,7 +84,7 @@ export default class ProfitLossSheet extends FinancialSheet {
* @return {IAccount & { type: IAccountType }[]}
*/
get costOfSalesAccounts() {
return this.accounts.filter((a) => a.type.key === 'cost_of_goods_sold');
return this.accounts.filter((a) => a.accountType === ACCOUNT_TYPE.COST_OF_GOODS_SOLD);
}
/**

View File

@@ -77,7 +77,7 @@ export default class ProfitLossSheetService {
key: 'base_currency',
});
// Retrieve all accounts on the storage.
const accounts = await accountRepository.all('type');
const accounts = await accountRepository.all();
const accountsGraph = await accountRepository.getDependencyGraph();
// Retrieve all journal transactions based on the given query.

View File

@@ -65,7 +65,7 @@ export default class TrialBalanceSheet extends FinancialSheet {
parentAccountId: account.parentAccountId,
name: account.name,
code: account.code,
accountNormal: account.type.normal,
accountNormal: account.accountNormal,
hasTransactions: entries.length > 0,
credit: trial.credit,

View File

@@ -69,7 +69,7 @@ export default class TrialBalanceSheetService extends FinancialSheet {
filter,
});
// Retrieve all accounts on the storage.
const accounts = await accountRepository.all('type');
const accounts = await accountRepository.all();
const accountsGraph = await accountRepository.getDependencyGraph();
// Retrieve all journal transactions based on the given query.

View File

@@ -513,7 +513,7 @@ export default class BillPaymentsService {
const transactions = await AccountTransaction.query()
.whereIn('reference_type', ['BillPayment'])
.where('reference_id', billPayment.id)
.withGraphFetched('account.type');
.withGraphFetched('account');
journal.loadEntries(transactions);
journal.removeEntries();