fleetmap-reports 2.0.54 → 2.0.56
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 +8 -1
- package/src/kms-report.js +2 -2
- package/src/tests/activity.test.js +24 -0
- package/src/util/timetable.js +15 -15
- package/src/util/trips.js +2 -2
- package/src/util/utils.js +6 -0
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -171,7 +171,14 @@ async function processDevices (from, to, devices, data, userData, traccarInstanc
|
|
|
171
171
|
|
|
172
172
|
const summary = []
|
|
173
173
|
if (userData.groupByDay) {
|
|
174
|
-
const trips =
|
|
174
|
+
const trips = []
|
|
175
|
+
for (const t of deviceTrips) {
|
|
176
|
+
const isInside = isInsideTimetable(t, userData)
|
|
177
|
+
const isPartialInside = await isPartialInsideTimetable(t, userData, deviceRoute)
|
|
178
|
+
if (userData.allWeek || !userData.weekDays || isInside || isPartialInside) {
|
|
179
|
+
trips.push(t)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
175
182
|
const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
|
|
176
183
|
for (const date of dates) {
|
|
177
184
|
const { tripsByDay, routeByDay } = await getDataByDay(d, date, { trips, route: deviceRoute }, userData, traccarInstance)
|
package/src/kms-report.js
CHANGED
|
@@ -44,8 +44,8 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (isClientSide() && (allDevices.length > 50 || ((new Date(to).getTime() - new Date(from).getTime()) > (1000 * 60 * 60 * 24 * 15))) && userData.groupByDay) {
|
|
47
|
-
const sliced = automaticReports.sliceArray(allDevices,
|
|
48
|
-
await executeServerSide('kms-report', sliced, from, to, userData, allDevices.length, traccarInstance
|
|
47
|
+
const sliced = automaticReports.sliceArray(allDevices, 1)
|
|
48
|
+
await executeServerSide('kms-report', sliced, from, to, userData, allDevices.length, traccarInstance).then(devices => {
|
|
49
49
|
allData.devices = devices
|
|
50
50
|
})
|
|
51
51
|
} else {
|
|
@@ -72,4 +72,28 @@ describe('activity report', function () {
|
|
|
72
72
|
console.log(device)
|
|
73
73
|
assert.equal(device.summary.reduce((a, b) => a + b.convertedSpentFuel, 0), 168.79999999999995)
|
|
74
74
|
}, 800000)
|
|
75
|
+
// eslint-disable-next-line no-undef
|
|
76
|
+
it('works with timetable', async () => {
|
|
77
|
+
const report = await getReports()
|
|
78
|
+
const userData = await report.getUserData()
|
|
79
|
+
userData.groupByDay = true
|
|
80
|
+
userData.allWeek = false
|
|
81
|
+
userData.weekDays = {
|
|
82
|
+
sunday: true,
|
|
83
|
+
monday: true,
|
|
84
|
+
tuesday: true,
|
|
85
|
+
wednesday: true,
|
|
86
|
+
thursday: true,
|
|
87
|
+
friday: true,
|
|
88
|
+
saturday: true
|
|
89
|
+
}
|
|
90
|
+
userData.dayHours = {
|
|
91
|
+
startTime: '22:00',
|
|
92
|
+
endTime: '05:00'
|
|
93
|
+
}
|
|
94
|
+
const data = await report.activityReport(new Date(2024, 1, 1, 0, 0, 0, 0),
|
|
95
|
+
new Date(2024, 1, 28, 23, 59, 59, 0),
|
|
96
|
+
userData)
|
|
97
|
+
assert.equal(data.length, 1)
|
|
98
|
+
}, 800000)
|
|
75
99
|
})
|
package/src/util/timetable.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
const { weekDaySelected, convertFromUTC, isClientSide, convertFromLocal } = require('./utils')
|
|
2
2
|
|
|
3
|
-
function isInside (
|
|
4
|
-
const tripStart = new Date(
|
|
5
|
-
const tripEnd = new Date(
|
|
3
|
+
function isInside (_tripStart, _tripEnd, userData) {
|
|
4
|
+
const tripStart = new Date(_tripStart)
|
|
5
|
+
const tripEnd = new Date(_tripEnd)
|
|
6
6
|
|
|
7
7
|
if (weekDaySelected(tripStart, userData.weekDays)) {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const timeWindowStartLocal = new Date(convertFromUTC(_tripStart, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
|
|
9
|
+
const timeWindowEndLocal = new Date(convertFromUTC(_tripEnd, userData.user.attributes.timezone).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const timeWindowStartUTC = isClientSide() ? timeWindowStartLocal : convertFromLocal(timeWindowStartLocal, userData.user.attributes.timezone)
|
|
12
|
+
const timeWindowEndUTC = isClientSide() ? timeWindowEndLocal : convertFromLocal(timeWindowEndLocal, userData.user.attributes.timezone)
|
|
13
13
|
|
|
14
|
-
if (
|
|
15
|
-
const startDatePreviousDay = new Date(
|
|
16
|
-
startDatePreviousDay.setDate(
|
|
17
|
-
const endDateNextDay = new Date(
|
|
18
|
-
endDateNextDay.setDate(
|
|
14
|
+
if (timeWindowStartUTC.getTime() > timeWindowEndUTC.getTime()) {
|
|
15
|
+
const startDatePreviousDay = new Date(timeWindowStartUTC)
|
|
16
|
+
startDatePreviousDay.setDate(timeWindowStartUTC.getDate() - 1)
|
|
17
|
+
const endDateNextDay = new Date(timeWindowEndUTC)
|
|
18
|
+
endDateNextDay.setDate(timeWindowEndUTC.getDate() + 1)
|
|
19
19
|
|
|
20
|
-
return (tripStart.getTime() > startDatePreviousDay.getTime() && tripEnd.getTime() <
|
|
21
|
-
(tripStart.getTime() >
|
|
20
|
+
return (tripStart.getTime() > startDatePreviousDay.getTime() && tripEnd.getTime() < timeWindowEndUTC.getTime()) ||
|
|
21
|
+
(tripStart.getTime() > timeWindowStartUTC.getTime() && tripEnd.getTime() < endDateNextDay.getTime())
|
|
22
22
|
}
|
|
23
23
|
// Trips inside time period
|
|
24
|
-
return tripStart.getTime() >
|
|
24
|
+
return tripStart.getTime() > timeWindowStartUTC.getTime() && tripEnd.getTime() < timeWindowEndUTC.getTime()
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
return false
|
package/src/util/trips.js
CHANGED
|
@@ -111,8 +111,8 @@ function isPartialInsideTimetable (t, userData, route) {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
async function getDataByDay (device, date, data, userData, traccarInstance) {
|
|
114
|
-
const startDateLocal = new Date(convertFromUTC(date, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '
|
|
115
|
-
const endDateLocal = new Date(convertFromUTC(date, userData.user.attributes.timezone).toISOString().split('T')[0] + ' '
|
|
114
|
+
const startDateLocal = new Date(convertFromUTC(date, userData.user.attributes.timezone).toISOString().split('T')[0] + ' 00:00:00')
|
|
115
|
+
const endDateLocal = new Date(convertFromUTC(date, userData.user.attributes.timezone).toISOString().split('T')[0] + ' 23:59:59')
|
|
116
116
|
const startDate = isClientSide() ? startDateLocal : convertFromLocal(startDateLocal, userData.user.attributes.timezone)
|
|
117
117
|
const endDate = isClientSide() ? endDateLocal : convertFromLocal(endDateLocal, userData.user.attributes.timezone)
|
|
118
118
|
|
package/src/util/utils.js
CHANGED
|
@@ -265,6 +265,12 @@ async function executeServerSide (type, sliced, from, to, userData, totalItems,
|
|
|
265
265
|
}))
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
if (userData.byDriver) {
|
|
269
|
+
reportData.sort((a, b) => (a.driver.name > b.driver.name) ? 1 : -1)
|
|
270
|
+
} else {
|
|
271
|
+
reportData.sort((a, b) => (a.device.name > b.device.name) ? 1 : -1)
|
|
272
|
+
}
|
|
273
|
+
|
|
268
274
|
return reportData
|
|
269
275
|
}
|
|
270
276
|
|