fleetmap-reports 2.0.118 → 2.0.120

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.118",
3
+ "version": "2.0.120",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -256,7 +256,6 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
256
256
  if (summary.length) {
257
257
  summary.forEach(s => {
258
258
  s.engineHours = deviceTrips.reduce((a, b) => a + b.duration, 0)
259
- s.distance = getKms(deviceTrips)
260
259
  s.convertedSpentFuel = calculateConsumption(d, { route: deviceRoute, summary: s })
261
260
  s.startTime = deviceTrips.length && deviceTrips[0].startTime
262
261
  s.startAddress = deviceTrips.length && deviceTrips[0].startAddress
package/src/kms-report.js CHANGED
@@ -79,17 +79,19 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
79
79
  const sliced = automaticReports.sliceArray(allDevices,
80
80
  20)
81
81
  for (const devices of sliced) {
82
- const needRoute = !userData.allWeek
82
+ const needRoute = userData.groupByDay || !userData.allWeek
83
83
  const {
84
84
  trips,
85
- route
86
- } = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, false, deviceCount, allDevices.length, 10, 2)
85
+ route,
86
+ summary
87
+ } = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, !userData.groupByDay, deviceCount, allDevices.length, 10, 2)
87
88
 
88
89
  // Process report data
89
90
  if (trips.length) {
90
91
  allData.devices = allData.devices.concat(await processDevices(from, to, devices, {
91
92
  trips,
92
- route
93
+ route,
94
+ summary
93
95
  }, userData, traccarInstance))
94
96
  }
95
97
  deviceCount += devices.length
@@ -228,7 +230,6 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
228
230
 
229
231
  if (userData.groupByDay) {
230
232
  if (trips.length > 0) {
231
- const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
232
233
  const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
233
234
  const days = await Promise.all(dates.map(async date => {
234
235
  const { tripsByDay } = await getDataByDay(d, date, { trips }, userData, traccarInstance)
@@ -246,13 +247,10 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
246
247
  })
247
248
  }
248
249
  } else {
250
+ const summary = data.summary.find(s => s.deviceId === d.id)
249
251
  devicesResult.push({
250
252
  device: d,
251
- summary: {
252
- startOdometer: trips.length ? trips[0].startOdometer : 0,
253
- endOdometer: trips.length ? trips[trips.length - 1].endOdometer : 0,
254
- distance: getKms(trips)
255
- }
253
+ summary
256
254
  })
257
255
  }
258
256
  }