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