fleetmap-reports 1.0.258 → 1.0.262
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/workspace.xml +46 -11
- package/package.json +1 -1
- package/src/activity-report.js +17 -18
- package/src/events-report.js +4 -5
- package/src/index.test.js +11 -0
- package/src/kms-report.js +1 -1
- package/src/location-report.js +4 -5
- package/src/speeding-report.js +4 -6
- package/src/trip-report.js +16 -17
- package/src/util/traccar.js +3 -3
- package/src/util/utils.js +38 -0
- package/src/zone-report.js +5 -10
package/.idea/workspace.xml
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ChangeListManager">
|
|
4
|
-
<list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="
|
|
5
|
-
<change beforePath="$PROJECT_DIR$/lang/enGB.js" beforeDir="false" afterPath="$PROJECT_DIR$/lang/enGB.js" afterDir="false" />
|
|
6
|
-
<change beforePath="$PROJECT_DIR$/lang/esCL.js" beforeDir="false" afterPath="$PROJECT_DIR$/lang/esCL.js" afterDir="false" />
|
|
7
|
-
<change beforePath="$PROJECT_DIR$/lang/ptBR.js" beforeDir="false" afterPath="$PROJECT_DIR$/lang/ptBR.js" afterDir="false" />
|
|
8
|
-
<change beforePath="$PROJECT_DIR$/lang/ptPT.js" beforeDir="false" afterPath="$PROJECT_DIR$/lang/ptPT.js" afterDir="false" />
|
|
4
|
+
<list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="calculate avg speed">
|
|
9
5
|
<change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
|
|
10
6
|
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
7
|
+
<change beforePath="$PROJECT_DIR$/src/activity-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/activity-report.js" afterDir="false" />
|
|
11
8
|
<change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
|
|
12
|
-
<change beforePath="$PROJECT_DIR$/src/
|
|
13
|
-
<change beforePath="$PROJECT_DIR$/src/
|
|
14
|
-
<change beforePath="$PROJECT_DIR$/src/util/
|
|
9
|
+
<change beforePath="$PROJECT_DIR$/src/kms-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/kms-report.js" afterDir="false" />
|
|
10
|
+
<change beforePath="$PROJECT_DIR$/src/trip-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/trip-report.js" afterDir="false" />
|
|
11
|
+
<change beforePath="$PROJECT_DIR$/src/util/traccar.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/util/traccar.js" afterDir="false" />
|
|
15
12
|
</list>
|
|
16
13
|
<option name="SHOW_DIALOG" value="false" />
|
|
17
14
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -219,7 +216,13 @@
|
|
|
219
216
|
<workItem from="1639766010908" duration="4991000" />
|
|
220
217
|
<workItem from="1639872937953" duration="1438000" />
|
|
221
218
|
<workItem from="1639954341221" duration="11986000" />
|
|
222
|
-
<workItem from="1640272520380" duration="
|
|
219
|
+
<workItem from="1640272520380" duration="2253000" />
|
|
220
|
+
<workItem from="1640789226071" duration="1935000" />
|
|
221
|
+
<workItem from="1640794844118" duration="10128000" />
|
|
222
|
+
<workItem from="1640866364417" duration="67000" />
|
|
223
|
+
<workItem from="1640866782794" duration="123000" />
|
|
224
|
+
<workItem from="1640866964393" duration="1022000" />
|
|
225
|
+
<workItem from="1640870147277" duration="2391000" />
|
|
223
226
|
</task>
|
|
224
227
|
<task id="LOCAL-00001" summary="Fix getStyle">
|
|
225
228
|
<created>1636983717385</created>
|
|
@@ -326,7 +329,35 @@
|
|
|
326
329
|
<option name="project" value="LOCAL" />
|
|
327
330
|
<updated>1640000462825</updated>
|
|
328
331
|
</task>
|
|
329
|
-
<
|
|
332
|
+
<task id="LOCAL-00016" summary="Fix reports by driver">
|
|
333
|
+
<created>1640274171902</created>
|
|
334
|
+
<option name="number" value="00016" />
|
|
335
|
+
<option name="presentableId" value="LOCAL-00016" />
|
|
336
|
+
<option name="project" value="LOCAL" />
|
|
337
|
+
<updated>1640274171902</updated>
|
|
338
|
+
</task>
|
|
339
|
+
<task id="LOCAL-00017" summary="location report - check if it's running on client side">
|
|
340
|
+
<created>1640795243287</created>
|
|
341
|
+
<option name="number" value="00017" />
|
|
342
|
+
<option name="presentableId" value="LOCAL-00017" />
|
|
343
|
+
<option name="project" value="LOCAL" />
|
|
344
|
+
<updated>1640795243288</updated>
|
|
345
|
+
</task>
|
|
346
|
+
<task id="LOCAL-00018" summary="timezone - check if it's running on client side">
|
|
347
|
+
<created>1640825795052</created>
|
|
348
|
+
<option name="number" value="00018" />
|
|
349
|
+
<option name="presentableId" value="LOCAL-00018" />
|
|
350
|
+
<option name="project" value="LOCAL" />
|
|
351
|
+
<updated>1640825795053</updated>
|
|
352
|
+
</task>
|
|
353
|
+
<task id="LOCAL-00019" summary="calculate avg speed">
|
|
354
|
+
<created>1640867522437</created>
|
|
355
|
+
<option name="number" value="00019" />
|
|
356
|
+
<option name="presentableId" value="LOCAL-00019" />
|
|
357
|
+
<option name="project" value="LOCAL" />
|
|
358
|
+
<updated>1640867522438</updated>
|
|
359
|
+
</task>
|
|
360
|
+
<option name="localTasksCounter" value="20" />
|
|
330
361
|
<servers />
|
|
331
362
|
</component>
|
|
332
363
|
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -359,6 +390,10 @@
|
|
|
359
390
|
<MESSAGE value="fix speeding report" />
|
|
360
391
|
<MESSAGE value="Trip and activity report with time period" />
|
|
361
392
|
<MESSAGE value="Fix trips distance because imported positions generate trips with 0 kms" />
|
|
362
|
-
<
|
|
393
|
+
<MESSAGE value="Fix reports by driver" />
|
|
394
|
+
<MESSAGE value="location report - check if it's running on client side" />
|
|
395
|
+
<MESSAGE value="timezone - check if it's running on client side" />
|
|
396
|
+
<MESSAGE value="calculate avg speed" />
|
|
397
|
+
<option name="LAST_COMMIT_MESSAGE" value="calculate avg speed" />
|
|
363
398
|
</component>
|
|
364
399
|
</project>
|
package/package.json
CHANGED
package/src/activity-report.js
CHANGED
|
@@ -140,8 +140,7 @@ async function createActivityReportByDriver(from, to){
|
|
|
140
140
|
console.log(deviceIds)
|
|
141
141
|
let tripsData = []
|
|
142
142
|
if(deviceIds.length > 0) {
|
|
143
|
-
|
|
144
|
-
tripsData = response.data
|
|
143
|
+
tripsData = await traccar.getTrips(traccarInstance, from, to, deviceIds)
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
const allData = {
|
|
@@ -189,12 +188,12 @@ function processDrivers(drivers, data) {
|
|
|
189
188
|
if (trips.length > 0) {
|
|
190
189
|
const driverData = {
|
|
191
190
|
driver: d,
|
|
192
|
-
summary: {
|
|
191
|
+
summary: [{
|
|
193
192
|
distance: trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
|
|
194
193
|
engineHours: trips.reduce((a, b) => a + b.duration, 0),
|
|
195
194
|
maxSpeed: trips.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
196
195
|
averageSpeed: Math.round(trips.reduce((a, b) => a + b.averageSpeed, 0) / trips.length),
|
|
197
|
-
},
|
|
196
|
+
}],
|
|
198
197
|
}
|
|
199
198
|
driversResult.push(driverData)
|
|
200
199
|
}
|
|
@@ -257,7 +256,7 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData) {
|
|
|
257
256
|
}
|
|
258
257
|
|
|
259
258
|
function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
|
|
260
|
-
const headers = [translations.report.
|
|
259
|
+
const headers = [translations.report.vehicle,
|
|
261
260
|
translations.report.group,
|
|
262
261
|
translations.report.distance,
|
|
263
262
|
translations.report.start + ' ' + translations.report.odometer,
|
|
@@ -275,7 +274,7 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
|
|
|
275
274
|
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
276
275
|
|
|
277
276
|
const temp = [
|
|
278
|
-
d.summary.deviceName,
|
|
277
|
+
d.summary[0].deviceName,
|
|
279
278
|
group ? group.name : '',
|
|
280
279
|
Number((d.summary[0].distance / 1000).toFixed(2)),
|
|
281
280
|
Number((d.summary[0].startOdometer / 1000).toFixed(2)),
|
|
@@ -443,10 +442,10 @@ function exportActivityReportToExcel_Driver(settings, translations, reportData)
|
|
|
443
442
|
reportData.drivers.forEach(d => {
|
|
444
443
|
data = data.concat([{
|
|
445
444
|
driver: d.driver.name,
|
|
446
|
-
distance: Number((d.summary.distance / 1000).toFixed(0)),
|
|
447
|
-
avgSpeed: Math.round(d.summary.averageSpeed * 1.85200),
|
|
448
|
-
maxSpeed: Math.round(d.summary.maxSpeed * 1.85200),
|
|
449
|
-
engineHours: convertMS(d.summary.engineHours)
|
|
445
|
+
distance: Number((d.summary[0].distance / 1000).toFixed(0)),
|
|
446
|
+
avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
447
|
+
maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
448
|
+
engineHours: convertMS(d.summary[0].engineHours)
|
|
450
449
|
}])
|
|
451
450
|
})
|
|
452
451
|
console.log(data)
|
|
@@ -475,15 +474,15 @@ function exportActivityReportToExcel_Vehicle(settings, translations, reportData)
|
|
|
475
474
|
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
476
475
|
|
|
477
476
|
data = data.concat([{
|
|
478
|
-
name: d.summary.deviceName,
|
|
477
|
+
name: d.summary[0].deviceName,
|
|
479
478
|
group: group ? group.name : '',
|
|
480
|
-
distance: Number((d.summary.distance / 1000).toFixed(0)),
|
|
481
|
-
startOdometer: Number((d.summary.startOdometer / 1000).toFixed(0)),
|
|
482
|
-
endOdometer: Number((d.summary.endOdometer / 1000).toFixed(0)),
|
|
483
|
-
avgSpeed: Math.round(d.summary.averageSpeed * 1.85200),
|
|
484
|
-
maxSpeed: Math.round(d.summary.maxSpeed * 1.85200),
|
|
485
|
-
engineHours: convertMS(d.summary.engineHours),
|
|
486
|
-
spentFuel: d.summary.convertedSpentFuel >= 0 ? d.summary.convertedSpentFuel : 0,
|
|
479
|
+
distance: Number((d.summary[0].distance / 1000).toFixed(0)),
|
|
480
|
+
startOdometer: Number((d.summary[0].startOdometer / 1000).toFixed(0)),
|
|
481
|
+
endOdometer: Number((d.summary[0].endOdometer / 1000).toFixed(0)),
|
|
482
|
+
avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
483
|
+
maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
484
|
+
engineHours: convertMS(d.summary[0].engineHours),
|
|
485
|
+
spentFuel: d.summary[0].convertedSpentFuel >= 0 ? d.summary[0].convertedSpentFuel : 0,
|
|
487
486
|
}])
|
|
488
487
|
})
|
|
489
488
|
console.log(data)
|
package/src/events-report.js
CHANGED
|
@@ -5,6 +5,7 @@ require('jspdf-autotable')
|
|
|
5
5
|
const {getStyle} = require("./reportStyle");
|
|
6
6
|
const {headerFromUser} = require("./util/pdfDocument");
|
|
7
7
|
const {getUserPartner} = require("fleetmap-partners");
|
|
8
|
+
const {convertToLocaleString} = require("./util/utils");
|
|
8
9
|
|
|
9
10
|
const fileName = 'EventReport'
|
|
10
11
|
|
|
@@ -120,6 +121,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
120
121
|
console.log('Export to PDF')
|
|
121
122
|
|
|
122
123
|
const lang = userData.user.attributes.lang
|
|
124
|
+
const timezone = userData.user.attributes.timezone
|
|
123
125
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
124
126
|
|
|
125
127
|
const headers = [
|
|
@@ -149,7 +151,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
149
151
|
doc.text(name, 20, space+20 )
|
|
150
152
|
doc.setFontSize(11)
|
|
151
153
|
doc.text(group, 200, space+20 )
|
|
152
|
-
doc.text(
|
|
154
|
+
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space+25 )
|
|
153
155
|
|
|
154
156
|
doc.autoTable(['','','','',''], [
|
|
155
157
|
[translations.report.event_ignitionOn,translations.report.event_ignitionOff, translations.report.event_geofenceEnter,
|
|
@@ -270,10 +272,7 @@ function getAlertInfo(drivers, alert) {
|
|
|
270
272
|
|
|
271
273
|
function getAlertDate(user, alert) {
|
|
272
274
|
if(alert.position) {
|
|
273
|
-
return
|
|
274
|
-
timeZone: user.attributes.timezone,
|
|
275
|
-
hour12: false
|
|
276
|
-
})
|
|
275
|
+
return convertToLocaleString(alert.position.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
277
276
|
}
|
|
278
277
|
}
|
|
279
278
|
|
package/src/index.test.js
CHANGED
|
@@ -44,6 +44,17 @@ describe('Reports', function() {
|
|
|
44
44
|
|
|
45
45
|
console.log(reportData)
|
|
46
46
|
|
|
47
|
+
await reports.kmsReportToPDF(userData, reportData[0])
|
|
48
|
+
})
|
|
49
|
+
it('test locationReport by day', async () => {
|
|
50
|
+
const reports = await getReports()
|
|
51
|
+
const userData = await reports.getUserData()
|
|
52
|
+
userData.groupByDay = true
|
|
53
|
+
const reportData = await reports.locations(new Date(2021, 10, 1), new Date(2021, 10, 3),
|
|
54
|
+
userData)
|
|
55
|
+
|
|
56
|
+
console.log(reportData)
|
|
57
|
+
|
|
47
58
|
await reports.kmsReportToPDF(userData, reportData[0])
|
|
48
59
|
})
|
|
49
60
|
})
|
package/src/kms-report.js
CHANGED
|
@@ -26,7 +26,7 @@ async function createKmsReportByDevice(from, to) {
|
|
|
26
26
|
|
|
27
27
|
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
28
28
|
const route = userData.allWeek ? [] : await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
|
|
29
|
-
const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
|
|
29
|
+
const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess.map(d => d.id))
|
|
30
30
|
|
|
31
31
|
console.log('trips:' + tripsData.length)
|
|
32
32
|
|
package/src/location-report.js
CHANGED
|
@@ -5,6 +5,7 @@ require('jspdf-autotable')
|
|
|
5
5
|
const {headerFromUser} = require("./util/pdfDocument");
|
|
6
6
|
const {getStyle} = require("./reportStyle")
|
|
7
7
|
const {getUserPartner} = require("fleetmap-partners");
|
|
8
|
+
const {convertToLocaleString} = require("./util/utils");
|
|
8
9
|
|
|
9
10
|
const fileName = 'LocationReport'
|
|
10
11
|
|
|
@@ -104,6 +105,7 @@ async function exportLocationReportToPDF(userData, reportData) {
|
|
|
104
105
|
console.log('Export to PDF')
|
|
105
106
|
|
|
106
107
|
const lang = userData.user.attributes.lang
|
|
108
|
+
const timezone = userData.user.attributes.timezone
|
|
107
109
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
108
110
|
|
|
109
111
|
const headers = [
|
|
@@ -136,7 +138,7 @@ async function exportLocationReportToPDF(userData, reportData) {
|
|
|
136
138
|
doc.text(name, 20, space + 20)
|
|
137
139
|
doc.setFontSize(11)
|
|
138
140
|
doc.text(group, 200, space + 20)
|
|
139
|
-
doc.text(
|
|
141
|
+
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
|
|
140
142
|
d.positions.map(a => {
|
|
141
143
|
const temp = [
|
|
142
144
|
getLocationDate(a, userData.user),
|
|
@@ -251,10 +253,7 @@ function deviceName(device){
|
|
|
251
253
|
}
|
|
252
254
|
|
|
253
255
|
function getLocationDate(location, user){
|
|
254
|
-
return
|
|
255
|
-
timeZone: user.attributes.timezone,
|
|
256
|
-
hour12: false
|
|
257
|
-
})
|
|
256
|
+
return convertToLocaleString(location.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
258
257
|
}
|
|
259
258
|
|
|
260
259
|
function getDriverName(location, drivers) {
|
package/src/speeding-report.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const messages = require('../lang')
|
|
2
2
|
const jsPDF = require('jspdf')
|
|
3
|
-
const {convertMS} = require("./util/utils")
|
|
3
|
+
const {convertMS, convertToLocaleString} = require("./util/utils")
|
|
4
4
|
const {headerFromUser} = require("./util/pdfDocument")
|
|
5
5
|
require('jspdf-autotable')
|
|
6
6
|
const { parse } = require('wkt')
|
|
@@ -318,6 +318,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
318
318
|
console.log('Export to PDF')
|
|
319
319
|
|
|
320
320
|
const lang = userData.user.attributes.lang
|
|
321
|
+
const timezone = userData.user.attributes.timezone
|
|
321
322
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
322
323
|
|
|
323
324
|
const overspeedData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
@@ -364,7 +365,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
|
|
|
364
365
|
doc.text(name, 20, space+20 )
|
|
365
366
|
doc.setFontSize(11)
|
|
366
367
|
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space+20 )
|
|
367
|
-
doc.text(
|
|
368
|
+
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space+25 )
|
|
368
369
|
if (d.alerts[0] && !userData.byDriver) {
|
|
369
370
|
doc.text(translations.report.speedLimit + ": " + (userData.useVehicleSpeedLimit ? Math.round(d.alerts[0].attributes.speedLimit * 1.85200) : userData.customSpeed) + ' Km/h', 20, space + 30)
|
|
370
371
|
}
|
|
@@ -490,10 +491,7 @@ function deviceName(device){
|
|
|
490
491
|
}
|
|
491
492
|
|
|
492
493
|
function getAlertDate(row, user) {
|
|
493
|
-
return
|
|
494
|
-
timeZone: user.attributes.timezone,
|
|
495
|
-
hour12: false
|
|
496
|
-
})
|
|
494
|
+
return convertToLocaleString(row.position.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
497
495
|
}
|
|
498
496
|
|
|
499
497
|
function getMaxSpeed(data) {
|
package/src/trip-report.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const automaticReports = require("./automaticReports")
|
|
2
2
|
const messages = require('../lang')
|
|
3
3
|
const jsPDF = require('jspdf')
|
|
4
|
-
const {convertMS} = require("./util/utils")
|
|
4
|
+
const {convertMS, convertToLocaleString, convertToLocaleDateString, convertToLocaleTimeString} = require("./util/utils")
|
|
5
5
|
require('jspdf-autotable')
|
|
6
6
|
const {coordsDistance} = require("./util/utils")
|
|
7
7
|
const drivers = require("./util/driver")
|
|
@@ -51,7 +51,7 @@ async function createTripReportByDevice(from, to, devices) {
|
|
|
51
51
|
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
52
52
|
|
|
53
53
|
const devicesToSlice = devices.slice()
|
|
54
|
-
const data = await traccar.getTrips(traccarInstance, from, to, devicesToSlice)
|
|
54
|
+
const data = await traccar.getTrips(traccarInstance, from, to, devicesToSlice.map(d => d.id))
|
|
55
55
|
const stopsData = await traccar.getStops(traccarInstance, from, to, devicesToSlice)
|
|
56
56
|
|
|
57
57
|
console.log('Trips:' + data.length)
|
|
@@ -217,6 +217,7 @@ async function exportTripReportToPDF(userData, reportData) {
|
|
|
217
217
|
console.log('Export to PDF')
|
|
218
218
|
|
|
219
219
|
const lang = userData.user.attributes.lang
|
|
220
|
+
const timezone = userData.user.attributes.timezone
|
|
220
221
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
221
222
|
const tripsData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
222
223
|
|
|
@@ -260,7 +261,7 @@ async function exportTripReportToPDF(userData, reportData) {
|
|
|
260
261
|
doc.text(name, 20, space+20 )
|
|
261
262
|
doc.setFontSize(11)
|
|
262
263
|
doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space+20 )
|
|
263
|
-
doc.text(
|
|
264
|
+
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space+25 )
|
|
264
265
|
if(!userData.allWeek) {
|
|
265
266
|
doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '')
|
|
266
267
|
+ (userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '')
|
|
@@ -398,23 +399,17 @@ function deviceName(device){
|
|
|
398
399
|
}
|
|
399
400
|
|
|
400
401
|
function getTripDate(user, trip){
|
|
401
|
-
return
|
|
402
|
-
timeZone: user.attributes.timezone,
|
|
403
|
-
hour12: false
|
|
404
|
-
})
|
|
402
|
+
return convertToLocaleDateString(trip.startTime, user.attributes.lang, user.attributes.timezone)
|
|
405
403
|
}
|
|
404
|
+
|
|
406
405
|
function getTripStart(user, trip){
|
|
407
|
-
return
|
|
408
|
-
timeZone: user.attributes.timezone,
|
|
409
|
-
hour12: false
|
|
410
|
-
})
|
|
406
|
+
return convertToLocaleTimeString(trip.startTime, user.attributes.lang, user.attributes.timezone)
|
|
411
407
|
}
|
|
408
|
+
|
|
412
409
|
function getTripEnd(user, trip){
|
|
413
|
-
return
|
|
414
|
-
timeZone: user.attributes.timezone,
|
|
415
|
-
hour12: false
|
|
416
|
-
})
|
|
410
|
+
return convertToLocaleTimeString(trip.endTime, user.attributes.lang, user.attributes.timezone)
|
|
417
411
|
}
|
|
412
|
+
|
|
418
413
|
function getDriverName(drivers, driverUniqueId) {
|
|
419
414
|
if(driverUniqueId) {
|
|
420
415
|
const driver = drivers.find(d => d.uniqueId === driverUniqueId)
|
|
@@ -423,18 +418,22 @@ function getDriverName(drivers, driverUniqueId) {
|
|
|
423
418
|
|
|
424
419
|
return ''
|
|
425
420
|
}
|
|
421
|
+
|
|
426
422
|
function getSumTotalKms(user, data) {
|
|
427
423
|
const values = data.map(item => {
|
|
428
424
|
return item.totalKms ? parseFloat(item.totalKms) : 0
|
|
429
425
|
})
|
|
430
426
|
return Intl.NumberFormat(user.attributes.lang, {maximumFractionDigits: 2}).format(values.reduce((a, b) => a + b, 0))
|
|
431
427
|
}
|
|
428
|
+
|
|
432
429
|
function getSumAvgSpeed(data) {
|
|
433
430
|
const values = data.map(item => {
|
|
434
|
-
return Math.round(item.averageSpeed * 1.85200)
|
|
431
|
+
return Math.round(item.averageSpeed * 1.85200) * item.totalKms
|
|
435
432
|
})
|
|
436
|
-
|
|
433
|
+
const totalKms = data.reduce((a, b) => a + b.totalKms, 0)
|
|
434
|
+
return totalKms > 0 ? Math.round((values.reduce((a, b) => a + b, 0)) / totalKms) : 0
|
|
437
435
|
}
|
|
436
|
+
|
|
438
437
|
function getMaxSpeed(data) {
|
|
439
438
|
const values = data.map(item => {
|
|
440
439
|
return item.maxSpeed
|
package/src/util/traccar.js
CHANGED
|
@@ -14,12 +14,12 @@ async function getRoute(traccar, from, to, devices){
|
|
|
14
14
|
return result.map(r => r.data).flat()
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
async function getTrips(traccar, from, to,
|
|
18
|
-
const devicesToSlice =
|
|
17
|
+
async function getTrips(traccar, from, to, deviceIds){
|
|
18
|
+
const devicesToSlice = deviceIds.slice()
|
|
19
19
|
const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
|
|
20
20
|
let requests = []
|
|
21
21
|
for (const a of arrayOfArrays) {
|
|
22
|
-
const promise = traccar.reports.reportsTripsGet(from, to, a
|
|
22
|
+
const promise = traccar.reports.reportsTripsGet(from, to, a)
|
|
23
23
|
requests = requests.concat(promise)
|
|
24
24
|
}
|
|
25
25
|
|
package/src/util/utils.js
CHANGED
|
@@ -55,8 +55,46 @@ async function getImgFromUrl(hostname) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
function isClientSide() { typeof window !== "undefined" }
|
|
59
|
+
|
|
60
|
+
function convertToLocaleString(value, lang, timezone){
|
|
61
|
+
if(isClientSide){
|
|
62
|
+
return new Date(value).toLocaleString()
|
|
63
|
+
} else {
|
|
64
|
+
return new Date(value).toLocaleString(lang, {
|
|
65
|
+
timeZone: timezone,
|
|
66
|
+
hour12: false
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function convertToLocaleDateString(value, lang, timezone){
|
|
72
|
+
if(isClientSide){
|
|
73
|
+
return new Date(value).toLocaleDateString()
|
|
74
|
+
} else {
|
|
75
|
+
return new Date(value).toLocaleDateString(lang, {
|
|
76
|
+
timeZone: timezone,
|
|
77
|
+
hour12: false
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function convertToLocaleTimeString(value, lang, timezone){
|
|
83
|
+
if(isClientSide){
|
|
84
|
+
return new Date(value).toLocaleTimeString()
|
|
85
|
+
} else {
|
|
86
|
+
return new Date(value).toLocaleTimeString(lang, {
|
|
87
|
+
timeZone: timezone,
|
|
88
|
+
hour12: false
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
58
93
|
exports.getImgFromUrl = getImgFromUrl
|
|
59
94
|
exports.convertMS = convertMS
|
|
60
95
|
exports.coordsDistance = coordsDistance
|
|
61
96
|
exports.getDates = getDates
|
|
97
|
+
exports.convertToLocaleString = convertToLocaleString
|
|
98
|
+
exports.convertToLocaleDateString = convertToLocaleDateString
|
|
99
|
+
exports.convertToLocaleTimeString = convertToLocaleTimeString
|
|
62
100
|
|
package/src/zone-report.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const moment = require('moment')
|
|
2
2
|
const messages = require('../lang')
|
|
3
3
|
const automaticReports = require("./automaticReports");
|
|
4
|
-
const {convertMS} = require("./util/utils")
|
|
4
|
+
const {convertMS, convertToLocaleString} = require("./util/utils")
|
|
5
5
|
const jsPDF = require('jspdf')
|
|
6
6
|
require('jspdf-autotable')
|
|
7
7
|
const {headerFromUser} = require("./util/pdfDocument");
|
|
@@ -150,6 +150,7 @@ async function exportZoneReportToPDF(userData, reportData) {
|
|
|
150
150
|
console.log('Export to PDF')
|
|
151
151
|
|
|
152
152
|
const lang = userData.user.attributes.lang
|
|
153
|
+
const timezone = userData.user.attributes.timezone
|
|
153
154
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
154
155
|
|
|
155
156
|
const headers = [
|
|
@@ -180,7 +181,7 @@ async function exportZoneReportToPDF(userData, reportData) {
|
|
|
180
181
|
doc.text(name, 20, space+20 )
|
|
181
182
|
doc.setFontSize(11)
|
|
182
183
|
doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space+20 )
|
|
183
|
-
doc.text(
|
|
184
|
+
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space+25 )
|
|
184
185
|
d.geofences.map(a => {
|
|
185
186
|
const temp = [
|
|
186
187
|
geofenceEnter(userData.user, a),
|
|
@@ -271,16 +272,10 @@ function deviceName(device){
|
|
|
271
272
|
}
|
|
272
273
|
|
|
273
274
|
function geofenceEnter(user, row){
|
|
274
|
-
return row.inTime ?
|
|
275
|
-
timeZone: user.attributes.timezone,
|
|
276
|
-
hour12: false
|
|
277
|
-
}) : ''
|
|
275
|
+
return row.inTime ? convertToLocaleString(row.inTime.fixTime, user.attributes.lang, user.attributes.timezone) : ''
|
|
278
276
|
}
|
|
279
277
|
function geofenceExit(user, row){
|
|
280
|
-
return row.outTime ?
|
|
281
|
-
timeZone: user.attributes.timezone,
|
|
282
|
-
hour12: false
|
|
283
|
-
}) : ''
|
|
278
|
+
return row.outTime ? convertToLocaleString(row.outTime.fixTime, user.attributes.lang, user.attributes.timezone) : ''
|
|
284
279
|
}
|
|
285
280
|
|
|
286
281
|
exports.createZoneReport = createZoneReport
|