mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat(server): financial sheet meta
This commit is contained in:
@@ -64,7 +64,11 @@ export interface IBalanceSheetQuery extends IFinancialSheetBranchesQuery {
|
||||
}
|
||||
|
||||
// Balance sheet meta.
|
||||
export interface IBalanceSheetMeta extends IFinancialSheetCommonMeta {}
|
||||
export interface IBalanceSheetMeta extends IFinancialSheetCommonMeta {
|
||||
formattedFromDate: string;
|
||||
formattedToDate: string;
|
||||
formattedDateRange: string;
|
||||
}
|
||||
|
||||
export interface IBalanceSheetFormatNumberSettings
|
||||
extends IFormatNumberSettings {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { INumberFormatQuery } from './FinancialStatements';
|
||||
import {
|
||||
IFinancialSheetCommonMeta,
|
||||
INumberFormatQuery,
|
||||
} from './FinancialStatements';
|
||||
import { IAccount } from './Account';
|
||||
import { ILedger } from './Ledger';
|
||||
import { IFinancialTable, ITableRow } from './Table';
|
||||
@@ -79,8 +82,8 @@ export interface ICashFlowStatementAggregateSection
|
||||
|
||||
export interface ICashFlowCashBeginningNode
|
||||
extends ICashFlowStatementCommonSection {
|
||||
sectionType: ICashFlowStatementSectionType.CASH_AT_BEGINNING;
|
||||
}
|
||||
sectionType: ICashFlowStatementSectionType.CASH_AT_BEGINNING;
|
||||
}
|
||||
|
||||
export type ICashFlowStatementSection =
|
||||
| ICashFlowStatementAccountSection
|
||||
@@ -89,10 +92,10 @@ export type ICashFlowStatementSection =
|
||||
| ICashFlowStatementCommonSection;
|
||||
|
||||
export interface ICashFlowStatementColumn {}
|
||||
export interface ICashFlowStatementMeta {
|
||||
isCostComputeRunning: boolean;
|
||||
organizationName: string;
|
||||
baseCurrency: string;
|
||||
export interface ICashFlowStatementMeta extends IFinancialSheetCommonMeta {
|
||||
formattedToDate: string;
|
||||
formattedFromDate: string;
|
||||
formattedDateRange: string;
|
||||
}
|
||||
|
||||
export interface ICashFlowStatementDOO {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
IFinancialSheetBranchesQuery,
|
||||
IFinancialSheetCommonMeta,
|
||||
INumberFormatQuery,
|
||||
} from './FinancialStatements';
|
||||
import { IFinancialTable } from './Table';
|
||||
@@ -134,10 +135,10 @@ export type IProfitLossSheetNode =
|
||||
| IProfitLossSheetEquationNode
|
||||
| IProfitLossSheetAccountNode;
|
||||
|
||||
export interface IProfitLossSheetMeta {
|
||||
isCostComputeRunning: boolean;
|
||||
organizationName: string;
|
||||
baseCurrency: string;
|
||||
export interface IProfitLossSheetMeta extends IFinancialSheetCommonMeta{
|
||||
formattedDateRange: string;
|
||||
formattedFromDate: string;
|
||||
formattedToDate: string;
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { INumberFormatQuery } from './FinancialStatements';
|
||||
import {
|
||||
IFinancialSheetCommonMeta,
|
||||
INumberFormatQuery,
|
||||
} from './FinancialStatements';
|
||||
import { IFinancialTable } from './Table';
|
||||
|
||||
export interface ITrialBalanceSheetQuery {
|
||||
@@ -24,10 +27,10 @@ export interface ITrialBalanceTotal {
|
||||
formattedBalance: string;
|
||||
}
|
||||
|
||||
export interface ITrialBalanceSheetMeta {
|
||||
isCostComputeRunning: boolean;
|
||||
organizationName: string;
|
||||
baseCurrency: string;
|
||||
export interface ITrialBalanceSheetMeta extends IFinancialSheetCommonMeta {
|
||||
formattedFromDate: string;
|
||||
formattedToDate: string;
|
||||
formattedDateRange: string;
|
||||
}
|
||||
|
||||
export interface ITrialBalanceAccount extends ITrialBalanceTotal {
|
||||
|
||||
@@ -82,6 +82,7 @@ export default class BalanceSheetStatementService
|
||||
const models = this.tenancy.models(tenantId);
|
||||
const balanceSheetRepo = new BalanceSheetRepository(models, filter);
|
||||
|
||||
// Loads all resources.
|
||||
await balanceSheetRepo.asyncInitialize();
|
||||
|
||||
// Balance sheet report instance.
|
||||
@@ -95,7 +96,7 @@ export default class BalanceSheetStatementService
|
||||
const data = balanceSheetInstanace.reportData();
|
||||
|
||||
// Balance sheet meta.
|
||||
const meta = await this.balanceSheetMeta.meta(tenantId);
|
||||
const meta = await this.balanceSheetMeta.meta(tenantId, filter);
|
||||
|
||||
return {
|
||||
query: filter,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { FinancialSheetMeta } from '../FinancialSheetMeta';
|
||||
import { IBalanceSheetMeta } from '@/interfaces';
|
||||
import { IBalanceSheetMeta, IBalanceSheetQuery } from '@/interfaces';
|
||||
import moment from 'moment';
|
||||
|
||||
@Service()
|
||||
export class BalanceSheetMetaInjectable {
|
||||
@@ -12,12 +13,21 @@ export class BalanceSheetMetaInjectable {
|
||||
* @param {number} tenantId -
|
||||
* @returns {IBalanceSheetMeta}
|
||||
*/
|
||||
public async meta(tenantId: number): Promise<IBalanceSheetMeta> {
|
||||
public async meta(
|
||||
tenantId: number,
|
||||
query: IBalanceSheetQuery
|
||||
): Promise<IBalanceSheetMeta> {
|
||||
const commonMeta = await this.financialSheetMeta.meta(tenantId);
|
||||
const formattedToDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||
const formattedFromDate = moment(query.fromDate).format('YYYY/MM/DD');
|
||||
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
||||
|
||||
return {
|
||||
...commonMeta,
|
||||
sheetName: 'Balance Sheet',
|
||||
formattedFromDate,
|
||||
formattedToDate,
|
||||
formattedDateRange
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export class BalanceSheetPdfInjectable {
|
||||
tenantId,
|
||||
table.table,
|
||||
table.meta.sheetName,
|
||||
table.meta.baseCurrency
|
||||
table.meta.formattedDateRange
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
ICashFlowStatementQuery,
|
||||
ICashFlowStatementDOO,
|
||||
IAccountTransaction,
|
||||
ICashFlowStatementMeta
|
||||
ICashFlowStatementMeta,
|
||||
} from '@/interfaces';
|
||||
import CashFlowStatement from './CashFlow';
|
||||
import Ledger from '@/services/Accounting/Ledger';
|
||||
@@ -16,6 +16,7 @@ import CashFlowRepository from './CashFlowRepository';
|
||||
import InventoryService from '@/services/Inventory/Inventory';
|
||||
import { parseBoolean } from 'utils';
|
||||
import { Tenant } from '@/system/models';
|
||||
import { CashflowSheetMeta } from './CashflowSheetMeta';
|
||||
|
||||
@Service()
|
||||
export default class CashFlowStatementService
|
||||
@@ -31,6 +32,9 @@ export default class CashFlowStatementService
|
||||
@Inject()
|
||||
inventoryService: InventoryService;
|
||||
|
||||
@Inject()
|
||||
private cashflowSheetMeta: CashflowSheetMeta;
|
||||
|
||||
/**
|
||||
* Defaults balance sheet filter query.
|
||||
* @return {IBalanceSheetQuery}
|
||||
@@ -138,38 +142,13 @@ export default class CashFlowStatementService
|
||||
tenant.metadata.baseCurrency,
|
||||
i18n
|
||||
);
|
||||
// Retrieve the cashflow sheet meta.
|
||||
const meta = await this.cashflowSheetMeta.meta(tenantId, filter);
|
||||
|
||||
return {
|
||||
data: cashFlowInstance.reportData(),
|
||||
query: filter,
|
||||
meta: this.reportMetadata(tenantId),
|
||||
meta,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import moment from 'moment';
|
||||
import { ICashFlowStatementMeta, ICashFlowStatementQuery } from '@/interfaces';
|
||||
import { FinancialSheetMeta } from '../FinancialSheetMeta';
|
||||
|
||||
@Service()
|
||||
export class CashflowSheetMeta {
|
||||
@Inject()
|
||||
private financialSheetMeta: FinancialSheetMeta;
|
||||
|
||||
/**
|
||||
* CAshflow sheet meta.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<ICashFlowStatementMeta>}
|
||||
*/
|
||||
public async meta(
|
||||
tenantId: number,
|
||||
query: ICashFlowStatementQuery
|
||||
): Promise<ICashFlowStatementMeta> {
|
||||
const meta = await this.financialSheetMeta.meta(tenantId);
|
||||
const formattedToDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||
const formattedFromDate = moment(query.fromDate).format('YYYY/MM/DD');
|
||||
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
||||
|
||||
return {
|
||||
...meta,
|
||||
formattedToDate,
|
||||
formattedFromDate,
|
||||
formattedDateRange,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export class CashflowTablePdfInjectable {
|
||||
tenantId,
|
||||
table.table,
|
||||
sheetName,
|
||||
table.meta.baseCurrency
|
||||
table.meta.formattedDateRange
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import moment from 'moment';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { FinancialSheetMeta } from '../FinancialSheetMeta';
|
||||
import { ICashFlowStatementMeta, ICashFlowStatementQuery } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class ProfitLossSheetMeta {
|
||||
@Inject()
|
||||
private financialSheetMeta: FinancialSheetMeta;
|
||||
|
||||
/**
|
||||
* Retrieve the P/L sheet meta.
|
||||
* @param {number} tenantId -
|
||||
* @returns {IBalanceSheetMeta}
|
||||
*/
|
||||
public async meta(
|
||||
tenantId: number,
|
||||
query: ICashFlowStatementQuery
|
||||
): Promise<ICashFlowStatementMeta> {
|
||||
const commonMeta = await this.financialSheetMeta.meta(tenantId);
|
||||
const formattedToDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||
const formattedFromDate = moment(query.fromDate).format('YYYY/MM/DD');
|
||||
const formattedDateRange = `From ${formattedFromDate} | To ${formattedToDate}`;
|
||||
|
||||
const sheetName = 'Cashflow Statement';
|
||||
|
||||
return {
|
||||
...commonMeta,
|
||||
sheetName,
|
||||
formattedFromDate,
|
||||
formattedToDate,
|
||||
formattedDateRange,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,10 @@ import {
|
||||
} from '@/interfaces';
|
||||
import ProfitLossSheet from './ProfitLossSheet';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import InventoryService from '@/services/Inventory/Inventory';
|
||||
import { parseBoolean } from 'utils';
|
||||
import { Tenant } from '@/system/models';
|
||||
import { mergeQueryWithDefaults } from './utils';
|
||||
import { ProfitLossSheetRepository } from './ProfitLossSheetRepository';
|
||||
import { ProfitLossSheetMeta } from './ProfitLossSheetMeta';
|
||||
|
||||
// Profit/Loss sheet service.
|
||||
@Service()
|
||||
@@ -19,7 +18,7 @@ export default class ProfitLossSheetService {
|
||||
private tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
private inventoryService: InventoryService;
|
||||
private profitLossSheetMeta: ProfitLossSheetMeta;
|
||||
|
||||
/**
|
||||
* Retrieve profit/loss sheet statement.
|
||||
@@ -47,6 +46,7 @@ export default class ProfitLossSheetService {
|
||||
|
||||
const profitLossRepo = new ProfitLossSheetRepository(models, filter);
|
||||
|
||||
// Loads the profit/loss sheet data.
|
||||
await profitLossRepo.asyncInitialize();
|
||||
|
||||
// Profit/Loss report instance.
|
||||
@@ -57,38 +57,15 @@ export default class ProfitLossSheetService {
|
||||
i18n
|
||||
);
|
||||
// Profit/loss report data and collumns.
|
||||
const profitLossData = profitLossInstance.reportData();
|
||||
const data = profitLossInstance.reportData();
|
||||
|
||||
// Retrieve the profit/loss sheet meta.
|
||||
const meta = await this.profitLossSheetMeta.meta(tenantId, filter);
|
||||
|
||||
return {
|
||||
data: profitLossData,
|
||||
query: filter,
|
||||
meta: this.reportMetadata(tenantId),
|
||||
data,
|
||||
meta,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the trial balance sheet meta.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @returns {ITrialBalanceSheetMeta}
|
||||
*/
|
||||
private reportMetadata(tenantId: number): IProfitLossSheetMeta {
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,12 @@ export class ProfitLossTablePdfInjectable {
|
||||
query: IProfitLossSheetQuery
|
||||
): Promise<Buffer> {
|
||||
const table = await this.profitLossTable.table(tenantId, query);
|
||||
const sheetName = 'Profit & Loss Sheet';
|
||||
|
||||
return this.tableSheetPdf.convertToPdf(
|
||||
tenantId,
|
||||
table.table,
|
||||
sheetName,
|
||||
table.meta.baseCurrency
|
||||
table.meta.sheetName,
|
||||
table.meta.formattedDateRange
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,20 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import moment from 'moment';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import {
|
||||
ITrialBalanceSheetMeta,
|
||||
ITrialBalanceSheetQuery,
|
||||
ITrialBalanceStatement,
|
||||
} from '@/interfaces';
|
||||
import { ITrialBalanceSheetQuery, ITrialBalanceStatement } from '@/interfaces';
|
||||
import TrialBalanceSheet from './TrialBalanceSheet';
|
||||
import FinancialSheet from '../FinancialSheet';
|
||||
import InventoryService from '@/services/Inventory/Inventory';
|
||||
import { parseBoolean } from 'utils';
|
||||
import { Tenant } from '@/system/models';
|
||||
import { TrialBalanceSheetRepository } from './TrialBalanceSheetRepository';
|
||||
import { TrialBalanceSheetMeta } from './TrialBalanceSheetMeta';
|
||||
|
||||
@Service()
|
||||
export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
private tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
inventoryService: InventoryService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
private trialBalanceSheetMetaService: TrialBalanceSheetMeta;
|
||||
|
||||
/**
|
||||
* Defaults trial balance sheet filter query.
|
||||
@@ -47,32 +39,6 @@ export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the trial balance sheet meta.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @returns {ITrialBalanceSheetMeta}
|
||||
*/
|
||||
private reportMetadata(tenantId: number): ITrialBalanceSheetMeta {
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve trial balance sheet statement.
|
||||
* @param {number} tenantId
|
||||
@@ -99,6 +65,7 @@ export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
repos,
|
||||
filter
|
||||
);
|
||||
// Loads the resources.
|
||||
await trialBalanceSheetRepos.asyncInitialize();
|
||||
|
||||
// Trial balance report instance.
|
||||
@@ -111,10 +78,13 @@ export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
// Trial balance sheet data.
|
||||
const trialBalanceSheetData = trialBalanceInstance.reportData();
|
||||
|
||||
// Trial balance sheet meta.
|
||||
const meta = await this.trialBalanceSheetMetaService.meta(tenantId, filter);
|
||||
|
||||
return {
|
||||
data: trialBalanceSheetData,
|
||||
query: filter,
|
||||
meta: this.reportMetadata(tenantId),
|
||||
meta,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import moment from 'moment';
|
||||
import { ITrialBalanceSheetMeta, ITrialBalanceSheetQuery } from '@/interfaces';
|
||||
import { FinancialSheetMeta } from '../FinancialSheetMeta';
|
||||
|
||||
@Service()
|
||||
export class TrialBalanceSheetMeta {
|
||||
@Inject()
|
||||
private financialSheetMeta: FinancialSheetMeta;
|
||||
|
||||
/**
|
||||
* Retrieves the trial balance sheet meta.
|
||||
* @param {number} tenantId
|
||||
* @param {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<ITrialBalanceSheetMeta>}
|
||||
*/
|
||||
public async meta(
|
||||
tenantId: number,
|
||||
query: ITrialBalanceSheetQuery
|
||||
): Promise<ITrialBalanceSheetMeta> {
|
||||
const commonMeta = await this.financialSheetMeta.meta(tenantId);
|
||||
|
||||
const formattedFromDate = moment(query.fromDate).format('YYYY/MM/DD');
|
||||
const formattedToDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||
const formattedDateRange = `From ${formattedFromDate} to ${formattedToDate}`;
|
||||
|
||||
const sheetName = 'Trial Balance Sheet';
|
||||
|
||||
return {
|
||||
...commonMeta,
|
||||
sheetName,
|
||||
formattedFromDate,
|
||||
formattedToDate,
|
||||
formattedDateRange,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,9 @@ export class TrialBalanceSheetPdfInjectable {
|
||||
private tableSheetPdf: TableSheetPdf;
|
||||
|
||||
/**
|
||||
* Converts the given balance sheet table to pdf.
|
||||
* Converts the given trial balance sheet table to pdf.
|
||||
* @param {number} tenantId - Tenant ID.
|
||||
* @param {IBalanceSheetQuery} query - Balance sheet query.
|
||||
* @param {ITrialBalanceSheetQuery} query - Trial balance sheet query.
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async pdf(
|
||||
@@ -22,13 +22,12 @@ export class TrialBalanceSheetPdfInjectable {
|
||||
query: ITrialBalanceSheetQuery
|
||||
): Promise<Buffer> {
|
||||
const table = await this.trialBalanceSheetTable.table(tenantId, query);
|
||||
const sheetName = 'Trial Balance Sheet';
|
||||
|
||||
return this.tableSheetPdf.convertToPdf(
|
||||
tenantId,
|
||||
table.table,
|
||||
sheetName,
|
||||
table.meta.baseCurrency
|
||||
table.meta.sheetName,
|
||||
table.meta.formattedDateRange
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user