feat(server): wip printing financial reports

This commit is contained in:
Ahmed Bouhuolia
2024-02-10 22:20:54 +02:00
parent ecaf8c99bb
commit 9395ef094a
36 changed files with 738 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ import { ProfitLossSheetExportInjectable } from './ProfitLossSheetExportInjectab
import { ProfitLossSheetTableInjectable } from './ProfitLossSheetTableInjectable';
import { IProfitLossSheetQuery, IProfitLossSheetTable } from '@/interfaces';
import ProfitLossSheetService from './ProfitLossSheetService';
import { ProfitLossTablePdfInjectable } from './ProfitLossTablePdfInjectable';
@Service()
export class ProfitLossSheetApplication {
@@ -15,6 +16,9 @@ export class ProfitLossSheetApplication {
@Inject()
private profitLossSheet: ProfitLossSheetService;
@Inject()
private profitLossPdf: ProfitLossTablePdfInjectable;
/**
* Retreives the profit/loss sheet.
* @param {number} tenantId
@@ -57,4 +61,14 @@ export class ProfitLossSheetApplication {
public xlsx(tenantId: number, query: IProfitLossSheetQuery): Promise<Buffer> {
return this.profitLossExport.xlsx(tenantId, query);
}
/**
* Retrieves the profit/loss sheet in pdf format.
* @param {number} tenantId
* @param {IProfitLossSheetQuery} query
* @returns {Promise<Buffer>}
*/
public pdf(tenantId: number, query: IProfitLossSheetQuery): Promise<Buffer> {
return this.profitLossPdf.pdf(tenantId, query);
}
}

View File

@@ -40,4 +40,11 @@ export class ProfitLossSheetExportInjectable {
return tableCsv;
}
public async pdf(
tenantId: number,
query: IProfitLossSheetQuery
): Promise<Buffer> {
const table = await this.profitLossSheetTable.table(tenantId, query);
}
}

View File

@@ -0,0 +1,34 @@
import { Inject, Service } from 'typedi';
import { IProfitLossSheetQuery } from '@/interfaces';
import { ProfitLossSheetTableInjectable } from './ProfitLossSheetTableInjectable';
import { TableSheetPdf } from '../TableSheetPdf';
@Service()
export class ProfitLossTablePdfInjectable {
@Inject()
private profitLossTable: ProfitLossSheetTableInjectable;
@Inject()
private tableSheetPdf: TableSheetPdf;
/**
* Retrieves the profit/loss sheet in pdf format.
* @param {number} tenantId
* @param {number} query
* @returns {Promise<IBalanceSheetTable>}
*/
public async pdf(
tenantId: number,
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
);
}
}