fleetmap-reports 1.0.325 → 1.0.329
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 +2 -1
- package/src/activity-report.js +1 -1
- package/src/kms-report.js +14 -11
- package/src/speeding-report.js +6 -6
- package/src/trip-report.js +6 -5
- package/src/util/trips.js +22 -19
- package/src/util/utils.js +20 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.329",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"axios": "^0.21.1",
|
|
14
14
|
"axios-cookiejar-support": "^1.0.1",
|
|
15
15
|
"docx": "^7.3.0",
|
|
16
|
+
"eslint": "^8.8.0",
|
|
16
17
|
"file-saver": "^2.0.5",
|
|
17
18
|
"fleetmap-partners": "^1.0.42",
|
|
18
19
|
"json-as-xlsx": "^1.2.1",
|
package/src/activity-report.js
CHANGED
|
@@ -65,7 +65,7 @@ async function createActivityReportByGroup(from, to, userData, traccarInstance){
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const withoutGroupDevices = await createActivityReportByDevice(from, to)
|
|
68
|
+
const withoutGroupDevices = await createActivityReportByDevice(from, to, userData, traccarInstance)
|
|
69
69
|
reportData.push(withoutGroupDevices)
|
|
70
70
|
|
|
71
71
|
return reportData
|
package/src/kms-report.js
CHANGED
|
@@ -5,11 +5,10 @@ const {getStyle} = require("./reportStyle")
|
|
|
5
5
|
const {headerFromUser,addTable} = require("./util/pdfDocument")
|
|
6
6
|
const {getUserPartner} = require("fleetmap-partners")
|
|
7
7
|
const traccar = require("./util/traccar")
|
|
8
|
-
const {getDates} = require("./util/utils")
|
|
8
|
+
const {getDates, convertFromUTC} = require("./util/utils")
|
|
9
9
|
const trips = require("./util/trips")
|
|
10
10
|
const drivers = require("./util/driver")
|
|
11
11
|
const { isInsideTimetable, isPartialInsideTimetable} = require("./util/trips")
|
|
12
|
-
const word = require("./word");
|
|
13
12
|
|
|
14
13
|
const fileName = 'KmsReport'
|
|
15
14
|
|
|
@@ -47,7 +46,7 @@ async function createKmsReportByDevice(from, to, userData, traccarInstance) {
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
50
|
-
const route =
|
|
49
|
+
const route = await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
|
|
51
50
|
const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
|
|
52
51
|
|
|
53
52
|
console.log('trips:' + tripsData.length)
|
|
@@ -70,7 +69,7 @@ async function createKmsReportByDriver(from, to, userData, traccarInstance) {
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
const tripsData = await traccar.getTrips(traccarInstance, from, to, devices)
|
|
73
|
-
const routeData = await traccar.
|
|
72
|
+
const routeData = await traccar.getRoute(traccarInstance, from, to, devices)
|
|
74
73
|
|
|
75
74
|
return { drivers: processDrivers(from, to, userData, {trips: tripsData, route: routeData}) }
|
|
76
75
|
}
|
|
@@ -157,7 +156,7 @@ function processDevices(from, to, devices, data, userData) {
|
|
|
157
156
|
|
|
158
157
|
if (deviceTrips.length > 0) {
|
|
159
158
|
if(userData.groupByDay) {
|
|
160
|
-
deviceTrips.forEach(t => t.tripDay =
|
|
159
|
+
deviceTrips.forEach(t => t.tripDay = convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' 12:00 PM')
|
|
161
160
|
const groupedTrips = deviceTrips.reduce(
|
|
162
161
|
(entryMap, e) => entryMap.set(e.tripDay, [...entryMap.get(e.tripDay)||[], e]),
|
|
163
162
|
new Map()
|
|
@@ -411,11 +410,16 @@ function exportKmsReportToExcel(userData, reportData) {
|
|
|
411
410
|
}
|
|
412
411
|
})
|
|
413
412
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
413
|
+
// add total
|
|
414
|
+
if (data.length) {
|
|
415
|
+
data = data.concat({
|
|
416
|
+
name: '',
|
|
417
|
+
group: '',
|
|
418
|
+
licenseplate: 'Total',
|
|
419
|
+
distance: data.reduce((prev, curr) => curr.distance ? {distance: (prev.distance || 0) + curr.distance} : prev).distance
|
|
420
|
+
})
|
|
421
|
+
}
|
|
422
|
+
|
|
419
423
|
return {
|
|
420
424
|
headers,
|
|
421
425
|
data,
|
|
@@ -426,4 +430,3 @@ function exportKmsReportToExcel(userData, reportData) {
|
|
|
426
430
|
exports.createKmsReport = createKmsReport
|
|
427
431
|
exports.exportKmsReportToPDF = exportKmsReportToPDF
|
|
428
432
|
exports.exportKmsReportToExcel = exportKmsReportToExcel
|
|
429
|
-
exports.exportKmsReportToWord = word.exportKmsReportToWord
|
package/src/speeding-report.js
CHANGED
|
@@ -29,7 +29,7 @@ async function createSpeedingReport(from, to, userData, traccarInstance) {
|
|
|
29
29
|
reportData.push(...allData)
|
|
30
30
|
} else {
|
|
31
31
|
console.log("createSpeedingReportByDevice")
|
|
32
|
-
const allData = await createSpeedingReportByDevice(from, to, userData
|
|
32
|
+
const allData = await createSpeedingReportByDevice(from, to, userData, traccarInstance)
|
|
33
33
|
reportData.push(allData)
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -60,16 +60,16 @@ async function createSpeedingReportByGroup(from, to, userData, traccarInstance){
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const
|
|
64
|
-
const withoutGroupDevices = userData.devices.filter(d => !groupIds.includes(d.groupId))
|
|
65
|
-
|
|
66
|
-
const withoutGroupData = await createSpeedingReportByDevice(from, to, withoutGroupDevices, userData, traccarInstance)
|
|
63
|
+
const withoutGroupData = await createSpeedingReportByDevice(from, to, userData, traccarInstance)
|
|
67
64
|
reportData.push(withoutGroupData)
|
|
68
65
|
|
|
69
66
|
return reportData
|
|
70
67
|
}
|
|
71
68
|
|
|
72
|
-
async function createSpeedingReportByDevice(from, to,
|
|
69
|
+
async function createSpeedingReportByDevice(from, to, userData, traccarInstance) {
|
|
70
|
+
const groupIds = userData.groups.map(g => g.id)
|
|
71
|
+
const devices = userData.devices.filter(d => !groupIds.includes(d.groupId))
|
|
72
|
+
|
|
73
73
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
74
74
|
|
|
75
75
|
const routes = await traccarHelper.getRoute(traccarInstance, from, to, devices)
|
package/src/trip-report.js
CHANGED
|
@@ -36,7 +36,9 @@ async function createTripReport(from, to, userData, traccar) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
async function createTripReportByDevice(from, to, userData, traccar) {
|
|
39
|
-
const
|
|
39
|
+
const groupIds = userData.groups.map(g => g.id)
|
|
40
|
+
const devices = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
41
|
+
|
|
40
42
|
const allData = {
|
|
41
43
|
devices: [],
|
|
42
44
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
@@ -91,10 +93,7 @@ async function createTripReportByGroup(from, to, userData, traccar) {
|
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
const
|
|
95
|
-
const withoutGroupDevices = userData.devices.filter(d => !groupIds.includes(d.groupId))
|
|
96
|
-
|
|
97
|
-
const allData = await createTripReportByDevice(from, to, withoutGroupDevices, userData)
|
|
96
|
+
const allData = await createTripReportByDevice(from, to, userData, traccar)
|
|
98
97
|
reportData.push(allData)
|
|
99
98
|
|
|
100
99
|
return reportData
|
|
@@ -124,6 +123,8 @@ function processDevices(from, to, devices, data, userData) {
|
|
|
124
123
|
&& (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|
|
125
124
|
const stops = data.stops.filter(s => s.deviceId === d.id)
|
|
126
125
|
|
|
126
|
+
console.log(trips)
|
|
127
|
+
|
|
127
128
|
addNearestPOIs(trips, userData)
|
|
128
129
|
|
|
129
130
|
trips.forEach(trip => {
|
package/src/util/trips.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {coordsDistance} = require("./utils");
|
|
1
|
+
const {coordsDistance, convertFromUTC} = require("./utils");
|
|
2
2
|
|
|
3
3
|
const minDistance = 0
|
|
4
4
|
const minAvgSpeed = 0
|
|
@@ -41,7 +41,9 @@ function checkTripsKms(traccarInstance, from, to, devices, data) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function isPartialInsideTimetable(t, userData, route){
|
|
44
|
-
const tripStart
|
|
44
|
+
const tripStart = new Date(t.startTime)
|
|
45
|
+
const tripEnd = new Date(t.endTime)
|
|
46
|
+
|
|
45
47
|
let isPartialInside = false
|
|
46
48
|
|
|
47
49
|
if((tripStart.getDay() === 0 && userData.weekDays.sunday) ||
|
|
@@ -52,22 +54,22 @@ function isPartialInsideTimetable(t, userData, route){
|
|
|
52
54
|
(tripStart.getDay() === 5 && userData.weekDays.friday) ||
|
|
53
55
|
(tripStart.getDay() === 6 && userData.weekDays.saturday)) {
|
|
54
56
|
|
|
55
|
-
const startDate = new Date(
|
|
56
|
-
const endDate = new Date(
|
|
57
|
+
const startDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
|
|
58
|
+
const endDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
|
|
57
59
|
|
|
58
60
|
if(startDate.getTime() > endDate.getTime()){
|
|
59
61
|
//Trip starts outside time period and ends inside time period
|
|
60
|
-
if (
|
|
61
|
-
&&
|
|
62
|
+
if (tripStart.getTime() < endDate.getTime()
|
|
63
|
+
&& tripEnd.getTime() > endDate.getTime()) {
|
|
62
64
|
//Trip starts inside time period and ends outside time period
|
|
63
|
-
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)
|
|
65
|
+
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)
|
|
64
66
|
updateTrip(t, routeInside)
|
|
65
67
|
t.endTime = endDate.toISOString()
|
|
66
68
|
t.endTimeIsOut = true
|
|
67
69
|
isPartialInside = true
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
if (
|
|
72
|
+
if (tripStart.getTime() < startDate.getTime()
|
|
71
73
|
&& new Date(t.endTime).getTime() > startDate.getTime()) {
|
|
72
74
|
|
|
73
75
|
//Trip starts outside time period and ends inside time period
|
|
@@ -79,18 +81,18 @@ function isPartialInsideTimetable(t, userData, route){
|
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
} else {
|
|
82
|
-
if (
|
|
83
|
-
&&
|
|
84
|
+
if (tripStart.getTime() < startDate.getTime()
|
|
85
|
+
&& tripEnd.getTime() > startDate.getTime()) {
|
|
84
86
|
//Trip starts outside time period and ends inside time period
|
|
85
|
-
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)
|
|
87
|
+
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)
|
|
86
88
|
updateTrip(t, routeInside)
|
|
87
89
|
t.startTime = startDate.toISOString()
|
|
88
90
|
t.startTimeIsOut = true
|
|
89
91
|
isPartialInside = true
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
if (
|
|
93
|
-
&&
|
|
94
|
+
if (tripStart.getTime() < endDate.getTime()
|
|
95
|
+
&& tripEnd.getTime() > endDate.getTime()) {
|
|
94
96
|
//Trip starts inside time period and ends outside time period
|
|
95
97
|
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)
|
|
96
98
|
updateTrip(t, routeInside)
|
|
@@ -104,9 +106,10 @@ function isPartialInsideTimetable(t, userData, route){
|
|
|
104
106
|
return isPartialInside
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
|
|
107
110
|
function isInsideTimetable(t, userData){
|
|
108
|
-
const tripStart
|
|
109
|
-
const tripEnd
|
|
111
|
+
const tripStart = new Date(t.startTime)
|
|
112
|
+
const tripEnd = new Date(t.endTime)
|
|
110
113
|
|
|
111
114
|
if((tripStart.getDay() === 0 && userData.weekDays.sunday) ||
|
|
112
115
|
(tripStart.getDay() === 1 && userData.weekDays.monday) ||
|
|
@@ -116,13 +119,12 @@ function isInsideTimetable(t, userData){
|
|
|
116
119
|
(tripStart.getDay() === 5 && userData.weekDays.friday) ||
|
|
117
120
|
(tripStart.getDay() === 6 && userData.weekDays.saturday)) {
|
|
118
121
|
|
|
119
|
-
const startDate = new Date(
|
|
120
|
-
const endDate = new Date(
|
|
121
|
-
|
|
122
|
-
console.log(tripStart, startDate, endDate)
|
|
122
|
+
const startDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
|
|
123
|
+
const endDate = new Date(convertFromUTC(t.startTime, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
|
|
123
124
|
|
|
124
125
|
//Trips inside time period
|
|
125
126
|
if(startDate.getTime() < endDate.getTime()) {
|
|
127
|
+
console.log((tripStart.getTime() > startDate.getTime() && tripEnd.getTime() < endDate.getTime()))
|
|
126
128
|
return tripStart.getTime() > startDate.getTime() && tripEnd.getTime() < endDate.getTime()
|
|
127
129
|
} else {
|
|
128
130
|
return (tripStart.getTime() < endDate.getTime() && tripEnd.getTime() < endDate.getTime()) ||
|
|
@@ -134,6 +136,7 @@ function isInsideTimetable(t, userData){
|
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
function updateTrip(t, route){
|
|
139
|
+
if (!route[route.length-1]) { return }
|
|
137
140
|
const distance = route[route.length-1].attributes.totalDistance - route[0].attributes.totalDistance
|
|
138
141
|
t.distance = distance
|
|
139
142
|
t.duration = new Date(route[route.length-1].fixTime).getTime() - new Date(route[0].fixTime).getTime()
|
package/src/util/utils.js
CHANGED
|
@@ -112,6 +112,24 @@ function convertToLocaleTimeString(value, lang, timezone){
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
function getTimezoneOffset(timezone){
|
|
116
|
+
if(isClientSide){
|
|
117
|
+
return new Date().getTimezoneOffset()
|
|
118
|
+
} else {
|
|
119
|
+
const utcDate = new Date(new Date().toLocaleString('en-US', { timeZone: 'UTC' }))
|
|
120
|
+
const tzDate = new Date(new Date().toLocaleString('en-US', { timeZone: timezone }))
|
|
121
|
+
return (utcDate.getTime() - tzDate.getTime()) / 6e4
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function convertFromUTC(value, timezone) {
|
|
126
|
+
const offset = getTimezoneOffset(timezone)
|
|
127
|
+
|
|
128
|
+
const valueDate = new Date(value)
|
|
129
|
+
valueDate.setTime(valueDate.getTime() - (offset * 60 * 1000))
|
|
130
|
+
return valueDate
|
|
131
|
+
}
|
|
132
|
+
|
|
115
133
|
exports.getImgFromUrl = getImgFromUrl
|
|
116
134
|
exports.convertMS = convertMS
|
|
117
135
|
exports.coordsDistance = coordsDistance
|
|
@@ -120,6 +138,8 @@ exports.convertToLocaleString = convertToLocaleString
|
|
|
120
138
|
exports.convertToLocaleDateString = convertToLocaleDateString
|
|
121
139
|
exports.convertToLocaleTimeString = convertToLocaleTimeString
|
|
122
140
|
exports.isClientSide = isClientSide
|
|
141
|
+
exports.getTimezoneOffset = getTimezoneOffset
|
|
142
|
+
exports.convertFromUTC = convertFromUTC
|
|
123
143
|
exports.getLogo = (user) => {
|
|
124
144
|
const host = window ? window.location.hostname : getUserPartner(user).host
|
|
125
145
|
return getImage(getLogoUrl(host))
|