mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 23:30:32 +00:00
fix: cashflow statement meta.
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
} from 'express';
|
} from 'express';
|
||||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||||
import CashFlowStatementService from 'services/FinancialStatements/CashFlow/CashFlowService';
|
import CashFlowStatementService from 'services/FinancialStatements/CashFlow/CashFlowService';
|
||||||
import { ICashFlowStatement } from 'interfaces';
|
import { ICashFlowStatementDOO, ICashFlowStatement } from 'interfaces';
|
||||||
import CashFlowTable from 'services/FinancialStatements/CashFlow/CashFlowTable';
|
import CashFlowTable from 'services/FinancialStatements/CashFlow/CashFlowTable';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@@ -54,12 +54,13 @@ export default class CashFlowController extends BaseFinancialReportController {
|
|||||||
* Retrieve the cashflow statment to json response.
|
* Retrieve the cashflow statment to json response.
|
||||||
* @param {ICashFlowStatement} cashFlow -
|
* @param {ICashFlowStatement} cashFlow -
|
||||||
*/
|
*/
|
||||||
private transformJsonResponse(cashFlow: ICashFlowStatement) {
|
private transformJsonResponse(cashFlowDOO: ICashFlowStatementDOO) {
|
||||||
const { data, query } = cashFlow;
|
const { data, query, meta } = cashFlowDOO;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: this.transfromToResponse(data),
|
data: this.transfromToResponse(data),
|
||||||
meta: this.transfromToResponse(query),
|
query: this.transfromToResponse(query),
|
||||||
|
meta: this.transfromToResponse(meta),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,15 +69,16 @@ export default class CashFlowController extends BaseFinancialReportController {
|
|||||||
* @param {ITransactionsByVendorsStatement} statement -
|
* @param {ITransactionsByVendorsStatement} statement -
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private transformToTableRows(cashFlow: ICashFlowStatement) {
|
private transformToTableRows(cashFlowDOO: ICashFlowStatementDOO) {
|
||||||
const cashFlowTable = new CashFlowTable(cashFlow);
|
const cashFlowTable = new CashFlowTable(cashFlowDOO);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
table: {
|
table: {
|
||||||
data: cashFlowTable.tableRows(),
|
data: cashFlowTable.tableRows(),
|
||||||
columns: cashFlowTable.tableColumns(),
|
columns: cashFlowTable.tableColumns(),
|
||||||
},
|
},
|
||||||
meta: this.transfromToResponse(cashFlow.query),
|
query: this.transfromToResponse(cashFlowDOO.query),
|
||||||
|
meta: this.transfromToResponse(cashFlowDOO.meta),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,13 +77,23 @@ export type ICashFlowStatementSection =
|
|||||||
| ICashFlowStatementCommonSection;
|
| ICashFlowStatementCommonSection;
|
||||||
|
|
||||||
export interface ICashFlowStatementColumn {}
|
export interface ICashFlowStatementColumn {}
|
||||||
export interface ICashFlowStatementMeta {}
|
export interface ICashFlowStatementMeta {
|
||||||
|
isCostComputeRunning: boolean;
|
||||||
|
organizationName: string;
|
||||||
|
baseCurrency: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ICashFlowStatementDOO {
|
||||||
|
data: ICashFlowStatementData;
|
||||||
|
meta: ICashFlowStatementMeta;
|
||||||
|
query: ICashFlowStatementQuery;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ICashFlowStatementService {
|
export interface ICashFlowStatementService {
|
||||||
cashFlow(
|
cashFlow(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
query: ICashFlowStatementQuery
|
query: ICashFlowStatementQuery
|
||||||
): Promise<ICashFlowStatement>;
|
): Promise<ICashFlowStatementDOO>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CASH FLOW SCHEMA TYPES.
|
// CASH FLOW SCHEMA TYPES.
|
||||||
@@ -185,6 +195,6 @@ export interface ICashFlowTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IDateRange {
|
export interface IDateRange {
|
||||||
fromDate: Date,
|
fromDate: Date;
|
||||||
toDate: Date,
|
toDate: Date;
|
||||||
}
|
}
|
||||||
@@ -6,12 +6,15 @@ import FinancialSheet from '../FinancialSheet';
|
|||||||
import {
|
import {
|
||||||
ICashFlowStatementService,
|
ICashFlowStatementService,
|
||||||
ICashFlowStatementQuery,
|
ICashFlowStatementQuery,
|
||||||
ICashFlowStatement,
|
ICashFlowStatementDOO,
|
||||||
IAccountTransaction,
|
IAccountTransaction,
|
||||||
|
ICashFlowStatementMeta
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import CashFlowStatement from './CashFlow';
|
import CashFlowStatement from './CashFlow';
|
||||||
import Ledger from 'services/Accounting/Ledger';
|
import Ledger from 'services/Accounting/Ledger';
|
||||||
import CashFlowRepository from './CashFlowRepository';
|
import CashFlowRepository from './CashFlowRepository';
|
||||||
|
import InventoryService from 'services/Inventory/Inventory';
|
||||||
|
import { parseBoolean } from 'utils';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class CashFlowStatementService
|
export default class CashFlowStatementService
|
||||||
@@ -24,6 +27,9 @@ export default class CashFlowStatementService
|
|||||||
@Inject()
|
@Inject()
|
||||||
cashFlowRepo: CashFlowRepository;
|
cashFlowRepo: CashFlowRepository;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
inventoryService: InventoryService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defaults balance sheet filter query.
|
* Defaults balance sheet filter query.
|
||||||
* @return {IBalanceSheetQuery}
|
* @return {IBalanceSheetQuery}
|
||||||
@@ -82,15 +88,12 @@ export default class CashFlowStatementService
|
|||||||
* Retrieve the cash flow sheet statement.
|
* Retrieve the cash flow sheet statement.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {ICashFlowStatementQuery} query
|
* @param {ICashFlowStatementQuery} query
|
||||||
* @returns {Promise<ICashFlowStatement>}
|
* @returns {Promise<ICashFlowStatementDOO>}
|
||||||
*/
|
*/
|
||||||
public async cashFlow(
|
public async cashFlow(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
query: ICashFlowStatementQuery
|
query: ICashFlowStatementQuery
|
||||||
): Promise<{
|
): Promise<ICashFlowStatementDOO> {
|
||||||
data: ICashFlowStatement;
|
|
||||||
query: ICashFlowStatementQuery;
|
|
||||||
}> {
|
|
||||||
// Retrieve all accounts on the storage.
|
// Retrieve all accounts on the storage.
|
||||||
const accounts = await this.cashFlowRepo.cashFlowAccounts(tenantId);
|
const accounts = await this.cashFlowRepo.cashFlowAccounts(tenantId);
|
||||||
|
|
||||||
@@ -120,7 +123,6 @@ export default class CashFlowStatementService
|
|||||||
tenantId,
|
tenantId,
|
||||||
filter
|
filter
|
||||||
);
|
);
|
||||||
|
|
||||||
// Transformes the transactions to ledgers.
|
// Transformes the transactions to ledgers.
|
||||||
const ledger = Ledger.fromTransactions(transactions);
|
const ledger = Ledger.fromTransactions(transactions);
|
||||||
const cashLedger = Ledger.fromTransactions(cashAtBeginningTransactions);
|
const cashLedger = Ledger.fromTransactions(cashAtBeginningTransactions);
|
||||||
@@ -139,6 +141,34 @@ export default class CashFlowStatementService
|
|||||||
return {
|
return {
|
||||||
data: cashFlowInstance.reportData(),
|
data: cashFlowInstance.reportData(),
|
||||||
query: filter,
|
query: filter,
|
||||||
|
meta: this.reportMetadata(tenantId),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the balance sheet meta.
|
||||||
|
* @param {number} tenantId -
|
||||||
|
* @returns {ICashFlowStatementMeta}
|
||||||
|
*/
|
||||||
|
private reportMetadata(tenantId: number): ICashFlowStatementMeta {
|
||||||
|
const settings = this.tenancy.settings(tenantId);
|
||||||
|
|
||||||
|
const isCostComputeRunning = this.inventoryService
|
||||||
|
.isItemsCostComputeRunning(tenantId);
|
||||||
|
|
||||||
|
const organizationName = settings.get({
|
||||||
|
group: 'organization',
|
||||||
|
key: 'name',
|
||||||
|
});
|
||||||
|
const baseCurrency = settings.get({
|
||||||
|
group: 'organization',
|
||||||
|
key: 'base_currency',
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
isCostComputeRunning: parseBoolean(isCostComputeRunning, false),
|
||||||
|
organizationName,
|
||||||
|
baseCurrency
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import {
|
|||||||
ITableRow,
|
ITableRow,
|
||||||
ITableColumn,
|
ITableColumn,
|
||||||
ICashFlowStatementQuery,
|
ICashFlowStatementQuery,
|
||||||
IDateRange
|
IDateRange,
|
||||||
|
ICashFlowStatementDOO
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import { dateRangeFromToCollection, tableRowMapper } from 'utils';
|
import { dateRangeFromToCollection, tableRowMapper } from 'utils';
|
||||||
import { mapValuesDeep } from 'utils/deepdash';
|
import { mapValuesDeep } from 'utils/deepdash';
|
||||||
@@ -28,20 +29,14 @@ const DISPLAY_COLUMNS_BY = {
|
|||||||
|
|
||||||
|
|
||||||
export default class CashFlowTable implements ICashFlowTable {
|
export default class CashFlowTable implements ICashFlowTable {
|
||||||
private report: {
|
private report: ICashFlowStatementDOO;
|
||||||
data: ICashFlowStatement;
|
|
||||||
query: ICashFlowStatementQuery;
|
|
||||||
};
|
|
||||||
private dateRangeSet: IDateRange[];
|
private dateRangeSet: IDateRange[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {ICashFlowStatement} reportStatement
|
* @param {ICashFlowStatement} reportStatement
|
||||||
*/
|
*/
|
||||||
constructor(reportStatement: {
|
constructor(reportStatement: ICashFlowStatementDOO) {
|
||||||
data: ICashFlowStatement;
|
|
||||||
query: ICashFlowStatementQuery;
|
|
||||||
}) {
|
|
||||||
this.report = reportStatement;
|
this.report = reportStatement;
|
||||||
this.dateRangeSet = [];
|
this.dateRangeSet = [];
|
||||||
this.initDateRangeCollection();
|
this.initDateRangeCollection();
|
||||||
|
|||||||
Reference in New Issue
Block a user