mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
feat(server): table sheet pdf
This commit is contained in:
@@ -20,10 +20,11 @@ export class BalanceSheetMetaInjectable {
|
|||||||
const commonMeta = await this.financialSheetMeta.meta(tenantId);
|
const commonMeta = await this.financialSheetMeta.meta(tenantId);
|
||||||
const formattedAsDate = moment(query.toDate).format('YYYY/MM/DD');
|
const formattedAsDate = moment(query.toDate).format('YYYY/MM/DD');
|
||||||
const formattedDateRange = `As ${formattedAsDate}`;
|
const formattedDateRange = `As ${formattedAsDate}`;
|
||||||
|
const sheetName = 'Balance Sheet Statement';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...commonMeta,
|
...commonMeta,
|
||||||
sheetName: 'Balance Sheet',
|
sheetName,
|
||||||
formattedAsDate,
|
formattedAsDate,
|
||||||
formattedDateRange,
|
formattedDateRange,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ITableColumn, ITableData, ITableRow } from '@/interfaces';
|
|||||||
import { ChromiumlyTenancy } from '@/services/ChromiumlyTenancy/ChromiumlyTenancy';
|
import { ChromiumlyTenancy } from '@/services/ChromiumlyTenancy/ChromiumlyTenancy';
|
||||||
import { TemplateInjectable } from '@/services/TemplateInjectable/TemplateInjectable';
|
import { TemplateInjectable } from '@/services/TemplateInjectable/TemplateInjectable';
|
||||||
import { FinancialTableStructure } from './FinancialTableStructure';
|
import { FinancialTableStructure } from './FinancialTableStructure';
|
||||||
|
import { tableClassNames } from './utils';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class TableSheetPdf {
|
export class TableSheetPdf {
|
||||||
@@ -25,21 +26,30 @@ export class TableSheetPdf {
|
|||||||
tenantId: number,
|
tenantId: number,
|
||||||
table: ITableData,
|
table: ITableData,
|
||||||
sheetName: string,
|
sheetName: string,
|
||||||
sheetDate: string
|
sheetDate: string,
|
||||||
|
customCSS?: string
|
||||||
): Promise<Buffer> {
|
): Promise<Buffer> {
|
||||||
// Prepare columns and rows for PDF conversion
|
// Prepare columns and rows for PDF conversion
|
||||||
const columns = this.tablePdfColumns(table.columns);
|
const columns = this.tablePdfColumns(table.columns);
|
||||||
const rows = this.tablePdfRows(table.rows);
|
const rows = this.tablePdfRows(table.rows);
|
||||||
|
|
||||||
|
const landscape = columns.length > 4;
|
||||||
|
|
||||||
// Generate HTML content from the template
|
// Generate HTML content from the template
|
||||||
const htmlContent = await this.templateInjectable.render(
|
const htmlContent = await this.templateInjectable.render(
|
||||||
tenantId,
|
tenantId,
|
||||||
'modules/financial-sheet',
|
'modules/financial-sheet',
|
||||||
{ sheetName, sheetDate, table: { rows, columns } }
|
{
|
||||||
|
table: { rows, columns },
|
||||||
|
sheetName,
|
||||||
|
sheetDate,
|
||||||
|
customCSS,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
// Convert the HTML content to PDF
|
// Convert the HTML content to PDF
|
||||||
return this.chromiumlyTenancy.convertHtmlContent(tenantId, htmlContent, {
|
return this.chromiumlyTenancy.convertHtmlContent(tenantId, htmlContent, {
|
||||||
margins: { top: 0, bottom: 0, left: 0, right: 0 },
|
margins: { top: 0, bottom: 0, left: 0, right: 0 },
|
||||||
|
landscape,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -63,6 +73,6 @@ export class TableSheetPdf {
|
|||||||
const flatNestedTree = curriedFlatNestedTree(R.__, {
|
const flatNestedTree = curriedFlatNestedTree(R.__, {
|
||||||
nestedPrefix: '<span style="padding-left: 15px;"></span>',
|
nestedPrefix: '<span style="padding-left: 15px;"></span>',
|
||||||
});
|
});
|
||||||
return R.compose(flatNestedTree)(rows);
|
return R.compose(tableClassNames, flatNestedTree)(rows);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
|
import { kebabCase } from 'lodash';
|
||||||
|
import { ITableRow } from '@/interfaces';
|
||||||
|
|
||||||
export const formatNumber = (balance, { noCents, divideOn1000 }): string => {
|
export const formatNumber = (balance, { noCents, divideOn1000 }): string => {
|
||||||
let formattedBalance: number = parseFloat(balance);
|
let formattedBalance: number = parseFloat(balance);
|
||||||
@@ -11,3 +12,19 @@ export const formatNumber = (balance, { noCents, divideOn1000 }): string => {
|
|||||||
}
|
}
|
||||||
return formattedBalance;
|
return formattedBalance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const tableClassNames = (rows: ITableRow[]) => {
|
||||||
|
return rows.map((row) => {
|
||||||
|
const classNames =
|
||||||
|
row?.rowTypes?.map((rowType) => `row-type--${kebabCase(rowType)}`) || [];
|
||||||
|
|
||||||
|
if (row.id) {
|
||||||
|
classNames.push(`row-id--${kebabCase(row.id)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...row,
|
||||||
|
classNames,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user