I have three arrays "listA, listB, listC" and I want to create three tables from those lists. So far I have only been able to create a single table and I I haven't been able to figure out how to do what I want with the documentation. fluentreports documentaiton
Here is what I have so far, I was looking at .addReport and tried using it but I am getting an error "Unhandled rejection TypeError: rpt.addReport is not a function". Can I please get some help to display multiple tables. My code is below.
const express = require('express');
const db = require('../config/db');
const router = new express.Router();
const PDFDocument = require('pdfkit')
const Report = require('fluentreports').Report
var fs = require("fs")
router.get('/getpdf', (req, res) => {
res.type('application/pdf');
// Our Simple Data in Object format:
var data = [{name: 'Elijah', age: 18}, {name: 'Abraham', age: 22}, {name: 'Gavin', age: 28}];
var results1;
db.sequelize.query("SELECT device.\"deviceID\", device.\"deviceType\", event.data, event.\"event_time_stamp\" FROM public.device, public.event WHERE event.\"device_deviceID\" = device.\"deviceID\"").spread((results, metadata) => {
//console.log(results)
var listA = [];
var listB = [];
var listC = [];
results.map(cv => {
switch (cv.deviceType) {
case 'type1':
listA.push(cv);
break;
case 'type2':
listB.push(cv);
break;
case 'type3':
listC.push(cv);
break;
}
});
listA.map(cv => {
[cv.quantity, cv.additional] = cv.data.split(',');
cv.deviceType = 'Poison Grizach';
cv.quantity = cv.quantity + '%'
delete cv.data;
});
listB.map(cv => {
[cv.mouse, cv.rat, cv.other, cv.additional] = cv.data.split(',');
cv.deviceType = 'Non-Poison Grizach';
delete cv.data;
});
listC.map(cv => {
[cv.flies, cv.quantity, cv.additional] = cv.data.split(',');
cv.deviceType = 'Insect Lamp';
cv.flies = cv.flies + '%'
delete cv.data;
});
var all = listA.concat(listB).concat(listC)
var headerFunction = function(Report) {
Report.print("Device Scans", {fontSize: 22, bold: true, underline:true, align: "center"});
Report.newLine(2);
Report.band([
{data: 'Device Type', width: 100},
{data: 'Quantity', width: 50},
{data: 'Mouse', width: 50},
{data: 'Rat', width: 50},
{data: 'Other', width: 50},
{data: 'Additional', width: 50},
{data: '% Myxi', width: 50},
]);
};
// Create a Report
var rpt = new Report(res,({fontSize: 10}))
.pageHeader( ["Device Scans"] ) // Add a simple (optional) page Header...
.margins(40)
.data( all ) // Add some Data (This is required)
.pageHeader(headerFunction)
.detail( [ ['deviceType', 100], ['quantity', 50] , ['mouse', 50], ['rat', 50], ['other', 50], ['additional', 50] , ['flies', 50]]) // Layout the report in a Grid of 200px & 50px
.render()
var rpt2 = new Report(res,({fontSize: 10}))
.pageHeader( ["Device Scans"] ) // Add a simple (optional) page Header...
.margins(40)
.data( listB ) // Add some Data (This is required)
.pageHeader(headerFunction)
.detail( [ ['deviceType', 100] , ['mouse', 50], ['rat', 50], ['other', 50], ['additional', 50] ]) // Layout the report in a Grid of 200px & 50px
rpt.addReport(rpt2)
})
});
module.exports = router;
via Tzvetlin Velev
No comments:
Post a Comment