fleetmap-reports 1.0.400 → 1.0.403
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/activity-report.js +699 -688
- package/src/speeding-report.js +7 -6
- package/src/trip-report.js +384 -385
- package/src/util/traccar.js +79 -80
package/src/activity-report.js
CHANGED
|
@@ -1,787 +1,798 @@
|
|
|
1
|
-
const automaticReports = require(
|
|
2
|
-
const {convertMS, getDates, getTranslations, weekDaySelected} = require(
|
|
1
|
+
const automaticReports = require('./automaticReports')
|
|
2
|
+
const { convertMS, getDates, getTranslations, weekDaySelected } = require('./util/utils')
|
|
3
3
|
const jsPDF = require('jspdf')
|
|
4
4
|
require('jspdf-autotable')
|
|
5
|
-
const drivers = require(
|
|
6
|
-
const {headerFromUser, addTable} = require(
|
|
7
|
-
const {getStyle} = require(
|
|
8
|
-
const {getUserPartner} = require(
|
|
9
|
-
const traccar = require(
|
|
10
|
-
const {isInsideTimetable, isPartialInsideTimetable, calculateTrip} = require(
|
|
11
|
-
const tripHelper = require(
|
|
12
|
-
const {devicesToProcess} = require(
|
|
5
|
+
const drivers = require('./util/driver')
|
|
6
|
+
const { headerFromUser, addTable } = require('./util/pdfDocument')
|
|
7
|
+
const { getStyle } = require('./reportStyle')
|
|
8
|
+
const { getUserPartner } = require('fleetmap-partners')
|
|
9
|
+
const traccar = require('./util/traccar')
|
|
10
|
+
const { isInsideTimetable, isPartialInsideTimetable, calculateTrip } = require('./util/trips')
|
|
11
|
+
const tripHelper = require('./util/trips')
|
|
12
|
+
const { devicesToProcess } = require('./util/device')
|
|
13
13
|
|
|
14
14
|
const fileName = 'ActivityReport'
|
|
15
15
|
|
|
16
|
-
async function createActivityReport(from, to, userData, traccarInstance) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return reportData
|
|
16
|
+
async function createActivityReport (from, to, userData, traccarInstance) {
|
|
17
|
+
console.log('Create ActivityReport')
|
|
18
|
+
const reportData = []
|
|
19
|
+
|
|
20
|
+
if (userData.byDriver) {
|
|
21
|
+
const allData = await createActivityReportByDriver(from, to, userData, traccarInstance)
|
|
22
|
+
reportData.push(allData)
|
|
23
|
+
} else if (userData.byGroup) {
|
|
24
|
+
const allData = await createActivityReportByGroup(from, to, userData, traccarInstance)
|
|
25
|
+
reportData.push(...allData)
|
|
26
|
+
} else {
|
|
27
|
+
const allData = await createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
28
|
+
reportData.push(allData)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return reportData
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
async function createActivityReportByGroup(from, to, userData, traccarInstance){
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const response = await traccarInstance.reports.reportsSummaryGet(from, to, null, [g.id])
|
|
51
|
-
const summaries = response.data
|
|
34
|
+
async function createActivityReportByGroup (from, to, userData, traccarInstance) {
|
|
35
|
+
console.log('ByGroup')
|
|
36
|
+
const reportData = []
|
|
37
|
+
for (const g of userData.groups) {
|
|
38
|
+
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
39
|
+
console.log(g.name + ' devices:' + devices.length)
|
|
40
|
+
if (devices.length > 0) {
|
|
41
|
+
const groupData = {
|
|
42
|
+
devices: [],
|
|
43
|
+
group: g,
|
|
44
|
+
xpert: devices.filter(d => d.attributes.xpert).length > 0,
|
|
45
|
+
from,
|
|
46
|
+
to
|
|
47
|
+
}
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
const response = await traccarInstance.reports.reportsSummaryGet(from, to, null, [g.id])
|
|
50
|
+
const summaries = response.data
|
|
55
51
|
|
|
56
|
-
|
|
52
|
+
const responseTrips = await traccarInstance.reports.reportsTripsGet(from, to, null, [g.id])
|
|
53
|
+
const trips = responseTrips.data
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
if (summaries.length > 0) {
|
|
58
|
+
console.log('Summary:' + summaries.length)
|
|
59
|
+
groupData.devices = processDevices(from, to, devices, { summaries, trips }, userData)
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
61
|
+
reportData.push(groupData)
|
|
62
|
+
}
|
|
66
63
|
}
|
|
64
|
+
}
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
const withoutGroupDevices = await createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
67
|
+
reportData.push(withoutGroupDevices)
|
|
70
68
|
|
|
71
|
-
|
|
69
|
+
return reportData
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
async function createActivityReportByDevice(from, to, userData, traccarInstance){
|
|
75
|
-
|
|
72
|
+
async function createActivityReportByDevice (from, to, userData, traccarInstance) {
|
|
73
|
+
const allDevices = devicesToProcess(userData)
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
const allData = {
|
|
76
|
+
devices: [],
|
|
77
|
+
xpert: allDevices.filter(d => d.attributes.xpert).length > 0,
|
|
78
|
+
from,
|
|
79
|
+
to
|
|
80
|
+
}
|
|
83
81
|
|
|
82
|
+
const sliced = automaticReports.sliceArray(allDevices, 5)
|
|
83
|
+
let deviceCount = 0
|
|
84
|
+
for (const devices of sliced) {
|
|
84
85
|
let summaries = []
|
|
85
|
-
const {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
86
|
+
const {
|
|
87
|
+
trips,
|
|
88
|
+
route,
|
|
89
|
+
summary
|
|
90
|
+
} = await traccar.getAllInOne(traccarInstance, from, to, devices, true, true, false, !userData.groupByDay, deviceCount, allDevices.length)
|
|
91
|
+
|
|
92
|
+
if (userData.groupByDay) {
|
|
93
|
+
console.log('trips:' + trips.length)
|
|
94
|
+
|
|
95
|
+
if (trips.length) {
|
|
96
|
+
tripHelper.checkTripsKms(traccarInstance, from, to, devices, { trips, route })
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const dates = getDates(from, to)
|
|
100
|
+
for (const date of dates) {
|
|
101
|
+
if (userData.allWeek || !userData.weekDays || !userData.dayHours) {
|
|
102
|
+
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
103
|
+
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
104
|
+
|
|
105
|
+
const summary = await traccar.getSummary(traccarInstance, fromByDay, toByDay, devices)
|
|
106
|
+
summary.forEach(s => {
|
|
107
|
+
s.date = date
|
|
108
|
+
})
|
|
109
|
+
summaries = summaries.concat(summary)
|
|
104
110
|
}
|
|
111
|
+
}
|
|
105
112
|
} else {
|
|
106
|
-
|
|
113
|
+
summaries = summary
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
console.log('Summary:' + summaries.length)
|
|
110
117
|
|
|
111
|
-
//Process report data
|
|
118
|
+
// Process report data
|
|
112
119
|
if (summaries.length || trips.length) {
|
|
113
|
-
|
|
120
|
+
allData.devices = allData.devices.concat(processDevices(from, to, devices, { summaries, trips, route }, userData))
|
|
114
121
|
}
|
|
122
|
+
deviceCount += devices.length
|
|
123
|
+
}
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
return allData
|
|
117
126
|
}
|
|
118
127
|
|
|
119
|
-
async function createActivityReportByDriver(from, to, userData, traccarInstance){
|
|
120
|
-
|
|
128
|
+
async function createActivityReportByDriver (from, to, userData, traccarInstance) {
|
|
129
|
+
const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
121
130
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
let tripsData = []
|
|
132
|
+
let routeData = []
|
|
133
|
+
if (devices.length > 0) {
|
|
134
|
+
const allInOne = await traccar.getAllInOne(traccarInstance, from, to, devices, true, true, false, false)
|
|
135
|
+
tripsData = allInOne.trips
|
|
136
|
+
routeData = allInOne.route
|
|
137
|
+
}
|
|
129
138
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
139
|
+
const allData = {
|
|
140
|
+
drivers: [],
|
|
141
|
+
from,
|
|
142
|
+
to
|
|
143
|
+
}
|
|
135
144
|
|
|
136
|
-
|
|
145
|
+
allData.drivers = processDrivers(from, to, userData.drivers, { trips: tripsData, route: routeData }, userData)
|
|
137
146
|
|
|
138
|
-
|
|
147
|
+
return allData
|
|
139
148
|
}
|
|
140
149
|
|
|
141
|
-
function processDevices(from, to, devices, data, userData) {
|
|
142
|
-
|
|
150
|
+
function processDevices (from, to, devices, data, userData) {
|
|
151
|
+
const devicesResult = []
|
|
143
152
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
devices.forEach(d => {
|
|
154
|
+
const deviceTrips = data.trips.filter(t => t.deviceId === d.id)
|
|
155
|
+
const deviceRoute = data.route.filter(t => t.deviceId === d.id)
|
|
147
156
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
157
|
+
let uncompletedTripRoute = []
|
|
158
|
+
if (deviceRoute.length && deviceTrips.length && deviceRoute[deviceRoute.length - 1].attributes.ignition) {
|
|
159
|
+
uncompletedTripRoute = deviceRoute.filter(p => p.attributes.ignition && new Date(p.fixTime).getTime() > new Date(deviceTrips[deviceTrips.length - 1].endTime).getTime())
|
|
160
|
+
if (uncompletedTripRoute.length) {
|
|
161
|
+
deviceTrips.push(calculateTrip(d, uncompletedTripRoute))
|
|
162
|
+
}
|
|
163
|
+
}
|
|
155
164
|
|
|
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
|
-
|
|
185
|
-
} else {
|
|
186
|
-
const summaryCurrentDay = data.summaries.find(s => {
|
|
187
|
-
return s.deviceId === d.id && s.date.getTime() === date.getTime()})
|
|
188
|
-
|
|
189
|
-
if (summaryCurrentDay) {
|
|
190
|
-
summaryCurrentDay.distance = distance
|
|
191
|
-
summaryCurrentDay.convertedSpentFuel = automaticReports.calculateSpentFuel(summaryCurrentDay.spentFuel, d)
|
|
192
|
-
summaryCurrentDay.startTime = tripsByDay.length && tripsByDay[0].startTime
|
|
193
|
-
summaryCurrentDay.endTime = tripsByDay.length && tripsByDay[tripsByDay.length-1].endTime
|
|
194
|
-
|
|
195
|
-
summary.push(summaryCurrentDay)
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
165
|
+
const summary = []
|
|
166
|
+
if (userData.groupByDay) {
|
|
167
|
+
const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
|
168
|
+
|
|
169
|
+
const dates = getDates(from, to)
|
|
170
|
+
for (const date of dates) {
|
|
171
|
+
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
172
|
+
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
173
|
+
|
|
174
|
+
const tripsByDay = trips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay))
|
|
175
|
+
const distance = tripsByDay.reduce((a, b) => a + b.distance, 0)
|
|
176
|
+
|
|
177
|
+
if (!userData.allWeek && userData.weekDays && userData.dayHours) {
|
|
178
|
+
if (weekDaySelected(date, userData.weekDays)) {
|
|
179
|
+
summary.push({
|
|
180
|
+
date,
|
|
181
|
+
deviceId: d.id,
|
|
182
|
+
averageSpeed: distance > 0 ? ((tripsByDay.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0,
|
|
183
|
+
distance,
|
|
184
|
+
engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
|
|
185
|
+
maxSpeed: tripsByDay.reduce((a, b) => {
|
|
186
|
+
return a > b.maxSpeed ? a : b.maxSpeed
|
|
187
|
+
}, 0),
|
|
188
|
+
endOdometer: 0,
|
|
189
|
+
startOdometer: 0,
|
|
190
|
+
startTime: tripsByDay.length && tripsByDay[0].startTime,
|
|
191
|
+
endTime: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
|
|
192
|
+
})
|
|
193
|
+
}
|
|
199
194
|
} else {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
endOdometer: trips.length ? trips[trips.length - 1].endOdometer : 0,
|
|
213
|
-
startTime: trips.length && trips[0].startTime,
|
|
214
|
-
endTime: trips.length && trips[trips.length - 1].endTime
|
|
215
|
-
})
|
|
216
|
-
} else {
|
|
217
|
-
summary.push(...data.summaries.filter(s => s.deviceId === d.id))
|
|
218
|
-
|
|
219
|
-
if (summary.length) {
|
|
220
|
-
summary.forEach(s => {
|
|
221
|
-
s.distance = deviceTrips.reduce((a, b) => a + b.distance, 0)
|
|
222
|
-
s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
|
|
223
|
-
s.startTime = deviceTrips.length && deviceTrips[0].startTime
|
|
224
|
-
s.endTime = deviceTrips.length && deviceTrips[deviceTrips.length - 1].endTime
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
}
|
|
195
|
+
const summaryCurrentDay = data.summaries.find(s => {
|
|
196
|
+
return s.deviceId === d.id && s.date.getTime() === date.getTime()
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
if (summaryCurrentDay) {
|
|
200
|
+
summaryCurrentDay.distance = distance
|
|
201
|
+
summaryCurrentDay.convertedSpentFuel = automaticReports.calculateSpentFuel(summaryCurrentDay.spentFuel, d)
|
|
202
|
+
summaryCurrentDay.startTime = tripsByDay.length && tripsByDay[0].startTime
|
|
203
|
+
summaryCurrentDay.endTime = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
|
|
204
|
+
|
|
205
|
+
summary.push(summaryCurrentDay)
|
|
206
|
+
}
|
|
228
207
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
if (!userData.allWeek && userData.weekDays && userData.dayHours) {
|
|
211
|
+
const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
|
212
|
+
const distance = trips.reduce((a, b) => a + b.distance, 0)
|
|
213
|
+
summary.push({
|
|
214
|
+
deviceId: d.id,
|
|
215
|
+
averageSpeed: distance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0,
|
|
216
|
+
distance,
|
|
217
|
+
engineHours: trips.reduce((a, b) => a + b.duration, 0),
|
|
218
|
+
maxSpeed: trips.reduce((a, b) => {
|
|
219
|
+
return a > b.maxSpeed ? a : b.maxSpeed
|
|
220
|
+
}, 0),
|
|
221
|
+
startOdometer: trips.length ? trips[0].startOdometer : 0,
|
|
222
|
+
endOdometer: trips.length ? trips[trips.length - 1].endOdometer : 0,
|
|
223
|
+
startTime: trips.length && trips[0].startTime,
|
|
224
|
+
endTime: trips.length && trips[trips.length - 1].endTime
|
|
225
|
+
})
|
|
226
|
+
} else {
|
|
227
|
+
summary.push(...data.summaries.filter(s => s.deviceId === d.id))
|
|
228
|
+
|
|
229
|
+
if (summary.length) {
|
|
230
|
+
summary.forEach(s => {
|
|
231
|
+
s.distance = deviceTrips.reduce((a, b) => a + b.distance, 0)
|
|
232
|
+
s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
|
|
233
|
+
s.startTime = deviceTrips.length && deviceTrips[0].startTime
|
|
234
|
+
s.endTime = deviceTrips.length && deviceTrips[deviceTrips.length - 1].endTime
|
|
235
|
+
})
|
|
233
236
|
}
|
|
234
|
-
|
|
235
|
-
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
236
239
|
|
|
237
|
-
|
|
240
|
+
const deviceData = {
|
|
241
|
+
device: d,
|
|
242
|
+
summary
|
|
243
|
+
}
|
|
244
|
+
devicesResult.push(deviceData)
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
return devicesResult
|
|
238
248
|
}
|
|
239
249
|
|
|
240
|
-
function processDrivers(from, to, drivers, data, userData) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
} else {
|
|
271
|
-
driverData.summary.push({
|
|
272
|
-
distance: trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
|
|
273
|
-
engineHours: trips.reduce((a, b) => a + b.duration, 0),
|
|
274
|
-
maxSpeed: trips.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
275
|
-
averageSpeed: Math.round(trips.reduce((a, b) => a + b.averageSpeed, 0) / trips.length),
|
|
276
|
-
startTime: trips.length && trips[0].startTime,
|
|
277
|
-
endTime: trips.length && trips[trips.length-1].endTime
|
|
278
|
-
})
|
|
279
|
-
}
|
|
280
|
-
driversResult.push(driverData)
|
|
250
|
+
function processDrivers (from, to, drivers, data, userData) {
|
|
251
|
+
console.log(data)
|
|
252
|
+
const driversResult = []
|
|
253
|
+
drivers.forEach(d => {
|
|
254
|
+
const route = data.route.filter(p => p.attributes.driverUniqueId === d.uniqueId)
|
|
255
|
+
const trips = data.trips.filter(t => t.driverUniqueId === d.uniqueId)
|
|
256
|
+
if (trips.length > 0) {
|
|
257
|
+
const driverData = {
|
|
258
|
+
driver: d,
|
|
259
|
+
summary: []
|
|
260
|
+
}
|
|
261
|
+
if (userData.groupByDay) {
|
|
262
|
+
const dates = getDates(from, to)
|
|
263
|
+
for (const date of dates) {
|
|
264
|
+
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
265
|
+
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
266
|
+
|
|
267
|
+
const tripsByDay = trips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay) &&
|
|
268
|
+
(userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|
|
269
|
+
|
|
270
|
+
driverData.summary.push({
|
|
271
|
+
date,
|
|
272
|
+
distance: tripsByDay.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
|
|
273
|
+
engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
|
|
274
|
+
maxSpeed: tripsByDay.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
275
|
+
averageSpeed: tripsByDay.length ? Math.round(tripsByDay.reduce((a, b) => a + b.averageSpeed, 0) / tripsByDay.length) : 0,
|
|
276
|
+
startTime: tripsByDay.length && tripsByDay[0].startTime,
|
|
277
|
+
endTime: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
|
|
278
|
+
})
|
|
281
279
|
}
|
|
282
|
-
|
|
280
|
+
} else {
|
|
281
|
+
driverData.summary.push({
|
|
282
|
+
distance: trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
|
|
283
|
+
engineHours: trips.reduce((a, b) => a + b.duration, 0),
|
|
284
|
+
maxSpeed: trips.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
285
|
+
averageSpeed: Math.round(trips.reduce((a, b) => a + b.averageSpeed, 0) / trips.length),
|
|
286
|
+
startTime: trips.length && trips[0].startTime,
|
|
287
|
+
endTime: trips.length && trips[trips.length - 1].endTime
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
driversResult.push(driverData)
|
|
291
|
+
}
|
|
292
|
+
})
|
|
283
293
|
|
|
284
|
-
|
|
294
|
+
return driversResult
|
|
285
295
|
}
|
|
286
296
|
|
|
287
|
-
async function exportActivityReportToPDF(userData, reportData) {
|
|
288
|
-
|
|
289
|
-
|
|
297
|
+
async function exportActivityReportToPDF (userData, reportData) {
|
|
298
|
+
console.log('Export to PDF')
|
|
299
|
+
const translations = getTranslations(userData)
|
|
300
|
+
|
|
301
|
+
if (reportData.devices || reportData.drivers) {
|
|
302
|
+
// eslint-disable-next-line new-cap
|
|
303
|
+
const doc = new jsPDF.jsPDF('l')
|
|
304
|
+
await headerFromUser(doc, translations.report.titleActivityReport, userData.user)
|
|
305
|
+
|
|
306
|
+
if (userData.groupByDay && userData.byDriver) {
|
|
307
|
+
exportActivityReportToPDFDriverGroupByDay(doc, translations, reportData, userData)
|
|
308
|
+
} else if (userData.groupByDay) {
|
|
309
|
+
exportActivityReportToPDFVehicleGroupByDay(doc, translations, reportData, userData)
|
|
310
|
+
} else if (userData.byDriver) {
|
|
311
|
+
exportActivityReportToPDFDriver(doc, translations, reportData, userData)
|
|
312
|
+
} else {
|
|
313
|
+
exportActivityReportToPDFVehicle(doc, translations, reportData, userData)
|
|
314
|
+
}
|
|
290
315
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
316
|
+
return doc
|
|
317
|
+
}
|
|
318
|
+
}
|
|
294
319
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
320
|
+
function exportActivityReportToPDFDriver (doc, translations, reportData, userData) {
|
|
321
|
+
const headers = [translations.report.driver,
|
|
322
|
+
translations.report.start,
|
|
323
|
+
translations.report.end,
|
|
324
|
+
translations.report.distance,
|
|
325
|
+
translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)',
|
|
326
|
+
translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)',
|
|
327
|
+
translations.report.driverHours]
|
|
328
|
+
|
|
329
|
+
doc.setFontSize(10)
|
|
330
|
+
doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, 30)
|
|
331
|
+
|
|
332
|
+
const data = []
|
|
333
|
+
reportData.drivers.forEach(d => {
|
|
334
|
+
const temp = [
|
|
335
|
+
d.driver.name,
|
|
336
|
+
d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
337
|
+
d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
338
|
+
Number((d.summary[0].distance / 1000).toFixed(2)),
|
|
339
|
+
Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
340
|
+
Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
341
|
+
convertMS(d.summary[0].engineHours)
|
|
342
|
+
]
|
|
343
|
+
data.push(temp)
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
const footValues = ['Total:' + reportData.drivers.length,
|
|
347
|
+
'', '',
|
|
348
|
+
(reportData.drivers.reduce((a, b) => a + b.summary[0].distance, 0) / 1000).toFixed(0),
|
|
349
|
+
getSumAvgSpeed(reportData.drivers, userData),
|
|
350
|
+
getSumMaxSpeed(reportData.drivers, userData),
|
|
351
|
+
convertMS(reportData.drivers.reduce((a, b) => a + b.summary[0].engineHours, 0))]
|
|
352
|
+
|
|
353
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
354
|
+
addTable(doc, headers, data, footValues, style, 35)
|
|
355
|
+
}
|
|
304
356
|
|
|
305
|
-
|
|
306
|
-
|
|
357
|
+
function exportActivityReportToPDFVehicle (doc, translations, reportData, userData) {
|
|
358
|
+
const headers = [translations.report.vehicle,
|
|
359
|
+
translations.report.group,
|
|
360
|
+
translations.report.start,
|
|
361
|
+
translations.report.end,
|
|
362
|
+
translations.report.distance,
|
|
363
|
+
translations.report.start + ' ' + translations.report.odometer,
|
|
364
|
+
translations.report.end + ' ' + translations.report.odometer,
|
|
365
|
+
translations.report.avgSpeed + ' (Km/h)',
|
|
366
|
+
translations.report.maxSpeed + ' (Km/h)',
|
|
367
|
+
translations.report.engineHours,
|
|
368
|
+
translations.report.spentFuel]
|
|
369
|
+
|
|
370
|
+
doc.setFontSize(10)
|
|
371
|
+
doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, 30)
|
|
372
|
+
|
|
373
|
+
const data = []
|
|
374
|
+
reportData.devices.forEach(d => {
|
|
375
|
+
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
376
|
+
|
|
377
|
+
const temp = [
|
|
378
|
+
d.summary[0].deviceName,
|
|
379
|
+
group ? group.name : '',
|
|
380
|
+
d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
381
|
+
d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
382
|
+
Number((d.summary[0].distance / 1000).toFixed(2)),
|
|
383
|
+
Number((d.summary[0].startOdometer / 1000).toFixed(2)),
|
|
384
|
+
Number((d.summary[0].endOdometer / 1000).toFixed(2)),
|
|
385
|
+
Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
386
|
+
Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
387
|
+
convertMS(d.summary[0].engineHours),
|
|
388
|
+
d.summary[0].convertedSpentFuel >= 0 ? d.summary[0].convertedSpentFuel : 0
|
|
389
|
+
]
|
|
390
|
+
data.push(temp)
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
const footValues = ['Total:' + reportData.devices.length,
|
|
394
|
+
'', '', '',
|
|
395
|
+
(reportData.devices.reduce((a, b) => a + b.summary[0].distance, 0) / 1000).toFixed(0),
|
|
396
|
+
'', '',
|
|
397
|
+
getSumAvgSpeed(reportData.devices, userData),
|
|
398
|
+
getSumMaxSpeed(reportData.devices, userData),
|
|
399
|
+
convertMS(reportData.devices.reduce((a, b) => a + b.summary[0].engineHours, 0)),
|
|
400
|
+
getSumSpentFuel(reportData.devices, userData)]
|
|
401
|
+
|
|
402
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
403
|
+
addTable(doc, headers, data, footValues, style, 35)
|
|
307
404
|
}
|
|
308
405
|
|
|
309
|
-
function
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
406
|
+
function exportActivityReportToPDFVehicleGroupByDay (doc, translations, reportData, userData) {
|
|
407
|
+
const headers = [translations.report.date,
|
|
408
|
+
translations.report.start,
|
|
409
|
+
translations.report.end,
|
|
410
|
+
translations.report.distance,
|
|
411
|
+
translations.report.start + ' ' + translations.report.odometer,
|
|
412
|
+
translations.report.end + ' ' + translations.report.odometer,
|
|
413
|
+
translations.report.avgSpeed + ' (Km/h)',
|
|
414
|
+
translations.report.maxSpeed + ' (Km/h)',
|
|
415
|
+
translations.report.engineHours,
|
|
416
|
+
translations.report.spentFuel]
|
|
417
|
+
|
|
418
|
+
const weekDays = [
|
|
419
|
+
translations.report.sunday,
|
|
420
|
+
translations.report.monday,
|
|
421
|
+
translations.report.tuesday,
|
|
422
|
+
translations.report.wednesday,
|
|
423
|
+
translations.report.thursday,
|
|
424
|
+
translations.report.friday,
|
|
425
|
+
translations.report.saturday
|
|
426
|
+
]
|
|
427
|
+
|
|
428
|
+
reportData.devices.forEach(function (d, index) {
|
|
429
|
+
const name = userData.byDriver ? d.driver.name : d.device.name
|
|
430
|
+
const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
|
|
431
|
+
|
|
432
|
+
const space = index === 0 ? 8 : 0
|
|
433
|
+
if (index) {
|
|
434
|
+
doc.addPage()
|
|
435
|
+
}
|
|
317
436
|
|
|
318
|
-
doc.setFontSize(
|
|
319
|
-
doc.text(
|
|
437
|
+
doc.setFontSize(13)
|
|
438
|
+
doc.text(name, 20, space + 20)
|
|
439
|
+
doc.setFontSize(11)
|
|
440
|
+
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
|
|
441
|
+
doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, space + 25)
|
|
442
|
+
|
|
443
|
+
if (!userData.allWeek && userData.weekDays) {
|
|
444
|
+
doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '') +
|
|
445
|
+
(userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '') +
|
|
446
|
+
(userData.weekDays.wednesday ? ' ' + translations.report.wednesday + ',' : '') +
|
|
447
|
+
(userData.weekDays.thursday ? ' ' + translations.report.thursday + ',' : '') +
|
|
448
|
+
(userData.weekDays.friday ? ' ' + translations.report.friday + ',' : '') +
|
|
449
|
+
(userData.weekDays.saturday ? ' ' + translations.report.saturday + ',' : '') +
|
|
450
|
+
(userData.weekDays.sunday ? ' ' + translations.report.sunday + ',' : '') +
|
|
451
|
+
' das ' +
|
|
452
|
+
userData.dayHours.startTime + ' - ' + userData.dayHours.endTime, 20, space + 30)
|
|
453
|
+
}
|
|
320
454
|
|
|
321
455
|
const data = []
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
456
|
+
d.summary.forEach(s => {
|
|
457
|
+
const temp = [
|
|
458
|
+
new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
|
|
459
|
+
s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
460
|
+
s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
461
|
+
Number((s.distance / 1000).toFixed(2)),
|
|
462
|
+
Number((s.startOdometer / 1000).toFixed(2)),
|
|
463
|
+
Number((s.endOdometer / 1000).toFixed(2)),
|
|
464
|
+
Math.round(s.averageSpeed * 1.85200),
|
|
465
|
+
Math.round(s.maxSpeed * 1.85200),
|
|
466
|
+
convertMS(s.engineHours),
|
|
467
|
+
s.convertedSpentFuel >= 0 ? s.convertedSpentFuel : 0
|
|
468
|
+
]
|
|
469
|
+
|
|
470
|
+
data.push(temp)
|
|
333
471
|
})
|
|
334
472
|
|
|
335
|
-
const footValues = ['Total:' +
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
473
|
+
const footValues = ['Total:' + d.summary.length,
|
|
474
|
+
'', '',
|
|
475
|
+
(d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
|
|
476
|
+
'', '',
|
|
477
|
+
getSumAvgSpeed(d.summary, userData),
|
|
478
|
+
getSumMaxSpeed(d.summary, userData),
|
|
479
|
+
convertMS(d.summary.reduce((a, b) => a + b.engineHours, 0)),
|
|
480
|
+
getSumSpentFuel(d.summary, userData)]
|
|
341
481
|
|
|
342
482
|
const style = getStyle(getUserPartner(userData.user))
|
|
343
|
-
addTable(doc, headers, data, footValues, style,
|
|
483
|
+
addTable(doc, headers, data, footValues, style, 40)
|
|
484
|
+
})
|
|
344
485
|
}
|
|
345
486
|
|
|
346
|
-
function
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
487
|
+
function exportActivityReportToExcelVehicleGroupByDay (settings, translations, reportData, userData) {
|
|
488
|
+
const headers = [{ label: translations.report.vehicle, value: 'name' },
|
|
489
|
+
{ label: translations.report.group, value: 'group' },
|
|
490
|
+
{ label: translations.report.date, value: 'date' },
|
|
491
|
+
{ label: translations.report.weekDay, value: 'weekday' },
|
|
492
|
+
{ label: translations.report.start, value: 'start' },
|
|
493
|
+
{ label: translations.report.end, value: 'end' },
|
|
494
|
+
{ label: translations.report.distance, value: 'distance' },
|
|
495
|
+
{ label: translations.report.start + ' ' + translations.report.odometer, value: 'startOdometer' },
|
|
496
|
+
{ label: translations.report.end + ' ' + translations.report.odometer, value: 'endOdometer' },
|
|
497
|
+
{ label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed' },
|
|
498
|
+
{ label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed' },
|
|
499
|
+
{ label: translations.report.engineHours, value: 'engineHours' },
|
|
500
|
+
{ label: translations.report.spentFuel, value: 'spentFuel' }]
|
|
501
|
+
|
|
502
|
+
const weekDays = [
|
|
503
|
+
translations.report.sunday,
|
|
504
|
+
translations.report.monday,
|
|
505
|
+
translations.report.tuesday,
|
|
506
|
+
translations.report.wednesday,
|
|
507
|
+
translations.report.thursday,
|
|
508
|
+
translations.report.friday,
|
|
509
|
+
translations.report.saturday
|
|
510
|
+
]
|
|
511
|
+
|
|
512
|
+
let data = []
|
|
513
|
+
if (reportData.devices) {
|
|
363
514
|
reportData.devices.forEach(d => {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const temp = [
|
|
367
|
-
d.summary[0].deviceName,
|
|
368
|
-
group ? group.name : '',
|
|
369
|
-
d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
370
|
-
d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
371
|
-
Number((d.summary[0].distance / 1000).toFixed(2)),
|
|
372
|
-
Number((d.summary[0].startOdometer / 1000).toFixed(2)),
|
|
373
|
-
Number((d.summary[0].endOdometer / 1000).toFixed(2)),
|
|
374
|
-
Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
375
|
-
Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
376
|
-
convertMS(d.summary[0].engineHours),
|
|
377
|
-
d.summary[0].convertedSpentFuel >= 0 ? d.summary[0].convertedSpentFuel : 0,
|
|
378
|
-
]
|
|
379
|
-
data.push(temp)
|
|
380
|
-
})
|
|
381
|
-
|
|
382
|
-
const footValues = ['Total:' + reportData.devices.length,
|
|
383
|
-
'','','',
|
|
384
|
-
(reportData.devices.reduce((a, b) => a + b.summary[0].distance, 0) / 1000).toFixed(0),
|
|
385
|
-
'', '',
|
|
386
|
-
getSumAvgSpeed(reportData.devices, userData),
|
|
387
|
-
getSumMaxSpeed(reportData.devices, userData),
|
|
388
|
-
convertMS(reportData.devices.reduce((a, b) => a + b.summary[0].engineHours, 0)),
|
|
389
|
-
getSumSpentFuel(reportData.devices, userData)]
|
|
390
|
-
|
|
391
|
-
const style = getStyle(getUserPartner(userData.user))
|
|
392
|
-
addTable(doc, headers, data, footValues, style, 35)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData, userData) {
|
|
396
|
-
const headers = [translations.report.date,
|
|
397
|
-
translations.report.start,
|
|
398
|
-
translations.report.end,
|
|
399
|
-
translations.report.distance,
|
|
400
|
-
translations.report.start + ' ' + translations.report.odometer,
|
|
401
|
-
translations.report.end + ' ' + translations.report.odometer,
|
|
402
|
-
translations.report.avgSpeed + ' (Km/h)',
|
|
403
|
-
translations.report.maxSpeed + ' (Km/h)',
|
|
404
|
-
translations.report.engineHours,
|
|
405
|
-
translations.report.spentFuel]
|
|
406
|
-
|
|
407
|
-
const weekDays = [
|
|
408
|
-
translations.report.sunday,
|
|
409
|
-
translations.report.monday,
|
|
410
|
-
translations.report.tuesday,
|
|
411
|
-
translations.report.wednesday,
|
|
412
|
-
translations.report.thursday,
|
|
413
|
-
translations.report.friday,
|
|
414
|
-
translations.report.saturday
|
|
415
|
-
]
|
|
416
|
-
|
|
417
|
-
reportData.devices.forEach(function (d, index) {
|
|
418
|
-
const name = userData.byDriver ? d.driver.name : d.device.name
|
|
419
|
-
const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
|
|
420
|
-
|
|
421
|
-
let space = index === 0 ? 8 : 0
|
|
422
|
-
if(index){
|
|
423
|
-
doc.addPage()
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
doc.setFontSize(13)
|
|
427
|
-
doc.text(name, 20, space + 20)
|
|
428
|
-
doc.setFontSize(11)
|
|
429
|
-
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
|
|
430
|
-
doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, space + 25)
|
|
431
|
-
|
|
432
|
-
if (!userData.allWeek && userData.weekDays) {
|
|
433
|
-
doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '')
|
|
434
|
-
+ (userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '')
|
|
435
|
-
+ (userData.weekDays.wednesday ? ' ' + translations.report.wednesday + ',' : '')
|
|
436
|
-
+ (userData.weekDays.thursday ? ' ' + translations.report.thursday + ',' : '')
|
|
437
|
-
+ (userData.weekDays.friday ? ' ' + translations.report.friday + ',' : '')
|
|
438
|
-
+ (userData.weekDays.saturday ? ' ' + translations.report.saturday + ',' : '')
|
|
439
|
-
+ (userData.weekDays.sunday ? ' ' + translations.report.sunday + ',' : '')
|
|
440
|
-
+ ' das '
|
|
441
|
-
+ userData.dayHours.startTime + ' - ' + userData.dayHours.endTime, 20, space + 30)
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
const data = []
|
|
445
|
-
d.summary.forEach(s => {
|
|
446
|
-
const temp = [
|
|
447
|
-
new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
|
|
448
|
-
s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
449
|
-
s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
450
|
-
Number((s.distance / 1000).toFixed(2)),
|
|
451
|
-
Number((s.startOdometer / 1000).toFixed(2)),
|
|
452
|
-
Number((s.endOdometer / 1000).toFixed(2)),
|
|
453
|
-
Math.round(s.averageSpeed * 1.85200),
|
|
454
|
-
Math.round(s.maxSpeed * 1.85200),
|
|
455
|
-
convertMS(s.engineHours),
|
|
456
|
-
s.convertedSpentFuel >= 0 ? s.convertedSpentFuel : 0
|
|
457
|
-
]
|
|
458
|
-
|
|
459
|
-
data.push(temp)
|
|
460
|
-
})
|
|
461
|
-
|
|
462
|
-
const footValues = ['Total:' + d.summary.length,
|
|
463
|
-
'','',
|
|
464
|
-
(d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
|
|
465
|
-
'', '',
|
|
466
|
-
getSumAvgSpeed(d.summary, userData),
|
|
467
|
-
getSumMaxSpeed(d.summary, userData),
|
|
468
|
-
convertMS(d.summary.reduce((a, b) => a + b.engineHours, 0)),
|
|
469
|
-
getSumSpentFuel(d.summary, userData)]
|
|
470
|
-
|
|
471
|
-
const style = getStyle(getUserPartner(userData.user))
|
|
472
|
-
addTable(doc, headers, data, footValues, style, 40)
|
|
473
|
-
})
|
|
474
|
-
}
|
|
515
|
+
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
475
516
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
{label: translations.report.group, value: 'group'},
|
|
479
|
-
{label: translations.report.date, value: 'date'},
|
|
480
|
-
{label: translations.report.weekDay, value: 'weekday'},
|
|
481
|
-
{label: translations.report.start, value: 'start'},
|
|
482
|
-
{label: translations.report.end, value: 'end'},
|
|
483
|
-
{label: translations.report.distance, value: 'distance'},
|
|
484
|
-
{label: translations.report.start + ' ' + translations.report.odometer, value: 'startOdometer'},
|
|
485
|
-
{label: translations.report.end + ' ' + translations.report.odometer, value: 'endOdometer'},
|
|
486
|
-
{label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed'},
|
|
487
|
-
{label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed'},
|
|
488
|
-
{label: translations.report.engineHours, value: 'engineHours'},
|
|
489
|
-
{label: translations.report.spentFuel, value: 'spentFuel'}]
|
|
490
|
-
|
|
491
|
-
const weekDays = [
|
|
492
|
-
translations.report.sunday,
|
|
493
|
-
translations.report.monday,
|
|
494
|
-
translations.report.tuesday,
|
|
495
|
-
translations.report.wednesday,
|
|
496
|
-
translations.report.thursday,
|
|
497
|
-
translations.report.friday,
|
|
498
|
-
translations.report.saturday
|
|
499
|
-
]
|
|
500
|
-
|
|
501
|
-
let data = []
|
|
502
|
-
if (reportData.devices) {
|
|
503
|
-
reportData.devices.forEach(d => {
|
|
504
|
-
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
505
|
-
|
|
506
|
-
data = data.concat([{}])
|
|
507
|
-
data = data.concat(d.summary.map(s => {
|
|
508
|
-
return {
|
|
509
|
-
name: s.deviceName,
|
|
510
|
-
group: group ? group.name : '',
|
|
511
|
-
date: new Date(s.date).toLocaleDateString(),
|
|
512
|
-
weekday: weekDays[s.date.getDay()],
|
|
513
|
-
start: s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
514
|
-
end:s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
515
|
-
distance: Number((s.distance / 1000).toFixed(0)),
|
|
516
|
-
startOdometer: Number((s.startOdometer / 1000).toFixed(0)),
|
|
517
|
-
endOdometer: Number((s.endOdometer / 1000).toFixed(0)),
|
|
518
|
-
avgSpeed: Math.round(s.averageSpeed * 1.85200),
|
|
519
|
-
maxSpeed: Math.round(s.maxSpeed * 1.85200),
|
|
520
|
-
engineHours: convertMS(s.engineHours),
|
|
521
|
-
spentFuel: s.convertedSpentFuel >= 0 ? s.convertedSpentFuel : 0
|
|
522
|
-
}
|
|
523
|
-
}))
|
|
524
|
-
})
|
|
525
|
-
console.log(data)
|
|
517
|
+
data = data.concat([{}])
|
|
518
|
+
data = data.concat(d.summary.map(s => {
|
|
526
519
|
return {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
520
|
+
name: s.deviceName,
|
|
521
|
+
group: group ? group.name : '',
|
|
522
|
+
date: new Date(s.date).toLocaleDateString(),
|
|
523
|
+
weekday: weekDays[s.date.getDay()],
|
|
524
|
+
start: s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
525
|
+
end: s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
526
|
+
distance: Number((s.distance / 1000).toFixed(0)),
|
|
527
|
+
startOdometer: Number((s.startOdometer / 1000).toFixed(0)),
|
|
528
|
+
endOdometer: Number((s.endOdometer / 1000).toFixed(0)),
|
|
529
|
+
avgSpeed: Math.round(s.averageSpeed * 1.85200),
|
|
530
|
+
maxSpeed: Math.round(s.maxSpeed * 1.85200),
|
|
531
|
+
engineHours: convertMS(s.engineHours),
|
|
532
|
+
spentFuel: s.convertedSpentFuel >= 0 ? s.convertedSpentFuel : 0
|
|
530
533
|
}
|
|
534
|
+
}))
|
|
535
|
+
})
|
|
536
|
+
console.log(data)
|
|
537
|
+
return {
|
|
538
|
+
headers,
|
|
539
|
+
data,
|
|
540
|
+
settings
|
|
531
541
|
}
|
|
542
|
+
}
|
|
532
543
|
}
|
|
533
544
|
|
|
534
|
-
function
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
545
|
+
function exportActivityReportToPDFDriverGroupByDay (doc, translations, reportData, userData) {
|
|
546
|
+
const headers = [translations.report.date,
|
|
547
|
+
translations.report.start,
|
|
548
|
+
translations.report.end,
|
|
549
|
+
translations.report.distance,
|
|
550
|
+
translations.report.avgSpeed + ' (Km/h)',
|
|
551
|
+
translations.report.maxSpeed + ' (Km/h)',
|
|
552
|
+
translations.report.engineHours]
|
|
553
|
+
|
|
554
|
+
const weekDays = [
|
|
555
|
+
translations.report.sunday,
|
|
556
|
+
translations.report.monday,
|
|
557
|
+
translations.report.tuesday,
|
|
558
|
+
translations.report.wednesday,
|
|
559
|
+
translations.report.thursday,
|
|
560
|
+
translations.report.friday,
|
|
561
|
+
translations.report.saturday
|
|
562
|
+
]
|
|
563
|
+
|
|
564
|
+
reportData.drivers.forEach(function (d, index) {
|
|
565
|
+
const name = d.driver.name
|
|
566
|
+
const group = userData.groups.find(g => g.drivers.includes(d.id))
|
|
567
|
+
|
|
568
|
+
const space = index === 0 ? 8 : 0
|
|
569
|
+
if (index) {
|
|
570
|
+
doc.addPage()
|
|
571
|
+
}
|
|
561
572
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
573
|
+
doc.setFontSize(13)
|
|
574
|
+
doc.text(name, 20, space + 20)
|
|
575
|
+
doc.setFontSize(11)
|
|
576
|
+
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
|
|
577
|
+
doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, space + 25)
|
|
578
|
+
|
|
579
|
+
if (!userData.allWeek && userData.weekDays) {
|
|
580
|
+
doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '') +
|
|
581
|
+
(userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '') +
|
|
582
|
+
(userData.weekDays.wednesday ? ' ' + translations.report.wednesday + ',' : '') +
|
|
583
|
+
(userData.weekDays.thursday ? ' ' + translations.report.thursday + ',' : '') +
|
|
584
|
+
(userData.weekDays.friday ? ' ' + translations.report.friday + ',' : '') +
|
|
585
|
+
(userData.weekDays.saturday ? ' ' + translations.report.saturday + ',' : '') +
|
|
586
|
+
(userData.weekDays.sunday ? ' ' + translations.report.sunday + ',' : '') +
|
|
587
|
+
' das ' +
|
|
588
|
+
userData.dayHours.startTime + ' - ' + userData.dayHours.endTime, 20, space + 30)
|
|
589
|
+
}
|
|
579
590
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
591
|
+
const data = []
|
|
592
|
+
d.summary.forEach(s => {
|
|
593
|
+
const temp = [
|
|
594
|
+
new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
|
|
595
|
+
s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
596
|
+
s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
597
|
+
Number((s.distance / 1000).toFixed(2)),
|
|
598
|
+
Math.round(s.averageSpeed * 1.85200),
|
|
599
|
+
Math.round(s.maxSpeed * 1.85200),
|
|
600
|
+
convertMS(s.engineHours)
|
|
601
|
+
]
|
|
602
|
+
|
|
603
|
+
data.push(temp)
|
|
604
|
+
})
|
|
594
605
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
606
|
+
const footValues = ['Total:' + d.summary.length,
|
|
607
|
+
'', '',
|
|
608
|
+
(d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
|
|
609
|
+
getSumAvgSpeed(d.summary, userData),
|
|
610
|
+
getSumMaxSpeed(d.summary, userData),
|
|
611
|
+
convertMS(d.summary.reduce((a, b) => a + b.engineHours, 0))]
|
|
601
612
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
613
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
614
|
+
addTable(doc, headers, data, footValues, style, 40)
|
|
615
|
+
})
|
|
605
616
|
}
|
|
606
617
|
|
|
607
|
-
function
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
618
|
+
function exportActivityReportToExcelDriverGroupByDay (settings, translations, reportData, userData) {
|
|
619
|
+
const headers = [{ label: translations.report.driver, value: 'name' },
|
|
620
|
+
{ label: translations.report.group, value: 'group' },
|
|
621
|
+
{ label: translations.report.date, value: 'date' },
|
|
622
|
+
{ label: translations.report.weekDay, value: 'weekday' },
|
|
623
|
+
{ label: translations.report.start, value: 'start' },
|
|
624
|
+
{ label: translations.report.end, value: 'end' },
|
|
625
|
+
{ label: translations.report.distance, value: 'distance' },
|
|
626
|
+
{ label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed' },
|
|
627
|
+
{ label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed' },
|
|
628
|
+
{ label: translations.report.engineHours, value: 'engineHours' }]
|
|
629
|
+
|
|
630
|
+
const weekDays = [
|
|
631
|
+
translations.report.sunday,
|
|
632
|
+
translations.report.monday,
|
|
633
|
+
translations.report.tuesday,
|
|
634
|
+
translations.report.wednesday,
|
|
635
|
+
translations.report.thursday,
|
|
636
|
+
translations.report.friday,
|
|
637
|
+
translations.report.saturday
|
|
638
|
+
]
|
|
639
|
+
|
|
640
|
+
let data = []
|
|
641
|
+
if (reportData.drivers) {
|
|
642
|
+
reportData.drivers.forEach(d => {
|
|
643
|
+
const group = userData.groups.find(g => g.drivers.includes(d.id))
|
|
628
644
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
reportData.drivers.forEach(d => {
|
|
632
|
-
const group = userData.groups.find(g => g.drivers.includes(d.id))
|
|
633
|
-
|
|
634
|
-
data = data.concat([{}])
|
|
635
|
-
data = data.concat(d.summary.map(s => {
|
|
636
|
-
return {
|
|
637
|
-
name: d.driver.name,
|
|
638
|
-
group: group ? group.name : '',
|
|
639
|
-
date: new Date(s.date).toLocaleDateString(),
|
|
640
|
-
weekday: weekDays[s.date.getDay()],
|
|
641
|
-
start: s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
642
|
-
end:s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
643
|
-
distance: Number((s.distance / 1000).toFixed(0)),
|
|
644
|
-
avgSpeed: Math.round(s.averageSpeed * 1.85200),
|
|
645
|
-
maxSpeed: Math.round(s.maxSpeed * 1.85200),
|
|
646
|
-
engineHours: convertMS(s.engineHours)
|
|
647
|
-
}
|
|
648
|
-
}))
|
|
649
|
-
})
|
|
650
|
-
console.log(data)
|
|
645
|
+
data = data.concat([{}])
|
|
646
|
+
data = data.concat(d.summary.map(s => {
|
|
651
647
|
return {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
648
|
+
name: d.driver.name,
|
|
649
|
+
group: group ? group.name : '',
|
|
650
|
+
date: new Date(s.date).toLocaleDateString(),
|
|
651
|
+
weekday: weekDays[s.date.getDay()],
|
|
652
|
+
start: s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
653
|
+
end: s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
654
|
+
distance: Number((s.distance / 1000).toFixed(0)),
|
|
655
|
+
avgSpeed: Math.round(s.averageSpeed * 1.85200),
|
|
656
|
+
maxSpeed: Math.round(s.maxSpeed * 1.85200),
|
|
657
|
+
engineHours: convertMS(s.engineHours)
|
|
655
658
|
}
|
|
659
|
+
}))
|
|
660
|
+
})
|
|
661
|
+
console.log(data)
|
|
662
|
+
return {
|
|
663
|
+
headers,
|
|
664
|
+
data,
|
|
665
|
+
settings
|
|
656
666
|
}
|
|
667
|
+
}
|
|
657
668
|
}
|
|
658
669
|
|
|
659
|
-
function
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}
|
|
670
|
+
function exportActivityReportToExcelDriver (settings, translations, reportData) {
|
|
671
|
+
const headers = [{ label: translations.report.driver, value: 'driver' },
|
|
672
|
+
{ label: translations.report.start, value: 'start' },
|
|
673
|
+
{ label: translations.report.end, value: 'end' },
|
|
674
|
+
{ label: translations.report.distance, value: 'distance' },
|
|
675
|
+
{ label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed' },
|
|
676
|
+
{ label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed' },
|
|
677
|
+
{ label: translations.report.driverHours, value: 'engineHours' }]
|
|
678
|
+
|
|
679
|
+
let data = []
|
|
680
|
+
if (reportData.drivers) {
|
|
681
|
+
reportData.drivers.forEach(d => {
|
|
682
|
+
data = data.concat([{
|
|
683
|
+
driver: d.driver.name,
|
|
684
|
+
start: d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
685
|
+
end: d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
686
|
+
distance: Number((d.summary[0].distance / 1000).toFixed(0)),
|
|
687
|
+
avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
688
|
+
maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
689
|
+
engineHours: convertMS(d.summary[0].engineHours)
|
|
690
|
+
}])
|
|
691
|
+
})
|
|
692
|
+
console.log(data)
|
|
693
|
+
return {
|
|
694
|
+
headers,
|
|
695
|
+
data,
|
|
696
|
+
settings
|
|
687
697
|
}
|
|
698
|
+
}
|
|
688
699
|
}
|
|
689
700
|
|
|
690
|
-
function
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
}
|
|
701
|
+
function exportActivityReportToExcelVehicle (settings, translations, reportData, userData) {
|
|
702
|
+
const headers = [{ label: translations.report.vehicle, value: 'name' },
|
|
703
|
+
{ label: translations.report.group, value: 'group' },
|
|
704
|
+
{ label: translations.report.start, value: 'start' },
|
|
705
|
+
{ label: translations.report.end, value: 'end' },
|
|
706
|
+
{ label: translations.report.distance, value: 'distance' },
|
|
707
|
+
{ label: translations.report.start + ' ' + translations.report.odometer, value: 'startOdometer' },
|
|
708
|
+
{ label: translations.report.end + ' ' + translations.report.odometer, value: 'endOdometer' },
|
|
709
|
+
{ label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed' },
|
|
710
|
+
{ label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed' },
|
|
711
|
+
{ label: translations.report.engineHours, value: 'engineHours' },
|
|
712
|
+
{ label: translations.report.spentFuel, value: 'spentFuel' }]
|
|
713
|
+
|
|
714
|
+
if (reportData.devices) {
|
|
715
|
+
let data = []
|
|
716
|
+
reportData.devices.forEach(d => {
|
|
717
|
+
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
718
|
+
|
|
719
|
+
data = data.concat([{
|
|
720
|
+
name: d.summary[0].deviceName,
|
|
721
|
+
group: group ? group.name : '',
|
|
722
|
+
start: d.summary[0].startTime ? new Date(d.summary[0].startTime).toLocaleString() : '',
|
|
723
|
+
end: d.summary[0].endTime ? new Date(d.summary[0].endTime).toLocaleString() : '',
|
|
724
|
+
distance: Number((d.summary[0].distance / 1000).toFixed(0)),
|
|
725
|
+
startOdometer: Number((d.summary[0].startOdometer / 1000).toFixed(0)),
|
|
726
|
+
endOdometer: Number((d.summary[0].endOdometer / 1000).toFixed(0)),
|
|
727
|
+
avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
728
|
+
maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
729
|
+
engineHours: convertMS(d.summary[0].engineHours),
|
|
730
|
+
spentFuel: d.summary[0].convertedSpentFuel >= 0 ? d.summary[0].convertedSpentFuel : 0
|
|
731
|
+
}])
|
|
732
|
+
})
|
|
733
|
+
console.log(data)
|
|
734
|
+
return {
|
|
735
|
+
headers,
|
|
736
|
+
data,
|
|
737
|
+
settings
|
|
728
738
|
}
|
|
739
|
+
}
|
|
729
740
|
}
|
|
730
741
|
|
|
731
|
-
function exportActivityReportToExcel(userData, reportData) {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
742
|
+
function exportActivityReportToExcel (userData, reportData) {
|
|
743
|
+
console.log('Export to Excel')
|
|
744
|
+
const translations = getTranslations(userData)
|
|
745
|
+
|
|
746
|
+
const settings = {
|
|
747
|
+
sheetName: translations.report.titleActivityReport, // The name of the sheet
|
|
748
|
+
fileName // The name of the spreadsheet
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
if (userData.groupByDay && userData.byDriver) {
|
|
752
|
+
return exportActivityReportToExcelDriverGroupByDay(settings, translations, reportData, userData)
|
|
753
|
+
} else if (userData.groupByDay) {
|
|
754
|
+
return exportActivityReportToExcelVehicleGroupByDay(settings, translations, reportData, userData)
|
|
755
|
+
} else if (userData.byDriver) {
|
|
756
|
+
return exportActivityReportToExcelDriver(settings, translations, reportData, userData)
|
|
757
|
+
} else {
|
|
758
|
+
return exportActivityReportToExcelVehicle(settings, translations, reportData, userData)
|
|
759
|
+
}
|
|
760
|
+
}
|
|
739
761
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
} else if(userData.byDriver){
|
|
745
|
-
return exportActivityReportToExcel_Driver(settings, translations, reportData, userData)
|
|
762
|
+
function getSumAvgSpeed (data, userData) {
|
|
763
|
+
const values = data.map(item => {
|
|
764
|
+
if (userData.groupByDay) {
|
|
765
|
+
return Math.round(item.averageSpeed * 1.85200)
|
|
746
766
|
} else {
|
|
747
|
-
|
|
767
|
+
return Math.round(item.summary[0].averageSpeed * 1.85200)
|
|
748
768
|
}
|
|
769
|
+
}).filter(v => v !== 0)
|
|
770
|
+
return Math.round((values.reduce((a, b) => a + b, 0)) / values.length)
|
|
749
771
|
}
|
|
750
772
|
|
|
751
|
-
function
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const values = data.map(item => {
|
|
764
|
-
if(userData.groupByDay){
|
|
765
|
-
return item.maxSpeed
|
|
766
|
-
} else {
|
|
767
|
-
return item.summary[0].maxSpeed
|
|
768
|
-
}
|
|
769
|
-
})
|
|
770
|
-
const max = values.reduce(function (a, b) {
|
|
771
|
-
return Math.max(a, b);
|
|
772
|
-
});
|
|
773
|
-
return Math.round(max * 1.85200)
|
|
773
|
+
function getSumMaxSpeed (data, userData) {
|
|
774
|
+
const values = data.map(item => {
|
|
775
|
+
if (userData.groupByDay) {
|
|
776
|
+
return item.maxSpeed
|
|
777
|
+
} else {
|
|
778
|
+
return item.summary[0].maxSpeed
|
|
779
|
+
}
|
|
780
|
+
})
|
|
781
|
+
const max = values.reduce(function (a, b) {
|
|
782
|
+
return Math.max(a, b)
|
|
783
|
+
})
|
|
784
|
+
return Math.round(max * 1.85200)
|
|
774
785
|
}
|
|
775
786
|
|
|
776
|
-
function getSumSpentFuel(data, userData){
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
787
|
+
function getSumSpentFuel (data, userData) {
|
|
788
|
+
const values = data.map(item => {
|
|
789
|
+
if (userData.groupByDay) {
|
|
790
|
+
return item.convertedSpentFuel >= 0 ? item.convertedSpentFuel : 0
|
|
791
|
+
} else {
|
|
792
|
+
return item.summary[0].convertedSpentFuel >= 0 ? item.summary[0].convertedSpentFuel : 0
|
|
793
|
+
}
|
|
794
|
+
})
|
|
795
|
+
return values.reduce((a, b) => a + b, 0)
|
|
785
796
|
}
|
|
786
797
|
|
|
787
798
|
exports.createActivityReport = createActivityReport
|