mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
fix: transactions by customers/vendors report localization.
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { query } from 'express-validator';
|
||||
import { Inject } from 'typedi';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ITransactionsByCustomersStatement } from 'interfaces';
|
||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||
import TransactionsByCustomersService from 'services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService';
|
||||
import TransactionsByCustomersTableRows from 'services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersTableRows';
|
||||
import HasTenancyService from 'services/Tenancy/TenancyService';
|
||||
|
||||
@Service()
|
||||
export default class TransactionsByCustomersReportController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
transactionsByCustomersService: TransactionsByCustomersService;
|
||||
|
||||
@Inject()
|
||||
transactionsByCustomersTableRows: TransactionsByCustomersTableRows;
|
||||
tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
@@ -51,12 +53,18 @@ export default class TransactionsByCustomersReportController extends BaseFinanci
|
||||
* Transformes the statement to table rows response.
|
||||
* @param {ITransactionsByCustomersStatement} statement -
|
||||
*/
|
||||
private transformToTableResponse({
|
||||
data,
|
||||
}: ITransactionsByCustomersStatement) {
|
||||
private transformToTableResponse(
|
||||
customersTransactions,
|
||||
tenantId
|
||||
) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const table = new TransactionsByCustomersTableRows(
|
||||
customersTransactions,
|
||||
i18n
|
||||
);
|
||||
return {
|
||||
table: {
|
||||
rows: this.transactionsByCustomersTableRows.tableRows(data),
|
||||
rows: table.tableRows(),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -65,10 +73,10 @@ export default class TransactionsByCustomersReportController extends BaseFinanci
|
||||
* Transformes the statement to json response.
|
||||
* @param {ITransactionsByCustomersStatement} statement -
|
||||
*/
|
||||
private transfromToJsonResponse({
|
||||
private transfromToJsonResponse(
|
||||
data,
|
||||
columns,
|
||||
}: ITransactionsByCustomersStatement) {
|
||||
columns
|
||||
): ITransactionsByCustomersStatement {
|
||||
return {
|
||||
data: this.transfromToResponse(data),
|
||||
columns: this.transfromToResponse(columns),
|
||||
@@ -91,7 +99,7 @@ export default class TransactionsByCustomersReportController extends BaseFinanci
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const transactionsByCustomers =
|
||||
const report =
|
||||
await this.transactionsByCustomersService.transactionsByCustomers(
|
||||
tenantId,
|
||||
filter
|
||||
@@ -108,7 +116,9 @@ export default class TransactionsByCustomersReportController extends BaseFinanci
|
||||
default:
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToTableResponse(transactionsByCustomers));
|
||||
.send(
|
||||
this.transformToTableResponse(report.data, tenantId)
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -6,13 +6,14 @@ import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||
import TransactionsByVendorsTableRows from 'services/FinancialStatements/TransactionsByVendor/TransactionsByVendorTableRows';
|
||||
import TransactionsByVendorsService from 'services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService';
|
||||
import { ITransactionsByVendorsStatement } from 'interfaces';
|
||||
import HasTenancyService from 'services/Tenancy/TenancyService';
|
||||
|
||||
export default class TransactionsByVendorsReportController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
transactionsByVendorsService: TransactionsByVendorsService;
|
||||
|
||||
@Inject()
|
||||
transactionsByVendorsTableRows: TransactionsByVendorsTableRows;
|
||||
tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
@@ -52,10 +53,16 @@ export default class TransactionsByVendorsReportController extends BaseFinancial
|
||||
* Transformes the report statement to table rows.
|
||||
* @param {ITransactionsByVendorsStatement} statement -
|
||||
*/
|
||||
private transformToTableRows({ data }: ITransactionsByVendorsStatement) {
|
||||
private transformToTableRows(
|
||||
tenantId: number,
|
||||
transactions: any[]
|
||||
) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const table = new TransactionsByVendorsTableRows(transactions, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
data: this.transactionsByVendorsTableRows.tableRows(data),
|
||||
data: table.tableRows(),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -87,7 +94,7 @@ export default class TransactionsByVendorsReportController extends BaseFinancial
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const transactionsByVendors =
|
||||
const report =
|
||||
await this.transactionsByVendorsService.transactionsByVendors(
|
||||
tenantId,
|
||||
filter
|
||||
@@ -99,12 +106,12 @@ export default class TransactionsByVendorsReportController extends BaseFinancial
|
||||
case 'application/json+table':
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToTableRows(transactionsByVendors));
|
||||
.send(this.transformToTableRows(tenantId, report.data));
|
||||
case 'json':
|
||||
default:
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToJsonResponse(transactionsByVendors));
|
||||
.send(this.transformToJsonResponse(report));
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
Reference in New Issue
Block a user