-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathdemo23.js
More file actions
179 lines (167 loc) · 5.33 KB
/
Copy pathdemo23.js
File metadata and controls
179 lines (167 loc) · 5.33 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"use strict";
const ReportBuilder = require('../lib/fluentReportsBuilder').ReportBuilder;
const displayReport = require('./reportDisplayer');
const data = [
{
"date": "01/01/2020",
"items": [
{
"group": 1,
"number": 1,
"blah": [
{"hi": 11},
{"hi": 12}
]
},
{
"group": 2,
"number": 2,
"blah": [
{"hi": 22},
{"hi": 23}
]
}
],
"itemsold": [
{
"group": 3,
"number": 3,
"blah2": [
{"hi": 33},
{"hi": 34}
]
},
{
"group": 4,
"number": 4,
"blah2": [
{"hi": 44},
{"hi": 45}
]
}
]
}
];
// Reports can have multiple States; by default they have one State, so all states will be directed to this value
// However, a specific "type" can have its own state; called "state: <number>"
// All functions that are created should be "function (report, data, state, vars)"
let reportData =
{
"type": "report",
"dataUUID": 10002,
"fontSize": 0,
"autoPrint": false,
"name": "demo23.pdf",
"paperSize": "letter",
"paperOrientation": "portrait",
"fonts": [],
"variables": {
"test": "1",
"temp": "5"
},
"subReports": [
{
"dataUUID": 10003,
"dataType": "parent",
"data": "items",
"subReports": [
{
"dataUUID": 10004,
"dataType": "parent",
"data": "blah",
"type": "report",
"detail": [
{
"text": "Subreport items/blah Data",
"settings": {
"align": 0,
"absoluteY": 0,
},
"type": "print"
},
{
"type": "print",
"settings": {
"absoluteX": 210,
"absoluteY": 0,
"align": 0
},
"field": "hi"
},
{
"type": "print",
"settings": {
"absoluteX": 190,
"absoluteY": 0,
"align": 0
},
"variable": "temp"
}
]
}
],
"calcs": {
"sum": [
"group"
]
}
},
{
"dataUUID": 10005,
"dataType": "parent",
"data": "itemsold",
"subReports": [
{
"dataUUID": 10006,
"dataType": "parent",
"data": "blah2",
"type": "report",
"detail": [
{
"text": "Subreport itemsold/blah2 Data",
"settings": {
"align": 0
},
"type": "print"
}
]
}
],
"calcs": {
"sum": [
"group"
]
}
}
],
"header": [
{
"type": "raw",
"values": [
"Sample Header"
]
}
],
"footer": [
{
"type": "raw",
"values": [
"Sample Footer"
]
}
]
};
let rpt = new ReportBuilder(reportData, data);
// 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
rpt.registerFont("Arimo", {normal: __dirname+'/Fonts/Arimo-Regular.ttf', bold: __dirname+'/Fonts/Arimo-Bold.ttf', 'italic': __dirname+'/Fonts/Arimo-Italic.ttf'})
.font("Arimo");
if (typeof process.env.TESTING === "undefined") { rpt.printStructure(); }
console.time("Rendered");
rpt.render().then((name) => {
console.timeEnd("Rendered");
const testing = {images: 1, blocks: ["120,130,300,100"]};
displayReport(null, name, testing);
}).catch((err) => {
console.error("Your report had errors while running", err);
});