fleetmap-reports 1.0.634 → 1.0.636

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/enGB.js CHANGED
@@ -269,7 +269,8 @@ module.exports = {
269
269
  unsubscribeFuelDropReport: 'If you no longer wish to receive these emails, please go to %url% and remove the option "Fuel drop report" in the settings in the "Reports" section.',
270
270
  minimumMinutes: 'Minimum time',
271
271
  maximumSpeed: 'Maximum speed',
272
- minutes: 'Minutes'
272
+ minutes: 'Minutes',
273
+ zone: 'Zone'
273
274
  },
274
275
  layout: {
275
276
  deviceOnline: 'Device Online',
package/lang/esCL.js CHANGED
@@ -258,7 +258,8 @@ module.exports = {
258
258
  unsubscribeFuelDropReport: this.unsubscribeTripReport,
259
259
  minimumMinutes: 'Tiempo mínimo',
260
260
  maximumSpeed: 'Velocidad máxima',
261
- minutes: 'Minutos'
261
+ minutes: 'Minutos',
262
+ zone: 'Zona'
262
263
  },
263
264
  layout: {
264
265
  deviceOnline: 'Dispositivo en línea',
package/lang/frFR.json CHANGED
@@ -266,7 +266,8 @@
266
266
  "unsubscribeFuelDropReport": "Si vous ne souhaitez pas recevoir ces e-mails, veuillez accéder à %url% et supprimer le \"rapport de perte de carburant\" paramètres dans la section \"Rapports\".",
267
267
  "minimumMinutes": "Temps minimal",
268
268
  "maximumSpeed": "Vitesse maximum",
269
- "minutes": "Minutes"
269
+ "minutes": "Minutes",
270
+ "zone": "Zone"
270
271
  },
271
272
  "layout": {
272
273
  "deviceOnline": "Appareil en ligne",
package/lang/ptBR.js CHANGED
@@ -261,7 +261,8 @@ module.exports = {
261
261
  unsubscribeFuelDropReport: 'Se não deseja receber estes emails por favor aceda a %url% e remova a opção "Relatório de perdas de combustível" nas definições na secção "Relatórios".',
262
262
  minimumMinutes: 'Tempo mínimo',
263
263
  maximumSpeed: 'Velocidade máxima',
264
- minutes: 'Minutos'
264
+ minutes: 'Minutos',
265
+ zone: 'Zona'
265
266
  },
266
267
  layout: {
267
268
  deviceOnline: 'Dispositivo Online',
package/lang/ptPT.js CHANGED
@@ -270,7 +270,8 @@ module.exports = {
270
270
  unsubscribeFuelDropReport: 'Se não deseja receber estes emails por favor aceda a %url% e remova a opção "Relatório de perdas de combustível" nas definições na secção "Relatórios".',
271
271
  minimumMinutes: 'Tempo mínimo',
272
272
  maximumSpeed: 'Velocidade máxima',
273
- minutes: 'Minutos'
273
+ minutes: 'Minutos',
274
+ zone: 'Zone'
274
275
  },
275
276
  layout: {
276
277
  test: 'Test Notification',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.634",
3
+ "version": "1.0.636",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -49,6 +49,8 @@ async function createIdleReportByDriver (from, to, userData, traccar) {
49
49
  return { drivers: [] }
50
50
  }
51
51
 
52
+ await loadGroupsData(userData, traccar)
53
+
52
54
  const results = await reportByDriver(devices, traccar, from, to, userData, processDrivers)
53
55
 
54
56
  const report = {
@@ -116,6 +118,8 @@ async function createIdleReportByDevice (from, to, userData, traccarInstance) {
116
118
  to
117
119
  }
118
120
 
121
+ await loadGroupsData(userData, traccarInstance)
122
+
119
123
  const devices = devicesToProcess(userData)
120
124
  const sliced = automaticReports.sliceArray(devices, 5)
121
125
 
@@ -124,7 +128,7 @@ async function createIdleReportByDevice (from, to, userData, traccarInstance) {
124
128
  const { route } = await traccarHelper.getAllInOne(traccarInstance, from, to, slice, true, false, false, false, deviceCount, devices.length)
125
129
 
126
130
  if (route.length > 0) {
127
- allData.devices.push(...processDevices(from, to, slice, route, userData))
131
+ allData.devices.push(...await processDevices(from, to, slice, route, userData))
128
132
  }
129
133
 
130
134
  deviceCount = deviceCount + slice.length
@@ -144,6 +148,7 @@ function processDrivers (from, to, userData, data) {
144
148
 
145
149
  if (filteredEvents.length) {
146
150
  filteredEvents.forEach(e => {
151
+ findPOIData(e, userData)
147
152
  findGeofenceData(e, userData)
148
153
 
149
154
  const device = userData.devices.find(d => d.id === e.position.deviceId)
@@ -162,22 +167,22 @@ function processDrivers (from, to, userData, data) {
162
167
  return driversResult
163
168
  }
164
169
 
165
- function processDevices (from, to, devices, routes, userData) {
170
+ async function processDevices (from, to, devices, routes, userData) {
166
171
  const devicesResult = []
167
-
168
- devices.forEach(d => {
172
+ for (const d of devices) {
169
173
  const route = routes.filter(p => p.deviceId === d.id)
170
174
 
171
175
  const idleEvents = getIdleEvents(route, undefined, userData.idleSpeedThreshold / 1.85200)
172
176
  const filteredEvents = idleEvents.filter(e => e.idleTime > (userData.minimumIdleMinutes ? userData.minimumIdleMinutes * 60 * 1000 : 0))
173
177
 
174
178
  if (filteredEvents.length) {
175
- filteredEvents.forEach(e => {
179
+ for (const e of filteredEvents) {
180
+ findPOIData(e, userData)
176
181
  findGeofenceData(e, userData)
177
182
 
178
183
  const driver = userData.drivers.find(d => d.id === e.position.attributes.driverUniqueId)
179
184
  e.driver = driver ? driver.name : ''
180
- })
185
+ }
181
186
 
182
187
  const deviceData = {
183
188
  device: d,
@@ -185,22 +190,32 @@ function processDevices (from, to, devices, routes, userData) {
185
190
  }
186
191
  devicesResult.push(deviceData)
187
192
  }
188
- })
193
+ }
189
194
 
190
195
  return devicesResult
191
196
  }
192
197
 
193
- function findGeofenceData (event, userData) {
198
+ function findPOIData (event, userData) {
194
199
  const nearestPOIs = getNearestPOIs(event.position.longitude, event.position.latitude, userData.geofences)
195
200
  if (nearestPOIs.length > 0) {
196
201
  event.endPOIName = nearestPOIs[0].p.name
197
- } else {
198
- const geofence = userData.geofences.filter(g => g && g.area.startsWith('POLYGON')).some(g =>
199
- insideGeofence({ latitude: event.position.latitude, longitude: event.position.longitude }, g)
200
- )
201
- if (geofence) {
202
- event.endPOIName = geofence.name
203
- }
202
+ }
203
+ }
204
+
205
+ function findGeofenceData (event, userData) {
206
+ const geofence = userData.geofences.filter(g => g && g.area.startsWith('POLYGON')).find(g =>
207
+ insideGeofence({ latitude: event.position.latitude, longitude: event.position.longitude }, g)
208
+ )
209
+ if (geofence) {
210
+ const group = userData.groups.find(g => g.geofenceIds && g.geofenceIds.includes(geofence.id))
211
+ event.geofenceName = geofence.name
212
+ event.geofenceGroup = (group && group.name) || ''
213
+ }
214
+ }
215
+
216
+ async function loadGroupsData (userData, traccarInstance) {
217
+ for (const g of userData.groups) {
218
+ g.geofenceIds = (await traccarInstance.geofences.geofencesGet(undefined, undefined, undefined, g.id, undefined, undefined).then(r => r.data)).map(g => g.id)
204
219
  }
205
220
  }
206
221
 
@@ -218,7 +233,8 @@ async function exportIdleReportToPDF (userData, reportData) {
218
233
  translations.report.start,
219
234
  translations.report.end,
220
235
  translations.report.address,
221
- translations.report.duration
236
+ translations.report.duration,
237
+ translations.report.zone
222
238
  ]
223
239
 
224
240
  if (userData.byDriver) {
@@ -262,6 +278,7 @@ async function exportIdleReportToPDF (userData, reportData) {
262
278
  getIdleEventTime(a.lastPosition, userData.user),
263
279
  a.endPOIName || a.position.address,
264
280
  convertMS(a.idleTime, true),
281
+ (a.geofenceName || '') + (a.geofenceGroup ? ' (' + a.geofenceGroup + ')' : ''),
265
282
  userData.byDriver ? a.deviceName : getDriver(a, userData.drivers)
266
283
  ]
267
284
  data.push(temp)
@@ -334,6 +351,7 @@ function exportIdleReportToExcel (userData, reportData) {
334
351
  { label: translations.report.end, value: 'end' },
335
352
  { label: translations.report.address, value: 'address' },
336
353
  { label: translations.report.duration, value: 'duration' },
354
+ { label: translations.report.zone, value: 'zone' },
337
355
  { label: userData.byDriver ? translations.report.vehicle : translations.report.driver, value: 'subname' }
338
356
  ]
339
357
 
@@ -349,7 +367,8 @@ function exportIdleReportToExcel (userData, reportData) {
349
367
  start: getIdleEventTime(a.position, userData.user),
350
368
  end: getIdleEventTime(a.lastPosition, userData.user),
351
369
  subname: userData.byDriver ? a.deviceName : getDriver(a, userData.drivers),
352
- address: a.endPOIName || a.position.address
370
+ address: a.endPOIName || a.position.address,
371
+ zone: (a.geofenceName || '') + (a.geofenceGroup ? ' (' + a.geofenceGroup + ')' : '')
353
372
  }
354
373
  }))
355
374
  // Totals