fleetmap-reports 1.0.936 → 1.0.937

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": "1.0.936",
3
+ "version": "1.0.937",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/kms-report.js CHANGED
@@ -178,9 +178,10 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
178
178
  const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
179
179
  const days = await Promise.all(dates.map(async date => {
180
180
  const { tripsByDay } = await getDataByDay(d, date, { trips }, userData, traccarInstance)
181
+ const odometerKms = tripsByDay.length > 0 ? tripsByDay[tripsByDay.length - 1].endOdometer - tripsByDay[0].startOdometer : 0
181
182
  return {
182
183
  date,
183
- kms: tripsByDay.reduce((a, b) => a + b.distance, 0)
184
+ kms: odometerKms > 0 ? odometerKms : tripsByDay.reduce((a, b) => a + b.distance, 0)
184
185
  }
185
186
  }))
186
187
 
@@ -192,12 +193,13 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
192
193
  })
193
194
  }
194
195
  } else {
196
+ const odometerKms = trips.length > 0 ? trips[trips.length - 1].endOdometer - trips[0].startOdometer : 0
195
197
  devicesResult.push({
196
198
  device: d,
197
199
  summary: {
198
200
  startOdometer: trips.length ? trips[0].startOdometer : 0,
199
201
  endOdometer: trips.length ? trips[trips.length - 1].endOdometer : 0,
200
- distance: trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0)
202
+ distance: odometerKms > 0 ? odometerKms : trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0)
201
203
  }
202
204
  })
203
205
  }