fleetmap-reports 1.0.643 → 1.0.645

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.643",
3
+ "version": "1.0.645",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -34,6 +34,7 @@ async function createActivityReport (from, to, userData, traccarInstance) {
34
34
  let unauthorizedStops = 0
35
35
  let authorizedStops = 0
36
36
  let otherStops = 0
37
+ let authorizedStopsTime = 0
37
38
 
38
39
  stops.forEach(s => {
39
40
  const unauthorized = unauthorizedGeofences.find(g => insideGeofence({ latitude: s.latitude, longitude: s.longitude }, g))
@@ -45,6 +46,7 @@ async function createActivityReport (from, to, userData, traccarInstance) {
45
46
 
46
47
  if (authorized) {
47
48
  authorizedStops = authorizedStops + 1
49
+ authorizedStopsTime = authorizedStopsTime + (s.duration > s.engineHours ? (s.duration - s.engineHours) : 0)
48
50
  } else {
49
51
  otherStops = otherStops + 1
50
52
  }
@@ -102,7 +104,7 @@ async function createActivityReport (from, to, userData, traccarInstance) {
102
104
  otherStops,
103
105
  authorizedStops,
104
106
  unauthorizedStops,
105
- authorizedStopsTime: unauthorizedStops.reduce((a, b) => a + (b.duration > b.engineHours ? (b.duration - b.engineHours) : 0), 0),
107
+ authorizedStopsTime,
106
108
  averageSpeed: totalDistance > 0 ? ((trips.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / totalDistance) : 0,
107
109
  maxSpeed: trips.reduce((a, b) => {
108
110
  return a > b.maxSpeed ? a : b.maxSpeed
@@ -57,13 +57,15 @@ function processDevices (from, to, devices, data, userData) {
57
57
  const nearestPOIs = getNearestPOIs(stop.longitude, stop.latitude, userData.geofences)
58
58
  if (nearestPOIs.length > 0) {
59
59
  stop.endPOIName = nearestPOIs[0].p.name
60
- } else {
61
- const geofence = userData.geofences.filter(g => g && g.area.startsWith('POLYGON')).some(g =>
62
- insideGeofence({ latitude: stop.latitude, longitude: stop.longitude }, g)
63
- )
64
- if (geofence) {
65
- stop.endPOIName = geofence.name
66
- }
60
+ }
61
+
62
+ const geofence = userData.geofences.filter(g => g && g.area.startsWith('POLYGON')).some(g =>
63
+ insideGeofence({ latitude: stop.latitude, longitude: stop.longitude }, g)
64
+ )
65
+ if (geofence) {
66
+ const group = userData.groups.find(g => g.geofenceIds && g.geofenceIds.includes(geofence.id))
67
+ stop.geofenceName = geofence.name
68
+ stop.geofenceGroup = (group && group.name) || ''
67
69
  }
68
70
 
69
71
  const totalStopTime = new Date(stop.endTime) - new Date(stop.startTime)
@@ -75,7 +77,7 @@ function processDevices (from, to, devices, data, userData) {
75
77
  device: d,
76
78
  from,
77
79
  to,
78
- stops: deviceStops
80
+ stops: deviceStops.filter(s => s.stopDuration > (userData.minimumStopMinutes ? userData.minimumStopMinutes * 60 * 1000 : 0))
79
81
  }
80
82
 
81
83
  devicesResult.push(deviceData)
@@ -99,7 +101,8 @@ async function exportStopReportToPDF (userData, reportData) {
99
101
  translations.report.end,
100
102
  translations.report.address,
101
103
  translations.report.idleTime,
102
- translations.report.event_ignitionOff
104
+ translations.report.event_ignitionOff,
105
+ translations.report.zone
103
106
  ]
104
107
 
105
108
  if (stopsData) {
@@ -122,6 +125,7 @@ async function exportStopReportToPDF (userData, reportData) {
122
125
  doc.setFontSize(11)
123
126
  doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space + 20)
124
127
  doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
128
+ doc.text(translations.report.minimumMinutes + ': ' + userData.minimumStopMinutes + ' ' + translations.report.minutes, 20, space + 35)
125
129
 
126
130
  d.stops.forEach(a => {
127
131
  data.push([
@@ -130,7 +134,8 @@ async function exportStopReportToPDF (userData, reportData) {
130
134
  getStopEnd(userData.user, a),
131
135
  a.endPOIName || a.address,
132
136
  convertMS(a.engineHours, true),
133
- convertMS(a.stopDuration, true)
137
+ convertMS(a.stopDuration, true),
138
+ (a.geofenceName || '') + (a.geofenceGroup ? ' (' + a.geofenceGroup + ')' : '')
134
139
  ])
135
140
  })
136
141
 
@@ -143,7 +148,7 @@ async function exportStopReportToPDF (userData, reportData) {
143
148
  const style = getStyle(getUserPartner(userData.user))
144
149
  addTable(doc,
145
150
  headers, data, footValues, style,
146
- space + 40,
151
+ space + 45,
147
152
  {
148
153
  4: { halign: 'right' },
149
154
  5: { halign: 'right' }
@@ -169,7 +174,8 @@ function exportStopReportToExcel (userData, reportData) {
169
174
  { label: translations.report.end, value: 'end' },
170
175
  { label: translations.report.address, value: 'address' },
171
176
  { label: translations.report.idleTime, value: 'idleTime' },
172
- { label: translations.report.event_ignitionOff, value: 'stopTime' }
177
+ { label: translations.report.event_ignitionOff, value: 'stopTime' },
178
+ { label: translations.report.zone, value: 'zone' }
173
179
  ]
174
180
 
175
181
  let data = []
@@ -184,7 +190,8 @@ function exportStopReportToExcel (userData, reportData) {
184
190
  end: getStopEnd(userData.user, a),
185
191
  address: a.endPOIName || a.address,
186
192
  idleTime: convertMS(a.engineHours, true),
187
- stopTime: convertMS(a.stopDuration, true)
193
+ stopTime: convertMS(a.stopDuration, true),
194
+ zone: (a.geofenceName || '') + (a.geofenceGroup ? ' (' + a.geofenceGroup + ')' : '')
188
195
  }
189
196
  }))
190
197
  // Totals