mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat(server): financial sheet meta
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user