-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathdemo26.js
More file actions
113 lines (97 loc) · 3.09 KB
/
Copy pathdemo26.js
File metadata and controls
113 lines (97 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use strict';
const Report = require('../lib/fluentReports' ).Report;
const displayReport = require('./reportDisplayer');
function printreport() {
var myTotalFormatter = function (data, callback) {
//console.log("myTotalFormatter: ", data);
for (var key in data) {
if (data.hasOwnProperty(key)) {
if (key === 'total') {
data[key] = '$ ' + data[key].toFixed(2);
}
}
}
callback(null, data);
};
let runTotals = function(rpt) {
rpt.standardFooter([
['BWshade$',1,3],
['sleeve$', 2, 3],
['cash$', 3, 3],
['credit$', 4, 3],
['total', 6, 3],
]);
};
let detail = function(rpt, data) {
rpt.band([
{data: data['BWshade$'], width: 60},
{data: data['sleeve$'], width: 60},
{data: data['cash$'], width: 60},
{data: data['credit$'], width: 60},
{data: data['total'], width: 100},
{data: data['total'].toFixed(2), width: 60},
], {border: 1});
};
let artData = [
{
'BWshade$': 0,
'sleeve$': 0,
'cash$': 15.37,
'credit$': 0,
'total': 15.37
},
{
'BWshade$': 1,
'sleeve$': 0,
'cash$': 0,
'credit$': 60,
'total': 60
},
{
'BWshade$': 1,
'sleeve$': 7,
'cash$': 123.39,
'credit$': 180,
'total': 303.39
},
{
'BWshade$': 8,
'sleeve$': 6,
'cash$': 190,
'credit$': 295,
'total': 485
},
{
'BWshade$': 2,
'sleeve$': 1,
'cash$': 85.17,
'credit$': 60,
'total': 145.17000000002
}
];
let rptName = "demo26.pdf";
// Create a Report
const resultReport = new Report(rptName)
.data(artData) // Add some Data (This is required)
.pageFooter(runTotals)
.detail(detail)
.sum('BWshade$')
.sum('sleeve$')
.sum('cash$')
.sum('credit$')
.sum('total')
.totalFormatter(myTotalFormatter);
// These two lines are not normally needed for any normal reports unless you want to use your own fonts...
// We need to add this because of TESTING and making the report consistent for CI environments
resultReport.registerFont("Arimo", {normal: __dirname+'/Fonts/Arimo-Regular.ttf', bold: __dirname+'/Fonts/Arimo-Bold.ttf', 'italic': __dirname+'/Fonts/Arimo-Italic.ttf'})
.font("Arimo");
// Hey, everyone needs to debug things occasionally -- creates debug output so that you can see how the report is built.
if (typeof process.env.TESTING === "undefined") { resultReport.printStructure(); }
console.time("Rendered");
resultReport.render(function(err, name) {
console.timeEnd("Rendered");
const testing = {images: 1};
displayReport(err, name, testing);
});
}
printreport();