fleetmap-reports 1.0.652 → 1.0.654

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/zone-report.js +48 -41
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.652",
3
+ "version": "1.0.654",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -83,9 +83,10 @@ async function createZoneReport (from, to, userData, traccar) {
83
83
  }
84
84
 
85
85
  function getNextIn (outDate, alerts, geofenceId, deviceRoute) {
86
- return alerts
86
+ const next = alerts
87
87
  .filter(a => a.type === 'geofenceEnter' && a.geofenceId === geofenceId)
88
- .find(a => new Date(a.position.fixTime).getTime() > outDate) ||
88
+ .find(a => new Date(a.position.fixTime).getTime() > outDate)
89
+ return (next && next.position && new Date(next.position.fixTime).getTime()) ||
89
90
  new Date(deviceRoute.slice(-1)[0].fixTime).getTime()
90
91
  }
91
92
 
@@ -101,45 +102,45 @@ async function processDevices (from, to, devices, userData, data) {
101
102
  const zoneInData = {}
102
103
 
103
104
  alerts.forEach(a => {
104
- if (a.position) {
105
- if (a.type === 'geofenceEnter') {
106
- const driver = userData.drivers.find(d => a.position.attributes && d.uniqueId === a.position.attributes.driverUniqueId)
107
- a.position.driverName = driver ? driver.name : ''
108
- zoneInData[a.geofenceId] = a
109
- } else if (a.type === 'geofenceExit') {
110
- const geofence = userData.geofences.find(g => g.id === a.geofenceId)
111
- if (!geofence) { return }
112
- const outDate = new Date(a.position.fixTime).getTime()
113
- const routeAfterOut = deviceRoute.filter(p =>
114
- new Date(p.fixTime).getTime() >= outDate &&
115
- new Date(p.fixTime).getTime() < getNextIn(outDate, alerts, a.geofenceId, deviceRoute)
116
- )
117
- if (zoneInData[a.geofenceId]) {
118
- const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
119
- const inDate = new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
120
- const routeIn = deviceRoute.filter(p =>
121
- new Date(p.fixTime).getTime() >= inDate &&
105
+ if (!a.position) { return }
106
+ if (a.type === 'geofenceEnter') {
107
+ const driver = userData.drivers.find(d => a.position.attributes && d.uniqueId === a.position.attributes.driverUniqueId)
108
+ a.position.driverName = driver ? driver.name : ''
109
+ zoneInData[a.geofenceId] = a
110
+ } else if (a.type === 'geofenceExit') {
111
+ const geofence = userData.geofences.find(g => g.id === a.geofenceId)
112
+ if (!geofence) { return }
113
+ const outDate = new Date(a.position.fixTime).getTime()
114
+ const routeAfterOut = deviceRoute.filter(p =>
115
+ new Date(p.fixTime).getTime() >= outDate &&
116
+ new Date(p.fixTime).getTime() < getNextIn(outDate, alerts, a.geofenceId, deviceRoute)
117
+ )
118
+ const distanceOut = calculateDistance(routeAfterOut)
119
+ if (zoneInData[a.geofenceId]) {
120
+ const totalInTime = moment(a.position.fixTime).diff(moment(zoneInData[a.geofenceId].position.fixTime), 'seconds')
121
+ const inDate = new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
122
+ const routeIn = deviceRoute.filter(p =>
123
+ new Date(p.fixTime).getTime() >= inDate &&
122
124
  new Date(p.fixTime).getTime() < outDate
123
- )
124
- zoneInOutData.push({
125
- inTime: zoneInData[a.geofenceId].position,
126
- outTime: a.position,
127
- totalTime: totalInTime,
128
- distanceIn: calculateDistance(routeIn),
129
- distanceOut: calculateDistance(routeAfterOut),
130
- geofenceName: geofence.name,
131
- stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
132
- driverName: zoneInData[a.geofenceId].position.driverName
133
- })
134
- zoneInData[a.geofenceId] = null
135
- } else {
136
- zoneInOutData.push({
137
- outTime: a.position,
138
- geofenceName: geofence.name,
139
- driverName: '',
140
- distanceOut: calculateDistance(routeAfterOut)
141
- })
142
- }
125
+ )
126
+ zoneInOutData.push({
127
+ inTime: zoneInData[a.geofenceId].position,
128
+ outTime: a.position,
129
+ totalTime: totalInTime,
130
+ distanceIn: calculateDistance(routeIn),
131
+ distanceOut,
132
+ geofenceName: geofence.name,
133
+ stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
134
+ driverName: zoneInData[a.geofenceId].position.driverName
135
+ })
136
+ zoneInData[a.geofenceId] = null
137
+ } else {
138
+ zoneInOutData.push({
139
+ outTime: a.position,
140
+ geofenceName: geofence.name,
141
+ driverName: '',
142
+ distanceOut
143
+ })
143
144
  }
144
145
  }
145
146
  })
@@ -233,6 +234,8 @@ async function exportZoneReportToPDF (userData, reportData) {
233
234
  translations.report.exit,
234
235
  translations.report.stopped,
235
236
  translations.report.duration,
237
+ translations.report.distanceIn || 'Kms Adentro',
238
+ translations.report.distanceOut || 'Kms Afuera',
236
239
  translations.report.geofence,
237
240
  translations.report.driver
238
241
  ]
@@ -265,6 +268,8 @@ async function exportZoneReportToPDF (userData, reportData) {
265
268
  geofenceExit(userData.user, a),
266
269
  a.stopped ? translations.report.yes : translations.report.no,
267
270
  a.totalTime ? convertMS(a.totalTime * 1000, true) : '',
271
+ a.distanceIn,
272
+ a.distanceOut,
268
273
  a.geofenceName,
269
274
  a.driverName
270
275
  ]
@@ -319,15 +324,17 @@ function exportZoneReportToExcel (userData, reportData) {
319
324
  { label: translations.report.exit, value: 'exit' },
320
325
  { label: translations.report.stopped, value: 'stopped' },
321
326
  { label: translations.report.duration, value: 'duration' },
327
+ { label: translations.report.distanceIn || 'Kms Adentro', value: 'distanceIn' },
328
+ { label: translations.report.distanceOut || 'Kms Afuera', value: 'distanceOut' },
322
329
  { label: translations.report.geofence, value: 'zone' },
323
330
  { label: translations.report.driver, value: 'driver' }
324
331
  ]
325
332
  let data = []
326
333
  if (reportData.devices) {
327
334
  reportData.devices.forEach(d => {
328
- data = data.concat([{}])
329
335
  data = data.concat(d.geofences.map(a => {
330
336
  return {
337
+ ...a,
331
338
  name: d.device.name,
332
339
  enter: geofenceEnter(userData.user, a),
333
340
  exit: geofenceExit(userData.user, a),