fleetmap-reports 1.0.287 → 1.0.288
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/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/modules.xml +1 -1
- package/.idea/vcs.xml +1 -1
- package/{.idea/fleetmap-reports.iml → fleetmap-reports.iml} +1 -2
- package/lang/enGB.js +2 -12
- package/lang/esCL.js +1 -10
- package/lang/index.js +1 -4
- package/lang/ptBR.js +1 -11
- package/lang/ptPT.js +1 -11
- package/package.json +1 -2
- package/src/activity-report.js +206 -542
- package/src/automaticReports.js +1 -1
- package/src/events-report.js +21 -25
- package/src/here.js +1 -1
- package/src/index.js +2 -12
- package/src/index.test.js +27 -60
- package/src/kms-report.js +103 -409
- package/src/location-report.js +18 -22
- package/src/refueling-report.js +1 -11
- package/src/reportStyle.js +0 -26
- package/src/speeding-report.js +180 -232
- package/src/trip-report.js +159 -152
- package/src/util/driver.js +13 -5
- package/src/util/utils.js +1 -67
- package/src/zone-report.js +23 -22
- package/.idea/aws.xml +0 -17
- package/.idea/runConfigurations.xml +0 -10
- package/.idea/shelf/Uncommitted_changes_before_Update_at_13_01_2022,_12_06_[Changes]/shelved.patch +0 -111
- package/.idea/shelf/Uncommitted_changes_before_Update_at_13_01_2022__12_06__Changes_.xml +0 -4
- package/.idea/workspace.xml +0 -515
- package/src/idle-report.js +0 -285
- package/src/tests/index.js +0 -22
- package/src/util/pdfDocument.js +0 -58
- package/src/util/traccar.js +0 -72
- package/src/util/trips.js +0 -76
package/src/kms-report.js
CHANGED
|
@@ -1,392 +1,100 @@
|
|
|
1
|
+
const {createActivityReport} = require("./activity-report");
|
|
1
2
|
const messages = require('../lang')
|
|
2
3
|
const jsPDF = require('jspdf')
|
|
3
4
|
require('jspdf-autotable')
|
|
4
|
-
const
|
|
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");
|
|
5
|
+
const reportStyle = require("./reportStyle")
|
|
12
6
|
|
|
13
7
|
|
|
14
8
|
let traccarInstance
|
|
15
|
-
let userData
|
|
16
9
|
|
|
17
10
|
const fileName = 'KmsReport'
|
|
18
11
|
|
|
19
|
-
async function createKmsReport(from, to,
|
|
12
|
+
async function createKmsReport(from, to, userData, traccar) {
|
|
20
13
|
console.log('Create KmsReport')
|
|
21
|
-
|
|
22
|
-
console.log(from, to)
|
|
23
14
|
traccarInstance = traccar
|
|
24
|
-
userData
|
|
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
|
|
15
|
+
return await createActivityReport(from, to, userData, traccar)
|
|
259
16
|
}
|
|
260
17
|
|
|
261
|
-
|
|
262
|
-
const lang = userData.user.attributes.lang
|
|
18
|
+
function exportKmsReportToPDF(userData, reportData) {
|
|
19
|
+
const lang = userData.user.attributes.lang
|
|
263
20
|
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
|
-
]
|
|
275
21
|
|
|
276
22
|
const headers = []
|
|
277
|
-
if(userData.
|
|
278
|
-
headers.push(translations.report.date,
|
|
279
|
-
translations.report.distance)
|
|
280
|
-
}
|
|
281
|
-
else if(userData.byDriver) {
|
|
23
|
+
if(userData.byDriver) {
|
|
282
24
|
headers.push(translations.report.driver,
|
|
283
25
|
translations.report.group,
|
|
284
26
|
translations.report.distance)
|
|
285
27
|
} else {
|
|
286
28
|
headers.push(translations.report.name,
|
|
287
|
-
translations.settings.vehicle_model,
|
|
288
29
|
translations.report.group,
|
|
289
30
|
translations.report.distance)
|
|
290
31
|
}
|
|
291
|
-
if (
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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)
|
|
32
|
+
if (reportData.devices || reportData.drivers) {
|
|
33
|
+
const doc = new jsPDF.jsPDF('l');
|
|
34
|
+
doc.setFontSize(14)
|
|
35
|
+
doc.text(translations.report.titleKmsReport, 15, 15 )
|
|
36
|
+
|
|
37
|
+
let data = []
|
|
38
|
+
doc.setFontSize(10)
|
|
39
|
+
doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, 30 )
|
|
40
|
+
if(userData.byDriver) {
|
|
41
|
+
reportData.drivers.forEach(d => {
|
|
42
|
+
const group = userData.groups.find(g => g.drivers.includes(d.driver.id))
|
|
43
|
+
|
|
44
|
+
const temp = [
|
|
45
|
+
d.driver.name,
|
|
46
|
+
group ? group.name : '',
|
|
47
|
+
Number((d.summary.distance / 1000).toFixed(0)),
|
|
48
|
+
]
|
|
49
|
+
data.push(temp)
|
|
342
50
|
})
|
|
343
51
|
} else {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
}
|
|
52
|
+
reportData.devices.forEach(d => {
|
|
53
|
+
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
54
|
+
|
|
55
|
+
const temp = [
|
|
56
|
+
d.summary.deviceName,
|
|
57
|
+
group ? group.name : '',
|
|
58
|
+
Number((d.summary.distance / 1000).toFixed(0))
|
|
59
|
+
]
|
|
60
|
+
data.push(temp)
|
|
61
|
+
})
|
|
62
|
+
}
|
|
369
63
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
64
|
+
const footValues = []
|
|
65
|
+
if(userData.byDriver) {
|
|
66
|
+
footValues.push(
|
|
67
|
+
'Total:' + reportData.drivers.length,
|
|
68
|
+
'',
|
|
69
|
+
(reportData.drivers.reduce((a, b) => a + b.summary.distance, 0)/1000).toFixed(0)
|
|
70
|
+
)
|
|
71
|
+
} else {
|
|
72
|
+
footValues.push(
|
|
73
|
+
'Total:' + reportData.devices.length,
|
|
74
|
+
'',
|
|
75
|
+
(reportData.devices.reduce((a, b) => a + b.summary.distance, 0)/1000).toFixed(0),
|
|
76
|
+
)
|
|
77
|
+
}
|
|
385
78
|
|
|
386
|
-
|
|
79
|
+
doc.autoTable({
|
|
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 });
|
|
387
97
|
|
|
388
|
-
addTable(doc, headers, data, footValues, style, 35)
|
|
389
|
-
}
|
|
390
98
|
return doc
|
|
391
99
|
}
|
|
392
100
|
}
|
|
@@ -394,19 +102,9 @@ async function exportKmsReportToPDF(userData, reportData) {
|
|
|
394
102
|
function exportKmsReportToExcel(userData, reportData) {
|
|
395
103
|
console.log('Export to Excel')
|
|
396
104
|
|
|
397
|
-
const lang = userData.user.attributes.lang
|
|
105
|
+
const lang = userData.user.attributes.lang
|
|
398
106
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
399
107
|
|
|
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
|
-
|
|
410
108
|
const settings = {
|
|
411
109
|
sheetName: translations.report.titleKmsReport, // The name of the sheet
|
|
412
110
|
fileName: fileName // The name of the spreadsheet
|
|
@@ -414,59 +112,55 @@ function exportKmsReportToExcel(userData, reportData) {
|
|
|
414
112
|
|
|
415
113
|
const headers = []
|
|
416
114
|
|
|
417
|
-
if(userData.
|
|
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) {
|
|
115
|
+
if(userData.byDriver) {
|
|
426
116
|
headers.push(
|
|
427
|
-
{label: translations.report.driver, value: '
|
|
117
|
+
{label: translations.report.driver, value: 'driver'},
|
|
428
118
|
{label: translations.report.group, value: 'group'},
|
|
429
119
|
{label: translations.report.distance, value: 'distance'})
|
|
430
120
|
} else {
|
|
431
121
|
headers.push(
|
|
432
122
|
{label: translations.report.vehicle, value: 'name'},
|
|
433
|
-
{label: translations.settings.vehicle_licenseplate, value: 'licenseplate'},
|
|
434
123
|
{label: translations.report.group, value: 'group'},
|
|
435
124
|
{label: translations.report.distance, value: 'distance'})
|
|
436
125
|
}
|
|
437
126
|
|
|
438
127
|
let data = []
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
128
|
+
if(userData.byDriver){
|
|
129
|
+
if (reportData.drivers) {
|
|
130
|
+
reportData.drivers.forEach(d => {
|
|
131
|
+
const group = userData.groups.find(g => g.drivers.includes(d.driver.id))
|
|
443
132
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
data = data.concat(d.days.map(a => {
|
|
447
|
-
return {
|
|
448
|
-
name: d.device.name,
|
|
133
|
+
data = data.concat([{
|
|
134
|
+
driver: d.driver.name,
|
|
449
135
|
group: group ? group.name : '',
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
group: group ? group.name : '',
|
|
460
|
-
licenseplate: userData.byDriver ? '' : d.device.attributes.license_plate,
|
|
461
|
-
distance: Number((d.summary.distance / 1000).toFixed(0))
|
|
462
|
-
}])
|
|
136
|
+
distance: Number((d.summary.distance / 1000).toFixed(0))
|
|
137
|
+
}])
|
|
138
|
+
})
|
|
139
|
+
console.log(data)
|
|
140
|
+
return {
|
|
141
|
+
headers,
|
|
142
|
+
data,
|
|
143
|
+
settings
|
|
144
|
+
}
|
|
463
145
|
}
|
|
464
|
-
}
|
|
146
|
+
} else {
|
|
147
|
+
if (reportData.devices) {
|
|
148
|
+
reportData.devices.forEach(d => {
|
|
149
|
+
const group = userData.groups.find(g => d.device.groupId === g.id)
|
|
465
150
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
151
|
+
data = data.concat([{
|
|
152
|
+
name: d.summary.deviceName,
|
|
153
|
+
group: group ? group.name : '',
|
|
154
|
+
distance: Number((d.summary.distance / 1000).toFixed(0))
|
|
155
|
+
}])
|
|
156
|
+
})
|
|
157
|
+
console.log(data)
|
|
158
|
+
return {
|
|
159
|
+
headers,
|
|
160
|
+
data,
|
|
161
|
+
settings
|
|
162
|
+
}
|
|
163
|
+
}
|
|
470
164
|
}
|
|
471
165
|
}
|
|
472
166
|
|
package/src/location-report.js
CHANGED
|
@@ -2,10 +2,7 @@ const automaticReports = require("./automaticReports");
|
|
|
2
2
|
const messages = require('../lang')
|
|
3
3
|
const jsPDF = require('jspdf')
|
|
4
4
|
require('jspdf-autotable')
|
|
5
|
-
const
|
|
6
|
-
const {getStyle} = require("./reportStyle")
|
|
7
|
-
const {getUserPartner} = require("fleetmap-partners");
|
|
8
|
-
const {convertToLocaleString} = require("./util/utils");
|
|
5
|
+
const reportStyle = require("./reportStyle")
|
|
9
6
|
|
|
10
7
|
const fileName = 'LocationReport'
|
|
11
8
|
|
|
@@ -101,11 +98,10 @@ function processDevices(from, to, devices, drivers, data) {
|
|
|
101
98
|
return devicesResult
|
|
102
99
|
}
|
|
103
100
|
|
|
104
|
-
|
|
101
|
+
function exportLocationReportToPDF(userData, reportData) {
|
|
105
102
|
console.log('Export to PDF')
|
|
106
103
|
|
|
107
104
|
const lang = userData.user.attributes.lang
|
|
108
|
-
const timezone = userData.user.attributes.timezone
|
|
109
105
|
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
110
106
|
|
|
111
107
|
const headers = [
|
|
@@ -114,13 +110,14 @@ async function exportLocationReportToPDF(userData, reportData) {
|
|
|
114
110
|
translations.report.speed,
|
|
115
111
|
translations.report.ignition,
|
|
116
112
|
translations.report.driver,
|
|
117
|
-
translations.
|
|
113
|
+
translations.temperature
|
|
118
114
|
]
|
|
119
115
|
|
|
120
116
|
if (reportData.devices) {
|
|
121
117
|
let first = true
|
|
122
118
|
const doc = new jsPDF.jsPDF('l');
|
|
123
|
-
|
|
119
|
+
doc.setFontSize(14)
|
|
120
|
+
doc.text(translations.report.titleLocationReport, 15, 15)
|
|
124
121
|
|
|
125
122
|
reportData.devices.forEach(d => {
|
|
126
123
|
let data = []
|
|
@@ -134,11 +131,11 @@ async function exportLocationReportToPDF(userData, reportData) {
|
|
|
134
131
|
first = false
|
|
135
132
|
space = 10
|
|
136
133
|
}
|
|
137
|
-
doc.setFontSize(
|
|
134
|
+
doc.setFontSize(12)
|
|
138
135
|
doc.text(name, 20, space + 20)
|
|
139
|
-
doc.setFontSize(
|
|
136
|
+
doc.setFontSize(10)
|
|
140
137
|
doc.text(group, 200, space + 20)
|
|
141
|
-
doc.text(
|
|
138
|
+
doc.text(new Date(d.from).toLocaleString() + ' - ' + new Date(d.to).toLocaleString(), 20, space + 25)
|
|
142
139
|
d.positions.map(a => {
|
|
143
140
|
const temp = [
|
|
144
141
|
getLocationDate(a, userData.user),
|
|
@@ -156,26 +153,22 @@ async function exportLocationReportToPDF(userData, reportData) {
|
|
|
156
153
|
'', getMaxSpeed(d.positions)
|
|
157
154
|
]
|
|
158
155
|
|
|
159
|
-
const style = getStyle(getUserPartner(userData.user))
|
|
160
156
|
doc.autoTable({
|
|
161
157
|
head: [headers],
|
|
162
158
|
body: data,
|
|
163
159
|
foot: [footValues],
|
|
164
160
|
showFoot: 'lastPage',
|
|
165
161
|
headStyles: {
|
|
166
|
-
fillColor:
|
|
167
|
-
textColor:
|
|
168
|
-
fontSize: 10
|
|
162
|
+
fillColor: reportStyle.pdfHeaderColor,
|
|
163
|
+
textColor: reportStyle.pdfHeaderTextColor
|
|
169
164
|
},
|
|
170
165
|
bodyStyles: {
|
|
171
|
-
fillColor:
|
|
172
|
-
textColor:
|
|
173
|
-
fontSize: 8
|
|
166
|
+
fillColor: reportStyle.pdfBodyColor,
|
|
167
|
+
textColor: reportStyle.pdfBodyTextColor
|
|
174
168
|
},
|
|
175
169
|
footStyles: {
|
|
176
|
-
fillColor:
|
|
177
|
-
textColor:
|
|
178
|
-
fontSize: 9
|
|
170
|
+
fillColor: reportStyle.pdfFooterColor,
|
|
171
|
+
textColor: reportStyle.pdfFooterTextColor
|
|
179
172
|
},
|
|
180
173
|
startY: space + 35
|
|
181
174
|
});
|
|
@@ -253,7 +246,10 @@ function deviceName(device){
|
|
|
253
246
|
}
|
|
254
247
|
|
|
255
248
|
function getLocationDate(location, user){
|
|
256
|
-
return
|
|
249
|
+
return new Date(location.fixTime).toLocaleString(user.attributes.lang, {
|
|
250
|
+
timeZone: user.attributes.timezone,
|
|
251
|
+
hour12: false
|
|
252
|
+
})
|
|
257
253
|
}
|
|
258
254
|
|
|
259
255
|
function getDriverName(location, drivers) {
|