fleetmap-reports 2.0.100 → 2.0.102

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": "2.0.100",
3
+ "version": "2.0.102",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -213,5 +213,15 @@ function Reports (config, axios) {
213
213
  this.gpsJumpReportToExcel = (userData, reportData) => {
214
214
  return require('./partnerReports/gpsjump-report').exportGPSJumpReportToExcel(userData, reportData)
215
215
  }
216
+
217
+ this.delayedStartReport = (from, to, userData) => {
218
+ return require('./partnerReports/delayedstart-report').create(from, to, userData, this.traccar)
219
+ }
220
+ this.delayedStartReportToPDF = (userData, reportData) => {
221
+ return require('./partnerReports/delayedstart-report').exportToPDF(userData, reportData)
222
+ }
223
+ this.delayedStartReportToExcel = (userData, reportData) => {
224
+ return require('./partnerReports/delayedstart-report').exportToExcel(userData, reportData)
225
+ }
216
226
  }
217
227
  module.exports = Reports
@@ -1,6 +1,6 @@
1
1
  const automaticReports = require('../automaticReports')
2
2
  const traccarHelper = require('../util/traccar')
3
- const { getDates, getTranslations } = require('../util/utils')
3
+ const { getDates, getTranslations, convertMS } = require('../util/utils')
4
4
  const { getUserPartner } = require('fleetmap-partners')
5
5
  const { getDataByDay } = require('../util/trips')
6
6
 
@@ -26,15 +26,33 @@ async function createDelayedStartReport (from, to, userData, traccar) {
26
26
  deviceCount = deviceCount + slice.length
27
27
  }
28
28
 
29
+ reportData.devices = reportData.devices.flat()
30
+
29
31
  return reportData
30
32
  }
31
33
 
32
34
  function getDelayDescription (startTime, activityStart, lowDelay, mediumDelay, highDelay) {
33
- return 'Low'
35
+ const startTimeDate = new Date(startTime)
36
+ const activityStartDate = new Date(startTime)
37
+ activityStartDate.setHours(activityStart.substring(0, 2), activityStart.substring(3, 5))
38
+
39
+ if (startTimeDate >= activityStartDate) {
40
+ const delay = startTimeDate.getTime() - activityStartDate.getTime()
41
+ if (delay < (lowDelay * 60 * 1000)) {
42
+ return '-'
43
+ } else if (delay < (mediumDelay * 60 * 1000)) {
44
+ return convertMS(delay, false) + ' - Low (+' + lowDelay + ')'
45
+ } else if (delay < (highDelay * 60 * 1000)) {
46
+ return convertMS(delay, false) + ' - Medium (+' + mediumDelay + ')'
47
+ } else {
48
+ return convertMS(delay, false) + ' - High (+' + highDelay + ')'
49
+ }
50
+ }
51
+
52
+ return ''
34
53
  }
35
54
 
36
55
  async function processDeviceData (from, to, allInOne, d, userData, traccar) {
37
- const group = userData.groups.find(g => g.id === d.groupId)
38
56
  const trips = allInOne.trips.filter(t => t.deviceId === d.id)
39
57
  const translations = getTranslations(userData)
40
58
 
@@ -56,27 +74,24 @@ async function processDeviceData (from, to, allInOne, d, userData, traccar) {
56
74
 
57
75
  if (tripsByDay.length > 0) {
58
76
  const startTime = tripsByDay[0].startTime
59
- const endTime = tripsByDay[tripsByDay.length].endTime
77
+ const endTime = tripsByDay[tripsByDay.length - 1].endTime
60
78
 
61
79
  const deviceDayData = {
62
80
  device: d.name,
81
+ groupId: d.groupId,
63
82
  licensePlate: d.attributes.license_plate,
64
- group: group ? group.name : '',
65
83
  driver: '',
66
84
  weekDay: weekDays[new Date(date).getDay()],
67
- startTime: startTime,
85
+ startTime,
68
86
  delayDescription: getDelayDescription(startTime, userData.activityStart, userData.lowDelay, userData.mediumDelay, userData.highDelay),
69
- endTime: endTime
87
+ endTime
70
88
  }
71
89
 
72
90
  days.push(deviceDayData)
73
91
  }
74
92
  }
75
93
 
76
- return {
77
- device: d,
78
- days
79
- }
94
+ return days
80
95
  }
81
96
 
82
97
  async function exportDelayedStartReportToPDF (userData, reportData) {
@@ -19,7 +19,7 @@ exports.insideGeofence = function insideGeofence (position, geofence) {
19
19
  exports.getNearestPOI = (position, geofences) => getNearestPOIs(position.longitude, position.latitude, geofences)[0]
20
20
  function getNearestPOIs (long, lat, geofences) {
21
21
  const distance = geofences
22
- .filter(g => g && g.area.startsWith('CIRCLE'))
22
+ .filter(g => g && g.area && g.area.startsWith('CIRCLE'))
23
23
  .map(g => {
24
24
  const str = g.area.substring('CIRCLE ('.length, g.area.indexOf(','))
25
25
  const radius = g.area.substring(g.area.indexOf(',') + 1, g.area.indexOf(')'))
package/src/util/utils.js CHANGED
@@ -19,7 +19,7 @@ exports.getLanguage = (userData) => {
19
19
  return userData.user.attributes.lang ||
20
20
  ((typeof navigator !== 'undefined') && navigator.language) ||
21
21
  getUserPartner(userData.user).lang ||
22
- 'en-GB'
22
+ 'pt-BR'
23
23
  }
24
24
 
25
25
  function convertMS (duration, withSeconds) {