fleetmap-reports 2.0.35 → 2.0.37

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.35",
3
+ "version": "2.0.37",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -136,7 +136,7 @@ function exportFuelConsumptionReportToExcel (userData, reportData) {
136
136
  data = data.concat(d.days.map((r) => {
137
137
  return {
138
138
  name: d.device.name,
139
- date: r.date,
139
+ date: r.date.toLocaleDateString(),
140
140
  kms: formatNumber(r.distance / 1000, lang),
141
141
  consumption: r.spentFuel > 0 ? formatNumber(r.spentFuel, lang) : 0,
142
142
  avg_consumption: formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms, lang),
@@ -203,7 +203,7 @@ async function exportFuelConsumptionReportToPDF (userData, reportData) {
203
203
 
204
204
  d.days.forEach(r =>
205
205
  data.push([
206
- r.date,
206
+ r.date.toLocaleDateString(),
207
207
  formatNumber(r.distance / 1000, lang),
208
208
  r.spentFuel > 0 ? formatNumber(r.spentFuel, lang) : 0,
209
209
  formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms, lang),
@@ -6,20 +6,13 @@ const { isInsideTimetable, isPartialInsideTimetable } = require('./trips')
6
6
  // get devices used by each driver between two dates
7
7
  async function devicesByDriver (traccarInstance, from, to, drivers, devices) {
8
8
  const eventsData = await traccar.getEvents(traccarInstance, from, to, devices, ['driverChanged'])
9
- const deviceIds = []
10
- const driversIds = []
11
- for (const d of drivers) {
12
- const events = eventsData.filter(e => {
13
- return !d.uniqueId.localeCompare(e.attributes.driverUniqueId, undefined, { sensitivity: 'base' })
14
- })
15
-
16
- if (events.length) {
17
- driversIds.push(d.id)
18
- }
9
+ const driverUniqueIdsToProcess = new Set(eventsData.map(e => e.attributes.driverUniqueId))
10
+ const driversToProcess = drivers.filter(d => driverUniqueIdsToProcess.has(d.uniqueId))
19
11
 
20
- deviceIds.push(...events.map(e => e.deviceId))
21
- }
22
- return { devices: devices.filter(d => deviceIds.includes(d.id)), drivers: drivers.filter(d => driversIds.includes(d.id)) }
12
+ const deviceIdsToProcess = new Set(eventsData.map(e => e.deviceId))
13
+ const devicesToProcess = devices.filter(d => deviceIdsToProcess.has(d.id))
14
+
15
+ return { devices: devicesToProcess, drivers: driversToProcess }
23
16
  }
24
17
 
25
18
  async function reportByDriver (devices, traccar, from, to, userData, processor, allInOneData = { route: true, trips: true, stops: true, summary: false }) {