fleetmap-reports 1.0.816 → 1.0.818

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.816",
3
+ "version": "1.0.818",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -21,7 +21,7 @@
21
21
  "fleetmap-partners": "^1.0.76",
22
22
  "json-as-xlsx": "^1.2.1",
23
23
  "jspdf": "^2.5.1",
24
- "jspdf-autotable": "^3.5.14",
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",
@@ -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 () => {
@@ -272,7 +272,7 @@ async function exportTripReportToPDF (userData, reportData) {
272
272
 
273
273
  const timezone = userData.user.attributes.timezone
274
274
  const translations = getTranslations(userData)
275
- const lang = userData.user.attributes.lang || (navigator && navigator.language)
275
+ const lang = userData.user.attributes.lang || (isClientSide() && navigator.language)
276
276
  const tripsData = userData.byDriver ? reportData.drivers : reportData.devices
277
277
 
278
278
  const headers = [
@@ -1,20 +1,21 @@
1
1
  require('jspdf-autotable')
2
2
  const { getStyle } = require('../reportStyle')
3
3
  const { getUserPartner } = require('fleetmap-partners')
4
- const { getLogoUrl } = require('./utils')
4
+ const { getImgFromUrl } = require('./utils')
5
5
 
6
- function header (doc, title, hostname, style, orientation) {
6
+ async function header (doc, title, hostname, style, orientation) {
7
7
  doc.setFontSize(16)
8
8
  doc.setFont('helvetica', 'bold')
9
9
  doc.text(title, 15, 15)
10
10
 
11
11
  if (style.imgWidth && style.imgHeight) {
12
12
  try {
13
- const image = getLogoUrl(hostname)
13
+ const image = await getImgFromUrl(hostname)
14
14
  if (image) {
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) {