fleetmap-reports 2.0.165 → 2.0.167
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 +2 -2
- package/src/index.js +3 -0
- package/src/sensor-report.js +77 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.167",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"country-reverse-geocoding": "^0.2.2",
|
|
19
19
|
"docx": "^7.3.0",
|
|
20
20
|
"file-saver": "^2.0.5",
|
|
21
|
-
"fleetmap-partners": "1.0.
|
|
21
|
+
"fleetmap-partners": "1.0.185",
|
|
22
22
|
"json-as-xlsx": "2.5.6",
|
|
23
23
|
"jspdf": "^2.5.1",
|
|
24
24
|
"jspdf-autotable": "3.8.1",
|
package/src/index.js
CHANGED
|
@@ -237,5 +237,8 @@ function Reports (config, axios) {
|
|
|
237
237
|
this.sensorReport = (from, to, userData) => {
|
|
238
238
|
return require('./sensor-report').create(from, to, userData, this.traccar)
|
|
239
239
|
}
|
|
240
|
+
this.sensorReportToPDF = (userData, reportData) => {
|
|
241
|
+
return require('./sensor-report').exportToPDF(userData, reportData)
|
|
242
|
+
}
|
|
240
243
|
}
|
|
241
244
|
module.exports = Reports
|
package/src/sensor-report.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
const automaticReports = require('./automaticReports')
|
|
2
2
|
const traccarHelper = require('./util/traccar')
|
|
3
|
-
const { devicesToProcess } = require('./util/device')
|
|
3
|
+
const { devicesToProcess, deviceName } = require('./util/device')
|
|
4
|
+
const { getTranslations, isClientSide, convertToLocaleString, convertMS } = require('./util/utils')
|
|
5
|
+
const jsPDF = require('jspdf')
|
|
6
|
+
const { headerFromUser, addTable } = require('./util/pdfDocument')
|
|
7
|
+
const { getStyle } = require('./reportStyle')
|
|
8
|
+
const { getUserPartner } = require('fleetmap-partners')
|
|
4
9
|
|
|
5
10
|
function processDevices (from, to, devices, data, userData) {
|
|
6
11
|
const result = []
|
|
@@ -69,4 +74,75 @@ async function create (from, to, userData, traccar) {
|
|
|
69
74
|
return result
|
|
70
75
|
}
|
|
71
76
|
|
|
77
|
+
async function exportToPDF (userData, reportData) {
|
|
78
|
+
console.log('exportSensorReportToPDF')
|
|
79
|
+
|
|
80
|
+
const timezone = userData.user.attributes.timezone
|
|
81
|
+
const translations = getTranslations(userData)
|
|
82
|
+
const lang = userData.user.attributes.lang || (isClientSide() && navigator.language)
|
|
83
|
+
const reportDataRows = reportData.devices
|
|
84
|
+
|
|
85
|
+
const headers = [
|
|
86
|
+
'Sensor',
|
|
87
|
+
translations.report.start,
|
|
88
|
+
translations.report.end,
|
|
89
|
+
'Estado',
|
|
90
|
+
translations.report.duration,
|
|
91
|
+
translations.report.endAddress
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
if (reportDataRows) {
|
|
95
|
+
// eslint-disable-next-line new-cap
|
|
96
|
+
const doc = new jsPDF.jsPDF('l')
|
|
97
|
+
await headerFromUser(doc, 'Relatório de Sensores', userData.user)
|
|
98
|
+
|
|
99
|
+
let index = 0
|
|
100
|
+
reportDataRows.forEach(function (d) {
|
|
101
|
+
if (d.rows.length) {
|
|
102
|
+
const data = []
|
|
103
|
+
const name = deviceName(d.device)
|
|
104
|
+
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
105
|
+
|
|
106
|
+
const space = index === 0 ? 8 : 0
|
|
107
|
+
if (index) {
|
|
108
|
+
doc.addPage()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
doc.setFontSize(13)
|
|
112
|
+
doc.text(name, 20, space + 20)
|
|
113
|
+
doc.setFontSize(11)
|
|
114
|
+
doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space + 20)
|
|
115
|
+
doc.text(convertToLocaleString(d.from, lang, timezone, userData.user) + ' - ' + convertToLocaleString(d.to, lang, timezone, userData.user), 20, space + 25)
|
|
116
|
+
|
|
117
|
+
d.rows.forEach(row => {
|
|
118
|
+
const temp = [
|
|
119
|
+
row.name,
|
|
120
|
+
convertToLocaleString(row.startTime, lang, timezone, userData.user),
|
|
121
|
+
convertToLocaleString(row.endTime, lang, timezone, userData.user),
|
|
122
|
+
row.valueDescription,
|
|
123
|
+
convertMS(row.duration),
|
|
124
|
+
row.endAddress
|
|
125
|
+
]
|
|
126
|
+
data.push(temp)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const footValues = []
|
|
130
|
+
|
|
131
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
132
|
+
|
|
133
|
+
addTable(doc, headers, data, footValues, style, 40, {
|
|
134
|
+
4: { halign: 'right' }
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
index++
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
return doc
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function exportToExcel (userData, reportData) {}
|
|
145
|
+
|
|
146
|
+
exports.exportToPDF = exportToPDF
|
|
147
|
+
exports.exportToExcel = exportToExcel
|
|
72
148
|
exports.create = create
|