fleetmap-reports 1.0.685 → 1.0.687

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.685",
3
+ "version": "1.0.687",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -143,7 +143,7 @@ function exportFuelConsumptionReportToExcel (userData, reportData) {
143
143
  { label: translations.report.date, value: 'date' },
144
144
  { label: translations.report.distance, value: 'kms' },
145
145
  { label: translations.report.consumption, value: 'consumption' },
146
- { label: translations.report.avg_consumption, value: 'avg_consumption' },
146
+ { label: (lang === 'pt-BR' ? translations.report.avg_consumption_by_liters : translations.report.avg_consumption), value: 'avg_consumption' },
147
147
  { label: translations.report.duration, value: 'duration' },
148
148
  { label: translations.report.odometer, value: 'accumulated_kms' },
149
149
  { label: translations.report.refueling, value: 'refueling' }
@@ -159,7 +159,7 @@ function exportFuelConsumptionReportToExcel (userData, reportData) {
159
159
  consumption: r.spentFuel > 0 ? formatNumber(r.spentFuel, lang) : 0,
160
160
  avg_consumption: formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms, lang),
161
161
  duration: convertMS(r.duration),
162
- accumulated_kms: (r.endOdometer / 100).toFixed(1),
162
+ accumulated_kms: formatNumber((r.endOdometer / 100), lang),
163
163
  refueling: formatNumber(r.refueling, lang)
164
164
  }
165
165
  }))
@@ -196,7 +196,7 @@ async function exportFuelConsumptionReportToPDF (userData, reportData) {
196
196
  translations.report.date,
197
197
  translations.report.distance,
198
198
  translations.report.consumption,
199
- translations.report.avg_consumption,
199
+ (lang === 'pt-BR' ? translations.report.avg_consumption_by_liters : translations.report.avg_consumption),
200
200
  translations.report.duration,
201
201
  translations.report.odometer,
202
202
  translations.report.refueling
@@ -226,8 +226,8 @@ async function exportFuelConsumptionReportToPDF (userData, reportData) {
226
226
  r.spentFuel > 0 ? formatNumber(r.spentFuel, lang) : 0,
227
227
  formatNumber(lang === 'pt-BR' ? r.avgConsumption.byLiters : r.avgConsumption.byKms, lang),
228
228
  convertMS(r.duration),
229
- (r.endOdometer / 1000).toFixed(1),
230
- r.refueling
229
+ formatNumber((r.endOdometer / 1000), lang),
230
+ formatNumber(r.refueling, lang)
231
231
  ]))
232
232
 
233
233
  const footValues = [
@@ -285,7 +285,7 @@ function getTotalRefueling (user, data) {
285
285
  }
286
286
 
287
287
  function getTotalAvgConsumption (user, data) {
288
- const values = data.map(a => a.distance * a.avgConsumption.byKms).reduce((a, b) => a + b, 0)
288
+ const values = data.map(a => a.distance * (user.attributes.lang === 'pt-BR' ? a.avgConsumption.byLiters : a.avgConsumption.byKms)).reduce((a, b) => a + b, 0)
289
289
  const totalKms = data.reduce((a, b) => a + b.distance, 0)
290
290
 
291
291
  const totalAvgConsumption = values / totalKms
@@ -1,6 +1,7 @@
1
1
  const automaticReports = require('./automaticReports')
2
2
  const { devicesToProcess } = require('./util/device')
3
3
  const { getTranslations } = require('./util/utils')
4
+ const traccarHelper = require('./util/traccar')
4
5
 
5
6
  function calculateFuelDrop (position, positions) {
6
7
  const index = positions.indexOf(position)
@@ -21,48 +22,43 @@ function calculateFuelDrop (position, positions) {
21
22
  async function createFuelDropReport (from, to, userData, traccar) {
22
23
  console.log('Create FuelDropReport')
23
24
 
24
- const reportData = []
25
-
26
25
  const allData = {
27
26
  devices: [],
28
27
  from,
29
28
  to
30
29
  }
31
30
 
31
+ const reportData = []
32
+ reportData.push(allData)
33
+
32
34
  const devices = devicesToProcess(userData)
33
35
 
34
- const arrayOfArrays = automaticReports.sliceArray(devices)
36
+ const arrayOfArrays = automaticReports.sliceArray(devices, 50)
35
37
  let data = []
36
- const types = ['deviceFuelDrop']
37
38
 
39
+ const types = ['deviceFuelDrop']
38
40
  for (const a of arrayOfArrays) {
39
41
  const response = await traccar.reports.reportsEventsGet(from, to, a.map(d => d.id), null, types)
40
42
  data = data.concat(response.data)
41
43
  }
42
-
43
44
  console.log('FuelDrop Alerts:' + data.length)
44
-
45
- if (data.length === 0) {
46
- return reportData
47
- }
48
45
  allData.totalDevices = 0
49
46
  allData.totalFuelDrops = 0
50
47
  allData.totalFuelDropLiters = 0
51
48
 
52
49
  for (const d of devices) {
53
50
  const alerts = data.filter(t => t.deviceId === d.id)
54
-
55
51
  if (alerts.length > 0) {
56
- const response = await traccar.reports.reportsRouteGet(from, to, [d.id])
57
- const positions = response.data
52
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, [d], true, false, false, false, 1, devices.length)
53
+ const route = allInOne.route.filter(t => t.deviceId === d.id)
58
54
 
59
55
  for (const a of alerts) {
60
56
  a.fuelDropLiters = 0
61
57
  if (a.positionId > 0) {
62
- const position = positions.find(p => p.id === a.positionId)
58
+ const position = route.find(p => p.id === a.positionId)
63
59
  if (position) {
64
60
  a.position = position
65
- const diff = calculateFuelDrop(position, positions)
61
+ const diff = calculateFuelDrop(position, route)
66
62
  a.fuelDropLiters = Math.round(diff * d.attributes.fuel_tank_capacity / 100)
67
63
  }
68
64
  }
@@ -76,16 +72,10 @@ async function createFuelDropReport (from, to, userData, traccar) {
76
72
  device: d,
77
73
  alerts: filteredAlerts
78
74
  })
79
-
80
- allData.totalDevices = allData.totalDevices + 1
81
- allData.totalFuelDrops = allData.totalFuelDrops + filteredAlerts.length
82
- allData.totalFuelDropLiters = allData.totalFuelDropLiters + filteredAlerts.reduce((a, b) => a + b.fuelDropLiters, 0)
83
75
  }
84
76
  }
85
77
  }
86
78
 
87
- reportData.push(allData)
88
-
89
79
  return reportData
90
80
  }
91
81
 
@@ -5,6 +5,7 @@ const assert = require('assert')
5
5
  const deviceId = 122575
6
6
  // eslint-disable-next-line no-undef
7
7
  describe('Test_Reports', function () {
8
+ this.timeout(5000000)
8
9
  it('Trip by device', async () => {
9
10
  console.log('trip by device')
10
11
  const report = await getReports()