fleetmap-reports 1.0.815 → 1.0.817

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/generated.pdf ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.815",
3
+ "version": "1.0.817",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -20,8 +20,8 @@
20
20
  "file-saver": "^2.0.5",
21
21
  "fleetmap-partners": "^1.0.76",
22
22
  "json-as-xlsx": "^1.2.1",
23
- "jspdf": "^2.3.1",
24
- "jspdf-autotable": "^3.5.14",
23
+ "jspdf": "^2.5.1",
24
+ "jspdf-autotable": "3.6.0",
25
25
  "moment": "^2.29.4",
26
26
  "tough-cookie": "^4.0.0",
27
27
  "traccar-api": "^1.0.5",
@@ -7,6 +7,10 @@ function calculateLastStopTime (stopTime, to, time) {
7
7
  return stopTime + (to.getTime() - new Date(time).getTime())
8
8
  }
9
9
 
10
+ function calculateFirstStopTime (stopTime, from, time) {
11
+ return stopTime + (new Date(time).getTime() - from.getTime())
12
+ }
13
+
10
14
  async function createActivityReport (from, to, userData, traccarInstance) {
11
15
  const unauthorizedGeofences = []
12
16
  const authorizedGeofences = []
@@ -7,13 +7,13 @@ 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
15
  const device = data[0].devices.find(d => d.device.id === 22326)
16
- assert.equal(device.summary[0].startOdometer, 248891759.24)
16
+ assert.equal(device.summary[0].startOdometer, 0)
17
17
  assert.equal(device.summary[0].distance, 0)
18
18
  assert.equal(device.summary[0].startTime, 0)
19
19
  assert.equal(device.summary[0].endTime, 0)
@@ -72,17 +72,4 @@ describe('activity report', function () {
72
72
  console.log(device)
73
73
  assert.equal(device.summary.reduce((a, b) => a + b.convertedSpentFuel, 0), 168.79999999999995)
74
74
  }, 800000)
75
- it('Activity test performance', async () => {
76
- const report = await getReports()
77
- const userData = await report.getUserData()
78
- userData.groupByDay = true
79
- userData.devices = userData.devices.filter(d => d.id === 69114)
80
- const data = await report.activityReport(new Date(2023, 5, 11, 0, 0, 0, 0),
81
- new Date(2023, 6, 11, 23, 59, 59, 0),
82
- userData)
83
- assert.equal(data.length, 1)
84
- const device = data[0].devices.find(d => d.device.id === 69114)
85
- console.log(device)
86
- assert.equal(device.summary.reduce((a, b) => a + b.convertedSpentFuel, 0), 168.79999999999995)
87
- }, 800000)
88
75
  })
@@ -12,10 +12,11 @@ describe('Test_Reports', function () {
12
12
  userData.customSpeed = false
13
13
  userData.useVehicleSpeedLimit = true
14
14
  const data = await report.speedingReport(
15
- new Date(Date.UTC(2022, 9, 22, 0, 0, 0, 0)),
16
- new Date(Date.UTC(2022, 9, 22, 23, 59, 59, 0)),
15
+ new Date(Date.UTC(2023, 7, 1, 0, 0, 0, 0)),
16
+ new Date(Date.UTC(2023, 7, 2, 23, 59, 59, 0)),
17
17
  userData)
18
- await report.speedingReportToPDF(userData, data)
18
+ const pdf = await report.speedingReportToPDF(userData, data[0])
19
+ pdf.save()
19
20
  }, 40000)
20
21
 
21
22
  it('converts madrid time', async () => {
@@ -15,6 +15,7 @@ async function header (doc, title, hostname, style, orientation) {
15
15
  doc.addImage(image, 'PNG', (orientation === 'l' ? 220 : 135) + (style.imgWidth < 50 ? 25 : 0), 5, style.imgWidth, style.imgHeight)
16
16
  }
17
17
  } catch (e) {
18
+ console.error(e)
18
19
  }
19
20
  }
20
21
  doc.setFont('helvetica', 'normal')
package/src/util/utils.js CHANGED
@@ -136,7 +136,7 @@ async function getImageBase64 (url) {
136
136
 
137
137
  function getLogoUrl (hostname) {
138
138
  const path = `/img/logos/${hostname}.png`
139
- return window ? path : `https://${hostname}${path}`
139
+ return isClientSide() ? path : `https://${hostname}${path}`
140
140
  }
141
141
 
142
142
  async function getImgFromUrl (hostname) {
@@ -253,3 +253,4 @@ exports.calculateDistance = (positions) => {
253
253
  }
254
254
 
255
255
  exports.sortPositions = (a, b) => new Date(a.fixTime).getTime() - new Date(b.fixTime).getTime()
256
+ exports.getLogoUrl = getLogoUrl