fleetmap-reports 1.0.381 → 1.0.384
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 +1 -1
- package/src/activity-report.js +24 -25
- package/src/events-report.js +5 -7
- package/src/fuelconsumption-report.js +4 -3
- package/src/fueldrop-report.js +17 -10
- package/src/idle-report.js +5 -5
- package/src/kms-report.js +5 -6
- package/src/location-report.js +5 -7
- package/src/refueling-report.js +5 -5
- package/src/speeding-report.js +3 -5
- package/src/trip-report.js +3 -7
- package/src/util/device.js +10 -0
- package/src/util/trips.js +3 -16
- package/src/util/utils.js +11 -0
- package/src/zone-report.js +5 -6
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const automaticReports = require("./automaticReports")
|
|
2
|
-
const {convertMS, getDates, getTranslations} = require("./util/utils")
|
|
2
|
+
const {convertMS, getDates, getTranslations, weekDaySelected} = require("./util/utils")
|
|
3
3
|
const jsPDF = require('jspdf')
|
|
4
4
|
require('jspdf-autotable')
|
|
5
5
|
const drivers = require("./util/driver")
|
|
@@ -9,6 +9,7 @@ const {getUserPartner} = require("fleetmap-partners")
|
|
|
9
9
|
const traccar = require("./util/traccar")
|
|
10
10
|
const {isInsideTimetable, isPartialInsideTimetable, calculateTrip} = require("./util/trips");
|
|
11
11
|
const tripHelper = require("./util/trips");
|
|
12
|
+
const {devicesToProcess} = require("./util/device");
|
|
12
13
|
|
|
13
14
|
const fileName = 'ActivityReport'
|
|
14
15
|
|
|
@@ -71,27 +72,23 @@ async function createActivityReportByGroup(from, to, userData, traccarInstance){
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
async function createActivityReportByDevice(from, to, userData, traccarInstance){
|
|
74
|
-
const
|
|
75
|
-
const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
75
|
+
const devices = devicesToProcess(userData)
|
|
76
76
|
|
|
77
77
|
const allData = {
|
|
78
78
|
devices: [],
|
|
79
|
-
xpert:
|
|
79
|
+
xpert: devices.filter(d => d.attributes.xpert).length > 0,
|
|
80
80
|
from: from,
|
|
81
81
|
to: to
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
//Get report data from traccar
|
|
85
|
-
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
86
|
-
|
|
87
84
|
let summaries = []
|
|
88
|
-
const {trips, route, summary} = await traccar.getAllInOne(traccarInstance, from, to,
|
|
85
|
+
const {trips, route, summary} = await traccar.getAllInOne(traccarInstance, from, to, devices, true, true, false, !userData.groupByDay)
|
|
89
86
|
|
|
90
87
|
if(userData.groupByDay) {
|
|
91
88
|
console.log('trips:' + trips.length)
|
|
92
89
|
|
|
93
90
|
if (trips.length) {
|
|
94
|
-
tripHelper.checkTripsKms(traccarInstance, from, to,
|
|
91
|
+
tripHelper.checkTripsKms(traccarInstance, from, to, devices, {trips, route})
|
|
95
92
|
}
|
|
96
93
|
|
|
97
94
|
const dates = getDates(from, to)
|
|
@@ -100,7 +97,7 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
|
100
97
|
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
101
98
|
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
102
99
|
|
|
103
|
-
const summary = await traccar.getSummary(traccarInstance, fromByDay, toByDay,
|
|
100
|
+
const summary = await traccar.getSummary(traccarInstance, fromByDay, toByDay, devices)
|
|
104
101
|
summary.forEach(s => s.date = date)
|
|
105
102
|
summaries = summaries.concat(summary)
|
|
106
103
|
}
|
|
@@ -113,7 +110,7 @@ async function createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
|
113
110
|
|
|
114
111
|
//Process report data
|
|
115
112
|
if (summaries.length || trips.length) {
|
|
116
|
-
allData.devices = processDevices(from, to,
|
|
113
|
+
allData.devices = processDevices(from, to, devices, {summaries: summaries, trips, route}, userData)
|
|
117
114
|
}
|
|
118
115
|
|
|
119
116
|
return allData
|
|
@@ -169,20 +166,22 @@ function processDevices(from, to, devices, data, userData) {
|
|
|
169
166
|
const distance = tripsByDay.reduce((a, b) => a + b.distance, 0)
|
|
170
167
|
|
|
171
168
|
if(!userData.allWeek && userData.weekDays && userData.dayHours) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
169
|
+
if(weekDaySelected(date, userData.weekDays)) {
|
|
170
|
+
summary.push({
|
|
171
|
+
date: date,
|
|
172
|
+
deviceId: d.id,
|
|
173
|
+
averageSpeed: distance > 0 ? ((tripsByDay.reduce((a, b) => a + (b.averageSpeed * b.distance), 0)) / distance) : 0,
|
|
174
|
+
distance: distance,
|
|
175
|
+
engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
|
|
176
|
+
maxSpeed: tripsByDay.reduce((a, b) => {
|
|
177
|
+
return a > b.maxSpeed ? a : b.maxSpeed
|
|
178
|
+
}, 0),
|
|
179
|
+
endOdometer: 0,
|
|
180
|
+
startOdometer: 0,
|
|
181
|
+
startTime: tripsByDay.length && tripsByDay[0].startTime,
|
|
182
|
+
endTime: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
|
|
183
|
+
})
|
|
184
|
+
}
|
|
186
185
|
} else {
|
|
187
186
|
const summaryCurrentDay = data.summaries.find(s => {
|
|
188
187
|
return s.deviceId === d.id && s.date.getTime() === date.getTime()})
|
package/src/events-report.js
CHANGED
|
@@ -5,6 +5,7 @@ const {getStyle} = require("./reportStyle");
|
|
|
5
5
|
const {headerFromUser} = require("./util/pdfDocument");
|
|
6
6
|
const {getUserPartner} = require("fleetmap-partners");
|
|
7
7
|
const {convertToLocaleString, getTranslations} = require("./util/utils");
|
|
8
|
+
const {devicesToProcess} = require("./util/device");
|
|
8
9
|
|
|
9
10
|
const fileName = 'EventReport'
|
|
10
11
|
|
|
@@ -36,17 +37,14 @@ async function createEventsReport(from, to, userData, traccar) {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
const
|
|
40
|
-
const withoutGroupDevices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
40
|
+
const devices = devicesToProcess(userData)
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const data = await getReportData(from, to, withoutGroupDevices, userData.eventTypes, traccar)
|
|
42
|
+
const data = await getReportData(from, to, devices, userData.eventTypes, traccar)
|
|
45
43
|
|
|
46
44
|
if(data.length > 0) {
|
|
47
45
|
reportData.push({
|
|
48
|
-
devices: await processDevices(from, to,
|
|
49
|
-
xpert:
|
|
46
|
+
devices: await processDevices(from, to, devices, userData.geofences, userData.drivers, data, traccar),
|
|
47
|
+
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
50
48
|
})
|
|
51
49
|
}
|
|
52
50
|
|
|
@@ -2,6 +2,7 @@ const automaticReports = require("./automaticReports")
|
|
|
2
2
|
const refuelingReport = require("./refueling-report")
|
|
3
3
|
const traccarHelper = require("./util/traccar")
|
|
4
4
|
const odoo = require("./util/odoo")
|
|
5
|
+
const {devicesToProcess} = require("./util/device");
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
@@ -16,9 +17,9 @@ async function createFuelConsumptionReport(from, to, userData, traccar) {
|
|
|
16
17
|
to: to
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
const devices = devicesToProcess(userData)
|
|
20
21
|
|
|
21
|
-
const allInOne = await traccarHelper.getAllInOne(traccar, from, to,
|
|
22
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, true, false, false)
|
|
22
23
|
const tripsData = allInOne.trips
|
|
23
24
|
const routeData = allInOne.route
|
|
24
25
|
|
|
@@ -33,7 +34,7 @@ async function createFuelConsumptionReport(from, to, userData, traccar) {
|
|
|
33
34
|
|
|
34
35
|
allData.totalDevices = 0
|
|
35
36
|
|
|
36
|
-
for (const d of
|
|
37
|
+
for (const d of devices) {
|
|
37
38
|
const trips = tripsData.filter(t => t.deviceId===d.id)
|
|
38
39
|
const route = routeData.filter(r => r.deviceId===d.id)
|
|
39
40
|
const deviceFuelServices = fuelServicesData.filter(f => d.attributes.odooId === f.vehicle_id[0])
|
package/src/fueldrop-report.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const automaticReports = require("./automaticReports");
|
|
2
|
+
const {devicesToProcess} = require("./util/device");
|
|
2
3
|
|
|
3
4
|
function calculateFuelDrop(position, positions) {
|
|
4
5
|
const index = positions.indexOf(position)
|
|
@@ -28,9 +29,9 @@ async function createFuelDropReport(from, to, userData, traccar) {
|
|
|
28
29
|
to: to
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
const devices = devicesToProcess(userData)
|
|
32
33
|
|
|
33
|
-
const arrayOfArrays = automaticReports.sliceArray(
|
|
34
|
+
const arrayOfArrays = automaticReports.sliceArray(devices)
|
|
34
35
|
let data = []
|
|
35
36
|
const types = ['deviceFuelDrop']
|
|
36
37
|
|
|
@@ -48,7 +49,7 @@ async function createFuelDropReport(from, to, userData, traccar) {
|
|
|
48
49
|
allData.totalFuelDrops = 0
|
|
49
50
|
allData.totalFuelDropLiters = 0
|
|
50
51
|
|
|
51
|
-
for (const d of
|
|
52
|
+
for (const d of devices) {
|
|
52
53
|
const alerts = data.filter(t => t.deviceId===d.id)
|
|
53
54
|
|
|
54
55
|
if(alerts.length > 0) {
|
|
@@ -67,13 +68,19 @@ async function createFuelDropReport(from, to, userData, traccar) {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
//Filter wrong fuel drop values
|
|
72
|
+
const filteredAlerts = alerts.filter(a => a.fuelDropLiters < d.attributes.fuel_tank_capacity && a.fuelDropLiters > 0)
|
|
73
|
+
|
|
74
|
+
if(filteredAlerts.length > 0) {
|
|
75
|
+
allData.devices.push({
|
|
76
|
+
device: d,
|
|
77
|
+
alerts: filteredAlerts
|
|
78
|
+
})
|
|
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
|
+
}
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
86
|
|
package/src/idle-report.js
CHANGED
|
@@ -4,6 +4,7 @@ const {headerFromUser, AmiriRegular} = require("./util/pdfDocument");
|
|
|
4
4
|
const {convertToLocaleString, convertMS, getTranslations} = require("./util/utils");
|
|
5
5
|
const {getStyle} = require("./reportStyle");
|
|
6
6
|
const {getUserPartner} = require("fleetmap-partners");
|
|
7
|
+
const {devicesToProcess} = require("./util/device");
|
|
7
8
|
|
|
8
9
|
const fileName = 'IdleReport'
|
|
9
10
|
|
|
@@ -17,7 +18,7 @@ async function createIdleReport(from, to, userData, traccarInstance) {
|
|
|
17
18
|
reportData.push(...allData)
|
|
18
19
|
} else {
|
|
19
20
|
console.log("ByDevice")
|
|
20
|
-
const report = await createTripReportByDevice(from, to, userData
|
|
21
|
+
const report = await createTripReportByDevice(from, to, userData, traccarInstance)
|
|
21
22
|
reportData.push(report)
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -60,17 +61,16 @@ async function createTripReportByGroup(from, to, userData, traccarInstance) {
|
|
|
60
61
|
return reportData
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
async function createTripReportByDevice(from, to,
|
|
64
|
+
async function createTripReportByDevice(from, to, userData, traccarInstance) {
|
|
64
65
|
const allData = {
|
|
65
66
|
devices: [],
|
|
66
67
|
from: from,
|
|
67
68
|
to: to
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
devices
|
|
71
|
+
const devices = devicesToProcess(userData)
|
|
71
72
|
|
|
72
|
-
const
|
|
73
|
-
const route = await traccar.getRoute(traccarInstance, from, to, devicesToSlice)
|
|
73
|
+
const route = await traccar.getRoute(traccarInstance, from, to, devices)
|
|
74
74
|
|
|
75
75
|
console.log('Route:' + route.length)
|
|
76
76
|
|
package/src/kms-report.js
CHANGED
|
@@ -10,6 +10,7 @@ const trips = require("./util/trips")
|
|
|
10
10
|
const drivers = require("./util/driver")
|
|
11
11
|
const { isInsideTimetable, isPartialInsideTimetable, calculateTrip} = require("./util/trips")
|
|
12
12
|
const traccarHelper = require("./util/traccar");
|
|
13
|
+
const {devicesToProcess} = require("./util/device");
|
|
13
14
|
|
|
14
15
|
const fileName = 'KmsReport'
|
|
15
16
|
|
|
@@ -37,8 +38,7 @@ async function createKmsReport(from, to, userData, traccarInstance) {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
async function createKmsReportByDevice(from, to, userData, traccarInstance) {
|
|
40
|
-
const
|
|
41
|
-
const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
41
|
+
const devices = devicesToProcess(userData)
|
|
42
42
|
|
|
43
43
|
const allData = {
|
|
44
44
|
devices: [],
|
|
@@ -46,16 +46,15 @@ async function createKmsReportByDevice(from, to, userData, traccarInstance) {
|
|
|
46
46
|
to: to
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devicesToProcess, true, true, false, false)
|
|
49
|
+
const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, true, false, false)
|
|
51
50
|
const tripsData = allInOne.trips
|
|
52
51
|
const routeData = allInOne.route
|
|
53
52
|
|
|
54
53
|
console.log('trips:' + tripsData.length)
|
|
55
54
|
|
|
56
55
|
if (tripsData.length > 0) {
|
|
57
|
-
trips.checkTripsKms(traccarInstance, from, to,
|
|
58
|
-
allData.devices = processDevices(from, to,
|
|
56
|
+
trips.checkTripsKms(traccarInstance, from, to, devices, {trips: tripsData, route: routeData})
|
|
57
|
+
allData.devices = processDevices(from, to, devices, {trips: tripsData, route: routeData}, userData)
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
return allData
|
package/src/location-report.js
CHANGED
|
@@ -5,6 +5,7 @@ const {getStyle} = require("./reportStyle")
|
|
|
5
5
|
const {getUserPartner} = require("fleetmap-partners");
|
|
6
6
|
const {convertToLocaleString, getTranslations} = require("./util/utils");
|
|
7
7
|
const traccarHelper = require("./util/traccar");
|
|
8
|
+
const {devicesToProcess} = require("./util/device");
|
|
8
9
|
|
|
9
10
|
const fileName = 'LocationReport'
|
|
10
11
|
|
|
@@ -79,23 +80,20 @@ async function createLocationReportByGroup(from, to, userData, traccar) {
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
async function createLocationReportByDevice(from, to, userData, traccar) {
|
|
82
|
-
const
|
|
83
|
-
const withoutGroupDevices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
83
|
+
const devices = devicesToProcess(userData)
|
|
84
84
|
|
|
85
85
|
const allData = {
|
|
86
86
|
devices: [],
|
|
87
|
-
xpert:
|
|
87
|
+
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
const devicesToSlice = withoutGroupDevices.slice()
|
|
92
|
-
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devicesToSlice, true, false, false, false)
|
|
90
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, devices, true, false, false, false)
|
|
93
91
|
const routeData = allInOne.route
|
|
94
92
|
|
|
95
93
|
console.log('Locations:'+routeData.length)
|
|
96
94
|
|
|
97
95
|
if(routeData.length > 0) {
|
|
98
|
-
allData.devices = processDevices(from, to,
|
|
96
|
+
allData.devices = processDevices(from, to, devices, userData.drivers, routeData)
|
|
99
97
|
}
|
|
100
98
|
|
|
101
99
|
return allData
|
package/src/refueling-report.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const helpers = require("turf")
|
|
2
2
|
const automaticReports = require("./automaticReports")
|
|
3
|
+
const {devicesToProcess} = require("./util/device");
|
|
3
4
|
|
|
4
5
|
const positionsToCheck = 15
|
|
5
6
|
|
|
@@ -14,12 +15,11 @@ async function createRefuelingReport(from, to, userData, traccar) {
|
|
|
14
15
|
to: to
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
const devices = devicesToProcess(userData).filter(d => automaticReports.deviceWithFuelInfo(d))
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
console.log('Devices:'+devicesToSlice.length)
|
|
20
|
+
console.log('Devices:'+devices.length)
|
|
21
21
|
|
|
22
|
-
const arrayOfArrays = automaticReports.sliceArray(
|
|
22
|
+
const arrayOfArrays = automaticReports.sliceArray(devices)
|
|
23
23
|
let data = []
|
|
24
24
|
for (const a of arrayOfArrays) {
|
|
25
25
|
const response = await traccar.reports.reportsRouteGet(from, to, a.map(d => d.id))
|
|
@@ -36,7 +36,7 @@ async function createRefuelingReport(from, to, userData, traccar) {
|
|
|
36
36
|
allData.totalRefueling = 0
|
|
37
37
|
allData.totalRefuelingLiters = 0
|
|
38
38
|
|
|
39
|
-
for (const d of
|
|
39
|
+
for (const d of devices) {
|
|
40
40
|
const positions = data.filter(t => t.deviceId===d.id)
|
|
41
41
|
|
|
42
42
|
if(positions.length > 0) {
|
package/src/speeding-report.js
CHANGED
|
@@ -11,6 +11,7 @@ const {distance, point} = require('turf')
|
|
|
11
11
|
const here = require('./here')
|
|
12
12
|
const {getUserPartner} = require("fleetmap-partners");
|
|
13
13
|
const traccarHelper = require("./util/traccar");
|
|
14
|
+
const {devicesToProcess} = require("./util/device");
|
|
14
15
|
|
|
15
16
|
const fileName = 'SpeedingReport'
|
|
16
17
|
const eventTypes = ['deviceOverspeed']
|
|
@@ -67,10 +68,7 @@ async function createSpeedingReportByGroup(from, to, userData, traccarInstance){
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
async function createSpeedingReportByDevice(from, to, userData, traccarInstance) {
|
|
70
|
-
const
|
|
71
|
-
const devices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
72
|
-
|
|
73
|
-
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
71
|
+
const devices = devicesToProcess(userData)
|
|
74
72
|
|
|
75
73
|
const allInOne = await traccarHelper.getAllInOne(traccarInstance, from, to, devices, true, false, false, false)
|
|
76
74
|
const routes = allInOne.route
|
|
@@ -471,7 +469,7 @@ function exportSpeedingReportToExcel(userData, reportData) {
|
|
|
471
469
|
distance: a.distance && new Intl.NumberFormat(lang, {maximumSignificantDigits: 1}).format(a.distance),
|
|
472
470
|
maxSpeed: a.attributes.maxSpeed ? Math.round(a.attributes.maxSpeed * 1.85200) : Math.round(a.attributes.speed * 1.85200),
|
|
473
471
|
duration: convertMS(a.eventTime, true),
|
|
474
|
-
fixTime:
|
|
472
|
+
fixTime: getAlertDate(a, userData.user),
|
|
475
473
|
name: userData.byDriver ? a.deviceName : d.device.name,
|
|
476
474
|
address: a.position.address + (a.geofenceName ? ' - ' + a.geofenceName : ''),
|
|
477
475
|
roadSpeedLimit: a.roadSpeedLimit
|
package/src/trip-report.js
CHANGED
|
@@ -8,6 +8,7 @@ const {getStyle} = require("./reportStyle")
|
|
|
8
8
|
const traccarHelper = require("./util/traccar")
|
|
9
9
|
const trips = require("./util/trips");
|
|
10
10
|
const {isInsideTimetable, addNearestPOIs, isPartialInsideTimetable, calculateTrip} = require("./util/trips")
|
|
11
|
+
const {devicesToProcess} = require("./util/device");
|
|
11
12
|
|
|
12
13
|
const fileName = 'TripReport'
|
|
13
14
|
|
|
@@ -34,20 +35,15 @@ async function createTripReport(from, to, userData, traccar) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
async function createTripReportByDevice(from, to, userData, traccar) {
|
|
37
|
-
const
|
|
38
|
-
const devices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
38
|
+
const devices = devicesToProcess(userData)
|
|
39
39
|
|
|
40
40
|
const allData = {
|
|
41
41
|
devices: [],
|
|
42
42
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
const sliced = automaticReports.sliceArray(devices, 5)
|
|
46
46
|
|
|
47
|
-
const devicesToSlice = devices.slice()
|
|
48
|
-
const sliced = automaticReports.sliceArray(devicesToSlice, 5)
|
|
49
|
-
|
|
50
|
-
console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
|
|
51
47
|
let deviceCount = 0
|
|
52
48
|
for(const slice of sliced) {
|
|
53
49
|
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, true, true, false)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function devicesToProcess(userData) {
|
|
2
|
+
const groupIds = userData.groups.map(g => g.id)
|
|
3
|
+
const devices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
4
|
+
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
5
|
+
|
|
6
|
+
console.log('LOADING_MESSAGE:' + devices.map(d => d.name).join(', '))
|
|
7
|
+
return devices
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.devicesToProcess = devicesToProcess
|
package/src/util/trips.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {coordsDistance, convertFromUTC} = require("./utils");
|
|
1
|
+
const {coordsDistance, convertFromUTC, weekDaySelected} = require("./utils");
|
|
2
2
|
|
|
3
3
|
const minDistance = 0
|
|
4
4
|
const minAvgSpeed = 0
|
|
@@ -57,13 +57,7 @@ function isPartialInsideTimetable(t, userData, route){
|
|
|
57
57
|
|
|
58
58
|
let isPartialInside = false
|
|
59
59
|
|
|
60
|
-
if((tripStart
|
|
61
|
-
(tripStart.getDay() === 1 && userData.weekDays.monday) ||
|
|
62
|
-
(tripStart.getDay() === 2 && userData.weekDays.tuesday) ||
|
|
63
|
-
(tripStart.getDay() === 3 && userData.weekDays.wednesday) ||
|
|
64
|
-
(tripStart.getDay() === 4 && userData.weekDays.thursday) ||
|
|
65
|
-
(tripStart.getDay() === 5 && userData.weekDays.friday) ||
|
|
66
|
-
(tripStart.getDay() === 6 && userData.weekDays.saturday)) {
|
|
60
|
+
if(weekDaySelected(tripStart, userData.weekDays)) {
|
|
67
61
|
|
|
68
62
|
const startDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
|
|
69
63
|
const endDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
|
|
@@ -122,14 +116,7 @@ function isInsideTimetable(t, userData){
|
|
|
122
116
|
const tripStart = new Date(t.startTime)
|
|
123
117
|
const tripEnd = new Date(t.endTime)
|
|
124
118
|
|
|
125
|
-
if((tripStart
|
|
126
|
-
(tripStart.getDay() === 1 && userData.weekDays.monday) ||
|
|
127
|
-
(tripStart.getDay() === 2 && userData.weekDays.tuesday) ||
|
|
128
|
-
(tripStart.getDay() === 3 && userData.weekDays.wednesday) ||
|
|
129
|
-
(tripStart.getDay() === 4 && userData.weekDays.thursday) ||
|
|
130
|
-
(tripStart.getDay() === 5 && userData.weekDays.friday) ||
|
|
131
|
-
(tripStart.getDay() === 6 && userData.weekDays.saturday)) {
|
|
132
|
-
|
|
119
|
+
if(weekDaySelected(tripStart, userData.weekDays)) {
|
|
133
120
|
const startDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
|
|
134
121
|
const endDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
|
|
135
122
|
|
package/src/util/utils.js
CHANGED
|
@@ -130,6 +130,16 @@ function convertFromUTC(value, timezone) {
|
|
|
130
130
|
return valueDate
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
function weekDaySelected(date, weekDays){
|
|
134
|
+
return (date.getDay() === 0 && weekDays.sunday) ||
|
|
135
|
+
(date.getDay() === 1 && weekDays.monday) ||
|
|
136
|
+
(date.getDay() === 2 && weekDays.tuesday) ||
|
|
137
|
+
(date.getDay() === 3 && weekDays.wednesday) ||
|
|
138
|
+
(date.getDay() === 4 && weekDays.thursday) ||
|
|
139
|
+
(date.getDay() === 5 && weekDays.friday) ||
|
|
140
|
+
(date.getDay() === 6 && weekDays.saturday)
|
|
141
|
+
}
|
|
142
|
+
|
|
133
143
|
exports.getImgFromUrl = getImgFromUrl
|
|
134
144
|
exports.convertMS = convertMS
|
|
135
145
|
exports.coordsDistance = coordsDistance
|
|
@@ -140,6 +150,7 @@ exports.convertToLocaleTimeString = convertToLocaleTimeString
|
|
|
140
150
|
exports.isClientSide = isClientSide
|
|
141
151
|
exports.getTimezoneOffset = getTimezoneOffset
|
|
142
152
|
exports.convertFromUTC = convertFromUTC
|
|
153
|
+
exports.weekDaySelected = weekDaySelected
|
|
143
154
|
exports.getLogo = (user) => {
|
|
144
155
|
const host = window ? window.location.hostname : getUserPartner(user).host
|
|
145
156
|
return getImage(getLogoUrl(host))
|
package/src/zone-report.js
CHANGED
|
@@ -6,6 +6,7 @@ require('jspdf-autotable')
|
|
|
6
6
|
const {headerFromUser} = require("./util/pdfDocument");
|
|
7
7
|
const {getStyle} = require("./reportStyle")
|
|
8
8
|
const {getUserPartner} = require("fleetmap-partners");
|
|
9
|
+
const {devicesToProcess} = require("./util/device");
|
|
9
10
|
|
|
10
11
|
const fileName = 'ZoneReport'
|
|
11
12
|
|
|
@@ -42,17 +43,15 @@ async function createZoneReport(from, to, userData, traccar) {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
const
|
|
46
|
-
const withoutGroupDevices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
46
|
+
const devices = devicesToProcess(userData)
|
|
47
47
|
|
|
48
48
|
const allData = {
|
|
49
49
|
devices: [],
|
|
50
|
-
xpert:
|
|
50
|
+
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
withoutGroupDevices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
54
53
|
|
|
55
|
-
const arrayOfArrays = automaticReports.sliceArray(
|
|
54
|
+
const arrayOfArrays = automaticReports.sliceArray(devices)
|
|
56
55
|
let data = []
|
|
57
56
|
for (const a of arrayOfArrays) {
|
|
58
57
|
const response = await traccar.reports.reportsEventsGet(from, to, a.map(d => d.id), null, types)
|
|
@@ -65,7 +64,7 @@ async function createZoneReport(from, to, userData, traccar) {
|
|
|
65
64
|
return reportData
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
allData.devices = await processDevices(from, to,
|
|
67
|
+
allData.devices = await processDevices(from, to, devices, userData.drivers, userData.geofences, data, traccar)
|
|
69
68
|
|
|
70
69
|
reportData.push(allData)
|
|
71
70
|
|