fleetmap-reports 1.0.299 → 1.0.303
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/.idea/jsLibraryMappings.xml +1 -1
- package/.idea/modules.xml +1 -1
- package/.idea/vcs.xml +1 -1
- package/{.idea/fleetmap-reports.iml → fleetmap-reports.iml} +1 -2
- package/package.json +3 -1
- package/src/activity-report.js +30 -2
- package/src/idle-report.js +4 -2
- package/src/index.js +3 -0
- package/src/kms-report.js +31 -76
- package/src/speeding-report.js +5 -3
- package/src/trip-report.js +27 -18
- package/src/util/trips.js +76 -5
- package/src/word/index.js +27 -0
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -7
package/.idea/modules.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ProjectModuleManager">
|
|
4
4
|
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/fleetmap-reports.iml" filepath="$PROJECT_DIR$/fleetmap-reports.iml" />
|
|
6
6
|
</modules>
|
|
7
7
|
</component>
|
|
8
8
|
</project>
|
package/.idea/vcs.xml
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
3
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
4
|
<exclude-output />
|
|
5
5
|
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
6
|
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
7
|
</component>
|
|
9
8
|
</module>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.303",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"axios": "^0.21.1",
|
|
14
14
|
"axios-cookiejar-support": "^1.0.1",
|
|
15
|
+
"docx": "^7.3.0",
|
|
16
|
+
"file-saver": "^2.0.5",
|
|
15
17
|
"fleetmap-partners": "^1.0.42",
|
|
16
18
|
"json-as-xlsx": "^1.2.1",
|
|
17
19
|
"jspdf": "^2.3.1",
|
package/src/activity-report.js
CHANGED
|
@@ -10,7 +10,8 @@ const {getUserPartner} = require("fleetmap-partners")
|
|
|
10
10
|
const traccar = require("./util/traccar")
|
|
11
11
|
const {createKmsReport} = require("./kms-report");
|
|
12
12
|
const {isInsideTimetable} = require("./util/trips");
|
|
13
|
-
|
|
13
|
+
const { Document, Packer, Paragraph, TextRun } = require("docx")
|
|
14
|
+
import { saveAs } from "file-saver"
|
|
14
15
|
let traccarInstance
|
|
15
16
|
let userData
|
|
16
17
|
|
|
@@ -179,7 +180,6 @@ async function createActivityReportByDriver(from, to){
|
|
|
179
180
|
return allData
|
|
180
181
|
}
|
|
181
182
|
|
|
182
|
-
|
|
183
183
|
function processDevices(devices, data, kmsReport) {
|
|
184
184
|
const devicesResult = []
|
|
185
185
|
|
|
@@ -267,6 +267,34 @@ async function exportActivityReportToPDF(userData, reportData) {
|
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
function exportActivityReportToWord(userData, reportData) {
|
|
271
|
+
const doc = new Document({
|
|
272
|
+
sections: [{
|
|
273
|
+
properties: {},
|
|
274
|
+
children: [
|
|
275
|
+
new Paragraph({
|
|
276
|
+
children: [
|
|
277
|
+
new TextRun("Hello World"),
|
|
278
|
+
new TextRun({
|
|
279
|
+
text: "Foo Bar",
|
|
280
|
+
bold: true,
|
|
281
|
+
}),
|
|
282
|
+
new TextRun({
|
|
283
|
+
text: "\tGithub is the best",
|
|
284
|
+
bold: true,
|
|
285
|
+
}),
|
|
286
|
+
],
|
|
287
|
+
}),
|
|
288
|
+
],
|
|
289
|
+
}],
|
|
290
|
+
})
|
|
291
|
+
Packer.toBlob(doc).then(blob => {
|
|
292
|
+
console.log(blob);
|
|
293
|
+
saveAs(blob, "example.docx");
|
|
294
|
+
console.log("Document created successfully");
|
|
295
|
+
})
|
|
296
|
+
}
|
|
297
|
+
|
|
270
298
|
function exportActivityReportToPDF_Driver(doc, translations, reportData) {
|
|
271
299
|
const headers = [translations.report.driver,
|
|
272
300
|
translations.report.distance,
|
package/src/idle-report.js
CHANGED
|
@@ -193,8 +193,10 @@ async function exportIdleReportToPDF(userData, reportData) {
|
|
|
193
193
|
footValues.splice(2, 0, '')
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
if(timezone === 'Asia/Qatar') {
|
|
197
|
+
doc.addFileToVFS("Amiri-Regular.ttf", AmiriRegular());
|
|
198
|
+
doc.addFont("Amiri-Regular.ttf", "Amiri", "normal");
|
|
199
|
+
}
|
|
198
200
|
|
|
199
201
|
const style = getStyle(getUserPartner(userData.user))
|
|
200
202
|
doc.autoTable({
|
package/src/index.js
CHANGED
|
@@ -40,6 +40,9 @@ function Reports(config, axios) {
|
|
|
40
40
|
this.tripReportToExcel = (userData, reportData) => {
|
|
41
41
|
return require('./trip-report').exportTripReportToExcel(userData, reportData)
|
|
42
42
|
}
|
|
43
|
+
this.tripReportToWord = (userData, reportData) => {
|
|
44
|
+
return require('./trip-report').exportTripReportToWord(userData, reportData)
|
|
45
|
+
}
|
|
43
46
|
|
|
44
47
|
this.zoneReport = (from, to, userData) => {
|
|
45
48
|
return require('./zone-report').createZoneReport(from, to, userData, this.traccar)
|
package/src/kms-report.js
CHANGED
|
@@ -8,7 +8,7 @@ const traccar = require("./util/traccar");
|
|
|
8
8
|
const {getDates} = require("./util/utils");
|
|
9
9
|
const trips = require("./util/trips");
|
|
10
10
|
const drivers = require("./util/driver");
|
|
11
|
-
const {isInsideTimetable} = require("./util/trips");
|
|
11
|
+
const { isInsideTimetable, isPartialInsideTimetable} = require("./util/trips");
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
let traccarInstance
|
|
@@ -58,8 +58,8 @@ async function createKmsReportByDevice(from, to) {
|
|
|
58
58
|
console.log('trips:' + tripsData.length)
|
|
59
59
|
|
|
60
60
|
if (tripsData.length > 0) {
|
|
61
|
-
|
|
62
|
-
allData.devices = processDevices(from, to, devicesToProcess,
|
|
61
|
+
trips.checkTripsKms(traccarInstance, from, to, devicesToProcess, {trips: tripsData, route: route})
|
|
62
|
+
allData.devices = processDevices(from, to, devicesToProcess, {trips: tripsData, route: route})
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
return allData
|
|
@@ -75,7 +75,9 @@ async function createKmsReportByDriver(from, to) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
const tripsData = await traccar.getTrips(traccarInstance, from, to, devices)
|
|
78
|
-
|
|
78
|
+
const routeData = await traccar.getTrips(traccarInstance, from, to, devices)
|
|
79
|
+
|
|
80
|
+
return { drivers: processDrivers(from, to, userData.drivers, {trips: tripsData, route: routeData}) }
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
async function createKmsReportByGroup(from, to) {
|
|
@@ -98,8 +100,8 @@ async function createKmsReportByGroup(from, to) {
|
|
|
98
100
|
console.log('trips:' + tripsData.length)
|
|
99
101
|
|
|
100
102
|
if (tripsData.length > 0) {
|
|
101
|
-
|
|
102
|
-
groupData.devices = processDevices(from, to, devices,
|
|
103
|
+
trips.checkTripsKms(traccarInstance, from, to, devices, {trips: tripsData, route: route})
|
|
104
|
+
groupData.devices = processDevices(from, to, devices, {trips: tripsData, route: route})
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
reportData.push(groupData)
|
|
@@ -116,7 +118,10 @@ function processDrivers(from, to, drivers, data) {
|
|
|
116
118
|
console.log(data)
|
|
117
119
|
const driversResult = []
|
|
118
120
|
drivers.forEach(d => {
|
|
119
|
-
const
|
|
121
|
+
const route = data.route.filter(p => p.attributes.driverUniqueId === d.uniqueId)
|
|
122
|
+
const trips = data.trips.filter(t => t.driverUniqueId === d.uniqueId
|
|
123
|
+
&& (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|
|
124
|
+
|
|
120
125
|
if (trips.length > 0) {
|
|
121
126
|
const driverData = {
|
|
122
127
|
driver: d
|
|
@@ -149,13 +154,15 @@ function processDrivers(from, to, drivers, data) {
|
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
|
|
152
|
-
function processDevices(from, to, devices,
|
|
157
|
+
function processDevices(from, to, devices, data) {
|
|
153
158
|
const devicesResult = []
|
|
154
159
|
|
|
155
160
|
for (const d of devices) {
|
|
156
|
-
const
|
|
161
|
+
const route = data.route.filter(t => t.deviceId === d.id)
|
|
162
|
+
const deviceTrips = data.trips.filter(t => t.deviceId === d.id
|
|
163
|
+
&& (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|
|
157
164
|
|
|
158
|
-
|
|
165
|
+
if (deviceTrips.length > 0) {
|
|
159
166
|
if(userData.groupByDay) {
|
|
160
167
|
deviceTrips.forEach(t => t.tripDay = new Date(t.startTime).toISOString().split('T')[0] + ' 12:00 PM')
|
|
161
168
|
const groupedTrips = deviceTrips.reduce(
|
|
@@ -167,82 +174,30 @@ function processDevices(from, to, devices, route, trips) {
|
|
|
167
174
|
|
|
168
175
|
const days = []
|
|
169
176
|
let keys = Array.from(groupedTrips.keys())
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
allDates.forEach(d => {
|
|
178
|
+
const day = d.toISOString().split('T')[0] + ' 12:00 PM'
|
|
179
|
+
if(!keys.includes(day)){
|
|
180
|
+
groupedTrips.set(day, [])
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
keys = Array.from(groupedTrips.keys())
|
|
185
|
+
keys.sort((a,b)=>new Date(a).getTime()-new Date(b).getTime());
|
|
186
|
+
keys.forEach(key => {
|
|
180
187
|
const currentDate = new Date(key)
|
|
181
|
-
|
|
188
|
+
const dayTrips = groupedTrips.get(key)
|
|
182
189
|
const day = {
|
|
183
190
|
date: currentDate,
|
|
184
191
|
kms: 0
|
|
185
192
|
}
|
|
186
193
|
|
|
187
|
-
|
|
188
|
-
day.kms = dayTrips.reduce((a, b) => a + b.distance, 0) || 0
|
|
189
|
-
} else {
|
|
190
|
-
if((currentDate.getDay() === 0 && userData.weekDays.sunday) ||
|
|
191
|
-
(currentDate.getDay() === 1 && userData.weekDays.monday) ||
|
|
192
|
-
(currentDate.getDay() === 2 && userData.weekDays.tuesday) ||
|
|
193
|
-
(currentDate.getDay() === 3 && userData.weekDays.wednesday) ||
|
|
194
|
-
(currentDate.getDay() === 4 && userData.weekDays.thursday) ||
|
|
195
|
-
(currentDate.getDay() === 5 && userData.weekDays.friday) ||
|
|
196
|
-
(currentDate.getDay() === 6 && userData.weekDays.saturday)) {
|
|
197
|
-
|
|
198
|
-
const startDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
|
|
199
|
-
const endDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
|
|
200
|
-
|
|
201
|
-
console.log(key, startDate, endDate)
|
|
202
|
-
|
|
203
|
-
if(startDate.getTime() < endDate.getTime()) {
|
|
204
|
-
//Trips inside time period
|
|
205
|
-
const filteredTrips = dayTrips.filter(t => new Date(t.startTime).getTime() > startDate.getTime()
|
|
206
|
-
&& new Date(t.endTime).getTime() < endDate.getTime())
|
|
207
|
-
|
|
208
|
-
day.kms = filteredTrips.reduce((a, b) => a + b.distance, 0) || 0
|
|
209
|
-
console.log('Inside trips:' + day.kms)
|
|
210
|
-
} else {
|
|
211
|
-
//Trips inside time period
|
|
212
|
-
const filteredTrips = dayTrips.filter(t => new Date(t.startTime).getTime() > startDate.getTime()
|
|
213
|
-
|| new Date(t.endTime).getTime() < endDate.getTime())
|
|
214
|
-
|
|
215
|
-
day.kms = filteredTrips.reduce((a, b) => a + b.distance, 0) || 0
|
|
216
|
-
console.log('Inside trips:' + day.kms)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
//Trip starts outside time period and ends inside time period
|
|
220
|
-
const startIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < startDate.getTime()
|
|
221
|
-
&& new Date(t.endTime).getTime() > startDate.getTime())
|
|
222
|
-
|
|
223
|
-
//Trip starts inside time period and ends outside time period
|
|
224
|
-
const endIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < endDate.getTime()
|
|
225
|
-
&& new Date(t.endTime).getTime() > endDate.getTime())
|
|
226
|
-
|
|
227
|
-
if (startIncompleteTrip.length) {
|
|
228
|
-
const routeInside = route.filter(p => new Date(p.fixTime).getTime() > startDate.getTime() && new Date(p.fixTime).getTime() < new Date(startIncompleteTrip[0].endTime).getTime())
|
|
229
|
-
day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
|
|
230
|
-
console.log('startIncompleteTrip:' + day.kms)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (endIncompleteTrip.length) {
|
|
234
|
-
const routeInside = route.filter(p => new Date(p.fixTime).getTime() < endDate.getTime() && new Date(p.fixTime).getTime() > new Date(endIncompleteTrip[0].startTime).getTime())
|
|
235
|
-
day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
|
|
236
|
-
console.log('endIncompleteTrip:' + day.kms)
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
194
|
+
day.kms = dayTrips.reduce((a, b) => a + b.distance, 0)
|
|
240
195
|
|
|
241
196
|
days.push(day)
|
|
242
197
|
})
|
|
243
198
|
devicesResult.push({
|
|
244
|
-
|
|
245
|
-
|
|
199
|
+
device: d,
|
|
200
|
+
days: days
|
|
246
201
|
})
|
|
247
202
|
} else {
|
|
248
203
|
devicesResult.push({
|
package/src/speeding-report.js
CHANGED
|
@@ -402,8 +402,10 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
402
402
|
footValues.splice(2, 0, '')
|
|
403
403
|
}
|
|
404
404
|
|
|
405
|
-
|
|
406
|
-
|
|
405
|
+
if(timezone === 'Asia/Qatar') {
|
|
406
|
+
doc.addFileToVFS("Amiri-Regular.ttf", AmiriRegular());
|
|
407
|
+
doc.addFont("Amiri-Regular.ttf", "Amiri", "normal");
|
|
408
|
+
}
|
|
407
409
|
|
|
408
410
|
const style = getStyle(getUserPartner(userData.user))
|
|
409
411
|
doc.autoTable({
|
|
@@ -428,7 +430,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
428
430
|
fontSize: 9
|
|
429
431
|
},
|
|
430
432
|
startY: space+35 });
|
|
431
|
-
|
|
433
|
+
} catch (e) {
|
|
432
434
|
console.error(e, 'moving on...')
|
|
433
435
|
}
|
|
434
436
|
})
|
package/src/trip-report.js
CHANGED
|
@@ -9,7 +9,8 @@ const {headerFromUser, addTable} = require("./util/pdfDocument")
|
|
|
9
9
|
const {getStyle} = require("./reportStyle")
|
|
10
10
|
const traccar = require("./util/traccar")
|
|
11
11
|
const trips = require("./util/trips");
|
|
12
|
-
const {isInsideTimetable, addNearestPOIs} = require("./util/trips")
|
|
12
|
+
const {isInsideTimetable, addNearestPOIs, isPartialInsideTimetable} = require("./util/trips")
|
|
13
|
+
const word = require('./word')
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
let traccarInstance
|
|
@@ -51,14 +52,15 @@ async function createTripReportByDevice(from, to) {
|
|
|
51
52
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
52
53
|
|
|
53
54
|
const devicesToSlice = devices.slice()
|
|
54
|
-
const
|
|
55
|
+
const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToSlice)
|
|
55
56
|
const stopsData = await traccar.getStops(traccarInstance, from, to, devicesToSlice)
|
|
57
|
+
const routeData = await traccar.getRoute(traccarInstance, from, to, devicesToSlice)
|
|
56
58
|
|
|
57
|
-
console.log('Trips:' +
|
|
59
|
+
console.log('Trips:' + tripsData.length)
|
|
58
60
|
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
allData.devices = processDevices(from, to, devices,
|
|
61
|
+
if (tripsData.length > 0) {
|
|
62
|
+
trips.checkTripsKms(traccarInstance, from, to, devices, {trips: tripsData, route: routeData})
|
|
63
|
+
allData.devices = processDevices(from, to, devices, {trips: tripsData, stops: stopsData, route: routeData})
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
return allData
|
|
@@ -82,11 +84,14 @@ async function createTripReportByGroup(from, to) {
|
|
|
82
84
|
const stopsResponse = await traccarInstance.reports.reportsStopsGet(from, to, null, [g.id])
|
|
83
85
|
const stopsData = stopsResponse.data
|
|
84
86
|
|
|
87
|
+
const routeResponse = await traccarInstance.reports.reportsRouteGet(from, to, null, [g.id])
|
|
88
|
+
const routeData = routeResponse.data
|
|
89
|
+
|
|
85
90
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
86
91
|
|
|
87
92
|
if (tripsData.length > 0) {
|
|
88
93
|
console.log('Trips:' + tripsData.length)
|
|
89
|
-
groupData.devices = processDevices(from, to, devices, tripsData, stopsData,
|
|
94
|
+
groupData.devices = processDevices(from, to, devices, {trips: tripsData, stops: stopsData, route: routeData})
|
|
90
95
|
|
|
91
96
|
reportData.push(groupData)
|
|
92
97
|
}
|
|
@@ -112,17 +117,19 @@ async function createTripReportByDriver(from, to){
|
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
const tripsData = await traccar.getTrips(traccarInstance, from, to, devices)
|
|
120
|
+
const routeData = await traccar.getRoute(traccarInstance, from, to, devices)
|
|
115
121
|
|
|
116
|
-
return { drivers: processDrivers(from, to, userData.drivers, tripsData)}
|
|
122
|
+
return { drivers: processDrivers(from, to, userData.drivers, {trips: tripsData, route: routeData})}
|
|
117
123
|
}
|
|
118
124
|
|
|
119
|
-
function processDevices(from, to, devices, data
|
|
125
|
+
function processDevices(from, to, devices, data) {
|
|
120
126
|
const devicesResult = []
|
|
121
127
|
|
|
122
128
|
devices.forEach(d => {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
const route = data.route.filter(t => t.deviceId === d.id)
|
|
130
|
+
const trips = data.trips.filter(t => t.deviceId === d.id
|
|
131
|
+
&& (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|
|
132
|
+
const stops = data.stops.filter(s => s.deviceId === d.id)
|
|
126
133
|
|
|
127
134
|
addNearestPOIs(trips, userData)
|
|
128
135
|
|
|
@@ -136,7 +143,7 @@ function processDevices(from, to, devices, data, stopsData) {
|
|
|
136
143
|
}
|
|
137
144
|
|
|
138
145
|
const stop = getStop(new Date(trip.startTime), stops)
|
|
139
|
-
if (stop) {
|
|
146
|
+
if (stop && !trip.endTimeIsOut) {
|
|
140
147
|
trip.stopDuration = (new Date(stop.endTime) - new Date(stop.startTime))
|
|
141
148
|
trip.stopEngineHours = stop.engineHours
|
|
142
149
|
} else {
|
|
@@ -173,8 +180,9 @@ function processDrivers(from, to, drivers, data) {
|
|
|
173
180
|
console.log(data)
|
|
174
181
|
const driversResult = []
|
|
175
182
|
drivers.forEach(d => {
|
|
176
|
-
const
|
|
177
|
-
|
|
183
|
+
const route = data.route.filter(p => p.attributes.driverUniqueId === d.uniqueId)
|
|
184
|
+
const trips = data.trips.filter(t => t.driverUniqueId === d.uniqueId
|
|
185
|
+
&& (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, route)))
|
|
178
186
|
|
|
179
187
|
trips.sort((a,b)=>new Date(a.startTime).getTime()-new Date(b.startTime).getTime())
|
|
180
188
|
|
|
@@ -438,6 +446,7 @@ function getStop(tripEndDate, stops){
|
|
|
438
446
|
return null
|
|
439
447
|
}
|
|
440
448
|
|
|
441
|
-
exports.createTripReport = createTripReport
|
|
442
|
-
exports.exportTripReportToPDF = exportTripReportToPDF
|
|
443
|
-
exports.exportTripReportToExcel = exportTripReportToExcel
|
|
449
|
+
exports.createTripReport = createTripReport
|
|
450
|
+
exports.exportTripReportToPDF = exportTripReportToPDF
|
|
451
|
+
exports.exportTripReportToExcel = exportTripReportToExcel
|
|
452
|
+
exports.exportTripReportToWord = word.exportTripReportToWord
|
package/src/util/trips.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const traccar = require("./traccar");
|
|
2
1
|
const {coordsDistance} = require("./utils");
|
|
3
2
|
|
|
4
3
|
const minDistance = 0
|
|
@@ -25,15 +24,14 @@ function addNearestPOIs(trips, userData){
|
|
|
25
24
|
})
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
function checkTripsKms(traccarInstance, from, to, devices, data) {
|
|
29
28
|
console.log('checkTripsKms')
|
|
30
|
-
const trips =
|
|
29
|
+
const trips = data.trips.filter(t => t.distance === minDistance && t.averageSpeed > minAvgSpeed)
|
|
31
30
|
if(trips.length > 0) {
|
|
32
31
|
//Vehicles with imported positions. calculate trip distance with route positions
|
|
33
|
-
const route = routeData.length === 0 ? await traccar.getRoute(traccarInstance, from, to, devices) : routeData
|
|
34
32
|
trips.forEach(t => {
|
|
35
33
|
if(t.distance === minDistance && t.averageSpeed > minAvgSpeed) {
|
|
36
|
-
const tripRoute = route.filter(p => p.deviceId === t.deviceId
|
|
34
|
+
const tripRoute = data.route.filter(p => p.deviceId === t.deviceId
|
|
37
35
|
&& new Date(p.fixTime).getTime() >= new Date(t.startTime).getTime()
|
|
38
36
|
&& new Date(p.fixTime).getTime() <= new Date(t.endTime).getTime())
|
|
39
37
|
t.distance = tripRoute.reduce((a, b) => a + b.attributes.distance, 0)
|
|
@@ -42,6 +40,70 @@ async function checkTripsKms(traccarInstance, from, to, routeData, tripsData, de
|
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
|
|
43
|
+
function isPartialInsideTimetable(t, userData, route){
|
|
44
|
+
const tripStart = new Date(t.startTime)
|
|
45
|
+
let isPartialInside = false
|
|
46
|
+
|
|
47
|
+
if((tripStart.getDay() === 0 && userData.weekDays.sunday) ||
|
|
48
|
+
(tripStart.getDay() === 1 && userData.weekDays.monday) ||
|
|
49
|
+
(tripStart.getDay() === 2 && userData.weekDays.tuesday) ||
|
|
50
|
+
(tripStart.getDay() === 3 && userData.weekDays.wednesday) ||
|
|
51
|
+
(tripStart.getDay() === 4 && userData.weekDays.thursday) ||
|
|
52
|
+
(tripStart.getDay() === 5 && userData.weekDays.friday) ||
|
|
53
|
+
(tripStart.getDay() === 6 && userData.weekDays.saturday)) {
|
|
54
|
+
|
|
55
|
+
const startDate = new Date(new Date(tripStart).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
|
|
56
|
+
const endDate = new Date(new Date(tripStart).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
|
|
57
|
+
|
|
58
|
+
if(startDate.getTime() > endDate.getTime()){
|
|
59
|
+
//Trip starts outside time period and ends inside time period
|
|
60
|
+
if (new Date(t.startTime).getTime() < endDate.getTime()
|
|
61
|
+
&& new Date(t.endTime).getTime() > endDate.getTime()) {
|
|
62
|
+
//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)
|
|
64
|
+
updateTrip(t, routeInside)
|
|
65
|
+
t.endTime = endDate.toISOString()
|
|
66
|
+
t.endTimeIsOut = true
|
|
67
|
+
isPartialInside = true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (new Date(t.startTime).getTime() < startDate.getTime()
|
|
71
|
+
&& new Date(t.endTime).getTime() > startDate.getTime()) {
|
|
72
|
+
|
|
73
|
+
//Trip starts outside time period and ends inside time period
|
|
74
|
+
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)
|
|
75
|
+
updateTrip(t, routeInside)
|
|
76
|
+
t.startTime = startDate.toISOString()
|
|
77
|
+
t.startTimeIsOut = true
|
|
78
|
+
isPartialInside = true
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
} else {
|
|
82
|
+
if (new Date(t.startTime).getTime() < startDate.getTime()
|
|
83
|
+
&& new Date(t.endTime).getTime() > startDate.getTime()) {
|
|
84
|
+
//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)
|
|
86
|
+
updateTrip(t, routeInside)
|
|
87
|
+
t.startTime = startDate.toISOString()
|
|
88
|
+
t.startTimeIsOut = true
|
|
89
|
+
isPartialInside = true
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (new Date(t.startTime).getTime() < endDate.getTime()
|
|
93
|
+
&& new Date(t.endTime).getTime() > endDate.getTime()) {
|
|
94
|
+
//Trip starts inside time period and ends outside time period
|
|
95
|
+
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
|
+
updateTrip(t, routeInside)
|
|
97
|
+
t.endTime = endDate.toISOString()
|
|
98
|
+
t.endTimeIsOut = true
|
|
99
|
+
isPartialInside = true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return isPartialInside
|
|
105
|
+
}
|
|
106
|
+
|
|
45
107
|
function isInsideTimetable(t, userData){
|
|
46
108
|
const tripStart = new Date(t.startTime)
|
|
47
109
|
const tripEnd = new Date(t.endTime)
|
|
@@ -71,6 +133,15 @@ function isInsideTimetable(t, userData){
|
|
|
71
133
|
return false
|
|
72
134
|
}
|
|
73
135
|
|
|
136
|
+
function updateTrip(t, route){
|
|
137
|
+
const distance = route[route.length-1].attributes.totalDistance - route[0].attributes.totalDistance
|
|
138
|
+
t.distance = distance
|
|
139
|
+
t.duration = new Date(route[route.length-1].fixTime).getTime() - new Date(route[0].fixTime).getTime()
|
|
140
|
+
t.maxSpeed = route.reduce((a, b) => Math.max(a, b.speed), 0)
|
|
141
|
+
t.averageSpeed = distance > 0 ? ((route.reduce((a, b) => a + b.speed, 0)) / route.length) : 0
|
|
142
|
+
}
|
|
143
|
+
|
|
74
144
|
exports.checkTripsKms = checkTripsKms
|
|
75
145
|
exports.isInsideTimetable = isInsideTimetable
|
|
146
|
+
exports.isPartialInsideTimetable = isPartialInsideTimetable
|
|
76
147
|
exports.addNearestPOIs = addNearestPOIs
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const {Document, Paragraph, Packer, TableRow, TableCell, Table} = require("docx")
|
|
2
|
+
const { saveAs } = require('file-saver')
|
|
3
|
+
const kmsReport = require('../kms-report')
|
|
4
|
+
|
|
5
|
+
exports.exportKmsReportToWord = (userData, reportData) => {
|
|
6
|
+
const excel = kmsReport.exportKmsReportToExcel(userData, reportData)
|
|
7
|
+
const table = new Table({
|
|
8
|
+
rows: excel.data.map(r => new TableRow({
|
|
9
|
+
children: r.map(c =>
|
|
10
|
+
new TableCell({
|
|
11
|
+
children: [new Paragraph(c)]
|
|
12
|
+
}))
|
|
13
|
+
}))
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const doc = new Document({
|
|
17
|
+
sections: [{
|
|
18
|
+
properties: {},
|
|
19
|
+
children: [
|
|
20
|
+
table
|
|
21
|
+
],
|
|
22
|
+
}],
|
|
23
|
+
})
|
|
24
|
+
Packer.toBlob(doc).then(blob => {
|
|
25
|
+
saveAs(blob, "trip.docx");
|
|
26
|
+
})
|
|
27
|
+
}
|
package/.idea/aws.xml
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="accountSettings">
|
|
4
|
-
<option name="activeProfile" value="profile:default" />
|
|
5
|
-
<option name="activeRegion" value="us-east-1" />
|
|
6
|
-
<option name="recentlyUsedProfiles">
|
|
7
|
-
<list>
|
|
8
|
-
<option value="profile:default" />
|
|
9
|
-
</list>
|
|
10
|
-
</option>
|
|
11
|
-
<option name="recentlyUsedRegions">
|
|
12
|
-
<list>
|
|
13
|
-
<option value="us-east-1" />
|
|
14
|
-
</list>
|
|
15
|
-
</option>
|
|
16
|
-
</component>
|
|
17
|
-
</project>
|