@measurequick/measurequick-report-generator 1.0.49 → 1.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,44 +1,65 @@
1
+ import * as graphics from "./templates/js/graphics.js";
2
+ import * as templates from "./templates/js/templates.js";
3
+ import * as request from "./templates/js/request.js";
4
+ import { PDFDocument } from 'pdf-lib';
5
+ import * as mqStandardRawData from "./scripts/raw-data-pdf-gen/mq-standard-raw-data.js";
6
+ import * as mqStandardFillable from "./scripts/fillable-pdf-gen/mq-standard-fillable.js";
7
+ import * as mqSystemVitalsFillable from "./scripts/fillable-pdf-gen/mq-system-vitals-fillable.js";
1
8
 
2
- import * as graphics from "./assets/graphics.js";
3
- import * as templates from "./assets/templates.js";
4
- import * as request from "./assets/request.js";
9
+ let jsPDF = require("jspdf");
10
+ let doc = new jsPDF(templates.docOptions);
11
+ let reportData;
12
+ let currentSnapshot;
5
13
 
6
- var jsPDF = require("jspdf");
7
- var doc = new jsPDF(templates.docOptions);
8
- var reportData;
9
-
10
- export function getReport(data=null) {
11
- try {
12
- if (data == null) reportData = JSON.parse(JSON.stringify(request.body));
13
- else reportData = JSON.parse(JSON.stringify(data));
14
-
15
- printBoilerPlate(reportData.meta.reportTheme);
16
-
17
- var profilePicture = reportData.meta.profilePicturePlacement == "header" ? reportData.staticPhotos.profilePicture : null;
18
- var companyLogo = reportData.meta.companyLogoPlacement == "header" ? reportData.staticPhotos.companyLogo : null;
19
- printHeaderData(reportData.meta.reportName, reportData.meta.techName, profilePicture, companyLogo);
20
-
21
- printBodyData(reportData.staticPhotos.geolocationMap);
14
+ export function getMqStandardReport(generationMethod, payload) {
15
+ // let report;
16
+ // if (generationMethod == "rawData") report = mqStandardRawData.generateReport(payload);
17
+ // else if (generationMethod == "fillable") report = mqStandardFillable.generateReport(payload);
18
+ // return report;
19
+ }
22
20
 
23
- profilePicture = reportData.meta.profilePicturePlacement == "footer" ? reportData.staticPhotos.profilePicture : null;
24
- companyLogo = reportData.meta.companyLogoPlacement == "footer" ? reportData.staticPhotos.companyLogo : null;
25
- printFooterData(reportData.meta.techName, profilePicture, companyLogo);
21
+ export function getMqSystemVitalsReport(payload) {
22
+ let report = mqSystemVitalsFillable.generateReport(payload);
23
+ return report;
24
+ }
26
25
 
27
- printPhotoSections();
26
+ export async function getFillableReport() {
27
+ const dataUri = templates.mqStandardFillablePdfBase64;
28
+ const pdfDoc = await PDFDocument.load(dataUri);
29
+ return pdfDoc;
30
+ }
28
31
 
32
+ export function getReport(data=null) {
33
+ try {
34
+ reportData = (data == null) ?
35
+ JSON.parse(JSON.stringify(request.body)) :
36
+ JSON.parse(JSON.stringify(data));
37
+ let testNumber = 0;
38
+ for (currentSnapshot in reportData.snapshots) {
39
+ if (testNumber > 0) doc.addPage();
40
+ printBoilerPlateStandard();
41
+ printHeaderData();
42
+ printBodyData(currentSnapshot);
43
+ printFooterData();
44
+ resizeAndPrintStaticImages();
45
+ testNumber++;
46
+ }
47
+ printDiagnosticPage();
29
48
  printInfoPage();
30
-
49
+ printPhotoPages();
31
50
  return doc.output("datauristring");
32
51
  } catch (e) {
33
52
  return doc.output("datauristring");
34
53
  }
35
54
  }
36
55
 
37
- function printBoilerPlate(theme) {
56
+ function printBoilerPlateStandard() {
38
57
  doc.addImage(graphics.headerMeasureQuick, "JPEG", 0, 0, 8.5, 1);
39
58
  doc.addImage(graphics.footerMeasureQuick, "JPEG", 0, 7.75, 8.5, 4.5);
40
- doc.addImage(graphics.companyLogoMeasureQuickLight, "JPEG", .25, 10, 2.15625, .5);
41
-
59
+ let mqLogo = graphics.companyLogoMeasureQuickLight;
60
+ if (reportData.meta.reportTheme == "light")
61
+ mqLogo = graphics.companyLogoMeasureQuickDark;
62
+ doc.addImage(mqLogo, "JPEG", .25, 10, 2.15625, .5);
42
63
  doc.setLineWidth(0.025);
43
64
  doc.setDrawColor(0);
44
65
  doc.setFillColor(242, 242, 242);
@@ -46,162 +67,398 @@ function printBoilerPlate(theme) {
46
67
  doc.rect(2.917, 1.125, 2.667, 3, "F");
47
68
  doc.rect(5.709, 1.125, 2.667, 3, "F");
48
69
  doc.rect(.125, 4.25, 4.0625, 3.375, "F");
49
-
50
70
  doc.addImage(graphics.iconSunshine, "JPEG", .4585, 1.625, 2, 2);
51
71
  doc.addImage(graphics.iconHouse, "JPEG", 3.252, 1.625, 2, 2);
52
72
  doc.addImage(graphics.iconInfo, "JPEG", 6.044, 1.625, 2, 2);
53
73
  doc.addImage(graphics.iconPerformance, "JPEG", 1.15625, 4.9375, 2, 2);
54
-
74
+ doc.setFontStyle("bold");
75
+ doc.setFontSize(9);
76
+ doc.text("Outdoor Measurements", .25, 1.33);
77
+ doc.text("Indoor Measurements", 3.042, 1.33);
78
+ doc.text("Weather Data", 5.834, 1.33);
79
+ doc.text("Performance Calculations", .25, 4.435);
80
+ doc.setFontSize(8);
81
+ doc.text("Capacity Calculations", .25, 4.655);
82
+ doc.text("Air-side Performance", 2.25, 4.655);
83
+ doc.text("Energy Efficiency", 2.25, 5.655);
55
84
  doc.setFontSize(6.5);
56
85
  doc.setFontStyle("bolditalic");
57
86
  doc.setTextColor(255, 255, 255);
58
- var disclaimer = `Disclaimer: This report was prepared by your service technician who is solely responsible for its content. This report is provided “as-is” excluding all warranties expressed or implied including without limitation the warranty of merchantability. ©2017-${new Date().getFullYear()} Manifold Cloud Services Ltd.`;
87
+ let disclaimer = `Disclaimer: This report was prepared by your service technician who is solely responsible for its content. This report is provided “as-is” excluding all warranties expressed or implied including without limitation the warranty of merchantability. ©2017-${new Date().getFullYear()} Manifold Cloud Services Ltd.`;
59
88
  disclaimer = doc.splitTextToSize(disclaimer.toUpperCase(), 8);
60
89
  doc.text(disclaimer, .125, 10.66);
61
90
  }
62
91
 
63
- function printHeaderData(reportName, techName, profilePicture, companyLogo) {
64
- var size = 13;
65
- var width = doc.getStringUnitWidth(reportName) * size / 72;
66
- while (width > 4.5){
67
- size -= .5;
68
- width = doc.getStringUnitWidth(reportName) * size / 72;
69
- }
92
+ function printBoilerPlateDiagnostic() {
93
+ doc.addImage(graphics.headerMeasureQuick, "JPEG", 0, 0, 8.5, 1);
94
+ doc.setLineWidth(0.025);
95
+ doc.setDrawColor(0);
96
+ doc.setFillColor(242, 242, 242);
97
+ doc.setTextColor(0, 0, 0);
98
+ doc.setFontSize(9);
99
+ doc.setFontStyle('bold');
100
+ doc.rect(.125, 3.3, 8.25, 7.6, "F");
101
+ doc.rect(.125, .6, 4.0625, 2.6, "F");
102
+ doc.rect(4.3125, .6, 4.0625, 2.6, "F");
103
+ doc.text("System Diagnostics", 4.4375, .8);
104
+ doc.text("Subsystem Review", .25, .8);
105
+ doc.text('Corrective Actions', .25, 3.5);
106
+ doc.setFontSize(8);
107
+ doc.setFontStyle('normal');
108
+
109
+ }
110
+
111
+ function printHeaderData() {
112
+ let size = 13.5;
113
+ do { size -= .5; } while ((doc.getStringUnitWidth(reportData.meta.reportName) * size / 72) > 4.5);
70
114
  doc.setFontSize(size);
71
115
  doc.setFontStyle("bold");
72
- doc.text(reportName, 0.25, .75);
73
- doc.setFontSize(8);
74
- if (profilePicture) printProfilePicture("header", techName, profilePicture);
75
- if (companyLogo) printCompanyLogo("header", companyLogo);
116
+ doc.text(reportData.meta.reportName, 0.25, .75);
76
117
  }
77
118
 
78
- function printBodyData(geolocationMap) {
119
+ function printBodyData(currentSnapshot) {
79
120
  doc.setTextColor(0, 0, 0);
80
- printMap(geolocationMap);
81
- printSingleBodySection(templates.outdoorMeasurements, .25, 2.317, 1.33);
82
- printSingleBodySection(templates.indoorMeasurements, 3.042, 5.109, 1.33);
83
- printSingleBodySection(templates.systemInfo, 5.834, 7.9, 1.33);
84
- printSingleBodySection(templates.performanceData, .25, 2, 4.435);
85
- }
86
-
87
- function printSingleBodySection(dataPoints, xLeft, xRight, y) {
88
- var yTop = y + .22;
89
- var s = .2;
90
- var dataPoint;
91
- var val;
92
- var units;
93
- var text;
94
- var i = 1;
95
- var printIcons = true;
96
- for (let key in dataPoints) {
97
- if (key == "headerLabel") {
98
- printIcons = !(dataPoints.headerLabel == "Performance Calculations");
99
- doc.setFontStyle("bold");
100
- doc.setFontSize(9);
101
- doc.text(dataPoints.headerLabel, xLeft, y);
102
- doc.setFontStyle("normal");
103
- doc.setFontSize(8);
104
- y += .22;
105
- } else if (key.includes("subHeaderLabel")) {
106
- doc.setFontStyle("bold");
107
- doc.text(dataPoints[`subHeaderLabel${i}`], xLeft, y);
108
- doc.setFontStyle("normal");
109
- y += .22;
110
- i++;
111
- } else if (key == "columnBreak") {
112
- xLeft += 2;
113
- xRight += 2;
114
- y = yTop;
115
- } else if (key == "rowBreak") {
116
- y += .3;
117
- } else {
118
- dataPoint = dataPoints[key];
119
- val = reportData.values[key];
120
- units = "";
121
- if (dataPoint.hasOwnProperty("units")) {
122
- units = Array.isArray(dataPoint.units) ? ` (${dataPoint.units[0]} / ${dataPoint.units[1]})` : ` (${dataPoint.units})`;
121
+ doc.setFontType("normal");
122
+ doc.setFontSize(8);
123
+ printBodySection(currentSnapshot, "outdoorMeasurements", .25, 2.317, 1.55);
124
+ printBodySection(currentSnapshot, "indoorMeasurements", 3.042, 5.109, 1.55);
125
+ printBodySection(currentSnapshot, "systemProfileWeatherData", 5.834, 7.9, 1.55);
126
+ printBodySection(currentSnapshot, "performanceData", .25, 2, 4.855);
127
+ printGeolocationMap();
128
+ }
129
+
130
+ function printBodySection(currentSnapshot, measurementSection, xLeft, xRight, y) {
131
+ let dataPoints = JSON.parse(reportData.snapshots[currentSnapshot][measurementSection]);
132
+ let printRangeIcons = true;
133
+ let units = "";
134
+ let labelText = "";
135
+ let valueText = "";
136
+ let yTop = y;
137
+ let s = .18;
138
+ let sMultiplier = measurementSection == "performanceData" ? 2 : 1;
139
+
140
+ for (let key in dataPoints.values) {
141
+ let dataPoint = dataPoints.values[key];
142
+ let valueBeforeEditing = dataPoint;
143
+ let templateRef = templates[measurementSection][key];
144
+ if (templateRef) {
145
+ if (templateRef.hasOwnProperty("units"))
146
+ units = Array.isArray(templateRef.units) ? `(${templateRef.units[0]} / ${templateRef.units[1]})` : `(${templateRef.units})`;
147
+ else units = "";
148
+ labelText = `${templateRef.label} ${units}:`;
149
+ if (templateRef.hasOwnProperty("roundTo")) {
150
+ dataPoint *= 1;
151
+ dataPoint = dataPoint.toFixed(templateRef.roundTo);
123
152
  }
124
- text = dataPoint.hasOwnProperty("secondaryValue") ? `${val} / ${reportData.values[dataPoint.secondaryValue]}` : val;
125
- doc.text(`${dataPoint.label}${units}:`, xLeft, y);
126
- doc.text(text, alignRight(text, xRight, 8), y);
127
- if (printIcons) doc.addImage(graphics[reportData.rangeIcons[key]], "JPEG", xRight + .05, y - .12, .16, .16);
128
- if (printIcons) doc.addImage(graphics[reportData.toolIcons[key]], "JPEG", xRight+.25, y - .12, .16, .16);
129
- y += s;
153
+ if (templateRef.hasOwnProperty("secondaryValue")) {
154
+ let secondaryDataPoint = dataPoints.values[templateRef.secondaryValue];
155
+ if (templateRef.hasOwnProperty("roundTo")) {
156
+ secondaryDataPoint *= 1;
157
+ secondaryDataPoint = secondaryDataPoint.toFixed(templateRef.roundTo);
158
+ }
159
+ valueText = `${dataPoint} / ${secondaryDataPoint}`;
160
+ } else valueText = `${dataPoint}`;
161
+ if (templateRef.label) doc.text(labelText, xLeft, y);
162
+ doc.text(valueText, alignRight(valueText, xRight, 8), y);
163
+ if (printRangeIcons) {
164
+ let rangeIconRef = getRangeIcon(key, valueBeforeEditing, currentSnapshot);
165
+ if (rangeIconRef) doc.addImage(graphics[rangeIconRef], "JPEG", xRight + .05, y - .12, .16, .16);
166
+ }
167
+ let toolIconRef = getToolIcon(reportData.snapshots[currentSnapshot].toolIcons[key]);
168
+ if (toolIconRef) doc.addImage(graphics[toolIconRef], "JPEG", xRight + .25, y - .12, .16, .16);
169
+ y += (s * sMultiplier);
170
+ } else if (key == "newColumn") {
171
+ sMultiplier = 1;
172
+ xLeft = 2.25;
173
+ xRight = 3.9;
174
+ y = yTop;
175
+ } else if (key == "newRow") {
176
+ y += .35;
130
177
  }
131
178
  }
132
179
  }
133
180
 
134
- function printMap(geolocationMap) {
135
- doc.addImage(geolocationMap, "PNG", 4.3125, 4.25, 4.0625, 3.375);
181
+ function printGeolocationMap() {
182
+ doc.addImage(reportData.staticPhotos.geolocationMap, "PNG", 4.3125, 4.25, 4.0625, 3.375);
136
183
  }
137
184
 
138
- function printProfilePicture(picturePlacement, techName, profilePicture) {
139
- var coords = templates.profilePictureCoordinates[picturePlacement];
140
- doc.addImage(profilePicture, "JPEG", coords.x, coords.y, coords.w, coords.h);
141
- doc.text(techName, alignRight(techName, 8.4, 8), coords.y + 1.2);
185
+ function printProfilePicture() {
186
+ let coords = templates.profilePictureCoordinates[reportData.meta.profilePicturePlacement];
187
+ doc.addImage(reportData.staticPhotos.profilePicture, "JPEG", coords.x, coords.y, coords.w, coords.h);
188
+ doc.text(reportData.meta.techName, alignRight(reportData.meta.techName, 8.4, 8), coords.y + 1.2);
142
189
  }
143
190
 
144
- function printCompanyLogo(logoPlacement, companyLogo) {
145
- var coords = templates.companyLogoCoordinates[logoPlacement];
146
- doc.addImage(companyLogo, "JPEG", coords.x, coords.y, coords.w, coords.h);
191
+ function printCompanyLogo() {
192
+ let coords = templates.companyLogoCoordinates[reportData.meta.companyLogoPlacement];
193
+ doc.addImage(reportData.staticPhotos.companyLogo, "JPEG", coords.x, coords.y, coords.w, coords.h);
147
194
  }
148
195
 
149
- function printFooterData(techName, profilePicture, companyLogo) {
150
- if (profilePicture) printProfilePicture("footer", techName, profilePicture);
151
- if (companyLogo) printCompanyLogo("footer", companyLogo);
152
-
196
+ function printFooterData() {
197
+ let s = .15;
198
+ let x = .2;
199
+ let y = 8;
200
+ let equipmentLabels = ["Make", "Model", "Serial"];
201
+ let i = -1;
153
202
  doc.setTextColor(255, 255, 255);
154
-
155
- var s = .2;
156
- var x = .2;
157
- var y = 8;
158
- var key;
159
-
160
203
  doc.setFontType("bold");
161
204
  doc.setFontSize(12);
162
205
  doc.text("Customer", x, y);
163
- doc.text(reportData.footerData.systemName, x + 2.5, y);
164
- doc.setFontType("normal");
206
+ doc.text("Equipment", x + 2.5, y);
207
+ doc.setFontSize(8);
208
+ y += .2;
165
209
  doc.setFontSize(10);
166
-
167
- y += s;
168
-
169
- for (let key in reportData.footerData) {
170
- if (key == "columnBreak") {
210
+ y += .05;
211
+ let footer = JSON.parse(reportData.footerData);
212
+ for (let key in footer) {
213
+ doc.setFontType("normal");
214
+ if (key.includes("header")) {
215
+ i = 0;
216
+ doc.setFontStyle("bold");
217
+ y += .1;
218
+ } else if (key == "systemCoords") {
219
+ s = .12;
171
220
  x += 2.5;
172
- y = 8 + s;
173
- } else if (key.includes("subHeaderLabel")) {
174
- doc.setFontType("bold");
175
- doc.text(`${reportData.footerData[key]}`, x, y);
176
- doc.setFontType("normal");
177
- y += s;
178
- } else {
179
- doc.text(`${reportData.footerData[key]}`, x, y);
221
+ y = 8.2;
222
+ doc.setFontStyle("bold");
223
+ doc.setFontSize(8);
224
+ doc.text("ID", x, y);
225
+ doc.setFontStyle("normal");
180
226
  y += s;
181
227
  }
228
+ let prefix = "";
229
+ if (i > -1) {
230
+ prefix = `${equipmentLabels[i]}: `;
231
+ i++;
232
+ }
233
+ doc.text(`${prefix}${footer[key]}`, x, y);
234
+ y += s;
182
235
  }
183
236
  }
184
237
 
185
- function printPhotoSections() {
186
- doc.setFontSize(16);
187
- doc.setFontColor(0, 0, 0);
188
- var x = 0;
189
- var y = 1;
238
+ function printDiagnosticPage() {
190
239
  doc.addPage();
191
- for (var i = 0; i < reportData.dynamicPhotos; i++) {
192
- doc.text(reportData.dynamicPhotos[i]);
193
- y += 1;
240
+ printBoilerPlateDiagnostic();
241
+ printSubsystemReview();
242
+ printSystemDiagnostics();
243
+ printCorrectiveActions();
244
+ }
245
+
246
+ function printSubsystemReview() {
247
+ let y = 1;
248
+ let ssr = JSON.parse(reportData.subsystemReview);
249
+ for (let i = 0; i < Object.keys(ssr).length; i++) {
250
+ let key = Object.keys(ssr)[i];
251
+ doc.text(templates.coolingSubsystemReview[key], .25, y);
252
+ doc.text(ssr[key], 3, y);
253
+ y += .15;
254
+ };
255
+ }
256
+
257
+ function printSystemDiagnostics() {
258
+ let y = 1;
259
+ let diagnostics = JSON.parse(reportData.systemDiagnostics);
260
+ for (let i = 0; i < Object.keys(diagnostics).length; i++) {
261
+ let key = Object.keys(diagnostics)[i];
262
+ // let score = diagnostics[key].score;
263
+ // let diagnosticIcon = null;
264
+ // //if (type === 'stability') icon = stability;
265
+ // if (score > 1 && score < 10) diagnosticIcon = graphics.iconFlagRed;
266
+ // else if (score >= 10 && score < 15) diagnosticIcon = graphics.iconFlagYellow;
267
+ // else if (score >= 15) diagnosticIcon = graphics.iconFlagBlack;
268
+ // if (diagnosticIcon) doc.addImage(graphics[diagnosticIcon], "JPEG", 7.8, y, .25, .25);
269
+ y += .2;
270
+ doc.text(diagnostics[key].title, 4.4375, y);
271
+ doc.text(`${diagnostics[key].score}`, 7.5, y);
272
+ }
273
+ }
274
+
275
+ function printCorrectiveActions() {
276
+ let y = 3.8;
277
+ doc.setFontSize(9);
278
+ let ca = JSON.parse(reportData.correctiveActions);
279
+ for (let i = 0; i < Object.keys(ca).length; i++) {
280
+ let sectionKey = Object.keys(ca)[i];
281
+ for (let j = 0; j < Object.keys(ca[sectionKey]).length; j++) {
282
+ let actionKey = Object.keys(ca[sectionKey])[j];
283
+ let action = ca[sectionKey][actionKey];
284
+ if (actionKey == "header") {
285
+ doc.setFontSize(10);
286
+ doc.setFontStyle("bold");
287
+ doc.text(action, .25, y);
288
+ } else {
289
+ doc.setFontSize(8);
290
+ doc.setFontStyle("normal");
291
+ doc.text(actionKey, .25, y);
292
+ }
293
+ y += .18;
294
+ }
295
+ y += .1;
296
+ }
297
+ }
298
+
299
+ function printPhotoPages() {
300
+ let photoSectionMapping = ["project", "equipment", "site", "customer"];
301
+ let x, y, header, currentQuadrant, currentSection;
302
+ for (let i = 0; i < 4; i++) { // loops through the 4 main sections of photos, listed above (photoSectionMapping)
303
+ currentSection = reportData[`${photoSectionMapping[i]}Photos`];
304
+ if (Object.keys(currentSection).length > 0) doc.addPage();
305
+ else break;
306
+ currentQuadrant = 1;
307
+ x = templates.photoCoordinates[`quadrant${currentQuadrant}`].x;
308
+ y = templates.photoCoordinates[`quadrant${currentQuadrant}`].y;
309
+ doc.setFontStyle("bold");
310
+ doc.text(`${photoSectionMapping[i][0].toUpperCase()}${photoSectionMapping[i].slice(1)} Photos`, x, y - .2);
311
+ doc.setFontStyle("normal");
312
+ for (let key in currentSection) { // loops through the "subsections" of each main photo section
313
+ if (currentSection[key].photos) {
314
+ for (let j = 0; j < currentSection[key].photos.length; j++) { // loops through the photos[] array within each subsection, of each main photo section
315
+ let currentPhoto = currentSection[key].photos[j];
316
+ if (currentQuadrant === 3) {
317
+ doc.setLineWidth(0.025);
318
+ doc.setDrawColor(194, 197, 204);
319
+ doc.line(.25, 5.5, 8.25, 5.5);
320
+ } else if (currentQuadrant === 5) {
321
+ doc.addPage();
322
+ currentQuadrant = 1;
323
+ }
324
+ x = templates.photoCoordinates[`quadrant${currentQuadrant}`].x;
325
+ y = templates.photoCoordinates[`quadrant${currentQuadrant}`].y;
326
+ if (currentPhoto.base64) {
327
+ doc.text(getPhotoSectionNameFromTag(currentPhoto.tag), x, y);
328
+ let wPicMax = 3.75,
329
+ hPicMax = 4,
330
+ wPic = wPicMax,
331
+ hPic = hPicMax,
332
+ r = currentPhoto.aspect_ratio * 1;
333
+ if (r >= 1) { // logo is a landscape image
334
+ wPic = wPicMax;
335
+ hPic = wPic / r;
336
+ if (hPic > hPicMax) { // calculated h is too large for the available space
337
+ hPic = hPicMax;
338
+ wPic = hPic * r;
339
+ }
340
+ } else { // logo is a portrait image
341
+ hPic = hPicMax;
342
+ wPic = hPic * r;
343
+ if (wPic > wPicMax) { // calculated w is too large for the available space
344
+ wPic = wPicMax;
345
+ hPic = wPic / r;
346
+ }
347
+ }
348
+ doc.addImage(currentPhoto.base64, "JPEG", x, y + .1, wPic, hPic);
349
+ }
350
+ currentQuadrant++;
351
+ }
352
+ // if (currentSection[key].hasNotes && currentSection[key].notes != "") {
353
+ // let notes = doc.splitTextToSize(`${currentSection[key].notes}`, 7.5);
354
+ // doc.setFontStyle("bold");
355
+ // doc.text("Notes:", x, y + hPic + .3);
356
+ // doc.setFontStyle("normal");
357
+ // doc.text(notes, x, y + hPic + .4);
358
+ // }
359
+ }
360
+ }
194
361
  }
195
362
  }
196
363
 
197
364
  function printInfoPage() {
365
+ let infoPage = templates[`${reportData.meta.reportType}InfoPage`];
198
366
  doc.addPage();
199
367
  doc.setTextColor(0, 0, 0);
200
- if (reportData.meta.reportType == "cooling") {
201
- doc.text(templates.coolingInfoPage.body, 1, 1);
202
- } else if (reportData.meta.reportType == "heating") {
203
- doc.text(templates.heatingInfoPage.body, 1, 1);
368
+ doc.setFontStyle("bold");
369
+ doc.setFontSize(14);
370
+ doc.text(infoPage.header, .5, .6);
371
+ doc.setFontSize(12);
372
+ for (let i = 0; i < infoPage.subheader.length; i++) {
373
+ let y = infoPage.y[i];
374
+ doc.setFontStyle("bold");
375
+ doc.text(infoPage.subheader[i], .5, y);
376
+ y += .2;
377
+ doc.setFontStyle("normal");
378
+ doc.text(doc.splitTextToSize(infoPage.body[i], 7.5), .5, y);
379
+ }
380
+ }
381
+
382
+ function getPhotoSectionNameFromTag(tag) {
383
+ let tagPrefixRemoved = tag.substr(tag.indexOf('_'));
384
+ let tagUnderscoresReplaced = tagPrefixRemoved.replaceAll('_', ' ');
385
+ let sectionName = `${tagUnderscoresReplaced.charAt(0).toUpperCase()}${tagUnderscoresReplaced.slice(1)}`;
386
+ return sectionName;
387
+ }
388
+
389
+ function resizeAndPrintStaticImages() {
390
+ let wMax = 2.25,
391
+ hMax = .7,
392
+ x_profile = 6.9,
393
+ y_profile = 8.13,
394
+ size_profile = 1.25,
395
+ x_name = 8.15,
396
+ y_name = 8.025,
397
+ r = reportData.meta.companyLogoAspectRatio,
398
+ xOffset = 0,
399
+ yOffset = 0,
400
+ w = 0,
401
+ h = 0,
402
+ x = 6,
403
+ y = .2;
404
+ if (reportData.meta.companyLogoPlacement !== "header") {
405
+ x = 6;
406
+ y = 8;
407
+ x_profile = 7.375;
408
+ y_profile = .15;
409
+ size_profile = reportData.meta.reportTheme === 'dark' ? .8 : .9;
410
+ x_name = 7.25;
411
+ y_name = .5;
412
+ wMax = 2.25;
413
+ hMax = .8
414
+ }
415
+ if (r >= 1) {
416
+ w = wMax;
417
+ h = w / r;
418
+ if (h > hMax) {
419
+ h = hMax;
420
+ w = h * r;
421
+ }
422
+ } else {
423
+ h = hMax;
424
+ w = h * r;
425
+ if (w > wMax) {
426
+ w = wMax;
427
+ h = w / r;
428
+ }
429
+ }
430
+ if (w < wMax) x = 8.5 - .25 - w;
431
+ doc.setFontSize(12);
432
+ doc.setFontType("bold");
433
+ doc.setTextColor(255, 255, 255);
434
+ if (reportData.meta.companyLogoPlacement == "Header" && h < hMax)
435
+ y = y + ((hMax - h) / 2);
436
+ doc.addImage(reportData.staticPhotos.companyLogo, "JPEG", x, y, w, h);
437
+ doc.addImage(reportData.staticPhotos.profilePicture, "JPEG", x_profile, y_profile, size_profile, size_profile);
438
+ }
439
+
440
+ function getToolIcon(measurementSource) {
441
+ switch (measurementSource) {
442
+ case "Fieldpiece": return "companyLogoFieldpiece";
443
+ default: return null;
444
+ }
445
+ }
446
+
447
+ function getRangeIcon(key, actualValue, currentSnapshot) {
448
+ let ranges = JSON.parse(reportData.snapshots[currentSnapshot].rangeIcons);
449
+ let target = null, low = null, high = null;
450
+ let rangeIconRef = null;
451
+ if (ranges[key]) {
452
+ target = parseFloat(ranges[key]);
453
+ if (ranges[`${key}_ideal_low`]) low = target - parseFloat(ranges[`${key}_ideal_low`]);
454
+ if (ranges[`${key}_ideal_high`]) high = target + parseFloat(ranges[`${key}_ideal_high`]);
455
+ if (target && low && high) {
456
+ if (actualValue < low) rangeIconRef = "iconRangeLow";
457
+ else if (actualValue > high) rangeIconRef = "iconRangeHigh";
458
+ else rangeIconRef = "iconRangeNormal";
459
+ }
204
460
  }
461
+ return rangeIconRef;
205
462
  }
206
463
 
207
464
  function alignRight(text, rightAlign, fontSize) {
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@measurequick/measurequick-report-generator",
3
- "version": "1.0.49",
3
+ "version": "1.0.52",
4
4
  "description": "Generates PDF documents for various MeasureQuick applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
9
  "dependencies": {
10
- "jspdf": "^1.3.5"
10
+ "jspdf": "^1.3.5",
11
+ "pdf-lib": "^1.16.0"
11
12
  },
12
13
  "keywords": [
13
14
  "measurequick"