fleetmap-reports 2.0.289 → 2.0.291

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.289",
3
+ "version": "2.0.291",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -28,32 +28,46 @@ async function createRefuelingReport (from, to, userData, traccar) {
28
28
 
29
29
  console.log('Devices:' + devices.length)
30
30
 
31
- const arrayOfArrays = automaticReports.sliceArray(devices)
32
- const data = []
33
- for (const a of arrayOfArrays) {
34
- const allInOne = await traccarHelper.getAllInOne(traccar, from, to, a, true, false, false, false)
35
- data.push(...allInOne.route)
36
- }
37
-
38
- const fuelServicesData = []
39
- if (devices.some(d => d.attributes.odooId)) {
40
- fuelServicesData.push(...(await odoo.getOdooFuelServices(traccar, from, to)))
41
- }
42
-
43
- if (data.length === 0) {
44
- return reportData
45
- }
31
+ const slices = automaticReports.sliceArray(devices, 5)
46
32
 
47
33
  allData.totalDevices = 0
48
34
  allData.totalRefueling = 0
49
35
  allData.totalRefuelingLiters = 0
36
+ let deviceCount = 0
37
+ for (const slice of slices) {
38
+ const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, false, false, false, deviceCount, devices.length)
39
+ const route = allInOne.route
40
+
41
+ const fuelServicesData = []
42
+ if (devices.some(d => d.attributes.odooId)) {
43
+ fuelServicesData.push(...(await odoo.getOdooFuelServices(traccar, from, to)))
44
+ }
45
+
46
+ allData.devices.push(...await processDevices(from, to, slice, route, userData, fuelServicesData))
47
+ deviceCount = deviceCount + slice.length
48
+ }
49
+ const refuelingPositions = allData.devices.map(d => d.refuelings).flat()
50
+ allData.totalDevices = allData.totalDevices + 1
51
+ allData.totalRefueling = allData.totalRefueling + refuelingPositions.length
52
+ allData.totalRefuelingLiters = allData.totalRefuelingLiters + refuelingPositions.reduce((a, b) => a + b.diff, 0)
53
+
54
+ reportData.push(allData)
55
+
56
+ return reportData
57
+ }
58
+
59
+ async function processDevices (from, to, devices, data, userData, fuelServicesData) {
60
+ const devicesResult = []
50
61
 
51
62
  for (const d of devices) {
52
63
  const positions = data.filter(t => t.deviceId === d.id)
53
64
  const deviceFuelServices = fuelServicesData.filter(f => Number.parseInt(d.attributes.odooId) === f.vehicle_id[0])
54
65
 
55
66
  if (positions.length > 0) {
56
- const refuelingPositions = await this.calculateRefuelingPositions(userData, d, { route: positions, fuelServices: deviceFuelServices })
67
+ const refuelingPositions = await calculateRefuelingPositions(userData, d, {
68
+ route: positions,
69
+ fuelServices: deviceFuelServices
70
+ })
57
71
 
58
72
  if (userData.drivers.length > 0) {
59
73
  refuelingPositions.forEach(r => {
@@ -71,20 +85,15 @@ async function createRefuelingReport (from, to, userData, traccar) {
71
85
  }
72
86
 
73
87
  if (refuelingPositions.length > 0) {
74
- allData.devices.push({
88
+ devicesResult.push({
75
89
  device: d,
76
90
  refuelings: refuelingPositions
77
91
  })
78
- allData.totalDevices = allData.totalDevices + 1
79
- allData.totalRefueling = allData.totalRefueling + refuelingPositions.length
80
- allData.totalRefuelingLiters = allData.totalRefuelingLiters + refuelingPositions.reduce((a, b) => a + b.diff, 0)
81
92
  }
82
93
  }
83
94
  }
84
95
 
85
- reportData.push(allData)
86
-
87
- return reportData
96
+ return devicesResult
88
97
  }
89
98
 
90
99
  function findNearestPOI (position, geofences) {
@@ -527,8 +527,8 @@ function exportTripReportToExcel (userData, reportData) {
527
527
  headers.unshift({ label: translations.report.driver, value: 'name' })
528
528
  headers.push({ label: translations.report.vehicle, value: 'subname' })
529
529
  } else {
530
+ headers.unshift({ label: translations.report.driver, value: 'subname' })
530
531
  headers.unshift({ label: translations.report.vehicle, value: 'name' })
531
- headers.push({ label: translations.report.driver, value: 'subname' })
532
532
  }
533
533
 
534
534
  tripsData.forEach(d => {