fleetmap-reports 1.0.668 → 1.0.669
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/package.json +1 -1
- package/src/kms-report.js +53 -49
package/package.json
CHANGED
package/src/kms-report.js
CHANGED
|
@@ -167,46 +167,48 @@ function processDevices (from, to, devices, data, userData) {
|
|
|
167
167
|
|
|
168
168
|
const trips = deviceTrips.filter(t => userData.allWeek || !userData.weekDays || isInsideTimetable(t, userData) || isPartialInsideTimetable(t, userData, deviceRoute))
|
|
169
169
|
|
|
170
|
-
if (
|
|
171
|
-
trips.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const allDates = getDates(from, to)
|
|
182
|
-
|
|
183
|
-
const days = []
|
|
184
|
-
let keys = Array.from(groupedTrips.keys())
|
|
185
|
-
allDates.forEach(d => {
|
|
186
|
-
d.setHours(12, 0, 0)
|
|
187
|
-
const day = d.toISOString()
|
|
188
|
-
if (!keys.includes(day)) {
|
|
189
|
-
groupedTrips.set(day, [])
|
|
190
|
-
}
|
|
191
|
-
})
|
|
170
|
+
if (userData.groupByDay) {
|
|
171
|
+
if (trips.length > 0) {
|
|
172
|
+
trips.forEach(t => {
|
|
173
|
+
const tripDay = convertFromUTC(t.startTime, userData.user.attributes.timezone)
|
|
174
|
+
tripDay.setHours(12, 0, 0)
|
|
175
|
+
t.tripDay = tripDay.toISOString()
|
|
176
|
+
})
|
|
177
|
+
const groupedTrips = trips.reduce(
|
|
178
|
+
(entryMap, e) => entryMap.set(e.tripDay, [...entryMap.get(e.tripDay) || [], e]),
|
|
179
|
+
new Map()
|
|
180
|
+
)
|
|
192
181
|
|
|
193
|
-
|
|
194
|
-
keys.sort((a, b) => new Date(a).getTime() - new Date(b).getTime())
|
|
195
|
-
keys.forEach(key => {
|
|
196
|
-
const currentDate = new Date(key)
|
|
197
|
-
const dayTrips = groupedTrips.get(key)
|
|
198
|
-
const day = {
|
|
199
|
-
date: currentDate,
|
|
200
|
-
kms: 0
|
|
201
|
-
}
|
|
202
|
-
day.kms = dayTrips.reduce((a, b) => a + b.distance, 0)
|
|
182
|
+
const allDates = getDates(from, to)
|
|
203
183
|
|
|
204
|
-
days
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
184
|
+
const days = []
|
|
185
|
+
let keys = Array.from(groupedTrips.keys())
|
|
186
|
+
allDates.forEach(d => {
|
|
187
|
+
d.setHours(12, 0, 0)
|
|
188
|
+
const day = d.toISOString()
|
|
189
|
+
if (!keys.includes(day)) {
|
|
190
|
+
groupedTrips.set(day, [])
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
keys = Array.from(groupedTrips.keys())
|
|
195
|
+
keys.sort((a, b) => new Date(a).getTime() - new Date(b).getTime())
|
|
196
|
+
keys.forEach(key => {
|
|
197
|
+
const currentDate = new Date(key)
|
|
198
|
+
const dayTrips = groupedTrips.get(key)
|
|
199
|
+
const day = {
|
|
200
|
+
date: currentDate,
|
|
201
|
+
kms: 0
|
|
202
|
+
}
|
|
203
|
+
day.kms = dayTrips.reduce((a, b) => a + b.distance, 0)
|
|
204
|
+
|
|
205
|
+
days.push(day)
|
|
206
|
+
})
|
|
207
|
+
devicesResult.push({
|
|
208
|
+
device: d,
|
|
209
|
+
days
|
|
210
|
+
})
|
|
211
|
+
}
|
|
210
212
|
} else {
|
|
211
213
|
devicesResult.push({
|
|
212
214
|
device: d,
|
|
@@ -384,17 +386,19 @@ function exportKmsReportToExcel (userData, reportData) {
|
|
|
384
386
|
: userData.groups.find(g => d.device.groupId === g.id)
|
|
385
387
|
|
|
386
388
|
if (userData.groupByDay) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
389
|
+
if (d.days) {
|
|
390
|
+
data = data.concat([{}])
|
|
391
|
+
data = data.concat(d.days.map(a => {
|
|
392
|
+
return {
|
|
393
|
+
name: d.device.name,
|
|
394
|
+
group: group ? group.name : '',
|
|
395
|
+
licenseplate: d.device.attributes.license_plate,
|
|
396
|
+
date: a.date,
|
|
397
|
+
weekday: weekDays[a.date.getDay()],
|
|
398
|
+
distance: Number((a.kms / 1000).toFixed(0))
|
|
399
|
+
}
|
|
400
|
+
}))
|
|
401
|
+
}
|
|
398
402
|
} else {
|
|
399
403
|
data = data.concat([{
|
|
400
404
|
name: userData.byDriver ? d.driver.name : d.device.name,
|