fleetmap-reports 1.0.435 → 1.0.438
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/lang/index.js +9 -9
- package/package.json +1 -1
- package/src/idle-report.js +11 -3
- package/src/location-report.js +275 -271
- package/src/word/index.js +85 -82
package/lang/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const enGBLocale = require('./enGB')
|
|
2
|
-
const ptBRLocale = require('./ptBR')
|
|
3
|
-
const esCLLocale = require('./esCL')
|
|
4
|
-
const ptPTLocale = require('./ptPT')
|
|
1
|
+
const enGBLocale = require('./enGB')
|
|
2
|
+
const ptBRLocale = require('./ptBR')
|
|
3
|
+
const esCLLocale = require('./esCL')
|
|
4
|
+
const ptPTLocale = require('./ptPT')
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
|
-
|
|
7
|
+
'en-GB': {
|
|
8
8
|
...enGBLocale
|
|
9
9
|
},
|
|
10
|
-
|
|
10
|
+
'pt-BR': {
|
|
11
11
|
...ptBRLocale
|
|
12
12
|
},
|
|
13
|
-
|
|
13
|
+
'pt-PT': {
|
|
14
14
|
...ptPTLocale
|
|
15
15
|
},
|
|
16
|
-
|
|
16
|
+
'es-CL': {
|
|
17
17
|
...esCLLocale
|
|
18
18
|
},
|
|
19
|
-
|
|
19
|
+
pt: {
|
|
20
20
|
...ptPTLocale
|
|
21
21
|
}
|
|
22
22
|
}
|
package/package.json
CHANGED
package/src/idle-report.js
CHANGED
|
@@ -11,6 +11,14 @@ const { reportByDriver } = require('./util/driver')
|
|
|
11
11
|
|
|
12
12
|
const fileName = 'IdleReport'
|
|
13
13
|
|
|
14
|
+
function getDriver (idleEvent, drivers) {
|
|
15
|
+
if (idleEvent && idleEvent.position && idleEvent.position.attributes.driverUniqueId) {
|
|
16
|
+
const driver = drivers.find(d => d.uniqueId === idleEvent.position.attributes.driverUniqueId)
|
|
17
|
+
return driver ? driver.name : idleEvent.position.attributes.driverUniqueId
|
|
18
|
+
}
|
|
19
|
+
return ''
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
async function createIdleReport (from, to, userData, traccarInstance) {
|
|
15
23
|
console.log('Create IdleReport')
|
|
16
24
|
const reportData = []
|
|
@@ -296,11 +304,11 @@ function exportIdleReportToExcel (userData, reportData) {
|
|
|
296
304
|
fileName // The name of the spreadsheet
|
|
297
305
|
}
|
|
298
306
|
const headers = [
|
|
299
|
-
userData.byDriver ?
|
|
307
|
+
{ label: userData.byDriver ? translations.report.driver : translations.report.vehicle, value: 'name' },
|
|
300
308
|
{ label: translations.report.date, value: 'fixTime' },
|
|
301
309
|
{ label: translations.report.address, value: 'address' },
|
|
302
310
|
{ label: translations.report.duration, value: 'duration' },
|
|
303
|
-
userData.byDriver ?
|
|
311
|
+
{ label: userData.byDriver ? translations.report.vehicle : translations.report.driver, value: 'subname' }
|
|
304
312
|
]
|
|
305
313
|
|
|
306
314
|
let data = []
|
|
@@ -312,7 +320,7 @@ function exportIdleReportToExcel (userData, reportData) {
|
|
|
312
320
|
name: userData.byDriver ? d.driver.name : d.device.name,
|
|
313
321
|
duration: convertMS(a.idleTime, true),
|
|
314
322
|
fixTime: getIdleEventDate(a, userData.user),
|
|
315
|
-
subname: userData.byDriver ? a.
|
|
323
|
+
subname: userData.byDriver ? a.deviceName : getDriver(a, userData.drivers),
|
|
316
324
|
address: a.position.address + (a.geofenceName ? ' - ' + a.geofenceName : '')
|
|
317
325
|
}
|
|
318
326
|
}))
|
package/src/location-report.js
CHANGED
|
@@ -1,350 +1,354 @@
|
|
|
1
1
|
const jsPDF = require('jspdf')
|
|
2
2
|
require('jspdf-autotable')
|
|
3
|
-
const {headerFromUser} = require(
|
|
4
|
-
const {getStyle} = require(
|
|
5
|
-
const {getUserPartner} = require(
|
|
6
|
-
const {convertToLocaleString, getTranslations} = require(
|
|
7
|
-
const traccarHelper = require(
|
|
8
|
-
const {devicesToProcess} = require(
|
|
3
|
+
const { headerFromUser } = require('./util/pdfDocument')
|
|
4
|
+
const { getStyle } = require('./reportStyle')
|
|
5
|
+
const { getUserPartner } = require('fleetmap-partners')
|
|
6
|
+
const { convertToLocaleString, getTranslations } = require('./util/utils')
|
|
7
|
+
const traccarHelper = require('./util/traccar')
|
|
8
|
+
const { devicesToProcess } = require('./util/device')
|
|
9
9
|
|
|
10
10
|
const fileName = 'LocationReport'
|
|
11
11
|
|
|
12
|
-
async function createLocationReport(from, to, userData, traccar) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return reportData
|
|
12
|
+
async function createLocationReport (from, to, userData, traccar) {
|
|
13
|
+
console.log('Create LocationReport')
|
|
14
|
+
const reportData = []
|
|
15
|
+
|
|
16
|
+
if (userData.byDriver) {
|
|
17
|
+
console.log('ByDriver')
|
|
18
|
+
const report = await createLocationReportByDriver(from, to, userData, traccar)
|
|
19
|
+
reportData.push(report)
|
|
20
|
+
} else if (userData.byGroup) {
|
|
21
|
+
console.log('ByGroup')
|
|
22
|
+
const allData = await createLocationReportByGroup(from, to, userData, traccar)
|
|
23
|
+
reportData.push(...allData)
|
|
24
|
+
} else {
|
|
25
|
+
console.log('ByDevice')
|
|
26
|
+
const report = await createLocationReportByDevice(from, to, userData, traccar)
|
|
27
|
+
reportData.push(report)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return reportData
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
async function createLocationReportByDriver(from, to, userData, traccar) {
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
async function createLocationReportByDriver (from, to, userData, traccar) {
|
|
34
|
+
const devices = await traccar.devices.devicesGet().then(d => d.data)
|
|
35
|
+
console.log(devices.length)
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
if (!devices.length) {
|
|
38
|
+
// Empty report
|
|
39
|
+
return { drivers: [] }
|
|
40
|
+
}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, false, false, false)
|
|
43
|
+
const routeData = allInOne.route
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
return { drivers: processDrivers(from, to, userData, routeData) }
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
async function createLocationReportByGroup(from, to, userData, traccar) {
|
|
50
|
-
|
|
48
|
+
async function createLocationReportByGroup (from, to, userData, traccar) {
|
|
49
|
+
const reportData = []
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
for (const g of userData.groups) {
|
|
52
|
+
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
if (devices.length > 0) {
|
|
55
|
+
const groupData = {
|
|
56
|
+
devices: [],
|
|
57
|
+
group: g,
|
|
58
|
+
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
59
|
+
}
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const response = await traccar.reports.reportsRouteGet(from, to, null, [g.id])
|
|
62
|
+
const data = response.data
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
if (data.length > 0) {
|
|
67
|
+
console.log('Locations:' + data.length)
|
|
68
|
+
groupData.devices = processDevices(from, to, devices, userData.drivers, data)
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
70
|
+
reportData.push(groupData)
|
|
71
|
+
}
|
|
74
72
|
}
|
|
73
|
+
}
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
const allData = await createLocationReportByDevice(from, to, userData, traccar)
|
|
76
|
+
reportData.push(allData)
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
return reportData
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
async function createLocationReportByDevice(from, to, userData, traccar) {
|
|
83
|
-
|
|
81
|
+
async function createLocationReportByDevice (from, to, userData, traccar) {
|
|
82
|
+
const devices = devicesToProcess(userData)
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
const allData = {
|
|
85
|
+
devices: [],
|
|
86
|
+
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
87
|
+
}
|
|
89
88
|
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, false, false, false)
|
|
90
|
+
const routeData = allInOne.route
|
|
92
91
|
|
|
93
|
-
|
|
92
|
+
console.log('Locations:' + routeData.length)
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
if (routeData.length > 0) {
|
|
95
|
+
allData.devices = processDevices(from, to, devices, userData.drivers, routeData)
|
|
96
|
+
}
|
|
98
97
|
|
|
99
|
-
|
|
98
|
+
return allData
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
function processDevices(from, to, devices, drivers, data) {
|
|
103
|
-
|
|
101
|
+
function processDevices (from, to, devices, drivers, data) {
|
|
102
|
+
const devicesResult = []
|
|
104
103
|
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
for (const d of devices) {
|
|
105
|
+
const positions = data.filter(t => t.deviceId === d.id)
|
|
107
106
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
})
|
|
107
|
+
if (drivers.length > 0) {
|
|
108
|
+
positions.forEach(p => {
|
|
109
|
+
const driver = drivers.find(d => d.uniqueId === p.attributes.driverUniqueId)
|
|
110
|
+
if (driver) {
|
|
111
|
+
p.driverName = driver.name
|
|
115
112
|
}
|
|
113
|
+
})
|
|
114
|
+
}
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
116
|
+
if (positions.length > 0) {
|
|
117
|
+
devicesResult.push({
|
|
118
|
+
device: d,
|
|
119
|
+
from,
|
|
120
|
+
to,
|
|
121
|
+
positions
|
|
122
|
+
})
|
|
125
123
|
}
|
|
124
|
+
}
|
|
126
125
|
|
|
127
|
-
|
|
126
|
+
return devicesResult
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
function processDrivers(from, to, userData, route) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
const driverData = {
|
|
145
|
-
driver: d,
|
|
146
|
-
from: from,
|
|
147
|
-
to: to,
|
|
148
|
-
positions: positions,
|
|
149
|
-
}
|
|
150
|
-
driversResult.push(driverData)
|
|
129
|
+
function processDrivers (from, to, userData, route) {
|
|
130
|
+
const driversResult = []
|
|
131
|
+
userData.drivers.forEach(d => {
|
|
132
|
+
const positions = route.filter(p => p.attributes.driverUniqueId === d.uniqueId)
|
|
133
|
+
if (positions.length > 0) {
|
|
134
|
+
positions.sort((a, b) => new Date(a.fixTime).getTime() - new Date(b.fixTime).getTime())
|
|
135
|
+
|
|
136
|
+
positions.forEach(p => {
|
|
137
|
+
const device = userData.devices.find(d => d.id === p.deviceId)
|
|
138
|
+
if (device) {
|
|
139
|
+
p.vehicleName = device.name
|
|
151
140
|
}
|
|
152
|
-
|
|
153
|
-
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
const driverData = {
|
|
144
|
+
driver: d,
|
|
145
|
+
from,
|
|
146
|
+
to,
|
|
147
|
+
positions
|
|
148
|
+
}
|
|
149
|
+
driversResult.push(driverData)
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
console.log(driversResult)
|
|
154
153
|
|
|
155
|
-
|
|
154
|
+
return driversResult
|
|
156
155
|
}
|
|
157
156
|
|
|
158
|
-
async function exportLocationReportToPDF(userData, reportData) {
|
|
159
|
-
|
|
157
|
+
async function exportLocationReportToPDF (userData, reportData) {
|
|
158
|
+
console.log('Export to PDF')
|
|
160
159
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
const translations = getTranslations(userData)
|
|
161
|
+
const lang = userData.user.attributes.lang || (navigator && navigator.language)
|
|
162
|
+
const timezone = userData.user.attributes.timezone
|
|
164
163
|
|
|
165
|
-
|
|
164
|
+
const positionsData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
166
165
|
|
|
167
|
-
|
|
166
|
+
const headers = userData.byDriver
|
|
167
|
+
? [
|
|
168
168
|
translations.report.date,
|
|
169
169
|
translations.report.address,
|
|
170
170
|
translations.report.speed,
|
|
171
171
|
translations.report.ignition,
|
|
172
172
|
translations.report.vehicle,
|
|
173
173
|
translations.report.temperature
|
|
174
|
-
|
|
174
|
+
]
|
|
175
|
+
: [
|
|
175
176
|
translations.report.date,
|
|
176
177
|
translations.report.address,
|
|
177
178
|
translations.report.speed,
|
|
178
179
|
translations.report.ignition,
|
|
179
180
|
translations.report.driver,
|
|
180
181
|
translations.report.temperature
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return doc
|
|
248
|
-
}
|
|
249
|
-
}
|
|
182
|
+
]
|
|
183
|
+
|
|
184
|
+
if (positionsData) {
|
|
185
|
+
let first = true
|
|
186
|
+
// eslint-disable-next-line new-cap
|
|
187
|
+
const doc = new jsPDF.jsPDF('l')
|
|
188
|
+
await headerFromUser(doc, translations.report.titleLocationReport, userData.user)
|
|
189
|
+
|
|
190
|
+
positionsData.forEach(d => {
|
|
191
|
+
const data = []
|
|
192
|
+
const name = userData.byDriver ? d.driver.name : deviceName(d.device)
|
|
193
|
+
const group = userData.byDriver ? '' : deviceGroupName(userData.groups, d.device, translations)
|
|
194
|
+
|
|
195
|
+
let space = 0
|
|
196
|
+
if (!first) {
|
|
197
|
+
doc.addPage()
|
|
198
|
+
} else {
|
|
199
|
+
first = false
|
|
200
|
+
space = 10
|
|
201
|
+
}
|
|
202
|
+
doc.setFontSize(13)
|
|
203
|
+
doc.text(name, 20, space + 20)
|
|
204
|
+
doc.setFontSize(11)
|
|
205
|
+
doc.text(group, 200, space + 20)
|
|
206
|
+
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
|
|
207
|
+
d.positions.forEach(a => {
|
|
208
|
+
const temp = [
|
|
209
|
+
getLocationDate(a, userData.user),
|
|
210
|
+
a.address,
|
|
211
|
+
Math.round(a.speed * 1.85200),
|
|
212
|
+
a.attributes.ignition ? translations.report.ignitionOn : translations.report.ignitionOff,
|
|
213
|
+
userData.byDriver ? a.vehicleName : getDriverName(a, userData.drivers),
|
|
214
|
+
getTempValue(a)
|
|
215
|
+
]
|
|
216
|
+
data.push(temp)
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
const footValues = [
|
|
220
|
+
'Total:' + d.positions.length,
|
|
221
|
+
'', getMaxSpeed(d.positions)
|
|
222
|
+
]
|
|
223
|
+
|
|
224
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
225
|
+
doc.autoTable({
|
|
226
|
+
head: [headers],
|
|
227
|
+
body: data,
|
|
228
|
+
foot: [footValues],
|
|
229
|
+
showFoot: 'lastPage',
|
|
230
|
+
headStyles: {
|
|
231
|
+
fillColor: style.pdfHeaderColor,
|
|
232
|
+
textColor: style.pdfHeaderTextColor,
|
|
233
|
+
fontSize: 10
|
|
234
|
+
},
|
|
235
|
+
bodyStyles: {
|
|
236
|
+
fillColor: style.pdfBodyColor,
|
|
237
|
+
textColor: style.pdfBodyTextColor,
|
|
238
|
+
fontSize: 8
|
|
239
|
+
},
|
|
240
|
+
footStyles: {
|
|
241
|
+
fillColor: style.pdfFooterColor,
|
|
242
|
+
textColor: style.pdfFooterTextColor,
|
|
243
|
+
fontSize: 9
|
|
244
|
+
},
|
|
245
|
+
startY: space + 35
|
|
246
|
+
})
|
|
247
|
+
})
|
|
250
248
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
row.attributes.temp1 !== 175 && row.attributes.temp1
|
|
254
|
-
|| row.attributes.temp2 !== 175 && row.attributes.temp2
|
|
255
|
-
) || ''
|
|
249
|
+
return doc
|
|
250
|
+
}
|
|
256
251
|
}
|
|
257
252
|
|
|
258
|
-
function
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
253
|
+
function getTempValue (row) {
|
|
254
|
+
return (row.attributes && (
|
|
255
|
+
(row.attributes.temp1 !== 175 && row.attributes.temp1) ||
|
|
256
|
+
(row.attributes.temp2 !== 175 && row.attributes.temp2)
|
|
257
|
+
)) || ''
|
|
258
|
+
}
|
|
264
259
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
{label: translations.report.
|
|
279
|
-
{label: translations.report.
|
|
280
|
-
{label: translations.report.
|
|
281
|
-
{label: translations.report.
|
|
282
|
-
{label: translations.report.
|
|
283
|
-
{label: translations.report.
|
|
284
|
-
{label: translations.report.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
}))
|
|
302
|
-
})
|
|
260
|
+
function exportLocationReportToExcel (userData, reportData) {
|
|
261
|
+
console.log('Export to Excel')
|
|
262
|
+
|
|
263
|
+
const translations = getTranslations(userData)
|
|
264
|
+
|
|
265
|
+
const positionsData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
266
|
+
|
|
267
|
+
const settings = {
|
|
268
|
+
sheetName: translations.report.titleLocationReport, // The name of the sheet
|
|
269
|
+
fileName // The name of the spreadsheet
|
|
270
|
+
}
|
|
271
|
+
const headers = userData.byDriver
|
|
272
|
+
? [
|
|
273
|
+
{ label: translations.report.driver, value: 'driver' },
|
|
274
|
+
{ label: translations.report.date, value: 'date' },
|
|
275
|
+
{ label: translations.report.address, value: 'address' },
|
|
276
|
+
{ label: translations.report.speed, value: 'speed' },
|
|
277
|
+
{ label: translations.report.ignition, value: 'ignition' },
|
|
278
|
+
{ label: translations.report.vehicle, value: 'name' },
|
|
279
|
+
{ label: translations.report.temperature, value: 'temperature' }
|
|
280
|
+
]
|
|
281
|
+
: [
|
|
282
|
+
{ label: translations.report.vehicle, value: 'name' },
|
|
283
|
+
{ label: translations.report.group, value: 'group' },
|
|
284
|
+
{ label: translations.report.date, value: 'date' },
|
|
285
|
+
{ label: translations.report.address, value: 'address' },
|
|
286
|
+
{ label: translations.report.speed, value: 'speed' },
|
|
287
|
+
{ label: translations.report.ignition, value: 'ignition' },
|
|
288
|
+
{ label: translations.report.driver, value: 'driver' },
|
|
289
|
+
{ label: translations.report.temperature, value: 'temperature' }
|
|
290
|
+
]
|
|
291
|
+
let data = []
|
|
292
|
+
if (positionsData) {
|
|
293
|
+
positionsData.forEach(d => {
|
|
294
|
+
data = data.concat(d.positions.map(a => {
|
|
303
295
|
return {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
296
|
+
name: userData.byDriver ? a.vehicleName : d.device.name,
|
|
297
|
+
group: userData.byDriver ? '' : deviceGroupName(userData.groups, d.device),
|
|
298
|
+
date: getLocationDate(a, userData.user),
|
|
299
|
+
address: a.address,
|
|
300
|
+
speed: Math.round(a.speed * 1.85200),
|
|
301
|
+
ignition: a.attributes.ignition ? translations.report.ignitionOn : translations.report.ignitionOff,
|
|
302
|
+
driver: userData.byDriver ? d.driver.name : getDriverName(a, userData.drivers),
|
|
303
|
+
temperature: getTempValue(a)
|
|
307
304
|
}
|
|
305
|
+
}))
|
|
306
|
+
})
|
|
307
|
+
return {
|
|
308
|
+
headers,
|
|
309
|
+
data,
|
|
310
|
+
settings
|
|
308
311
|
}
|
|
312
|
+
}
|
|
309
313
|
}
|
|
310
314
|
|
|
311
|
-
function deviceGroupName(groups, device, translation){
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
315
|
+
function deviceGroupName (groups, device, translation) {
|
|
316
|
+
const group = groups.find(g => device.groupId === g.id)
|
|
317
|
+
if (group) {
|
|
318
|
+
if (translation) {
|
|
319
|
+
return translation.report.group + ': ' + group.name
|
|
320
|
+
} else {
|
|
321
|
+
return group.name
|
|
319
322
|
}
|
|
320
|
-
|
|
323
|
+
}
|
|
324
|
+
return ''
|
|
321
325
|
}
|
|
322
326
|
|
|
323
|
-
function deviceName(device){
|
|
324
|
-
|
|
327
|
+
function deviceName (device) {
|
|
328
|
+
return device.name + (device.attributes.license_plate ? ', ' + device.attributes.license_plate : '') + (device.model ? ', ' + device.model : '')
|
|
325
329
|
}
|
|
326
330
|
|
|
327
|
-
function getLocationDate(location, user){
|
|
328
|
-
|
|
331
|
+
function getLocationDate (location, user) {
|
|
332
|
+
return convertToLocaleString(location.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
329
333
|
}
|
|
330
334
|
|
|
331
|
-
function getDriverName(location, drivers) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
335
|
+
function getDriverName (location, drivers) {
|
|
336
|
+
if (location.attributes.driverUniqueId) {
|
|
337
|
+
const driver = drivers.find(d => d.uniqueId === location.attributes.driverUniqueId)
|
|
338
|
+
return driver ? driver.name : location.attributes.driverUniqueId
|
|
339
|
+
}
|
|
336
340
|
|
|
337
|
-
|
|
341
|
+
return ''
|
|
338
342
|
}
|
|
339
343
|
|
|
340
|
-
function getMaxSpeed(data) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
344
|
+
function getMaxSpeed (data) {
|
|
345
|
+
const values = data.map(item => {
|
|
346
|
+
return item.speed
|
|
347
|
+
})
|
|
348
|
+
const max = values.reduce(function (a, b) {
|
|
349
|
+
return Math.max(a, b)
|
|
350
|
+
})
|
|
351
|
+
return Math.round(max * 1.85200)
|
|
348
352
|
}
|
|
349
353
|
|
|
350
354
|
exports.createLocationReport = createLocationReport
|
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
|
}
|