mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat(server): financial sheet meta
This commit is contained in:
@@ -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