fleetmap-reports 1.0.938 → 1.0.940
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
|
@@ -2,7 +2,11 @@ const automaticReports = require('../automaticReports')
|
|
|
2
2
|
const traccarHelper = require('../util/traccar')
|
|
3
3
|
const { getUncompletedTrip } = require('../util/trips')
|
|
4
4
|
const { getEndTripMessages, getCanDriverStyleMessages, parseEndTripMessage, parseCanDriverStyleMessage } = require('../util/xpert')
|
|
5
|
-
const { calculateDistance } = require('../util/utils')
|
|
5
|
+
const { calculateDistance, getTranslations, getLanguage } = require('../util/utils')
|
|
6
|
+
const { addTable } = require('../util/pdfDocument')
|
|
7
|
+
const jsPDF = require('jspdf')
|
|
8
|
+
const { getStyle } = require('../reportStyle')
|
|
9
|
+
const { getUserPartner } = require('fleetmap-partners')
|
|
6
10
|
|
|
7
11
|
async function createPerformanceReport (from, to, userData, traccar) {
|
|
8
12
|
const reportData = []
|
|
@@ -215,7 +219,41 @@ function calculateRPMSections (route, min, max) {
|
|
|
215
219
|
}
|
|
216
220
|
|
|
217
221
|
function exportPerformanceReportToPDF (userData, reportData) {
|
|
222
|
+
const timezone = userData.user.attributes.timezone
|
|
223
|
+
const translations = getTranslations(userData)
|
|
224
|
+
const lang = getLanguage(userData)
|
|
225
|
+
|
|
226
|
+
const headers = [
|
|
227
|
+
translations.report.vehicle,
|
|
228
|
+
'Totale Utilisation',
|
|
229
|
+
'Conduite',
|
|
230
|
+
'Ralenti',
|
|
231
|
+
'Totale (L)',
|
|
232
|
+
'Conduite (L)',
|
|
233
|
+
'Ralenti (L)',
|
|
234
|
+
'Conduite (Km)',
|
|
235
|
+
'Économique',
|
|
236
|
+
'Économique (L)',
|
|
237
|
+
'Économique (Km)',
|
|
238
|
+
'Cruise Control',
|
|
239
|
+
'Cruise Control (L)',
|
|
240
|
+
'Cruise Control (Km)',
|
|
241
|
+
'Tour moteur élevé',
|
|
242
|
+
'Accéleration brusque (Sum)',
|
|
243
|
+
'Freinage brusque (Sum)',
|
|
244
|
+
'Virages brusque'
|
|
245
|
+
]
|
|
246
|
+
|
|
247
|
+
const data = []
|
|
248
|
+
reportData.devices.forEach(d => {
|
|
218
249
|
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
const doc = new jsPDF.jsPDF('l')
|
|
253
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
254
|
+
|
|
255
|
+
addTable(doc, headers, data, footValues, style)
|
|
256
|
+
return doc
|
|
219
257
|
}
|
|
220
258
|
|
|
221
259
|
function exportPerformanceReportToExcel (userData, reportData) {
|
package/src/util/trips.js
CHANGED
|
@@ -45,7 +45,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
|
|
|
45
45
|
route = allInOneData.route
|
|
46
46
|
}
|
|
47
47
|
const routeInside = route.filter(p => new Date(p.fixTime).getTime() < new Date(endDate.toUTCString()).getTime() && new Date(p.fixTime).getTime() > new Date(t.startTime).getTime() && t.deviceId === p.deviceId)
|
|
48
|
-
updateTrip(t, routeInside)
|
|
48
|
+
updateTrip(device, t, routeInside)
|
|
49
49
|
t.endTime = endDate.toISOString().replace('Z', '+0000')
|
|
50
50
|
t.endTimeIsOut = true
|
|
51
51
|
isPartialInside = true
|
|
@@ -59,7 +59,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
|
|
|
59
59
|
route = allInOneData.route
|
|
60
60
|
}
|
|
61
61
|
const routeInside = route.filter(p => new Date(p.fixTime).getTime() > startDate.getTime() && new Date(p.fixTime).getTime() < new Date(t.endTime).getTime() && t.deviceId === p.deviceId)
|
|
62
|
-
updateTrip(t, routeInside)
|
|
62
|
+
updateTrip(device, t, routeInside)
|
|
63
63
|
t.startTime = startDate.toISOString().replace('Z', '+0000')
|
|
64
64
|
t.startTimeIsOut = true
|
|
65
65
|
isPartialInside = true
|
|
@@ -73,7 +73,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
|
|
|
73
73
|
route = allInOneData.route
|
|
74
74
|
}
|
|
75
75
|
const routeInside = route.filter(p => new Date(p.fixTime).getTime() > new Date(startDate.toUTCString()).getTime() && new Date(p.fixTime).getTime() < new Date(t.endTime).getTime() && t.deviceId === p.deviceId)
|
|
76
|
-
updateTrip(t, routeInside)
|
|
76
|
+
updateTrip(device, t, routeInside)
|
|
77
77
|
t.startTime = startDate.toISOString().replace('Z', '+0000')
|
|
78
78
|
t.startTimeIsOut = true
|
|
79
79
|
isPartialInside = true
|
|
@@ -87,7 +87,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
|
|
|
87
87
|
route = allInOneData.route
|
|
88
88
|
}
|
|
89
89
|
const routeInside = route.filter(p => new Date(p.fixTime).getTime() < endDate.getTime() && new Date(p.fixTime).getTime() > new Date(t.startTime).getTime() && t.deviceId === p.deviceId)
|
|
90
|
-
updateTrip(t, routeInside)
|
|
90
|
+
updateTrip(device, t, routeInside)
|
|
91
91
|
t.endTime = endDate.toISOString().replace('Z', '+0000')
|
|
92
92
|
t.endTimeIsOut = true
|
|
93
93
|
isPartialInside = true
|
|
@@ -138,7 +138,7 @@ function isInsideTimetable (t, userData) {
|
|
|
138
138
|
return isInside(t.startTime, t.endTime, userData)
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
function updateTrip (t, route) {
|
|
141
|
+
function updateTrip (device, t, route) {
|
|
142
142
|
if (!route[route.length - 1]) { return }
|
|
143
143
|
route = route.filter(p => p.attributes.ignition)
|
|
144
144
|
const distance = calculateDistance(route, false) * 1000
|
|
@@ -146,6 +146,10 @@ function updateTrip (t, route) {
|
|
|
146
146
|
t.duration = new Date(route[route.length - 1].fixTime).getTime() - new Date(route[0].fixTime).getTime()
|
|
147
147
|
t.maxSpeed = route.reduce((a, b) => Math.max(a, b.speed), 0)
|
|
148
148
|
t.averageSpeed = distance > 0 ? ((route.reduce((a, b) => a + b.speed, 0)) / route.length) : 0
|
|
149
|
+
t.startOdometer = !device.attributes['report.ignoreOdometer'] && route[0].attributes.odometer ? route[0].attributes.odometer : route[0].attributes.totalDistance
|
|
150
|
+
t.endOdometer = !device.attributes['report.ignoreOdometer'] && route[route.length - 1].attributes.odometer ? route[route.length - 1].attributes.odometer : route[route.length - 1].attributes.totalDistance
|
|
151
|
+
console.log('startOdometer', t.startOdometer)
|
|
152
|
+
console.log('endOdometer', t.endOdometer)
|
|
149
153
|
}
|
|
150
154
|
|
|
151
155
|
function getUncompletedTrip (device, deviceRoute, deviceTrips) {
|