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 { APAgingSummaryExportInjectable } from './APAgingSummaryExportInjectable
import { APAgingSummaryTableInjectable } from './APAgingSummaryTableInjectable';
import { IAPAgingSummaryQuery } from '@/interfaces';
import { APAgingSummaryService } from './APAgingSummaryService';
import { APAgingSummaryPdfInjectable } from './APAgingSummaryPdfInjectable';
@Service()
export class APAgingSummaryApplication {
@@ -15,6 +16,9 @@ export class APAgingSummaryApplication {
@Inject()
private APAgingSummarySheet: APAgingSummaryService;
@Inject()
private APAgingSumaryPdf: APAgingSummaryPdfInjectable;
/**
* Retrieve the A/P aging summary in sheet format.
* @param {number} tenantId
@@ -50,4 +54,14 @@ export class APAgingSummaryApplication {
public xlsx(tenantId: number, query: IAPAgingSummaryQuery) {
return this.APAgingSummaryExport.xlsx(tenantId, query);
}
/**
* Retrieves the A/P aging summary in pdf format.
* @param {number} tenantId
* @param {IAPAgingSummaryQuery} query
* @returns {Promise<Buffer>}
*/
public pdf(tenantId: number, query: IAPAgingSummaryQuery) {
return this.APAgingSumaryPdf.pdf(tenantId, query);
}
}

View File

@@ -0,0 +1,34 @@
import { Inject, Service } from 'typedi';
import { IAPAgingSummaryQuery } from '@/interfaces';
import { TableSheetPdf } from '../TableSheetPdf';
import { APAgingSummaryTableInjectable } from './APAgingSummaryTableInjectable';
@Service()
export class APAgingSummaryPdfInjectable {
@Inject()
private APAgingSummaryTable: APAgingSummaryTableInjectable;
@Inject()
private tableSheetPdf: TableSheetPdf;
/**
* Converts the given A/P aging summary sheet table to pdf.
* @param {number} tenantId - Tenant ID.
* @param {IAPAgingSummaryQuery} query - Balance sheet query.
* @returns {Promise<Buffer>}
*/
public async pdf(
tenantId: number,
query: IAPAgingSummaryQuery
): Promise<Buffer> {
const table = await this.APAgingSummaryTable.table(tenantId, query);
const sheetName = 'AR Aging Summary';
return this.tableSheetPdf.convertToPdf(
tenantId,
table.table,
sheetName,
table.meta.baseCurrency
);
}
}

View File

@@ -3,6 +3,7 @@ import { IARAgingSummaryQuery } from '@/interfaces';
import { ARAgingSummaryTableInjectable } from './ARAgingSummaryTableInjectable';
import { ARAgingSummaryExportInjectable } from './ARAgingSummaryExportInjectable';
import ARAgingSummaryService from './ARAgingSummaryService';
import { ARAgingSummaryPdfInjectable } from './ARAgingSummaryPdfInjectable';
@Service()
export class ARAgingSummaryApplication {
@@ -15,6 +16,9 @@ export class ARAgingSummaryApplication {
@Inject()
private ARAgingSummarySheet: ARAgingSummaryService;
@Inject()
private ARAgingSummaryPdf: ARAgingSummaryPdfInjectable;
/**
* Retrieve the A/R aging summary sheet.
* @param {number} tenantId
@@ -50,4 +54,14 @@ export class ARAgingSummaryApplication {
public csv(tenantId: number, query: IARAgingSummaryQuery) {
return this.ARAgingSummaryExport.csv(tenantId, query);
}
/**
* Retrieves the A/R aging summary in pdf format.
* @param {number} tenantId
* @param {IARAgingSummaryQuery} query
* @returns {Promise<Buffer>}
*/
public pdf(tenantId: number, query: IARAgingSummaryQuery) {
return this.ARAgingSummaryPdf.pdf(tenantId, query);
}
}

View File

@@ -0,0 +1,34 @@
import { Inject, Service } from 'typedi';
import { IARAgingSummaryQuery } from '@/interfaces';
import { TableSheetPdf } from '../TableSheetPdf';
import { ARAgingSummaryTableInjectable } from './ARAgingSummaryTableInjectable';
@Service()
export class ARAgingSummaryPdfInjectable {
@Inject()
private ARAgingSummaryTable: ARAgingSummaryTableInjectable;
@Inject()
private tableSheetPdf: TableSheetPdf;
/**
* Converts the given balance sheet table to pdf.
* @param {number} tenantId - Tenant ID.
* @param {IBalanceSheetQuery} query - Balance sheet query.
* @returns {Promise<Buffer>}
*/
public async pdf(
tenantId: number,
query: IARAgingSummaryQuery
): Promise<Buffer> {
const table = await this.ARAgingSummaryTable.table(tenantId, query);
const sheetName = 'AR Aging Summary';
return this.tableSheetPdf.convertToPdf(
tenantId,
table.table,
sheetName,
table.meta.baseCurrency
);
}
}