fleetmap-reports 1.0.288 → 1.0.292
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/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +7 -0
- package/{fleetmap-reports.iml → .idea/fleetmap-reports.iml} +2 -1
- package/.idea/jsLibraryMappings.xml +1 -1
- package/.idea/modules.xml +1 -1
- package/.idea/vcs.xml +1 -1
- package/lang/enGB.js +12 -2
- package/lang/esCL.js +10 -1
- package/lang/index.js +4 -1
- package/lang/ptBR.js +11 -1
- package/lang/ptPT.js +11 -1
- package/package.json +2 -1
- package/src/activity-report.js +542 -206
- package/src/automaticReports.js +1 -1
- package/src/events-report.js +25 -21
- package/src/here.js +1 -1
- package/src/idle-report.js +285 -0
- package/src/index.js +12 -2
- package/src/index.test.js +18 -25
- package/src/kms-report.js +409 -103
- package/src/location-report.js +22 -18
- package/src/refueling-report.js +11 -1
- package/src/reportStyle.js +26 -0
- package/src/speeding-report.js +239 -180
- package/src/tests/index.js +22 -0
- package/src/trip-report.js +152 -159
- package/src/util/driver.js +5 -13
- package/src/util/pdfDocument.js +58 -0
- package/src/util/traccar.js +72 -0
- package/src/util/trips.js +76 -0
- package/src/util/utils.js +67 -1
- package/src/zone-report.js +22 -23
package/src/kms-report.js
CHANGED
|
@@ -1,100 +1,392 @@
|
|
|
1
|
-
const {createActivityReport} = require("./activity-report");
|
|
2
1
|
const messages = require('../lang')
|
|
3
2
|
const jsPDF = require('jspdf')
|
|
4
3
|
require('jspdf-autotable')
|
|
5
|
-
const
|
|
4
|
+
const {getStyle} = require("./reportStyle");
|
|
5
|
+
const {headerFromUser,addTable} = require("./util/pdfDocument");
|
|
6
|
+
const {getUserPartner} = require("fleetmap-partners");
|
|
7
|
+
const traccar = require("./util/traccar");
|
|
8
|
+
const {getDates} = require("./util/utils");
|
|
9
|
+
const trips = require("./util/trips");
|
|
10
|
+
const drivers = require("./util/driver");
|
|
11
|
+
const {isInsideTimetable} = require("./util/trips");
|
|
6
12
|
|
|
7
13
|
|
|
8
14
|
let traccarInstance
|
|
15
|
+
let userData
|
|
9
16
|
|
|
10
17
|
const fileName = 'KmsReport'
|
|
11
18
|
|
|
12
|
-
async function createKmsReport(from, to,
|
|
19
|
+
async function createKmsReport(from, to, reportUserData, traccar) {
|
|
13
20
|
console.log('Create KmsReport')
|
|
21
|
+
|
|
22
|
+
console.log(from, to)
|
|
14
23
|
traccarInstance = traccar
|
|
15
|
-
|
|
24
|
+
userData = reportUserData
|
|
25
|
+
const reportData = []
|
|
26
|
+
if(userData.byDriver){
|
|
27
|
+
console.log("ByDriver")
|
|
28
|
+
const allData = await createKmsReportByDriver(from, to)
|
|
29
|
+
reportData.push(allData)
|
|
30
|
+
}
|
|
31
|
+
else if(userData.byGroup){
|
|
32
|
+
console.log("ByGroup")
|
|
33
|
+
const allData = await createKmsReportByGroup(from, to)
|
|
34
|
+
reportData.push(...allData)
|
|
35
|
+
} else {
|
|
36
|
+
console.log("ByDevice")
|
|
37
|
+
const allData = await createKmsReportByDevice(from, to)
|
|
38
|
+
reportData.push(allData)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return reportData
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function createKmsReportByDevice(from, to) {
|
|
45
|
+
const groupIds = userData.groups.map(g => g.id)
|
|
46
|
+
const devicesToProcess = userData.byGroup ? userData.devices.filter(d => !groupIds.includes(d.groupId)) : userData.devices
|
|
47
|
+
|
|
48
|
+
const allData = {
|
|
49
|
+
devices: [],
|
|
50
|
+
from: from,
|
|
51
|
+
to: to
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
devicesToProcess.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
55
|
+
const route = userData.allWeek ? [] : await traccar.getRoute(traccarInstance, from, to, devicesToProcess)
|
|
56
|
+
const tripsData = await traccar.getTrips(traccarInstance, from, to, devicesToProcess)
|
|
57
|
+
|
|
58
|
+
console.log('trips:' + tripsData.length)
|
|
59
|
+
|
|
60
|
+
if (tripsData.length > 0) {
|
|
61
|
+
await trips.checkTripsKms(traccarInstance, from, to, route, tripsData, devicesToProcess)
|
|
62
|
+
allData.devices = processDevices(from, to, devicesToProcess, route, tripsData)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return allData
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function createKmsReportByDriver(from, to) {
|
|
69
|
+
const devices = await drivers.devicesByDriver(traccarInstance, from, to, userData.drivers, userData.devices)
|
|
70
|
+
console.log(devices.length)
|
|
71
|
+
|
|
72
|
+
if(!devices.length) {
|
|
73
|
+
//empty report
|
|
74
|
+
return { drivers: [] }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const tripsData = await traccar.getTrips(traccarInstance, from, to, devices)
|
|
78
|
+
return { drivers: processDrivers(from, to, userData.drivers, tripsData) }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function createKmsReportByGroup(from, to) {
|
|
82
|
+
const reportData = []
|
|
83
|
+
for (const g of userData.groups) {
|
|
84
|
+
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
85
|
+
console.log(g.name + ' devices:' + devices.length)
|
|
86
|
+
if(devices.length > 0) {
|
|
87
|
+
const groupData = {
|
|
88
|
+
devices: [],
|
|
89
|
+
group: g,
|
|
90
|
+
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const route = userData.allWeek ? [] : await traccar.getRoute(traccarInstance, from, to, devices)
|
|
94
|
+
const tripsData = await traccar.getTrips(traccarInstance, from, to, devices)
|
|
95
|
+
|
|
96
|
+
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
97
|
+
|
|
98
|
+
console.log('trips:' + tripsData.length)
|
|
99
|
+
|
|
100
|
+
if (tripsData.length > 0) {
|
|
101
|
+
await trips.checkTripsKms(traccarInstance, from, to, route, tripsData, devices)
|
|
102
|
+
groupData.devices = processDevices(from, to, devices, route, tripsData)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
reportData.push(groupData)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const withoutGroupData = await createKmsReportByDevice(from, to)
|
|
110
|
+
reportData.push(withoutGroupData)
|
|
111
|
+
|
|
112
|
+
return reportData
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function processDrivers(from, to, drivers, data) {
|
|
116
|
+
console.log(data)
|
|
117
|
+
const driversResult = []
|
|
118
|
+
drivers.forEach(d => {
|
|
119
|
+
const trips = data.filter(t => t.driverUniqueId === d.uniqueId)
|
|
120
|
+
if (trips.length > 0) {
|
|
121
|
+
const driverData = {
|
|
122
|
+
driver: d
|
|
123
|
+
}
|
|
124
|
+
if(userData.groupByDay) {
|
|
125
|
+
driverData.days = []
|
|
126
|
+
const dates = getDates(from, to)
|
|
127
|
+
for(const date of dates){
|
|
128
|
+
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
129
|
+
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
130
|
+
|
|
131
|
+
const tripsByDay = trips.filter(t => (new Date(t.startTime) > fromByDay && new Date(t.endTime) < toByDay)
|
|
132
|
+
&& (userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData)))
|
|
133
|
+
|
|
134
|
+
driverData.days.push({
|
|
135
|
+
date: date,
|
|
136
|
+
kms: tripsByDay.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0)
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
driverData.summary = {
|
|
141
|
+
distance: trips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
driversResult.push(driverData)
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
return driversResult
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
function processDevices(from, to, devices, route, trips) {
|
|
153
|
+
const devicesResult = []
|
|
154
|
+
|
|
155
|
+
for (const d of devices) {
|
|
156
|
+
const deviceTrips = trips.filter(t => t.deviceId === d.id)
|
|
157
|
+
|
|
158
|
+
if (deviceTrips.length > 0) {
|
|
159
|
+
if(userData.groupByDay) {
|
|
160
|
+
deviceTrips.forEach(t => t.tripDay = new Date(t.startTime).toISOString().split('T')[0] + ' 12:00 PM')
|
|
161
|
+
const groupedTrips = deviceTrips.reduce(
|
|
162
|
+
(entryMap, e) => entryMap.set(e.tripDay, [...entryMap.get(e.tripDay)||[], e]),
|
|
163
|
+
new Map()
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
const allDates = getDates(from, to)
|
|
167
|
+
|
|
168
|
+
const days = []
|
|
169
|
+
let keys = Array.from(groupedTrips.keys())
|
|
170
|
+
allDates.forEach(d => {
|
|
171
|
+
const day = d.toISOString().split('T')[0] + ' 12:00 PM'
|
|
172
|
+
if(!keys.includes(day)){
|
|
173
|
+
groupedTrips.set(day, [])
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
keys = Array.from(groupedTrips.keys())
|
|
178
|
+
keys.sort((a,b)=>new Date(a).getTime()-new Date(b).getTime());
|
|
179
|
+
keys.forEach(key => {
|
|
180
|
+
const currentDate = new Date(key)
|
|
181
|
+
let dayTrips = groupedTrips.get(key)
|
|
182
|
+
const day = {
|
|
183
|
+
date: currentDate,
|
|
184
|
+
kms: 0
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if(userData.allWeek || !userData.weekDays){
|
|
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
|
+
}
|
|
240
|
+
|
|
241
|
+
days.push(day)
|
|
242
|
+
})
|
|
243
|
+
devicesResult.push({
|
|
244
|
+
device: d,
|
|
245
|
+
days: days
|
|
246
|
+
})
|
|
247
|
+
} else {
|
|
248
|
+
devicesResult.push({
|
|
249
|
+
device: d,
|
|
250
|
+
summary: {
|
|
251
|
+
distance: deviceTrips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return devicesResult
|
|
16
259
|
}
|
|
17
260
|
|
|
18
|
-
function exportKmsReportToPDF(userData, reportData) {
|
|
19
|
-
const lang = userData.user.attributes.lang
|
|
261
|
+
async function exportKmsReportToPDF(userData, reportData) {
|
|
262
|
+
const lang = userData.user.attributes.lang || (navigator && navigator.language)
|
|
20
263
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
264
|
+
const kmsData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
265
|
+
|
|
266
|
+
const weekDays = [
|
|
267
|
+
translations.report.sunday,
|
|
268
|
+
translations.report.monday,
|
|
269
|
+
translations.report.tuesday,
|
|
270
|
+
translations.report.wednesday,
|
|
271
|
+
translations.report.thursday,
|
|
272
|
+
translations.report.friday,
|
|
273
|
+
translations.report.saturday
|
|
274
|
+
]
|
|
21
275
|
|
|
22
276
|
const headers = []
|
|
23
|
-
if(userData.
|
|
277
|
+
if(userData.groupByDay) {
|
|
278
|
+
headers.push(translations.report.date,
|
|
279
|
+
translations.report.distance)
|
|
280
|
+
}
|
|
281
|
+
else if(userData.byDriver) {
|
|
24
282
|
headers.push(translations.report.driver,
|
|
25
283
|
translations.report.group,
|
|
26
284
|
translations.report.distance)
|
|
27
285
|
} else {
|
|
28
286
|
headers.push(translations.report.name,
|
|
287
|
+
translations.settings.vehicle_model,
|
|
29
288
|
translations.report.group,
|
|
30
289
|
translations.report.distance)
|
|
31
290
|
}
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
34
|
-
doc.
|
|
35
|
-
doc
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
291
|
+
if (kmsData) {
|
|
292
|
+
const orientation = userData.groupByDay ? 'p' : 'l'
|
|
293
|
+
const doc = new jsPDF.jsPDF(orientation)
|
|
294
|
+
await headerFromUser(doc, translations.report.titleKmsReport, userData.user, orientation)
|
|
295
|
+
|
|
296
|
+
if (userData.groupByDay) {
|
|
297
|
+
kmsData.forEach(function (d, index) {
|
|
298
|
+
const name = userData.byDriver ? d.driver.name : d.device.name
|
|
299
|
+
const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
|
|
300
|
+
|
|
301
|
+
let space = index === 0 ? 8 : 0
|
|
302
|
+
if(index){
|
|
303
|
+
doc.addPage()
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
doc.setFontSize(13)
|
|
307
|
+
doc.text(name, 20, space + 20)
|
|
308
|
+
doc.setFontSize(11)
|
|
309
|
+
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
|
|
310
|
+
doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, space + 25)
|
|
311
|
+
|
|
312
|
+
if(!userData.allWeek && userData.weekDays) {
|
|
313
|
+
doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '')
|
|
314
|
+
+ (userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '')
|
|
315
|
+
+ (userData.weekDays.wednesday ? ' ' + translations.report.wednesday + ',' : '')
|
|
316
|
+
+ (userData.weekDays.thursday ? ' ' + translations.report.thursday + ',' : '')
|
|
317
|
+
+ (userData.weekDays.friday ? ' ' + translations.report.friday + ',' : '')
|
|
318
|
+
+ (userData.weekDays.saturday ? ' ' + translations.report.saturday + ',' : '')
|
|
319
|
+
+ (userData.weekDays.sunday ? ' ' + translations.report.sunday + ',' : '')
|
|
320
|
+
+ ' das '
|
|
321
|
+
+ userData.dayHours.startTime + ' - ' + userData.dayHours.endTime, 20, space + 30)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const data = []
|
|
325
|
+
d.days.forEach(day => {
|
|
326
|
+
const temp = [
|
|
327
|
+
new Date(day.date).toLocaleDateString() + ' - ' + weekDays[day.date.getDay()],
|
|
328
|
+
(day.kms/1000).toFixed(0)
|
|
329
|
+
]
|
|
330
|
+
|
|
331
|
+
data.push(temp)
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
const footValues = []
|
|
335
|
+
footValues.push(
|
|
336
|
+
'',
|
|
337
|
+
(d.days.reduce((a, b) => a + b.kms, 0)/1000).toFixed(0)
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
341
|
+
addTable(doc, headers, data, footValues, style, 40)
|
|
50
342
|
})
|
|
51
343
|
} else {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
d.summary.deviceName,
|
|
57
|
-
group ? group.name : '',
|
|
58
|
-
Number((d.summary.distance / 1000).toFixed(0))
|
|
59
|
-
]
|
|
60
|
-
data.push(temp)
|
|
61
|
-
})
|
|
62
|
-
}
|
|
344
|
+
const data = []
|
|
345
|
+
if (userData.byDriver) {
|
|
346
|
+
reportData.drivers.forEach(d => {
|
|
347
|
+
const group = userData.groups.find(g => g.drivers.includes(d.driver.id))
|
|
63
348
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
349
|
+
const temp = [
|
|
350
|
+
d.driver.name,
|
|
351
|
+
group ? group.name : '',
|
|
352
|
+
Number((d.summary.distance / 1000).toFixed(0)),
|
|
353
|
+
]
|
|
354
|
+
data.push(temp)
|
|
355
|
+
})
|
|
356
|
+
} else {
|
|
357
|
+
reportData.devices.forEach(d => {
|
|
358
|
+
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
359
|
+
|
|
360
|
+
const temp = [
|
|
361
|
+
d.device.name,
|
|
362
|
+
d.device.model,
|
|
363
|
+
group ? group.name : '',
|
|
364
|
+
Number((d.summary.distance / 1000).toFixed(0))
|
|
365
|
+
]
|
|
366
|
+
data.push(temp)
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const footValues = []
|
|
371
|
+
if(userData.byDriver) {
|
|
372
|
+
footValues.push(
|
|
373
|
+
'Total:' + reportData.drivers.length,
|
|
374
|
+
'',
|
|
375
|
+
(reportData.drivers.reduce((a, b) => a + b.summary.distance, 0)/1000).toFixed(0)
|
|
376
|
+
)
|
|
377
|
+
} else {
|
|
378
|
+
footValues.push(
|
|
379
|
+
'Total:' + reportData.devices.length,
|
|
380
|
+
'',
|
|
381
|
+
'',
|
|
382
|
+
(reportData.devices.reduce((a, b) => a + b.summary.distance, 0)/1000).toFixed(0),
|
|
383
|
+
)
|
|
384
|
+
}
|
|
78
385
|
|
|
79
|
-
|
|
80
|
-
head: [headers],
|
|
81
|
-
body: data,
|
|
82
|
-
foot: [footValues],
|
|
83
|
-
showFoot: 'lastPage',
|
|
84
|
-
headStyles: {
|
|
85
|
-
fillColor: reportStyle.pdfHeaderColor,
|
|
86
|
-
textColor: reportStyle.pdfHeaderTextColor
|
|
87
|
-
},
|
|
88
|
-
bodyStyles: {
|
|
89
|
-
fillColor: reportStyle.pdfBodyColor,
|
|
90
|
-
textColor: reportStyle.pdfBodyTextColor
|
|
91
|
-
},
|
|
92
|
-
footStyles: {
|
|
93
|
-
fillColor: reportStyle.pdfFooterColor,
|
|
94
|
-
textColor: reportStyle.pdfFooterTextColor
|
|
95
|
-
},
|
|
96
|
-
startY: 35 });
|
|
386
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
97
387
|
|
|
388
|
+
addTable(doc, headers, data, footValues, style, 35)
|
|
389
|
+
}
|
|
98
390
|
return doc
|
|
99
391
|
}
|
|
100
392
|
}
|
|
@@ -102,9 +394,19 @@ function exportKmsReportToPDF(userData, reportData) {
|
|
|
102
394
|
function exportKmsReportToExcel(userData, reportData) {
|
|
103
395
|
console.log('Export to Excel')
|
|
104
396
|
|
|
105
|
-
const lang = userData.user.attributes.lang
|
|
397
|
+
const lang = userData.user.attributes.lang || (navigator && navigator.language)
|
|
106
398
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
107
399
|
|
|
400
|
+
const weekDays = [
|
|
401
|
+
translations.report.sunday,
|
|
402
|
+
translations.report.monday,
|
|
403
|
+
translations.report.tuesday,
|
|
404
|
+
translations.report.wednesday,
|
|
405
|
+
translations.report.thursday,
|
|
406
|
+
translations.report.friday,
|
|
407
|
+
translations.report.saturday
|
|
408
|
+
]
|
|
409
|
+
|
|
108
410
|
const settings = {
|
|
109
411
|
sheetName: translations.report.titleKmsReport, // The name of the sheet
|
|
110
412
|
fileName: fileName // The name of the spreadsheet
|
|
@@ -112,55 +414,59 @@ function exportKmsReportToExcel(userData, reportData) {
|
|
|
112
414
|
|
|
113
415
|
const headers = []
|
|
114
416
|
|
|
115
|
-
if(userData.
|
|
417
|
+
if(userData.groupByDay) {
|
|
418
|
+
headers.push(
|
|
419
|
+
{label: translations.report.vehicle, value: 'name'},
|
|
420
|
+
{label: translations.report.licensePlate, value: 'licenseplate'},
|
|
421
|
+
{label: translations.report.group, value: 'group'},
|
|
422
|
+
{label: translations.report.date, value: 'date'},
|
|
423
|
+
{label: translations.report.weekDay, value: 'weekday'},
|
|
424
|
+
{label: translations.report.distance, value: 'distance'})
|
|
425
|
+
} else if(userData.byDriver) {
|
|
116
426
|
headers.push(
|
|
117
|
-
{label: translations.report.driver, value: '
|
|
427
|
+
{label: translations.report.driver, value: 'name'},
|
|
118
428
|
{label: translations.report.group, value: 'group'},
|
|
119
429
|
{label: translations.report.distance, value: 'distance'})
|
|
120
430
|
} else {
|
|
121
431
|
headers.push(
|
|
122
432
|
{label: translations.report.vehicle, value: 'name'},
|
|
433
|
+
{label: translations.settings.vehicle_licenseplate, value: 'licenseplate'},
|
|
123
434
|
{label: translations.report.group, value: 'group'},
|
|
124
435
|
{label: translations.report.distance, value: 'distance'})
|
|
125
436
|
}
|
|
126
437
|
|
|
127
438
|
let data = []
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
439
|
+
const info = userData.byDriver ? reportData.drivers : reportData.devices
|
|
440
|
+
info.forEach(d => {
|
|
441
|
+
const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.driver.id)) :
|
|
442
|
+
userData.groups.find(g => d.device.groupId === g.id)
|
|
132
443
|
|
|
133
|
-
|
|
134
|
-
|
|
444
|
+
if (userData.groupByDay) {
|
|
445
|
+
data = data.concat([{}])
|
|
446
|
+
data = data.concat(d.days.map(a => {
|
|
447
|
+
return {
|
|
448
|
+
name: d.device.name,
|
|
135
449
|
group: group ? group.name : '',
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
450
|
+
licenseplate: d.device.attributes.license_plate,
|
|
451
|
+
date: a.date,
|
|
452
|
+
weekday: weekDays[a.date.getDay()],
|
|
453
|
+
distance: Number((a.kms / 1000).toFixed(0))
|
|
454
|
+
}
|
|
455
|
+
}))
|
|
456
|
+
} else {
|
|
457
|
+
data = data.concat([{
|
|
458
|
+
name: userData.byDriver ? d.driver.name : d.device.name,
|
|
459
|
+
group: group ? group.name : '',
|
|
460
|
+
licenseplate: userData.byDriver ? '' : d.device.attributes.license_plate,
|
|
461
|
+
distance: Number((d.summary.distance / 1000).toFixed(0))
|
|
462
|
+
}])
|
|
145
463
|
}
|
|
146
|
-
}
|
|
147
|
-
if (reportData.devices) {
|
|
148
|
-
reportData.devices.forEach(d => {
|
|
149
|
-
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
464
|
+
})
|
|
150
465
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}])
|
|
156
|
-
})
|
|
157
|
-
console.log(data)
|
|
158
|
-
return {
|
|
159
|
-
headers,
|
|
160
|
-
data,
|
|
161
|
-
settings
|
|
162
|
-
}
|
|
163
|
-
}
|
|
466
|
+
return {
|
|
467
|
+
headers,
|
|
468
|
+
data,
|
|
469
|
+
settings
|
|
164
470
|
}
|
|
165
471
|
}
|
|
166
472
|
|
package/src/location-report.js
CHANGED
|
@@ -2,7 +2,10 @@ const automaticReports = require("./automaticReports");
|
|
|
2
2
|
const messages = require('../lang')
|
|
3
3
|
const jsPDF = require('jspdf')
|
|
4
4
|
require('jspdf-autotable')
|
|
5
|
-
const
|
|
5
|
+
const {headerFromUser} = require("./util/pdfDocument");
|
|
6
|
+
const {getStyle} = require("./reportStyle")
|
|
7
|
+
const {getUserPartner} = require("fleetmap-partners");
|
|
8
|
+
const {convertToLocaleString} = require("./util/utils");
|
|
6
9
|
|
|
7
10
|
const fileName = 'LocationReport'
|
|
8
11
|
|
|
@@ -98,10 +101,11 @@ function processDevices(from, to, devices, drivers, data) {
|
|
|
98
101
|
return devicesResult
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
function exportLocationReportToPDF(userData, reportData) {
|
|
104
|
+
async function exportLocationReportToPDF(userData, reportData) {
|
|
102
105
|
console.log('Export to PDF')
|
|
103
106
|
|
|
104
107
|
const lang = userData.user.attributes.lang
|
|
108
|
+
const timezone = userData.user.attributes.timezone
|
|
105
109
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
106
110
|
|
|
107
111
|
const headers = [
|
|
@@ -110,14 +114,13 @@ function exportLocationReportToPDF(userData, reportData) {
|
|
|
110
114
|
translations.report.speed,
|
|
111
115
|
translations.report.ignition,
|
|
112
116
|
translations.report.driver,
|
|
113
|
-
translations.temperature
|
|
117
|
+
translations.report.temperature
|
|
114
118
|
]
|
|
115
119
|
|
|
116
120
|
if (reportData.devices) {
|
|
117
121
|
let first = true
|
|
118
122
|
const doc = new jsPDF.jsPDF('l');
|
|
119
|
-
doc.
|
|
120
|
-
doc.text(translations.report.titleLocationReport, 15, 15)
|
|
123
|
+
await headerFromUser(doc, translations.report.titleLocationReport, userData.user)
|
|
121
124
|
|
|
122
125
|
reportData.devices.forEach(d => {
|
|
123
126
|
let data = []
|
|
@@ -131,11 +134,11 @@ function exportLocationReportToPDF(userData, reportData) {
|
|
|
131
134
|
first = false
|
|
132
135
|
space = 10
|
|
133
136
|
}
|
|
134
|
-
doc.setFontSize(
|
|
137
|
+
doc.setFontSize(13)
|
|
135
138
|
doc.text(name, 20, space + 20)
|
|
136
|
-
doc.setFontSize(
|
|
139
|
+
doc.setFontSize(11)
|
|
137
140
|
doc.text(group, 200, space + 20)
|
|
138
|
-
doc.text(
|
|
141
|
+
doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
|
|
139
142
|
d.positions.map(a => {
|
|
140
143
|
const temp = [
|
|
141
144
|
getLocationDate(a, userData.user),
|
|
@@ -153,22 +156,26 @@ function exportLocationReportToPDF(userData, reportData) {
|
|
|
153
156
|
'', getMaxSpeed(d.positions)
|
|
154
157
|
]
|
|
155
158
|
|
|
159
|
+
const style = getStyle(getUserPartner(userData.user))
|
|
156
160
|
doc.autoTable({
|
|
157
161
|
head: [headers],
|
|
158
162
|
body: data,
|
|
159
163
|
foot: [footValues],
|
|
160
164
|
showFoot: 'lastPage',
|
|
161
165
|
headStyles: {
|
|
162
|
-
fillColor:
|
|
163
|
-
textColor:
|
|
166
|
+
fillColor: style.pdfHeaderColor,
|
|
167
|
+
textColor: style.pdfHeaderTextColor,
|
|
168
|
+
fontSize: 10
|
|
164
169
|
},
|
|
165
170
|
bodyStyles: {
|
|
166
|
-
fillColor:
|
|
167
|
-
textColor:
|
|
171
|
+
fillColor: style.pdfBodyColor,
|
|
172
|
+
textColor: style.pdfBodyTextColor,
|
|
173
|
+
fontSize: 8
|
|
168
174
|
},
|
|
169
175
|
footStyles: {
|
|
170
|
-
fillColor:
|
|
171
|
-
textColor:
|
|
176
|
+
fillColor: style.pdfFooterColor,
|
|
177
|
+
textColor: style.pdfFooterTextColor,
|
|
178
|
+
fontSize: 9
|
|
172
179
|
},
|
|
173
180
|
startY: space + 35
|
|
174
181
|
});
|
|
@@ -246,10 +253,7 @@ function deviceName(device){
|
|
|
246
253
|
}
|
|
247
254
|
|
|
248
255
|
function getLocationDate(location, user){
|
|
249
|
-
return
|
|
250
|
-
timeZone: user.attributes.timezone,
|
|
251
|
-
hour12: false
|
|
252
|
-
})
|
|
256
|
+
return convertToLocaleString(location.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
253
257
|
}
|
|
254
258
|
|
|
255
259
|
function getDriverName(location, drivers) {
|