fleetmap-reports 2.0.39 → 2.0.41

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/lang/enGB.js CHANGED
@@ -183,7 +183,7 @@ module.exports = {
183
183
  titleLocationReport: 'Locations Report',
184
184
  titleSpeedingReport: 'Overspeed Report',
185
185
  titleZoneReport: 'Zone Report',
186
- titleRefuelReport: 'Refueling Report',
186
+ titleRefuelingReport: 'Refueling Report',
187
187
  titleFuelConsumptionReport: 'Fuel Consumption Report',
188
188
  titleFuelDropReport: 'Fuel Drop Report',
189
189
  titleEventsReport: 'Events Report',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.39",
3
+ "version": "2.0.41",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@ function sliceArray (longArray, size) {
17
17
 
18
18
  function deviceWithFuelInfo (device) {
19
19
  return device.attributes.odooId || device.attributes.xpert ||
20
- (device.attributes.fuel_low_threshold >= 0 && device.attributes.fuel_high_threshold >= 0 && device.attributes.fuel_tank_capacity)
20
+ device.attributes.fuel_tank_capacity
21
21
  }
22
22
 
23
23
  function calculateXpertDistance (date, positions) {
@@ -2,10 +2,14 @@ const helpers = require('@turf/helpers')
2
2
  const automaticReports = require('./automaticReports')
3
3
  const { devicesToProcess } = require('./util/device')
4
4
  const distance = require('@turf/distance')
5
- const { getTranslations } = require('./util/utils')
5
+ const { getTranslations, getLanguage, convertToLocaleString } = require('./util/utils')
6
6
  const odoo = require('./util/odoo')
7
7
  const traccarHelper = require('./util/traccar')
8
8
  const { calculateFuelDiff, getRefuelingLiters } = require('./util/fuel')
9
+ const jsPDF = require('jspdf')
10
+ const { headerFromUser, addTable } = require('./util/pdfDocument')
11
+ const { getStyle } = require('./reportStyle')
12
+ const { getUserPartner } = require('fleetmap-partners')
9
13
 
10
14
  // const positionsToCheck = 15
11
15
 
@@ -232,11 +236,11 @@ function exportRefuelingReportToExcel (userData, reportData) {
232
236
  fileName: 'RefuelingReport' // The name of the spreadsheet
233
237
  }
234
238
  const headers = [
235
- { label: translations.report.name, value: 'name' },
236
- { label: translations.report.driver, value: 'driver' },
239
+ { label: translations.report.vehicle, value: 'name' },
237
240
  { label: translations.report.date, value: 'fixTime' },
238
241
  { label: translations.report.address, value: 'address' },
239
- { label: translations.report.refueling, value: 'diff' }
242
+ { label: translations.report.refueling, value: 'diff' },
243
+ { label: translations.report.driver, value: 'driver' }
240
244
  ]
241
245
  let data = []
242
246
  if (reportData.devices) {
@@ -260,8 +264,67 @@ function exportRefuelingReportToExcel (userData, reportData) {
260
264
  }
261
265
  }
262
266
 
263
- function exportRefuelingReportToPDF (userData, reportData) {
267
+ async function exportRefuelingReportToPDF (userData, reportData) {
264
268
  console.log('Export to PDF')
269
+ const timezone = userData.user.attributes.timezone
270
+ const translations = getTranslations(userData)
271
+ const lang = getLanguage(userData)
272
+
273
+ // eslint-disable-next-line new-cap
274
+ const doc = new jsPDF.jsPDF('l')
275
+ await headerFromUser(doc, translations.report.titleRefuelingReport, userData.user)
276
+
277
+ const headers = [
278
+ translations.report.date,
279
+ translations.report.address,
280
+ translations.report.refueling,
281
+ translations.report.driver
282
+ ]
283
+
284
+ reportData.devices.forEach((d, index) => {
285
+ const data = []
286
+ const name = deviceName(d.device)
287
+ const group = userData.groups.find(g => d.device.groupId === g.id)
288
+
289
+ const space = index === 0 ? 8 : 0
290
+ if (index) {
291
+ doc.addPage()
292
+ }
293
+
294
+ doc.setFontSize(13)
295
+ doc.text(name, 20, space + 20)
296
+ doc.setFontSize(11)
297
+ doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space + 20)
298
+ doc.text(convertToLocaleString(reportData.from, lang, timezone) + ' - ' + convertToLocaleString(reportData.to, lang, timezone), 20, space + 25)
299
+
300
+ d.refuelings.forEach(r =>
301
+ data.push([
302
+ new Date(r.position.fixTime).toLocaleString(),
303
+ r.geofenceName || r.position.address,
304
+ r.diff,
305
+ r.driverName
306
+ ])
307
+ )
308
+
309
+ const footValues = [
310
+ 'Total:' + d.refuelings.length,
311
+ '',
312
+ d.refuelings.reduce((a, b) => a + b.diff, 0),
313
+ ''
314
+ ]
315
+
316
+ const style = getStyle(getUserPartner(userData.user))
317
+ addTable(doc, headers, data, footValues, style, space + 40,
318
+ {
319
+ 2: { halign: 'right' }
320
+ })
321
+ })
322
+
323
+ return doc
324
+ }
325
+
326
+ function deviceName (device) {
327
+ return device.name + (device.attributes.license_plate ? ', ' + device.attributes.license_plate : '') + (device.model ? ', ' + device.model : '')
265
328
  }
266
329
 
267
330
  exports.createRefuelingReport = createRefuelingReport