fleetmap-reports 1.0.465 → 1.0.467
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/lang/enGB.js +1 -0
- package/lang/esCL.js +1 -0
- package/lang/ptBR.js +1 -0
- package/lang/ptPT.js +1 -0
- package/package.json +1 -1
- package/src/machines-report.js +49 -47
package/lang/enGB.js
CHANGED
package/lang/esCL.js
CHANGED
|
@@ -215,6 +215,7 @@ module.exports = {
|
|
|
215
215
|
endOdometer: 'End (Km)',
|
|
216
216
|
spentFuel: 'Consumo',
|
|
217
217
|
engineHours: 'Utilización (HH:mm)',
|
|
218
|
+
totalEngineHours: 'Utilización Total (H:m)',
|
|
218
219
|
driverHours: 'Tiempo de Conducción (H:m)',
|
|
219
220
|
refueling: 'Cargas',
|
|
220
221
|
fueldrop: 'Combustível Perdido (L)',
|
package/lang/ptBR.js
CHANGED
|
@@ -218,6 +218,7 @@ module.exports = {
|
|
|
218
218
|
endOdometer: 'Fim (Km)',
|
|
219
219
|
spentFuel: 'Consumo (L)',
|
|
220
220
|
engineHours: 'Utilização (H:m)',
|
|
221
|
+
totalEngineHours: 'Total Use (H:m)',
|
|
221
222
|
driverHours: 'Tempo de Condução (H:m)',
|
|
222
223
|
refueling: 'Abastecimentos',
|
|
223
224
|
fueldrop: 'Combustível Perdido (L)',
|
package/lang/ptPT.js
CHANGED
|
@@ -224,6 +224,7 @@ module.exports = {
|
|
|
224
224
|
endOdometer: 'Fim (Km)',
|
|
225
225
|
spentFuel: 'Consumo (L)',
|
|
226
226
|
engineHours: 'Utilização (H:m)',
|
|
227
|
+
totalEngineHours: 'Total Use (H:m)',
|
|
227
228
|
driverHours: 'Tempo de Condução (H:m)',
|
|
228
229
|
refueling: 'Abastecimentos',
|
|
229
230
|
fueldrop: 'Combustível Perdido (L)',
|
package/package.json
CHANGED
package/src/machines-report.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
const { devicesToProcess } = require('./util/device')
|
|
2
2
|
const automaticReports = require('./automaticReports')
|
|
3
3
|
const traccarHelper = require('./util/traccar')
|
|
4
|
-
const {
|
|
5
|
-
const { getDates, weekDaySelected, convertMS, getTranslations } = require('./util/utils')
|
|
4
|
+
const { getDates, convertMS, getTranslations, convertFromUTC } = require('./util/utils')
|
|
6
5
|
const { getStyle } = require('./reportStyle')
|
|
7
6
|
const { getUserPartner } = require('fleetmap-partners')
|
|
8
7
|
const { addTable, headerFromUser } = require('./util/pdfDocument')
|
|
@@ -36,15 +35,13 @@ async function createMachinesReportByDevice (from, to, userData, traccar) {
|
|
|
36
35
|
|
|
37
36
|
let deviceCount = 0
|
|
38
37
|
for (const slice of sliced) {
|
|
39
|
-
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true,
|
|
40
|
-
const tripsData = allInOne.trips
|
|
38
|
+
const allInOne = await traccarHelper.getAllInOne(traccar, from, to, slice, true, false, false, false, deviceCount, devices.length)
|
|
41
39
|
const routeData = allInOne.route
|
|
42
40
|
|
|
43
|
-
console.log('
|
|
41
|
+
console.log('Route:' + routeData.length)
|
|
44
42
|
|
|
45
|
-
if (
|
|
43
|
+
if (routeData.length > 0) {
|
|
46
44
|
allData.devices.push(...processDevices(from, to, slice, {
|
|
47
|
-
trips: tripsData,
|
|
48
45
|
route: routeData
|
|
49
46
|
}, userData))
|
|
50
47
|
}
|
|
@@ -54,58 +51,60 @@ async function createMachinesReportByDevice (from, to, userData, traccar) {
|
|
|
54
51
|
return allData
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
function createSummary (date, d, tripsByDay) {
|
|
58
|
-
return {
|
|
59
|
-
date,
|
|
60
|
-
deviceId: d.id,
|
|
61
|
-
engineHours: tripsByDay.reduce((a, b) => a + b.duration, 0),
|
|
62
|
-
startTime: tripsByDay.length && tripsByDay[0].startTime,
|
|
63
|
-
endTime: tripsByDay.length && tripsByDay[tripsByDay.length - 1].endTime
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
54
|
function processDevices (from, to, devices, data, userData) {
|
|
68
55
|
const devicesResult = []
|
|
69
56
|
|
|
70
57
|
devices.forEach(d => {
|
|
71
|
-
const deviceTrips = data.trips.filter(t => t.deviceId === d.id)
|
|
72
58
|
const deviceRoute = data.route.filter(t => t.deviceId === d.id)
|
|
73
59
|
|
|
74
|
-
if (deviceRoute.length > 0) {
|
|
75
|
-
let uncompletedTripRoute = []
|
|
76
|
-
if (deviceRoute.length && deviceTrips.length && deviceRoute[deviceRoute.length - 1].attributes.ignition) {
|
|
77
|
-
uncompletedTripRoute = deviceRoute.filter(p => p.attributes.ignition && new Date(p.fixTime).getTime() > new Date(deviceTrips[deviceTrips.length - 1].endTime).getTime())
|
|
78
|
-
if (uncompletedTripRoute.length) {
|
|
79
|
-
deviceTrips.push(calculateTrip(d, uncompletedTripRoute))
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
60
|
+
if (deviceRoute.filter(p => p.attributes.ignition && p.valid).length > 0) {
|
|
83
61
|
const summary = []
|
|
84
|
-
const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
|
85
62
|
|
|
86
|
-
const
|
|
63
|
+
const convertFrom = new Date(convertFromUTC(from, userData.user.attributes.timezone))
|
|
64
|
+
const convertTo = new Date(convertFromUTC(to, userData.user.attributes.timezone))
|
|
65
|
+
|
|
66
|
+
const dates = getDates(convertFrom, convertTo)
|
|
67
|
+
|
|
87
68
|
for (const date of dates) {
|
|
88
69
|
const fromByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0)
|
|
89
70
|
const toByDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59)
|
|
90
71
|
|
|
91
|
-
const
|
|
72
|
+
const routeByDay = deviceRoute.filter(p => (new Date(p.fixTime) > fromByDay && new Date(p.fixTime) < toByDay) && p.valid && p.attributes.hours !== undefined)
|
|
73
|
+
|
|
74
|
+
routeByDay.sort((a, b) => new Date(a.fixTime).getTime() - new Date(b.fixTime).getTime())
|
|
92
75
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
76
|
+
let firstOn
|
|
77
|
+
let lastOff
|
|
78
|
+
|
|
79
|
+
routeByDay.forEach(p => {
|
|
80
|
+
if (p.attributes.ignition || (firstOn && !p.attributes.ignition && lastOff.attributes.ignition)) {
|
|
81
|
+
lastOff = p
|
|
97
82
|
}
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
|
|
84
|
+
if (p.attributes.ignition && !firstOn) {
|
|
85
|
+
firstOn = p
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const dayData = {
|
|
90
|
+
date,
|
|
91
|
+
deviceId: d.id,
|
|
92
|
+
engineHours: firstOn ? routeByDay[routeByDay.length - 1].attributes.hours - routeByDay[0].attributes.hours : 0,
|
|
93
|
+
totalHours: routeByDay.length ? routeByDay[routeByDay.length - 1].attributes.hours : undefined,
|
|
94
|
+
startTime: firstOn ? firstOn.fixTime : undefined,
|
|
95
|
+
endTime: lastOff ? lastOff.fixTime : undefined
|
|
100
96
|
}
|
|
97
|
+
|
|
98
|
+
summary.push(dayData)
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
if (summary.length) {
|
|
102
|
+
const deviceData = {
|
|
103
|
+
device: d,
|
|
104
|
+
summary
|
|
105
|
+
}
|
|
106
|
+
devicesResult.push(deviceData)
|
|
107
107
|
}
|
|
108
|
-
devicesResult.push(deviceData)
|
|
109
108
|
}
|
|
110
109
|
})
|
|
111
110
|
|
|
@@ -121,7 +120,8 @@ async function exportMachinesReportToPDF (userData, reportData) {
|
|
|
121
120
|
const headers = [translations.report.date,
|
|
122
121
|
translations.report.start,
|
|
123
122
|
translations.report.end,
|
|
124
|
-
translations.report.engineHours
|
|
123
|
+
translations.report.engineHours,
|
|
124
|
+
translations.report.totalEngineHours]
|
|
125
125
|
|
|
126
126
|
const weekDays = [
|
|
127
127
|
translations.report.sunday,
|
|
@@ -137,7 +137,7 @@ async function exportMachinesReportToPDF (userData, reportData) {
|
|
|
137
137
|
const name = userData.byDriver ? d.driver.name : d.device.name
|
|
138
138
|
const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
|
|
139
139
|
|
|
140
|
-
const space = index === 0 ?
|
|
140
|
+
const space = index === 0 ? 8 : 0
|
|
141
141
|
if (index) {
|
|
142
142
|
doc.addPage()
|
|
143
143
|
}
|
|
@@ -147,7 +147,6 @@ async function exportMachinesReportToPDF (userData, reportData) {
|
|
|
147
147
|
doc.setFontSize(11)
|
|
148
148
|
doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
|
|
149
149
|
doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, space + 25)
|
|
150
|
-
doc.text('Total de horas de uso: ' + convertMS(d.totalEngineHours), 20, space + 30)
|
|
151
150
|
|
|
152
151
|
const data = []
|
|
153
152
|
d.summary.forEach(s => {
|
|
@@ -155,7 +154,8 @@ async function exportMachinesReportToPDF (userData, reportData) {
|
|
|
155
154
|
new Date(s.date).toLocaleDateString() + ' - ' + weekDays[s.date.getDay()],
|
|
156
155
|
s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
157
156
|
s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
158
|
-
convertMS(s.engineHours)
|
|
157
|
+
convertMS(s.engineHours),
|
|
158
|
+
s.totalHours ? convertMS(s.totalHours) : ''
|
|
159
159
|
]
|
|
160
160
|
|
|
161
161
|
data.push(temp)
|
|
@@ -196,7 +196,8 @@ async function exportMachinesReportToExcel (userData, reportData) {
|
|
|
196
196
|
{ label: translations.report.date, value: 'date' },
|
|
197
197
|
{ label: translations.report.start, value: 'start' },
|
|
198
198
|
{ label: translations.report.end, value: 'end' },
|
|
199
|
-
{ label: translations.report.engineHours, value: 'engineHours' }
|
|
199
|
+
{ label: translations.report.engineHours, value: 'engineHours' },
|
|
200
|
+
{ label: translations.report.totalEngineHours, value: 'totalEngineHours' }]
|
|
200
201
|
|
|
201
202
|
let data = []
|
|
202
203
|
reportData.devices.forEach(d => {
|
|
@@ -211,7 +212,8 @@ async function exportMachinesReportToExcel (userData, reportData) {
|
|
|
211
212
|
weekday: weekDays[s.date.getDay()],
|
|
212
213
|
start: s.startTime ? new Date(s.startTime).toLocaleTimeString() : '',
|
|
213
214
|
end: s.endTime ? new Date(s.endTime).toLocaleTimeString() : '',
|
|
214
|
-
engineHours: convertMS(s.engineHours)
|
|
215
|
+
engineHours: convertMS(s.engineHours),
|
|
216
|
+
totalEngineHours: s.totalHours ? convertMS(s.totalHours) : ''
|
|
215
217
|
}
|
|
216
218
|
}))
|
|
217
219
|
})
|