fleetmap-reports 1.0.637 → 1.0.638

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.637",
3
+ "version": "1.0.638",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -2,6 +2,14 @@ const traccar = require('../util/traccar')
2
2
  const { getIdleEvents } = require('../util/route')
3
3
  const { insideGeofence, getNearestPOIs } = require('../util/geofence')
4
4
 
5
+ function calculateLastStopTime (stopTime, to, time) {
6
+ return stopTime + (to.getTime() - new Date(time).getTime())
7
+ }
8
+
9
+ function calculateFirstStopTime (stopTime, from, time) {
10
+ return stopTime + (new Date(time).getTime(), from.getTime())
11
+ }
12
+
5
13
  async function createActivityReport (from, to, userData, traccarInstance) {
6
14
  const notAuthGroup = userData.groups.find(g => g.name === 'Zones Non Autorisées')
7
15
  const authGroup = userData.groups.find(g => g.name === 'Zones Autorisées')
@@ -53,7 +61,17 @@ async function createActivityReport (from, to, userData, traccarInstance) {
53
61
  stopTime = stopTime + (new Date(startTrip).getTime() - from.getTime())
54
62
  */
55
63
 
56
- stopTime = endTrip ? stopTime + (to.getTime() - new Date(endTrip.endTime).getTime()) : stopTime
64
+ if (endTrip && stops.length > 0) {
65
+ if (endTrip.endTime > stops[stops.length - 1].endTime) {
66
+ stopTime = calculateLastStopTime(stopTime, to, endTrip.endTime)
67
+ } else {
68
+ stopTime = calculateLastStopTime(stopTime, to, stops[stops.length - 1].endTime)
69
+ }
70
+ } else if (!endTrip && stops.length > 0) {
71
+ stopTime = calculateLastStopTime(stopTime, to, stops[stops.length - 1].endTime)
72
+ } if (endTrip && stops.length === 0) {
73
+ stopTime = calculateLastStopTime(stopTime, to, endTrip.endTime)
74
+ }
57
75
 
58
76
  const startNearestPOIs = startTrip ? getNearestPOIs(startTrip.startLon, startTrip.startLat, userData.geofences) : []
59
77
  const endNearestPOIs = endTrip ? getNearestPOIs(endTrip.endLon, endTrip.endLat, userData.geofences) : []