mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat: optimize style of account drawer.
This commit is contained in:
@@ -353,7 +353,9 @@ export default class AccountsController extends BaseController {
|
||||
tenantId,
|
||||
transactionsFilter
|
||||
);
|
||||
return res.status(200).send({ transactions });
|
||||
return res.status(200).send({
|
||||
transactions: this.transfromToResponse(transactions),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import events from 'subscribers/events';
|
||||
import AccountTypesUtils from 'lib/AccountTypes';
|
||||
import { ERRORS } from './constants';
|
||||
import { transaction } from 'objection';
|
||||
|
||||
@Service()
|
||||
export default class AccountsService {
|
||||
@@ -631,6 +632,30 @@ export default class AccountsService {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
runningBalanceFromClosing(
|
||||
transactions: IAccountTransaction[],
|
||||
closingBalance: number,
|
||||
accountNormal: string,
|
||||
) {
|
||||
let remain = closingBalance;
|
||||
|
||||
return transactions.map((entry, index) => {
|
||||
const { credit, debit } = entry;
|
||||
const amount = accountNormal === 'credit' ?
|
||||
credit - debit : debit - credit;
|
||||
|
||||
const runningBalance = Math.min(amount, remain);
|
||||
const output = {
|
||||
...entry.toJSON(),
|
||||
runningBalance: remain,
|
||||
runningBalanceFormatted: remain,
|
||||
};
|
||||
remain -= Math.max(runningBalance, 0);
|
||||
return output;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the accounts transactions.
|
||||
* @param {number} tenantId -
|
||||
@@ -642,6 +667,9 @@ export default class AccountsService {
|
||||
): Promise<{ transactions: IAccountTransaction }> {
|
||||
const { AccountTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
// Retrieve the given account or throw not found error.
|
||||
const account = await this.getAccountOrThrowError(tenantId, filter.accountId);
|
||||
|
||||
this.logger.info('[accounts] trying to get accounts transactions list.');
|
||||
const transactions = await AccountTransaction.query().onBuild((query) => {
|
||||
query.orderBy('date', 'DESC');
|
||||
@@ -652,7 +680,14 @@ export default class AccountsService {
|
||||
query.withGraphFetched('account');
|
||||
query.withGraphFetched('contact');
|
||||
});
|
||||
return { transactions };
|
||||
|
||||
return {
|
||||
transactions: this.runningBalanceFromClosing(
|
||||
transactions,
|
||||
account.amount,
|
||||
account.accountNormal,
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user