fleetmap-reports 1.0.446 → 1.0.450

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
@@ -161,6 +161,10 @@ module.exports = {
161
161
  delete_geofence: 'Delete'
162
162
  },
163
163
  report: {
164
+ closed: 'Door Closed',
165
+ opened: 'Door Opened',
166
+ sun: 'Sun',
167
+ rain: 'Rain',
164
168
  temperature: 'Temperatura',
165
169
  select_vehicles: 'Select vehicles',
166
170
  select_vehicles_placeholder: 'Vehicles',
package/lang/ptBR.js CHANGED
@@ -153,6 +153,12 @@ module.exports = {
153
153
  delete_geofence: 'Apagar'
154
154
  },
155
155
  report: {
156
+ closed: 'Porta fechada',
157
+ opened: 'Porta aberta',
158
+ sun: 'Sol',
159
+ rain: 'Chuva',
160
+ digital_ports1: 'Portas Digitais 1',
161
+ digital_ports2: 'Portas Digitais 2',
156
162
  temperature: 'Temperatura',
157
163
  select_vehicles: 'Seleccionar veículos',
158
164
  select_vehicles_placeholder: 'Veículos',
package/lang/ptPT.js CHANGED
@@ -157,6 +157,12 @@ module.exports = {
157
157
  delete_geofence: 'Apagar'
158
158
  },
159
159
  report: {
160
+ closed: 'Porta fechada',
161
+ opened: 'Porta aberta',
162
+ sun: 'Sol',
163
+ rain: 'Chuva',
164
+ digital_ports1: 'Portas Digitais 1',
165
+ digital_ports2: 'Portas Digitais 2',
160
166
  temperature: 'Temperatura',
161
167
  select_vehicles: 'Seleccionar veículos',
162
168
  select_vehicles_placeholder: 'Veículos',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.446",
3
+ "version": "1.0.450",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -219,6 +219,7 @@ function exportSpeedingReportToExcel (userData, reportData) {
219
219
  { label: translations.report.eventType, value: 'eventType' },
220
220
  { label: translations.report.date, value: 'fixTime' },
221
221
  { label: translations.report.address, value: 'address' },
222
+ { label: translations.report.driver, value: 'driver' },
222
223
  { label: translations.report.info, value: 'info' }
223
224
  ]
224
225
  let data = []
@@ -230,7 +231,8 @@ function exportSpeedingReportToExcel (userData, reportData) {
230
231
  eventType: a.type === 'alarm' ? translations.report['event_' + a.attributes.alarm] : translations.report['event_' + a.type],
231
232
  fixTime: getAlertDate(userData.user, a),
232
233
  address: a.geofenceName || (a.position ? a.position.address : ''),
233
- info: getAlertInfo(userData.drivers, a)
234
+ info: getAlertInfo(userData.drivers, a),
235
+ driver: a.driver
234
236
  }
235
237
  }))
236
238
  })
@@ -262,7 +264,7 @@ function getAlertInfo (drivers, alert) {
262
264
  const driver = drivers.find(d => d.uniqueId === alert.attributes.driverUniqueId)
263
265
  return driver ? driver.name : alert.attributes.driverUniqueId
264
266
  }
265
- return alert.driver
267
+ return ''
266
268
  }
267
269
 
