mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix: transactions by reference report.
This commit is contained in:
@@ -3,7 +3,7 @@ import { Router, Request, Response, NextFunction } from 'express';
|
|||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import BaseController from 'api/controllers/BaseController';
|
import BaseController from 'api/controllers/BaseController';
|
||||||
import TransactionsByReferenceService from 'services/FinancialStatements/TransactionsByReference';
|
import TransactionsByReferenceService from 'services/FinancialStatements/TransactionsByReference';
|
||||||
|
import { ITransactionsByReferenceTransaction } from 'interfaces';
|
||||||
@Service()
|
@Service()
|
||||||
export default class TransactionsByReferenceController extends BaseController {
|
export default class TransactionsByReferenceController extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
@@ -61,27 +61,30 @@ export default class TransactionsByReferenceController extends BaseController {
|
|||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const transactions =
|
const data =
|
||||||
await this.transactionsByReferenceService.getTransactionsByReference(
|
await this.transactionsByReferenceService.getTransactionsByReference(
|
||||||
tenantId,
|
tenantId,
|
||||||
filter
|
filter
|
||||||
);
|
);
|
||||||
const accept = this.accepts(req);
|
|
||||||
const acceptType = accept.types(['json']);
|
|
||||||
|
|
||||||
switch (acceptType) {
|
return res
|
||||||
case 'json':
|
.status(200)
|
||||||
default:
|
.send(this.transformToJsonResponse(data.transactions));
|
||||||
return res
|
|
||||||
.status(200)
|
|
||||||
.send(this.transformToJsonResponse(transactions));
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private transformToJsonResponse(transactions) {
|
/**
|
||||||
return transactions;
|
* Transformes the given report transaction to json response.
|
||||||
|
* @param transactions
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
private transformToJsonResponse(
|
||||||
|
transactions: ITransactionsByReferenceTransaction[]
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
transactions: this.transfromToResponse(transactions),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ export default class TransactionsByReference extends FinancialSheet {
|
|||||||
transaction: IAccountTransaction
|
transaction: IAccountTransaction
|
||||||
): ITransactionsByReferenceTransaction => {
|
): ITransactionsByReferenceTransaction => {
|
||||||
return {
|
return {
|
||||||
|
date: this.getDateMeta(transaction.date),
|
||||||
|
|
||||||
credit: this.getAmountMeta(transaction.credit, { money: true }),
|
credit: this.getAmountMeta(transaction.credit, { money: true }),
|
||||||
debit: this.getAmountMeta(transaction.debit, { money: true }),
|
debit: this.getAmountMeta(transaction.debit, { money: true }),
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export default class TransactionsByReferenceService {
|
|||||||
tenantId: number,
|
tenantId: number,
|
||||||
query: ITransactionsByReferenceQuery
|
query: ITransactionsByReferenceQuery
|
||||||
): Promise<{
|
): Promise<{
|
||||||
data: ITransactionsByReferenceTransaction[];
|
transactions: ITransactionsByReferenceTransaction[];
|
||||||
}> {
|
}> {
|
||||||
const filter = {
|
const filter = {
|
||||||
...this.defaultQuery,
|
...this.defaultQuery,
|
||||||
@@ -71,7 +71,7 @@ export default class TransactionsByReferenceService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: report.reportData(),
|
transactions: report.reportData(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user