diff --git a/server/src/api/controllers/FinancialStatements/CashFlow/CashFlow.ts b/server/src/api/controllers/FinancialStatements/CashFlow/CashFlow.ts index 5434f33c1..acc6fc12a 100644 --- a/server/src/api/controllers/FinancialStatements/CashFlow/CashFlow.ts +++ b/server/src/api/controllers/FinancialStatements/CashFlow/CashFlow.ts @@ -9,7 +9,7 @@ import { } from 'express'; import BaseFinancialReportController from '../BaseFinancialReportController'; import CashFlowStatementService from 'services/FinancialStatements/CashFlow/CashFlowService'; -import { ICashFlowStatement } from 'interfaces'; +import { ICashFlowStatementDOO, ICashFlowStatement } from 'interfaces'; import CashFlowTable from 'services/FinancialStatements/CashFlow/CashFlowTable'; @Service() @@ -54,12 +54,13 @@ export default class CashFlowController extends BaseFinancialReportController { * Retrieve the cashflow statment to json response. * @param {ICashFlowStatement} cashFlow - */ - private transformJsonResponse(cashFlow: ICashFlowStatement) { - const { data, query } = cashFlow; + private transformJsonResponse(cashFlowDOO: ICashFlowStatementDOO) { + const { data, query, meta } = cashFlowDOO; return { 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 - * */ - private transformToTableRows(cashFlow: ICashFlowStatement) { - const cashFlowTable = new CashFlowTable(cashFlow); + private transformToTableRows(cashFlowDOO: ICashFlowStatementDOO) { + const cashFlowTable = new CashFlowTable(cashFlowDOO); return { table: { data: cashFlowTable.tableRows(), columns: cashFlowTable.tableColumns(), }, - meta: this.transfromToResponse(cashFlow.query), + query: this.transfromToResponse(cashFlowDOO.query), + meta: this.transfromToResponse(cashFlowDOO.meta), }; } diff --git a/server/src/interfaces/CashFlow.ts b/server/src/interfaces/CashFlow.ts index 1a8877b4d..ade9c4aaa 100644 --- a/server/src/interfaces/CashFlow.ts +++ b/server/src/interfaces/CashFlow.ts @@ -4,8 +4,8 @@ import { ILedger } from './Ledger'; import { ITableRow } from './Table'; export interface ICashFlowStatementQuery { - fromDate: Date|string; - toDate: Date|string; + fromDate: Date | string; + toDate: Date | string; displayColumnsBy: string; displayColumnsType: string; noneZero: boolean; @@ -77,13 +77,23 @@ export type ICashFlowStatementSection = | ICashFlowStatementCommonSection; 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 { cashFlow( tenantId: number, query: ICashFlowStatementQuery - ): Promise; + ): Promise; } // CASH FLOW SCHEMA TYPES. @@ -185,6 +195,6 @@ export interface ICashFlowTable { } export interface IDateRange { - fromDate: Date, - toDate: Date, -} \ No newline at end of file + fromDate: Date; + toDate: Date; +} diff --git a/server/src/services/FinancialStatements/CashFlow/CashFlowService.ts b/server/src/services/FinancialStatements/CashFlow/CashFlowService.ts index ddd28365c..578a4b884 100644 --- a/server/src/services/FinancialStatements/CashFlow/CashFlowService.ts +++ b/server/src/services/FinancialStatements/CashFlow/CashFlowService.ts @@ -6,12 +6,15 @@ import FinancialSheet from '../FinancialSheet'; import { ICashFlowStatementService, ICashFlowStatementQuery, - ICashFlowStatement, + ICashFlowStatementDOO, IAccountTransaction, + ICashFlowStatementMeta } from 'interfaces'; import CashFlowStatement from './CashFlow'; import Ledger from 'services/Accounting/Ledger'; import CashFlowRepository from './CashFlowRepository'; +import InventoryService from 'services/Inventory/Inventory'; +import { parseBoolean } from 'utils'; @Service() export default class CashFlowStatementService @@ -24,6 +27,9 @@ export default class CashFlowStatementService @Inject() cashFlowRepo: CashFlowRepository; + @Inject() + inventoryService: InventoryService; + /** * Defaults balance sheet filter query. * @return {IBalanceSheetQuery} @@ -82,15 +88,12 @@ export default class CashFlowStatementService * Retrieve the cash flow sheet statement. * @param {number} tenantId * @param {ICashFlowStatementQuery} query - * @returns {Promise} + * @returns {Promise} */ public async cashFlow( tenantId: number, query: ICashFlowStatementQuery - ): Promise<{ - data: ICashFlowStatement; - query: ICashFlowStatementQuery; - }> { + ): Promise { // Retrieve all accounts on the storage. const accounts = await this.cashFlowRepo.cashFlowAccounts(tenantId); @@ -120,7 +123,6 @@ export default class CashFlowStatementService tenantId, filter ); - // Transformes the transactions to ledgers. const ledger = Ledger.fromTransactions(transactions); const cashLedger = Ledger.fromTransactions(cashAtBeginningTransactions); @@ -139,6 +141,34 @@ export default class CashFlowStatementService return { data: cashFlowInstance.reportData(), 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 + }; + } } diff --git a/server/src/services/FinancialStatements/CashFlow/CashFlowTable.ts b/server/src/services/FinancialStatements/CashFlow/CashFlowTable.ts index 35eee34bc..58fc5a8a4 100644 --- a/server/src/services/FinancialStatements/CashFlow/CashFlowTable.ts +++ b/server/src/services/FinancialStatements/CashFlow/CashFlowTable.ts @@ -8,7 +8,8 @@ import { ITableRow, ITableColumn, ICashFlowStatementQuery, - IDateRange + IDateRange, + ICashFlowStatementDOO } from 'interfaces'; import { dateRangeFromToCollection, tableRowMapper } from 'utils'; import { mapValuesDeep } from 'utils/deepdash'; @@ -28,20 +29,14 @@ const DISPLAY_COLUMNS_BY = { export default class CashFlowTable implements ICashFlowTable { - private report: { - data: ICashFlowStatement; - query: ICashFlowStatementQuery; - }; + private report: ICashFlowStatementDOO; private dateRangeSet: IDateRange[]; /** * Constructor method. * @param {ICashFlowStatement} reportStatement */ - constructor(reportStatement: { - data: ICashFlowStatement; - query: ICashFlowStatementQuery; - }) { + constructor(reportStatement: ICashFlowStatementDOO) { this.report = reportStatement; this.dateRangeSet = []; this.initDateRangeCollection();