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 { CustomerBalanceSummaryExportInjectable } from './CustomerBalanceSummary
import { CustomerBalanceSummaryTableInjectable } from './CustomerBalanceSummaryTableInjectable';
import { ICustomerBalanceSummaryQuery } from '@/interfaces';
import { CustomerBalanceSummaryService } from './CustomerBalanceSummaryService';
import { CustomerBalanceSummaryPdf } from './CustomerBalanceSummaryPdf';
@Service()
export class CustomerBalanceSummaryApplication {
@@ -15,6 +16,9 @@ export class CustomerBalanceSummaryApplication {
@Inject()
private customerBalanceSummarySheet: CustomerBalanceSummaryService;
@Inject()
private customerBalanceSummaryPdf: CustomerBalanceSummaryPdf;
/**
* Retrieves the customer balance sheet in json format.
* @param {number} tenantId
@@ -57,4 +61,14 @@ export class CustomerBalanceSummaryApplication {
public csv(tenantId: number, query: ICustomerBalanceSummaryQuery) {
return this.customerBalanceSummaryExport.csv(tenantId, query);
}
/**
* Retrieves the customer balance sheet in PDF format.
* @param {number} tenantId
* @param {ICustomerBalanceSummaryQuery} query
* @returns {Promise<Buffer>}
*/
public pdf(tenantId: number, query: ICustomerBalanceSummaryQuery) {
return this.customerBalanceSummaryPdf.pdf(tenantId, query);
}
}

View File

@@ -0,0 +1,34 @@
import { Inject, Service } from 'typedi';
import { IAPAgingSummaryQuery, ICustomerBalanceSummaryQuery } from '@/interfaces';
import { TableSheetPdf } from '../TableSheetPdf';
import { CustomerBalanceSummaryTableInjectable } from './CustomerBalanceSummaryTableInjectable';
@Service()
export class CustomerBalanceSummaryPdf {
@Inject()
private customerBalanceSummaryTable: CustomerBalanceSummaryTableInjectable;
@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: ICustomerBalanceSummaryQuery
): Promise<Buffer> {
const table = await this.customerBalanceSummaryTable.table(tenantId, query);
const sheetName = 'Customer Balance Summary';
return this.tableSheetPdf.convertToPdf(
tenantId,
table.table,
sheetName,
table.meta.baseCurrency
);
}
}