fleetmap-reports 1.0.904 → 1.0.907

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
@@ -277,7 +277,8 @@ module.exports = {
277
277
  timeOut: 'Time Out',
278
278
  maxTemp: 'Max Temp',
279
279
  minTemp: 'Min Temp',
280
- avgTemp: 'Avg Temp'
280
+ avgTemp: 'Avg Temp',
281
+ total: 'Total'
281
282
  },
282
283
  layout: {
283
284
  deviceOnline: 'Device Online',
package/lang/esCL.js CHANGED
@@ -266,7 +266,8 @@ module.exports = {
266
266
  timeOut: 'Tempo Afuera',
267
267
  maxTemp: 'Temp.Max',
268
268
  minTemp: 'Temp.Min',
269
- avgTemp: 'Temp.Média'
269
+ avgTemp: 'Temp.Média',
270
+ total: 'Total'
270
271
  },
271
272
  layout: {
272
273
  deviceOnline: 'Dispositivo en línea',
package/lang/frFR.json CHANGED
@@ -275,7 +275,8 @@
275
275
  "zone": "Zone",
276
276
  "maxTemp": "Temp.Max",
277
277
  "minTemp": "Temp.Min",
278
- "avgTemp": "Temp.Moyenne"
278
+ "avgTemp": "Temp.Moyenne",
279
+ "total": "Total"
279
280
  },
280
281
  "layout": {
281
282
  "deviceOnline": "Appareil en ligne",
package/lang/ptBR.js CHANGED
@@ -271,7 +271,8 @@ module.exports = {
271
271
  timeOut: 'Tempo Fora',
272
272
  maxTemp: 'Temp.Máx',
273
273
  minTemp: 'Temp.Min',
274
- avgTemp: 'Temp.Média'
274
+ avgTemp: 'Temp.Média',
275
+ total: 'Total'
275
276
  },
276
277
  layout: {
277
278
  deviceOnline: 'Dispositivo Online',
package/lang/ptPT.js CHANGED
@@ -280,7 +280,8 @@ module.exports = {
280
280
  timeOut: 'Tempo Fora',
281
281
  maxTemp: 'Temp.Máx',
282
282
  minTemp: 'Temp.Min',
283
- avgTemp: 'Temp.Média'
283
+ avgTemp: 'Temp.Média',
284
+ total: 'Total'
284
285
  },
285
286
  layout: {
286
287
  test: 'Test Notification',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.904",
3
+ "version": "1.0.907",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  const automaticReports = require('./automaticReports')
2
2
  const {
3
3
  convertMS, getDates, getTranslations, weekDaySelected, convertToLocaleString, isClientSide,
4
- getLanguage
4
+ getLanguage, convertFromUTC, convertFromLocal
5
5
  } = require('./util/utils')
6
6
  const jsPDF = require('jspdf')
7
7
  require('jspdf-autotable')
@@ -12,7 +12,7 @@ const {
12
12
  const { getStyle } = require('./reportStyle')
13
13
  const { getUserPartner } = require('fleetmap-partners')
14
14
  const traccar = require('./util/traccar')
15
- const { isInsideTimetable, isPartialInsideTimetable, calculateTrip } = require('./util/trips')
15
+ const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, calculatePartialTrip } = require('./util/trips')
16
16
  const { devicesToProcess } = require('./util/device')
17
17
  const { getDriverData } = require('./util/driver')
18
18
  const { calculateConsumption } = require('./util/fuel')
@@ -157,6 +157,14 @@ async function createActivityReportByDriver (from, to, userData, traccarInstance
157
157
  return allData
158
158
  }
159
159
 
160
+ function checkTripsPartialInsideDate (date, userData, tripsByDay, deviceRoute) {
161
+ const startDateLocal = new Date(convertFromUTC(date, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
162
+ const endDateLocal = new Date(convertFromUTC(date, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
163
+ const startDate = isClientSide() ? startDateLocal : convertFromLocal(startDateLocal, userData.user.attributes.timezone)
164
+ const endDate = isClientSide() ? endDateLocal : convertFromLocal(endDateLocal, userData.user.attributes.timezone)
165
+ tripsByDay.forEach(t => calculatePartialTrip(startDate, endDate, deviceRoute, t))
166
+ }
167
+
160
168
  function processDevices (from, to, devices, data, userData) {
161
169
  const devicesResult = []
162
170
 
@@ -180,8 +188,10 @@ function processDevices (from, to, devices, data, userData) {
180
188
  for (const date of dates) {
181
189
  const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
182
190
  const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
191
+ const tripsByDay = trips.filter(t => new Date(t.endTime) > fromByDay && new Date(t.startTime) < toByDay).map(t => { return { ...t } })
192
+
193
+ checkTripsPartialInsideDate(date, userData, tripsByDay, deviceRoute)
183
194
 
184
- const tripsByDay = trips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.startTime) < toByDay))
185
195
  const routeByDay = deviceRoute.filter(p => (new Date(p.fixTime) > fromByDay && new Date(p.fixTime) < toByDay))
186
196
  const distance = tripsByDay.reduce((a, b) => a + b.distance, 0)
187
197
 
@@ -201,7 +211,9 @@ function processDevices (from, to, devices, data, userData) {
201
211
  startTime: tripsByDay.length && tripsByDay[0].startTime,
202
212
  startAddress: tripsByDay.length && tripsByDay[0].startAddress,
203
213
  endTime: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime,
204
- endAddress: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
214
+ endAddress: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress,
215
+ startTimeIsOut: tripsByDay.some(t => t.startTimeIsOut),
216
+ endTimeIsOut: tripsByDay.some(t => t.endTimeIsOut)
205
217
  })
206
218
  }
207
219
  } else {
@@ -217,6 +229,8 @@ function processDevices (from, to, devices, data, userData) {
217
229
  summaryCurrentDay.endAddress = tripsByDay.length && tripsByDay[tripsByDay.length - 1].endAddress
218
230
  summaryCurrentDay.startOdometer = tripsByDay.length ? tripsByDay[0].startOdometer : 0
219
231
  summaryCurrentDay.endOdometer = tripsByDay.length ? tripsByDay[tripsByDay.length - 1].endOdometer : 0
232
+ summaryCurrentDay.startTimeIsOut = tripsByDay.some(t => t.startTimeIsOut)
233
+ summaryCurrentDay.endTimeIsOut = tripsByDay.some(t => t.endTimeIsOut)
220
234
  summary.push(summaryCurrentDay)
221
235
  }
222
236
  }
package/src/kms-report.js CHANGED
@@ -332,31 +332,26 @@ function exportKmsReportToExcel (userData, reportData) {
332
332
 
333
333
  const translations = getTranslations(userData)
334
334
 
335
- const weekDays = [
336
- translations.report.sunday,
337
- translations.report.monday,
338
- translations.report.tuesday,
339
- translations.report.wednesday,
340
- translations.report.thursday,
341
- translations.report.friday,
342
- translations.report.saturday
343
- ]
344
-
345
335
  const settings = {
346
336
  sheetName: translations.report.titleKmsReport, // The name of the sheet
347
337
  fileName // The name of the spreadsheet
348
338
  }
349
339
 
350
340
  const headers = []
341
+ const info = userData.byDriver ? reportData.drivers : reportData.devices
351
342
 
352
343
  if (userData.groupByDay) {
353
344
  headers.push(
354
345
  { label: translations.report.vehicle, value: 'name' },
355
346
  { label: translations.settings.vehicle_licenseplate, value: 'licenseplate' },
356
- { label: translations.report.group, value: 'group' },
357
- { label: translations.report.date, value: 'date' },
358
- { label: translations.report.weekDay, value: 'weekday' },
359
- { label: translations.report.distance, value: 'distance' })
347
+ { label: translations.report.group, value: 'group' })
348
+
349
+ const days = info[0].days
350
+ days.forEach((day, index) => {
351
+ headers.push({ label: new Date(day.date).toLocaleDateString(), value: 'day' + index })
352
+ })
353
+
354
+ headers.push({ label: translations.report.total, value: 'total' })
360
355
  } else if (userData.byDriver) {
361
356
  headers.push(
362
357
  { label: translations.report.driver, value: 'name' },
@@ -371,7 +366,7 @@ function exportKmsReportToExcel (userData, reportData) {
371
366
  }
372
367
 
373
368
  let data = []
374
- const info = userData.byDriver ? reportData.drivers : reportData.devices
369
+
375
370
  info.forEach(d => {
376
371
  const group = userData.byDriver
377
372
  ? userData.groups.find(g => g.drivers && g.drivers.includes(d.driver.id))
@@ -379,17 +374,19 @@ function exportKmsReportToExcel (userData, reportData) {
379
374
 
380
375
  if (userData.groupByDay) {
381
376
  if (d.days) {
382
- data = data.concat([{}])
383
- data = data.concat(d.days.map(a => {
384
- return {
385
- name: d.device.name,
386
- group: group ? group.name : '',
387
- licenseplate: d.device.attributes.license_plate,
388
- date: a.date,
389
- weekday: weekDays[a.date.getDay()],
390
- distance: Number((a.kms / 1000).toFixed(0))
391
- }
392
- }))
377
+ const vehicle = {
378
+ name: d.device.name,
379
+ group: group ? group.name : '',
380
+ licenseplate: d.device.attributes.license_plate
381
+ }
382
+
383
+ d.days.forEach((day, index) => {
384
+ vehicle['day' + index] = Number((day.kms / 1000).toFixed(0))
385
+ })
386
+
387
+ vehicle.total = Number(d.days.reduce((a, b) => a + (b.kms / 1000), 0).toFixed(0))
388
+
389
+ data = data.concat([vehicle])
393
390
  }
394
391
  } else {
395
392
  data = data.concat([{
@@ -402,7 +399,7 @@ function exportKmsReportToExcel (userData, reportData) {
402
399
  })
403
400
 
404
401
  // add total
405
- if (data.length) {
402
+ if (data.length && !userData.groupByDay) {
406
403
  data = data.concat({
407
404
  name: '',
408
405
  group: '',
package/src/util/trips.js CHANGED
@@ -5,7 +5,6 @@ const minDistance = 0
5
5
  const minAvgSpeed = 0
6
6
 
7
7
  function checkTripsKms (traccarInstance, from, to, devices, data) {
8
- console.log('checkTripsKms')
9
8
  const trips = data.trips.filter(t => t.distance === minDistance && t.averageSpeed > minAvgSpeed)
10
9
  if (trips.length > 0) {
11
10
  // Vehicles with imported positions. calculate trip distance with route positions
@@ -31,64 +30,67 @@ function checkTripsKms (traccarInstance, from, to, devices, data) {
31
30
  }
32
31
  }
33
32
 
34
- function isPartialInsideTimetable (t, userData, route) {
33
+ function calculatePartialTrip (startDate, endDate, route, t) {
34
+ let isPartialInside = false
35
35
  const tripStart = new Date(t.startTime)
36
36
  const tripEnd = new Date(t.endTime)
37
37
 
38
- let isPartialInside = false
38
+ if (startDate.getTime() > endDate.getTime()) {
39
+ if (tripStart.getTime() < endDate.getTime() &&
40
+ tripEnd.getTime() > endDate.getTime()) {
41
+ // Trip starts inside time period and ends outside time period
42
+ const routeInside = route.filter(p => new Date(p.fixTime).getTime() < new Date(endDate.toUTCString()).getTime() && new Date(p.fixTime).getTime() > new Date(t.startTime).getTime() && t.deviceId === p.deviceId)
43
+ updateTrip(t, routeInside)
44
+ t.endTime = endDate.toISOString().replace('Z', '+0000')
45
+ t.endTimeIsOut = true
46
+ isPartialInside = true
47
+ }
48
+
49
+ if (tripStart.getTime() < startDate.getTime() &&
50
+ new Date(t.endTime).getTime() > startDate.getTime()) {
51
+ // Trip starts outside time period and ends inside time period
52
+ const routeInside = route.filter(p => new Date(p.fixTime).getTime() > startDate.getTime() && new Date(p.fixTime).getTime() < new Date(t.endTime).getTime() && t.deviceId === p.deviceId)
53
+ updateTrip(t, routeInside)
54
+ t.startTime = startDate.toISOString().replace('Z', '+0000')
55
+ t.startTimeIsOut = true
56
+ isPartialInside = true
57
+ }
58
+ } else {
59
+ if (tripStart.getTime() < startDate.getTime() &&
60
+ tripEnd.getTime() > startDate.getTime()) {
61
+ // Trip starts outside time period and ends inside time period
62
+ const routeInside = route.filter(p => new Date(p.fixTime).getTime() > new Date(startDate.toUTCString()).getTime() && new Date(p.fixTime).getTime() < new Date(t.endTime).getTime() && t.deviceId === p.deviceId)
63
+ updateTrip(t, routeInside)
64
+ t.startTime = startDate.toISOString().replace('Z', '+0000')
65
+ t.startTimeIsOut = true
66
+ isPartialInside = true
67
+ }
68
+
69
+ if (tripStart.getTime() < endDate.getTime() &&
70
+ tripEnd.getTime() > endDate.getTime()) {
71
+ // Trip starts inside time period and ends outside time period
72
+ const routeInside = route.filter(p => new Date(p.fixTime).getTime() < endDate.getTime() && new Date(p.fixTime).getTime() > new Date(t.startTime).getTime() && t.deviceId === p.deviceId)
73
+ updateTrip(t, routeInside)
74
+ t.endTime = endDate.toISOString().replace('Z', '+0000')
75
+ t.endTimeIsOut = true
76
+ isPartialInside = true
77
+ }
78
+ }
79
+ return isPartialInside
80
+ }
39
81
 
40
- if (weekDaySelected(tripStart, userData.weekDays)) {
82
+ function isPartialInsideTimetable (t, userData, route) {
83
+ if (weekDaySelected(new Date(t.startTime), userData.weekDays)) {
41
84
  const startDateLocal = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
42
85
  const endDateLocal = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
43
86
 
44
87
  const startDate = isClientSide() ? startDateLocal : convertFromLocal(startDateLocal, userData.user.attributes.timezone)
45
88
  const endDate = isClientSide() ? endDateLocal : convertFromLocal(endDateLocal, userData.user.attributes.timezone)
46
89
 
47
- if (startDate.getTime() > endDate.getTime()) {
48
- // Trip starts outside time period and ends inside time period
49
- if (tripStart.getTime() < endDate.getTime() &&
50
- tripEnd.getTime() > endDate.getTime()) {
51
- // Trip starts inside time period and ends outside time period
52
- const routeInside = route.filter(p => new Date(p.fixTime).getTime() < new Date(endDate.toUTCString()).getTime() && new Date(p.fixTime).getTime() > new Date(t.startTime).getTime() && t.deviceId === p.deviceId)
53
- updateTrip(t, routeInside)
54
- t.endTime = endDate.toISOString().replace('Z', '+0000')
55
- t.endTimeIsOut = true
56
- isPartialInside = true
57
- }
58
-
59
- if (tripStart.getTime() < startDate.getTime() &&
60
- new Date(t.endTime).getTime() > startDate.getTime()) {
61
- // Trip starts outside time period and ends inside time period
62
- const routeInside = route.filter(p => new Date(p.fixTime).getTime() > startDate.getTime() && new Date(p.fixTime).getTime() < new Date(t.endTime).getTime() && t.deviceId === p.deviceId)
63
- updateTrip(t, routeInside)
64
- t.startTime = startDate.toISOString().replace('Z', '+0000')
65
- t.startTimeIsOut = true
66
- isPartialInside = true
67
- }
68
- } else {
69
- if (tripStart.getTime() < startDate.getTime() &&
70
- tripEnd.getTime() > startDate.getTime()) {
71
- // Trip starts outside time period and ends inside time period
72
- const routeInside = route.filter(p => new Date(p.fixTime).getTime() > new Date(startDate.toUTCString()).getTime() && new Date(p.fixTime).getTime() < new Date(t.endTime).getTime() && t.deviceId === p.deviceId)
73
- updateTrip(t, routeInside)
74
- t.startTime = startDate.toISOString().replace('Z', '+0000')
75
- t.startTimeIsOut = true
76
- isPartialInside = true
77
- }
78
-
79
- if (tripStart.getTime() < endDate.getTime() &&
80
- tripEnd.getTime() > endDate.getTime()) {
81
- // Trip starts inside time period and ends outside time period
82
- const routeInside = route.filter(p => new Date(p.fixTime).getTime() < endDate.getTime() && new Date(p.fixTime).getTime() > new Date(t.startTime).getTime() && t.deviceId === p.deviceId)
83
- updateTrip(t, routeInside)
84
- t.endTime = endDate.toISOString().replace('Z', '+0000')
85
- t.endTimeIsOut = true
86
- isPartialInside = true
87
- }
88
- }
90
+ return calculatePartialTrip(startDate, endDate, route, t)
89
91
  }
90
92
 
91
- return isPartialInside
93
+ return false
92
94
  }
93
95
 
94
96
  function isInsideTimetable (t, userData) {
@@ -97,7 +99,8 @@ function isInsideTimetable (t, userData) {
97
99
 
98
100
  function updateTrip (t, route) {
99
101
  if (!route[route.length - 1]) { return }
100
- const distance = route[route.length - 1].attributes.totalDistance - route[0].attributes.totalDistance
102
+ route = route.filter(p => p.attributes.ignition)
103
+ const distance = calculateDistance(route, false) * 1000
101
104
  t.distance = distance
102
105
  t.duration = new Date(route[route.length - 1].fixTime).getTime() - new Date(route[0].fixTime).getTime()
103
106
  t.maxSpeed = route.reduce((a, b) => Math.max(a, b.speed), 0)
@@ -159,6 +162,7 @@ function calculateStopDuration (stop) {
159
162
  exports.checkTripsKms = checkTripsKms
160
163
  exports.isInsideTimetable = isInsideTimetable
161
164
  exports.isPartialInsideTimetable = isPartialInsideTimetable
165
+ exports.calculatePartialTrip = calculatePartialTrip
162
166
  exports.calculateTrip = calculateTrip
163
167
  exports.getTripIdleTime = getTripIdleTime
164
168
  exports.calculateStopDuration = calculateStopDuration
package/src/util/utils.js CHANGED
@@ -215,13 +215,13 @@ exports.convertFromLocal = (value, timezone) => {
215
215
  }
216
216
 
217
217
  function weekDaySelected (date, weekDays) {
218
- return (date.getDay() === 0 && weekDays.sunday) ||
218
+ return !weekDays || ((date.getDay() === 0 && weekDays.sunday) ||
219
219
  (date.getDay() === 1 && weekDays.monday) ||
220
220
  (date.getDay() === 2 && weekDays.tuesday) ||
221
221
  (date.getDay() === 3 && weekDays.wednesday) ||
222
222
  (date.getDay() === 4 && weekDays.thursday) ||
223
223
  (date.getDay() === 5 && weekDays.friday) ||
224
- (date.getDay() === 6 && weekDays.saturday)
224
+ (date.getDay() === 6 && weekDays.saturday))
225
225
  }
226
226
 
227
227
  exports.getImgFromUrl = getImgFromUrl