feat(server): financial reports meta

This commit is contained in:
Ahmed Bouhuolia
2024-02-17 23:36:29 +02:00
parent d2e6cc0036
commit 06e78db49d
62 changed files with 726 additions and 474 deletions

View File

@@ -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,
};
}
}

View File

@@ -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
);
}
}

View File

@@ -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,
};
}
}