mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
fix: cashflow statement meta.
This commit is contained in:
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ICashFlowStatement>;
|
||||
): Promise<ICashFlowStatementDOO>;
|
||||
}
|
||||
|
||||
// CASH FLOW SCHEMA TYPES.
|
||||
@@ -185,6 +195,6 @@ export interface ICashFlowTable {
|
||||
}
|
||||
|
||||
export interface IDateRange {
|
||||
fromDate: Date,
|
||||
toDate: Date,
|
||||
}
|
||||
fromDate: Date;
|
||||
toDate: Date;
|
||||
}
|
||||
|
||||
@@ -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<ICashFlowStatement>}
|
||||
* @returns {Promise<ICashFlowStatementDOO>}
|
||||
*/
|
||||
public async cashFlow(
|
||||
tenantId: number,
|
||||
query: ICashFlowStatementQuery
|
||||
): Promise<{
|
||||
data: ICashFlowStatement;
|
||||
query: ICashFlowStatementQuery;
|
||||
}> {
|
||||
): Promise<ICashFlowStatementDOO> {
|
||||
// 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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user