fleetmap-reports 2.0.343 → 2.0.345

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.343",
3
+ "version": "2.0.345",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -535,7 +535,9 @@ function exportTripReportToExcel (userData, reportData) {
535
535
  }
536
536
 
537
537
  tripsData.forEach(d => {
538
- const group = userData.groups.find(g => g.id === d.device.groupId)
538
+ const group = userData.byDriver
539
+ ? userData.groups.find(g => g.drivers && g.drivers.includes(d.id))
540
+ : userData.groups.find(g => g.id === d.device.groupId)
539
541
  data = data.concat([{}])
540
542
  data = data.concat(d.trips.map(a => {
541
543
  return {
@@ -556,7 +558,7 @@ function exportTripReportToExcel (userData, reportData) {
556
558
  maxTemp: a.maxTemp,
557
559
  minTemp: a.minTemp,
558
560
  avgTemp: a.avgTemp && Number(a.avgTemp.toFixed(1)),
559
- model: d.device.model,
561
+ model: d.device && d.device.model,
560
562
  group: group && group.name
561
563
  }
562
564
  }))
package/src/util/fuel.js CHANGED
@@ -32,6 +32,15 @@ function calculateSpentFuel (value, device, withFuelUsed) {
32
32
  return withFuelUsed ? value : (value * device.attributes.fuel_tank_capacity) / 100
33
33
  }
34
34
 
35
+ const { fuel_low_threshold, fuel_high_threshold, fuel_tank_capacity } = device.attributes
36
+ if (fuel_low_threshold != null && fuel_high_threshold != null && fuel_tank_capacity) {
37
+ const sensorRange = Math.abs(fuel_high_threshold - fuel_low_threshold)
38
+ const rawFuel = fuel_low_threshold > fuel_high_threshold
39
+ ? (value < 0 ? Math.abs(value) : 0)
40
+ : value
41
+ return rawFuel > 0 ? (rawFuel / sensorRange) * fuel_tank_capacity : 0
42
+ }
43
+
35
44
  return value
36
45
  }
37
46