fleetmap-reports 1.0.284 → 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/jsLibraryMappings.xml +1 -1
- package/.idea/modules.xml +1 -1
- package/.idea/vcs.xml +1 -1
- package/{.idea/fleetmap-reports.iml → fleetmap-reports.iml} +1 -2
- package/lang/enGB.js +1 -11
- 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 +25 -18
- 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 -239
- 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/codeStyles/Project.xml +0 -7
- 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/.idea/aws.xml
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="accountSettings">
|
|
4
|
-
<option name="activeProfile" value="profile:default" />
|
|
5
|
-
<option name="activeRegion" value="us-east-1" />
|
|
6
|
-
<option name="recentlyUsedProfiles">
|
|
7
|
-
<list>
|
|
8
|
-
<option value="profile:default" />
|
|
9
|
-
</list>
|
|
10
|
-
</option>
|
|
11
|
-
<option name="recentlyUsedRegions">
|
|
12
|
-
<list>
|
|
13
|
-
<option value="us-east-1" />
|
|
14
|
-
</list>
|
|
15
|
-
</option>
|
|
16
|
-
</component>
|
|
17
|
-
</project>
|
package/src/idle-report.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
const traccar = require("./util/traccar");
|
|
2
|
-
const messages = require("../lang");
|
|
3
|
-
const jsPDF = require("jspdf");
|
|
4
|
-
const {headerFromUser, AmiriRegular} = require("./util/pdfDocument");
|
|
5
|
-
const {convertToLocaleString, convertMS} = require("./util/utils");
|
|
6
|
-
const {getStyle} = require("./reportStyle");
|
|
7
|
-
const {getUserPartner} = require("fleetmap-partners");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let traccarInstance
|
|
11
|
-
let userData
|
|
12
|
-
|
|
13
|
-
const fileName = 'IdleReport'
|
|
14
|
-
|
|
15
|
-
async function createIdleReport(from, to, reportUserData, traccar) {
|
|
16
|
-
console.log('Create IdleReport')
|
|
17
|
-
userData = reportUserData
|
|
18
|
-
traccarInstance = traccar
|
|
19
|
-
const reportData = []
|
|
20
|
-
|
|
21
|
-
if (userData.byGroup) {
|
|
22
|
-
console.log("ByGroup")
|
|
23
|
-
const allData = await createTripReportByGroup(from, to)
|
|
24
|
-
reportData.push(...allData)
|
|
25
|
-
} else {
|
|
26
|
-
console.log("ByDevice")
|
|
27
|
-
const report = await createTripReportByDevice(from, to)
|
|
28
|
-
reportData.push(report)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return reportData
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function createTripReportByGroup(from, to) {
|
|
35
|
-
const reportData = []
|
|
36
|
-
for (const g of userData.groups) {
|
|
37
|
-
const devices = userData.devices.filter(d => d.groupId === g.id)
|
|
38
|
-
console.log(g.name + ' devices:' + devices.length)
|
|
39
|
-
if(devices.length > 0) {
|
|
40
|
-
const groupData = {
|
|
41
|
-
devices: [],
|
|
42
|
-
group: g,
|
|
43
|
-
from: from,
|
|
44
|
-
to: to
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const response = await traccarInstance.reports.reportsRouteGet(from, to, null, [g.id])
|
|
48
|
-
const routes = response.data
|
|
49
|
-
|
|
50
|
-
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
51
|
-
|
|
52
|
-
if (routes.length > 0) {
|
|
53
|
-
console.log('Routes:' + routes.length)
|
|
54
|
-
groupData.devices = processDevices(from, to, devices, routes)
|
|
55
|
-
|
|
56
|
-
reportData.push(groupData)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const groupIds = userData.groups.map(g => g.id)
|
|
62
|
-
const withoutGroupDevices = userData.devices.filter(d => !groupIds.includes(d.groupId))
|
|
63
|
-
|
|
64
|
-
const allData = await createTripReportByDevice(from, to, withoutGroupDevices)
|
|
65
|
-
reportData.push(allData)
|
|
66
|
-
|
|
67
|
-
return reportData
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function createTripReportByDevice(from, to) {
|
|
71
|
-
const devices = userData.devices
|
|
72
|
-
const allData = {
|
|
73
|
-
devices: [],
|
|
74
|
-
from: from,
|
|
75
|
-
to: to
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
devices.sort((a, b) => (a.name > b.name) ? 1 : -1)
|
|
79
|
-
|
|
80
|
-
const devicesToSlice = devices.slice()
|
|
81
|
-
const route = await traccar.getRoute(traccarInstance, from, to, devicesToSlice)
|
|
82
|
-
|
|
83
|
-
console.log('Route:' + route.length)
|
|
84
|
-
|
|
85
|
-
if (route.length > 0) {
|
|
86
|
-
allData.devices = processDevices(from, to, devices, route)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return allData
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function processDevices(from, to, devices, routes) {
|
|
93
|
-
const devicesResult = []
|
|
94
|
-
|
|
95
|
-
devices.forEach(d => {
|
|
96
|
-
const route = routes.filter(p => p.deviceId === d.id)
|
|
97
|
-
|
|
98
|
-
const idleEvents = []
|
|
99
|
-
let inIdle = false
|
|
100
|
-
route.forEach(p => {
|
|
101
|
-
if(p.attributes.ignition && p.speed === 0){
|
|
102
|
-
if(!inIdle) {
|
|
103
|
-
const idleEvent = {
|
|
104
|
-
position: p,
|
|
105
|
-
idleTime: 0
|
|
106
|
-
}
|
|
107
|
-
idleEvents.push(idleEvent)
|
|
108
|
-
inIdle = true
|
|
109
|
-
}
|
|
110
|
-
} else if(inIdle) {
|
|
111
|
-
const currentIdleEvent = idleEvents[idleEvents.length-1]
|
|
112
|
-
currentIdleEvent.idleTime = new Date(p.fixTime) - new Date(currentIdleEvent.position.fixTime)
|
|
113
|
-
inIdle = false
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
if(idleEvents.length) {
|
|
118
|
-
const deviceData = {
|
|
119
|
-
device: d,
|
|
120
|
-
idleEvents: idleEvents
|
|
121
|
-
}
|
|
122
|
-
devicesResult.push(deviceData)
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
return devicesResult
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function exportIdleReportToPDF(userData, reportData) {
|
|
130
|
-
console.log('Export to PDF')
|
|
131
|
-
|
|
132
|
-
const lang = userData.user.attributes.lang
|
|
133
|
-
const timezone = userData.user.attributes.timezone
|
|
134
|
-
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
135
|
-
|
|
136
|
-
const idleData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
137
|
-
|
|
138
|
-
const headers = [
|
|
139
|
-
translations.report.date,
|
|
140
|
-
translations.report.address,
|
|
141
|
-
translations.report.duration
|
|
142
|
-
]
|
|
143
|
-
|
|
144
|
-
if (userData.byDriver) {
|
|
145
|
-
headers.push(translations.report.vehicle)
|
|
146
|
-
} else {
|
|
147
|
-
headers.push(translations.report.driver)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (idleData) {
|
|
151
|
-
let first = true
|
|
152
|
-
const doc = new jsPDF.jsPDF('l');
|
|
153
|
-
await headerFromUser(doc, translations.report.titleIdleReport, userData.user)
|
|
154
|
-
|
|
155
|
-
idleData.forEach(d => {
|
|
156
|
-
try {
|
|
157
|
-
let data = []
|
|
158
|
-
|
|
159
|
-
const name = userData.byDriver ? d.driver.name : deviceName(d.device)
|
|
160
|
-
const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
|
|
161
|
-
|
|
162
|
-
let space = 0
|
|
163
|
-
if(!first) {
|
|
164
|
-
doc.addPage()
|
|
165
|
-
} else {
|
|
166
|
-
first = false
|
|
167
|
-
space = 10
|
|
168
|
-
}
|
|
169
|
-
doc.setFontSize(13)
|
|
170
|
-
doc.text(name, 20, space+20 )
|
|
171
|
-
doc.setFontSize(11)
|
|
172
|
-
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space+20 )
|
|
173
|
-
doc.text(convertToLocaleString(reportData.from, lang, timezone) + ' - ' + convertToLocaleString(reportData.to, lang, timezone), 20, space+25 )
|
|
174
|
-
|
|
175
|
-
d.idleEvents.map(a => {
|
|
176
|
-
const temp = [
|
|
177
|
-
getIdleEventDate(a, userData.user),
|
|
178
|
-
a.position.address,
|
|
179
|
-
convertMS(a.idleTime, true),
|
|
180
|
-
userData.byDriver ? a.deviceName : a.driver
|
|
181
|
-
]
|
|
182
|
-
|
|
183
|
-
data.push(temp)
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
const footValues = [
|
|
187
|
-
'Total:' + d.idleEvents.length,
|
|
188
|
-
'',
|
|
189
|
-
convertMS(d.idleEvents.reduce((a, b) => a + b.idleTime, 0), true)
|
|
190
|
-
]
|
|
191
|
-
|
|
192
|
-
if(userData.roadSpeedLimits){
|
|
193
|
-
footValues.splice(2, 0, '')
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
doc.addFileToVFS("Amiri-Regular.ttf", AmiriRegular());
|
|
197
|
-
doc.addFont("Amiri-Regular.ttf", "Amiri", "normal");
|
|
198
|
-
|
|
199
|
-
const style = getStyle(getUserPartner(userData.user))
|
|
200
|
-
doc.autoTable({
|
|
201
|
-
head: [headers],
|
|
202
|
-
body: data,
|
|
203
|
-
foot: [footValues],
|
|
204
|
-
showFoot: 'lastPage',
|
|
205
|
-
headStyles: {
|
|
206
|
-
fillColor: style.pdfHeaderColor,
|
|
207
|
-
textColor: style.pdfHeaderTextColor,
|
|
208
|
-
fontSize: 10
|
|
209
|
-
},
|
|
210
|
-
bodyStyles: {
|
|
211
|
-
fillColor: style.pdfBodyColor,
|
|
212
|
-
textColor: style.pdfBodyTextColor,
|
|
213
|
-
fontSize: 8,
|
|
214
|
-
font: timezone === 'Asia/Qatar' ? "Amiri" : ''
|
|
215
|
-
|
|
216
|
-
},
|
|
217
|
-
footStyles: {
|
|
218
|
-
fillColor: style.pdfFooterColor,
|
|
219
|
-
textColor: style.pdfFooterTextColor,
|
|
220
|
-
fontSize: 9
|
|
221
|
-
},
|
|
222
|
-
startY: space+35 });
|
|
223
|
-
} catch (e) {
|
|
224
|
-
console.error(e, 'moving on...')
|
|
225
|
-
}
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
return doc
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function exportIdleReportToExcel(userData, reportData) {
|
|
233
|
-
console.log('Export to Excel')
|
|
234
|
-
|
|
235
|
-
const lang = userData.user.attributes.lang
|
|
236
|
-
const translations = messages[lang] ? messages[lang] : messages['en-GB']
|
|
237
|
-
|
|
238
|
-
const idleData = userData.byDriver ? reportData.drivers : reportData.devices
|
|
239
|
-
|
|
240
|
-
const settings = {
|
|
241
|
-
sheetName: translations.report.titleIdleReport.substring(0, 31), // The name of the sheet
|
|
242
|
-
fileName: fileName, // The name of the spreadsheet
|
|
243
|
-
}
|
|
244
|
-
const headers = [
|
|
245
|
-
userData.byDriver ? {label: translations.report.driver, value:'driver'} : {label: translations.report.vehicle, value:'name'},
|
|
246
|
-
{label: translations.report.date, value:'fixTime'},
|
|
247
|
-
{label: translations.report.address, value:'address'},
|
|
248
|
-
{label: translations.report.duration, value:'duration'},
|
|
249
|
-
userData.byDriver ? {label: translations.report.vehicle, value:'name'} : {label: translations.report.driver, value:'driver'}
|
|
250
|
-
]
|
|
251
|
-
|
|
252
|
-
let data = []
|
|
253
|
-
if (idleData) {
|
|
254
|
-
idleData.forEach(d => {
|
|
255
|
-
data = data.concat([{}])
|
|
256
|
-
data = data.concat(d.idleEvents.map(a => {
|
|
257
|
-
return {
|
|
258
|
-
driver: userData.byDriver ? d.driver.name : a.driver,
|
|
259
|
-
duration: convertMS(a.idleTime, true),
|
|
260
|
-
fixTime: getIdleEventDate(a, userData.user),
|
|
261
|
-
name: userData.byDriver ? a.deviceName : d.device.name,
|
|
262
|
-
address: a.position.address + (a.geofenceName ? ' - ' + a.geofenceName : '')
|
|
263
|
-
}
|
|
264
|
-
}))
|
|
265
|
-
})
|
|
266
|
-
console.log(data)
|
|
267
|
-
return {
|
|
268
|
-
headers,
|
|
269
|
-
data,
|
|
270
|
-
settings
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function deviceName(device){
|
|
276
|
-
return device.name + (device.attributes.license_plate ? ', ' +device.attributes.license_plate : '') + (device.model ? ', ' + device.model : '')
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
function getIdleEventDate(row, user) {
|
|
280
|
-
return convertToLocaleString(row.position.fixTime, user.attributes.lang, user.attributes.timezone)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
exports.createIdleReport = createIdleReport;
|
|
284
|
-
exports.exportIdleReportToPDF = exportIdleReportToPDF;
|
|
285
|
-
exports.exportIdleReportToExcel = exportIdleReportToExcel;
|
package/src/tests/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const {SessionApi} = require("traccar-api");
|
|
2
|
-
const axios = require('axios')
|
|
3
|
-
const axiosCookieJarSupport = require('axios-cookiejar-support').default;
|
|
4
|
-
const tough = require('tough-cookie');
|
|
5
|
-
const Index = require('../index');
|
|
6
|
-
const cookieJar = new tough.CookieJar();
|
|
7
|
-
const traccarConfig = {
|
|
8
|
-
basePath: 'https://api.pinme.io/api',
|
|
9
|
-
baseOptions: {
|
|
10
|
-
withCredentials: true,
|
|
11
|
-
jar: cookieJar
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
axiosCookieJarSupport(axios)
|
|
16
|
-
|
|
17
|
-
exports.getReports = async() => {
|
|
18
|
-
await new SessionApi(traccarConfig, null, axios).sessionPost(process.env.email, process.env.password)
|
|
19
|
-
return new Index(traccarConfig, axios)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|