fleetmap-reports 1.0.459 → 1.0.463
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 +2 -0
- package/src/events-report.js +10 -7
- package/src/index.test.js +1 -0
- package/src/location-report.js +7 -2
- package/src/util/odoo.js +9 -7
- package/src/util/timetable.js +26 -0
- package/src/util/trips.js +2 -20
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -196,6 +196,7 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
196
196
|
})
|
|
197
197
|
|
|
198
198
|
if (summaryCurrentDay) {
|
|
199
|
+
summaryCurrentDay.engineHours = tripsByDay.reduce((a, b) => a + b.duration, 0)
|
|
199
200
|
summaryCurrentDay.distance = distance
|
|
200
201
|
summaryCurrentDay.convertedSpentFuel = automaticReports.calculateSpentFuel(summaryCurrentDay.spentFuel, d)
|
|
201
202
|
summaryCurrentDay.startTime = tripsByDay.length && tripsByDay[0].startTime
|
|
@@ -227,6 +228,7 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
227
228
|
|
|
228
229
|
if (summary.length) {
|
|
229
230
|
summary.forEach(s => {
|
|
231
|
+
s.engineHours = deviceTrips.reduce((a, b) => a + b.duration, 0)
|
|
230
232
|
s.distance = deviceTrips.reduce((a, b) => a + b.distance, 0)
|
|
231
233
|
s.convertedSpentFuel = automaticReports.calculateSpentFuel(s.spentFuel, d)
|
|
232
234
|
s.startTime = deviceTrips.length && deviceTrips[0].startTime
|
package/src/events-report.js
CHANGED
|
@@ -6,6 +6,7 @@ const { headerFromUser } = require('./util/pdfDocument')
|
|
|
6
6
|
const { getUserPartner } = require('fleetmap-partners')
|
|
7
7
|
const { convertToLocaleString, getTranslations } = require('./util/utils')
|
|
8
8
|
const { devicesToProcess } = require('./util/device')
|
|
9
|
+
const { isInside } = require('./util/timetable')
|
|
9
10
|
|
|
10
11
|
const fileName = 'EventReport'
|
|
11
12
|
|
|
@@ -43,7 +44,7 @@ async function createEventsReport (from, to, userData, traccar) {
|
|
|
43
44
|
|
|
44
45
|
if (data.length > 0) {
|
|
45
46
|
reportData.push({
|
|
46
|
-
devices: await processDevices(from, to, devices,
|
|
47
|
+
devices: await processDevices(from, to, devices, data, traccar, userData),
|
|
47
48
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
48
49
|
})
|
|
49
50
|
}
|
|
@@ -68,21 +69,21 @@ async function getReportData (from, to, devices, types, traccar) {
|
|
|
68
69
|
return data
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
async function processDevices (from, to, devices,
|
|
72
|
+
async function processDevices (from, to, devices, data, traccar, userData) {
|
|
72
73
|
const devicesResult = []
|
|
73
74
|
let i = 0
|
|
74
75
|
await Promise.all(devices.map(async d => {
|
|
75
|
-
const
|
|
76
|
+
const deviceAlerts = data.filter(t => t.deviceId === d.id)
|
|
76
77
|
|
|
77
|
-
if (
|
|
78
|
+
if (deviceAlerts.length > 0) {
|
|
78
79
|
const response = await traccar.reports.reportsRouteGet(from, to, [d.id])
|
|
79
80
|
const positions = response.data
|
|
80
81
|
|
|
81
|
-
for (const a of
|
|
82
|
+
for (const a of deviceAlerts) {
|
|
82
83
|
a.position = positions.find(p => p.id === a.positionId)
|
|
83
84
|
|
|
84
85
|
if (a.geofenceId) {
|
|
85
|
-
const geofence = geofences.find(g => g.id === a.geofenceId)
|
|
86
|
+
const geofence = userData.geofences.find(g => g.id === a.geofenceId)
|
|
86
87
|
if (geofence) {
|
|
87
88
|
if (a.type === 'deviceOverspeed') {
|
|
88
89
|
a.geofenceName = geofence.name + ' (' + Math.round(a.attributes.speedLimit * 1.85200) + ' Km/h)'
|
|
@@ -93,11 +94,13 @@ async function processDevices (from, to, devices, geofences, drivers, data, trac
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
if (a.position && a.position.attributes.driverUniqueId) {
|
|
96
|
-
const driver = drivers.find(d => d.uniqueId === a.position.attributes.driverUniqueId)
|
|
97
|
+
const driver = userData.drivers.find(d => d.uniqueId === a.position.attributes.driverUniqueId)
|
|
97
98
|
a.driver = driver && driver.name
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
|
|
102
|
+
const alerts = deviceAlerts.filter(a => userData.allWeek || !userData.weekDays || (!a.position || isInside(a.position.fixTime, a.position.fixTime, userData)))
|
|
103
|
+
|
|
101
104
|
console.log('LOADING_MESSAGE:' + d.name)
|
|
102
105
|
console.log(`PROGRESS_PERC:${++i / devices.length * 100}`)
|
|
103
106
|
|
package/src/index.test.js
CHANGED
|
@@ -15,6 +15,7 @@ async function getSpeedingReport (report, userData) {
|
|
|
15
15
|
|
|
16
16
|
// eslint-disable-next-line no-undef
|
|
17
17
|
describe('Test_Reports', function () {
|
|
18
|
+
this.timeout(500000)
|
|
18
19
|
// eslint-disable-next-line no-undef
|
|
19
20
|
it('Speeding by device', async () => {
|
|
20
21
|
const report = await getReports()
|
package/src/location-report.js
CHANGED
|
@@ -188,6 +188,8 @@ async function exportLocationReportToPDF (userData, reportData) {
|
|
|
188
188
|
headers.push(getDigitalPort1Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations))
|
|
189
189
|
headers.push(getDigitalPort2Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations))
|
|
190
190
|
}
|
|
191
|
+
headers.push('Latitude')
|
|
192
|
+
headers.push('Longitude')
|
|
191
193
|
|
|
192
194
|
let first = true
|
|
193
195
|
// eslint-disable-next-line new-cap
|
|
@@ -228,7 +230,8 @@ async function exportLocationReportToPDF (userData, reportData) {
|
|
|
228
230
|
temp.push(getDigitalPortValue(a, 1, translations))
|
|
229
231
|
temp.push(getDigitalPortValue(a, 2, translations))
|
|
230
232
|
}
|
|
231
|
-
|
|
233
|
+
temp.push(a.latitude)
|
|
234
|
+
temp.push(a.longitude)
|
|
232
235
|
data.push(temp)
|
|
233
236
|
})
|
|
234
237
|
|
|
@@ -323,7 +326,9 @@ function exportLocationReportToExcel (userData, reportData) {
|
|
|
323
326
|
{ label: translations.report.address, value: 'address' },
|
|
324
327
|
{ label: translations.report.speed, value: 'speed' },
|
|
325
328
|
{ label: translations.report.ignition, value: 'ignition' },
|
|
326
|
-
{ label: translations.report.driver, value: 'driver' }
|
|
329
|
+
{ label: translations.report.driver, value: 'driver' },
|
|
330
|
+
{ label: 'Latitude', value: 'latitude' },
|
|
331
|
+
{ label: 'Longitude', value: 'longitude' }
|
|
327
332
|
]
|
|
328
333
|
|
|
329
334
|
if (userData.includeTemperature) {
|
package/src/util/odoo.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
|
|
2
|
-
async function getOdooFuelServices(traccar, from, to) {
|
|
3
|
-
|
|
2
|
+
async function getOdooFuelServices (traccar, from, to) {
|
|
3
|
+
const url = `/odoo/reports/refuelingServices?startDate=${from.toDateString()}&endDate=${to.toDateString()}`
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
console.log('LOADING_MESSAGE:' + url)
|
|
6
|
+
const { data } = await traccar.axios.get(url, {
|
|
7
|
+
jar: traccar.cookieJar,
|
|
8
|
+
withCredentials: true
|
|
9
|
+
})
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
console.log(data)
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
return data
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
exports.getOdooFuelServices = getOdooFuelServices
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const { weekDaySelected, convertFromUTC, isClientSide, convertFromLocal } = require('./utils')
|
|
2
|
+
|
|
3
|
+
function isInside (start, end, userData) {
|
|
4
|
+
const tripStart = new Date(start)
|
|
5
|
+
const tripEnd = new Date(end)
|
|
6
|
+
|
|
7
|
+
if (weekDaySelected(tripStart, userData.weekDays)) {
|
|
8
|
+
const startDateLocal = new Date(convertFromUTC(start, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
|
|
9
|
+
const endDateLocal = new Date(convertFromUTC(end, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
|
|
10
|
+
|
|
11
|
+
const startDate = isClientSide() ? startDateLocal : convertFromLocal(startDateLocal, userData.user.attributes.timezone)
|
|
12
|
+
const endDate = isClientSide() ? endDateLocal : convertFromLocal(endDateLocal, userData.user.attributes.timezone)
|
|
13
|
+
|
|
14
|
+
// Trips inside time period
|
|
15
|
+
if (startDate.getTime() < endDate.getTime()) {
|
|
16
|
+
return tripStart.getTime() > startDate.getTime() && tripEnd.getTime() < endDate.getTime()
|
|
17
|
+
} else {
|
|
18
|
+
return (tripStart.getTime() < endDate.getTime() && tripEnd.getTime() < endDate.getTime()) ||
|
|
19
|
+
(tripStart.getTime() > startDate.getTime())
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.isInside = isInside
|
package/src/util/trips.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { coordsDistance, convertFromUTC, weekDaySelected, convertFromLocal, isClientSide } = require('./utils')
|
|
2
|
+
const { isInside } = require('./timetable')
|
|
2
3
|
|
|
3
4
|
const minDistance = 0
|
|
4
5
|
const minAvgSpeed = 0
|
|
@@ -112,26 +113,7 @@ function isPartialInsideTimetable (t, userData, route) {
|
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
function isInsideTimetable (t, userData) {
|
|
115
|
-
|
|
116
|
-
const tripEnd = new Date(t.endTime)
|
|
117
|
-
|
|
118
|
-
if (weekDaySelected(tripStart, userData.weekDays)) {
|
|
119
|
-
const startDateLocal = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
|
|
120
|
-
const endDateLocal = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
|
|
121
|
-
|
|
122
|
-
const startDate = isClientSide() ? startDateLocal : convertFromLocal(startDateLocal, userData.user.attributes.timezone)
|
|
123
|
-
const endDate = isClientSide() ? endDateLocal : convertFromLocal(endDateLocal, userData.user.attributes.timezone)
|
|
124
|
-
|
|
125
|
-
// Trips inside time period
|
|
126
|
-
if (startDate.getTime() < endDate.getTime()) {
|
|
127
|
-
return tripStart.getTime() > startDate.getTime() && tripEnd.getTime() < endDate.getTime()
|
|
128
|
-
} else {
|
|
129
|
-
return (tripStart.getTime() < endDate.getTime() && tripEnd.getTime() < endDate.getTime()) ||
|
|
130
|
-
(tripStart.getTime() > startDate.getTime())
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return false
|
|
116
|
+
return isInside(t.startTime, t.endTime, userData)
|
|
135
117
|
}
|
|
136
118
|
|
|
137
119
|
function updateTrip (t, route) {
|