fleetmap-reports 1.0.821 → 1.0.823

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.821",
3
+ "version": "1.0.823",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -6,7 +6,6 @@ const { convertToFeature, convertPositionToFeature } = require('../util/utils')
6
6
  function calculateLastStopTime (stopTime, to, time) {
7
7
  return stopTime + (to.getTime() - new Date(time).getTime())
8
8
  }
9
-
10
9
  async function createActivityReport (from, to, userData, traccarInstance) {
11
10
  const unauthorizedGeofences = []
12
11
  const authorizedGeofences = []
@@ -7,11 +7,14 @@ describe('activity report', function () {
7
7
  it('Activity by device', async () => {
8
8
  const report = await getReports()
9
9
  const userData = await report.getUserData()
10
- userData.groupByDay = true
11
- const data = await report.activityReport(new Date(2023, 0, 1, 0, 0, 0, 0),
12
- new Date(2023, 0, 31, 23, 59, 59, 0),
10
+
11
+ const data = await report.activityReport(new Date(2022, 0, 1, 0, 0, 0, 0),
12
+ new Date(2022, 0, 31, 23, 59, 59, 0),
13
13
  userData)
14
14
  assert.equal(data.length, 1)
15
+ const device = data[0].devices.find(d => d.device.id === 22326)
16
+ assert.equal(device.summary[0].startOdometer, 0)
17
+ assert.equal(device.summary[0].distance, 0)
15
18
  assert.equal(device.summary[0].startTime, 0)
16
19
  assert.equal(device.summary[0].endTime, 0)
17
20
  }, 80000)
@@ -32,6 +32,18 @@ describe('zones', function () {
32
32
  console.log('result', result)
33
33
  }, 4000000)
34
34
 
35
+ it('works with afriquia', async () => {
36
+ const report = await getReports(process.env.USER_AFRIQUIA, process.env.PASS_AFRIQUIA)
37
+ const userData = await report.getUserData()
38
+ console.log(userData.devices.length)
39
+ console.log(userData.geofences)
40
+ const result = await report.zoneReport(
41
+ new Date(Date.UTC(2023, 5, 11, 0, 0, 0, 0)),
42
+ new Date(Date.UTC(2023, 5, 11, 23, 59, 59, 0)),
43
+ userData)
44
+ console.log('result', result)
45
+ }, 4000000)
46
+
35
47
  // eslint-disable-next-line no-undef
36
48
  it('works with casais', async () => {
37
49
  const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
@@ -186,12 +186,37 @@ async function processDevices (from, to, devices, userData, data) {
186
186
  }
187
187
  } else {
188
188
  if (zoneInOutData.length > 0) {
189
- devicesResult.push({
190
- device: d,
191
- from,
192
- to,
193
- geofences: userData.onlyWithKmsOut ? zoneInOutData.filter(a => a.distanceOut) : zoneInOutData
194
- })
189
+ if (userData.tripsBetweenZones) {
190
+ const tripsBetweenZones = []
191
+ zoneInOutData.forEach((a, index) => {
192
+ if (index + 1 < zoneInOutData.length && a.outTime && zoneInOutData[index + 1].inTime) {
193
+ tripsBetweenZones.push({
194
+ outTime: a.outTime,
195
+ outGeofenceName: a.geofenceName,
196
+ inTime: zoneInOutData[index + 1].inTime,
197
+ inGeofenceName: zoneInOutData[index + 1].geofenceName,
198
+ distanceOut: a.distanceOutAny,
199
+ totalOutTime: new Date(zoneInOutData[index + 1].inTime.fixTime).getTime() - new Date(a.outTime.fixTime).getTime()
200
+ })
201
+ }
202
+ })
203
+ if (tripsBetweenZones.length > 0) {
204
+ devicesResult.push({
205
+ device: d,
206
+ from,
207
+ to,
208
+ tripsBetweenZones: true,
209
+ geofences: userData.onlyWithKmsOut ? tripsBetweenZones.filter(a => a.distanceOut) : tripsBetweenZones
210
+ })
211
+ }
212
+ } else {
213
+ devicesResult.push({
214
+ device: d,
215
+ from,
216
+ to,
217
+ geofences: userData.onlyWithKmsOut ? zoneInOutData.filter(a => a.distanceOut) : zoneInOutData
218
+ })
219
+ }
195
220
  }
196
221
  }
197
222
  }
@@ -314,7 +339,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
314
339
  new Date(p.fixTime).getTime() >= outDate &&
315
340
  new Date(p.fixTime).getTime() < anyNextIn
316
341
  )
317
- const distanceOutAny = zoneInData.length < 2 ? calculateDistance(routeAfterOutAndBeforeAnyNextIn) : 0
342
+ const distanceOutAny = Object.keys(zoneInData).length < 2 ? calculateDistance(routeAfterOutAndBeforeAnyNextIn) : 0
318
343
 
319
344
  if (zoneInData[a.geofenceId]) {
320
345
  const totalInTime = new Date(a.position.fixTime).getTime() - new Date(zoneInData[a.geofenceId].position.fixTime).getTime()
@@ -336,7 +361,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to) {
336
361
  stopped: routeIn.filter(p => !p.attributes.ignition).length > 0,
337
362
  driverName: zoneInData[a.geofenceId].position.driverName
338
363
  })
339
- zoneInData[a.geofenceId] = null
364
+ delete zoneInData[a.geofenceId]
340
365
  } else {
341
366
  const totalInTime = new Date(a.position.fixTime).getTime() - from.getTime()
342
367
  const routeIn = deviceRoute.filter(p =>
@@ -461,6 +486,15 @@ async function exportZoneReportToPDF (userData, reportData) {
461
486
  headers.push(translations.report.date)
462
487
  reportData.devices[0].days[0].geofences.forEach(g => headers.push(g.geofenceName))
463
488
  headers.push(translations.report.distanceOut || 'Kms Afuera')
489
+ } else if (userData.tripsBetweenZones) {
490
+ headers.push(...[
491
+ translations.report.date_start,
492
+ translations.report.geofenceOut || 'Zone OUT',
493
+ translations.report.date_end,
494
+ translations.report.geofenceIn || 'Zone IN',
495
+ translations.report.duration,
496
+ translations.report.distance
497
+ ])
464
498
  } else {
465
499
  headers.push(...[
466
500
  translations.report.enter,
@@ -543,25 +577,44 @@ async function exportZoneReportToPDF (userData, reportData) {
543
577
  } else {
544
578
  const data = []
545
579
  space = reportHeader(index === 0, doc, translations, d, lang, timezone, userData)
546
- d.geofences.forEach(a => {
547
- const temp = [
548
- geofenceEnter(userData.user, a),
549
- geofenceExit(userData.user, a),
550
- a.stopped ? translations.report.yes : translations.report.no,
551
- convertMS(a.totalInTime, true),
552
- a.distanceIn ? a.distanceIn.toLocaleString(lang, { maximumFractionDigits: 2 }) : 0,
553
- a.distanceOut ? a.distanceOut.toLocaleString(lang, { maximumFractionDigits: 2 }) : 0,
554
- a.geofenceName,
555
- a.driverName
556
- ]
557
- data.push(temp)
558
- })
559
- const footer = ['Total:' + d.geofences.length]
560
- addTable(doc, headers, data, footer, style, space + 35, {
561
- 3: { halign: 'right' },
562
- 4: { halign: 'right' },
563
- 5: { halign: 'right' }
564
- })
580
+ if (userData.tripsBetweenZones) {
581
+ d.geofences.forEach(a => {
582
+ const temp = [
583
+ geofenceExit(userData.user, a),
584
+ a.outGeofenceName,
585
+ geofenceEnter(userData.user, a),
586
+ a.inGeofenceName,
587
+ convertMS(a.totalOutTime, true),
588
+ a.distanceOut ? a.distanceOut.toLocaleString(lang, { maximumFractionDigits: 2 }) : 0
589
+ ]
590
+ data.push(temp)
591
+ })
592
+ const footer = ['Total:' + d.geofences.length]
593
+ addTable(doc, headers, data, footer, style, space + 35, {
594
+ 4: { halign: 'right' },
595
+ 5: { halign: 'right' }
596
+ })
597
+ } else {
598
+ d.geofences.forEach(a => {
599
+ const temp = [
600
+ geofenceEnter(userData.user, a),
601
+ geofenceExit(userData.user, a),
602
+ a.stopped ? translations.report.yes : translations.report.no,
603
+ convertMS(a.totalInTime, true),
604
+ a.distanceIn ? a.distanceIn.toLocaleString(lang, { maximumFractionDigits: 2 }) : 0,
605
+ a.distanceOut ? a.distanceOut.toLocaleString(lang, { maximumFractionDigits: 2 }) : 0,
606
+ a.geofenceName,
607
+ a.driverName
608
+ ]
609
+ data.push(temp)
610
+ })
611
+ const footer = ['Total:' + d.geofences.length]
612
+ addTable(doc, headers, data, footer, style, space + 35, {
613
+ 3: { halign: 'right' },
614
+ 4: { halign: 'right' },
615
+ 5: { halign: 'right' }
616
+ })
617
+ }
565
618
  }
566
619
  })
567
620
  return doc
@@ -599,6 +652,16 @@ function exportZoneReportToExcel (userData, reportData) {
599
652
  headers.push({ label: g.geofenceName, value: g.geofenceId })
600
653
  )
601
654
  headers.push({ label: translations.report.distanceOut || 'Kms Afuera', value: 'distanceOut' })
655
+ } else if (userData.tripsBetweenZones) {
656
+ headers.push(...[
657
+ { label: translations.report.vehicle, value: 'name' },
658
+ { label: translations.report.date_start, value: 'exit' },
659
+ { label: translations.report.geofenceOut || 'Zone OUT', value: 'zoneOut' },
660
+ { label: translations.report.date_end, value: 'enter' },
661
+ { label: translations.report.geofenceIn || 'Zone IN', value: 'zoneIn' },
662
+ { label: translations.report.duration, value: 'totalOutTime' },
663
+ { label: translations.report.distance, value: 'distanceOut' }
664
+ ])
602
665
  } else {
603
666
  headers.push(...[
604
667
  { label: translations.report.vehicle, value: 'name' },
@@ -693,6 +756,8 @@ function getColumns (device, data, userData, translations, excel) {
693
756
  totalInTime: convertMS(data.totalInTime, !userData.groupByDay),
694
757
  totalOutTime: convertMS(data.totalOutTime, !userData.groupByDay),
695
758
  zone: data.geofenceName,
759
+ zoneOut: data.outGeofenceName,
760
+ zoneIn: data.inGeofenceName,
696
761
  driver: data.driverName
697
762
  }
698
763
  }