@@ -306,6 +306,7 @@ const generatePdf = async (req, res) => {
306
306
const doc = new PDFDocument ( ) ;
307
307
const filename = 'sales-report.pdf' ;
308
308
const orders = req . body ;
309
+ // console.log(orders);
309
310
res . setHeader ( 'Content-Type' , 'application/pdf' ) ;
310
311
res . setHeader ( 'Content-Disposition' , `attachment; filename=${ filename } ` ) ;
311
312
doc . pipe ( res ) ;
@@ -331,27 +332,32 @@ const generatePdf = async (req, res) => {
331
332
332
333
const headers = [ 'Order ID' , 'Name' , 'Date' , 'Total' ] ;
333
334
334
- let headerX = 20 ;
335
- const headerY = doc . y + 10 ;
335
+ let headerX = 20 ;
336
+ const headerY = doc . y + 10 ;
336
337
337
- doc . text ( headers [ 0 ] , headerX , headerY ) ;
338
- headerX += 200 ;
338
+ doc . text ( headers [ 0 ] , headerX , headerY ) ;
339
+ headerX += 200 ;
339
340
340
- headers . slice ( 1 ) . forEach ( header => {
341
- doc . text ( header , headerX , headerY ) ;
342
- headerX += 130 ;
343
- } ) ;
341
+ headers . slice ( 1 ) . forEach ( header => {
342
+ doc . text ( header , headerX , headerY ) ;
343
+ headerX += 130 ;
344
+ } ) ;
344
345
345
- let dataY = headerY + 25 ;
346
+ let dataY = headerY + 25 ;
346
347
347
- orders . forEach ( order => {
348
- doc . text ( order . dataId , 20 , dataY ) ;
349
- doc . text ( order . name , 210 , dataY ) ;
350
- doc . text ( order . date , 350 , dataY ) ;
351
- doc . text ( order . totalAmount , 480 , dataY ) ;
352
- dataY += 30 ;
348
+ orders . forEach ( order => {
349
+ const cleanedDataId = order . dataId . trim ( ) ;
350
+ const cleanedName = order . name . trim ( ) ;
353
351
354
- } ) ;
352
+ doc . text ( cleanedDataId , 20 , dataY , { width : 200 } ) ;
353
+ doc . text ( cleanedName , 230 , dataY ) ;
354
+ doc . text ( order . date , 350 , dataY , { width : 120 } ) ;
355
+ doc . text ( order . totalAmount , 490 , dataY ) ;
356
+
357
+ dataY += 30 ;
358
+ } ) ;
359
+
360
+
355
361
356
362
doc . end ( ) ;
357
363
} catch ( error ) {
@@ -360,9 +366,9 @@ const generatePdf = async (req, res) => {
360
366
}
361
367
362
368
363
- const downloadExcel = async ( req , res ) => {
369
+ const downloadExcel = async ( req , res ) => {
364
370
try {
365
-
371
+
366
372
const workbook = new ExcelJS . Workbook ( ) ;
367
373
const worksheet = workbook . addWorksheet ( 'Sales Report' ) ;
368
374
0 commit comments