@measurequick/measurequick-report-generator 1.4.23 → 1.4.25
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/package.json +1 -1
- package/report-gen-scripts/acca-certificate.js +5 -3
- package/report-gen-scripts/bluvac-report.js +6 -6
- package/report-gen-scripts/classic-report.js +1 -1
- package/report-gen-scripts/corrective-measures.js +11 -10
- package/report-gen-scripts/cover-page.js +5 -3
- package/report-gen-scripts/energy-star-certificate.js +5 -3
- package/report-gen-scripts/franklin-energy-report.js +3 -4
- package/report-gen-scripts/full-report.js +57 -28
- package/report-gen-scripts/measurement-details-acca.js +5 -6
- package/report-gen-scripts/measurement-details.js +7 -8
- package/report-gen-scripts/photos-report-s3.js +16 -11
- package/report-gen-scripts/photos-report.js +118 -115
- package/report-gen-scripts/ptcs-heat-pump-report.js +25 -20
- package/report-gen-scripts/sign-terms-conditions.js +17 -12
- package/report-gen-scripts/system-info-page.js +11 -11
- package/report-gen-scripts/vitals-cooling-report.js +199 -197
- package/report-gen-scripts/vitals-heating-report.js +5 -3
package/package.json
CHANGED
|
@@ -22,7 +22,9 @@ export async function getReport(payload) {
|
|
|
22
22
|
|
|
23
23
|
// flatten and return as base64
|
|
24
24
|
form.flatten();
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
} catch (error) {
|
|
25
|
+
let _pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
26
|
+
return { code: 200, pdf: _pdf };
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return { code: 400, error: error };
|
|
29
|
+
}
|
|
28
30
|
}
|
|
@@ -6,10 +6,10 @@ import * as util from '../util.js';
|
|
|
6
6
|
|
|
7
7
|
export async function getReport(payload) {
|
|
8
8
|
try {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const pdfDoc = await PDFDocument.load(util._base64ToArrayBuffer(payload.meta.base64));
|
|
10
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
11
|
+
return { code: 200, pdf: pdf };
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return { code: 400, error: error };
|
|
14
|
+
}
|
|
15
15
|
}
|
|
@@ -97,12 +97,12 @@ export async function getReport(payload) {
|
|
|
97
97
|
|
|
98
98
|
/** START CORRECTIVE ACTIONS **/
|
|
99
99
|
let header,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
text = "",
|
|
101
|
+
col = 1,
|
|
102
|
+
maxWidth = 165,
|
|
103
|
+
maxHeight = 362,
|
|
104
|
+
maxLines = Math.floor(maxHeight / font.heightAtSize(8)) - 3,
|
|
105
|
+
numLines = 1;
|
|
106
106
|
for (let i = 0; i < payload.system_data.block3.length && col < 7; i++) {
|
|
107
107
|
let action = payload.system_data.block3[i];
|
|
108
108
|
if (header != action.ref) {
|
|
@@ -128,8 +128,9 @@ export async function getReport(payload) {
|
|
|
128
128
|
/** END CORRECTIVE ACTIONS **/
|
|
129
129
|
|
|
130
130
|
form.flatten();
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
132
|
+
return { code: 200, pdf: pdf };
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return { code: 400, error: error };
|
|
135
|
+
}
|
|
135
136
|
}
|
|
@@ -31,7 +31,9 @@ export async function getReport(payload) {
|
|
|
31
31
|
if (companyImage) form.getButton("Company Logo").setImage(companyImage);
|
|
32
32
|
} else if (companyImage) form.getButton("Company Logo Full").setImage(companyImage);
|
|
33
33
|
form.flatten();
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
} catch (error) {
|
|
34
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
35
|
+
return { code: 200, pdf: pdf };
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return { code: 400, error: error };
|
|
38
|
+
}
|
|
37
39
|
}
|
|
@@ -25,7 +25,9 @@ export async function getReport(payload) {
|
|
|
25
25
|
|
|
26
26
|
// flatten and return as base64
|
|
27
27
|
form.flatten();
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
} catch (error) {
|
|
28
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
29
|
+
return { code: 200, pdf: pdf };
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return { code: 400, error: error };
|
|
32
|
+
}
|
|
31
33
|
}
|
|
@@ -21,10 +21,9 @@ export async function getReport(payload) {
|
|
|
21
21
|
|
|
22
22
|
// flatten and return as base64
|
|
23
23
|
form.flatten();
|
|
24
|
-
|
|
25
|
-
return
|
|
24
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
25
|
+
return { code: 200, pdf: pdf };
|
|
26
26
|
} catch (error) {
|
|
27
|
-
|
|
28
|
-
return error;
|
|
27
|
+
return { code: 400, error: error };
|
|
29
28
|
}
|
|
30
29
|
}
|
|
@@ -9,6 +9,8 @@ import * as photosReportS3 from './photos-report-s3.js';
|
|
|
9
9
|
import * as systemInfoPage from './system-info-page.js';
|
|
10
10
|
import * as vitalsCoolingReport from './vitals-cooling-report.js';
|
|
11
11
|
import * as vitalsHeatingReport from './vitals-heating-report.js';
|
|
12
|
+
import * as energyStarCertificate from './energy-star-certificate.js';
|
|
13
|
+
import * as accaCertificate from './acca-certificate.js';
|
|
12
14
|
import * as util from '../util.js';
|
|
13
15
|
|
|
14
16
|
let docs = [];
|
|
@@ -24,7 +26,9 @@ export async function getReport(payload) {
|
|
|
24
26
|
const coverPageDoc = coverPageBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(coverPageBase64)) : false;
|
|
25
27
|
const [_coverPageDoc] = coverPageDoc ? await coreDoc.copyPages(coverPageDoc, [0]) : false;
|
|
26
28
|
if (_coverPageDoc) coreDoc.insertPage(coreDoc.getPages().length, _coverPageDoc);
|
|
27
|
-
} catch (
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return { code: 400, error: error };
|
|
31
|
+
}
|
|
28
32
|
|
|
29
33
|
/******** TEST IN VITALS (2 PAGES) *********/
|
|
30
34
|
try {
|
|
@@ -54,7 +58,9 @@ export async function getReport(payload) {
|
|
|
54
58
|
coreDoc.insertPage(coreDoc.getPages().length, _vitalsReportPg1);
|
|
55
59
|
coreDoc.insertPage(coreDoc.getPages().length, _vitalsReportPg2);
|
|
56
60
|
}
|
|
57
|
-
} catch (
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return { code: 400, error: error };
|
|
63
|
+
}
|
|
58
64
|
|
|
59
65
|
/******** TEST IN MEASUREMENTS (1 PAGE) *********/
|
|
60
66
|
try {
|
|
@@ -62,7 +68,9 @@ export async function getReport(payload) {
|
|
|
62
68
|
const measurementDetailsDoc = measurementDetailsBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(measurementDetailsBase64)) : false;
|
|
63
69
|
const [_measurementDetailsDoc] = measurementDetailsDoc ? await coreDoc.copyPages(measurementDetailsDoc, [0]) : false;
|
|
64
70
|
if (_measurementDetailsDoc) coreDoc.insertPage(coreDoc.getPages().length, _measurementDetailsDoc);
|
|
65
|
-
} catch (
|
|
71
|
+
} catch (error) {
|
|
72
|
+
return { code: 400, error: error };
|
|
73
|
+
}
|
|
66
74
|
|
|
67
75
|
/******** TEST IN ACCA MEASUREMENTS (1 PAGE) *********/
|
|
68
76
|
try {
|
|
@@ -72,7 +80,9 @@ export async function getReport(payload) {
|
|
|
72
80
|
const [_measurementDetailsAccaDoc] = measurementDetailsAccaDoc ? await coreDoc.copyPages(measurementDetailsAccaDoc, [0]) : false;
|
|
73
81
|
if (_measurementDetailsAccaDoc) coreDoc.insertPage(coreDoc.getPages().length, _measurementDetailsAccaDoc);
|
|
74
82
|
}
|
|
75
|
-
} catch (
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return { code: 400, error: error };
|
|
85
|
+
}
|
|
76
86
|
|
|
77
87
|
/******** TEST OUT VITALS (2 PAGES) *********/
|
|
78
88
|
try {
|
|
@@ -85,7 +95,9 @@ export async function getReport(payload) {
|
|
|
85
95
|
coreDoc.insertPage(coreDoc.getPages().length, _vitalsReportPg1);
|
|
86
96
|
coreDoc.insertPage(coreDoc.getPages().length, _vitalsReportPg2);
|
|
87
97
|
}
|
|
88
|
-
} catch (
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return { code: 400, error: error };
|
|
100
|
+
}
|
|
89
101
|
|
|
90
102
|
/******** TEST OUT MEASUREMENTS (1 PAGE) *********/
|
|
91
103
|
try {
|
|
@@ -95,31 +107,40 @@ export async function getReport(payload) {
|
|
|
95
107
|
const [_measurementDetailsDocPg2] = measurementDetailsDoc ? await coreDoc.copyPages(measurementDetailsDoc, [1]) : false;
|
|
96
108
|
if (_measurementDetailsDocPg2) coreDoc.insertPage(coreDoc.getPages().length, _measurementDetailsDocPg2);
|
|
97
109
|
}
|
|
98
|
-
} catch (
|
|
110
|
+
} catch (error) {
|
|
111
|
+
return { code: 400, error: error };
|
|
112
|
+
}
|
|
99
113
|
|
|
100
114
|
/******** TEST OUT ACCA MEASUREMENTS (1 PAGE) *********/
|
|
101
115
|
try {
|
|
102
|
-
if (payload.acca) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (_measurementDetailsAccaDocPg2) coreDoc.insertPage(coreDoc.getPages().length, _measurementDetailsAccaDocPg2);
|
|
108
|
-
}
|
|
116
|
+
if (payload.acca && payload.tests.length > 1) {
|
|
117
|
+
let measurementDetailsAccaBase64 = await measurementDetailsAcca.getReport(payload);
|
|
118
|
+
const measurementDetailsAccaDoc = measurementDetailsAccaBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(measurementDetailsAccaBase64)) : false;
|
|
119
|
+
const [_measurementDetailsAccaDocPg2] = measurementDetailsAccaDoc ? await coreDoc.copyPages(measurementDetailsAccaDoc, [1]) : false;
|
|
120
|
+
if (_measurementDetailsAccaDocPg2) coreDoc.insertPage(coreDoc.getPages().length, _measurementDetailsAccaDocPg2);
|
|
109
121
|
}
|
|
110
|
-
} catch (
|
|
122
|
+
} catch (error) {
|
|
123
|
+
return { code: 400, error: error };
|
|
124
|
+
}
|
|
111
125
|
|
|
112
|
-
/******** ACCA / ESVI
|
|
126
|
+
/******** ACCA / ESVI CERTIFICATES (1 PAGE) *********/
|
|
113
127
|
try {
|
|
114
|
-
if (payload.acca) {
|
|
115
|
-
if (payload.
|
|
116
|
-
let
|
|
117
|
-
const
|
|
118
|
-
const [
|
|
119
|
-
if (
|
|
128
|
+
if (payload.acca && payload.equipment.certificates) {
|
|
129
|
+
if (payload.equipment.certificates.esvi) {
|
|
130
|
+
let energyStarCertificateBase64 = await energyStarCertificate.getReport(payload);
|
|
131
|
+
const energyStarCertificateDoc = energyStarCertificateBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(energyStarCertificateBase64)) : false;
|
|
132
|
+
const [_energyStarCertificateDoc] = accaCertificateDoc ? await coreDoc.copyPages(energyStarCertificateDoc, [1]) : false;
|
|
133
|
+
if (_energyStarCertificateDoc) coreDoc.insertPage(coreDoc.getPages().length, _energyStarCertificateDoc);
|
|
134
|
+
} else if (payload.equipment.certificates.acca_qi || payload.equipment.certificates.acca_veo) {
|
|
135
|
+
let accaCertificateBase64 = await accaCertificate.getReport(payload);
|
|
136
|
+
const accaCertificateDoc = accaCertificateBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(accaCertificateBase64)) : false;
|
|
137
|
+
const [_accaCertificateDoc] = accaCertificateDoc ? await coreDoc.copyPages(accaCertificateDoc, [1]) : false;
|
|
138
|
+
if (_accaCertificateDoc) coreDoc.insertPage(coreDoc.getPages().length, _accaCertificateDoc);
|
|
120
139
|
}
|
|
121
140
|
}
|
|
122
|
-
} catch (
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return { code: 400, error: error };
|
|
143
|
+
}
|
|
123
144
|
|
|
124
145
|
/******** BLUVAC REPORT (1 PAGE) *********/
|
|
125
146
|
if (payload.project.evacuation_pdf && payload.meta.pdf_settings.includeBluvacReport) {
|
|
@@ -128,7 +149,9 @@ export async function getReport(payload) {
|
|
|
128
149
|
const bluvacReportDoc = bluvacReportBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(bluvacReportBase64)) : false;
|
|
129
150
|
const [_bluvacReportDoc] = bluvacReportDoc ? await coreDoc.copyPages(bluvacReportDoc, [0]) : false;
|
|
130
151
|
if (_bluvacReportDoc) coreDoc.insertPage(coreDoc.getPages().length, _bluvacReportDoc);
|
|
131
|
-
} catch (
|
|
152
|
+
} catch (error) {
|
|
153
|
+
return { code: 400, error: error };
|
|
154
|
+
}
|
|
132
155
|
}
|
|
133
156
|
|
|
134
157
|
/******** CORRECTIVE MEASURES (1-2 PAGES) *********/
|
|
@@ -141,7 +164,9 @@ export async function getReport(payload) {
|
|
|
141
164
|
if (_correctiveMeasuresDoc) coreDoc.insertPage(coreDoc.getPages().length, _correctiveMeasuresDoc);
|
|
142
165
|
if (_correctiveMeasuresDocPage2) coreDoc.insertPage(coreDoc.getPages().length, _correctiveMeasuresDocPage2);
|
|
143
166
|
} else if (_correctiveMeasuresDoc) coreDoc.insertPage(coreDoc.getPages().length, _correctiveMeasuresDoc);
|
|
144
|
-
} catch (
|
|
167
|
+
} catch (error) {
|
|
168
|
+
return { code: 400, error: error };
|
|
169
|
+
}
|
|
145
170
|
|
|
146
171
|
/******** PHOTOS (X PAGES) *********/
|
|
147
172
|
try {
|
|
@@ -152,7 +177,9 @@ export async function getReport(payload) {
|
|
|
152
177
|
const [_photosReport] = await coreDoc.copyPages(photosReportDoc, [i]);
|
|
153
178
|
coreDoc.insertPage(coreDoc.getPages().length, _photosReport);
|
|
154
179
|
}
|
|
155
|
-
} catch (
|
|
180
|
+
} catch (error) {
|
|
181
|
+
return { code: 400, error: error };
|
|
182
|
+
}
|
|
156
183
|
|
|
157
184
|
/******** SYSTEM INFO (1 PAGE) *********/
|
|
158
185
|
try {
|
|
@@ -160,8 +187,10 @@ export async function getReport(payload) {
|
|
|
160
187
|
const systemInfoPageDoc = systemInfoPageBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(systemInfoPageBase64)) : false;
|
|
161
188
|
const [_systemInfoPageDoc] = systemInfoPageDoc ? await coreDoc.copyPages(systemInfoPageDoc, [0]) : false;
|
|
162
189
|
if (_systemInfoPageDoc) coreDoc.insertPage(coreDoc.getPages().length, _systemInfoPageDoc);
|
|
163
|
-
} catch (
|
|
190
|
+
} catch (error) {
|
|
191
|
+
return { code: 400, error: error };
|
|
192
|
+
}
|
|
164
193
|
|
|
165
|
-
let
|
|
166
|
-
return
|
|
194
|
+
let pdf = await coreDoc.saveAsBase64({ dataUri: true });
|
|
195
|
+
return { code: 200, pdf: pdf };
|
|
167
196
|
}
|
|
@@ -154,8 +154,6 @@ export async function getReport(payload) { // DAVID TODO
|
|
|
154
154
|
form.getButton(`SSR${c + 1}`).setImage(icon);
|
|
155
155
|
c++;
|
|
156
156
|
}
|
|
157
|
-
// else if (val == true || val == 'true') form.getButton(`Block${blockNum}-Row${rowNum}-Col2-Icon`).setImage(embeddedIcons.iconRangeGreen);
|
|
158
|
-
// else if (val == false || val == 'false') form.getButton(`Block${blockNum}-Row${rowNum}-Col2-Icon`).setImage(embeddedIcons.iconRangeRed);
|
|
159
157
|
else form.getTextField(`Block${blockNum}-Row${rowNum}-Col2`).setText(`${val}`);
|
|
160
158
|
} else break;
|
|
161
159
|
}
|
|
@@ -169,8 +167,9 @@ export async function getReport(payload) { // DAVID TODO
|
|
|
169
167
|
pdfDocPg1.insertPage(1, secondPage);
|
|
170
168
|
}
|
|
171
169
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
170
|
+
let pdf = await pdfDocPg1.saveAsBase64({ dataUri: true });
|
|
171
|
+
return { code: 200, pdf: pdf };
|
|
172
|
+
} catch (error) {
|
|
173
|
+
return { code: 400, error: error };
|
|
174
|
+
}
|
|
176
175
|
}
|
|
@@ -153,9 +153,7 @@ export async function getReport(payload) {
|
|
|
153
153
|
if (!val) val = "--";
|
|
154
154
|
else if (measurement.fixTo && typeof val == 'number') val = val.toFixed(measurement.fixTo);
|
|
155
155
|
if ((measurement.label == 'Ambient CO' || measurement.label == 'Return CO' || measurement.label == 'Supply CO') && !measurement.value) val = '0.0';
|
|
156
|
-
//if (measurement.fixTo && typeof val == 'number') val = val.toFixed(measurement.fixTo);
|
|
157
156
|
if (typeof val == 'number' || !isNaN(val)) val = val.toLocaleString("en-US");
|
|
158
|
-
//else if (!isNaN(parseFloat(val))) val = parseFloat(val).toLocaleString("en-US");
|
|
159
157
|
if (measurement.fixTo && typeof val == 'number') val = val.toFixed(measurement.fixTo);
|
|
160
158
|
if (measurement.ref == 'co' || measurement.ref == 'o2' || measurement.ref == 'temperature_air' || measurement.ref == 'temperature_stack' || measurement.ref == 'coaf' || measurement.ref == 'excess_air' || measurement.ref == 'efficiency_gcv' || measurement.ref == 'efficiency_ncv' || measurement.ref == 'dew_point') val = measurement.value;
|
|
161
159
|
else if (measurement.ref == 'pressure_fuel' || measurement.ref == 'pressure_manifold' || measurement.ref == 'pressure_static_total_external' || measurement.ref == 'temperature_rise' || measurement.ref == 'temperature_rise_target' || measurement.ref == 'temperature_return' || measurement.ref == 'temperature_supply' || measurement.ref == 'airflow' || measurement.ref == 'gas_input_rated' || measurement.ref == 'gas_input_after' || measurement.ref == 'gas_output') val = measurement.value;
|
|
@@ -163,13 +161,13 @@ export async function getReport(payload) {
|
|
|
163
161
|
form.getTextField(`Block${blockNum}-Row${rowNum}-Col2${altLabel}`).setText(`${val}`);
|
|
164
162
|
if (blockNum != 4) {
|
|
165
163
|
let rangeIcon;
|
|
166
|
-
|
|
164
|
+
|
|
167
165
|
if (measurement.label == 'Ambient CO' || measurement.label == 'Return CO' || measurement.label == 'Supply CO') {
|
|
168
166
|
let v = measurement.value;
|
|
169
167
|
if (typeof v == 'string') v = parseFloat(v);
|
|
170
168
|
if (v > 9) rangeIcon = embeddedIcons.iconRangeHigh;
|
|
171
169
|
} else rangeIcon = util.getRangeIcon(test, measurement.ref, embeddedIcons);
|
|
172
|
-
|
|
170
|
+
|
|
173
171
|
if (rangeIcon && payload.meta.pdf_settings.includeRangeIndicators) form.getButton(`Block${blockNum}-Row${rowNum}-Col3`).setImage(rangeIcon);
|
|
174
172
|
let toolIcon = false;
|
|
175
173
|
if (measurement.ref == "superheat" || measurement.ref == "subcooling" || measurement.ref == "compression_ratio" || measurement.ref == "airflow_estimated") toolIcon = embeddedIcons.iconCalculator;
|
|
@@ -194,8 +192,9 @@ export async function getReport(payload) {
|
|
|
194
192
|
pdfDocPg1.insertPage(1, secondPage);
|
|
195
193
|
}
|
|
196
194
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
let pdf = await pdfDocPg1.saveAsBase64({ dataUri: true });
|
|
196
|
+
return { code: 200, pdf: pdf };
|
|
197
|
+
} catch (error) {
|
|
198
|
+
return { code: 400, error: error };
|
|
199
|
+
}
|
|
201
200
|
}
|
|
@@ -6,18 +6,18 @@ import * as base64 from '../base-64/icons.js';
|
|
|
6
6
|
import * as util from '../util.js';
|
|
7
7
|
|
|
8
8
|
export async function getReport(payload) {
|
|
9
|
-
|
|
10
|
-
const mqLogoBytes =
|
|
9
|
+
try {
|
|
10
|
+
const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
|
|
11
11
|
let maxPhotosPerPage = payload.meta.pdf_settings.maxPhotosPerPage ? payload.meta.pdf_settings.maxPhotosPerPage : 2;
|
|
12
12
|
|
|
13
13
|
// Layout Configuration
|
|
14
14
|
let docs = [], forms = [], page = photos6, pSize = "Small";
|
|
15
15
|
if (maxPhotosPerPage == 4) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
page = photos4;
|
|
17
|
+
pSize = "Mid";
|
|
18
18
|
} else if (maxPhotosPerPage == 2) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
page = photos2;
|
|
20
|
+
pSize = "Large";
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// Process All Photos
|
|
@@ -49,8 +49,8 @@ export async function getReport(payload) {
|
|
|
49
49
|
}
|
|
50
50
|
let imageToSet;
|
|
51
51
|
if (photo && photo.base64 && typeof photo.base64 == 'string') {
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
if (photo.base64 && photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
53
|
+
else if (photo.base64 && photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
54
54
|
}
|
|
55
55
|
if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
|
|
56
56
|
let caption = photo.section;
|
|
@@ -66,8 +66,13 @@ export async function getReport(payload) {
|
|
|
66
66
|
forms.forEach(form => { form.flatten() });
|
|
67
67
|
let pdfDoc = await PDFDocument.create();
|
|
68
68
|
for (let i = 0; i < docs.length; i++) {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const [nextPage] = await pdfDoc.copyPages(docs[i], [0]);
|
|
70
|
+
pdfDoc.insertPage(i, nextPage);
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
73
|
+
return { code: 200, pdf: pdf };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return { code: 400, error: error };
|
|
77
|
+
}
|
|
73
78
|
}
|
|
@@ -7,136 +7,139 @@ import * as util from '../util.js';
|
|
|
7
7
|
|
|
8
8
|
export async function getReport(payload) {
|
|
9
9
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
|
|
11
|
+
let maxPhotosPerPage = payload.meta.pdf_settings.maxPhotosPerPage;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
// Layout Configuration
|
|
14
|
+
let docs = [], forms = [], page = photos6, pSize = "Small";
|
|
15
|
+
if (maxPhotosPerPage == 4) {
|
|
16
|
+
page = photos4;
|
|
17
|
+
pSize = "Mid";
|
|
18
|
+
} else if (maxPhotosPerPage == 2) {
|
|
19
|
+
page = photos2;
|
|
20
|
+
pSize = "Large";
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
// Process All Photos
|
|
24
|
+
let canProcessReport = false;
|
|
25
|
+
let previousPhotoSectionName;
|
|
26
|
+
let docIndex = 0;
|
|
27
|
+
let initialProjectPhotoPageLoaded = false;
|
|
28
|
+
let photoSectionKeys = Object.keys(payload.photos.project);
|
|
29
|
+
if (photoSectionKeys && photoSectionKeys.length > 0) {
|
|
30
|
+
let photoPosition = 1;
|
|
31
|
+
for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) { // Iterate over X user-defined photo sections within each photo collection
|
|
32
|
+
let photoSectionKey = photoSectionKeys[pskIndex];
|
|
33
|
+
let photoSection = payload.photos.project[photoSectionKey];
|
|
34
|
+
let photoSectionName = photoSection.name;
|
|
35
|
+
let photos = photoSection.photos;
|
|
36
|
+
if (photos && photos.length > 0) {
|
|
37
|
+
for (let pIndex = 1; pIndex <= photos.length; pIndex++) { // Iterate over X user-defined photos within each photo section
|
|
38
|
+
let photo = photos[pIndex - 1];
|
|
39
|
+
//If image has proper photo data, continue processing, else do not try and make an empty page.
|
|
40
|
+
if (photo && photo.base64 && typeof photo.base64 == 'string') {
|
|
41
|
+
if (!initialProjectPhotoPageLoaded) {
|
|
42
|
+
initialProjectPhotoPageLoaded = true;
|
|
43
|
+
canProcessReport = true;
|
|
44
|
+
//Initial Page, this needs to only publish this page IF and only IF it has valid image data
|
|
45
|
+
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
46
|
+
forms[docIndex] = docs[docIndex].getForm();
|
|
47
|
+
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
48
|
+
forms[docIndex].getTextField("Header").setText(`Project Photos`);
|
|
49
|
+
}
|
|
50
|
+
if (photoPosition > maxPhotosPerPage) { // Need a new page
|
|
51
|
+
photoPosition = 1;
|
|
52
|
+
docIndex++;
|
|
53
|
+
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
54
|
+
forms[docIndex] = docs[docIndex].getForm();
|
|
55
|
+
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
56
|
+
forms[docIndex].getTextField("Header").setText(`Project Photos`);
|
|
57
|
+
}
|
|
58
|
+
let imageToSet;
|
|
40
59
|
if (photo && photo.base64 && typeof photo.base64 == 'string') {
|
|
41
|
-
if(
|
|
42
|
-
|
|
43
|
-
canProcessReport = true;
|
|
44
|
-
//Initial Page, this needs to only publish this page IF and only IF it has valid image data
|
|
45
|
-
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
46
|
-
forms[docIndex] = docs[docIndex].getForm();
|
|
47
|
-
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
48
|
-
forms[docIndex].getTextField("Header").setText(`Project Photos`);
|
|
49
|
-
}
|
|
50
|
-
if (photoPosition > maxPhotosPerPage) { // Need a new page
|
|
51
|
-
photoPosition = 1;
|
|
52
|
-
docIndex++;
|
|
53
|
-
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
54
|
-
forms[docIndex] = docs[docIndex].getForm();
|
|
55
|
-
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
56
|
-
forms[docIndex].getTextField("Header").setText(`Project Photos`);
|
|
57
|
-
}
|
|
58
|
-
let imageToSet;
|
|
59
|
-
if (photo && photo.base64 && typeof photo.base64 == 'string') {
|
|
60
|
-
if (photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
61
|
-
else if (photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
62
|
-
}
|
|
63
|
-
if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
|
|
64
|
-
let photoSubText = photoSection.name;
|
|
65
|
-
let isFirstPhotoOfSection = previousPhotoSectionName !== photoSectionName;
|
|
66
|
-
if (isFirstPhotoOfSection && photoSection.hasNotes && photoSection.notes) photoSubText += `: ${photoSection.notes}`;
|
|
67
|
-
forms[docIndex].getTextField(`Notes${photoPosition}`).setText(`${photoSubText}`);
|
|
68
|
-
photoPosition++;
|
|
69
|
-
previousPhotoSectionName = photoSectionName;
|
|
60
|
+
if (photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
61
|
+
else if (photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
70
62
|
}
|
|
63
|
+
if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
|
|
64
|
+
let photoSubText = photoSection.name;
|
|
65
|
+
let isFirstPhotoOfSection = previousPhotoSectionName !== photoSectionName;
|
|
66
|
+
if (isFirstPhotoOfSection && photoSection.hasNotes && photoSection.notes) photoSubText += `: ${photoSection.notes}`;
|
|
67
|
+
forms[docIndex].getTextField(`Notes${photoPosition}`).setText(`${photoSubText}`);
|
|
68
|
+
photoPosition++;
|
|
69
|
+
previousPhotoSectionName = photoSectionName;
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
73
|
}
|
|
74
|
+
}
|
|
75
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
|
-
|
|
76
|
+
let initialEquipmentPhotoPageLoaded = false;
|
|
77
|
+
photoSectionKeys = Object.keys(payload.photos.equipment);
|
|
78
|
+
let hasPhotos = payload.photos.equipment && payload.photos.equipment.photo_models_serials && payload.photos.equipment.photo_models_serials.photos && payload.photos.equipment.photo_models_serials.photos.length > 0;
|
|
79
|
+
if (photoSectionKeys && photoSectionKeys.length > 0 && hasPhotos) {
|
|
80
|
+
let photoPosition = 1;
|
|
81
|
+
for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) { // Iterate over X user-defined photo sections within each photo collection
|
|
82
|
+
let photoSectionKey = photoSectionKeys[pskIndex];
|
|
83
|
+
let photoSection = payload.photos.equipment[photoSectionKey];
|
|
84
|
+
let photoSectionName = photoSection.name;
|
|
85
|
+
let photos = photoSection.photos;
|
|
86
|
+
if (photos && photos.length > 0) {
|
|
87
|
+
for (let pIndex = 1; pIndex <= photos.length; pIndex++) { // Iterate over X user-defined photos within each photo section
|
|
88
|
+
let photo = photos[pIndex - 1];
|
|
89
|
+
if (photo && photo.base64 && typeof photo.base64 == 'string') {
|
|
90
|
+
//Initial page load, this should wait until we know there is VALID image data
|
|
91
|
+
if (!initialEquipmentPhotoPageLoaded) {
|
|
92
|
+
initialEquipmentPhotoPageLoaded = true;
|
|
93
|
+
canProcessReport = true;
|
|
94
|
+
if (initialProjectPhotoPageLoaded && docIndex === 0) docIndex++;
|
|
95
|
+
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
96
|
+
forms[docIndex] = docs[docIndex].getForm();
|
|
97
|
+
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
98
|
+
forms[docIndex].getTextField("Header").setText(`Equipment Photos`);
|
|
99
|
+
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
let imageToSet;
|
|
110
|
-
if (photo && photo.base64 && typeof photo.base64 == 'string') {
|
|
111
|
-
if (photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
112
|
-
else if (photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
113
|
-
}
|
|
114
|
-
if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
|
|
115
|
-
let photoSubText = photoSection.name;
|
|
116
|
-
let isFirstPhotoOfSection = previousPhotoSectionName !== photoSectionName;
|
|
117
|
-
if (isFirstPhotoOfSection && photoSection.hasNotes && photoSection.notes) photoSubText += `: ${photoSection.notes}`;
|
|
118
|
-
forms[docIndex].getTextField(`Notes${photoPosition}`).setText(`${photoSubText}`);
|
|
119
|
-
photoPosition++;
|
|
120
|
-
previousPhotoSectionName = photoSectionName;
|
|
101
|
+
if (photoPosition > maxPhotosPerPage) { // Need a new page
|
|
102
|
+
photoPosition = 1;
|
|
103
|
+
docIndex++;
|
|
104
|
+
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
105
|
+
forms[docIndex] = docs[docIndex].getForm();
|
|
106
|
+
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
107
|
+
forms[docIndex].getTextField("Header").setText(`Equipment Photos`);
|
|
121
108
|
}
|
|
109
|
+
let imageToSet;
|
|
110
|
+
if (photo && photo.base64 && typeof photo.base64 == 'string') {
|
|
111
|
+
if (photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
112
|
+
else if (photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
113
|
+
}
|
|
114
|
+
if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
|
|
115
|
+
let photoSubText = photoSection.name;
|
|
116
|
+
let isFirstPhotoOfSection = previousPhotoSectionName !== photoSectionName;
|
|
117
|
+
if (isFirstPhotoOfSection && photoSection.hasNotes && photoSection.notes) photoSubText += `: ${photoSection.notes}`;
|
|
118
|
+
forms[docIndex].getTextField(`Notes${photoPosition}`).setText(`${photoSubText}`);
|
|
119
|
+
photoPosition++;
|
|
120
|
+
previousPhotoSectionName = photoSectionName;
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
}
|
|
125
|
-
docIndex++;
|
|
126
124
|
}
|
|
125
|
+
docIndex++;
|
|
126
|
+
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
return await pdfDoc.saveAsBase64({ dataUri: true });
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
return false;
|
|
128
|
+
// Prepare Deliverable
|
|
129
|
+
if (canProcessReport) {
|
|
130
|
+
forms.forEach(form => { form.flatten() });
|
|
131
|
+
let pdfDoc = await PDFDocument.create();
|
|
132
|
+
for (let i = 0; i < docs.length; i++) {
|
|
133
|
+
const [nextPage] = await pdfDoc.copyPages(docs[i], [0]);
|
|
134
|
+
pdfDoc.insertPage(i, nextPage);
|
|
140
135
|
}
|
|
141
|
-
|
|
136
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
137
|
+
return { code: 200, pdf: pdf };
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return { code: 400, error: error };
|
|
144
|
+
}
|
|
142
145
|
}
|
|
@@ -3,24 +3,29 @@ import * as pdf from '../base-64/ptcs-heat-pump.js';
|
|
|
3
3
|
import * as util from '../util.js';
|
|
4
4
|
|
|
5
5
|
export async function getReport(payload) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
try {
|
|
7
|
+
const formPdfBytes = util._base64ToArrayBuffer(pdf.base64);
|
|
8
|
+
const pdfDoc = await PDFDocument.load(formPdfBytes);
|
|
9
|
+
const photoBytesStripHeat = util._base64ToArrayBuffer(payload.images.imageStripHeatBase64);
|
|
10
|
+
const photoBytesHpThermostat = util._base64ToArrayBuffer(payload.images.imageHpThermostatBase64);
|
|
11
|
+
var imageStripHeat;
|
|
12
|
+
var imageHpThermostat;
|
|
13
|
+
if (photoBytesStripHeat) imageStripHeat = await pdfDoc.embedJpg(photoBytesStripHeat);
|
|
14
|
+
if (photoBytesHpThermostat) imageHpThermostat = await pdfDoc.embedJpg(photoBytesHpThermostat);
|
|
15
|
+
const form = pdfDoc.getForm();
|
|
16
|
+
Object.keys(payload.textFields).forEach(fieldKey => {
|
|
17
|
+
if (payload.textFields[fieldKey]) form.getTextField(fieldKey).setText(`${payload.textFields[fieldKey]}`);
|
|
18
|
+
});
|
|
19
|
+
Object.keys(payload.checkFields).forEach(fieldKey => {
|
|
20
|
+
if (payload.checkFields[fieldKey]) form.getCheckBox(`${payload.checkFields[fieldKey]}`).check();
|
|
21
|
+
});
|
|
22
|
+
if (imageStripHeat) form.getButton("customImage1").setImage(imageStripHeat);
|
|
23
|
+
if (imageHpThermostat) form.getButton("customImage2").setImage(imageHpThermostat);
|
|
24
|
+
form.flatten();
|
|
25
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
26
|
+
return { code: 200, pdf: pdf };
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return { code: 400, error: error };
|
|
30
|
+
}
|
|
26
31
|
}
|
|
@@ -5,18 +5,23 @@ import * as termsConditionsArkansas from '../base-64/terms-arkansas-thermostat.j
|
|
|
5
5
|
import * as util from '../util.js';
|
|
6
6
|
|
|
7
7
|
export async function getReport(payload) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
try {
|
|
9
|
+
let termsConditionsBase64 = getPdfBase64(payload.meta.signature_type);
|
|
10
|
+
if (termsConditionsBase64) {
|
|
11
|
+
const formPdfBytes = util._base64ToArrayBuffer(termsConditionsBase64);
|
|
12
|
+
const pdfDoc = await PDFDocument.load(formPdfBytes);
|
|
13
|
+
const signatureBytes = util._base64ToArrayBuffer(payload.signatureBase64);
|
|
14
|
+
const signature = await pdfDoc.embedPng(signatureBytes);
|
|
15
|
+
const form = pdfDoc.getForm();
|
|
16
|
+
form.getButton("SignatureCustomer").setImage(signature);
|
|
17
|
+
form.flatten();
|
|
18
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
19
|
+
return { code: 200, pdf: pdf };
|
|
20
|
+
} else return false;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return { code: 400, error: error };
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
function getPdfBase64(reportType) {
|
|
@@ -6,15 +6,15 @@ import * as util from '../util.js';
|
|
|
6
6
|
|
|
7
7
|
export async function getReport(payload) {
|
|
8
8
|
try {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
const pdfDoc = payload.meta.report_mode == "heating" ? await PDFDocument.load(util._base64ToArrayBuffer(pdfHeating.base64)) : await PDFDocument.load(util._base64ToArrayBuffer(pdfCooling.base64));
|
|
10
|
+
const form = pdfDoc.getForm();
|
|
11
|
+
const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
|
|
12
|
+
const mqLogo = await pdfDoc.embedPng(mqLogoBytes);
|
|
13
|
+
form.getButton("FullWidthLogo").setImage(mqLogo);
|
|
14
|
+
form.flatten();
|
|
15
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
16
|
+
return { code: 200, pdf: pdf };
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return { code: 400, error: error };
|
|
19
|
+
}
|
|
20
20
|
}
|
|
@@ -1,212 +1,214 @@
|
|
|
1
1
|
import { PDFDocument } from 'pdf-lib';
|
|
2
|
-
import * as base64
|
|
2
|
+
import * as base64 from '../base-64/icons.js';
|
|
3
3
|
import * as pdf from '../base-64/mq-vitals-cooling.js';
|
|
4
|
-
import * as systemInfoPage
|
|
4
|
+
import * as systemInfoPage from './system-info-page.js';
|
|
5
5
|
import * as util from '../util.js';
|
|
6
6
|
|
|
7
7
|
export async function getReport(payload, _test) {
|
|
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
|
-
|
|
8
|
+
try {
|
|
9
|
+
// fetch and load form
|
|
10
|
+
const formPdfBytes = util._base64ToArrayBuffer(pdf.base64);
|
|
11
|
+
const pdfDoc = await PDFDocument.load(formPdfBytes);
|
|
12
|
+
|
|
13
|
+
// fetch resources
|
|
14
|
+
const iconRangeGreenBytes = util._base64ToArrayBuffer(base64.iconRangeGreen);
|
|
15
|
+
const iconRangeRedBytes = util._base64ToArrayBuffer(base64.iconRangeRed);
|
|
16
|
+
const iconFlagBlackBytes = util._base64ToArrayBuffer(base64.iconFlagBlack);
|
|
17
|
+
const iconFlagGreenBytes = util._base64ToArrayBuffer(base64.iconFlagGreen);
|
|
18
|
+
const iconFlagRedBytes = util._base64ToArrayBuffer(base64.iconFlagRed);
|
|
19
|
+
const iconFlagYellowBytes = util._base64ToArrayBuffer(base64.iconFlagYellow);
|
|
20
|
+
const iconStabilityBytes = util._base64ToArrayBuffer(base64.iconStability);
|
|
21
|
+
const iconThumbprintGreenBytes = util._base64ToArrayBuffer(base64.iconThumbprintGreen);
|
|
22
|
+
const iconThumbprintRedBytes = util._base64ToArrayBuffer(base64.iconThumbprintRed);
|
|
23
|
+
const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
|
|
24
|
+
|
|
25
|
+
// load resources
|
|
26
|
+
const iconRangeGreen = await pdfDoc.embedPng(iconRangeGreenBytes);
|
|
27
|
+
const iconRangeRed = await pdfDoc.embedPng(iconRangeRedBytes);
|
|
28
|
+
const iconFlagBlack = await pdfDoc.embedPng(iconFlagBlackBytes);
|
|
29
|
+
const iconFlagGreen = await pdfDoc.embedPng(iconFlagGreenBytes);
|
|
30
|
+
const iconFlagRed = await pdfDoc.embedPng(iconFlagRedBytes);
|
|
31
|
+
const iconFlagYellow = await pdfDoc.embedPng(iconFlagYellowBytes);
|
|
32
|
+
const iconStability = await pdfDoc.embedPng(iconStabilityBytes);
|
|
33
|
+
const iconThumbprintGreen = await pdfDoc.embedPng(iconThumbprintGreenBytes);
|
|
34
|
+
const iconThumbprintRed = await pdfDoc.embedPng(iconThumbprintRedBytes);
|
|
35
|
+
const mqLogo = await pdfDoc.embedPng(mqLogoBytes);
|
|
36
|
+
|
|
37
|
+
// embed company logo and profile picture
|
|
38
|
+
let profileImage, companyImage;
|
|
39
|
+
let profileImageType = util.checkProfilePicture(payload.meta);
|
|
40
|
+
let companyImageType = util.checkCompanyLogo(payload.meta);
|
|
41
|
+
if (profileImageType) {
|
|
42
|
+
if (profileImageType.shape == "square") profileImage = payload.meta.profile_settings.profilePicSquareBase64;
|
|
43
|
+
else if (profileImageType.shape == "circle") profileImage = payload.meta.profile_settings.profilePicCircleBase64;
|
|
44
|
+
if (profileImageType.type == "jpg") profileImage = await pdfDoc.embedJpg(util._base64ToArrayBuffer(profileImage));
|
|
45
|
+
else if (profileImageType.type == "png") profileImage = await pdfDoc.embedPng(util._base64ToArrayBuffer(profileImage));
|
|
46
|
+
}
|
|
47
|
+
if (companyImageType == "jpg") companyImage = await pdfDoc.embedJpg(util._base64ToArrayBuffer(payload.meta.profile_settings.companyLogoBase64));
|
|
48
|
+
else if (companyImageType == "png") companyImage = await pdfDoc.embedPng(util._base64ToArrayBuffer(payload.meta.profile_settings.companyLogoBase64));
|
|
49
|
+
|
|
50
|
+
// get form for filling
|
|
51
|
+
const form = pdfDoc.getForm();
|
|
52
|
+
|
|
53
|
+
// print system diagnostics section
|
|
54
|
+
let t = payload.tests[0].testInfo;
|
|
55
|
+
if (_test) t = _test.testInfo;
|
|
56
|
+
if (t && t.diagnostics && t.diagnostics.multi_point_analysis && t.diagnostics.multi_point_analysis.length > 0) {
|
|
57
|
+
for (let i = 0; i < 9; i++) {
|
|
58
|
+
let d = t.diagnostics.multi_point_analysis[i];
|
|
59
|
+
if (d) {
|
|
60
|
+
let diagnosticIcon = iconFlagBlack;
|
|
61
|
+
if (d.type === 'stability') diagnosticIcon = iconStability;
|
|
62
|
+
else if (d.score > 1 && d.score < 10) diagnosticIcon = iconFlagRed;
|
|
63
|
+
else if (d.score >= 10 && d.score < 15) diagnosticIcon = iconFlagYellow;
|
|
64
|
+
form.getButton(`ImageDiagnostics${i + 1}_af_image`).setImage(diagnosticIcon);
|
|
65
|
+
form.getTextField(`SystemDiagnostics${i + 1}`).setText(`${d.title}`);
|
|
66
|
+
form.getTextField(`SystemDiagnostics${i + 1}a`).setText(`${d.score}`);
|
|
67
|
+
}
|
|
67
68
|
}
|
|
69
|
+
} else {
|
|
70
|
+
form.getButton("ImageDiagnostics1_af_image").setImage(iconFlagGreen);
|
|
71
|
+
form.getTextField("SystemDiagnostics1").setText("No system-wide issues were detected.");
|
|
68
72
|
}
|
|
69
|
-
} else {
|
|
70
|
-
form.getButton("ImageDiagnostics1_af_image").setImage(iconFlagGreen);
|
|
71
|
-
form.getTextField("SystemDiagnostics1").setText("No system-wide issues were detected.");
|
|
72
|
-
}
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
74
|
+
let header = payload.meta.header ? payload.meta.header : "A/C System Vitals";
|
|
75
|
+
form.getTextField('Header').setText(header);
|
|
76
|
+
|
|
77
|
+
// get text fields
|
|
78
|
+
let textFields = getTextFields(payload, t);
|
|
79
|
+
|
|
80
|
+
// print company logo and profile picture
|
|
81
|
+
if (profileImage && companyImage) { // both images are embedded in the document
|
|
82
|
+
form.getButton("ProfilePicture").setImage(profileImage);
|
|
83
|
+
form.getButton("HalfWidthLogo").setImage(companyImage);
|
|
84
|
+
if (payload.meta.profile_settings.techFirstName || payload.meta.profile_settings.techLastName)
|
|
85
|
+
form.getTextField('TechName').setText(`${payload.meta.profile_settings.techFirstName} ${payload.meta.profile_settings.techLastName}`);
|
|
86
|
+
} else if (profileImage) { // no company logo is embedded in the document
|
|
87
|
+
form.getButton("ProfilePicture").setImage(profileImage);
|
|
88
|
+
form.getButton("HalfWidthLogo").setImage(mqLogo);
|
|
89
|
+
if (payload.meta.profile_settings.techFirstName || payload.meta.profile_settings.techLastName)
|
|
90
|
+
form.getTextField('TechName').setText(`${payload.meta.profile_settings.techFirstName} ${payload.meta.profile_settings.techLastName}`);
|
|
91
|
+
} else { // no profile picture is embedded in the document
|
|
92
|
+
if (companyImage) form.getButton("FullWidthLogo").setImage(companyImage);
|
|
93
|
+
else form.getButton("FullWidthLogo").setImage(mqLogo);
|
|
94
|
+
}
|
|
95
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
|
-
|
|
96
|
+
// print customer data
|
|
97
|
+
let dateTimePlacement = "Upper";
|
|
98
|
+
let e = "";
|
|
99
|
+
let d = "";
|
|
100
|
+
|
|
101
|
+
let date = new Date();
|
|
102
|
+
if (textFields.cName && textFields.address && textFields.city && textFields.state && textFields.zip) {
|
|
103
|
+
dateTimePlacement = "Lower";
|
|
104
|
+
form.getTextField('Name').setText(`${textFields.cName}`);
|
|
105
|
+
form.getTextField('Address1').setText(`${textFields.address}`);
|
|
106
|
+
if (textFields.address2) {
|
|
107
|
+
form.getTextField('Address2').setText(`${textFields.address2}`);
|
|
108
|
+
form.getTextField('CityStateZip').setText(`${textFields.city}${textFields.state}${textFields.zip}`);
|
|
109
|
+
} else form.getTextField('Address2').setText(`${textFields.city}${textFields.state}${textFields.zip}`);
|
|
110
|
+
form.getTextField('DateOfServiceLabelUpper').setText("");
|
|
111
|
+
form.getTextField('TimeOfServiceLabelUpper').setText("");
|
|
112
|
+
form.getTextField('DateOfServiceLabelLower').setText("Date of Service:");
|
|
113
|
+
form.getTextField('TimeOfServiceLabelLower').setText("Time of Service:");
|
|
114
|
+
form.getTextField('DateOfServiceLower').setText(date.toLocaleDateString("en-US"));
|
|
115
|
+
form.getTextField('TimeOfServiceLower').setText(date.toLocaleTimeString("en-US"));
|
|
116
|
+
} else {
|
|
117
|
+
form.getTextField('DateOfServiceLabelLower').setText("");
|
|
118
|
+
form.getTextField('TimeOfServiceLabelLower').setText("");
|
|
119
|
+
form.getTextField('DateOfServiceLabelUpper').setText("Date of Service:");
|
|
120
|
+
form.getTextField('TimeOfServiceLabelUpper').setText("Time of Service:");
|
|
121
|
+
form.getTextField('DateOfServiceUpper').setText(date.toLocaleDateString("en-US"));
|
|
122
|
+
form.getTextField('TimeOfServiceUpper').setText(date.toLocaleTimeString("en-US"));
|
|
123
|
+
}
|
|
124
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
125
|
+
let systemScorePercentage = t.data.vitals_score ? +t.data.vitals_score.toFixed(0) : 0;
|
|
126
|
+
let systemScoreGrade = util.getGradeFromScore(systemScorePercentage);
|
|
127
|
+
let systemScoreColor = util.getColorFromGrade(systemScoreGrade);
|
|
128
|
+
if (!t.data.vitals_score) {
|
|
129
|
+
systemScorePercentage = "--";
|
|
130
|
+
systemScoreGrade = "";
|
|
131
|
+
} else systemScorePercentage += "%";
|
|
132
|
+
|
|
133
|
+
// print measurement data (first page)
|
|
134
|
+
form.getTextField(`YourSystemScore${systemScoreColor}`).setText(`${systemScorePercentage} ${systemScoreGrade}`);
|
|
135
|
+
form.getTextField('Superheat').setText(`${textFields.superheat} °${payload.units.temperature}`);
|
|
136
|
+
form.getTextField('Subcooling').setText(`${textFields.subcooling} °${payload.units.temperature}`);
|
|
137
|
+
form.getTextField('CondenserApproach').setText(`${textFields.approach} °${payload.units.temperature}`);
|
|
138
|
+
form.getTextField('TemperatureSplit').setText(`${textFields.tempSplit} °${payload.units.temperature}`);
|
|
139
|
+
form.getTextField('TotalExternalStaticPressure').setText(`${textFields.tesp} inH2O`);
|
|
140
|
+
form.getTextField('FilterFaceVelocity').setText(`${textFields.fltrFace} FPM`);
|
|
141
|
+
|
|
142
|
+
// print losses data (second page)
|
|
143
|
+
let prefix;
|
|
144
|
+
let lossColor = textFields.ageLosses < 3 ? "Green" : "Red";
|
|
145
|
+
prefix = textFields.ageLosses == 0 ? "" : "-";
|
|
146
|
+
form.getTextField(`AgeLosses${lossColor}`).setText(`${prefix}${textFields.ageLosses}`);
|
|
147
|
+
lossColor = textFields.tempSplitLosses < 3 ? "Green" : "Red";
|
|
148
|
+
prefix = textFields.tempSplitLosses == 0 ? "" : "-";
|
|
149
|
+
form.getTextField(`TemperatureSplitLosses${lossColor}`).setText(`${prefix}${textFields.tempSplitLosses}`);
|
|
150
|
+
lossColor = textFields.staticLosses < 3 ? "Green" : "Red";
|
|
151
|
+
prefix = textFields.staticLosses == 0 ? "" : "-";
|
|
152
|
+
form.getTextField(`StaticPressureLosses${lossColor}`).setText(`${prefix}${textFields.staticLosses}`);
|
|
153
|
+
lossColor = textFields.approachLosses < 3 ? "Green" : "Red";
|
|
154
|
+
prefix = textFields.approachLosses == 0 ? "" : "-";
|
|
155
|
+
form.getTextField(`ApproachLosses${lossColor}`).setText(`${prefix}${textFields.approachLosses}`);
|
|
156
|
+
lossColor = textFields.refChargeLosses < 3 ? "Green" : "Red";
|
|
157
|
+
prefix = textFields.refChargeLosses == 0 ? "" : "-";
|
|
158
|
+
form.getTextField(`RefrigerantChargeIssues${lossColor}`).setText(`${prefix}${textFields.refChargeLosses}`);
|
|
159
|
+
form.getTextField('YourSystemScorePage2').setText(`${systemScorePercentage} ${systemScoreGrade}`);
|
|
160
|
+
|
|
161
|
+
// print targets and range icons
|
|
162
|
+
const measureLabels = ["Superheat", "Subcooling", "Condenser", "TempSplit", "Tesp", "FilterFace"];
|
|
163
|
+
const targetKeys = ["superheat", "subcooling", "approach", "temperature_split", "pressure_static_total_external", "velocity_face_filter1"];
|
|
164
|
+
for (let i = 0; i < measureLabels.length; i++) {
|
|
165
|
+
let iconPlacement = "Mid";
|
|
166
|
+
let icon = iconRangeRed;
|
|
167
|
+
let actual = +t.data[targetKeys[i]];
|
|
168
|
+
let mid = +t.targets[targetKeys[i]];
|
|
169
|
+
let low = +t.targets[`${targetKeys[i]}_ideal_low`];
|
|
170
|
+
let high = +t.targets[`${targetKeys[i]}_ideal_high`];
|
|
171
|
+
low = mid - low;
|
|
172
|
+
high = mid + high;
|
|
173
|
+
if (targetKeys[i] == "pressure_static_total_external") high = mid * 1.4;
|
|
174
|
+
else if (targetKeys[i] == "velocity_face_filter1") high = 500;
|
|
175
|
+
let val = t.data[targetKeys[i]];
|
|
176
|
+
if (actual < low && targetKeys[i] != "velocity_face_filter1") iconPlacement = "Low";
|
|
177
|
+
else if (actual > high) iconPlacement = "High";
|
|
178
|
+
else if (val) icon = iconRangeGreen;
|
|
179
|
+
if (icon) form.getButton(`Image${measureLabels[i]}${iconPlacement}_af_image`).setImage(icon);
|
|
180
|
+
let targetZone = "";
|
|
181
|
+
if (targetKeys[i] == "pressure_static_total_external" || targetKeys[i] == "velocity_face_filter1") targetZone = `(< ${high.toFixed(1)})`;
|
|
182
|
+
else if (!isNaN(low) && low != "NaN" && !isNaN(high) && high != "NaN") targetZone = `(${low.toFixed(1)} - ${high.toFixed(1)})`;
|
|
183
|
+
form.getTextField(`${measureLabels[i]}Target`).setText(targetZone);
|
|
184
|
+
}
|
|
185
185
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (payload.meta.report_type != "FullReport") {
|
|
199
|
-
let systemInfoPageBase64 = await systemInfoPage.getReport(payload);
|
|
200
|
-
const systemInfoPageDoc = systemInfoPageBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(systemInfoPageBase64)) : false;
|
|
201
|
-
const [_systemInfoPageDoc] = systemInfoPageDoc ? await pdfDoc.copyPages(systemInfoPageDoc, [0]) : false;
|
|
202
|
-
if (_systemInfoPageDoc) pdfDoc.insertPage(pdfDoc.getPages().length, _systemInfoPageDoc);
|
|
203
|
-
}
|
|
186
|
+
// print pass fail measures
|
|
187
|
+
if (t.subsystem_review_complete) {
|
|
188
|
+
let passFails = ["electrical_system_pass_fail", "air_distribution_system_pass_fail", "air_filtration_system_pass_fail", "condensate_drain_system_pass_fail", "refrigerant_charge_pass_fail", "outdoor_equipment_pass_fail", "indoor_equipment_pass_fail", "cooling_capacity_pass_fail", "cooling_electrical_efficiency_pass_fail"];
|
|
189
|
+
let pfLabels = ["Electrical system", "Air distribution system", "Air filtration system", "Condensate drain system", "Refrigerant charge", "Outdoor equipment", "Indoor equipment", "Cooling capacity", "Cooling electrical efficiency"];
|
|
190
|
+
for (let i = 1; i <= passFails.length; i++) {
|
|
191
|
+
let meas = t[passFails[i - 1]];
|
|
192
|
+
let icon = meas == "Pass" || meas == "High" || meas == "Mid" ? iconRangeGreen : iconRangeRed;
|
|
193
|
+
form.getButton(`ImageSubsystem${i}_af_image`).setImage(icon);
|
|
194
|
+
form.getTextField(`SSR${i}`).setText(pfLabels[i - 1]);
|
|
195
|
+
}
|
|
196
|
+
} else form.getTextField(`SSR1`).setText("Not yet reviewed");
|
|
204
197
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
198
|
+
if (payload.meta.report_type != "FullReport") {
|
|
199
|
+
let systemInfoPageBase64 = await systemInfoPage.getReport(payload);
|
|
200
|
+
const systemInfoPageDoc = systemInfoPageBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(systemInfoPageBase64)) : false;
|
|
201
|
+
const [_systemInfoPageDoc] = systemInfoPageDoc ? await pdfDoc.copyPages(systemInfoPageDoc, [0]) : false;
|
|
202
|
+
if (_systemInfoPageDoc) pdfDoc.insertPage(pdfDoc.getPages().length, _systemInfoPageDoc);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// flatten and return as base64
|
|
206
|
+
form.flatten();
|
|
207
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
208
|
+
return { code: 200, pdf: pdf };
|
|
209
|
+
} catch (error) {
|
|
210
|
+
return { code: 400, error: error };
|
|
211
|
+
}
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
function getTextFields(payload, test) {
|
|
@@ -231,9 +231,11 @@ export async function getReport(payload, _test) {
|
|
|
231
231
|
|
|
232
232
|
// flatten and return as base64
|
|
233
233
|
form.flatten();
|
|
234
|
-
|
|
235
|
-
return
|
|
236
|
-
} catch (error) {
|
|
234
|
+
let pdf = await pdfDoc.saveAsBase64({ dataUri: true });
|
|
235
|
+
return { code: 200, pdf: pdf };
|
|
236
|
+
} catch (error) {
|
|
237
|
+
return { code: 400, error: error };
|
|
238
|
+
}
|
|
237
239
|
}
|
|
238
240
|
|
|
239
241
|
function getTextFields(payload, test) {
|