fleetmap-reports 1.0.435 → 1.0.436
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/src/word/index.js +85 -82
package/package.json
CHANGED
package/src/word/index.js
CHANGED
|
@@ -1,92 +1,95 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const {
|
|
2
|
+
Document, Paragraph, Packer, TableRow, TableCell, Table, WidthType, ImageRun, Header, TextRun, HeadingLevel,
|
|
3
|
+
AlignmentType, Footer
|
|
4
|
+
} = require('docx')
|
|
4
5
|
const { saveAs } = require('file-saver')
|
|
5
6
|
const utils = require('../util/utils')
|
|
6
|
-
const {
|
|
7
|
+
const { getUserPartner } = require('fleetmap-partners')
|
|
7
8
|
const colWidth = 2000
|
|
8
9
|
|
|
9
|
-
function formatCellValue(value) {
|
|
10
|
-
|
|
10
|
+
function formatCellValue (value) {
|
|
11
|
+
return value.toLocaleDateString ? value.toLocaleDateString() : value + ''
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
exports.reportToWord = async (userData, dateRange, excel, title) => {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
console.log('excel', excel)
|
|
16
|
+
const partnerData = getUserPartner(userData.user)
|
|
16
17
|
|
|
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
|
-
]
|
|
18
|
+
if (!excel.data.length && utils.isClientSide()) {
|
|
19
|
+
alert('Não há dados')
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
const logo = await utils.getLogo(userData.user)
|
|
23
|
+
console.log('logo', logo)
|
|
24
|
+
const table = new Table({
|
|
25
|
+
columnWidths: excel.headers.map(() => colWidth),
|
|
26
|
+
rows: [
|
|
27
|
+
new TableRow({
|
|
28
|
+
children: excel.headers.map(r => new TableCell({
|
|
29
|
+
children: [new Paragraph(r.label)],
|
|
30
|
+
width: {
|
|
31
|
+
size: colWidth,
|
|
32
|
+
type: WidthType.DXA
|
|
33
|
+
}
|
|
34
|
+
}))
|
|
35
|
+
}),
|
|
36
|
+
...excel.data.filter(r => Object.keys(r).length).map(r => new TableRow({
|
|
37
|
+
children: Object.keys(r).map(k =>
|
|
38
|
+
new TableCell({
|
|
39
|
+
children: [new Paragraph(formatCellValue(r[k]))],
|
|
40
|
+
width: {
|
|
41
|
+
size: colWidth,
|
|
42
|
+
type: WidthType.DXA
|
|
43
|
+
}
|
|
44
|
+
}))
|
|
45
|
+
}))
|
|
46
|
+
]
|
|
47
|
+
})
|
|
48
|
+
const doc = new Document({
|
|
49
|
+
sections: [{
|
|
50
|
+
headers: {
|
|
51
|
+
default: new Header({
|
|
52
|
+
children: [
|
|
53
|
+
new Paragraph({
|
|
54
|
+
children: [
|
|
55
|
+
new ImageRun({
|
|
56
|
+
data: logo,
|
|
57
|
+
transformation: {
|
|
58
|
+
width: (partnerData.reports && partnerData.reports.logoWidth * 2) || 200,
|
|
59
|
+
height: (partnerData.reports && partnerData.reports.logoHeight * 2) || 50
|
|
60
|
+
}
|
|
62
61
|
})
|
|
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
|
-
}
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
})
|
|
66
|
+
},
|
|
67
|
+
footers: {
|
|
68
|
+
default: new Footer({
|
|
69
|
+
children: [
|
|
70
|
+
new Paragraph({
|
|
71
|
+
children: [
|
|
72
|
+
new TextRun('Relatório gerado a ' + new Date().toLocaleString())
|
|
73
|
+
]
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
})
|
|
77
|
+
},
|
|
78
|
+
properties: {},
|
|
79
|
+
children: [
|
|
80
|
+
new Paragraph({
|
|
81
|
+
children: [new TextRun(title)],
|
|
82
|
+
heading: HeadingLevel.HEADING_1,
|
|
83
|
+
alignment: AlignmentType.CENTER
|
|
84
|
+
}),
|
|
85
|
+
new Paragraph({}),
|
|
86
|
+
new Paragraph(new Date(dateRange[0]).toLocaleString() + ' - ' + new Date(dateRange[1]).toLocaleString()),
|
|
87
|
+
new Paragraph({}),
|
|
88
|
+
table
|
|
89
|
+
]
|
|
90
|
+
}]
|
|
91
|
+
})
|
|
92
|
+
Packer.toBlob(doc).then(blob => {
|
|
93
|
+
saveAs(blob, 'report.docx')
|
|
94
|
+
})
|
|
92
95
|
}
|