fleetmap-reports 1.0.249 → 1.0.253
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/.idea/workspace.xml +55 -6
- package/lang/enGB.js +8 -0
- package/lang/esCL.js +8 -0
- package/lang/ptBR.js +8 -0
- package/lang/ptPT.js +8 -0
- package/package.json +1 -1
- package/src/activity-report.js +362 -191
- package/src/index.js +2 -2
- package/src/kms-report.js +155 -110
- package/src/speeding-report.js +110 -45
- package/src/trip-report.js +71 -44
- package/src/util/traccar.js +14 -0
- package/src/util/trips.js +18 -0
- package/src/util/utils.js +1 -1
package/src/speeding-report.js
CHANGED
|
@@ -13,16 +13,18 @@ const {getUserPartner} = require("fleetmap-partners");
|
|
|
13
13
|
const traccar = require("./util/traccar");
|
|
14
14
|
|
|
15
15
|
let traccarInstance
|
|
16
|
+
let userData
|
|
16
17
|
|
|
17
18
|
const fileName = 'SpeedingReport'
|
|
18
19
|
|
|
19
|
-
async function createSpeedingReport(from, to,
|
|
20
|
+
async function createSpeedingReport(from, to, reportUserData, traccar) {
|
|
20
21
|
traccarInstance = traccar
|
|
21
|
-
|
|
22
|
+
userData = reportUserData
|
|
23
|
+
console.log('createSpeedingReport', from, to, userData, traccar)
|
|
22
24
|
const reportData = []
|
|
23
25
|
|
|
24
26
|
if(userData.byDriver){
|
|
25
|
-
const allData = await createSpeedingReportByDriver(from, to
|
|
27
|
+
const allData = await createSpeedingReportByDriver(from, to)
|
|
26
28
|
reportData.push(allData)
|
|
27
29
|
}
|
|
28
30
|
else if(userData.byGroup){
|
|
@@ -37,48 +39,50 @@ async function createSpeedingReport(from, to, userData, traccar, roadSpeedLimits
|
|
|
37
39
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
+
const eventTypes = ['deviceOverspeed']
|
|
43
|
+
const events = await traccar.getEvents(traccarInstance, from, to, devices, eventTypes)
|
|
44
|
+
const routes = userData.useVehicleSpeedLimit ? [] : await traccar.getRoute(traccarInstance, from, to, devices)
|
|
42
45
|
|
|
43
46
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
44
47
|
|
|
45
|
-
if (
|
|
46
|
-
groupData.devices = await processDevices(from, to, devices,
|
|
48
|
+
if (events.length > 0) {
|
|
49
|
+
groupData.devices = await processDevices(from, to, devices, events, routes)
|
|
47
50
|
reportData.push(groupData)
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
const withoutGroupData = await createSpeedingReportByDevice(from, to
|
|
55
|
+
const withoutGroupData = await createSpeedingReportByDevice(from, to)
|
|
53
56
|
reportData.push(withoutGroupData)
|
|
54
57
|
} else {
|
|
55
|
-
const allData = await createSpeedingReportByDevice(from, to
|
|
58
|
+
const allData = await createSpeedingReportByDevice(from, to)
|
|
56
59
|
reportData.push(allData)
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
return reportData
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
async function createSpeedingReportByDevice(from, to
|
|
65
|
+
async function createSpeedingReportByDevice(from, to) {
|
|
63
66
|
const groupIds = userData.groups.map(g => g.id)
|
|
64
67
|
const withoutGroupDevices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
65
68
|
|
|
66
69
|
withoutGroupDevices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
67
70
|
|
|
68
|
-
const
|
|
69
|
-
const
|
|
71
|
+
const eventTypes = ['deviceOverspeed']
|
|
72
|
+
const events = await traccar.getEvents(traccarInstance, from, to, withoutGroupDevices, eventTypes)
|
|
73
|
+
const routes = userData.useVehicleSpeedLimit ? [] : await traccar.getRoute(traccarInstance, from, to, withoutGroupDevices)
|
|
70
74
|
|
|
71
75
|
const allData = { devices: [] }
|
|
72
76
|
|
|
73
|
-
if(
|
|
74
|
-
allData.devices = await processDevices(from, to, withoutGroupDevices,
|
|
77
|
+
if(events.length > 0 || userData.roadSpeedLimits) {
|
|
78
|
+
allData.devices = await processDevices(from, to, withoutGroupDevices, events, routes)
|
|
75
79
|
allData.xpert = withoutGroupDevices.filter(d => d && d.attributes && d.attributes.xpert).length > 0
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
return allData
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
async function createSpeedingReportByDriver(from, to
|
|
85
|
+
async function createSpeedingReportByDriver(from, to) {
|
|
82
86
|
const deviceIds = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
83
87
|
console.log('Devices with driver',deviceIds.length)
|
|
84
88
|
|
|
@@ -93,18 +97,18 @@ async function createSpeedingReportByDriver(from, to, userData) {
|
|
|
93
97
|
}
|
|
94
98
|
console.log(eventsData.length)
|
|
95
99
|
|
|
96
|
-
await getEventsPosition(from , to, userData.devices,
|
|
97
|
-
allData.drivers = await processDrivers(from, to,
|
|
100
|
+
await getEventsPosition(from , to, userData.devices, eventsData)
|
|
101
|
+
allData.drivers = await processDrivers(from, to, eventsData)
|
|
98
102
|
console.log(allData.drivers.length)
|
|
99
103
|
return allData
|
|
100
104
|
}
|
|
101
105
|
|
|
102
|
-
async function processDrivers(from, to,
|
|
106
|
+
async function processDrivers(from, to, data) {
|
|
103
107
|
console.log(data)
|
|
104
108
|
const driversResult = []
|
|
105
109
|
const alertsWithPosition = data.filter(a => a.position)
|
|
106
110
|
|
|
107
|
-
drivers.forEach(d => {
|
|
111
|
+
userData.drivers.forEach(d => {
|
|
108
112
|
const alerts = alertsWithPosition.filter(e => e.position.attributes.driverUniqueId === d.uniqueId)
|
|
109
113
|
|
|
110
114
|
if (alerts.length > 0) {
|
|
@@ -124,34 +128,70 @@ async function processDrivers(from, to, drivers, data) {
|
|
|
124
128
|
return driversResult
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
async function processDevices(from, to, devices,
|
|
131
|
+
async function processDevices(from, to, devices, events, routes) {
|
|
128
132
|
const devicesResult = []
|
|
129
133
|
|
|
130
|
-
|
|
134
|
+
if(userData.useVehicleSpeedLimit) {
|
|
135
|
+
await getEventsPosition(from, to, devices, events)
|
|
131
136
|
|
|
132
|
-
|
|
137
|
+
console.log(events)
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
for (const d of devices) {
|
|
140
|
+
const deviceEvents = events.filter(t => t.deviceId === d.id)
|
|
136
141
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
if (deviceEvents.length > 0) {
|
|
143
|
+
const alertsWithPosition = deviceEvents.filter(a => a.position).sort((a, b) => a.positionId - b.positionId)
|
|
144
|
+
devicesResult.push({
|
|
145
|
+
device: d,
|
|
146
|
+
from: from,
|
|
147
|
+
to: to,
|
|
148
|
+
alerts: alertsWithPosition,
|
|
149
|
+
maxSpeed: alertsWithPosition.reduce((a, b) => {
|
|
150
|
+
return a > (b && b.attributes && b.attributes.maxSpeed) ? a : (b && b.attributes && b.attributes.maxSpeed)
|
|
151
|
+
}, 0),
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
for (const d of devices) {
|
|
157
|
+
const positions = routes.filter(t => t.deviceId === d.id)
|
|
158
|
+
const maxSpeed = userData.customSpeed / 1.85200
|
|
159
|
+
|
|
160
|
+
const alerts = []
|
|
161
|
+
for(let pIndex = 0; pIndex < positions.length ; pIndex++){
|
|
162
|
+
const position = positions[pIndex]
|
|
163
|
+
if(position.speed > maxSpeed){
|
|
164
|
+
const alert = {
|
|
165
|
+
position: position,
|
|
166
|
+
attributes: {
|
|
167
|
+
speedLimit: maxSpeed,
|
|
168
|
+
speed: position.speed
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
pIndex = calculateEventData(positions, pIndex, alert)
|
|
173
|
+
|
|
174
|
+
alerts.push(alert)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if(alerts.length > 0){
|
|
178
|
+
devicesResult.push({
|
|
179
|
+
device: d,
|
|
180
|
+
from: from,
|
|
181
|
+
to: to,
|
|
182
|
+
alerts: alerts,
|
|
183
|
+
maxSpeed: alerts.reduce((a, b) => {
|
|
184
|
+
return a > (b && b.attributes && b.attributes.maxSpeed) ? a : (b && b.attributes && b.attributes.maxSpeed)
|
|
185
|
+
}, 0),
|
|
186
|
+
})
|
|
187
|
+
}
|
|
148
188
|
}
|
|
149
189
|
}
|
|
150
190
|
|
|
151
191
|
return devicesResult
|
|
152
192
|
}
|
|
153
193
|
|
|
154
|
-
async function getEventsPosition(from, to, devices,
|
|
194
|
+
async function getEventsPosition(from, to, devices, events){
|
|
155
195
|
|
|
156
196
|
const deviceIds = [...new Set(events.map(e => e.deviceId))]
|
|
157
197
|
const routeData = await traccar.getRoute(traccarInstance, from, to, deviceIds.map(id => { return { id: id } } ))
|
|
@@ -161,10 +201,10 @@ async function getEventsPosition(from, to, devices, geofences, drivers, events,
|
|
|
161
201
|
for (const d of devices) {
|
|
162
202
|
let alerts = events.filter(t => t.deviceId === d.id)
|
|
163
203
|
|
|
164
|
-
if (alerts.length > 0 || roadSpeedLimits) {
|
|
204
|
+
if (alerts.length > 0 || userData.roadSpeedLimits) {
|
|
165
205
|
const positions = routeData.filter(p => p.deviceId === d.id)
|
|
166
206
|
|
|
167
|
-
if (roadSpeedLimits && positions.length) {
|
|
207
|
+
if (userData.roadSpeedLimits && positions.length) {
|
|
168
208
|
try {
|
|
169
209
|
const results = await here.routeMatch(positions)
|
|
170
210
|
const hereAlerts = results.map(r => {
|
|
@@ -202,7 +242,7 @@ async function getEventsPosition(from, to, devices, geofences, drivers, events,
|
|
|
202
242
|
let geofence = null
|
|
203
243
|
|
|
204
244
|
if (a.geofenceId) {
|
|
205
|
-
geofence = geofences.find(g => g.id === a.geofenceId)
|
|
245
|
+
geofence = userData.geofences.find(g => g.id === a.geofenceId)
|
|
206
246
|
if (geofence) {
|
|
207
247
|
a.geofenceName = geofence.name + ' (' + Math.round(a.attributes.speedLimit * 1.85200) + ' Km/h)'
|
|
208
248
|
}
|
|
@@ -230,7 +270,7 @@ async function getEventsPosition(from, to, devices, geofences, drivers, events,
|
|
|
230
270
|
}
|
|
231
271
|
|
|
232
272
|
if (a.position.attributes.driverUniqueId) {
|
|
233
|
-
const driver = drivers.find(d => d.uniqueId === a.position.attributes.driverUniqueId)
|
|
273
|
+
const driver = userData.drivers.find(d => d.uniqueId === a.position.attributes.driverUniqueId)
|
|
234
274
|
a.driver = driver && driver.name
|
|
235
275
|
}
|
|
236
276
|
|
|
@@ -243,6 +283,31 @@ async function getEventsPosition(from, to, devices, geofences, drivers, events,
|
|
|
243
283
|
}
|
|
244
284
|
}
|
|
245
285
|
|
|
286
|
+
function calculateEventData(positions, pIndex, a, geofence){
|
|
287
|
+
let endEventPosition = a.position
|
|
288
|
+
let maxSpeed = a.position.speed
|
|
289
|
+
let dist = 0
|
|
290
|
+
while (pIndex + 1 < positions.length) {
|
|
291
|
+
pIndex++
|
|
292
|
+
|
|
293
|
+
dist += distance(point([endEventPosition.longitude, endEventPosition.latitude]),
|
|
294
|
+
point([positions[pIndex].longitude, positions[pIndex].latitude]))
|
|
295
|
+
endEventPosition = positions[pIndex]
|
|
296
|
+
if (endEventPosition.speed <= a.attributes.speedLimit || (geofence && isOutsideGeofence(geofence, endEventPosition))) {
|
|
297
|
+
a.eventTime = new Date(endEventPosition.fixTime) - new Date(a.position.fixTime)
|
|
298
|
+
a.attributes.maxSpeed = maxSpeed
|
|
299
|
+
a.distance = dist
|
|
300
|
+
break
|
|
301
|
+
} else {
|
|
302
|
+
if (maxSpeed < endEventPosition.speed) {
|
|
303
|
+
maxSpeed = endEventPosition.speed
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return pIndex
|
|
309
|
+
}
|
|
310
|
+
|
|
246
311
|
function isOutsideGeofence(geofence, endEventPosition) {
|
|
247
312
|
const v = turf.feature(turf.flip(parse(geofence.area)))
|
|
248
313
|
const point = turf.point([endEventPosition.longitude, endEventPosition.latitude])
|
|
@@ -266,7 +331,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
266
331
|
translations.report.duration,
|
|
267
332
|
]
|
|
268
333
|
|
|
269
|
-
if(userData.
|
|
334
|
+
if(userData.roadSpeedLimits) {
|
|
270
335
|
headers.splice(2, 0, translations.report.roadSpeedLimit)
|
|
271
336
|
}
|
|
272
337
|
|
|
@@ -301,7 +366,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
301
366
|
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space+20 )
|
|
302
367
|
doc.text(new Date(d.from).toLocaleString() + ' - ' + new Date(d.to).toLocaleString(), 20, space+25 )
|
|
303
368
|
if (d.alerts[0] && !userData.byDriver) {
|
|
304
|
-
doc.text(translations.report.speedLimit + ": " + Math.round(d.alerts[0].attributes.speedLimit * 1.85200) + ' Km/h', 20, space + 30)
|
|
369
|
+
doc.text(translations.report.speedLimit + ": " + (userData.useVehicleSpeedLimit ? Math.round(d.alerts[0].attributes.speedLimit * 1.85200) : userData.customSpeed) + ' Km/h', 20, space + 30)
|
|
305
370
|
}
|
|
306
371
|
d.alerts.map(a => {
|
|
307
372
|
const temp = [
|
|
@@ -314,7 +379,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
314
379
|
userData.byDriver ? a.deviceName : a.driver
|
|
315
380
|
]
|
|
316
381
|
|
|
317
|
-
if(userData.
|
|
382
|
+
if(userData.roadSpeedLimits){
|
|
318
383
|
temp.splice(2, 0, a.roadSpeedLimit)
|
|
319
384
|
}
|
|
320
385
|
|
|
@@ -330,7 +395,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
330
395
|
convertMS(d.alerts.reduce((a, b) => a + b.eventTime, 0), true)
|
|
331
396
|
]
|
|
332
397
|
|
|
333
|
-
if(userData.
|
|
398
|
+
if(userData.roadSpeedLimits){
|
|
334
399
|
footValues.splice(2, 0, '')
|
|
335
400
|
}
|
|
336
401
|
|
|
@@ -389,7 +454,7 @@ function exportSpeedingReportToExcel(userData, reportData) {
|
|
|
389
454
|
userData.byDriver ? {label: translations.report.vehicle, value:'name'} : {label: translations.report.driver, value:'driver'}
|
|
390
455
|
]
|
|
391
456
|
|
|
392
|
-
if (userData.
|
|
457
|
+
if (userData.roadSpeedLimits){
|
|
393
458
|
headers.splice(3, 0, {label: translations.report.roadSpeedLimit, value:'roadSpeedLimit'})
|
|
394
459
|
}
|
|
395
460
|
|
package/src/trip-report.js
CHANGED
|
@@ -6,40 +6,43 @@ require('jspdf-autotable')
|
|
|
6
6
|
const {coordsDistance} = require("./util/utils")
|
|
7
7
|
const drivers = require("./util/driver")
|
|
8
8
|
const {getUserPartner} = require("fleetmap-partners")
|
|
9
|
-
const {headerFromUser} = require("./util/pdfDocument")
|
|
9
|
+
const {headerFromUser, addTable} = require("./util/pdfDocument")
|
|
10
10
|
const {getStyle} = require("./reportStyle")
|
|
11
11
|
const traccar = require("./util/traccar")
|
|
12
|
+
const trips = require("./util/trips");
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
let traccarInstance
|
|
16
|
+
let userData
|
|
15
17
|
|
|
16
18
|
const fileName = 'TripReport'
|
|
17
19
|
|
|
18
|
-
async function createTripReport(from, to,
|
|
20
|
+
async function createTripReport(from, to, reportUserData, traccar) {
|
|
19
21
|
console.log('Create TripReport')
|
|
22
|
+
userData = reportUserData
|
|
20
23
|
traccarInstance = traccar
|
|
21
24
|
const reportData = []
|
|
22
25
|
|
|
23
26
|
if(userData.byDriver){
|
|
24
|
-
const allData = await createTripReportByDriver(from, to
|
|
27
|
+
const allData = await createTripReportByDriver(from, to)
|
|
25
28
|
reportData.push(allData)
|
|
26
29
|
}
|
|
27
30
|
else if(userData.byGroup){
|
|
28
31
|
console.log("ByGroup")
|
|
29
|
-
const allData = await createTripReportByGroup(from, to
|
|
32
|
+
const allData = await createTripReportByGroup(from, to)
|
|
30
33
|
reportData.push(...allData)
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
const groupIds = userData.groups.map(g => g.id)
|
|
34
37
|
const withoutGroupDevices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
35
38
|
|
|
36
|
-
const allData = await createTripReportByDevice(from, to,
|
|
39
|
+
const allData = await createTripReportByDevice(from, to, withoutGroupDevices)
|
|
37
40
|
reportData.push(allData)
|
|
38
41
|
|
|
39
42
|
return reportData
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
async function createTripReportByDevice(from, to,
|
|
45
|
+
async function createTripReportByDevice(from, to, devices) {
|
|
43
46
|
const allData = {
|
|
44
47
|
devices: [],
|
|
45
48
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
@@ -54,14 +57,14 @@ async function createTripReportByDevice(from, to, userData, devices) {
|
|
|
54
57
|
console.log('Trips:' + data.length)
|
|
55
58
|
|
|
56
59
|
if (data.length > 0) {
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
await trips.checkTripsKms(traccarInstance, from, to,[], data, devices)
|
|
61
|
+
allData.devices = processDevices(from, to, devices, data, stopsData)
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
return allData
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
async function createTripReportByGroup(from, to
|
|
67
|
+
async function createTripReportByGroup(from, to) {
|
|
65
68
|
const reportData = []
|
|
66
69
|
for (const g of userData.groups) {
|
|
67
70
|
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
@@ -93,7 +96,7 @@ async function createTripReportByGroup(from, to, userData) {
|
|
|
93
96
|
return reportData
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
async function createTripReportByDriver(from, to
|
|
99
|
+
async function createTripReportByDriver(from, to){
|
|
97
100
|
const deviceIds = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
98
101
|
console.log(deviceIds.length)
|
|
99
102
|
|
|
@@ -112,11 +115,11 @@ async function createTripReportByDriver(from, to, userData){
|
|
|
112
115
|
return allData
|
|
113
116
|
}
|
|
114
117
|
|
|
115
|
-
function processDevices(from, to, devices, data, stopsData
|
|
118
|
+
function processDevices(from, to, devices, data, stopsData) {
|
|
116
119
|
const devicesResult = []
|
|
117
120
|
|
|
118
121
|
devices.forEach(d => {
|
|
119
|
-
const trips = data.filter(t => t.deviceId === d.id)
|
|
122
|
+
const trips = data.filter(t => t.deviceId === d.id && (userData.allWeek || isInsideTimetable(t, userData)))
|
|
120
123
|
const stops = stopsData.filter(s => s.deviceId === d.id)
|
|
121
124
|
|
|
122
125
|
trips.forEach(t => {
|
|
@@ -146,8 +149,8 @@ function processDevices(from, to, devices, data, stopsData, userData) {
|
|
|
146
149
|
})
|
|
147
150
|
|
|
148
151
|
if (trips.length > 0) {
|
|
149
|
-
trips.forEach(
|
|
150
|
-
const stop =
|
|
152
|
+
trips.forEach(trip => {
|
|
153
|
+
const stop = getStop(new Date(trip.startTime), stops)
|
|
151
154
|
|
|
152
155
|
if (stop) {
|
|
153
156
|
trip.stopDuration = (new Date(stop.endTime) - new Date(stop.startTime))
|
|
@@ -240,27 +243,38 @@ async function exportTripReportToPDF(userData, reportData) {
|
|
|
240
243
|
}
|
|
241
244
|
|
|
242
245
|
if (tripsData) {
|
|
243
|
-
let first = true
|
|
244
246
|
const doc = new jsPDF.jsPDF('l');
|
|
245
247
|
await headerFromUser(doc, translations.report.titleTripReport, userData.user)
|
|
246
|
-
|
|
248
|
+
|
|
249
|
+
tripsData.forEach(function (d, index) {
|
|
247
250
|
const data = []
|
|
248
251
|
const name = userData.byDriver ? d.driver.name : deviceName(d.device)
|
|
249
252
|
const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
|
|
250
253
|
|
|
251
|
-
let space = 0
|
|
252
|
-
if(
|
|
254
|
+
let space = index === 0 ? 8 : 0
|
|
255
|
+
if(index){
|
|
253
256
|
doc.addPage()
|
|
254
|
-
} else {
|
|
255
|
-
first = false
|
|
256
|
-
space = 8
|
|
257
257
|
}
|
|
258
|
+
|
|
258
259
|
doc.setFontSize(13)
|
|
259
260
|
doc.text(name, 20, space+20 )
|
|
260
261
|
doc.setFontSize(11)
|
|
261
262
|
doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space+20 )
|
|
262
263
|
doc.text(new Date(d.from).toLocaleString() + ' - ' + new Date(d.to).toLocaleString(), 20, space+25 )
|
|
263
|
-
|
|
264
|
+
if(!userData.allWeek) {
|
|
265
|
+
doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '')
|
|
266
|
+
+ (userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '')
|
|
267
|
+
+ (userData.weekDays.wednesday ? ' ' + translations.report.wednesday + ',' : '')
|
|
268
|
+
+ (userData.weekDays.thursday ? ' ' + translations.report.thursday + ',' : '')
|
|
269
|
+
+ (userData.weekDays.friday ? ' ' + translations.report.friday + ',' : '')
|
|
270
|
+
+ (userData.weekDays.saturday ? ' ' + translations.report.saturday + ',' : '')
|
|
271
|
+
+ (userData.weekDays.sunday ? ' ' + translations.report.sunday + ',' : '')
|
|
272
|
+
+ ' das '
|
|
273
|
+
+ userData.dayHours.startTime + ' - ' + userData.dayHours.endTime, 20, space + 30)
|
|
274
|
+
doc.text(translations.report.headerStartAddress + ': ' + d.trips[0].startAddress, 20, space+40 )
|
|
275
|
+
} else {
|
|
276
|
+
doc.text(translations.report.headerStartAddress + ': ' + d.trips[0].startAddress, 20, space+35 )
|
|
277
|
+
}
|
|
264
278
|
|
|
265
279
|
d.trips.map(a => {
|
|
266
280
|
const temp = [
|
|
@@ -306,28 +320,8 @@ async function exportTripReportToPDF(userData, reportData) {
|
|
|
306
320
|
}
|
|
307
321
|
|
|
308
322
|
const style = getStyle(getUserPartner(userData.user))
|
|
309
|
-
doc.
|
|
310
|
-
|
|
311
|
-
body: data,
|
|
312
|
-
foot: [footValues],
|
|
313
|
-
showFoot: 'lastPage',
|
|
314
|
-
headStyles: {
|
|
315
|
-
fillColor: style.pdfHeaderColor,
|
|
316
|
-
textColor: style.pdfHeaderTextColor,
|
|
317
|
-
fontSize: 10
|
|
318
|
-
},
|
|
319
|
-
bodyStyles: {
|
|
320
|
-
fillColor: style.pdfBodyColor,
|
|
321
|
-
textColor: style.pdfBodyTextColor,
|
|
322
|
-
fontSize: 8
|
|
323
|
-
},
|
|
324
|
-
footStyles: {
|
|
325
|
-
fillColor: style.pdfFooterColor,
|
|
326
|
-
textColor: style.pdfFooterTextColor,
|
|
327
|
-
fontSize: 9
|
|
328
|
-
},
|
|
329
|
-
startY: space+35 })
|
|
330
|
-
}
|
|
323
|
+
addTable(doc, headers, data, footValues, style, space + (userData.allWeek ? 40 : 45))
|
|
324
|
+
})
|
|
331
325
|
return doc
|
|
332
326
|
}
|
|
333
327
|
}
|
|
@@ -451,6 +445,39 @@ function getMaxSpeed(data) {
|
|
|
451
445
|
return Math.round(max * 1.85200)
|
|
452
446
|
}
|
|
453
447
|
|
|
448
|
+
function getStop(tripEndDate, stops){
|
|
449
|
+
const stopList = stops.filter(s => new Date(s.startTime).getTime() >= tripEndDate.getTime())
|
|
450
|
+
if(stopList.length){
|
|
451
|
+
return stopList[0]
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return null
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function isInsideTimetable(t, userData){
|
|
458
|
+
const tripStart = new Date(t.startTime)
|
|
459
|
+
const tripEnd = new Date(t.endTime)
|
|
460
|
+
|
|
461
|
+
if((tripStart.getDay() === 0 && userData.weekDays.sunday) ||
|
|
462
|
+
(tripStart.getDay() === 1 && userData.weekDays.monday) ||
|
|
463
|
+
(tripStart.getDay() === 2 && userData.weekDays.tuesday) ||
|
|
464
|
+
(tripStart.getDay() === 3 && userData.weekDays.wednesday) ||
|
|
465
|
+
(tripStart.getDay() === 4 && userData.weekDays.thursday) ||
|
|
466
|
+
(tripStart.getDay() === 5 && userData.weekDays.friday) ||
|
|
467
|
+
(tripStart.getDay() === 6 && userData.weekDays.saturday)) {
|
|
468
|
+
|
|
469
|
+
const startDate = new Date(new Date(tripStart).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
|
|
470
|
+
const endDate = new Date(new Date(tripStart).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
|
|
471
|
+
|
|
472
|
+
console.log(tripStart, startDate, endDate)
|
|
473
|
+
|
|
474
|
+
//Trips inside time period
|
|
475
|
+
return tripStart.getTime() > startDate.getTime() && tripEnd.getTime() < endDate.getTime()
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return false
|
|
479
|
+
}
|
|
480
|
+
|
|
454
481
|
exports.createTripReport = createTripReport;
|
|
455
482
|
exports.exportTripReportToPDF = exportTripReportToPDF;
|
|
456
483
|
exports.exportTripReportToExcel = exportTripReportToExcel;
|
package/src/util/traccar.js
CHANGED
|
@@ -52,7 +52,21 @@ async function getEvents(traccar, from, to, devices, events){
|
|
|
52
52
|
return result.map(r => r.data).flat()
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
async function getSummary(traccar, from, to, devices){
|
|
56
|
+
const devicesToSlice = devices.slice()
|
|
57
|
+
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
|
|
58
|
+
let requests = []
|
|
59
|
+
for (const a of arrayOfArrays) {
|
|
60
|
+
const promise = traccar.reports.reportsSummaryGet(from, to, a.map(d => d.id))
|
|
61
|
+
requests = requests.concat(promise)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const result = await Promise.all(requests)
|
|
65
|
+
return result.map(r => r.data).flat()
|
|
66
|
+
}
|
|
67
|
+
|
|
55
68
|
exports.getRoute = getRoute
|
|
56
69
|
exports.getTrips = getTrips
|
|
57
70
|
exports.getStops = getStops
|
|
58
71
|
exports.getEvents = getEvents
|
|
72
|
+
exports.getSummary = getSummary
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const traccar = require("./traccar");
|
|
2
|
+
|
|
3
|
+
async function checkTripsKms(traccarInstance, from, to, routeData, tripsData, devices) {
|
|
4
|
+
console.log('checkTripsKms')
|
|
5
|
+
const trips = tripsData.filter(t => t.distance === 0 && t.averageSpeed > 10)
|
|
6
|
+
if(trips.length > 0) {
|
|
7
|
+
//Vehicles with imported positions. calculate trip distance with route positions
|
|
8
|
+
const route = routeData.length === 0 ? await traccar.getRoute(traccarInstance, from, to, devices) : routeData
|
|
9
|
+
trips.forEach(t => {
|
|
10
|
+
const tripRoute = route.filter(p => p.deviceId === t.deviceId
|
|
11
|
+
&& new Date(p.fixTime).getTime() > new Date(t.startTime).getTime()
|
|
12
|
+
&& new Date(p.fixTime).getTime() < new Date(t.endTime).getTime())
|
|
13
|
+
t.distance = tripRoute.reduce((a, b) => a + b.attributes.distance, 0)
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.checkTripsKms = checkTripsKms
|
package/src/util/utils.js
CHANGED
|
@@ -31,7 +31,7 @@ function coordsDistance(lon1, lat1, lon2, lat2) {
|
|
|
31
31
|
|
|
32
32
|
function getDates(startDate, endDate) {
|
|
33
33
|
const dates = []
|
|
34
|
-
let currentDate = startDate
|
|
34
|
+
let currentDate = new Date(startDate.toISOString().split('T')[0] + ' 12:00 PM')
|
|
35
35
|
const addDays = function (days) {
|
|
36
36
|
const date = new Date(this.valueOf())
|
|
37
37
|
date.setDate(date.getDate() + days)
|