fleetmap-reports 2.0.122 → 2.0.123

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.122",
3
+ "version": "2.0.123",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -24,7 +24,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
24
24
 
25
25
  const devices = devicesToProcess(userData)
26
26
 
27
- const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, true, false, false)
27
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, true, true, false)
28
28
  const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
29
29
  const summary = await getSummaryByDay(dates, userData, traccar, devices, true, from, to)
30
30
 
@@ -40,6 +40,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
40
40
  allData.totalDevices = 0
41
41
 
42
42
  for (const d of devices) {
43
+ const stops = allInOne.stops.filter(t => t.deviceId === d.id)
43
44
  const trips = allInOne.trips.filter(t => t.deviceId === d.id)
44
45
  const route = allInOne.route.filter(r => r.deviceId === d.id)
45
46
  const deviceFuelServices = fuelServicesData.filter(f => Number.parseInt(d.attributes.odooId) === f.vehicle_id[0])
@@ -48,12 +49,12 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
48
49
  const refuelingPositions = await refuelingReport.calculateRefuelingPositions(userData, d, { route, trips, fuelServices: deviceFuelServices })
49
50
  const days = []
50
51
  for (const date of dates) {
51
- const { tripsByDay, routeByDay, refuelingPositionsByDay } = await getDataByDay(d, date, { trips, route, refuelingPositions }, userData, traccar)
52
+ const { tripsByDay, stopsByDay, routeByDay, refuelingPositionsByDay } = await getDataByDay(d, date, { trips, stops, route, refuelingPositions }, userData, traccar)
52
53
  const summaryByDay = summary.find(a => a.date === date).summary
53
54
  const summaryByDevice = summaryByDay.find(a => a.deviceId === d.id)
54
55
 
55
56
  const distance = summaryByDevice.distance
56
- const spentFuel = calculateConsumption(d, { trips: tripsByDay, stops: [], route: routeByDay, summary: summaryByDevice })
57
+ const spentFuel = calculateConsumption(d, { trips: tripsByDay, stops: stopsByDay, route: routeByDay, summary: summaryByDevice })
57
58
 
58
59
  const dataRow = {
59
60
  date,
package/src/util/trips.js CHANGED
@@ -97,6 +97,12 @@ async function getDataByDay (device, date, data, userData, traccarInstance) {
97
97
  }
98
98
  }
99
99
 
100
+ const stopsByDay = []
101
+ if (data.stops) {
102
+ const filteredStops = data.stops.filter(t => new Date(t.endTime) > startDate && new Date(t.startTime) < endDate)
103
+ stopsByDay.push(...filteredStops.map(t => { return { ...t } }))
104
+ }
105
+
100
106
  const routeByDay = data.route ? data.route.filter(p => (new Date(p.fixTime) > startDate && new Date(p.fixTime) < endDate)) : []
101
107
 
102
108
  const refuelingPositionsByDay = data.refuelingPositions ? data.refuelingPositions.filter(p => (new Date(p.date) > startDate && new Date(p.date) < endDate)) : []
@@ -106,7 +112,7 @@ async function getDataByDay (device, date, data, userData, traccarInstance) {
106
112
  (!z.outTime || (new Date(z.outTime.fixTime) > startDate)))
107
113
  : []
108
114
 
109
- return { tripsByDay, routeByDay, refuelingPositionsByDay, zoneInOutDayData }
115
+ return { tripsByDay, stopsByDay, routeByDay, refuelingPositionsByDay, zoneInOutDayData }
110
116
  }
111
117
 
112
118
  function isValidAvgSpeed (kms, startTime, endTime) {