Update invoiceService.ts

This commit is contained in:
AllenTJ7 2025-05-20 14:15:36 +05:30
parent 80b3829347
commit 762e6b77e5

View File

@ -5,17 +5,10 @@ import * as path from 'path';
import { format } from 'date-fns'; import { format } from 'date-fns';
import { sendEmailWithAttachmentUtil } from "../../../utils/emailService"; import { sendEmailWithAttachmentUtil } from "../../../utils/emailService";
let pdfMake: any; const pdfMake = require('pdfmake/build/pdfmake');
let pdfFonts: any; const pdfFonts = require('pdfmake/build/vfs_fonts');
function initPdfLibraries() {
if (!pdfMake) {
pdfMake = require('pdfmake/build/pdfmake');
pdfFonts = require('pdfmake/build/vfs_fonts');
pdfMake.vfs = pdfFonts.pdfMake ? pdfFonts.pdfMake.vfs : pdfFonts.vfs; pdfMake.vfs = pdfFonts.pdfMake ? pdfFonts.pdfMake.vfs : pdfFonts.vfs;
}
return pdfMake;
}
const admin = getAdmin(); const admin = getAdmin();
const logger = getLogger(); const logger = getLogger();
@ -53,7 +46,6 @@ export interface EmailOptions {
export class InvoiceService { export class InvoiceService {
async generateInvoice(data: InvoiceData): Promise<string> { async generateInvoice(data: InvoiceData): Promise<string> {
try { try {
const pdfMake = initPdfLibraries();
const tempFilePath = path.join(os.tmpdir(), `invoice_${data.invoiceNumber}.pdf`); const tempFilePath = path.join(os.tmpdir(), `invoice_${data.invoiceNumber}.pdf`);
const hasGst = data.gstNumber && data.gstNumber.length > 0; const hasGst = data.gstNumber && data.gstNumber.length > 0;