fleetmap-reports 1.0.929 → 1.0.931

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.929",
3
+ "version": "1.0.931",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "country-reverse-geocoding": "^0.2.2",
20
20
  "docx": "^7.3.0",
21
21
  "file-saver": "^2.0.5",
22
- "fleetmap-partners": "^1.0.126",
22
+ "fleetmap-partners": "^1.0.144",
23
23
  "json-as-xlsx": "^1.2.1",
24
24
  "jspdf": "^2.5.1",
25
25
  "jspdf-autotable": "3.6.0",
package/src/kms-report.js CHANGED
@@ -329,45 +329,93 @@ function exportKmsReportToExcel (userData, reportData) {
329
329
  fileName // The name of the spreadsheet
330
330
  }
331
331
 
332
- const headers = []
333
332
  const info = userData.byDriver ? reportData.drivers : reportData.devices
333
+ const columns = getExcelTableColumns(userData, info, translations)
334
334
 
335
- if (userData.groupByDay) {
336
- headers.push(
337
- { label: translations.report.vehicle, value: 'name' },
338
- { label: translations.settings.vehicle_licenseplate, value: 'licenseplate' },
339
- { label: translations.report.group, value: 'group' },
340
- { label: translations.report.startOdometer, value: 'startOdometer' })
335
+ const data = []
336
+ info.forEach(d => {
337
+ data.push(...getExcelContent(userData, d, translations))
338
+ })
341
339
 
342
- const days = info[0].days
343
- days.forEach((day, index) => {
344
- headers.push({ label: new Date(day.date).toLocaleDateString(), value: 'day' + index })
340
+ // add total
341
+ if (data.length) {
342
+ data.push({
343
+ name: '',
344
+ group: '',
345
+ licenseplate: 'Total',
346
+ distance: data.reduce((prev, curr) => curr.distance ? { distance: (prev.distance || 0) + curr.distance } : prev).distance
345
347
  })
348
+ }
346
349
 
347
- headers.push({ label: translations.report.total, value: 'total' },
348
- { label: translations.report.endOdometer, value: 'endOdometer' })
350
+ return {
351
+ headers: columns,
352
+ data,
353
+ settings
354
+ }
355
+ }
356
+
357
+ function getExcelTableColumns (userData, info, translations) {
358
+ const columns = []
359
+ if (userData.groupByDay) {
360
+ const partner = getUserPartner(userData.user)
361
+ if (partner.reports.kmsReportDaysInColumns) {
362
+ columns.push(
363
+ { label: translations.report.vehicle, value: 'name' },
364
+ { label: translations.settings.vehicle_licenseplate, value: 'licenseplate' },
365
+ { label: translations.report.group, value: 'group' },
366
+ { label: translations.report.startOdometer, value: 'startOdometer' })
367
+
368
+ const days = info[0].days
369
+ days.forEach((day, index) => {
370
+ columns.push({ label: new Date(day.date).toLocaleDateString(), value: 'day' + index })
371
+ })
372
+
373
+ columns.push({ label: translations.report.total, value: 'total' },
374
+ { label: translations.report.endOdometer, value: 'endOdometer' })
375
+ } else {
376
+ columns.push(
377
+ { label: translations.report.vehicle, value: 'name' },
378
+ { label: translations.settings.vehicle_licenseplate, value: 'licenseplate' },
379
+ { label: translations.report.group, value: 'group' },
380
+ { label: translations.report.date, value: 'date' },
381
+ { label: translations.report.weekDay, value: 'weekday' },
382
+ { label: translations.report.distance, value: 'distance' })
383
+ }
349
384
  } else if (userData.byDriver) {
350
- headers.push(
385
+ columns.push(
351
386
  { label: translations.report.driver, value: 'name' },
352
387
  { label: translations.report.group, value: 'group' },
353
388
  { label: translations.report.distance, value: 'distance' })
354
389
  } else {
355
- headers.push(
390
+ columns.push(
356
391
  { label: translations.report.vehicle, value: 'name' },
357
392
  { label: translations.settings.vehicle_licenseplate, value: 'licenseplate' },
358
393
  { label: translations.report.group, value: 'group' },
359
394
  { label: translations.report.distance, value: 'distance' })
360
395
  }
396
+ return columns
397
+ }
361
398
 
362
- let data = []
399
+ function getExcelContent (userData, d, translations) {
400
+ const weekDays = [
401
+ translations.report.sunday,
402
+ translations.report.monday,
403
+ translations.report.tuesday,
404
+ translations.report.wednesday,
405
+ translations.report.thursday,
406
+ translations.report.friday,
407
+ translations.report.saturday
408
+ ]
363
409
 
364
- info.forEach(d => {
365
- const group = userData.byDriver
366
- ? userData.groups.find(g => g.drivers && g.drivers.includes(d.driver.id))
367
- : userData.groups.find(g => d.device.groupId === g.id)
410
+ const data = []
411
+ const group = userData.byDriver
412
+ ? userData.groups.find(g => g.drivers && g.drivers.includes(d.driver.id))
413
+ : userData.groups.find(g => d.device.groupId === g.id)
368
414
 
369
- if (userData.groupByDay) {
370
- if (d.days) {
415
+ if (userData.groupByDay) {
416
+ const partner = getUserPartner(userData.user)
417
+ if (d.days) {
418
+ if (partner.reports.kmsReportDaysInColumns) {
371
419
  const vehicle = {
372
420
  name: d.device.name,
373
421
  group: group ? group.name : '',
@@ -382,33 +430,30 @@ function exportKmsReportToExcel (userData, reportData) {
382
430
 
383
431
  vehicle.total = Number(d.days.reduce((a, b) => a + (b.kms / 1000), 0).toFixed(0))
384
432
 
385
- data = data.concat([vehicle])
433
+ data.push(vehicle)
434
+ } else {
435
+ data.push({})
436
+ data.push(...(d.days.map(a => {
437
+ return {
438
+ name: d.device.name,
439
+ group: group ? group.name : '',
440
+ licenseplate: d.device.attributes.license_plate,
441
+ date: a.date,
442
+ weekday: weekDays[a.date.getDay()],
443
+ distance: Number((a.kms / 1000).toFixed(0))
444
+ }
445
+ })))
386
446
  }
387
- } else {
388
- data = data.concat([{
389
- name: userData.byDriver ? d.driver.name : d.device.name,
390
- group: group ? group.name : '',
391
- licenseplate: userData.byDriver ? '' : d.device.attributes.license_plate,
392
- distance: Number((d.summary.distance / 1000).toFixed(0))
393
- }])
394
447
  }
395
- })
396
-
397
- // add total
398
- if (data.length && !userData.groupByDay) {
399
- data = data.concat({
400
- name: '',
401
- group: '',
402
- licenseplate: 'Total',
403
- distance: data.reduce((prev, curr) => curr.distance ? { distance: (prev.distance || 0) + curr.distance } : prev).distance
448
+ } else {
449
+ data.push({
450
+ name: userData.byDriver ? d.driver.name : d.device.name,
451
+ group: group ? group.name : '',
452
+ licenseplate: userData.byDriver ? '' : d.device.attributes.license_plate,
453
+ distance: Number((d.summary.distance / 1000).toFixed(0))
404
454
  })
405
455
  }
406
-
407
- return {
408
- headers,
409
- data,
410
- settings
411
- }
456
+ return data
412
457
  }
413
458
 
414
459
  exports.createKmsReport = createKmsReport
@@ -214,4 +214,14 @@ function calculateRPMSections (route, min, max) {
214
214
  return sections
215
215
  }
216
216
 
217
+ function exportPerformanceReportToPDF (userData, reportData) {
218
+
219
+ }
220
+
221
+ function exportPerformanceReportToExcel (userData, reportData) {
222
+
223
+ }
224
+
217
225
  exports.createPerformanceReport = createPerformanceReport
226
+ exports.exportPerformanceReportToPDF = exportPerformanceReportToPDF
227
+ exports.exportPerformanceReportToExcel = exportPerformanceReportToExcel
@@ -45,18 +45,19 @@ describe('zones', function () {
45
45
 
46
46
  // eslint-disable-next-line no-undef
47
47
  it('works with casais zones in columns', async () => {
48
- const report = await getReports(process.env.USER_CASAIS, process.env.PASS_CASAIS)
48
+ const report = await getReports('fleetmap.joao.penas2@gmail.com', 'penas46881')
49
49
  const userData = await report.getUserData()
50
50
  userData.zonesByColumn = true
51
- userData.devices = userData.devices.filter(d => d.name === 'G-1101-E Clio')
52
- userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ')
53
- userData.onlyWithKmsOut = true
51
+ userData.devices = userData.devices.filter(d => d.id === 81202)
52
+ userData.geofences = userData.geofences.filter(g => g.name === 'baliza 1 - raio verde ' ||
53
+ g.name === 'baliza 2 - raio amarelo')
54
+ userData.onlyWithKmsOut = false
54
55
  const result = await report.zoneReport(
55
- new Date(Date.UTC(2023, 0, 1, 0, 0, 0, 0)),
56
- new Date(Date.UTC(2023, 0, 31, 23, 59, 59, 0)),
56
+ new Date(Date.UTC(2023, 6, 13, 0, 0, 0, 0)),
57
+ new Date(Date.UTC(2023, 6, 13, 23, 59, 59, 0)),
57
58
  userData)
58
- const first = result[0].devices[0].days[0]
59
+ const first = result[0].devices[0]
59
60
  console.log(first)
60
- assert.equal(first.distanceOut, 35.52274536571346)
61
+ assert.equal(first.days[0].distanceOut, 28)
61
62
  }, 4000000)
62
63
  })
package/src/util/trips.js CHANGED
@@ -40,7 +40,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
40
40
  if (tripStart.getTime() < endDate.getTime() &&
41
41
  tripEnd.getTime() > endDate.getTime()) {
42
42
  // Trip starts inside time period and ends outside time period
43
- if (!route) {
43
+ if (!route && device) {
44
44
  const allInOneData = await traccarHelper.getAllInOne(traccarInstance, startDate, endDate, [device], true, false, false, false, undefined, undefined, 5, 1, undefined, true)
45
45
  route = allInOneData.route
46
46
  }
@@ -54,7 +54,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
54
54
  if (tripStart.getTime() < startDate.getTime() &&
55
55
  new Date(t.endTime).getTime() > startDate.getTime()) {
56
56
  // Trip starts outside time period and ends inside time period
57
- if (!route) {
57
+ if (!route && device) {
58
58
  const allInOneData = await traccarHelper.getAllInOne(traccarInstance, startDate, endDate, [device], true, false, false, false, undefined, undefined, 5, 1, undefined, true)
59
59
  route = allInOneData.route
60
60
  }
@@ -68,7 +68,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
68
68
  if (tripStart.getTime() < startDate.getTime() &&
69
69
  tripEnd.getTime() > startDate.getTime()) {
70
70
  // Trip starts outside time period and ends inside time period
71
- if (!route) {
71
+ if (!route && device) {
72
72
  const allInOneData = await traccarHelper.getAllInOne(traccarInstance, startDate, endDate, [device], true, false, false, false, undefined, undefined, 5, 1, undefined, true)
73
73
  route = allInOneData.route
74
74
  }
@@ -82,7 +82,7 @@ async function calculatePartialTrip (device, startDate, endDate, route, t, tracc
82
82
  if (tripStart.getTime() < endDate.getTime() &&
83
83
  tripEnd.getTime() > endDate.getTime()) {
84
84
  // Trip starts inside time period and ends outside time period
85
- if (!route) {
85
+ if (!route && device) {
86
86
  const allInOneData = await traccarHelper.getAllInOne(traccarInstance, startDate, endDate, [device], true, false, false, false, undefined, undefined, 5, 1, undefined, true)
87
87
  route = allInOneData.route
88
88
  }
@@ -104,7 +104,7 @@ function isPartialInsideTimetable (t, userData, route) {
104
104
  const startDate = isClientSide() ? startDateLocal : convertFromLocal(startDateLocal, userData.user.attributes.timezone)
105
105
  const endDate = isClientSide() ? endDateLocal : convertFromLocal(endDateLocal, userData.user.attributes.timezone)
106
106
 
107
- return calculatePartialTrip(startDate, endDate, route, t)
107
+ return calculatePartialTrip(undefined, startDate, endDate, route, t)
108
108
  }
109
109
 
110
110
  return false