fleetmap-reports 1.0.920 → 1.0.922

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.920",
3
+ "version": "1.0.922",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/kms-report.js CHANGED
@@ -7,7 +7,7 @@ const {
7
7
  } = require('./util/pdfDocument')
8
8
  const { getUserPartner } = require('fleetmap-partners')
9
9
  const traccar = require('./util/traccar')
10
- const { getDates, getTranslations } = require('./util/utils')
10
+ const { getDates, getTranslations, isClientSide, executeServerSide } = require('./util/utils')
11
11
  const drivers = require('./util/driver')
12
12
  const { isInsideTimetable, isPartialInsideTimetable, calculateTrip, getDataByDay, checkTripsKms } = require('./util/trips')
13
13
  const traccarHelper = require('./util/traccar')
@@ -43,21 +43,29 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
43
43
  to
44
44
  }
45
45
 
46
- let deviceCount = 0
47
- const sliced = automaticReports.sliceArray(allDevices, 20)
48
- for (const devices of sliced) {
49
- const needRoute = !userData.allWeek
50
- const {
51
- trips,
52
- route
53
- } = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, false, deviceCount, allDevices.length, 10, 2)
54
-
55
- // Process report data
56
- if (trips.length) {
57
- checkTripsKms(traccarInstance, from, to, allDevices, { trips, route })
58
- allData.devices = allData.devices.concat(await processDevices(from, to, allDevices, { trips, route }, userData, traccarInstance))
46
+ if (isClientSide() && allDevices.length > 50 && userData.groupByDay) {
47
+ const sliced = automaticReports.sliceArray(allDevices, 20)
48
+ await executeServerSide('kms-report', allData, sliced, from, to, userData, allDevices.length)
49
+ } else {
50
+ let deviceCount = 0
51
+ const sliced = automaticReports.sliceArray(allDevices, 20)
52
+ for (const devices of sliced) {
53
+ const needRoute = !userData.allWeek
54
+ const {
55
+ trips,
56
+ route
57
+ } = await traccar.getAllInOne(traccarInstance, from, to, devices, needRoute, true, false, false, deviceCount, allDevices.length, 10, 2)
58
+
59
+ // Process report data
60
+ if (trips.length) {
61
+ checkTripsKms(traccarInstance, from, to, allDevices, { trips, route })
62
+ allData.devices = allData.devices.concat(await processDevices(from, to, allDevices, {
63
+ trips,
64
+ route
65
+ }, userData, traccarInstance))
66
+ }
67
+ deviceCount += devices.length
59
68
  }
60
- deviceCount += devices.length
61
69
  }
62
70
 
63
71
  return allData
@@ -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
  })
@@ -343,7 +343,7 @@ async function exportTripReportToPDF (userData, reportData) {
343
343
  doc.text(name, 20, space + 20)
344
344
  doc.setFontSize(11)
345
345
  doc.text(group ? translations.report.group + ': ' + group.name : '', 200, space + 20)
346
- doc.text(convertToLocaleString(d.from, lang, timezone) + ' - ' + convertToLocaleString(d.to, lang, timezone), 20, space + 25)
346
+ doc.text(convertToLocaleString(d.from, lang, timezone, userData.user) + ' - ' + convertToLocaleString(d.to, lang, timezone, userData.user), 20, space + 25)
347
347
  if (!userData.allWeek && userData.weekDays) {
348
348
  doc.text((userData.weekDays.monday ? ' ' + translations.report.monday + ',' : '') +
349
349
  (userData.weekDays.tuesday ? ' ' + translations.report.tuesday + ',' : '') +
package/src/util/utils.js CHANGED
@@ -224,6 +224,18 @@ function weekDaySelected (date, weekDays) {
224
224
  (date.getDay() === 6 && weekDays.saturday))
225
225
  }
226
226
 
227
+ async function executeServerSide (type, allData, sliced, from, to, userData, totalDevices) {
228
+ let deviceCount = 0
229
+ for (const devices of sliced) {
230
+ const url = `https://${process.env.SERVER_HOST}/reports/${type}`
231
+ const data = await axios.post(url, { from, to, userData: { ...userData, devices } }, { withCredentials: true }).then(d => d.data)
232
+ allData.devices.push(...(data[0].devices))
233
+ deviceCount = deviceCount + devices.length
234
+ console.log(`PROGRESS_PERC:${deviceCount / totalDevices * 100}`)
235
+ }
236
+ }
237
+
238
+ exports.executeServerSide = executeServerSide
227
239
  exports.getImgFromUrl = getImgFromUrl
228
240
  exports.convertMS = convertMS
229
241
  exports.coordsDistance = coordsDistance