-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathreportgenerator.htm
177 lines (161 loc) · 7.19 KB
/
reportgenerator.htm
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
<head>
<meta charset="utf-8">
<title>fluentReports</title>
<meta name="description" content="Node and Browser based Reporting engine">
<meta name="keywords" content="fluentReports pdf report development data driven javascript engine node node.js io.js browser chrome firefox safari">
<meta name="author" content="Nathanael Anderson">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./fluentReportsGenerator.js"></script>
<style type="text/css" media="screen">
body {
background-color: #c9c9c9;
}
#fluentReportsEditor {
border: solid red 1px;
height: 450px;
}
</style>
</head>
<body>
<div>Report Generator</div>
<div id="fluentReportsEditor"></div>
<pre id="results"></pre>
<!-- div><a href="#">Display ⏎ ⇕ ↕ </a></div-->
</body>
<script>
const data = [
{id: 1, name: "John Doe", emphours: [
{week: 20, day: "Monday", hours: 4},
{week: 20, day: "Tuesday", hours: 8},
{week: 20, day: "Wednesday", hours: 8},
{week: 21, day: "Thursday", hours: -2},
{week: 21, day: "Friday", hours: 8},
{week: 22, day: "Monday", hours: 4},
{week: 22, day: "Tuesday", hours: 8},
{week: 22, day: "Wednesday", hours: 8},
{week: 23, day: "Thursday", hours: 2},
{week: 23, day: "Friday", hours: 8},
{week: 25, day: "Monday", hours: 4},
{week: 25, day: "Tuesday", hours: 8},
{week: 25, day: "Wednesday", hours: 8},
{week: 26, day: "Thursday", hours: 2},
{week: 26, day: "Friday", hours: 8}
]},
{id: 3, name: "Sarah Williams", emphours: [
{week:20, day: "Monday", hours: 8}
]},
{id: 5, name: "Jane Doe", emphours: [
{week: 20, day: "Monday", hours: 5},
{week: 20, day: "Tuesday", hours: 8},
{week: 21, day: "Wednesday", hours: 7},
{week: 21, day: "Thursday", hours: 8},
{week: 21, day: "Friday", hours: 8},
{week: 22, day: "Monday", hours: 5},
{week: 22, day: "Tuesday", hours: 8},
{week: 23, day: "Wednesday", hours: 7},
{week: 23, day: "Thursday", hours: 8},
{week: 23, day: "Friday", hours: 8},
{week: 25, day: "Monday", hours: 5},
{week: 25, day: "Tuesday", hours: 8},
{week: 26, day: "Wednesday", hours: 7},
{week: 26, day: "Thursday", hours: 8},
{week: 26, day: "Friday", hours: 8}
]}
];
let reportData =
{
type: 'report',
name: 'demo19.pdf',
autoPrint: false,
fontSize: 8,
paperSize: "legal",
variables: {counter: 0},
//titleHeader: [],
finalSummary: {type: 'raw', values: ["Total Hours:", "hours", 3]},
pageHeader: {type: 'raw', values: ["Employee Hours"]},
//pageFooter: null,
//detail: [],
groupBy: [{
type: 'group',
groupOn: 'name',
header: [
{
type: "print",
field: 'name',
settings: {fontBold: true, fill: '#6f6f6f', textColor: '#ffffff', link: 'http://www.fluentReports.com/'}
} ],
detail: [],
footer: [
{type: 'calculation', op: "concat", name: 'totals', fields: [{text: "Totals for "}, {field: "name"}]},
{
type: "band",
fields: [
{function: {type: 'function', name: 'Totals for data.name', function: "return `Totals for ${data.name}`", async: false}, width: 180},
{total: "hours", width: 100, align: 3}
]},
{type: 'newLine'}
],
}
],
subReport:
{
type: 'report',
dataType: 'parent',
data: 'emphours',
calcs: {sum: ['hours']},
groupBy: [
{
type: "group",
groupOn: "week",
header: [
{
skip: true, type: 'function', function: "vars.counter=0;", async: false, name: 'counter reset'
},
{
type: 'print',
function: {type: 'function', function: 'return `Week Number: ${data.week}`', name: 'Week number: data.week'},
settings: {x: 100, addY: 2}
}],
detail: [],
footer: [ {
type: 'newLine'
}]
}
],
detail: [
{
type: 'function', function: "vars.counter++;", name: 'increase counter'
},
{
type: 'band',
fields: [
{text: '', width: 80},
{field: 'day', width: 100},
{field: 'hours', width: 100, align: 3, textColor: {type: 'function', function: "return data.hours < 0 ? '#FF0000' : '#000000';", name: 'textColor'}}
],
settings:
{
border:0, width: 0, wrap: true, textColor: '#0000ff',
fill: {type: 'function', function: "return (vars.counter % 2 === 0 ? '#f0f0f0' : '#e0e0e0');", name: 'fill'}
}
},
]
},
// footer: []
};
const frg = new FluentReportsGenerator({
id: "fluentReportsEditor",
data: data,
report: reportData,
debug: true,
multiSelectKey: "shift", // can be "ctrl", "shift", or "meta"
// preview: false, // You can disable the preview button if you want...
save: (value, done) => {
console.log("Saving");
const results = document.getElementById("results");
results.innerText = JSON.stringify(value, null, 4);
console.dir(value);
done();
}
});
</script>