mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
feat(server): financial reports meta
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { FinancialSheetMeta } from '../FinancialSheetMeta';
|
||||
import { IBalanceSheetMeta, IBalanceSheetQuery, IInventoryValuationReportQuery } from '@/interfaces';
|
||||
import moment from 'moment';
|
||||
|
||||
@Service()
|
||||
export class InventoryValuationMetaInjectable {
|
||||
@Inject()
|
||||
private financialSheetMeta: FinancialSheetMeta;
|
||||
|
||||
/**
|
||||
* Retrieve the balance sheet meta.
|
||||
* @param {number} tenantId -
|
||||
* @returns {IBalanceSheetMeta}
|
||||
*/
|
||||
public async meta(
|
||||
tenantId: number,
|
||||
query: IInventoryValuationReportQuery
|
||||
): Promise<IBalanceSheetMeta> {
|
||||
const commonMeta = await this.financialSheetMeta.meta(tenantId);
|
||||
const formattedAsDate = moment(query.asDate).format('YYYY/MM/DD');
|
||||
const formattedDateRange = `As ${formattedAsDate}`;
|
||||
|
||||
return {
|
||||
...commonMeta,
|
||||
sheetName: 'Inventory Valuation Sheet',
|
||||
formattedAsDate,
|
||||
formattedDateRange,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -23,13 +23,12 @@ export class InventoryValuationSheetPdf {
|
||||
query: IInventoryValuationReportQuery
|
||||
): Promise<Buffer> {
|
||||
const table = await this.inventoryValuationTable.table(tenantId, query);
|
||||
const sheetName = 'Inventory Valuation Sheet';
|
||||
|
||||
return this.tableSheetPdf.convertToPdf(
|
||||
tenantId,
|
||||
table.table,
|
||||
sheetName,
|
||||
table.meta.baseCurrency
|
||||
table.meta.sheetName,
|
||||
table.meta.formattedDateRange
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { InventoryValuationSheet } from './InventoryValuationSheet';
|
||||
import InventoryService from '@/services/Inventory/Inventory';
|
||||
import { Tenant } from '@/system/models';
|
||||
import { InventoryValuationMetaInjectable } from './InventoryValuationSheetMeta';
|
||||
|
||||
@Service()
|
||||
export class InventoryValuationSheetService {
|
||||
@@ -22,6 +23,9 @@ export class InventoryValuationSheetService {
|
||||
@Inject()
|
||||
inventoryService: InventoryService;
|
||||
|
||||
@Inject()
|
||||
private inventoryValuationMeta: InventoryValuationMetaInjectable;
|
||||
|
||||
/**
|
||||
* Defaults balance sheet filter query.
|
||||
* @return {IBalanceSheetQuery}
|
||||
@@ -46,33 +50,6 @@ export class InventoryValuationSheetService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the balance sheet meta.
|
||||
* @param {number} tenantId -
|
||||
* @returns {IBalanceSheetMeta}
|
||||
*/
|
||||
reportMetadata(tenantId: number): IInventoryValuationSheetMeta {
|
||||
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 {
|
||||
organizationName,
|
||||
baseCurrency,
|
||||
isCostComputeRunning,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Inventory valuation sheet.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
@@ -136,10 +113,13 @@ export class InventoryValuationSheetService {
|
||||
// Retrieve the inventory valuation report data.
|
||||
const inventoryValuationData = inventoryValuationInstance.reportData();
|
||||
|
||||
// Retrieves the inventorty valuation meta.
|
||||
const meta = await this.inventoryValuationMeta.meta(tenantId, filter);
|
||||
|
||||
return {
|
||||
data: inventoryValuationData,
|
||||
query: filter,
|
||||
meta: this.reportMetadata(tenantId),
|
||||
meta,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user