fleetmap-reports 1.0.581 → 1.0.583
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/trip-report.js +78 -58
- package/src/util/pdfDocument.js +11 -1
package/package.json
CHANGED
package/src/trip-report.js
CHANGED
|
@@ -163,15 +163,10 @@ function processDevices (from, to, devices, data, userData, traccar) {
|
|
|
163
163
|
addNearestPOIs(trips, userData)
|
|
164
164
|
|
|
165
165
|
trips.forEach(trip => {
|
|
166
|
-
if (deviceRoute[0].protocol === 'teltonika')
|
|
166
|
+
if ((deviceRoute[0].protocol === 'teltonika' && deviceRoute[0].attributes.fuel) ||
|
|
167
|
+
automaticReports.deviceWithFuelInfo(d)) {
|
|
167
168
|
trip.fuelConsumption = trip.spentFuel
|
|
168
|
-
trip.avgFuelConsumption = trip.totalKms > 0 ?
|
|
169
|
-
} else if (automaticReports.deviceWithFuelInfo(d)) {
|
|
170
|
-
trip.fuelConsumption = Math.round((trip.spentFuel * d.attributes.fuel_tank_capacity) / 100)
|
|
171
|
-
trip.avgFuelConsumption = trip.totalKms > 0 ? Math.round(trip.fuelConsumption * 100 / trip.totalKms) : 0
|
|
172
|
-
} else {
|
|
173
|
-
trip.fuelConsumption = '-'
|
|
174
|
-
trip.avgFuelConsumption = '-'
|
|
169
|
+
trip.avgFuelConsumption = trip.totalKms > 0 ? trip.fuelConsumption * 100 / trip.totalKms : 0
|
|
175
170
|
}
|
|
176
171
|
|
|
177
172
|
const stop = getStop(new Date(trip.startTime), stops)
|
|
@@ -201,9 +196,11 @@ function processDevices (from, to, devices, data, userData, traccar) {
|
|
|
201
196
|
}, 0),
|
|
202
197
|
trips
|
|
203
198
|
}
|
|
204
|
-
|
|
199
|
+
|
|
200
|
+
if (trips[0].fuelConsumption !== undefined) {
|
|
205
201
|
deviceData.totalFuelConsumption = trips.reduce((a, b) => a + b.fuelConsumption, 0)
|
|
206
|
-
deviceData.avgFuelConsumption = deviceData.totalDistance > 0 ?
|
|
202
|
+
deviceData.avgFuelConsumption = deviceData.totalDistance > 0 ? (deviceData.totalFuelConsumption * 100) / (deviceData.totalDistance / 1000) : 0
|
|
203
|
+
console.log(deviceData)
|
|
207
204
|
}
|
|
208
205
|
|
|
209
206
|
devicesResult.push(deviceData)
|
|
@@ -257,26 +254,28 @@ async function exportTripReportToPDF (userData, reportData) {
|
|
|
257
254
|
translations.report.start,
|
|
258
255
|
translations.report.end,
|
|
259
256
|
translations.report.endAddress,
|
|
260
|
-
translations.report.tripTime
|
|
257
|
+
translations.report.tripTime,
|
|
258
|
+
translations.report.idleTime,
|
|
259
|
+
translations.report.stopTime,
|
|
260
|
+
translations.report.distance,
|
|
261
|
+
translations.report.avgSpeed,
|
|
262
|
+
translations.report.maxSpeed
|
|
261
263
|
]
|
|
262
264
|
|
|
263
|
-
if (userData.byDriver) {
|
|
264
|
-
headers.push(translations.report.idleTime,
|
|
265
|
-
translations.report.stopTime,
|
|
266
|
-
translations.report.distance,
|
|
267
|
-
translations.report.avgSpeed,
|
|
268
|
-
translations.report.maxSpeed,
|
|
269
|
-
translations.report.name)
|
|
270
|
-
} else {
|
|
271
|
-
headers.push(translations.report.idleTime,
|
|
272
|
-
translations.report.stopTime,
|
|
273
|
-
translations.report.distance,
|
|
274
|
-
translations.report.avgSpeed,
|
|
275
|
-
translations.report.maxSpeed,
|
|
276
|
-
translations.report.driver)
|
|
277
|
-
}
|
|
278
|
-
|
|
279
265
|
if (tripsData) {
|
|
266
|
+
const withFuelData = tripsData.reduce((a, b) => a || b.totalFuelConsumption !== undefined)
|
|
267
|
+
|
|
268
|
+
if (withFuelData) {
|
|
269
|
+
headers.push(translations.report.consumption,
|
|
270
|
+
translations.report.avg_consumption)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (userData.byDriver) {
|
|
274
|
+
headers.push(translations.report.name)
|
|
275
|
+
} else {
|
|
276
|
+
headers.push(translations.report.driver)
|
|
277
|
+
}
|
|
278
|
+
|
|
280
279
|
// eslint-disable-next-line new-cap
|
|
281
280
|
const doc = new jsPDF.jsPDF('l')
|
|
282
281
|
await headerFromUser(doc, translations.report.titleTripReport, userData.user)
|
|
@@ -326,6 +325,10 @@ async function exportTripReportToPDF (userData, reportData) {
|
|
|
326
325
|
Math.round(a.averageSpeed * 1.85200),
|
|
327
326
|
Math.round(a.maxSpeed * 1.85200))
|
|
328
327
|
|
|
328
|
+
if (withFuelData) {
|
|
329
|
+
temp.push(a.fuelConsumption.toFixed(1), a.avgFuelConsumption.toFixed(1))
|
|
330
|
+
}
|
|
331
|
+
|
|
329
332
|
if (userData.byDriver) {
|
|
330
333
|
temp.push(a.deviceName)
|
|
331
334
|
} else {
|
|
@@ -346,8 +349,21 @@ async function exportTripReportToPDF (userData, reportData) {
|
|
|
346
349
|
getSumAvgSpeed(d.trips),
|
|
347
350
|
getMaxSpeed(d.trips))
|
|
348
351
|
|
|
352
|
+
if (withFuelData) {
|
|
353
|
+
footValues.push(parseFloat(d.totalFuelConsumption).toFixed(1), parseFloat(d.avgFuelConsumption).toFixed(1))
|
|
354
|
+
}
|
|
355
|
+
|
|
349
356
|
const style = getStyle(getUserPartner(userData.user))
|
|
350
|
-
addTable(doc,
|
|
357
|
+
addTable(doc,
|
|
358
|
+
headers, data, footValues, style,
|
|
359
|
+
space + (userData.allWeek ? 40 : 45),
|
|
360
|
+
{
|
|
361
|
+
7: { halign: 'right' },
|
|
362
|
+
8: { halign: 'right' },
|
|
363
|
+
9: { halign: 'right' },
|
|
364
|
+
10: { halign: 'right' },
|
|
365
|
+
11: { halign: 'right' }
|
|
366
|
+
})
|
|
351
367
|
})
|
|
352
368
|
return doc
|
|
353
369
|
}
|
|
@@ -364,37 +380,37 @@ function exportTripReportToExcel (userData, reportData) {
|
|
|
364
380
|
sheetName: translations.report.titleTripReport, // The name of the sheet
|
|
365
381
|
fileName // The name of the spreadsheet
|
|
366
382
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
]
|
|
382
|
-
: [
|
|
383
|
-
{ label: translations.report.vehicle, value: 'name' },
|
|
384
|
-
{ label: translations.report.date, value: 'date' },
|
|
385
|
-
{ label: translations.report.start, value: 'start' },
|
|
386
|
-
{ label: translations.report.end, value: 'end' },
|
|
387
|
-
{ label: translations.report.endAddress, value: 'endAddress' },
|
|
388
|
-
{ label: translations.report.tripTime, value: 'tripTime' },
|
|
389
|
-
{ label: translations.report.idleTime, value: 'idleTime' },
|
|
390
|
-
{ label: translations.report.stopTime, value: 'stopTime' },
|
|
391
|
-
{ label: translations.report.distance, value: 'distance' },
|
|
392
|
-
{ label: translations.report.avgSpeed, value: 'averageSpeed' },
|
|
393
|
-
{ label: translations.report.maxSpeed, value: 'maxSpeed' },
|
|
394
|
-
{ label: translations.report.driver, value: 'subname' }
|
|
395
|
-
]
|
|
383
|
+
|
|
384
|
+
const headers = [
|
|
385
|
+
{ label: translations.report.date, value: 'date' },
|
|
386
|
+
{ label: translations.report.start, value: 'start' },
|
|
387
|
+
{ label: translations.report.end, value: 'end' },
|
|
388
|
+
{ label: translations.report.endAddress, value: 'endAddress' },
|
|
389
|
+
{ label: translations.report.tripTime, value: 'tripTime' },
|
|
390
|
+
{ label: translations.report.idleTime, value: 'idleTime' },
|
|
391
|
+
{ label: translations.report.stopTime, value: 'stopTime' },
|
|
392
|
+
{ label: translations.report.distance, value: 'distance' },
|
|
393
|
+
{ label: translations.report.avgSpeed, value: 'averageSpeed' },
|
|
394
|
+
{ label: translations.report.maxSpeed, value: 'maxSpeed' }
|
|
395
|
+
]
|
|
396
|
+
|
|
396
397
|
let data = []
|
|
397
398
|
if (tripsData) {
|
|
399
|
+
const withFuelData = tripsData.reduce((a, b) => a || b.totalFuelConsumption !== undefined)
|
|
400
|
+
|
|
401
|
+
if (withFuelData) {
|
|
402
|
+
headers.push({ label: translations.report.consumption, value: 'consumption' },
|
|
403
|
+
{ label: translations.report.avg_consumption, value: 'avgConsumption' })
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (userData.byDriver) {
|
|
407
|
+
headers.unshift({ label: translations.report.driver, value: 'name' })
|
|
408
|
+
headers.push({ label: translations.report.vehicle, value: 'subname' })
|
|
409
|
+
} else {
|
|
410
|
+
headers.unshift({ label: translations.report.vehicle, value: 'name' })
|
|
411
|
+
headers.push({ label: translations.report.driver, value: 'subname' })
|
|
412
|
+
}
|
|
413
|
+
|
|
398
414
|
tripsData.forEach(d => {
|
|
399
415
|
data = data.concat([{}])
|
|
400
416
|
data = data.concat(d.trips.map(a => {
|
|
@@ -410,6 +426,8 @@ function exportTripReportToExcel (userData, reportData) {
|
|
|
410
426
|
distance: Number(a.totalKms.toFixed(2)),
|
|
411
427
|
averageSpeed: Math.round(a.averageSpeed * 1.85200),
|
|
412
428
|
maxSpeed: Math.round(a.maxSpeed * 1.85200),
|
|
429
|
+
consumption: a.fuelConsumption.toFixed(1),
|
|
430
|
+
avgConsumption: a.avgFuelConsumption.toFixed(1),
|
|
413
431
|
subname: userData.byDriver ? a.deviceName : getDriverName(userData.drivers, a.driverUniqueId)
|
|
414
432
|
}
|
|
415
433
|
}))
|
|
@@ -421,7 +439,9 @@ function exportTripReportToExcel (userData, reportData) {
|
|
|
421
439
|
stopTime: convertMS(d.trips.reduce((a, b) => a + b.stopDuration, 0)),
|
|
422
440
|
distance: getSumTotalKms(userData.user, d.trips),
|
|
423
441
|
averageSpeed: getSumAvgSpeed(d.trips),
|
|
424
|
-
maxSpeed: getMaxSpeed(d.trips)
|
|
442
|
+
maxSpeed: getMaxSpeed(d.trips),
|
|
443
|
+
consumption: parseFloat(d.totalFuelConsumption).toFixed(1),
|
|
444
|
+
avgConsumption: parseFloat(d.avgFuelConsumption).toFixed(1)
|
|
425
445
|
}])
|
|
426
446
|
data = data.concat([{}])
|
|
427
447
|
})
|
package/src/util/pdfDocument.js
CHANGED
|
@@ -25,7 +25,7 @@ async function headerFromUser (doc, title, user, orientation = 'l') {
|
|
|
25
25
|
return header(doc, title, partner.host, getStyle(partner), orientation)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function addTable (doc, headers, data, footValues, style, startY) {
|
|
28
|
+
function addTable (doc, headers, data, footValues, style, startY, columnStyles = {}) {
|
|
29
29
|
doc.autoTable({
|
|
30
30
|
head: [headers],
|
|
31
31
|
body: data,
|
|
@@ -45,7 +45,17 @@ function addTable (doc, headers, data, footValues, style, startY) {
|
|
|
45
45
|
fillColor: style.pdfFooterColor,
|
|
46
46
|
textColor: style.pdfFooterTextColor,
|
|
47
47
|
fontSize: 9
|
|
48
|
+
|
|
49
|
+
},
|
|
50
|
+
didDrawCell: (data) => {
|
|
51
|
+
data.table.foot.forEach((footRow) => {
|
|
52
|
+
const keys = Object.keys(columnStyles)
|
|
53
|
+
keys.forEach(a => {
|
|
54
|
+
footRow.cells[a].styles.halign = 'right'
|
|
55
|
+
})
|
|
56
|
+
})
|
|
48
57
|
},
|
|
58
|
+
columnStyles,
|
|
49
59
|
startY
|
|
50
60
|
})
|
|
51
61
|
}
|