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