fleetmap-reports 1.0.251 → 1.0.252

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/src/kms-report.js CHANGED
@@ -1,4 +1,3 @@
1
- const {createActivityReport} = require("./activity-report");
2
1
  const messages = require('../lang')
3
2
  const jsPDF = require('jspdf')
4
3
  require('jspdf-autotable')
@@ -52,84 +51,102 @@ function processDevices(from, to, devices, route, trips) {
52
51
  const deviceTrips = trips.filter(t => t.deviceId === d.id)
53
52
 
54
53
  if (deviceTrips.length > 0) {
55
- deviceTrips.forEach(t => t.tripDay = new Date(t.startTime).toISOString().split('T')[0] + ' 12:00 PM')
56
- const groupedTrips = deviceTrips.reduce(
57
- (entryMap, e) => entryMap.set(e.tripDay, [...entryMap.get(e.tripDay)||[], e]),
58
- new Map()
59
- )
60
-
61
- const allDates = getDates(from, to)
62
-
63
- const days = []
64
- let keys = Array.from(groupedTrips.keys())
65
- allDates.forEach(d => {
66
- const day = d.toISOString().split('T')[0] + ' 12:00 PM'
67
- if(!keys.includes(day)){
68
- groupedTrips.set(day, [])
69
- }
70
- })
71
-
72
- keys = Array.from(groupedTrips.keys())
73
- keys.sort((a,b)=>new Date(a).getTime()-new Date(b).getTime());
74
- keys.forEach(key => {
75
- const currentDate = new Date(key)
76
- let dayTrips = groupedTrips.get(key)
77
- const day = {
78
- date: currentDate,
79
- kms: 0
80
- }
81
-
82
- if(userData.allWeek){
83
- day.kms = dayTrips.reduce((a, b) => a + b.distance, 0) || 0
84
- } else {
85
- if((currentDate.getDay() === 0 && userData.weekDays.sunday) ||
86
- (currentDate.getDay() === 1 && userData.weekDays.monday) ||
87
- (currentDate.getDay() === 2 && userData.weekDays.tuesday) ||
88
- (currentDate.getDay() === 3 && userData.weekDays.wednesday) ||
89
- (currentDate.getDay() === 4 && userData.weekDays.thursday) ||
90
- (currentDate.getDay() === 5 && userData.weekDays.friday) ||
91
- (currentDate.getDay() === 6 && userData.weekDays.saturday)) {
92
-
93
- const startDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
94
- const endDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
95
-
96
- console.log(key, startDate, endDate)
97
-
98
- //Trips inside time period
99
- const filteredTrips = dayTrips.filter(t => new Date(t.startTime).getTime() > startDate.getTime()
100
- && new Date(t.endTime).getTime() < endDate.getTime())
54
+ if(userData.groupByDay) {
55
+ deviceTrips.forEach(t => t.tripDay = new Date(t.startTime).toISOString().split('T')[0] + ' 12:00 PM')
56
+ const groupedTrips = deviceTrips.reduce(
57
+ (entryMap, e) => entryMap.set(e.tripDay, [...entryMap.get(e.tripDay)||[], e]),
58
+ new Map()
59
+ )
101
60
 
102
- //Trip starts outside time period and ends inside time period
103
- const startIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < startDate.getTime()
104
- && new Date(t.endTime).getTime() > startDate.getTime())
61
+ const allDates = getDates(from, to)
62
+
63
+ const days = []
64
+ let keys = Array.from(groupedTrips.keys())
65
+ allDates.forEach(d => {
66
+ const day = d.toISOString().split('T')[0] + ' 12:00 PM'
67
+ if(!keys.includes(day)){
68
+ groupedTrips.set(day, [])
69
+ }
70
+ })
71
+
72
+ keys = Array.from(groupedTrips.keys())
73
+ keys.sort((a,b)=>new Date(a).getTime()-new Date(b).getTime());
74
+ keys.forEach(key => {
75
+ const currentDate = new Date(key)
76
+ let dayTrips = groupedTrips.get(key)
77
+ const day = {
78
+ date: currentDate,
79
+ kms: 0
80
+ }
105
81
 
106
- //Trip starts inside time period and ends outside time period
107
- const endIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < endDate.getTime()
82
+ if(userData.allWeek){
83
+ day.kms = dayTrips.reduce((a, b) => a + b.distance, 0) || 0
84
+ } else {
85
+ if((currentDate.getDay() === 0 && userData.weekDays.sunday) ||
86
+ (currentDate.getDay() === 1 && userData.weekDays.monday) ||
87
+ (currentDate.getDay() === 2 && userData.weekDays.tuesday) ||
88
+ (currentDate.getDay() === 3 && userData.weekDays.wednesday) ||
89
+ (currentDate.getDay() === 4 && userData.weekDays.thursday) ||
90
+ (currentDate.getDay() === 5 && userData.weekDays.friday) ||
91
+ (currentDate.getDay() === 6 && userData.weekDays.saturday)) {
92
+
93
+ const startDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
94
+ const endDate = new Date(new Date(key).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
95
+
96
+ console.log(key, startDate, endDate)
97
+
98
+ if(startDate.getTime() < endDate.getTime()) {
99
+ //Trips inside time period
100
+ const filteredTrips = dayTrips.filter(t => new Date(t.startTime).getTime() > startDate.getTime()
101
+ && new Date(t.endTime).getTime() < endDate.getTime())
102
+
103
+ day.kms = filteredTrips.reduce((a, b) => a + b.distance, 0) || 0
104
+ console.log('Inside trips:' + day.kms)
105
+ } else {
106
+ //Trips inside time period
107
+ const filteredTrips = dayTrips.filter(t => new Date(t.startTime).getTime() > startDate.getTime()
108
+ || new Date(t.endTime).getTime() < endDate.getTime())
109
+
110
+ day.kms = filteredTrips.reduce((a, b) => a + b.distance, 0) || 0
111
+ console.log('Inside trips:' + day.kms)
112
+ }
113
+
114
+ //Trip starts outside time period and ends inside time period
115
+ const startIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < startDate.getTime()
116
+ && new Date(t.endTime).getTime() > startDate.getTime())
117
+
118
+ //Trip starts inside time period and ends outside time period
119
+ const endIncompleteTrip = dayTrips.filter(t => new Date(t.startTime).getTime() < endDate.getTime()
108
120
  && new Date(t.endTime).getTime() > endDate.getTime())
109
121
 
110
- day.kms = filteredTrips.reduce((a, b) => a + b.distance, 0) || 0
111
- console.log('Inside trips:'+day.kms)
112
-
113
- if(startIncompleteTrip.length){
114
- const routeInside = route.filter(p => new Date(p.fixTime).getTime() > startDate.getTime() && new Date(p.fixTime).getTime() < new Date(startIncompleteTrip[0].endTime).getTime())
115
- day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
116
- console.log('startIncompleteTrip:'+day.kms)
117
- }
118
-
119
- if(endIncompleteTrip.length){
120
- const routeInside = route.filter(p => new Date(p.fixTime).getTime() < endDate.getTime() && new Date(p.fixTime).getTime() > new Date(endIncompleteTrip[0].startTime).getTime())
121
- day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
122
- console.log('endIncompleteTrip:'+day.kms)
122
+ if (startIncompleteTrip.length) {
123
+ const routeInside = route.filter(p => new Date(p.fixTime).getTime() > startDate.getTime() && new Date(p.fixTime).getTime() < new Date(startIncompleteTrip[0].endTime).getTime())
124
+ day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
125
+ console.log('startIncompleteTrip:' + day.kms)
126
+ }
127
+
128
+ if (endIncompleteTrip.length) {
129
+ const routeInside = route.filter(p => new Date(p.fixTime).getTime() < endDate.getTime() && new Date(p.fixTime).getTime() > new Date(endIncompleteTrip[0].startTime).getTime())
130
+ day.kms = day.kms + (routeInside.reduce((a, b) => a + b.distance, 0) || 0)
131
+ console.log('endIncompleteTrip:' + day.kms)
132
+ }
123
133
  }
124
134
  }
125
- }
126
135
 
127
- days.push(day)
128
- })
129
- devicesResult.push({
130
- device: d,
131
- days: days
132
- })
136
+ days.push(day)
137
+ })
138
+ devicesResult.push({
139
+ device: d,
140
+ days: days
141
+ })
142
+ } else {
143
+ devicesResult.push({
144
+ device: d,
145
+ summary: {
146
+ distance: deviceTrips.filter(t => t.distance > 0).reduce((a, b) => a + b.distance, 0),
147
+ }
148
+ })
149
+ }
133
150
  }
134
151
  }
135
152
 
@@ -142,27 +159,22 @@ async function createKmsReport(from, to, reportUserData, traccar) {
142
159
  console.log(from, to)
143
160
  traccarInstance = traccar
144
161
  userData = reportUserData
145
- if(userData.groupByDay){
146
- const reportData = []
147
-
148
- if(userData.byDriver){
149
- const allData = await createKmsReportByDriver(from, to)
150
- reportData.push(allData)
151
- }
152
- else if(userData.byGroup){
153
- const allGroupsData = await createKmsReportByGroup(from, to)
154
- allGroupsData.forEach(data => reportData.push(data))
155
- const withoutGroupDevices = await createKmsReportByDevice(from, to)
156
- reportData.push(withoutGroupDevices)
157
- } else {
158
- const allData = await createKmsReportByDevice(from, to)
159
- reportData.push(allData)
160
- }
161
-
162
- return reportData
162
+ const reportData = []
163
+ if(userData.byDriver){
164
+ const allData = await createKmsReportByDriver(from, to)
165
+ reportData.push(allData)
166
+ }
167
+ else if(userData.byGroup){
168
+ const allGroupsData = await createKmsReportByGroup(from, to)
169
+ allGroupsData.forEach(data => reportData.push(data))
170
+ const withoutGroupDevices = await createKmsReportByDevice(from, to)
171
+ reportData.push(withoutGroupDevices)
163
172
  } else {
164
- return await createActivityReport(from, to, userData, traccar)
173
+ const allData = await createKmsReportByDevice(from, to)
174
+ reportData.push(allData)
165
175
  }
176
+
177
+ return reportData
166
178
  }
167
179
 
168
180
  async function exportKmsReportToPDF(userData, reportData) {
@@ -170,6 +182,16 @@ async function exportKmsReportToPDF(userData, reportData) {
170
182
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
171
183
  const kmsData = userData.byDriver ? reportData.drivers : reportData.devices
172
184
 
185
+ const weekDays = [
186
+ translations.report.sunday,
187
+ translations.report.monday,
188
+ translations.report.tuesday,
189
+ translations.report.wednesday,
190
+ translations.report.thursday,
191
+ translations.report.friday,
192
+ translations.report.saturday
193
+ ]
194
+
173
195
  const headers = []
174
196
  if(userData.groupByDay) {
175
197
  headers.push(translations.report.date,
@@ -186,32 +208,42 @@ async function exportKmsReportToPDF(userData, reportData) {
186
208
  translations.report.distance)
187
209
  }
188
210
  if (kmsData) {
189
- let first = true
190
- const doc = userData.groupByDay ? new jsPDF.jsPDF('p') : new jsPDF.jsPDF('l')
191
- await headerFromUser(doc, translations.report.titleKmsReport, userData.user, 'p')
211
+ const orientation = userData.groupByDay ? 'p' : 'l'
212
+ const doc = new jsPDF.jsPDF(orientation)
213
+ await headerFromUser(doc, translations.report.titleKmsReport, userData.user, orientation)
192
214
 
193
215
  if (userData.groupByDay) {
194
- for (const d of kmsData) {
216
+ kmsData.forEach(function (d, index) {
195
217
  const name = userData.byDriver ? d.driver.name : d.device.name
196
218
  const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
197
219
 
198
- let space = 0
199
- if (!first) {
220
+ let space = index === 0 ? 8 : 0
221
+ if(index){
200
222
  doc.addPage()
201
- } else {
202
- first = false
203
- space = 8
204
223
  }
224
+
205
225
  doc.setFontSize(13)
206
226
  doc.text(name, 20, space + 20)
207
227
  doc.setFontSize(11)
208
228
  doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space + 20)
209
229
  doc.text(new Date(reportData.from).toLocaleString() + ' - ' + new Date(reportData.to).toLocaleString(), 20, space + 25)
210
230
 
231
+ if(!userData.allWeek) {
232
+ doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '')
233
+ + (userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '')
234
+ + (userData.weekDays.wednesday ? ' ' + translations.report.wednesday + ',' : '')
235
+ + (userData.weekDays.thursday ? ' ' + translations.report.thursday + ',' : '')
236
+ + (userData.weekDays.friday ? ' ' + translations.report.friday + ',' : '')
237
+ + (userData.weekDays.saturday ? ' ' + translations.report.saturday + ',' : '')
238
+ + (userData.weekDays.sunday ? ' ' + translations.report.sunday + ',' : '')
239
+ + ' das '
240
+ + userData.dayHours.startTime + ' - ' + userData.dayHours.endTime, 20, space + 30)
241
+ }
242
+
211
243
  const data = []
212
244
  d.days.forEach(day => {
213
245
  const temp = [
214
- new Date(day.date).toLocaleDateString(),
246
+ new Date(day.date).toLocaleDateString() + ' - ' + weekDays[day.date.getDay()],
215
247
  (day.kms/1000).toFixed(0)
216
248
  ]
217
249
 
@@ -225,9 +257,8 @@ async function exportKmsReportToPDF(userData, reportData) {
225
257
  )
226
258
 
227
259
  const style = getStyle(getUserPartner(userData.user))
228
-
229
- addTable(doc, headers, data, footValues, style, 35)
230
- }
260
+ addTable(doc, headers, data, footValues, style, 40)
261
+ })
231
262
  } else {
232
263
  const data = []
233
264
  if (userData.byDriver) {
@@ -246,7 +277,7 @@ async function exportKmsReportToPDF(userData, reportData) {
246
277
  const group = userData.groups.find(g => d.device.groupId === g.id)
247
278
 
248
279
  const temp = [
249
- d.summary.deviceName,
280
+ d.device.name,
250
281
  d.device.model,
251
282
  group ? group.name : '',
252
283
  Number((d.summary.distance / 1000).toFixed(0))
@@ -285,6 +316,16 @@ function exportKmsReportToExcel(userData, reportData) {
285
316
  const lang = userData.user.attributes.lang || (navigator && navigator.language)
286
317
  const translations = messages[lang] ? messages[lang] : messages['en-GB']
287
318
 
319
+ const weekDays = [
320
+ translations.report.sunday,
321
+ translations.report.monday,
322
+ translations.report.tuesday,
323
+ translations.report.wednesday,
324
+ translations.report.thursday,
325
+ translations.report.friday,
326
+ translations.report.saturday
327
+ ]
328
+
288
329
  const settings = {
289
330
  sheetName: translations.report.titleKmsReport, // The name of the sheet
290
331
  fileName: fileName // The name of the spreadsheet
@@ -298,6 +339,7 @@ function exportKmsReportToExcel(userData, reportData) {
298
339
  {label: translations.report.licensePlate, value: 'licenseplate'},
299
340
  {label: translations.report.group, value: 'group'},
300
341
  {label: translations.report.date, value: 'date'},
342
+ {label: translations.report.weekDay, value: 'weekday'},
301
343
  {label: translations.report.distance, value: 'distance'})
302
344
  } else if(userData.byDriver) {
303
345
  headers.push(
@@ -326,12 +368,13 @@ function exportKmsReportToExcel(userData, reportData) {
326
368
  group: group ? group.name : '',
327
369
  licenseplate: d.device.attributes.license_plate,
328
370
  date: a.date,
371
+ weekday: weekDays[a.date.getDay()],
329
372
  distance: Number((a.kms / 1000).toFixed(0))
330
373
  }
331
374
  }))
332
375
  } else {
333
376
  data = data.concat([{
334
- name: userData.byDriver ? d.driver.name : d.summary.deviceName,
377
+ name: userData.byDriver ? d.driver.name : d.device.name,
335
378
  group: group ? group.name : '',
336
379
  licenseplate: userData.byDriver ? '' : d.device.attributes.license_plate,
337
380
  distance: Number((d.summary.distance / 1000).toFixed(0))
@@ -366,7 +366,7 @@ async function exportSpeedingReportToPDF(userData, reportData) {
366
366
  doc.text(group ? translations.report.group + ': ' + group.name : '', 150, space+20 )
367
367
  doc.text(new Date(d.from).toLocaleString() + ' - ' + new Date(d.to).toLocaleString(), 20, space+25 )
368
368
  if (d.alerts[0] && !userData.byDriver) {
369
- doc.text(translations.report.speedLimit + ": " + Math.round(d.alerts[0].attributes.speedLimit * 1.85200) + ' Km/h', 20, space + 30)
369
+ doc.text(translations.report.speedLimit + ": " + (userData.useVehicleSpeedLimit ? Math.round(d.alerts[0].attributes.speedLimit * 1.85200) : userData.customSpeed) + ' Km/h', 20, space + 30)
370
370
  }
371
371
  d.alerts.map(a => {
372
372
  const temp = [
@@ -6,7 +6,7 @@ require('jspdf-autotable')
6
6
  const {coordsDistance} = require("./util/utils")
7
7
  const drivers = require("./util/driver")
8
8
  const {getUserPartner} = require("fleetmap-partners")
9
- const {headerFromUser} = require("./util/pdfDocument")
9
+ const {headerFromUser, addTable} = require("./util/pdfDocument")
10
10
  const {getStyle} = require("./reportStyle")
11
11
  const traccar = require("./util/traccar")
12
12
 
@@ -116,7 +116,7 @@ function processDevices(from, to, devices, data, stopsData, userData) {
116
116
  const devicesResult = []
117
117
 
118
118
  devices.forEach(d => {
119
- const trips = data.filter(t => t.deviceId === d.id)
119
+ const trips = data.filter(t => t.deviceId === d.id && (userData.allWeek || isInsideTimetable(t, userData)))
120
120
  const stops = stopsData.filter(s => s.deviceId === d.id)
121
121
 
122
122
  trips.forEach(t => {
@@ -146,8 +146,8 @@ function processDevices(from, to, devices, data, stopsData, userData) {
146
146
  })
147
147
 
148
148
  if (trips.length > 0) {
149
- trips.forEach(function(trip, index) {
150
- const stop = stops.length+1 > index ? stops[index+1] : null
149
+ trips.forEach(trip => {
150
+ const stop = getStop(new Date(trip.startTime), stops)
151
151
 
152
152
  if (stop) {
153
153
  trip.stopDuration = (new Date(stop.endTime) - new Date(stop.startTime))
@@ -240,27 +240,38 @@ async function exportTripReportToPDF(userData, reportData) {
240
240
  }
241
241
 
242
242
  if (tripsData) {
243
- let first = true
244
243
  const doc = new jsPDF.jsPDF('l');
245
244
  await headerFromUser(doc, translations.report.titleTripReport, userData.user)
246
- for(const d of tripsData){
245
+
246
+ tripsData.forEach(function (d, index) {
247
247
  const data = []
248
248
  const name = userData.byDriver ? d.driver.name : deviceName(d.device)
249
249
  const group = userData.byDriver ? userData.groups.find(g => g.drivers.includes(d.id)) : userData.groups.find(g => d.device.groupId === g.id)
250
250
 
251
- let space = 0
252
- if(!first) {
251
+ let space = index === 0 ? 8 : 0
252
+ if(index){
253
253
  doc.addPage()
254
- } else {
255
- first = false
256
- space = 8
257
254
  }
255
+
258
256
  doc.setFontSize(13)
259
257
  doc.text(name, 20, space+20 )
260
258
  doc.setFontSize(11)
261
259
  doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space+20 )
262
260
  doc.text(new Date(d.from).toLocaleString() + ' - ' + new Date(d.to).toLocaleString(), 20, space+25 )
263
- doc.text(translations.report.headerStartAddress + ': ' + d.trips[0].startAddress, 20, space+30 )
261
+ if(!userData.allWeek) {
262
+ doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '')
263
+ + (userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '')
264
+ + (userData.weekDays.wednesday ? ' ' + translations.report.wednesday + ',' : '')
265
+ + (userData.weekDays.thursday ? ' ' + translations.report.thursday + ',' : '')
266
+ + (userData.weekDays.friday ? ' ' + translations.report.friday + ',' : '')
267
+ + (userData.weekDays.saturday ? ' ' + translations.report.saturday + ',' : '')
268
+ + (userData.weekDays.sunday ? ' ' + translations.report.sunday + ',' : '')
269
+ + ' das '
270
+ + userData.dayHours.startTime + ' - ' + userData.dayHours.endTime, 20, space + 30)
271
+ doc.text(translations.report.headerStartAddress + ': ' + d.trips[0].startAddress, 20, space+40 )
272
+ } else {
273
+ doc.text(translations.report.headerStartAddress + ': ' + d.trips[0].startAddress, 20, space+35 )
274
+ }
264
275
 
265
276
  d.trips.map(a => {
266
277
  const temp = [
@@ -306,28 +317,8 @@ async function exportTripReportToPDF(userData, reportData) {
306
317
  }
307
318
 
308
319
  const style = getStyle(getUserPartner(userData.user))
309
- doc.autoTable({
310
- head: [headers],
311
- body: data,
312
- foot: [footValues],
313
- showFoot: 'lastPage',
314
- headStyles: {
315
- fillColor: style.pdfHeaderColor,
316
- textColor: style.pdfHeaderTextColor,
317
- fontSize: 10
318
- },
319
- bodyStyles: {
320
- fillColor: style.pdfBodyColor,
321
- textColor: style.pdfBodyTextColor,
322
- fontSize: 8
323
- },
324
- footStyles: {
325
- fillColor: style.pdfFooterColor,
326
- textColor: style.pdfFooterTextColor,
327
- fontSize: 9
328
- },
329
- startY: space+35 })
330
- }
320
+ addTable(doc, headers, data, footValues, style, space + (userData.allWeek ? 40 : 45))
321
+ })
331
322
  return doc
332
323
  }
333
324
  }
@@ -451,6 +442,39 @@ function getMaxSpeed(data) {
451
442
  return Math.round(max * 1.85200)
452
443
  }
453
444
 
445
+ function getStop(tripEndDate, stops){
446
+ const stopList = stops.filter(s => new Date(s.startTime).getTime() >= tripEndDate.getTime())
447
+ if(stopList.length){
448
+ return stopList[0]
449
+ }
450
+
451
+ return null
452
+ }
453
+
454
+ function isInsideTimetable(t, userData){
455
+ const tripStart = new Date(t.startTime)
456
+ const tripEnd = new Date(t.endTime)
457
+
458
+ if((tripStart.getDay() === 0 && userData.weekDays.sunday) ||
459
+ (tripStart.getDay() === 1 && userData.weekDays.monday) ||
460
+ (tripStart.getDay() === 2 && userData.weekDays.tuesday) ||
461
+ (tripStart.getDay() === 3 && userData.weekDays.wednesday) ||
462
+ (tripStart.getDay() === 4 && userData.weekDays.thursday) ||
463
+ (tripStart.getDay() === 5 && userData.weekDays.friday) ||
464
+ (tripStart.getDay() === 6 && userData.weekDays.saturday)) {
465
+
466
+ const startDate = new Date(new Date(tripStart).toISOString().split('T')[0] + ' '+userData.dayHours.startTime)
467
+ const endDate = new Date(new Date(tripStart).toISOString().split('T')[0] + ' '+userData.dayHours.endTime)
468
+
469
+ console.log(tripStart, startDate, endDate)
470
+
471
+ //Trips inside time period
472
+ return tripStart.getTime() > startDate.getTime() && tripEnd.getTime() < endDate.getTime()
473
+ }
474
+
475
+ return false
476
+ }
477
+
454
478
  exports.createTripReport = createTripReport;
455
479
  exports.exportTripReportToPDF = exportTripReportToPDF;
456
480
  exports.exportTripReportToExcel = exportTripReportToExcel;
@@ -52,7 +52,21 @@ async function getEvents(traccar, from, to, devices, events){
52
52
  return result.map(r => r.data).flat()
53
53
  }
54
54
 
55
+ async function getSummary(traccar, from, to, devices){
56
+ const devicesToSlice = devices.slice()
57
+ const arrayOfArrays = automaticReports.sliceArray(devicesToSlice)
58
+ let requests = []
59
+ for (const a of arrayOfArrays) {
60
+ const promise = traccar.reports.reportsSummaryGet(from, to, a.map(d => d.id))
61
+ requests = requests.concat(promise)
62
+ }
63
+
64
+ const result = await Promise.all(requests)
65
+ return result.map(r => r.data).flat()
66
+ }
67
+
55
68
  exports.getRoute = getRoute
56
69
  exports.getTrips = getTrips
57
70
  exports.getStops = getStops
58
71
  exports.getEvents = getEvents
72
+ exports.getSummary = getSummary
package/src/util/utils.js CHANGED
@@ -31,7 +31,7 @@ function coordsDistance(lon1, lat1, lon2, lat2) {
31
31
 
32
32
  function getDates(startDate, endDate) {
33
33
  const dates = []
34
- let currentDate = startDate
34
+ let currentDate = new Date(startDate.toISOString().split('T')[0] + ' 12:00 PM')
35
35
  const addDays = function (days) {
36
36
  const date = new Date(this.valueOf())
37
37
  date.setDate(date.getDate() + days)