fleetmap-reports 1.0.469 → 1.0.471
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/lang/index.js +3 -0
- package/package.json +1 -1
- package/src/fuelconsumption-report.js +2 -3
- package/src/fueldrop-report.js +2 -3
- package/src/kms-report.js +3 -6
- package/src/machines-report.js +63 -36
- package/src/refueling-report.js +2 -3
- package/src/speeding-report.js +5 -7
- package/src/util/utils.js +3 -0
package/lang/index.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ const refuelingReport = require('./refueling-report')
|
|
|
3
3
|
const traccarHelper = require('./util/traccar')
|
|
4
4
|
const odoo = require('./util/odoo')
|
|
5
5
|
const { devicesToProcess } = require('./util/device')
|
|
6
|
-
const
|
|
6
|
+
const { getTranslations } = require('./util/utils')
|
|
7
7
|
|
|
8
8
|
async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
9
9
|
console.log('Create FuelConsumption Report')
|
|
@@ -108,8 +108,7 @@ function calculateConsumption (userData, d, day, avgConsumption, data) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
function exportFuelConsumptionReportToExcel (userData, reportData) {
|
|
111
|
-
const
|
|
112
|
-
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
111
|
+
const translations = getTranslations(userData)
|
|
113
112
|
|
|
114
113
|
const settings = {
|
|
115
114
|
sheetName: 'FuelConsumptionReport', // The name of the sheet
|
package/src/fueldrop-report.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const automaticReports = require('./automaticReports')
|
|
2
2
|
const { devicesToProcess } = require('./util/device')
|
|
3
|
-
const
|
|
3
|
+
const { getTranslations } = require('./util/utils')
|
|
4
4
|
|
|
5
5
|
function calculateFuelDrop (position, positions) {
|
|
6
6
|
const index = positions.indexOf(position)
|
|
@@ -91,8 +91,7 @@ async function createFuelDropReport (from, to, userData, traccar) {
|
|
|
91
91
|
|
|
92
92
|
function exportFuelDropReportToExcel (userData, reportData) {
|
|
93
93
|
console.log('Export to Excel')
|
|
94
|
-
const
|
|
95
|
-
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
94
|
+
const translations = getTranslations(userData)
|
|
96
95
|
|
|
97
96
|
const settings = {
|
|
98
97
|
sheetName: 'FuelDropReport', // The name of the sheet
|
package/src/kms-report.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
const messages = require('../lang')
|
|
2
1
|
const jsPDF = require('jspdf')
|
|
3
2
|
require('jspdf-autotable')
|
|
4
3
|
const { getStyle } = require('./reportStyle')
|
|
5
4
|
const { headerFromUser, addTable } = require('./util/pdfDocument')
|
|
6
5
|
const { getUserPartner } = require('fleetmap-partners')
|
|
7
6
|
const traccar = require('./util/traccar')
|
|
8
|
-
const { getDates, convertFromUTC } = require('./util/utils')
|
|
7
|
+
const { getDates, convertFromUTC, getTranslations } = require('./util/utils')
|
|
9
8
|
const trips = require('./util/trips')
|
|
10
9
|
const drivers = require('./util/driver')
|
|
11
10
|
const { isInsideTimetable, isPartialInsideTimetable, calculateTrip } = require('./util/trips')
|
|
@@ -218,8 +217,7 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
async function exportKmsReportToPDF (userData, reportData) {
|
|
221
|
-
const
|
|
222
|
-
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
220
|
+
const translations = getTranslations(userData)
|
|
223
221
|
const kmsData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
224
222
|
|
|
225
223
|
const weekDays = [
|
|
@@ -355,8 +353,7 @@ async function exportKmsReportToPDF (userData, reportData) {
|
|
|
355
353
|
function exportKmsReportToExcel (userData, reportData) {
|
|
356
354
|
console.log('Export to Excel')
|
|
357
355
|
|
|
358
|
-
const
|
|
359
|
-
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
356
|
+
const translations = getTranslations(userData)
|
|
360
357
|
|
|
361
358
|
const weekDays = [
|
|
362
359
|
translations.report.sunday,
|
package/src/machines-report.js
CHANGED
|
@@ -38,8 +38,6 @@ async function createMachinesReportByDevice (from, to, userData, traccar) {
|
|
|
38
38
|
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, false, false, false, deviceCount, devices.length)
|
|
39
39
|
const routeData = allInOne.route
|
|
40
40
|
|
|
41
|
-
console.log('Route:' + routeData.length)
|
|
42
|
-
|
|
43
41
|
if (routeData.length > 0) {
|
|
44
42
|
allData.devices.push(...processDevices(from, to, slice, {
|
|
45
43
|
route: routeData
|
|
@@ -63,41 +61,26 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
63
61
|
const convertFrom = new Date(convertFromUTC(from, userData.user.attributes.timezone))
|
|
64
62
|
const convertTo = new Date(convertFromUTC(to, userData.user.attributes.timezone))
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (p.attributes.ignition && !firstOn) {
|
|
85
|
-
firstOn = p
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
const dayData = {
|
|
90
|
-
date,
|
|
91
|
-
deviceId: d.id,
|
|
92
|
-
engineHours: firstOn ? routeByDay[routeByDay.length - 1].attributes.hours - routeByDay[0].attributes.hours : 0,
|
|
93
|
-
totalHours: routeByDay.length ? routeByDay[routeByDay.length - 1].attributes.hours : undefined,
|
|
94
|
-
startTime: firstOn ? firstOn.fixTime : undefined,
|
|
95
|
-
endTime: lastOff ? lastOff.fixTime : undefined
|
|
64
|
+
if (userData.withDetails) {
|
|
65
|
+
const ignitions = calculateIgnitions(deviceRoute)
|
|
66
|
+
for (const ignition of ignitions) {
|
|
67
|
+
const dayData = getSummaryData(new Date(ignition.on.fixTime), d, ignition.route, ignition.on, ignition.off)
|
|
68
|
+
summary.push(dayData)
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
const dates = getDates(convertFrom, convertTo)
|
|
72
|
+
for (const date of dates) {
|
|
73
|
+
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
74
|
+
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
75
|
+
|
|
76
|
+
const routeByDay = deviceRoute.filter(p => (new Date(p.fixTime) > fromByDay && new Date(p.fixTime) < toByDay) && p.valid && p.attributes.hours !== undefined)
|
|
77
|
+
routeByDay.sort((a, b) => new Date(a.fixTime).getTime() - new Date(b.fixTime).getTime())
|
|
78
|
+
|
|
79
|
+
const ignitions = calculateIgnitions(routeByDay)
|
|
80
|
+
const dayData = getSummaryData(date, d, routeByDay, ignitions.length ? ignitions[0].on : undefined, ignitions.length ? ignitions[ignitions.length - 1].off : undefined)
|
|
81
|
+
summary.push(dayData)
|
|
96
82
|
}
|
|
97
|
-
|
|
98
|
-
summary.push(dayData)
|
|
99
83
|
}
|
|
100
|
-
|
|
101
84
|
if (summary.length) {
|
|
102
85
|
const deviceData = {
|
|
103
86
|
device: d,
|
|
@@ -111,6 +94,50 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
111
94
|
return devicesResult
|
|
112
95
|
}
|
|
113
96
|
|
|
97
|
+
function getSummaryData (date, device, route, start, end) {
|
|
98
|
+
return {
|
|
99
|
+
date,
|
|
100
|
+
deviceId: device.id,
|
|
101
|
+
engineHours: start ? route[route.length - 1].attributes.hours - route[0].attributes.hours : undefined,
|
|
102
|
+
totalHours: route.length ? route[route.length - 1].attributes.hours : undefined,
|
|
103
|
+
startTime: start ? start.fixTime : undefined,
|
|
104
|
+
endTime: end ? end.fixTime : undefined
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function calculateIgnitions (routeOfDay) {
|
|
109
|
+
let indexStart
|
|
110
|
+
let last
|
|
111
|
+
const ignitions = []
|
|
112
|
+
routeOfDay.forEach((p, index) => {
|
|
113
|
+
// difference between last position and current position is bigger than 5 minutes
|
|
114
|
+
if ((last && last.attributes.ignition && (new Date(p.fixTime).getTime() - new Date(last.fixTime).getTime()) > 300000) &&
|
|
115
|
+
ignitions.length &&
|
|
116
|
+
!ignitions[ignitions.length - 1].off) {
|
|
117
|
+
ignitions[ignitions.length - 1].off = last
|
|
118
|
+
ignitions[ignitions.length - 1].route = routeOfDay.slice(indexStart, index)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (p.attributes.ignition && (!ignitions.length || ignitions[ignitions.length - 1].off)) {
|
|
122
|
+
ignitions.push({ on: p })
|
|
123
|
+
indexStart = index
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ignition is off
|
|
127
|
+
// or is last route position
|
|
128
|
+
if ((!p.attributes.ignition || index + 1 === routeOfDay.length) &&
|
|
129
|
+
ignitions.length &&
|
|
130
|
+
!ignitions[ignitions.length - 1].off) {
|
|
131
|
+
ignitions[ignitions.length - 1].off = p
|
|
132
|
+
ignitions[ignitions.length - 1].route = (index + 1) === routeOfDay.length ? routeOfDay.slice(indexStart) : routeOfDay.slice(indexStart, index + 1)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
last = p
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
return ignitions
|
|
139
|
+
}
|
|
140
|
+
|
|
114
141
|
async function exportMachinesReportToPDF (userData, reportData) {
|
|
115
142
|
const doc = new jsPDF.jsPDF('l')
|
|
116
143
|
const translations = getTranslations(userData)
|
|
@@ -163,7 +190,7 @@ async function exportMachinesReportToPDF (userData, reportData) {
|
|
|
163
190
|
|
|
164
191
|
const footValues = ['',
|
|
165
192
|
'', '',
|
|
166
|
-
convertMS(d.summary.reduce((a, b) => a + b.engineHours, 0))]
|
|
193
|
+
convertMS(d.summary.reduce((a, b) => a + (b.engineHours || 0), 0))]
|
|
167
194
|
|
|
168
195
|
const style = getStyle(getUserPartner(userData.user))
|
|
169
196
|
addTable(doc, headers, data, footValues, style, 40)
|
package/src/refueling-report.js
CHANGED
|
@@ -2,7 +2,7 @@ const helpers = require('@turf/helpers')
|
|
|
2
2
|
const automaticReports = require('./automaticReports')
|
|
3
3
|
const { devicesToProcess } = require('./util/device')
|
|
4
4
|
const distance = require('@turf/distance')
|
|
5
|
-
const
|
|
5
|
+
const { getTranslations } = require('./util/utils')
|
|
6
6
|
|
|
7
7
|
const positionsToCheck = 15
|
|
8
8
|
|
|
@@ -178,8 +178,7 @@ async function calculateRefuelingPositions (userData, d, data) {
|
|
|
178
178
|
|
|
179
179
|
function exportRefuelingReportToExcel (userData, reportData) {
|
|
180
180
|
console.log('Export to Excel')
|
|
181
|
-
const
|
|
182
|
-
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
181
|
+
const translations = getTranslations(userData)
|
|
183
182
|
|
|
184
183
|
const settings = {
|
|
185
184
|
sheetName: 'RefuelingReport', // The name of the sheet
|
package/src/speeding-report.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const messages = require('../lang')
|
|
2
1
|
const jsPDF = require('jspdf')
|
|
3
|
-
const { convertMS, convertToLocaleString, convertToFeature, convertPositionToFeature } = require('./util/utils')
|
|
2
|
+
const { convertMS, convertToLocaleString, convertToFeature, convertPositionToFeature, getTranslations } = require('./util/utils')
|
|
4
3
|
const { headerFromUser, AmiriRegular } = require('./util/pdfDocument')
|
|
5
4
|
require('jspdf-autotable')
|
|
6
5
|
const { getStyle } = require('./reportStyle')
|
|
@@ -353,10 +352,10 @@ function calculateEventData (positions, pIndex, alert, device, geofence, userDat
|
|
|
353
352
|
|
|
354
353
|
async function exportSpeedingReportToPDF (userData, reportData) {
|
|
355
354
|
console.log('Export to PDF')
|
|
355
|
+
const lang = userData.user.attributes.lang || (navigator && navigator.language)
|
|
356
356
|
|
|
357
|
-
const lang = userData.user.attributes.lang
|
|
358
357
|
const timezone = userData.user.attributes.timezone
|
|
359
|
-
const translations =
|
|
358
|
+
const translations = getTranslations(userData)
|
|
360
359
|
|
|
361
360
|
const overspeedData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
362
361
|
|
|
@@ -479,9 +478,8 @@ async function exportSpeedingReportToPDF (userData, reportData) {
|
|
|
479
478
|
function exportSpeedingReportToExcel (userData, reportData) {
|
|
480
479
|
console.log('Export to Excel')
|
|
481
480
|
|
|
482
|
-
const lang = userData.user.attributes.lang
|
|
483
|
-
const translations =
|
|
484
|
-
|
|
481
|
+
const lang = userData.user.attributes.lang || (navigator && navigator.language)
|
|
482
|
+
const translations = getTranslations(userData)
|
|
485
483
|
const overspeedData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
486
484
|
|
|
487
485
|
const settings = {
|
package/src/util/utils.js
CHANGED
|
@@ -6,6 +6,9 @@ const distance = require('@turf/distance')
|
|
|
6
6
|
|
|
7
7
|
exports.getTranslations = (userData) => {
|
|
8
8
|
const lang = userData.user.attributes.lang || (navigator && navigator.language)
|
|
9
|
+
if (!messages[lang]) {
|
|
10
|
+
console.warn('no lang found for', userData.user, userData.user.attributes.lang, navigator && navigator.language)
|
|
11
|
+
}
|
|
9
12
|
return messages[lang] ? messages[lang] : messages['en-GB']
|
|
10
13
|
}
|
|
11
14
|
|