268
270
  function getAlertDate (user, alert) {
package/src/index.test.js CHANGED
@@ -15,10 +15,12 @@ async function getSpeedingReport (report, userData) {
15
15
 
16
16
  // eslint-disable-next-line no-undef
17
17
  describe('Test_Reports', function () {
18
+ this.timeout(500000)
18
19
  // eslint-disable-next-line no-undef
19
20
  it('Speeding by device', async () => {
20
21
  const report = await getReports()
21
22
  const userData = await report.getUserData()
23
+ userData.roadSpeedLimit = true
22
24
  const { device, totalDistance, totalEventTime } = await getSpeedingReport(report, userData)
23
25
  assert.equal(device.alerts.length, 15) // Total Alerts
24
26
  assert.equal(totalDistance, 19.59984677533689) // Total Kms
@@ -49,8 +51,9 @@ describe('Test_Reports', function () {
49
51
  const device = data[0].devices.find(d => d.device.id === 22326)
50
52
  assert.equal(device.trips.length, 7) // Total Trips
51
53
  assert.equal(device.trips[0].endPOIName, 'Casa João')
54
+ assert.equal(device.trips[0].idleTime, 602000)
52
55
  assert.equal(device.trips[1].endPOIName, undefined)
53
- assert.equal(device.totalDistance, 339204.53999999166) // Total Kms
56
+ assert.equal(device.totalDistance, 339170.3099999875) // Total Kms
54
57
  }, 20000)
55
58
  // eslint-disable-next-line no-undef
56
59
  it('Trip by driver', async () => {
@@ -63,10 +66,10 @@ describe('Test_Reports', function () {
63
66
  assert.equal(data.length, 1)
64
67
  console.log(data[0].drivers)
65
68
  const driver = data[0].drivers.find(d => d.driver.id === 14020)
66
- assert.equal(driver.trips.length, 9) // Total Trips
67
- assert.equal(driver.totalDuration, 6274000)
68
- assert.equal(driver.maxSpeed, 70.1944)
69
- }, 20000)
69
+ assert.equal(driver.trips.length, 13) // Total Trips
70
+ assert.equal(driver.totalDuration, 8159000)
71
+ assert.equal(driver.maxSpeed, 78.8337)
72
+ }, 90000)
70
73
  // eslint-disable-next-line no-undef
71
74
  it('Trip without addresses', async () => {
72
75
  const report = await getReports()
@@ -224,7 +227,7 @@ describe('Test_Reports', function () {
224
227
  assert.equal(data.length, 1)
225
228
  const device = data[0].devices.find(d => d.device.id === 22326)
226
229
  const totalIdleTime = device.idleEvents.reduce((a, b) => a + b.idleTime, 0)
227
- assert.equal(device.idleEvents.length, 8) // Total Alerts
230
+ assert.equal(device.idleEvents.length, 9) // Total Alerts
228
231
  assert.equal(totalIdleTime, 1294000) // Total Duration
229
232
  }, 20000)
230
233
  // eslint-disable-next-line no-undef
@@ -169,19 +169,26 @@ async function exportLocationReportToPDF (userData, reportData) {
169
169
  translations.report.address,
170
170
  translations.report.speed,
171
171
  translations.report.ignition,
172
- translations.report.vehicle,
173
- translations.report.temperature
172
+ translations.report.vehicle
174
173
  ]
175
174
  : [
176
175
  translations.report.date,
177
176
  translations.report.address,
178
177
  translations.report.speed,
179
178
  translations.report.ignition,
180
- translations.report.driver,
181
- translations.report.temperature
179
+ translations.report.driver
182
180
  ]
183
181
 
182
+ if (userData.includeTemperature) {
183
+ headers.push(translations.report.temperature)
184
+ }
185
+
184
186
  if (positionsData) {
187
+ if (userData.includeDigitalPorts) {
188
+ headers.push(getDigitalPort1Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations))
189
+ headers.push(getDigitalPort2Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations))
190
+ }
191
+
185
192
  let first = true
186
193
  // eslint-disable-next-line new-cap
187
194
  const doc = new jsPDF.jsPDF('l')
@@ -210,9 +217,18 @@ async function exportLocationReportToPDF (userData, reportData) {
210
217
  a.address,
211
218
  Math.round(a.speed * 1.85200),
212
219
  a.attributes.ignition ? translations.report.ignitionOn : translations.report.ignitionOff,
213
- userData.byDriver ? a.vehicleName : getDriverName(a, userData.drivers),
214
- getTempValue(a)
220
+ userData.byDriver ? a.vehicleName : getDriverName(a, userData.drivers)
215
221
  ]
222
+
223
+ if (userData.includeTemperature) {
224
+ temp.push(getTempValue(a))
225
+ }
226
+
227
+ if (userData.includeDigitalPorts) {
228
+ temp.push(getDigitalPortValue(a, 1, translations))
229
+ temp.push(getDigitalPortValue(a, 2, translations))
230
+ }
231
+
216
232
  data.push(temp)
217
233
  })
218
234
 
@@ -257,6 +273,28 @@ function getTempValue (row) {
257
273
  )) || ''
258
274
  }
259
275
 
276
+ function getDigitalPort1Label (row, translations) {
277
+ return row.attributes.door1 || translations.report.digital_ports1
278
+ }
279
+
280
+ function getDigitalPort2Label (row, translations) {
281
+ return row.attributes.door2 || translations.report.digital_ports2
282
+ }
283
+
284
+ function getDigitalPortValue (row, index, translations) {
285
+ switch (index) {
286
+ case 1:
287
+ return row.attributes && row.attributes.door1 ? translations.report[row.attributes.door1] : ''
288
+ case 2:
289
+ if (row.attributes && row.attributes.door2) {
290
+ return translations.report[row.attributes.door2]
291
+ }
292
+ return row.attributes && row.attributes.rain ? translations.report[row.attributes.rain] : ''
293
+ default:
294
+ return ''
295
+ }
296
+ }
297
+
260
298
  function exportLocationReportToExcel (userData, reportData) {
261
299
  console.log('Export to Excel')
262
300
 
@@ -285,11 +323,20 @@ function exportLocationReportToExcel (userData, reportData) {
285
323
  { label: translations.report.address, value: 'address' },
286
324
  { label: translations.report.speed, value: 'speed' },
287
325
  { label: translations.report.ignition, value: 'ignition' },
288
- { label: translations.report.driver, value: 'driver' },
289
- { label: translations.report.temperature, value: 'temperature' }
326
+ { label: translations.report.driver, value: 'driver' }
290
327
  ]
328
+
329
+ if (userData.includeTemperature) {
330
+ headers.push({ label: translations.report.temperature, value: 'temperature' })
331
+ }
332
+
291
333
  let data = []
292
334
  if (positionsData) {
335
+ if (userData.includeDigitalPorts) {
336
+ headers.push({ label: getDigitalPort1Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations), value: 'digitalport1' })
337
+ headers.push({ label: getDigitalPort2Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations), value: 'digitalport2' })
338
+ }
339
+
293
340
  positionsData.forEach(d => {
294
341
  data = data.concat(d.positions.map(a => {
295
342
  return {
@@ -300,7 +347,9 @@ function exportLocationReportToExcel (userData, reportData) {
300
347
  speed: Math.round(a.speed * 1.85200),
301
348
  ignition: a.attributes.ignition ? translations.report.ignitionOn : translations.report.ignitionOff,
302
349
  driver: userData.byDriver ? d.driver.name : getDriverName(a, userData.drivers),
303
- temperature: getTempValue(a)
350
+ temperature: getTempValue(a),
351
+ digitalport1: getDigitalPortValue(a, 1, translations),
352
+ digitalport2: getDigitalPortValue(a, 2, translations)
304
353
  }
305
354
  }))
306
355
  })
@@ -169,9 +169,10 @@ function processDevices (from, to, devices, data, userData, traccar) {
169
169
  }
170
170
 
171
171
  const stop = getStop(new Date(trip.startTime), stops)
172
+
172
173
  if (stop && !trip.endTimeIsOut) {
173
174
  trip.stopDuration = (new Date(stop.endTime) - new Date(stop.startTime))
174
- trip.stopEngineHours = stop.engineHours
175
+ trip.stopEngineHours = trip.idleTime + stop.idleTime
175
176
  } else {
176
177
  trip.stopDuration = 0
177
178
  trip.stopEngineHours = 0
@@ -270,6 +271,7 @@ async function exportTripReportToPDF (userData, reportData) {
270
271
  }
271
272
 
272
273
  if (tripsData) {
274
+ // eslint-disable-next-line new-cap
273
275
  const doc = new jsPDF.jsPDF('l')
274
276
  await headerFromUser(doc, translations.report.titleTripReport, userData.user)
275
277
 
package/src/util/odoo.js CHANGED
@@ -1,14 +1,16 @@
1
1
 
2
- async function getOdooFuelServices(traccar, from, to) {
3
- const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
2
+ async function getOdooFuelServices (traccar, from, to) {
3
+ const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
4
4
 
5
- const {data} = await traccar.axios.get(url,{
6
- jar: traccar.cookieJar,
7
- withCredentials: true })
5
+ console.log('LOADING_MESSAGE:' + url)
6
+ const { data } = await traccar.axios.get(url, {
7
+ jar: traccar.cookieJar,
8
+ withCredentials: true
9
+ })
8
10
 
9
- console.log(data)
11
+ console.log(data)
10
12
 
11
- return data
13
+ return data
12
14
  }
13
15
 
14
16
  exports.getOdooFuelServices = getOdooFuelServices
package/src/util/route.js CHANGED
@@ -1,4 +1,5 @@
1
1
  function getIdleEvents (route, driver) {
2
+ const speedThreshold = 3
2
3
  const idleEvents = []
3
4
 
4
5
  const routeByDevice = route.reduce(function (a, x) {
@@ -8,8 +9,9 @@ function getIdleEvents (route, driver) {
8
9
 
9
10
  Object.keys(routeByDevice).forEach(function (key) {
10
11
  let inIdle = false
12
+ let last = null
11
13
  routeByDevice[key].forEach(p => {
12
- if (p.attributes.ignition && p.speed === 0 && (!driver || p.attributes.driverUniqueId === driver.uniqueId)) {
14
+ if (p.attributes.ignition && p.speed < speedThreshold && (!driver || p.attributes.driverUniqueId === driver.uniqueId)) {
13
15
  if (!inIdle) {
14
16
  const idleEvent = {
15
17
  position: p,
@@ -17,20 +19,16 @@ function getIdleEvents (route, driver) {
17
19
  }
18
20
  idleEvents.push(idleEvent)
19
21
  inIdle = true
20
- } else {
21
- if (!idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId) {
22
- idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId = p.attributes.driverUniqueId
23
- }
22
+ }
24
23
 
25
- if (p.attributes.idleTime) {
26
- idleEvents[idleEvents.length - 1].idleTime = p.attributes.idleTime
27
- }
24
+ if (!idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId) {
25
+ idleEvents[idleEvents.length - 1].position.attributes.driverUniqueId = p.attributes.driverUniqueId
28
26
  }
27
+
28
+ last = p
29
29
  } else if (inIdle) {
30
30
  const currentIdleEvent = idleEvents[idleEvents.length - 1]
31
- if (p.attributes.idleTime === undefined) {
32
- currentIdleEvent.idleTime = new Date(p.fixTime) - new Date(currentIdleEvent.position.fixTime)
33
- }
31
+ currentIdleEvent.idleTime = new Date(last.fixTime) - new Date(currentIdleEvent.position.fixTime)
34
32
  inIdle = false
35
33
  }
36
34
  })
@@ -38,5 +36,4 @@ function getIdleEvents (route, driver) {
38
36
 
39
37
  return idleEvents
40
38
  }
41
-
42
39
  exports.getIdleEvents = getIdleEvents