fleetmap-reports 1.0.259 → 1.0.263
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 +41 -5
- package/package.json +1 -1
- package/src/activity-report.js +193 -23
- package/src/events-report.js +4 -5
- package/src/kms-report.js +1 -1
- package/src/location-report.js +4 -11
- 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,11 +1,11 @@
|
|
|
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="
|
|
4
|
+
<list default="true" id="eb665c86-c893-4333-bd2a-721dc27980b9" name="Changes" comment="fix activity report by driver">
|
|
5
5
|
<change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
|
|
6
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" />
|
|
7
8
|
<change beforePath="$PROJECT_DIR$/src/index.test.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.test.js" afterDir="false" />
|
|
8
|
-
<change beforePath="$PROJECT_DIR$/src/location-report.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/location-report.js" afterDir="false" />
|
|
9
9
|
</list>
|
|
10
10
|
<option name="SHOW_DIALOG" value="false" />
|
|
11
11
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -215,7 +215,11 @@
|
|
|
215
215
|
<workItem from="1639954341221" duration="11986000" />
|
|
216
216
|
<workItem from="1640272520380" duration="2253000" />
|
|
217
217
|
<workItem from="1640789226071" duration="1935000" />
|
|
218
|
-
<workItem from="1640794844118" duration="
|
|
218
|
+
<workItem from="1640794844118" duration="10128000" />
|
|
219
|
+
<workItem from="1640866364417" duration="67000" />
|
|
220
|
+
<workItem from="1640866782794" duration="123000" />
|
|
221
|
+
<workItem from="1640866964393" duration="1022000" />
|
|
222
|
+
<workItem from="1640870147277" duration="6811000" />
|
|
219
223
|
</task>
|
|
220
224
|
<task id="LOCAL-00001" summary="Fix getStyle">
|
|
221
225
|
<created>1636983717385</created>
|
|
@@ -329,7 +333,35 @@
|
|
|
329
333
|
<option name="project" value="LOCAL" />
|
|
330
334
|
<updated>1640274171902</updated>
|
|
331
335
|
</task>
|
|
332
|
-
<
|
|
336
|
+
<task id="LOCAL-00017" summary="location report - check if it's running on client side">
|
|
337
|
+
<created>1640795243287</created>
|
|
338
|
+
<option name="number" value="00017" />
|
|
339
|
+
<option name="presentableId" value="LOCAL-00017" />
|
|
340
|
+
<option name="project" value="LOCAL" />
|
|
341
|
+
<updated>1640795243288</updated>
|
|
342
|
+
</task>
|
|
343
|
+
<task id="LOCAL-00018" summary="timezone - check if it's running on client side">
|
|
344
|
+
<created>1640825795052</created>
|
|
345
|
+
<option name="number" value="00018" />
|
|
346
|
+
<option name="presentableId" value="LOCAL-00018" />
|
|
347
|
+
<option name="project" value="LOCAL" />
|
|
348
|
+
<updated>1640825795053</updated>
|
|
349
|
+
</task>
|
|
350
|
+
<task id="LOCAL-00019" summary="calculate avg speed">
|
|
351
|
+
<created>1640867522437</created>
|
|
352
|
+
<option name="number" value="00019" />
|
|
353
|
+
<option name="presentableId" value="LOCAL-00019" />
|
|
354
|
+
<option name="project" value="LOCAL" />
|
|
355
|
+
<updated>1640867522438</updated>
|
|
356
|
+
</task>
|
|
357
|
+
<task id="LOCAL-00020" summary="fix activity report by driver">
|
|
358
|
+
<created>1640872780966</created>
|
|
359
|
+
<option name="number" value="00020" />
|
|
360
|
+
<option name="presentableId" value="LOCAL-00020" />
|
|
361
|
+
<option name="project" value="LOCAL" />
|
|
362
|
+
<updated>1640872780968</updated>
|
|
363
|
+
</task>
|
|
364
|
+
<option name="localTasksCounter" value="21" />
|
|
333
365
|
<servers />
|
|
334
366
|
</component>
|
|
335
367
|
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -363,6 +395,10 @@
|
|
|
363
395
|
<MESSAGE value="Trip and activity report with time period" />
|
|
364
396
|
<MESSAGE value="Fix trips distance because imported positions generate trips with 0 kms" />
|
|
365
397
|
<MESSAGE value="Fix reports by driver" />
|
|
366
|
-
<
|
|
398
|
+
<MESSAGE value="location report - check if it's running on client side" />
|
|
399
|
+
<MESSAGE value="timezone - check if it's running on client side" />
|
|
400
|
+
<MESSAGE value="calculate avg speed" />
|
|
401
|
+
<MESSAGE value="fix activity report by driver" />
|
|
402
|
+
<option name="LAST_COMMIT_MESSAGE" value="fix activity report by driver" />
|
|
367
403
|
</component>
|
|
368
404
|
</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 = {
|
|
@@ -150,7 +149,7 @@ async function createActivityReportByDriver(from, to){
|
|
|
150
149
|
to: to
|
|
151
150
|
}
|
|
152
151
|
|
|
153
|
-
allData.drivers = processDrivers(userData.drivers, tripsData)
|
|
152
|
+
allData.drivers = processDrivers(from, to, userData.drivers, tripsData)
|
|
154
153
|
|
|
155
154
|
return allData
|
|
156
155
|
}
|
|
@@ -181,7 +180,7 @@ function processDevices(devices, data, kmsReport) {
|
|
|
181
180
|
return devicesResult
|
|
182
181
|
}
|
|
183
182
|
|
|
184
|
-
function processDrivers(drivers, data) {
|
|
183
|
+
function processDrivers(from, to, drivers, data) {
|
|
185
184
|
console.log(data)
|
|
186
185
|
const driversResult = []
|
|
187
186
|
drivers.forEach(d => {
|
|
@@ -189,12 +188,63 @@ function processDrivers(drivers, data) {
|
|
|
189
188
|
if (trips.length > 0) {
|
|
190
189
|
const driverData = {
|
|
191
190
|
driver: d,
|
|
192
|
-
summary:
|
|
191
|
+
summary: [],
|
|
192
|
+
}
|
|
193
|
+
if(userData.groupByDay) {
|
|
194
|
+
const dates = getDates(from, to)
|
|
195
|
+
for(const date of dates){
|
|
196
|
+
if(userData.allWeek){
|
|
197
|
+
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
198
|
+
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
199
|
+
|
|
200
|
+
const tripsByDay = trips.filter(t => new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay)
|
|
201
|
+
|
|
202
|
+
driverData.summary.push({
|
|
203
|
+
date: date,
|
|
204
|
+
distance: tripsByDay.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
|
|
205
|
+
engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
|
|
206
|
+
maxSpeed: tripsByDay.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
207
|
+
averageSpeed: tripsByDay.length > 0 ? Math.round(tripsByDay.reduce((a, b) => a + b.averageSpeed, 0) / tripsByDay.length) : 0,
|
|
208
|
+
})
|
|
209
|
+
} else {
|
|
210
|
+
if((date.getDay() === 0 && userData.weekDays.sunday) ||
|
|
211
|
+
(date.getDay() === 1 && userData.weekDays.monday) ||
|
|
212
|
+
(date.getDay() === 2 && userData.weekDays.tuesday) ||
|
|
213
|
+
(date.getDay() === 3 && userData.weekDays.wednesday) ||
|
|
214
|
+
(date.getDay() === 4 && userData.weekDays.thursday) ||
|
|
215
|
+
(date.getDay() === 5 && userData.weekDays.friday) ||
|
|
216
|
+
(date.getDay() === 6 && userData.weekDays.saturday)) {
|
|
217
|
+
|
|
218
|
+
const fromByDay = new Date(new Date(date).toISOString().split('T')[0] + ' ' + userData.dayHours.startTime)
|
|
219
|
+
const toByDay = new Date(new Date(date).toISOString().split('T')[0] + ' ' + userData.dayHours.endTime)
|
|
220
|
+
|
|
221
|
+
const tripsByDay = trips.filter(t => new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay)
|
|
222
|
+
|
|
223
|
+
driverData.summary.push({
|
|
224
|
+
date: date,
|
|
225
|
+
distance: tripsByDay.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
|
|
226
|
+
engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
|
|
227
|
+
maxSpeed: tripsByDay.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
228
|
+
averageSpeed: tripsByDay.length > 0 ? Math.round(tripsByDay.reduce((a, b) => a + b.averageSpeed, 0) / tripsByDay.length) : 0,
|
|
229
|
+
})
|
|
230
|
+
}else {
|
|
231
|
+
driverData.summary.push({
|
|
232
|
+
date: date,
|
|
233
|
+
distance: 0,
|
|
234
|
+
engineHours: 0,
|
|
235
|
+
maxSpeed: 0,
|
|
236
|
+
averageSpeed: 0,
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
driverData.summary.push({
|
|
193
243
|
distance: trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
|
|
194
244
|
engineHours: trips.reduce((a, b) => a + b.duration, 0),
|
|
195
245
|
maxSpeed: trips.reduce((a, b) => Math.max(a, b.maxSpeed), 0),
|
|
196
246
|
averageSpeed: Math.round(trips.reduce((a, b) => a + b.averageSpeed, 0) / trips.length),
|
|
197
|
-
}
|
|
247
|
+
})
|
|
198
248
|
}
|
|
199
249
|
driversResult.push(driverData)
|
|
200
250
|
}
|
|
@@ -212,9 +262,11 @@ async function exportActivityReportToPDF(userData, reportData) {
|
|
|
212
262
|
const doc = new jsPDF.jsPDF('l')
|
|
213
263
|
await headerFromUser(doc, translations.report.titleActivityReport, userData.user)
|
|
214
264
|
|
|
215
|
-
if(userData.groupByDay){
|
|
265
|
+
if(userData.groupByDay && userData.byDriver) {
|
|
266
|
+
exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData)
|
|
267
|
+
} else if(userData.groupByDay) {
|
|
216
268
|
exportActivityReportToPDF_Vehicle_GroupByDay(doc, translations, reportData)
|
|
217
|
-
} else if(userData.byDriver){
|
|
269
|
+
} else if(userData.byDriver) {
|
|
218
270
|
exportActivityReportToPDF_Driver(doc, translations, reportData)
|
|
219
271
|
} else {
|
|
220
272
|
exportActivityReportToPDF_Vehicle(doc, translations, reportData)
|
|
@@ -257,7 +309,7 @@ function exportActivityReportToPDF_Driver(doc, translations, reportData) {
|
|
|
257
309
|
}
|
|
258
310
|
|
|
259
311
|
function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
|
|
260
|
-
const headers = [translations.report.
|
|
312
|
+
const headers = [translations.report.vehicle,
|
|
261
313
|
translations.report.group,
|
|
262
314
|
translations.report.distance,
|
|
263
315
|
translations.report.start + ' ' + translations.report.odometer,
|
|
@@ -275,7 +327,7 @@ function exportActivityReportToPDF_Vehicle(doc, translations, reportData) {
|
|
|
275
327
|
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
276
328
|
|
|
277
329
|
const temp = [
|
|
278
|
-
d.summary.deviceName,
|
|
330
|
+
d.summary[0].deviceName,
|
|
279
331
|
group ? group.name : '',
|
|
280
332
|
Number((d.summary[0].distance / 1000).toFixed(2)),
|
|
281
333
|
Number((d.summary[0].startOdometer / 1000).toFixed(2)),
|
|
@@ -431,6 +483,122 @@ function exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations,
|
|
|
431
483
|
}
|
|
432
484
|
}
|
|
433
485
|
|
|
486
|
+
function exportActivityReportToPDF_Driver_GroupByDay(doc, translations, reportData) {
|
|
487
|
+
const headers = [translations.report.date,
|
|
488
|
+
translations.report.distance,
|
|
489
|
+
translations.report.avgSpeed + ' (Km/h)',
|
|
490
|
+
translations.report.maxSpeed + ' (Km/h)',
|
|
491
|
+
translations.report.engineHours]
|
|
492
|
+
|
|
493
|
+
const weekDays = [
|
|
494
|
+
translations.report.sunday,
|
|
495
|
+
translations.report.monday,
|
|
496
|
+
translations.report.tuesday,
|
|
497
|
+
translations.report.wednesday,
|
|
498
|
+
translations.report.thursday,
|
|
499
|
+
translations.report.friday,
|
|
500
|
+
translations.report.saturday
|
|
501
|
+
]
|
|
502
|
+
|
|
503
|
+
reportData.drivers.forEach(function (d, index) {
|
|
504
|
+
const name = d.driver.name
|
|
505
|
+
const group = userData.groups.find(g => g.drivers.includes(d.id))
|
|
506
|
+
|
|
507
|
+
let space = index === 0 ? 8 : 0
|
|
508
|
+
if(index){
|
|
509
|
+
doc.addPage()
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
doc.setFontSize(13)
|
|
513
|
+
doc.text(name, 20, space + 20)
|
|
514
|
+
doc.setFontSize(11)
|
|
515
|
+
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
|
|
516
|
+
doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, space + 25)
|
|
517
|
+
|
|
518
|
+
if (!userData.allWeek) {
|
|
519
|
+
doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '')
|
|
520
|
+
+ (userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '')
|
|
521
|
+
+ (userData.weekDays.wednesday ? ' ' + translations.report.wednesday + ',' : '')
|
|
522
|
+
+ (userData.weekDays.thursday ? ' ' + translations.report.thursday + ',' : '')
|
|
523
|
+
+ (userData.weekDays.friday ? ' ' + translations.report.friday + ',' : '')
|
|
524
|
+
+ (userData.weekDays.saturday ? ' ' + translations.report.saturday + ',' : '')
|
|
525
|
+
+ (userData.weekDays.sunday ? ' ' + translations.report.sunday + ',' : '')
|
|
526
|
+
+ ' das '
|
|
527
|
+
+ userData.dayHours.startTime + ' - ' + userData.dayHours.endTime, 20, space + 30)
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const data = []
|
|
531
|
+
d.summary.forEach(s => {
|
|
532
|
+
const temp = [
|
|
533
|
+
new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
|
|
534
|
+
Number((s.distance / 1000).toFixed(2)),
|
|
535
|
+
Math.round(s.averageSpeed * 1.85200),
|
|
536
|
+
Math.round(s.maxSpeed * 1.85200),
|
|
537
|
+
convertMS(s.engineHours)
|
|
538
|
+
]
|
|
539
|
+
|
|
540
|
+
data.push(temp)
|
|
541
|
+
})
|
|
542
|
+
|
|
543
|
+
const footValues = ['Total:' + d.summary.length,
|
|
544
|
+
(d.summary.reduce((a, b) => a + b.distance, 0) / 1000).toFixed(0),
|
|
545
|
+
getSumAvgSpeed(d.summary),
|
|
546
|
+
getSumMaxSpeed(d.summary),
|
|
547
|
+
convertMS(d.summary.reduce((a, b) => a + b.engineHours, 0))]
|
|
548
|
+
|
|
549
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
550
|
+
addTable(doc, headers, data, footValues, style, 40)
|
|
551
|
+
})
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData) {
|
|
555
|
+
const headers = [{label: translations.report.driver, value: 'name'},
|
|
556
|
+
{label: translations.report.group, value: 'group'},
|
|
557
|
+
{label: translations.report.date, value: 'date'},
|
|
558
|
+
{label: translations.report.weekDay, value: 'weekday'},
|
|
559
|
+
{label: translations.report.distance, value: 'distance'},
|
|
560
|
+
{label: translations.report.speed + ' ' + translations.report.avgSpeed + ' (Km/h)', value: 'avgSpeed'},
|
|
561
|
+
{label: translations.report.speed + ' ' + translations.report.maxSpeed + ' (Km/h)', value: 'maxSpeed'},
|
|
562
|
+
{label: translations.report.engineHours, value: 'engineHours'}]
|
|
563
|
+
|
|
564
|
+
const weekDays = [
|
|
565
|
+
translations.report.sunday,
|
|
566
|
+
translations.report.monday,
|
|
567
|
+
translations.report.tuesday,
|
|
568
|
+
translations.report.wednesday,
|
|
569
|
+
translations.report.thursday,
|
|
570
|
+
translations.report.friday,
|
|
571
|
+
translations.report.saturday
|
|
572
|
+
]
|
|
573
|
+
|
|
574
|
+
let data = []
|
|
575
|
+
if (reportData.drivers) {
|
|
576
|
+
reportData.drivers.forEach(d => {
|
|
577
|
+
const group = userData.groups.find(g => g.drivers.includes(d.id))
|
|
578
|
+
|
|
579
|
+
data = data.concat([{}])
|
|
580
|
+
data = data.concat(d.summary.map(s => {
|
|
581
|
+
return {
|
|
582
|
+
name: d.driver.name,
|
|
583
|
+
group: group ? group.name : '',
|
|
584
|
+
date: new Date(s.date).toLocaleDateString(),
|
|
585
|
+
weekday: weekDays[s.date.getDay()],
|
|
586
|
+
distance: Number((s.distance / 1000).toFixed(0)),
|
|
587
|
+
avgSpeed: Math.round(s.averageSpeed * 1.85200),
|
|
588
|
+
maxSpeed: Math.round(s.maxSpeed * 1.85200),
|
|
589
|
+
engineHours: convertMS(s.engineHours)
|
|
590
|
+
}
|
|
591
|
+
}))
|
|
592
|
+
})
|
|
593
|
+
console.log(data)
|
|
594
|
+
return {
|
|
595
|
+
headers,
|
|
596
|
+
data,
|
|
597
|
+
settings
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
434
602
|
function exportActivityReportToExcel_Driver(settings, translations, reportData) {
|
|
435
603
|
const headers = [{label: translations.report.driver, value: 'driver'},
|
|
436
604
|
{label: translations.report.distance, value: 'distance'},
|
|
@@ -443,10 +611,10 @@ function exportActivityReportToExcel_Driver(settings, translations, reportData)
|
|
|
443
611
|
reportData.drivers.forEach(d => {
|
|
444
612
|
data = data.concat([{
|
|
445
613
|
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)
|
|
614
|
+
distance: Number((d.summary[0].distance / 1000).toFixed(0)),
|
|
615
|
+
avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
616
|
+
maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
617
|
+
engineHours: convertMS(d.summary[0].engineHours)
|
|
450
618
|
}])
|
|
451
619
|
})
|
|
452
620
|
console.log(data)
|
|
@@ -475,15 +643,15 @@ function exportActivityReportToExcel_Vehicle(settings, translations, reportData)
|
|
|
475
643
|
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
476
644
|
|
|
477
645
|
data = data.concat([{
|
|
478
|
-
name: d.summary.deviceName,
|
|
646
|
+
name: d.summary[0].deviceName,
|
|
479
647
|
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,
|
|
648
|
+
distance: Number((d.summary[0].distance / 1000).toFixed(0)),
|
|
649
|
+
startOdometer: Number((d.summary[0].startOdometer / 1000).toFixed(0)),
|
|
650
|
+
endOdometer: Number((d.summary[0].endOdometer / 1000).toFixed(0)),
|
|
651
|
+
avgSpeed: Math.round(d.summary[0].averageSpeed * 1.85200),
|
|
652
|
+
maxSpeed: Math.round(d.summary[0].maxSpeed * 1.85200),
|
|
653
|
+
engineHours: convertMS(d.summary[0].engineHours),
|
|
654
|
+
spentFuel: d.summary[0].convertedSpentFuel >= 0 ? d.summary[0].convertedSpentFuel : 0,
|
|
487
655
|
}])
|
|
488
656
|
})
|
|
489
657
|
console.log(data)
|
|
@@ -506,7 +674,9 @@ function exportActivityReportToExcel(reportUserData, reportData) {
|
|
|
506
674
|
fileName: fileName // The name of the spreadsheet
|
|
507
675
|
}
|
|
508
676
|
|
|
509
|
-
if(userData.groupByDay){
|
|
677
|
+
if(userData.groupByDay && userData.byDriver){
|
|
678
|
+
return exportActivityReportToExcel_Driver_GroupByDay(settings, translations, reportData)
|
|
679
|
+
} else if(userData.groupByDay){
|
|
510
680
|
return exportActivityReportToExcel_Vehicle_GroupByDay(settings, translations, reportData)
|
|
511
681
|
} else if(userData.byDriver){
|
|
512
682
|
return exportActivityReportToExcel_Driver(settings, translations, reportData)
|
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/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,11 +5,10 @@ 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
|
|
|
11
|
-
const clientSide = typeof window !== "undefined"
|
|
12
|
-
|
|
13
12
|
async function createLocationReport(from, to, userData, traccar) {
|
|
14
13
|
console.log('Create LocationReport')
|
|
15
14
|
|
|
@@ -106,6 +105,7 @@ async function exportLocationReportToPDF(userData, reportData) {
|
|
|
106
105
|
console.log('Export to PDF')
|
|
107
106
|
|
|
108
107
|
const lang = userData.user.attributes.lang
|
|
108
|
+
const timezone = userData.user.attributes.timezone
|
|
109
109
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
110
110
|
|
|
111
111
|
const headers = [
|
|
@@ -138,7 +138,7 @@ async function exportLocationReportToPDF(userData, reportData) {
|
|
|
138
138
|
doc.text(name, 20, space + 20)
|
|
139
139
|
doc.setFontSize(11)
|
|
140
140
|
doc.text(group, 200, space + 20)
|
|
141
|
-
doc.text(
|
|
141
|
+
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
|
|
142
142
|
d.positions.map(a => {
|
|
143
143
|
const temp = [
|
|
144
144
|
getLocationDate(a, userData.user),
|
|
@@ -253,14 +253,7 @@ function deviceName(device){
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
function getLocationDate(location, user){
|
|
256
|
-
|
|
257
|
-
return new Date(location.fixTime).toLocaleString()
|
|
258
|
-
} else {
|
|
259
|
-
return new Date(location.fixTime).toLocaleString(user.attributes.lang, {
|
|
260
|
-
timeZone: user.attributes.timezone,
|
|
261
|
-
hour12: false
|
|
262
|
-
})
|
|
263
|
-
}
|
|
256
|
+
return convertToLocaleString(location.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
264
257
|
}
|
|
265
258
|
|
|
266
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
|